OpenFPM  5.2.0
Project that contain the implementation of distributed structures
mainFD.cpp
1 //
2 // Created by Abhinav Singh on 15.11.2021.
3 //
4 
28 // Include Vector Expression,Vector Expressions for Subset,FD , and Solver header files
29 #include "config.h"
30 #include <iostream>
31 #include "FiniteDifference/FD_Solver.hpp"
32 #include "FiniteDifference/FD_op.hpp"
33 #include "FiniteDifference/FD_expressions.hpp"
34 #include "FiniteDifference/util/EqnsStructFD.hpp"
36 
37 int main(int argc, char* argv[])
38 {
39  {
54  openfpm_init(&argc,&argv);
55  using namespace FD;
56  timer tt2;
57  tt2.start();
58  size_t gd_sz = 81;
59  constexpr int x = 0;
60  constexpr int y = 1;
61  const size_t szu[2] = {gd_sz,gd_sz};
62  int sz[2]={int(gd_sz),int(gd_sz)};
63  Box<2, double> box({0, 0}, {1,1});
64  periodicity<2> bc = {NON_PERIODIC, NON_PERIODIC};
65  double spacing;
66  spacing = 1.0 / (sz[0] - 1);
67  Ghost<2,long int> ghost(1);
68  auto &v_cl = create_vcluster();
70  grid_dist_id<2, double, LidCavity> domain(szu, box,ghost,bc);
71  double x0, y0, x1, y1;
72  x0 = box.getLow(0);
73  y0 = box.getLow(1);
74  x1 = box.getHigh(0);
75  y1 = box.getHigh(1);
76 
78 
92  auto it = domain.getDomainIterator();
93  while (it.isNext())
94  {
95  auto key = it.get();
96  auto gkey = it.getGKey(key);
97  double x = gkey.get(0) * domain.spacing(0);
98  double y = gkey.get(1) * domain.spacing(1);
99  if (y==1)
100  {domain.get<1>(key) = 1.0;}
101  else
102  {domain.get<1>(key) = 0.0;}
103 
104  ++it;
105  }
106  domain.ghost_get<0>();
108 
119  Derivative_x Dx;
120  Derivative_y Dy;
121  Derivative_xx Dxx;
122  Derivative_yy Dyy;
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);
132 
143  eq_id x_comp,y_comp;
144  x_comp.setId(0);
145  y_comp.setId(1);
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]));
149  RHS=0;
150  dV=0;
151  double V_err=1;
152  int n;
153  while (V_err >= 0.05 && n <= 50) {
154  if (n%5==0){
155  domain.ghost_get<0,1>(SKIP_LABELLING);
156  domain.write_frame("LID",n,BINARY);
157  domain.ghost_get<0>();
158  }
159  domain.ghost_get<0>(SKIP_LABELLING);
160  RHS[x] = -Dx(P);
161  RHS[y] = -Dy(P);
162  FD_scheme<equations2d2,decltype(domain)> Solver(ghost,domain);
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]);
174 
175  domain.ghost_get<5>(SKIP_LABELLING);
176  div = (Dx(V_star[x]) + Dy(V_star[y]));
177 
178  FD_scheme<equations2d1E,decltype(domain)> SolverH(ghost,domain);
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);
186  SolverH.solve(H);
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);
191  sum = 0;
192  sum1 = 0;
193  auto it2 = domain.getDomainIterator();
194  while (it2.isNext()) {
195  auto p = it2.get();
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];
202  ++it2;
203  }
204  V[x] = V_star[x];
205  V[y] = V_star[y];
206  v_cl.sum(sum);
207  v_cl.sum(sum1);
208  v_cl.execute();
209  sum = sqrt(sum);
210  sum1 = sqrt(sum1);
211  V_err_old = V_err;
212  V_err = sum / sum1;
213  n++;
214  if (v_cl.rank() == 0) {
215  std::cout << "Rel l2 cgs err in V = " << V_err << "."<< std::endl;
216  }
217  }
218  domain.write("LID_final");
219  tt2.stop();
220  if (v_cl.rank() == 0) {
221  std::cout << "The entire solver took " << tt2.getcputime() << "(CPU) ------ " << tt2.getwct()
222  << "(Wall) Seconds.";
223  }
224  }
225  openfpm_finalize();
227 
237 }
This class represent an N-dimensional box.
Definition: Box.hpp:60
Finite Differences.
Definition: FD_Solver.hpp:128
Definition: Ghost.hpp:40
Test structure used for several test.
Definition: Point_test.hpp:106
This class implement the point shape in an N-dimensional space.
Definition: Point.hpp:28
This is a distributed grid.
Class for cpu time benchmarking.
Definition: timer.hpp:28
void stop()
Stop the timer.
Definition: timer.hpp:119
double getcputime()
Return the cpu time.
Definition: timer.hpp:142
void start()
Start the timer.
Definition: timer.hpp:90
double getwct()
Return the elapsed real time.
Definition: timer.hpp:130
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...
Definition: aggregate.hpp:221
Specify the general characteristic of system to solve.
Definition: EqnsStruct.hpp:648
Boundary conditions.
Definition: common.hpp:22