42#include "DCPSE/DCPSE_OP/DCPSE_op.hpp"
43#include "DCPSE/DCPSE_OP/DCPSE_Solver.hpp"
44#include "Operators/Vector/vector_dist_operators.hpp"
45#include "Vector/vector_dist_subset.hpp"
48int main(
int argc,
char* argv[])
66 openfpm_init(&argc,&argv);
71 double V_err_eps = 1e-2;
76 const size_t sz[2] = {gd_sz,gd_sz};
78 size_t bc[2] = {NON_PERIODIC, NON_PERIODIC};
80 spacing = 1.0 / (sz[0] - 1);
81 double rCut = 3.1 * spacing;
85 auto &v_cl = create_vcluster();
86 typedef aggregate<double, VectorS<2, double>,
VectorS<2, double>,
VectorS<2, double>,double,
VectorS<2, double>,double,
double> LidCavity;
89 Particles.setPropNames({
"00-Pressure",
"01-Velocity",
"02-RHS",
"03-dV",
"04-Divergence",
"05-Divergence",
"06-H",
"07-dP"});
91 double x0, y0, x1, y1;
112 auto it = Particles.getGridIterator(sz);
117 mem_id k0 = key.get(0);
118 double xp = k0 * spacing;
119 Particles.getLastPos()[0] = xp;
120 mem_id k1 = key.get(1);
121 double yp = k1 * spacing;
122 Particles.getLastPos()[1] = yp;
123 Particles.getLastProp<1>()[0]=0.0;
124 Particles.getLastProp<1>()[1]=0.0;
125 if (xp != x0 && yp != y0 && xp != x1 && yp != y1)
127 Particles.getLastSubset(0);
129 else if(yp==y1 && xp>x0 && xp<x1)
131 Particles.getLastSubset(1);
132 Particles.getLastProp<1>()[0]=1.0;
136 Particles.getLastSubset(3);
140 Particles.getLastSubset(4);
144 Particles.getLastSubset(2);
150 Particles.ghost_get<0>();
168 auto &bulk=Particles_bulk.getIds();
169 auto &up_p=Particles_up.getIds();
170 auto &dw_p=Particles_down.getIds();
171 auto &l_p=Particles_left.getIds();
172 auto &r_p=Particles_right.getIds();
175 auto P = getV<0>(Particles);
176 auto V = getV<1>(Particles);
177 auto RHS = getV<2>(Particles);
178 auto dV = getV<3>(Particles);
179 auto div = getV<4>(Particles);
180 auto V_star = getV<5>(Particles);
181 auto H = getV<6>(Particles);
182 auto dP = getV<7>(Particles);
186 auto P_bulk = getV<0>(Particles_bulk);
187 auto V_bulk = getV<1>(Particles_bulk);
188 auto RHS_bulk =getV<2>(Particles_bulk);
189 auto V_star_bulk = getV<5>(Particles_bulk);
190 auto dP_bulk = getV<7>(Particles_bulk);
194 Derivative_x Dx(Particles, 2, rCut,sampling_factor, support_options::RADIUS);
195 Derivative_xx Dxx(Particles, 2, rCut,sampling_factor2, support_options::RADIUS);
196 Derivative_yy Dyy(Particles, 2, rCut,sampling_factor2, support_options::RADIUS);
197 Derivative_y Dy(Particles, 2, rCut,sampling_factor, support_options::RADIUS);
198 Derivative_x Bulk_Dx(Particles_bulk, 2, rCut,sampling_factor, support_options::RADIUS);
199 Derivative_y Bulk_Dy(Particles_bulk, 2, rCut,sampling_factor, support_options::RADIUS);
212 int n = 0, nmax = 300, ctr = 0, errctr=1, Vreset = 0;
225 double sum, sum1, sum_k,V_err_old;
226 auto StokesX=(V[x]*Dx(V_star[x])+V[y]*Dy(V_star[x]))-(1.0/Re)*(Dxx(V_star[x])+Dyy(V_star[x]));
227 auto StokesY=(V[x]*Dx(V_star[y])+V[y]*Dy(V_star[y]))-(1.0/Re)*(Dxx(V_star[y])+Dyy(V_star[y]));
229 solverPetsc.setSolver(KSPGMRES);
235 while (V_err >= V_err_eps && n <= nmax) {
237 Particles.ghost_get<0,1,2,3,4,5,6,7>(SKIP_LABELLING);
238 Particles.deleteGhost();
239 Particles.write_frame(
"LID",n,BINARY);
240 Particles.ghost_get<0>();
243 Particles.ghost_get<0>(SKIP_LABELLING);
244 RHS_bulk[x] = -Bulk_Dx(
P);
245 RHS_bulk[y] = -Bulk_Dy(
P);
246 DCPSE_scheme<
equations2d2,
decltype(Particles)> Solver(Particles);
247 Solver.impose(StokesX, bulk, RHS[x],
vx);
248 Solver.impose(StokesY, bulk, RHS[y], vy);
249 Solver.impose(V_star[x], up_p, 1.0,
vx);
250 Solver.impose(V_star[y], up_p, 0.0, vy);
251 Solver.impose(V_star[x], l_p, 0.0,
vx);
252 Solver.impose(V_star[y], l_p, 0.0, vy);
253 Solver.impose(V_star[x], r_p, 0.0,
vx);
254 Solver.impose(V_star[y], r_p, 0.0, vy);
255 Solver.impose(V_star[x], dw_p, 0.0,
vx);
256 Solver.impose(V_star[y], dw_p, 0.0, vy);
257 Solver.solve_with_solver(solverPetsc,V_star[x], V_star[y]);
259 Particles.ghost_get<5>(SKIP_LABELLING);
260 div = (Dx(V_star[x]) + Dy(V_star[y]));
262 DCPSE_scheme<
equations2d1E,
decltype(Particles)> SolverH(Particles,options_solver::LAGRANGE_MULTIPLIER);
263 auto Helmholtz = Dxx(H)+Dyy(H);
265 SolverH.impose(Dy(H), up_p,0);
266 SolverH.impose(Dx(H), l_p,0);
267 SolverH.impose(Dx(H), r_p,0);
268 SolverH.impose(Dy(H), dw_p,0);
271 Particles.ghost_get<6>(SKIP_LABELLING);
272 Particles.ghost_get<6>(SKIP_LABELLING);
273 P_bulk =
P - alpha*(div-0.5*(V[x]*Bulk_Dx(H)+V[y]*Bulk_Dy(H)));
274 V_star_bulk[0] = V_star[0] - Bulk_Dx(H);
275 V_star_bulk[1] = V_star[1] - Bulk_Dy(H);
279 for (
int j = 0; j < bulk.size(); j++) {
280 auto p = bulk.get<0>(j);
281 sum += (Particles.getProp<5>(p)[0] - Particles.getProp<1>(p)[0]) *
282 (Particles.getProp<5>(p)[0] - Particles.getProp<1>(p)[0]) +
283 (Particles.getProp<5>(p)[1] - Particles.getProp<1>(p)[1]) *
284 (Particles.getProp<5>(p)[1] - Particles.getProp<1>(p)[1]);
285 sum1 += Particles.getProp<5>(p)[0] * Particles.getProp<5>(p)[0] +
286 Particles.getProp<5>(p)[1] * Particles.getProp<5>(p)[1];
297 if (V_err > V_err_old || abs(V_err_old - V_err) < 1e-8) {
314 if (v_cl.rank() == 0) {
315 std::cout <<
"Rel l2 cgs err in V = " << V_err <<
" at " << n <<
" and took " <<tt.
getwct() <<
"("<<tt.
getcputime()<<
") seconds(CPU)." << std::endl;
318 Particles.deleteGhost();
319 Particles.write(
"LID");
321 if (v_cl.rank() == 0) {
322 std::cout <<
"The simulation took " << tt2.
getcputime() <<
"(CPU) ------ " << tt2.
getwct()
323 <<
"(Wall) Seconds.";
This class represent an N-dimensional box.
Test structure used for several test.
This class implement the point shape in an N-dimensional space.
In case T does not match the PETSC precision compilation create a stub structure.
Class for cpu time benchmarking.
void stop()
Stop the timer.
double getcputime()
Return the cpu time.
void start()
Start the timer.
double getwct()
Return the elapsed real time.
aggregate of properties, from a list of object if create a struct that follow the OPENFPM native stru...
Specify the general characteristic of system to solve.
It model an expression expr1 + ... exprn.