libMesh::ExodusII_IO Class Reference

Handles reading and writing of Exodus binary files. More...

#include <exodusII_io.h>

Inheritance diagram for libMesh::ExodusII_IO:

Public Member Functions

 ExodusII_IO (MeshBase &mesh, bool single_precision=false)
 
virtual ~ExodusII_IO ()
 
virtual void read (const std::string &name) override
 
virtual void write (const std::string &fname) override
 
void verbose (bool set_verbosity)
 
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)
 
void copy_nodal_solution (System &system, std::string system_var_name, std::string exodus_var_name, unsigned int timestep=1)
 
void copy_elemental_solution (System &system, std::string system_var_name, std::string exodus_var_name, unsigned int timestep=1)
 
void read_elemental_variable (std::string elemental_var_name, unsigned int timestep, std::map< unsigned int, Real > &unique_id_to_value_map)
 
void read_global_variable (std::vector< std::string > global_var_names, unsigned int timestep, std::vector< Real > &global_values)
 
void write_discontinuous_exodusII (const std::string &name, const EquationSystems &es, const std::set< std::string > *system_names=nullptr)
 
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)
 
void write_element_data (const EquationSystems &es)
 
virtual void write_nodal_data (const std::string &, const std::vector< Number > &, const std::vector< std::string > &) override
 
void write_nodal_data_discontinuous (const std::string &, const std::vector< Number > &, const std::vector< std::string > &) override
 
void write_global_data (const std::vector< Number > &, const std::vector< std::string > &)
 
void write_information_records (const std::vector< std::string > &)
 
void write_timestep (const std::string &fname, const EquationSystems &es, const int timestep, const Real time, const std::set< std::string > *system_names=nullptr)
 
void set_output_variables (const std::vector< std::string > &output_variables, bool allow_empty=true)
 
void use_mesh_dimension_instead_of_spatial_dimension (bool val)
 
void write_as_dimension (unsigned dim)
 
void set_coordinate_offset (Point p)
 
void append (bool val)
 
const std::vector< std::string > & get_elem_var_names ()
 
const std::vector< std::string > & get_nodal_var_names ()
 
ExodusII_IO_Helperget_exio_helper ()
 
void write_nodal_data_common (std::string fname, const std::vector< std::string > &names, bool continuous=true)
 
virtual void write_equation_systems (const std::string &, const EquationSystems &, const std::set< std::string > *system_names=nullptr)
 
virtual void write_discontinuous_equation_systems (const std::string &, const EquationSystems &, const std::set< std::string > *system_names=nullptr)
 
virtual void write_nodal_data (const std::string &, const NumericVector< Number > &, const std::vector< std::string > &)
 
unsigned int & ascii_precision ()
 
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)
 
void skip_comment_lines (std::istream &in, const char comment_start)
 
const MeshBasemesh () const
 

Protected Attributes

std::vector< bool > elems_of_dimension
 
const bool _is_parallel_format
 
const bool _serial_only_needed_on_proc_0
 
const Parallel::Communicator_communicator
 

Private Attributes

std::unique_ptr< ExodusII_IO_Helperexio_helper
 
int _timestep
 
bool _verbose
 
bool _append
 
std::vector< std::string > _output_variables
 
bool _allow_empty_variables
 

Detailed Description

Handles reading and writing of Exodus binary files.

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

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.

Definition at line 45 of file exodusII_io.C.

51  :
52  MeshInput<MeshBase> (mesh),
53  MeshOutput<MeshBase> (mesh,
54  /* is_parallel_format = */ false,
55  /* serial_only_needed_on_proc_0 = */ true),
57 #ifdef LIBMESH_HAVE_EXODUS_API
58  exio_helper(new ExodusII_IO_Helper(*this, false, true, single_precision)),
59  _timestep(1),
60  _verbose(false),
61  _append(false),
62 #endif
64 {
65 }
ParallelObject(const Parallel::Communicator &comm_in)
std::unique_ptr< ExodusII_IO_Helper > exio_helper
Definition: exodusII_io.h:323

◆ ~ExodusII_IO()

libMesh::ExodusII_IO::~ExodusII_IO ( )
virtual

Destructor.

Definition at line 133 of file exodusII_io.C.

References exio_helper.

134 {
135  exio_helper->close();
136 }
std::unique_ptr< ExodusII_IO_Helper > exio_helper
Definition: exodusII_io.h:323

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.

Definition at line 450 of file exodusII_io.C.

References _append.

451 {
452  _append = val;
453 }

◆ ascii_precision()

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

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.

Referenced by libMesh::TecplotIO::write_ascii(), libMesh::GMVIO::write_ascii_new_impl(), and libMesh::GMVIO::write_ascii_old_impl().

245 {
246  return _ascii_precision;
247 }

◆ comm()

const Parallel::Communicator& libMesh::ParallelObject::comm ( ) const
inlineinherited
Returns
A reference to the Parallel::Communicator object used by this mesh.

Definition at line 89 of file parallel_object.h.

References libMesh::ParallelObject::_communicator.

Referenced by libMesh::__libmesh_petsc_diff_solver_jacobian(), libMesh::__libmesh_petsc_diff_solver_monitor(), libMesh::__libmesh_petsc_diff_solver_residual(), libMesh::__libmesh_tao_equality_constraints(), libMesh::__libmesh_tao_equality_constraints_jacobian(), libMesh::__libmesh_tao_gradient(), libMesh::__libmesh_tao_hessian(), libMesh::__libmesh_tao_inequality_constraints(), libMesh::__libmesh_tao_inequality_constraints_jacobian(), libMesh::__libmesh_tao_objective(), libMesh::MeshRefinement::_coarsen_elements(), libMesh::ExactSolution::_compute_error(), libMesh::UniformRefinementEstimator::_estimate_error(), libMesh::BoundaryInfo::_find_id_maps(), libMesh::SlepcEigenSolver< T >::_petsc_shell_matrix_get_diagonal(), libMesh::PetscLinearSolver< T >::_petsc_shell_matrix_get_diagonal(), libMesh::SlepcEigenSolver< T >::_petsc_shell_matrix_mult(), libMesh::PetscLinearSolver< T >::_petsc_shell_matrix_mult(), libMesh::PetscLinearSolver< T >::_petsc_shell_matrix_mult_add(), libMesh::EquationSystems::_read_impl(), libMesh::MeshRefinement::_refine_elements(), libMesh::MeshRefinement::_smooth_flags(), libMesh::PetscDMWrapper::add_dofs_helper(), libMesh::PetscDMWrapper::add_dofs_to_section(), libMesh::ImplicitSystem::add_matrix(), libMesh::System::add_vector(), libMesh::UnstructuredMesh::all_second_order(), libMesh::MeshTools::Modification::all_tri(), libMesh::LaplaceMeshSmoother::allgather_graph(), libMesh::FEMSystem::assemble_qoi(), libMesh::MeshCommunication::assign_global_indices(), libMesh::DofMap::attach_matrix(), libMesh::MeshTools::Generation::build_extrusion(), libMesh::BoundaryInfo::build_node_list_from_side_list(), libMesh::EquationSystems::build_parallel_elemental_solution_vector(), libMesh::EquationSystems::build_parallel_solution_vector(), libMesh::PetscDMWrapper::build_section(), libMesh::PetscDMWrapper::build_sf(), libMesh::MeshBase::cache_elem_dims(), libMesh::System::calculate_norm(), libMesh::DofMap::check_dirichlet_bcid_consistency(), libMesh::PetscDMWrapper::check_section_n_dofs(), libMesh::Nemesis_IO_Helper::compute_num_global_elem_blocks(), libMesh::Nemesis_IO_Helper::compute_num_global_nodesets(), libMesh::Nemesis_IO_Helper::compute_num_global_sidesets(), libMesh::Problem_Interface::computeF(), libMesh::Problem_Interface::computeJacobian(), libMesh::Problem_Interface::computePreconditioner(), copy_elemental_solution(), libMesh::MeshTools::correct_node_proc_ids(), libMesh::MeshTools::create_bounding_box(), libMesh::MeshTools::create_nodal_bounding_box(), libMesh::MeshRefinement::create_parent_error_vector(), libMesh::MeshTools::create_processor_bounding_box(), libMesh::MeshTools::create_subdomain_bounding_box(), libMesh::MeshCommunication::delete_remote_elements(), libMesh::DofMap::distribute_dofs(), DMlibMeshFunction(), DMlibMeshJacobian(), DMlibMeshSetSystem_libMesh(), DMVariableBounds_libMesh(), libMesh::MeshRefinement::eliminate_unrefined_patches(), libMesh::EpetraVector< T >::EpetraVector(), libMesh::WeightedPatchRecoveryErrorEstimator::estimate_error(), libMesh::PatchRecoveryErrorEstimator::estimate_error(), libMesh::JumpErrorEstimator::estimate_error(), libMesh::AdjointRefinementEstimator::estimate_error(), libMesh::ExactErrorEstimator::estimate_error(), libMesh::MeshRefinement::flag_elements_by_elem_fraction(), libMesh::MeshRefinement::flag_elements_by_error_fraction(), libMesh::MeshRefinement::flag_elements_by_nelem_target(), libMesh::CondensedEigenSystem::get_eigenpair(), libMesh::DofMap::get_info(), libMesh::ImplicitSystem::get_linear_solver(), libMesh::LocationMap< T >::init(), libMesh::TimeSolver::init(), libMesh::SystemSubsetBySubdomain::init(), libMesh::PetscDMWrapper::init_and_attach_petscdm(), libMesh::EigenSystem::init_data(), libMesh::EigenSystem::init_matrices(), libMesh::OptimizationSystem::initialize_equality_constraints_storage(), libMesh::OptimizationSystem::initialize_inequality_constraints_storage(), libMesh::MeshTools::libmesh_assert_consistent_distributed(), libMesh::MeshTools::libmesh_assert_consistent_distributed_nodes(), libMesh::MeshTools::libmesh_assert_contiguous_dof_ids(), libMesh::MeshTools::libmesh_assert_parallel_consistent_new_node_procids(), libMesh::MeshTools::libmesh_assert_parallel_consistent_procids< Elem >(), libMesh::MeshTools::libmesh_assert_parallel_consistent_procids< Node >(), libMesh::MeshTools::libmesh_assert_topology_consistent_procids< Node >(), libMesh::MeshTools::libmesh_assert_valid_boundary_ids(), libMesh::MeshTools::libmesh_assert_valid_dof_ids(), libMesh::MeshTools::libmesh_assert_valid_neighbors(), libMesh::DistributedMesh::libmesh_assert_valid_parallel_flags(), libMesh::DistributedMesh::libmesh_assert_valid_parallel_object_ids(), libMesh::DistributedMesh::libmesh_assert_valid_parallel_p_levels(), libMesh::MeshTools::libmesh_assert_valid_refinement_flags(), libMesh::MeshTools::libmesh_assert_valid_unique_ids(), libMesh::libmesh_petsc_snes_fd_residual(), libMesh::libmesh_petsc_snes_jacobian(), libMesh::libmesh_petsc_snes_mffd_residual(), libMesh::libmesh_petsc_snes_postcheck(), libMesh::libmesh_petsc_snes_residual(), libMesh::libmesh_petsc_snes_residual_helper(), libMesh::MeshRefinement::limit_level_mismatch_at_edge(), libMesh::MeshRefinement::limit_level_mismatch_at_node(), libMesh::MeshRefinement::limit_overrefined_boundary(), libMesh::MeshRefinement::limit_underrefined_boundary(), libMesh::MeshRefinement::make_coarsening_compatible(), libMesh::MeshCommunication::make_elems_parallel_consistent(), libMesh::MeshRefinement::make_flags_parallel_consistent(), libMesh::MeshCommunication::make_new_node_proc_ids_parallel_consistent(), libMesh::MeshCommunication::make_new_nodes_parallel_consistent(), libMesh::MeshCommunication::make_node_ids_parallel_consistent(), libMesh::MeshCommunication::make_node_proc_ids_parallel_consistent(), libMesh::MeshCommunication::make_node_unique_ids_parallel_consistent(), libMesh::MeshCommunication::make_nodes_parallel_consistent(), libMesh::MeshCommunication::make_p_levels_parallel_consistent(), libMesh::MeshRefinement::make_refinement_compatible(), libMesh::FEMSystem::mesh_position_set(), libMesh::DistributedMesh::n_active_elem(), libMesh::MeshTools::n_active_levels(), libMesh::BoundaryInfo::n_boundary_conds(), libMesh::BoundaryInfo::n_edge_conds(), libMesh::CondensedEigenSystem::n_global_non_condensed_dofs(), libMesh::MeshTools::n_levels(), libMesh::BoundaryInfo::n_nodeset_conds(), libMesh::MeshTools::n_p_levels(), libMesh::BoundaryInfo::n_shellface_conds(), libMesh::DistributedMesh::parallel_max_elem_id(), libMesh::DistributedMesh::parallel_max_node_id(), libMesh::ReplicatedMesh::parallel_max_unique_id(), libMesh::DistributedMesh::parallel_max_unique_id(), libMesh::DistributedMesh::parallel_n_elem(), libMesh::DistributedMesh::parallel_n_nodes(), libMesh::SparsityPattern::Build::parallel_sync(), libMesh::MeshTools::paranoid_n_levels(), libMesh::petsc_auto_fieldsplit(), libMesh::System::point_gradient(), libMesh::System::point_hessian(), libMesh::System::point_value(), libMesh::MeshBase::prepare_for_use(), libMesh::Nemesis_IO::read(), libMesh::XdrIO::read(), libMesh::CheckpointIO::read_header(), libMesh::XdrIO::read_header(), libMesh::System::read_header(), libMesh::System::read_legacy_data(), libMesh::System::read_SCALAR_dofs(), libMesh::XdrIO::read_serialized_bc_names(), libMesh::XdrIO::read_serialized_bcs_helper(), libMesh::System::read_serialized_blocked_dof_objects(), libMesh::XdrIO::read_serialized_connectivity(), libMesh::XdrIO::read_serialized_nodes(), libMesh::XdrIO::read_serialized_nodesets(), libMesh::XdrIO::read_serialized_subdomain_names(), libMesh::System::read_serialized_vector(), libMesh::MeshBase::recalculate_n_partitions(), libMesh::MeshRefinement::refine_and_coarsen_elements(), libMesh::DistributedMesh::renumber_dof_objects(), libMesh::CheckpointIO::select_split_config(), libMesh::DofMap::set_nonlocal_dof_objects(), libMesh::PetscDMWrapper::set_point_range_in_section(), libMesh::PetscDiffSolver::setup_petsc_data(), libMesh::LaplaceMeshSmoother::smooth(), libMesh::split_mesh(), libMesh::MeshBase::subdomain_ids(), libMesh::BoundaryInfo::sync(), libMesh::MeshRefinement::test_level_one(), libMesh::MeshRefinement::test_unflagged(), libMesh::MeshTools::total_weight(), libMesh::MeshRefinement::uniformly_coarsen(), libMesh::NameBasedIO::write(), libMesh::XdrIO::write(), libMesh::System::write_SCALAR_dofs(), libMesh::XdrIO::write_serialized_bcs_helper(), libMesh::System::write_serialized_blocked_dof_objects(), libMesh::XdrIO::write_serialized_connectivity(), libMesh::XdrIO::write_serialized_nodes(), and libMesh::XdrIO::write_serialized_nodesets().

