libMesh
exodusII_io.h
Go to the documentation of this file.
1 // The libMesh Finite Element Library.
2 // Copyright (C) 2002-2025 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 
52 class ExodusII_IO : public MeshInput<MeshBase>,
53  public MeshOutput<MeshBase>,
54  public ParallelObject
55 {
56 public:
57 
62  explicit
64  bool single_precision=false);
65 
70  explicit
71  ExodusII_IO (const MeshBase & mesh,
72  bool single_precision=false);
73 
82  ExodusII_IO (ExodusII_IO &&) = default;
83  ExodusII_IO (const ExodusII_IO &) = delete;
84  ExodusII_IO & operator= (const ExodusII_IO &) = delete;
85  ExodusII_IO & operator= (ExodusII_IO &&) = delete;
86  virtual ~ExodusII_IO ();
87 
92  static int get_exodus_version();
93 
101  virtual void read (const std::string & name) override;
102 
120  ExodusHeaderInfo read_header (const std::string & name);
121 
129  virtual void write (const std::string & fname) override;
130 
134  void verbose (bool set_verbosity);
135 
141  void write_complex_magnitude (bool val);
142 
153  void write_added_sides (bool val);
154 
155  virtual bool get_add_sides () override;
156 
160  const std::vector<Real> & get_time_steps();
161 
171  int get_num_time_steps();
172 
177  void copy_nodal_solution(System & system,
178  std::string system_var_name,
179  std::string exodus_var_name,
180  unsigned int timestep=1);
181 
186  void copy_elemental_solution(System & system,
187  std::string system_var_name,
188  std::string exodus_var_name,
189  unsigned int timestep=1);
190 
194  void copy_scalar_solution(System & system,
195  std::vector<std::string> system_var_names,
196  std::vector<std::string> exodus_var_names,
197  unsigned int timestep=1);
198 
210  void read_elemental_variable(std::string elemental_var_name,
211  unsigned int timestep,
212  std::map<unsigned int, Real> & unique_id_to_value_map);
213 
221  void read_global_variable(std::vector<std::string> global_var_names,
222  unsigned int timestep,
223  std::vector<Real> & global_values);
224 
228  void write_discontinuous_exodusII (const std::string & name,
229  const EquationSystems & es,
230  const std::set<std::string> * system_names=nullptr);
231 
240  void write_timestep_discontinuous (const std::string &fname,
241  const EquationSystems &es,
242  const int timestep,
243  const Real time,
244  const std::set<std::string> * system_names=nullptr);
245 
249  void write_element_data (const EquationSystems & es);
250 
272  void
274  (const EquationSystems & es,
275  const std::set<std::string> * system_names = nullptr,
276  const std::string & var_suffix = "_elem_node_");
277 
284 
288  virtual void write_nodal_data (const std::string &,
289  const std::vector<Number> &,
290  const std::vector<std::string> &) override;
291 
295  void write_nodal_data_discontinuous (const std::string &,
296  const std::vector<Number> &,
297  const std::vector<std::string> &) override;
298 
302  void write_global_data (const std::vector<Number> &,
303  const std::vector<std::string> &);
304 
308  void write_information_records (const std::vector<std::string> &);
309 
318  void write_timestep (const std::string & fname,
319  const EquationSystems & es,
320  const int timestep,
321  const Real time,
322  const std::set<std::string> * system_names=nullptr);
323 
330  virtual void write_equation_systems (const std::string & fname,
331  const EquationSystems & es,
332  const std::set<std::string> * system_names=nullptr) override;
333 
343  void write_elemsets();
344 
359  void
360  write_sideset_data (int timestep,
361  const std::vector<std::string> & var_names,
362  const std::vector<std::set<boundary_id_type>> & side_ids,
363  const std::vector<std::map<BoundaryInfo::BCTuple, Real>> & bc_vals);
364 
371  void
372  read_sideset_data (int timestep,
373  std::vector<std::string> & var_names,
374  std::vector<std::set<boundary_id_type>> & side_ids,
375  std::vector<std::map<BoundaryInfo::BCTuple, Real>> & bc_vals);
376 
388  void
389  get_sideset_data_indices (std::map<BoundaryInfo::BCTuple, unsigned int> & bc_array_indices);
390 
405  void
406  write_nodeset_data (int timestep,
407  const std::vector<std::string> & var_names,
408  const std::vector<std::set<boundary_id_type>> & node_boundary_ids,
409  const std::vector<std::map<BoundaryInfo::NodeBCTuple, Real>> & bc_vals);
410 
416  void
417  read_nodeset_data (int timestep,
418  std::vector<std::string> & var_names,
419  std::vector<std::set<boundary_id_type>> & node_boundary_ids,
420  std::vector<std::map<BoundaryInfo::NodeBCTuple, Real>> & bc_vals);
421 
433  void
434  get_nodeset_data_indices (std::map<BoundaryInfo::NodeBCTuple, unsigned int> & bc_array_indices);
435 
448  void
449  write_elemset_data (int timestep,
450  const std::vector<std::string> & var_names,
451  const std::vector<std::set<elemset_id_type>> & elemset_ids_in,
452  const std::vector<std::map<std::pair<dof_id_type, elemset_id_type>, Real>> & elemset_vals);
453 
457  void
458  read_elemset_data (int timestep,
459  std::vector<std::string> & var_names,
460  std::vector<std::set<elemset_id_type>> & elemset_ids_in,
461  std::vector<std::map<std::pair<dof_id_type, elemset_id_type>, Real>> & elemset_vals);
462 
474  void
475  get_elemset_data_indices (std::map<std::pair<dof_id_type, elemset_id_type>, unsigned int> & elemset_array_indices);
476 
482  void set_extra_integer_vars(const std::vector<std::string> & extra_integer_vars);
483 
492  void set_output_variables(const std::vector<std::string> & output_variables,
493  bool allow_empty = true);
494 
507 
517  void write_as_dimension(unsigned dim);
518 
534 
540  void append(bool val);
541 
545  const std::vector<std::string> & get_elem_var_names();
546 
550  const std::vector<std::string> & get_nodal_var_names();
551 
555  const std::vector<std::string> & get_global_var_names();
556 
570  const std::vector<int> & get_elem_num_map() const;
571 
576  const std::vector<int> & get_node_num_map() const;
577 
578 #ifdef LIBMESH_HAVE_EXODUS_API
579 
583 #endif
584 
591  void set_hdf5_writing(bool write_hdf5);
592 
602  void set_discontinuous_bex(bool disc_bex);
603 
608  void write_nodal_data_common(std::string fname,
609  const std::vector<std::string> & names,
610  bool continuous=true);
611 
612 private:
618 #ifdef LIBMESH_HAVE_EXODUS_API
619  std::unique_ptr<ExodusII_IO_Helper> exio_helper;
620 
626 
630  bool _verbose;
631 
636  bool _append;
637 #endif
638 
644  std::vector<std::string> _extra_integer_vars;
645 
650  std::vector<std::string> _output_variables;
651 
661 
672 
677  bool _disc_bex;
678 };
679 
680 
681 } // namespace libMesh
682 
683 
684 #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:2375
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:976
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:983
ExodusII_IO_Helper & get_exio_helper()
Return a reference to the ExodusII_IO_Helper object.
Definition: exodusII_io.C:2396
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:2141
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:644
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:2053
The ExodusII_IO class implements reading meshes in the ExodusII file format from Sandia National Labs...
Definition: exodusII_io.h:52
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:2157
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:2391
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:2087
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:998
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:2100
This is the MeshBase class.
Definition: mesh_base.h:75
int _timestep
Stores the current value of the timestep when calling ExodusII_IO::write_timestep().
Definition: exodusII_io.h:625
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:209
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:2111
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:2127
virtual bool get_add_sides() override
Definition: exodusII_io.C:1012
This class defines an abstract interface for Mesh input.
Definition: mesh_base.h:57
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:179
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:184
bool _verbose
should we be verbose?
Definition: exodusII_io.h:630
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:2033
bool _append
Default false.
Definition: exodusII_io.h:636
Manages consistently variables, degrees of freedom, and coefficient vectors.
Definition: system.h:96
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:1043
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:1147
const std::vector< Real > & get_time_steps()
Definition: exodusII_io.C:1020
std::vector< std::string > _output_variables
The names of the variables to be output.
Definition: exodusII_io.h:650
This is the ExodusII_IO_Helper class.
void write_information_records(const std::vector< std::string > &)
Write out information records.
Definition: exodusII_io.C:1972
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:1309
void verbose(bool set_verbosity)
Set the flag indicating if we should be verbose.
Definition: exodusII_io.C:959
void write_elemsets()
Write elemsets stored on the Mesh to file.
Definition: exodusII_io.C:2041
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:2296
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:244
bool _disc_bex
Set to true (false is the default) to generate independent nodes for every Bezier Extraction element...
Definition: exodusII_io.h:677
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:1326
void write_global_data(const std::vector< Number > &, const std::vector< std::string > &)
Write out global variables.
Definition: exodusII_io.C:1985
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:2218
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:1263
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:671
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:619
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:2381
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:193
static int get_exodus_version()
Definition: exodusII_io.C:168
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:969
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:2180
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:2017
virtual ~ExodusII_IO()
Definition: exodusII_io.C:238
const std::vector< std::string > & get_elem_var_names()
Return list of the elemental variable names.
Definition: exodusII_io.C:2369
void write_element_data(const EquationSystems &es)
Write out element solution.
Definition: exodusII_io.C:1359
ExodusHeaderInfo read_header(const std::string &name)
Read only the header information, instead of the entire mesh.
Definition: exodusII_io.C:923
bool _allow_empty_variables
Flag which controls the behavior of _output_variables: .) If true, _output_variables is allowed to re...
Definition: exodusII_io.h:660
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:1446
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:2413
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:1819
void write_added_sides(bool val)
By default, we only write out the elements physically stored in the mesh.
Definition: exodusII_io.C:1005
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:2407
const std::vector< std::string > & get_nodal_var_names()
Return list of the nodal variable names.
Definition: exodusII_io.C:2363
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:2070
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:2170
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:990