2018-06-11 15:19:05 -04:00
|
|
|
/*
|
|
|
|
|
Copyright 2013--2018 James E. McClure, Virginia Polytechnic & State University
|
|
|
|
|
|
|
|
|
|
This file is part of the Open Porous Media project (OPM).
|
|
|
|
|
OPM is free software: you can redistribute it and/or modify
|
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
|
(at your option) any later version.
|
|
|
|
|
OPM is distributed in the hope that it will be useful,
|
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
|
along with OPM. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
*/
|
2014-09-09 14:42:13 -04:00
|
|
|
#ifndef MESH_INC
|
|
|
|
|
#define MESH_INC
|
|
|
|
|
|
|
|
|
|
#include <iostream>
|
2019-03-18 09:42:44 -04:00
|
|
|
#include <memory>
|
2014-09-09 14:42:13 -04:00
|
|
|
#include <string.h>
|
|
|
|
|
#include <vector>
|
|
|
|
|
|
2021-03-17 10:24:14 -04:00
|
|
|
#include "analysis/PointList.h"
|
2015-06-11 15:01:24 -04:00
|
|
|
#include "common/Array.h"
|
|
|
|
|
#include "common/Communication.h"
|
2014-09-09 14:42:13 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
namespace IO {
|
|
|
|
|
|
|
|
|
|
|
2021-03-18 09:41:39 -04:00
|
|
|
//! Enums to define types
|
|
|
|
|
enum class VariableType {
|
|
|
|
|
NodeVariable,
|
|
|
|
|
EdgeVariable,
|
|
|
|
|
SurfaceVariable,
|
|
|
|
|
VolumeVariable,
|
|
|
|
|
NullVariable
|
2021-03-17 10:24:14 -04:00
|
|
|
};
|
2021-03-18 09:41:39 -04:00
|
|
|
enum class DataType { Double, Float, Int, Null };
|
|
|
|
|
enum class MeshType { PointMesh, SurfaceMesh, VolumeMesh, Unknown };
|
2021-06-02 15:36:44 -04:00
|
|
|
enum class FileFormat { OLD, NEW, NEW_SINGLE, SILO, HDF5 };
|
2021-03-18 09:41:39 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
//! 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 & );
|
2014-11-06 14:23:57 -05:00
|
|
|
|
|
|
|
|
|
2014-09-09 14:42:13 -04:00
|
|
|
/*! \class Mesh
|
|
|
|
|
\brief A base class for meshes
|
|
|
|
|
*/
|
|
|
|
|
class Mesh
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
//! Destructor
|
|
|
|
|
virtual ~Mesh();
|
2014-11-04 21:58:20 -05:00
|
|
|
//! Mesh class name (eg. PointList)
|
|
|
|
|
virtual std::string className() const = 0;
|
2014-11-06 14:23:57 -05:00
|
|
|
//! Number of points for the given variable type
|
|
|
|
|
virtual size_t numberPointsVar( VariableType type ) const = 0;
|
2014-11-04 21:58:20 -05:00
|
|
|
//! Pack the data
|
2021-03-17 10:24:14 -04:00
|
|
|
virtual std::pair<size_t, void *> pack( int level ) const = 0;
|
2014-11-04 21:58:20 -05:00
|
|
|
//! Unpack the data
|
2021-03-17 10:24:14 -04:00
|
|
|
virtual void unpack( const std::pair<size_t, void *> &data ) = 0;
|
|
|
|
|
|
2014-09-09 14:42:13 -04:00
|
|
|
protected:
|
|
|
|
|
//! Empty constructor
|
|
|
|
|
Mesh();
|
2021-03-17 10:24:14 -04:00
|
|
|
Mesh( const Mesh & );
|
|
|
|
|
Mesh &operator=( const Mesh & );
|
2014-09-09 14:42:13 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*! \class PointList
|
|
|
|
|
\brief A class used to hold a list of verticies
|
|
|
|
|
*/
|
2021-03-17 10:24:14 -04:00
|
|
|
class PointList : public Mesh
|
2014-09-09 14:42:13 -04:00
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
//! Empty constructor
|
|
|
|
|
PointList();
|
|
|
|
|
//! Constructor for N points
|
|
|
|
|
PointList( size_t N );
|
|
|
|
|
//! Destructor
|
|
|
|
|
virtual ~PointList();
|
2014-11-04 21:58:20 -05:00
|
|
|
//! Mesh class name
|
|
|
|
|
virtual std::string className() const { return "PointList"; }
|
2014-11-06 14:23:57 -05:00
|
|
|
//! Number of points for the given variable type
|
|
|
|
|
virtual size_t numberPointsVar( VariableType type ) const;
|
2014-11-04 21:58:20 -05:00
|
|
|
//! Pack the data
|
2021-03-17 10:24:14 -04:00
|
|
|
virtual std::pair<size_t, void *> pack( int level ) const;
|
2014-11-04 21:58:20 -05:00
|
|
|
//! Unpack the data
|
2021-03-17 10:24:14 -04:00
|
|
|
virtual void unpack( const std::pair<size_t, void *> &data );
|
2017-01-31 08:22:29 -05:00
|
|
|
//! Access the points
|
2021-03-17 10:24:14 -04:00
|
|
|
const std::vector<Point> &getPoints() const { return points; }
|
|
|
|
|
|
2014-09-09 14:42:13 -04:00
|
|
|
public:
|
2021-03-17 10:24:14 -04:00
|
|
|
std::vector<Point> points; //!< List of points vertex
|
2014-09-09 14:42:13 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
2015-02-04 09:55:22 -05:00
|
|
|
/*! \class TriList
|
|
|
|
|
\brief A class used to hold a list of triangles specified by their vertex coordinates
|
2014-09-09 14:42:13 -04:00
|
|
|
*/
|
2015-02-04 09:55:22 -05:00
|
|
|
class TriMesh;
|
2021-03-17 10:24:14 -04:00
|
|
|
class TriList : public Mesh
|
2014-09-09 14:42:13 -04:00
|
|
|
{
|
|
|
|
|
public:
|
2015-02-04 09:55:22 -05:00
|
|
|
//! Empty constructor
|
|
|
|
|
TriList();
|
|
|
|
|
//! Constructor for N triangles
|
|
|
|
|
TriList( size_t N_tri );
|
|
|
|
|
//! Constructor from TriMesh
|
2021-03-17 10:24:14 -04:00
|
|
|
TriList( const TriMesh & );
|
2014-09-09 14:42:13 -04:00
|
|
|
//! Destructor
|
2015-02-04 09:55:22 -05:00
|
|
|
virtual ~TriList();
|
2014-11-04 21:58:20 -05:00
|
|
|
//! Mesh class name
|
2015-02-04 09:55:22 -05:00
|
|
|
virtual std::string className() const { return "TriList"; }
|
2014-11-06 14:23:57 -05:00
|
|
|
//! Number of points for the given variable type
|
|
|
|
|
virtual size_t numberPointsVar( VariableType type ) const;
|
2014-11-04 21:58:20 -05:00
|
|
|
//! Pack the data
|
2021-03-17 10:24:14 -04:00
|
|
|
virtual std::pair<size_t, void *> pack( int level ) const;
|
2014-11-04 21:58:20 -05:00
|
|
|
//! Unpack the data
|
2021-03-17 10:24:14 -04:00
|
|
|
virtual void unpack( const std::pair<size_t, void *> &data );
|
|
|
|
|
|
2014-09-09 14:42:13 -04:00
|
|
|
public:
|
2021-03-17 10:24:14 -04:00
|
|
|
std::vector<Point> A; //!< First vertex
|
|
|
|
|
std::vector<Point> B; //!< Second vertex
|
|
|
|
|
std::vector<Point> C; //!< Third vertex
|
2014-09-09 14:42:13 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
2015-02-04 09:55:22 -05:00
|
|
|
/*! \class TriMesh
|
2021-03-17 10:24:14 -04:00
|
|
|
\brief A class used to hold a list of trianges specified by their vertex number and list of
|
|
|
|
|
coordiantes
|
2014-09-09 14:42:13 -04:00
|
|
|
*/
|
2021-03-17 10:24:14 -04:00
|
|
|
class TriMesh : public Mesh
|
2014-09-09 14:42:13 -04:00
|
|
|
{
|
|
|
|
|
public:
|
2015-02-04 09:55:22 -05:00
|
|
|
//! TriMesh constructor
|
|
|
|
|
TriMesh();
|
|
|
|
|
//! Constructor for Nt triangles and Np points
|
|
|
|
|
TriMesh( size_t N_tri, size_t N_point );
|
|
|
|
|
//! Constructor for Nt triangles and the given points
|
2015-04-22 14:23:55 -04:00
|
|
|
TriMesh( size_t N_tri, std::shared_ptr<PointList> points );
|
2015-02-04 09:55:22 -05:00
|
|
|
//! Constructor from TriList
|
2021-03-17 10:24:14 -04:00
|
|
|
TriMesh( const TriList & );
|
2014-09-09 14:42:13 -04:00
|
|
|
//! Destructor
|
2015-02-04 09:55:22 -05:00
|
|
|
virtual ~TriMesh();
|
2014-11-04 21:58:20 -05:00
|
|
|
//! Mesh class name
|
2015-02-04 09:55:22 -05:00
|
|
|
virtual std::string className() const { return "TriMesh"; }
|
2014-11-06 14:23:57 -05:00
|
|
|
//! Number of points for the given variable type
|
|
|
|
|
virtual size_t numberPointsVar( VariableType type ) const;
|
2014-11-04 21:58:20 -05:00
|
|
|
//! Pack the data
|
2021-03-17 10:24:14 -04:00
|
|
|
virtual std::pair<size_t, void *> pack( int level ) const;
|
2014-11-04 21:58:20 -05:00
|
|
|
//! Unpack the data
|
2021-03-17 10:24:14 -04:00
|
|
|
virtual void unpack( const std::pair<size_t, void *> &data );
|
|
|
|
|
|
2014-09-09 14:42:13 -04:00
|
|
|
public:
|
2021-03-17 10:24:14 -04:00
|
|
|
std::shared_ptr<PointList> vertices; //!< List of verticies
|
|
|
|
|
std::vector<int> A; //!< First vertex
|
|
|
|
|
std::vector<int> B; //!< Second vertex
|
|
|
|
|
std::vector<int> C; //!< Third vertex
|
2014-09-09 14:42:13 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
2015-06-11 15:01:24 -04:00
|
|
|
/*! \class Domain
|
|
|
|
|
\brief A class used to hold the domain
|
|
|
|
|
*/
|
2021-03-17 10:24:14 -04:00
|
|
|
class DomainMesh : public Mesh
|
2015-06-11 15:01:24 -04:00
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
//! Empty constructor
|
|
|
|
|
DomainMesh();
|
|
|
|
|
//! Default constructor
|
|
|
|
|
DomainMesh( RankInfoStruct rank_data, int nx, int ny, int nz, double Lx, double Ly, double Lz );
|
|
|
|
|
//! Destructor
|
|
|
|
|
virtual ~DomainMesh();
|
|
|
|
|
//! Mesh class name
|
|
|
|
|
virtual std::string className() const { return "DomainMesh"; }
|
|
|
|
|
//! Number of points for the given variable type
|
|
|
|
|
virtual size_t numberPointsVar( VariableType type ) const;
|
|
|
|
|
//! Pack the data
|
2021-03-17 10:24:14 -04:00
|
|
|
virtual std::pair<size_t, void *> pack( int level ) const;
|
2015-06-11 15:01:24 -04:00
|
|
|
//! Unpack the data
|
2021-03-17 10:24:14 -04:00
|
|
|
virtual void unpack( const std::pair<size_t, void *> &data );
|
|
|
|
|
|
2015-06-11 15:01:24 -04:00
|
|
|
public:
|
|
|
|
|
int nprocx, nprocy, nprocz, rank;
|
|
|
|
|
int nx, ny, nz;
|
|
|
|
|
double Lx, Ly, Lz;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
2014-11-04 21:58:20 -05:00
|
|
|
/*! \class Variable
|
2015-06-11 15:01:24 -04:00
|
|
|
\brief A base class for variables
|
2014-11-04 21:58:20 -05:00
|
|
|
*/
|
2021-03-17 10:24:14 -04:00
|
|
|
struct Variable {
|
2014-11-04 21:58:20 -05:00
|
|
|
public:
|
2014-11-05 16:54:18 -05:00
|
|
|
// Internal variables
|
2021-03-17 10:24:14 -04:00
|
|
|
unsigned char dim; //!< Number of points per grid point (1: scalar, 3: vector, ...)
|
|
|
|
|
VariableType type; //!< Variable type
|
|
|
|
|
DataType precision; //!< Variable precision to use for IO
|
|
|
|
|
std::string name; //!< Variable name
|
|
|
|
|
Array<double> data; //!< Variable data
|
2014-11-04 21:58:20 -05:00
|
|
|
//! Empty constructor
|
2021-03-17 10:24:14 -04:00
|
|
|
Variable() : dim( 0 ), type( VariableType::NullVariable ), precision( DataType::Double ) {}
|
2017-01-31 08:22:29 -05:00
|
|
|
//! Constructor
|
2021-03-17 10:24:14 -04:00
|
|
|
Variable( int dim_, IO::VariableType type_, const std::string &name_ )
|
|
|
|
|
: dim( dim_ ), type( type_ ), precision( DataType::Double ), name( name_ )
|
|
|
|
|
{
|
|
|
|
|
}
|
2017-01-31 08:22:29 -05:00
|
|
|
//! Constructor
|
2021-03-17 10:24:14 -04:00
|
|
|
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_ )
|
|
|
|
|
{
|
|
|
|
|
}
|
2014-11-04 21:58:20 -05:00
|
|
|
//! Destructor
|
|
|
|
|
virtual ~Variable() {}
|
2021-03-17 10:24:14 -04:00
|
|
|
|
2014-11-04 21:58:20 -05:00
|
|
|
protected:
|
|
|
|
|
//! Empty constructor
|
2021-03-17 10:24:14 -04:00
|
|
|
Variable( const Variable & );
|
|
|
|
|
Variable &operator=( const Variable & );
|
2014-11-04 21:58:20 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
2014-09-09 14:42:13 -04:00
|
|
|
/*! \class MeshDataStruct
|
|
|
|
|
\brief A class used to hold database info for saving a mesh
|
|
|
|
|
*/
|
|
|
|
|
struct MeshDataStruct {
|
2017-03-01 15:48:17 -05:00
|
|
|
DataType precision; //!< Precision to use for IO (mesh)
|
|
|
|
|
std::string meshName; //!< Mesh name
|
|
|
|
|
std::shared_ptr<Mesh> mesh; //!< Mesh data
|
2021-03-17 10:24:14 -04:00
|
|
|
std::vector<std::shared_ptr<Variable>> vars;
|
2017-03-01 15:48:17 -05:00
|
|
|
//! Empty constructor
|
2021-03-17 10:24:14 -04:00
|
|
|
MeshDataStruct() : precision( DataType::Double ) {}
|
2017-01-31 08:22:29 -05:00
|
|
|
//! Check the data
|
2021-03-18 09:41:39 -04:00
|
|
|
bool check( bool abort = true ) const;
|
2014-09-09 14:42:13 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//! Convert the mesh to a TriMesh (will return NULL if this is invalid)
|
2015-04-22 14:23:55 -04:00
|
|
|
std::shared_ptr<PointList> getPointList( std::shared_ptr<Mesh> mesh );
|
|
|
|
|
std::shared_ptr<TriMesh> getTriMesh( std::shared_ptr<Mesh> mesh );
|
|
|
|
|
std::shared_ptr<TriList> getTriList( std::shared_ptr<Mesh> mesh );
|
|
|
|
|
std::shared_ptr<const PointList> getPointList( std::shared_ptr<const Mesh> mesh );
|
|
|
|
|
std::shared_ptr<const TriMesh> getTriMesh( std::shared_ptr<const Mesh> mesh );
|
|
|
|
|
std::shared_ptr<const TriList> getTriList( std::shared_ptr<const Mesh> mesh );
|
2014-09-09 14:42:13 -04:00
|
|
|
|
|
|
|
|
|
2021-03-17 10:24:14 -04:00
|
|
|
} // namespace IO
|
2014-09-09 14:42:13 -04:00
|
|
|
|
|
|
|
|
#endif
|