90  { return _communicator; }
const Parallel::Communicator & _communicator

◆ 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.

Definition at line 513 of file exodusII_io.C.

References libMesh::ParallelObject::comm(), libMesh::CONSTANT, libMesh::DofObject::dof_number(), end, exio_helper, libMesh::MeshInput< MT >::mesh(), libMesh::MONOMIAL, libMesh::DofObject::n_comp(), libMesh::System::number(), libMesh::Parallel::Communicator::rank(), libMesh::System::solution, libMesh::System::update(), libMesh::System::variable_number(), and libMesh::System::variable_type().

517 {
518  if (system.comm().rank() == 0)
519  {
520  if (!exio_helper->opened_for_reading)
521  libmesh_error_msg("ERROR, ExodusII file must be opened for reading before copying an elemental solution!");
522 
523  // Map from element ID to elemental variable value. We need to use
524  // a map here rather than a vector (e.g. elem_var_values) since the
525  // libmesh element numbering can contain "holes". This is the case
526  // if we are reading elemental var values from an adaptively refined
527  // mesh that has not been sequentially renumbered.
528  std::map<dof_id_type, Real> elem_var_value_map;
529  exio_helper->read_elemental_var_values(exodus_var_name, timestep, elem_var_value_map);
530 
531  const unsigned int var_num = system.variable_number(system_var_name);
532  if (system.variable_type(var_num) != FEType(CONSTANT, MONOMIAL))
533  libmesh_error_msg("Error! Trying to copy elemental solution into a variable that is not of CONSTANT MONOMIAL type.");
534 
535  std::map<dof_id_type, Real>::iterator
536  it = elem_var_value_map.begin(),
537  end = elem_var_value_map.end();
538 
539  for (; it!=end; ++it)
540  {
541  const Elem * elem = MeshInput<MeshBase>::mesh().query_elem_ptr(it->first);
542 
543  if (elem && elem->n_comp(system.number(), var_num) > 0)
544  {
545  dof_id_type dof_index = elem->dof_number(system.number(), var_num, 0);
546  system.solution->set (dof_index, it->second);
547  }
548  }
549  }
550 
551  system.solution->close();
552  system.update();
553 }
IterBase * end
std::unique_ptr< ExodusII_IO_Helper > exio_helper
Definition: exodusII_io.h:323
uint8_t dof_id_type
Definition: id_types.h:64

◆ 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.

Definition at line 78 of file exodusII_io.C.

81 {
82  libmesh_deprecated();
83  copy_nodal_solution(system, var_name, var_name, timestep);
84 }
void copy_nodal_solution(System &system, std::string var_name, unsigned int timestep=1)
Definition: exodusII_io.C:78

◆ 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.

Definition at line 479 of file exodusII_io.C.

References libMesh::DofObject::dof_number(), exio_helper, libMesh::MeshInput< MT >::mesh(), libMesh::DofObject::n_comp(), libMesh::System::number(), libMesh::System::solution, libMesh::System::update(), and libMesh::System::variable_number().

483 {
484  if (!exio_helper->opened_for_reading)
485  libmesh_error_msg("ERROR, ExodusII file must be opened for reading before copying a nodal solution!");
486 
487  exio_helper->read_nodal_var_values(exodus_var_name, timestep);
488 
489  const unsigned int var_num = system.variable_number(system_var_name);
490 
491  for (dof_id_type i=0,
492  n_nodal = cast_int<dof_id_type>(exio_helper->nodal_var_values.size());
493  i != n_nodal; ++i)
494  {
495  const Node * node = MeshInput<MeshBase>::mesh().query_node_ptr(i);
496 
497  if (node && node->n_comp(system.number(), var_num) > 0)
498  {
499  dof_id_type dof_index = node->dof_number(system.number(), var_num, 0);
500 
501  // If the dof_index is local to this processor, set the value
502  if ((dof_index >= system.solution->first_local_index()) && (dof_index < system.solution->last_local_index()))
503  system.solution->set (dof_index, exio_helper->nodal_var_values[i]);
504  }
505  }
506 
507  system.solution->close();
508  system.update();
509 }
std::unique_ptr< ExodusII_IO_Helper > exio_helper
Definition: exodusII_io.h:323
uint8_t dof_id_type
Definition: id_types.h:64

◆ get_elem_var_names()

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

Return list of the elemental variable names

Definition at line 1032 of file exodusII_io.C.

References libMesh::ExodusII_IO_Helper::ELEMENTAL, and exio_helper.

1033 {
1034  exio_helper->read_var_names(ExodusII_IO_Helper::ELEMENTAL);
1035  return exio_helper->elem_var_names;
1036 }
std::unique_ptr< ExodusII_IO_Helper > exio_helper
Definition: exodusII_io.h:323

◆ get_exio_helper()

ExodusII_IO_Helper & libMesh::ExodusII_IO::get_exio_helper ( )

Return a reference to the ExodusII_IO_Helper object.

Definition at line 1038 of file exodusII_io.C.

References exio_helper.

1039 {
1040  // Provide a warning when accessing the helper object
1041  // since it is a non-public API and is likely to see
1042  // future API changes
1043  libmesh_experimental();
1044 
1045  return *exio_helper;
1046 }
std::unique_ptr< ExodusII_IO_Helper > exio_helper
Definition: exodusII_io.h:323

◆ get_nodal_var_names()

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

Return list of the nodal variable names

Definition at line 1026 of file exodusII_io.C.

References exio_helper, and libMesh::ExodusII_IO_Helper::NODAL.

1027 {
1028  exio_helper->read_var_names(ExodusII_IO_Helper::NODAL);
1029  return exio_helper->nodal_var_names;
1030 }
std::unique_ptr< ExodusII_IO_Helper > exio_helper
Definition: exodusII_io.h:323

◆ 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.

Definition at line 468 of file exodusII_io.C.

References exio_helper.

469 {
470  if (!exio_helper->opened_for_reading && !exio_helper->opened_for_writing)
471  libmesh_error_msg("ERROR, ExodusII file must be opened for reading or writing before calling ExodusII_IO::get_num_time_steps()!");
472 
473  exio_helper->read_num_time_steps();
474  return exio_helper->num_time_steps;
475 }
std::unique_ptr< ExodusII_IO_Helper > exio_helper
Definition: exodusII_io.h:323

◆ get_time_steps()

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

Definition at line 457 of file exodusII_io.C.

References exio_helper.

