31#include "FiniteDifference/FD_Solver.hpp"
32#include "FiniteDifference/FD_op.hpp"
33#include "FiniteDifference/FD_expressions.hpp"
34#include "FiniteDifference/util/EqnsStructFD.hpp"
37int main(
int argc,
char* argv[])
54 openfpm_init(&argc,&argv);
61 const size_t szu[2] = {gd_sz,gd_sz};
62 int sz[2]={
int(gd_sz),
int(gd_sz)};
66 spacing = 1.0 / (sz[0] - 1);
68 auto &v_cl = create_vcluster();
69 typedef aggregate<double, VectorS<2, double>,
VectorS<2, double>,
VectorS<2, double>,double,
VectorS<2, double>,double,
double> LidCavity;
71 double x0, y0, x1, y1;
92 auto it = domain.getDomainIterator();
96 auto gkey = it.getGKey(key);
97 double x = gkey.get(0) * domain.spacing(0);
98 double y = gkey.get(1) * domain.spacing(1);
100 {domain.get<1>(key) = 1.0;}
102 {domain.get<1>(key) = 0.0;}
106 domain.ghost_get<0>();
123 auto P = getV<0>(domain);
124 auto V = getV<1>(domain);
125 auto RHS = getV<2>(domain);
126 auto dV = getV<3>(domain);
127 auto div = getV<4>(domain);
128 auto V_star = getV<5>(domain);
129 auto H = getV<6>(domain);
130 auto dP = getV<7>(domain);
146 double sum, sum1, sum_k,V_err_old;
147 auto StokesX=(V[x]*Dx(V_star[x])+V[y]*Dy(V_star[x]))-(1.0/100.0)*(Dxx(V_star[x])+Dyy(V_star[x]));
148 auto StokesY=(V[x]*Dx(V_star[y])+V[y]*Dy(V_star[y]))-(1.0/100.0)*(Dxx(V_star[y])+Dyy(V_star[y]));
153 while (V_err >= 0.05 && n <= 50) {
155 domain.ghost_get<0,1>(SKIP_LABELLING);
156 domain.write_frame(
"LID",n,BINARY);
157 domain.ghost_get<0>();
159 domain.ghost_get<0>(SKIP_LABELLING);
163 Solver.impose(StokesX, {1,1},{sz[0]-2,sz[1]-2}, RHS[x], x_comp);
164 Solver.impose(StokesY, {1,1},{sz[0]-2,sz[1]-2}, RHS[y], y_comp);
165 Solver.impose(V_star[x], {0,sz[1]-1},{sz[0]-1,sz[1]-1}, 1.0, x_comp);
166 Solver.impose(V_star[y], {0,sz[1]-1},{sz[0]-1,sz[1]-1}, 0.0, y_comp);
167 Solver.impose(V_star[x], {0,1},{0,sz[1]-2}, 0.0, x_comp);
168 Solver.impose(V_star[y], {0,1},{0,sz[1]-2}, 0.0, y_comp);
169 Solver.impose(V_star[x], {sz[0]-1,1},{sz[0]-1,sz[1]-2}, 0.0, x_comp);
170 Solver.impose(V_star[y], {sz[0]-1,1},{sz[0]-1,sz[1]-2}, 0.0, y_comp);
171 Solver.impose(V_star[x], {0,0},{sz[0]-1,0}, 0.0, x_comp);
172 Solver.impose(V_star[y], {0,0},{sz[0]-1,0}, 0.0, y_comp);
173 Solver.solve(V_star[x], V_star[y]);
175 domain.ghost_get<5>(SKIP_LABELLING);
176 div = (Dx(V_star[x]) + Dy(V_star[y]));
179 auto Helmholtz = Dxx(H)+Dyy(H);
180 SolverH.impose(Helmholtz,{1,1},{sz[0]-2,sz[1]-2},div);
181 SolverH.impose(Dy(H), {0,sz[0]-1},{sz[0]-1,sz[1]-1},0);
182 SolverH.impose(Dx(H), {sz[0]-1,1},{sz[0]-1,sz[1]-2},0);
183 SolverH.impose(Dx(H), {0,0},{sz[0]-1,0},0,x_comp,
true);
184 SolverH.impose(H, {0,0},{0,0},0);
185 SolverH.impose(Dy(H), {0,1},{0,sz[1]-2},0);
187 domain.ghost_get<1,4,6>(SKIP_LABELLING);
188 P =
P - 0.01*(div-0.5*(V[x]*Dx(H)+V[y]*Dy(H)));
189 V_star[0] = V_star[0] - Dx(H);
190 V_star[1] = V_star[1] - Dy(H);
193 auto it2 = domain.getDomainIterator();
194 while (it2.isNext()) {
196 sum += (domain.getProp<5>(p)[0] - domain.getProp<1>(p)[0]) *
197 (domain.getProp<5>(p)[0] - domain.getProp<1>(p)[0]) +
198 (domain.getProp<5>(p)[1] - domain.getProp<1>(p)[1]) *
199 (domain.getProp<5>(p)[1] - domain.getProp<1>(p)[1]);
200 sum1 += domain.getProp<5>(p)[0] * domain.getProp<5>(p)[0] +
201 domain.getProp<5>(p)[1] * domain.getProp<5>(p)[1];
214 if (v_cl.rank() == 0) {
215 std::cout <<
"Rel l2 cgs err in V = " << V_err <<
"."<< std::endl;
218 domain.write(
"LID_final");
220 if (v_cl.rank() == 0) {
221 std::cout <<
"The entire solver took " << tt2.
getcputime() <<
"(CPU) ------ " << tt2.
getwct()
222 <<
"(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 is a distributed grid.
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.
KeyT const ValueT ValueT OffsetIteratorT OffsetIteratorT int
[in] The number of segments that comprise the sorting data
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.