Skip to content

Commit 7859a48

Browse files
committed
Apply clang-format
1 parent d936cc2 commit 7859a48

28 files changed

+1116
-1108
lines changed

elastic-tube-1d/fluid-cpp/src/FluidComputeSolution.cpp

Lines changed: 56 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,27 @@
33
#include <cmath>
44
#include <iomanip>
55
#include <iostream>
6-
#include <vector>
76
#include <numeric>
7+
#include <vector>
88

99
using std::sin;
1010
using std::sqrt;
1111

1212
// Simplifies strided access on a 1d buffer
13-
template<class T>
13+
template <class T>
1414
class StridedAccess {
15-
public:
16-
StridedAccess(T*first, int stride) : first(first), stride(stride) {};
17-
// This accessor allows for row-major access
18-
T& operator()(int i, int j) { return first[j*stride+i]; }
19-
private:
20-
T*first;
21-
int stride;
15+
public:
16+
StridedAccess(T *first, int stride)
17+
: first(first), stride(stride){};
18+
// This accessor allows for row-major access
19+
T &operator()(int i, int j)
20+
{
21+
return first[j * stride + i];
22+
}
23+
24+
private:
25+
T * first;
26+
int stride;
2227
};
2328

2429
extern "C" {
@@ -35,16 +40,16 @@ void dgesv_(
3540

3641
/* Function for fluid_nl i.e. non-linear */
3742
int fluidComputeSolutionSerial(
38-
double const * const velocity_old,
39-
double const * const pressure_old,
40-
double const * const crossSectionLength_old,
41-
double const * const crossSectionLength,
42-
double t,
43-
int N,
44-
double kappa,
45-
double tau,
46-
double * velocity,
47-
double * pressure)
43+
double const *const velocity_old,
44+
double const *const pressure_old,
45+
double const *const crossSectionLength_old,
46+
double const *const crossSectionLength,
47+
double t,
48+
int N,
49+
double kappa,
50+
double tau,
51+
double * velocity,
52+
double * pressure)
4853
{
4954
const double PI = 3.141592653589793;
5055

@@ -59,67 +64,52 @@ int fluidComputeSolutionSerial(
5964

6065
// Used as Ax = b
6166
// i.e. LHS*x = Res
62-
std::vector<double> Res(2 * N + 2);
63-
std::vector<double> LHS_buffer(std::pow(2*N + 2, 2));
64-
StridedAccess<double> LHS(LHS_buffer.data(), 2* N + 2);
67+
std::vector<double> Res(2 * N + 2);
68+
std::vector<double> LHS_buffer(std::pow(2 * N + 2, 2));
69+
StridedAccess<double> LHS(LHS_buffer.data(), 2 * N + 2);
6570

6671
/* LAPACK Variables */
67-
int nlhs = (2 * N + 2);
68-
int nrhs = 1;
72+
int nlhs = (2 * N + 2);
73+
int nrhs = 1;
6974
std::vector<int> ipiv(nlhs);
7075

7176
/* Stabilization Intensity */
7277
const double alpha = 0.0; //(N * kappa * tau) / (N * tau + 1);
73-
const double L = 10.0;
74-
const double dx = L / kappa; // 1.0 / (N * kappa);
78+
const double L = 10.0;
79+
const double dx = L / kappa; // 1.0 / (N * kappa);
7580

7681
// k is the iteration counter
77-
for(int k = 1; ; ++k) {
82+
for (int k = 1;; ++k) {
7883
std::fill(Res.begin(), Res.end(), 0.0);
7984

8085
for (int i = 1; i < N; i++) {
81-
/* Momentum */
86+
/* Momentum */
8287
Res[i] = (velocity_old[i] * crossSectionLength_old[i] - velocity[i] * crossSectionLength[i]) * dx / tau;
8388

84-
Res[i] += 0.25 * (- crossSectionLength[i + 1] * velocity[i] * velocity[i + 1]
85-
- crossSectionLength[i] * velocity[i] * velocity[i + 1]);
89+
Res[i] += 0.25 * (-crossSectionLength[i + 1] * velocity[i] * velocity[i + 1] - crossSectionLength[i] * velocity[i] * velocity[i + 1]);
8690

87-
Res[i] += 0.25 * (- crossSectionLength[i + 1] * velocity[i] * velocity[i]
88-
- crossSectionLength[i] * velocity[i] * velocity[i]
89-
+ crossSectionLength[i] * velocity[i - 1] * velocity[i]
90-
+ crossSectionLength[i - 1] * velocity[i - 1] * velocity[i]);
91+
Res[i] += 0.25 * (-crossSectionLength[i + 1] * velocity[i] * velocity[i] - crossSectionLength[i] * velocity[i] * velocity[i] + crossSectionLength[i] * velocity[i - 1] * velocity[i] + crossSectionLength[i - 1] * velocity[i - 1] * velocity[i]);
9192

92-
Res[i] += 0.25 * (+ crossSectionLength[i - 1] * velocity[i - 1] * velocity[i - 1]
93-
+ crossSectionLength[i] * velocity[i - 1] * velocity[i - 1]);
93+
Res[i] += 0.25 * (+crossSectionLength[i - 1] * velocity[i - 1] * velocity[i - 1] + crossSectionLength[i] * velocity[i - 1] * velocity[i - 1]);
9494

95-
Res[i] += 0.25*(+ crossSectionLength[i - 1] * pressure[i - 1]
96-
+ crossSectionLength[i] * pressure[i - 1]
97-
- crossSectionLength[i - 1] * pressure[i]
98-
+ crossSectionLength[i + 1] * pressure[i]
99-
- crossSectionLength[i] * pressure[i + 1]
100-
- crossSectionLength[i + 1] * pressure[i + 1]);
95+
Res[i] += 0.25 * (+crossSectionLength[i - 1] * pressure[i - 1] + crossSectionLength[i] * pressure[i - 1] - crossSectionLength[i - 1] * pressure[i] + crossSectionLength[i + 1] * pressure[i] - crossSectionLength[i] * pressure[i + 1] - crossSectionLength[i + 1] * pressure[i + 1]);
10196

10297
/* Continuity */
10398
Res[i + N + 1] = (crossSectionLength_old[i] - crossSectionLength[i]) * dx / tau;
104-
Res[i + N + 1] += 0.25*(+ crossSectionLength[i - 1] * velocity[i - 1]
105-
+ crossSectionLength[i] * velocity[i - 1]
106-
+ crossSectionLength[i - 1] * velocity[i]
107-
- crossSectionLength[i + 1] * velocity[i]
108-
- crossSectionLength[i] * velocity[i + 1]
109-
- crossSectionLength[i + 1] * velocity[i + 1]);
99+
Res[i + N + 1] += 0.25 * (+crossSectionLength[i - 1] * velocity[i - 1] + crossSectionLength[i] * velocity[i - 1] + crossSectionLength[i - 1] * velocity[i] - crossSectionLength[i + 1] * velocity[i] - crossSectionLength[i] * velocity[i + 1] - crossSectionLength[i + 1] * velocity[i + 1]);
110100

111101
Res[i + N + 1] += alpha * (pressure[i - 1] - 2 * pressure[i] + pressure[i + 1]);
112102
}
113103

114104
/* Boundary */
115105

116106
/* Velocity Inlet is prescribed */
117-
const double u0 = 10.0;
118-
const double ampl = 3.0;
119-
const double frequency = 10.0;
120-
const double t_shift = 0.0;
107+
const double u0 = 10.0;
108+
const double ampl = 3.0;
109+
const double frequency = 10.0;
110+
const double t_shift = 0.0;
121111
const double velocity_in = u0 + ampl * sin(frequency * (t + t_shift) * PI);
122-
Res[0] = velocity_in - velocity[0];
112+
Res[0] = velocity_in - velocity[0];
123113

124114
/* Pressure Inlet is linearly interpolated */
125115
Res[N + 1] = -pressure[0] + 2 * pressure[1] - pressure[2];
@@ -129,17 +119,15 @@ int fluidComputeSolutionSerial(
129119

130120
/* Pressure Outlet is "non-reflecting" */
131121
const double tmp2 = sqrt(c_mk2 - pressure_old[N] / 2) - (velocity[N] - velocity_old[N]) / 4;
132-
Res[2 * N + 1] = -pressure[N] + 2 * (c_mk2 - std::pow(tmp2, 2));
122+
Res[2 * N + 1] = -pressure[N] + 2 * (c_mk2 - std::pow(tmp2, 2));
133123

134124
// compute norm of residual
135125
const double norm_1 = std::sqrt(
136-
std::inner_product(Res.begin(), Res.end(), Res.begin(), 0.0)
137-
);
126+
std::inner_product(Res.begin(), Res.end(), Res.begin(), 0.0));
138127

139128
const double norm_2 = std::sqrt(
140129
std::inner_product(pressure, pressure + chunkLength, pressure, 0.0) +
141-
std::inner_product(velocity, velocity + chunkLength, velocity, 0.0)
142-
);
130+
std::inner_product(velocity, velocity + chunkLength, velocity, 0.0));
143131
const double norm = norm_1 / norm_2;
144132

145133
// NOTE tolerance is 1e-10 and max iterations is 1000 in python
@@ -153,34 +141,25 @@ int fluidComputeSolutionSerial(
153141

154142
for (int i = 1; i < N; i++) {
155143
// Momentum, Velocity
156-
LHS(i, i - 1) +=0.25*(-2 * crossSectionLength[i - 1] * velocity[i - 1]
157-
-2 * crossSectionLength[i] * velocity[i - 1]
158-
- crossSectionLength[i] * velocity[i]
159-
- crossSectionLength[i - 1] * velocity[i]);
160-
161-
LHS(i, i) += crossSectionLength[i] * dx / tau;
162-
LHS(i, i) += 0.25 * (+ crossSectionLength[i + 1] * velocity[i + 1]
163-
+ crossSectionLength[i] * velocity[i + 1]
164-
+2 * crossSectionLength[i + 1] * velocity[i]
165-
+2 * crossSectionLength[i] * velocity[i]
166-
- crossSectionLength[i] * velocity[i - 1]
167-
- crossSectionLength[i - 1] * velocity[i - 1]);
168-
LHS(i, i + 1) += 0.25 * (+ crossSectionLength[i + 1] * velocity[i]
169-
+ crossSectionLength[i] * velocity[i]);
144+
LHS(i, i - 1) += 0.25 * (-2 * crossSectionLength[i - 1] * velocity[i - 1] - 2 * crossSectionLength[i] * velocity[i - 1] - crossSectionLength[i] * velocity[i] - crossSectionLength[i - 1] * velocity[i]);
145+
146+
LHS(i, i) += crossSectionLength[i] * dx / tau;
147+
LHS(i, i) += 0.25 * (+crossSectionLength[i + 1] * velocity[i + 1] + crossSectionLength[i] * velocity[i + 1] + 2 * crossSectionLength[i + 1] * velocity[i] + 2 * crossSectionLength[i] * velocity[i] - crossSectionLength[i] * velocity[i - 1] - crossSectionLength[i - 1] * velocity[i - 1]);
148+
LHS(i, i + 1) += 0.25 * (+crossSectionLength[i + 1] * velocity[i] + crossSectionLength[i] * velocity[i]);
170149

171150
// Momentum, Pressure
172151
LHS(i, N + 1 + i - 1) += -0.25 * crossSectionLength[i - 1] - 0.25 * crossSectionLength[i];
173-
LHS(i, N + 1 + i) += 0.25 * crossSectionLength[i - 1] - 0.25 * crossSectionLength[i + 1];
174-
LHS(i, N + 1 + i + 1) += 0.25 * crossSectionLength[i] + 0.25 * crossSectionLength[i + 1];
152+
LHS(i, N + 1 + i) += 0.25 * crossSectionLength[i - 1] - 0.25 * crossSectionLength[i + 1];
153+
LHS(i, N + 1 + i + 1) += 0.25 * crossSectionLength[i] + 0.25 * crossSectionLength[i + 1];
175154

176155
// Continuity, Velocity
177156
LHS(i + N + 1, i - 1) += -0.25 * crossSectionLength[i - 1] - 0.25 * crossSectionLength[i];
178-
LHS(i + N + 1, i) += -0.25 * crossSectionLength[i - 1] + 0.25 * crossSectionLength[i + 1];
179-
LHS(i + N + 1, i + 1) += 0.25 * crossSectionLength[i] + 0.25 * crossSectionLength[i + 1];
157+
LHS(i + N + 1, i) += -0.25 * crossSectionLength[i - 1] + 0.25 * crossSectionLength[i + 1];
158+
LHS(i + N + 1, i + 1) += 0.25 * crossSectionLength[i] + 0.25 * crossSectionLength[i + 1];
180159

181160
// Continuity, Pressure
182161
LHS(i + N + 1, N + 1 + i - 1) -= alpha;
183-
LHS(i + N + 1, N + 1 + i) += 2 * alpha;
162+
LHS(i + N + 1, N + 1 + i) += 2 * alpha;
184163
LHS(i + N + 1, N + 1 + i + 1) -= alpha;
185164
}
186165

elastic-tube-1d/fluid-cpp/src/FluidComputeSolution.h

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@
33
const double PI = 3.14159265359;
44

55
int fluidComputeSolutionSerial(
6-
double const * const velocity_old,
7-
double const * const pressure_old,
8-
double const * const crossSectionLength_old,
9-
double const * const crossSectionLength,
10-
double t,
11-
int N,
12-
double kappa,
13-
double tau,
14-
double * velocity,
15-
double * pressure);
6+
double const *const velocity_old,
7+
double const *const pressure_old,
8+
double const *const crossSectionLength_old,
9+
double const *const crossSectionLength,
10+
double t,
11+
int N,
12+
double kappa,
13+
double tau,
14+
double * velocity,
15+
double * pressure);

elastic-tube-1d/fluid-cpp/src/FluidSolver.cpp

Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
#include "FluidComputeSolution.h"
22
#include "utilities.h"
33

4+
#include <cmath>
45
#include <iostream>
56
#include <vector>
6-
#include <cmath>
77
#include "precice/precice.hpp"
88

99
using namespace precice;
@@ -19,11 +19,11 @@ int main(int argc, char **argv)
1919
return -1;
2020
}
2121

22-
std::string configFileName(argv[1]);
23-
int domainSize = 100; //N
24-
int chunkLength = domainSize + 1;
25-
const double kappa = 100;
26-
const double L = 10.0; // tube length
22+
std::string configFileName(argv[1]);
23+
int domainSize = 100; //N
24+
int chunkLength = domainSize + 1;
25+
const double kappa = 100;
26+
const double L = 10.0; // tube length
2727

2828
const std::string solverName = "Fluid";
2929

@@ -32,23 +32,23 @@ int main(int argc, char **argv)
3232
precice::Participant interface(solverName, configFileName, 0, 1);
3333
std::cout << "preCICE configured..." << std::endl;
3434

35-
auto meshName = "Fluid-Nodes-Mesh";
36-
auto pressureName = "Pressure";
37-
auto crossSectionLengthName = "CrossSectionLength";
38-
const int dimensions = interface.getMeshDimensions(meshName);
35+
auto meshName = "Fluid-Nodes-Mesh";
36+
auto pressureName = "Pressure";
37+
auto crossSectionLengthName = "CrossSectionLength";
38+
const int dimensions = interface.getMeshDimensions(meshName);
3939

40-
std::vector<int> vertexIDs(chunkLength);
40+
std::vector<int> vertexIDs(chunkLength);
4141

4242
const double PI = 3.141592653589793;
4343

44-
const double r0 = 1 / sqrt(PI); // radius of the tube
45-
const double a0 = std::pow(r0, 2) * PI; // cross sectional area
46-
const double u0 = 10; // mean velocity
47-
const double ampl = 3; // amplitude of varying velocity
48-
const double frequency = 10; // frequency of variation
49-
const double t_shift = 0; // temporal shift of variation
50-
const double p0 = 0; // pressure at outlet
51-
const double vel_in_0 = u0 + ampl * sin(frequency * (t_shift) * PI);
44+
const double r0 = 1 / sqrt(PI); // radius of the tube
45+
const double a0 = std::pow(r0, 2) * PI; // cross sectional area
46+
const double u0 = 10; // mean velocity
47+
const double ampl = 3; // amplitude of varying velocity
48+
const double frequency = 10; // frequency of variation
49+
const double t_shift = 0; // temporal shift of variation
50+
const double p0 = 0; // pressure at outlet
51+
const double vel_in_0 = u0 + ampl * sin(frequency * (t_shift) *PI);
5252

5353
std::vector<double> pressure(chunkLength, p0);
5454
std::vector<double> pressure_old(pressure);
@@ -58,7 +58,7 @@ int main(int argc, char **argv)
5858
std::vector<double> velocity_old(velocity);
5959
std::vector<double> grid(dimensions * chunkLength);
6060

61-
const double cellwidth =(L / domainSize) ;
61+
const double cellwidth = (L / domainSize);
6262
for (int i = 0; i < chunkLength; i++) {
6363
for (int d = 0; d < dimensions; d++) {
6464
if (d == 0) {
@@ -75,7 +75,7 @@ int main(int argc, char **argv)
7575
interface.writeData(meshName, pressureName, vertexIDs, pressure);
7676
}
7777

78-
double t = 0.0;
78+
double t = 0.0;
7979
std::cout << "Initialize preCICE..." << std::endl;
8080
interface.initialize();
8181

@@ -84,7 +84,7 @@ int main(int argc, char **argv)
8484
std::copy(crossSectionLength.begin(), crossSectionLength.end(), crossSectionLength_old.begin());
8585

8686
// initialize such that mass conservation is fulfilled
87-
for(int i = 0; i < chunkLength; ++i) {
87+
for (int i = 0; i < chunkLength; ++i) {
8888
velocity_old[i] = vel_in_0 * crossSectionLength_old[0] / crossSectionLength_old[i];
8989
}
9090

@@ -95,34 +95,34 @@ int main(int argc, char **argv)
9595
}
9696

9797
auto dt = interface.getMaxTimeStepSize();
98-
98+
9999
fluidComputeSolutionSerial(
100100
// values from last time window
101101
velocity_old.data(), pressure_old.data(), crossSectionLength_old.data(),
102102
// last received crossSectionLength
103103
crossSectionLength.data(),
104-
t+dt, // used for inlet velocity
105-
domainSize,
106-
kappa,
104+
t + dt, // used for inlet velocity
105+
domainSize,
106+
kappa,
107107
dt, // tau
108108
// resulting velocity pressure
109109
velocity.data(),
110110
pressure.data());
111-
111+
112112
interface.writeData(meshName, pressureName, vertexIDs, pressure);
113-
113+
114114
interface.advance(dt);
115115

116-
interface.readData(meshName,crossSectionLengthName, vertexIDs, interface.getMaxTimeStepSize(), crossSectionLength);
116+
interface.readData(meshName, crossSectionLengthName, vertexIDs, interface.getMaxTimeStepSize(), crossSectionLength);
117117

118118
if (interface.requiresReadingCheckpoint()) {
119119
} else {
120120
t += dt;
121121
write_vtk(t, out_counter, outputFilePrefix.c_str(), chunkLength, grid.data(), velocity.data(), pressure.data(), crossSectionLength.data());
122122
for (int i = 0; i < chunkLength; i++) {
123123
crossSectionLength_old[i] = crossSectionLength[i];
124-
pressure_old[i] = pressure[i];
125-
velocity_old[i] = velocity[i];
124+
pressure_old[i] = pressure[i];
125+
velocity_old[i] = velocity[i];
126126
}
127127
out_counter++;
128128
}

0 commit comments

Comments
 (0)