1 #include "Grid/grid_dist_id.hpp" 2 #include "data_type/aggregate.hpp" 88 for (
int i = 0 ; i < 3 ; i++)
92 for (
int i = 0 ; i < 3 ; i++)
96 for (
int i = 0 ; i < 3 ; i++)
109 auto key = it.get_dist();
110 auto keyg = it.get();
115 for (
int i = 0 ; i < 3 ; i++)
116 {pc.
get(i) = keyg.get(i) * it.getSpacing(i);}
119 vp.
get(0) = pc.
get(1)*u.get(2) - pc.
get(2)*u.get(1);
120 vp.
get(1) = pc.
get(2)*u.get(0) - pc.
get(0)*u.get(2);
121 vp.
get(2) = pc.
get(0)*u.get(1) - pc.
get(1)*u.get(0);
123 double distance = vp.
norm() / sqrt(3);
126 if (sph1.isInside(pc) || sph2.isInside(pc) || sph3.isInside(pc) || (distance < 0.1 && channel_box.isInside(pc)) )
129 Old.template insert<U>(key) = 1.0;
130 Old.template insert<V>(key) = 0.0;
133 New.template insert<U>(key) = 0.0;
134 New.template insert<V>(key) = 0.0;
144 long int x_start = Old.
size(0)*1.95f/domain.
getHigh(0);
145 long int y_start = Old.
size(1)*1.95f/domain.
getHigh(1);
146 long int z_start = Old.
size(1)*1.95f/domain.
getHigh(2);
148 long int x_stop = Old.
size(0)*2.05f/domain.
getHigh(0);
149 long int y_stop = Old.
size(1)*2.05f/domain.
getHigh(1);
150 long int z_stop = Old.
size(1)*2.05f/domain.
getHigh(2);
156 while (it_init.isNext())
158 auto key = it_init.get_dist();
160 Old.template insert<U>(key) = 0.5 + (((double)std::rand())/RAND_MAX -0.5)/10.0;
161 Old.template insert<V>(key) = 0.25 + (((double)std::rand())/RAND_MAX -0.5)/20.0;
170 int main(
int argc,
char* argv[])
172 openfpm_init(&argc,&argv);
178 size_t sz[3] = {256,256,256};
197 size_t timeSteps = 200;
200 size_t timeSteps = 150000;
216 init(Old,New,domain);
220 Old.template ghost_get<U,V>();
224 double uFactor = deltaT * du/(spacing[x]*spacing[x]);
225 double vFactor = deltaT * dv/(spacing[x]*spacing[x]);
227 auto & v_cl = create_vcluster();
229 Old.
write(
"Init_condition");
234 for (
size_t i = 0; i < timeSteps; ++i)
244 auto mx = Cp.move(0,-1);
245 auto px = Cp.move(0,+1);
246 auto my = Cp.move(1,-1);
247 auto py = Cp.move(1,1);
248 auto mz = Cp.move(2,-1);
249 auto pz = Cp.move(2,1);
260 LapU += Old.
get<U>(mz);
261 LapV += Old.
get<V>(mz);
265 LapU += Old.
get<U>(pz);
266 LapV += Old.
get<V>(pz);
270 LapU += Old.
get<U>(Cp);
271 LapV += Old.
get<V>(Cp);
276 LapU += Old.
get<U>(pz);
277 LapV += Old.
get<V>(pz);
281 LapU+= Old.
get<U>(mz);
282 LapV += Old.
get<V>(mz);
286 LapU+= Old.
get<U>(Cp);
287 LapV += Old.
get<V>(Cp);
295 LapU += Old.
get<U>(my);
296 LapV += Old.
get<V>(my);
300 LapU += Old.
get<U>(py);
301 LapV += Old.
get<V>(py);
305 LapU+= Old.
get<U>(Cp);
306 LapV += Old.
get<V>(Cp);
311 LapU += Old.
get<U>(py);
312 LapV += Old.
get<V>(py);
316 LapU+= Old.
get<U>(my);
317 LapV += Old.
get<V>(my);
321 LapU+= Old.
get<U>(Cp);
322 LapV += Old.
get<V>(Cp);
329 LapU += Old.
get<U>(mx);
330 LapV += Old.
get<V>(mx);
334 LapU += Old.
get<U>(px);
335 LapV += Old.
get<V>(px);
339 LapU+= Old.
get<U>(Cp);
340 LapV += Old.
get<V>(Cp);
345 LapU += Old.
get<U>(px);
346 LapV += Old.
get<V>(px);
350 LapU+= Old.
get<U>(mx);
351 LapV += Old.
get<V>(mx);
355 LapU+= Old.
get<U>(Cp);
356 LapV += Old.
get<V>(Cp);
359 LapU -= 6.0*Old.
get<U>(Cp);
360 LapV -= 6.0*Old.
get<V>(Cp);
365 New.
insert<U>(Cp) = Old.
get<U>(Cp) + uFactor * LapU +
366 - deltaT * Old.
get<U>(Cp) * Old.
get<V>(Cp) * Old.
get<V>(Cp) +
367 - deltaT *
F * (Old.
get<U>(Cp) - 1.0);
371 New.
insert<V>(Cp) = Old.
get<V>(Cp) + vFactor * LapV +
372 deltaT * Old.
get<U>(Cp) * Old.
get<V>(Cp) * Old.
get<V>(Cp) +
373 - deltaT * (
F+K) * Old.
get<V>(Cp);
395 Old.
save(
"output_" + std::to_string(count));
399 if (v_cl.rank() == 0)
400 {std::cout <<
"STEP: " << i <<
" " << std::endl;}
408 std::cout <<
"Total simulation: " << tot_sim.
getwct() << std::endl;
bool write(std::string output, size_t opt=VTK_WRITER|FORMAT_BINARY)
Write the distributed grid information.
bool write_frame(std::string output, size_t i, size_t opt=VTK_WRITER|FORMAT_ASCII)
Write the distributed grid information.
grid_key_dx is the key to access any element in the grid
size_t size() const
Return the total number of points in the grid.
auto get(const grid_dist_key_dx< dim, bg_key > &v1) const -> typename std::add_lvalue_reference< decltype(loc_grid.get(v1.getSub()).template get< p >(v1.getKey()))>::type
Get the reference of the selected element.
This class implement the point shape in an N-dimensional space.
auto insert(const grid_dist_key_dx< dim, bg_key > &v1) -> decltype(loc_grid.get(v1.getSub()).template insert< p >(v1.getKey()))
insert an element in the grid
St spacing(size_t i) const
Get the spacing of the grid in direction i.
double getwct()
Return the elapsed real time.
__device__ __host__ T norm()
norm of the vector
void save(const std::string &filename) const
Save the grid state on HDF5.
This is a distributed grid.
bool existPoint(const grid_dist_key_dx< dim, bg_key > &v1) const
Check if the point exist.
__device__ __host__ const T & get(unsigned int i) const
Get coordinate.
grid_dist_id_iterator_dec< Decomposition > getGridIterator(const grid_key_dx< dim > &start, const grid_key_dx< dim > &stop)
void start()
Start the timer.
grid_dist_iterator< dim, device_grid, decltype(device_grid::type_of_subiterator()), FREE > getDomainIterator() const
It return an iterator that span the full grid domain (each processor span its local domain)
grid_dist_id< dim, St, T, Decomposition, Memory, device_grid > & copy_sparse(grid_dist_id< dim, St, T, Decomposition, Memory, device_grid > &g, bool use_memcpy=true)
Copy the give grid into this grid.
This class represent an N-dimensional box.
This class implement the Sphere concept in an N-dimensional space.
void ghost_get(size_t opt=0)
It synchronize the ghost parts.
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
Decomposition & getDecomposition()
Get the object that store the information about the decomposition.
Class for cpu time benchmarking.
void stop()
Stop the timer.
[v_transform metafunction]