Commit ffcab9ac authored by Pietro Incardona's avatar Pietro Incardona

Fixing test

parent ca2becb0
......@@ -25,8 +25,7 @@ var options0= {
title : 'Example',
vAxis: {title: 'Y Axis'},
hAxis: {title: 'X Axis'},
seriesType: 'bars',
};
seriesType: 'bars'};
var chart = new google.visualization.ComboChart(document.getElementById('chart_div0'));chart.draw(data0, options0);
}</script>
</head>
......
......@@ -25,8 +25,7 @@ var options0= {
title : 'Example',
vAxis: {title: 'Y Axis'},
hAxis: {title: 'X Axis'},
seriesType: '',
};
seriesType: ''};
var chart = new google.visualization.ComboChart(document.getElementById('chart_div0'));chart.draw(data0, options0);
}</script>
</head>
......
......@@ -25,8 +25,7 @@ var options0= {
title : '',
vAxis: {title: ''},
hAxis: {title: ''},
seriesType: '',
};
seriesType: ''};
var chart = new google.visualization.ComboChart(document.getElementById('chart_div0'));chart.draw(data0, options0);
}</script>
</head>
......
......@@ -25,8 +25,7 @@ var options0= {
title : '',
vAxis: {title: ''},
hAxis: {title: ''},
seriesType: '',
};
seriesType: ''};
var chart = new google.visualization.ComboChart(document.getElementById('chart_div0'));chart.draw(data0, options0);
}</script>
</head>
......
......@@ -25,8 +25,7 @@ var options0= {
title : '',
vAxis: {title: ''},
hAxis: {title: ''},
seriesType: '',
};
seriesType: ''};
var chart = new google.visualization.ComboChart(document.getElementById('chart_div0'));chart.draw(data0, options0);
}</script>
</head>
......
......@@ -54,22 +54,19 @@ title : 'Example',
vAxis: {title: 'Y Axis'},
hAxis: {title: 'X Axis'},
seriesType: 'bars',
series: {3: {type: 'line'}}
};
series: {3: {type: 'line'}}};
var options1= {
title : 'Example',
vAxis: {title: 'Y Axis'},
hAxis: {title: 'X Axis'},
seriesType: 'bars',
series: {3: {type: 'line'}}
};
series: {3: {type: 'line'}}};
var options2= {
title : 'Example',
vAxis: {title: 'Y Axis'},
hAxis: {title: 'X Axis'},
seriesType: 'bars',
series: {3: {type: 'line'}}
};
series: {3: {type: 'line'}}};
var chart = new google.visualization.ComboChart(document.getElementById('chart_div0'));chart.draw(data0, options0);
var chart = new google.visualization.ComboChart(document.getElementById('chart_div1'));chart.draw(data1, options1);
var chart = new google.visualization.ComboChart(document.getElementById('chart_div2'));chart.draw(data2, options2);
......
......@@ -26,8 +26,7 @@ title : 'Example',
vAxis: {title: 'Y Axis'},
hAxis: {title: 'X Axis'},
seriesType: 'bars',
series: {3: {type: 'line'}}
};
series: {3: {type: 'line'}}};
var chart = new google.visualization.ComboChart(document.getElementById('chart_div0'));chart.draw(data0, options0);
}</script>
</head>
......
......@@ -32,8 +32,7 @@ vAxis: {title: 'Y Axis'},
hAxis: {title: 'X Axis'},
curveType: 'function',
lineWidth: 1,
intervals: { 'style':'area' },
};
intervals: { 'style':'area' }};
var chart = new google.visualization.ComboChart(document.getElementById('chart_div0'));chart.draw(data0, options0);
}</script>
</head>
......
......@@ -17,6 +17,7 @@
#include <boost/mpl/for_each.hpp>
#include "csv_multiarray.hpp"
#include "util.hpp"
#include "is_csv_writable.hpp"
#define CSV_WRITER 0x30000
......@@ -60,8 +61,9 @@ struct csv_prp
// Remove the reference from the column type
typedef typename boost::remove_reference<col_type>::type col_rtype;
typedef typename std::remove_all_extents<col_rtype>::type base_col_rtype;
csv_value_str<col_rtype>(obj.template get<T::value>(),str);
csv_value_str<col_rtype, is_csv_writable<base_col_rtype>::value >(obj.template get<T::value>(),str);
}
};
......
......@@ -9,6 +9,7 @@ BOOST_AUTO_TEST_SUITE( csv_writer_test )
BOOST_AUTO_TEST_CASE( csv_writer_particles )
{
{
// Allocate a property vector
auto v_prp = allocate_openfpm_prp(16);
// Vector of position
......@@ -30,7 +31,31 @@ BOOST_AUTO_TEST_CASE( csv_writer_particles )
bool test = compare("csv_out.csv","csv_out_test.csv");
BOOST_REQUIRE_EQUAL(true,test);
}
{
// Allocate a property vector
auto v_prp = allocate_openfpm_aggregate_with_complex(16);
// Vector of position
openfpm::vector<Point<3,float>> v_pos;
// create a positional vector
for (size_t i = 0 ; i < v_prp.size() ; i++)
{
Point<3,float> p({1.0,2.0,3.0});
v_pos.add(p);
}
// CSVWriter test
CSVWriter<openfpm::vector<Point<3,float>>, openfpm::vector< aggregate<float,float,float,float,float[3],float[3][3],openfpm::vector<int>> > > csv_writer;
// Write the CSV
csv_writer.write("csv_out_unk.csv",v_pos,v_prp);
bool test = compare("csv_out_unk.csv","csv_out_unk_test.csv");
BOOST_REQUIRE_EQUAL(true,test);
}
}
......
......@@ -124,7 +124,7 @@ struct csv_col_str<T[N1][N2][N3][N4]>
* Will produce ",1.0,2.0,3.0"
*
*/
template<typename T>
template<typename T, bool is_writable>
struct csv_value_str
{
inline csv_value_str(T & v, std::stringstream & str)
......@@ -134,8 +134,8 @@ struct csv_value_str
};
//! Partial specialization for N=1 1D-Array
template<typename T,size_t N1>
struct csv_value_str<T[N1]>
template<typename T,size_t N1, bool is_writable>
struct csv_value_str<T[N1], is_writable>
{
inline csv_value_str(const T v[N1], std::stringstream & str)
{
......@@ -145,8 +145,8 @@ struct csv_value_str<T[N1]>
};
//! Partial specialization for N=2 2D-Array
template<typename T,size_t N1,size_t N2>
struct csv_value_str<T[N1][N2]>
template<typename T,size_t N1,size_t N2, bool is_writable>
struct csv_value_str<T[N1][N2], is_writable>
{
inline csv_value_str(const T v[N1][N2], std::stringstream & str)
{
......@@ -161,8 +161,8 @@ struct csv_value_str<T[N1][N2]>
};
//! Partial specialization for N=3
template<typename T,size_t N1,size_t N2,size_t N3>
struct csv_value_str<T[N1][N2][N3]>
template<typename T,size_t N1,size_t N2,size_t N3, bool is_writable>
struct csv_value_str<T[N1][N2][N3], is_writable>
{
inline csv_value_str(const T v[N1][N2][N3], std::stringstream & str)
{
......@@ -180,8 +180,8 @@ struct csv_value_str<T[N1][N2][N3]>
};
//! Partial specialization for N=4
template<typename T,size_t N1,size_t N2,size_t N3,size_t N4>
struct csv_value_str<T[N1][N2][N3][N4]>
template<typename T,size_t N1,size_t N2,size_t N3,size_t N4, bool is_writable>
struct csv_value_str<T[N1][N2][N3][N4],is_writable>
{
inline csv_value_str(const T v[N1][N2][N3][N4], std::stringstream & str)
{
......@@ -201,4 +201,14 @@ struct csv_value_str<T[N1][N2][N3][N4]>
}
};
//! Partial specialization for unknown property
template<typename T>
struct csv_value_str<T,false>
{
inline csv_value_str(const T v, std::stringstream & str)
{
str << "," << 0.0;
}
};
#endif /* CSV_MULTIARRAY_COPY_HPP_ */
......@@ -7,9 +7,9 @@ io_CXXFLAGS = $(CUDA_CFLAGS) $(INCLUDES_PATH) $(BOOST_CPPFLAGS) -I/usr/local/inc
io_CFLAGS = $(CUDA_CFLAGS)
io_LDADD = $(LINKLIBS)
nobase_include_HEADERS = CSVWriter/csv_multiarray.hpp CSVWriter/CSVWriter.hpp \
nobase_include_HEADERS = CSVWriter/csv_multiarray.hpp CSVWriter/CSVWriter.hpp CSVWriter/is_csv_writable.hpp \
GraphMLWriter/GraphMLWriter.hpp util.hpp \
VTKWriter/VTKWriter.hpp VTKWriter/VTKWriter_dist_graph.hpp VTKWriter/VTKWriter_graph.hpp VTKWriter/VTKWriter_point_set.hpp VTKWriter/VTKWriter_grids.hpp VTKWriter/VTKWriter_grids_st.hpp VTKWriter/VTKWriter_grids_util.hpp VTKWriter/VTKWriter_vector_box.hpp HDF5_XdmfWriter/HDF5_XdmfWriter.hpp HDF5_XdmfWriter/HDF5_XdmfWriter_point_set.hpp HDF5_XdmfWriter/HDF5_XdmfWriter_util.hpp \
VTKWriter/VTKWriter.hpp VTKWriter/VTKWriter_dist_graph.hpp VTKWriter/VTKWriter_graph.hpp VTKWriter/VTKWriter_point_set.hpp VTKWriter/VTKWriter_grids.hpp VTKWriter/VTKWriter_grids_st.hpp VTKWriter/VTKWriter_grids_util.hpp VTKWriter/VTKWriter_vector_box.hpp VTKWriter/is_vtk_writable.hpp HDF5_XdmfWriter/HDF5_XdmfWriter.hpp HDF5_XdmfWriter/HDF5_XdmfWriter_point_set.hpp HDF5_XdmfWriter/HDF5_XdmfWriter_util.hpp \
Plot/GoogleChart.hpp Plot/util.hpp
......
......@@ -14,6 +14,10 @@
#define GGRAPH_COLUMS 1
#define GGRAPH_POINTS 2
#define GC_ZOOM std::string("explorer: {actions: ['dragToZoom', 'rightClickToReset'],axis: 'horizontal,vertical',keepInBounds: true, maxZoomIn: 128.0}")
#define GC_X_LOG std::string("hAxis: { logscale: true }")
#define GC_Y_LOG std::string("vAxis: { logscale: true }")
/*! \brief Google chart options
*
*/
......@@ -58,6 +62,9 @@ struct GCoptions
//! more
std::string more;
//! curve type
std::string curveType = "function";
GCoptions & operator=(const GCoptions & opt)
{
title = opt.title;
......@@ -190,7 +197,7 @@ class GoogleChart
}
data << "data" << i << ".addRows([\n";
for (size_t i = 0 ; i < y.size() ; i++)
for (size_t i = 0 ; i < y.size() && x.size() ; i++)
{
for (size_t j = 0 ; j < y.get(i).size()+1 ; j++)
......@@ -215,13 +222,14 @@ class GoogleChart
std::string get_colums_bar_option(const GCoptions & opt)
{
std::stringstream str;
str << "title : '" << opt.title << "',\n";
str << "vAxis: {title: '" << opt.yAxis << "'},\n";
str << "hAxis: {title: '" << opt.xAxis << "'},\n";
str << "seriesType: '" << opt.stype << "',\n";
str << "title : '" << opt.title << "'";
str << ",\nvAxis: {title: '" << opt.yAxis << "'}";
str << ",\nhAxis: {title: '" << opt.xAxis << "'}";
str << ",\nseriesType: '" << opt.stype << "'";
if (opt.stypeext.size() != 0)
str << "series: " << opt.stypeext << "\n";
str << opt.more;
str << ",\nseries: " << opt.stypeext;
if (opt.more.size() != 0)
str << ",\n" <<opt.more;
return str.str();
}
......@@ -229,21 +237,22 @@ class GoogleChart
std::string get_points_plot_option(const GCoptions & opt)
{
std::stringstream str;
str << "title : '" << opt.title << "',\n";
str << "vAxis: {title: '" << opt.yAxis << "'},\n";
str << "hAxis: {title: '" << opt.xAxis << "'},\n";
str << "curveType: 'function',\n";
str << "title : '" << opt.title << "'";
str << ",\nvAxis: {title: '" << opt.yAxis << "'}";
str << ",\nhAxis: {title: '" << opt.xAxis << "'}";
str << ",\ncurveType: '"<< opt.curveType << "'";
str << "lineWidth: " << opt.lineWidth << ",\n";
str << ",\nlineWidth: " << opt.lineWidth;
if (opt.intervalsext.size() != 0)
str << "intervals: " << opt.intervalsext << ",\n";
str << ",\nintervals: " << opt.intervalsext;
else
str << "intervals: " << "{ 'style':'area' }" << ",\n";
str << ",\nintervals: " << "{ 'style':'area' }";
if (opt.intervalext.size() != 0)
str << "interval: " << opt.intervalext << "\n";
str << ",\ninterval: " << opt.intervalext << "\n";
str << opt.more;
if (opt.more.size() != 0)
str << ",\n" << opt.more;
return str.str();
}
......@@ -405,11 +414,64 @@ public:
set_of_graphs.last().opt = opt;
}
/*! \brief Add lines graph
*
* \param y A vector of vectors of values. each vector is a graph of points
*
* \param x Give a name or number to each x value, so can be a string or a number
*
* \param opt Graph options
*
*/
template<typename X, typename Y> void AddLines(openfpm::vector<X> & x, openfpm::vector<Y> & y , const GCoptions & opt)
{
openfpm::vector<std::string> yn;
if (y.size() == 0)
{
std::cerr << "Error: " << __FILE__ << ":" << __LINE__ << " vector y must be filled" << std::endl;
return;
}
for (size_t i = 0 ; i < y.last().size() ; i++)
yn.add(std::string("line") + std::to_string(i));
if (y.size() == 0)
return;
// number of points
size_t np = y.last().size();
for (size_t j = 0 ; j < y.size() ; j++)
{
if (y.get(j).size() != np)
std::cerr << __FILE__ << ":" << __LINE__ << " Error all the graph must have the same number of points " << np << "!=" << y.get(j).size() << std::endl;
}
openfpm::vector<openfpm::vector<X>> swap;
// swap the vector
// Each vector is a graph
// It is different from the other call where each vector
// has multiple value for the same point
for (size_t i = 0 ; i < np ; i++)
{
swap.add();
for (size_t j = 0 ; j < y.size() ; j++)
{
swap.last().add(y.get(j).get(i));
}
}
AddLinesGraph(x,swap,yn,opt);
}
/*! \brief Add a simple lines graph
*
* \param y A vector of vectors of values. The size of y indicate how many x values
* we have, while the internal vector can store multiple realizations,
* or min and max, for error bar
* we have, while the internal vector can store multiple value of the same point,
* for example error bar
*
* \param x Give a name or number to each x value, so can be a string or a number
*
......
......@@ -10,6 +10,7 @@
#include <boost/mpl/pair.hpp>
#include "VTKWriter_grids_util.hpp"
#include "is_vtk_writable.hpp"
/*! \brief It store one grid
*
......@@ -76,8 +77,9 @@ struct prop_out_g
void operator()(T& t) const
{
typedef typename boost::mpl::at<typename ele_g::value_type::value_type::type,boost::mpl::int_<T::value>>::type ptype;
typedef typename std::remove_all_extents<ptype>::type base_ptype;
meta_prop<boost::mpl::int_<T::value> ,ele_g,St, ptype > m(vg,v_out);
meta_prop<boost::mpl::int_<T::value> ,ele_g,St, ptype, is_vtk_writable<base_ptype>::value > m(vg,v_out);
}
void lastProp()
......
......@@ -9,116 +9,184 @@
#define SRC_VTKWRITER_GRIDS_UTIL_HPP_
#include "util/util_debug.hpp"
#include "is_vtk_writable.hpp"
/*! \brief This class specialize functions in the case the type T
* has or not defined attributes
/*! \brief Return the Attributes name (if they have)
*
* In C++ partial specialization of a function is not allowed so we have to
* encapsulate this function in a class
*
* \tparam has_attributes parameter that specialize the function in case the grid
* define or not attributes name
*
* \tparam Grid type we are processing
* \tparam i the property we are going to write
*
*/
template<bool has_attributes, typename St, typename ele_g, unsigned int i>
class prop_output_g
template<typename ele_g, bool has_attributes>
struct getAttrName
{
public:
/*! \brief Get attribute name
*
* \param i id of the attribute
* \param oprp post-fix to add
*
*/
static inline std::string get(size_t i, const std::string & oprp)
{
return ele_g::value_type::value_type::attributes::name[i] + oprp;
}
};
/*! \brief For each vertex set the value
template<typename ele_g>
struct getAttrName<ele_g,false>
{
/*! \brief Get attribute name
*
* \tparam i vertex property to print
* \param i id of the attribute
* \param oprp post-fix to add
*
*/
static std::string get_point_data(const openfpm::vector< ele_g > & vg)
static inline std::string get(size_t i, const std::string & oprp)
{
return std::string("attr" + std::to_string(i) + oprp);
}
};
/*! \brief Get the vtk properties header appending a prefix at the end
*
* \tparam has_attributes indicate if the properties have attributes name
* \param oprp prefix
*
*/
template<unsigned int i, typename ele_g, bool has_attributes> std::string get_point_property_header_impl(const std::string & oprp)
{
//! vertex node output string
std::string v_out;
typedef typename boost::mpl::at<typename ele_g::value_type::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
if (std::rank<ctype>::value == 1)
{
//! vertex node output string
std::string v_out;
//Get type of the property
std::string type = getType<typename std::remove_all_extents<ctype>::type>();
for (size_t k = 0 ; k < vg.size() ; k++)
// if the type is not supported skip-it
if (type.size() == 0)
{
//! Get a vertex iterator
auto it = vg.get(k).g.getIterator();
std::cerr << "Error " << __FILE__ << ":" << __LINE__ << " the type " << demangle(typeid(ctype).name()) << " is not supported by vtk\n";
return "";
}
// if there is the next element
while (it.isNext())
// Create point data properties
v_out += "VECTORS " + getAttrName<ele_g,has_attributes>::get(i,oprp) + " " + type + "\n";
}
else
{
std::string type = getType<typename std::remove_all_extents<ctype>::type>();
// if the type is not supported return
if (type.size() == 0)
{
// We check if is a custom vtk writable object
if (is_vtk_writable<ctype>::value == true)
{
// Print the property
v_out += std::to_string(vg.get(k).get_o(it.get()).template get<i>()) + "\n";
type = getType<typename vtk_type<ctype,is_custom_vtk_writable<ctype>::value>::type >();
// increment the iterator and counter
++it;
// We check if it is a vector or scalar like type
if (vtk_dims<ctype>::value == 1)
v_out += "SCALARS " + getAttrName<ele_g,has_attributes>::get(i,oprp) + " " + type + "\n";
else
v_out += "VECTORS " + getAttrName<ele_g,has_attributes>::get(i,oprp) + " " + type + "\n";
}
return v_out;
}
return v_out;
// Create point data properties
v_out += "SCALARS " + getAttrName<ele_g,has_attributes>::get(i,oprp) + " " + type + "\n";
// Default lookup table
v_out += "LOOKUP_TABLE default\n";
}
/*! \brief Given a Graph return the point data header for a typename T
// return the vertex list
return v_out;
}
#if 0
/*! \brief This class specialize functions in the case the type T
* has or not defined attributes
*
* In C++ partial specialization of a function is not allowed so we have to
* encapsulate this function in a class
*
* \tparam has_attributes parameter that specialize the function in case the grid
* define or not attributes name
*
* \tparam Grid type we are processing
* \tparam i the property we are going to write
*
*/
template<bool has_attributes, typename St, typename ele_g, unsigned int i>
class prop_output_g
{
public:
/*! \brief Return the VTK point data header for a typename T
*
* \tparam T type to write
* \param n_node number of the node
*
*/
static std::string get_point_property_header(const std::string & oprp)
{
//! vertex node output string
std::string v_out;
return get_point_property_header_impl<i,ele_g,has_attributes>(oprp);
}
};
typedef typename boost::mpl::at<typename ele_g::value_type::value_type::type,boost::mpl::int_<i>>::type ctype;
#endif
// Check if T is a supported format
// for now we support only scalar of native type
if (std::rank<ctype>::value == 1)
{
//Get type of the property
std::string type = getType<typename std::remove_all_extents<ctype>::type>();
/*! \brief Write the vectror property
*
* \tparam dim Dimensionality of the property
*
*/
template<unsigned int dim, typename T>
class prop_write_out
{
public:
// if the type is not supported skip-it
if (type.size() == 0)
{
std::cerr << "Error " << __FILE__ << ":" << __LINE__ << " the type " << demangle(typeid(ctype).name()) << " is not supported by vtk\n";
return "";
}
template<typename vector, typename iterator, typename I> static void write(std::string & v_out, vector & vg, size_t k, iterator & it)
{
// Create point data properties
v_out += "VECTORS " + get_attributes("") + " " + type + "\n";
// Print the properties
for (size_t i1 = 0 ; i1 < vtk_dims<T>::value ; i1++)
{
v_out += std::to_string(vg.get(k).g.get_o(it.get()).template get<I::value>().get_vtk(i1)) + " ";
}
else
if (vtk_dims<T>::value == 2)
{
std::string type = getType<ctype>();
// if the type is not supported return
if (type.size() == 0)
return v_out;
// Create point data properties
v_out += "SCALARS " + get_attributes(oprp) + " " + type + "\n";
// Default lookup table
v_out += "LOOKUP_TABLE default\n";
v_out += "0.0";
}
// return the vertex list
return v_out;
v_out += "\n";
}
};
/*! \brief Get the attributes name
*
*/
/*! \brief Write the scalar property
*
*
*/
template<typename T>
class prop_write_out<1,T>
{
public:
static std::string get_attributes(const std::string & out)
template<typename vector, typename iterator, typename I> static void write(std::string & v_out, vector & vg, size_t k, iterator & it)
{
return ele_g::value_type::value_type::attributes::name[i] + out;
// Print the property
v_out += std::to_string(vg.get(k).g.get_o(it.get()).template get<I::value>()) + "\n";
}
};
#if 0
/*! \brief This class specialize functions in the case the type T
* has not defined attributes
......@@ -145,66 +213,22 @@ public:
*/
static std::string get_point_property_header(const std::string & oprp)
{
//! vertex node output string
std::string v_out;
typedef typename boost::mpl::at<typename ele_g::value_type::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
if (std::rank<ctype>::value == 1)
{
//Get type of the property
std::string type = getType<typename std::remove_all_extents<ctype>::type>();
// if the type is not supported skip-it
if (type.size() == 0)
{
std::cerr << "Error " << __FILE__ << ":" << __LINE__ << " the type " << demangle(typeid(ctype).name()) << " is not supported by vtk\n";
return "";
}
// Create point data properties
v_out += "VECTORS " + get_attributes("") + " " + type + "\n";
}
else
{
std::string type = getType<typename std::remove_all_extents<ctype>::type>();
// if the type is not supported return
if (type.size() == 0)
return v_out;
// Create point data properties
v_out += "SCALARS " + get_attributes(oprp) + " " + type + "\n";
// Default lookup table
v_out += "LOOKUP_TABLE default\n";
}
// return the vertex list
return v_out;
}
/*! \brief Get the attributes name
*
*/
static std::string get_attributes(const std::string & oprp)
{