MFEM v4.7.0
Finite element discretization library
Loading...
Searching...
No Matches
mfem::ConduitDataCollection Class Reference

Data collection that uses the Conduit Mesh Blueprint specification. More...

#include <conduitdatacollection.hpp>

Inheritance diagram for mfem::ConduitDataCollection:
[legend]
Collaboration diagram for mfem::ConduitDataCollection:
[legend]

Public Member Functions

 ConduitDataCollection (const std::string &collection_name, Mesh *mesh=NULL)
 Constructor. The collection name is used when saving the data.
 
 ConduitDataCollection (MPI_Comm comm, const std::string &collection_name, Mesh *mesh=NULL)
 Construct a parallel ConduitDataCollection.
 
virtual ~ConduitDataCollection ()
 We will delete the mesh and fields if we own them.
 
void SetProtocol (const std::string &protocol)
 Set the Conduit relay i/o protocol to use.
 
virtual void Save ()
 Save the collection and a Conduit blueprint root file.
 
virtual void Load (int cycle=0)
 Load the collection based blueprint data.
 
- Public Member Functions inherited from mfem::DataCollection
 DataCollection (const std::string &collection_name, Mesh *mesh_=NULL)
 Initialize the collection with its name and Mesh.
 
virtual void RegisterField (const std::string &field_name, GridFunction *gf)
 Add a grid function to the collection.
 
virtual void DeregisterField (const std::string &field_name)
 Remove a grid function from the collection.
 
virtual void RegisterQField (const std::string &q_field_name, QuadratureFunction *qf)
 Add a QuadratureFunction to the collection.
 
virtual void DeregisterQField (const std::string &field_name)
 Remove a QuadratureFunction from the collection.
 
bool HasField (const std::string &field_name) const
 Check if a grid function is part of the collection.
 
GridFunctionGetField (const std::string &field_name)
 Get a pointer to a grid function in the collection.
 
MPI_Comm GetComm () const
 Return the associated MPI communicator or MPI_COMM_NULL.
 
ParGridFunctionGetParField (const std::string &field_name)
 Get a pointer to a parallel grid function in the collection.
 
bool HasQField (const std::string &q_field_name) const
 Check if a QuadratureFunction with the given name is in the collection.
 
QuadratureFunctionGetQField (const std::string &q_field_name)
 Get a pointer to a QuadratureFunction in the collection.
 
const FieldMapTypeGetFieldMap () const
 Get a const reference to the internal field map.
 
const QFieldMapTypeGetQFieldMap () const
 Get a const reference to the internal q-field map.
 
MeshGetMesh ()
 Get a pointer to the mesh in the collection.
 
virtual void SetMesh (Mesh *new_mesh)
 Set/change the mesh associated with the collection.
 
virtual void SetMesh (MPI_Comm comm, Mesh *new_mesh)
 Set/change the mesh associated with the collection.
 
void SetCycle (int c)
 Set time cycle (for time-dependent simulations)
 
void SetTime (real_t t)
 Set physical time (for time-dependent simulations)
 
void SetTimeStep (real_t ts)
 Set the simulation time step (for time-dependent simulations)
 
int GetCycle () const
 Get time cycle (for time-dependent simulations)
 
real_t GetTime () const
 Get physical time (for time-dependent simulations)
 
real_t GetTimeStep () const
 Get the simulation time step (for time-dependent simulations)
 
const std::string & GetCollectionName () const
 Get the name of the collection.
 
void SetOwnData (bool o)
 Set the ownership of collection data.
 
void SetPrecision (int prec)
 Set the precision (number of digits) used for the text output of doubles.
 
virtual void SetPadDigits (int digits)
 Set the number of digits used for both the cycle and the MPI rank.
 
virtual void SetPadDigitsCycle (int digits)
 Set the number of digits used for the cycle.
 
virtual void SetPadDigitsRank (int digits)
 Set the number of digits used for the MPI rank in filenames.
 
virtual void SetFormat (int fmt)
 Set the desired output mesh and data format.
 
virtual void SetCompression (bool comp)
 Set the flag for use of gz compressed files.
 
void SetPrefixPath (const std::string &prefix)
 Set the path where the DataCollection will be saved.
 
const std::string & GetPrefixPath () const
 Get the path where the DataCollection will be saved.
 
virtual void SaveMesh ()
 Save the mesh, creating the collection directory.
 
virtual void SaveField (const std::string &field_name)
 Save one field, assuming the collection directory already exists.
 
virtual void SaveQField (const std::string &q_field_name)
 Save one q-field, assuming the collection directory already exists.
 
virtual ~DataCollection ()
 Delete the mesh and fields if owned by the collection.
 
