1#include "Grid/grid_dist_id.hpp"
2#include "data_type/aggregate.hpp"
12constexpr int normal = 3;
13constexpr int tgrad_u = 4;
14constexpr int tgrad_v = 5;
15constexpr int U_next = 6;
16constexpr int V_next = 7;
28 auto it =
grid.getGridIterator();
31 double sx =
grid.spacing(0);
40 auto key = it.get_dist();
46 for (
int i = 0 ; i < 3 ; i++)
47 {pc.
get(i) = keyg.get(i) * it.getSpacing(i);}
50 if (sph1.isInside(pc) ==
true && sph2.isInside(pc) ==
false)
61 if (theta > 0.6 && theta < 0.8 && aphi > 0.0 && aphi < 0.2)
63 grid.template insert<U>(key) = 0.5;
64 grid.template insert<V>(key) = 0.25;
68 grid.template insert<U>(key) = 1.0;
69 grid.template insert<V>(key) = 0.0;
71 grid.template insert<phi>(key) = sph_zero.distance(pc);
72 grid.template insert<normal>(key)[0] = pn[0];
73 grid.template insert<normal>(key)[1] = pn[1];
74 grid.template insert<normal>(key)[2] = pn[2];
77 grid.template insert<U_next>(key) = 0.0;
78 grid.template insert<V_next>(key) = 0.0;
87template<
unsigned int U_src,
unsigned int V_src,
unsigned int U_dst,
unsigned int V_dst>
88void extend(
sgrid_type &
grid,
size_t (& sz)[3],
double (& spacing)[3])
93 auto func_extend = [delta,&spacing](
auto &
grid,
auto & ids,
94 unsigned char * mask_sum)
99 Vc::double_v Uext = 0.0;
100 Vc::double_v Vext = 0.0;
121 load_crs<x,0,phi>(phi_c,
grid,ids);
122 load_crs_v<x,0,x,normal>(n[x],
grid,ids);
123 load_crs_v<x,0,y,normal>(n[y],
grid,ids);
124 load_crs_v<x,0,z,normal>(n[z],
grid,ids);
126 load_crs<x,0,U_src>(Uc,
grid,ids);
127 load_crs<x,0,V_src>(Vc,
grid,ids);
128 load_crs<x,-1,U_src>(Uc_xm,
grid,ids);
129 load_crs<x,-1,V_src>(Vc_xm,
grid,ids);
130 load_crs<y,-1,U_src>(Uc_ym,
grid,ids);
131 load_crs<y,-1,V_src>(Vc_ym,
grid,ids);
132 load_crs<z,-1,U_src>(Uc_zm,
grid,ids);
133 load_crs<z,-1,V_src>(Vc_zm,
grid,ids);
134 load_crs<x,1,U_src>(Uc_xp,
grid,ids);
135 load_crs<x,1,V_src>(Vc_xp,
grid,ids);
136 load_crs<y,1,U_src>(Uc_yp,
grid,ids);
137 load_crs<y,1,V_src>(Vc_yp,
grid,ids);
138 load_crs<z,1,U_src>(Uc_zp,
grid,ids);
139 load_crs<z,1,V_src>(Vc_zp,
grid,ids);
141 s = phi_c / sqrt(phi_c*phi_c + delta*delta);
144 auto dir_pos = dir > 0;
145 auto dir_neg = dir < 0;
147 Uext += Vc::iif(dir_pos,dir * (Uc - Uc_xm)/spacing[0],Vc::double_v(0.0));
148 Vext += Vc::iif(dir_pos,dir * (Vc - Vc_xm)/spacing[0],Vc::double_v(0.0));
149 Uext += Vc::iif(dir_neg,dir * (Uc_xp - Uc)/spacing[0],Vc::double_v(0.0));
150 Vext += Vc::iif(dir_neg,dir * (Vc_xp - Vc)/spacing[0],Vc::double_v(0.0));
156 Uext += Vc::iif(dir_pos,dir * (Uc - Uc_ym)/spacing[1],Vc::double_v(0.0));
157 Vext += Vc::iif(dir_pos,dir * (Vc - Vc_ym)/spacing[1],Vc::double_v(0.0));
158 Uext += Vc::iif(dir_neg,dir * (Uc_yp - Uc)/spacing[1],Vc::double_v(0.0));
159 Vext += Vc::iif(dir_neg,dir * (Vc_yp - Vc)/spacing[1],Vc::double_v(0.0));
165 Uext += Vc::iif(dir_pos,dir * (Uc - Uc_zm)/spacing[2],Vc::double_v(0.0));
166 Vext += Vc::iif(dir_pos,dir * (Vc - Vc_zm)/spacing[2],Vc::double_v(0.0));
167 Uext += Vc::iif(dir_neg,dir * (Uc_zp - Uc)/spacing[2],Vc::double_v(0.0));
168 Vext += Vc::iif(dir_neg,dir * (Vc_zp - Vc)/spacing[2],Vc::double_v(0.0));
170 Uext = Uc - 0.0003*Uext;
171 Vext = Vc - 0.0003*Vext;
173 store_crs<U_dst>(
grid,Uext,ids);
174 store_crs<V_dst>(
grid,Vext,ids);
177 grid.template conv_cross_ids<1,double>({0,0,0},{sz[0] - 1, sz[1] - 1, sz[2] - 1},func_extend);
180int main(
int argc,
char* argv[])
182 openfpm_init(&argc,&argv);
188 size_t sz[3] = {512,512,512};
203 double dv = 0.5*1e-5;
207 size_t timeSteps = 200;
210 size_t timeSteps = 100000;
221 double spacing[3] = {
grid.spacing(0),
grid.spacing(1),
grid.spacing(2)};
227 grid.template ghost_get<U,V>();
231 double uFactor = deltaT * du;
232 double vFactor = deltaT * dv;
234 auto & v_cl = create_vcluster();
239 for (
size_t i = 0; i < timeSteps ; ++i)
241 auto func_grad = [&spacing](
auto &
grid,
auto & ids,
242 unsigned char * mask_sum){
256 Vc::double_v u_out[3];
257 Vc::double_v v_out[3];
259 load_crs<x,-1,U>(xmU,
grid,ids);
260 load_crs<y,-1,U>(ymU,
grid,ids);
261 load_crs<z,-1,U>(zmU,
grid,ids);
262 load_crs<x,0,U>(Uc,
grid,ids);
264 load_crs<x,-1,V>(xmV,
grid,ids);
265 load_crs<y,-1,V>(ymV,
grid,ids);
266 load_crs<z,-1,V>(zmV,
grid,ids);
267 load_crs<x,0,V>(Vc,
grid,ids);
269 load_crs_v<x,0,x,normal>(n[x],
grid,ids);
270 load_crs_v<x,0,y,normal>(n[y],
grid,ids);
271 load_crs_v<x,0,z,normal>(n[z],
grid,ids);
273 u_out[0] = (1.0-n[0]*n[0])*(Uc - xmU)/spacing[0] + (-n[1]*n[1])*(Uc - ymU)/spacing[1] + (-n[2]*n[2])*(Uc - zmU)/spacing[2];
274 u_out[1] = (-n[0]*n[0])*(Uc - xmU)/spacing[0] + (1.0-n[1]*n[1])*(Uc - ymU)/spacing[1] + (-n[2]*n[2])*(Uc - zmU)/spacing[2];
275 u_out[2] = (-n[0]*n[0])*(Uc - xmU)/spacing[0] + (-n[1]*n[1])*(Uc - ymU)/spacing[1] + (1.0-n[2]*n[2])*(Uc - zmU)/spacing[2];
277 v_out[0] = (1.0-n[0]*n[0])*(Vc - xmV)/spacing[0] + (-n[1]*n[1])*(Vc - ymV)/spacing[1] + (-n[2]*n[2])*(Vc - zmV)/spacing[2];
278 v_out[1] = (-n[0]*n[0])*(Vc - xmV)/spacing[0] + (1.0-n[1]*n[1])*(Vc - ymV)/spacing[1] + (-n[2]*n[2])*(Vc - zmV)/spacing[2];
279 v_out[2] = (-n[0]*n[0])*(Vc - xmV)/spacing[0] + (-n[1]*n[1])*(Vc - ymV)/spacing[1] + (1.0-n[2]*n[2])*(Vc - zmV)/spacing[2];
281 Vc::Mask<double> surround;
283 for (
int i = 0 ; i < Vc::double_v::Size ; i++)
284 {surround[i] = (mask_sum[i] == 6);}
286 u_out[0] = Vc::iif(surround,u_out[0],Vc::double_v(0.0));
287 u_out[1] = Vc::iif(surround,u_out[1],Vc::double_v(0.0));
288 u_out[2] = Vc::iif(surround,u_out[2],Vc::double_v(0.0));
290 v_out[0] = Vc::iif(surround,v_out[0],Vc::double_v(0.0));
291 v_out[1] = Vc::iif(surround,v_out[1],Vc::double_v(0.0));
292 v_out[2] = Vc::iif(surround,v_out[2],Vc::double_v(0.0));
294 store_crs_v<tgrad_u,x>(
grid,u_out[0],ids);
295 store_crs_v<tgrad_u,y>(
grid,u_out[1],ids);
296 store_crs_v<tgrad_u,z>(
grid,u_out[2],ids);
298 store_crs_v<tgrad_v,x>(
grid,v_out[0],ids);
299 store_crs_v<tgrad_v,y>(
grid,v_out[1],ids);
300 store_crs_v<tgrad_v,z>(
grid,v_out[2],ids);
303 grid.template conv_cross_ids<1,double>({0,0,0},{sz[0]-1,sz[1] - 1,sz[2] - 1},func_grad);
305 auto func_lap = [&spacing,uFactor,vFactor,deltaT,K,
F](
auto &
grid,
auto & ids,
306 unsigned char * mask_sum){
308 Vc::double_v gradU_px;
309 Vc::double_v gradU_py;
310 Vc::double_v gradU_pz;
312 Vc::double_v gradU_x;
313 Vc::double_v gradU_y;
314 Vc::double_v gradU_z;
316 Vc::double_v gradV_px;
317 Vc::double_v gradV_py;
318 Vc::double_v gradV_pz;
320 Vc::double_v gradV_x;
321 Vc::double_v gradV_y;
322 Vc::double_v gradV_z;
333 load_crs_v<x,1,x,tgrad_u>(gradU_px,
grid,ids);
334 load_crs_v<y,1,y,tgrad_u>(gradU_py,
grid,ids);
335 load_crs_v<z,1,z,tgrad_u>(gradU_pz,
grid,ids);
337 load_crs_v<x,0,x,tgrad_u>(gradU_x,
grid,ids);
338 load_crs_v<x,0,y,tgrad_u>(gradU_y,
grid,ids);
339 load_crs_v<x,0,z,tgrad_u>(gradU_z,
grid,ids);
341 load_crs_v<x,1,x,tgrad_v>(gradV_px,
grid,ids);
342 load_crs_v<y,1,y,tgrad_v>(gradV_py,
grid,ids);
343 load_crs_v<z,1,z,tgrad_v>(gradV_pz,
grid,ids);
345 load_crs_v<x,0,x,tgrad_v>(gradV_x,
grid,ids);
346 load_crs_v<x,0,y,tgrad_v>(gradV_y,
grid,ids);
347 load_crs_v<x,0,z,tgrad_v>(gradV_z,
grid,ids);
349 load_crs<x,0,U>(Uc,
grid,ids);
350 load_crs<x,0,V>(Vc,
grid,ids);
352 lapU += (gradU_px - gradU_x) / spacing[0];
353 lapV += (gradV_px - gradV_x) / spacing[0];
354 lapU += (gradU_py - gradU_y) / spacing[1];
355 lapV += (gradV_py - gradV_y) / spacing[1];
356 lapU += (gradU_pz - gradU_z) / spacing[2];
357 lapV += (gradV_pz - gradV_z) / spacing[2];
360 outU = Uc + uFactor * lapU +
361 - deltaT * Uc * Vc * Vc +
362 - deltaT *
F * (Uc - 1.0);
366 outV = Vc + vFactor * lapV +
367 deltaT * Uc * Vc * Vc +
368 - deltaT * (
F+K) * Vc;
370 Vc::Mask<double> surround;
372 for (
int i = 0 ; i < Vc::double_v::Size ; i++)
373 {surround[i] = (mask_sum[i] == 6);}
376 outU = Vc::iif(surround,outU,Uc);
377 outV = Vc::iif(surround,outV,Vc);
379 store_crs<U_next>(
grid,outU,ids);
380 store_crs<V_next>(
grid,outV,ids);
383 grid.template conv_cross_ids<1,double>({0,0,0},{sz[0]-1,sz[1] - 1,sz[2] - 1},func_lap);
391 for (
int j = 0 ; j < 2 ; j++)
394 {extend<U_next,V_next,U,V>(
grid,sz,spacing);}
396 {extend<U,V,U_next,V_next>(
grid,sz,spacing);}
424 grid.ghost_get<U,V>();
434 if (v_cl.rank() == 0)
435 {std::cout <<
"STEP: " << i <<
" " << std::endl;}
438 grid.write_frame(
"out",i);
443 std::cout <<
"Total simulation: " << tot_sim.
getwct() << std::endl;
This class represent an N-dimensional box.
This class implement the point shape in an N-dimensional space.
__device__ __host__ const T & get(unsigned int i) const
Get coordinate.
__device__ __host__ T norm() const
norm of the vector
This class implement the Sphere concept in an N-dimensional space.
This is a distributed grid.
Class for cpu time benchmarking.
void stop()
Stop the timer.
void start()
Start the timer.
double getwct()
Return the elapsed real time.
OutputIteratorT OffsetT ReductionOpT OuputT init
< [in] The initial value of the reduction
[v_transform metafunction]