OpenFPM_pdata  4.1.0
Project that contain the implementation of distributed structures
 
Loading...
Searching...
No Matches
main.cpp
1#include "Grid/grid_dist_id.hpp"
2#include "data_type/aggregate.hpp"
3#include "timer.hpp"
4
73constexpr int U = 0;
74constexpr int V = 1;
75
76constexpr int U_next = 2;
77constexpr int V_next = 3;
78
79constexpr int x = 0;
80constexpr int y = 1;
81constexpr int z = 2;
82
84{
85 auto it = grid.getGridIterator();
86
87 while (it.isNext())
88 {
89 // Get the local grid key
90 auto key = it.get_dist();
91
92 // Old values U and V
93 grid.template insert<U>(key) = 1.0;
94 grid.template insert<V>(key) = 0.0;
95
96 // Old values U and V
97 grid.template insert<U_next>(key) = 0.0;
98 grid.template insert<V_next>(key) = 0.0;
99
100 ++it;
101 }
102
103 long int x_start = grid.size(0)*1.55f/domain.getHigh(0);
104 long int y_start = grid.size(1)*1.55f/domain.getHigh(1);
105 long int z_start = grid.size(1)*1.55f/domain.getHigh(2);
106
107 long int x_stop = grid.size(0)*1.85f/domain.getHigh(0);
108 long int y_stop = grid.size(1)*1.85f/domain.getHigh(1);
109 long int z_stop = grid.size(1)*1.85f/domain.getHigh(2);
110
111 grid_key_dx<3> start({x_start,y_start,z_start});
112 grid_key_dx<3> stop ({x_stop,y_stop,z_stop});
113 auto it_init = grid.getGridIterator(start,stop);
114
115 while (it_init.isNext())
116 {
117 auto key = it_init.get_dist();
118
119 grid.template insert<U>(key) = 0.5 + (((double)std::rand())/RAND_MAX -0.5)/10.0;
120 grid.template insert<V>(key) = 0.25 + (((double)std::rand())/RAND_MAX -0.5)/20.0;
121
122 ++it_init;
123 }
124}
125
126
127int main(int argc, char* argv[])
128{
129 openfpm_init(&argc,&argv);
130
131 // domain
132 Box<3,double> domain({0.0,0.0,0.0},{2.5,2.5,2.5});
133
134 // grid size
135 size_t sz[3] = {256,256,256};
136
137 // Define periodicity of the grid
138 periodicity<3> bc = {PERIODIC,PERIODIC,PERIODIC};
139
140 // Ghost in grid unit
142
143 // deltaT
144 double deltaT = 0.25;
145
146 // Diffusion constant for specie U
147 double du = 2*1e-5;
148
149 // Diffusion constant for specie V
150 double dv = 1*1e-5;
151
152 // Number of timesteps
153#ifdef TEST_RUN
154 size_t timeSteps = 200;
155#else
156 size_t timeSteps = 5000;
157#endif
158
159 // K and F (Physical constant in the equation)
160 double K = 0.053;
161 double F = 0.014;
162
164
166
168
169 // spacing of the grid on x and y
170 double spacing[3] = {grid.spacing(0),grid.spacing(1),grid.spacing(2)};
171
172 init(grid,domain);
173
174 // sync the ghost
175 size_t count = 0;
176 grid.template ghost_get<U,V>();
177
178 // because we assume that spacing[x] == spacing[y] we use formula 2
179 // and we calculate the prefactor of Eq 2
180 double uFactor = deltaT * du/(spacing[x]*spacing[x]);
181 double vFactor = deltaT * dv/(spacing[x]*spacing[x]);
182
183 timer tot_sim;
184 tot_sim.start();
185
186 auto & v_cl = create_vcluster();
187
188 for (size_t i = 0; i < timeSteps ; ++i)
189 {
190 if (v_cl.rank() == 0)
191 {std::cout << "STEP: " << i << std::endl;}
192/* if (i % 300 == 0)
193 {
194 std::cout << "STEP: " << i << std::endl;
195 grid.write_frame("out",i,VTK_WRITER);
196 }*/
197
199
200
201 auto func = [uFactor,vFactor,deltaT,F,K](Vc::double_v & u_out,Vc::double_v & v_out,
202 Vc::double_v & u,Vc::double_v & v,
204 unsigned char * mask){
205
206 u_out = u + uFactor *(uc.xm + uc.xp +
207 uc.ym + uc.yp +
208 uc.zm + uc.zp - 6.0*u) - deltaT * u*v*v
209 - deltaT * F * (u - 1.0);
210
211 v_out = v + vFactor *(vc.xm + vc.xp +
212 vc.ym + vc.yp +
213 vc.zm + vc.zp - 6.0*v) + deltaT * u*v*v
214 - deltaT * (F+K) * v;
215 };
216
218
220
221 if (i % 2 == 0)
222 {
223
224 timer ts;
225 ts.start();
226 grid.conv_cross2<U,V,U_next,V_next,1>({0,0,0},{(long int)sz[0]-1,(long int)sz[1]-1,(long int)sz[2]-1},func);
227 ts.stop();
228 std::cout << ts.getwct() << std::endl;
229
230 // After copy we synchronize again the ghost part U and V
231 grid.ghost_get<U_next,V_next>();
232 }
233 else
234 {
235 grid.conv_cross2<U_next,V_next,U,V,1>({0,0,0},{(long int)sz[0]-1,(long int)sz[1]-1,(long int)sz[2]-1},func);
236
237 // After copy we synchronize again the ghost part U and V
238 grid.ghost_get<U,V>();
239 }
240
242
243 // Every 500 time step we output the configuration for
244 // visualization
245// if (i % 500 == 0)
246// {
247// grid.save("output_" + std::to_string(count));
248// count++;
249// }
250 }
251
252 tot_sim.stop();
253 std::cout << "Total simulation: " << tot_sim.getwct() << std::endl;
254
255 grid.write("final");
256
258
271
272 openfpm_finalize();
273
275
284}
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
KeyT const ValueT ValueT OffsetIteratorT OffsetIteratorT int
[in] The number of segments that comprise the sorting data
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