libMesh
Public Member Functions | Protected Member Functions | Protected Attributes | Private Attributes | List of all members
libMesh::ExodusII_IO Class Reference

The ExodusII_IO class implements reading meshes in the ExodusII file format from Sandia National Labs. More...

#include <exodusII_io.h>

Inheritance diagram for libMesh::ExodusII_IO:
[legend]

Public Member Functions

 ExodusII_IO (MeshBase &mesh, bool single_precision=false)
 Constructor. More...
 
virtual ~ExodusII_IO ()
 Destructor. More...
 
virtual void read (const std::string &name) override
 This method implements reading a mesh from a specified file. More...
 
virtual void write (const std::string &fname) override
 This method implements writing a mesh to a specified file. More...
 
void verbose (bool set_verbosity)
 Set the flag indicating if we should be verbose. More...
 
const std::vector< Real > & get_time_steps ()
 
int get_num_time_steps ()
 
void copy_nodal_solution (System &system, std::string var_name, unsigned int timestep=1)
 Backward compatibility version of function that takes a single variable name. More...
 
void copy_nodal_solution (System &system, std::string system_var_name, std::string exodus_var_name, unsigned int timestep=1)
 If we read in a nodal solution while reading in a mesh, we can attempt to copy that nodal solution into an EquationSystems object. More...
 
void copy_elemental_solution (System &system, std::string system_var_name, std::string exodus_var_name, unsigned int timestep=1)
 If we read in a elemental solution while reading in a mesh, we can attempt to copy that elemental solution into an EquationSystems object. More...
 
void read_elemental_variable (std::string elemental_var_name, unsigned int timestep, std::map< unsigned int, Real > &unique_id_to_value_map)
 Given an elemental variable and a time step, returns a mapping from the elements (top parent) unique IDs to the value of the elemental variable at the corresponding time step index. More...
 
void read_global_variable (std::vector< std::string > global_var_names, unsigned int timestep, std::vector< Real > &global_values)
 Given a vector of global variables and a time step, returns the values of the global variable at the corresponding time step index. More...
 
void write_discontinuous_exodusII (const std::string &name, const EquationSystems &es, const std::set< std::string > *system_names=nullptr)
 Writes a exodusII file with discontinuous data. More...
 
void write_timestep_discontinuous (const std::string &fname, const EquationSystems &es, const int timestep, const Real time, const std::set< std::string > *system_names=nullptr)
 Writes a discontinuous solution at a specific timestep. More...
 
void write_element_data (const EquationSystems &es)
 Write out element solution. More...
 
virtual void write_nodal_data (const std::string &, const std::vector< Number > &, const std::vector< std::string > &) override
 Write out a nodal solution. More...
 
void write_nodal_data_discontinuous (const std::string &, const std::vector< Number > &, const std::vector< std::string > &) override
 Write out a discontinuous nodal solution. More...
 
void write_global_data (const std::vector< Number > &, const std::vector< std::string > &)
 Write out global variables. More...
 
void write_information_records (const std::vector< std::string > &)
 Write out information records. More...
 
void write_timestep (const std::string &fname, const EquationSystems &es, const int timestep, const Real time, const std::set< std::string > *system_names=nullptr)
 Writes out the solution at a specific timestep. More...
 
void set_output_variables (const std::vector< std::string > &output_variables, bool allow_empty=true)
 Sets the list of variable names to be included in the output. More...
 
void use_mesh_dimension_instead_of_spatial_dimension (bool val)
 In the general case, meshes containing 2D elements can be manifolds living in 3D space, thus by default we write all meshes with the Exodus dimension set to LIBMESH_DIM = mesh.spatial_dimension(). More...
 
void write_as_dimension (unsigned dim)
 Directly control the num_dim which is written to the Exodus file. More...
 
void set_coordinate_offset (Point p)
 Allows you to set a vector that is added to the coordinates of all of the nodes. More...
 
