1#include "Grid/grid_dist_id.hpp"
2#include "data_type/aggregate.hpp"
39constexpr int U_next = 2;
40constexpr int V_next = 3;
42typedef sgrid_dist_id_gpu<3,double,aggregate<double,double,double,double> >
sgrid_type;
46 auto it =
grid.getGridIterator();
52 for (
int i = 0 ; i < 3 ; i++)
56 for (
int i = 0 ; i < 3 ; i++)
60 for (
int i = 0 ; i < 3 ; i++)
70 double spacing_x =
grid.spacing(0);
71 double spacing_y =
grid.spacing(1);
72 double spacing_z =
grid.spacing(2);
76 grid.addPoints([spacing_x,spacing_y,spacing_z,u,sph1,sph2,sph3,channel_box] __device__ (
int i,
int j,
int k)
82 vp.
get(0) = pc.get(1)*u.get(2) - pc.get(2)*u.get(1);
83 vp.
get(1) = pc.get(2)*u.get(0) - pc.get(0)*u.get(2);
84 vp.
get(2) = pc.get(0)*u.get(1) - pc.get(1)*u.get(0);
86 double distance = vp.
norm() / sqrt(3.0f);
89 if (sph1.isInside(pc) || sph2.isInside(pc) || sph3.isInside(pc) || (distance < 0.1 && channel_box.isInside(pc)) )
94 [] __device__ (InsertBlockT & data,
int i,
int j,
int k)
96 data.template get<U>() = 1.0;
97 data.template get<V>() = 0.0;
102 grid.template flush<smax_<U>,
smax_<V>>(flush_type::FLUSH_ON_DEVICE);
104 long int x_start =
grid.size(0)*1.95f/domain.getHigh(0);
105 long int y_start =
grid.size(1)*1.95f/domain.getHigh(1);
106 long int z_start =
grid.size(1)*1.95f/domain.getHigh(2);
108 long int x_stop =
grid.size(0)*2.05f/domain.getHigh(0);
109 long int y_stop =
grid.size(1)*2.05f/domain.getHigh(1);
110 long int z_stop =
grid.size(1)*2.05f/domain.getHigh(2);
115 grid.addPoints(start,stop,[] __device__ (
int i,
int j,
int k)
119 [] __device__ (InsertBlockT & data,
int i,
int j,
int k)
121 data.template get<U>() = 0.5;
122 data.template get<V>() = 0.24;
126 grid.template flush<smin_<U>,
smax_<V>>(flush_type::FLUSH_ON_DEVICE);
130int main(
int argc,
char* argv[])
132 openfpm_init(&argc,&argv);
138 size_t sz[3] = {256,256,256};
157 size_t timeSteps = 300;
160 size_t timeSteps = 150000;
169 grid.template setBackgroundValue<0>(-0.5);
170 grid.template setBackgroundValue<1>(-0.5);
171 grid.template setBackgroundValue<2>(-0.5);
172 grid.template setBackgroundValue<3>(-0.5);
175 double spacing[3] = {
grid.spacing(0),
grid.spacing(1),
grid.spacing(2)};
180 grid.template ghost_get<U,V>(RUN_ON_DEVICE);
184 double uFactor = deltaT * du/(spacing[0]*spacing[0]);
185 double vFactor = deltaT * dv/(spacing[0]*spacing[0]);
187 grid.template deviceToHost<U,V>();
188 grid.write(
"Init_condition");
193 for (
size_t i = 0; i < timeSteps; ++i)
199 auto func = [uFactor,vFactor,deltaT,
F,K] __device__ (
double & u_out,
double & v_out,
200 CpBlockType & u, CpBlockType & v,
201 int i,
int j,
int k){
203 double uc = u(i,j,k);
204 double vc = v(i,j,k);
206 double u_px = u(i+1,j,k);
207 double u_mx = u(i-1,j,k);
209 double u_py = u(i,j+1,k);
210 double u_my = u(i,j-1,k);
212 double u_pz = u(i,j,k+1);
213 double u_mz = u(i,j,k-1);
215 double v_px = v(i+1,j,k);
216 double v_mx = v(i-1,j,k);
218 double v_py = v(i,j+1,k);
219 double v_my = v(i,j-1,k);
221 double v_pz = v(i,j,k+1);
222 double v_mz = v(i,j,k-1);
226 if (u_mx < -0.1 && u_px < -0.1)
238 if (u_my < -0.1 && u_py < -0.1)
250 if (u_mz < -0.1 && u_pz < -0.1)
264 if (v_mx < -0.1 && v_px < -0.1)
276 if (v_my < -0.1 && v_py < -0.1)
288 if (v_mz < -0.1 && v_pz < -0.1)
300 u_out = uc + uFactor *(u_mx + u_px +
302 u_mz + u_pz - 6.0*uc) - deltaT * uc*vc*vc
303 - deltaT *
F * (uc - 1.0);
306 v_out = vc + vFactor *(v_mx + v_px +
308 v_mz + v_pz - 6.0*vc) + deltaT * uc*vc*vc
309 - deltaT * (
F+K) * vc;
316 grid.conv2<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);
320 grid.ghost_get<U_next,V_next>(RUN_ON_DEVICE | SKIP_LABELLING);
324 grid.conv2<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);
327 grid.ghost_get<U,V>(RUN_ON_DEVICE | SKIP_LABELLING);
342 std::cout <<
"STEP: " << i << std::endl;
351 std::cout <<
"Total simulation: " << tot_sim.
getwct() << std::endl;
353 grid.template deviceToHost<U,V>();
387int main(
int argc,
char* argv[])
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.
grid_key_dx is the key to access any element in the grid
Class for cpu time benchmarking.
void stop()
Stop the timer.
void start()
Start the timer.
double getwct()
Return the elapsed real time.
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]
get the type of the block