OpenFPM  5.2.0
Project that contain the implementation of distributed structures
gs.cpp
1 
2 
4 #include "Operators/Vector/vector_dist_operators.hpp"
5 #include "DCPSE/DCPSE_op/DCPSE_op.hpp"
6 #include <string>
8 
9 constexpr int x = 0;
10 constexpr int y = 1;
11 
13 
14 int main(int argc, char* argv[])
15 {
16 
17 
18 
19  // initialize the library
20  openfpm_init(&argc,&argv);
21  auto &v_cl=create_vcluster();
22 
23 
24 
25  //std::cout << "RK4"<< std::endl;
26 
27  std::ofstream output_file;
28  output_file.open("rk4_error_results.csv",std::ios_base::app);
29 
30  size_t gdsz = std::stof(argv[1]);
31  const size_t sz[3] = {gdsz,gdsz,gdsz};
32  Box<3,double> box({0.0,0.0,0.0},{2.5,2.5,2.5});
33  // Define periodicity of the grid
34  size_t bc[3] = {PERIODIC,PERIODIC,PERIODIC};
35  double spacing[3];
36  spacing[0] = 2.5 / (sz[0]);
37  spacing[1] = 2.5 / (sz[1]);
38  spacing[2] = 2.5 / (sz[2]);
39  double rCut = 2.9 * spacing[0];
40  Ghost<3, double> ghost(rCut);
41 
42  // integration time
43  // double t=0.0,tf=0.5;
44  double t=0,tf=std::stof(argv[2]);
45  double init_dt = 1;
46 
49 
50  dist_vector_type Particles(0, box, bc, ghost);
51  Particles.setPropNames({"Concentration","Initial","k1","k2","k3","k4"});
52  // analytical solution
53  auto it = Particles.getGridIterator(sz);
54  while (it.isNext()) {
55  Particles.add();
56  auto key = it.get();
57  double x = 0.0 + key.get(0) * spacing[0];
58  Particles.getLastPos()[0] = x;
59  double y = 0.0 + key.get(1) * spacing[1];
60  Particles.getLastPos()[1] = y;
61  double z = 0.0 + key.get(2) * spacing[2];
62  Particles.getLastPos()[2] = z;
63  // Here fill the Initial value of the concentration.
64  Particles.template getLastProp<1>()[0] = 1.0;
65  Particles.template getLastProp<1>()[1] = 0.0;
66 
67  if (x > 1.55 && x < 1.85 && y > 1.55 && y < 1.85 && z > 1.55 && z < 1.85) {
68  Particles.template getLastProp<1>()[0] = 0.5 + (((double)std::rand())/RAND_MAX -0.5)/10.0;
69  Particles.template getLastProp<1>()[1] = 0.25 + (((double)std::rand())/RAND_MAX -0.5)/20.0;
70  }
71 
72  ++it;
73  }
74  Particles.map();
75  Particles.ghost_get<0>();
76 
77 
78  auto verletList = Particles.template getVerlet<VL_NON_SYMMETRIC|VL_SKIP_REF_PART>(rCut);
79  Laplacian<decltype(verletList)> Lap(Particles, verletList, 2, rCut, support_options::RADIUS);
80 
81  auto C = getV<0>(Particles);
82  auto Init = getV<1>(Particles);
83  auto k1 = getV<2>(Particles);
84  auto k2 = getV<3>(Particles);
85  auto k3 = getV<4>(Particles);
86  auto k4 = getV<5>(Particles);
87  // integrate for different numbers of time steps
88  double dt = init_dt;
89 
90  //std::cout << std::endl;
91  //std::cout << "--- RK4 Solving for dt = " << dt << " ..." << std::endl;
92  size_t steps = 0;
93  double K = 0.053;
94  double F = 0.014;
95 
96  double d1 = 2*1e-4;
97  double d2 = 1*1e-4;
98 
99  timer timer_integrate;
100  timer_integrate.start();
101  while (t < tf) {
102  C=Init;
103  Particles.ghost_get<0>(SKIP_LABELLING);
104  k1[x]=d1*Lap(C[x]) - C[x] * C[y] * C[y] + F - F * C[x];
105  k1[y]=d2*Lap(C[y]) + C[x] * C[y] * C[y] - (F+K) * C[y];
106 
107  C=Init+0.5*dt*k1;
108  Particles.ghost_get<0>(SKIP_LABELLING);
109  k2[x]=d1*Lap(C[x]) - C[x] * C[y] * C[y] + F - F * C[x];
110  k2[y]=d2*Lap(C[y]) + C[x] * C[y] * C[y] - (F+K) * C[y];
111 
112  C=Init+0.5*dt*k2;
113  Particles.ghost_get<0>(SKIP_LABELLING);
114  k3[x]=d1*Lap(C[x]) - C[x] * C[y] * C[y] + F - F * C[x];
115  k3[y]=d2*Lap(C[y]) + C[x] * C[y] * C[y] - (F+K) * C[y];
116 
117  C=Init+dt*k3;
118  Particles.ghost_get<0>(SKIP_LABELLING);
119  k4[x]=d1*Lap(C[x]) - C[x] * C[y] * C[y] + F - F * C[x];
120  k4[y]=d2*Lap(C[y]) + C[x] * C[y] * C[y] - (F+K) * C[y];
121  Init = Init + dt / 6.0 * (k1 + 2.0 * k2 + 2.0 * k3 + k4);
122  //if(steps%100==0){
123  //Particles.deleteGhost();
124  //Particles.write_frame("Test",steps,t);
125  //Particles.ghost_get<0>();
126  //}
127  t += dt;
128  steps++;
129  }
130  timer_integrate.stop();
131  Particles.ghost_get<0,1>();
132  Particles.deleteGhost();
133  Particles.write("Final");
134 
135  double tt=timer_integrate.getwct();
136  v_cl.sum(tt);
137  v_cl.execute();
138 
139  if(v_cl.rank()==0)
140  {output_file << steps <<","<<v_cl.size()<<"," << tt/v_cl.size() << "\n";}
141  // Particles.write("particles_dt=" + boost::lexical_cast<std::string>(dt));
142  output_file.close();
143 
144 
145  openfpm_finalize();
146 
147 }
This class represent an N-dimensional box.
Definition: Box.hpp:60
Definition: Ghost.hpp:40
Laplacian second order on h (spacing)
Definition: Laplacian.hpp:23
This class implement the point shape in an N-dimensional space.
Definition: Point.hpp:28
Class for cpu time benchmarking.
Definition: timer.hpp:28
void stop()
Stop the timer.
Definition: timer.hpp:119
void start()
Start the timer.
Definition: timer.hpp:90
double getwct()
Return the elapsed real time.
Definition: timer.hpp:130
Main class that encapsulate a vector properties operand to be used for expressions construction.
Distributed vector.
[v_transform metafunction]
aggregate of properties, from a list of object if create a struct that follow the OPENFPM native stru...
Definition: aggregate.hpp:221