void append (bool val)
 If true, this flag will cause the ExodusII_IO object to attempt to open an existing file for writing, rather than creating a new file. More...
 
const std::vector< std::string > & get_elem_var_names ()
 Return list of the elemental variable names. More...
 
const std::vector< std::string > & get_nodal_var_names ()
 Return list of the nodal variable names. More...
 
ExodusII_IO_Helperget_exio_helper ()
 Return a reference to the ExodusII_IO_Helper object. More...
 
void write_nodal_data_common (std::string fname, const std::vector< std::string > &names, bool continuous=true)
 This function factors out a bunch of code which is common to the write_nodal_data() and write_nodal_data_discontinuous() functions. More...
 
virtual void write_equation_systems (const std::string &, const EquationSystems &, const std::set< std::string > *system_names=nullptr)
 This method implements writing a mesh with data to a specified file where the data is taken from the EquationSystems object. More...
 
virtual void write_discontinuous_equation_systems (const std::string &, const EquationSystems &, const std::set< std::string > *system_names=nullptr)
 This method implements writing a mesh with discontinuous data to a specified file where the data is taken from the EquationSystems object. More...
 
virtual void write_nodal_data (const std::string &, const NumericVector< Number > &, const std::vector< std::string > &)
 This method should be overridden by "parallel" output formats for writing nodal data. More...
 
unsigned int & ascii_precision ()
 Return/set the precision to use when writing ASCII files. More...
 
const Parallel::Communicatorcomm () const
 
processor_id_type n_processors () const
 
processor_id_type processor_id () const
 

Protected Member Functions

MeshBasemesh ()
 
void set_n_partitions (unsigned int n_parts)
 Sets the number of partitions in the mesh. More...
 
void skip_comment_lines (std::istream &in, const char comment_start)
 Reads input from in, skipping all the lines that start with the character comment_start. More...
 
const MeshBasemesh () const
 

Protected Attributes

std::vector< bool > elems_of_dimension
 A vector of bools describing what dimension elements have been encountered when reading a mesh. More...
 
const bool _is_parallel_format
 Flag specifying whether this format is parallel-capable. More...
 
const bool _serial_only_needed_on_proc_0
 Flag specifying whether this format can be written by only serializing the mesh to processor zero. More...
 
const Parallel::Communicator_communicator
 

Private Attributes

std::unique_ptr< ExodusII_IO_Helperexio_helper
 Only attempt to instantiate an ExodusII helper class if the Exodus API is defined. More...
 
int _timestep
 Stores the current value of the timestep when calling ExodusII_IO::write_timestep(). More...
 
bool _verbose
 should we be verbose? More...
 
bool _append
 Default false. More...
 
std::vector< std::string > _output_variables
 The names of the variables to be output. More...
 
bool _allow_empty_variables
 If true, _output_variables is allowed to remain empty. More...
 

Detailed Description

The ExodusII_IO class implements reading meshes in the ExodusII file format from Sandia National Labs.

By default, LibMesh expects ExodusII files to have a ".exd" or ".e" file extension.

Author
Benjamin Kirk
John Peterson
Date
2004 Handles reading and writing of Exodus binary files.

Definition at line 52 of file exodusII_io.h.

Constructor & Destructor Documentation

◆ ExodusII_IO()

libMesh::ExodusII_IO::ExodusII_IO ( MeshBase mesh,
bool  single_precision = false 
)
explicit

Constructor.

Takes a writable reference to a mesh object. This is the constructor required to read a mesh.

◆ ~ExodusII_IO()

virtual libMesh::ExodusII_IO::~ExodusII_IO ( )
virtual

Destructor.

Member Function Documentation

◆ append()

void libMesh::ExodusII_IO::append ( bool  val)

If true, this flag will cause the ExodusII_IO object to attempt to open an existing file for writing, rather than creating a new file.

Obviously this will only work if the file already exists.

◆ ascii_precision()

