Commit 13e4a081 authored by incardon's avatar incardon

Added VTKWriter for staggered grid

parent e4e6e157
......@@ -96,6 +96,7 @@ enum file_type
#define GRAPH 1
#define VECTOR_BOX 2
#define VECTOR_GRIDS 3
#define VECTOR_ST_GRIDS 4
template <typename Graph, unsigned int imp>
class VTKWriter
......@@ -106,5 +107,6 @@ class VTKWriter
#include "VTKWriter_graph.hpp"
#include "VTKWriter_vector_box.hpp"
#include "VTKWriter_grids.hpp"
#include "VTKWriter_grids_st.hpp"
#endif /* VTKWRITER_HPP_ */
......@@ -177,13 +177,9 @@ class VTKWriter<pair,VECTOR_GRIDS>
}
/*! \brief Create the VTK point definition
*
* \tparam s_type spatial type of the data
* \tparam attr false x,y,z are set to 0 for each vertex
*
*/
template <bool attr> std::string get_point_list()
std::string get_point_list()
{
//! vertex node output string
std::stringstream v_out;
......@@ -220,12 +216,8 @@ class VTKWriter<pair,VECTOR_GRIDS>
}
/*! \brief Create the VTK vertex definition
*
* \tparam s_type spatial type of the data
* \tparam attr false x,y,z are set to 0 for each vertex
*
*/
std::string get_vertex_list()
{
//! vertex node output string
......@@ -336,7 +328,7 @@ public:
point_prop_header = get_point_properties_list();
// Get point list
point_list = get_point_list<has_attributes<typename pair::first::value_type>::value>();
point_list = get_point_list();
// vertex properties header
vertex_prop_header = get_vertex_properties_list();
......
This diff is collapsed.
......@@ -2,12 +2,14 @@
* VTKWriter_grids_util.hpp
*
* Created on: Aug 10, 2015
* Author: i-bird
* Author: Pietro Incardona
*/
#ifndef SRC_VTKWRITER_GRIDS_UTIL_HPP_
#define SRC_VTKWRITER_GRIDS_UTIL_HPP_
#include "util/util_debug.hpp"
/*! \brief This class specialize functions in the case the type T
* has or not defined attributes
*
......@@ -67,14 +69,20 @@ public:
//! vertex node output string
std::string v_out;
typedef typename boost::fusion::result_of::at<typename ele_g::value_type::type,boost::mpl::int_<i>>::type ctype;
// Check if T is a supported format
// for now we support only scalar of native type
std::string type = getType<typename boost::fusion::result_of::at<typename ele_g::value_type::type,boost::mpl::int_<i>>::type>();
std::string type = getType<ctype>();
// if the type is not supported return
// if the type is not supported return
if (type.size() == 0)
{return v_out;}
{
std::cerr << "Error " << __FILE__ << ":" << __LINE__ << " the type " << demangle(typeid(ctype).name()) << " is not supported by vtk\n";
return "";
}
// Create point data properties
v_out += "SCALARS " + get_attributes(oprp) + " " + type + "\n";
......@@ -136,7 +144,10 @@ public:
// if the type is not supported return
if (type.size() == 0)
{return v_out;}
{
std::cerr << "Error " << __FILE__ << ":" << __LINE__ << " the type " << demangle(typeid(ctype).name()) << " is not supported by vtk\n";
return "";
}
// Create point data properties
v_out += "SCALARS " + get_attributes(oprp) + " " + type + "\n";
......
......@@ -258,6 +258,7 @@ void fill_grid_some_data(grid_cpu<2,Point_test<float>> & g)
BOOST_AUTO_TEST_CASE( vtk_writer_use_grids)
{
{
// Create box grids
Point<2,float> offset1({0.0,0.0});
Point<2,float> spacing1({0.1,0.2});
......@@ -304,6 +305,58 @@ BOOST_AUTO_TEST_CASE( vtk_writer_use_grids)
// Check that match
bool test = compare("vtk_grids.vtk","vtk_grids_test.vtk");
BOOST_REQUIRE_EQUAL(test,true);
}
{
// Create box grids
Point<2,float> offset1({0.0,0.0});
Point<2,float> spacing1({0.1,0.1});
Box<2,size_t> d1({1,2},{14,15});
// Create box grids
Point<2,float> offset2({0.0,0.0});
Point<2,float> spacing2({0.1,0.1});
Box<2,size_t> d2({2,1},{13,15});
// Create box grids
Point<2,float> offset3({5.0,5.0});
Point<2,float> spacing3({0.1,0.1});
Box<2,size_t> d3({3,2},{11,10});
// Create box grids
Point<2,float> offset4({5.0,5.0});
Point<2,float> spacing4({0.1,0.1});
Box<2,size_t> d4({1,1},{7,7});
size_t sz[] = {16,16};
grid_cpu<2,Point_test<float>> g1(sz);
g1.setMemory();
fill_grid_some_data(g1);
grid_cpu<2,Point_test<float>> g2(sz);
g2.setMemory();
fill_grid_some_data(g2);
grid_cpu<2,Point_test<float>> g3(sz);
g3.setMemory();
fill_grid_some_data(g3);
grid_cpu<2,Point_test<float>> g4(sz);
g4.setMemory();
fill_grid_some_data(g4);
comb<2> cmb;
cmb.zero();
comb<2> cmb2;
cmb2.mone();
// Create a writer and write
VTKWriter<boost::mpl::pair<grid_cpu<2,Point_test<float>>,float>,VECTOR_ST_GRIDS> vtk_g;
vtk_g.add(0,g1,offset1,spacing1,d1,cmb);
vtk_g.add(0,g2,offset2,spacing2,d2,cmb);
vtk_g.add(1,g3,offset3,spacing3,d3,cmb);
vtk_g.add(1,g4,offset4,spacing4,d4,cmb2);
vtk_g.write("vtk_grids_st.vtk");
}
}
BOOST_AUTO_TEST_SUITE_END()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment