OpenFPM_pdata  4.1.0
Project that contain the implementation of distributed structures
debug.hpp
1 /*
2  * debug.hpp
3  *
4  * Created on: Mar 12, 2020
5  * Author: i-bird
6  */
7 
8 #ifndef DEBUG_HPP_
9 #define DEBUG_HPP_
10 
11 #include "VTKWriter/VTKWriter.hpp"
12 
13 template<typename T>
14 void load_sizes(T * sizes, int d, int sza)
15 {
16  sizes[d] = sza;
17 
18  return;
19 }
20 
21 template<typename T, typename szAType, typename ... szType>
22 void load_sizes(T * sizes, int d , szAType sza, szType ... sz)
23 {
24  sizes[d] = sza;
25 
26  load_sizes(sizes,d+1,sz ...);
27 }
28 
29 template<typename T, typename ... szType>
30 void print_array(std::string file,T * arr, szType ... sz)
31 {
32  size_t sizes[sizeof...(sz)];
33 
34  int d = 0;
35 
36  load_sizes(sizes,d,sz ...);
37 
38  // ok now we create a grid
39 
40  grid_cpu<sizeof...(sz),aggregate<T>> grd(sizes);
41  grd.setMemory();
42 
43  auto it = grd.getIterator();
44  auto & lin = grd.getGrid();
45 
46  while (it.isNext())
47  {
48  auto p = it.get();
49 
50  grd.template get<0>(p) = arr[lin.LinId(p)];
51 
52  ++it;
53  }
54 
55  // Create a writer and write
56  VTKWriter<boost::mpl::pair<grid_cpu<sizeof...(sz),aggregate<T>>,double>,VECTOR_GRIDS> vtk_g;
57 
58  Point<sizeof...(sz),double> offset;
59  Box<sizeof...(sz),size_t> dom;
60  Point<sizeof...(sz),double> spacing;
61 
62  for (int i = 0 ; i < sizeof...(sz) ; i++)
63  {
64  offset[i] = 0;
65  spacing[i] = 1;
66  dom.setLow(i,0);
67  dom.setHigh(i,sizes[i]);
68  }
69 
70  vtk_g.add(grd,offset,spacing,dom);
71 
73  prp_names.add("scalar");
74 
75  vtk_g.write(file.c_str(), prp_names, "grids", file_type::ASCII);
76 
77 }
78 
79 template<typename T>
80 void print_grid(std::string file,T & grid)
81 {
82  // Create a writer and write
83  VTKWriter<boost::mpl::pair<T,double>,VECTOR_GRIDS> vtk_g;
84 
85  Point<T::dims,double> offset;
87  Point<T::dims,double> spacing;
88 
89  for (int i = 0 ; i < T::dims ; i++)
90  {
91  offset[i] = 0;
92  spacing[i] = 1;
93  dom.setLow(i,0);
94  dom.setHigh(i,grid.getGrid().size(i));
95  }
96 
97  vtk_g.add(grid,offset,spacing,dom);
98 
100 
101  vtk_g.write(file.c_str(), prp_names, "grids", file_type::ASCII);
102 
103 }
104 
105 
106 #endif /* DEBUG_HPP_ */
__device__ __host__ boost::mpl::at< type, boost::mpl::int_< i > >::type & get()
get the properties i
Definition: aggregate.hpp:240
This class implement the point shape in an N-dimensional space.
Definition: Point.hpp:27
__device__ __host__ void setHigh(int i, T val)
set the high interval of the box
Definition: Box.hpp:544
__device__ __host__ void setLow(int i, T val)
set the low interval of the box
Definition: Box.hpp:533
This class represent an N-dimensional box.
Definition: Box.hpp:60