458 {
459  if (!exio_helper->opened_for_reading)
460  libmesh_error_msg("ERROR, ExodusII file must be opened for reading before calling ExodusII_IO::get_time_steps()!");
461 
462  exio_helper->read_time_steps();
463  return exio_helper->time_steps;
464 }
std::unique_ptr< ExodusII_IO_Helper > exio_helper
Definition: exodusII_io.h:323

◆ mesh() [1/2]

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

Definition at line 169 of file mesh_input.h.

Referenced by libMesh::GMVIO::_read_one_cell(), libMesh::VTKIO::cells_to_vtk(), libMesh::TetGenIO::element_in(), libMesh::UNVIO::elements_in(), libMesh::UNVIO::elements_out(), libMesh::UNVIO::groups_in(), libMesh::TetGenIO::node_in(), libMesh::UNVIO::nodes_in(), libMesh::UNVIO::nodes_out(), libMesh::VTKIO::nodes_to_vtk(), libMesh::Nemesis_IO::prepare_to_write_nodal_data(), libMesh::Nemesis_IO::read(), read(), libMesh::GMVIO::read(), libMesh::XdrIO::read(), libMesh::CheckpointIO::read(), libMesh::VTKIO::read(), libMesh::CheckpointIO::read_bcs(), libMesh::CheckpointIO::read_connectivity(), libMesh::CheckpointIO::read_header(), libMesh::XdrIO::read_header(), libMesh::UCDIO::read_implementation(), libMesh::UNVIO::read_implementation(), libMesh::GmshIO::read_mesh(), libMesh::CheckpointIO::read_nodes(), libMesh::CheckpointIO::read_nodesets(), libMesh::CheckpointIO::read_remote_elem(), libMesh::XdrIO::read_serialized_bcs_helper(), libMesh::XdrIO::read_serialized_connectivity(), libMesh::XdrIO::read_serialized_nodes(), libMesh::XdrIO::read_serialized_nodesets(), libMesh::XdrIO::read_serialized_subdomain_names(), libMesh::OFFIO::read_stream(), libMesh::MatlabIO::read_stream(), libMesh::CheckpointIO::read_subdomain_names(), libMesh::TetGenIO::write(), libMesh::Nemesis_IO::write(), write(), libMesh::XdrIO::write(), libMesh::CheckpointIO::write(), libMesh::GMVIO::write_ascii_new_impl(), libMesh::GMVIO::write_ascii_old_impl(), libMesh::GMVIO::write_binary(), libMesh::GMVIO::write_discontinuous_gmv(), libMesh::Nemesis_IO::write_element_data(), write_element_data(), libMesh::UCDIO::write_header(), libMesh::UCDIO::write_implementation(), libMesh::UCDIO::write_interior_elems(), libMesh::GmshIO::write_mesh(), libMesh::VTKIO::write_nodal_data(), libMesh::UCDIO::write_nodal_data(), write_nodal_data(), write_nodal_data_common(), write_nodal_data_discontinuous(), libMesh::UCDIO::write_nodes(), libMesh::CheckpointIO::write_nodesets(), libMesh::XdrIO::write_parallel(), libMesh::GmshIO::write_post(), libMesh::XdrIO::write_serialized_bcs_helper(), libMesh::XdrIO::write_serialized_connectivity(), libMesh::XdrIO::write_serialized_nodes(), libMesh::XdrIO::write_serialized_nodesets(), libMesh::XdrIO::write_serialized_subdomain_names(), libMesh::UCDIO::write_soln(), and libMesh::CheckpointIO::write_subdomain_names().

170 {
171  if (_obj == nullptr)
172  libmesh_error_msg("ERROR: _obj should not be nullptr!");
173  return *_obj;
174 }

◆ mesh() [2/2]

◆ n_processors()

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

Definition at line 95 of file parallel_object.h.

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

Referenced by libMesh::BoundaryInfo::_find_id_maps(), libMesh::PetscDMWrapper::add_dofs_to_section(), libMesh::DistributedMesh::add_elem(), libMesh::DistributedMesh::add_node(), libMesh::LaplaceMeshSmoother::allgather_graph(), libMesh::FEMSystem::assembly(), libMesh::AztecLinearSolver< T >::AztecLinearSolver(), libMesh::BoundaryInfo::build_node_list_from_side_list(), libMesh::EquationSystems::build_parallel_elemental_solution_vector(), libMesh::DistributedMesh::clear(), libMesh::Nemesis_IO_Helper::compute_border_node_ids(), libMesh::Nemesis_IO_Helper::construct_nemesis_filename(), libMesh::UnstructuredMesh::create_pid_mesh(), libMesh::MeshTools::create_processor_bounding_box(), libMesh::DofMap::distribute_dofs(), libMesh::DofMap::distribute_local_dofs_node_major(), libMesh::DofMap::distribute_local_dofs_var_major(), libMesh::EnsightIO::EnsightIO(), libMesh::MeshBase::get_info(), libMesh::SystemSubsetBySubdomain::init(), libMesh::PetscDMWrapper::init_and_attach_petscdm(), libMesh::Nemesis_IO_Helper::initialize(), libMesh::DistributedMesh::insert_elem(), libMesh::MeshTools::libmesh_assert_contiguous_dof_ids(), libMesh::MeshTools::libmesh_assert_parallel_consistent_new_node_procids(), libMesh::MeshTools::libmesh_assert_parallel_consistent_procids< Elem >(), libMesh::MeshTools::libmesh_assert_parallel_consistent_procids< Node >(), libMesh::MeshTools::libmesh_assert_topology_consistent_procids< Node >(), libMesh::MeshTools::libmesh_assert_valid_boundary_ids(), libMesh::MeshTools::libmesh_assert_valid_dof_ids(), libMesh::MeshTools::libmesh_assert_valid_neighbors(), libMesh::MeshTools::libmesh_assert_valid_refinement_flags(), libMesh::DofMap::local_variable_indices(), libMesh::MeshRefinement::make_coarsening_compatible(), libMesh::MeshBase::n_active_elem_on_proc(), libMesh::MeshBase::n_elem_on_proc(), libMesh::MeshBase::n_nodes_on_proc(), libMesh::MeshBase::partition(), libMesh::PetscLinearSolver< T >::PetscLinearSolver(), libMesh::System::point_gradient(), libMesh::System::point_hessian(), libMesh::System::point_value(), libMesh::NameBasedIO::read(), libMesh::Nemesis_IO::read(), libMesh::CheckpointIO::read(), libMesh::CheckpointIO::read_connectivity(), libMesh::XdrIO::read_header(), libMesh::CheckpointIO::read_nodes(), libMesh::System::read_parallel_data(), libMesh::System::read_SCALAR_dofs(), libMesh::System::read_serialized_blocked_dof_objects(), libMesh::System::read_serialized_vector(), libMesh::DistributedMesh::renumber_dof_objects(), libMesh::DofMap::set_nonlocal_dof_objects(), libMesh::PetscDMWrapper::set_point_range_in_section(), libMesh::MeshRefinement::uniformly_coarsen(), libMesh::DistributedMesh::update_parallel_id_counts(), libMesh::GMVIO::write_binary(), libMesh::GMVIO::write_discontinuous_gmv(), libMesh::System::write_parallel_data(), libMesh::System::write_SCALAR_dofs(), libMesh::XdrIO::write_serialized_bcs_helper(), libMesh::System::write_serialized_blocked_dof_objects(), libMesh::XdrIO::write_serialized_connectivity(), libMesh::XdrIO::write_serialized_nodes(), and libMesh::XdrIO::write_serialized_nodesets().

