1 #include "Grid/grid_dist_id.hpp" 2 #include "data_type/aggregate.hpp" 76 constexpr
int U_next = 2;
77 constexpr
int V_next = 3;
85 auto it =
grid.getGridIterator();
90 auto key = it.get_dist();
93 grid.template insert<U>(key) = 1.0;
94 grid.template insert<V>(key) = 0.0;
97 grid.template insert<U_next>(key) = 0.0;
98 grid.template insert<V_next>(key) = 0.0;
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);
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);
113 auto it_init =
grid.getGridIterator(start,stop);
115 while (it_init.isNext())
117 auto key = it_init.get_dist();
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;
127 int main(
int argc,
char* argv[])
129 openfpm_init(&argc,&argv);
135 size_t sz[3] = {256,256,256};
144 double deltaT = 0.25;
154 size_t timeSteps = 200;
156 size_t timeSteps = 5000;
170 double spacing[3] = {
grid.spacing(0),
grid.spacing(1),
grid.spacing(2)};
176 grid.template ghost_get<U,V>();
180 double uFactor = deltaT * du/(spacing[x]*spacing[x]);
181 double vFactor = deltaT * dv/(spacing[x]*spacing[x]);
186 auto & v_cl = create_vcluster();
188 for (
size_t i = 0; i < timeSteps ; ++i)
190 if (v_cl.rank() == 0)
191 {std::cout <<
"STEP: " << i << std::endl;}
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){
206 u_out = u + uFactor *(uc.xm + uc.xp +
208 uc.zm + uc.zp - 6.0*u) - deltaT * u*v*v
209 - deltaT *
F * (u - 1.0);
211 v_out = v + vFactor *(vc.xm + vc.xp +
213 vc.zm + vc.zp - 6.0*v) + deltaT * u*v*v
214 - deltaT * (
F+K) * v;
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);
228 std::cout << ts.
getwct() << std::endl;
231 grid.ghost_get<U_next,V_next>();
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);
238 grid.ghost_get<U,V>();
253 std::cout <<
"Total simulation: " << tot_sim.
getwct() << std::endl;
grid_key_dx is the key to access any element in the grid
double getwct()
Return the elapsed real time.
This is a distributed grid.
KeyT const ValueT ValueT OffsetIteratorT OffsetIteratorT int
[in] The number of segments that comprise the sorting data
void start()
Start the timer.
This class represent an N-dimensional box.
aggregate of properties, from a list of object if create a struct that follow the OPENFPM native stru...
OutputIteratorT OffsetT ReductionOpT OuputT init
< [in] The initial value of the reduction
__device__ __host__ T getHigh(int i) const
get the high interval of the box
Class for cpu time benchmarking.
void stop()
Stop the timer.
[v_transform metafunction]