8#ifndef SRC_VTKWRITER_GRIDS_ST_HPP_
9#define SRC_VTKWRITER_GRIDS_ST_HPP_
12#include <boost/mpl/pair.hpp>
13#include "VTKWriter_grids_util.hpp"
14#include "util/util_debug.hpp"
15#include "util/convert.hpp"
22template <
typename Gr
id>
100template <
typename Gr
id,
typename St>
201template <
typename pair>
217 for (
size_t i = 0 ; i < vg.
size() ; i++)
219 for (
size_t j = 0 ; j < vg.get(i).g.
size() ; j++)
221 if (vg.get(i).g.get(j).grids.
size() != 0)
222 tot += vg.get(i).g.get(j).grids.get(0)->
size();
242 v_out +=
"VERTICES " + std::to_string(get_total()) +
" " + std::to_string(get_total() * 2) +
"\n";
262 v_out +=
"POINTS " + std::to_string(get_total()) +
" float" +
"\n";
276 std::stringstream v_out;
279 for (
size_t i = 0 ; i < vg.
size() ; i++)
282 for (
size_t j = 0 ; j < vg.get(i).g.
size() ; j++)
285 if (vg.get(i).g.get(j).grids.
size() == 0)
289 auto it = vg.get(i).g.get(j).grids.get(0)->getIterator();
305 p = it.
get().toPoint();
306 p = pmul(p,vg.get(i).spacing) + offset;
308 if (pair::first::dims == 2)
309 v_out << p.
toString() <<
" 0.0" <<
"\n";
332 std::stringstream v_out;
335 for (
size_t i = 0 ; i < vg.
size() ; i++)
338 for (
size_t j = 0 ; j < vg.get(i).g.
size() ; j++)
340 if (k < vg.get(i).g.get(j).grids.
size())
343 v_out << vg.get(i).g.get(j).cmb.to_string();
362 std::stringstream v_out;
367 typedef typename boost::mpl::at<typename pair::first::value_type::type,boost::mpl::int_<0>>::type ctype;
369 std::string type = getType<ctype>();
372 if (type.size() == 0)
374#ifndef DISABLE_ALL_RTTI
375 std::cerr <<
"Error " << __FILE__ <<
":" << __LINE__ <<
" the type " << demangle(
typeid(ctype).name()) <<
" is not supported by vtk\n";
380 std::string prp_cp = get_prop_components(k);
383 v_out <<
"SCALARS " << prop_name <<
"_" << prp_cp <<
" " << type +
"\n";
386 v_out <<
"LOOKUP_TABLE default\n";
389 for (
size_t i = 0 ; i < vg.
size() ; i++)
392 for (
size_t j = 0 ; j < vg.get(i).g.
size() ; j++)
395 if (vg.get(i).g.get(j).grids.
size() == 0)
398 if (k < vg.get(i).g.get(j).grids.
size())
401 auto & g_src = *vg.get(i).g.get(j).grids.get(k);
404 auto it = g_src.getIterator();
414 v_out << std::to_string(g_src.template get<0>(key)) <<
"\n";
423 auto & g_src = *vg.get(i).g.get(j).grids.get(0);
426 auto it = g_src.getIterator();
455 std::stringstream v_out;
458 v_out <<
"SCALARS domain float\n";
461 v_out <<
"LOOKUP_TABLE default\n";
464 for (
size_t i = 0 ; i < vg.
size() ; i++)
467 for (
size_t j = 0 ; j < vg.get(i).g.
size() ; j++)
470 if (vg.get(i).g.get(j).grids.
size() == 0)
474 auto it = vg.get(i).g.get(j).grids.get(0)->getIterator();
479 if (vg.get(i).dom.isInside(it.get().toPoint()) ==
true)
503 for (
size_t i = 0 ; i < vg.
size() ; i++)
506 for (
size_t j = 0 ; j < vg.get(i).g.
size() ; j++)
509 if (vg.get(i).g.get(j).grids.
size() > max)
510 max = vg.get(i).g.get(j).grids.
size();
530 for (
size_t i = 0 ; i < vg.
size() ; i++)
533 for (
size_t j = 0 ; j < vg.get(i).g.
size() ; j++)
536 if (vg.get(i).g.get(j).grids.
size() == 0)
539 auto it = vg.get(i).g.get(j).grids.get(0)->getIterator();
543 v_out +=
"1 " + std::to_string(k) +
"\n";
564 v_out +=
"POINT_DATA " + std::to_string(get_total()) +
"\n";
581 for(
size_t i = 0 ; i < vg.get(
id).g.
size() ; i++)
584 if (cmb == vg.get(
id).g.get(i).cmb)
586 vg.get(
id).g.get(i).grids.add(&g);
593 vg.get(
id).g.add(cg);
594 vg.get(
id).g.last().grids.add(&g);
618 const typename pair::first & g,
628 vg.get(i).offset = offset;
629 vg.get(i).spacing = spacing;
633 append_grid(i,g,cmb);
648 template<
int prp = -1>
bool write(std::string file,
649 std::string g_name =
"grids",
650 file_type ft = file_type::ASCII)
653 std::string vtk_header;
655 std::string point_list;
657 std::string vertex_list;
659 std::string vtk_binary_or_ascii;
661 std::string point_prop_header;
663 std::string vertex_prop_header;
665 std::string point_data_header;
667 std::string point_data;
670 vtk_header =
"# vtk DataFile Version 3.0\n"
674 if (ft == file_type::ASCII)
675 {vtk_header +=
"ASCII\n";}
677 {vtk_header +=
"BINARY\n";}
680 vtk_header +=
"DATASET POLYDATA\n";
683 point_prop_header = get_point_properties_list();
686 point_list = get_point_list();
689 vertex_prop_header = get_vertex_properties_list();
692 vertex_list = get_vertex_list();
695 point_data_header = get_point_data_header();
698 size_t mf = getMaxFused();
701 for (
size_t i = 0 ; i < mf ; i++)
702 point_data += get_properties_output(i,g_name);
708 std::ofstream ofs(file);
711 if (ofs.is_open() ==
false)
712 {std::cerr <<
"Error cannot create the VTK file: " + file +
"\n";}
714 ofs << vtk_header << point_prop_header << point_list <<
715 vertex_prop_header << vertex_list << point_data_header << point_data;
This class represent an N-dimensional box.
This class implement the point shape in an N-dimensional space.
void one()
Set to one the point coordinate.
__device__ __host__ const T & get(unsigned int i) const
Get coordinate.
std::string toString() const
Return the string with the point coordinate.
std::string get_point_list()
Create the VTK point definition.
std::string get_properties_output(size_t k, std::string prop_name)
Create the VTK properties output.
void add(size_t i, const typename pair::first &g, const Point< pair::first::dims, typename pair::second > &offset, const Point< pair::first::dims, typename pair::second > &spacing, const Box< pair::first::dims, typename pair::second > &dom, const comb< pair::first::dims > &cmb)
Add grid dataset.
std::string get_vertex_properties_list()
It get the vertex properties list.
size_t getMaxFused()
Get the maximum number of fused grid.
openfpm::vector< ele_g_st< typename pair::first, typename pair::second > > vg
Vector of grids.
std::string get_prop_components(size_t k)
It generate a name for the property cell component.
size_t get_total()
Get the total number of points.
std::string lastProp()
Return the output of the domain property.
std::string get_point_data_header()
Get the point data header.
void append_grid(size_t id, const typename pair::first &g, const comb< pair::first::dims > &cmb)
Append the grid to the sub-domain, if for a sub-domain we have a grid that is overlapping fuse them,...
std::string get_vertex_list()
Create the VTK vertex definition.
std::string get_point_properties_list()
It get the vertex properties list.
bool write(std::string file, std::string g_name="grids", file_type ft=file_type::ASCII)
It write a VTK file from a graph.
convert a staggered element into a string for vtk write
openfpm::vector< cell_grid< Grid > > g
fused grids
ele_g_st< Grid, St > & operator=(const ele_g_st &ele)
Copy the object.
ele_g_st(const Point< Grid::dims, St > &offset, const Point< Grid::dims, St > &spacing, const Box< Grid::dims, St > &dom)
convert a staggered grid property into a string
Point< Grid::dims, St > offset
offset where it start the grid
ele_g_st(const ele_g_st &ele)
Copy constructor.
ele_g_st(ele_g_st &&ele)
Copy constructor.
ele_g_st< Grid, St > & operator=(ele_g_st &&ele)
Copy the object.
Box< Grid::dims, size_t > dom
Part of the grid that is real domain.
Point< Grid::dims, St > spacing
spacing of the grid
std::string dataset
output string
Implementation of 1-D std::vector like structure.
static Point< dim, St > convert(const comb< dim > &c)
Return the combination converted to point.
for each combination in the cell grid you can have different grids
cell_grid< Grid > & operator=(cell_grid< Grid > &&cg)
Copy the cell grid.
openfpm::vector< const Grid * > grids
vector of fused grids
cell_grid(const comb< Grid::dims > &cmb)
construct a cell grid
cell_grid< Grid > & operator=(const cell_grid< Grid > &cg)
Copy the cell grid.
cell_grid(cell_grid< Grid > &&cg)
copy constructor
cell_grid(const cell_grid< Grid > &cg)
copy contructor
Position of the element of dimension d in the hyper-cube of dimension dim.