OpenFPM_pdata  4.1.0
Project that contain the implementation of distributed structures
 
Loading...
Searching...
No Matches
main.cpp
1
12#include "Grid/grid_dist_id.hpp"
13#include "data_type/aggregate.hpp"
14#include "timer.hpp"
15
44constexpr int U = 0;
45constexpr int V = 1;
46
47constexpr int x = 0;
48constexpr int y = 1;
49constexpr int z = 2;
50
52{
53 auto it = Old.getGridIterator();
54
55 while (it.isNext())
56 {
57 // Get the local grid key
58 auto key = it.get_dist();
59
60 // Old values U and V
61 Old.template insert<U>(key) = 1.0;
62 Old.template insert<V>(key) = 0.0;
63
64 // Old values U and V
65 New.template insert<U>(key) = 0.0;
66 New.template insert<V>(key) = 0.0;
67
68 ++it;
69 }
70
71 long int x_start = Old.size(0)*1.55f/domain.getHigh(0);
72 long int y_start = Old.size(1)*1.55f/domain.getHigh(1);
73 long int z_start = Old.size(1)*1.55f/domain.getHigh(2);
74
75 long int x_stop = Old.size(0)*1.85f/domain.getHigh(0);
76 long int y_stop = Old.size(1)*1.85f/domain.getHigh(1);
77 long int z_stop = Old.size(1)*1.85f/domain.getHigh(2);
78
79 grid_key_dx<3> start({x_start,y_start,z_start});
80 grid_key_dx<3> stop ({x_stop,y_stop,z_stop});
81 auto it_init = Old.getGridIterator(start,stop);
82
83 while (it_init.isNext())
84 {
85 auto key = it_init.get_dist();
86
87 Old.template insert<U>(key) = 0.5 + (((double)std::rand())/RAND_MAX -0.5)/10.0;
88 Old.template insert<V>(key) = 0.25 + (((double)std::rand())/RAND_MAX -0.5)/20.0;
89
90 ++it_init;
91 }
92}
93
94
95int main(int argc, char* argv[])
96{
97 openfpm_init(&argc,&argv);
98
99 // domain
100 Box<3,double> domain({0.0,0.0,0.0},{2.5,2.5,2.5});
101
102 // grid size
103 size_t sz[3] = {128,128,128};
104
105 // Define periodicity of the grid
106 periodicity<3> bc = {PERIODIC,PERIODIC,PERIODIC};
107
108 // Ghost in grid unit
110
111 // deltaT
112 double deltaT = 1;
113
114 // Diffusion constant for specie U
115 double du = 2*1e-5;
116
117 // Diffusion constant for specie V
118 double dv = 1*1e-5;
119
120 // Number of timesteps
121#ifdef TEST_RUN
122 size_t timeSteps = 200;
123#else
124 size_t timeSteps = 5000;
125#endif
126
127 // K and F (Physical constant in the equation)
128 double K = 0.053;
129 double F = 0.014;
130
132
133 // New grid with the decomposition of the old grid
134 sgrid_dist_id<3, double, aggregate<double,double>> New(Old.getDecomposition(),sz,g);
135
136
137 // spacing of the grid on x and y
138 double spacing[3] = {Old.spacing(0),Old.spacing(1),Old.spacing(2)};
139
140 init(Old,New,domain);
141
142 // sync the ghost
143 size_t count = 0;
144 Old.template ghost_get<U,V>();
145
146 // because we assume that spacing[x] == spacing[y] we use formula 2
147 // and we calculate the prefactor of Eq 2
148 double uFactor = deltaT * du/(spacing[x]*spacing[x]);
149 double vFactor = deltaT * dv/(spacing[x]*spacing[x]);
150
151 Old.write("Init_condition");
152
153 timer tot_sim;
154 tot_sim.start();
155
156 auto & v_cl = create_vcluster();
157
158 for (size_t i = 0; i < timeSteps; ++i)
159 {
160 if (v_cl.rank() == 0)
161 {std::cout << "STEP: " << i << std::endl;}
162/* if (i % 300 == 0)
163 {
164 std::cout << "STEP: " << i << std::endl;
165 Old.write_frame("out",i);
166 }*/
167
169
170 auto it = Old.getDomainIterator();
171
172 while (it.isNext())
173 {
174 // center point
175 auto Cp = it.get();
176
177 // plus,minus X,Y,Z
178 auto mx = Cp.move(0,-1);
179 auto px = Cp.move(0,+1);
180 auto my = Cp.move(1,-1);
181 auto py = Cp.move(1,1);
182 auto mz = Cp.move(2,-1);
183 auto pz = Cp.move(2,1);
184
185 // update based on Eq 2
186 New.insert<U>(Cp) = Old.get<U>(Cp) + uFactor * (
187 Old.get<U>(mz) +
188 Old.get<U>(pz) +
189 Old.get<U>(my) +
190 Old.get<U>(py) +
191 Old.get<U>(mx) +
192 Old.get<U>(px) -
193 6.0*Old.get<U>(Cp)) +
194 - deltaT * Old.get<U>(Cp) * Old.get<V>(Cp) * Old.get<V>(Cp) +
195 - deltaT * F * (Old.get<U>(Cp) - 1.0);
196
197
198 // update based on Eq 2
199 New.insert<V>(Cp) = Old.get<V>(Cp) + vFactor * (
200 Old.get<V>(mz) +
201 Old.get<V>(pz) +
202 Old.get<V>(my) +
203 Old.get<V>(py) +
204 Old.get<V>(mx) +
205 Old.get<V>(px) -
206 6*Old.get<V>(Cp)) +
207 deltaT * Old.get<U>(Cp) * Old.get<V>(Cp) * Old.get<V>(Cp) +
208 - deltaT * (F+K) * Old.get<V>(Cp);
209
210 // Next point in the grid
211 ++it;
212 }
213
215
216 // Here we copy New into the old grid in preparation of the new step
217 // It would be better to alternate, but using this we can show the usage
218 // of the function copy. To note that copy work only on two grid of the same
219 // decomposition. If you want to copy also the decomposition, or force to be
220 // exactly the same, use Old = New
221 Old.copy_sparse(New);
222
223 // After copy we synchronize again the ghost part U and V
224 Old.ghost_get<U,V>();
225
226 // Every 500 time step we output the configuration for
227 // visualization
228 if (i % 500 == 0)
229 {
230 Old.save("output_" + std::to_string(count));
231 count++;
232 }
233 }
234
235 tot_sim.stop();
236 std::cout << "Total simulation: " << tot_sim.getwct() << std::endl;
237
239
252
253 openfpm_finalize();
254
256
265}
This class represent an N-dimensional box.
Definition Box.hpp:61
This is a distributed grid.
grid_key_dx is the key to access any element in the grid
Definition grid_key.hpp:19
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
OutputIteratorT OffsetT ReductionOpT OuputT init
< [in] The initial value of the reduction
[v_transform metafunction]
aggregate of properties, from a list of object if create a struct that follow the OPENFPM native stru...
Boundary conditions.
Definition common.hpp:22