unsigned int & libMesh::MeshOutput< MeshBase >::ascii_precision ( )
inherited

Return/set the precision to use when writing ASCII files.

By default we use numeric_limits<Real>::digits10 + 2, which should be enough to write out to ASCII and get the exact same Real back when reading in.

Definition at line 244 of file mesh_output.h.

245 {
246  return _ascii_precision;
247 }
unsigned int _ascii_precision
Precision to use when writing ASCII files.
Definition: mesh_output.h:182

◆ comm()

const Parallel::Communicator& libMesh::ParallelObject::comm ( ) const
inherited

◆ copy_elemental_solution()

void libMesh::ExodusII_IO::copy_elemental_solution ( System system,
std::string  system_var_name,
std::string  exodus_var_name,
unsigned int  timestep = 1 
)

If we read in a elemental solution while reading in a mesh, we can attempt to copy that elemental solution into an EquationSystems object.

◆ copy_nodal_solution() [1/2]

void libMesh::ExodusII_IO::copy_nodal_solution ( System system,
std::string  var_name,
unsigned int  timestep = 1 
)

Backward compatibility version of function that takes a single variable name.

Deprecated:
Use the version of copy_nodal_solution() that takes two names.

◆ copy_nodal_solution() [2/2]

void libMesh::ExodusII_IO::copy_nodal_solution ( System system,
std::string  system_var_name,
std::string  exodus_var_name,
unsigned int  timestep = 1 
)

If we read in a nodal solution while reading in a mesh, we can attempt to copy that nodal solution into an EquationSystems object.

◆ get_elem_var_names()

const std::vector<std::string>& libMesh::ExodusII_IO::get_elem_var_names ( )

Return list of the elemental variable names.

◆ get_exio_helper()

ExodusII_IO_Helper& libMesh::ExodusII_IO::get_exio_helper ( )

Return a reference to the ExodusII_IO_Helper object.

◆ get_nodal_var_names()

const std::vector<std::string>& libMesh::ExodusII_IO::get_nodal_var_names ( )

Return list of the nodal variable names.

◆ get_num_time_steps()

int libMesh::ExodusII_IO::get_num_time_steps ( )
Returns
The number of timesteps currently stored in the Exodus file.

Knowing the number of time steps currently stored in the file is sometimes necessary when appending, so we can know where to start writing new data. Throws an error if the file is not currently open for reading or writing.

◆ get_time_steps()

const std::vector<Real>& libMesh::ExodusII_IO::get_time_steps ( )
Returns
An array containing the timesteps in the file.

◆ mesh() [1/2]

MeshBase & libMesh::MeshInput< MeshBase >::mesh ( )
protectedinherited
Returns
The object as a writable reference.

Definition at line 169 of file mesh_input.h.

Referenced by libMesh::XdrIO::write_parallel().

170 {
171  if (_obj == nullptr)
172  libmesh_error_msg("ERROR: _obj should not be nullptr!");
173  return *_obj;
174 }
MeshBase * _obj
A pointer to a non-const object object.
Definition: mesh_input.h:114

◆ mesh() [2/2]

const MeshBase & libMesh::MeshOutput< MeshBase >::mesh ( ) const
protectedinherited
Returns
The object as a read-only reference.

Definition at line 234 of file mesh_output.h.

235 {
236  libmesh_assert(_obj);
237  return *_obj;
238 }
const MeshBase *const _obj
A pointer to a constant object.
Definition: mesh_output.h:177

◆ n_processors()

processor_id_type libMesh::ParallelObject::n_processors ( ) const
inherited
Returns
The number of processors in the group.

Definition at line 93 of file parallel_object.h.

References libMesh::ParallelObject::_communicator, and libMesh::Parallel::Communicator::size().

Referenced by libMesh::MeshBase::partition().

94  { return cast_int<processor_id_type>(_communicator.size()); }
processor_id_type size() const
Definition: communicator.h:175
const Parallel::Communicator & _communicator

