8#ifndef SRC_GRID_STAGGERED_DIST_GRID_UTIL_HPP_
9#define SRC_GRID_STAGGERED_DIST_GRID_UTIL_HPP_
11#include "util/common.hpp"
12#include "VTKWriter/VTKWriter.hpp"
13#include "util/convert.hpp"
23template<typename ele, typename vtk, bool has_attributes=has_attributes<ele>::value>
33 vtk_write(vtk vtk_w,
const std::string output,
const size_t i)
35 vtk_w.write(output +
"_" + ele::attributes::name[i] +
".vtk",ele::attributes::name[i]);
46template<
typename ele,
typename vtk>
56 vtk_write(vtk vtk_w,
const std::string output,
const size_t i)
58 vtk_w.write(output +
"_" + std::to_string(i) +
".vtk",
"attr" + std::to_string(i));
74 static inline size_t mul()
84 static inline size_t dim()
91template<
typename T,
size_t N1>
99 static inline size_t mul()
109 static inline size_t dim()
116template<
typename T,
size_t N1,
size_t N2>
124 static inline size_t mul()
134 static inline size_t dim()
141template<
typename T,
size_t N1,
size_t N2,
size_t N3>
145 static inline size_t mul()
155 static inline size_t dim()
162template<
typename T,
size_t N1,
size_t N2,
size_t N3,
size_t N4>
166 static inline size_t mul()
168 return N1 * N2 * N3 * N4;
176 static inline size_t dim()
183template<
typename T,
size_t N1,
size_t N2,
size_t N3,
size_t N4,
size_t N5>
187 static inline size_t mul()
189 return N1 * N2 * N3 * N4 * N5;
197 static inline size_t dim()
204template<
typename T,
size_t N1,
size_t N2,
size_t N3,
size_t N4,
size_t N5,
size_t N6>
208 static inline size_t mul()
210 return N1 * N2 * N3 * N4 * N5 * N6;
218 static inline size_t dim()
225template<
typename T,
size_t N1,
size_t N2,
size_t N3,
size_t N4,
size_t N5,
size_t N6,
size_t N7>
229 static inline size_t mul()
231 return N1 * N2 * N3 * N4 * N5 * N6 * N7;
239 static inline size_t dim()
246template<
typename T,
size_t N1,
size_t N2,
size_t N3,
size_t N4,
size_t N5,
size_t N6,
size_t N7,
size_t N8>
247struct extends<T[N1][N2][N3][N4][N5][N6][N7][N8]>
254 static inline size_t mul()
256 return N1 * N2 * N3 * N4 * N5 * N6 * N7 * N8;
264 static inline size_t dim()
271template<
typename T,
size_t N1,
size_t N2,
size_t N3,
size_t N4,
size_t N5,
size_t N6,
size_t N7,
size_t N8,
size_t N9>
272struct extends<T[N1][N2][N3][N4][N5][N6][N7][N8][N9]>
279 static inline size_t mul()
281 return N1 * N2 * N3 * N4 * N5 * N6 * N7 * N8 * N9;
289 static inline size_t dim()
296template<
typename T,
size_t N1,
size_t N2,
size_t N3,
size_t N4,
size_t N5,
size_t N6,
size_t N7,
size_t N8,
size_t N9,
size_t N10>
297struct extends<T[N1][N2][N3][N4][N5][N6][N7][N8][N9][N10]>
304 static inline size_t mul()
306 return N1 * N2 * N3 * N4 * N5 * N6 * N7 * N8 * N9 * N10;
314 static inline size_t dim()
344 template<
unsigned int p_val,
typename sg,
typename v_g>
static inline void write(sg & st_g, v_g & vg,
size_t lg)
348 size_t k = vg.size() - 1;
351 auto & g_src = st_g.get_loc_grid(lg);
352 auto & g_dst = vg.get(k);
355 g_dst.resize(g_src.getGrid().getSize());
359 auto it = vg.get(k).getIterator();
363 g_dst.template get<0>(it.get()) = g_src.template get<p_val>(it.get());
376template<
typename T,
size_t N1>
390 template<
unsigned int p_val,
typename sg,
typename v_g>
static inline void write(sg & st_g, v_g & vg,
size_t lg)
392 for (
size_t i = 0 ; i < N1 ; i++)
396 size_t k = vg.size() - 1;
399 auto & g_src = st_g.get_loc_grid(lg);
400 auto & g_dst = vg.get(k);
403 g_dst.resize(g_src.getGrid().getSize());
405 auto it = vg.get(k).getIterator();
409 g_dst.template get<0>(it.get()) = g_src.template get<p_val>(it.get())[i];
418template<
typename T,
size_t N1,
size_t N2>
432 template<
unsigned int p_val,
typename sg,
typename v_g>
static inline void write(sg & st_g, v_g & vg,
size_t lg)
434 for (
size_t i = 0 ; i < N1 ; i++)
436 for (
size_t j = 0 ; j < N2 ; j++)
440 size_t k = vg.size() - 1;
443 vg.get(k).resize(st_g.get_loc_grid(lg).getGrid().getSize());
446 auto & g_src = st_g.get_loc_grid(lg);
447 auto & g_dst = vg.get(k);
448 auto it = vg.get(k).getIterator();
452 g_dst.template get<0>(it.get()) = g_src.template get<p_val>(it.get())[i][j];
475template<unsigned int dim, typename v, bool has_pM = has_posMask<v>::value>
502 typedef typename boost::mpl::at<v,typename boost::mpl::int_<T::value>>::type
prop;
504 bool val = prop::stag_pos_mask[T::value];
519 pos_prp[T::value].add(c);
521 else if (dim_prp == 1)
524 for (
size_t i = 0 ; i < dim ; i++)
530 pos_prp[T::value].add(c);
533 else if (dim_prp == 2)
539 for (
size_t i = 0 ; i < dim ; i++)
541 comb<dim> c1 = pos_prp[T::value-1].get(i);
542 for (
size_t j = 0 ; j < dim ; j++)
550 pos_prp[T::value].add(c_res);
554 else if (dim_prp > 2)
556 std::cerr << __FILE__ <<
":" << __LINE__ <<
" Tensor of rank bigger than 2 are not supported";
573template<
unsigned int dim,
typename v>
603 typedef typename boost::mpl::at<v,typename boost::mpl::int_<T::value>>::type
prop;
615 pos_prp[T::value].add(c);
617 else if (dim_prp == 1)
620 for (
size_t i = 0 ; i < dim ; i++)
626 pos_prp[T::value].add(c);
629 else if (dim_prp == 2)
632 for (
size_t i = 0 ; i < dim ; i++)
634 comb<dim> c1 = pos_prp[T::value-1].get(i);
635 for (
size_t j = 0 ; j < dim ; j++)
643 pos_prp[T::value].add(c_res);
647 else if (dim_prp > 2)
649 std::cerr << __FILE__ <<
":" << __LINE__ <<
" Tensor of rank bigger than 2 are not supported";
660template<
unsigned int dim,
typename st_gr
id,
typename St>
678 :p_id(p_id),st_g(st_g)
681 template<
unsigned int p_val>
void out_normal()
684 typedef typename boost::mpl::at< typename st_grid::value_type::type , typename boost::mpl::int_<p_val> >::type
ele;
696 for (
size_t i = 0 ; i < vg.size() ; i++)
699 vg.get(i).resize(st_g.get_loc_grid(i).getGrid().getSize());
701 auto & g_src = st_g.get_loc_grid(i);
702 auto & g_dst = vg.get(i);
704 auto it = vg.get(i).getIterator();
708 object_si_d<
decltype(g_src.get_o(it.get())),
decltype(g_dst.get_o(it.get())) ,OBJ_ENCAP,p_val>(g_src.get_o(it.get()),g_dst.get_o(it.get()));
717 vtk_w.add(g_dst,offset,spacing,dom);
720 vtk_w.write(
"vtk_grids_st_" + std::to_string(p_id) +
"_" + std::to_string(p_val) +
".vtk",st_g.getPropNames(),
"grids",file_type::BINARY);
723 template<
unsigned int p_val>
void out_staggered()
726 typedef typename boost::mpl::at< typename st_grid::value_type::type , typename boost::mpl::int_<p_val> >::type
ele;
729 typedef typename std::remove_all_extents<ele>::type r_ele;
743 for (
size_t i = 0 ; i < st_g.getN_loc_grid() ; i++)
748 for ( ; k < vg.size() ; k++)
754 vtk_w.add(i,vg.get(k),offset,spacing,dom,st_g.c_prp[p_val].get(k));
767 if (st_g.is_staggered_prop(T::value) ==
false)
768 out_normal<T::value>();
770 out_staggered<T::value>();
789template<
typename Eqs_sys,
typename it1_type,
typename it2_type>
bool checkIterator(
const it1_type & it1,
const it2_type & it2)
796 for (
size_t i = 0 ; i < Eqs_sys::dims ; i++)
798 if (it1_k.
get(i) != it2_k.
get(i))
800 std::cerr << __FILE__ <<
":" << __LINE__ <<
" error src iterator and destination iterator does not match in size\n";
825template<
unsigned int dim,
unsigned int n_prop,
typename v_prp_
id,
typename v_prp_type>
838 typedef boost::mpl::size<v_prp_id> v_size;
857 :interp_pts(interp_pts),stag_pos(stag_pos){};
864 typedef typename boost::mpl::at_c<v_prp_type,T::value>::type prp_type;
865 typedef typename boost::mpl::at<v_prp_id,T>::type p_id;
867 interp_pts[T::value].resize(stag_pos[p_id::value].size());
869 for (
size_t i = 0 ; i < stag_pos[p_id::value].size() ; i++)
872 interp_pts[T::value].get(i) =
SubHyperCube<dim,dim - std::rank<prp_type>::value>::getCombinations_R(stag_pos[p_id::value].get(i),0);
875 for (
size_t j = 0 ; j < interp_pts[T::value].get(i).size() ; j++)
877 for (
size_t k = 0 ; k < dim ; k++)
878 interp_pts[T::value].get(i)[j].getComb()[k] = - ((interp_pts[T::value].get(i)[j].getComb()[k] == -1)?0:interp_pts[T::value].get(i)[j].getComb()[k]);
This class represent an N-dimensional box.
This class calculate elements of the hyper-cube.
This class implement the point shape in an N-dimensional space.
This represent a sub-hyper-cube of an hyper-cube like a face or an edge of a cube.
grid_key_dx is the key to access any element in the grid
__device__ __host__ index_type get(index_type i) const
Get the i index.
Implementation of 1-D std::vector like structure.
It create separated grid for each properties to write them into a file.
stag_create_and_add_grid(st_grid &st_g, size_t p_id)
Constructor.
void operator()(T &t)
It call the copy function for each property.
void operator()(T &t) const
stag_set_position(openfpm::vector< comb< dim > >(&pos_prp)[boost::fusion::result_of::size< v >::type::value])
vector containing the position of the properties in the cells (staggered properties are staggered)
this class is a functor for "for_each" algorithm
stag_set_position(openfpm::vector< comb< dim > >(&pos_prp)[boost::fusion::result_of::size< v >::type::value])
vector containing the position of the properties in the cells (staggered properties are staggered)
void operator()(T &t) const
aggregate of properties, from a list of object if create a struct that follow the OPENFPM native stru...
Position of the element of dimension d in the hyper-cube of dimension dim.
signed char * getComb()
get the combination array pointer
signed char value(int i) const
get the index i of the combination
void zero()
Set all the elements to zero.
static size_t mul()
number of elements
static size_t mul()
number of elements
static size_t mul()
number of elements
static size_t mul()
number of elements
static size_t mul()
number of elements
static size_t mul()
Matrix case return N1*N2 component.
static size_t mul()
Vector case return N1 component.
Classes to get the number of components of the properties.
static size_t dim()
Dimensionality.
static size_t mul()
Scalar case.
this class is a functor for "for_each" algorithm
interp_points(openfpm::vector< std::vector< comb< dim > > >(&interp_pts)[v_size::value], const openfpm::vector< comb< dim > >(&stag_pos)[n_prop])
constructor
void operator()(T &t)
It call the copy function for each property.
It copy the properties from one object to another.
This is a container to create a general object.
vtk_write(vtk vtk_w, const std::string output, const size_t i)
Add the grid with attributes name.
write a property that has attributes
vtk_write(vtk vtk_w, const std::string output, const size_t i)
Add the grid with attributes name.
static void write(sg &st_g, v_g &vg, size_t lg)
write the staggered grid
static void write(sg &st_g, v_g &vg, size_t lg)
write the staggered grid
Classes to copy each component into a grid and add to the VTKWriter the grid.
static void write(sg &st_g, v_g &vg, size_t lg)
write the staggered grid