fix merge conflict
This commit is contained in:
commit
9fddfff384
|
@ -150,7 +150,7 @@ IF ( NOT ONLY_BUILD_DOCS )
|
|||
CONFIGURE_NETCDF()
|
||||
CONFIGURE_SILO()
|
||||
CONFIGURE_LBPM()
|
||||
CONFIGURE_TIMER( 0 "${${PROJ}_INSTALL_DIR}/null_timer" )
|
||||
CONFIGURE_TIMER( 0 "${${PROJ}_INSTALL_DIR}/null_timer" FALSE )
|
||||
CONFIGURE_LINE_COVERAGE()
|
||||
# Set the external library link list
|
||||
SET( EXTERNAL_LIBS ${EXTERNAL_LIBS} ${TIMER_LIBS} )
|
||||
|
|
|
@ -57,8 +57,6 @@ inline std::vector<std::string> splitList( const char *line, const char token )
|
|||
}
|
||||
|
||||
|
||||
|
||||
};
|
||||
}; // namespace IO
|
||||
|
||||
#endif
|
||||
|
||||
|
|
259
IO/Mesh.cpp
259
IO/Mesh.cpp
|
@ -1,4 +1,5 @@
|
|||
#include "Mesh.h"
|
||||
#include "IO/IOHelpers.h"
|
||||
#include "common/Utilities.h"
|
||||
|
||||
#include <limits>
|
||||
|
@ -21,35 +22,40 @@ inline Point nullPoint()
|
|||
/****************************************************
|
||||
* Mesh *
|
||||
****************************************************/
|
||||
Mesh::Mesh( )
|
||||
{
|
||||
}
|
||||
Mesh::~Mesh( )
|
||||
{
|
||||
}
|
||||
Mesh::Mesh() {}
|
||||
Mesh::~Mesh() {}
|
||||
|
||||
|
||||
/****************************************************
|
||||
* MeshDataStruct *
|
||||
****************************************************/
|
||||
bool MeshDataStruct::check() const
|
||||
#define checkResult( pass, msg ) \
|
||||
do { \
|
||||
if ( !( pass ) ) { \
|
||||
if ( abort ) \
|
||||
ERROR( msg ); \
|
||||
return false; \
|
||||
} \
|
||||
} while ( 0 )
|
||||
bool MeshDataStruct::check( bool abort ) const
|
||||
{
|
||||
enum VariableType { NodeVariable=1, EdgeVariable=2, SurfaceVariable=2, VolumeVariable=3, NullVariable=0 };
|
||||
bool pass = mesh != nullptr;
|
||||
for ( const auto &var : vars ) {
|
||||
pass = pass && static_cast<int>(var->type)>=1 && static_cast<int>(var->type)<=3;
|
||||
pass = pass && !var->data.empty();
|
||||
checkResult( var->type == VariableType::NodeVariable ||
|
||||
var->type == VariableType::EdgeVariable ||
|
||||
var->type == VariableType::SurfaceVariable ||
|
||||
var->type == VariableType::VolumeVariable,
|
||||
"Invalid data type" );
|
||||
checkResult( !var->data.empty(), "Variable data is empty" );
|
||||
}
|
||||
if ( !pass )
|
||||
return false;
|
||||
const std::string &meshClass = mesh->className();
|
||||
if ( meshClass == "PointList" ) {
|
||||
const auto mesh2 = dynamic_cast<IO::PointList*>( mesh.get() );
|
||||
if ( mesh2 == nullptr )
|
||||
return false;
|
||||
auto mesh2 = dynamic_cast<IO::PointList *>( mesh.get() );
|
||||
ASSERT( mesh2 );
|
||||
for ( const auto &var : vars ) {
|
||||
if ( var->type == IO::VariableType::NodeVariable ) {
|
||||
pass = pass && var->data.size(0)==mesh2->points.size() && var->data.size(1)==var->dim;
|
||||
size_t N_points = mesh2->points.size();
|
||||
checkResult( var->data.size( 0 ) == N_points, "sizeof NodeVariable" );
|
||||
checkResult( var->data.size( 1 ) == var->dim, "sizeof NodeVariable" );
|
||||
} else if ( var->type == IO::VariableType::EdgeVariable ) {
|
||||
ERROR( "Invalid type for PointList" );
|
||||
} else if ( var->type == IO::VariableType::SurfaceVariable ) {
|
||||
|
@ -61,62 +67,63 @@ bool MeshDataStruct::check() const
|
|||
}
|
||||
}
|
||||
} else if ( meshClass == "TriMesh" || meshClass == "TriList" ) {
|
||||
const auto mesh2 = getTriMesh( mesh );
|
||||
if ( mesh2 == nullptr )
|
||||
return false;
|
||||
auto mesh2 = getTriMesh( mesh );
|
||||
ASSERT( mesh2 );
|
||||
for ( const auto &var : vars ) {
|
||||
if ( var->type == IO::VariableType::NodeVariable ) {
|
||||
pass = pass && var->data.size(0)==mesh2->vertices->points.size() && var->data.size(1)==var->dim;
|
||||
size_t N_points = mesh2->vertices->points.size();
|
||||
checkResult( var->data.size( 0 ) == N_points, "sizeof NodeVariable" );
|
||||
checkResult( var->data.size( 1 ) == var->dim, "sizeof NodeVariable" );
|
||||
} else if ( var->type == IO::VariableType::EdgeVariable ) {
|
||||
ERROR( "Not finished" );
|
||||
} else if ( var->type == IO::VariableType::SurfaceVariable ) {
|
||||
ERROR( "Not finished" );
|
||||
} else if ( var->type == IO::VariableType::VolumeVariable ) {
|
||||
pass = pass && var->data.size(0)==mesh2->A.size() && var->data.size(1)==var->dim;
|
||||
checkResult( var->data.size( 0 ) == mesh2->A.size(), "sizeof VolumeVariable" );
|
||||
checkResult( var->data.size( 1 ) == var->dim, "sizeof VolumeVariable" );
|
||||
} else {
|
||||
ERROR( "Invalid variable type" );
|
||||
}
|
||||
}
|
||||
} else if ( meshClass == "DomainMesh" ) {
|
||||
const auto mesh2 = dynamic_cast<IO::DomainMesh*>( mesh.get() );
|
||||
if ( mesh2 == nullptr )
|
||||
return false;
|
||||
auto mesh2 = dynamic_cast<IO::DomainMesh *>( mesh.get() );
|
||||
ASSERT( mesh2 );
|
||||
for ( const auto &var : vars ) {
|
||||
ArraySize varSize;
|
||||
if ( var->type == IO::VariableType::NodeVariable ) {
|
||||
pass = pass && (int) var->data.size(0)==(mesh2->nx+1) && (int) var->data.size(1)==(mesh2->ny+1)
|
||||
&& (int) var->data.size(2)==(mesh2->nz+1) && var->data.size(3)==var->dim;
|
||||
varSize = ArraySize( mesh2->nx + 1, mesh2->ny + 1, mesh2->nz + 1, var->dim );
|
||||
} else if ( var->type == IO::VariableType::EdgeVariable ) {
|
||||
ERROR( "Not finished" );
|
||||
} else if ( var->type == IO::VariableType::SurfaceVariable ) {
|
||||
ERROR( "Not finished" );
|
||||
} else if ( var->type == IO::VariableType::VolumeVariable ) {
|
||||
pass = pass && (int) var->data.size(0)==mesh2->nx && (int) var->data.size(1)==mesh2->ny
|
||||
&& (int) var->data.size(2)==mesh2->nz && var->data.size(3)==var->dim;
|
||||
varSize = ArraySize( mesh2->nx, mesh2->ny, mesh2->nz, var->dim );
|
||||
} else {
|
||||
ERROR( "Invalid variable type" );
|
||||
}
|
||||
if ( var->data.size( 0 ) == varSize[0] * varSize[1] * varSize[2] &&
|
||||
var->data.size( 1 ) == varSize[3] )
|
||||
var->data.resize( varSize );
|
||||
for ( int d = 0; d < 4; d++ )
|
||||
checkResult( var->data.size( d ) == varSize[d], "DomainMesh Variable" );
|
||||
}
|
||||
} else {
|
||||
ERROR( "Unknown mesh class: " + mesh->className() );
|
||||
}
|
||||
return pass;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/****************************************************
|
||||
* PointList *
|
||||
****************************************************/
|
||||
PointList::PointList( )
|
||||
{
|
||||
}
|
||||
PointList::PointList() {}
|
||||
PointList::PointList( size_t N )
|
||||
{
|
||||
Point tmp = nullPoint();
|
||||
points.resize( N, tmp );
|
||||
}
|
||||
PointList::~PointList( )
|
||||
{
|
||||
}
|
||||
PointList::~PointList() {}
|
||||
size_t PointList::numberPointsVar( VariableType type ) const
|
||||
{
|
||||
size_t N = 0;
|
||||
|
@ -165,9 +172,7 @@ void PointList::unpack( const std::pair<size_t,void*>& data_in )
|
|||
/****************************************************
|
||||
* TriList *
|
||||
****************************************************/
|
||||
TriList::TriList( )
|
||||
{
|
||||
}
|
||||
TriList::TriList() {}
|
||||
TriList::TriList( size_t N_tri )
|
||||
{
|
||||
Point tmp = nullPoint();
|
||||
|
@ -190,9 +195,7 @@ TriList::TriList( const TriMesh& mesh )
|
|||
for ( size_t i = 0; i < C.size(); i++ )
|
||||
C[i] = P[mesh.C[i]];
|
||||
}
|
||||
TriList::~TriList( )
|
||||
{
|
||||
}
|
||||
TriList::~TriList() {}
|
||||
size_t TriList::numberPointsVar( VariableType type ) const
|
||||
{
|
||||
size_t N = 0;
|
||||
|
@ -257,9 +260,7 @@ void TriList::unpack( const std::pair<size_t,void*>& data_in )
|
|||
/****************************************************
|
||||
* TriMesh *
|
||||
****************************************************/
|
||||
TriMesh::TriMesh( )
|
||||
{
|
||||
}
|
||||
TriMesh::TriMesh() {}
|
||||
TriMesh::TriMesh( size_t N_tri, size_t N_point )
|
||||
{
|
||||
vertices.reset( new PointList( N_point ) );
|
||||
|
@ -312,8 +313,10 @@ std::pair<size_t,void*> TriMesh::pack( int level ) const
|
|||
std::pair<size_t, void *> data_out( 0, NULL );
|
||||
if ( level == 0 ) {
|
||||
const std::vector<Point> &points = vertices->points;
|
||||
data_out.first = (3+3*points.size())*sizeof(double) + 3*A.size()*sizeof(int);
|
||||
double *data_ptr = new double[4+3*points.size()+(3*A.size()*sizeof(int))/sizeof(double)];
|
||||
data_out.first =
|
||||
( 3 + 3 * points.size() ) * sizeof( double ) + 3 * A.size() * sizeof( int );
|
||||
double *data_ptr =
|
||||
new double[4 + 3 * points.size() + ( 3 * A.size() * sizeof( int ) ) / sizeof( double )];
|
||||
data_out.second = data_ptr;
|
||||
uint64_t *data_int64 = reinterpret_cast<uint64_t *>( data_ptr );
|
||||
data_int64[0] = level;
|
||||
|
@ -368,22 +371,34 @@ void TriMesh::unpack( const std::pair<size_t,void*>& data_in )
|
|||
/****************************************************
|
||||
* Domain mesh *
|
||||
****************************************************/
|
||||
DomainMesh::DomainMesh():
|
||||
nprocx(0), nprocy(0), nprocz(0), rank(0),
|
||||
nx(0), ny(0), nz(0),
|
||||
Lx(0), Ly(0), Lz(0)
|
||||
DomainMesh::DomainMesh()
|
||||
: nprocx( 0 ),
|
||||
nprocy( 0 ),
|
||||
nprocz( 0 ),
|
||||
rank( 0 ),
|
||||
nx( 0 ),
|
||||
ny( 0 ),
|
||||
nz( 0 ),
|
||||
Lx( 0 ),
|
||||
Ly( 0 ),
|
||||
Lz( 0 )
|
||||
{
|
||||
}
|
||||
DomainMesh::DomainMesh( RankInfoStruct data,
|
||||
int nx2, int ny2, int nz2, double Lx2, double Ly2, double Lz2 ):
|
||||
nprocx(data.nx), nprocy(data.ny), nprocz(data.nz), rank(data.rank[1][1][1]),
|
||||
nx(nx2), ny(ny2), nz(nz2),
|
||||
Lx(Lx2), Ly(Ly2), Lz(Lz2)
|
||||
{
|
||||
}
|
||||
DomainMesh::~DomainMesh()
|
||||
DomainMesh::DomainMesh(
|
||||
RankInfoStruct data, int nx2, int ny2, int nz2, double Lx2, double Ly2, double Lz2 )
|
||||
: nprocx( data.nx ),
|
||||
nprocy( data.ny ),
|
||||
nprocz( data.nz ),
|
||||
rank( data.rank[1][1][1] ),
|
||||
nx( nx2 ),
|
||||
ny( ny2 ),
|
||||
nz( nz2 ),
|
||||
Lx( Lx2 ),
|
||||
Ly( Ly2 ),
|
||||
Lz( Lz2 )
|
||||
{
|
||||
}
|
||||
DomainMesh::~DomainMesh() {}
|
||||
size_t DomainMesh::numberPointsVar( VariableType type ) const
|
||||
{
|
||||
size_t N = 0;
|
||||
|
@ -477,5 +492,129 @@ std::shared_ptr<const TriList> getTriList( std::shared_ptr<const Mesh> mesh )
|
|||
}
|
||||
|
||||
|
||||
} // IO namespace
|
||||
/****************************************************
|
||||
* Convert enum values *
|
||||
****************************************************/
|
||||
std::string getString( VariableType type )
|
||||
{
|
||||
if ( type == VariableType::NodeVariable )
|
||||
return "node";
|
||||
else if ( type == VariableType::EdgeVariable )
|
||||
return "edge";
|
||||
else if ( type == VariableType::SurfaceVariable )
|
||||
return "face";
|
||||
else if ( type == VariableType::VolumeVariable )
|
||||
return "cell";
|
||||
else if ( type == VariableType::NullVariable )
|
||||
return "null";
|
||||
else
|
||||
ERROR( "Invalid type" );
|
||||
return "";
|
||||
}
|
||||
VariableType getVariableType( const std::string &type_in )
|
||||
{
|
||||
auto type = deblank( type_in );
|
||||
if ( type == "node" )
|
||||
return VariableType::NodeVariable;
|
||||
else if ( type == "edge" || type == "1" )
|
||||
return VariableType::EdgeVariable;
|
||||
else if ( type == "face" )
|
||||
return VariableType::SurfaceVariable;
|
||||
else if ( type == "cell" || type == "3" )
|
||||
return VariableType::VolumeVariable;
|
||||
else if ( type == "null" )
|
||||
return VariableType::NullVariable;
|
||||
else
|
||||
ERROR( "Invalid type: " + type );
|
||||
return VariableType::NullVariable;
|
||||
}
|
||||
std::string getString( DataType type )
|
||||
{
|
||||
if ( type == DataType::Double )
|
||||
return "double";
|
||||
else if ( type == DataType::Float )
|
||||
return "float";
|
||||
else if ( type == DataType::Int )
|
||||
return "int";
|
||||
else if ( type == DataType::Null )
|
||||
return "null";
|
||||
else
|
||||
ERROR( "Invalid type" );
|
||||
return "";
|
||||
}
|
||||
DataType getDataType( const std::string &type_in )
|
||||
{
|
||||
auto type = deblank( type_in );
|
||||
if ( type == "double" )
|
||||
return DataType::Double;
|
||||
else if ( type == "float" )
|
||||
return DataType::Float;
|
||||
else if ( type == "int" )
|
||||
return DataType::Int;
|
||||
else if ( type == "null" )
|
||||
return DataType::Null;
|
||||
else
|
||||
ERROR( "Invalid type: " + type );
|
||||
return DataType::Null;
|
||||
}
|
||||
std::string getString( MeshType type )
|
||||
{
|
||||
if ( type == MeshType::PointMesh )
|
||||
return "PointMesh";
|
||||
else if ( type == MeshType::SurfaceMesh )
|
||||
return "SurfaceMesh";
|
||||
else if ( type == MeshType::VolumeMesh )
|
||||
return "VolumeMesh";
|
||||
else if ( type == MeshType::Unknown )
|
||||
return "unknown";
|
||||
else
|
||||
ERROR( "Invalid type" );
|
||||
return "";
|
||||
}
|
||||
MeshType getMeshType( const std::string &type_in )
|
||||
{
|
||||
auto type = deblank( type_in );
|
||||
if ( type == "PointMesh" || type == "1" )
|
||||
return MeshType::PointMesh;
|
||||
else if ( type == "SurfaceMesh" || type == "2" )
|
||||
return MeshType::SurfaceMesh;
|
||||
else if ( type == "VolumeMesh" || type == "3" )
|
||||
return MeshType::VolumeMesh;
|
||||
else if ( type == "unknown" || type == "-1" )
|
||||
return MeshType::Unknown;
|
||||
else
|
||||
ERROR( "Invalid type: " + type );
|
||||
return MeshType::Unknown;
|
||||
}
|
||||
std::string getString( FileFormat type )
|
||||
{
|
||||
if ( type == FileFormat::OLD )
|
||||
return "old";
|
||||
else if ( type == FileFormat::NEW )
|
||||
return "new";
|
||||
else if ( type == FileFormat::NEW_SINGLE )
|
||||
return "new(single)";
|
||||
else if ( type == FileFormat::SILO )
|
||||
return "silo";
|
||||
else
|
||||
ERROR( "Invalid type" );
|
||||
return "";
|
||||
}
|
||||
FileFormat getFileFormat( const std::string &type_in )
|
||||
{
|
||||
auto type = deblank( type_in );
|
||||
if ( type == "old" || type == "1" )
|
||||
return FileFormat::OLD;
|
||||
else if ( type == "new" || type == "2" )
|
||||
return FileFormat::NEW;
|
||||
else if ( type == "new(single)" || type == "3" )
|
||||
return FileFormat::NEW_SINGLE;
|
||||
else if ( type == "silo" || type == "4" )
|
||||
return FileFormat::SILO;
|
||||
else
|
||||
ERROR( "Invalid type: " + type );
|
||||
return FileFormat::SILO;
|
||||
}
|
||||
|
||||
|
||||
} // namespace IO
|
||||
|
|
59
IO/Mesh.h
59
IO/Mesh.h
|
@ -6,17 +6,36 @@
|
|||
#include <string.h>
|
||||
#include <vector>
|
||||
|
||||
#include "analysis/PointList.h"
|
||||
#include "common/Array.h"
|
||||
#include "common/Communication.h"
|
||||
#include "analysis/PointList.h"
|
||||
|
||||
|
||||
namespace IO {
|
||||
|
||||
|
||||
//! Possible variable types
|
||||
enum class VariableType: unsigned char { NodeVariable=1, EdgeVariable=2, SurfaceVariable=2, VolumeVariable=3, NullVariable=0 };
|
||||
enum class DataType: unsigned char { Double=1, Float=2, Int=2, Null=0 };
|
||||
//! Enums to define types
|
||||
enum class VariableType {
|
||||
NodeVariable,
|
||||
EdgeVariable,
|
||||
SurfaceVariable,
|
||||
VolumeVariable,
|
||||
NullVariable
|
||||
};
|
||||
enum class DataType { Double, Float, Int, Null };
|
||||
enum class MeshType { PointMesh, SurfaceMesh, VolumeMesh, Unknown };
|
||||
enum class FileFormat { OLD, NEW, NEW_SINGLE, SILO };
|
||||
|
||||
|
||||
//! Convert enums to/from strings (more future-proof than static_cast<int>)
|
||||
std::string getString( VariableType );
|
||||
std::string getString( DataType );
|
||||
std::string getString( MeshType );
|
||||
std::string getString( FileFormat );
|
||||
VariableType getVariableType( const std::string & );
|
||||
DataType getDataType( const std::string & );
|
||||
MeshType getMeshType( const std::string & );
|
||||
FileFormat getFileFormat( const std::string & );
|
||||
|
||||
|
||||
/*! \class Mesh
|
||||
|
@ -35,6 +54,7 @@ public:
|
|||
virtual std::pair<size_t, void *> pack( int level ) const = 0;
|
||||
//! Unpack the data
|
||||
virtual void unpack( const std::pair<size_t, void *> &data ) = 0;
|
||||
|
||||
protected:
|
||||
//! Empty constructor
|
||||
Mesh();
|
||||
|
@ -65,6 +85,7 @@ public:
|
|||
virtual void unpack( const std::pair<size_t, void *> &data );
|
||||
//! Access the points
|
||||
const std::vector<Point> &getPoints() const { return points; }
|
||||
|
||||
public:
|
||||
std::vector<Point> points; //!< List of points vertex
|
||||
};
|
||||
|
@ -93,6 +114,7 @@ public:
|
|||
virtual std::pair<size_t, void *> pack( int level ) const;
|
||||
//! Unpack the data
|
||||
virtual void unpack( const std::pair<size_t, void *> &data );
|
||||
|
||||
public:
|
||||
std::vector<Point> A; //!< First vertex
|
||||
std::vector<Point> B; //!< Second vertex
|
||||
|
@ -101,7 +123,8 @@ public:
|
|||
|
||||
|
||||
/*! \class TriMesh
|
||||
\brief A class used to hold a list of trianges specified by their vertex number and list of coordiantes
|
||||
\brief A class used to hold a list of trianges specified by their vertex number and list of
|
||||
coordiantes
|
||||
*/
|
||||
class TriMesh : public Mesh
|
||||
{
|
||||
|
@ -124,6 +147,7 @@ public:
|
|||
virtual std::pair<size_t, void *> pack( int level ) const;
|
||||
//! Unpack the data
|
||||
virtual void unpack( const std::pair<size_t, void *> &data );
|
||||
|
||||
public:
|
||||
std::shared_ptr<PointList> vertices; //!< List of verticies
|
||||
std::vector<int> A; //!< First vertex
|
||||
|
@ -152,6 +176,7 @@ public:
|
|||
virtual std::pair<size_t, void *> pack( int level ) const;
|
||||
//! Unpack the data
|
||||
virtual void unpack( const std::pair<size_t, void *> &data );
|
||||
|
||||
public:
|
||||
int nprocx, nprocy, nprocz, rank;
|
||||
int nx, ny, nz;
|
||||
|
@ -159,12 +184,10 @@ public:
|
|||
};
|
||||
|
||||
|
||||
|
||||
/*! \class Variable
|
||||
\brief A base class for variables
|
||||
*/
|
||||
struct Variable
|
||||
{
|
||||
struct Variable {
|
||||
public:
|
||||
// Internal variables
|
||||
unsigned char dim; //!< Number of points per grid point (1: scalar, 3: vector, ...)
|
||||
|
@ -175,13 +198,19 @@ public:
|
|||
//! Empty constructor
|
||||
Variable() : dim( 0 ), type( VariableType::NullVariable ), precision( DataType::Double ) {}
|
||||
//! Constructor
|
||||
Variable( int dim_, IO::VariableType type_, const std::string& name_ ):
|
||||
dim(dim_), type(type_), precision(DataType::Double), name(name_) {}
|
||||
Variable( int dim_, IO::VariableType type_, const std::string &name_ )
|
||||
: dim( dim_ ), type( type_ ), precision( DataType::Double ), name( name_ )
|
||||
{
|
||||
}
|
||||
//! Constructor
|
||||
Variable( int dim_, IO::VariableType type_, const std::string& name_, const Array<double>& data_ ):
|
||||
dim(dim_), type(type_), precision(DataType::Double), name(name_), data(data_) {}
|
||||
Variable(
|
||||
int dim_, IO::VariableType type_, const std::string &name_, const Array<double> &data_ )
|
||||
: dim( dim_ ), type( type_ ), precision( DataType::Double ), name( name_ ), data( data_ )
|
||||
{
|
||||
}
|
||||
//! Destructor
|
||||
virtual ~Variable() {}
|
||||
|
||||
protected:
|
||||
//! Empty constructor
|
||||
Variable( const Variable & );
|
||||
|
@ -189,7 +218,6 @@ protected:
|
|||
};
|
||||
|
||||
|
||||
|
||||
/*! \class MeshDataStruct
|
||||
\brief A class used to hold database info for saving a mesh
|
||||
*/
|
||||
|
@ -201,7 +229,7 @@ struct MeshDataStruct {
|
|||
//! Empty constructor
|
||||
MeshDataStruct() : precision( DataType::Double ) {}
|
||||
//! Check the data
|
||||
bool check() const;
|
||||
bool check( bool abort = true ) const;
|
||||
};
|
||||
|
||||
|
||||
|
@ -214,7 +242,6 @@ 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
|
||||
} // namespace IO
|
||||
|
||||
#endif
|
||||
|
||||
|
|
|
@ -1,51 +1,43 @@
|
|||
#include "IO/MeshDatabase.h"
|
||||
#include "IO/IOHelpers.h"
|
||||
#include "IO/Mesh.h"
|
||||
#include "IO/PackData.h"
|
||||
#include "IO/IOHelpers.h"
|
||||
#include "common/MPI.h"
|
||||
#include "common/Utilities.h"
|
||||
|
||||
#include <vector>
|
||||
#include <cstdio>
|
||||
#include <map>
|
||||
#include <set>
|
||||
#include <cstdio>
|
||||
#include <vector>
|
||||
|
||||
#include <ProfilerApp.h>
|
||||
|
||||
|
||||
// Default pack/unpack
|
||||
// clang-format off
|
||||
#define INSTANTIATE_PACK( TYPE ) \
|
||||
template<> \
|
||||
size_t packsize<TYPE>( const TYPE &rhs ) \
|
||||
{ \
|
||||
return sizeof( TYPE ); \
|
||||
} \
|
||||
template<> \
|
||||
void pack<TYPE>( const TYPE &rhs, char *buffer ) \
|
||||
{ \
|
||||
memcpy( buffer, &rhs, sizeof( IO::MeshType ) ); \
|
||||
} \
|
||||
template<> \
|
||||
void unpack<TYPE>( TYPE &data, const char *buffer ) \
|
||||
{ \
|
||||
memcpy( &data, buffer, sizeof( IO::MeshType ) ); \
|
||||
}
|
||||
INSTANTIATE_PACK( IO::VariableType )
|
||||
INSTANTIATE_PACK( IO::DataType )
|
||||
INSTANTIATE_PACK( IO::MeshType )
|
||||
INSTANTIATE_PACK( IO::FileFormat )
|
||||
// clang-format on
|
||||
|
||||
|
||||
// MeshType
|
||||
template<>
|
||||
size_t packsize<IO::MeshType>( const IO::MeshType& rhs )
|
||||
{
|
||||
return sizeof(IO::MeshType);
|
||||
}
|
||||
template<>
|
||||
void pack<IO::MeshType>( const IO::MeshType& rhs, char *buffer )
|
||||
{
|
||||
memcpy(buffer,&rhs,sizeof(IO::MeshType));
|
||||
}
|
||||
template<>
|
||||
void unpack<IO::MeshType>( IO::MeshType& data, const char *buffer )
|
||||
{
|
||||
memcpy(&data,buffer,sizeof(IO::MeshType));
|
||||
}
|
||||
// Variable::VariableType
|
||||
template<>
|
||||
size_t packsize<IO::VariableType>( const IO::VariableType& rhs )
|
||||
{
|
||||
return sizeof(IO::VariableType);
|
||||
}
|
||||
template<>
|
||||
void pack<IO::VariableType>( const IO::VariableType& rhs, char *buffer )
|
||||
{
|
||||
memcpy(buffer,&rhs,sizeof(IO::VariableType));
|
||||
}
|
||||
template<>
|
||||
void unpack<IO::VariableType>( IO::VariableType& data, const char *buffer )
|
||||
{
|
||||
memcpy(&data,buffer,sizeof(IO::VariableType));
|
||||
}
|
||||
// DatabaseEntry
|
||||
template<>
|
||||
size_t packsize<IO::DatabaseEntry>( const IO::DatabaseEntry &rhs )
|
||||
|
@ -56,17 +48,23 @@ template<>
|
|||
void pack<IO::DatabaseEntry>( const IO::DatabaseEntry &rhs, char *buffer )
|
||||
{
|
||||
size_t i = 0;
|
||||
pack(rhs.name,&buffer[i]); i+=packsize(rhs.name);
|
||||
pack(rhs.file,&buffer[i]); i+=packsize(rhs.file);
|
||||
pack(rhs.offset,&buffer[i]); i+=packsize(rhs.offset);
|
||||
pack( rhs.name, &buffer[i] );
|
||||
i += packsize( rhs.name );
|
||||
pack( rhs.file, &buffer[i] );
|
||||
i += packsize( rhs.file );
|
||||
pack( rhs.offset, &buffer[i] );
|
||||
i += packsize( rhs.offset );
|
||||
}
|
||||
template<>
|
||||
void unpack<IO::DatabaseEntry>( IO::DatabaseEntry &data, const char *buffer )
|
||||
{
|
||||
size_t i = 0;
|
||||
unpack(data.name,&buffer[i]); i+=packsize(data.name);
|
||||
unpack(data.file,&buffer[i]); i+=packsize(data.file);
|
||||
unpack(data.offset,&buffer[i]); i+=packsize(data.offset);
|
||||
unpack( data.name, &buffer[i] );
|
||||
i += packsize( data.name );
|
||||
unpack( data.file, &buffer[i] );
|
||||
i += packsize( data.file );
|
||||
unpack( data.offset, &buffer[i] );
|
||||
i += packsize( data.offset );
|
||||
}
|
||||
// VariableDatabase
|
||||
template<>
|
||||
|
@ -78,53 +76,69 @@ template<>
|
|||
void pack<IO::VariableDatabase>( const IO::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);
|
||||
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<IO::VariableDatabase>( IO::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);
|
||||
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
|
||||
template<>
|
||||
size_t packsize<IO::MeshDatabase>( const IO::MeshDatabase &data )
|
||||
{
|
||||
return packsize(data.name)
|
||||
+ packsize(data.type)
|
||||
+ packsize(data.meshClass)
|
||||
+ packsize(data.format)
|
||||
+ packsize(data.domains)
|
||||
+ packsize(data.variables)
|
||||
+ packsize(data.variable_data);
|
||||
return packsize( data.name ) + packsize( data.type ) + packsize( data.meshClass ) +
|
||||
packsize( data.format ) + packsize( data.domains ) + packsize( data.variables ) +
|
||||
packsize( data.variable_data );
|
||||
}
|
||||
template<>
|
||||
void pack<IO::MeshDatabase>( const IO::MeshDatabase &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.meshClass,&buffer[i]); i+=packsize(rhs.meshClass);
|
||||
pack(rhs.format,&buffer[i]); i+=packsize(rhs.format);
|
||||
pack(rhs.domains,&buffer[i]); i+=packsize(rhs.domains);
|
||||
pack(rhs.variables,&buffer[i]); i+=packsize(rhs.variables);
|
||||
pack(rhs.variable_data,&buffer[i]); i+=packsize(rhs.variable_data);
|
||||
pack( rhs.name, &buffer[i] );
|
||||
i += packsize( rhs.name );
|
||||
pack( rhs.type, &buffer[i] );
|
||||
i += packsize( rhs.type );
|
||||
pack( rhs.meshClass, &buffer[i] );
|
||||
i += packsize( rhs.meshClass );
|
||||
pack( rhs.format, &buffer[i] );
|
||||
i += packsize( rhs.format );
|
||||
pack( rhs.domains, &buffer[i] );
|
||||
i += packsize( rhs.domains );
|
||||
pack( rhs.variables, &buffer[i] );
|
||||
i += packsize( rhs.variables );
|
||||
pack( rhs.variable_data, &buffer[i] );
|
||||
i += packsize( rhs.variable_data );
|
||||
}
|
||||
template<>
|
||||
void unpack<IO::MeshDatabase>( IO::MeshDatabase &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.meshClass,&buffer[i]); i+=packsize(data.meshClass);
|
||||
unpack(data.format,&buffer[i]); i+=packsize(data.format);
|
||||
unpack(data.domains,&buffer[i]); i+=packsize(data.domains);
|
||||
unpack(data.variables,&buffer[i]); i+=packsize(data.variables);
|
||||
unpack(data.variable_data,&buffer[i]); i+=packsize(data.variable_data);
|
||||
unpack( data.name, &buffer[i] );
|
||||
i += packsize( data.name );
|
||||
unpack( data.type, &buffer[i] );
|
||||
i += packsize( data.type );
|
||||
unpack( data.meshClass, &buffer[i] );
|
||||
i += packsize( data.meshClass );
|
||||
unpack( data.format, &buffer[i] );
|
||||
i += packsize( data.format );
|
||||
unpack( data.domains, &buffer[i] );
|
||||
i += packsize( data.domains );
|
||||
unpack( data.variables, &buffer[i] );
|
||||
i += packsize( data.variables );
|
||||
unpack( data.variable_data, &buffer[i] );
|
||||
i += packsize( data.variable_data );
|
||||
}
|
||||
|
||||
|
||||
|
@ -146,10 +160,7 @@ 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 { return !operator>( rhs ); }
|
||||
bool VariableDatabase::operator>( const VariableDatabase &rhs ) const
|
||||
{
|
||||
if ( name > rhs.name )
|
||||
|
@ -175,12 +186,8 @@ bool VariableDatabase::operator<(const VariableDatabase& rhs ) const
|
|||
/****************************************************
|
||||
* MeshDatabase *
|
||||
****************************************************/
|
||||
MeshDatabase::MeshDatabase()
|
||||
{
|
||||
}
|
||||
MeshDatabase::~MeshDatabase()
|
||||
{
|
||||
}
|
||||
MeshDatabase::MeshDatabase() {}
|
||||
MeshDatabase::~MeshDatabase() {}
|
||||
MeshDatabase::MeshDatabase( const MeshDatabase &rhs )
|
||||
{
|
||||
name = rhs.name;
|
||||
|
@ -223,21 +230,21 @@ std::string DatabaseEntry::write( ) const
|
|||
}
|
||||
DatabaseEntry::DatabaseEntry( const char *line )
|
||||
{
|
||||
std::vector<std::string> list = splitList(line,';');
|
||||
auto list = splitList( line, ';' );
|
||||
name = list[0];
|
||||
file = list[1];
|
||||
offset = atol( list[2].c_str() );
|
||||
}
|
||||
void DatabaseEntry::read( const char *line )
|
||||
{
|
||||
std::vector<std::string> list = splitList(line,';');
|
||||
auto list = splitList( line, ';' );
|
||||
name = list[0];
|
||||
file = list[1];
|
||||
offset = atol( list[2].c_str() );
|
||||
}
|
||||
void DatabaseEntry::read( const std::string &line )
|
||||
{
|
||||
std::vector<std::string> list = splitList(line.c_str(),';');
|
||||
auto list = splitList( line.c_str(), ';' );
|
||||
name = list[0];
|
||||
file = list[1];
|
||||
offset = atol( list[2].c_str() );
|
||||
|
@ -246,7 +253,8 @@ void DatabaseEntry::read( const std::string& line )
|
|||
|
||||
// Gather the mesh databases from all processors
|
||||
inline int tod( int N ) { return ( N + 7 ) / sizeof( double ); }
|
||||
std::vector<MeshDatabase> gatherAll( const std::vector<MeshDatabase>& meshes, const Utilities::MPI& comm )
|
||||
std::vector<MeshDatabase> gatherAll(
|
||||
const std::vector<MeshDatabase> &meshes, const Utilities::MPI &comm )
|
||||
{
|
||||
if ( comm.getSize() == 1 )
|
||||
return meshes;
|
||||
|
@ -301,7 +309,8 @@ std::vector<MeshDatabase> gatherAll( const std::vector<MeshDatabase>& meshes, co
|
|||
}
|
||||
for ( auto it = data.begin(); it != data.end(); ++it ) {
|
||||
// Get the unique variables
|
||||
std::set<VariableDatabase> 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<VariableDatabase>( data2.begin(), data2.end() );
|
||||
}
|
||||
// Free temporary memory
|
||||
|
@ -311,7 +320,7 @@ std::vector<MeshDatabase> gatherAll( const std::vector<MeshDatabase>& meshes, co
|
|||
// Return the results
|
||||
std::vector<MeshDatabase> data2( data.size() );
|
||||
size_t i = 0;
|
||||
for (std::map<std::string,MeshDatabase>::iterator it=data.begin(); it!=data.end(); ++it, ++i)
|
||||
for ( auto it = data.begin(); it != data.end(); ++it, ++i )
|
||||
data2[i] = it->second;
|
||||
PROFILE_STOP( "gatherAll-unpack", 2 );
|
||||
PROFILE_STOP( "gatherAll" );
|
||||
|
@ -326,22 +335,23 @@ void write( const std::vector<MeshDatabase>& meshes, const std::string& filename
|
|||
FILE *fid = fopen( filename.c_str(), "wb" );
|
||||
for ( size_t i = 0; i < meshes.size(); i++ ) {
|
||||
fprintf( fid, "%s\n", meshes[i].name.c_str() );
|
||||
fprintf(fid," type: %i\n",static_cast<int>(meshes[i].type));
|
||||
fprintf( fid, " type: %s\n", getString( meshes[i].type ).data() );
|
||||
fprintf( fid, " meshClass: %s\n", meshes[i].meshClass.c_str() );
|
||||
fprintf(fid," format: %i\n",static_cast<int>(meshes[i].format));
|
||||
fprintf( fid, " format: %s\n", getString( meshes[i].format ).data() );
|
||||
for ( size_t j = 0; j < meshes[i].domains.size(); j++ )
|
||||
fprintf( fid, " domain: %s\n", meshes[i].domains[j].write().c_str() );
|
||||
fprintf( fid, " variables: " );
|
||||
for ( size_t j = 0; j < meshes[i].variables.size(); j++ ) {
|
||||
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, "%s|%s|%i; ", var.name.data(), getString( var.type ).data(), var.dim );
|
||||
}
|
||||
fprintf( fid, "\n" );
|
||||
std::map<std::pair<std::string,std::string>,DatabaseEntry>::const_iterator it;
|
||||
for (it=meshes[i].variable_data.begin(); it!=meshes[i].variable_data.end(); ++it) {
|
||||
for ( auto it = meshes[i].variable_data.begin(); it != meshes[i].variable_data.end();
|
||||
++it ) {
|
||||
const char *domain = it->first.first.c_str();
|
||||
const char *variable = it->first.second.c_str();
|
||||
fprintf(fid," variable(%s,%s): %s\n",domain,variable,it->second.write().c_str());
|
||||
fprintf(
|
||||
fid, " variable(%s,%s): %s\n", domain, variable, it->second.write().c_str() );
|
||||
}
|
||||
}
|
||||
fclose( fid );
|
||||
|
@ -368,9 +378,9 @@ std::vector<MeshDatabase> read( const std::string& filename )
|
|||
name.resize( name.size() - 1 );
|
||||
meshes.back().name = name;
|
||||
} else if ( strncmp( line, " format:", 10 ) == 0 ) {
|
||||
meshes.back().format = static_cast<unsigned char>(atoi(&line[10]));
|
||||
meshes.back().format = getFileFormat( &line[10] );
|
||||
} else if ( strncmp( line, " type:", 8 ) == 0 ) {
|
||||
meshes.back().type = static_cast<MeshType>(atoi(&line[8]));
|
||||
meshes.back().type = getMeshType( &line[8] );
|
||||
} else if ( strncmp( line, " meshClass:", 13 ) == 0 ) {
|
||||
meshes.back().meshClass = deblank( std::string( &line[13] ) );
|
||||
} else if ( strncmp( line, " domain:", 10 ) == 0 ) {
|
||||
|
@ -384,7 +394,7 @@ std::vector<MeshDatabase> read( const std::string& filename )
|
|||
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].type = getVariableType( tmp[1] );
|
||||
mesh.variables[i].dim = atoi( tmp[2].c_str() );
|
||||
}
|
||||
} else if ( strncmp( line, " variable(", 12 ) == 0 ) {
|
||||
|
@ -410,14 +420,14 @@ std::vector<MeshDatabase> read( const std::string& filename )
|
|||
// Return the mesh type
|
||||
IO::MeshType meshType( const IO::Mesh &mesh )
|
||||
{
|
||||
IO::MeshType type = IO::Unknown;
|
||||
IO::MeshType type = IO::MeshType::Unknown;
|
||||
const std::string meshClass = mesh.className();
|
||||
if ( meshClass == "PointList" ) {
|
||||
type = IO::PointMesh;
|
||||
type = IO::MeshType::PointMesh;
|
||||
} else if ( meshClass == "TriList" || meshClass == "TriMesh" ) {
|
||||
type = IO::SurfaceMesh;
|
||||
type = IO::MeshType::SurfaceMesh;
|
||||
} else if ( meshClass == "DomainMesh" ) {
|
||||
type = IO::VolumeMesh;
|
||||
type = IO::MeshType::VolumeMesh;
|
||||
} else {
|
||||
ERROR( "Unknown mesh" );
|
||||
}
|
||||
|
@ -425,5 +435,4 @@ IO::MeshType meshType( const IO::Mesh& mesh )
|
|||
}
|
||||
|
||||
|
||||
} // IO namespace
|
||||
|
||||
} // namespace IO
|
||||
|
|
|
@ -5,21 +5,14 @@
|
|||
#include "common/MPI.h"
|
||||
|
||||
#include <iostream>
|
||||
#include <map>
|
||||
#include <memory>
|
||||
#include <string.h>
|
||||
#include <vector>
|
||||
#include <map>
|
||||
|
||||
|
||||
namespace IO {
|
||||
|
||||
class Mesh;
|
||||
|
||||
|
||||
//! Enum to identify mesh type
|
||||
//enum class MeshType : char { PointMesh=1, SurfaceMesh=2, VolumeMesh=3, Unknown=-1 };
|
||||
enum MeshType { PointMesh=1, SurfaceMesh=2, VolumeMesh=3, Unknown=-1 };
|
||||
|
||||
|
||||
//! Helper struct for containing offsets for the mesh info
|
||||
struct DatabaseEntry {
|
||||
|
@ -56,11 +49,12 @@ struct MeshDatabase {
|
|||
std::string name; //!< Name of the mesh
|
||||
MeshType type; //!< Mesh type
|
||||
std::string meshClass; //!< Mesh class
|
||||
unsigned char format; //!< Data format (1: old, 2: new, 3: new (single), 4: silo)
|
||||
FileFormat format; //!< Data format (1: old, 2: new, 3: new (single), 4: silo)
|
||||
std::vector<DatabaseEntry> domains; //!< List of the domains
|
||||
std::vector<VariableDatabase> variables; //!< List of the variables
|
||||
std::map<variable_id, DatabaseEntry> variable_data; //!< Data for the variables
|
||||
VariableDatabase getVariableDatabase( const std::string &varname ) const;
|
||||
|
||||
public:
|
||||
MeshDatabase();
|
||||
~MeshDatabase();
|
||||
|
@ -70,7 +64,8 @@ public:
|
|||
|
||||
|
||||
//! Gather the mesh databases from all processors
|
||||
std::vector<MeshDatabase> gatherAll( const std::vector<MeshDatabase>& meshes, const Utilities::MPI& comm );
|
||||
std::vector<MeshDatabase> gatherAll(
|
||||
const std::vector<MeshDatabase> &meshes, const Utilities::MPI &comm );
|
||||
|
||||
|
||||
//! Write the mesh databases to a file
|
||||
|
@ -85,6 +80,6 @@ std::vector<MeshDatabase> read( const std::string& filename );
|
|||
IO::MeshType meshType( const IO::Mesh &mesh );
|
||||
|
||||
|
||||
} // IO namespace
|
||||
} // namespace IO
|
||||
|
||||
#endif
|
||||
|
|
35
IO/PIO.cpp
35
IO/PIO.cpp
|
@ -1,10 +1,10 @@
|
|||
#include "IO/PIO.h"
|
||||
#include "common/Utilities.h"
|
||||
#include "common/MPI.h"
|
||||
#include "common/Utilities.h"
|
||||
|
||||
#include <cstring>
|
||||
#include <fstream>
|
||||
#include <string>
|
||||
#include <cstring>
|
||||
|
||||
|
||||
namespace IO {
|
||||
|
@ -20,7 +20,6 @@ std::ostream perr(&perr_buffer);
|
|||
std::ostream plog( &plog_buffer );
|
||||
|
||||
|
||||
|
||||
/****************************************************************************
|
||||
* Functions to control logging *
|
||||
****************************************************************************/
|
||||
|
@ -95,18 +94,12 @@ void Utilities::stopLogging( )
|
|||
/****************************************************************************
|
||||
* ParallelStreamBuffer class *
|
||||
****************************************************************************/
|
||||
ParallelStreamBuffer::ParallelStreamBuffer( ):
|
||||
d_rank(0), d_size(0), d_buffer_size(0), d_buffer(NULL)
|
||||
ParallelStreamBuffer::ParallelStreamBuffer()
|
||||
: d_rank( 0 ), d_size( 0 ), d_buffer_size( 0 ), d_buffer( NULL )
|
||||
{
|
||||
}
|
||||
ParallelStreamBuffer:: ~ParallelStreamBuffer()
|
||||
{
|
||||
delete [] d_buffer;
|
||||
}
|
||||
void ParallelStreamBuffer::setOutputStream( std::ostream *stream )
|
||||
{
|
||||
d_stream.push_back( stream );
|
||||
}
|
||||
ParallelStreamBuffer::~ParallelStreamBuffer() { delete[] d_buffer; }
|
||||
void ParallelStreamBuffer::setOutputStream( std::ostream *stream ) { d_stream.push_back( stream ); }
|
||||
int ParallelStreamBuffer::sync()
|
||||
{
|
||||
for ( size_t i = 0; i < d_stream.size(); i++ ) {
|
||||
|
@ -140,7 +133,9 @@ std::streamsize ParallelStreamBuffer::xsputn( const char* text, std::streamsize
|
|||
reserve( d_size + n );
|
||||
memcpy( &d_buffer[d_size], text, n );
|
||||
d_size += n;
|
||||
if ( text[n-1]==0 || text[n-1]==10 ) { sync(); }
|
||||
if ( text[n - 1] == 0 || text[n - 1] == 10 ) {
|
||||
sync();
|
||||
}
|
||||
return n;
|
||||
}
|
||||
int ParallelStreamBuffer::overflow( int ch )
|
||||
|
@ -148,13 +143,12 @@ int ParallelStreamBuffer::overflow(int ch)
|
|||
reserve( d_size + 1 );
|
||||
d_buffer[d_size] = ch;
|
||||
d_size++;
|
||||
if ( ch==0 || ch==10 ) { sync(); }
|
||||
if ( ch == 0 || ch == 10 ) {
|
||||
sync();
|
||||
}
|
||||
return std::char_traits<char>::to_int_type( ch );
|
||||
}
|
||||
int ParallelStreamBuffer::underflow()
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
int ParallelStreamBuffer::underflow() { return -1; }
|
||||
void ParallelStreamBuffer::reset()
|
||||
{
|
||||
sync();
|
||||
|
@ -165,5 +159,4 @@ void ParallelStreamBuffer::reset()
|
|||
}
|
||||
|
||||
|
||||
} // IO namespace
|
||||
|
||||
} // namespace IO
|
||||
|
|
1
IO/PIO.h
1
IO/PIO.h
|
@ -45,7 +45,6 @@ inline int printp( const char *format, ... );
|
|||
class ParallelStreamBuffer : public std::streambuf
|
||||
{
|
||||
public:
|
||||
|
||||
/*!
|
||||
* Create a parallel buffer class. The object will require further
|
||||
* initialization to set up the I/O streams and prefix string.
|
||||
|
|
|
@ -3,9 +3,9 @@
|
|||
|
||||
#include "IO/PIO.h"
|
||||
|
||||
#include <cstdio>
|
||||
#include <iostream>
|
||||
#include <stdarg.h>
|
||||
#include <cstdio>
|
||||
|
||||
|
||||
namespace IO {
|
||||
|
@ -24,6 +24,6 @@ inline int printp( const char *format, ... )
|
|||
}
|
||||
|
||||
|
||||
} // IO namespace
|
||||
} // namespace IO
|
||||
|
||||
#endif
|
||||
|
|
|
@ -102,4 +102,3 @@ void unpack<std::string>( std::string& data, const char *buffer )
|
|||
{
|
||||
data = std::string( buffer );
|
||||
}
|
||||
|
||||
|
|
|
@ -2,9 +2,9 @@
|
|||
#ifndef included_PackData
|
||||
#define included_PackData
|
||||
|
||||
#include <vector>
|
||||
#include <set>
|
||||
#include <map>
|
||||
#include <set>
|
||||
#include <vector>
|
||||
|
||||
|
||||
//! Template function to return the buffer size required to pack a class
|
||||
|
@ -75,4 +75,3 @@ void unpack( std::set<TYPE>& data, const char *buffer );
|
|||
#include "IO/PackData.hpp"
|
||||
|
||||
#endif
|
||||
|
||||
|
|
|
@ -4,11 +4,10 @@
|
|||
|
||||
#include "IO/PackData.h"
|
||||
|
||||
#include <map>
|
||||
#include <set>
|
||||
#include <string.h>
|
||||
#include <vector>
|
||||
#include <set>
|
||||
#include <map>
|
||||
|
||||
|
||||
|
||||
/********************************************************
|
||||
|
@ -92,8 +91,10 @@ void pack( const std::map<TYPE1,TYPE2>& rhs, char *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);
|
||||
pack( it->first, &buffer[pos] );
|
||||
pos += packsize( it->first );
|
||||
pack( it->second, &buffer[pos] );
|
||||
pos += packsize( it->second );
|
||||
}
|
||||
}
|
||||
template<class TYPE1, class TYPE2>
|
||||
|
@ -105,8 +106,10 @@ void unpack( std::map<TYPE1,TYPE2>& data, const char *buffer )
|
|||
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);
|
||||
unpack( tmp.first, &buffer[pos] );
|
||||
pos += packsize( tmp.first );
|
||||
unpack( tmp.second, &buffer[pos] );
|
||||
pos += packsize( tmp.second );
|
||||
data.insert( tmp );
|
||||
}
|
||||
}
|
||||
|
@ -133,7 +136,8 @@ void pack( const std::set<TYPE>& rhs, char *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);
|
||||
pack( *it );
|
||||
pos += packsize( *it );
|
||||
}
|
||||
}
|
||||
template<class TYPE>
|
||||
|
@ -145,11 +149,11 @@ void unpack( std::set<TYPE>& data, const char *buffer )
|
|||
data.clear();
|
||||
for ( size_t i = 0; i < N; i++ ) {
|
||||
TYPE tmp;
|
||||
unpack(tmp,&buffer[pos]); pos+=packsize(tmp);
|
||||
unpack( tmp, &buffer[pos] );
|
||||
pos += packsize( tmp );
|
||||
data.insert( tmp );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
|
|
138
IO/Reader.cpp
138
IO/Reader.cpp
|
@ -1,7 +1,7 @@
|
|||
#include "IO/Reader.h"
|
||||
#include "IO/IOHelpers.h"
|
||||
#include "IO/Mesh.h"
|
||||
#include "IO/MeshDatabase.h"
|
||||
#include "IO/IOHelpers.h"
|
||||
#include "common/Utilities.h"
|
||||
|
||||
#ifdef USE_SILO
|
||||
|
@ -10,18 +10,30 @@
|
|||
|
||||
|
||||
#include <ProfilerApp.h>
|
||||
#include <cstdio>
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
#include <map>
|
||||
#include <string.h>
|
||||
#include <vector>
|
||||
#include <map>
|
||||
#include <cstdio>
|
||||
|
||||
|
||||
// Inline function to read line without a return argument
|
||||
static inline void fgetl( char *str, int num, FILE *stream )
|
||||
{
|
||||
char *ptr = fgets( str, num, stream );
|
||||
if ( 0 ) {char *temp = (char *)&ptr; temp++;}
|
||||
if ( 0 ) {
|
||||
char *temp = (char *) &ptr;
|
||||
temp++;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Check if the file exists
|
||||
bool fileExists( const std::string &filename )
|
||||
{
|
||||
std::ifstream ifile( filename.c_str() );
|
||||
return ifile.good();
|
||||
}
|
||||
|
||||
|
||||
|
@ -31,16 +43,42 @@ std::string IO::getPath( const std::string& filename )
|
|||
std::string file( filename );
|
||||
size_t k1 = file.rfind( 47 );
|
||||
size_t k2 = file.rfind( 92 );
|
||||
if ( k1==std::string::npos ) { k1=0; }
|
||||
if ( k2==std::string::npos ) { k2=0; }
|
||||
if ( k1 == std::string::npos ) {
|
||||
k1 = 0;
|
||||
}
|
||||
if ( k2 == std::string::npos ) {
|
||||
k2 = 0;
|
||||
}
|
||||
return file.substr( 0, std::max( k1, k2 ) );
|
||||
}
|
||||
|
||||
|
||||
// List the timesteps in the given directors (dumps.LBPM)
|
||||
std::vector<std::string> IO::readTimesteps( const std::string& filename )
|
||||
// List the timesteps in the given directory (dumps.LBPM)
|
||||
std::vector<std::string> IO::readTimesteps( const std::string &path, const std::string &format )
|
||||
{
|
||||
// Get the name of the summary filename
|
||||
std::string filename = path + "/";
|
||||
if ( format == "old" || format == "new" ) {
|
||||
filename += "summary.LBM";
|
||||
} else if ( format == "silo" ) {
|
||||
filename += "LBM.visit";
|
||||
} else if ( format == "auto" ) {
|
||||
bool test_old = fileExists( path + "/summary.LBM" );
|
||||
bool test_silo = fileExists( path + "/LBM.visit" );
|
||||
if ( test_old && test_silo ) {
|
||||
ERROR( "Unable to determine format (both summary.LBM and LBM.visit exist)" );
|
||||
} else if ( test_old ) {
|
||||
filename += "summary.LBM";
|
||||
} else if ( test_silo ) {
|
||||
filename += "LBM.visit";
|
||||
} else {
|
||||
ERROR( "Unable to determine format (neither summary.LBM or LBM.visit exist)" );
|
||||
}
|
||||
} else {
|
||||
ERROR( "Unknown format: " + format );
|
||||
}
|
||||
PROFILE_START( "readTimesteps" );
|
||||
// Read the data
|
||||
FILE *fid = fopen( filename.c_str(), "rb" );
|
||||
if ( fid == NULL )
|
||||
ERROR( "Error opening file" );
|
||||
|
@ -59,11 +97,52 @@ std::vector<std::string> IO::readTimesteps( const std::string& filename )
|
|||
fclose( fid );
|
||||
PROFILE_STOP( "readTimesteps" );
|
||||
return timesteps;
|
||||
return timesteps;
|
||||
}
|
||||
|
||||
|
||||
// Get the maximum number of domains
|
||||
int IO::maxDomains( const std::string &path, const std::string &format, const Utilities::MPI &comm )
|
||||
{
|
||||
int rank = comm.getRank();
|
||||
int n_domains = 0;
|
||||
if ( rank == 0 ) {
|
||||
// Get the timesteps
|
||||
auto timesteps = IO::readTimesteps( path, format );
|
||||
ASSERT( !timesteps.empty() );
|
||||
// Get the database for the first domain
|
||||
auto db = IO::getMeshList( path, timesteps[0] );
|
||||
for ( size_t i = 0; i < db.size(); i++ )
|
||||
n_domains = std::max<int>( n_domains, db[i].domains.size() );
|
||||
}
|
||||
return comm.bcast( n_domains, 0 );
|
||||
}
|
||||
|
||||
|
||||
// Read the data for the given timestep
|
||||
std::vector<IO::MeshDataStruct> IO::readData(
|
||||
const std::string &path, const std::string ×tep, int rank )
|
||||
{
|
||||
// Get the mesh databases
|
||||
auto db = IO::getMeshList( path, timestep );
|
||||
// Create the data
|
||||
std::vector<IO::MeshDataStruct> data( db.size() );
|
||||
for ( size_t i = 0; i < data.size(); i++ ) {
|
||||
data[i].precision = IO::DataType::Double;
|
||||
data[i].meshName = db[i].name;
|
||||
data[i].mesh = getMesh( path, timestep, db[i], rank );
|
||||
data[i].vars.resize( db[i].variables.size() );
|
||||
for ( size_t j = 0; j < db[i].variables.size(); j++ )
|
||||
data[i].vars[j] = getVariable( path, timestep, db[i], rank, db[i].variables[j].name );
|
||||
INSIST( data[i].check(), "Failed check of " + data[i].meshName );
|
||||
}
|
||||
return data;
|
||||
}
|
||||
|
||||
|
||||
// Read the list of variables for the given timestep
|
||||
std::vector<IO::MeshDatabase> IO::getMeshList( const std::string& path, const std::string& timestep )
|
||||
std::vector<IO::MeshDatabase> IO::getMeshList(
|
||||
const std::string &path, const std::string ×tep )
|
||||
{
|
||||
std::string filename = path + "/" + timestep + "/LBM.summary";
|
||||
return IO::read( filename );
|
||||
|
@ -76,7 +155,7 @@ std::shared_ptr<IO::Mesh> IO::getMesh( const std::string& path, const std::strin
|
|||
{
|
||||
PROFILE_START( "getMesh" );
|
||||
std::shared_ptr<IO::Mesh> mesh;
|
||||
if ( meshDatabase.format==1 ) {
|
||||
if ( meshDatabase.format == FileFormat::OLD ) {
|
||||
// Old format (binary doubles)
|
||||
std::string filename = path + "/" + timestep + "/" + meshDatabase.domains[domain].file;
|
||||
FILE *fid = fopen( filename.c_str(), "rb" );
|
||||
|
@ -90,7 +169,7 @@ std::shared_ptr<IO::Mesh> IO::getMesh( const std::string& path, const std::strin
|
|||
fclose( fid );
|
||||
if ( count % 3 != 0 )
|
||||
ERROR( "Error reading file" );
|
||||
if ( meshDatabase.type==IO::PointMesh ) {
|
||||
if ( meshDatabase.type == IO::MeshType::PointMesh ) {
|
||||
size_t N = count / 3;
|
||||
std::shared_ptr<PointList> pointlist( new PointList( N ) );
|
||||
std::vector<Point> &P = pointlist->points;
|
||||
|
@ -100,7 +179,7 @@ std::shared_ptr<IO::Mesh> IO::getMesh( const std::string& path, const std::strin
|
|||
P[i].z = data[3 * i + 2];
|
||||
}
|
||||
mesh = pointlist;
|
||||
} else if ( meshDatabase.type==IO::SurfaceMesh ) {
|
||||
} else if ( meshDatabase.type == IO::MeshType::SurfaceMesh ) {
|
||||
if ( count % 9 != 0 )
|
||||
ERROR( "Error reading file (2)" );
|
||||
size_t N_tri = count / 9;
|
||||
|
@ -120,14 +199,15 @@ std::shared_ptr<IO::Mesh> IO::getMesh( const std::string& path, const std::strin
|
|||
C[i].z = data[9 * i + 8];
|
||||
}
|
||||
mesh = trilist;
|
||||
} else if ( meshDatabase.type==IO::VolumeMesh ) {
|
||||
} else if ( meshDatabase.type == IO::MeshType::VolumeMesh ) {
|
||||
// this was never supported in the old format
|
||||
mesh = std::shared_ptr<DomainMesh>( new DomainMesh() );
|
||||
} else {
|
||||
ERROR( "Unknown mesh type" );
|
||||
}
|
||||
delete[] data;
|
||||
} else if ( meshDatabase.format==2 ) {
|
||||
} else if ( meshDatabase.format == FileFormat::NEW ||
|
||||
meshDatabase.format == FileFormat::NEW_SINGLE ) {
|
||||
const DatabaseEntry &database = meshDatabase.domains[domain];
|
||||
std::string filename = path + "/" + timestep + "/" + database.file;
|
||||
FILE *fid = fopen( filename.c_str(), "rb" );
|
||||
|
@ -154,7 +234,7 @@ std::shared_ptr<IO::Mesh> IO::getMesh( const std::string& path, const std::strin
|
|||
}
|
||||
mesh->unpack( std::pair<size_t, void *>( bytes, data ) );
|
||||
delete[] data;
|
||||
} else if ( meshDatabase.format==4 ) {
|
||||
} else if ( meshDatabase.format == FileFormat::SILO ) {
|
||||
// Reading a silo file
|
||||
#ifdef USE_SILO
|
||||
const DatabaseEntry &database = meshDatabase.domains[domain];
|
||||
|
@ -200,7 +280,8 @@ std::shared_ptr<IO::Mesh> IO::getMesh( const std::string& path, const std::strin
|
|||
silo::readUniformMesh( fid, database.name, range, N );
|
||||
auto rankinfo = silo::read<int>( fid, database.name + "_rankinfo" );
|
||||
RankInfoStruct rank_data( rankinfo[0], rankinfo[1], rankinfo[2], rankinfo[3] );
|
||||
mesh.reset( new IO::DomainMesh( rank_data, N[0], N[1], N[2], range[1]-range[0], range[3]-range[2], range[5]-range[4] ) );
|
||||
mesh.reset( new IO::DomainMesh( rank_data, N[0], N[1], N[2], range[1] - range[0],
|
||||
range[3] - range[2], range[5] - range[4] ) );
|
||||
} else {
|
||||
ERROR( "Unknown mesh class" );
|
||||
}
|
||||
|
@ -221,12 +302,11 @@ std::shared_ptr<IO::Variable> IO::getVariable( const std::string& path, const st
|
|||
const MeshDatabase &meshDatabase, int domain, const std::string &variable )
|
||||
{
|
||||
std::pair<std::string, std::string> key( meshDatabase.domains[domain].name, variable );
|
||||
std::map<std::pair<std::string,std::string>,DatabaseEntry>::const_iterator it;
|
||||
it = meshDatabase.variable_data.find(key);
|
||||
auto it = meshDatabase.variable_data.find( key );
|
||||
if ( it == meshDatabase.variable_data.end() )
|
||||
return std::shared_ptr<IO::Variable>();
|
||||
std::shared_ptr<IO::Variable> var;
|
||||
if ( meshDatabase.format == 2 ) {
|
||||
if ( meshDatabase.format == FileFormat::NEW || meshDatabase.format == FileFormat::NEW_SINGLE ) {
|
||||
const DatabaseEntry &database = it->second;
|
||||
std::string filename = path + "/" + timestep + "/" + database.file;
|
||||
FILE *fid = fopen( filename.c_str(), "rb" );
|
||||
|
@ -238,15 +318,15 @@ std::shared_ptr<IO::Variable> IO::getVariable( const std::string& path, const st
|
|||
std::vector<std::string> values = splitList( &line[i2 + 1], ',' );
|
||||
ASSERT( values.size() == 5 );
|
||||
int dim = atoi( values[0].c_str() );
|
||||
int type = atoi(values[1].c_str());
|
||||
auto type = values[1];
|
||||
size_t N = atol( values[2].c_str() );
|
||||
size_t bytes = atol( values[3].c_str() );
|
||||
std::string precision = values[4];
|
||||
var = std::shared_ptr<IO::Variable>( new IO::Variable() );
|
||||
var->dim = dim;
|
||||
var->type = static_cast<IO::VariableType>(type);
|
||||
var->type = getVariableType( type );
|
||||
var->name = variable;
|
||||
var->data.resize(N*dim);
|
||||
var->data.resize( N, dim );
|
||||
if ( precision == "double" ) {
|
||||
size_t count = fread( var->data.data(), sizeof( double ), N * dim, fid );
|
||||
ASSERT( count * sizeof( double ) == bytes );
|
||||
|
@ -254,7 +334,7 @@ std::shared_ptr<IO::Variable> IO::getVariable( const std::string& path, const st
|
|||
ERROR( "Format not implimented" );
|
||||
}
|
||||
fclose( fid );
|
||||
} else if ( meshDatabase.format == 4 ) {
|
||||
} else if ( meshDatabase.format == FileFormat::SILO ) {
|
||||
// Reading a silo file
|
||||
#ifdef USE_SILO
|
||||
const auto &database = meshDatabase.domains[domain];
|
||||
|
@ -291,9 +371,12 @@ void IO::reformatVariable( const IO::Mesh& mesh, IO::Variable& var )
|
|||
if ( mesh.className() == "DomainMesh" ) {
|
||||
const IO::DomainMesh &mesh2 = dynamic_cast<const IO::DomainMesh &>( mesh );
|
||||
if ( var.type == VariableType::NodeVariable ) {
|
||||
size_t N2 = var.data.length() / ((mesh2.nx+1)*(mesh2.ny+1)*(mesh2.nz+1));
|
||||
ASSERT( (mesh2.nx+1)*(mesh2.ny+1)*(mesh2.nz+1)*N2 == var.data.length() );
|
||||
var.data.reshape( { (size_t) mesh2.nx+1, (size_t) mesh2.ny+1, (size_t) mesh2.nz+1, N2 } );
|
||||
size_t N2 =
|
||||
var.data.length() / ( ( mesh2.nx + 1 ) * ( mesh2.ny + 1 ) * ( mesh2.nz + 1 ) );
|
||||
ASSERT(
|
||||
( mesh2.nx + 1 ) * ( mesh2.ny + 1 ) * ( mesh2.nz + 1 ) * N2 == var.data.length() );
|
||||
var.data.reshape(
|
||||
{ (size_t) mesh2.nx + 1, (size_t) mesh2.ny + 1, (size_t) mesh2.nz + 1, N2 } );
|
||||
} else if ( var.type == VariableType::EdgeVariable ) {
|
||||
ERROR( "Not finished" );
|
||||
} else if ( var.type == VariableType::SurfaceVariable ) {
|
||||
|
@ -335,6 +418,3 @@ void IO::reformatVariable( const IO::Mesh& mesh, IO::Variable& var )
|
|||
ERROR( "Unknown mesh type" );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
|
45
IO/Reader.h
45
IO/Reader.h
|
@ -17,8 +17,47 @@ namespace IO {
|
|||
std::string getPath( const std::string &filename );
|
||||
|
||||
|
||||
//! List the timesteps in the given directors (dumps.LBPM)
|
||||
std::vector<std::string> readTimesteps( const std::string& filename );
|
||||
/*!
|
||||
* @brief Get the maximum number of domains written
|
||||
* @details This function reads the summary files to determine the maximum
|
||||
* number of domains in the output.
|
||||
* @param[in] path The path to use for reading
|
||||
* @param[in] format The data format to use:
|
||||
* old - Old mesh format (provided for backward compatibility)
|
||||
* new - New format, 1 file/process
|
||||
* silo - Silo
|
||||
* auto - Auto-determin the format
|
||||
* @param[in] comm Optional comm to use to reduce IO load by
|
||||
* reading on rank 0 and then communicating the result
|
||||
*/
|
||||
int maxDomains( const std::string &path, const std::string &format = "auto",
|
||||
const Utilities::MPI &comm = MPI_COMM_SELF );
|
||||
|
||||
|
||||
/*!
|
||||
* @brief Read the timestep list
|
||||
* @details This function reads the timestep list from the summary file.
|
||||
* @param[in] path The path to use for reading
|
||||
* @param[in] format The data format to use:
|
||||
* old - Old mesh format (provided for backward compatibility)
|
||||
* new - New format, 1 file/process
|
||||
* silo - Silo
|
||||
* auto - Auto-determin the format
|
||||
* @return append Append any existing data (default is false)
|
||||
*/
|
||||
std::vector<std::string> readTimesteps(
|
||||
const std::string &path, const std::string &format = "auto" );
|
||||
|
||||
|
||||
/*!
|
||||
* @brief Read the data for the timestep
|
||||
* @details This function reads the mesh and variable data provided for the given timestep.
|
||||
* @param[in] path The path to use for reading
|
||||
* @param[in] timestep The timestep iteration
|
||||
* @param[in] domain The desired domain to read
|
||||
*/
|
||||
std::vector<IO::MeshDataStruct> readData(
|
||||
const std::string &path, const std::string ×tep, int domain );
|
||||
|
||||
|
||||
//! Read the list of mesh databases for the given timestep
|
||||
|
@ -53,6 +92,6 @@ std::shared_ptr<IO::Variable> getVariable( const std::string& path, const std::s
|
|||
void reformatVariable( const IO::Mesh &mesh, IO::Variable &var );
|
||||
|
||||
|
||||
} // IO namespace
|
||||
} // namespace IO
|
||||
|
||||
#endif
|
||||
|
|
216
IO/Writer.cpp
216
IO/Writer.cpp
|
@ -1,21 +1,62 @@
|
|||
#include "IO/Writer.h"
|
||||
#include "IO/MeshDatabase.h"
|
||||
#include "IO/IOHelpers.h"
|
||||
#include "IO/MeshDatabase.h"
|
||||
#include "IO/silo.h"
|
||||
#include "common/MPI.h"
|
||||
#include "common/Utilities.h"
|
||||
|
||||
#include <sys/stat.h>
|
||||
#include <algorithm>
|
||||
#include <vector>
|
||||
#include <set>
|
||||
#include <memory>
|
||||
|
||||
#include <set>
|
||||
#include <sys/stat.h>
|
||||
#include <vector>
|
||||
|
||||
|
||||
enum class Format { OLD, NEW, SILO, UNKNOWN };
|
||||
|
||||
|
||||
/****************************************************
|
||||
* Recursively create the subdirectory *
|
||||
****************************************************/
|
||||
static void recursiveMkdir( const std::string &path, mode_t mode )
|
||||
{
|
||||
// Iterate through the root directories until we create the desired path
|
||||
for ( size_t pos = 0; pos < path.size(); ) {
|
||||
// slide backwards in string until next slash found
|
||||
pos++;
|
||||
for ( ; pos < path.size(); pos++ ) {
|
||||
if ( path[pos] == '/' || path[pos] == 92 )
|
||||
break;
|
||||
}
|
||||
// Create the temporary path
|
||||
auto path2 = path.substr( 0, pos );
|
||||
// Check if the temporary path exists
|
||||
struct stat status;
|
||||
int result = stat( path2.data(), &status );
|
||||
if ( result == 0 ) {
|
||||
// if there is a part of the path that already exists make sure it is really a directory
|
||||
if ( !S_ISDIR( status.st_mode ) ) {
|
||||
ERROR(
|
||||
"Error in recursiveMkdir...\n"
|
||||
" Cannot create directories in path = " +
|
||||
path +
|
||||
"\n because some intermediate item in path exists and is NOT a directory" );
|
||||
}
|
||||
continue;
|
||||
}
|
||||
// Create the directory and test the result
|
||||
result = mkdir( path2.data(), mode );
|
||||
if ( result != 0 ) {
|
||||
// Maybe another rank created the directory, check
|
||||
int result = stat( path2.data(), &status );
|
||||
if ( result != 0 && !S_ISDIR( status.st_mode ) )
|
||||
ERROR( "Error in Utilities::recursiveMkdir...\n"
|
||||
" Cannot create directory = " +
|
||||
path2 );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/****************************************************
|
||||
* Initialize the writer *
|
||||
|
@ -38,7 +79,7 @@ void IO::initialize( const std::string& path, const std::string& format, bool ap
|
|||
ERROR( "Unknown format" );
|
||||
int rank = Utilities::MPI( MPI_COMM_WORLD ).getRank();
|
||||
if ( !append && rank == 0 ) {
|
||||
mkdir(path.c_str(),S_IRWXU|S_IRGRP);
|
||||
recursiveMkdir( path, S_IRWXU | S_IRGRP );
|
||||
std::string filename;
|
||||
if ( global_IO_format == Format::OLD || global_IO_format == Format::NEW )
|
||||
filename = global_IO_path + "/summary.LBM";
|
||||
|
@ -53,9 +94,9 @@ void IO::initialize( const std::string& path, const std::string& format, bool ap
|
|||
|
||||
|
||||
// Write the mesh data in the original format
|
||||
static std::vector<IO::MeshDatabase> writeMeshesOrigFormat( const std::vector<IO::MeshDataStruct>& meshData, const std::string& path )
|
||||
static std::vector<IO::MeshDatabase> writeMeshesOrigFormat(
|
||||
const std::vector<IO::MeshDataStruct> &meshData, const std::string &path, int rank )
|
||||
{
|
||||
int rank = Utilities::MPI(MPI_COMM_WORLD).getRank();
|
||||
std::vector<IO::MeshDatabase> meshes_written;
|
||||
for ( size_t i = 0; i < meshData.size(); i++ ) {
|
||||
char domainname[100], filename[100], fullpath[200];
|
||||
|
@ -69,25 +110,28 @@ static std::vector<IO::MeshDatabase> writeMeshesOrigFormat( const std::vector<IO
|
|||
mesh_entry.name = meshData[i].meshName;
|
||||
mesh_entry.type = meshType( *mesh );
|
||||
mesh_entry.meshClass = meshData[i].mesh->className();
|
||||
mesh_entry.format = 1;
|
||||
mesh_entry.format = IO::FileFormat::OLD;
|
||||
IO::DatabaseEntry domain;
|
||||
domain.name = domainname;
|
||||
domain.file = filename;
|
||||
domain.offset = 0;
|
||||
mesh_entry.domains.push_back( domain );
|
||||
if ( !meshData[i].vars.empty() ) {
|
||||
printf("Warning: variables are not supported with this format\n");
|
||||
printf( "Warning: variables are not supported with this format (original)\n" );
|
||||
// for (size_t j=0; j<meshData[i].vars.size(); j++)
|
||||
// mesh_entry.variables.push_back( meshData[i].vars[j]->name );
|
||||
}
|
||||
const std::string meshClass = mesh->className();
|
||||
if ( meshClass == "PointList" ) {
|
||||
// List of points
|
||||
std::shared_ptr<IO::PointList> pointlist = std::dynamic_pointer_cast<IO::PointList>(mesh);
|
||||
std::shared_ptr<IO::PointList> pointlist =
|
||||
std::dynamic_pointer_cast<IO::PointList>( mesh );
|
||||
const std::vector<Point> &P = pointlist->points;
|
||||
for ( size_t i = 0; i < P.size(); i++ ) {
|
||||
double x[3];
|
||||
x[0] = P[i].x; x[1] = P[i].y; x[2] = P[i].z;
|
||||
x[0] = P[i].x;
|
||||
x[1] = P[i].y;
|
||||
x[2] = P[i].z;
|
||||
fwrite( x, sizeof( double ), 3, fid );
|
||||
}
|
||||
} else if ( meshClass == "TriList" || meshClass == "TriMesh" ) {
|
||||
|
@ -98,9 +142,15 @@ static std::vector<IO::MeshDatabase> writeMeshesOrigFormat( const std::vector<IO
|
|||
const std::vector<Point> &C = trilist->C;
|
||||
for ( size_t i = 0; i < A.size(); i++ ) {
|
||||
double tri[9];
|
||||
tri[0] = A[i].x; tri[1] = A[i].y; tri[2] = A[i].z;
|
||||
tri[3] = B[i].x; tri[4] = B[i].y; tri[5] = B[i].z;
|
||||
tri[6] = C[i].x; tri[7] = C[i].y; tri[8] = C[i].z;
|
||||
tri[0] = A[i].x;
|
||||
tri[1] = A[i].y;
|
||||
tri[2] = A[i].z;
|
||||
tri[3] = B[i].x;
|
||||
tri[4] = B[i].y;
|
||||
tri[5] = B[i].z;
|
||||
tri[6] = C[i].x;
|
||||
tri[7] = C[i].y;
|
||||
tri[8] = C[i].z;
|
||||
fwrite( tri, sizeof( double ), 9, fid );
|
||||
}
|
||||
} else if ( meshClass == "DomainMesh" ) {
|
||||
|
@ -110,7 +160,9 @@ static std::vector<IO::MeshDatabase> writeMeshesOrigFormat( const std::vector<IO
|
|||
}
|
||||
fclose( fid );
|
||||
std::sort( mesh_entry.variables.begin(), mesh_entry.variables.end() );
|
||||
mesh_entry.variables.erase( std::unique( mesh_entry.variables.begin(), mesh_entry.variables.end() ), mesh_entry.variables.end() );
|
||||
mesh_entry.variables.erase(
|
||||
std::unique( mesh_entry.variables.begin(), mesh_entry.variables.end() ),
|
||||
mesh_entry.variables.end() );
|
||||
meshes_written.push_back( mesh_entry );
|
||||
}
|
||||
return meshes_written;
|
||||
|
@ -118,9 +170,9 @@ static std::vector<IO::MeshDatabase> writeMeshesOrigFormat( const std::vector<IO
|
|||
|
||||
|
||||
// Create the database entry for the mesh data
|
||||
static IO::MeshDatabase getDatabase( const std::string& filename, const IO::MeshDataStruct& mesh, int format )
|
||||
static IO::MeshDatabase getDatabase(
|
||||
const std::string &filename, const IO::MeshDataStruct &mesh, IO::FileFormat format, int rank )
|
||||
{
|
||||
int rank = Utilities::MPI(MPI_COMM_WORLD).getRank();
|
||||
char domainname[100];
|
||||
sprintf( domainname, "%s_%05i", mesh.meshName.c_str(), rank );
|
||||
// Create the MeshDatabase
|
||||
|
@ -158,12 +210,11 @@ static IO::MeshDatabase getDatabase( const std::string& filename, const IO::Mesh
|
|||
|
||||
// Write a mesh (and variables) to a file
|
||||
static IO::MeshDatabase write_domain( FILE *fid, const std::string &filename,
|
||||
const IO::MeshDataStruct& mesh, int format )
|
||||
const IO::MeshDataStruct &mesh, IO::FileFormat format, int rank )
|
||||
{
|
||||
const int level = 0;
|
||||
int rank = Utilities::MPI(MPI_COMM_WORLD).getRank();
|
||||
// Create the MeshDatabase
|
||||
IO::MeshDatabase database = getDatabase( filename, mesh, format );
|
||||
IO::MeshDatabase database = getDatabase( filename, mesh, format, rank );
|
||||
// Write the mesh
|
||||
IO::DatabaseEntry &domain = database.domains[0];
|
||||
domain.offset = ftell( fid );
|
||||
|
@ -174,20 +225,17 @@ static IO::MeshDatabase write_domain( FILE *fid, const std::string& filename,
|
|||
delete[]( char * ) data.second;
|
||||
// Write the variables
|
||||
for ( size_t i = 0; i < mesh.vars.size(); i++ ) {
|
||||
ASSERT( mesh.vars[i]->type != IO::VariableType::NullVariable );
|
||||
std::pair<std::string, std::string> key( domain.name, mesh.vars[i]->name );
|
||||
IO::DatabaseEntry& variable = database.variable_data[key];
|
||||
auto &variable = database.variable_data[key];
|
||||
variable.offset = ftell( fid );
|
||||
int dim = mesh.vars[i]->dim;
|
||||
int type = static_cast<int>(mesh.vars[i]->type);
|
||||
auto type = getString( mesh.vars[i]->type );
|
||||
size_t N = mesh.vars[i]->data.length();
|
||||
if ( type == static_cast<int>(IO::VariableType::NullVariable) ) {
|
||||
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",
|
||||
database.name.c_str(), rank, variable.name.c_str(),
|
||||
dim, type, N_mesh, N*sizeof(double) );
|
||||
fprintf( fid, "Var: %s-%05i-%s: %i, %s, %lu, %lu, double\n", database.name.c_str(), rank,
|
||||
variable.name.c_str(), dim, type.data(), N_mesh, N * sizeof( double ) );
|
||||
fwrite( mesh.vars[i]->data.data(), sizeof( double ), N, fid );
|
||||
fprintf( fid, "\n" );
|
||||
}
|
||||
|
@ -198,7 +246,8 @@ static IO::MeshDatabase write_domain( FILE *fid, const std::string& filename,
|
|||
#ifdef USE_SILO
|
||||
// Write a PointList mesh (and variables) to a file
|
||||
template<class TYPE>
|
||||
static void writeSiloPointMesh( DBfile *fid, const IO::PointList& mesh, const std::string& meshname )
|
||||
static void writeSiloPointMesh(
|
||||
DBfile *fid, const IO::PointList &mesh, const std::string &meshname )
|
||||
{
|
||||
const auto &points = mesh.getPoints();
|
||||
std::vector<TYPE> x( points.size() ), y( points.size() ), z( points.size() );
|
||||
|
@ -208,9 +257,10 @@ static void writeSiloPointMesh( DBfile *fid, const IO::PointList& mesh, const st
|
|||
z[i] = points[i].z;
|
||||
}
|
||||
const TYPE *coords[] = { x.data(), y.data(), z.data() };
|
||||
silo::writePointMesh<TYPE>( fid, meshname, 3, points.size(), coords );
|
||||
IO::silo::writePointMesh<TYPE>( fid, meshname, 3, points.size(), coords );
|
||||
}
|
||||
static void writeSiloPointList( DBfile *fid, const IO::MeshDataStruct& meshData, IO::MeshDatabase database )
|
||||
static void writeSiloPointList(
|
||||
DBfile *fid, const IO::MeshDataStruct &meshData, IO::MeshDatabase database )
|
||||
{
|
||||
const IO::PointList &mesh = dynamic_cast<IO::PointList &>( *meshData.mesh );
|
||||
const std::string meshname = database.domains[0].name;
|
||||
|
@ -229,19 +279,19 @@ static void writeSiloPointList( DBfile *fid, const IO::MeshDataStruct& meshData,
|
|||
z[i] = points[i].z;
|
||||
}
|
||||
const double *coords[] = { x.data(), y.data(), z.data() };
|
||||
silo::writePointMesh( fid, meshname, 3, points.size(), coords );
|
||||
IO::silo::writePointMesh( fid, meshname, 3, points.size(), coords );
|
||||
for ( size_t i = 0; i < meshData.vars.size(); i++ ) {
|
||||
const IO::Variable &var = *meshData.vars[i];
|
||||
if ( var.precision == IO::DataType::Double ) {
|
||||
silo::writePointMeshVariable( fid, meshname, var.name, var.data );
|
||||
IO::silo::writePointMeshVariable( fid, meshname, var.name, var.data );
|
||||
} else if ( var.precision == IO::DataType::Float ) {
|
||||
Array<float> data2( var.data.size() );
|
||||
data2.copy( var.data );
|
||||
silo::writePointMeshVariable( fid, meshname, var.name, data2 );
|
||||
IO::silo::writePointMeshVariable( fid, meshname, var.name, data2 );
|
||||
} else if ( var.precision == IO::DataType::Int ) {
|
||||
Array<int> data2( var.data.size() );
|
||||
data2.copy( var.data );
|
||||
silo::writePointMeshVariable( fid, meshname, var.name, data2 );
|
||||
IO::silo::writePointMeshVariable( fid, meshname, var.name, data2 );
|
||||
} else {
|
||||
ERROR( "Unsupported format" );
|
||||
}
|
||||
|
@ -260,7 +310,7 @@ static void writeSiloTriMesh( DBfile *fid, const IO::TriMesh& mesh, const std::s
|
|||
}
|
||||
const TYPE *coords[] = { x.data(), y.data(), z.data() };
|
||||
const int *tri[] = { mesh.A.data(), mesh.B.data(), mesh.C.data() };
|
||||
silo::writeTriMesh<TYPE>( fid, meshname, 3, 2, points.size(), coords, mesh.A.size(), tri );
|
||||
IO::silo::writeTriMesh<TYPE>( fid, meshname, 3, 2, points.size(), coords, mesh.A.size(), tri );
|
||||
}
|
||||
static void writeSiloTriMesh2( DBfile *fid, const IO::MeshDataStruct &meshData,
|
||||
const IO::TriMesh &mesh, IO::MeshDatabase database )
|
||||
|
@ -275,57 +325,60 @@ static void writeSiloTriMesh2( DBfile *fid, const IO::MeshDataStruct& meshData,
|
|||
}
|
||||
for ( size_t i = 0; i < meshData.vars.size(); i++ ) {
|
||||
const IO::Variable &var = *meshData.vars[i];
|
||||
auto type = static_cast<silo::VariableType>( var.type );
|
||||
if ( var.precision == IO::DataType::Double ) {
|
||||
silo::writeTriMeshVariable( fid, 3, meshname, var.name, var.data, type );
|
||||
IO::silo::writeTriMeshVariable( fid, 3, meshname, var.name, var.data, var.type );
|
||||
} else if ( var.precision == IO::DataType::Float ) {
|
||||
Array<float> data2( var.data.size() );
|
||||
data2.copy( var.data );
|
||||
silo::writeTriMeshVariable( fid, 3, meshname, var.name, data2, type );
|
||||
IO::silo::writeTriMeshVariable( fid, 3, meshname, var.name, data2, var.type );
|
||||
} else if ( var.precision == IO::DataType::Int ) {
|
||||
Array<int> data2( var.data.size() );
|
||||
data2.copy( var.data );
|
||||
silo::writeTriMeshVariable( fid, 3, meshname, var.name, data2, type );
|
||||
IO::silo::writeTriMeshVariable( fid, 3, meshname, var.name, data2, var.type );
|
||||
} else {
|
||||
ERROR( "Unsupported format" );
|
||||
}
|
||||
}
|
||||
}
|
||||
static void writeSiloTriMesh( DBfile *fid, const IO::MeshDataStruct& meshData, IO::MeshDatabase database )
|
||||
static void writeSiloTriMesh(
|
||||
DBfile *fid, const IO::MeshDataStruct &meshData, IO::MeshDatabase database )
|
||||
{
|
||||
const IO::TriMesh &mesh = dynamic_cast<IO::TriMesh &>( *meshData.mesh );
|
||||
writeSiloTriMesh2( fid, meshData, mesh, database );
|
||||
}
|
||||
static void writeSiloTriList( DBfile *fid, const IO::MeshDataStruct& meshData, IO::MeshDatabase database )
|
||||
static void writeSiloTriList(
|
||||
DBfile *fid, const IO::MeshDataStruct &meshData, IO::MeshDatabase database )
|
||||
{
|
||||
auto mesh = getTriMesh( meshData.mesh );
|
||||
writeSiloTriMesh2( fid, meshData, *mesh, database );
|
||||
}
|
||||
// Write a DomainMesh mesh (and variables) to a file
|
||||
static void writeSiloDomainMesh( DBfile *fid, const IO::MeshDataStruct& meshData, IO::MeshDatabase database )
|
||||
static void writeSiloDomainMesh(
|
||||
DBfile *fid, const IO::MeshDataStruct &meshData, IO::MeshDatabase database )
|
||||
{
|
||||
const IO::DomainMesh &mesh = dynamic_cast<IO::DomainMesh &>( *meshData.mesh );
|
||||
RankInfoStruct info( mesh.rank, mesh.nprocx, mesh.nprocy, mesh.nprocz );
|
||||
std::array<double,6> range = { info.ix*mesh.Lx/info.nx, (info.ix+1)*mesh.Lx/info.nx,
|
||||
info.jy*mesh.Ly/info.ny, (info.jy+1)*mesh.Ly/info.ny,
|
||||
info.kz*mesh.Lz/info.nz, (info.kz+1)*mesh.Lz/info.nz };
|
||||
std::array<double, 6> range = { info.ix * mesh.Lx / info.nx,
|
||||
( info.ix + 1 ) * mesh.Lx / info.nx, info.jy * mesh.Ly / info.ny,
|
||||
( info.jy + 1 ) * mesh.Ly / info.ny, info.kz * mesh.Lz / info.nz,
|
||||
( info.kz + 1 ) * mesh.Lz / info.nz };
|
||||
std::array<int, 3> N = { mesh.nx, mesh.ny, mesh.nz };
|
||||
auto meshname = database.domains[0].name;
|
||||
silo::writeUniformMesh<3>( fid, meshname, range, N );
|
||||
silo::write<int>( fid, meshname+"_rankinfo", { mesh.rank, mesh.nprocx, mesh.nprocy, mesh.nprocz } );
|
||||
IO::silo::writeUniformMesh<3>( fid, meshname, range, N );
|
||||
IO::silo::write<int>(
|
||||
fid, meshname + "_rankinfo", { mesh.rank, mesh.nprocx, mesh.nprocy, mesh.nprocz } );
|
||||
for ( size_t i = 0; i < meshData.vars.size(); i++ ) {
|
||||
const auto &var = *meshData.vars[i];
|
||||
auto type = static_cast<silo::VariableType>( var.type );
|
||||
if ( var.precision == IO::DataType::Double ) {
|
||||
silo::writeUniformMeshVariable<3>( fid, meshname, N, var.name, var.data, type );
|
||||
IO::silo::writeUniformMeshVariable<3>( fid, meshname, N, var.name, var.data, var.type );
|
||||
} else if ( var.precision == IO::DataType::Float ) {
|
||||
Array<float> data2( var.data.size() );
|
||||
data2.copy( var.data );
|
||||
silo::writeUniformMeshVariable<3>( fid, meshname, N, var.name, data2, type );
|
||||
IO::silo::writeUniformMeshVariable<3>( fid, meshname, N, var.name, data2, var.type );
|
||||
} else if ( var.precision == IO::DataType::Int ) {
|
||||
Array<int> data2( var.data.size() );
|
||||
data2.copy( var.data );
|
||||
silo::writeUniformMeshVariable<3>( fid, meshname, N, var.name, data2, type );
|
||||
IO::silo::writeUniformMeshVariable<3>( fid, meshname, N, var.name, data2, var.type );
|
||||
} else {
|
||||
ERROR( "Unsupported format" );
|
||||
}
|
||||
|
@ -333,10 +386,10 @@ static void writeSiloDomainMesh( DBfile *fid, const IO::MeshDataStruct& meshData
|
|||
}
|
||||
// Write a mesh (and variables) to a file
|
||||
static IO::MeshDatabase write_domain_silo( DBfile *fid, const std::string &filename,
|
||||
const IO::MeshDataStruct& mesh, int format )
|
||||
const IO::MeshDataStruct &mesh, IO::FileFormat format, int rank )
|
||||
{
|
||||
// Create the MeshDatabase
|
||||
auto database = getDatabase( filename, mesh, format );
|
||||
auto database = getDatabase( filename, mesh, format, rank );
|
||||
if ( database.meshClass == "PointList" ) {
|
||||
writeSiloPointList( fid, mesh, database );
|
||||
} else if ( database.meshClass == "TriMesh" ) {
|
||||
|
@ -372,9 +425,10 @@ std::pair<int,int> getSiloMeshType( const std::string& meshClass )
|
|||
}
|
||||
return std::make_pair( meshType, varType );
|
||||
}
|
||||
void writeSiloSummary( const std::vector<IO::MeshDatabase>& meshes_written, const std::string& filename )
|
||||
void writeSiloSummary(
|
||||
const std::vector<IO::MeshDatabase> &meshes_written, const std::string &filename )
|
||||
{
|
||||
auto fid = silo::open( filename, silo::CREATE );
|
||||
auto fid = IO::silo::open( filename, IO::silo::CREATE );
|
||||
for ( const auto &data : meshes_written ) {
|
||||
auto type = getSiloMeshType( data.meshClass );
|
||||
std::vector<int> meshTypes( data.domains.size(), type.first );
|
||||
|
@ -382,24 +436,24 @@ void writeSiloSummary( const std::vector<IO::MeshDatabase>& meshes_written, cons
|
|||
std::vector<std::string> meshNames;
|
||||
for ( const auto &tmp : data.domains )
|
||||
meshNames.push_back( tmp.file + ":" + tmp.name );
|
||||
silo::writeMultiMesh( fid, data.name, meshNames, meshTypes );
|
||||
IO::silo::writeMultiMesh( fid, data.name, meshNames, meshTypes );
|
||||
for ( const auto &variable : data.variables ) {
|
||||
std::vector<std::string> varnames;
|
||||
for ( const auto &tmp : data.domains )
|
||||
varnames.push_back( tmp.file + ":" + variable.name );
|
||||
silo::writeMultiVar( fid, variable.name, varnames, varTypes );
|
||||
IO::silo::writeMultiVar( fid, variable.name, varnames, varTypes );
|
||||
}
|
||||
}
|
||||
silo::close( fid );
|
||||
IO::silo::close( fid );
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
// Write the mesh data in the new format
|
||||
static std::vector<IO::MeshDatabase> writeMeshesNewFormat(
|
||||
const std::vector<IO::MeshDataStruct>& meshData, const std::string& path, int format )
|
||||
const std::vector<IO::MeshDataStruct> &meshData, const std::string &path, IO::FileFormat format,
|
||||
int rank )
|
||||
{
|
||||
int rank = Utilities::MPI(MPI_COMM_WORLD).getRank();
|
||||
std::vector<IO::MeshDatabase> meshes_written;
|
||||
char filename[100], fullpath[200];
|
||||
sprintf( filename, "%05i", rank );
|
||||
|
@ -407,7 +461,7 @@ static std::vector<IO::MeshDatabase> writeMeshesNewFormat(
|
|||
FILE *fid = fopen( fullpath, "wb" );
|
||||
for ( size_t i = 0; i < meshData.size(); i++ ) {
|
||||
std::shared_ptr<IO::Mesh> mesh = meshData[i].mesh;
|
||||
meshes_written.push_back( write_domain(fid,filename,meshData[i],format) );
|
||||
meshes_written.push_back( write_domain( fid, filename, meshData[i], format, rank ) );
|
||||
}
|
||||
fclose( fid );
|
||||
return meshes_written;
|
||||
|
@ -416,22 +470,26 @@ static std::vector<IO::MeshDatabase> writeMeshesNewFormat(
|
|||
|
||||
// Write the mesh data to silo
|
||||
static std::vector<IO::MeshDatabase> writeMeshesSilo(
|
||||
const std::vector<IO::MeshDataStruct>& meshData, const std::string& path, int format )
|
||||
const std::vector<IO::MeshDataStruct> &meshData, const std::string &path, IO::FileFormat format,
|
||||
int rank )
|
||||
{
|
||||
#ifdef USE_SILO
|
||||
int rank = Utilities::MPI(MPI_COMM_WORLD).getRank();
|
||||
std::vector<IO::MeshDatabase> meshes_written;
|
||||
char filename[100], fullpath[200];
|
||||
sprintf( filename, "%05i.silo", rank );
|
||||
sprintf( fullpath, "%s/%s", path.c_str(), filename );
|
||||
auto fid = silo::open( fullpath, silo::CREATE );
|
||||
auto fid = IO::silo::open( fullpath, IO::silo::CREATE );
|
||||
for ( size_t i = 0; i < meshData.size(); i++ ) {
|
||||
auto mesh = meshData[i].mesh;
|
||||
meshes_written.push_back( write_domain_silo(fid,filename,meshData[i],format) );
|
||||
meshes_written.push_back( write_domain_silo( fid, filename, meshData[i], format, rank ) );
|
||||
}
|
||||
silo::close( fid );
|
||||
IO::silo::close( fid );
|
||||
return meshes_written;
|
||||
#else
|
||||
NULL_USE( meshData );
|
||||
NULL_USE( path );
|
||||
NULL_USE( format );
|
||||
NULL_USE( rank );
|
||||
ERROR( "Application built without silo support" );
|
||||
return std::vector<IO::MeshDatabase>();
|
||||
#endif
|
||||
|
@ -441,34 +499,30 @@ static std::vector<IO::MeshDatabase> writeMeshesSilo(
|
|||
/****************************************************
|
||||
* Write the mesh data *
|
||||
****************************************************/
|
||||
void IO::writeData( const std::string& subdir, const std::vector<IO::MeshDataStruct>& meshData, const Utilities::MPI& comm )
|
||||
void IO::writeData( const std::string &subdir, const std::vector<IO::MeshDataStruct> &meshData,
|
||||
const Utilities::MPI &comm )
|
||||
{
|
||||
if ( global_IO_path.empty() )
|
||||
IO::initialize();
|
||||
PROFILE_START( "writeData" );
|
||||
int rank = Utilities::MPI( MPI_COMM_WORLD ).getRank();
|
||||
// Check the meshData before writing
|
||||
for ( const auto& data : meshData ) {
|
||||
if ( !data.check() )
|
||||
ERROR("Error in meshData");
|
||||
}
|
||||
for ( const auto &data : meshData )
|
||||
ASSERT( data.check() );
|
||||
// Create the output directory
|
||||
std::string path = global_IO_path + "/" + subdir;
|
||||
if ( rank == 0 ) {
|
||||
mkdir(path.c_str(),S_IRWXU|S_IRGRP);
|
||||
}
|
||||
comm.barrier();
|
||||
recursiveMkdir( path, S_IRWXU | S_IRGRP );
|
||||
// Write the mesh files
|
||||
std::vector<IO::MeshDatabase> meshes_written;
|
||||
if ( global_IO_format == Format::OLD ) {
|
||||
// Write the original triangle format
|
||||
meshes_written = writeMeshesOrigFormat( meshData, path );
|
||||
meshes_written = writeMeshesOrigFormat( meshData, path, rank );
|
||||
} else if ( global_IO_format == Format::NEW ) {
|
||||
// Write the new format (double precision)
|
||||
meshes_written = writeMeshesNewFormat( meshData, path, 2 );
|
||||
meshes_written = writeMeshesNewFormat( meshData, path, IO::FileFormat::NEW, rank );
|
||||
} else if ( global_IO_format == Format::SILO ) {
|
||||
// Write silo
|
||||
meshes_written = writeMeshesSilo( meshData, path, 4 );
|
||||
meshes_written = writeMeshesSilo( meshData, path, IO::FileFormat::SILO, rank );
|
||||
} else {
|
||||
ERROR( "Unknown format" );
|
||||
}
|
||||
|
@ -504,5 +558,3 @@ void IO::writeData( const std::string& subdir, const std::vector<IO::MeshDataStr
|
|||
}
|
||||
PROFILE_STOP( "writeData" );
|
||||
}
|
||||
|
||||
|
||||
|
|
23
IO/Writer.h
23
IO/Writer.h
|
@ -14,17 +14,18 @@ namespace IO {
|
|||
|
||||
/*!
|
||||
* @brief Initialize the writer
|
||||
* @details This function initializes the writer to the given path. All subsequent
|
||||
* writes will occur in this directory. If this is not called, then it will default
|
||||
* to the current path.
|
||||
* @details This function initializes the writer to the given path.
|
||||
* All subsequent writes will occur in this directory.
|
||||
* If this is not called, then it will default to the current path.
|
||||
* @param[in] path The path to use for writes
|
||||
* @param[in] format The data format to use:
|
||||
* old - Old mesh format (provided for backward compatibility, cannot write variables)
|
||||
* new - New format, 1 file/process
|
||||
* silo - Silo
|
||||
* old - Old mesh format
|
||||
* (provided for backward compatibility, cannot write variables)
|
||||
* new - New format, 1 file/process silo - Silo
|
||||
* @param[in] append Append any existing data (default is false)
|
||||
*/
|
||||
void initialize( const std::string& path="", const std::string& format="silo", bool append=false );
|
||||
void initialize(
|
||||
const std::string &path = "", const std::string &format = "silo", bool append = false );
|
||||
|
||||
|
||||
/*!
|
||||
|
@ -34,7 +35,8 @@ void initialize( const std::string& path="", const std::string& format="silo", b
|
|||
* @param[in] meshData The data to write
|
||||
* @param[in] comm The comm to use for writing (usually MPI_COMM_WORLD or a dup thereof)
|
||||
*/
|
||||
void writeData( const std::string& subdir, const std::vector<IO::MeshDataStruct>& meshData, const Utilities::MPI& comm );
|
||||
void writeData( const std::string &subdir, const std::vector<IO::MeshDataStruct> &meshData,
|
||||
const Utilities::MPI &comm );
|
||||
|
||||
|
||||
/*!
|
||||
|
@ -44,7 +46,8 @@ void writeData( const std::string& subdir, const std::vector<IO::MeshDataStruct>
|
|||
* @param[in] meshData The data to write
|
||||
* @param[in] comm The comm to use for writing (usually MPI_COMM_WORLD or a dup thereof)
|
||||
*/
|
||||
inline void writeData( int timestep, const std::vector<IO::MeshDataStruct>& meshData, const Utilities::MPI& comm )
|
||||
inline void writeData(
|
||||
int timestep, const std::vector<IO::MeshDataStruct> &meshData, const Utilities::MPI &comm )
|
||||
{
|
||||
char subdir[100];
|
||||
sprintf( subdir, "vis%03i", timestep );
|
||||
|
@ -52,6 +55,6 @@ inline void writeData( int timestep, const std::vector<IO::MeshDataStruct>& mesh
|
|||
}
|
||||
|
||||
|
||||
} // IO namespace
|
||||
} // namespace IO
|
||||
|
||||
#endif
|
||||
|
|
111
IO/netcdf.cpp
111
IO/netcdf.cpp
|
@ -1,6 +1,6 @@
|
|||
#include "IO/netcdf.h"
|
||||
#include "common/Utilities.h"
|
||||
#include "common/MPI.h"
|
||||
#include "common/Utilities.h"
|
||||
|
||||
#include "ProfilerApp.h"
|
||||
|
||||
|
@ -56,12 +56,33 @@ static inline VariableType convertType( nc_type type )
|
|||
|
||||
|
||||
// Get nc_type from the template
|
||||
template<class T> inline nc_type getType();
|
||||
template<> inline nc_type getType<char>() { return NC_CHAR; }
|
||||
template<> inline nc_type getType<short>() { return NC_SHORT; }
|
||||
template<> inline nc_type getType<int>() { return NC_INT; }
|
||||
template<> inline nc_type getType<float>() { return NC_FLOAT; }
|
||||
template<> inline nc_type getType<double>() { return NC_DOUBLE; }
|
||||
template<class T>
|
||||
inline nc_type getType();
|
||||
template<>
|
||||
inline nc_type getType<char>()
|
||||
{
|
||||
return NC_CHAR;
|
||||
}
|
||||
template<>
|
||||
inline nc_type getType<short>()
|
||||
{
|
||||
return NC_SHORT;
|
||||
}
|
||||
template<>
|
||||
inline nc_type getType<int>()
|
||||
{
|
||||
return NC_INT;
|
||||
}
|
||||
template<>
|
||||
inline nc_type getType<float>()
|
||||
{
|
||||
return NC_FLOAT;
|
||||
}
|
||||
template<>
|
||||
inline nc_type getType<double>()
|
||||
{
|
||||
return NC_DOUBLE;
|
||||
}
|
||||
|
||||
|
||||
// Function to reverse an array
|
||||
|
@ -134,13 +155,16 @@ int open( const std::string& filename, FileMode mode, const Utilities::MPI& comm
|
|||
}
|
||||
} else {
|
||||
if ( mode == READ ) {
|
||||
int err = nc_open_par( filename.c_str(), NC_MPIPOSIX, comm.getCommunicator(), MPI_INFO_NULL, &fid );
|
||||
int err = nc_open_par(
|
||||
filename.c_str(), NC_MPIPOSIX, comm.getCommunicator(), MPI_INFO_NULL, &fid );
|
||||
CHECK_NC_ERR( err );
|
||||
} else if ( mode == WRITE ) {
|
||||
int err = nc_open_par( filename.c_str(), NC_WRITE|NC_MPIPOSIX, comm.getCommunicator(), MPI_INFO_NULL, &fid );
|
||||
int err = nc_open_par( filename.c_str(), NC_WRITE | NC_MPIPOSIX, comm.getCommunicator(),
|
||||
MPI_INFO_NULL, &fid );
|
||||
CHECK_NC_ERR( err );
|
||||
} else if ( mode == CREATE ) {
|
||||
int err = nc_create_par( filename.c_str(), NC_NETCDF4|NC_MPIIO, comm.getCommunicator(), MPI_INFO_NULL, &fid );
|
||||
int err = nc_create_par( filename.c_str(), NC_NETCDF4 | NC_MPIIO,
|
||||
comm.getCommunicator(), MPI_INFO_NULL, &fid );
|
||||
CHECK_NC_ERR( err );
|
||||
} else {
|
||||
ERROR( "Unknown file mode" );
|
||||
|
@ -239,7 +263,6 @@ VariableType getAttType( int fid, const std::string& att )
|
|||
}
|
||||
|
||||
|
||||
|
||||
/****************************************************
|
||||
* Read a variable *
|
||||
****************************************************/
|
||||
|
@ -329,9 +352,8 @@ Array<std::string> getVar<std::string>( int fid, const std::string& var )
|
|||
PROFILE_STOP( "getVar<std::string>" );
|
||||
return text;
|
||||
}
|
||||
static inline void get_stride_args( const std::vector<int>& start,
|
||||
const std::vector<int>& count, const std::vector<int>& stride,
|
||||
size_t *startp, size_t *countp, ptrdiff_t *stridep )
|
||||
static inline void get_stride_args( const std::vector<int> &start, const std::vector<int> &count,
|
||||
const std::vector<int> &stride, size_t *startp, size_t *countp, ptrdiff_t *stridep )
|
||||
{
|
||||
for ( size_t i = 0; i < start.size(); i++ )
|
||||
startp[i] = start[i];
|
||||
|
@ -341,29 +363,29 @@ static inline void get_stride_args( const std::vector<int>& start,
|
|||
stridep[i] = stride[i];
|
||||
}
|
||||
template<class TYPE>
|
||||
int nc_get_vars_TYPE( int fid, int varid, const size_t start[],
|
||||
const size_t count[], const ptrdiff_t stride[], TYPE *ptr );
|
||||
int nc_get_vars_TYPE( int fid, int varid, const size_t start[], const size_t count[],
|
||||
const ptrdiff_t stride[], TYPE *ptr );
|
||||
template<>
|
||||
int nc_get_vars_TYPE<short>( int fid, int varid, const size_t start[],
|
||||
const size_t count[], const ptrdiff_t stride[], short *ptr )
|
||||
int nc_get_vars_TYPE<short>( int fid, int varid, const size_t start[], const size_t count[],
|
||||
const ptrdiff_t stride[], short *ptr )
|
||||
{
|
||||
return nc_get_vars_short( fid, varid, start, count, stride, ptr );
|
||||
}
|
||||
template<>
|
||||
int nc_get_vars_TYPE<int>( int fid, int varid, const size_t start[],
|
||||
const size_t count[], const ptrdiff_t stride[], int *ptr )
|
||||
int nc_get_vars_TYPE<int>( int fid, int varid, const size_t start[], const size_t count[],
|
||||
const ptrdiff_t stride[], int *ptr )
|
||||
{
|
||||
return nc_get_vars_int( fid, varid, start, count, stride, ptr );
|
||||
}
|
||||
template<>
|
||||
int nc_get_vars_TYPE<float>( int fid, int varid, const size_t start[],
|
||||
const size_t count[], const ptrdiff_t stride[], float *ptr )
|
||||
int nc_get_vars_TYPE<float>( int fid, int varid, const size_t start[], const size_t count[],
|
||||
const ptrdiff_t stride[], float *ptr )
|
||||
{
|
||||
return nc_get_vars_float( fid, varid, start, count, stride, ptr );
|
||||
}
|
||||
template<>
|
||||
int nc_get_vars_TYPE<double>( int fid, int varid, const size_t start[],
|
||||
const size_t count[], const ptrdiff_t stride[], double *ptr )
|
||||
int nc_get_vars_TYPE<double>( int fid, int varid, const size_t start[], const size_t count[],
|
||||
const ptrdiff_t stride[], double *ptr )
|
||||
{
|
||||
return nc_get_vars_double( fid, varid, start, count, stride, ptr );
|
||||
}
|
||||
|
@ -377,7 +399,8 @@ Array<TYPE> getVar( int fid, const std::string& var, const std::vector<int>& sta
|
|||
if ( start[d] < 0 || start[d] + stride[d] * ( count[d] - 1 ) > (int) var_size[d] ) {
|
||||
int rank = Utilities::MPI( MPI_COMM_WORLD ).getRank();
|
||||
char tmp[1000];
|
||||
sprintf(tmp,"%i: Range exceeded array dimension:\n"
|
||||
sprintf( tmp,
|
||||
"%i: Range exceeded array dimension:\n"
|
||||
" start[%i]=%i, count[%i]=%i, stride[%i]=%i, var_size[%i]=%i",
|
||||
rank, d, start[d], d, count[d], d, stride[d], d, (int) var_size[d] );
|
||||
ERROR( tmp );
|
||||
|
@ -387,15 +410,20 @@ Array<TYPE> getVar( int fid, const std::string& var, const std::vector<int>& sta
|
|||
size_t startp[10], countp[10];
|
||||
ptrdiff_t stridep[10];
|
||||
get_stride_args( start, count, stride, startp, countp, stridep );
|
||||
int err = nc_get_vars_TYPE<TYPE>( fid, getVarID(fid,var), startp, countp, stridep, x.data() );
|
||||
int err =
|
||||
nc_get_vars_TYPE<TYPE>( fid, getVarID( fid, var ), startp, countp, stridep, x.data() );
|
||||
CHECK_NC_ERR( err );
|
||||
PROFILE_STOP( "getVar<> (strided)" );
|
||||
return x.reverseDim();
|
||||
}
|
||||
template Array<short> getVar<short>( int, const std::string&, const std::vector<int>&, const std::vector<int>&, const std::vector<int>& );
|
||||
template Array<int> getVar<int>( int, const std::string&, const std::vector<int>&, const std::vector<int>&, const std::vector<int>& );
|
||||
template Array<float> getVar<float>( int, const std::string&, const std::vector<int>&, const std::vector<int>&, const std::vector<int>& );
|
||||
template Array<double> getVar<double>( int, const std::string&, const std::vector<int>&, const std::vector<int>&, const std::vector<int>& );
|
||||
template Array<short> getVar<short>( int, const std::string &, const std::vector<int> &,
|
||||
const std::vector<int> &, const std::vector<int> & );
|
||||
template Array<int> getVar<int>( int, const std::string &, const std::vector<int> &,
|
||||
const std::vector<int> &, const std::vector<int> & );
|
||||
template Array<float> getVar<float>( int, const std::string &, const std::vector<int> &,
|
||||
const std::vector<int> &, const std::vector<int> & );
|
||||
template Array<double> getVar<double>( int, const std::string &, const std::vector<int> &,
|
||||
const std::vector<int> &, const std::vector<int> & );
|
||||
|
||||
|
||||
/****************************************************
|
||||
|
@ -427,7 +455,8 @@ Array<std::string> getAtt<std::string>( int fid, const std::string& att )
|
|||
/****************************************************
|
||||
* Write an array to a file *
|
||||
****************************************************/
|
||||
std::vector<int> defDim( int fid, const std::vector<std::string>& names, const std::vector<int>& dims )
|
||||
std::vector<int> defDim(
|
||||
int fid, const std::vector<std::string> &names, const std::vector<int> &dims )
|
||||
{
|
||||
std::vector<int> dimid( names.size(), 0 );
|
||||
for ( size_t i = 0; i < names.size(); i++ ) {
|
||||
|
@ -453,20 +482,22 @@ void write( int fid, const std::string& var, const std::vector<int>& dimids,
|
|||
// parallel write: each process writes its subarray to the file
|
||||
auto x = data.reverseDim();
|
||||
std::vector<size_t> count = { data.size( 0 ), data.size( 1 ), data.size( 2 ) };
|
||||
std::vector<size_t> start = { info.ix*data.size(0), info.jy*data.size(1), info.kz*data.size(2) };
|
||||
std::vector<size_t> start = { info.ix * data.size( 0 ), info.jy * data.size( 1 ),
|
||||
info.kz * data.size( 2 ) };
|
||||
nc_put_vara( fid, varid, start.data(), count.data(), x.data() );
|
||||
}
|
||||
template void write<short>( int fid, const std::string& var, const std::vector<int>& dimids, const Array<short>& data, const RankInfoStruct& info );
|
||||
template void write<int>( int fid, const std::string& var, const std::vector<int>& dimids, const Array<int>& data, const RankInfoStruct& info );
|
||||
template void write<float>( int fid, const std::string& var, const std::vector<int>& dimids, const Array<float>& data, const RankInfoStruct& info );
|
||||
template void write<double>( int fid, const std::string& var, const std::vector<int>& dimids, const Array<double>& data, const RankInfoStruct& info );
|
||||
template void write<short>( int fid, const std::string &var, const std::vector<int> &dimids,
|
||||
const Array<short> &data, const RankInfoStruct &info );
|
||||
template void write<int>( int fid, const std::string &var, const std::vector<int> &dimids,
|
||||
const Array<int> &data, const RankInfoStruct &info );
|
||||
template void write<float>( int fid, const std::string &var, const std::vector<int> &dimids,
|
||||
const Array<float> &data, const RankInfoStruct &info );
|
||||
template void write<double>( int fid, const std::string &var, const std::vector<int> &dimids,
|
||||
const Array<double> &data, const RankInfoStruct &info );
|
||||
|
||||
|
||||
|
||||
}; // netcdf namespace
|
||||
}; // namespace netcdf
|
||||
|
||||
#else
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
|
|
11
IO/netcdf.h
11
IO/netcdf.h
|
@ -5,9 +5,8 @@
|
|||
#include <vector>
|
||||
|
||||
#include "common/Array.h"
|
||||
#include "common/MPI.h"
|
||||
#include "common/Communication.h"
|
||||
|
||||
#include "common/MPI.h"
|
||||
|
||||
|
||||
namespace netcdf {
|
||||
|
@ -125,7 +124,8 @@ Array<TYPE> getAtt( int fid, const std::string& att );
|
|||
* @details This function writes the grid dimensions to netcdf.
|
||||
* @param fid Handle to the open file
|
||||
*/
|
||||
std::vector<int> defDim( int fid, const std::vector<std::string>& names, const std::vector<int>& dims );
|
||||
std::vector<int> defDim(
|
||||
int fid, const std::vector<std::string> &names, const std::vector<int> &dims );
|
||||
|
||||
|
||||
/*!
|
||||
|
@ -134,8 +134,9 @@ std::vector<int> defDim( int fid, const std::vector<std::string>& names, const s
|
|||
* @param fid Handle to the open file
|
||||
*/
|
||||
template<class TYPE>
|
||||
void write( int fid, const std::string& var, const std::vector<int>& dimids, const Array<TYPE>& data, const RankInfoStruct& rank_info );
|
||||
void write( int fid, const std::string &var, const std::vector<int> &dimids,
|
||||
const Array<TYPE> &data, const RankInfoStruct &rank_info );
|
||||
|
||||
|
||||
}; // netcdf namespace
|
||||
}; // namespace netcdf
|
||||
#endif
|
||||
|
|
39
IO/silo.cpp
39
IO/silo.cpp
|
@ -1,6 +1,6 @@
|
|||
#include "IO/silo.h"
|
||||
#include "common/Utilities.h"
|
||||
#include "common/MPI.h"
|
||||
#include "common/Utilities.h"
|
||||
|
||||
#include "ProfilerApp.h"
|
||||
|
||||
|
@ -10,8 +10,7 @@
|
|||
#include <silo.h>
|
||||
|
||||
|
||||
|
||||
namespace silo {
|
||||
namespace IO::silo {
|
||||
|
||||
|
||||
/****************************************************
|
||||
|
@ -29,25 +28,22 @@ DBfile* open( const std::string& filename, FileMode mode )
|
|||
}
|
||||
return fid;
|
||||
}
|
||||
void close( DBfile* fid )
|
||||
{
|
||||
DBClose( fid );
|
||||
}
|
||||
void close( DBfile *fid ) { DBClose( fid ); }
|
||||
|
||||
|
||||
/****************************************************
|
||||
* Helper functions *
|
||||
****************************************************/
|
||||
VariableDataType varDataType( DBfile *fid, const std::string& name )
|
||||
DataType varDataType( DBfile *fid, const std::string &name )
|
||||
{
|
||||
auto type = DBGetVarType( fid, name.c_str() );
|
||||
VariableDataType type2 = VariableDataType::UNKNOWN;
|
||||
DataType type2 = DataType::Null;
|
||||
if ( type == DB_DOUBLE )
|
||||
type2 = VariableDataType::DOUBLE;
|
||||
type2 = DataType::Double;
|
||||
else if ( type == DB_FLOAT )
|
||||
type2 = VariableDataType::FLOAT;
|
||||
type2 = DataType::Float;
|
||||
else if ( type == DB_INT )
|
||||
type2 = VariableDataType::INT;
|
||||
type2 = DataType::Int;
|
||||
return type2;
|
||||
}
|
||||
|
||||
|
@ -55,8 +51,8 @@ VariableDataType varDataType( DBfile *fid, const std::string& name )
|
|||
/****************************************************
|
||||
* Write/read a uniform mesh to silo *
|
||||
****************************************************/
|
||||
void readUniformMesh( DBfile* fid, const std::string& meshname,
|
||||
std::vector<double>& range, std::vector<int>& N )
|
||||
void readUniformMesh(
|
||||
DBfile *fid, const std::string &meshname, std::vector<double> &range, std::vector<int> &N )
|
||||
{
|
||||
DBquadmesh *mesh = DBGetQuadmesh( fid, meshname.c_str() );
|
||||
int ndim = mesh->ndims;
|
||||
|
@ -75,8 +71,7 @@ void readUniformMesh( DBfile* fid, const std::string& meshname,
|
|||
* Write a multimesh *
|
||||
****************************************************/
|
||||
void writeMultiMesh( DBfile *fid, const std::string &meshname,
|
||||
const std::vector<std::string>& meshNames,
|
||||
const std::vector<int>& meshTypes )
|
||||
const std::vector<std::string> &meshNames, const std::vector<int> &meshTypes )
|
||||
{
|
||||
std::vector<char *> meshnames( meshNames.size() );
|
||||
for ( size_t i = 0; i < meshNames.size(); ++i )
|
||||
|
@ -84,7 +79,8 @@ void writeMultiMesh( DBfile* fid, const std::string& meshname,
|
|||
std::string tree_name = meshname + "_tree";
|
||||
DBoptlist *optList = DBMakeOptlist( 1 );
|
||||
DBAddOption( optList, DBOPT_MRGTREE_NAME, (char *) tree_name.c_str() );
|
||||
DBPutMultimesh( fid, meshname.c_str(), meshNames.size(), meshnames.data(), (int*) meshTypes.data(), nullptr );
|
||||
DBPutMultimesh( fid, meshname.c_str(), meshNames.size(), meshnames.data(),
|
||||
(int *) meshTypes.data(), nullptr );
|
||||
DBFreeOptlist( optList );
|
||||
}
|
||||
|
||||
|
@ -93,18 +89,17 @@ void writeMultiMesh( DBfile* fid, const std::string& meshname,
|
|||
* Write a multivariable *
|
||||
****************************************************/
|
||||
void writeMultiVar( DBfile *fid, const std::string &varname,
|
||||
const std::vector<std::string>& varNames,
|
||||
const std::vector<int>& varTypes )
|
||||
const std::vector<std::string> &varNames, const std::vector<int> &varTypes )
|
||||
{
|
||||
std::vector<char *> varnames( varNames.size(), nullptr );
|
||||
for ( size_t j = 0; j < varNames.size(); j++ )
|
||||
varnames[j] = const_cast<char *>( varNames[j].c_str() );
|
||||
DBPutMultivar( fid, varname.c_str(), varNames.size(), varnames.data(), (int*) varTypes.data(), nullptr );
|
||||
DBPutMultivar(
|
||||
fid, varname.c_str(), varNames.size(), varnames.data(), (int *) varTypes.data(), nullptr );
|
||||
}
|
||||
|
||||
|
||||
|
||||
}; // silo namespace
|
||||
}; // namespace IO::silo
|
||||
|
||||
|
||||
#else
|
||||
|
|
44
IO/silo.h
44
IO/silo.h
|
@ -1,13 +1,14 @@
|
|||
#ifndef SILO_INTERFACE
|
||||
#define SILO_INTERFACE
|
||||
|
||||
#include <array>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <array>
|
||||
|
||||
#include "IO/Mesh.h"
|
||||
#include "common/Array.h"
|
||||
#include "common/MPI.h"
|
||||
#include "common/Communication.h"
|
||||
#include "common/MPI.h"
|
||||
|
||||
|
||||
#ifdef USE_SILO
|
||||
|
@ -17,16 +18,11 @@
|
|||
#endif
|
||||
|
||||
|
||||
|
||||
namespace silo {
|
||||
namespace IO::silo {
|
||||
|
||||
|
||||
enum FileMode { READ, WRITE, CREATE };
|
||||
|
||||
enum class VariableType : int { NodeVariable=1, EdgeVariable=2, SurfaceVariable=2, VolumeVariable=3, NullVariable=0 };
|
||||
|
||||
enum class VariableDataType { DOUBLE, FLOAT, INT, UNKNOWN };
|
||||
|
||||
|
||||
/*!
|
||||
* @brief Open silo file
|
||||
|
@ -52,7 +48,7 @@ void close( DBfile* fid );
|
|||
* @param[in] fid Handle to the open file
|
||||
* @param[in] name Name of variable
|
||||
*/
|
||||
VariableDataType varDataType( DBfile *dbfile, const std::string& name );
|
||||
DataType varDataType( DBfile *dbfile, const std::string &name );
|
||||
|
||||
|
||||
/*!
|
||||
|
@ -98,8 +94,8 @@ void writeUniformMesh( DBfile* fid, const std::string& meshname,
|
|||
* @param[out] range Range of mesh { xmin, xmax, ymin, ymax, zmin, zmax }
|
||||
* @param[out] N Number of cells in each direction
|
||||
*/
|
||||
void readUniformMesh( DBfile* fid, const std::string& meshname,
|
||||
std::vector<double>& range, std::vector<int>& N );
|
||||
void readUniformMesh(
|
||||
DBfile *fid, const std::string &meshname, std::vector<double> &range, std::vector<int> &N );
|
||||
|
||||
|
||||
/*!
|
||||
|
@ -113,8 +109,9 @@ void readUniformMesh( DBfile* fid, const std::string& meshname,
|
|||
* @param[in] type Variable type
|
||||
*/
|
||||
template<int NDIM, class TYPE>
|
||||
void writeUniformMeshVariable( DBfile* fid, const std::string& meshname, const std::array<int,NDIM>& N,
|
||||
const std::string& varname, const Array<TYPE>& data, VariableType type );
|
||||
void writeUniformMeshVariable( DBfile *fid, const std::string &meshname,
|
||||
const std::array<int, NDIM> &N, const std::string &varname, const Array<TYPE> &data,
|
||||
VariableType type );
|
||||
|
||||
|
||||
/*!
|
||||
|
@ -138,8 +135,8 @@ Array<TYPE> readUniformMeshVariable( DBfile* fid, const std::string& varname );
|
|||
* @param[in] coords Coordinates of the points
|
||||
*/
|
||||
template<class TYPE>
|
||||
void writePointMesh( DBfile* fid, const std::string& meshname,
|
||||
int ndim, int N, const TYPE *coords[] );
|
||||
void writePointMesh(
|
||||
DBfile *fid, const std::string &meshname, int ndim, int N, const TYPE *coords[] );
|
||||
|
||||
|
||||
/*!
|
||||
|
@ -162,8 +159,8 @@ Array<TYPE> readPointMesh( DBfile* fid, const std::string& meshname );
|
|||
* @param[in] data Variable data
|
||||
*/
|
||||
template<class TYPE>
|
||||
void writePointMeshVariable( DBfile* fid, const std::string& meshname,
|
||||
const std::string& varname, const Array<TYPE>& data );
|
||||
void writePointMeshVariable(
|
||||
DBfile *fid, const std::string &meshname, const std::string &varname, const Array<TYPE> &data );
|
||||
|
||||
|
||||
/*!
|
||||
|
@ -190,8 +187,8 @@ Array<TYPE> readPointMeshVariable( DBfile* fid, const std::string& varname );
|
|||
* @param[in] tri Coordinates of the points
|
||||
*/
|
||||
template<class TYPE>
|
||||
void writeTriMesh( DBfile* fid, const std::string& meshname,
|
||||
int ndim, int ndim_tri, int N, const TYPE *coords[], int N_tri, const int *tri[] );
|
||||
void writeTriMesh( DBfile *fid, const std::string &meshname, int ndim, int ndim_tri, int N,
|
||||
const TYPE *coords[], int N_tri, const int *tri[] );
|
||||
|
||||
|
||||
/*!
|
||||
|
@ -241,8 +238,7 @@ Array<TYPE> readTriMeshVariable( DBfile* fid, const std::string& varname );
|
|||
* @param[in] subMeshTypes Type of each submesh
|
||||
*/
|
||||
void writeMultiMesh( DBfile *fid, const std::string &meshname,
|
||||
const std::vector<std::string>& subMeshNames,
|
||||
const std::vector<int>& subMeshTypes );
|
||||
const std::vector<std::string> &subMeshNames, const std::vector<int> &subMeshTypes );
|
||||
|
||||
|
||||
/*!
|
||||
|
@ -257,12 +253,10 @@ void writeMultiMesh( DBfile* fid, const std::string& meshname,
|
|||
* @param[in] nvar Number of subvariables (used to determine suffix)
|
||||
*/
|
||||
void writeMultiVar( DBfile *fid, const std::string &varname,
|
||||
const std::vector<std::string>& subVarNames,
|
||||
const std::vector<int>& subVarTypes );
|
||||
const std::vector<std::string> &subVarNames, const std::vector<int> &subVarTypes );
|
||||
|
||||
|
||||
}; // silo namespace
|
||||
}; // namespace IO::silo
|
||||
#endif
|
||||
|
||||
#include "IO/silo.hpp"
|
||||
|
||||
|
|
|
@ -13,7 +13,7 @@
|
|||
#include <silo.h>
|
||||
|
||||
|
||||
namespace silo {
|
||||
namespace IO::silo {
|
||||
|
||||
|
||||
/****************************************************
|
||||
|
@ -413,7 +413,7 @@ Array<TYPE> readTriMeshVariable( DBfile *fid, const std::string &varname )
|
|||
}
|
||||
|
||||
|
||||
}; // namespace silo
|
||||
}; // namespace IO::silo
|
||||
|
||||
|
||||
#endif
|
||||
|
|
|
@ -26,7 +26,6 @@ cmake \
|
|||
-D CMAKE_CXX_COMPILER:PATH=CC \
|
||||
-D CFLAGS="-DCBUB" \
|
||||
-D CXXFLAGS="-DCBUB" \
|
||||
-D MPI_COMPILER:BOOL=TRUE \
|
||||
-D MPIEXEC=aprun \
|
||||
-D USE_EXT_MPI_FOR_SERIAL_TESTS:BOOL=TRUE \
|
||||
-D CMAKE_BUILD_TYPE:STRING=Debug \
|
||||
|
|
|
@ -1,362 +0,0 @@
|
|||
# - Message Passing Interface (MPI) module.
|
||||
#
|
||||
# The Message Passing Interface (MPI) is a library used to write
|
||||
# high-performance parallel applications that use message passing, and
|
||||
# is typically deployed on a cluster. MPI is a standard interface
|
||||
# (defined by the MPI forum) for which many implementations are
|
||||
# available. All of these implementations have somewhat different
|
||||
# compilation approaches (different include paths, libraries to link
|
||||
# against, etc.), and this module tries to smooth out those differences.
|
||||
#
|
||||
# This module will set the following variables:
|
||||
# MPI_FOUND TRUE if we have found MPI
|
||||
# MPI_COMPILE_FLAGS Compilation flags for MPI programs
|
||||
# MPI_INCLUDE_PATH Include path(s) for MPI header
|
||||
# MPI_LINK_FLAGS Linking flags for MPI programs
|
||||
# MPI_LIBRARY First MPI library to link against (cached)
|
||||
# MPI_EXTRA_LIBRARY Extra MPI libraries to link against (cached)
|
||||
# MPI_LIBRARIES All libraries to link MPI programs against
|
||||
# MPIEXEC Executable for running MPI programs
|
||||
# MPIEXEC_NUMPROC_FLAG Flag to pass to MPIEXEC before giving it the
|
||||
# number of processors to run on
|
||||
# MPIEXEC_PREFLAGS Flags to pass to MPIEXEC directly before the
|
||||
# executable to run.
|
||||
# MPIEXEC_POSTFLAGS Flags to pass to MPIEXEC after all other flags.
|
||||
#
|
||||
# This module will attempt to auto-detect these settings, first by
|
||||
# looking for a MPI compiler, which many MPI implementations provide
|
||||
# as a pass-through to the native compiler to simplify the compilation
|
||||
# of MPI programs. The MPI compiler is stored in the cache variable
|
||||
# MPI_COMPILER, and will attempt to look for commonly-named drivers
|
||||
# mpic++, mpicxx, mpiCC, or mpicc. If the compiler driver is found and
|
||||
# recognized, it will be used to set all of the module variables. To
|
||||
# skip this auto-detection, set MPI_LIBRARY and MPI_INCLUDE_PATH in
|
||||
# the CMake cache.
|
||||
#
|
||||
# If no compiler driver is found or the compiler driver is not
|
||||
# recognized, this module will then search for common include paths
|
||||
# and library names to try to detect MPI.
|
||||
#
|
||||
# If CMake initially finds a different MPI than was intended, and you
|
||||
# want to use the MPI compiler auto-detection for a different MPI
|
||||
# implementation, set MPI_COMPILER to the MPI compiler driver you want
|
||||
# to use (e.g., mpicxx) and then set MPI_LIBRARY to the string
|
||||
# MPI_LIBRARY-NOTFOUND. When you re-configure, auto-detection of MPI
|
||||
# will run again with the newly-specified MPI_COMPILER.
|
||||
#
|
||||
# When using MPIEXEC to execute MPI applications, you should typically
|
||||
# use all of the MPIEXEC flags as follows:
|
||||
# ${MPIEXEC} ${MPIEXEC_NUMPROC_FLAG} PROCS ${MPIEXEC_PREFLAGS} EXECUTABLE
|
||||
# ${MPIEXEC_POSTFLAGS} ARGS
|
||||
# where PROCS is the number of processors on which to execute the program,
|
||||
# EXECUTABLE is the MPI program, and ARGS are the arguments to pass to the
|
||||
# MPI program.
|
||||
|
||||
#=============================================================================
|
||||
# Copyright 2001-2009 Kitware, Inc.
|
||||
#
|
||||
# Distributed under the OSI-approved BSD License (the "License");
|
||||
# see accompanying file Copyright.txt for details.
|
||||
#
|
||||
# This software is distributed WITHOUT ANY WARRANTY; without even the
|
||||
# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||
# See the License for more information.
|
||||
#=============================================================================
|
||||
# (To distribute this file outside of CMake, substitute the full
|
||||
# License text for the above reference.)
|
||||
|
||||
# This module is maintained by David Partyka <dave.partyka@kitware.com>.
|
||||
|
||||
# A set of directories to search through in addition to the standard system paths
|
||||
# that find_program will search through.
|
||||
# Microsoft HPC SDK is automatically added to the system path
|
||||
# Argonne National Labs MPICH2 sets a registry key that we can use.
|
||||
|
||||
set(_MPI_PACKAGE_DIR
|
||||
mpi
|
||||
mpich
|
||||
openmpi
|
||||
lib/mpi
|
||||
lib/mpich
|
||||
lib/openmpi
|
||||
"MPICH/SDK"
|
||||
"Microsoft Compute Cluster Pack"
|
||||
"Microsoft HPC Pack 2008 R2"
|
||||
)
|
||||
|
||||
set(_MPI_PREFIX_PATH)
|
||||
if(WIN32)
|
||||
list(APPEND _MPI_PREFIX_PATH "[HKEY_LOCAL_MACHINE\\SOFTWARE\\MPICH\\SMPD;binary]/..")
|
||||
list(APPEND _MPI_PREFIX_PATH "[HKEY_LOCAL_MACHINE\\SOFTWARE\\MPICH2;Path]")
|
||||
endif()
|
||||
|
||||
foreach(SystemPrefixDir ${CMAKE_SYSTEM_PREFIX_PATH})
|
||||
foreach(MpiPackageDir ${_MPI_PREFIX_PATH})
|
||||
if(EXISTS ${SystemPrefixDir}/${MpiPackageDir})
|
||||
list(APPEND _MPI_PREFIX_PATH "${SystemPrefixDir}/${MpiPackageDir}")
|
||||
endif()
|
||||
endforeach(MpiPackageDir)
|
||||
endforeach(SystemPrefixDir)
|
||||
|
||||
# Most mpi distros have some form of mpiexec which gives us something we can reliably look for.
|
||||
find_program(MPIEXEC
|
||||
NAMES mpiexec mpirun lamexec
|
||||
PATHS ${_MPI_PREFIX_PATH}
|
||||
PATH_SUFFIXES bin
|
||||
DOC "Executable for running MPI programs."
|
||||
)
|
||||
|
||||
# call get_filename_component twice to remove mpiexec and the directory it exists in (typically bin).
|
||||
# This gives us a fairly reliable base directory to search for /bin /lib and /include from.
|
||||
get_filename_component(_MPI_BASE_DIR "${MPIEXEC}" PATH)
|
||||
get_filename_component(_MPI_BASE_DIR "${_MPI_BASE_DIR}" PATH)
|
||||
|
||||
# If there is an mpi compiler find it and interogate (farther below) it for the include
|
||||
# and lib dirs otherwise we will continue to search from ${_MPI_BASE_DIR}.
|
||||
find_program(MPI_COMPILER
|
||||
NAMES mpic++ mpicxx mpiCC mpicc
|
||||
HINTS "${_MPI_BASE_DIR}"
|
||||
PATH_SUFFIXES bin
|
||||
DOC "MPI compiler. Used only to detect MPI compilation flags.")
|
||||
mark_as_advanced(MPI_COMPILER)
|
||||
|
||||
set(MPIEXEC_NUMPROC_FLAG "-np" CACHE STRING "Flag used by MPI to specify the number of processes for MPIEXEC; the next option will be the number of processes.")
|
||||
set(MPIEXEC_PREFLAGS "" CACHE STRING "These flags will be directly before the executable that is being run by MPIEXEC.")
|
||||
set(MPIEXEC_POSTFLAGS "" CACHE STRING "These flags will come after all flags given to MPIEXEC.")
|
||||
set(MPIEXEC_MAX_NUMPROCS "2" CACHE STRING "Maximum number of processors available to run MPI applications.")
|
||||
mark_as_advanced(MPIEXEC MPIEXEC_NUMPROC_FLAG MPIEXEC_PREFLAGS
|
||||
MPIEXEC_POSTFLAGS MPIEXEC_MAX_NUMPROCS)
|
||||
|
||||
if (MPI_INCLUDE_PATH AND MPI_LIBRARY)
|
||||
# Do nothing: we already have MPI_INCLUDE_PATH and MPI_LIBRARY in
|
||||
# the cache, and we don't want to override those settings.
|
||||
elseif (MPI_COMPILER)
|
||||
# Check whether the -showme:compile option works. This indicates
|
||||
# that we have either Open MPI or a newer version of LAM-MPI, and
|
||||
# implies that -showme:link will also work.
|
||||
# Note that Windows distros do not have an mpi compiler to interogate.
|
||||
exec_program(${MPI_COMPILER}
|
||||
ARGS -showme:compile
|
||||
OUTPUT_VARIABLE MPI_COMPILE_CMDLINE
|
||||
RETURN_VALUE MPI_COMPILER_RETURN)
|
||||
|
||||
if (MPI_COMPILER_RETURN EQUAL 0)
|
||||
# If we appear to have -showme:compile, then we should also have
|
||||
# -showme:link. Try it.
|
||||
exec_program(${MPI_COMPILER}
|
||||
ARGS -showme:link
|
||||
OUTPUT_VARIABLE MPI_LINK_CMDLINE
|
||||
RETURN_VALUE MPI_COMPILER_RETURN)
|
||||
|
||||
# Note that we probably have -showme:incdirs and -showme:libdirs
|
||||
# as well.
|
||||
set(MPI_COMPILER_MAY_HAVE_INCLIBDIRS TRUE)
|
||||
endif (MPI_COMPILER_RETURN EQUAL 0)
|
||||
|
||||
if (MPI_COMPILER_RETURN EQUAL 0)
|
||||
# Do nothing: we have our command lines now
|
||||
else (MPI_COMPILER_RETURN EQUAL 0)
|
||||
# Older versions of LAM-MPI have "-showme". Try it.
|
||||
exec_program(${MPI_COMPILER}
|
||||
ARGS -showme
|
||||
OUTPUT_VARIABLE MPI_COMPILE_CMDLINE
|
||||
RETURN_VALUE MPI_COMPILER_RETURN)
|
||||
endif (MPI_COMPILER_RETURN EQUAL 0)
|
||||
|
||||
if (MPI_COMPILER_RETURN EQUAL 0)
|
||||
# Do nothing: we have our command lines now
|
||||
else (MPI_COMPILER_RETURN EQUAL 0)
|
||||
# MPICH uses "-show". Try it.
|
||||
exec_program(${MPI_COMPILER}
|
||||
ARGS -show
|
||||
OUTPUT_VARIABLE MPI_COMPILE_CMDLINE
|
||||
RETURN_VALUE MPI_COMPILER_RETURN)
|
||||
endif (MPI_COMPILER_RETURN EQUAL 0)
|
||||
|
||||
if (MPI_COMPILER_RETURN EQUAL 0)
|
||||
# We have our command lines, but we might need to copy
|
||||
# MPI_COMPILE_CMDLINE into MPI_LINK_CMDLINE, if the underlying
|
||||
if (NOT MPI_LINK_CMDLINE)
|
||||
SET(MPI_LINK_CMDLINE ${MPI_COMPILE_CMDLINE})
|
||||
endif (NOT MPI_LINK_CMDLINE)
|
||||
else (MPI_COMPILER_RETURN EQUAL 0)
|
||||
message(STATUS "Unable to determine MPI from MPI driver ${MPI_COMPILER}")
|
||||
endif (MPI_COMPILER_RETURN EQUAL 0)
|
||||
endif (MPI_INCLUDE_PATH AND MPI_LIBRARY)
|
||||
|
||||
if (MPI_INCLUDE_PATH AND MPI_LIBRARY)
|
||||
# Do nothing: we already have MPI_INCLUDE_PATH and MPI_LIBRARY in
|
||||
# the cache, and we don't want to override those settings.
|
||||
elseif (MPI_COMPILE_CMDLINE)
|
||||
# Extract compile flags from the compile command line.
|
||||
string(REGEX MATCHALL "(^| )-[Df]([^\" ]+|\"[^\"]+\")" MPI_ALL_COMPILE_FLAGS "${MPI_COMPILE_CMDLINE}")
|
||||
set(MPI_COMPILE_FLAGS_WORK)
|
||||
foreach(FLAG ${MPI_ALL_COMPILE_FLAGS})
|
||||
if (MPI_COMPILE_FLAGS_WORK)
|
||||
set(MPI_COMPILE_FLAGS_WORK "${MPI_COMPILE_FLAGS_WORK} ${FLAG}")
|
||||
else(MPI_COMPILE_FLAGS_WORK)
|
||||
set(MPI_COMPILE_FLAGS_WORK ${FLAG})
|
||||
endif(MPI_COMPILE_FLAGS_WORK)
|
||||
endforeach(FLAG)
|
||||
|
||||
# Extract include paths from compile command line
|
||||
string(REGEX MATCHALL "(^| )-I([^\" ]+|\"[^\"]+\")" MPI_ALL_INCLUDE_PATHS "${MPI_COMPILE_CMDLINE}")
|
||||
set(MPI_INCLUDE_PATH_WORK)
|
||||
foreach(IPATH ${MPI_ALL_INCLUDE_PATHS})
|
||||
string(REGEX REPLACE "^ ?-I" "" IPATH ${IPATH})
|
||||
string(REGEX REPLACE "//" "/" IPATH ${IPATH})
|
||||
list(APPEND MPI_INCLUDE_PATH_WORK ${IPATH})
|
||||
endforeach(IPATH)
|
||||
|
||||
if (NOT MPI_INCLUDE_PATH_WORK)
|
||||
if (MPI_COMPILER_MAY_HAVE_INCLIBDIRS)
|
||||
# The compile command line didn't have any include paths on it,
|
||||
# but we may have -showme:incdirs. Use it.
|
||||
exec_program(${MPI_COMPILER}
|
||||
ARGS -showme:incdirs
|
||||
OUTPUT_VARIABLE MPI_INCLUDE_PATH_WORK
|
||||
RETURN_VALUE MPI_COMPILER_RETURN)
|
||||
separate_arguments(MPI_INCLUDE_PATH_WORK)
|
||||
endif (MPI_COMPILER_MAY_HAVE_INCLIBDIRS)
|
||||
endif (NOT MPI_INCLUDE_PATH_WORK)
|
||||
|
||||
if (NOT MPI_INCLUDE_PATH_WORK)
|
||||
# If all else fails, just search for mpi.h in the normal include
|
||||
# paths.
|
||||
find_path(MPI_INCLUDE_PATH mpi.h
|
||||
HINTS ${_MPI_BASE_DIR} ${_MPI_PREFIX_PATH}
|
||||
PATH_SUFFIXES include
|
||||
)
|
||||
set(MPI_INCLUDE_PATH_WORK ${MPI_INCLUDE_PATH})
|
||||
endif (NOT MPI_INCLUDE_PATH_WORK)
|
||||
|
||||
# Extract linker paths from the link command line
|
||||
string(REGEX MATCHALL "(^| |-Wl,)-L([^\" ]+|\"[^\"]+\")" MPI_ALL_LINK_PATHS "${MPI_LINK_CMDLINE}")
|
||||
set(MPI_LINK_PATH)
|
||||
foreach(LPATH ${MPI_ALL_LINK_PATHS})
|
||||
string(REGEX REPLACE "^(| |-Wl,)-L" "" LPATH ${LPATH})
|
||||
string(REGEX REPLACE "//" "/" LPATH ${LPATH})
|
||||
list(APPEND MPI_LINK_PATH ${LPATH})
|
||||
endforeach(LPATH)
|
||||
|
||||
if (NOT MPI_LINK_PATH)
|
||||
if (MPI_COMPILER_MAY_HAVE_INCLIBDIRS)
|
||||
# The compile command line didn't have any linking paths on it,
|
||||
# but we may have -showme:libdirs. Use it.
|
||||
exec_program(${MPI_COMPILER}
|
||||
ARGS -showme:libdirs
|
||||
OUTPUT_VARIABLE MPI_LINK_PATH
|
||||
RETURN_VALUE MPI_COMPILER_RETURN)
|
||||
separate_arguments(MPI_LINK_PATH)
|
||||
endif (MPI_COMPILER_MAY_HAVE_INCLIBDIRS)
|
||||
endif (NOT MPI_LINK_PATH)
|
||||
|
||||
# Extract linker flags from the link command line
|
||||
string(REGEX MATCHALL "(^| )-Wl,([^\" ]+|\"[^\"]+\")" MPI_ALL_LINK_FLAGS "${MPI_LINK_CMDLINE}")
|
||||
set(MPI_LINK_FLAGS_WORK)
|
||||
foreach(FLAG ${MPI_ALL_LINK_FLAGS})
|
||||
if (MPI_LINK_FLAGS_WORK)
|
||||
set(MPI_LINK_FLAGS_WORK "${MPI_LINK_FLAGS_WORK} ${FLAG}")
|
||||
else(MPI_LINK_FLAGS_WORK)
|
||||
set(MPI_LINK_FLAGS_WORK ${FLAG})
|
||||
endif(MPI_LINK_FLAGS_WORK)
|
||||
endforeach(FLAG)
|
||||
if ( MPI_LINK_FLAGS_WORK )
|
||||
string ( REGEX REPLACE "^ " "" MPI_LINK_FLAGS_WORK ${MPI_LINK_FLAGS_WORK} )
|
||||
endif ()
|
||||
|
||||
# Extract the set of libraries to link against from the link command
|
||||
# line
|
||||
string(REGEX MATCHALL "(^| )-l([^\" ]+|\"[^\"]+\")" MPI_LIBNAMES "${MPI_LINK_CMDLINE}")
|
||||
|
||||
# Determine full path names for all of the libraries that one needs
|
||||
# to link against in an MPI program
|
||||
set(MPI_LIBRARIES)
|
||||
foreach(LIB ${MPI_LIBNAMES})
|
||||
string(REGEX REPLACE "^ ?-l" "" LIB ${LIB})
|
||||
set(MPI_LIB "MPI_LIB-NOTFOUND" CACHE FILEPATH "Cleared" FORCE)
|
||||
find_library(MPI_LIB ${LIB} HINTS ${MPI_LINK_PATH})
|
||||
if (MPI_LIB)
|
||||
list(APPEND MPI_LIBRARIES ${MPI_LIB})
|
||||
elseif (NOT MPI_FIND_QUIETLY)
|
||||
message(WARNING "Unable to find MPI library ${LIB}")
|
||||
endif ()
|
||||
endforeach(LIB)
|
||||
set(MPI_LIB "MPI_LIB-NOTFOUND" CACHE INTERNAL "Scratch variable for MPI detection" FORCE)
|
||||
|
||||
# Chop MPI_LIBRARIES into the old-style MPI_LIBRARY and
|
||||
# MPI_EXTRA_LIBRARY.
|
||||
list(LENGTH MPI_LIBRARIES MPI_NUMLIBS)
|
||||
list(LENGTH MPI_LIBNAMES MPI_NUMLIBS_EXPECTED)
|
||||
if (MPI_NUMLIBS EQUAL MPI_NUMLIBS_EXPECTED)
|
||||
list(GET MPI_LIBRARIES 0 MPI_LIBRARY_WORK)
|
||||
set(MPI_LIBRARY ${MPI_LIBRARY_WORK} CACHE FILEPATH "MPI library to link against" FORCE)
|
||||
else (MPI_NUMLIBS EQUAL MPI_NUMLIBS_EXPECTED)
|
||||
set(MPI_LIBRARY "MPI_LIBRARY-NOTFOUND" CACHE FILEPATH "MPI library to link against" FORCE)
|
||||
endif (MPI_NUMLIBS EQUAL MPI_NUMLIBS_EXPECTED)
|
||||
if (MPI_NUMLIBS GREATER 1)
|
||||
set(MPI_EXTRA_LIBRARY_WORK ${MPI_LIBRARIES})
|
||||
list(REMOVE_AT MPI_EXTRA_LIBRARY_WORK 0)
|
||||
set(MPI_EXTRA_LIBRARY ${MPI_EXTRA_LIBRARY_WORK} CACHE STRING "Extra MPI libraries to link against" FORCE)
|
||||
else (MPI_NUMLIBS GREATER 1)
|
||||
set(MPI_EXTRA_LIBRARY "MPI_EXTRA_LIBRARY-NOTFOUND" CACHE STRING "Extra MPI libraries to link against" FORCE)
|
||||
endif (MPI_NUMLIBS GREATER 1)
|
||||
|
||||
# Set up all of the appropriate cache entries
|
||||
set(MPI_COMPILE_FLAGS ${MPI_COMPILE_FLAGS_WORK} CACHE STRING "MPI compilation flags" FORCE)
|
||||
set(MPI_INCLUDE_PATH ${MPI_INCLUDE_PATH_WORK} CACHE STRING "MPI include path" FORCE)
|
||||
set(MPI_LINK_FLAGS ${MPI_LINK_FLAGS_WORK} CACHE STRING "MPI linking flags" FORCE)
|
||||
else (MPI_COMPILE_CMDLINE)
|
||||
# No MPI compiler to interogate so attempt to find everything with find functions.
|
||||
find_path(MPI_INCLUDE_PATH mpi.h
|
||||
HINTS ${_MPI_BASE_DIR} ${_MPI_PREFIX_PATH}
|
||||
PATH_SUFFIXES include Inc
|
||||
)
|
||||
|
||||
# Decide between 32-bit and 64-bit libraries for Microsoft's MPI
|
||||
if("${CMAKE_SIZEOF_VOID_P}" EQUAL 8)
|
||||
set(MS_MPI_ARCH_DIR amd64)
|
||||
else()
|
||||
set(MS_MPI_ARCH_DIR i386)
|
||||
endif()
|
||||
|
||||
find_library(MPI_LIBRARY
|
||||
NAMES mpi mpich msmpi
|
||||
HINTS ${_MPI_BASE_DIR} ${_MPI_PREFIX_PATH}
|
||||
PATH_SUFFIXES lib lib/${MS_MPI_ARCH_DIR} Lib Lib/${MS_MPI_ARCH_DIR}
|
||||
)
|
||||
|
||||
find_library(MPI_EXTRA_LIBRARY
|
||||
NAMES mpi++
|
||||
HINTS ${_MPI_BASE_DIR} ${_MPI_PREFIX_PATH}
|
||||
PATH_SUFFIXES lib
|
||||
DOC "Extra MPI libraries to link against.")
|
||||
|
||||
set(MPI_COMPILE_FLAGS "" CACHE STRING "MPI compilation flags")
|
||||
set(MPI_LINK_FLAGS "" CACHE STRING "MPI linking flags")
|
||||
endif (MPI_INCLUDE_PATH AND MPI_LIBRARY)
|
||||
|
||||
# Set up extra variables to conform to
|
||||
if (MPI_EXTRA_LIBRARY)
|
||||
set(MPI_LIBRARIES ${MPI_LIBRARY} ${MPI_EXTRA_LIBRARY})
|
||||
else (MPI_EXTRA_LIBRARY)
|
||||
set(MPI_LIBRARIES ${MPI_LIBRARY})
|
||||
endif (MPI_EXTRA_LIBRARY)
|
||||
|
||||
if (MPI_INCLUDE_PATH AND MPI_LIBRARY)
|
||||
set(MPI_FOUND TRUE)
|
||||
else (MPI_INCLUDE_PATH AND MPI_LIBRARY)
|
||||
set(MPI_FOUND FALSE)
|
||||
endif (MPI_INCLUDE_PATH AND MPI_LIBRARY)
|
||||
|
||||
#include("${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake")
|
||||
# handle the QUIETLY and REQUIRED arguments
|
||||
#find_package_handle_standard_args(MPI DEFAULT_MSG MPI_LIBRARY MPI_INCLUDE_PATH)
|
||||
|
||||
mark_as_advanced(MPI_INCLUDE_PATH MPI_COMPILE_FLAGS MPI_LINK_FLAGS MPI_LIBRARY
|
||||
MPI_EXTRA_LIBRARY)
|
||||
|
||||
# unset to cleanup namespace
|
||||
unset(_MPI_PACKAGE_DIR)
|
||||
unset(_MPI_PREFIX_PATH)
|
||||
unset(_MPI_BASE_DIR)
|
|
@ -4,7 +4,7 @@
|
|||
# CONFIGURE_TIMER( DEFAULT_USE_TIMER NULL_TIMER_DIR )
|
||||
# This function assumes that USE_TIMER is set to indicate if the timer should be used
|
||||
# If USE_TIMER is set, TIMER_DIRECTORY specifies the install path for the timer
|
||||
# If USE_TIMER is not set we will create a summy timer that does nothing.
|
||||
# If USE_TIMER is not set we will create a dummy timer that does nothing.
|
||||
# The input argument DEFAULT_USE_TIMER specifies if the timer library is included by default.
|
||||
# The input argument NULL_TIMER_DIR specifies the location to install the dummy timer.
|
||||
# If it is an empty string, the default install path "${CMAKE_CURRENT_BINARY_DIR}/null_timer" is used.
|
||||
|
@ -13,7 +13,7 @@
|
|||
# TIMER_CXXFLAGS - C++ flags for the timer library
|
||||
# TIMER_LDFLAGS - Linker flags to link the timer library
|
||||
# TIMER_LDLIBS - Linker libraries to link the timer library
|
||||
FUNCTION( CONFIGURE_TIMER DEFAULT_USE_TIMER NULL_TIMER_DIR )
|
||||
FUNCTION( CONFIGURE_TIMER DEFAULT_USE_TIMER NULL_TIMER_DIR QUIET )
|
||||
# Determine if we want to use the timer utility
|
||||
CHECK_ENABLE_FLAG( USE_TIMER ${DEFAULT_USE_TIMER} )
|
||||
SET( TIMER_INCLUDE )
|
||||
|
@ -33,20 +33,23 @@ FUNCTION( CONFIGURE_TIMER DEFAULT_USE_TIMER NULL_TIMER_DIR )
|
|||
FIND_LIBRARY( TIMER_LIBS NAMES timerutility PATHS ${TIMER_DIRECTORY}/lib NO_DEFAULT_PATH )
|
||||
SET( TIMER_INCLUDE ${TIMER_DIRECTORY}/include )
|
||||
SET( TIMER_CXXFLAGS "-DUSE_TIMER -I${TIMER_DIRECTORY}/include" )
|
||||
SET( TIMER_LDFLAGS -L${TIMER_DIRECTORY}/lib )
|
||||
SET( TIMER_LDLIBS -ltimerutility )
|
||||
SET( TIMER_LDFLAGS )
|
||||
SET( TIMER_LDLIBS "${TIMER_LIBS}" )
|
||||
ELSE()
|
||||
MESSAGE( FATAL_ERROR "Default search for TIMER is not yet supported. Use -D TIMER_DIRECTORY=" )
|
||||
ENDIF()
|
||||
SET( CMAKE_INSTALL_RPATH ${CMAKE_INSTALL_RPATH} "${TIMER_DIRECTORY}/lib" PARENT_SCOPE )
|
||||
INCLUDE_DIRECTORIES( "${TIMER_INCLUDE}" )
|
||||
ADD_DEFINITIONS( -DUSE_TIMER )
|
||||
MESSAGE( "Using timer utility" )
|
||||
MESSAGE( " TIMER_LIBRARIES = ${TIMER_LIBS}" )
|
||||
IF ( NOT QUIET )
|
||||
MESSAGE( STATUS "Using timer utility" )
|
||||
MESSAGE( STATUS " TIMER_LIBRARIES = ${TIMER_LIBS}" )
|
||||
ENDIF()
|
||||
ELSE()
|
||||
IF ( "${NULL_TIMER_DIR}" STREQUAL "" )
|
||||
SET( NULL_TIMER_DIR "${CMAKE_CURRENT_BINARY_DIR}/null_timer" )
|
||||
ENDIF()
|
||||
# Write ProfilerApp.h
|
||||
FILE(WRITE "${NULL_TIMER_DIR}/ProfilerApp.h" "#define PROFILE_START(...) do {} while(0)\n" )
|
||||
FILE(APPEND "${NULL_TIMER_DIR}/ProfilerApp.h" "#define PROFILE_STOP(...) do {} while(0)\n" )
|
||||
FILE(APPEND "${NULL_TIMER_DIR}/ProfilerApp.h" "#define PROFILE_START2(...) do {} while(0)\n" )
|
||||
|
@ -61,9 +64,25 @@ FUNCTION( CONFIGURE_TIMER DEFAULT_USE_TIMER NULL_TIMER_DIR )
|
|||
FILE(APPEND "${NULL_TIMER_DIR}/ProfilerApp.h" "#define PROFILE_DISABLE_TRACE() do {} while(0)\n" )
|
||||
FILE(APPEND "${NULL_TIMER_DIR}/ProfilerApp.h" "#define PROFILE_ENABLE_MEMORY() do {} while(0)\n" )
|
||||
FILE(APPEND "${NULL_TIMER_DIR}/ProfilerApp.h" "#define PROFILE_DISABLE_MEMORY() do {} while(0)\n" )
|
||||
# Write MemoryApp.h
|
||||
FILE(WRITE "${NULL_TIMER_DIR}/MemoryApp.h" "#include <cstring>\n" )
|
||||
FILE(APPEND "${NULL_TIMER_DIR}/MemoryApp.h" "class MemoryApp final {\n" )
|
||||
FILE(APPEND "${NULL_TIMER_DIR}/MemoryApp.h" "public:\n" )
|
||||
FILE(APPEND "${NULL_TIMER_DIR}/MemoryApp.h" " struct MemoryStats {\n" )
|
||||
FILE(APPEND "${NULL_TIMER_DIR}/MemoryApp.h" " size_t bytes_new, bytes_delete, N_new, N_delete, tot_bytes_used, system_memory, stack_used, stack_size;\n" )
|
||||
FILE(APPEND "${NULL_TIMER_DIR}/MemoryApp.h" " MemoryStats() { memset(this,0,sizeof(MemoryStats)); }\n" )
|
||||
FILE(APPEND "${NULL_TIMER_DIR}/MemoryApp.h" " };\n" )
|
||||
FILE(APPEND "${NULL_TIMER_DIR}/MemoryApp.h" " static inline void print( std::ostream& ) {}\n" )
|
||||
FILE(APPEND "${NULL_TIMER_DIR}/MemoryApp.h" " static inline size_t getMemoryUsage() { return 0; }\n" )
|
||||
FILE(APPEND "${NULL_TIMER_DIR}/MemoryApp.h" " static inline size_t getTotalMemoryUsage() { return 0; }\n" )
|
||||
FILE(APPEND "${NULL_TIMER_DIR}/MemoryApp.h" " static inline size_t getSystemMemory() { return 0; }\n" )
|
||||
FILE(APPEND "${NULL_TIMER_DIR}/MemoryApp.h" " static inline MemoryStats getMemoryStats() { return MemoryStats(); }\n" )
|
||||
FILE(APPEND "${NULL_TIMER_DIR}/MemoryApp.h" "};\n" )
|
||||
SET( TIMER_INCLUDE "${NULL_TIMER_DIR}" )
|
||||
INCLUDE_DIRECTORIES( "${TIMER_INCLUDE}" )
|
||||
MESSAGE( "Disabling timer utility" )
|
||||
IF ( NOT QUIET )
|
||||
MESSAGE( STATUS "Disabling timer utility" )
|
||||
ENDIF()
|
||||
ENDIF()
|
||||
SET( TIMER_INCLUDE "${TIMER_INCLUDE}" PARENT_SCOPE )
|
||||
SET( TIMER_CXXFLAGS "${TIMER_CXXFLAGS}" PARENT_SCOPE )
|
||||
|
@ -88,12 +107,12 @@ MACRO( CHECK_ENABLE_FLAG FLAG DEFAULT )
|
|||
SET( ${FLAG} ${DEFAULT} )
|
||||
ELSEIF( ${FLAG} STREQUAL "" )
|
||||
SET( ${FLAG} ${DEFAULT} )
|
||||
ELSEIF( ( ${${FLAG}} STREQUAL "false" ) OR ( ${${FLAG}} STREQUAL "0" ) OR ( ${${FLAG}} STREQUAL "OFF" ) )
|
||||
ELSEIF( ( ${${FLAG}} STREQUAL "FALSE" ) OR ( ${${FLAG}} STREQUAL "false" ) OR ( ${${FLAG}} STREQUAL "0" ) OR ( ${${FLAG}} STREQUAL "OFF" ) )
|
||||
SET( ${FLAG} 0 )
|
||||
ELSEIF( ( ${${FLAG}} STREQUAL "true" ) OR ( ${${FLAG}} STREQUAL "1" ) OR ( ${${FLAG}} STREQUAL "ON" ) )
|
||||
ELSEIF( ( ${${FLAG}} STREQUAL "TRUE" ) OR ( ${${FLAG}} STREQUAL "true" ) OR ( ${${FLAG}} STREQUAL "1" ) OR ( ${${FLAG}} STREQUAL "ON" ) )
|
||||
SET( ${FLAG} 1 )
|
||||
ELSE()
|
||||
MESSAGE( "Bad value for ${FLAG} (${${FLAG}}); use true or false" )
|
||||
MESSAGE( FATAL_ERROR "Bad value for ${FLAG} (${${FLAG}}); use true or false" )
|
||||
ENDIF ()
|
||||
ENDMACRO()
|
||||
|
||||
|
|
|
@ -32,7 +32,6 @@ SET( CMAKE_MAKE_PROGRAM $ENV{CMAKE_MAKE_PROGRAM} )
|
|||
SET( CTEST_CMAKE_GENERATOR $ENV{CTEST_CMAKE_GENERATOR} )
|
||||
SET( LDLIBS $ENV{LDLIBS} )
|
||||
SET( LDFLAGS $ENV{LDFLAGS} )
|
||||
SET( MPI_COMPILER $ENV{MPI_COMPILER} )
|
||||
SET( MPI_DIRECTORY $ENV{MPI_DIRECTORY} )
|
||||
SET( MPI_INCLUDE $ENV{MPI_INCLUDE} )
|
||||
SET( MPI_LINK_FLAGS $ENV{MPI_LINK_FLAGS} )
|
||||
|
@ -198,7 +197,7 @@ SET( CTEST_OPTIONS "${CTEST_OPTIONS};-DCMAKE_C_FLAGS='${CFLAGS}';-DCMAKE_CXX_FLA
|
|||
SET( CTEST_OPTIONS "${CTEST_OPTIONS};-DLDFLAGS:STRING='${FLAGS}';-DLDLIBS:STRING='${LDLIBS}'" )
|
||||
SET( CTEST_OPTIONS "${CTEST_OPTIONS};-DENABLE_GCOV:BOOL=${ENABLE_GCOV}" )
|
||||
IF ( USE_MPI )
|
||||
SET( CTEST_OPTIONS "${CTEST_OPTIONS};-DMPI_COMPILER:BOOL=true;-DMPIEXEC=${MPIEXEC}")
|
||||
SET( CTEST_OPTIONS "${CTEST_OPTIONS};-DMPIEXEC=${MPIEXEC}")
|
||||
IF ( NOT USE_VALGRIND )
|
||||
SET( CTEST_OPTIONS "${CTEST_OPTIONS};-DUSE_MPI_FOR_SERIAL_TESTS:BOOL=true")
|
||||
ENDIF()
|
||||
|
|
|
@ -43,91 +43,59 @@ MACRO( CONFIGURE_MPI )
|
|||
# Determine if we want to use MPI
|
||||
CHECK_ENABLE_FLAG( USE_MPI 1 )
|
||||
IF ( USE_MPI )
|
||||
# Check if we specified the MPI directory
|
||||
IF ( MPI_DIRECTORY )
|
||||
# Check the provided MPI directory for include files
|
||||
VERIFY_PATH( "${MPI_DIRECTORY}" )
|
||||
IF ( EXISTS "${MPI_DIRECTORY}/include/mpi.h" )
|
||||
SET( MPI_INCLUDE_PATH "${MPI_DIRECTORY}/include" )
|
||||
ELSEIF ( EXISTS "${MPI_DIRECTORY}/Inc/mpi.h" )
|
||||
SET( MPI_INCLUDE_PATH "${MPI_DIRECTORY}/Inc" )
|
||||
ELSE()
|
||||
MESSAGE( FATAL_ERROR "mpi.h not found in ${MPI_DIRECTORY}/include" )
|
||||
ENDIF ()
|
||||
INCLUDE_DIRECTORIES ( ${MPI_INCLUDE_PATH} )
|
||||
SET ( MPI_INCLUDE ${MPI_INCLUDE_PATH} )
|
||||
# Set MPI libraries
|
||||
IF ( ${CMAKE_SYSTEM_NAME} STREQUAL "Windows" )
|
||||
FIND_LIBRARY( MSMPI_LIB NAMES msmpi PATHS "${MPI_DIRECTORY}/Lib/x64" NO_DEFAULT_PATH )
|
||||
FIND_LIBRARY( MSMPI_LIB NAMES msmpi PATHS "${MPI_DIRECTORY}/Lib/amd64" NO_DEFAULT_PATH )
|
||||
FIND_LIBRARY( MSMPIFEC_LIB NAMES msmpifec PATHS "${MPI_DIRECTORY}/Lib/x64" NO_DEFAULT_PATH )
|
||||
FIND_LIBRARY( MSMPIFEC_LIB NAMES msmpifec PATHS "${MPI_DIRECTORY}/Lib/amd64" NO_DEFAULT_PATH )
|
||||
FIND_LIBRARY( MSMPIFMC_LIB NAMES msmpifmc PATHS "${MPI_DIRECTORY}/Lib/x64" NO_DEFAULT_PATH )
|
||||
FIND_LIBRARY( MSMPIFMC_LIB NAMES msmpifmc PATHS "${MPI_DIRECTORY}/Lib/amd64" NO_DEFAULT_PATH )
|
||||
SET( MPI_LIBRARIES ${MSMPI_LIB} ${MSMPIFEC_LIB} ${MSMPIFMC_LIB} )
|
||||
ENDIF()
|
||||
# Set the mpi executable
|
||||
MESSAGE( "Configuring MPI" )
|
||||
IF ( MPIEXEC )
|
||||
# User specified the MPI command directly, use as is
|
||||
ELSEIF ( MPIEXEC_CMD )
|
||||
# User specified the name of the MPI executable
|
||||
SET ( MPIEXEC ${MPI_DIRECTORY}/bin/${MPIEXEC_CMD} )
|
||||
IF ( NOT EXISTS ${MPIEXEC} )
|
||||
MESSAGE( FATAL_ERROR "${MPIEXEC_CMD} not found in ${MPI_DIRECTORY}/bin" )
|
||||
SET( MPIEXEC_EXECUTABLE ${MPIEXEC} )
|
||||
ENDIF()
|
||||
IF ( NOT MPI_SKIP_SEARCH )
|
||||
FIND_PACKAGE( MPI )
|
||||
ELSE()
|
||||
# Search for the MPI executable in the current directory
|
||||
FIND_PROGRAM( MPIEXEC NAMES mpiexec mpirun lamexec PATHS ${MPI_DIRECTORY}/bin NO_DEFAULT_PATH )
|
||||
IF ( NOT MPIEXEC )
|
||||
MESSAGE( FATAL_ERROR "Could not locate mpi executable" )
|
||||
# Write mpi test
|
||||
SET( MPI_TEST_SRC "${CMAKE_CURRENT_BINARY_DIR}/test_mpi.cpp" )
|
||||
FILE(WRITE ${MPI_TEST_SRC} "#include <mpi.h>\n" )
|
||||
FILE(APPEND ${MPI_TEST_SRC} "int main(int argc, char** argv) {\n" )
|
||||
FILE(APPEND ${MPI_TEST_SRC} " MPI_Init(NULL, NULL);\n")
|
||||
FILE(APPEND ${MPI_TEST_SRC} " MPI_Finalize();\n" )
|
||||
FILE(APPEND ${MPI_TEST_SRC} "}\n" )
|
||||
# Test the compile
|
||||
IF ( CMAKE_CXX_COMPILER )
|
||||
SET( TMP_FLAGS -DINCLUDE_DIRECTORIES=${MPI_CXX_INCLUDE_PATH} )
|
||||
TRY_COMPILE( MPI_TEST_CXX ${CMAKE_CURRENT_BINARY_DIR} ${MPI_TEST_SRC}
|
||||
CMAKE_FLAGS ${TMP_FLAGS}
|
||||
LINK_OPTIONS ${MPI_CXX_LINK_FLAGS}
|
||||
LINK_LIBRARIES ${MPI_CXX_LIBRARIES}
|
||||
OUTPUT_VARIABLE OUT_TXT)
|
||||
IF ( NOT ${MPI_TEST} )
|
||||
MESSAGE( FATAL_ERROR "Skipping MPI search and default compile fails:\n${OUT_TXT}" )
|
||||
ENDIF()
|
||||
SET( MPI_C_FOUND TRUE )
|
||||
SET( MPI_CXX_FOUND TRUE )
|
||||
SET( MPI_Fortran_FOUND TRUE )
|
||||
ENDIF()
|
||||
ENDIF()
|
||||
# Set MPI flags
|
||||
IF ( NOT MPIEXEC_NUMPROC_FLAG )
|
||||
SET( MPIEXEC_NUMPROC_FLAG "-np" )
|
||||
ENDIF()
|
||||
ELSEIF ( MPI_COMPILER )
|
||||
# The mpi compiler should take care of everything
|
||||
IF ( MPI_INCLUDE )
|
||||
INCLUDE_DIRECTORIES( ${MPI_INCLUDE} )
|
||||
ENDIF()
|
||||
ELSE()
|
||||
# Perform the default search for MPI
|
||||
INCLUDE ( FindMPI )
|
||||
IF ( NOT MPI_FOUND )
|
||||
MESSAGE( " MPI_INCLUDE = ${MPI_INCLUDE}" )
|
||||
MESSAGE( " MPI_LINK_FLAGS = ${MPI_LINK_FLAGS}" )
|
||||
MESSAGE( " MPI_LIBRARIES = ${MPI_LIBRARIES}" )
|
||||
MESSAGE( FATAL_ERROR "Did not find MPI" )
|
||||
ENDIF ()
|
||||
INCLUDE_DIRECTORIES( "${MPI_INCLUDE_PATH}" )
|
||||
SET( MPI_INCLUDE "${MPI_INCLUDE_PATH}" )
|
||||
ENDIF()
|
||||
# Check if we need to use MPI for serial tests
|
||||
CHECK_ENABLE_FLAG( USE_MPI_FOR_SERIAL_TESTS 0 )
|
||||
# Set defaults if they have not been set
|
||||
IF ( NOT MPIEXEC )
|
||||
SET( MPIEXEC mpirun )
|
||||
ENDIF()
|
||||
IF ( NOT MPIEXEC_NUMPROC_FLAG )
|
||||
SET( MPIEXEC_NUMPROC_FLAG "-np" )
|
||||
ENDIF()
|
||||
# Set the definitions
|
||||
ADD_DEFINITIONS( "-DUSE_MPI" )
|
||||
MESSAGE( "Using MPI" )
|
||||
STRING( STRIP "${MPI_CXX_COMPILE_FLAGS}" MPI_CXX_COMPILE_FLAGS )
|
||||
STRING( STRIP "${MPI_CXX_LINK_FLAGS}" MPI_CXX_LINK_FLAGS )
|
||||
STRING( STRIP "${MPI_CXX_LIBRARIES}" MPI_CXX_LIBRARIES )
|
||||
MESSAGE( " MPI_CXX_FOUND = ${MPI_CXX_FOUND}" )
|
||||
MESSAGE( " MPI_CXX_COMPILER = ${MPI_CXX_COMPILER}" )
|
||||
MESSAGE( " MPI_CXX_COMPILE_FLAGS = ${MPI_CXX_COMPILE_FLAGS}" )
|
||||
MESSAGE( " MPI_CXX_INCLUDE_PATH = ${MPI_CXX_INCLUDE_PATH}" )
|
||||
MESSAGE( " MPI_CXX_LINK_FLAGS = ${MPI_CXX_LINK_FLAGS}" )
|
||||
MESSAGE( " MPI_CXX_LIBRARIES = ${MPI_CXX_LIBRARIES}" )
|
||||
MESSAGE( " MPIEXEC = ${MPIEXEC}" )
|
||||
MESSAGE( " MPIEXEC_NUMPROC_FLAG = ${MPIEXEC_NUMPROC_FLAG}" )
|
||||
MESSAGE( " MPI_INCLUDE = ${MPI_INCLUDE}" )
|
||||
MESSAGE( " MPI_LINK_FLAGS = ${MPI_LINK_FLAGS}" )
|
||||
MESSAGE( " MPI_LIBRARIES = ${MPI_LIBRARIES}" )
|
||||
ELSE()
|
||||
SET( USE_MPI_FOR_SERIAL_TESTS 0 )
|
||||
SET( MPIEXEC "" )
|
||||
SET( MPIEXEC_NUMPROC_FLAG "" )
|
||||
SET( MPI_INCLUDE "" )
|
||||
SET( MPI_LINK_FLAGS "" )
|
||||
SET( MPI_LIBRARIES "" )
|
||||
MESSAGE( "Not using MPI, all parallel tests will be disabled" )
|
||||
MESSAGE( " MPIEXEC_PREFLAGS = ${MPIEXEC_PREFLAGS}" )
|
||||
MESSAGE( " MPIEXEC_POSTFLAGS = ${MPIEXEC_POSTFLAGS}" )
|
||||
ADD_DEFINITIONS( -DUSE_MPI )
|
||||
INCLUDE_DIRECTORIES( ${MPI_CXX_INCLUDE_PATH} )
|
||||
SET( MPI_LIBRARIES ${MPI_CXX_LIBRARIES} )
|
||||
SET( MPI_LINK_FLAGS ${MPI_CXX_LINK_FLAGS} )
|
||||
IF ( NOT MPI_CXX_FOUND )
|
||||
MESSAGE( FATAL_ERROR "MPI not found" )
|
||||
ENDIF()
|
||||
IF ( USE_MPI AND NOT MPIEXEC )
|
||||
MESSAGE( FATAL_ERROR "Unable to find MPIEXEC, please set it before continuing" )
|
||||
ENDIF()
|
||||
ENDIF()
|
||||
ENDMACRO()
|
||||
|
||||
|
|
|
@ -681,8 +681,8 @@ MACRO( TARGET_LINK_EXTERNAL_LIBRARIES TARGET_NAME )
|
|||
FOREACH ( tmp ${BLAS_LAPACK_LIBS} )
|
||||
TARGET_LINK_LIBRARIES( ${TARGET_NAME} ${ARGN} ${tmp} )
|
||||
ENDFOREACH()
|
||||
FOREACH ( MPI_LIBRARIES )
|
||||
TARGET_LINK_LIBRARIES( ${EXE} ${ARGN} ${tmp} )
|
||||
FOREACH ( tmp ${MPI_LIBRARIES} )
|
||||
TARGET_LINK_LIBRARIES( ${TARGET_NAME} ${ARGN} ${tmp} )
|
||||
ENDFOREACH()
|
||||
FOREACH ( tmp ${CMAKE_C_IMPLICIT_LINK_LIBRARIES}
|
||||
${CMAKE_CXX_IMPLICIT_LINK_LIBRARIES} ${CMAKE_Fortran_IMPLICIT_LINK_LIBRARIES} )
|
||||
|
|
|
@ -164,7 +164,7 @@ SET( CTEST_OPTIONS )
|
|||
SET( CTEST_OPTIONS "-DCMAKE_BUILD_TYPE:STRING=${CMAKE_BUILD_TYPE}" )
|
||||
SET( CTEST_OPTIONS "${CTEST_OPTIONS};-DCMAKE_C_COMPILER:PATH=${CC};-DCMAKE_C_FLAGS='${C_FLAGS}';" )
|
||||
SET( CTEST_OPTIONS "${CTEST_OPTIONS};-DCMAKE_CXX_COMPILER:PATH=${CXX};-DCMAKE_CXX_FLAGS='${CXX_FLAGS}'" )
|
||||
SET( CTEST_OPTIONS "${CTEST_OPTIONS};-DMPI_COMPILER:BOOL=true;-DMPIEXEC=${MPIEXEC};-DUSE_EXT_MPI_FOR_SERIAL_TESTS:BOOL=true")
|
||||
SET( CTEST_OPTIONS "${CTEST_OPTIONS};-DMPIEXEC=${MPIEXEC};-DUSE_EXT_MPI_FOR_SERIAL_TESTS:BOOL=true")
|
||||
IF ( USE_CUDA )
|
||||
SET( CTEST_OPTIONS "${CTEST_OPTIONS};-DUSE_CUDA:BOOL=true;-DCUDA_NVCC_FLAGS='${CUDA_FLAGS}';-DCUDA_HOST_COMPILER=${CUDA_HOST_COMPILER}" )
|
||||
ELSE()
|
||||
|
|
|
@ -33,7 +33,6 @@ cmake \
|
|||
-D CMAKE_CXX_STANDARD=14 \
|
||||
-D USE_TIMER=false \
|
||||
-D TIMER_DIRECTORY=${HOME}/timerutility/build/opt \
|
||||
-D MPI_COMPILER:BOOL=TRUE \
|
||||
-D MPIEXEC=aprun \
|
||||
-D USE_EXT_MPI_FOR_SERIAL_TESTS:BOOL=TRUE \
|
||||
-D USE_CUDA=0 \
|
||||
|
|
|
@ -27,7 +27,6 @@ cmake \
|
|||
-D CMAKE_CXX_STD=11 \
|
||||
-D USE_TIMER=false \
|
||||
-D TIMER_DIRECTORY=${HOME}/timerutility/build/opt \
|
||||
-D MPI_COMPILER:BOOL=TRUE \
|
||||
-D MPIEXEC=aprun \
|
||||
-D USE_EXT_MPI_FOR_SERIAL_TESTS:BOOL=TRUE \
|
||||
-D USE_CUDA=0 \
|
||||
|
|
|
@ -25,7 +25,6 @@ cmake \
|
|||
-D CMAKE_CUDA_FLAGS="-arch sm_35" \
|
||||
-D CMAKE_CUDA_HOST_COMPILER="/opt/gcc/6.3.0/bin/gcc" \
|
||||
-D USE_MPI=1 \
|
||||
-D MPI_COMPILER:BOOL=TRUE \
|
||||
-D MPIEXEC=aprun \
|
||||
-D USE_EXT_MPI_FOR_SERIAL_TESTS:BOOL=TRUE \
|
||||
-D USE_SILO=1 \
|
||||
|
|
|
@ -20,7 +20,6 @@ cmake \
|
|||
-D CMAKE_CUDA_FLAGS="-arch sm_35" \
|
||||
-D CMAKE_CUDA_HOST_COMPILER="/opt/gcc/6.3.0/bin/gcc" \
|
||||
-D USE_MPI=1 \
|
||||
-D MPI_COMPILER:BOOL=TRUE \
|
||||
-D MPIEXEC=aprun \
|
||||
-D USE_EXT_MPI_FOR_SERIAL_TESTS:BOOL=TRUE \
|
||||
-D USE_NETCDF=0 \
|
||||
|
|
|
@ -36,6 +36,5 @@ cmake \
|
|||
|
||||
# MPI_THREAD_MULTIPLE=1 MV2_USE_RDMA_CM=0 MV2_USE_RDMA_CM= MV2_NUM_HCAS=1 MV2_USE_CUDA=1 MV2_ENABLE_AFFINITY=0 srun -n 2 -N 1 --cpu-bind=v -c 1 ./test_MPI
|
||||
|
||||
# -D MPI_COMPILER:BOOL=TRUE \
|
||||
# -D MPIEXEC=mpirun \
|
||||
# -D USE_EXT_MPI_FOR_SERIAL_TESTS:BOOL=TRUE \
|
||||
|
|
|
@ -21,7 +21,6 @@ cmake \
|
|||
-D HIP_NVCC_OPTIONS="-arch sm_70" \
|
||||
-D LINK_LIBRARIES="/sw/summit/cuda/9.2.148/lib64/libcudart.so" \
|
||||
-D USE_MPI=1 \
|
||||
-D MPI_COMPILER:BOOL=TRUE \
|
||||
-D USE_NETCDF=0 \
|
||||
-D USE_SILO=1 \
|
||||
-D SILO_DIRECTORY=${TPL_DIR}/silo \
|
||||
|
|
|
@ -9,7 +9,6 @@ cmake \
|
|||
-D CMAKE_CUDA_FLAGS="-arch sm_35" \
|
||||
-D CMAKE_CUDA_HOST_COMPILER="/usr/bin/gcc" \
|
||||
-D USE_MPI=1 \
|
||||
-D MPI_COMPILER:BOOL=TRUE \
|
||||
-D MPIEXEC=aprun \
|
||||
-D USE_EXT_MPI_FOR_SERIAL_TESTS:BOOL=TRUE \
|
||||
${HOME}/LBPM-WIA
|
||||
|
|
|
@ -10,7 +10,6 @@ cmake \
|
|||
-D CMAKE_CXX_COMPILER:PATH=mpicxx \
|
||||
-D CMAKE_C_FLAGS="" \
|
||||
-D CMAKE_CXX_FLAGS="" \
|
||||
-D MPI_COMPILER:BOOL=TRUE \
|
||||
-D MPIEXEC=mpirun \
|
||||
-D USE_EXT_MPI_FOR_SERIAL_TESTS:BOOL=TRUE \
|
||||
-D CMAKE_BUILD_TYPE:STRING=Release \
|
||||
|
|
|
@ -5,7 +5,6 @@ cmake -D CMAKE_C_COMPILER:PATH=/opt/arden/openmpi/3.1.2/bin/mpicc \
|
|||
-D CMAKE_C_FLAGS="-O3 -fPIC" \
|
||||
-D CMAKE_CXX_FLAGS="-O3 -fPIC " \
|
||||
-D CMAKE_CXX_STANDARD=14 \
|
||||
-D MPI_COMPILER:BOOL=TRUE \
|
||||
-D MPIEXEC=mpirun \
|
||||
-D USE_EXT_MPI_FOR_SERIAL_TESTS:BOOL=TRUE \
|
||||
-D CMAKE_BUILD_TYPE:STRING=Release \
|
||||
|
|
|
@ -8,7 +8,6 @@ cmake \
|
|||
-D CMAKE_CXX_COMPILER:PATH=mpicxx \
|
||||
-D CMAKE_C_FLAGS="" \
|
||||
-D CMAKE_CXX_FLAGS="" \
|
||||
-D MPI_COMPILER:BOOL=TRUE \
|
||||
-D MPIEXEC=mpirun \
|
||||
-D USE_EXT_MPI_FOR_SERIAL_TESTS:BOOL=TRUE \
|
||||
-D CMAKE_BUILD_TYPE:STRING=Release \
|
||||
|
|
|
@ -8,7 +8,6 @@ cmake \
|
|||
-D CMAKE_CXX_COMPILER:PATH=mpicxx \
|
||||
-D CMAKE_C_FLAGS="" \
|
||||
-D CMAKE_CXX_FLAGS="" \
|
||||
-D MPI_COMPILER:BOOL=TRUE \
|
||||
-D MPIEXEC=mpirun \
|
||||
-D USE_EXT_MPI_FOR_SERIAL_TESTS:BOOL=TRUE \
|
||||
-D CMAKE_BUILD_TYPE:STRING=Release \
|
||||
|
|
|
@ -11,7 +11,6 @@ cmake \
|
|||
-D CMAKE_CXX_COMPILER:PATH=mpicxx \
|
||||
-D CMAKE_C_FLAGS="-fPIC" \
|
||||
-D CMAKE_CXX_FLAGS="-fPIC" \
|
||||
-D MPI_COMPILER:BOOL=TRUE \
|
||||
-D MPIEXEC=mpirun \
|
||||
-D USE_EXT_MPI_FOR_SERIAL_TESTS:BOOL=TRUE \
|
||||
-D CMAKE_BUILD_TYPE:STRING=Release \
|
||||
|
|
|
@ -7,7 +7,6 @@ cmake \
|
|||
-D CMAKE_C_FLAGS="-g " \
|
||||
-D CMAKE_CXX_FLAGS="-g " \
|
||||
-D CMAKE_CXX_STANDARD=14 \
|
||||
-D MPI_COMPILER:BOOL=TRUE \
|
||||
-D MPIEXEC=mpirun \
|
||||
-D USE_EXT_MPI_FOR_SERIAL_TESTS:BOOL=TRUE \
|
||||
-D CMAKE_BUILD_TYPE:STRING=Release \
|
||||
|
|
|
@ -12,7 +12,6 @@ cmake \
|
|||
-D CMAKE_CXX_COMPILER:PATH=mpicxx \
|
||||
-D CMAKE_C_FLAGS="-fPIC" \
|
||||
-D CMAKE_CXX_FLAGS="-fPIC" \
|
||||
-D MPI_COMPILER:BOOL=TRUE \
|
||||
-D MPIEXEC=mpirun \
|
||||
-D USE_EXT_MPI_FOR_SERIAL_TESTS:BOOL=TRUE \
|
||||
-D CMAKE_BUILD_TYPE:STRING=Release \
|
||||
|
|
|
@ -20,7 +20,6 @@ cmake \
|
|||
-D CMAKE_CUDA_FLAGS="-arch sm_70 -Xptxas=-v -Xptxas -dlcm=cg -lineinfo" \
|
||||
-D CMAKE_CUDA_HOST_COMPILER="/sw/summit/gcc/6.4.0/bin/gcc" \
|
||||
-D USE_MPI=1 \
|
||||
-D MPI_COMPILER:BOOL=TRUE \
|
||||
-D MPIEXEC=mpirun \
|
||||
-D USE_EXT_MPI_FOR_SERIAL_TESTS:BOOL=TRUE \
|
||||
-D USE_HDF5=1 \
|
||||
|
|
|
@ -15,7 +15,6 @@ cmake \
|
|||
-D CMAKE_C_COMPILER:PATH=cc \
|
||||
-D CMAKE_CXX_COMPILER:PATH=CC \
|
||||
-D CMAKE_CXX_COMPILER:PATH=CC \
|
||||
-D MPI_COMPILER:BOOL=TRUE \
|
||||
-D MPIEXEC=aprun \
|
||||
-D USE_EXT_MPI_FOR_SERIAL_TESTS:BOOL=TRUE \
|
||||
-D CMAKE_BUILD_TYPE:STRING=Debug \
|
||||
|
|
|
@ -5,9 +5,7 @@ cmake -D CMAKE_C_COMPILER:PATH=/opt/arden/openmpi/3.1.2/bin/mpicc \
|
|||
-D CMAKE_C_FLAGS="-O3 -fPIC" \
|
||||
-D CMAKE_CXX_FLAGS="-O3 -fPIC " \
|
||||
-D CMAKE_CXX_STANDARD=14 \
|
||||
-D MPI_COMPILER:BOOL=TRUE \
|
||||
-D MPIEXEC=mpirun \
|
||||
-D USE_EXT_MPI_FOR_SERIAL_TESTS:BOOL=TRUE \
|
||||
-D CMAKE_BUILD_TYPE:STRING=Release \
|
||||
-D CUDA_FLAGS="-arch sm_35" \
|
||||
-D CUDA_HOST_COMPILER="/usr/bin/gcc" \
|
||||
|
|
|
@ -12,7 +12,6 @@ i -D CMAKE_CXX_COMPILER:PATH=/home/christopher/openmpi/install_dir/bin/mpicxx
|
|||
-D USE_DOXYGEN=false \
|
||||
# -D CMAKE_C_FLAGS="-std=gnu++11 -w" \
|
||||
# -D CMAKE_CXX_FLAGS="-std=gnu++11 -w" \
|
||||
-D MPI_COMPILER:BOOL=TRUE \
|
||||
-D MPIEXEC=/home/christopher/openmpi/install_dir/bin/mpirun \
|
||||
-D USE_EXT_MPI_FOR_SERIAL_TESTS:BOOL=TRUE \
|
||||
-D CMAKE_BUILD_TYPE:STRING=Release \
|
||||
|
|
|
@ -7,7 +7,6 @@ cmake \
|
|||
-D CMAKE_C_FLAGS="-g " \
|
||||
-D CMAKE_CXX_FLAGS="-g -Wno-deprecated-declarations" \
|
||||
-D CXX_STD=11 \
|
||||
-D MPI_COMPILER:BOOL=TRUE \
|
||||
-D MPIEXEC=mpirun \
|
||||
-D USE_EXT_MPI_FOR_SERIAL_TESTS:BOOL=TRUE \
|
||||
-D CMAKE_BUILD_TYPE:STRING=Debug \
|
||||
|
|
|
@ -35,8 +35,8 @@ ADD_LBPM_EXECUTABLE( GenerateSphereTest )
|
|||
#ADD_LBPM_EXECUTABLE( BlobAnalysis )
|
||||
#ADD_LBPM_EXECUTABLE( BlobIdentify )
|
||||
#ADD_LBPM_EXECUTABLE( BlobIdentifyParallel )
|
||||
#ADD_LBPM_EXECUTABLE( convertIO )
|
||||
#ADD_LBPM_EXECUTABLE( DataAggregator )
|
||||
ADD_LBPM_EXECUTABLE( convertIO )
|
||||
ADD_LBPM_EXECUTABLE( DataAggregator )
|
||||
#ADD_LBPM_EXECUTABLE( BlobAnalyzeParallel )(
|
||||
ADD_LBPM_EXECUTABLE( lbpm_minkowski_scalar )
|
||||
ADD_LBPM_EXECUTABLE( TestPoissonSolver )
|
||||
|
|
|
@ -1,18 +1,18 @@
|
|||
#include <exception>
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
#include <memory>
|
||||
#include <stdexcept>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <iostream>
|
||||
#include <exception>
|
||||
#include <stdexcept>
|
||||
#include <fstream>
|
||||
#include <memory>
|
||||
|
||||
#include "common/UnitTest.h"
|
||||
#include "common/Utilities.h"
|
||||
#include "common/MPI.h"
|
||||
#include "IO/MeshDatabase.h"
|
||||
#include "IO/Reader.h"
|
||||
#include "IO/Writer.h"
|
||||
#include "ProfilerApp.h"
|
||||
#include "common/MPI.h"
|
||||
#include "common/UnitTest.h"
|
||||
#include "common/Utilities.h"
|
||||
|
||||
inline bool approx_equal( const Point &A, const Point &B )
|
||||
{
|
||||
|
@ -25,19 +25,105 @@ inline bool approx_equal( const double& A, const double& B )
|
|||
}
|
||||
|
||||
|
||||
inline double distance( const Point& p )
|
||||
inline double distance( const Point &p ) { return sqrt( p.x * p.x + p.y * p.y + p.z * p.z ); }
|
||||
|
||||
|
||||
bool checkMesh( const std::vector<IO::MeshDataStruct> &meshData, const std::string &format,
|
||||
std::shared_ptr<IO::Mesh> mesh )
|
||||
{
|
||||
return sqrt(p.x*p.x+p.y*p.y+p.z*p.z);
|
||||
|
||||
// Get direct access to the meshes used to test the reader
|
||||
const auto pointmesh = dynamic_cast<IO::PointList *>( meshData[0].mesh.get() );
|
||||
const auto trimesh = dynamic_cast<IO::TriMesh *>( meshData[1].mesh.get() );
|
||||
const auto trilist = dynamic_cast<IO::TriList *>( meshData[2].mesh.get() );
|
||||
const auto domain = dynamic_cast<IO::DomainMesh *>( meshData[3].mesh.get() );
|
||||
const size_t N_tri = trimesh->A.size();
|
||||
if ( mesh->className() == "pointmesh" ) {
|
||||
// Check the pointmesh
|
||||
auto pmesh = IO::getPointList( mesh );
|
||||
if ( pmesh.get() == NULL )
|
||||
return false;
|
||||
if ( pmesh->points.size() != pointmesh->points.size() )
|
||||
return false;
|
||||
}
|
||||
if ( mesh->className() == "trimesh" || mesh->className() == "trilist" ) {
|
||||
// Check the trimesh/trilist
|
||||
auto mesh1 = IO::getTriMesh( mesh );
|
||||
auto mesh2 = IO::getTriList( mesh );
|
||||
if ( mesh1.get() == NULL || mesh2.get() == NULL )
|
||||
return false;
|
||||
if ( mesh1->A.size() != N_tri || mesh1->B.size() != N_tri || mesh1->C.size() != N_tri ||
|
||||
mesh2->A.size() != N_tri || mesh2->B.size() != N_tri || mesh2->C.size() != N_tri )
|
||||
return false;
|
||||
const std::vector<Point> &P1 = mesh1->vertices->points;
|
||||
const std::vector<int> &A1 = mesh1->A;
|
||||
const std::vector<int> &B1 = mesh1->B;
|
||||
const std::vector<int> &C1 = mesh1->C;
|
||||
const std::vector<Point> &A2 = mesh2->A;
|
||||
const std::vector<Point> &B2 = mesh2->B;
|
||||
const std::vector<Point> &C2 = mesh2->C;
|
||||
const std::vector<Point> &A = trilist->A;
|
||||
const std::vector<Point> &B = trilist->B;
|
||||
const std::vector<Point> &C = trilist->C;
|
||||
for ( size_t i = 0; i < N_tri; i++ ) {
|
||||
if ( !approx_equal( P1[A1[i]], A[i] ) || !approx_equal( P1[B1[i]], B[i] ) ||
|
||||
!approx_equal( P1[C1[i]], C[i] ) )
|
||||
return false;
|
||||
if ( !approx_equal( A2[i], A[i] ) || !approx_equal( B2[i], B[i] ) ||
|
||||
!approx_equal( C2[i], C[i] ) )
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if ( mesh->className() == "domain" && format != "old" ) {
|
||||
// Check the domain mesh
|
||||
const IO::DomainMesh &mesh1 = *std::dynamic_pointer_cast<IO::DomainMesh>( mesh );
|
||||
if ( mesh1.nprocx != domain->nprocx || mesh1.nprocy != domain->nprocy ||
|
||||
mesh1.nprocz != domain->nprocz )
|
||||
return false;
|
||||
if ( mesh1.nx != domain->nx || mesh1.ny != domain->ny || mesh1.nz != domain->nz )
|
||||
return false;
|
||||
if ( mesh1.Lx != domain->Lx || mesh1.Ly != domain->Ly || mesh1.Lz != domain->Lz )
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool checkVar( const std::string &format, std::shared_ptr<IO::Mesh> mesh,
|
||||
std::shared_ptr<IO::Variable> variable1, std::shared_ptr<IO::Variable> variable2 )
|
||||
{
|
||||
if ( format == "new" )
|
||||
IO::reformatVariable( *mesh, *variable2 );
|
||||
bool pass = true;
|
||||
const IO::Variable &var1 = *variable1;
|
||||
const IO::Variable &var2 = *variable2;
|
||||
pass = var1.name == var2.name;
|
||||
pass = pass && var1.dim == var2.dim;
|
||||
pass = pass && var1.type == var2.type;
|
||||
pass = pass && var1.data.length() == var2.data.length();
|
||||
if ( pass ) {
|
||||
for ( size_t m = 0; m < var1.data.length(); m++ )
|
||||
pass = pass && approx_equal( var1.data( m ), var2.data( m ) );
|
||||
}
|
||||
return pass;
|
||||
}
|
||||
|
||||
|
||||
// Test writing and reading the given format
|
||||
void testWriter( const std::string& format, std::vector<IO::MeshDataStruct>& meshData, UnitTest& ut )
|
||||
void testWriter(
|
||||
const std::string &format, std::vector<IO::MeshDataStruct> &meshData, UnitTest &ut )
|
||||
{
|
||||
PROFILE_SCOPED( path, 0, timer );
|
||||
|
||||
Utilities::MPI comm( MPI_COMM_WORLD );
|
||||
int nprocs = comm.getSize();
|
||||
comm.barrier();
|
||||
|
||||
|
||||
// Set the path for the writer
|
||||
std::string path = "test_" + format;
|
||||
|
||||
|
||||
// Get the format
|
||||
std::string format2 = format;
|
||||
auto precision = IO::DataType::Double;
|
||||
|
@ -49,6 +135,7 @@ void testWriter( const std::string& format, std::vector<IO::MeshDataStruct>& mes
|
|||
precision = IO::DataType::Float;
|
||||
}
|
||||
|
||||
|
||||
// Set the precision for the variables
|
||||
for ( auto &data : meshData ) {
|
||||
data.precision = precision;
|
||||
|
@ -57,123 +144,59 @@ void testWriter( const std::string& format, std::vector<IO::MeshDataStruct>& mes
|
|||
}
|
||||
|
||||
// Write the data
|
||||
PROFILE_START(format+"-write");
|
||||
IO::initialize( "test_"+format, format2, false );
|
||||
IO::initialize( path, format2, false );
|
||||
IO::writeData( 0, meshData, comm );
|
||||
IO::writeData( 3, meshData, comm );
|
||||
comm.barrier();
|
||||
PROFILE_STOP(format+"-write");
|
||||
|
||||
// Get the summary name for reading
|
||||
std::string path = "test_" + format;
|
||||
std::string summary_name;
|
||||
if ( format=="old" || format=="new" )
|
||||
summary_name = "summary.LBM";
|
||||
else if ( format=="silo-float" || format=="silo-double" )
|
||||
summary_name = "LBM.visit";
|
||||
else
|
||||
ERROR("Unknown format");
|
||||
|
||||
// Get direct access to the meshes used to test the reader
|
||||
const auto pointmesh = dynamic_cast<IO::PointList*>( meshData[0].mesh.get() );
|
||||
const auto trimesh = dynamic_cast<IO::TriMesh*>( meshData[1].mesh.get() );
|
||||
const auto trilist = dynamic_cast<IO::TriList*>( meshData[2].mesh.get() );
|
||||
const auto domain = dynamic_cast<IO::DomainMesh*>( meshData[3].mesh.get() );
|
||||
const size_t N_tri = trimesh->A.size();
|
||||
|
||||
// Get a list of the timesteps
|
||||
PROFILE_START(format+"-read-timesteps");
|
||||
auto timesteps = IO::readTimesteps( path + "/" + summary_name );
|
||||
PROFILE_STOP(format+"-read-timesteps");
|
||||
auto timesteps = IO::readTimesteps( path, format2 );
|
||||
if ( timesteps.size() == 2 )
|
||||
ut.passes( format + ": Corrent number of timesteps" );
|
||||
else
|
||||
ut.failure( format + ": Incorrent number of timesteps" );
|
||||
|
||||
// Check the mesh lists
|
||||
|
||||
// Test the simple read interface
|
||||
bool pass = true;
|
||||
for ( const auto ×tep : timesteps ) {
|
||||
auto data = IO::readData( path, timestep, comm.getRank() );
|
||||
pass = pass && data.size() == meshData.size();
|
||||
for ( size_t i = 0; i < data.size(); i++ ) {
|
||||
pass = pass && checkMesh( meshData, format, data[i].mesh );
|
||||
}
|
||||
}
|
||||
if ( pass )
|
||||
ut.passes( format + ": Simple read interface" );
|
||||
else
|
||||
ut.failure( format + ": Simple read interface" );
|
||||
|
||||
|
||||
// Test reading each mesh domain
|
||||
for ( const auto ×tep : timesteps ) {
|
||||
// Load the list of meshes and check its size
|
||||
PROFILE_START(format+"-read-getMeshList");
|
||||
auto databaseList = IO::getMeshList( path, timestep );
|
||||
PROFILE_STOP(format+"-read-getMeshList");
|
||||
if ( databaseList.size() == meshData.size() )
|
||||
ut.passes( format + ": Corrent number of meshes found" );
|
||||
else
|
||||
ut.failure( format + ": Incorrent number of meshes found" );
|
||||
// Check the number of domains for each mesh
|
||||
bool pass = true;
|
||||
for ( const auto& database : databaseList )
|
||||
pass = pass && (int)database.domains.size()==nprocs;
|
||||
if ( pass ) {
|
||||
ut.passes(format+": Corrent number of domains for mesh");
|
||||
} else {
|
||||
for ( const auto &database : databaseList ) {
|
||||
int N_domains = database.domains.size();
|
||||
if ( N_domains != nprocs ) {
|
||||
ut.failure( format + ": Incorrent number of domains for mesh" );
|
||||
continue;
|
||||
}
|
||||
// For each domain, load the mesh and check its data
|
||||
for ( const auto& database : databaseList ) {
|
||||
pass = true;
|
||||
for (size_t k=0; k<database.domains.size(); k++) {
|
||||
PROFILE_START(format+"-read-getMesh");
|
||||
bool pass = true;
|
||||
for ( int k = 0; k < N_domains; k++ ) {
|
||||
auto mesh = IO::getMesh( path, timestep, database, k );
|
||||
PROFILE_STOP(format+"-read-getMesh");
|
||||
if ( mesh.get()==NULL ) {
|
||||
printf("Failed to load %s\n",database.name.c_str());
|
||||
pass = false;
|
||||
break;
|
||||
}
|
||||
if ( database.name=="pointmesh" ) {
|
||||
// Check the pointmesh
|
||||
auto pmesh = IO::getPointList(mesh);
|
||||
if ( pmesh.get()==NULL ) {
|
||||
pass = false;
|
||||
break;
|
||||
}
|
||||
if ( pmesh->points.size() != pointmesh->points.size() ) {
|
||||
pass = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if ( database.name=="trimesh" || database.name=="trilist" ) {
|
||||
// Check the trimesh/trilist
|
||||
auto mesh1 = IO::getTriMesh(mesh);
|
||||
auto mesh2 = IO::getTriList(mesh);
|
||||
if ( mesh1.get()==NULL || mesh2.get()==NULL ) {
|
||||
pass = false;
|
||||
break;
|
||||
}
|
||||
if ( mesh1->A.size()!=N_tri || mesh1->B.size()!=N_tri || mesh1->C.size()!=N_tri ||
|
||||
mesh2->A.size()!=N_tri || mesh2->B.size()!=N_tri || mesh2->C.size()!=N_tri )
|
||||
{
|
||||
pass = false;
|
||||
break;
|
||||
}
|
||||
const std::vector<Point>& P1 = mesh1->vertices->points;
|
||||
const std::vector<int>& A1 = mesh1->A;
|
||||
const std::vector<int>& B1 = mesh1->B;
|
||||
const std::vector<int>& C1 = mesh1->C;
|
||||
const std::vector<Point>& A2 = mesh2->A;
|
||||
const std::vector<Point>& B2 = mesh2->B;
|
||||
const std::vector<Point>& C2 = mesh2->C;
|
||||
const std::vector<Point>& A = trilist->A;
|
||||
const std::vector<Point>& B = trilist->B;
|
||||
const std::vector<Point>& C = trilist->C;
|
||||
for (size_t i=0; i<N_tri; i++) {
|
||||
if ( !approx_equal(P1[A1[i]],A[i]) || !approx_equal(P1[B1[i]],B[i]) || !approx_equal(P1[C1[i]],C[i]) )
|
||||
pass = false;
|
||||
if ( !approx_equal(A2[i],A[i]) || !approx_equal(B2[i],B[i]) || !approx_equal(C2[i],C[i]) )
|
||||
pass = false;
|
||||
}
|
||||
}
|
||||
if ( database.name=="domain" && format!="old" ) {
|
||||
// Check the domain mesh
|
||||
const IO::DomainMesh& mesh1 = *std::dynamic_pointer_cast<IO::DomainMesh>(mesh);
|
||||
if ( mesh1.nprocx!=domain->nprocx || mesh1.nprocy!=domain->nprocy || mesh1.nprocz!=domain->nprocz )
|
||||
pass = false;
|
||||
if ( mesh1.nx!=domain->nx || mesh1.ny!=domain->ny || mesh1.nz!=domain->nz )
|
||||
pass = false;
|
||||
if ( mesh1.Lx!=domain->Lx || mesh1.Ly!=domain->Ly || mesh1.Lz!=domain->Lz )
|
||||
if ( !mesh ) {
|
||||
ut.failure( "Failed to load " + database.name );
|
||||
pass = false;
|
||||
} else {
|
||||
pass = pass && checkMesh( meshData, format, mesh );
|
||||
}
|
||||
}
|
||||
if ( pass ) {
|
||||
|
@ -185,35 +208,25 @@ void testWriter( const std::string& format, std::vector<IO::MeshDataStruct>& mes
|
|||
// Load the variables and check their data
|
||||
if ( format == "old" )
|
||||
continue; // Old format does not support variables
|
||||
const IO::MeshDataStruct* mesh0 = NULL;
|
||||
const IO::MeshDataStruct *mesh0 = nullptr;
|
||||
for ( size_t k = 0; k < meshData.size(); k++ ) {
|
||||
if ( meshData[k].meshName == database.name ) {
|
||||
mesh0 = &meshData[k];
|
||||
break;
|
||||
}
|
||||
}
|
||||
for (size_t k=0; k<database.domains.size(); k++) {
|
||||
for ( int k = 0; k < N_domains; k++ ) {
|
||||
auto mesh = IO::getMesh( path, timestep, database, k );
|
||||
for ( size_t v = 0; v < mesh0->vars.size(); v++ ) {
|
||||
PROFILE_START( format + "-read-getVariable" );
|
||||
auto variable = IO::getVariable(path,timestep,database,k,mesh0->vars[v]->name);
|
||||
if ( format=="new" )
|
||||
IO::reformatVariable( *mesh, *variable );
|
||||
PROFILE_STOP(format+"-read-getVariable");
|
||||
const IO::Variable& var1 = *mesh0->vars[v];
|
||||
const IO::Variable& var2 = *variable;
|
||||
pass = var1.name == var2.name;
|
||||
pass = pass && var1.dim == var2.dim;
|
||||
pass = pass && var1.type == var2.type;
|
||||
pass = pass && var1.data.length() == var2.data.length();
|
||||
if ( pass ) {
|
||||
for (size_t m=0; m<var1.data.length(); m++)
|
||||
pass = pass && approx_equal(var1.data(m),var2.data(m));
|
||||
}
|
||||
auto variable =
|
||||
IO::getVariable( path, timestep, database, k, mesh0->vars[v]->name );
|
||||
pass = checkVar( format, mesh, mesh0->vars[v], variable );
|
||||
if ( pass ) {
|
||||
ut.passes( format + ": Variable \"" + variable->name + "\" matched" );
|
||||
} else {
|
||||
ut.failure(format+": Variable \"" + variable->name + "\" did not match");
|
||||
ut.failure(
|
||||
format + ": Variable \"" + variable->name + "\" did not match" );
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -264,8 +277,8 @@ int main(int argc, char **argv)
|
|||
Point A( x[tri[i][0]], y[tri[i][0]], z[tri[i][0]] );
|
||||
Point B( x[tri[i][1]], y[tri[i][1]], z[tri[i][1]] );
|
||||
Point C( x[tri[i][2]], y[tri[i][2]], z[tri[i][2]] );
|
||||
if ( !approx_equal(trilist->A[i],A) || !approx_equal(trilist->B[i],B) || !approx_equal(trilist->C[i],C) )
|
||||
{
|
||||
if ( !approx_equal( trilist->A[i], A ) || !approx_equal( trilist->B[i], B ) ||
|
||||
!approx_equal( trilist->C[i], C ) ) {
|
||||
printf( "Failed to create trilist\n" );
|
||||
return -1;
|
||||
}
|
||||
|
@ -317,7 +330,8 @@ int main(int argc, char **argv)
|
|||
list_node_vec->data( 3 * i + 2, 2 ) = trilist->C[i].z;
|
||||
}
|
||||
domain_node_mag->data.resize( domain->nx + 1, domain->ny + 1, domain->nz + 1 );
|
||||
domain_node_vec->data.resize({(size_t)domain->nx+1,(size_t)domain->ny+1,(size_t)domain->nz+1,3});
|
||||
domain_node_vec->data.resize(
|
||||
{ (size_t) domain->nx + 1, (size_t) domain->ny + 1, (size_t) domain->nz + 1, 3 } );
|
||||
for ( int i = 0; i < domain->nx + 1; i++ ) {
|
||||
for ( int j = 0; j < domain->ny + 1; j++ ) {
|
||||
for ( int k = 0; k < domain->nz + 1; k++ ) {
|
||||
|
@ -339,7 +353,8 @@ int main(int argc, char **argv)
|
|||
list_cell_mag->data = set_cell_mag->data;
|
||||
list_cell_vec->data = set_cell_vec->data;
|
||||
domain_cell_mag->data.resize( domain->nx, domain->ny, domain->nz );
|
||||
domain_cell_vec->data.resize({(size_t)domain->nx,(size_t)domain->ny,(size_t)domain->nz,3});
|
||||
domain_cell_vec->data.resize(
|
||||
{ (size_t) domain->nx, (size_t) domain->ny, (size_t) domain->nz, 3 } );
|
||||
for ( int i = 0; i < domain->nx; i++ ) {
|
||||
for ( int j = 0; j < domain->ny; j++ ) {
|
||||
for ( int k = 0; k < domain->nz; k++ ) {
|
||||
|
@ -375,6 +390,8 @@ int main(int argc, char **argv)
|
|||
meshData[3].vars.push_back( domain_node_vec );
|
||||
meshData[3].vars.push_back( domain_cell_mag );
|
||||
meshData[3].vars.push_back( domain_cell_vec );
|
||||
for ( const auto &data : meshData )
|
||||
ASSERT( data.check( true ) );
|
||||
|
||||
// Run the tests
|
||||
testWriter( "old", meshData, ut );
|
||||
|
@ -390,5 +407,3 @@ int main(int argc, char **argv)
|
|||
Utilities::shutdown();
|
||||
return N_errors;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -5,84 +5,65 @@
|
|||
#include <stdexcept>
|
||||
#include <fstream>
|
||||
|
||||
#include "common/MPI_Helpers.h"
|
||||
#include "common/Communication.h"
|
||||
#include "common/MPI.h"
|
||||
#include "common/Utilities.h"
|
||||
#include "IO/Mesh.h"
|
||||
#include "IO/Reader.h"
|
||||
#include "IO/Writer.h"
|
||||
#include "ProfilerApp.h"
|
||||
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
// Initialize MPI
|
||||
Utilities::startup( argc, argv );
|
||||
Utilities::MPI comm( MPI_COMM_WORLD );
|
||||
int rank = comm.getRank();
|
||||
int nprocs = comm.getSize();
|
||||
Utilities::setErrorHandlers();
|
||||
PROFILE_ENABLE(2);
|
||||
PROFILE_ENABLE_TRACE();
|
||||
PROFILE_START("Main");
|
||||
|
||||
{ // Limit scope
|
||||
|
||||
|
||||
Utilities::MPI comm( MPI_COMM_WORLD );
|
||||
// Get inputs
|
||||
if ( argc != 3 ) {
|
||||
if ( argc != 5 ) {
|
||||
std::cerr << "Error calling convertIO:\n";
|
||||
std::cerr << " convertIO input_file format\n";
|
||||
std::cerr << " convertIO <input_path> <input_format> <output_path> <output_format>\n";
|
||||
return -1;
|
||||
}
|
||||
std::string filename = argv[1];
|
||||
std::string format = argv[2];
|
||||
std::string path = IO::getPath( filename );
|
||||
std::string path_in = argv[1];
|
||||
std::string format_in = argv[2];
|
||||
std::string path_out = argv[3];
|
||||
std::string format_out = argv[4];
|
||||
|
||||
// Check that we have enough ranks to load and write the data
|
||||
// This is really only a bottleneck for the writer
|
||||
int N_domains = IO::maxDomains( path_in, format_in, comm );
|
||||
ASSERT( comm.getSize() == N_domains );
|
||||
|
||||
// Read the timesteps
|
||||
auto timesteps = IO::readTimesteps( filename );
|
||||
auto timesteps = IO::readTimesteps( path_in, format_in );
|
||||
|
||||
// Loop through the timesteps, reading/writing the data
|
||||
IO::initialize( "", format, false );
|
||||
IO::initialize( path_out, format_out, false );
|
||||
for ( auto timestep : timesteps ) {
|
||||
|
||||
// Read the list of MeshDatabase
|
||||
auto databases = IO::getMeshList( path, timestep );
|
||||
// Set the domain to read (needs to be the current rank for the writer to be valid)
|
||||
int domain = comm.getRank();
|
||||
|
||||
// Build the MeshDataStruct
|
||||
std::vector<IO::MeshDataStruct> meshData(databases.size());
|
||||
|
||||
// Loop through the database
|
||||
int i = 0;
|
||||
PROFILE_START("Read");
|
||||
for ( const auto& database : databases ) {
|
||||
|
||||
// Read the appropriate mesh domain
|
||||
ASSERT( (int) database.domains.size() == nprocs );
|
||||
meshData[i].meshName = database.name;
|
||||
meshData[i].mesh = IO::getMesh( path, timestep, database, rank );
|
||||
|
||||
// Read the variables
|
||||
for ( auto var : database.variables ) {
|
||||
auto varData = IO::getVariable( path, timestep, database, rank, var.name );
|
||||
IO::reformatVariable( *meshData[i].mesh, *varData );
|
||||
meshData[i].vars.push_back( varData );
|
||||
}
|
||||
|
||||
i++;
|
||||
}
|
||||
MPI_Barrier(comm);
|
||||
PROFILE_STOP("Read");
|
||||
// Get the maximum number of domains for the
|
||||
auto data = IO::readData( path_in, timestep, domain );
|
||||
|
||||
// Save the mesh data to a new file
|
||||
PROFILE_START("Write");
|
||||
IO::writeData( timestep, meshData, MPI_COMM_WORLD );
|
||||
MPI_Barrier(comm);
|
||||
PROFILE_STOP("Write");
|
||||
IO::writeData( timestep, data, comm );
|
||||
|
||||
}
|
||||
|
||||
} // Limit scope
|
||||
|
||||
// shutdown
|
||||
PROFILE_STOP("Main");
|
||||
PROFILE_SAVE("convertData",true);
|
||||
comm.barrier();
|
||||
Utilities::shutdown();
|
||||
return 0;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user