int Error () const
 Get the current error state.
 
void ResetError (int err_state=No_Error)
 Reset the error state.
 

Static Public Member Functions

static void MeshToBlueprintMesh (Mesh *m, conduit::Node &out, const std::string &coordset_name="coords", const std::string &main_topology_name="main", const std::string &boundary_topology_name="boundary", const std::string &main_adjset_name="main_adjset")
 Describes a MFEM mesh using the mesh blueprint.
 
static void GridFunctionToBlueprintField (GridFunction *gf, conduit::Node &out, const std::string &main_topology_name="main")
 Describes a MFEM grid function using the mesh blueprint.
 
static MeshBlueprintMeshToMesh (const conduit::Node &n_mesh, const std::string &main_toplogy_name="", bool zero_copy=false)
 Constructs and MFEM mesh from a Conduit Blueprint Description.
 
static GridFunctionBlueprintFieldToGridFunction (Mesh *mesh, const conduit::Node &n_field, bool zero_copy=false)
 Constructs and MFEM Grid Function from a Conduit Blueprint Description.
 

Protected Member Functions

std::string RootFileName ()
 Returns blueprint root file name for the current cycle.
 
std::string MeshFileName (int domain_id, const std::string &file_protocol="hdf5")
 Returns the mesh file name for a given domain at the current cycle.
 
std::string MeshDirectoryName ()
 Returns the mesh output directory for the current cycle.
 
std::string MeshFilePattern (const std::string &file_protocol="hdf5")
 Returns the mesh file pattern for the current cycle.
 
void SaveRootFile (int num_domains, const conduit::Node &n_mesh, const std::string &file_protocol)
 Saves root file for the current cycle.
 
void SaveMeshAndFields (int domain_id, const conduit::Node &n_mesh, const std::string &file_protocol)
 Saves all meshes and fields for the current cycle.
 
void LoadRootFile (conduit::Node &n_root_out)
 Loads contents of the root field for the current cycle into n_root_out.
 
void LoadMeshAndFields (int domain_id, const std::string &file_protocol)
 Loads all meshes and fields of a given domain id for the current cycle.
 
- Protected Member Functions inherited from mfem::DataCollection
void DeleteData ()
 Delete data owned by the DataCollection keeping field information.
 
void DeleteAll ()
 Delete data owned by the DataCollection including field information.
 
std::string GetMeshShortFileName () const
 
std::string GetMeshFileName () const
 
std::string GetFieldFileName (const std::string &field_name) const
 
void SaveOneField (const FieldMapIterator &it)
 Save one field to disk, assuming the collection directory exists.
 
void SaveOneQField (const QFieldMapIterator &it)
 Save one q-field to disk, assuming the collection directory exists.
 

Protected Attributes

std::string relay_protocol
 
- Protected Attributes inherited from mfem::DataCollection
std::string name
 Name of the collection, used as a directory name when saving.
 
std::string prefix_path
 A path where the directory with results is saved. If not empty, it has '/' at the end.
 
GFieldMap field_map
 
QFieldMap q_field_map
 
Meshmesh
 The (common) mesh for the collected fields.
 
int cycle
 Time cycle; for time-dependent simulations cycle >= 0, otherwise = -1.
 
real_t time
 Physical time (for time-dependent simulations)
 
real_t time_step
 Time step i.e. delta_t (for time-dependent simulations)
 
bool serial
 Serial or parallel run? False iff mesh is a ParMesh.
 
bool appendRankToFileName
 Append rank to any output file names.
 
int myid
 MPI rank (in parallel)
 
int num_procs
 Number of MPI ranks (in parallel)
 
MPI_Comm m_comm
 Associated MPI communicator.
 
int precision
 Precision (number of digits) used for the text output of doubles.
 
int pad_digits_cycle
 Number of digits used for the cycle and MPI rank in filenames.
 
int pad_digits_rank
 
int format
 Output mesh format: see the Format enumeration.
 
int compression
 
bool own_data
 Should the collection delete its mesh and fields.
 
int error
 Error state.
 

Additional Inherited Members

- Public Types inherited from mfem::DataCollection
enum  Format { SERIAL_FORMAT = 0 , PARALLEL_FORMAT = 1 }
 Format constants to be used with SetFormat(). More...
 
enum  { NO_ERROR = 0 , No_Error = 0 , READ_ERROR = 1 , WRITE_ERROR = 2 }
 Errors returned by Error() More...
 
typedef GFieldMap::MapType FieldMapType
 
typedef GFieldMap::iterator FieldMapIterator
 
typedef GFieldMap::const_iterator FieldMapConstIterator
 
