libMesh
Loading...
Searching...
No Matches
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
32namespace libMesh
33{
34
35// Forward declarations
36class EquationSystems;
37class ExodusII_IO_Helper;
38class MeshBase;
39class System;
40
50class ExodusII_IO : public MeshInput<MeshBase>,
51 public MeshOutput<MeshBase>,
52 public ParallelObject
53{
54public:
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;
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
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
669private:
675#ifdef LIBMESH_HAVE_EXODUS_API
676 std::unique_ptr<ExodusII_IO_Helper> exio_helper;
677
683
688
694#endif
695
701 std::vector<std::string> _extra_integer_vars;
702
707 std::vector<std::string> _output_variables;
708
718
729
737
743};
744
745
746} // namespace libMesh
747
748
749#endif // LIBMESH_EXODUSII_IO_H
unsigned int dim
This is the EquationSystems class.
This class is used as both an external data structure for passing around Exodus file header informati...
This is the ExodusII_IO_Helper class.
The ExodusII_IO class implements reading meshes in the ExodusII file format from Sandia National Labs...
Definition exodusII_io.h:53
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.
void set_max_name_length(unsigned int max_length)
For backwards compatibility, libMesh currently truncates names in ExodusII output to the old default ...
std::unique_ptr< ExodusII_IO_Helper > exio_helper
Only attempt to instantiate an ExodusII helper class if the Exodus API is defined.
virtual void write(const std::string &fname) override
This method implements writing a mesh to a specified file.
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.
bool _set_unique_ids_from_maps
Set Elem/Node unique_ids based on the elem_num_map and node_num_map contents during reading,...
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.
virtual bool get_add_sides() override
ExodusHeaderInfo read_header(const std::string &name)
Read only the header information, instead of the entire mesh.
void append(bool val)
If true, this flag will cause the ExodusII_IO object to attempt to open an existing file for writing,...
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.
void set_coordinate_offset(Point p)
Allows you to set a vector that is added to the coordinates of all of the nodes.
ExodusII_IO(ExodusII_IO &&)=default
ExodusII_IO special functions:
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.
int _timestep
Stores the current value of the timestep when calling ExodusII_IO::write_timestep().
const std::vector< Real > & get_time_steps()
bool _verbose
should we be verbose?
bool _write_complex_abs
By default, when complex numbers are enabled, for each variable we write out three values: the real p...
const std::vector< std::string > & get_global_var_names()
Return list of the global variable names.
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,...
void verbose(bool set_verbosity)
Set the flag indicating if we should be verbose.
static int get_exodus_version()
void write_complex_magnitude(bool val)
Set the flag indicating whether the complex modulus should be written when complex numbers are enable...
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.
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...
ExodusII_IO & operator=(const ExodusII_IO &)=delete
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...
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 ...
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.
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),...
std::vector< std::string > _output_variables
The names of the variables to be output.
void write_as_dimension(unsigned dim)
Directly control the num_dim which is written to the Exodus file.
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.
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 ...
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,...
void write_information_records(const std::vector< std::string > &)
Write out information records.
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,...
ExodusII_IO(const ExodusII_IO &)=delete
const std::vector< std::string > & get_elem_var_names()
Return list of the elemental variable names.
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.
void set_unique_ids_from_maps(bool val)
If true, this flag enforces the following behaviors:
ExodusII_IO_Helper & get_exio_helper()
Return a reference to the ExodusII_IO_Helper object.
bool _disc_bex
Set to true (false is the default) to generate independent nodes for every Bezier Extraction element.
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...
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,...
void write_elemsets()
Write elemsets stored on the Mesh to file.
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.
void write_global_data(const std::vector< Number > &, const std::vector< std::string > &)
Write out global variables.
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...
bool _append
Default false.
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.
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 ...
void write_element_data(const EquationSystems &es)
Write out element solution.
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,...
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.
const std::vector< std::string > & get_nodal_var_names()
Return list of the nodal variable names.
virtual void read(const std::string &name) override
This method implements reading a mesh from a specified file.
virtual void write_nodal_data(const std::string &, const std::vector< Number > &, const std::vector< std::string > &) override
Write out a nodal solution.
bool _allow_empty_variables
Flag which controls the behavior of _output_variables: .) If true, _output_variables is allowed to re...
void write_added_sides(bool val)
By default, we only write out the elements physically stored in the mesh.
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.
void set_discontinuous_bex(bool disc_bex)
Set to true (false is the default) to generate independent nodes for every Bezier Extraction element ...
void write_nodal_data_discontinuous(const std::string &, const std::vector< Number > &, const std::vector< std::string > &) override
Write out a discontinuous nodal solution.
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.
This is the MeshBase class.
Definition mesh_base.h:81
This class defines an abstract interface for Mesh input.
Definition mesh_input.h:49
This class defines an abstract interface for Mesh output.
Definition mesh_output.h:54
An object whose state is distributed along a set of processors.
A Point defines a location in LIBMESH_DIM dimensional Real space.
Definition point.h:40
Manages consistently variables, degrees of freedom, and coefficient vectors.
Definition system.h:100
The libMesh namespace provides an interface to certain functionality in the library.
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real