libMesh
exodusII_io.h
Go to the documentation of this file.
1 // The libMesh Finite Element Library.
2 // Copyright (C) 2002-2026 Benjamin S. Kirk, John W. Peterson, Roy H. Stogner
3 
4 // This library is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU Lesser General Public
6 // License as published by the Free Software Foundation; either
7 // version 2.1 of the License, or (at your option) any later version.
8 
9 // This library is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 // Lesser General Public License for more details.
13 
14 // You should have received a copy of the GNU Lesser General Public
15 // License along with this library; if not, write to the Free Software
16 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 
18 
19 
20 #ifndef LIBMESH_EXODUSII_IO_H
21 #define LIBMESH_EXODUSII_IO_H
22 
23 
24 // Local includes
25 #include "libmesh/libmesh_common.h"
26 #include "libmesh/mesh_input.h"
27 #include "libmesh/mesh_output.h"
28 #include "libmesh/parallel_object.h"
29 #include "libmesh/boundary_info.h" // BoundaryInfo::BCTuple
30 #include "libmesh/exodus_header_info.h"
31 
32 namespace libMesh
33 {
34 
35 // Forward declarations
36 class EquationSystems;
37 class ExodusII_IO_Helper;
38 class MeshBase;
39 class System;
40 
50 class ExodusII_IO : public MeshInput<MeshBase>,
51  public MeshOutput<MeshBase>,
52  public ParallelObject
53 {
54 public:
55 
60  explicit
62  bool single_precision=false);
63 
68  explicit
69  ExodusII_IO (const MeshBase & mesh,
70  bool single_precision=false);
71 
80  ExodusII_IO (ExodusII_IO &&) = default;
81  ExodusII_IO (const ExodusII_IO &) = delete;
82  ExodusII_IO & operator= (const ExodusII_IO &) = delete;
83  ExodusII_IO & operator= (ExodusII_IO &&) = delete;
84  virtual ~ExodusII_IO ();
85 
90  static int get_exodus_version();
91 
99  virtual void read (const std::string & name) override;
100 
118  ExodusHeaderInfo read_header (const std::string & name);
119 
127  virtual void write (const std::string & fname) override;
128 
132  void verbose (bool set_verbosity);
133 
139  void write_complex_magnitude (bool val);
140 
178  void set_unique_ids_from_maps (bool val);
179 
190  void write_added_sides (bool val);
191 
192  virtual bool get_add_sides () override;
193 
197  const std::vector<Real> & get_time_steps();
198 
208  int get_num_time_steps();
209 
219  void copy_nodal_solution(System & system,
220  std::string system_var_name,
221  std::string exodus_var_name,
222  unsigned int timestep=1);
223 
233  void copy_elemental_solution(System & system,
234  std::string system_var_name,
235  std::string exodus_var_name,
236  unsigned int timestep=1);
237 
241  void copy_scalar_solution(System & system,
242  std::vector<std::string> system_var_names,
243  std::vector<std::string> exodus_var_names,
244  unsigned int timestep=1);
245 
257  void read_elemental_variable(std::string elemental_var_name,
258  unsigned int timestep,
259  std::map<unsigned int, Real> & unique_id_to_value_map);
260 
268  void read_global_variable(std::vector<std::string> global_var_names,
269  unsigned int timestep,
270  std::vector<Real> & global_values);
271 
275  void write_discontinuous_exodusII (const std::string & name,
276  const EquationSystems & es,
277  const std::set<std::string> * system_names=nullptr);
278 
287  void write_timestep_discontinuous (const std::string &fname,
288  const EquationSystems &es,
289  const int timestep,
290  const Real time,
291  const std::set<std::string> * system_names=nullptr);
292 
296  void write_element_data (const EquationSystems & es);
297 
319  void
321  (const EquationSystems & es,
322  const std::set<std::string> * system_names = nullptr,
323  const std::string & var_suffix = "_elem_node_");
324 
331 
335  virtual void write_nodal_data (const std::string &,
336  const std::vector<Number> &,
337  const std::vector<std::string> &) override;
338 
342  void write_nodal_data_discontinuous (const std::string &,
343  const std::vector<Number> &,
344  const std::vector<std::string> &) override;
345 
349  void write_global_data (const std::vector<Number> &,
350  const std::vector<std::string> &);
351 
355  void write_information_records (const std::vector<std::string> &);
356 
365  void write_timestep (const std::string & fname,
366  const EquationSystems & es,
367  const int timestep,
368  const Real time,
369  const std::set<std::string> * system_names=nullptr);
370 
377  virtual void write_equation_systems (const std::string & fname,
378  const EquationSystems & es,
379  const std::set<std::string> * system_names=nullptr) override;
380 
390  void write_elemsets();
391 
406  void
407  write_sideset_data (int timestep,
408  const std::vector<std::string> & var_names,
409  const std::vector<std::set<boundary_id_type>> & side_ids,
410  const std::vector<std::map<BoundaryInfo::BCTuple, Real>> & bc_vals);
411 
418  void
419  read_sideset_data (int timestep,
420  std::vector<std::string> & var_names,
421  std::vector<std::set<boundary_id_type>> & side_ids,
422  std::vector<std::map<BoundaryInfo::BCTuple, Real>> & bc_vals);
423 
435  void
436  get_sideset_data_indices (std::map<BoundaryInfo::BCTuple, unsigned int> & bc_array_indices);
437 
452  void
453  write_nodeset_data (int timestep,
454  const std::vector<std::string> & var_names,
455  const std::vector<std::set<boundary_id_type>> & node_boundary_ids,
456  const std::vector<std::map<BoundaryInfo::NodeBCTuple, Real>> & bc_vals);
457 
463  void
464  read_nodeset_data (int timestep,
465  std::vector<std::string> & var_names,
466  std::vector<std::set<boundary_id_type>> & node_boundary_ids,
467  std::vector<std::map<BoundaryInfo::NodeBCTuple, Real>> & bc_vals);
468 
480  void
481  get_nodeset_data_indices (std::map<BoundaryInfo::NodeBCTuple, unsigned int> & bc_array_indices);
482 
495  void
496  write_elemset_data (int timestep,
497  const std::vector<std::string> & var_names,
498  const std::vector<std::set<elemset_id_type>> & elemset_ids_in,
499  const std::vector<std::map<std::pair<dof_id_type, elemset_id_type>, Real>> & elemset_vals);
500 
504  void
505  read_elemset_data (int timestep,
506  std::vector<std::string> & var_names,
507  std::vector<std::set<elemset_id_type>> & elemset_ids_in,
508  std::vector<std::map<std::pair<dof_id_type, elemset_id_type>, Real>> & elemset_vals);
509 
521  void
522  get_elemset_data_indices (std::map<std::pair<dof_id_type, elemset_id_type>, unsigned int> & elemset_array_indices);
523 
529  void set_extra_integer_vars(const std::vector<std::string> & extra_integer_vars);
530 
539  void set_output_variables(const std::vector<std::string> & output_variables,
540  bool allow_empty = true);
541 
554 
564  void write_as_dimension(unsigned dim);
565 
581 
587  void append(bool val);
588 
597  void set_max_name_length(unsigned int max_length);
598 
602  const std::vector<std::string> & get_elem_var_names();
603 
607  const std::vector<std::string> & get_nodal_var_names();
608 
612  const std::vector<std::string> & get_global_var_names();
613 
627  const std::vector<int> & get_elem_num_map() const;
628 
633  const std::vector<int> & get_node_num_map() const;
634 
635 #ifdef LIBMESH_HAVE_EXODUS_API
636 
640 #endif
641 
648  void set_hdf5_writing(bool write_hdf5);
649 
659  void set_discontinuous_bex(bool disc_bex);
660 
665  void write_nodal_data_common(std::string fname,
666  const std::vector<std::string> & names,
667  bool continuous=true);
668 
669 private:
675 #ifdef LIBMESH_HAVE_EXODUS_API
676  std::unique_ptr<ExodusII_IO_Helper> exio_helper;
677 
683 
687  bool _verbose;
688 
693  bool _append;
694 #endif
695 
701  std::vector<std::string> _extra_integer_vars;
702 
707  std::vector<std::string> _output_variables;
708 
718 
729 
737 
742  bool _disc_bex;
743 };
744 
745 
746 } // namespace libMesh
747 
748 
749 #endif // LIBMESH_EXODUSII_IO_H
std::string name(const ElemQuality q)
This function returns a string containing some name for q.
Definition: elem_quality.C:42
const std::vector< std::string > & get_global_var_names()
Return list of the global variable names.
Definition: exodusII_io.C:2392
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().
Definition: exodusII_io.C:987
This is the EquationSystems class.
void write_as_dimension(unsigned dim)
Directly control the num_dim which is written to the Exodus file.
Definition: exodusII_io.C:994
ExodusII_IO_Helper & get_exio_helper()
Return a reference to the ExodusII_IO_Helper object.
Definition: exodusII_io.C:2413
void write_elemset_data(int timestep, const std::vector< std::string > &var_names, const std::vector< std::set< elemset_id_type >> &elemset_ids_in, const std::vector< std::map< std::pair< dof_id_type, elemset_id_type >, Real >> &elemset_vals)
The Exodus format can also store values on elemsets.
Definition: exodusII_io.C:2158
This class is used as both an external data structure for passing around Exodus file header informati...
std::vector< std::string > _extra_integer_vars
An optional list of variables in the EXODUS file that are to be used to set extra integers when loadi...
Definition: exodusII_io.h:701
unsigned int dim
void write_sideset_data(int timestep, const std::vector< std::string > &var_names, const std::vector< std::set< boundary_id_type >> &side_ids, const std::vector< std::map< BoundaryInfo::BCTuple, Real >> &bc_vals)
The Exodus format can also store values on sidesets.
Definition: exodusII_io.C:2070
The ExodusII_IO class implements reading meshes in the ExodusII file format from Sandia National Labs...
Definition: exodusII_io.h:50
void set_max_name_length(unsigned int max_length)
For backwards compatibility, libMesh currently truncates names in ExodusII output to the old default ...
Definition: exodusII_io.C:2430
void read_elemset_data(int timestep, std::vector< std::string > &var_names, std::vector< std::set< elemset_id_type >> &elemset_ids_in, std::vector< std::map< std::pair< dof_id_type, elemset_id_type >, Real >> &elemset_vals)
Read all the elemset data at a particular timestep.
Definition: exodusII_io.C:2174
const std::vector< int > & get_node_num_map() const
Identical to the behavior of get_elem_num_map(), but for the node_num_map instead.
Definition: exodusII_io.C:2408
This class defines an abstract interface for Mesh output.
Definition: mesh_output.h:53
void get_sideset_data_indices(std::map< BoundaryInfo::BCTuple, unsigned int > &bc_array_indices)
Similar to read_sideset_data(), but instead of creating one std::map per sideset per variable...
Definition: exodusII_io.C:2104
The libMesh namespace provides an interface to certain functionality in the library.
ExodusII_IO(MeshBase &mesh, bool single_precision=false)
Constructor.
Definition: exodusII_io.C:122
void append(bool val)
If true, this flag will cause the ExodusII_IO object to attempt to open an existing file for writing...
Definition: exodusII_io.C:1009
void get_nodeset_data_indices(std::map< BoundaryInfo::NodeBCTuple, unsigned int > &bc_array_indices)
Similar to read_nodeset_data(), but instead of creating one std::map per nodeset per variable...
Definition: exodusII_io.C:2117
This is the MeshBase class.
Definition: mesh_base.h:80
int _timestep
Stores the current value of the timestep when calling ExodusII_IO::write_timestep().
Definition: exodusII_io.h:682
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.
Definition: exodusII_io.C:211
void write_nodeset_data(int timestep, const std::vector< std::string > &var_names, const std::vector< std::set< boundary_id_type >> &node_boundary_ids, const std::vector< std::map< BoundaryInfo::NodeBCTuple, Real >> &bc_vals)
The Exodus format can also store values on nodesets.
Definition: exodusII_io.C:2128
void read_nodeset_data(int timestep, std::vector< std::string > &var_names, std::vector< std::set< boundary_id_type >> &node_boundary_ids, std::vector< std::map< BoundaryInfo::NodeBCTuple, Real >> &bc_vals)
Read all the nodeset data at a particular timestep.
Definition: exodusII_io.C:2144
virtual bool get_add_sides() override
Definition: exodusII_io.C:1023
This class defines an abstract interface for Mesh input.
Definition: mesh_base.h:60
void set_extra_integer_vars(const std::vector< std::string > &extra_integer_vars)
Set the elemental variables in the Exodus file to be read into extra element integers.
Definition: exodusII_io.C:181
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.
Definition: exodusII_io.C:186
bool _verbose
should we be verbose?
Definition: exodusII_io.h:687
virtual void write_equation_systems(const std::string &fname, const EquationSystems &es, const std::set< std::string > *system_names=nullptr) override
Writes out the solution for no specific time or timestep.
Definition: exodusII_io.C:2050
bool _append
Default false.
Definition: exodusII_io.h:693
Manages consistently variables, degrees of freedom, and coefficient vectors.
Definition: system.h:98
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 in...
Definition: exodusII_io.C:1054
void set_unique_ids_from_maps(bool val)
If true, this flag enforces the following behaviors:
Definition: exodusII_io.C:977
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 sol...
Definition: exodusII_io.C:1161
const std::vector< Real > & get_time_steps()
Definition: exodusII_io.C:1031
std::vector< std::string > _output_variables
The names of the variables to be output.
Definition: exodusII_io.h:707
This is the ExodusII_IO_Helper class.
void write_information_records(const std::vector< std::string > &)
Write out information records.
Definition: exodusII_io.C:1989
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 ...
Definition: exodusII_io.C:1326
void verbose(bool set_verbosity)
Set the flag indicating if we should be verbose.
Definition: exodusII_io.C:962
void write_elemsets()
Write elemsets stored on the Mesh to file.
Definition: exodusII_io.C:2058
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_d...
Definition: exodusII_io.C:2313
An object whose state is distributed along a set of processors.
virtual void read(const std::string &name) override
This method implements reading a mesh from a specified file.
Definition: exodusII_io.C:246
bool _disc_bex
Set to true (false is the default) to generate independent nodes for every Bezier Extraction element...
Definition: exodusII_io.h:742
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 ...
Definition: exodusII_io.C:1343
void write_global_data(const std::vector< Number > &, const std::vector< std::string > &)
Write out global variables.
Definition: exodusII_io.C:2002
void write_nodal_data_discontinuous(const std::string &, const std::vector< Number > &, const std::vector< std::string > &) override
Write out a discontinuous nodal solution.
Definition: exodusII_io.C:2235
void copy_scalar_solution(System &system, std::vector< std::string > system_var_names, std::vector< std::string > exodus_var_names, unsigned int timestep=1)
Copy global variables into scalar variables of a System object.
Definition: exodusII_io.C:1280
bool _write_complex_abs
By default, when complex numbers are enabled, for each variable we write out three values: the real p...
Definition: exodusII_io.h:728
std::unique_ptr< ExodusII_IO_Helper > exio_helper
Only attempt to instantiate an ExodusII helper class if the Exodus API is defined.
Definition: exodusII_io.h:676
const std::vector< int > & get_elem_num_map() const
Returns a const reference to the elem_num_map, which is a vector that is created when a Mesh is read ...
Definition: exodusII_io.C:2398
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.
Definition: exodusII_io.C:195
static int get_exodus_version()
Definition: exodusII_io.C:170
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
void write_complex_magnitude(bool val)
Set the flag indicating whether the complex modulus should be written when complex numbers are enable...
Definition: exodusII_io.C:972
ExodusII_IO & operator=(const ExodusII_IO &)=delete
virtual void write(const std::string &fname) override
This method implements writing a mesh to a specified file.
Definition: exodusII_io.C:2197
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.
Definition: exodusII_io.C:2034
virtual ~ExodusII_IO()
Definition: exodusII_io.C:240
const std::vector< std::string > & get_elem_var_names()
Return list of the elemental variable names.
Definition: exodusII_io.C:2386
void write_element_data(const EquationSystems &es)
Write out element solution.
Definition: exodusII_io.C:1376
ExodusHeaderInfo read_header(const std::string &name)
Read only the header information, instead of the entire mesh.
Definition: exodusII_io.C:926
bool _allow_empty_variables
Flag which controls the behavior of _output_variables: .) If true, _output_variables is allowed to re...
Definition: exodusII_io.h:717
void write_element_data_from_discontinuous_nodal_data(const EquationSystems &es, const std::set< std::string > *system_names=nullptr, const std::string &var_suffix="_elem_node_")
Similar to the function above, but instead of only handling (CONSTANT, MONOMIAL) data, writes out a general discontinuous solution field, e.g.
Definition: exodusII_io.C:1463
void set_discontinuous_bex(bool disc_bex)
Set to true (false is the default) to generate independent nodes for every Bezier Extraction element ...
Definition: exodusII_io.C:2436
virtual void write_nodal_data(const std::string &, const std::vector< Number > &, const std::vector< std::string > &) override
Write out a nodal solution.
Definition: exodusII_io.C:1836
void write_added_sides(bool val)
By default, we only write out the elements physically stored in the mesh.
Definition: exodusII_io.C:1016
void set_hdf5_writing(bool write_hdf5)
Set to true (the default) to write files in an HDF5-based file format (when HDF5 is available)...
Definition: exodusII_io.C:2424
const std::vector< std::string > & get_nodal_var_names()
Return list of the nodal variable names.
Definition: exodusII_io.C:2380
A Point defines a location in LIBMESH_DIM dimensional Real space.
Definition: point.h:39
void read_sideset_data(int timestep, std::vector< std::string > &var_names, std::vector< std::set< boundary_id_type >> &side_ids, std::vector< std::map< BoundaryInfo::BCTuple, Real >> &bc_vals)
Similar to write_sideset_data(), this function is used to read the data at a particular timestep...
Definition: exodusII_io.C:2087
void get_elemset_data_indices(std::map< std::pair< dof_id_type, elemset_id_type >, unsigned int > &elemset_array_indices)
Similar to read_elemset_data(), but instead of creating one std::map per nodeset per variable...
Definition: exodusII_io.C:2187
bool _set_unique_ids_from_maps
Set Elem/Node unique_ids based on the elem_num_map and node_num_map contents during reading...
Definition: exodusII_io.h:736
void set_coordinate_offset(Point p)
Allows you to set a vector that is added to the coordinates of all of the nodes.
Definition: exodusII_io.C:1001