typedef QFieldMap::MapType QFieldMapType
 
typedef QFieldMap::iterator QFieldMapIterator
 
typedef QFieldMap::const_iterator QFieldMapConstIterator
 
- Static Protected Member Functions inherited from mfem::DataCollection
static int create_directory (const std::string &dir_name, const Mesh *mesh, int myid)
 
- Static Protected Attributes inherited from mfem::DataCollection
static const int precision_default = 6
 Default value for precision.
 
static const int pad_digits_default = 6
 Default value for pad_digits_*.
 

Detailed Description

Data collection that uses the Conduit Mesh Blueprint specification.

ConduitDataCollection provides json, simple binary, and HDF5-based file formats for visualization or restart. It also provides methods that convert between MFEM Meshes and GridFunctions and Conduit Mesh Blueprint descriptions.

For more information, see:

Note
The ConduitDataCollection only wraps the mfem objects to save them and creates them on load, Conduit does not own any of the data. The SidreDataCollection provides more features, for example the SidreDataCollection allocates and will own the data backing the mfem objects in the data collection.

This class also provides public static methods that convert between MFEM Meshes and GridFunctions and Conduit Mesh Blueprint descriptions.

Those that describe MFEM data using Conduit (MFEM to Conduit Blueprint) try to zero-copy as much of data MFEM as possible. The Conduit node result will not own all of the data, however you can easily make a copy of the result node using Conduit's API when necessary.

Those that construct MFEM objects from Conduit Nodes (Conduit Blueprint to MFEM) provide a zero-copy option. Zero-copy is only possible if the blueprint data matches the data types provided by the MFEM API, for example: ints for connectivity arrays, doubles for field value arrays, allocations that match MFEM's striding options, etc. If these constraints are not met, MFEM objects that own the data are created and returned. In either case pointers to new MFEM object instances are returned, the zero-copy only applies to data backing the MFEM object instances.

Note
QuadratureFunctions (q-fields) are not supported.
AMR Meshes are not fully supported.
Warning
This class is still experimental, meaning that in future releases, it may not be backward compatible, and the output files generated by the current version may become unreadable. Data collection with Conduit I/O routines

Definition at line 69 of file conduitdatacollection.hpp.

Constructor & Destructor Documentation

◆ ConduitDataCollection() [1/2]

mfem::ConduitDataCollection::ConduitDataCollection ( const std::string & collection_name,
Mesh * mesh = NULL )

Constructor. The collection name is used when saving the data.

If mesh is NULL, then the mesh can be set later by calling either SetMesh() or Load(). The latter works only in serial.

Definition at line 38 of file conduitdatacollection.cpp.

◆ ConduitDataCollection() [2/2]

mfem::ConduitDataCollection::ConduitDataCollection ( MPI_Comm comm,
const std::string & collection_name,
Mesh * mesh = NULL )

Construct a parallel ConduitDataCollection.

Definition at line 49 of file conduitdatacollection.cpp.

◆ ~ConduitDataCollection()

mfem::ConduitDataCollection::~ConduitDataCollection ( )
virtual

We will delete the mesh and fields if we own them.

Definition at line 64 of file conduitdatacollection.cpp.

Member Function Documentation

◆ BlueprintFieldToGridFunction()

mfem::GridFunction * mfem::ConduitDataCollection::BlueprintFieldToGridFunction ( Mesh * mesh,
const conduit::Node & n_field,
bool zero_copy = false )
static

Constructs and MFEM Grid Function from a Conduit Blueprint Description.

If zero_copy == true, tries to construct a grid function that points to the data described by the conduit node. This is only possible if the data in the node matches the data types needed for the MFEM API (doubles for field values, allocated in soa or aos ordering, etc). If these constraints are not met, a grid function that owns the data is created and returned.

Definition at line 512 of file conduitdatacollection.cpp.

◆ BlueprintMeshToMesh()

mfem::Mesh * mfem::ConduitDataCollection::BlueprintMeshToMesh ( const conduit::Node & n_mesh,
const std::string & main_toplogy_name = "",
bool zero_copy = false )
static

Constructs and MFEM mesh from a Conduit Blueprint Description.

main_topology_name is used to select which topology to use, when empty ("") the first topology entry will be used.

If zero_copy == true, tries to construct a mesh that points to the data described by the conduit node. This is only possible if the data in the node matches the data types needed for the MFEM API (ints for connectivity, doubles for field values, etc). If these constraints are not met, a mesh that owns the data is created and returned.

Definition at line 166 of file conduitdatacollection.cpp.

◆ GridFunctionToBlueprintField()

