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"
22 template <
typename Gr
id>
100 template <
typename Gr
id,
typename St>
121 :offset(offset),spacing(spacing),dom(dom)
201 template <
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 std::cerr <<
"Error " << __FILE__ <<
":" << __LINE__ <<
" the type " << demangle(
typeid(ctype).name()) <<
" is not supported by vtk\n";
378 std::string prp_cp = get_prop_components(k);
381 v_out <<
"SCALARS " << prop_name <<
"_" << prp_cp <<
" " << type +
"\n";
384 v_out <<
"LOOKUP_TABLE default\n";
387 for (
size_t i = 0 ; i < vg.size() ; i++)
390 for (
size_t j = 0 ; j < vg.get(i).g.size() ; j++)
393 if (vg.get(i).g.get(j).grids.size() == 0)
396 if (k < vg.get(i).g.get(j).grids.size())
399 auto & g_src = *vg.get(i).g.get(j).grids.get(k);
402 auto it = g_src.getIterator();
412 v_out << std::to_string(g_src.template get<0>(
key)) <<
"\n";
421 auto & g_src = *vg.get(i).g.get(j).grids.get(0);
424 auto it = g_src.getIterator();
453 std::stringstream v_out;
456 v_out <<
"SCALARS domain float\n";
459 v_out <<
"LOOKUP_TABLE default\n";
462 for (
size_t i = 0 ; i < vg.size() ; i++)
465 for (
size_t j = 0 ; j < vg.get(i).g.size() ; j++)
468 if (vg.get(i).g.get(j).grids.size() == 0)
472 auto it = vg.get(i).g.get(j).grids.get(0)->getIterator();
477 if (vg.get(i).dom.isInside(it.get().toPoint()) ==
true)
501 for (
size_t i = 0 ; i < vg.size() ; i++)
504 for (
size_t j = 0 ; j < vg.get(i).g.size() ; j++)
507 if (vg.get(i).g.get(j).grids.size() > max)
508 max = vg.get(i).g.get(j).grids.size();
528 for (
size_t i = 0 ; i < vg.size() ; i++)
531 for (
size_t j = 0 ; j < vg.get(i).g.size() ; j++)
534 if (vg.get(i).g.get(j).grids.size() == 0)
537 auto it = vg.get(i).g.get(j).grids.get(0)->getIterator();
541 v_out +=
"1 " + std::to_string(k) +
"\n";
562 v_out +=
"POINT_DATA " + std::to_string(get_total()) +
"\n";
579 for(
size_t i = 0 ; i < vg.get(
id).g.size() ; i++)
582 if (cmb == vg.get(
id).g.get(i).cmb)
584 vg.get(
id).g.get(i).grids.add(&g);
591 vg.get(
id).g.add(cg);
592 vg.get(
id).g.last().grids.add(&g);
616 const typename pair::first & g,
626 vg.get(i).offset = offset;
627 vg.
get(i).spacing = spacing;
631 append_grid(i,g,cmb);
646 template<
int prp = -1>
bool write(std::string file,
647 std::string g_name =
"grids",
648 file_type ft = file_type::ASCII)
651 std::string vtk_header;
653 std::string point_list;
655 std::string vertex_list;
657 std::string vtk_binary_or_ascii;
659 std::string point_prop_header;
661 std::string vertex_prop_header;
663 std::string point_data_header;
665 std::string point_data;
668 vtk_header =
"# vtk DataFile Version 3.0\n"
672 if (ft == file_type::ASCII)
673 {vtk_header +=
"ASCII\n";}
675 {vtk_header +=
"BINARY\n";}
678 vtk_header +=
"DATASET POLYDATA\n";
681 point_prop_header = get_point_properties_list();
684 point_list = get_point_list();
687 vertex_prop_header = get_vertex_properties_list();
690 vertex_list = get_vertex_list();
693 point_data_header = get_point_data_header();
696 size_t mf = getMaxFused();
699 for (
size_t i = 0 ; i < mf ; i++)
700 point_data += get_properties_output(i,g_name);
706 std::ofstream ofs(file);
709 if (ofs.is_open() ==
false)
710 {std::cerr <<
"Error cannot create the VTK file: " + file +
"\n";}
712 ofs << vtk_header << point_prop_header << point_list <<
713 vertex_prop_header << vertex_list << point_data_header << point_data;
openfpm::vector< cell_grid< Grid > > g
fused grids
ele_g_st< Grid, St > & operator=(ele_g_st &&ele)
Copy the object.
std::string get_point_list()
Create the VTK point definition.
std::string dataset
output string
std::string get_point_data_header()
Get the point data header.
std::string toString() const
Return the string with the point coordinate.
std::string get_point_properties_list()
It get the vertex properties list.
size_t get_total()
Get the total number of points.
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.
static Point< dim, St > convert(const comb< dim > &c)
Return the combination converted to point.
Box< Grid::dims, size_t > dom
Part of the grid that is real domain.
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
cell_grid(cell_grid< Grid > &&cg)
copy constructor
std::string get_prop_components(size_t k)
It generate a name for the property cell component.
openfpm::vector< const Grid * > grids
vector of fused grids
size_t getMaxFused()
Get the maximum number of fused grid.
cell_grid< Grid > & operator=(cell_grid< Grid > &&cg)
Copy the cell grid.
void one()
Set to one the point coordinate.
for each combination in the cell grid you can have different grids
const T & get(size_t i) const
Get coordinate.
This class represent an N-dimensional box.
This class is a trick to indicate the compiler a specific specialization pattern. ...
Point< Grid::dims, St > spacing
spacing of the grid
std::string get_vertex_list()
Create the VTK vertex definition.
Point< Grid::dims, St > offset
offset where it start the grid
cell_grid(const comb< Grid::dims > &cmb)
construct a cell grid
convert a staggered element into a string for vtk write
std::string lastProp()
Return the output of the domain property.
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...
openfpm::vector< ele_g_st< typename pair::first, typename pair::second > > vg
Vector of grids.
ele_g_st(ele_g_st &&ele)
Copy constructor.
std::string get_properties_output(size_t k, std::string prop_name)
Create the VTK properties output.
ele_g_st(const ele_g_st &ele)
Copy constructor.
cell_grid(const cell_grid< Grid > &cg)
copy contructor
std::string get_vertex_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.
cell_grid< Grid > & operator=(const cell_grid< Grid > &cg)
Copy the cell grid.