96  { 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
inlineinherited
Returns
The rank of this processor in the group.

Definition at line 101 of file parallel_object.h.

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

Referenced by libMesh::BoundaryInfo::_find_id_maps(), libMesh::EquationSystems::_read_impl(), libMesh::PetscDMWrapper::add_dofs_to_section(), libMesh::DistributedMesh::add_elem(), libMesh::BoundaryInfo::add_elements(), libMesh::DofMap::add_neighbors_to_send_list(), libMesh::DistributedMesh::add_node(), libMesh::UnstructuredMesh::all_second_order(), libMesh::MeshTools::Modification::all_tri(), libMesh::FEMSystem::assembly(), libMesh::EquationSystems::build_discontinuous_solution_vector(), libMesh::Nemesis_IO_Helper::build_element_and_node_maps(), libMesh::InfElemBuilder::build_inf_elem(), libMesh::BoundaryInfo::build_node_list_from_side_list(), libMesh::EquationSystems::build_parallel_elemental_solution_vector(), libMesh::DistributedMesh::clear(), libMesh::ExodusII_IO_Helper::close(), libMesh::Nemesis_IO_Helper::compute_border_node_ids(), libMesh::Nemesis_IO_Helper::compute_communication_map_parameters(), libMesh::Nemesis_IO_Helper::compute_internal_and_border_elems_and_internal_nodes(), libMesh::Nemesis_IO_Helper::compute_node_communication_maps(), libMesh::Nemesis_IO_Helper::compute_num_global_elem_blocks(), libMesh::Nemesis_IO_Helper::compute_num_global_nodesets(), libMesh::Nemesis_IO_Helper::compute_num_global_sidesets(), libMesh::Nemesis_IO_Helper::construct_nemesis_filename(), libMesh::MeshTools::correct_node_proc_ids(), libMesh::ExodusII_IO_Helper::create(), libMesh::DistributedMesh::delete_elem(), libMesh::DistributedMesh::delete_node(), libMesh::MeshCommunication::delete_remote_elements(), libMesh::DofMap::distribute_dofs(), libMesh::DofMap::distribute_local_dofs_node_major(), libMesh::DofMap::distribute_local_dofs_var_major(), libMesh::DistributedMesh::DistributedMesh(), libMesh::DofMap::end_dof(), libMesh::DofMap::end_old_dof(), libMesh::EnsightIO::EnsightIO(), libMesh::MeshFunction::find_element(), libMesh::MeshFunction::find_elements(), libMesh::UnstructuredMesh::find_neighbors(), libMesh::DofMap::first_dof(), libMesh::DofMap::first_old_dof(), libMesh::Nemesis_IO_Helper::get_cmap_params(), libMesh::Nemesis_IO_Helper::get_eb_info_global(), libMesh::Nemesis_IO_Helper::get_elem_cmap(), libMesh::Nemesis_IO_Helper::get_elem_map(), libMesh::MeshBase::get_info(), libMesh::DofMap::get_info(), libMesh::Nemesis_IO_Helper::get_init_global(), libMesh::Nemesis_IO_Helper::get_init_info(), libMesh::Nemesis_IO_Helper::get_loadbal_param(), libMesh::Nemesis_IO_Helper::get_node_cmap(), libMesh::Nemesis_IO_Helper::get_node_map(), libMesh::Nemesis_IO_Helper::get_ns_param_global(), libMesh::Nemesis_IO_Helper::get_ss_param_global(), libMesh::SparsityPattern::Build::handle_vi_vj(), libMesh::SystemSubsetBySubdomain::init(), libMesh::ExodusII_IO_Helper::initialize(), libMesh::ExodusII_IO_Helper::initialize_element_variables(), libMesh::ExodusII_IO_Helper::initialize_global_variables(), libMesh::ExodusII_IO_Helper::initialize_nodal_variables(), libMesh::DistributedMesh::insert_elem(), libMesh::DofMap::is_evaluable(), libMesh::SparsityPattern::Build::join(), libMesh::DofMap::last_dof(), libMesh::MeshTools::libmesh_assert_consistent_distributed(), libMesh::MeshTools::libmesh_assert_consistent_distributed_nodes(), libMesh::MeshTools::libmesh_assert_contiguous_dof_ids(), libMesh::MeshTools::libmesh_assert_parallel_consistent_procids< Elem >(), libMesh::MeshTools::libmesh_assert_valid_neighbors(), libMesh::DistributedMesh::libmesh_assert_valid_parallel_object_ids(), libMesh::DofMap::local_variable_indices(), libMesh::MeshRefinement::make_coarsening_compatible(), libMesh::MeshBase::n_active_local_elem(), libMesh::BoundaryInfo::n_boundary_conds(), libMesh::BoundaryInfo::n_edge_conds(), libMesh::DofMap::n_local_dofs(), libMesh::System::n_local_dofs(), libMesh::MeshBase::n_local_elem(), libMesh::MeshBase::n_local_nodes(), libMesh::BoundaryInfo::n_nodeset_conds(), libMesh::BoundaryInfo::n_shellface_conds(), libMesh::SparsityPattern::Build::operator()(), libMesh::DistributedMesh::own_node(), libMesh::System::point_gradient(), libMesh::System::point_hessian(), libMesh::System::point_value(), libMesh::Nemesis_IO_Helper::put_cmap_params(), libMesh::Nemesis_IO_Helper::put_elem_cmap(), libMesh::Nemesis_IO_Helper::put_elem_map(), libMesh::Nemesis_IO_Helper::put_loadbal_param(), libMesh::Nemesis_IO_Helper::put_node_cmap(), libMesh::Nemesis_IO_Helper::put_node_map(), libMesh::NameBasedIO::read(), libMesh::Nemesis_IO::read(), libMesh::XdrIO::read(), libMesh::CheckpointIO::read(), libMesh::ExodusII_IO_Helper::read_elem_num_map(), libMesh::ExodusII_IO_Helper::read_global_values(), libMesh::CheckpointIO::read_header(), libMesh::XdrIO::read_header(), libMesh::System::read_header(), libMesh::System::read_legacy_data(), libMesh::ExodusII_IO_Helper::read_node_num_map(), libMesh::System::read_parallel_data(), libMesh::System::read_SCALAR_dofs(), libMesh::XdrIO::read_serialized_bc_names(), libMesh::XdrIO::read_serialized_bcs_helper(), libMesh::System::read_serialized_blocked_dof_objects(), libMesh::XdrIO::read_serialized_connectivity(), libMesh::System::read_serialized_data(), libMesh::XdrIO::read_serialized_nodes(), libMesh::XdrIO::read_serialized_nodesets(), libMesh::XdrIO::read_serialized_subdomain_names(), libMesh::System::read_serialized_vector(), libMesh::System::read_serialized_vectors(), libMesh::DistributedMesh::renumber_dof_objects(), libMesh::CheckpointIO::select_split_config(), libMesh::DofMap::set_nonlocal_dof_objects(), libMesh::PetscDMWrapper::set_point_range_in_section(), libMesh::LaplaceMeshSmoother::smooth(), libMesh::MeshTools::total_weight(), libMesh::MeshRefinement::uniformly_coarsen(), libMesh::Parallel::Packing< T >::unpack(), libMesh::DistributedMesh::update_parallel_id_counts(), libMesh::NameBasedIO::write(), libMesh::XdrIO::write(), libMesh::CheckpointIO::write(), libMesh::EquationSystems::write(), libMesh::GMVIO::write_discontinuous_gmv(), write_element_data(), libMesh::ExodusII_IO_Helper::write_element_values(), libMesh::ExodusII_IO_Helper::write_elements(), write_global_data(), libMesh::ExodusII_IO_Helper::write_global_values(), libMesh::System::write_header(), write_information_records(), libMesh::ExodusII_IO_Helper::write_information_records(), libMesh::ExodusII_IO_Helper::write_nodal_coordinates(), libMesh::UCDIO::write_nodal_data(), write_nodal_data(), write_nodal_data_discontinuous(), libMesh::ExodusII_IO_Helper::write_nodal_values(), libMesh::Nemesis_IO_Helper::write_nodesets(), libMesh::ExodusII_IO_Helper::write_nodesets(), libMesh::System::write_parallel_data(), libMesh::System::write_SCALAR_dofs(), libMesh::XdrIO::write_serialized_bc_names(), libMesh::XdrIO::write_serialized_bcs_helper(), libMesh::System::write_serialized_blocked_dof_objects(), libMesh::XdrIO::write_serialized_connectivity(), libMesh::System::write_serialized_data(), libMesh::XdrIO::write_serialized_nodes(), libMesh::XdrIO::write_serialized_nodesets(), libMesh::XdrIO::write_serialized_subdomain_names(), libMesh::System::write_serialized_vector(), libMesh::System::write_serialized_vectors(), libMesh::Nemesis_IO_Helper::write_sidesets(), libMesh::ExodusII_IO_Helper::write_sidesets(), write_timestep(), libMesh::ExodusII_IO_Helper::write_timestep(), and write_timestep_discontinuous().

102  { return cast_int<processor_id_type>(_communicator.rank()); }
const Parallel::Communicator & _communicator
processor_id_type rank() const
Definition: communicator.h:173

◆ read()

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 >.

Definition at line 140 of file exodusII_io.C.

References libMesh::MeshBase::add_elem(), libMesh::BoundaryInfo::add_node(), libMesh::MeshBase::add_point(), libMesh::BoundaryInfo::add_shellface(), libMesh::BoundaryInfo::add_side(), libMesh::ExodusII_IO_Helper::ElementMaps::assign_conversion(), libMesh::Elem::build(), libMesh::MeshBase::clear(), libMesh::Elem::dim(), libMesh::MeshBase::elem_ref(), libMesh::MeshInput< MeshBase >::elems_of_dimension, libMesh::Utility::enum_to_string(), exio_helper, libMesh::MeshBase::get_boundary_info(), libMesh::ExodusII_IO_Helper::Conversion::get_shellface_index_offset(), libMesh::ExodusII_IO_Helper::Conversion::get_side_map(), libMesh::DofObject::id(), libMesh::index_range(), libMesh::ExodusII_IO_Helper::Conversion::invalid_id, libMesh::MeshInput< MT >::mesh(), libMesh::MeshInput< MeshBase >::mesh(), libMesh::MeshBase::mesh_dimension(), libMesh::MeshBase::node_ptr(), libMesh::BoundaryInfo::nodeset_name(), libMesh::MeshBase::reserve_elem(), libMesh::MeshBase::reserve_nodes(), libMesh::DofObject::set_id(), libMesh::MeshBase::set_mesh_dimension(), libMesh::Elem::set_node(), libMesh::BoundaryInfo::sideset_name(), libMesh::Elem::subdomain_id(), and libMesh::MeshBase::subdomain_name().

Referenced by libMesh::NameBasedIO::read(), and libMesh::Nemesis_IO::read().

141 {
142  // Get a reference to the mesh we are reading
143  MeshBase & mesh = MeshInput<MeshBase>::mesh();
144 
145  // Clear any existing mesh data
146  mesh.clear();
147 
148  // Keep track of what kinds of elements this file contains
149  elems_of_dimension.clear();
150  elems_of_dimension.resize(4, false);
151 
152  // Instantiate the ElementMaps interface
153  ExodusII_IO_Helper::ElementMaps em;
154 
155  // Open the exodus file in EX_READ mode
156  exio_helper->open(fname.c_str(), /*read_only=*/true);
157 
158  // Get header information from exodus file
159  exio_helper->read_header();
160 
161  // Read the QA records
162  exio_helper->read_qa_records();
163 
164  // Print header information
165  exio_helper->print_header();
166 
167  // Read nodes from the exodus file
168  exio_helper->read_nodes();
169 
170  // Reserve space for the nodes.
171  mesh.reserve_nodes(exio_helper->num_nodes);
172 
173  // Read the node number map from the Exodus file. This is
174  // required if we want to preserve the numbering of nodes as it
175  // exists in the Exodus file. If the Exodus file does not contain
176  // a node_num_map, the identity map is returned by this call.
177  exio_helper->read_node_num_map();
178 
179  // Loop over the nodes, create Nodes with local processor_id 0.
180  for (int i=0; i<exio_helper->num_nodes; i++)
181  {
182  // Use the node_num_map to get the correct ID for Exodus
183  int exodus_id = exio_helper->node_num_map[i];
184 
185  // Catch the node that was added to the mesh
186  Node * added_node = mesh.add_point (Point(exio_helper->x[i], exio_helper->y[i], exio_helper->z[i]), exodus_id-1);
187 
188  // If the Mesh assigned an ID different from what is in the
189  // Exodus file, we should probably error.
190  if (added_node->id() != static_cast<unsigned>(exodus_id-1))
191  libmesh_error_msg("Error! Mesh assigned node ID " \
192  << added_node->id() \
193  << " which is different from the (zero-based) Exodus ID " \
194  << exodus_id-1 \
195  << "!");
196  }
197 
198  // This assert is no longer valid if the nodes are not numbered
199  // sequentially starting from 1 in the Exodus file.
200  // libmesh_assert_equal_to (static_cast<unsigned int>(exio_helper->num_nodes), mesh.n_nodes());
201 
202  // Get information about all the blocks
203  exio_helper->read_block_info();
204 
205  // Reserve space for the elements
206  mesh.reserve_elem(exio_helper->num_elem);
207 
208  // Read the element number map from the Exodus file. This is
209  // required if we want to preserve the numbering of elements as it
210  // exists in the Exodus file. If the Exodus file does not contain
211  // an elem_num_map, the identity map is returned by this call.
212  exio_helper->read_elem_num_map();
213 
214  // Read in the element connectivity for each block.
215  int nelem_last_block = 0;
216 
217  // Loop over all the blocks
218  for (int i=0; i<exio_helper->num_elem_blk; i++)
219  {
220  // Read the information for block i
221  exio_helper->read_elem_in_block (i);
222  int subdomain_id = exio_helper->get_block_id(i);
223 
224  // populate the map of names
225  std::string subdomain_name = exio_helper->get_block_name(i);
226  if (!subdomain_name.empty())
227  mesh.subdomain_name(static_cast<subdomain_id_type>(subdomain_id)) = subdomain_name;
228 
229  // Set any relevant node/edge maps for this element
230  const std::string type_str (exio_helper->get_elem_type());
231  const ExodusII_IO_Helper::Conversion conv = em.assign_conversion(type_str);
232 
233  // Loop over all the faces in this block
234  int jmax = nelem_last_block+exio_helper->num_elem_this_blk;
235  for (int j=nelem_last_block; j<jmax; j++)
236  {
237  Elem * elem = Elem::build (conv.get_canonical_type()).release();
238  libmesh_assert (elem);
239  elem->subdomain_id() = static_cast<subdomain_id_type>(subdomain_id) ;
240 
241  // Use the elem_num_map to obtain the ID of this element in the Exodus file
242  int exodus_id = exio_helper->elem_num_map[j];
243 
244  // Assign this element the same ID it had in the Exodus
245  // file, but make it zero-based by subtracting 1. Note:
246  // some day we could use 1-based numbering in libmesh and
247  // thus match the Exodus numbering exactly, but at the
248  // moment libmesh is zero-based.
249  elem->set_id(exodus_id-1);
250 
251  // Record that we have seen an element of dimension elem->dim()
252  elems_of_dimension[elem->dim()] = true;
253 
254  // Catch the Elem pointer that the Mesh throws back
255  elem = mesh.add_elem (elem);
256 
257  // If the Mesh assigned an ID different from what is in the
258  // Exodus file, we should probably error.
259  if (elem->id() != static_cast<unsigned>(exodus_id-1))
260  libmesh_error_msg("Error! Mesh assigned ID " \
261  << elem->id() \
262  << " which is different from the (zero-based) Exodus ID " \
263  << exodus_id-1 \
264  << "!");
265 
266  // Set all the nodes for this element
267  for (int k=0; k<exio_helper->num_nodes_per_elem; k++)
268  {
269  // global index
270  int gi = (j-nelem_last_block)*exio_helper->num_nodes_per_elem + conv.get_node_map(k);
271 
272  // The entries in 'connect' are actually (1-based)
273  // indices into the node_num_map, so to get the right
274  // node ID we:
275  // 1.) Subtract 1 from connect[gi]
276  // 2.) Pass it through node_num_map to get the corresponding Exodus ID
277  // 3.) Subtract 1 from that, since libmesh node numbering is "zero"-based,
278  // even when the Exodus node numbering doesn't start with 1.
279  int libmesh_node_id = exio_helper->node_num_map[exio_helper->connect[gi] - 1] - 1;
280 
281  // Set the node pointer in the Elem
282  elem->set_node(k) = mesh.node_ptr(libmesh_node_id);
283  }
284  }
285 
286  // running sum of # of elements per block,
287  // (should equal total number of elements in the end)
288  nelem_last_block += exio_helper->num_elem_this_blk;
289  }
290 
291  // This assert isn't valid if the Exodus file's numbering doesn't
292  // start with 1! For example, if Exodus's elem_num_map is 21, 22,
293  // 23, 24, 25, 26, 27, 28, 29, 30, ... 84, then by the time you are
294  // done with the loop above, mesh.n_elem() will report 84 and
295  // nelem_last_block will be 64.
296  // libmesh_assert_equal_to (static_cast<unsigned>(nelem_last_block), mesh.n_elem());
297 
298  // Set the mesh dimension to the largest encountered for an element
299  for (unsigned char i=0; i!=4; ++i)
300  if (elems_of_dimension[i])
302 
303  // Read in sideset information -- this is useful for applying boundary conditions
304  {
305  // Get basic information about all sidesets
306  exio_helper->read_sideset_info();
307  int offset=0;
308  for (int i=0; i<exio_helper->num_side_sets; i++)
309  {
310  // Compute new offset
311  offset += (i > 0 ? exio_helper->num_sides_per_set[i-1] : 0);
312  exio_helper->read_sideset (i, offset);
313 
314  std::string sideset_name = exio_helper->get_side_set_name(i);
315  if (!sideset_name.empty())
317  (cast_int<boundary_id_type>(exio_helper->get_side_set_id(i)))
318  = sideset_name;
319  }
320 
321  for (auto e : index_range(exio_helper->elem_list))
322  {
323  // The numbers in the Exodus file sidesets should be thought
324  // of as (1-based) indices into the elem_num_map array. So,
325  // to get the right element ID we have to:
326  // 1.) Subtract 1 from elem_list[e] (to get a zero-based index)
327  // 2.) Pass it through elem_num_map (to get the corresponding Exodus ID)
328  // 3.) Subtract 1 from that, since libmesh is "zero"-based,
329  // even when the Exodus numbering doesn't start with 1.
330  dof_id_type libmesh_elem_id =
331  cast_int<dof_id_type>(exio_helper->elem_num_map[exio_helper->elem_list[e] - 1] - 1);
332 
333  // Set any relevant node/edge maps for this element
334  Elem & elem = mesh.elem_ref(libmesh_elem_id);
335 
336  const ExodusII_IO_Helper::Conversion conv = em.assign_conversion(elem.type());
337 
338  // Map the zero-based Exodus side numbering to the libmesh side numbering
339  unsigned int raw_side_index = exio_helper->side_list[e]-1;
340  std::size_t side_index_offset = conv.get_shellface_index_offset();
341 
342  if (raw_side_index < side_index_offset)
343  {
344  // We assume this is a "shell face"
345  int mapped_shellface = raw_side_index;
346 
347  // Check for errors
348  if (mapped_shellface == ExodusII_IO_Helper::Conversion::invalid_id)
349  libmesh_error_msg("Invalid 1-based side id: " \
350  << mapped_shellface \
351  << " detected for " \
352  << Utility::enum_to_string(elem.type()));
353 
354  // Add this (elem,shellface,id) triplet to the BoundaryInfo object.
355  mesh.get_boundary_info().add_shellface (libmesh_elem_id,
356  cast_int<unsigned short>(mapped_shellface),
357  cast_int<boundary_id_type>(exio_helper->id_list[e]));
358  }
359  else
360  {
361  unsigned int side_index = static_cast<unsigned int>(raw_side_index - side_index_offset);
362  int mapped_side = conv.get_side_map(side_index);
363 
364  // Check for errors
366  libmesh_error_msg("Invalid 1-based side id: " \
367  << side_index \
368  << " detected for " \
369  << Utility::enum_to_string(elem.type()));
370 
371  // Add this (elem,side,id) triplet to the BoundaryInfo object.
372  mesh.get_boundary_info().add_side (libmesh_elem_id,
373  cast_int<unsigned short>(mapped_side),
374  cast_int<boundary_id_type>(exio_helper->id_list[e]));
375  }
376  }
377  }
378 
379  // Read nodeset info
380  {
381  exio_helper->read_nodeset_info();
382 
383  for (int nodeset=0; nodeset<exio_helper->num_node_sets; nodeset++)
384  {
385  boundary_id_type nodeset_id =
386  cast_int<boundary_id_type>(exio_helper->nodeset_ids[nodeset]);
387 
388  std::string nodeset_name = exio_helper->get_node_set_name(nodeset);
389  if (!nodeset_name.empty())
390  mesh.get_boundary_info().nodeset_name(nodeset_id) = nodeset_name;
391 
392  exio_helper->read_nodeset(nodeset);
393 
394  for (const auto & exodus_id : exio_helper->node_list)
395  {
396  // As before, the entries in 'node_list' are 1-based
397  // indices into the node_num_map array, so we have to map
398  // them. See comment above.
399  int libmesh_node_id = exio_helper->node_num_map[exodus_id - 1] - 1;
400  mesh.get_boundary_info().add_node(cast_int<dof_id_type>(libmesh_node_id),
401  nodeset_id);
402  }
403  }
404  }
405 
406 #if LIBMESH_DIM < 3
407  if (mesh.mesh_dimension() > LIBMESH_DIM)
408  libmesh_error_msg("Cannot open dimension " \
409  << mesh.mesh_dimension() \
410  << " mesh file when configured without " \
411  << mesh.mesh_dimension() \
412  << "D support.");
413 #endif
414 }
virtual void reserve_nodes(const dof_id_type nn)=0
std::string & nodeset_name(boundary_id_type id)
std::vector< bool > elems_of_dimension
Definition: mesh_input.h:97
TestClass subdomain_id_type
Definition: id_types.h:43
IntRange< std::size_t > index_range(const std::vector< T > &vec)
Definition: int_range.h:104
const BoundaryInfo & get_boundary_info() const
Definition: mesh_base.h:131
virtual Node * add_point(const Point &p, const dof_id_type id=DofObject::invalid_id, const processor_id_type proc_id=DofObject::invalid_processor_id)=0
void add_node(const Node *node, const boundary_id_type id)
int8_t boundary_id_type
Definition: id_types.h:51
virtual Elem * add_elem(Elem *e)=0
static std::unique_ptr< Elem > build(const ElemType type, Elem *p=nullptr)
Definition: elem.C:245
std::string & subdomain_name(subdomain_id_type id)
Definition: mesh_base.C:538
void set_mesh_dimension(unsigned char d)
Definition: mesh_base.h:213
virtual void clear()
Definition: mesh_base.C:260
std::string & sideset_name(boundary_id_type id)
std::string enum_to_string(const T e)
std::unique_ptr< ExodusII_IO_Helper > exio_helper
Definition: exodusII_io.h:323
void add_side(const dof_id_type elem, const unsigned short int side, const boundary_id_type id)
void add_shellface(const dof_id_type elem, const unsigned short int shellface, const boundary_id_type id)
virtual const Elem & elem_ref(const dof_id_type i) const
Definition: mesh_base.h:504
unsigned int mesh_dimension() const
Definition: mesh_base.C:126
virtual const Node * node_ptr(const dof_id_type i) const =0
virtual void reserve_elem(const dof_id_type ne)=0
uint8_t dof_id_type
Definition: id_types.h:64

◆ 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

Definition at line 555 of file exodusII_io.C.

References exio_helper, libMesh::MeshInput< MT >::mesh(), libMesh::Elem::top_parent(), and libMesh::DofObject::unique_id().

558 {
559  // Note that this function MUST be called before renumbering
560  std::map<dof_id_type, Real> elem_var_value_map;
561 
562  exio_helper->read_elemental_var_values(elemental_var_name, timestep, elem_var_value_map);
563  for (auto & pr : elem_var_value_map)
564  {
565  const Elem * elem = MeshInput<MeshBase>::mesh().query_elem_ptr(pr.first);
566  unique_id_to_value_map.insert(std::make_pair(elem->top_parent()->unique_id(), pr.second));
567  }
568 }
std::unique_ptr< ExodusII_IO_Helper > exio_helper
Definition: exodusII_io.h:323

◆ 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

Definition at line 570 of file exodusII_io.C.

References exio_helper, and libMesh::ExodusII_IO_Helper::GLOBAL.

573 {
574  std::size_t size = global_var_names.size();
575  if (size == 0)
576  libmesh_error_msg("ERROR, empty list of global variables to read from the Exodus file.");
577 
578  // read the values for all global variables
579  std::vector<Real> values_from_exodus;
580  exio_helper->read_var_names(ExodusII_IO_Helper::GLOBAL);
581  exio_helper->read_global_values(values_from_exodus, timestep);
582  std::vector<std::string> global_var_names_exodus = exio_helper->global_var_names;
583 
584  global_values.clear();
585  for (std::size_t i = 0; i != size; ++i)
586  {
587  // for each global variable in global_var_names, look the corresponding one in global_var_names_from_exodus
588  // and fill global_values accordingly
589  auto it = find(global_var_names_exodus.begin(), global_var_names_exodus.end(), global_var_names[i]);
590  if (it != global_var_names_exodus.end())
591  global_values.push_back(values_from_exodus[it - global_var_names_exodus.begin()]);
592  else
593  libmesh_error_msg("ERROR, Global variable " << global_var_names[i] << \
594  " not found in Exodus file.");
595  }
596 
597 }
std::unique_ptr< ExodusII_IO_Helper > exio_helper
Definition: exodusII_io.h:323

◆ 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.

Definition at line 442 of file exodusII_io.C.

References exio_helper.

443 {
444  libmesh_warning("This method may be deprecated in the future");
445  exio_helper->set_coordinate_offset(p);
446 }
std::unique_ptr< ExodusII_IO_Helper > exio_helper
Definition: exodusII_io.h:323

◆ set_n_partitions()

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

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().

Referenced by libMesh::Nemesis_IO::read(), and libMesh::XdrIO::read_header().

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.

Definition at line 68 of file exodusII_io.C.

References _allow_empty_variables, and _output_variables.

70 {
71  _output_variables = output_variables;
72  _allow_empty_variables = allow_empty;
73 }
std::vector< std::string > _output_variables
Definition: exodusII_io.h:347

◆ 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.

Referenced by libMesh::TetGenIO::read(), and libMesh::UCDIO::read_implementation().

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.

Definition at line 428 of file exodusII_io.C.

References exio_helper.

429 {
430  exio_helper->use_mesh_dimension_instead_of_spatial_dimension(val);
431 }
std::unique_ptr< ExodusII_IO_Helper > exio_helper
Definition: exodusII_io.h:323

◆ verbose()

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

Set the flag indicating if we should be verbose.

Definition at line 418 of file exodusII_io.C.

References _verbose, and exio_helper.

419 {
420  _verbose = set_verbosity;
421 
422  // Set the verbose flag in the helper object as well.
423  exio_helper->verbose = _verbose;
424 }
std::unique_ptr< ExodusII_IO_Helper > exio_helper
Definition: exodusII_io.h:323

◆ write()

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

This method implements writing a mesh to a specified file.

Implements libMesh::MeshOutput< MeshBase >.

Definition at line 879 of file exodusII_io.C.

References _append, _verbose, exio_helper, libMesh::MeshBase::get_boundary_info(), libMesh::MeshInput< MeshBase >::mesh(), libMesh::MeshOutput< MT >::mesh(), and libMesh::BoundaryInfo::n_edge_conds().

Referenced by libMesh::ErrorVector::plot_error(), and libMesh::NameBasedIO::write().

880 {
881  const MeshBase & mesh = MeshOutput<MeshBase>::mesh();
882 
883  // We may need to gather a DistributedMesh to output it, making that
884  // const qualifier in our constructor a dirty lie
885  // The "true" specifies that we only need the mesh serialized to processor 0
886  MeshSerializer serialize(MeshInput<MeshBase>::mesh(), !MeshOutput<MeshBase>::_is_parallel_format, true);
887 
888  libmesh_assert( !exio_helper->opened_for_writing );
889 
890  // If the user has set the append flag here, it doesn't really make
891  // sense: the intent of this function is to write a Mesh with no
892  // data, while "appending" is really intended to add data to an
893  // existing file. If we're verbose, print a message to this effect.
894  if (_append && _verbose)
895  libmesh_warning("Warning: Appending in ExodusII_IO::write() does not make sense.\n"
896  "Creating a new file instead!");
897 
898  exio_helper->create(fname);
899  exio_helper->initialize(fname,mesh);
900  exio_helper->write_nodal_coordinates(mesh);
901  exio_helper->write_elements(mesh);
902  exio_helper->write_sidesets(mesh);
903  exio_helper->write_nodesets(mesh);
904 
905  if ((mesh.get_boundary_info().n_edge_conds() > 0) && _verbose)
906  libmesh_warning("Warning: Mesh contains edge boundary IDs, but these "
907  "are not supported by the ExodusII format.");
908 }
const MT & mesh() const
Definition: mesh_output.h:234
std::size_t n_edge_conds() const
const BoundaryInfo & get_boundary_info() const
Definition: mesh_base.h:131
std::unique_ptr< ExodusII_IO_Helper > exio_helper
Definition: exodusII_io.h:323

◆ 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.

Definition at line 435 of file exodusII_io.C.

References exio_helper.

436 {
437  exio_helper->write_as_dimension(dim);
438 }
std::unique_ptr< ExodusII_IO_Helper > exio_helper
Definition: exodusII_io.h:323

◆ write_discontinuous_equation_systems()

void libMesh::MeshOutput< MeshBase >::write_discontinuous_equation_systems ( const std::string &  fname,
const EquationSystems es,
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.

Definition at line 92 of file mesh_output.C.

References libMesh::EquationSystems::build_discontinuous_solution_vector(), libMesh::EquationSystems::build_variable_names(), libMesh::EquationSystems::get_mesh(), and libMesh::out.

Referenced by write_timestep_discontinuous().

95 {
96  LOG_SCOPE("write_discontinuous_equation_systems()", "MeshOutput");
97 
98  // We may need to gather and/or renumber a DistributedMesh to output
99  // it, making that const qualifier in our constructor a dirty lie
100  MT & my_mesh = const_cast<MT &>(*_obj);
101 
102  // If we're asked to write data that's associated with a different
103  // mesh, output files full of garbage are the result.
104  libmesh_assert_equal_to(&es.get_mesh(), _obj);
105 
106  // A non-renumbered mesh may not have a contiguous numbering, and
107  // that needs to be fixed before we can build a solution vector.
108  if (my_mesh.max_elem_id() != my_mesh.n_elem() ||
109  my_mesh.max_node_id() != my_mesh.n_nodes())
110  {
111  // If we were allowed to renumber then we should have already
112  // been properly renumbered...
113  libmesh_assert(!my_mesh.allow_renumbering());
114 
115  libmesh_do_once(libMesh::out <<
116  "Warning: This MeshOutput subclass only supports meshes which are contiguously renumbered!"
117  << std::endl;);
118 
119  my_mesh.allow_renumbering(true);
120 
121  my_mesh.renumber_nodes_and_elements();
122 
123  // Not sure what good going back to false will do here, the
124  // renumbering horses have already left the barn...
125  my_mesh.allow_renumbering(false);
126  }
127 
128  MeshSerializer serialize(const_cast<MT &>(*_obj), !_is_parallel_format, _serial_only_needed_on_proc_0);
129 
130  // Build the list of variable names that will be written.
131  std::vector<std::string> names;
132  es.build_variable_names (names, nullptr, system_names);
133 
134  if (!_is_parallel_format)
135  {
136  // Build the nodal solution values & get the variable
137  // names from the EquationSystems object
138  std::vector<Number> soln;
139  es.build_discontinuous_solution_vector (soln, system_names);
140 
141  this->write_nodal_data_discontinuous (fname, soln, names);
142  }
143  else // _is_parallel_format
144  {
145  libmesh_not_implemented();
146  }
147 }
virtual void write_nodal_data_discontinuous(const std::string &, const std::vector< Number > &, const std::vector< std::string > &)
Definition: mesh_output.h:114
const MeshBase *const _obj
Definition: mesh_output.h:177
OStreamProxy out(std::cout)

◆ 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

Definition at line 89 of file exodusII_io.C.

References libMesh::EquationSystems::build_discontinuous_solution_vector(), libMesh::EquationSystems::build_variable_names(), and write_nodal_data_discontinuous().

92 {
93  std::vector<std::string> solution_names;
94  std::vector<Number> v;
95 
96  es.build_variable_names (solution_names, nullptr, system_names);
97  es.build_discontinuous_solution_vector (v, system_names);
98 
99  this->write_nodal_data_discontinuous(name, v, solution_names);
100 }
std::string name(const ElemQuality q)
Definition: elem_quality.C:42
void write_nodal_data_discontinuous(const std::string &, const std::vector< Number > &, const std::vector< std::string > &) override
Definition: exodusII_io.C:912

◆ write_element_data()

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

Write out element solution.

Definition at line 599 of file exodusII_io.C.

References _output_variables, _timestep, std::abs(), libMesh::EquationSystems::build_elemental_solution_vector(), libMesh::EquationSystems::build_variable_names(), libMesh::CONSTANT, exio_helper, libMesh::EquationSystems::get_vars_active_subdomains(), libMesh::MeshInput< MeshBase >::mesh(), libMesh::MeshOutput< MT >::mesh(), libMesh::MONOMIAL, libMesh::ParallelObject::processor_id(), and value.

Referenced by libMesh::ErrorVector::plot_error().

600 {
601  // Be sure the file has been opened for writing!
602  if (MeshOutput<MeshBase>::mesh().processor_id() == 0 && !exio_helper->opened_for_writing)
603  libmesh_error_msg("ERROR, ExodusII file must be initialized before outputting element variables.");
604 
605  // This function currently only works on serialized meshes. We rely
606  // on having a reference to a non-const MeshBase object from our
607  // MeshInput parent class to construct a MeshSerializer object,
608  // similar to what is done in ExodusII_IO::write(). Note that
609  // calling ExodusII_IO::write_timestep() followed by
610  // ExodusII_IO::write_element_data() when the underlying Mesh is a
611  // DistributedMesh will result in an unnecessary additional
612  // serialization/re-parallelization step.
613  // The "true" specifies that we only need the mesh serialized to processor 0
614  MeshSerializer serialize(MeshInput<MeshBase>::mesh(), !MeshOutput<MeshBase>::_is_parallel_format, true);
615 
616  // To be (possibly) filled with a filtered list of variable names to output.
617  std::vector<std::string> names;
618 
619  // If _output_variables is populated, only output the monomials which are
620  // also in the _output_variables vector.
621  if (_output_variables.size() > 0)
622  {
623  std::vector<std::string> monomials;
624  const FEType type(CONSTANT, MONOMIAL);
625 
626  // Create a list of monomial variable names
627  es.build_variable_names(monomials, &type);
628 
629  // Filter that list against the _output_variables list. Note: if names is still empty after
630  // all this filtering, all the monomial variables will be gathered
631  for (const auto & var : monomials)
632  if (std::find(_output_variables.begin(), _output_variables.end(), var) != _output_variables.end())
633  names.push_back(var);
634  }
635 
636  // If we pass in a list of names to "get_solution" it'll filter the variables coming back
637  std::vector<Number> soln;
638  es.build_elemental_solution_vector(soln, names);
639 
640  // Also, store the list of subdomains on which each variable is active
641  std::vector<std::set<subdomain_id_type>> vars_active_subdomains;
642  es.get_vars_active_subdomains(names, vars_active_subdomains);
643 
644  if (soln.empty()) // If there is nothing to write just return
645  return;
646 
647  // The data must ultimately be written block by block. This means that this data
648  // must be sorted appropriately.
650  return;
651 
652  const MeshBase & mesh = MeshOutput<MeshBase>::mesh();
653 
654 #ifdef LIBMESH_USE_COMPLEX_NUMBERS
655 
656  std::vector<std::string> complex_names = exio_helper->get_complex_names(names);
657 
658  std::vector<std::set<subdomain_id_type>> complex_vars_active_subdomains =
659  exio_helper->get_complex_vars_active_subdomains(vars_active_subdomains);
660  exio_helper->initialize_element_variables(complex_names, complex_vars_active_subdomains);
661 
662  unsigned int num_values = soln.size();
663  unsigned int num_vars = names.size();
664  unsigned int num_elems = num_values / num_vars;
665 
666  // This will contain the real and imaginary parts and the magnitude
667  // of the values in soln
668  std::vector<Real> complex_soln(3*num_values);
669 
670  for (unsigned i=0; i<num_vars; ++i)
671  {
672 
673  for (unsigned int j=0; j<num_elems; ++j)
674  {
675  Number value = soln[i*num_vars + j];
676  complex_soln[3*i*num_elems + j] = value.real();
677  }
678  for (unsigned int j=0; j<num_elems; ++j)
679  {
680  Number value = soln[i*num_vars + j];
681  complex_soln[3*i*num_elems + num_elems +j] = value.imag();
682  }
683  for (unsigned int j=0; j<num_elems; ++j)
684  {
685  Number value = soln[i*num_vars + j];
686  complex_soln[3*i*num_elems + 2*num_elems + j] = std::abs(value);
687  }
688  }
689 
690  exio_helper->write_element_values(mesh, complex_soln, _timestep, complex_vars_active_subdomains);
691 
692 #else
693  exio_helper->initialize_element_variables(names, vars_active_subdomains);
694  exio_helper->write_element_values(mesh, soln, _timestep, vars_active_subdomains);
695 #endif
696 }
const MeshBase & mesh() const
Definition: mesh_output.h:234
double abs(double a)
std::vector< std::string > _output_variables
Definition: exodusII_io.h:347
std::unique_ptr< ExodusII_IO_Helper > exio_helper
Definition: exodusII_io.h:323
static const bool value
Definition: xdr_io.C:109
processor_id_type processor_id() const

◆ write_equation_systems()

void libMesh::MeshOutput< MeshBase >::write_equation_systems ( const std::string &  fname,
const EquationSystems es,
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.

Definition at line 31 of file mesh_output.C.

References libMesh::EquationSystems::build_parallel_solution_vector(), libMesh::EquationSystems::build_solution_vector(), libMesh::EquationSystems::build_variable_names(), libMesh::EquationSystems::get_mesh(), and libMesh::out.

Referenced by libMesh::Nemesis_IO::write_timestep(), and write_timestep().

34 {
35  LOG_SCOPE("write_equation_systems()", "MeshOutput");
36 
37  // We may need to gather and/or renumber a DistributedMesh to output
38  // it, making that const qualifier in our constructor a dirty lie
39  MT & my_mesh = const_cast<MT &>(*_obj);
40 
41  // If we're asked to write data that's associated with a different
42  // mesh, output files full of garbage are the result.
43  libmesh_assert_equal_to(&es.get_mesh(), _obj);
44 
45  // A non-renumbered mesh may not have a contiguous numbering, and
46  // that needs to be fixed before we can build a solution vector.
47  if (my_mesh.max_elem_id() != my_mesh.n_elem() ||
48  my_mesh.max_node_id() != my_mesh.n_nodes())
49  {
50  // If we were allowed to renumber then we should have already
51  // been properly renumbered...
52  libmesh_assert(!my_mesh.allow_renumbering());
53 
54  libmesh_do_once(libMesh::out <<
55  "Warning: This MeshOutput subclass only supports meshes which are contiguously renumbered!"
56  << std::endl;);
57 
58  my_mesh.allow_renumbering(true);
59 
60  my_mesh.renumber_nodes_and_elements();
61 
62  // Not sure what good going back to false will do here, the
63  // renumbering horses have already left the barn...
64  my_mesh.allow_renumbering(false);
65  }
66 
67  MeshSerializer serialize(const_cast<MT &>(*_obj), !_is_parallel_format, _serial_only_needed_on_proc_0);
68 
69  // Build the list of variable names that will be written.
70  std::vector<std::string> names;
71  es.build_variable_names (names, nullptr, system_names);
72 
74  {
75  // Build the nodal solution values & get the variable
76  // names from the EquationSystems object
77  std::vector<Number> soln;
78  es.build_solution_vector (soln, system_names);
79 
80  this->write_nodal_data (fname, soln, names);
81  }
82  else // _is_parallel_format
83  {
84  std::unique_ptr<NumericVector<Number>> parallel_soln =
85  es.build_parallel_solution_vector(system_names);
86 
87  this->write_nodal_data (fname, *parallel_soln, names);
88  }
89 }
virtual void write_nodal_data(const std::string &, const std::vector< Number > &, const std::vector< std::string > &)
Definition: mesh_output.h:105
const MeshBase *const _obj
Definition: mesh_output.h:177
OStreamProxy out(std::cout)

◆ write_global_data()

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

Write out global variables.

Definition at line 809 of file exodusII_io.C.

References _timestep, std::abs(), exio_helper, libMesh::ParallelObject::processor_id(), and value.

811 {
813  return;
814 
815  if (!exio_helper->opened_for_writing)
816  libmesh_error_msg("ERROR, ExodusII file must be initialized before outputting global variables.");
817 
818 #ifdef LIBMESH_USE_COMPLEX_NUMBERS
819 
820  std::vector<std::string> complex_names = exio_helper->get_complex_names(names);
821 
822  exio_helper->initialize_global_variables(complex_names);
823 
824  unsigned int num_values = soln.size();
825  unsigned int num_vars = names.size();
826  unsigned int num_elems = num_values / num_vars;
827 
828  // This will contain the real and imaginary parts and the magnitude
829  // of the values in soln
830  std::vector<Real> complex_soln(3*num_values);
831 
832  for (unsigned i=0; i<num_vars; ++i)
833  {
834 
835  for (unsigned int j=0; j<num_elems; ++j)
836  {
837  Number value = soln[i*num_vars + j];
838  complex_soln[3*i*num_elems + j] = value.real();
839  }
840  for (unsigned int j=0; j<num_elems; ++j)
841  {
842  Number value = soln[i*num_vars + j];
843  complex_soln[3*i*num_elems + num_elems +j] = value.imag();
844  }
845  for (unsigned int j=0; j<num_elems; ++j)
846  {
847  Number value = soln[i*num_vars + j];
848  complex_soln[3*i*num_elems + 2*num_elems + j] = std::abs(value);
849  }
850  }
851 
852  exio_helper->write_global_values(complex_soln, _timestep);
853 
854 #else
855  exio_helper->initialize_global_variables(names);
856  exio_helper->write_global_values(soln, _timestep);
857 #endif
858 }
const MeshBase & mesh() const
Definition: mesh_output.h:234
double abs(double a)
std::unique_ptr< ExodusII_IO_Helper > exio_helper
Definition: exodusII_io.h:323
static const bool value
Definition: xdr_io.C:109
processor_id_type processor_id() const

◆ write_information_records()

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

Write out information records.

Definition at line 796 of file exodusII_io.C.

References exio_helper, and libMesh::ParallelObject::processor_id().

797 {
799  return;
800 
801  if (!exio_helper->opened_for_writing)
802  libmesh_error_msg("ERROR, ExodusII file must be initialized before outputting information records.");
803 
804  exio_helper->write_information_records(records);
805 }
const MeshBase & mesh() const
Definition: mesh_output.h:234
std::unique_ptr< ExodusII_IO_Helper > exio_helper
Definition: exodusII_io.h:323
processor_id_type processor_id() const

◆ write_nodal_data() [1/2]

void libMesh::MeshOutput< MeshBase >::write_nodal_data ( const std::string &  fname,
const NumericVector< Number > &  parallel_soln,
const std::vector< std::string > &  names 
)
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.

Definition at line 150 of file mesh_output.C.

References libMesh::NumericVector< T >::localize().

153 {
154  // This is the fallback implementation for parallel I/O formats that
155  // do not yet implement proper writing in parallel, and instead rely
156  // on the full solution vector being available on all processors.
157  std::vector<Number> soln;
158  parallel_soln.localize(soln);
159  this->write_nodal_data(fname, soln, names);
160 }
virtual void write_nodal_data(const std::string &, const std::vector< Number > &, const std::vector< std::string > &)
Definition: mesh_output.h:105
virtual void localize(std::vector< T > &v_local) const =0

◆ write_nodal_data() [2/2]

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

Write out a nodal solution.

Reimplemented from libMesh::MeshOutput< MeshBase >.

Definition at line 700 of file exodusII_io.C.

References _allow_empty_variables, _output_variables, _timestep, std::abs(), exio_helper, libMesh::MeshTools::Generation::Private::idx(), libMesh::MeshInput< MeshBase >::mesh(), libMesh::MeshOutput< MT >::mesh(), libMesh::MeshBase::n_nodes(), libMesh::MeshBase::node_ptr_range(), libMesh::ParallelObject::processor_id(), and write_nodal_data_common().

Referenced by libMesh::NameBasedIO::write_nodal_data().

703 {
704  LOG_SCOPE("write_nodal_data()", "ExodusII_IO");
705 
706  const MeshBase & mesh = MeshOutput<MeshBase>::mesh();
707 
708  int num_vars = cast_int<int>(names.size());
709  dof_id_type num_nodes = mesh.n_nodes();
710 
711  // The names of the variables to be output
712  std::vector<std::string> output_names;
713 
715  output_names = _output_variables;
716  else
717  output_names = names;
718 
719 #ifdef LIBMESH_USE_COMPLEX_NUMBERS
720 
721  std::vector<std::string> complex_names = exio_helper->get_complex_names(names);
722 
723  // Call helper function for opening/initializing data, giving it the
724  // complex variable names
725  this->write_nodal_data_common(fname, complex_names, /*continuous=*/true);
726 #else
727  // Call helper function for opening/initializing data
728  this->write_nodal_data_common(fname, output_names, /*continuous=*/true);
729 #endif
730 
731  if (mesh.processor_id())
732  return;
733 
734  // This will count the number of variables actually output
735  for (int c=0; c<num_vars; c++)
736  {
737  std::stringstream name_to_find;
738 
739  std::vector<std::string>::iterator pos =
740  std::find(output_names.begin(), output_names.end(), names[c]);
741  if (pos == output_names.end())
742  continue;
743 
744  unsigned int variable_name_position =
745  cast_int<unsigned int>(pos - output_names.begin());
746 
747  // Set up temporary vectors to be passed to Exodus to write the
748  // nodal values for a single variable at a time.
749 #ifdef LIBMESH_USE_REAL_NUMBERS
750  std::vector<Number> cur_soln;
751 
752  // num_nodes is either exactly how much space we will need for
753  // each vector, or a safe upper bound for the amount of memory
754  // we will require when there are gaps in the numbering.
755  cur_soln.reserve(num_nodes);
756 #else
757  std::vector<Real> real_parts;
758  std::vector<Real> imag_parts;
759  std::vector<Real> magnitudes;
760  real_parts.reserve(num_nodes);
761  imag_parts.reserve(num_nodes);
762  magnitudes.reserve(num_nodes);
763 #endif
764 
765  // There could be gaps in "soln", but it will always be in the
766  // order of [num_vars * node_id + var_id]. We now copy the
767  // proper solution values contiguously into "cur_soln",
768  // removing the gaps.
769  for (const auto & node : mesh.node_ptr_range())
770  {
771  dof_id_type idx = node->id()*num_vars + c;
772 #ifdef LIBMESH_USE_REAL_NUMBERS
773  cur_soln.push_back(soln[idx]);
774 #else
775  real_parts.push_back(soln[idx].real());
776  imag_parts.push_back(soln[idx].imag());
777  magnitudes.push_back(std::abs(soln[idx]));
778 #endif
779  }
780 
781  // Finally, actually call the Exodus API to write to file.
782 #ifdef LIBMESH_USE_REAL_NUMBERS
783  exio_helper->write_nodal_values(variable_name_position+1, cur_soln, _timestep);
784 #else
785  exio_helper->write_nodal_values(3*variable_name_position+1, real_parts, _timestep);
786  exio_helper->write_nodal_values(3*variable_name_position+2, imag_parts, _timestep);
787  exio_helper->write_nodal_values(3*variable_name_position+3, magnitudes, _timestep);
788 #endif
789 
790  }
791 }
const MT & mesh() const
Definition: mesh_output.h:234
double abs(double a)
virtual SimpleRange< node_iterator > node_ptr_range()=0
std::vector< std::string > _output_variables
Definition: exodusII_io.h:347
void write_nodal_data_common(std::string fname, const std::vector< std::string > &names, bool continuous=true)
Definition: exodusII_io.C:970
std::unique_ptr< ExodusII_IO_Helper > exio_helper
Definition: exodusII_io.h:323
processor_id_type processor_id() const
virtual dof_id_type n_nodes() const =0
unsigned int idx(const ElemType type, const unsigned int nx, const unsigned int i, const unsigned int j)
uint8_t dof_id_type
Definition: id_types.h:64

◆ 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

Definition at line 970 of file exodusII_io.C.

References _append, _verbose, exio_helper, libMesh::MeshBase::get_boundary_info(), libMesh::MeshInput< MeshBase >::mesh(), libMesh::MeshOutput< MT >::mesh(), and libMesh::BoundaryInfo::n_edge_conds().

Referenced by write_nodal_data(), and write_nodal_data_discontinuous().

973 {
974  const MeshBase & mesh = MeshOutput<MeshBase>::mesh();
975 
976  // This function can be called multiple times, we only want to open
977  // the ExodusII file the first time it's called.
978  if (!exio_helper->opened_for_writing)
979  {
980  // If we're appending, open() the file with read_only=false,
981  // otherwise create() it and write the contents of the mesh to
982  // it.
983  if (_append)
984  {
985  exio_helper->open(fname.c_str(), /*read_only=*/false);
986  // If we're appending, it's not valid to call exio_helper->initialize()
987  // or exio_helper->initialize_nodal_variables(), but we do need to set up
988  // certain aspects of the Helper object itself, such as the number of nodes
989  // and elements. We do that by reading the header...
990  exio_helper->read_header();
991 
992  // ...and reading the block info
993  exio_helper->read_block_info();
994  }
995  else
996  {
997  exio_helper->create(fname);
998 
999  exio_helper->initialize(fname, mesh, !continuous);
1000  exio_helper->write_nodal_coordinates(mesh, !continuous);
1001  exio_helper->write_elements(mesh, !continuous);
1002 
1003  exio_helper->write_sidesets(mesh);
1004  exio_helper->write_nodesets(mesh);
1005 
1006  if ((mesh.get_boundary_info().n_edge_conds() > 0) && _verbose)
1007  libmesh_warning("Warning: Mesh contains edge boundary IDs, but these "
1008  "are not supported by the ExodusII format.");
1009 
1010  exio_helper->initialize_nodal_variables(names);
1011  }
1012  }
1013  else
1014  {
1015  // We are already open for writing, so check that the filename
1016  // passed to this function matches the filename currently in use
1017  // by the helper.
1018  if (fname != exio_helper->current_filename)
1019  libmesh_error_msg("Error! This ExodusII_IO object is already associated with file: " \
1020  << exio_helper->current_filename \
1021  << ", cannot use it with requested file: " \
1022  << fname);
1023  }
1024 }
const MT & mesh() const
Definition: mesh_output.h:234
std::size_t n_edge_conds() const
const BoundaryInfo & get_boundary_info() const
Definition: mesh_base.h:131
std::unique_ptr< ExodusII_IO_Helper > exio_helper
Definition: exodusII_io.h:323

◆ write_nodal_data_discontinuous()

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

Write out a discontinuous nodal solution.

Reimplemented from libMesh::MeshOutput< MeshBase >.

Definition at line 912 of file exodusII_io.C.

References _timestep, std::abs(), libMesh::MeshBase::active_element_ptr_range(), exio_helper, libMesh::MeshInput< MeshBase >::mesh(), libMesh::MeshOutput< MT >::mesh(), libMesh::ParallelObject::processor_id(), and write_nodal_data_common().

Referenced by write_discontinuous_exodusII().

915 {
916  LOG_SCOPE("write_nodal_data_discontinuous()", "ExodusII_IO");
917 
918  const MeshBase & mesh = MeshOutput<MeshBase>::mesh();
919 
920  int num_vars = cast_int<int>(names.size());
921  int num_nodes = 0;
922  for (const auto & elem : mesh.active_element_ptr_range())
923  num_nodes += elem->n_nodes();
924 
925 #ifdef LIBMESH_USE_COMPLEX_NUMBERS
926 
927  std::vector<std::string> complex_names = exio_helper->get_complex_names(names);
928 
929  // Call helper function for opening/initializing data, giving it the
930  // complex variable names
931  this->write_nodal_data_common(fname, complex_names, /*continuous=*/false);
932 #else
933  // Call helper function for opening/initializing data
934  this->write_nodal_data_common(fname, names, /*continuous=*/false);
935 #endif
936 
937  if (mesh.processor_id())
938  return;
939 
940  for (int c=0; c<num_vars; c++)
941  {
942 #ifdef LIBMESH_USE_COMPLEX_NUMBERS
943  std::vector<Real> real_parts(num_nodes);
944  std::vector<Real> imag_parts(num_nodes);
945  std::vector<Real> magnitudes(num_nodes);
946 
947  for (int i=0; i<num_nodes; ++i)
948  {
949  real_parts[i] = soln[i*num_vars + c].real();
950  imag_parts[i] = soln[i*num_vars + c].imag();
951  magnitudes[i] = std::abs(soln[i*num_vars + c]);
952  }
953  exio_helper->write_nodal_values(3*c+1,real_parts,_timestep);
954  exio_helper->write_nodal_values(3*c+2,imag_parts,_timestep);
955  exio_helper->write_nodal_values(3*c+3,magnitudes,_timestep);
956 #else
957  // Copy out this variable's solution
958  std::vector<Number> cur_soln(num_nodes);
959 
960  for (int i=0; i<num_nodes; i++)
961  cur_soln[i] = soln[i*num_vars + c];
962 
963  exio_helper->write_nodal_values(c+1,cur_soln,_timestep);
964 #endif
965  }
966 }
const MT & mesh() const
Definition: mesh_output.h:234
double abs(double a)
virtual SimpleRange< element_iterator > active_element_ptr_range()=0
void write_nodal_data_common(std::string fname, const std::vector< std::string > &names, bool continuous=true)
Definition: exodusII_io.C:970
std::unique_ptr< ExodusII_IO_Helper > exio_helper
Definition: exodusII_io.h:323
processor_id_type processor_id() const

◆ 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.

Definition at line 862 of file exodusII_io.C.

References _timestep, exio_helper, libMesh::ParallelObject::processor_id(), and libMesh::MeshOutput< MeshBase >::write_equation_systems().

867 {
868  _timestep = timestep;
869  write_equation_systems(fname,es,system_names);
870 
872  return;
873 
874  exio_helper->write_timestep(timestep, time);
875 }
const MeshBase & mesh() const
Definition: mesh_output.h:234
virtual void write_equation_systems(const std::string &, const EquationSystems &, const std::set< std::string > *system_names=nullptr)
Definition: mesh_output.C:31
std::unique_ptr< ExodusII_IO_Helper > exio_helper
Definition: exodusII_io.h:323
processor_id_type processor_id() const

◆ 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.

Definition at line 104 of file exodusII_io.C.

References _timestep, exio_helper, libMesh::ParallelObject::processor_id(), and libMesh::MeshOutput< MeshBase >::write_discontinuous_equation_systems().

109 {
110  _timestep = timestep;
111  write_discontinuous_equation_systems (fname,es,system_names);
112 
114  return;
115 
116  exio_helper->write_timestep(timestep, time);
117 }
const MeshBase & mesh() const
Definition: mesh_output.h:234
virtual void write_discontinuous_equation_systems(const std::string &, const EquationSystems &, const std::set< std::string > *system_names=nullptr)
Definition: mesh_output.C:92
std::unique_ptr< ExodusII_IO_Helper > exio_helper
Definition: exodusII_io.h:323
processor_id_type processor_id() const

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.

Referenced by set_output_variables(), and write_nodal_data().

◆ _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.

Referenced by append(), write(), and write_nodal_data_common().

◆ _communicator

◆ _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.

Referenced by libMesh::FroIO::write(), libMesh::PostscriptIO::write(), and libMesh::EnsightIO::write().

◆ _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.

Referenced by set_output_variables(), write_element_data(), and write_nodal_data().

◆ _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

◆ _verbose

bool libMesh::ExodusII_IO::_verbose
private

should we be verbose?

Definition at line 334 of file exodusII_io.h.

Referenced by verbose(), write(), and write_nodal_data_common().

◆ elems_of_dimension

◆ exio_helper


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