◆ processor_id()

processor_id_type libMesh::ParallelObject::processor_id ( ) const
inherited

◆ read()

virtual void libMesh::ExodusII_IO::read ( const std::string &  name)
overridevirtual

This method implements reading a mesh from a specified file.

Open the file named name and read the mesh in Sandia National Lab's ExodusII format. This is the method to use for reading in meshes generated by cubit. Works in 2D for TRIs, TRI6s, QUAD s, and QUAD9s. Works in 3D for TET4s, TET10s, HEX8s, and HEX27s.

Implements libMesh::MeshInput< MeshBase >.

◆ read_elemental_variable()

void libMesh::ExodusII_IO::read_elemental_variable ( std::string  elemental_var_name,
unsigned int  timestep,
std::map< unsigned int, Real > &  unique_id_to_value_map 
)

Given an elemental variable and a time step, returns a mapping from the elements (top parent) unique IDs to the value of the elemental variable at the corresponding time step index.

Note that this function MUST only be called before renumbering! This function is essentially a wrapper for read_elemental_var_values from the exodus helper (which is not accessible outside this class).

Parameters
elemental_var_nameName of an elemental variable
timestepThe corresponding time step index
unique_id_to_value_mapThe map to be filled

◆ read_global_variable()

void libMesh::ExodusII_IO::read_global_variable ( std::vector< std::string >  global_var_names,
unsigned int  timestep,
std::vector< Real > &  global_values 
)

Given a vector of global variables and a time step, returns the values of the global variable at the corresponding time step index.

Parameters
global_var_namesVector of names of global variables
timestepThe corresponding time step index
global_valuesThe vector to be filled

◆ set_coordinate_offset()

void libMesh::ExodusII_IO::set_coordinate_offset ( Point  p)

Allows you to set a vector that is added to the coordinates of all of the nodes.

Effectively, this "moves" the mesh to a particular position.

Deprecated:
As requested by Roy in libmesh PR #90, this function was "deprecated on arrival". There is not really a suitable replacement for it in the works, however. The same effect could be achieved by calling MeshTools::Modification::translate() twice, but that approach seems inefficient in the case of very large problems with millions of nodes. That said, this should probably become a base class API so that it works for all the different IO subclasses.

◆ set_n_partitions()

void libMesh::MeshInput< MeshBase >::set_n_partitions ( unsigned int  n_parts)
protectedinherited

Sets the number of partitions in the mesh.

Typically this gets done by the partitioner, but some parallel file formats begin "pre-partitioned".

Definition at line 91 of file mesh_input.h.

References libMesh::MeshInput< MT >::mesh().

91 { this->mesh().set_n_partitions() = n_parts; }
unsigned int & set_n_partitions()
Definition: mesh_base.h:1371

◆ set_output_variables()

void libMesh::ExodusII_IO::set_output_variables ( const std::vector< std::string > &  output_variables,
bool  allow_empty = true 
)

Sets the list of variable names to be included in the output.

This is optional. If this is never called then all variables will be present. If this is called and an empty vector is supplied no variables will be output. Setting the allow_empty = false will result in empty vectors supplied here to also be populated with all variables.

◆ skip_comment_lines()

void libMesh::MeshInput< MeshBase >::skip_comment_lines ( std::istream &  in,
const char  comment_start 
)
protectedinherited

Reads input from in, skipping all the lines that start with the character comment_start.

Definition at line 179 of file mesh_input.h.

181 {
182  char c, line[256];
183 
184  while (in.get(c), c==comment_start)
185  in.getline (line, 255);
186 
187  // put back first character of
188  // first non-comment line
189  in.putback (c);
190 }

◆ use_mesh_dimension_instead_of_spatial_dimension()

void libMesh::ExodusII_IO::use_mesh_dimension_instead_of_spatial_dimension ( bool  val)

