Commit 7cd835c3 authored by Abhinav Singh's avatar Abhinav Singh
Browse files

Merge remote-tracking branch 'origin/FD_solver' into develop

# Conflicts:
#	src/VTKWriter/VTKWriter_grids_util.hpp
#	test_data/vtk_points_pp_header_test.vtp
#	test_data/vtk_points_pp_test.vtp
#	test_data/vtk_points_test.vtp
#	test_data/vtk_points_with_prp_names_test.vtp
parents 217bde24 4702a728
......@@ -7,9 +7,10 @@ if [ -d "$1/BOOST" ]; then
exit 0
fi
wget http://ppmcore.mpi-cbg.de/upload/boost_1_72_0.tar.bz2
tar -xvf boost_1_72_0.tar.bz2
cd boost_1_72_0
rm boost_1_75_0.tar.bz2
wget http://ppmcore.mpi-cbg.de/upload/boost_1_75_0.tar.bz2
tar -xvf boost_1_75_0.tar.bz2
cd boost_1_75_0
if [ x"$4" != x"" ]; then
if [ -f $HOME/user-config.jam ]; then
mv $HOME/user-config.jam $HOME/user-config.jam_bck
......@@ -23,10 +24,10 @@ fi
./bootstrap.sh --with-toolset=$3
mkdir $1/BOOST
./b2 -j $2 install --prefix=$1/BOOST
rm -rf boost_1_72_0
rm -rf boost_1_75_0
if [ -f $HOME/user-config.jam_bck ]; then
mv $HOME/user-config.jam_bck $HOME/user-config.jam
fi
rm -rf boost_1_72_0.tar.bz2
rm -rf boost_1_75_0.tar.bz2
......@@ -15,37 +15,74 @@
#include <fstream>
#include "util/common.hpp"
/*! \brief Get the type
/*! \brief Get the type Old
*
* It convert T to a string identify the corrispondent type in VTK format
*
*/
template <typename T> std::string getType()
{
// Create a property string based on the type of the property
if (std::is_same<T,float>::value)
return "float";
else if (std::is_same<T,double>::value)
return "double";
else if (std::is_same<T,char>::value)
return "char";
else if (std::is_same<T,unsigned char>::value)
return "unsigned_char";
else if (std::is_same<T,short>::value)
return "short";
else if (std::is_same<T,unsigned short>::value)
return "unsigned_short";
else if (std::is_same<T,int>::value)
return "int";
else if (std::is_same<T,unsigned int>::value)
return "unsigned_int";
else if (std::is_same<T,long int>::value)
return "int";
else if (std::is_same<T,unsigned long int>::value )
return "unsigned_int";
else if (std::is_same<T,bool>::value )
return "bit";
return "";
}
/*! \brief Get the type
*
* It convert T to a string identify the corrispondent type in VTK format
*
*/
template <typename T> std::string getTypeNew()
{
// Create a property string based on the type of the property
if (std::is_same<T,float>::value)
return "float";
return "Float32";
else if (std::is_same<T,double>::value)
return "double";
return "Float64";
else if (std::is_same<T,char>::value)
return "char";
return "Int8";
else if (std::is_same<T,unsigned char>::value)
return "unsigned_char";
return "Uint8";
else if (std::is_same<T,short>::value)
return "short";
return "Int16";
else if (std::is_same<T,unsigned short>::value)
return "unsigned_short";
return "Uint16";
else if (std::is_same<T,int>::value)
return "int";
return "Int32";
else if (std::is_same<T,unsigned int>::value)
return "unsigned_int";
return "Uint32";
else if (std::is_same<T,long int>::value)
return "int";
return "Int64";
else if (std::is_same<T,unsigned long int>::value )
return "unsigned_int";
return "Uint64";
else if (std::is_same<T,bool>::value )
return "bit";
return "Int8";
return "";
}
......
......@@ -141,7 +141,7 @@ template<unsigned int i, typename ele_g, bool has_attributes> std::string get_po
* \param oprp prefix
*
*/
/*template<unsigned int i, typename ele_g, bool has_attributes> std::string get_point_property_header_impl_new(const std::string & oprp, const openfpm::vector<std::string> & prop_names,file_type ft)
template<unsigned int i, typename ele_g, bool has_attributes> std::string get_point_property_header_impl_new(const std::string & oprp, const openfpm::vector<std::string> & prop_names,file_type ft)
{
//! vertex node output string
std::string v_out;
......@@ -233,7 +233,7 @@ template<unsigned int i, typename ele_g, bool has_attributes> std::string get_po
// return the vertex list
return v_out;
}*/
}
/*! \brief Write the vectror property
*
......@@ -648,7 +648,6 @@ struct meta_prop<I,ele_g,St,T,false>
* \tparam is_writable flag that indicate if a property is writable
*
*/
#if 0
template<typename I, typename ele_g, typename St, typename T, bool is_writable>
struct meta_prop_new
{
......@@ -911,8 +910,6 @@ struct meta_prop_new<I,ele_g,St,T,false>
}
};
#endif
template<unsigned int dims,typename T> inline void output_point(Point<dims,T> & p,std::stringstream & v_out, file_type ft)
{
if (ft == file_type::ASCII)
......
......@@ -120,17 +120,27 @@ struct prop_out_v
typedef typename boost::mpl::at<typename ele_v::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_v,St, ptype, is_vtk_writable<base_ptype>::value > m(vv,v_out,prop_names,ft);
meta_prop_new<boost::mpl::int_<T::value> ,ele_v,St, ptype, is_vtk_writable<base_ptype>::value > m(vv,v_out,prop_names,ft);
}
void lastProp()
{
// Create point data properties
v_out += "SCALARS domain float\n";
std::string v_outToEncode,v_Encoded;
// Create point data properties
//v_out += "SCALARS domain float\n";
// Default lookup table
v_out += "LOOKUP_TABLE default\n";
//v_out += "LOOKUP_TABLE default\n";
v_out += " <DataArray type=\"Float32\" Name=\"domain\"";
if (ft == file_type::ASCII) {
v_out += " format=\"ascii\">\n";
}
else {
v_out += " format=\"binary\">\n";
}
if (ft == file_type::BINARY) {
v_outToEncode.append(8,0);
}
// Produce point data
for (size_t k = 0 ; k < vv.size() ; k++)
{
......@@ -143,23 +153,23 @@ struct prop_out_v
if (ft == file_type::ASCII)
{
if (it.get() < vv.get(k).mark)
v_out += "1.0\n";
v_outToEncode += "1.0\n";
else
v_out += "0.0\n";
v_outToEncode += "0.0\n";
}
else
{
if (it.get() < vv.get(k).mark)
{
float one = 1;
one = swap_endian_lt(one);
v_out.append((const char *)&one,sizeof(int));
//one = swap_endian_lt(one);
v_outToEncode.append((const char *)&one,sizeof(int));
}
else
{
float zero = 0;
zero = swap_endian_lt(zero);
v_out.append((const char *)&zero,sizeof(int));
//zero = swap_endian_lt(zero);
v_outToEncode.append((const char *)&zero,sizeof(int));
}
}
......@@ -167,7 +177,77 @@ struct prop_out_v
++it;
}
}
}
if (ft == file_type::BINARY)
{
*(size_t *) &v_outToEncode[0] = v_outToEncode.size()-sizeof(size_t);
v_Encoded.resize(v_outToEncode.size()/3*4+4);
size_t sz=EncodeToBase64((const unsigned char*)&v_outToEncode[0],v_outToEncode.size(),(unsigned char *)&v_Encoded[0],0);
v_Encoded.resize(sz);
v_out += v_Encoded + "\n";
}
else{
v_out += v_outToEncode;
};
v_out+=" </DataArray>\n";
}
};
/*! \brief this class is a functor for "for_each" algorithm
*
* This class is a functor for "for_each" algorithm. For each
* element of the boost::vector the operator() is called.
* Is mainly used to produce an output for each property
*
* \tparam ele_v It is the class ele_v that store the couple vector of position and property
*
*
*/
template<typename ele_v, typename St>
struct prop_out_v_pvtp
{
//! property output string
std::string & v_out;
//! properties names
const openfpm::vector<std::string> & prop_names;
/*! \brief constructor
*
* \param v_out string to fill with the vertex properties
* \param vv vector we are processing
* \param ft ASCII or BINARY format
*
*/
prop_out_v_pvtp(std::string & v_out,
const openfpm::vector<std::string> & prop_names)
:v_out(v_out),prop_names(prop_names)
{
//meta_prop_new<boost::mpl::int_<T::value> ,ele_v,St, ptype, is_vtk_writable<base_ptype>::value > m(vv,v_out,prop_names,ft);
};
/*! \brief It produce an output for each property
*
* \param t property id
*
*/
template<typename T>
void operator()(T& t) const
{
typedef typename boost::mpl::at<typename ele_v::value_type::value_type::type,boost::mpl::int_<T::value>>::type ptype;
typedef typename std::remove_all_extents<ptype>::type base_ptype;
//std::string type = getTypeNew<base_ptype>();
meta_prop_new<boost::mpl::int_<T::value> ,ele_v,St, ptype, is_vtk_writable<base_ptype>::value >::get_pvtp_out(v_out,prop_names);
//v_out += " <PDataArray type=\""+type+"\" Name=\""+getAttrName<ele_g,has_attributes>::get(i,prop_names,oprp)+"\""+" NumberOfComponents=\"3\"";
}
void lastProp()
{
v_out += " <PDataArray type=\"Float32\" Name=\"domain\"/>\n </PPointData>\n";
}
};
/*!
......@@ -212,14 +292,24 @@ class VTKWriter<pair,VECTOR_POINTS>
* \return a string that define the vertex properties in graphML format
*
*/
std::string get_vertex_properties_list()
std::string get_vertex_properties_list(file_type & opt)
{
//! vertex property output string
std::string v_out;
// write the number of vertex
v_out += "VERTICES " + std::to_string(get_total()) + " " + std::to_string(get_total() * 2) + "\n";
v_out += " <Verts>\n";
if (opt == file_type::ASCII)
{
v_out+=" <DataArray type=\"Int64\" Name=\"connectivity\" format=\"ascii\">\n";
}
else
{
v_out+=" <DataArray type=\"Int64\" Name=\"connectivity\" format=\"binary\">\n";
}
// write the number of vertex
//v_out += "VERTICES " + std::to_string(get_total()) + " " + std::to_string(get_total() * 2) + "\n";
// return the vertex properties string
return v_out;
}
......@@ -238,7 +328,7 @@ class VTKWriter<pair,VECTOR_POINTS>
// write the number of vertex
v_out += "POINTS " + std::to_string(get_total()) + " " + getType<typename pair::first::value_type::coord_type>() + "\n";
v_out += " <Piece NumberOfPoints=\"" + std::to_string(get_total()) + "\" " +"NumberOfVerts=\"" + std::to_string(get_total()) + "\">\n";
// return the vertex properties string
return v_out;
......@@ -251,14 +341,31 @@ class VTKWriter<pair,VECTOR_POINTS>
* \return the list of points
*
*/
std::string get_point_list(file_type ft)
std::string get_point_list(file_type & opt)
{
//! vertex node output string
std::stringstream v_out;
v_out<<" <Points>\n";
if (opt == file_type::ASCII)
{
v_out<<" <DataArray type=\"Float64\" Name=\"Points\" NumberOfComponents=\"3\" format=\"ascii\">\n";
}
else
{
v_out<<" <DataArray type=\"Float64\" Name=\"Points\" NumberOfComponents=\"3\" format=\"binary\">\n";
}
std::stringstream binaryToEncode;
//! For each defined grid
if (opt == file_type::BINARY)
{
size_t tmp=0;
binaryToEncode.write((const char *)&tmp,sizeof(tmp));
}
for (size_t i = 0 ; i < vps.size() ; i++)
for (size_t i = 0 ; i < vps.size() ; i++)
{
//! write the particle position
auto it = vps.get(i).g.getIterator();
......@@ -269,17 +376,28 @@ class VTKWriter<pair,VECTOR_POINTS>
Point<pair::first::value_type::dims,typename pair::first::value_type::coord_type> p;
p = vps.get(i).g.get(it.get());
output_point<pair::first::value_type::dims,typename pair::first::value_type::coord_type>(p,v_out,ft);
output_point_new<pair::first::value_type::dims,typename pair::first::value_type::coord_type>(p,binaryToEncode,opt);
// increment the iterator and counter
++it;
}
}
//! In case of binary we have to add a new line at the end of the list
if (ft == file_type::BINARY)
v_out << std::endl;
if (opt == file_type::BINARY){
std::string buffer_out,buffer_bin;
buffer_bin=binaryToEncode.str();
*(size_t *)&buffer_bin[0]=buffer_bin.size()-8;
buffer_out.resize(buffer_bin.size()/3*4+4);
unsigned long sz = EncodeToBase64((const unsigned char*)&buffer_bin[0],buffer_bin.size(),(unsigned char*)&buffer_out[0],0);
buffer_out.resize(sz);
v_out << buffer_out<<std::endl;
}
else
{
v_out<<binaryToEncode.str();
}
v_out<<" </DataArray>\n";
v_out<<" </Points>\n";
// return the vertex list
return v_out.str();
}
......@@ -294,10 +412,12 @@ class VTKWriter<pair,VECTOR_POINTS>
std::string get_vertex_list(file_type ft)
{
// vertex node output string
std::string v_out;
size_t k = 0;
std::string v_out,v_outToEncode,v_Encoded;
size_t k = 0;
if (ft == file_type::BINARY) {
v_outToEncode.append(8,0);
}
for (size_t i = 0 ; i < vps.size() ; i++)
{
//! For each grid point create a vertex
......@@ -305,17 +425,66 @@ class VTKWriter<pair,VECTOR_POINTS>
while (it.isNext())
{
output_vertex(k,v_out,ft);
output_vertex_new(k,v_outToEncode,ft);
++k;
++it;
}
}
//! In case of binary we have to add a new line at the end of the list
if (ft == file_type::BINARY)
{v_out += "\n";}
{
*(size_t *) &v_outToEncode[0] = v_outToEncode.size()-sizeof(size_t);
v_Encoded.resize(v_outToEncode.size()/3*4+4);
size_t sz=EncodeToBase64((const unsigned char*)&v_outToEncode[0],v_outToEncode.size(),(unsigned char *)&v_Encoded[0],0);
v_Encoded.resize(sz);
v_out += v_Encoded + "\n";
}
else{
v_out += v_outToEncode;
};
v_out += " </DataArray>\n";
v_out += " <DataArray type=\"Int64\" Name=\"offsets\" ";
if (ft == file_type::ASCII)
{
v_out += "format=\"ascii\">\n";
}
else{
v_out += "format=\"binary\">\n";
}
k=0;
v_outToEncode.clear();
if (ft == file_type::BINARY) {
v_outToEncode.append(8,0);
}
for (size_t i = 0 ; i < vps.size() ; i++)
{
//! For each grid point create a vertex
auto it = vps.get(i).g.getIterator();
while (it.isNext())
{
output_vertex_new(k+1,v_outToEncode,ft);
++k;
++it;
}
}
if (ft == file_type::BINARY)
{
*(size_t *) &v_outToEncode[0] = v_outToEncode.size()-sizeof(size_t);
v_Encoded.resize(v_outToEncode.size()/3*4+4);
size_t sz=EncodeToBase64((const unsigned char*)&v_outToEncode[0],v_outToEncode.size(),(unsigned char *)&v_Encoded[0],0);
v_Encoded.resize(sz);
v_out += v_Encoded + "\n";
}
else{
v_out += v_outToEncode;
};
v_out += " </DataArray>\n";
v_out += " </Verts>\n";
// return the vertex list
return v_out;
}
......@@ -329,11 +498,14 @@ class VTKWriter<pair,VECTOR_POINTS>
{
std::string v_out;
v_out += "POINT_DATA " + std::to_string(get_total()) + "\n";
v_out += " <PointData>\n";
return v_out;
}
struct doubleint{
long int i;
double d;
};
/*! \brief return the meta data string
*
* \param meta_data string with the meta-data to add
......@@ -356,18 +528,35 @@ class VTKWriter<pair,VECTOR_POINTS>
if (exist == true)
{
meta_string += "FIELD FieldData 1\n";
meta_string += "TIME 1 1 double\n";
if (opt == file_type::ASCII)
{meta_string += std::to_string(time);}
//<DataArray type="Float64" Name="TimeValue" NumberOfTuples="1" format="ascii" RangeMin="2" RangeMax="2">
//meta_string += "";
meta_string += " <FieldData>\n";
if (opt == file_type::ASCII)
{ meta_string += " <DataArray type=\"Float64\" Name=\"TimeValue\" NumberOfTuples=\"1\" format=\"ascii\">\n";
meta_string += std::to_string(time);
}
else
{
time = swap_endian_lt(time);
meta_string.append((const char *)&time,sizeof(double));
meta_string += " <DataArray type=\"Float64\" Name=\"TimeValue\" NumberOfTuples=\"1\" format=\"binary\">\n";
//time = swap_endian_lt(time);
unsigned char time_string[24];//= base64_encode((const unsigned char*)&time,6);
//const unsigned char Time=(const unsigned char)time;
doubleint timeInit;
timeInit.i=8;
timeInit.d=time;
size_t sz=EncodeToBase64((const unsigned char*)&timeInit,16,time_string,0);
//meta_string.append((const char *)&time,sizeof(double));
//meta_string += time_string;
meta_string.append((const char *)time_string,sz);
}
meta_string += "\n";
meta_string += " </DataArray>\n";
meta_string += " </FieldData>\n";
}
return meta_string;
}
......@@ -400,6 +589,57 @@ public:
this->vpp.add(t2);
}
/*! \brief It write a Merged VTP type file from a vector of points
*
* \tparam prp_out which properties to output [default = -1 (all)]
*
* \return true if the write complete successfully
*
*/
bool write_pvtp(std::string file,const openfpm::vector<std::string> & prop_names,size_t n,size_t timestamp=-1)
{
//openfpm::vector< ele_vpp<typename pair::second>> vpp;
// Header for the vtk
std::string vtk_header;
std::string Name_data;
std::string PpointEnd;
std::string Piece;
vtk_header = "<VTKFile type=\"PPolyData\" version=\"1.0\" byte_order=\"LittleEndian\" header_type=\"UInt64\">\n <PPolyData>\n <PPointData>\n";
prop_out_v_pvtp< ele_vpp<typename pair::second>, typename pair::first::value_type::coord_type> pp(Name_data,prop_names);
boost::mpl::for_each< boost::mpl::range_c<int,0, pair::second::value_type::max_prop> >(pp);
pp.lastProp();
PpointEnd += " <PPoints>\n <PDataArray type=\""+getTypeNew<typename decltype(vps)::value_type::value_type::value_type::coord_type>()+"\" Name=\"Points\" NumberOfComponents=\"3\"/>\n </PPoints>\n";
if (timestamp==-1) {
for (int i = 0; i < n; i++)
{ Piece += " <Piece Source=\"" + file.substr(0, file.size()) + "_" +std::to_string(i) + ".vtp\"/>\n";}
file += ".pvtp";
}
else{
for (int i = 0; i < n; i++)
{ Piece += " <Piece Source=\"" + file.substr(0, file.size()) + "_" +std::to_string(i) + "_" + std::to_string(timestamp) + ".vtp\"/>\n";}
file += "_" + std::to_string(timestamp) + ".pvtp";
}
std::string closingFile=" </PPolyData>\n</VTKFile>";
// write the file
std::ofstream ofs(file);
// Check if the file is open
if (ofs.is_open() == false)
{std::cerr << "Error cannot create the PVTP file: " + file + "\n";}
ofs << vtk_header << Name_data <<PpointEnd<< Piece << closingFile;
// Close the file
ofs.close();
return true;
}
/*! \brief It write a VTK file from a vector of points
*
* \tparam prp_out which properties to output [default = -1 (all)]
......@@ -436,17 +676,18 @@ public:
std::string point_data;