1#include "Grid/grid_dist_id.hpp"
2#include "data_type/aggregate.hpp"
13constexpr int normal = 3;
14constexpr int tgrad_u = 4;
15constexpr int tgrad_v = 5;
16constexpr int U_next = 6;
17constexpr int V_next = 7;
29 auto it =
grid.getGridIterator();
32 double sx =
grid.spacing(0);
41 auto key = it.get_dist();
47 for (
int i = 0 ; i < 3 ; i++)
48 {pc.
get(i) = keyg.get(i) * it.getSpacing(i);}
51 if (sph1.isInside(pc) ==
true && sph2.isInside(pc) ==
false)
62 if (theta > 0.6 && theta < 0.8 && aphi > 0.0 && aphi < 0.2)
64 grid.template insert<U>(key) = 0.5;
65 grid.template insert<V>(key) = 0.25;
69 grid.template insert<U>(key) = 1.0;
70 grid.template insert<V>(key) = 0.0;
72 grid.template insert<phi>(key) = sph_zero.distance(pc);
73 grid.template insert<normal>(key)[0] = pn[0];
74 grid.template insert<normal>(key)[1] = pn[1];
75 grid.template insert<normal>(key)[2] = pn[2];
78 grid.template insert<U_next>(key) = 0.0;
79 grid.template insert<V_next>(key) = 0.0;
88template<
unsigned int U_src,
unsigned int V_src,
unsigned int U_dst,
unsigned int V_dst>
93 auto it =
grid.getDomainIterator();
101 auto mx = Cp.move(0,-1);
102 auto px = Cp.move(0,+1);
103 auto my = Cp.move(1,-1);
104 auto py = Cp.move(1,1);
105 auto mz = Cp.move(2,-1);
106 auto pz = Cp.move(2,1);
108 double s =
grid.get<phi>(Cp) / sqrt(fabs(
grid.get<phi>(Cp)) + delta);
113 double dir = s*
grid.get<normal>(Cp)[x];
117 Uext += dir * (
grid.get<U_src>(Cp) -
grid.get<U_src>(mx));
118 Vext += dir * (
grid.get<V_src>(Cp) -
grid.get<V_src>(mx));
122 Uext += dir * (
grid.get<U_src>(px) -
grid.get<U_src>(Cp));
123 Vext += dir * (
grid.get<V_src>(px) -
grid.get<V_src>(Cp));
127 dir = s*
grid.get<normal>(Cp)[y];
130 Uext += dir * (
grid.get<U_src>(Cp) -
grid.get<U_src>(my));
131 Vext += dir * (
grid.get<V_src>(Cp) -
grid.get<V_src>(my));
135 Uext += dir * (
grid.get<U_src>(py) -
grid.get<U_src>(Cp));
136 Vext += dir * (
grid.get<V_src>(py) -
grid.get<V_src>(Cp));
139 dir = s*
grid.get<normal>(Cp)[z];
142 Uext += dir * (
grid.get<U_src>(Cp) -
grid.get<U_src>(mz));
143 Vext += dir * (
grid.get<V_src>(Cp) -
grid.get<V_src>(mz));
147 Uext += dir * (
grid.get<U_src>(pz) -
grid.get<U_src>(Cp));
148 Vext += dir * (
grid.get<V_src>(pz) -
grid.get<V_src>(Cp));
156 grid.insert<U_dst>(Cp) =
grid.get<U_src>(Cp) - 1.0*Uext;
157 grid.insert<V_dst>(Cp) =
grid.get<V_src>(Cp) - 1.0*Vext;
163 std::cout <<
"UEX max: " << max << std::endl;
166int main(
int argc,
char* argv[])
168 openfpm_init(&argc,&argv);
174 size_t sz[3] = {512,512,512};
189 double dv = 0.5*1e-5;
193 size_t timeSteps = 200;
196 size_t timeSteps = 150000;
207 double spacing[3] = {
grid.spacing(0),
grid.spacing(1),
grid.spacing(2)};
213 grid.template ghost_get<U,V>();
217 double uFactor = deltaT * du;
218 double vFactor = deltaT * dv;
220 auto & v_cl = create_vcluster();
225 for (
size_t i = 0; i < timeSteps ; ++i)
228 auto it =
grid.getDomainIterator();
236 auto mx = Cp.move(0,-1);
237 auto px = Cp.move(0,+1);
238 auto my = Cp.move(1,-1);
239 auto py = Cp.move(1,1);
240 auto mz = Cp.move(2,-1);
241 auto pz = Cp.move(2,1);
243 grid.insert<tgrad_u>(Cp)[0] = 0.0;
244 grid.insert<tgrad_u>(Cp)[1] = 0.0;
245 grid.insert<tgrad_u>(Cp)[2] = 0.0;
246 grid.insert<tgrad_v>(Cp)[0] = 0.0;
247 grid.insert<tgrad_v>(Cp)[1] = 0.0;
248 grid.insert<tgrad_v>(Cp)[2] = 0.0;
252 if (
grid.existPoint(mz) ==
true &&
grid.existPoint(pz) ==
true &&
253 grid.existPoint(my) ==
true &&
grid.existPoint(py) ==
true &&
254 grid.existPoint(mx) ==
true &&
grid.existPoint(px) == true )
257 gradU[x] = (
grid.get<U>(Cp) -
grid.get<U>(mx)) /
grid.spacing(0);
258 gradU[y] = (
grid.get<U>(Cp) -
grid.get<U>(my)) /
grid.spacing(1);
259 gradU[z] = (
grid.get<U>(Cp) -
grid.get<U>(mz)) /
grid.spacing(2);
262 gradV[x] = (
grid.get<V>(Cp) -
grid.get<V>(mx)) /
grid.spacing(0);
263 gradV[y] = (
grid.get<V>(Cp) -
grid.get<V>(my)) /
grid.spacing(1);
264 gradV[z] = (
grid.get<V>(Cp) -
grid.get<V>(mz)) /
grid.spacing(2);
272 for (
int i = 0 ; i < 3 ; i++)
274 for (
int j = 0 ; j < 3 ; j++)
276 grid.insert<tgrad_u>(Cp)[i] += (((i == j)?1.0:0.0) -
grid.get<normal>(Cp)[i]*
grid.get<normal>(Cp)[j])*gradU[j];
277 grid.insert<tgrad_v>(Cp)[i] += (((i == j)?1.0:0.0) -
grid.get<normal>(Cp)[i]*
grid.get<normal>(Cp)[j])*gradV[j];
288 auto it =
grid.getDomainIterator();
296 auto mx = Cp.move(0,-1);
297 auto px = Cp.move(0,+1);
298 auto my = Cp.move(1,-1);
299 auto py = Cp.move(1,1);
300 auto mz = Cp.move(2,-1);
301 auto pz = Cp.move(2,1);
307 if (
grid.existPoint(mz) ==
true &&
grid.existPoint(pz) ==
true &&
308 grid.existPoint(my) ==
true &&
grid.existPoint(py) ==
true &&
309 grid.existPoint(mx) ==
true &&
grid.existPoint(px) == true )
315 lapU += (
grid.get<tgrad_u>(px)[0] -
grid.get<tgrad_u>(Cp)[0]) /
grid.spacing(0);
316 lapV += (
grid.get<tgrad_v>(px)[0] -
grid.get<tgrad_v>(Cp)[0]) /
grid.spacing(0);
317 lapU += (
grid.get<tgrad_u>(py)[1] -
grid.get<tgrad_u>(Cp)[1]) /
grid.spacing(1);
318 lapV += (
grid.get<tgrad_v>(py)[1] -
grid.get<tgrad_v>(Cp)[1]) /
grid.spacing(1);
319 lapU += (
grid.get<tgrad_u>(pz)[2] -
grid.get<tgrad_u>(Cp)[2]) /
grid.spacing(2);
320 lapV += (
grid.get<tgrad_v>(pz)[2] -
grid.get<tgrad_v>(Cp)[2]) /
grid.spacing(2);
323 grid.insert<U_next>(Cp) =
grid.get<U>(Cp) + uFactor * lapU +
324 - deltaT *
grid.get<U>(Cp) *
grid.get<V>(Cp) *
grid.get<V>(Cp) +
325 - deltaT *
F * (
grid.get<U>(Cp) - 1.0);
329 grid.insert<V_next>(Cp) =
grid.get<V>(Cp) + vFactor * lapV +
330 deltaT *
grid.get<U>(Cp) *
grid.get<V>(Cp) *
grid.get<V>(Cp) +
331 - deltaT * (
F+K) *
grid.get<V>(Cp);
345 for (
int j = 0 ; j < 2 ; j++)
348 {extend<U_next,V_next,U,V>(
grid);}
350 {extend<U,V,U_next,V_next>(
grid);}
378 grid.ghost_get<U,V>();
384 grid.save(
"output_" + std::to_string(count));
388 if (v_cl.rank() == 0)
389 {std::cout <<
"STEP: " << i <<
" " << std::endl;}
392 grid.write_frame(
"out",i);
397 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__ void zero()
Set to zero the point coordinate.
__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]