In the general case, meshes containing 2D elements can be manifolds living in 3D space, thus by default we write all meshes with the Exodus dimension set to LIBMESH_DIM = mesh.spatial_dimension().

In certain cases, however, the user may know his 2D mesh actually lives in the z=0 plane, and therefore wants to write a truly 2D Exodus mesh. In such a case, he should call this function with val=true.

◆ verbose()

void libMesh::ExodusII_IO::verbose ( bool  set_verbosity)

Set the flag indicating if we should be verbose.

◆ write()

virtual void libMesh::ExodusII_IO::write ( const std::string &  fname)
overridevirtual

This method implements writing a mesh to a specified file.

Implements libMesh::MeshOutput< MeshBase >.

◆ write_as_dimension()

void libMesh::ExodusII_IO::write_as_dimension ( unsigned  dim)

Directly control the num_dim which is written to the Exodus file.

If non-zero, this value supersedes all other dimensions, including: 1.) MeshBase::spatial_dimension() 2.) MeshBase::mesh_dimension() 3.) Any value passed to use_mesh_dimension_instead_of_spatial_dimension() This is useful/necessary for working around a bug in Paraview which prevents the "Plot Over Line" filter from working on 1D meshes.

◆ write_discontinuous_equation_systems()

virtual void libMesh::MeshOutput< MeshBase >::write_discontinuous_equation_systems ( const std::string &  ,
const EquationSystems ,
const std::set< std::string > *  system_names = nullptr 
)
virtualinherited

This method implements writing a mesh with discontinuous data to a specified file where the data is taken from the EquationSystems object.

◆ write_discontinuous_exodusII()

void libMesh::ExodusII_IO::write_discontinuous_exodusII ( const std::string &  name,
const EquationSystems es,
const std::set< std::string > *  system_names = nullptr 
)

Writes a exodusII file with discontinuous data.

◆ write_element_data()

void libMesh::ExodusII_IO::write_element_data ( const EquationSystems es)

Write out element solution.

◆ write_equation_systems()

virtual void libMesh::MeshOutput< MeshBase >::write_equation_systems ( const std::string &  ,
const EquationSystems ,
const std::set< std::string > *  system_names = nullptr 
)
virtualinherited

This method implements writing a mesh with data to a specified file where the data is taken from the EquationSystems object.

Reimplemented in libMesh::NameBasedIO.

◆ write_global_data()

void libMesh::ExodusII_IO::write_global_data ( const std::vector< Number > &  ,
const std::vector< std::string > &   
)

Write out global variables.

◆ write_information_records()

void libMesh::ExodusII_IO::write_information_records ( const std::vector< std::string > &  )

Write out information records.

◆ write_nodal_data() [1/2]

virtual void libMesh::MeshOutput< MeshBase >::write_nodal_data ( const std::string &  ,
const NumericVector< Number > &  ,
const std::vector< std::string > &   
)
virtualinherited

This method should be overridden by "parallel" output formats for writing nodal data.

Instead of getting a localized copy of the nodal solution vector, it is passed a NumericVector of type=PARALLEL which is in node-major order i.e. (u0,v0,w0, u1,v1,w1, u2,v2,w2, u3,v3,w3, ...) and contains n_nodes*n_vars total entries. Then, it is up to the individual I/O class to extract the required solution values from this vector and write them in parallel.

If not implemented, localizes the parallel vector into a std::vector and calls the other version of this function.

Reimplemented in libMesh::Nemesis_IO.

◆ write_nodal_data() [2/2]

virtual void libMesh::ExodusII_IO::write_nodal_data ( const std::string &  ,
const std::vector< Number > &  ,
const std::vector< std::string > &   
)
overridevirtual

Write out a nodal solution.

Reimplemented from libMesh::MeshOutput< MeshBase >.

◆ write_nodal_data_common()

void libMesh::ExodusII_IO::write_nodal_data_common ( std::string  fname,
const std::vector< std::string > &  names,
bool  continuous = true 
)

