Finishing the loading of variables into the visit writer
This commit is contained in:
109
IO/MPIHelpers.cpp
Normal file
109
IO/MPIHelpers.cpp
Normal file
@@ -0,0 +1,109 @@
|
|||||||
|
#include "IO/MPIHelpers.h"
|
||||||
|
|
||||||
|
namespace IO {
|
||||||
|
|
||||||
|
|
||||||
|
/********************************************************
|
||||||
|
* Concrete implimentations for packing/unpacking *
|
||||||
|
********************************************************/
|
||||||
|
// unsigned char
|
||||||
|
template<>
|
||||||
|
size_t packsize<unsigned char>( const unsigned char& rhs )
|
||||||
|
{
|
||||||
|
return sizeof(unsigned char);
|
||||||
|
}
|
||||||
|
template<>
|
||||||
|
void pack<unsigned char>( const unsigned char& rhs, char *buffer )
|
||||||
|
{
|
||||||
|
memcpy(buffer,&rhs,sizeof(unsigned char));
|
||||||
|
}
|
||||||
|
template<>
|
||||||
|
void unpack<unsigned char>( unsigned char& data, const char *buffer )
|
||||||
|
{
|
||||||
|
memcpy(&data,buffer,sizeof(unsigned char));
|
||||||
|
}
|
||||||
|
// char
|
||||||
|
template<>
|
||||||
|
size_t packsize<char>( const char& rhs )
|
||||||
|
{
|
||||||
|
return sizeof(char);
|
||||||
|
}
|
||||||
|
template<>
|
||||||
|
void pack<char>( const char& rhs, char *buffer )
|
||||||
|
{
|
||||||
|
memcpy(buffer,&rhs,sizeof(char));
|
||||||
|
}
|
||||||
|
template<>
|
||||||
|
void unpack<char>( char& data, const char *buffer )
|
||||||
|
{
|
||||||
|
memcpy(&data,buffer,sizeof(char));
|
||||||
|
}
|
||||||
|
// int
|
||||||
|
template<>
|
||||||
|
size_t packsize<int>( const int& rhs )
|
||||||
|
{
|
||||||
|
return sizeof(int);
|
||||||
|
}
|
||||||
|
template<>
|
||||||
|
void pack<int>( const int& rhs, char *buffer )
|
||||||
|
{
|
||||||
|
memcpy(buffer,&rhs,sizeof(int));
|
||||||
|
}
|
||||||
|
template<>
|
||||||
|
void unpack<int>( int& data, const char *buffer )
|
||||||
|
{
|
||||||
|
memcpy(&data,buffer,sizeof(int));
|
||||||
|
}
|
||||||
|
// unsigned int
|
||||||
|
template<>
|
||||||
|
size_t packsize<unsigned int>( const unsigned int& rhs )
|
||||||
|
{
|
||||||
|
return sizeof(unsigned int);
|
||||||
|
}
|
||||||
|
template<>
|
||||||
|
void pack<unsigned int>( const unsigned int& rhs, char *buffer )
|
||||||
|
{
|
||||||
|
memcpy(buffer,&rhs,sizeof(int));
|
||||||
|
}
|
||||||
|
template<>
|
||||||
|
void unpack<unsigned int>( unsigned int& data, const char *buffer )
|
||||||
|
{
|
||||||
|
memcpy(&data,buffer,sizeof(int));
|
||||||
|
}
|
||||||
|
// size_t
|
||||||
|
template<>
|
||||||
|
size_t packsize<size_t>( const size_t& rhs )
|
||||||
|
{
|
||||||
|
return sizeof(size_t);
|
||||||
|
}
|
||||||
|
template<>
|
||||||
|
void pack<size_t>( const size_t& rhs, char *buffer )
|
||||||
|
{
|
||||||
|
memcpy(buffer,&rhs,sizeof(size_t));
|
||||||
|
}
|
||||||
|
template<>
|
||||||
|
void unpack<size_t>( size_t& data, const char *buffer )
|
||||||
|
{
|
||||||
|
memcpy(&data,buffer,sizeof(size_t));
|
||||||
|
}
|
||||||
|
// std::string
|
||||||
|
template<>
|
||||||
|
size_t packsize<std::string>( const std::string& rhs )
|
||||||
|
{
|
||||||
|
return rhs.size()+1;
|
||||||
|
}
|
||||||
|
template<>
|
||||||
|
void pack<std::string>( const std::string& rhs, char *buffer )
|
||||||
|
{
|
||||||
|
memcpy(buffer,rhs.c_str(),rhs.size()+1);
|
||||||
|
}
|
||||||
|
template<>
|
||||||
|
void unpack<std::string>( std::string& data, const char *buffer )
|
||||||
|
{
|
||||||
|
data = std::string(buffer);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
223
IO/MPIHelpers.h
Normal file
223
IO/MPIHelpers.h
Normal file
@@ -0,0 +1,223 @@
|
|||||||
|
#ifndef MPI_HELPERS_INC
|
||||||
|
#define MPI_HELPERS_INC
|
||||||
|
|
||||||
|
#include <string.h>
|
||||||
|
#include <vector>
|
||||||
|
#include <set>
|
||||||
|
#include <map>
|
||||||
|
|
||||||
|
|
||||||
|
namespace IO {
|
||||||
|
|
||||||
|
|
||||||
|
//! Template function to return the buffer size required to pack a class
|
||||||
|
template<class TYPE>
|
||||||
|
size_t packsize( const TYPE& rhs );
|
||||||
|
|
||||||
|
//! Template function to pack a class to a buffer
|
||||||
|
template<class TYPE>
|
||||||
|
void pack( const TYPE& rhs, char *buffer );
|
||||||
|
|
||||||
|
//! Template function to unpack a class from a buffer
|
||||||
|
template<class TYPE>
|
||||||
|
void unpack( TYPE& data, const char *buffer );
|
||||||
|
|
||||||
|
|
||||||
|
//! Template function to return the buffer size required to pack a std::vector
|
||||||
|
template<class TYPE>
|
||||||
|
size_t packsize( const std::vector<TYPE>& rhs );
|
||||||
|
|
||||||
|
//! Template function to pack a class to a buffer
|
||||||
|
template<class TYPE>
|
||||||
|
void pack( const std::vector<TYPE>& rhs, char *buffer );
|
||||||
|
|
||||||
|
//! Template function to pack a class to a buffer
|
||||||
|
template<class TYPE>
|
||||||
|
void unpack( std::vector<TYPE>& data, const char *buffer );
|
||||||
|
|
||||||
|
|
||||||
|
//! Template function to return the buffer size required to pack a std::pair
|
||||||
|
template<class TYPE1, class TYPE2>
|
||||||
|
size_t packsize( const std::pair<TYPE1,TYPE2>& rhs );
|
||||||
|
|
||||||
|
//! Template function to pack a class to a buffer
|
||||||
|
template<class TYPE1, class TYPE2>
|
||||||
|
void pack( const std::pair<TYPE1,TYPE2>& rhs, char *buffer );
|
||||||
|
|
||||||
|
//! Template function to pack a class to a buffer
|
||||||
|
template<class TYPE1, class TYPE2>
|
||||||
|
void unpack( std::pair<TYPE1,TYPE2>& data, const char *buffer );
|
||||||
|
|
||||||
|
|
||||||
|
//! Template function to return the buffer size required to pack a std::map
|
||||||
|
template<class TYPE1, class TYPE2>
|
||||||
|
size_t packsize( const std::map<TYPE1,TYPE2>& rhs );
|
||||||
|
|
||||||
|
//! Template function to pack a class to a buffer
|
||||||
|
template<class TYPE1, class TYPE2>
|
||||||
|
void pack( const std::map<TYPE1,TYPE2>& rhs, char *buffer );
|
||||||
|
|
||||||
|
//! Template function to pack a class to a buffer
|
||||||
|
template<class TYPE1, class TYPE2>
|
||||||
|
void unpack( std::map<TYPE1,TYPE2>& data, const char *buffer );
|
||||||
|
|
||||||
|
|
||||||
|
//! Template function to return the buffer size required to pack a std::set
|
||||||
|
template<class TYPE>
|
||||||
|
size_t packsize( const std::set<TYPE>& rhs );
|
||||||
|
|
||||||
|
//! Template function to pack a class to a buffer
|
||||||
|
template<class TYPE>
|
||||||
|
void pack( const std::set<TYPE>& rhs, char *buffer );
|
||||||
|
|
||||||
|
//! Template function to pack a class to a buffer
|
||||||
|
template<class TYPE>
|
||||||
|
void unpack( std::set<TYPE>& data, const char *buffer );
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/********************************************************
|
||||||
|
* Default instantiations for std::vector *
|
||||||
|
********************************************************/
|
||||||
|
template<class TYPE>
|
||||||
|
size_t packsize( const std::vector<TYPE>& rhs )
|
||||||
|
{
|
||||||
|
size_t bytes = sizeof(size_t);
|
||||||
|
for (size_t i=0; i<rhs.size(); i++)
|
||||||
|
bytes += packsize(rhs[i]);
|
||||||
|
return bytes;
|
||||||
|
}
|
||||||
|
template<class TYPE>
|
||||||
|
void pack( const std::vector<TYPE>& rhs, char *buffer )
|
||||||
|
{
|
||||||
|
size_t size = rhs.size();
|
||||||
|
memcpy(buffer,&size,sizeof(size_t));
|
||||||
|
size_t pos = sizeof(size_t);
|
||||||
|
for (int i=0; i<rhs.size(); i++) {
|
||||||
|
pack(rhs[i],&buffer[pos]);
|
||||||
|
pos += packsize(rhs[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
template<class TYPE>
|
||||||
|
void unpack( std::vector<TYPE>& data, const char *buffer )
|
||||||
|
{
|
||||||
|
size_t size;
|
||||||
|
memcpy(&size,buffer,sizeof(size_t));
|
||||||
|
data.clear();
|
||||||
|
data.resize(size);
|
||||||
|
size_t pos = sizeof(size_t);
|
||||||
|
for (int i=0; i<data.size(); i++) {
|
||||||
|
unpack(data[i],&buffer[pos]);
|
||||||
|
pos += packsize(data[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/********************************************************
|
||||||
|
* Default instantiations for std::pair *
|
||||||
|
********************************************************/
|
||||||
|
template<class TYPE1, class TYPE2>
|
||||||
|
size_t packsize( const std::pair<TYPE1,TYPE2>& rhs )
|
||||||
|
{
|
||||||
|
return packsize(rhs.first)+packsize(rhs.second);
|
||||||
|
}
|
||||||
|
template<class TYPE1, class TYPE2>
|
||||||
|
void pack( const std::pair<TYPE1,TYPE2>& rhs, char *buffer )
|
||||||
|
{
|
||||||
|
pack(rhs.first,buffer);
|
||||||
|
pack(rhs.second,&buffer[packsize(rhs.first)]);
|
||||||
|
}
|
||||||
|
template<class TYPE1, class TYPE2>
|
||||||
|
void unpack( std::pair<TYPE1,TYPE2>& data, const char *buffer )
|
||||||
|
{
|
||||||
|
unpack(data.first,buffer);
|
||||||
|
unpack(data.second,&buffer[packsize(data.first)]);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/********************************************************
|
||||||
|
* Default instantiations for std::map *
|
||||||
|
********************************************************/
|
||||||
|
template<class TYPE1, class TYPE2>
|
||||||
|
size_t packsize( const std::map<TYPE1,TYPE2>& rhs )
|
||||||
|
{
|
||||||
|
size_t bytes = sizeof(size_t);
|
||||||
|
typename std::map<TYPE1,TYPE2>::const_iterator it;
|
||||||
|
for (it=rhs.begin(); it!=rhs.end(); ++it) {
|
||||||
|
bytes += packsize(it->first);
|
||||||
|
bytes += packsize(it->second);
|
||||||
|
}
|
||||||
|
return bytes;
|
||||||
|
}
|
||||||
|
template<class TYPE1, class TYPE2>
|
||||||
|
void pack( const std::map<TYPE1,TYPE2>& rhs, char *buffer )
|
||||||
|
{
|
||||||
|
size_t N = rhs.size();
|
||||||
|
pack(N,buffer);
|
||||||
|
size_t pos = sizeof(size_t);
|
||||||
|
typename std::map<TYPE1,TYPE2>::const_iterator it;
|
||||||
|
for (it=rhs.begin(); it!=rhs.end(); ++it) {
|
||||||
|
pack(it->first,&buffer[pos]); pos+=packsize(it->first);
|
||||||
|
pack(it->second,&buffer[pos]); pos+=packsize(it->second);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
template<class TYPE1, class TYPE2>
|
||||||
|
void unpack( std::map<TYPE1,TYPE2>& data, const char *buffer )
|
||||||
|
{
|
||||||
|
size_t N = 0;
|
||||||
|
unpack(N,buffer);
|
||||||
|
size_t pos = sizeof(size_t);
|
||||||
|
data.clear();
|
||||||
|
for (size_t i=0; i<N; i++) {
|
||||||
|
std::pair<TYPE1,TYPE2> tmp;
|
||||||
|
unpack(tmp.first,&buffer[pos]); pos+=packsize(tmp.first);
|
||||||
|
unpack(tmp.second,&buffer[pos]); pos+=packsize(tmp.second);
|
||||||
|
data.insert(tmp);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/********************************************************
|
||||||
|
* Default instantiations for std::set *
|
||||||
|
********************************************************/
|
||||||
|
template<class TYPE>
|
||||||
|
size_t packsize( const std::set<TYPE>& rhs )
|
||||||
|
{
|
||||||
|
size_t bytes = sizeof(size_t);
|
||||||
|
typename std::set<TYPE>::const_iterator it;
|
||||||
|
for (it=rhs.begin(); it!=rhs.end(); ++it) {
|
||||||
|
bytes += packsize(*it);
|
||||||
|
}
|
||||||
|
return bytes;
|
||||||
|
}
|
||||||
|
template<class TYPE>
|
||||||
|
void pack( const std::set<TYPE>& rhs, char *buffer )
|
||||||
|
{
|
||||||
|
size_t N = rhs.size();
|
||||||
|
pack(N,buffer);
|
||||||
|
size_t pos = sizeof(size_t);
|
||||||
|
typename std::set<TYPE>::const_iterator it;
|
||||||
|
for (it=rhs.begin(); it!=rhs.end(); ++it) {
|
||||||
|
pack(*it); pos+=packsize(*it);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
template<class TYPE>
|
||||||
|
void unpack( std::set<TYPE>& data, const char *buffer )
|
||||||
|
{
|
||||||
|
size_t N = 0;
|
||||||
|
unpack(N,buffer);
|
||||||
|
size_t pos = sizeof(size_t);
|
||||||
|
data.clear();
|
||||||
|
for (size_t i=0; i<N; i++) {
|
||||||
|
TYPE tmp;
|
||||||
|
unpack(tmp,&buffer[pos]); pos+=packsize(tmp);
|
||||||
|
data.insert(tmp);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
37
IO/Mesh.cpp
37
IO/Mesh.cpp
@@ -42,6 +42,13 @@ PointList::PointList( size_t N )
|
|||||||
PointList::~PointList( )
|
PointList::~PointList( )
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
size_t PointList::numberPointsVar( VariableType type ) const
|
||||||
|
{
|
||||||
|
size_t N = 0;
|
||||||
|
if ( type == VariableType::NodeVariable )
|
||||||
|
N = points.size();
|
||||||
|
return N;
|
||||||
|
}
|
||||||
std::pair<size_t,void*> PointList::pack( int level ) const
|
std::pair<size_t,void*> PointList::pack( int level ) const
|
||||||
{
|
{
|
||||||
std::pair<size_t,void*> data_out(0,NULL);
|
std::pair<size_t,void*> data_out(0,NULL);
|
||||||
@@ -111,6 +118,15 @@ TriList::TriList( const TriMesh& mesh )
|
|||||||
TriList::~TriList( )
|
TriList::~TriList( )
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
size_t TriList::numberPointsVar( VariableType type ) const
|
||||||
|
{
|
||||||
|
size_t N = 0;
|
||||||
|
if ( type==VariableType::NodeVariable )
|
||||||
|
N = 3*A.size();
|
||||||
|
else if ( type==VariableType::SurfaceVariable || type==VariableType::VolumeVariable )
|
||||||
|
N = A.size();
|
||||||
|
return N;
|
||||||
|
}
|
||||||
std::pair<size_t,void*> TriList::pack( int level ) const
|
std::pair<size_t,void*> TriList::pack( int level ) const
|
||||||
{
|
{
|
||||||
std::pair<size_t,void*> data_out(0,NULL);
|
std::pair<size_t,void*> data_out(0,NULL);
|
||||||
@@ -207,6 +223,15 @@ TriMesh::~TriMesh( )
|
|||||||
B.clear();
|
B.clear();
|
||||||
C.clear();
|
C.clear();
|
||||||
}
|
}
|
||||||
|
size_t TriMesh::numberPointsVar( VariableType type ) const
|
||||||
|
{
|
||||||
|
size_t N = 0;
|
||||||
|
if ( type==VariableType::NodeVariable )
|
||||||
|
N = vertices->points.size();
|
||||||
|
else if ( type==VariableType::SurfaceVariable || type==VariableType::VolumeVariable )
|
||||||
|
N = A.size();
|
||||||
|
return N;
|
||||||
|
}
|
||||||
std::pair<size_t,void*> TriMesh::pack( int level ) const
|
std::pair<size_t,void*> TriMesh::pack( int level ) const
|
||||||
{
|
{
|
||||||
std::pair<size_t,void*> data_out(0,NULL);
|
std::pair<size_t,void*> data_out(0,NULL);
|
||||||
@@ -296,6 +321,18 @@ std::shared_ptr<TriList> getTriList( std::shared_ptr<Mesh> mesh )
|
|||||||
}
|
}
|
||||||
return mesh2;
|
return mesh2;
|
||||||
}
|
}
|
||||||
|
std::shared_ptr<const PointList> getPointList( std::shared_ptr<const Mesh> mesh )
|
||||||
|
{
|
||||||
|
return getPointList( std::const_pointer_cast<Mesh>(mesh) );
|
||||||
|
}
|
||||||
|
std::shared_ptr<const TriMesh> getTriMesh( std::shared_ptr<const Mesh> mesh )
|
||||||
|
{
|
||||||
|
return getTriMesh( std::const_pointer_cast<Mesh>(mesh) );
|
||||||
|
}
|
||||||
|
std::shared_ptr<const TriList> getTriList( std::shared_ptr<const Mesh> mesh )
|
||||||
|
{
|
||||||
|
return getTriList( std::const_pointer_cast<Mesh>(mesh) );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
} // IO namespace
|
} // IO namespace
|
||||||
|
|||||||
16
IO/Mesh.h
16
IO/Mesh.h
@@ -12,6 +12,10 @@
|
|||||||
namespace IO {
|
namespace IO {
|
||||||
|
|
||||||
|
|
||||||
|
//! Possible variable types
|
||||||
|
enum class VariableType : unsigned char { NodeVariable=1, EdgeVariable=2, SurfaceVariable=2, VolumeVariable=3, Null=0 };
|
||||||
|
|
||||||
|
|
||||||
/*! \class Mesh
|
/*! \class Mesh
|
||||||
\brief A base class for meshes
|
\brief A base class for meshes
|
||||||
*/
|
*/
|
||||||
@@ -22,6 +26,8 @@ public:
|
|||||||
virtual ~Mesh();
|
virtual ~Mesh();
|
||||||
//! Mesh class name (eg. PointList)
|
//! Mesh class name (eg. PointList)
|
||||||
virtual std::string className() const = 0;
|
virtual std::string className() const = 0;
|
||||||
|
//! Number of points for the given variable type
|
||||||
|
virtual size_t numberPointsVar( VariableType type ) const = 0;
|
||||||
//! Pack the data
|
//! Pack the data
|
||||||
virtual std::pair<size_t,void*> pack( int level ) const = 0;
|
virtual std::pair<size_t,void*> pack( int level ) const = 0;
|
||||||
//! Unpack the data
|
//! Unpack the data
|
||||||
@@ -48,6 +54,8 @@ public:
|
|||||||
virtual ~PointList();
|
virtual ~PointList();
|
||||||
//! Mesh class name
|
//! Mesh class name
|
||||||
virtual std::string className() const { return "PointList"; }
|
virtual std::string className() const { return "PointList"; }
|
||||||
|
//! Number of points for the given variable type
|
||||||
|
virtual size_t numberPointsVar( VariableType type ) const;
|
||||||
//! Pack the data
|
//! Pack the data
|
||||||
virtual std::pair<size_t,void*> pack( int level ) const;
|
virtual std::pair<size_t,void*> pack( int level ) const;
|
||||||
//! Unpack the data
|
//! Unpack the data
|
||||||
@@ -76,6 +84,8 @@ public:
|
|||||||
virtual ~TriMesh();
|
virtual ~TriMesh();
|
||||||
//! Mesh class name
|
//! Mesh class name
|
||||||
virtual std::string className() const { return "TriMesh"; }
|
virtual std::string className() const { return "TriMesh"; }
|
||||||
|
//! Number of points for the given variable type
|
||||||
|
virtual size_t numberPointsVar( VariableType type ) const;
|
||||||
//! Pack the data
|
//! Pack the data
|
||||||
virtual std::pair<size_t,void*> pack( int level ) const;
|
virtual std::pair<size_t,void*> pack( int level ) const;
|
||||||
//! Unpack the data
|
//! Unpack the data
|
||||||
@@ -104,6 +114,8 @@ public:
|
|||||||
virtual ~TriList();
|
virtual ~TriList();
|
||||||
//! Mesh class name
|
//! Mesh class name
|
||||||
virtual std::string className() const { return "TriList"; }
|
virtual std::string className() const { return "TriList"; }
|
||||||
|
//! Number of points for the given variable type
|
||||||
|
virtual size_t numberPointsVar( VariableType type ) const;
|
||||||
//! Pack the data
|
//! Pack the data
|
||||||
virtual std::pair<size_t,void*> pack( int level ) const;
|
virtual std::pair<size_t,void*> pack( int level ) const;
|
||||||
//! Unpack the data
|
//! Unpack the data
|
||||||
@@ -122,7 +134,6 @@ public:
|
|||||||
struct Variable
|
struct Variable
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
enum class VariableType : unsigned char { NodeVariable=1, EdgeVariable=2, SurfaceVariable=2, VolumeVariable=3, Null=0 };
|
|
||||||
// Internal variables
|
// Internal variables
|
||||||
unsigned int dim; //!< Number of points per grid point (1: scalar, 3: vector, ...)
|
unsigned int dim; //!< Number of points per grid point (1: scalar, 3: vector, ...)
|
||||||
VariableType type; //!< Variable type
|
VariableType type; //!< Variable type
|
||||||
@@ -154,6 +165,9 @@ struct MeshDataStruct {
|
|||||||
std::shared_ptr<PointList> getPointList( std::shared_ptr<Mesh> mesh );
|
std::shared_ptr<PointList> getPointList( std::shared_ptr<Mesh> mesh );
|
||||||
std::shared_ptr<TriMesh> getTriMesh( std::shared_ptr<Mesh> mesh );
|
std::shared_ptr<TriMesh> getTriMesh( std::shared_ptr<Mesh> mesh );
|
||||||
std::shared_ptr<TriList> getTriList( std::shared_ptr<Mesh> mesh );
|
std::shared_ptr<TriList> getTriList( std::shared_ptr<Mesh> mesh );
|
||||||
|
std::shared_ptr<const PointList> getPointList( std::shared_ptr<const Mesh> mesh );
|
||||||
|
std::shared_ptr<const TriMesh> getTriMesh( std::shared_ptr<const Mesh> mesh );
|
||||||
|
std::shared_ptr<const TriList> getTriList( std::shared_ptr<const Mesh> mesh );
|
||||||
|
|
||||||
|
|
||||||
} // IO namespace
|
} // IO namespace
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
#include "IO/MeshDatabase.h"
|
#include "IO/MeshDatabase.h"
|
||||||
#include "IO/Mesh.h"
|
#include "IO/Mesh.h"
|
||||||
#include "IO/IOHelpers.h"
|
#include "IO/IOHelpers.h"
|
||||||
|
#include "IO/MPIHelpers.h"
|
||||||
#include "common/Utilities.h"
|
#include "common/Utilities.h"
|
||||||
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
@@ -16,149 +17,6 @@ namespace IO {
|
|||||||
/****************************************************
|
/****************************************************
|
||||||
* Pack/unpack data from a buffer *
|
* Pack/unpack data from a buffer *
|
||||||
****************************************************/
|
****************************************************/
|
||||||
template<class TYPE>
|
|
||||||
size_t packsize( const TYPE& rhs );
|
|
||||||
template<class TYPE>
|
|
||||||
void pack( const TYPE& rhs, char *buffer );
|
|
||||||
template<class TYPE>
|
|
||||||
void unpack( TYPE& data, const char *buffer );
|
|
||||||
// std::vector
|
|
||||||
template<class TYPE>
|
|
||||||
size_t packsize( const std::vector<TYPE>& rhs )
|
|
||||||
{
|
|
||||||
size_t bytes = sizeof(size_t);
|
|
||||||
for (size_t i=0; i<rhs.size(); i++)
|
|
||||||
bytes += packsize(rhs[i]);
|
|
||||||
return bytes;
|
|
||||||
}
|
|
||||||
template<class TYPE>
|
|
||||||
void pack( const std::vector<TYPE>& rhs, char *buffer )
|
|
||||||
{
|
|
||||||
size_t size = rhs.size();
|
|
||||||
memcpy(buffer,&size,sizeof(size_t));
|
|
||||||
size_t pos = sizeof(size_t);
|
|
||||||
for (int i=0; i<rhs.size(); i++) {
|
|
||||||
pack(rhs[i],&buffer[pos]);
|
|
||||||
pos += packsize(rhs[i]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
template<class TYPE>
|
|
||||||
void unpack( std::vector<TYPE>& data, const char *buffer )
|
|
||||||
{
|
|
||||||
size_t size;
|
|
||||||
memcpy(&size,buffer,sizeof(size_t));
|
|
||||||
data.clear();
|
|
||||||
data.resize(size);
|
|
||||||
size_t pos = sizeof(size_t);
|
|
||||||
for (int i=0; i<data.size(); i++) {
|
|
||||||
unpack(data[i],&buffer[pos]);
|
|
||||||
pos += packsize(data[i]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// std::pair
|
|
||||||
template<class TYPE1, class TYPE2>
|
|
||||||
size_t packsize( const std::pair<TYPE1,TYPE2>& rhs )
|
|
||||||
{
|
|
||||||
return packsize(rhs.first)+packsize(rhs.second);
|
|
||||||
}
|
|
||||||
template<class TYPE1, class TYPE2>
|
|
||||||
void pack( const std::pair<TYPE1,TYPE2>& rhs, char *buffer )
|
|
||||||
{
|
|
||||||
pack(rhs.first,buffer);
|
|
||||||
pack(rhs.second,&buffer[packsize(rhs.first)]);
|
|
||||||
}
|
|
||||||
template<class TYPE1, class TYPE2>
|
|
||||||
void unpack( std::pair<TYPE1,TYPE2>& data, const char *buffer )
|
|
||||||
{
|
|
||||||
unpack(data.first,buffer);
|
|
||||||
unpack(data.second,&buffer[packsize(data.first)]);
|
|
||||||
}
|
|
||||||
// std::map
|
|
||||||
template<class TYPE1, class TYPE2>
|
|
||||||
size_t packsize( const std::map<TYPE1,TYPE2>& rhs )
|
|
||||||
{
|
|
||||||
size_t bytes = sizeof(size_t);
|
|
||||||
typename std::map<TYPE1,TYPE2>::const_iterator it;
|
|
||||||
for (it=rhs.begin(); it!=rhs.end(); ++it) {
|
|
||||||
bytes += packsize(it->first);
|
|
||||||
bytes += packsize(it->second);
|
|
||||||
}
|
|
||||||
return bytes;
|
|
||||||
}
|
|
||||||
template<class TYPE1, class TYPE2>
|
|
||||||
void pack( const std::map<TYPE1,TYPE2>& rhs, char *buffer )
|
|
||||||
{
|
|
||||||
size_t N = rhs.size();
|
|
||||||
pack(N,buffer);
|
|
||||||
size_t pos = sizeof(size_t);
|
|
||||||
typename std::map<TYPE1,TYPE2>::const_iterator it;
|
|
||||||
for (it=rhs.begin(); it!=rhs.end(); ++it) {
|
|
||||||
pack(it->first,&buffer[pos]); pos+=packsize(it->first);
|
|
||||||
pack(it->second,&buffer[pos]); pos+=packsize(it->second);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
template<class TYPE1, class TYPE2>
|
|
||||||
void unpack( std::map<TYPE1,TYPE2>& data, const char *buffer )
|
|
||||||
{
|
|
||||||
size_t N = 0;
|
|
||||||
unpack(N,buffer);
|
|
||||||
size_t pos = sizeof(size_t);
|
|
||||||
data.clear();
|
|
||||||
for (size_t i=0; i<N; i++) {
|
|
||||||
std::pair<TYPE1,TYPE2> tmp;
|
|
||||||
unpack(tmp.first,&buffer[pos]); pos+=packsize(tmp.first);
|
|
||||||
unpack(tmp.second,&buffer[pos]); pos+=packsize(tmp.second);
|
|
||||||
data.insert(tmp);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// size_t
|
|
||||||
template<>
|
|
||||||
size_t packsize<size_t>( const size_t& rhs )
|
|
||||||
{
|
|
||||||
return sizeof(size_t);
|
|
||||||
}
|
|
||||||
template<>
|
|
||||||
void pack<size_t>( const size_t& rhs, char *buffer )
|
|
||||||
{
|
|
||||||
memcpy(buffer,&rhs,sizeof(size_t));
|
|
||||||
}
|
|
||||||
template<>
|
|
||||||
void unpack<size_t>( size_t& data, const char *buffer )
|
|
||||||
{
|
|
||||||
memcpy(&data,buffer,sizeof(size_t));
|
|
||||||
}
|
|
||||||
// unsigned char
|
|
||||||
template<>
|
|
||||||
size_t packsize<unsigned char>( const unsigned char& rhs )
|
|
||||||
{
|
|
||||||
return sizeof(unsigned char);
|
|
||||||
}
|
|
||||||
template<>
|
|
||||||
void pack<unsigned char>( const unsigned char& rhs, char *buffer )
|
|
||||||
{
|
|
||||||
memcpy(buffer,&rhs,sizeof(unsigned char));
|
|
||||||
}
|
|
||||||
template<>
|
|
||||||
void unpack<unsigned char>( unsigned char& data, const char *buffer )
|
|
||||||
{
|
|
||||||
memcpy(&data,buffer,sizeof(unsigned char));
|
|
||||||
}
|
|
||||||
// std::string
|
|
||||||
template<>
|
|
||||||
size_t packsize<std::string>( const std::string& rhs )
|
|
||||||
{
|
|
||||||
return rhs.size()+1;
|
|
||||||
}
|
|
||||||
template<>
|
|
||||||
void pack<std::string>( const std::string& rhs, char *buffer )
|
|
||||||
{
|
|
||||||
memcpy(buffer,rhs.c_str(),rhs.size()+1);
|
|
||||||
}
|
|
||||||
template<>
|
|
||||||
void unpack<std::string>( std::string& data, const char *buffer )
|
|
||||||
{
|
|
||||||
data = std::string(buffer);
|
|
||||||
}
|
|
||||||
// MeshType
|
// MeshType
|
||||||
template<>
|
template<>
|
||||||
size_t packsize<MeshType>( const MeshType& rhs )
|
size_t packsize<MeshType>( const MeshType& rhs )
|
||||||
@@ -175,6 +33,22 @@ void unpack<MeshType>( MeshType& data, const char *buffer )
|
|||||||
{
|
{
|
||||||
memcpy(&data,buffer,sizeof(MeshType));
|
memcpy(&data,buffer,sizeof(MeshType));
|
||||||
}
|
}
|
||||||
|
// Variable::VariableType
|
||||||
|
template<>
|
||||||
|
size_t packsize<VariableType>( const VariableType& rhs )
|
||||||
|
{
|
||||||
|
return sizeof(VariableType);
|
||||||
|
}
|
||||||
|
template<>
|
||||||
|
void pack<VariableType>( const VariableType& rhs, char *buffer )
|
||||||
|
{
|
||||||
|
memcpy(buffer,&rhs,sizeof(MeshType));
|
||||||
|
}
|
||||||
|
template<>
|
||||||
|
void unpack<VariableType>( VariableType& data, const char *buffer )
|
||||||
|
{
|
||||||
|
memcpy(&data,buffer,sizeof(MeshType));
|
||||||
|
}
|
||||||
// DatabaseEntry
|
// DatabaseEntry
|
||||||
template<>
|
template<>
|
||||||
size_t packsize<DatabaseEntry>( const DatabaseEntry& rhs )
|
size_t packsize<DatabaseEntry>( const DatabaseEntry& rhs )
|
||||||
@@ -193,9 +67,31 @@ template<>
|
|||||||
void unpack<DatabaseEntry>( DatabaseEntry& data, const char *buffer )
|
void unpack<DatabaseEntry>( DatabaseEntry& data, const char *buffer )
|
||||||
{
|
{
|
||||||
size_t i=0;
|
size_t i=0;
|
||||||
unpack(data.name,&buffer[i]); i+=packsize(data.name);
|
unpack(data.name,&buffer[i]); i+=packsize(data.name);
|
||||||
unpack(data.file,&buffer[i]); i+=packsize(data.file);
|
unpack(data.file,&buffer[i]); i+=packsize(data.file);
|
||||||
unpack(data.offset,&buffer[i]); i+=packsize(data.offset);
|
unpack(data.offset,&buffer[i]); i+=packsize(data.offset);
|
||||||
|
}
|
||||||
|
// VariableDatabase
|
||||||
|
template<>
|
||||||
|
size_t packsize<VariableDatabase>( const VariableDatabase& rhs )
|
||||||
|
{
|
||||||
|
return packsize(rhs.name)+packsize(rhs.type)+packsize(rhs.dim);
|
||||||
|
}
|
||||||
|
template<>
|
||||||
|
void pack<VariableDatabase>( const VariableDatabase& rhs, char *buffer )
|
||||||
|
{
|
||||||
|
size_t i=0;
|
||||||
|
pack(rhs.name,&buffer[i]); i+=packsize(rhs.name);
|
||||||
|
pack(rhs.type,&buffer[i]); i+=packsize(rhs.type);
|
||||||
|
pack(rhs.dim,&buffer[i]); i+=packsize(rhs.dim);
|
||||||
|
}
|
||||||
|
template<>
|
||||||
|
void unpack<VariableDatabase>( VariableDatabase& data, const char *buffer )
|
||||||
|
{
|
||||||
|
size_t i=0;
|
||||||
|
unpack(data.name,&buffer[i]); i+=packsize(data.name);
|
||||||
|
unpack(data.type,&buffer[i]); i+=packsize(data.type);
|
||||||
|
unpack(data.dim,&buffer[i]); i+=packsize(data.dim);
|
||||||
}
|
}
|
||||||
// MeshDatabase
|
// MeshDatabase
|
||||||
template<>
|
template<>
|
||||||
@@ -235,6 +131,47 @@ void unpack<MeshDatabase>( MeshDatabase& data, const char *buffer )
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/****************************************************
|
||||||
|
* VariableDatabase *
|
||||||
|
****************************************************/
|
||||||
|
bool VariableDatabase::operator==(const VariableDatabase& rhs ) const
|
||||||
|
{
|
||||||
|
return type==rhs.type && dim==rhs.dim && name==rhs.name;
|
||||||
|
}
|
||||||
|
bool VariableDatabase::operator!=(const VariableDatabase& rhs ) const
|
||||||
|
{
|
||||||
|
return type!=rhs.type || dim!=rhs.dim || name!=rhs.name;
|
||||||
|
}
|
||||||
|
bool VariableDatabase::operator>=(const VariableDatabase& rhs ) const
|
||||||
|
{
|
||||||
|
return operator>(rhs) || operator==(rhs);
|
||||||
|
}
|
||||||
|
bool VariableDatabase::operator<=(const VariableDatabase& rhs ) const
|
||||||
|
{
|
||||||
|
return !operator>(rhs);
|
||||||
|
}
|
||||||
|
bool VariableDatabase::operator>(const VariableDatabase& rhs ) const
|
||||||
|
{
|
||||||
|
if ( name>rhs.name )
|
||||||
|
return true;
|
||||||
|
else if ( name<rhs.name )
|
||||||
|
return false;
|
||||||
|
if ( type>rhs.type )
|
||||||
|
return true;
|
||||||
|
else if ( type<rhs.type )
|
||||||
|
return false;
|
||||||
|
if ( dim>rhs.dim )
|
||||||
|
return true;
|
||||||
|
else if ( dim<rhs.dim )
|
||||||
|
return false;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
bool VariableDatabase::operator<(const VariableDatabase& rhs ) const
|
||||||
|
{
|
||||||
|
return !operator>(rhs) && operator!=(rhs);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/****************************************************
|
/****************************************************
|
||||||
* MeshDatabase *
|
* MeshDatabase *
|
||||||
****************************************************/
|
****************************************************/
|
||||||
@@ -351,8 +288,8 @@ std::vector<MeshDatabase> gatherAll( const std::vector<MeshDatabase>& meshes, MP
|
|||||||
}
|
}
|
||||||
for (std::map<std::string,MeshDatabase>::iterator it=data.begin(); it!=data.end(); ++it) {
|
for (std::map<std::string,MeshDatabase>::iterator it=data.begin(); it!=data.end(); ++it) {
|
||||||
// Get the unique variables
|
// Get the unique variables
|
||||||
std::set<std::string> data2(it->second.variables.begin(),it->second.variables.end());
|
std::set<VariableDatabase> data2(it->second.variables.begin(),it->second.variables.end());
|
||||||
it->second.variables = std::vector<std::string>(data2.begin(),data2.end());
|
it->second.variables = std::vector<VariableDatabase>(data2.begin(),data2.end());
|
||||||
}
|
}
|
||||||
// Free temporary memory
|
// Free temporary memory
|
||||||
delete [] localbuf;
|
delete [] localbuf;
|
||||||
@@ -383,7 +320,8 @@ void write( const std::vector<MeshDatabase>& meshes, const std::string& filename
|
|||||||
fprintf(fid," domain: %s\n",meshes[i].domains[j].write().c_str());
|
fprintf(fid," domain: %s\n",meshes[i].domains[j].write().c_str());
|
||||||
fprintf(fid," variables: ");
|
fprintf(fid," variables: ");
|
||||||
for (size_t j=0; j<meshes[i].variables.size(); j++) {
|
for (size_t j=0; j<meshes[i].variables.size(); j++) {
|
||||||
fprintf(fid,"%s; ",meshes[i].variables[j].c_str());
|
const VariableDatabase& var = meshes[i].variables[j];
|
||||||
|
fprintf(fid,"%s|%i|%i; ",var.name.c_str(),static_cast<int>(var.type),var.dim);
|
||||||
}
|
}
|
||||||
fprintf(fid,"\n");
|
fprintf(fid,"\n");
|
||||||
std::map<std::pair<std::string,std::string>,DatabaseEntry>::const_iterator it;
|
std::map<std::pair<std::string,std::string>,DatabaseEntry>::const_iterator it;
|
||||||
@@ -426,7 +364,16 @@ std::vector<MeshDatabase> read( const std::string& filename )
|
|||||||
DatabaseEntry data(&line[10]);
|
DatabaseEntry data(&line[10]);
|
||||||
meshes.back().domains.push_back(data);
|
meshes.back().domains.push_back(data);
|
||||||
} else if ( strncmp(line," variables:",13)==0 ) {
|
} else if ( strncmp(line," variables:",13)==0 ) {
|
||||||
meshes.back().variables = splitList(&line[13],';');
|
MeshDatabase& mesh = meshes.back();
|
||||||
|
std::vector<std::string> variables = splitList(&line[13],';');
|
||||||
|
mesh.variables.resize(variables.size());
|
||||||
|
for (size_t i=0; i<variables.size(); i++) {
|
||||||
|
std::vector<std::string> tmp = splitList(variables[i].c_str(),'|');
|
||||||
|
ASSERT(tmp.size()==3);
|
||||||
|
mesh.variables[i].name = tmp[0];
|
||||||
|
mesh.variables[i].type = static_cast<VariableType>(atoi(tmp[1].c_str()));
|
||||||
|
mesh.variables[i].dim = atoi(tmp[2].c_str());
|
||||||
|
}
|
||||||
} else if ( strncmp(line," variable(",12)==0 ) {
|
} else if ( strncmp(line," variable(",12)==0 ) {
|
||||||
size_t i1 = find(line,',');
|
size_t i1 = find(line,',');
|
||||||
size_t i2 = find(line,':');
|
size_t i2 = find(line,':');
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
#ifndef MeshDatabase_INC
|
#ifndef MeshDatabase_INC
|
||||||
#define MeshDatabase_INC
|
#define MeshDatabase_INC
|
||||||
|
|
||||||
|
#include "IO/Mesh.h"
|
||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
@@ -37,15 +39,31 @@ struct DatabaseEntry {
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
//! Structure to hold the info about the variables
|
||||||
|
struct VariableDatabase {
|
||||||
|
std::string name; //!< Name of the variable
|
||||||
|
IO::VariableType type; //!< Variable
|
||||||
|
unsigned int dim; //!< Number of points per grid point (1: scalar, 3: vector, ...)
|
||||||
|
// Overload key operators
|
||||||
|
bool operator==(const VariableDatabase& rhs ) const;
|
||||||
|
bool operator!=(const VariableDatabase& rhs ) const;
|
||||||
|
bool operator>=(const VariableDatabase& rhs ) const;
|
||||||
|
bool operator<=(const VariableDatabase& rhs ) const;
|
||||||
|
bool operator> (const VariableDatabase& rhs ) const;
|
||||||
|
bool operator< (const VariableDatabase& rhs ) const;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
//! Structure to hold the info about the meshes
|
//! Structure to hold the info about the meshes
|
||||||
struct MeshDatabase {
|
struct MeshDatabase {
|
||||||
|
typedef std::pair<std::string,std::string> variable_id;
|
||||||
std::string name; //!< Name of the mesh
|
std::string name; //!< Name of the mesh
|
||||||
MeshType type; //!< Mesh type
|
MeshType type; //!< Mesh type
|
||||||
std::string meshClass; //!< Mesh class
|
std::string meshClass; //!< Mesh class
|
||||||
unsigned char format; //!< Data format
|
unsigned char format; //!< Data format
|
||||||
std::vector<DatabaseEntry> domains; //!< List of the domains
|
std::vector<DatabaseEntry> domains; //!< List of the domains
|
||||||
std::vector<std::string> variables; //!< List of the variables
|
std::vector<VariableDatabase> variables; //!< List of the variables
|
||||||
std::map<std::pair<std::string,std::string>,DatabaseEntry> variable_data; //!< Data for the variables
|
std::map<variable_id,DatabaseEntry> variable_data; //!< Data for the variables
|
||||||
public:
|
public:
|
||||||
MeshDatabase();
|
MeshDatabase();
|
||||||
~MeshDatabase();
|
~MeshDatabase();
|
||||||
|
|||||||
@@ -160,7 +160,7 @@ std::shared_ptr<IO::Variable> IO::getVariable( const std::string& path, const st
|
|||||||
ASSERT(count==bytes);
|
ASSERT(count==bytes);
|
||||||
std::shared_ptr<IO::Variable> var( new IO::Variable() );
|
std::shared_ptr<IO::Variable> var( new IO::Variable() );
|
||||||
var->dim = dim;
|
var->dim = dim;
|
||||||
var->type = static_cast<IO::Variable::VariableType>(type);
|
var->type = static_cast<IO::VariableType>(type);
|
||||||
var->name = variable;
|
var->name = variable;
|
||||||
var->data.resize(N);
|
var->data.resize(N);
|
||||||
double *var_data = var->data.data();
|
double *var_data = var->data.data();
|
||||||
|
|||||||
@@ -106,14 +106,23 @@ static IO::MeshDatabase write_domain( FILE *fid, const std::string& filename,
|
|||||||
variable.name = mesh.vars[i]->name;
|
variable.name = mesh.vars[i]->name;
|
||||||
variable.file = filename;
|
variable.file = filename;
|
||||||
variable.offset = ftell(fid);
|
variable.offset = ftell(fid);
|
||||||
|
IO::VariableDatabase info;
|
||||||
|
info.name = variable.name;
|
||||||
|
info.type = mesh.vars[i]->type;
|
||||||
|
info.dim = mesh.vars[i]->dim;
|
||||||
|
database.variables.push_back(info);
|
||||||
std::pair<std::string,std::string> key(domainname,variable.name);
|
std::pair<std::string,std::string> key(domainname,variable.name);
|
||||||
database.variables.push_back(variable.name);
|
|
||||||
database.variable_data.insert(
|
database.variable_data.insert(
|
||||||
std::pair<std::pair<std::string,std::string>,IO::DatabaseEntry>(key,variable) );
|
std::pair<std::pair<std::string,std::string>,IO::DatabaseEntry>(key,variable) );
|
||||||
int dim = mesh.vars[i]->dim;
|
int dim = mesh.vars[i]->dim;
|
||||||
int type = static_cast<int>(mesh.vars[i]->type);
|
int type = static_cast<int>(mesh.vars[i]->type);
|
||||||
size_t N = mesh.vars[i]->data.size();
|
size_t N = mesh.vars[i]->data.size();
|
||||||
const void* data = N==0 ? 0:&mesh.vars[i]->data[0];
|
const void* data = N==0 ? 0:&mesh.vars[i]->data[0];
|
||||||
|
if ( type == static_cast<int>(IO::VariableType::Null) ) {
|
||||||
|
ERROR("Variable type not set");
|
||||||
|
}
|
||||||
|
size_t N_mesh = mesh.mesh->numberPointsVar(mesh.vars[i]->type);
|
||||||
|
ASSERT(N==dim*N_mesh);
|
||||||
fprintf(fid,"Var: %s-%05i-%s: %i, %i, %lu, %lu, double\n",
|
fprintf(fid,"Var: %s-%05i-%s: %i, %i, %lu, %lu, double\n",
|
||||||
database.name.c_str(), rank, variable.name.c_str(),
|
database.name.c_str(), rank, variable.name.c_str(),
|
||||||
dim, type, N, dim*N*sizeof(double) );
|
dim, type, N, dim*N*sizeof(double) );
|
||||||
|
|||||||
@@ -2169,6 +2169,7 @@ int main(int argc, char **argv)
|
|||||||
std::shared_ptr<IO::Variable> dist( new IO::Variable() );
|
std::shared_ptr<IO::Variable> dist( new IO::Variable() );
|
||||||
dist->name = "distance";
|
dist->name = "distance";
|
||||||
dist->dim = 1;
|
dist->dim = 1;
|
||||||
|
dist->type = IO::VariableType::NodeVariable;
|
||||||
dist->data.resize(3*mesh->A.size());
|
dist->data.resize(3*mesh->A.size());
|
||||||
for (size_t i=0; i<mesh->A.size(); i++) {
|
for (size_t i=0; i<mesh->A.size(); i++) {
|
||||||
const Point& a = mesh->A[i];
|
const Point& a = mesh->A[i];
|
||||||
|
|||||||
@@ -81,22 +81,21 @@ int main(int argc, char **argv)
|
|||||||
|
|
||||||
// Create the variables
|
// Create the variables
|
||||||
std::shared_ptr<IO::Variable> dist_set1( new IO::Variable() );
|
std::shared_ptr<IO::Variable> dist_set1( new IO::Variable() );
|
||||||
std::shared_ptr<IO::Variable> dist_trimesh( new IO::Variable() );
|
|
||||||
std::shared_ptr<IO::Variable> dist_list( new IO::Variable() );
|
std::shared_ptr<IO::Variable> dist_list( new IO::Variable() );
|
||||||
dist_set1->dim = 1;
|
dist_set1->dim = 1;
|
||||||
dist_trimesh->dim = 1;
|
dist_list->dim = 1;
|
||||||
dist_set1->name = "Distance";
|
dist_set1->name = "Distance";
|
||||||
dist_trimesh->name = "Distance";
|
dist_list->name = "Distance";
|
||||||
dist_set1->type = IO::Variable::VariableType::NodeVariable;
|
dist_set1->type = IO::VariableType::NodeVariable;
|
||||||
dist_trimesh->type = IO::Variable::VariableType::NodeVariable;
|
dist_list->type = IO::VariableType::NodeVariable;
|
||||||
dist_set1->data.resize( N_points );
|
dist_set1->data.resize( N_points );
|
||||||
for (int i=0; i<N_points; i++)
|
for (int i=0; i<N_points; i++)
|
||||||
dist_set1->data[i] = distance(set1->points[i]);
|
dist_set1->data[i] = distance(set1->points[i]);
|
||||||
dist_trimesh->data.resize( 3*N_tri );
|
dist_list->data.resize( 3*N_tri );
|
||||||
for (int i=0; i<N_tri; i++) {
|
for (int i=0; i<N_tri; i++) {
|
||||||
dist_trimesh->data[3*i+0] = trimesh->A[i];
|
dist_list->data[3*i+0] = distance(trilist->A[i]);
|
||||||
dist_trimesh->data[3*i+1] = trimesh->B[i];
|
dist_list->data[3*i+1] = distance(trilist->B[i]);
|
||||||
dist_trimesh->data[3*i+2] = trimesh->C[i];
|
dist_list->data[3*i+2] = distance(trilist->C[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create the MeshDataStruct
|
// Create the MeshDataStruct
|
||||||
@@ -106,10 +105,10 @@ int main(int argc, char **argv)
|
|||||||
meshData[0].vars.push_back(dist_set1);
|
meshData[0].vars.push_back(dist_set1);
|
||||||
meshData[1].meshName = "trimesh";
|
meshData[1].meshName = "trimesh";
|
||||||
meshData[1].mesh = trimesh;
|
meshData[1].mesh = trimesh;
|
||||||
meshData[1].vars.push_back(dist_trimesh);
|
meshData[1].vars.push_back(dist_set1);
|
||||||
meshData[2].meshName = "trilist";
|
meshData[2].meshName = "trilist";
|
||||||
meshData[2].mesh = trilist;
|
meshData[2].mesh = trilist;
|
||||||
meshData[2].vars.push_back(dist_set1);
|
meshData[2].vars.push_back(dist_list);
|
||||||
|
|
||||||
// Write the data
|
// Write the data
|
||||||
IO::writeData( 0, meshData, 1 );
|
IO::writeData( 0, meshData, 1 );
|
||||||
@@ -215,7 +214,7 @@ int main(int argc, char **argv)
|
|||||||
for (size_t v=0; v<list[i].variables.size(); v++) {
|
for (size_t v=0; v<list[i].variables.size(); v++) {
|
||||||
for (size_t k=0; k<list[i].domains.size(); k++) {
|
for (size_t k=0; k<list[i].domains.size(); k++) {
|
||||||
std::shared_ptr<const IO::Variable> variable =
|
std::shared_ptr<const IO::Variable> variable =
|
||||||
IO::getVariable(".",timesteps[i],list[j],k,list[j].variables[v]);
|
IO::getVariable(".",timesteps[i],list[j],k,list[j].variables[v].name);
|
||||||
const IO::Variable& var1 = *mesh0->vars[v];
|
const IO::Variable& var1 = *mesh0->vars[v];
|
||||||
const IO::Variable& var2 = *variable;
|
const IO::Variable& var2 = *variable;
|
||||||
pass = var1.name == var2.name;
|
pass = var1.name == var2.name;
|
||||||
|
|||||||
@@ -47,6 +47,7 @@
|
|||||||
|
|
||||||
// LBPM headers
|
// LBPM headers
|
||||||
#include "IO/Reader.h"
|
#include "IO/Reader.h"
|
||||||
|
#include "IO/IOHelpers.h"
|
||||||
#include "common/Utilities.h"
|
#include "common/Utilities.h"
|
||||||
|
|
||||||
// vtk headers
|
// vtk headers
|
||||||
@@ -192,11 +193,11 @@ avtLBMFileFormat::FreeUpResources(void)
|
|||||||
// ****************************************************************************
|
// ****************************************************************************
|
||||||
|
|
||||||
void
|
void
|
||||||
avtLBMFileFormat::PopulateDatabaseMetaData(avtDatabaseMetaData *md, int timeState)
|
avtLBMFileFormat::PopulateDatabaseMetaData(avtDatabaseMetaData *md, int timestate)
|
||||||
{
|
{
|
||||||
DebugStream::Stream1() << "avtLBMFileFormat::PopulateDatabaseMetaData: " << timeState << std::endl;
|
DebugStream::Stream1() << "avtLBMFileFormat::PopulateDatabaseMetaData: " << timestate << std::endl;
|
||||||
// Add the mesh domains to the meta data
|
// Add the mesh domains to the meta data
|
||||||
const std::vector<IO::MeshDatabase> database = d_database[timeState];
|
const std::vector<IO::MeshDatabase> database = d_database[timestate];
|
||||||
for (size_t i=0; i<database.size(); i++) {
|
for (size_t i=0; i<database.size(); i++) {
|
||||||
DebugStream::Stream1() << " Adding " << database[i].name << std::endl;
|
DebugStream::Stream1() << " Adding " << database[i].name << std::endl;
|
||||||
avtMeshMetaData *mmd = new avtMeshMetaData;
|
avtMeshMetaData *mmd = new avtMeshMetaData;
|
||||||
@@ -217,63 +218,34 @@ avtLBMFileFormat::PopulateDatabaseMetaData(avtDatabaseMetaData *md, int timeStat
|
|||||||
Expression expr;
|
Expression expr;
|
||||||
char expdef[100], expname[100];
|
char expdef[100], expname[100];
|
||||||
sprintf(expdef,"coord(<%s>)[%i]",mmd->name.c_str(),j);
|
sprintf(expdef,"coord(<%s>)[%i]",mmd->name.c_str(),j);
|
||||||
sprintf(expname,"%s-%s",mmd->name.c_str(),xyz[j]);
|
sprintf(expname,"%s/%s",xyz[j],mmd->name.c_str());
|
||||||
expr.SetName(expname);
|
expr.SetName(expname);
|
||||||
expr.SetDefinition(expdef);
|
expr.SetDefinition(expdef);
|
||||||
md->AddExpression(&expr);
|
md->AddExpression(&expr);
|
||||||
}
|
}
|
||||||
// Add the variables
|
// Add the variables
|
||||||
|
for (size_t j=0; j<database[i].variables.size(); j++) {
|
||||||
|
IO::VariableDatabase variable = database[i].variables[j];
|
||||||
|
std::string varname = variable.name + "/" + mmd->name;
|
||||||
|
avtCentering center = AVT_UNKNOWN_CENT;
|
||||||
|
if ( variable.type==IO::VariableType::NodeVariable ) {
|
||||||
|
center = AVT_NODECENT;
|
||||||
|
} else if ( variable.type==IO::VariableType::SurfaceVariable ) {
|
||||||
|
center = AVT_ZONECENT;
|
||||||
|
} else if ( variable.type==IO::VariableType::VolumeVariable ) {
|
||||||
|
center = AVT_ZONECENT;
|
||||||
|
}
|
||||||
|
if ( variable.dim==1 ) {
|
||||||
|
AddScalarVarToMetaData( md, varname, mmd->name, center );
|
||||||
|
} else if ( variable.dim==3 ) {
|
||||||
|
AddVectorVarToMetaData( md, varname, mmd->name, center, variable.dim );
|
||||||
|
} else if ( variable.dim==9 ) {
|
||||||
|
AddTensorVarToMetaData( md, varname, mmd->name, center, variable.dim );
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
DebugStream::Stream1() << " Finished" << std::endl;
|
DebugStream::Stream1() << " Finished" << std::endl;
|
||||||
|
|
||||||
//
|
|
||||||
// CODE TO ADD A SCALAR VARIABLE
|
|
||||||
//
|
|
||||||
// string mesh_for_this_var = meshname; // ??? -- could be multiple meshes
|
|
||||||
// string varname = ...
|
|
||||||
//
|
|
||||||
// AVT_NODECENT, AVT_ZONECENT, AVT_UNKNOWN_CENT
|
|
||||||
// avtCentering cent = AVT_NODECENT;
|
|
||||||
//
|
|
||||||
//
|
|
||||||
// Here's the call that tells the meta-data object that we have a var:
|
|
||||||
//
|
|
||||||
// AddScalarVarToMetaData(md, varname, mesh_for_this_var, cent);
|
|
||||||
//
|
|
||||||
|
|
||||||
//
|
|
||||||
// CODE TO ADD A VECTOR VARIABLE
|
|
||||||
//
|
|
||||||
// string mesh_for_this_var = meshname; // ??? -- could be multiple meshes
|
|
||||||
// string varname = ...
|
|
||||||
// int vector_dim = 2;
|
|
||||||
//
|
|
||||||
// AVT_NODECENT, AVT_ZONECENT, AVT_UNKNOWN_CENT
|
|
||||||
// avtCentering cent = AVT_NODECENT;
|
|
||||||
//
|
|
||||||
//
|
|
||||||
// Here's the call that tells the meta-data object that we have a var:
|
|
||||||
//
|
|
||||||
// AddVectorVarToMetaData(md, varname, mesh_for_this_var, cent,vector_dim);
|
|
||||||
//
|
|
||||||
|
|
||||||
//
|
|
||||||
// CODE TO ADD A TENSOR VARIABLE
|
|
||||||
//
|
|
||||||
// string mesh_for_this_var = meshname; // ??? -- could be multiple meshes
|
|
||||||
// string varname = ...
|
|
||||||
// int tensor_dim = 9;
|
|
||||||
//
|
|
||||||
// AVT_NODECENT, AVT_ZONECENT, AVT_UNKNOWN_CENT
|
|
||||||
// avtCentering cent = AVT_NODECENT;
|
|
||||||
//
|
|
||||||
//
|
|
||||||
// Here's the call that tells the meta-data object that we have a var:
|
|
||||||
//
|
|
||||||
// AddTensorVarToMetaData(md, varname, mesh_for_this_var, cent,tensor_dim);
|
|
||||||
//
|
|
||||||
|
|
||||||
//
|
//
|
||||||
// CODE TO ADD A MATERIAL
|
// CODE TO ADD A MATERIAL
|
||||||
//
|
//
|
||||||
@@ -333,22 +305,22 @@ avtLBMFileFormat::PopulateDatabaseMetaData(avtDatabaseMetaData *md, int timeStat
|
|||||||
// ****************************************************************************
|
// ****************************************************************************
|
||||||
|
|
||||||
vtkDataSet *
|
vtkDataSet *
|
||||||
avtLBMFileFormat::GetMesh(int timeState, int domain, const char *meshname)
|
avtLBMFileFormat::GetMesh(int timestate, int domain, const char *meshname)
|
||||||
{
|
{
|
||||||
DebugStream::Stream1() << "avtLBMFileFormat::GetMesh - " << meshname
|
DebugStream::Stream1() << "avtLBMFileFormat::GetMesh - " << meshname
|
||||||
<< "," << timeState << "," << domain << std::endl;
|
<< "," << timestate << "," << domain << std::endl;
|
||||||
TIME_TYPE start, stop, freq;
|
TIME_TYPE start, stop, freq;
|
||||||
get_frequency(&freq);
|
get_frequency(&freq);
|
||||||
get_time(&start);
|
get_time(&start);
|
||||||
// Check if we have a cached copy of the mesh
|
// Check if we have a cached copy of the mesh
|
||||||
char cache_name[1000];
|
char cache_name[1000];
|
||||||
sprintf(cache_name,"%i-%i-%s",timeState,domain,meshname);
|
sprintf(cache_name,"%i-%i-%s",timestate,domain,meshname);
|
||||||
if ( d_meshcache.find(cache_name)!=d_meshcache.end() )
|
if ( d_meshcache.find(cache_name)!=d_meshcache.end() )
|
||||||
return dynamic_cast<vtkDataSet*>(d_meshcache.find(cache_name)->second);
|
return dynamic_cast<vtkDataSet*>(d_meshcache.find(cache_name)->second);
|
||||||
// Read the mesh
|
// Read the mesh
|
||||||
std::shared_ptr<IO::Mesh> mesh;
|
std::shared_ptr<IO::Mesh> mesh;
|
||||||
const std::vector<IO::MeshDatabase> database = d_database[timeState];
|
const std::vector<IO::MeshDatabase> database = d_database[timestate];
|
||||||
const std::string timestep = d_timesteps[timeState];
|
const std::string timestep = d_timesteps[timestate];
|
||||||
for (size_t i=0; i<database.size(); i++) {
|
for (size_t i=0; i<database.size(); i++) {
|
||||||
if ( database[i].name==std::string(meshname) ) {
|
if ( database[i].name==std::string(meshname) ) {
|
||||||
DebugStream::Stream1() << " calling getMesh" << std::endl;
|
DebugStream::Stream1() << " calling getMesh" << std::endl;
|
||||||
@@ -369,10 +341,10 @@ avtLBMFileFormat::GetMesh(int timeState, int domain, const char *meshname)
|
|||||||
}
|
}
|
||||||
// Create the mesh in vtk
|
// Create the mesh in vtk
|
||||||
vtkDataSet* vtkMesh = meshToVTK(mesh);
|
vtkDataSet* vtkMesh = meshToVTK(mesh);
|
||||||
|
vtkMesh->PrintSelf(std::cerr,vtkIndent(6));
|
||||||
DebugStream::Stream2() << " mesh created:" << std::endl;
|
DebugStream::Stream2() << " mesh created:" << std::endl;
|
||||||
ASSERT(vtkMesh!=NULL);
|
ASSERT(vtkMesh!=NULL);
|
||||||
DebugStream::Stream2() << " " << vtkMesh->GetNumberOfCells() << std::endl;
|
DebugStream::Stream2() << " " << vtkMesh->GetNumberOfCells() << std::endl;
|
||||||
DebugStream::Stream2() << " " << vtkMesh->GetNumberOfCells() << std::endl;
|
|
||||||
vtkMesh->PrintSelf(DebugStream::Stream2(),vtkIndent(6));
|
vtkMesh->PrintSelf(DebugStream::Stream2(),vtkIndent(6));
|
||||||
// Cache the mesh and return
|
// Cache the mesh and return
|
||||||
// meshcache[cache_name] = mesh;
|
// meshcache[cache_name] = mesh;
|
||||||
@@ -404,33 +376,35 @@ avtLBMFileFormat::GetMesh(int timeState, int domain, const char *meshname)
|
|||||||
// ****************************************************************************
|
// ****************************************************************************
|
||||||
|
|
||||||
vtkDataArray *
|
vtkDataArray *
|
||||||
avtLBMFileFormat::GetVar(int timestate, int domain, const char *varname)
|
avtLBMFileFormat::GetVar(int timestate, int domain, const char *meshvarname)
|
||||||
{
|
{
|
||||||
DebugStream::Stream1() << "avtLBMFileFormat::GetVar" << std::endl;
|
DebugStream::Stream1() << "avtLBMFileFormat::GetVar: " << meshvarname
|
||||||
EXCEPTION1(InvalidVariableException, varname);
|
<< "," << timestate << "," << domain << std::endl;
|
||||||
return NULL;
|
std::vector<std::string> tmp = IO::splitList(meshvarname,'/');
|
||||||
|
ASSERT(tmp.size()==2);
|
||||||
//
|
std::string varname = tmp[0];
|
||||||
// If you have a file format where variables don't apply (for example a
|
std::string meshname = tmp[1];
|
||||||
// strictly polygonal format like the STL (Stereo Lithography) format,
|
const std::vector<IO::MeshDatabase> database = d_database[timestate];
|
||||||
// then uncomment the code below.
|
const std::string timestep = d_timesteps[timestate];
|
||||||
//
|
std::shared_ptr<const IO::Variable> variable;
|
||||||
// EXCEPTION1(InvalidVariableException, varname);
|
for (size_t i=0; i<database.size(); i++) {
|
||||||
//
|
if ( database[i].name==std::string(meshname) ) {
|
||||||
|
DebugStream::Stream1() << " calling getVar" << std::endl;
|
||||||
//
|
try {
|
||||||
// If you do have a scalar variable, here is some code that may be helpful.
|
variable = IO::getVariable(d_path,timestep,database[i],domain,varname);
|
||||||
//
|
} catch (const std::exception &err) {
|
||||||
// int ntuples = XXX; // this is the number of entries in the variable.
|
DebugStream::Stream1() << " Caught errror calling getVar:" << std::endl;
|
||||||
// vtkFloatArray *rv = vtkFloatArray::New();
|
DebugStream::Stream1() << err.what() << std::endl;
|
||||||
// rv->SetNumberOfTuples(ntuples);
|
} catch (...) {
|
||||||
// for (int i = 0 ; i < ntuples ; i++)
|
DebugStream::Stream1() << " Caught unknown errror calling getVar" << std::endl;
|
||||||
// {
|
return NULL;
|
||||||
// rv->SetTuple1(i, VAL); // you must determine value for ith entry.
|
}
|
||||||
// }
|
}
|
||||||
//
|
}
|
||||||
// return rv;
|
if ( variable == NULL )
|
||||||
//
|
EXCEPTION1(InvalidVariableException, varname);
|
||||||
|
vtkDataArray* vtkVar = varToVTK(variable);
|
||||||
|
return vtkVar;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -458,6 +432,8 @@ avtLBMFileFormat::GetVar(int timestate, int domain, const char *varname)
|
|||||||
vtkDataArray *
|
vtkDataArray *
|
||||||
avtLBMFileFormat::GetVectorVar(int timestate, int domain, const char *varname)
|
avtLBMFileFormat::GetVectorVar(int timestate, int domain, const char *varname)
|
||||||
{
|
{
|
||||||
|
cerr << "avtLBMFileFormat::GetVectorVar - " << varname
|
||||||
|
<< "," << timestate << "," << domain << std::endl;
|
||||||
DebugStream::Stream1() << "avtLBMFileFormat::GetVectorVar" << std::endl;
|
DebugStream::Stream1() << "avtLBMFileFormat::GetVectorVar" << std::endl;
|
||||||
EXCEPTION1(InvalidVariableException, varname);
|
EXCEPTION1(InvalidVariableException, varname);
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|||||||
@@ -101,11 +101,14 @@ class avtLBMFileFormat : public avtMTMDFileFormat
|
|||||||
// Populate the databes
|
// Populate the databes
|
||||||
virtual void PopulateDatabaseMetaData(avtDatabaseMetaData*, int);
|
virtual void PopulateDatabaseMetaData(avtDatabaseMetaData*, int);
|
||||||
|
|
||||||
|
// Helper typedefs
|
||||||
|
typedef std::pair<std::string,int> mesh_key;
|
||||||
|
|
||||||
// DATA MEMBERS
|
// DATA MEMBERS
|
||||||
std::string d_path;
|
std::string d_path;
|
||||||
std::vector<std::string> d_timesteps;
|
std::vector<std::string> d_timesteps;
|
||||||
std::vector<std::vector<IO::MeshDatabase> > d_database;
|
std::vector<std::vector<IO::MeshDatabase> > d_database;
|
||||||
std::map<std::string,vtkObjectBase*> d_meshcache;
|
std::map<std::string,vtkObjectBase*> d_meshcache;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -77,7 +77,7 @@ inline vtkDataSet* TriMeshToVTK( std::shared_ptr<const IO::TriMesh> mesh )
|
|||||||
vtkPolyData *vtkMesh = vtkPolyData::New();
|
vtkPolyData *vtkMesh = vtkPolyData::New();
|
||||||
vtkMesh->SetPoints(points);
|
vtkMesh->SetPoints(points);
|
||||||
vtkMesh->Allocate(N_tri);
|
vtkMesh->Allocate(N_tri);
|
||||||
for (int i=0; i<(int)N_tri; i++) {
|
for (size_t i=0; i<N_tri; i++) {
|
||||||
vtkIdType ids[3] = {A[i],B[i],C[i]};
|
vtkIdType ids[3] = {A[i],B[i],C[i]};
|
||||||
vtkMesh->InsertNextCell(VTK_TRIANGLE,3,ids);
|
vtkMesh->InsertNextCell(VTK_TRIANGLE,3,ids);
|
||||||
}
|
}
|
||||||
@@ -89,22 +89,49 @@ inline vtkDataSet* TriMeshToVTK( std::shared_ptr<const IO::TriMesh> mesh )
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Convert a TriList to vtkDataSet
|
||||||
|
inline vtkDataSet* TriListToVTK( std::shared_ptr<const IO::TriList> mesh )
|
||||||
|
{
|
||||||
|
std::vector<LBPM_Point> point_set(3*mesh->A.size());
|
||||||
|
for (size_t i=0; i<mesh->A.size(); i++) {
|
||||||
|
point_set[3*i+0] = mesh->A[i];
|
||||||
|
point_set[3*i+1] = mesh->B[i];
|
||||||
|
point_set[3*i+2] = mesh->C[i];
|
||||||
|
}
|
||||||
|
vtkFloatArray *coords = pointToVTK(point_set);
|
||||||
|
ASSERT(coords!=NULL);
|
||||||
|
vtkPoints *points = vtkPoints::New(VTK_FLOAT);
|
||||||
|
points->SetData(coords);
|
||||||
|
points->ComputeBounds();
|
||||||
|
size_t N_tri = mesh->A.size();
|
||||||
|
vtkPolyData *vtkMesh = vtkPolyData::New();
|
||||||
|
vtkMesh->SetPoints(points);
|
||||||
|
vtkMesh->Allocate(N_tri);
|
||||||
|
for (int i=0; i<(int)N_tri; i++) {
|
||||||
|
vtkIdType ids[3] = {3*i+0,3*i+1,3*i+2};
|
||||||
|
vtkMesh->InsertNextCell(VTK_TRIANGLE,3,ids);
|
||||||
|
}
|
||||||
|
vtkMesh->BuildCells();
|
||||||
|
vtkMesh->ComputeBounds();
|
||||||
|
points->Delete();
|
||||||
|
coords->Delete();
|
||||||
|
return vtkMesh;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// Convert a mesh to vtkDataSet
|
// Convert a mesh to vtkDataSet
|
||||||
inline vtkDataSet* meshToVTK( std::shared_ptr<IO::Mesh> mesh )
|
inline vtkDataSet* meshToVTK( std::shared_ptr<const IO::Mesh> mesh )
|
||||||
{
|
{
|
||||||
vtkDataSet* mesh2 = NULL;
|
vtkDataSet* mesh2 = NULL;
|
||||||
if ( std::dynamic_pointer_cast<IO::PointList>(mesh) != NULL ) {
|
if ( std::dynamic_pointer_cast<const IO::PointList>(mesh) != NULL ) {
|
||||||
// We are dealing with a point mesh
|
// We are dealing with a point mesh
|
||||||
DebugStream::Stream1() << " Creating point mesh" << std::endl;
|
mesh2 = PointListToVTK( std::dynamic_pointer_cast<const IO::PointList>(mesh) );
|
||||||
std::shared_ptr<const IO::PointList> pointMesh = IO::getPointList(mesh);
|
|
||||||
mesh2 = PointListToVTK( pointMesh );
|
|
||||||
DebugStream::Stream1() << " Point mesh created" << std::endl;
|
DebugStream::Stream1() << " Point mesh created" << std::endl;
|
||||||
} else if ( std::dynamic_pointer_cast<IO::TriMesh>(mesh) != NULL ||
|
} else if ( std::dynamic_pointer_cast<const IO::TriMesh>(mesh) != NULL ) {
|
||||||
std::dynamic_pointer_cast<IO::TriList>(mesh) != NULL )
|
mesh2 = TriMeshToVTK( std::dynamic_pointer_cast<const IO::TriMesh>(mesh) );
|
||||||
{
|
DebugStream::Stream1() << " Surface mesh created" << std::endl;
|
||||||
DebugStream::Stream1() << " Creating surface mesh" << std::endl;
|
} else if ( std::dynamic_pointer_cast<const IO::TriList>(mesh) != NULL ) {
|
||||||
std::shared_ptr<const IO::TriMesh> triMesh = IO::getTriMesh(mesh);
|
mesh2 = TriListToVTK( std::dynamic_pointer_cast<const IO::TriList>(mesh) );
|
||||||
mesh2 = TriMeshToVTK( triMesh );
|
|
||||||
DebugStream::Stream1() << " Surface mesh created" << std::endl;
|
DebugStream::Stream1() << " Surface mesh created" << std::endl;
|
||||||
} else {
|
} else {
|
||||||
DebugStream::Stream1() << " Error, unknown mesh type" << std::endl;
|
DebugStream::Stream1() << " Error, unknown mesh type" << std::endl;
|
||||||
@@ -114,3 +141,21 @@ inline vtkDataSet* meshToVTK( std::shared_ptr<IO::Mesh> mesh )
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Convert a variable to vtkDataSet
|
||||||
|
inline vtkDataArray* varToVTK( std::shared_ptr<const IO::Variable> var )
|
||||||
|
{
|
||||||
|
vtkFloatArray* var2 = NULL;
|
||||||
|
if ( var->dim==1 ) {
|
||||||
|
// Scalar variable
|
||||||
|
var2 = vtkFloatArray::New();
|
||||||
|
var2->SetNumberOfTuples(var->data.size());
|
||||||
|
for (size_t i=0; i<var->data.size(); i++)
|
||||||
|
var2->SetTuple1(i,var->data[i]);
|
||||||
|
} else {
|
||||||
|
DebugStream::Stream1() << " Error, variable not yet supported" << std::endl;
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
return var2;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user