18#ifndef LIBMESH_EXODUSII_IO_HELPER_H
19#define LIBMESH_EXODUSII_IO_HELPER_H
21#include "libmesh/libmesh_config.h"
23#ifdef LIBMESH_HAVE_EXODUS_API
26#include "libmesh/parallel_object.h"
27#include "libmesh/point.h"
28#include "libmesh/boundary_info.h"
29#include "libmesh/enum_elem_type.h"
30#include "libmesh/exodus_header_info.h"
39#define EX_CHECK_ERR(code, msg) \
42 libmesh_error_msg((msg)); \
45#define EX_EXCEPTIONLESS_CHECK_ERR(code, msg) \
48 libMesh::err << (msg) << std::endl; \
49 libmesh_exceptionless_error(); \
86 bool run_only_on_proc0=
true,
87 bool single_precision=
false);
132 void open(
const char * filename,
bool read_only);
287 void close() noexcept;
343 const
std::vector<
int> & num_map);
348 int exodus_mapped_id);
355 virtual
void create(
std::
string filename);
382 bool use_discontinuous=false);
426 const
std::vector<
std::
string> & var_names,
436 std::vector<
std::
string> & var_names,
459 const
std::vector<
std::
string> & var_names,
468 std::vector<
std::
string> & var_names,
487 const
std::vector<
std::
string> & var_names,
496 std::vector<
std::
string> & var_names,
523 const
std::vector<
Real> & values,
543 const
std::vector<
Real> & values,
546 const
std::vector<
std::
string> & derived_var_names,
626 bool write_complex_abs) const;
635 bool write_complex_abs) const;
647 bool write_complex_abs) const;
1078 bool single_precision_in);
1103 bool single_precision_in);
1126 std::vector<std::string> & result);
1140 const std::vector<std::string> & names);
1335 NamesData(
size_t n_strings,
size_t string_length);
The BoundaryInfo class contains information relevant to boundary conditions including storing faces,...
The DofObject defines an abstract base class for objects that have degrees of freedom associated with...
This is the base class from which all geometric element types are derived.
int get_inverse_side_map(int i) const
static const int invalid_id
An invalid_id that can be returned to signal failure in case something goes wrong.
int get_shellface_map(int i) const
size_t shellface_index_offset
The shellface index offset defines the offset due to a difference between libMesh and Exodus in index...
int get_node_map(int i) const
const std::vector< int > * inverse_side_map
Pointer to the inverse side map for this element.
const std::vector< int > * inverse_shellface_map
Pointer to the inverse shellface map for this element.
std::string exodus_type
The string corresponding to the Exodus type for this element.
int dim
The element dimension; useful since we don't seem to have a cheap way to look this up from ElemType.
ElemType libmesh_type
The canonical (i.e.
int get_inverse_node_map(int i) const
const std::vector< int > * shellface_map
Pointer to the shellface map for this element.
const std::vector< int > * node_map
Pointer to the node map for this element.
const std::vector< int > * side_map
Pointer to the side map for this element.
std::string exodus_elem_type() const
int get_side_map(int i) const
const std::vector< int > * inverse_node_map
Pointer to the inverse node map for this element.
int n_nodes
The number of nodes per element; useful likewise.
int get_inverse_shellface_map(int i) const
std::size_t get_shellface_index_offset() const
ElemType libmesh_elem_type() const
This class is useful for managing anything that requires a char ** input/output in ExodusII file.
void push_back_entry(const std::string &name)
Adds another name to the current data table.
char * get_char_star(int i)
Provide access to the i'th underlying char *.
std::vector< std::vector< char > > data_table
char ** get_char_star_star()
Provide access to the underlying C data table.
std::vector< char * > data_table_pointers
This is the ExodusII_IO_Helper class.
void write_as_dimension(unsigned dim)
Sets the value of _write_as_dimension.
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 nodeset variables, if any, into the provided data structures.
void read_block_info()
Reads information for all of the blocks in the ExodusII mesh file.
void update()
Uses ex_update() to flush buffers to file.
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 elemset variables, if any, into the provided data structures.
std::vector< int > elemset_id_list
std::vector< int > exodus_node_num_to_libmesh
void write_var_names_impl(const char *var_type, int &count, const std::vector< std::string > &names)
write_var_names() dispatches to this function.
std::map< subdomain_id_type, std::vector< std::string > > get_complex_subdomain_to_var_names(const std::map< subdomain_id_type, std::vector< std::string > > &subdomain_to_var_names, bool write_complex_abs) const
Takes a map from subdomain id -> vector of active variable names as input and returns a corresponding...
void read_nodeset_info()
Reads information about all of the nodesets in the ExodusII mesh file.
unsigned int bex_num_elem_cvs
void use_mesh_dimension_instead_of_spatial_dimension(bool val)
Sets the underlying value of the boolean flag _use_mesh_dimension_instead_of_spatial_dimension.
void write_sideset_data(const MeshBase &mesh, 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)
Write sideset data for the requested timestep.
virtual void write_nodal_coordinates(const MeshBase &mesh, bool use_discontinuous=false)
Writes the nodal coordinates contained in "mesh".
ExodusHeaderInfo header_info
void read_node_num_map()
Reads the optional node_num_map from the ExodusII mesh file.
void read_time_steps()
Reads and stores the timesteps in the 'time_steps' array.
bool _add_sides
Set to true iff we want to write separate "side" elements too.
dof_id_type get_libmesh_id(int exodus_id, const std::vector< int > &num_map)
Internal implementation for the two sets of functions above.
std::vector< std::string > get_complex_names(const std::vector< std::string > &names, bool write_complex_abs) const
std::vector< std::string > nodal_var_names
std::vector< int > num_df_per_set
bool _global_vars_initialized
void read_and_store_header_info()
Reads an ExodusII mesh file header, and stores required information on this object.
unsigned _write_as_dimension
ExodusII_IO_Helper(const ExodusII_IO_Helper &)=default
Special functions.
ExodusHeaderInfo read_header() const
Reads an ExodusII mesh file header, leaving this object's internal data structures unchanged.
virtual void write_sidesets(const MeshBase &mesh)
Writes the sidesets contained in "mesh".
std::map< int, std::string > id_to_ns_names
void read_elemental_var_values(std::string elemental_var_name, int time_step, std::map< dof_id_type, Real > &elem_var_value_map)
Reads elemental values for the variable 'elemental_var_name' at the specified timestep into the 'elem...
std::vector< std::set< subdomain_id_type > > get_complex_vars_active_subdomains(const std::vector< std::set< subdomain_id_type > > &vars_active_subdomains, bool write_complex_abs) const
returns a "tripled" copy of vars_active_subdomains, which is necessary in the complex-valued case.
std::vector< int > num_elem_df_per_set
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)
Write elemset data for the requested timestep.
int get_node_set_id(int index)
Get the node set id for the given node set index.
std::map< dof_id_type, Real > nodal_var_values
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)
Write nodeset data for the requested timestep.
virtual void initialize_element_variables(std::vector< std::string > names, const std::vector< std::set< subdomain_id_type > > &vars_active_subdomains)
Sets up the nodal variables.
void close() noexcept
Closes the ExodusII mesh file.
void read_qa_records()
Reads the QA records from an ExodusII file.
ExodusII_IO_Helper(ExodusII_IO_Helper &&)=default
bool _elem_vars_initialized
void write_element_values_element_major(const MeshBase &mesh, const std::vector< Real > &values, int timestep, const std::vector< std::set< subdomain_id_type > > &vars_active_subdomains, const std::vector< std::string > &derived_var_names, const std::map< subdomain_id_type, std::vector< std::string > > &subdomain_to_var_names)
Same as the function above, but assume the input 'values' vector is in element-major order,...
void read_all_nodesets()
New API that reads all nodesets simultaneously.
std::string current_filename
std::vector< Real > elem_var_values
std::vector< int > num_nodes_per_set
std::vector< std::string > sideset_var_names
void read_bex_cv_blocks()
Reads the optional bex_cv_blocks from the ExodusII mesh file.
void get_sideset_data_indices(const MeshBase &mesh, 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 set_dof_object_unique_id(MeshBase &mesh, DofObject *dof_object, int exodus_mapped_id)
dof_id_type get_libmesh_elem_id(int exodus_elem_id)
std::vector< int > ss_ids
std::vector< int > id_list
void message(std::string_view msg)
Prints the message defined in msg.
ExodusII_IO_Helper & operator=(const ExodusII_IO_Helper &)=delete
This class contains references so it can't be default copy/move-assigned.
virtual void write_nodesets(const MeshBase &mesh)
Writes the nodesets contained in "mesh".
std::string get_block_name(int index)
Get the block name for the given block index if supplied in the mesh file.
void write_nodal_values(int var_id, const std::vector< Real > &values, int timestep)
Writes the vector of values to a nodal variable.
void read_elemset_info()
Reads information about all of the elemsets in the ExodusII mesh file.
std::vector< int > side_list
std::vector< std::vector< std::vector< Real > > > bex_dense_constraint_vecs
bool _nodal_vars_initialized
void read_nodes()
Reads the nodal data (x,y,z coordinates) from the ExodusII mesh file.
std::vector< int > node_sets_dist_index
virtual void read_var_names_impl(const char *var_type, int &count, std::vector< std::string > &result)
read_var_names() dispatches to this function.
std::vector< int > num_elems_per_set
virtual ~ExodusII_IO_Helper()
const char * get_elem_type() const
static int get_exodus_version()
bool set_unique_ids_from_maps
std::vector< int > node_num_map
std::vector< int > elem_face_counts
int get_side_set_id(int index)
Get the side set id for the given side set index.
void set_max_name_length(unsigned int max_length)
Set how many characters to use in names when opening a file for writing.
void read_var_names(ExodusVarType type)
void read_sideset(int id, int offset)
Reads information about sideset id and inserts it into the global sideset array at the position offse...
int get_block_id(int index)
Get the block number for the given block index.
void write_var_names(ExodusVarType type, const std::vector< std::string > &names)
Wraps calls to exII::ex_put_var_names() and exII::ex_put_var_param().
dof_id_type added_node_offset_on(processor_id_type p) const
void read_elemset(int id, int offset)
Reads information about elemset id and inserts it into the global elemset array at the position offse...
dof_id_type get_libmesh_node_id(int exodus_node_id)
Helper function that takes a (1-based) Exodus node/elem id and determines the corresponding libMesh N...
std::vector< std::vector< int > > c0polyhedron_face_connect
void write_timestep(int timestep, Real time)
Writes the time for the timestep.
void init_element_equivalence_map()
std::vector< int > exodus_elem_num_to_libmesh
std::string get_node_set_name(int index)
Get the node set name for the given node set index if supplied in the mesh file.
std::vector< std::string > global_var_names
void print_nodes(std::ostream &out_stream=libMesh::out)
Prints the nodal information, by default to libMesh::out.
std::vector< int > elemset_ids
std::vector< int > elem_node_counts
std::map< int, std::string > id_to_edge_block_names
void read_sideset_info()
Reads information about all of the sidesets in the ExodusII mesh file.
void conditionally_set_elem_unique_id(MeshBase &mesh, Elem *elem, int zero_based_elem_num_map_index)
std::vector< int > elem_list
virtual void create(std::string filename)
Opens an ExodusII mesh file named filename for writing.
std::map< std::string, ElemType > element_equivalence_map
Defines equivalence classes of Exodus element types that map to libmesh ElemTypes.
std::vector< int > num_sides_per_set
std::vector< std::string > elem_var_names
void print_header()
Prints the ExodusII mesh file header, which includes the mesh title, the number of nodes,...
std::map< dof_id_type, dof_id_type > libmesh_elem_num_to_exodus
dof_id_type node_id_to_vec_id(dof_id_type n) const
void read_global_values(std::vector< Real > &values, int timestep)
Reads the vector of global variables.
void read_edge_blocks(MeshBase &mesh)
Read in edge blocks, storing information in the BoundaryInfo object.
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,...
void open(const char *filename, bool read_only)
Opens an ExodusII mesh file named filename.
virtual void write_elements(const MeshBase &mesh, bool use_discontinuous=false)
Writes the elements contained in "mesh".
std::vector< std::string > elemset_var_names
ExodusVarType
Wraps calls to exII::ex_get_var_names() and exII::ex_get_var_param().
int num_elem_all_elemsets
std::map< dof_id_type, dof_id_type > libmesh_node_num_to_exodus
std::vector< Real > time_steps
void init_conversion_map()
std::vector< dof_id_type > _true_node_offsets
If we're adding "fake" sides to visualize SIDE_DISCONTINUOUS variables, we also need to know how many...
unsigned int _max_name_length
std::map< int, std::map< ElemType, ExodusII_IO_Helper::Conversion > > conversion_map
Associates libMesh ElemTypes with node/face/edge/etc.
std::vector< int > block_ids
void initialize_global_variables(std::vector< std::string > names)
Sets up the global variables.
std::vector< int > connect
std::vector< int > edge_block_ids
void read_sideset_data(const MeshBase &mesh, 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)
Read sideset variables, if any, into the provided data structures.
void check_existing_vars(ExodusVarType type, std::vector< std::string > &names, std::vector< std::string > &names_from_file)
When appending: during initialization, check that variable names in the file match those you attempt ...
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< int > nodeset_ids
void set_coordinate_offset(Point p)
Allows you to set a vector that is added to the coordinates of all of the nodes.
void write_information_records(const std::vector< std::string > &records)
Writes the vector of information records.
std::vector< char > & title
int num_elem_all_sidesets
bool _use_mesh_dimension_instead_of_spatial_dimension
std::map< int, std::string > id_to_ss_names
std::vector< int > node_sets_node_index
void read_elem_num_map()
Reads the optional node_num_map from the ExodusII mesh file.
void read_face_blocks()
Reads NSIDED face blocks used by NFACED element blocks.
void read_num_time_steps()
Reads the number of timesteps currently stored in the Exodus file and stores it in the num_time_steps...
std::vector< int > node_sets_node_list
const ExodusII_IO_Helper::Conversion & get_conversion(const ElemType type) const
void initialize_nodal_variables(std::vector< std::string > names)
Sets up the nodal variables.
void write_global_values(const std::vector< Real > &values, int timestep)
Writes the vector of global variables.
std::vector< int > elemset_list
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 elemset per variable,...
std::string get_side_set_name(int index)
Get the side set name for the given side set index if supplied in the mesh file.
std::vector< std::string > nodeset_var_names
void conditionally_set_node_unique_id(MeshBase &mesh, Node *node, int zero_based_node_num_map_index)
Helper function that conditionally sets the unique_id of the passed-in Node/Elem.
std::vector< int > num_node_df_per_set
void read_nodal_var_values(std::string nodal_var_name, int time_step)
Reads the nodal values for the variable 'nodal_var_name' at the specified time into the 'nodal_var_va...
std::vector< std::vector< long unsigned int > > bex_cv_conn
virtual void initialize(std::string title, const MeshBase &mesh, bool use_discontinuous=false)
Initializes the Exodus file.
void set_add_sides(bool add_sides)
Sets whether or not to write extra "side" elements.
std::map< int, std::string > id_to_block_names
std::map< int, std::string > id_to_elemset_names
std::vector< Real > node_sets_dist_fact
void write_elemsets(const MeshBase &mesh)
Write elemsets stored on the Mesh to the exo file.
void write_element_values(const MeshBase &mesh, const std::vector< Real > &values, int timestep, const std::vector< std::set< subdomain_id_type > > &vars_active_subdomains)
Writes the vector of values to the element variables.
void read_elem_in_block(int block)
Reads all of the element connectivity for block block in the ExodusII mesh file.
std::vector< dof_id_type > _added_side_node_offsets
If we're adding "fake" sides to visualize SIDE_DISCONTINUOUS variables, _added_side_node_offsets[p] g...
std::vector< int > elem_num_map
std::vector< char > elem_type
This is the MeshBase class.
A Node is like a Point, but with more information.
An object whose state is distributed along a set of processors.
A Point defines a location in LIBMESH_DIM dimensional Real space.
The libMesh namespace provides an interface to certain functionality in the library.
ElemType
Defines an enum for geometric element types.
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
uint8_t processor_id_type
This class facilitates inline conversion of an input data vector to a different precision level,...
const std::vector< Real > & our_data
std::vector< float > float_vec
~MappedOutputVector()=default
std::vector< double > double_vec