This function factors out a bunch of code which is common to the write_nodal_data() and write_nodal_data_discontinuous() functions.

◆ write_nodal_data_discontinuous()

void libMesh::ExodusII_IO::write_nodal_data_discontinuous ( const std::string &  ,
const std::vector< Number > &  ,
const std::vector< std::string > &   
)
overridevirtual

Write out a discontinuous nodal solution.

Reimplemented from libMesh::MeshOutput< MeshBase >.

◆ write_timestep()

void libMesh::ExodusII_IO::write_timestep ( const std::string &  fname,
const EquationSystems es,
const int  timestep,
const Real  time,
const std::set< std::string > *  system_names = nullptr 
)

Writes out the solution at a specific timestep.

Parameters
fnameName of the file to write to
esEquationSystems object which contains the solution vector.
timestepThe timestep to write out, should be 1 indexed.
timeThe current simulation time.
system_namesOptional list of systems to write solutions for.

◆ write_timestep_discontinuous()

void libMesh::ExodusII_IO::write_timestep_discontinuous ( const std::string &  fname,
const EquationSystems es,
const int  timestep,
const Real  time,
const std::set< std::string > *  system_names = nullptr 
)

Writes a discontinuous solution at a specific timestep.

Parameters
fnameName of the file to be written
esEquationSystems object which contains the solution vector
timestepThe timestep to write out. (should be 1 indexed)
timeThe current simulation time
system_namesOptional list of systems to write solutions for.

Member Data Documentation

◆ _allow_empty_variables

bool libMesh::ExodusII_IO::_allow_empty_variables
private

If true, _output_variables is allowed to remain empty.

If false, if _output_variables is empty it will be populated with a complete list of all variables By default, calling set_output_variables() sets this flag to true, but it provides an override.

Definition at line 354 of file exodusII_io.h.

◆ _append

bool libMesh::ExodusII_IO::_append
private

Default false.

If true, files will be opened with EX_WRITE rather than created from scratch when writing.

Definition at line 340 of file exodusII_io.h.

◆ _communicator

const Parallel::Communicator& libMesh::ParallelObject::_communicator
protectedinherited

◆ _is_parallel_format

const bool libMesh::MeshOutput< MeshBase >::_is_parallel_format
protectedinherited

Flag specifying whether this format is parallel-capable.

If this is false (default) I/O is only permitted when the mesh has been serialized.

Definition at line 159 of file mesh_output.h.

◆ _output_variables

std::vector<std::string> libMesh::ExodusII_IO::_output_variables
private

The names of the variables to be output.

If this is empty then all variables are output.

Definition at line 347 of file exodusII_io.h.

◆ _serial_only_needed_on_proc_0

const bool libMesh::MeshOutput< MeshBase >::_serial_only_needed_on_proc_0
protectedinherited

Flag specifying whether this format can be written by only serializing the mesh to processor zero.

If this is false (default) the mesh will be serialized to all processors

Definition at line 168 of file mesh_output.h.

◆ _timestep

int libMesh::ExodusII_IO::_timestep
private

Stores the current value of the timestep when calling ExodusII_IO::write_timestep().

Definition at line 329 of file exodusII_io.h.

◆ _verbose

bool libMesh::ExodusII_IO::_verbose
private

should we be verbose?

Definition at line 334 of file exodusII_io.h.

◆ elems_of_dimension

std::vector<bool> libMesh::MeshInput< MeshBase >::elems_of_dimension
protectedinherited

A vector of bools describing what dimension elements have been encountered when reading a mesh.

Definition at line 97 of file mesh_input.h.

◆ exio_helper

std::unique_ptr<ExodusII_IO_Helper> libMesh::ExodusII_IO::exio_helper
private

Only attempt to instantiate an ExodusII helper class if the Exodus API is defined.

This class will have no functionality when LIBMESH_HAVE_EXODUS_API is not defined.

Definition at line 323 of file exodusII_io.h.


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