libMesh::CheckpointIO Class Reference

#include <checkpoint_io.h>

Inheritance diagram for libMesh::CheckpointIO:

Public Types

typedef largest_id_type xdr_id_type
 
typedef uint64_t header_id_type
 

Public Member Functions

 CheckpointIO (MeshBase &, const bool=false)
 
 CheckpointIO (const MeshBase &, const bool=false)
 
virtual ~CheckpointIO ()
 
virtual void read (const std::string &input_name) override
 
virtual void write (const std::string &name) override
 
bool binary () const
 
bool & binary ()
 
bool parallel () const
 
bool & parallel ()
 
const std::string & version () const
 
std::string & version ()
 
const std::vector< processor_id_type > & current_processor_ids () const
 
std::vector< processor_id_type > & current_processor_ids ()
 
const processor_id_typecurrent_n_processors () const
 
processor_id_typecurrent_n_processors ()
 
template<typename file_id_type >
void read_remote_elem (Xdr &io, bool libmesh_dbg_var(expect_all_remote))
 
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 std::vector< Number > &, const std::vector< std::string > &)
 
virtual void write_nodal_data (const std::string &, const NumericVector< Number > &, const std::vector< std::string > &)
 
virtual void write_nodal_data_discontinuous (const std::string &, const std::vector< 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
 

Static Public Member Functions

static void cleanup (const std::string &input_name, processor_id_type n_procs)
 

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 Member Functions

void write_subdomain_names (Xdr &io) const
 
void write_connectivity (Xdr &io, const std::set< const Elem *, CompareElemIdsByLevel > &elements) const
 
void write_remote_elem (Xdr &io, const std::set< const Elem *, CompareElemIdsByLevel > &elements) const
 
void write_nodes (Xdr &io, const std::set< const Node *> &nodeset) const
 
void write_bcs (Xdr &io, const std::set< const Elem *, CompareElemIdsByLevel > &elements, const std::vector< std::tuple< dof_id_type, unsigned short int, boundary_id_type >> &bc_triples) const
 
void write_nodesets (Xdr &io, const std::set< const Node *> &nodeset, const std::vector< std::tuple< dof_id_type, boundary_id_type >> &bc_tuples) const
 
void write_bc_names (Xdr &io, const BoundaryInfo &info, bool is_sideset) const
 
template<typename file_id_type >
file_id_type read_header (const std::string &name)
 
template<typename file_id_type >
void read_subfile (Xdr &io, bool expect_all_remote)
 
template<typename file_id_type >
void read_subdomain_names (Xdr &io)
 
template<typename file_id_type >
void read_connectivity (Xdr &io)
 
template<typename file_id_type >
void read_remote_elem (Xdr &io, bool expect_all_remote)
 
template<typename file_id_type >
void read_nodes (Xdr &io)
 
template<typename file_id_type >
void read_bcs (Xdr &io)
 
template<typename file_id_type >
void read_nodesets (Xdr &io)
 
template<typename file_id_type >
void read_bc_names (Xdr &io, BoundaryInfo &info, bool is_sideset)
 
unsigned int n_active_levels_in (MeshBase::const_element_iterator begin, MeshBase::const_element_iterator end) const
 
processor_id_type select_split_config (const std::string &input_name, header_id_type &data_size)
 

Private Attributes

bool _binary
 
bool _parallel
 
std::string _version
 
std::vector< processor_id_type_my_processor_ids
 
processor_id_type _my_n_processors
 

Detailed Description

The CheckpointIO class can be used to write simplified restart files that can be used to restart simulations that have crashed.

Author
Benjamin Kirk
John Peterson
Derek Gaston
Roy Stogner
Date
2017

Definition at line 60 of file checkpoint_io.h.

Member Typedef Documentation

◆ header_id_type

Definition at line 69 of file checkpoint_io.h.

◆ xdr_id_type

Constructor & Destructor Documentation

◆ CheckpointIO() [1/2]

libMesh::CheckpointIO::CheckpointIO ( MeshBase mesh,
const bool  binary_in = false 
)
explicit

Constructor. Takes a writable reference to a mesh object. This is the constructor required to read a mesh. The optional parameter binary can be used to switch between ASCII (false, the default) or binary (true) files.

Definition at line 160 of file checkpoint_io.C.

160  :
161  MeshInput<MeshBase> (mesh,/* is_parallel_format = */ true),
162  MeshOutput<MeshBase>(mesh,/* is_parallel_format = */ true),
164  _binary (binary_in),
165  _parallel (false),
166  _version ("checkpoint-1.2"),
169 {
170 }
ParallelObject(const Parallel::Communicator &comm_in)
std::vector< processor_id_type > _my_processor_ids
processor_id_type n_processors() const
processor_id_type _my_n_processors
virtual bool is_replicated() const
Definition: mesh_base.h:176
processor_id_type processor_id() const

◆ CheckpointIO() [2/2]

libMesh::CheckpointIO::CheckpointIO ( const MeshBase mesh,
const bool  binary_in = false 
)
explicit

Constructor. Takes a reference to a constant mesh object. This constructor will only allow us to write the mesh. The optional parameter binary can be used to switch between ASCII (false, the default) or binary (true) files.

Definition at line 172 of file checkpoint_io.C.

172  :
173  MeshOutput<MeshBase>(mesh,/* is_parallel_format = */ true),
175  _binary (binary_in),
176  _parallel (false),
179 {
180 }
ParallelObject(const Parallel::Communicator &comm_in)
std::vector< processor_id_type > _my_processor_ids
processor_id_type n_processors() const
processor_id_type _my_n_processors
virtual bool is_replicated() const
Definition: mesh_base.h:176
processor_id_type processor_id() const

◆ ~CheckpointIO()

libMesh::CheckpointIO::~CheckpointIO ( )
virtual

Destructor.

Definition at line 182 of file checkpoint_io.C.

183 {
184 }

Member Function Documentation

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

◆ binary() [1/2]

bool libMesh::CheckpointIO::binary ( ) const
inline

Get/Set the flag indicating if we should read/write binary.

Definition at line 145 of file checkpoint_io.h.

References _binary.

Referenced by read(), read_header(), select_split_config(), and write().

145 { return _binary; }

◆ binary() [2/2]

bool& libMesh::CheckpointIO::binary ( )
inline

Definition at line 146 of file checkpoint_io.h.

References _binary.

146 { return _binary; }

◆ cleanup()

void libMesh::CheckpointIO::cleanup ( const std::string &  input_name,
processor_id_type  n_procs 
)
static

Used to remove a checkpoint directory and its corresponding files. This effectively undoes all the work done be calls to write(...). For example, if a checkpoint configuration was written via:

unsigned int n_splits = 42;
std::unique_ptr<CheckpointIO> cp = split_mesh(my_mesh, n_splits);
// ...
cp->write("foo.cpr");

then you could remove all the corresponding created files/dirs by:

CheckpointIO::cleanup(my_mesh, n_splits);

Or for cases where the split configuration was determined automatically (e.g. via number of running procs with distributed/parallel mesh), then you could:

CheckpointIO::cleanup(your_mesh, your_mesh.comm().size());

Other remaining checkpoint split configurations for the mesh are left unmodified.

Definition at line 245 of file checkpoint_io.C.

246 {
247  auto header = header_file(input_name, n_procs);
248  auto ret = std::remove(header.c_str());
249  if (ret != 0)
250  libmesh_warning("Failed to clean up checkpoint header '" << header << "': " << std::strerror(ret));
251 
252  for (processor_id_type i = 0; i < n_procs; i++)
253  {
254  auto split = split_file(input_name, n_procs, i);
255  ret = std::remove(split.c_str());
256  if (ret != 0)
257  libmesh_warning("Failed to clean up checkpoint split file '" << split << "': " << std::strerror(ret));
258  }
259 
260  auto dir = split_dir(input_name, n_procs);
261  ret = rmdir(dir.c_str());
262  if (ret != 0)
263  libmesh_warning("Failed to clean up checkpoint split dir '" << dir << "': " << std::strerror(ret));
264 
265  // We expect that this may fail if there are other split configurations still present in this
266  // directory - so don't bother to check/warn for failure.
267  rmdir(input_name.c_str());
268 }
uint8_t processor_id_type
Definition: id_types.h:99
tbb::split split
Definition: threads_tbb.h:79

◆ 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(), libMesh::ExodusII_IO::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(), 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(), 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

◆ current_n_processors() [1/2]

const processor_id_type& libMesh::CheckpointIO::current_n_processors ( ) const
inline

Get/Set the n_processors to use

The default n_processors to use is the n_processors() of the mesh.

This is used for m->n parallel checkpoint file writing: You can force CheckpointIO to view the world as if it contains this number of processors by setting it here

Definition at line 183 of file checkpoint_io.h.

References _my_n_processors.

183 { return _my_n_processors; }
processor_id_type _my_n_processors

◆ current_n_processors() [2/2]

processor_id_type& libMesh::CheckpointIO::current_n_processors ( )
inline

Definition at line 184 of file checkpoint_io.h.

References _my_n_processors.

184 { return _my_n_processors; }
processor_id_type _my_n_processors

◆ current_processor_ids() [1/2]

const std::vector<processor_id_type>& libMesh::CheckpointIO::current_processor_ids ( ) const
inline

Get/Set the processor id or processor ids to use.

The default processor_id to use is the processor_id() of the mesh.

This is used for m->n parallel checkpoint file writing: You can force CheckpointIO to write out different partitions of a mesh by setting which partitions to write from each processor here.

Definition at line 170 of file checkpoint_io.h.

References _my_processor_ids.

170 { return _my_processor_ids; }
std::vector< processor_id_type > _my_processor_ids

◆ current_processor_ids() [2/2]

std::vector<processor_id_type>& libMesh::CheckpointIO::current_processor_ids ( )
inline

Definition at line 171 of file checkpoint_io.h.

References _my_processor_ids.

171 { return _my_processor_ids; }
std::vector< processor_id_type > _my_processor_ids

◆ 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(), libMesh::ExodusII_IO::read(), libMesh::GMVIO::read(), libMesh::XdrIO::read(), read(), libMesh::VTKIO::read(), read_bcs(), read_connectivity(), read_header(), libMesh::XdrIO::read_header(), libMesh::UCDIO::read_implementation(), libMesh::UNVIO::read_implementation(), libMesh::GmshIO::read_mesh(), read_nodes(), read_nodesets(), 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(), read_subdomain_names(), libMesh::TetGenIO::write(), libMesh::Nemesis_IO::write(), libMesh::ExodusII_IO::write(), libMesh::XdrIO::write(), 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(), libMesh::ExodusII_IO::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(), libMesh::ExodusII_IO::write_nodal_data(), libMesh::ExodusII_IO::write_nodal_data_common(), libMesh::ExodusII_IO::write_nodal_data_discontinuous(), libMesh::UCDIO::write_nodes(), 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 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_active_levels_in()

unsigned int libMesh::CheckpointIO::n_active_levels_in ( MeshBase::const_element_iterator  begin,
MeshBase::const_element_iterator  end 
) const
private
Returns
The number of levels of refinement in the active mesh on this processor.
Note
This includes all elements on this processor even those not owned by this processor! Implemented by looping over all the active elements and finding the maximum level.

Definition at line 1307 of file checkpoint_io.C.

References libMesh::as_range(), end, std::max(), and libMesh::MeshTools::max_level().

1309 {
1310  unsigned int max_level = 0;
1311 
1312  for (const auto & elem : as_range(begin, end))
1313  max_level = std::max(elem->level(), max_level);
1314 
1315  return max_level + 1;
1316 }
IterBase * end
long double max(long double a, double b)
unsigned int max_level(const MeshBase &mesh)
SimpleRange< I > as_range(const std::pair< I, I > &p)
Definition: simple_range.h:57

◆ 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(), read(), read_connectivity(), libMesh::XdrIO::read_header(), 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

◆ parallel() [1/2]

bool libMesh::CheckpointIO::parallel ( ) const
inline

Get/Set the flag indicating if we should read/write binary.

Definition at line 151 of file checkpoint_io.h.

References _parallel.

Referenced by write().

151 { return _parallel; }

◆ parallel() [2/2]

bool& libMesh::CheckpointIO::parallel ( )
inline

Definition at line 152 of file checkpoint_io.h.

References _parallel.

152 { return _parallel; }

◆ 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(), read(), libMesh::ExodusII_IO_Helper::read_elem_num_map(), libMesh::ExodusII_IO_Helper::read_global_values(), 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(), 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(), write(), libMesh::EquationSystems::write(), libMesh::GMVIO::write_discontinuous_gmv(), libMesh::ExodusII_IO::write_element_data(), libMesh::ExodusII_IO_Helper::write_element_values(), libMesh::ExodusII_IO_Helper::write_elements(), libMesh::ExodusII_IO::write_global_data(), libMesh::ExodusII_IO_Helper::write_global_values(), libMesh::System::write_header(), libMesh::ExodusII_IO::write_information_records(), libMesh::ExodusII_IO_Helper::write_information_records(), libMesh::ExodusII_IO_Helper::write_nodal_coordinates(), libMesh::UCDIO::write_nodal_data(), libMesh::ExodusII_IO::write_nodal_data(), libMesh::ExodusII_IO::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(), libMesh::ExodusII_IO::write_timestep(), libMesh::ExodusII_IO_Helper::write_timestep(), and libMesh::ExodusII_IO::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::CheckpointIO::read ( const std::string &  input_name)
overridevirtual

This method implements reading a mesh from a specified file. If the mesh has been split for running on several processors, input_name should simply be the name of the mesh split directory without the "-split[n]" suffix. The number of splits will be determined automatically by the number of processes being used for the mesh at the time of reading.

Implements libMesh::MeshInput< MeshBase >.

Definition at line 750 of file checkpoint_io.C.

References binary(), libMesh::MeshCommunication::broadcast(), libMesh::Xdr::close(), libMesh::DECODE, libMesh::MeshBase::is_replicated(), libMesh::MeshInput< MeshBase >::mesh(), libMesh::MeshInput< MT >::mesh(), libMesh::MeshBase::n_elem(), libMesh::ParallelObject::n_processors(), libMesh::ParallelObject::processor_id(), libMesh::READ, select_split_config(), and libMesh::MeshBase::set_distributed().

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

751 {
752  LOG_SCOPE("read()","CheckpointIO");
753 
754  MeshBase & mesh = MeshInput<MeshBase>::mesh();
755 
756  libmesh_assert(!mesh.n_elem());
757 
758  header_id_type data_size;
759  processor_id_type input_n_procs = select_split_config(input_name, data_size);
760  auto header_name = header_file(input_name, input_n_procs);
761  bool input_parallel = input_n_procs > 0;
762 
763  // If this is a serial read then we're going to only read the mesh
764  // on processor 0, then broadcast it
765  if ((input_parallel && !mesh.is_replicated()) || mesh.processor_id() == 0)
766  {
767  // If we're trying to read a parallel checkpoint file on a
768  // replicated mesh, we'll read every file on processor 0 so we
769  // can broadcast it later. If we're on a distributed mesh then
770  // we'll read every id to it's own processor and we'll "wrap
771  // around" with any ids that exceed our processor count.
772  const processor_id_type begin_proc_id =
773  (input_parallel && !mesh.is_replicated()) ?
774  mesh.processor_id() : 0;
775  const processor_id_type stride =
776  (input_parallel && !mesh.is_replicated()) ?
777  mesh.n_processors() : 1;
778 
779  for (processor_id_type proc_id = begin_proc_id; proc_id < input_n_procs;
780  proc_id = cast_int<processor_id_type>(proc_id + stride))
781  {
782  auto file_name = split_file(input_name, input_n_procs, proc_id);
783 
784  {
785  std::ifstream in (file_name.c_str());
786 
787  if (!in.good())
788  libmesh_error_msg("ERROR: cannot locate specified file:\n\t" << file_name);
789  }
790 
791  // Do we expect all our files' remote_elem entries to really
792  // be remote? Only if we're not reading multiple input
793  // files on the same processor.
794  const bool expect_all_remote =
795  (input_n_procs <= mesh.n_processors() &&
796  !mesh.is_replicated());
797 
798  Xdr io (file_name, this->binary() ? DECODE : READ);
799 
800  switch (data_size) {
801  case 2:
802  this->read_subfile<uint16_t>(io, expect_all_remote);
803  break;
804  case 4:
805  this->read_subfile<uint32_t>(io, expect_all_remote);
806  break;
807  case 8:
808  this->read_subfile<uint64_t>(io, expect_all_remote);
809  break;
810  default:
811  libmesh_error();
812  }
813 
814  io.close();
815  }
816  }
817 
818  // If the mesh was only read on processor 0 then we need to broadcast it
819  if (mesh.is_replicated())
820  MeshCommunication().broadcast(mesh);
821  // If the mesh is really distributed then we need to make sure it
822  // knows that
823  else if (mesh.n_processors() > 1)
825 }
uint8_t processor_id_type
Definition: id_types.h:99
processor_id_type select_split_config(const std::string &input_name, header_id_type &data_size)
virtual void set_distributed()
Definition: mesh_base.h:169
processor_id_type n_processors() const
virtual bool is_replicated() const
Definition: mesh_base.h:176
virtual dof_id_type n_elem() const =0
processor_id_type processor_id() const

◆ read_bc_names()

template<typename file_id_type >
void libMesh::CheckpointIO::read_bc_names ( Xdr io,
BoundaryInfo info,
bool  is_sideset 
)
private

Read boundary names information (sideset and nodeset)

Definition at line 1279 of file checkpoint_io.C.

References libMesh::Xdr::data(), libMesh::index_range(), libMesh::BoundaryInfo::set_nodeset_name_map(), and libMesh::BoundaryInfo::set_sideset_name_map().

1280 {
1281  std::map<boundary_id_type, std::string> & boundary_map = is_sideset ?
1282  info.set_sideset_name_map() : info.set_nodeset_name_map();
1283 
1284  std::vector<file_id_type> boundary_ids;
1285  std::vector<std::string> boundary_names;
1286 
1287  file_id_type n_boundary_names = 0;
1288 
1289  if (is_sideset)
1290  io.data(n_boundary_names, "# sideset id to name map");
1291  else
1292  io.data(n_boundary_names, "# nodeset id to name map");
1293 
1294  if (n_boundary_names)
1295  {
1296  io.data(boundary_ids);
1297  io.data(boundary_names);
1298  }
1299 
1300  // Add them back into the map
1301  for (auto i : index_range(boundary_ids))
1302  boundary_map[cast_int<boundary_id_type>(boundary_ids[i])] =
1303  boundary_names[i];
1304 }
IntRange< std::size_t > index_range(const std::vector< T > &vec)
Definition: int_range.h:104

◆ read_bcs()

template<typename file_id_type >
void libMesh::CheckpointIO::read_bcs ( Xdr io)
private

Read the boundary conditions for a parallel, distributed mesh

Definition at line 1231 of file checkpoint_io.C.

References libMesh::BoundaryInfo::add_side(), libMesh::Xdr::data(), libMesh::MeshBase::get_boundary_info(), libMesh::index_range(), libMesh::MeshInput< MeshBase >::mesh(), and libMesh::MeshInput< MT >::mesh().

1232 {
1233  // convenient reference to our mesh
1234  MeshBase & mesh = MeshInput<MeshBase>::mesh();
1235 
1236  // and our boundary info object
1237  BoundaryInfo & boundary_info = mesh.get_boundary_info();
1238 
1239  std::vector<file_id_type> element_id_list;
1240  std::vector<uint16_t> side_list;
1241  std::vector<file_id_type> bc_id_list;
1242 
1243  io.data(element_id_list, "# element ids for bcs");
1244  io.data(side_list, "# sides of elements for bcs");
1245  io.data(bc_id_list, "# bc ids");
1246 
1247  for (auto i : index_range(element_id_list))
1248  boundary_info.add_side
1249  (cast_int<dof_id_type>(element_id_list[i]), side_list[i],
1250  cast_int<boundary_id_type>(bc_id_list[i]));
1251 }
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
void add_side(const dof_id_type elem, const unsigned short int side, const boundary_id_type id)

◆ read_connectivity()

template<typename file_id_type >
void libMesh::CheckpointIO::read_connectivity ( Xdr io)
private

Read the connectivity for a parallel, distributed mesh

Definition at line 1023 of file checkpoint_io.C.

References libMesh::Elem::add_child(), libMesh::MeshBase::add_elem(), libMesh::Elem::build(), libMesh::Xdr::data(), libMesh::Xdr::data_stream(), libMesh::Elem::dim(), libMesh::MeshBase::elem_ptr(), libMesh::Elem::hack_p_level(), libMesh::MeshInput< MT >::mesh(), libMesh::MeshInput< MeshBase >::mesh(), n_nodes, libMesh::Elem::n_nodes(), libMesh::ParallelObject::n_processors(), libMesh::Elem::node_id(), libMesh::MeshBase::node_ptr(), libMesh::Elem::parent(), libMesh::DofObject::processor_id(), libMesh::MeshBase::query_elem_ptr(), libMesh::DofObject::set_id(), libMesh::MeshBase::set_mesh_dimension(), libMesh::Elem::set_node(), libMesh::Elem::set_p_refinement_flag(), libMesh::Elem::set_refinement_flag(), libMesh::DofObject::set_unique_id(), libMesh::Elem::subdomain_id(), libMesh::Elem::type(), and libMesh::Elem::type_to_n_nodes_map.

1024 {
1025  // convenient reference to our mesh
1026  MeshBase & mesh = MeshInput<MeshBase>::mesh();
1027 
1028  file_id_type n_elems_here;
1029  io.data(n_elems_here);
1030 
1031  // Keep track of the highest dimensional element we've added to the mesh
1032  unsigned int highest_elem_dim = 1;
1033 
1034  // RHS: Originally we used invalid_processor_id as a "no parent" tag
1035  // number, because I'm an idiot. Let's try to support broken files
1036  // as much as possible.
1037  bool file_is_broken = false;
1038 
1039  for (unsigned int i=0; i<n_elems_here; i++)
1040  {
1041  // id type pid subdomain_id parent_id
1042  std::vector<file_id_type> elem_data(6);
1043  io.data_stream
1044  (elem_data.data(), cast_int<unsigned int>(elem_data.size()),
1045  cast_int<unsigned int>(elem_data.size()));
1046 
1047 #ifdef LIBMESH_ENABLE_UNIQUE_ID
1048  file_id_type unique_id = 0;
1049  io.data(unique_id, "# unique id");
1050 #endif
1051 
1052 #ifdef LIBMESH_ENABLE_AMR
1053  uint16_t p_level = 0;
1054  io.data(p_level, "# p_level");
1055 
1056  uint16_t rflag, pflag;
1057  io.data(rflag, "# rflag");
1058  io.data(pflag, "# pflag");
1059 #endif
1060 
1061  unsigned int n_nodes = Elem::type_to_n_nodes_map[elem_data[1]];
1062 
1063  // Snag the node ids this element was connected to
1064  std::vector<file_id_type> conn_data(n_nodes);
1065  io.data_stream
1066  (conn_data.data(), cast_int<unsigned int>(conn_data.size()),
1067  cast_int<unsigned int>(conn_data.size()));
1068 
1069  const dof_id_type id =
1070  cast_int<dof_id_type> (elem_data[0]);
1071  const ElemType elem_type =
1072  static_cast<ElemType> (elem_data[1]);
1073  const processor_id_type proc_id =
1074  cast_int<processor_id_type>
1075  (elem_data[2] % mesh.n_processors());
1076  const subdomain_id_type subdomain_id =
1077  cast_int<subdomain_id_type>(elem_data[3]);
1078 
1079  // Old broken files used processsor_id_type(-1)...
1080  // But we *know* our first element will be level 0
1081  if (i == 0 && elem_data[4] == 65535)
1082  file_is_broken = true;
1083 
1084  // On a broken file we can't tell whether a parent of 65535 is a
1085  // null parent or an actual parent of 65535. Assuming the
1086  // former will cause less breakage.
1087  Elem * parent =
1088  (elem_data[4] == static_cast<largest_id_type>(-1) ||
1089  (file_is_broken && elem_data[4] == 65535)) ?
1090  nullptr : mesh.elem_ptr(cast_int<dof_id_type>(elem_data[4]));
1091  const unsigned short int child_num =
1092  (elem_data[5] == static_cast<largest_id_type>(-1) ||
1093  (file_is_broken && elem_data[5] == 65535)) ?
1094  static_cast<unsigned short>(-1) :
1095  cast_int<unsigned short>(elem_data[5]);
1096 
1097  if (!parent)
1098  libmesh_assert_equal_to
1099  (child_num, static_cast<unsigned short>(-1));
1100 
1101  Elem * old_elem = mesh.query_elem_ptr(id);
1102 
1103  // If we already have this element (e.g. from another file,
1104  // when reading multiple distributed CheckpointIO files into
1105  // a ReplicatedMesh) then we don't want to add it again
1106  // (because ReplicatedMesh can't handle that) but we do want
1107  // to assert consistency between what we're reading and what
1108  // we have.
1109  if (old_elem)
1110  {
1111  libmesh_assert_equal_to(elem_type, old_elem->type());
1112  libmesh_assert_equal_to(proc_id, old_elem->processor_id());
1113  libmesh_assert_equal_to(subdomain_id, old_elem->subdomain_id());
1114  if (parent)
1115  libmesh_assert_equal_to(parent, old_elem->parent());
1116  else
1117  libmesh_assert(!old_elem->parent());
1118 
1119  libmesh_assert_equal_to(old_elem->n_nodes(), conn_data.size());
1120 
1121  for (unsigned int n=0,
1122  n_conn = cast_int<unsigned int>(conn_data.size());
1123  n != n_conn; n++)
1124  libmesh_assert_equal_to
1125  (old_elem->node_id(n),
1126  cast_int<dof_id_type>(conn_data[n]));
1127  }
1128  else
1129  {
1130  // Create the element
1131  Elem * elem = Elem::build(elem_type, parent).release();
1132 
1133 #ifdef LIBMESH_ENABLE_UNIQUE_ID
1134  elem->set_unique_id() = unique_id;
1135 #endif
1136 
1137  if (elem->dim() > highest_elem_dim)
1138  highest_elem_dim = elem->dim();
1139 
1140  elem->set_id() = id;
1141  elem->processor_id() = proc_id;
1142  elem->subdomain_id() = subdomain_id;
1143 
1144 #ifdef LIBMESH_ENABLE_AMR
1145  elem->hack_p_level(p_level);
1146 
1147  elem->set_refinement_flag (cast_int<Elem::RefinementState>(rflag));
1148  elem->set_p_refinement_flag(cast_int<Elem::RefinementState>(pflag));
1149 
1150  // Set parent connections
1151  if (parent)
1152  {
1153  // We must specify a child_num, because we will have
1154  // skipped adding any preceding remote_elem children
1155  parent->add_child(elem, child_num);
1156  }
1157 #endif
1158 
1159  libmesh_assert(elem->n_nodes() == conn_data.size());
1160 
1161  // Connect all the nodes to this element
1162  for (unsigned int n=0,
1163  n_conn = cast_int<unsigned int>(conn_data.size());
1164  n != n_conn; n++)
1165  elem->set_node(n) =
1166  mesh.node_ptr(cast_int<dof_id_type>(conn_data[n]));
1167 
1168  mesh.add_elem(elem);
1169  }
1170  }
1171 
1172  mesh.set_mesh_dimension(cast_int<unsigned char>(highest_elem_dim));
1173 }
TestClass subdomain_id_type
Definition: id_types.h:43
uint64_t largest_id_type
Definition: id_types.h:139
uint8_t processor_id_type
Definition: id_types.h:99
static const unsigned int type_to_n_nodes_map[INVALID_ELEM]
Definition: elem.h:589
processor_id_type n_processors() const
const dof_id_type n_nodes
Definition: tecplot_io.C:68
virtual Elem * add_elem(Elem *e)=0
static std::unique_ptr< Elem > build(const ElemType type, Elem *p=nullptr)
Definition: elem.C:245
void set_mesh_dimension(unsigned char d)
Definition: mesh_base.h:213
virtual const Elem * elem_ptr(const dof_id_type i) const =0
virtual const Elem * query_elem_ptr(const dof_id_type i) const =0
virtual const Node * node_ptr(const dof_id_type i) const =0
uint8_t dof_id_type
Definition: id_types.h:64

◆ read_header()

template<typename file_id_type >
file_id_type libMesh::CheckpointIO::read_header ( const std::string &  name)
private

Read header data on processor 0, then broadcast. Returns the number of processors for which parallel non-header files have been written, or 0 if files were written in serial.

Definition at line 830 of file checkpoint_io.C.

References binary(), libMesh::Parallel::Communicator::broadcast(), libMesh::ParallelObject::comm(), libMesh::Xdr::data(), libMesh::DECODE, libMesh::MeshBase::get_boundary_info(), libMesh::MeshInput< MeshBase >::mesh(), libMesh::MeshInput< MT >::mesh(), libMesh::Quality::name(), libMesh::ParallelObject::processor_id(), libMesh::READ, libMesh::MeshBase::set_mesh_dimension(), libMesh::BoundaryInfo::set_nodeset_name_map(), libMesh::BoundaryInfo::set_sideset_name_map(), and libMesh::MeshBase::set_subdomain_name_map().

831 {
832  MeshBase & mesh = MeshInput<MeshBase>::mesh();
833 
834  // Hack for codes which don't look at all elem dimensions
835  uint16_t mesh_dimension;
836 
837  // Will this be a parallel input file? With how many processors? Stay tuned!
838  uint16_t input_parallel;
839  file_id_type input_n_procs;
840 
841  // We'll write a header file from processor 0 and broadcast.
842  if (this->processor_id() == 0)
843  {
844  Xdr io (name, this->binary() ? DECODE : READ);
845 
846  // read the version, but don't care about it
847  std::string input_version;
848  io.data(input_version);
849 
850  // read the data type, don't care about it this time
851  header_id_type data_size;
852  io.data (data_size);
853 
854  // read the dimension
855  io.data (mesh_dimension);
856 
857  // Read whether or not this is a parallel file
858  io.data(input_parallel);
859 
860  // With how many processors?
861  if (input_parallel)
862  io.data(input_n_procs);
863 
864  // read subdomain names
865  this->read_subdomain_names<file_id_type>(io);
866 
867  // read boundary names
868  BoundaryInfo & boundary_info = mesh.get_boundary_info();
869 
870  this->read_bc_names<file_id_type>(io, boundary_info, true); // sideset names
871  this->read_bc_names<file_id_type>(io, boundary_info, false); // nodeset names
872  }
873 
874  // broadcast data from processor 0, set values everywhere
875  this->comm().broadcast(mesh_dimension);
876  mesh.set_mesh_dimension(cast_int<unsigned char>(mesh_dimension));
877 
878  this->comm().broadcast(input_parallel);
879 
880  if (input_parallel)
881  this->comm().broadcast(input_n_procs);
882  else
883  input_n_procs = 1;
884 
885  std::map<subdomain_id_type, std::string> & subdomain_map =
887  this->comm().broadcast(subdomain_map);
888 
889  BoundaryInfo & boundary_info = mesh.get_boundary_info();
890  this->comm().broadcast(boundary_info.set_sideset_name_map());
891  this->comm().broadcast(boundary_info.set_nodeset_name_map());
892 
893  return input_parallel ? input_n_procs : 0;
894 }
std::string name(const ElemQuality q)
Definition: elem_quality.C:42
const Parallel::Communicator & comm() const
const BoundaryInfo & get_boundary_info() const
Definition: mesh_base.h:131
void set_mesh_dimension(unsigned char d)
Definition: mesh_base.h:213
std::map< subdomain_id_type, std::string > & set_subdomain_name_map()
Definition: mesh_base.h:1335
processor_id_type processor_id() const
void broadcast(T &data, const unsigned int root_id=0) const

◆ read_nodes()

template<typename file_id_type >
void libMesh::CheckpointIO::read_nodes ( Xdr io)
private

Read the nodal locations for a parallel, distributed mesh

Definition at line 950 of file checkpoint_io.C.

References libMesh::MeshBase::add_point(), libMesh::Xdr::data(), libMesh::Xdr::data_stream(), libMesh::MeshInput< MT >::mesh(), libMesh::MeshInput< MeshBase >::mesh(), libMesh::ParallelObject::n_processors(), libMesh::MeshBase::query_node_ptr(), and libMesh::DofObject::set_unique_id().

951 {
952  // convenient reference to our mesh
953  MeshBase & mesh = MeshInput<MeshBase>::mesh();
954 
955  file_id_type n_nodes_here;
956  io.data(n_nodes_here, "# n_nodes on proc");
957 
958  // Will hold the node id and pid
959  std::vector<file_id_type> id_pid(2);
960 
961  // For the coordinates
962  std::vector<Real> coords(LIBMESH_DIM);
963 
964  for (unsigned int i=0; i<n_nodes_here; i++)
965  {
966  io.data_stream(id_pid.data(), 2, 2);
967 
968 #ifdef LIBMESH_ENABLE_UNIQUE_ID
969  file_id_type unique_id = 0;
970  io.data(unique_id, "# unique id");
971 #endif
972 
973  io.data_stream(coords.data(), LIBMESH_DIM, LIBMESH_DIM);
974 
975  Point p;
976  p(0) = coords[0];
977 
978 #if LIBMESH_DIM > 1
979  p(1) = coords[1];
980 #endif
981 
982 #if LIBMESH_DIM > 2
983  p(2) = coords[2];
984 #endif
985 
986  const dof_id_type id = cast_int<dof_id_type>(id_pid[0]);
987 
988  // "Wrap around" if we see more processors than we're using.
989  processor_id_type pid =
990  cast_int<processor_id_type>(id_pid[1] % mesh.n_processors());
991 
992  // If we already have this node (e.g. from another file, when
993  // reading multiple distributed CheckpointIO files into a
994  // ReplicatedMesh) then we don't want to add it again (because
995  // ReplicatedMesh can't handle that) but we do want to assert
996  // consistency between what we're reading and what we have.
997  const Node * old_node = mesh.query_node_ptr(id);
998 
999  if (old_node)
1000  {
1001  libmesh_assert_equal_to(pid, old_node->processor_id());
1002 #ifdef LIBMESH_ENABLE_UNIQUE_ID
1003  libmesh_assert_equal_to(unique_id, old_node->unique_id());
1004 #endif
1005  }
1006  else
1007  {
1008 #ifdef LIBMESH_ENABLE_UNIQUE_ID
1009  Node * node =
1010 #endif
1011  mesh.add_point(p, id, pid);
1012 
1013 #ifdef LIBMESH_ENABLE_UNIQUE_ID
1014  node->set_unique_id() = unique_id;
1015 #endif
1016  }
1017  }
1018 }
unique_id_type & set_unique_id()
Definition: dof_object.h:685
uint8_t processor_id_type
Definition: id_types.h:99
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
processor_id_type n_processors() const
virtual const Node * query_node_ptr(const dof_id_type i) const =0
uint8_t dof_id_type
Definition: id_types.h:64

◆ read_nodesets()

template<typename file_id_type >
void libMesh::CheckpointIO::read_nodesets ( Xdr io)
private

Read the nodeset conditions for a parallel, distributed mesh

Definition at line 1256 of file checkpoint_io.C.

References libMesh::BoundaryInfo::add_node(), libMesh::Xdr::data(), libMesh::MeshBase::get_boundary_info(), libMesh::index_range(), libMesh::MeshInput< MeshBase >::mesh(), and libMesh::MeshInput< MT >::mesh().

1257 {
1258  // convenient reference to our mesh
1259  MeshBase & mesh = MeshInput<MeshBase>::mesh();
1260 
1261  // and our boundary info object
1262  BoundaryInfo & boundary_info = mesh.get_boundary_info();
1263 
1264  std::vector<file_id_type> node_id_list;
1265  std::vector<file_id_type> bc_id_list;
1266 
1267  io.data(node_id_list, "# node id list");
1268  io.data(bc_id_list, "# nodeset bc id list");
1269 
1270  for (auto i : index_range(node_id_list))
1271  boundary_info.add_node
1272  (cast_int<dof_id_type>(node_id_list[i]),
1273  cast_int<boundary_id_type>(bc_id_list[i]));
1274 }
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
void add_node(const Node *node, const boundary_id_type id)

◆ read_remote_elem() [1/2]

template<typename file_id_type >
void libMesh::CheckpointIO::read_remote_elem ( Xdr io,
bool  expect_all_remote 
)
private

Read the remote_elem neighbor and child links for a parallel, distributed mesh

If we expect all these remote_elem links to truly be remote, because we aren't doing an N -> M restart with M < N, then we set expect_all_remote to true and test more assertions.

◆ read_remote_elem() [2/2]

template<typename file_id_type >
void libMesh::CheckpointIO::read_remote_elem ( Xdr io,
bool   libmesh_dbg_varexpect_all_remote 
)

Definition at line 1177 of file checkpoint_io.C.

References libMesh::Elem::add_child(), libMesh::Xdr::data(), libMesh::MeshBase::elem_ref(), libMesh::index_range(), libMesh::MeshInput< MT >::mesh(), libMesh::MeshInput< MeshBase >::mesh(), libMesh::Elem::neighbor_ptr(), libMesh::Elem::raw_child_ptr(), libMesh::remote_elem, and libMesh::Elem::set_neighbor().

1178 {
1179  // convenient reference to our mesh
1180  MeshBase & mesh = MeshInput<MeshBase>::mesh();
1181 
1182  // Find the remote_elem neighbor links
1183  std::vector<file_id_type> elem_ids;
1184  std::vector<uint16_t> elem_sides;
1185 
1186  io.data(elem_ids, "# remote neighbor elem_ids");
1187  io.data(elem_sides, "# remote neighbor elem_sides");
1188 
1189  libmesh_assert_equal_to(elem_ids.size(), elem_sides.size());
1190 
1191  for (auto i : index_range(elem_ids))
1192  {
1193  Elem & elem = mesh.elem_ref(cast_int<dof_id_type>(elem_ids[i]));
1194  if (!elem.neighbor_ptr(elem_sides[i]))
1195  elem.set_neighbor(elem_sides[i],
1196  const_cast<RemoteElem *>(remote_elem));
1197  else
1198  libmesh_assert(!expect_all_remote);
1199  }
1200 
1201  // Find the remote_elem children links
1202  std::vector<file_id_type> parent_ids;
1203  std::vector<uint16_t> child_numbers;
1204 
1205  io.data(parent_ids, "# remote child parent_ids");
1206  io.data(child_numbers, "# remote child_numbers");
1207 
1208 #ifdef LIBMESH_ENABLE_AMR
1209  for (auto i : index_range(parent_ids))
1210  {
1211  Elem & elem = mesh.elem_ref(cast_int<dof_id_type>(parent_ids[i]));
1212 
1213  // We'd like to assert that no child pointer already exists to
1214  // be overwritten by remote_elem, but Elem doesn't actually have
1215  // an API that will return a child pointer without asserting
1216  // that it isn't nullptr.
1217  const Elem * child = elem.raw_child_ptr(child_numbers[i]);
1218 
1219  if (!child)
1220  elem.add_child(const_cast<RemoteElem *>(remote_elem),
1221  child_numbers[i]);
1222  else
1223  libmesh_assert(!expect_all_remote);
1224  }
1225 #endif
1226 }
IntRange< std::size_t > index_range(const std::vector< T > &vec)
Definition: int_range.h:104
void add_child(Elem *elem)
Definition: elem.C:1461
void set_neighbor(const unsigned int i, Elem *n)
Definition: elem.h:2083
const Elem * raw_child_ptr(unsigned int i) const
Definition: elem.h:2569
virtual const Elem & elem_ref(const dof_id_type i) const
Definition: mesh_base.h:504
const RemoteElem * remote_elem
Definition: remote_elem.C:57

◆ read_subdomain_names()

template<typename file_id_type >
void libMesh::CheckpointIO::read_subdomain_names ( Xdr io)
private

Read subdomain name information

Definition at line 920 of file checkpoint_io.C.

References libMesh::Xdr::data(), libMesh::index_range(), libMesh::MeshInput< MT >::mesh(), libMesh::MeshInput< MeshBase >::mesh(), and libMesh::MeshBase::set_subdomain_name_map().

921 {
922  MeshBase & mesh = MeshInput<MeshBase>::mesh();
923 
924  std::map<subdomain_id_type, std::string> & subdomain_map =
926 
927  std::vector<file_id_type> subdomain_ids;
928  subdomain_ids.reserve(subdomain_map.size());
929 
930  std::vector<std::string> subdomain_names;
931  subdomain_names.reserve(subdomain_map.size());
932 
933  file_id_type n_subdomain_names = 0;
934  io.data(n_subdomain_names, "# subdomain id to name map");
935 
936  if (n_subdomain_names)
937  {
938  io.data(subdomain_ids);
939  io.data(subdomain_names);
940 
941  for (auto i : index_range(subdomain_ids))
942  subdomain_map[cast_int<subdomain_id_type>(subdomain_ids[i])] =
943  subdomain_names[i];
944  }
945 }
IntRange< std::size_t > index_range(const std::vector< T > &vec)
Definition: int_range.h:104
std::map< subdomain_id_type, std::string > & set_subdomain_name_map()
Definition: mesh_base.h:1335

◆ read_subfile()

template<typename file_id_type >
void libMesh::CheckpointIO::read_subfile ( Xdr io,
bool  expect_all_remote 
)
private

Read a non-header file

Definition at line 899 of file checkpoint_io.C.

900 {
901  // read the nodal locations
902  this->read_nodes<file_id_type> (io);
903 
904  // read connectivity
905  this->read_connectivity<file_id_type> (io);
906 
907  // read remote_elem connectivity
908  this->read_remote_elem<file_id_type> (io, expect_all_remote);
909 
910  // read the boundary conditions
911  this->read_bcs<file_id_type> (io);
912 
913  // read the nodesets
914  this->read_nodesets<file_id_type> (io);
915 }

◆ select_split_config()

processor_id_type libMesh::CheckpointIO::select_split_config ( const std::string &  input_name,
header_id_type data_size 
)
private

Definition at line 186 of file checkpoint_io.C.

References _my_n_processors, binary(), libMesh::Parallel::Communicator::broadcast(), libMesh::ParallelObject::comm(), libMesh::Xdr::data(), libMesh::DECODE, libMesh::ParallelObject::processor_id(), and libMesh::READ.

Referenced by read().

187 {
188  std::string header_name;
189 
190  // We'll read a header file from processor 0 and broadcast.
191  if (this->processor_id() == 0)
192  {
193  header_name = header_file(input_name, _my_n_processors);
194 
195  {
196  // look for header+splits with nprocs equal to _my_n_processors
197  std::ifstream in (header_name.c_str());
198  if (!in.good())
199  {
200  // otherwise fall back to a serial/single-split mesh
201  header_name = header_file(input_name, 1);
202  std::ifstream in2 (header_name.c_str());
203  if (!in2.good())
204  {
205  libmesh_error_msg("ERROR: cannot locate header file for input '" << input_name << "'");
206  }
207  }
208  }
209 
210  Xdr io (header_name, this->binary() ? DECODE : READ);
211 
212  // read the version, but don't care about it
213  std::string input_version;
214  io.data(input_version);
215 
216  // read the data type
217  io.data (data_size);
218  }
219 
220  this->comm().broadcast(data_size);
221  this->comm().broadcast(header_name);
222 
223  // How many per-processor files are here?
224  largest_id_type input_n_procs;
225 
226  switch (data_size) {
227  case 2:
228  input_n_procs = this->read_header<uint16_t>(header_name);
229  break;
230  case 4:
231  input_n_procs = this->read_header<uint32_t>(header_name);
232  break;
233  case 8:
234  input_n_procs = this->read_header<uint64_t>(header_name);
235  break;
236  default:
237  libmesh_error();
238  }
239 
240  if (!input_n_procs)
241  input_n_procs = 1;
242  return cast_int<processor_id_type>(input_n_procs);
243 }
uint64_t largest_id_type
Definition: id_types.h:139
const Parallel::Communicator & comm() const
processor_id_type _my_n_processors
processor_id_type processor_id() const
void broadcast(T &data, const unsigned int root_id=0) const

◆ 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

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

◆ version() [1/2]

const std::string& libMesh::CheckpointIO::version ( ) const
inline

Get/Set the version string.

Definition at line 157 of file checkpoint_io.h.

References _version.

157 { return _version; }

◆ version() [2/2]

std::string& libMesh::CheckpointIO::version ( )
inline

Definition at line 158 of file checkpoint_io.h.

References _version.

158 { return _version; }

◆ write()

void libMesh::CheckpointIO::write ( const std::string &  name)
overridevirtual

This method implements writing a mesh to a specified file. If the mesh has been split for running on several processors, this will create a subdirectory named "[name]-split[n]" where name is the given name argument and n is the number of processors the mesh is split for running on. For example:

unsigned int n_splits = 42;
std::unique_ptr<CheckpointIO> cp = split_mesh(my_mesh, n_splits);
// ...
cp->write("foo.cpr");

would create a directory named "foo.cpr-split42".

Implements libMesh::MeshOutput< MeshBase >.

Definition at line 270 of file checkpoint_io.C.

References _my_n_processors, _my_processor_ids, _parallel, _version, binary(), libMesh::BoundaryInfo::build_node_list(), libMesh::BoundaryInfo::build_side_list(), libMesh::Xdr::close(), libMesh::connect_children(), libMesh::connect_families(), libMesh::Xdr::data(), libMesh::MeshBase::element_ptr_range(), libMesh::MeshBase::elements_begin(), libMesh::MeshBase::elements_end(), libMesh::ENCODE, libMesh::MeshBase::get_boundary_info(), libMesh::DofObject::invalid_processor_id, libMesh::MeshBase::is_serial(), libMesh::MeshInput< MeshBase >::mesh(), libMesh::MeshOutput< MT >::mesh(), libMesh::MeshBase::mesh_dimension(), libMesh::Quality::name(), parallel(), libMesh::ParallelObject::processor_id(), libMesh::query_ghosting_functors(), libMesh::reconnect_nodes(), libMesh::WRITE, write_bc_names(), write_bcs(), write_connectivity(), write_nodes(), write_nodesets(), write_remote_elem(), and write_subdomain_names().

271 {
272  LOG_SCOPE("write()", "CheckpointIO");
273 
274  // convenient reference to our mesh
275  const MeshBase & mesh = MeshOutput<MeshBase>::mesh();
276 
277  // FIXME: For backwards compatibility, we'll assume for now that we
278  // only want to write distributed meshes in parallel. Later we can
279  // do a gather_to_zero() and support that case too.
281 
282  processor_id_type use_n_procs = 1;
283  if (_parallel)
284  use_n_procs = _my_n_processors;
285 
286  std::string header_file_name = header_file(name, use_n_procs);
287  make_dir(name, use_n_procs);
288 
289  // We'll write a header file from processor 0 to make it easier to do unambiguous
290  // restarts later:
291  if (this->processor_id() == 0)
292  {
293  Xdr io (header_file_name, this->binary() ? ENCODE : WRITE);
294 
295  // write the version
296  io.data(_version, "# version");
297 
298  // write what kind of data type we're using
299  header_id_type data_size = sizeof(largest_id_type);
300  io.data(data_size, "# integer size");
301 
302  // Write out the max mesh dimension for backwards compatibility
303  // with code that sets it independently of element dimensions
304  {
305  uint16_t mesh_dimension = cast_int<uint16_t>(mesh.mesh_dimension());
306  io.data(mesh_dimension, "# dimensions");
307  }
308 
309  // Write out whether or not this is serial output
310  {
311  uint16_t parallel = _parallel;
312  io.data(parallel, "# parallel");
313  }
314 
315  // If we're writing out a parallel mesh then we need to write the number of processors
316  // so we can check it upon reading the file
317  if (_parallel)
318  {
320  io.data(n_procs, "# n_procs");
321  }
322 
323  // write subdomain names
324  this->write_subdomain_names(io);
325 
326  // write boundary id names
327  const BoundaryInfo & boundary_info = mesh.get_boundary_info();
328  write_bc_names(io, boundary_info, true); // sideset names
329  write_bc_names(io, boundary_info, false); // nodeset names
330  }
331 
332  // If this is a serial mesh written to a serial file then we're only
333  // going to write local data from processor 0. If this is a mesh being
334  // written in parallel then we're going to write from every
335  // processor.
336  std::vector<processor_id_type> ids_to_write;
337 
338  // We're going to sort elements by pid in one pass, to avoid sending
339  // predicated iterators through the whole mesh N_p times
340  std::unordered_map<processor_id_type, std::vector<Elem *>> elements_on_pid;
341 
342  if (_parallel)
343  {
344  ids_to_write = _my_processor_ids;
345  for (processor_id_type p : ids_to_write)
346  elements_on_pid[p].clear();
347  auto eop_end = elements_on_pid.end();
348  for (auto & elem : mesh.element_ptr_range())
349  {
350  const processor_id_type p = elem->processor_id();
351  auto eop_it = elements_on_pid.find(p);
352  if (eop_it != eop_end)
353  eop_it->second.push_back(elem);
354  }
355  }
356  else if (mesh.is_serial())
357  {
358  if (mesh.processor_id() == 0)
359  {
360  // placeholder
361  ids_to_write.push_back(0);
362  }
363  }
364  else
365  {
366  libmesh_error_msg("Cannot write serial checkpoint from distributed mesh");
367  }
368 
369  // Call build_side_list() and build_node_list() just *once* to avoid
370  // redundant expensive sorts during mesh splitting.
371  const BoundaryInfo & boundary_info = mesh.get_boundary_info();
372  std::vector<std::tuple<dof_id_type, unsigned short int, boundary_id_type>>
373  bc_triples = boundary_info.build_side_list();
374  std::vector<std::tuple<dof_id_type, boundary_id_type>>
375  bc_tuples = boundary_info.build_node_list();
376 
377  for (const auto & my_pid : ids_to_write)
378  {
379  auto file_name = split_file(name, use_n_procs, my_pid);
380  Xdr io (file_name, this->binary() ? ENCODE : WRITE);
381 
382  std::set<const Elem *, CompareElemIdsByLevel> elements;
383 
384  // For serial files or for already-distributed meshs, we write
385  // everything we can see.
386  if (!_parallel || !mesh.is_serial())
387  elements.insert(mesh.elements_begin(), mesh.elements_end());
388  // For parallel files written from serial meshes we write what
389  // we'd be required to keep if we were to be deleting remote
390  // elements. This allows us to write proper parallel files even
391  // from a ReplicateMesh.
392  //
393  // WARNING: If we have a DistributedMesh which used
394  // "add_extra_ghost_elem" rather than ghosting functors to
395  // preserve elements and which is *also* currently serialized
396  // then we're not preserving those elements here. As a quick
397  // workaround user code should delete_remote_elements() before
398  // writing the checkpoint; as a long term workaround user code
399  // should use ghosting functors instead of extra_ghost_elem
400  // lists.
401  else
402  {
404  {
405  const auto elements_vec_it = elements_on_pid.find(p);
406  if (elements_vec_it != elements_on_pid.end())
407  {
408  const auto & p_elements = elements_vec_it->second;
409  Elem * const * elempp = p_elements.data();
410  Elem * const * elemend = elempp + p_elements.size();
411 
412  const MeshBase::const_element_iterator
413  pid_elements_begin = MeshBase::const_element_iterator
414  (elempp, elemend, Predicates::NotNull<Elem * const *>()),
415  pid_elements_end = MeshBase::const_element_iterator
416  (elemend, elemend, Predicates::NotNull<Elem * const *>()),
417  active_pid_elements_begin = MeshBase::const_element_iterator
418  (elempp, elemend, Predicates::Active<Elem * const *>()),
419  active_pid_elements_end = MeshBase::const_element_iterator
420  (elemend, elemend, Predicates::Active<Elem * const *>());
421 
423  (mesh, p, active_pid_elements_begin,
424  active_pid_elements_end, elements);
425  connect_children(mesh, pid_elements_begin,
426  pid_elements_end, elements);
427  }
428  connect_families(elements);
429  }
430  }
431 
432  std::set<const Node *> connected_nodes;
433  reconnect_nodes(elements, connected_nodes);
434 
435  // write the nodal locations
436  this->write_nodes (io, connected_nodes);
437 
438  // write connectivity
439  this->write_connectivity (io, elements);
440 
441  // write remote_elem connectivity
442  this->write_remote_elem (io, elements);
443 
444  // write the boundary condition information
445  this->write_bcs (io, elements, bc_triples);
446 
447  // write the nodeset information
448  this->write_nodesets (io, connected_nodes, bc_tuples);
449 
450  // close it up
451  io.close();
452  }
453 
454  // this->comm().barrier();
455 }
std::string name(const ElemQuality q)
Definition: elem_quality.C:42
const MT & mesh() const
Definition: mesh_output.h:234
void write_remote_elem(Xdr &io, const std::set< const Elem *, CompareElemIdsByLevel > &elements) const
void write_connectivity(Xdr &io, const std::set< const Elem *, CompareElemIdsByLevel > &elements) const
uint64_t largest_id_type
Definition: id_types.h:139
uint8_t processor_id_type
Definition: id_types.h:99
void write_bcs(Xdr &io, const std::set< const Elem *, CompareElemIdsByLevel > &elements, const std::vector< std::tuple< dof_id_type, unsigned short int, boundary_id_type >> &bc_triples) const
const BoundaryInfo & get_boundary_info() const
Definition: mesh_base.h:131
void build_side_list(std::vector< dof_id_type > &element_id_list, std::vector< unsigned short int > &side_list, std::vector< boundary_id_type > &bc_id_list) const
virtual element_iterator elements_begin()=0
std::vector< processor_id_type > _my_processor_ids
virtual bool is_serial() const
Definition: mesh_base.h:154
void reconnect_nodes(const std::set< const Elem *, CompareElemIdsByLevel > &connected_elements, std::set< const Node *> &connected_nodes)
virtual SimpleRange< element_iterator > element_ptr_range()=0
void write_subdomain_names(Xdr &io) const
static const processor_id_type invalid_processor_id
Definition: dof_object.h:358
processor_id_type _my_n_processors
void connect_families(std::set< const Elem *, CompareElemIdsByLevel > &connected_elements)
virtual element_iterator elements_end()=0
void write_bc_names(Xdr &io, const BoundaryInfo &info, bool is_sideset) const
void query_ghosting_functors(const MeshBase &mesh, processor_id_type pid, MeshBase::const_element_iterator elem_it, MeshBase::const_element_iterator elem_end, std::set< const Elem *, CompareElemIdsByLevel > &connected_elements)
void write_nodesets(Xdr &io, const std::set< const Node *> &nodeset, const std::vector< std::tuple< dof_id_type, boundary_id_type >> &bc_tuples) const
unsigned int mesh_dimension() const
Definition: mesh_base.C:126
void write_nodes(Xdr &io, const std::set< const Node *> &nodeset) const
void connect_children(const MeshBase &mesh, MeshBase::const_element_iterator elem_it, MeshBase::const_element_iterator elem_end, std::set< const Elem *, CompareElemIdsByLevel > &connected_elements)
processor_id_type processor_id() const

◆ write_bc_names()

void libMesh::CheckpointIO::write_bc_names ( Xdr io,
const BoundaryInfo info,
bool  is_sideset 
) const
private

Write boundary names information (sideset and nodeset)

Definition at line 718 of file checkpoint_io.C.

References libMesh::Xdr::data(), libMesh::BoundaryInfo::get_nodeset_name_map(), and libMesh::BoundaryInfo::get_sideset_name_map().

Referenced by write().

719 {
720  const std::map<boundary_id_type, std::string> & boundary_map = is_sideset ?
721  info.get_sideset_name_map() : info.get_nodeset_name_map();
722 
723  std::vector<largest_id_type> boundary_ids; boundary_ids.reserve(boundary_map.size());
724  std::vector<std::string> boundary_names; boundary_names.reserve(boundary_map.size());
725 
726  // We need to loop over the map and make sure that there aren't any invalid entries. Since we
727  // return writable references in boundary_info, it's possible for the user to leave some entity names
728  // blank. We can't write those to the XDA file.
729  largest_id_type n_boundary_names = 0;
730  for (const auto & pr : boundary_map)
731  if (!pr.second.empty())
732  {
733  n_boundary_names++;
734  boundary_ids.push_back(pr.first);
735  boundary_names.push_back(pr.second);
736  }
737 
738  if (is_sideset)
739  io.data(n_boundary_names, "# sideset id to name map");
740  else
741  io.data(n_boundary_names, "# nodeset id to name map");
742  // Write out the ids and names in two vectors
743  if (n_boundary_names)
744  {
745  io.data(boundary_ids);
746  io.data(boundary_names);
747  }
748 }
uint64_t largest_id_type
Definition: id_types.h:139

◆ write_bcs()

void libMesh::CheckpointIO::write_bcs ( Xdr io,
const std::set< const Elem *, CompareElemIdsByLevel > &  elements,
const std::vector< std::tuple< dof_id_type, unsigned short int, boundary_id_type >> &  bc_triples 
) const
private

Write the side boundary conditions for part of a mesh

Definition at line 650 of file checkpoint_io.C.

References libMesh::Xdr::data(), and libMesh::Xdr::writing().

Referenced by write().

653 {
654  libmesh_assert (io.writing());
655 
656  // Build a list of (elem, side, bc) tuples.
657  std::size_t bc_size = bc_triples.size();
658 
659  std::vector<largest_id_type> element_id_list;
660  std::vector<uint16_t> side_list;
661  std::vector<largest_id_type> bc_id_list;
662 
663  element_id_list.reserve(bc_size);
664  side_list.reserve(bc_size);
665  bc_id_list.reserve(bc_size);
666 
667  std::unordered_set<dof_id_type> elems;
668  for (auto & e : elements)
669  elems.insert(e->id());
670 
671  for (const auto & t : bc_triples)
672  if (elems.count(std::get<0>(t)))
673  {
674  element_id_list.push_back(std::get<0>(t));
675  side_list.push_back(std::get<1>(t));
676  bc_id_list.push_back(std::get<2>(t));
677  }
678 
679 
680  io.data(element_id_list, "# element ids for bcs");
681  io.data(side_list, "# sides of elements for bcs");
682  io.data(bc_id_list, "# bc ids");
683 }

◆ write_connectivity()

void libMesh::CheckpointIO::write_connectivity ( Xdr io,
const std::set< const Elem *, CompareElemIdsByLevel > &  elements 
) const
private

Write the connectivity for part of a mesh

Definition at line 533 of file checkpoint_io.C.

References libMesh::Xdr::data(), libMesh::Xdr::data_stream(), n_nodes, and libMesh::Xdr::writing().

Referenced by write().

535 {
536  libmesh_assert (io.writing());
537 
538  // Put these out here to reduce memory churn
539  // id type pid subdomain_id parent_id
540  std::vector<largest_id_type> elem_data(6);
541  std::vector<largest_id_type> conn_data;
542 
543  largest_id_type n_elems_here = elements.size();
544 
545  io.data(n_elems_here, "# number of elements");
546 
547  for (const auto & elem : elements)
548  {
549  unsigned int n_nodes = elem->n_nodes();
550 
551  elem_data[0] = elem->id();
552  elem_data[1] = elem->type();
553  elem_data[2] = elem->processor_id();
554  elem_data[3] = elem->subdomain_id();
555 
556 #ifdef LIBMESH_ENABLE_AMR
557  if (elem->parent() != nullptr)
558  {
559  elem_data[4] = elem->parent()->id();
560  elem_data[5] = elem->parent()->which_child_am_i(elem);
561  }
562  else
563 #endif
564  {
565  elem_data[4] = static_cast<largest_id_type>(-1);
566  elem_data[5] = static_cast<largest_id_type>(-1);
567  }
568 
569  conn_data.resize(n_nodes);
570 
571  for (unsigned int i=0; i<n_nodes; i++)
572  conn_data[i] = elem->node_id(i);
573 
574  io.data_stream(elem_data.data(),
575  cast_int<unsigned int>(elem_data.size()),
576  cast_int<unsigned int>(elem_data.size()));
577 
578 #ifdef LIBMESH_ENABLE_UNIQUE_ID
579  largest_id_type unique_id = elem->unique_id();
580 
581  io.data(unique_id, "# unique id");
582 #endif
583 
584 #ifdef LIBMESH_ENABLE_AMR
585  uint16_t p_level = cast_int<uint16_t>(elem->p_level());
586  io.data(p_level, "# p_level");
587 
588  uint16_t rflag = elem->refinement_flag();
589  io.data(rflag, "# rflag");
590 
591  uint16_t pflag = elem->p_refinement_flag();
592  io.data(pflag, "# pflag");
593 #endif
594  io.data_stream(conn_data.data(),
595  cast_int<unsigned int>(conn_data.size()),
596  cast_int<unsigned int>(conn_data.size()));
597  }
598 }
uint64_t largest_id_type
Definition: id_types.h:139
const dof_id_type n_nodes
Definition: tecplot_io.C:68

◆ 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 libMesh::ExodusII_IO::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_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 libMesh::ExodusII_IO::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_nodal_data() [1/2]

virtual void libMesh::MeshOutput< MeshBase >::write_nodal_data ( const std::string &  ,
const std::vector< Number > &  ,
const std::vector< std::string > &   
)
inlinevirtualinherited

This method implements writing a mesh with nodal data to a specified file where the nodal data and variable names are provided.

Reimplemented in libMesh::ExodusII_IO, libMesh::Nemesis_IO, libMesh::UCDIO, libMesh::NameBasedIO, libMesh::GmshIO, libMesh::GMVIO, libMesh::VTKIO, libMesh::MEDITIO, libMesh::GnuPlotIO, and libMesh::TecplotIO.

Definition at line 105 of file mesh_output.h.

108  { libmesh_not_implemented(); }

◆ write_nodal_data() [2/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_discontinuous()

virtual void libMesh::MeshOutput< MeshBase >::write_nodal_data_discontinuous ( const std::string &  ,
const std::vector< Number > &  ,
const std::vector< std::string > &   
)
inlinevirtualinherited

This method implements writing a mesh with discontinuous data to a specified file where the nodal data and variables names are provided.

Reimplemented in libMesh::ExodusII_IO.

Definition at line 114 of file mesh_output.h.

117  { libmesh_not_implemented(); }

◆ write_nodes()

void libMesh::CheckpointIO::write_nodes ( Xdr io,
const std::set< const Node *> &  nodeset 
) const
private

Write the nodal locations for part of a mesh

Definition at line 491 of file checkpoint_io.C.

References libMesh::Xdr::data(), and libMesh::Xdr::data_stream().

Referenced by write().

493 {
494  largest_id_type n_nodes_here = nodeset.size();
495 
496  io.data(n_nodes_here, "# n_nodes on proc");
497 
498  // Will hold the node id and pid
499  std::vector<largest_id_type> id_pid(2);
500 
501  // For the coordinates
502  std::vector<Real> coords(LIBMESH_DIM);
503 
504  for (const auto & node : nodeset)
505  {
506  id_pid[0] = node->id();
507  id_pid[1] = node->processor_id();
508 
509  io.data_stream(id_pid.data(), 2, 2);
510 
511 #ifdef LIBMESH_ENABLE_UNIQUE_ID
512  largest_id_type unique_id = node->unique_id();
513 
514  io.data(unique_id, "# unique id");
515 #endif
516 
517  coords[0] = (*node)(0);
518 
519 #if LIBMESH_DIM > 1
520  coords[1] = (*node)(1);
521 #endif
522 
523 #if LIBMESH_DIM > 2
524  coords[2] = (*node)(2);
525 #endif
526 
527  io.data_stream(coords.data(), LIBMESH_DIM, 3);
528  }
529 }
uint64_t largest_id_type
Definition: id_types.h:139

◆ write_nodesets()

void libMesh::CheckpointIO::write_nodesets ( Xdr io,
const std::set< const Node *> &  nodeset,
const std::vector< std::tuple< dof_id_type, boundary_id_type >> &  bc_tuples 
) const
private

Write the nodal boundary conditions for part of a mesh

Definition at line 687 of file checkpoint_io.C.

References libMesh::Xdr::data(), libMesh::MeshInput< MeshBase >::mesh(), libMesh::MeshOutput< MT >::mesh(), libMesh::MeshBase::node_ptr(), and libMesh::Xdr::writing().

Referenced by write().

690 {
691  libmesh_assert (io.writing());
692 
693  // convenient reference to our mesh
694  const MeshBase & mesh = MeshOutput<MeshBase>::mesh();
695 
696  // Build a list of (node, bc) tuples
697  std::size_t nodeset_size = bc_tuples.size();
698 
699  std::vector<largest_id_type> node_id_list;
700  std::vector<largest_id_type> bc_id_list;
701 
702  node_id_list.reserve(nodeset_size);
703  bc_id_list.reserve(nodeset_size);
704 
705  for (const auto & t : bc_tuples)
706  if (nodeset.count(mesh.node_ptr(std::get<0>(t))))
707  {
708  node_id_list.push_back(std::get<0>(t));
709  bc_id_list.push_back(std::get<1>(t));
710  }
711 
712  io.data(node_id_list, "# node id list");
713  io.data(bc_id_list, "# nodeset bc id list");
714 }
const MT & mesh() const
Definition: mesh_output.h:234
virtual const Node * node_ptr(const dof_id_type i) const =0

◆ write_remote_elem()

void libMesh::CheckpointIO::write_remote_elem ( Xdr io,
const std::set< const Elem *, CompareElemIdsByLevel > &  elements 
) const
private

Write the remote_elem neighbor and child links for part of a mesh

Definition at line 601 of file checkpoint_io.C.

References libMesh::Elem::child_ptr(), libMesh::Xdr::data(), libMesh::Elem::neighbor_ptr(), libMesh::remote_elem, and libMesh::Xdr::writing().

Referenced by write().

603 {
604  libmesh_assert (io.writing());
605 
606  // Find the remote_elem neighbor and child links
607  std::vector<largest_id_type> elem_ids, parent_ids;
608  std::vector<uint16_t> elem_sides, child_numbers;
609 
610  for (const auto & elem : elements)
611  {
612  for (auto n : elem->side_index_range())
613  {
614  const Elem * neigh = elem->neighbor_ptr(n);
615  if (neigh == remote_elem ||
616  (neigh && !elements.count(neigh)))
617  {
618  elem_ids.push_back(elem->id());
619  elem_sides.push_back(n);
620  }
621  }
622 
623 #ifdef LIBMESH_ENABLE_AMR
624  if (elem->has_children())
625  {
626  for (unsigned short c = 0,
627  nc = cast_int<unsigned short>(elem->n_children());
628  c != nc; ++c)
629  {
630  const Elem * child = elem->child_ptr(c);
631  if (child == remote_elem ||
632  (child && !elements.count(child)))
633  {
634  parent_ids.push_back(elem->id());
635  child_numbers.push_back(c);
636  }
637  }
638  }
639 #endif
640  }
641 
642  io.data(elem_ids, "# remote neighbor elem_ids");
643  io.data(elem_sides, "# remote neighbor elem_sides");
644  io.data(parent_ids, "# remote child parent_ids");
645  io.data(child_numbers, "# remote child_numbers");
646 }
const RemoteElem * remote_elem
Definition: remote_elem.C:57

◆ write_subdomain_names()

void libMesh::CheckpointIO::write_subdomain_names ( Xdr io) const
private

Write subdomain name information

Definition at line 457 of file checkpoint_io.C.

References libMesh::Xdr::data(), libMesh::MeshBase::get_subdomain_name_map(), libMesh::MeshInput< MeshBase >::mesh(), and libMesh::MeshOutput< MT >::mesh().

Referenced by write().

458 {
459  {
460  const MeshBase & mesh = MeshOutput<MeshBase>::mesh();
461 
462  const std::map<subdomain_id_type, std::string> & subdomain_map = mesh.get_subdomain_name_map();
463 
464  std::vector<largest_id_type> subdomain_ids; subdomain_ids.reserve(subdomain_map.size());
465  std::vector<std::string> subdomain_names; subdomain_names.reserve(subdomain_map.size());
466 
467  // We need to loop over the map and make sure that there aren't any invalid entries. Since we
468  // return writable references in mesh_base, it's possible for the user to leave some entity names
469  // blank. We can't write those to the XDA file.
470  largest_id_type n_subdomain_names = 0;
471  for (const auto & pr : subdomain_map)
472  if (!pr.second.empty())
473  {
474  n_subdomain_names++;
475  subdomain_ids.push_back(pr.first);
476  subdomain_names.push_back(pr.second);
477  }
478 
479  io.data(n_subdomain_names, "# subdomain id to name map");
480  // Write out the ids and names in two vectors
481  if (n_subdomain_names)
482  {
483  io.data(subdomain_ids);
484  io.data(subdomain_names);
485  }
486  }
487 }
const MT & mesh() const
Definition: mesh_output.h:234
uint64_t largest_id_type
Definition: id_types.h:139
const std::map< subdomain_id_type, std::string > & get_subdomain_name_map() const
Definition: mesh_base.h:1337

Member Data Documentation

◆ _binary

bool libMesh::CheckpointIO::_binary
private

Definition at line 309 of file checkpoint_io.h.

Referenced by binary().

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

◆ _my_n_processors

processor_id_type libMesh::CheckpointIO::_my_n_processors
private

Definition at line 317 of file checkpoint_io.h.

Referenced by current_n_processors(), select_split_config(), and write().

◆ _my_processor_ids

std::vector<processor_id_type> libMesh::CheckpointIO::_my_processor_ids
private

Definition at line 314 of file checkpoint_io.h.

Referenced by current_processor_ids(), and write().

◆ _parallel

bool libMesh::CheckpointIO::_parallel
private

Definition at line 310 of file checkpoint_io.h.

Referenced by parallel(), and write().

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

◆ _version

std::string libMesh::CheckpointIO::_version
private

Definition at line 311 of file checkpoint_io.h.

Referenced by version(), and write().

◆ elems_of_dimension


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