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"
48 int 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);
195 auto verletList = Particles.template getVerlet<VL_NON_SYMMETRIC|VL_SKIP_REF_PART>(rCut);
196 auto verletList_bulk = Particles_bulk.template getVerlet<VL_NON_SYMMETRIC|VL_SKIP_REF_PART>(rCut);
198 Derivative_x<decltype(verletList)> Dx(Particles, verletList, 2, rCut);
199 Derivative_xx<decltype(verletList)> Dxx(Particles, verletList, 2, rCut);
200 Derivative_yy<decltype(verletList)> Dyy(Particles, verletList, 2, rCut);
201 Derivative_y<decltype(verletList)> Dy(Particles, verletList, 2, rCut);
202 Derivative_x<decltype(verletList_bulk)> Bulk_Dx(Particles, Particles_bulk, verletList_bulk, 2, rCut);
203 Derivative_y<decltype(verletList_bulk)> Bulk_Dy(Particles, Particles_bulk, verletList_bulk, 2, rCut);
216 int n = 0, nmax = 300, ctr = 0, errctr=1, Vreset = 0;
229 double sum, sum1, sum_k,V_err_old;
230 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]));
231 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]));
239 while (V_err >= V_err_eps && n <= nmax) {
241 Particles.ghost_get<0,1,2,3,4,5,6,7>(SKIP_LABELLING);
242 Particles.deleteGhost();
243 Particles.write_frame(
"LID",n,BINARY);
244 Particles.ghost_get<0>();
247 Particles.ghost_get<0>(SKIP_LABELLING);
248 RHS_bulk[x] = -Bulk_Dx(
P);
249 RHS_bulk[y] = -Bulk_Dy(
P);
250 DCPSE_scheme<
equations2d2, decltype(Particles)> Solver(Particles);
251 Solver.impose(StokesX, bulk, RHS[x],
vx);
252 Solver.impose(StokesY, bulk, RHS[y], vy);
253 Solver.impose(V_star[x], up_p, 1.0,
vx);
254 Solver.impose(V_star[y], up_p, 0.0, vy);
255 Solver.impose(V_star[x], l_p, 0.0,
vx);
256 Solver.impose(V_star[y], l_p, 0.0, vy);
257 Solver.impose(V_star[x], r_p, 0.0,
vx);
258 Solver.impose(V_star[y], r_p, 0.0, vy);
259 Solver.impose(V_star[x], dw_p, 0.0,
vx);
260 Solver.impose(V_star[y], dw_p, 0.0, vy);
261 Solver.solve_with_solver(solverPetsc,V_star[x], V_star[y]);
263 Particles.ghost_get<5>(SKIP_LABELLING);
264 div = (Dx(V_star[x]) + Dy(V_star[y]));
266 DCPSE_scheme<
equations2d1E,decltype(Particles)> SolverH(Particles,options_solver::LAGRANGE_MULTIPLIER);
267 auto Helmholtz = Dxx(H)+Dyy(H);
269 SolverH.impose(Dy(H), up_p,0);
270 SolverH.impose(Dx(H), l_p,0);
271 SolverH.impose(Dx(H), r_p,0);
272 SolverH.impose(Dy(H), dw_p,0);
275 Particles.ghost_get<6>(SKIP_LABELLING);
276 Particles.ghost_get<6>(SKIP_LABELLING);
277 P_bulk =
P - alpha*(div-0.5*(V[x]*Bulk_Dx(H)+V[y]*Bulk_Dy(H)));
278 V_star_bulk[0] = V_star[0] - Bulk_Dx(H);
279 V_star_bulk[1] = V_star[1] - Bulk_Dy(H);
283 for (
int j = 0; j < bulk.size(); j++) {
284 auto p = bulk.get<0>(j);
285 sum += (Particles.getProp<5>(p)[0] - Particles.getProp<1>(p)[0]) *
286 (Particles.getProp<5>(p)[0] - Particles.getProp<1>(p)[0]) +
287 (Particles.getProp<5>(p)[1] - Particles.getProp<1>(p)[1]) *
288 (Particles.getProp<5>(p)[1] - Particles.getProp<1>(p)[1]);
289 sum1 += Particles.getProp<5>(p)[0] * Particles.getProp<5>(p)[0] +
290 Particles.getProp<5>(p)[1] * Particles.getProp<5>(p)[1];
301 if (V_err > V_err_old || abs(V_err_old - V_err) < 1e-8) {
318 if (v_cl.rank() == 0) {
319 std::cout <<
"Rel l2 cgs err in V = " << V_err <<
" at " << n <<
" and took " <<tt.
getwct() <<
"("<<tt.
getcputime()<<
") seconds(CPU)." << std::endl;
322 Particles.deleteGhost();
323 Particles.write(
"LID");
325 if (v_cl.rank() == 0) {
326 std::cout <<
"The simulation took " << tt2.
getcputime() <<
"(CPU) ------ " << tt2.
getwct()
327 <<
"(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.
This class is able to do Matrix inversion in parallel with PETSC solvers.
void setSolver(KSPType type)
Set the Petsc solver.
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.