void mfem::ConduitDataCollection::GridFunctionToBlueprintField ( GridFunction * gf,
conduit::Node & out,
const std::string & main_topology_name = "main" )
static

Describes a MFEM grid function using the mesh blueprint.

Sets up passed conduit::Node out to describe the given grid function using the mesh field blueprint.

Zero-copies as much data as possible.

main_toplogy_name is used to set the associated topology name. With the default setting, the resulting field is associated with the topology main.

Definition at line 903 of file conduitdatacollection.cpp.

◆ Load()

void mfem::ConduitDataCollection::Load ( int cycle = 0)
virtual

Load the collection based blueprint data.

Reimplemented from mfem::DataCollection.

Definition at line 121 of file conduitdatacollection.cpp.

◆ LoadMeshAndFields()

void mfem::ConduitDataCollection::LoadMeshAndFields ( int domain_id,
const std::string & file_protocol )
protected

Loads all meshes and fields of a given domain id for the current cycle.

Definition at line 1175 of file conduitdatacollection.cpp.

◆ LoadRootFile()

void mfem::ConduitDataCollection::LoadRootFile ( conduit::Node & n_root_out)
protected

Loads contents of the root field for the current cycle into n_root_out.

Definition at line 1084 of file conduitdatacollection.cpp.

◆ MeshDirectoryName()

std::string mfem::ConduitDataCollection::MeshDirectoryName ( )
protected

Returns the mesh output directory for the current cycle.

Definition at line 986 of file conduitdatacollection.cpp.

◆ MeshFileName()

std::string mfem::ConduitDataCollection::MeshFileName ( int domain_id,
const std::string & file_protocol = "hdf5" )
protected

Returns the mesh file name for a given domain at the current cycle.

Definition at line 969 of file conduitdatacollection.cpp.

◆ MeshFilePattern()

std::string mfem::ConduitDataCollection::MeshFilePattern ( const std::string & file_protocol = "hdf5")
protected

Returns the mesh file pattern for the current cycle.

Definition at line 997 of file conduitdatacollection.cpp.

◆ MeshToBlueprintMesh()

void mfem::ConduitDataCollection::MeshToBlueprintMesh ( Mesh * m,
conduit::Node & out,
const std::string & coordset_name = "coords",
const std::string & main_topology_name = "main",
const std::string & boundary_topology_name = "boundary",
const std::string & main_adjset_name = "main_adjset" )
static

Describes a MFEM mesh using the mesh blueprint.

Sets up passed conduit::Node to describe the given mesh using the mesh blueprint.

Zero-copies as much data as possible.

coordset_name, main_topology_name, and boundary_topology_name control the names used for the mesh blueprint entries.

With the default set of names, this method describes the mesh's coordinates with a coordinate set entry named coords. Describes the mesh with a topology entry named 'main'. If the mesh has nodes, these are described in a field entry named mesh_nodes. If the mesh has an attribute field, this is described in a field entry named mesh_attribute.

If the mesh has boundary info, this is described in a topology entry named boundary. If the boundary has an attribute field, this is described in a field entry named boundary_attribute.

Definition at line 644 of file conduitdatacollection.cpp.

◆ RootFileName()

std::string mfem::ConduitDataCollection::RootFileName ( )
protected

Returns blueprint root file name for the current cycle.

Definition at line 959 of file conduitdatacollection.cpp.

◆ Save()

void mfem::ConduitDataCollection::Save ( )
virtual

Save the collection and a Conduit blueprint root file.

Reimplemented from mfem::DataCollection.

Definition at line 70 of file conduitdatacollection.cpp.

◆ SaveMeshAndFields()

void mfem::ConduitDataCollection::SaveMeshAndFields ( int domain_id,
const conduit::Node & n_mesh,
const std::string & file_protocol )
protected

Saves all meshes and fields for the current cycle.

Definition at line 1075 of file conduitdatacollection.cpp.

◆ SaveRootFile()

void mfem::ConduitDataCollection::SaveRootFile ( int num_domains,
const conduit::Node & n_mesh,
const std::string & file_protocol )
protected

Saves root file for the current cycle.

Definition at line 1015 of file conduitdatacollection.cpp.

◆ SetProtocol()

void mfem::ConduitDataCollection::SetProtocol ( const std::string & protocol)

Set the Conduit relay i/o protocol to use.

Supported options: hdf5 (default), json, conduit_json, conduit_bin

Definition at line 155 of file conduitdatacollection.cpp.

Member Data Documentation

◆ relay_protocol

std::string mfem::ConduitDataCollection::relay_protocol
protected

Definition at line 109 of file conduitdatacollection.hpp.


The documentation for this class was generated from the following files: