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) libmesh_override
 
virtual void write (const std::string &name) libmesh_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=libmesh_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 > &)
 
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
 
void write_nodesets (Xdr &io, const std::set< const Node * > &nodeset) 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

Definition at line 69 of file checkpoint_io.h.

Constructor & Destructor Documentation

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 156 of file checkpoint_io.C.

156  :
157  MeshInput<MeshBase> (mesh,/* is_parallel_format = */ true),
158  MeshOutput<MeshBase>(mesh,/* is_parallel_format = */ true),
160  _binary (binary_in),
161  _parallel (false),
162  _version ("checkpoint-1.2"),
165 {
166 }
ParallelObject(const Parallel::Communicator &comm_in)
processor_id_type n_processors() const
std::vector< processor_id_type > _my_processor_ids
processor_id_type _my_n_processors
processor_id_type processor_id() const
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 168 of file checkpoint_io.C.

168  :
169  MeshOutput<MeshBase>(mesh,/* is_parallel_format = */ true),
171  _binary (binary_in),
172  _parallel (false),
175 {
176 }
ParallelObject(const Parallel::Communicator &comm_in)
processor_id_type n_processors() const
std::vector< processor_id_type > _my_processor_ids
processor_id_type _my_n_processors
processor_id_type processor_id() const
libMesh::CheckpointIO::~CheckpointIO ( )
virtual

Destructor.

Definition at line 178 of file checkpoint_io.C.

179 {
180 }

Member Function Documentation

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

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.

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

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; }
bool& libMesh::CheckpointIO::binary ( )
inline

Definition at line 146 of file checkpoint_io.h.

References _binary.

146 { return _binary; }
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 241 of file checkpoint_io.C.

242 {
243  auto header = header_file(input_name, n_procs);
244  auto ret = std::remove(header.c_str());
245  if (ret != 0)
246  libmesh_warning("Failed to clean up checkpoint header '" << header << "': " << std::strerror(ret));
247 
248  for (processor_id_type i = 0; i < n_procs; i++)
249  {
250  auto split = split_file(input_name, n_procs, i);
251  auto ret = std::remove(split.c_str());
252  if (ret != 0)
253  libmesh_warning("Failed to clean up checkpoint split file '" << split << "': " << std::strerror(ret));
254  }
255 
256  auto dir = split_dir(input_name, n_procs);
257  ret = rmdir(dir.c_str());
258  if (ret != 0)
259  libmesh_warning("Failed to clean up checkpoint split dir '" << dir << "': " << std::strerror(ret));
260 
261  // We expect that this may fail if there are other split configurations still present in this
262  // directory - so don't bother to check/warn for failure.
263  rmdir(input_name.c_str());
264 }
uint8_t processor_id_type
Definition: id_types.h:99
tbb::split split
Definition: threads_tbb.h:79
const Parallel::Communicator& libMesh::ParallelObject::comm ( ) const
inlineinherited
Returns
A reference to the Parallel::Communicator object used by this mesh.

Definition at line 87 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_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_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::ParmetisPartitioner::_do_repartition(), libMesh::UniformRefinementEstimator::_estimate_error(), libMesh::BoundaryInfo::_find_id_maps(), libMesh::PetscLinearSolver< T >::_petsc_shell_matrix_get_diagonal(), libMesh::SlepcEigenSolver< T >::_petsc_shell_matrix_get_diagonal(), libMesh::PetscLinearSolver< T >::_petsc_shell_matrix_mult(), libMesh::SlepcEigenSolver< 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::ImplicitSystem::add_matrix(), libMesh::System::add_vector(), libMesh::EigenSparseLinearSolver< T >::adjoint_solve(), libMesh::UnstructuredMesh::all_second_order(), libMesh::MeshTools::Modification::all_tri(), libMesh::LaplaceMeshSmoother::allgather_graph(), libMesh::FEMSystem::assemble_qoi(), libMesh::MeshCommunication::assign_global_indices(), libMesh::ParmetisPartitioner::assign_partitioning(), libMesh::DofMap::attach_matrix(), libMesh::Parallel::BinSorter< KeyType, IdxType >::binsort(), libMesh::Parallel::Sort< KeyType, IdxType >::binsort(), libMesh::MeshCommunication::broadcast(), libMesh::SparseMatrix< T >::build(), libMesh::MeshTools::Generation::build_extrusion(), libMesh::Parallel::Histogram< KeyType, IdxType >::build_histogram(), libMesh::PetscNonlinearSolver< T >::build_mat_null_space(), libMesh::BoundaryInfo::build_node_list_from_side_list(), libMesh::EquationSystems::build_parallel_solution_vector(), libMesh::MeshBase::cache_elem_dims(), libMesh::System::calculate_norm(), libMesh::DofMap::check_dirichlet_bcid_consistency(), libMesh::DistributedVector< T >::clone(), libMesh::EigenSparseVector< T >::clone(), libMesh::LaspackVector< T >::clone(), libMesh::EpetraVector< T >::clone(), libMesh::PetscVector< T >::clone(), libMesh::EpetraVector< T >::close(), libMesh::Parallel::Sort< KeyType, IdxType >::communicate_bins(), 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::MeshCommunication::gather(), libMesh::MeshCommunication::gather_neighboring_elements(), libMesh::CondensedEigenSystem::get_eigenpair(), libMesh::DofMap::get_info(), libMesh::ImplicitSystem::get_linear_solver(), libMesh::EquationSystems::get_solution(), libMesh::LocationMap< T >::init(), libMesh::TopologyMap::init(), libMesh::TimeSolver::init(), libMesh::TaoOptimizationSolver< T >::init(), libMesh::PetscNonlinearSolver< T >::init(), libMesh::DistributedVector< T >::init(), libMesh::EpetraVector< T >::init(), libMesh::PetscVector< T >::init(), libMesh::SystemSubsetBySubdomain::init(), libMesh::EigenSystem::init_data(), libMesh::EigenSystem::init_matrices(), libMesh::ParmetisPartitioner::initialize(), libMesh::OptimizationSystem::initialize_equality_constraints_storage(), libMesh::OptimizationSystem::initialize_inequality_constraints_storage(), 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_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::DistributedVector< T >::max(), libMesh::FEMSystem::mesh_position_set(), libMesh::MeshSerializer::MeshSerializer(), libMesh::DistributedVector< T >::min(), 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::Partitioner::partition(), libMesh::LinearPartitioner::partition_range(), libMesh::MetisPartitioner::partition_range(), libMesh::Partitioner::partition_unpartitioned_elements(), libMesh::petsc_auto_fieldsplit(), libMesh::System::point_gradient(), libMesh::System::point_hessian(), libMesh::System::point_value(), libMesh::MeshBase::prepare_for_use(), libMesh::SparseMatrix< T >::print(), libMesh::Nemesis_IO::read(), libMesh::XdrIO::read(), read_header(), libMesh::XdrIO::read_header(), libMesh::XdrIO::read_serialized_bc_names(), 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::MeshBase::recalculate_n_partitions(), libMesh::MeshCommunication::redistribute(), libMesh::MeshRefinement::refine_and_coarsen_elements(), libMesh::DistributedMesh::renumber_dof_objects(), select_split_config(), libMesh::MeshCommunication::send_coarse_ghosts(), libMesh::Partitioner::set_node_processor_ids(), libMesh::DofMap::set_nonlocal_dof_objects(), libMesh::Partitioner::set_parent_processor_ids(), libMesh::PetscDiffSolver::setup_petsc_data(), libMesh::LaplaceMeshSmoother::smooth(), libMesh::Parallel::Sort< KeyType, IdxType >::sort(), libMesh::split_mesh(), libMesh::MeshBase::subdomain_ids(), libMesh::BoundaryInfo::sync(), libMesh::Parallel::sync_element_data_by_parent_id(), libMesh::Parallel::sync_node_data_by_element_id(), libMesh::MeshRefinement::test_level_one(), libMesh::MeshRefinement::test_unflagged(), libMesh::MeshTools::total_weight(), libMesh::MeshRefinement::uniformly_coarsen(), libMesh::NameBasedIO::write(), libMesh::XdrIO::write(), libMesh::XdrIO::write_serialized_bcs_helper(), libMesh::XdrIO::write_serialized_connectivity(), libMesh::XdrIO::write_serialized_nodes(), libMesh::XdrIO::write_serialized_nodesets(), libMesh::DistributedVector< T >::zero_clone(), libMesh::EigenSparseVector< T >::zero_clone(), libMesh::LaspackVector< T >::zero_clone(), libMesh::EpetraVector< T >::zero_clone(), and libMesh::PetscVector< T >::zero_clone().

88  { return _communicator; }
const Parallel::Communicator & _communicator
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
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
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
MeshBase & libMesh::MeshInput< MeshBase >::mesh ( )
protectedinherited
Returns
The object as a writable reference.

Referenced by libMesh::GMVIO::_read_one_cell(), 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::GMVIO::read(), libMesh::ExodusII_IO::read(), libMesh::XdrIO::read(), 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::UCDIO::UCDIO(), libMesh::VTKIO::VTKIO(), libMesh::TetGenIO::write(), libMesh::ExodusII_IO::write(), libMesh::XdrIO::write(), write(), libMesh::GMVIO::write_ascii_new_impl(), libMesh::GMVIO::write_ascii_old_impl(), write_bcs(), libMesh::GMVIO::write_binary(), libMesh::GMVIO::write_discontinuous_gmv(), libMesh::ExodusII_IO::write_element_data(), libMesh::UCDIO::write_implementation(), libMesh::GmshIO::write_mesh(), 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(), 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(), and write_subdomain_names().

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 1273 of file checkpoint_io.C.

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

Referenced by current_n_processors().

1275 {
1276  unsigned int max_level = 0;
1277 
1278  for (MeshBase::const_element_iterator it = begin;
1279  it != end; ++it)
1280  max_level = std::max((*it)->level(), max_level);
1281 
1282  return max_level + 1;
1283 }
IterBase * end
long double max(long double a, double b)
unsigned int max_level(const MeshBase &mesh)
processor_id_type libMesh::ParallelObject::n_processors ( ) const
inlineinherited
Returns
The number of processors in the group.

Definition at line 93 of file parallel_object.h.

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

Referenced by libMesh::ParmetisPartitioner::_do_repartition(), libMesh::BoundaryInfo::_find_id_maps(), libMesh::DistributedMesh::add_elem(), libMesh::DistributedMesh::add_node(), libMesh::LaplaceMeshSmoother::allgather_graph(), libMesh::FEMSystem::assembly(), libMesh::ParmetisPartitioner::assign_partitioning(), libMesh::AztecLinearSolver< T >::AztecLinearSolver(), libMesh::MeshCommunication::broadcast(), libMesh::BoundaryInfo::build_node_list_from_side_list(), libMesh::DistributedMesh::clear(), libMesh::Nemesis_IO_Helper::compute_border_node_ids(), libMesh::Nemesis_IO_Helper::construct_nemesis_filename(), libMesh::MeshTools::correct_node_proc_ids(), 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::DistributedMesh::DistributedMesh(), libMesh::EnsightIO::EnsightIO(), libMesh::MeshCommunication::gather(), libMesh::MeshCommunication::gather_neighboring_elements(), libMesh::MeshBase::get_info(), libMesh::EquationSystems::get_solution(), libMesh::DistributedVector< T >::init(), libMesh::SystemSubsetBySubdomain::init(), libMesh::ParmetisPartitioner::initialize(), libMesh::Nemesis_IO_Helper::initialize(), libMesh::DistributedMesh::insert_elem(), 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::SparsityPattern::Build::parallel_sync(), libMesh::Partitioner::partition(), libMesh::MeshBase::partition(), libMesh::Partitioner::partition_unpartitioned_elements(), libMesh::PetscLinearSolver< T >::PetscLinearSolver(), libMesh::System::point_gradient(), libMesh::System::point_hessian(), libMesh::System::point_value(), libMesh::SparseMatrix< T >::print(), libMesh::NameBasedIO::read(), libMesh::Nemesis_IO::read(), read(), read_connectivity(), libMesh::XdrIO::read_header(), read_nodes(), libMesh::MeshCommunication::redistribute(), libMesh::DistributedMesh::renumber_dof_objects(), libMesh::Partitioner::repartition(), libMesh::MeshCommunication::send_coarse_ghosts(), libMesh::Partitioner::set_node_processor_ids(), libMesh::DofMap::set_nonlocal_dof_objects(), libMesh::Parallel::Sort< KeyType, IdxType >::sort(), libMesh::MeshRefinement::uniformly_coarsen(), libMesh::DistributedMesh::update_parallel_id_counts(), libMesh::GMVIO::write_binary(), libMesh::GMVIO::write_discontinuous_gmv(), libMesh::XdrIO::write_serialized_bcs_helper(), libMesh::XdrIO::write_serialized_connectivity(), libMesh::XdrIO::write_serialized_nodes(), and libMesh::XdrIO::write_serialized_nodesets().

94  { return cast_int<processor_id_type>(_communicator.size()); }
unsigned int size() const
Definition: parallel.h:725
const Parallel::Communicator & _communicator
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; }
bool& libMesh::CheckpointIO::parallel ( )
inline

Definition at line 152 of file checkpoint_io.h.

References _parallel.

152 { return _parallel; }
processor_id_type libMesh::ParallelObject::processor_id ( ) const
inlineinherited
Returns
The rank of this processor in the group.

Definition at line 99 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::DistributedMesh::add_elem(), libMesh::BoundaryInfo::add_elements(), libMesh::DofMap::add_neighbors_to_send_list(), libMesh::DistributedMesh::add_node(), libMesh::MeshRefinement::add_node(), libMesh::MeshTools::Modification::all_tri(), libMesh::FEMSystem::assembly(), libMesh::ParmetisPartitioner::assign_partitioning(), libMesh::MeshCommunication::broadcast(), libMesh::EquationSystems::build_discontinuous_solution_vector(), libMesh::Nemesis_IO_Helper::build_element_and_node_maps(), libMesh::ParmetisPartitioner::build_graph(), libMesh::InfElemBuilder::build_inf_elem(), libMesh::BoundaryInfo::build_node_list_from_side_list(), libMesh::DofMap::build_sparsity(), 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::EnsightIO::EnsightIO(), libMesh::MeshFunction::find_element(), libMesh::MeshFunction::find_elements(), libMesh::UnstructuredMesh::find_neighbors(), libMesh::MeshCommunication::gather(), libMesh::MeshCommunication::gather_neighboring_elements(), 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::EquationSystems::get_solution(), libMesh::Nemesis_IO_Helper::get_ss_param_global(), libMesh::SparsityPattern::Build::handle_vi_vj(), libMesh::DistributedVector< T >::init(), libMesh::SystemSubsetBySubdomain::init(), libMesh::ParmetisPartitioner::initialize(), 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::MeshTools::libmesh_assert_parallel_consistent_procids< Elem >(), libMesh::MeshTools::libmesh_assert_parallel_consistent_procids< Node >(), 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::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::WeightedPatchRecoveryErrorEstimator::EstimateError::operator()(), libMesh::SparsityPattern::Build::operator()(), libMesh::PatchRecoveryErrorEstimator::EstimateError::operator()(), libMesh::SparsityPattern::Build::parallel_sync(), libMesh::MetisPartitioner::partition_range(), libMesh::System::point_gradient(), libMesh::System::point_hessian(), libMesh::System::point_value(), libMesh::SparseMatrix< T >::print(), libMesh::NumericVector< T >::print_global(), 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::ExodusII_IO_Helper::read_node_num_map(), libMesh::XdrIO::read_serialized_bc_names(), 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::MeshCommunication::redistribute(), libMesh::DistributedMesh::renumber_dof_objects(), select_split_config(), libMesh::MeshCommunication::send_coarse_ghosts(), libMesh::Partitioner::set_node_processor_ids(), libMesh::DofMap::set_nonlocal_dof_objects(), libMesh::LaplaceMeshSmoother::smooth(), libMesh::MeshTools::total_weight(), libMesh::MeshRefinement::uniformly_coarsen(), libMesh::Parallel::Packing< Node * >::unpack(), libMesh::Parallel::Packing< Elem * >::unpack(), libMesh::DistributedMesh::update_parallel_id_counts(), libMesh::MeshTools::weight(), 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::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::XdrIO::write_serialized_bc_names(), 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::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().

100  { return cast_int<processor_id_type>(_communicator.rank()); }
const Parallel::Communicator & _communicator
unsigned int rank() const
Definition: parallel.h:723
void libMesh::CheckpointIO::read ( const std::string &  input_name)
virtual

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

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

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

Referenced by current_n_processors().

1246 {
1247  std::map<boundary_id_type, std::string> & boundary_map = is_sideset ?
1248  info.set_sideset_name_map() : info.set_nodeset_name_map();
1249 
1250  std::vector<file_id_type> boundary_ids;
1251  std::vector<std::string> boundary_names;
1252 
1253  file_id_type n_boundary_names = 0;
1254 
1255  if (is_sideset)
1256  io.data(n_boundary_names, "# sideset id to name map");
1257  else
1258  io.data(n_boundary_names, "# nodeset id to name map");
1259 
1260  if (n_boundary_names)
1261  {
1262  io.data(boundary_ids);
1263  io.data(boundary_names);
1264  }
1265 
1266  // Add them back into the map
1267  for (std::size_t i=0; i<boundary_ids.size(); i++)
1268  boundary_map[cast_int<boundary_id_type>(boundary_ids[i])] =
1269  boundary_names[i];
1270 }
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 1197 of file checkpoint_io.C.

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

Referenced by current_n_processors().

1198 {
1199  // convenient reference to our mesh
1200  MeshBase & mesh = MeshInput<MeshBase>::mesh();
1201 
1202  // and our boundary info object
1203  BoundaryInfo & boundary_info = mesh.get_boundary_info();
1204 
1205  std::vector<file_id_type> element_id_list;
1206  std::vector<uint16_t> side_list;
1207  std::vector<file_id_type> bc_id_list;
1208 
1209  io.data(element_id_list, "# element ids for bcs");
1210  io.data(side_list, "# sides of elements for bcs");
1211  io.data(bc_id_list, "# bc ids");
1212 
1213  for (std::size_t i=0; i<element_id_list.size(); i++)
1214  boundary_info.add_side
1215  (cast_int<dof_id_type>(element_id_list[i]), side_list[i],
1216  cast_int<dof_id_type>(bc_id_list[i]));
1217 }
template<typename file_id_type >
void libMesh::CheckpointIO::read_connectivity ( Xdr io)
private

Read the connectivity for a parallel, distributed mesh

Definition at line 1007 of file checkpoint_io.C.

References 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::DofObject::invalid_processor_id, libmesh_nullptr, 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.

Referenced by current_n_processors().

1008 {
1009  // convenient reference to our mesh
1010  MeshBase & mesh = MeshInput<MeshBase>::mesh();
1011 
1012  file_id_type n_elems_here;
1013  io.data(n_elems_here);
1014 
1015  // Keep track of the highest dimensional element we've added to the mesh
1016  unsigned int highest_elem_dim = 1;
1017 
1018  for (unsigned int i=0; i<n_elems_here; i++)
1019  {
1020  // id type pid subdomain_id parent_id
1021  std::vector<file_id_type> elem_data(6);
1022  io.data_stream
1023  (&elem_data[0], cast_int<unsigned int>(elem_data.size()),
1024  cast_int<unsigned int>(elem_data.size()));
1025 
1026 #ifdef LIBMESH_ENABLE_UNIQUE_ID
1027  file_id_type unique_id = 0;
1028  io.data(unique_id, "# unique id");
1029 #endif
1030 
1031 #ifdef LIBMESH_ENABLE_AMR
1032  uint16_t p_level = 0;
1033  io.data(p_level, "# p_level");
1034 
1035  uint16_t rflag, pflag;
1036  io.data(rflag, "# rflag");
1037  io.data(pflag, "# pflag");
1038 #endif
1039 
1040  unsigned int n_nodes = Elem::type_to_n_nodes_map[elem_data[1]];
1041 
1042  // Snag the node ids this element was connected to
1043  std::vector<file_id_type> conn_data(n_nodes);
1044  io.data_stream
1045  (&conn_data[0], cast_int<unsigned int>(conn_data.size()),
1046  cast_int<unsigned int>(conn_data.size()));
1047 
1048  const dof_id_type id =
1049  cast_int<dof_id_type> (elem_data[0]);
1050  const ElemType elem_type =
1051  static_cast<ElemType> (elem_data[1]);
1052  const processor_id_type proc_id =
1053  cast_int<processor_id_type>
1054  (elem_data[2] % mesh.n_processors());
1055  const subdomain_id_type subdomain_id =
1056  cast_int<subdomain_id_type>(elem_data[3]);
1057  const dof_id_type parent_id =
1058  cast_int<dof_id_type> (elem_data[4]);
1059  const unsigned short int child_num =
1060  cast_int<dof_id_type> (elem_data[5]);
1061 
1062  Elem * parent =
1063  (parent_id == DofObject::invalid_processor_id) ?
1064  libmesh_nullptr : mesh.elem_ptr(parent_id);
1065 
1066  if (!parent)
1067  libmesh_assert_equal_to
1068  (child_num, DofObject::invalid_processor_id);
1069 
1070  Elem * old_elem = mesh.query_elem_ptr(id);
1071 
1072  // If we already have this element (e.g. from another file,
1073  // when reading multiple distributed CheckpointIO files into
1074  // a ReplicatedMesh) then we don't want to add it again
1075  // (because ReplicatedMesh can't handle that) but we do want
1076  // to assert consistency between what we're reading and what
1077  // we have.
1078  if (old_elem)
1079  {
1080  libmesh_assert_equal_to(elem_type, old_elem->type());
1081  libmesh_assert_equal_to(proc_id, old_elem->processor_id());
1082  libmesh_assert_equal_to(subdomain_id, old_elem->subdomain_id());
1083  if (parent)
1084  libmesh_assert_equal_to(parent, old_elem->parent());
1085  else
1086  libmesh_assert(!old_elem->parent());
1087 
1088  libmesh_assert_equal_to(old_elem->n_nodes(), conn_data.size());
1089 
1090  for (std::size_t n=0; n != conn_data.size(); ++n)
1091  libmesh_assert_equal_to
1092  (old_elem->node_id(n),
1093  cast_int<dof_id_type>(conn_data[n]));
1094  }
1095  else
1096  {
1097  // Create the element
1098  Elem * elem = Elem::build(elem_type, parent).release();
1099 
1100 #ifdef LIBMESH_ENABLE_UNIQUE_ID
1101  elem->set_unique_id() = unique_id;
1102 #endif
1103 
1104  if (elem->dim() > highest_elem_dim)
1105  highest_elem_dim = elem->dim();
1106 
1107  elem->set_id() = id;
1108  elem->processor_id() = proc_id;
1109  elem->subdomain_id() = subdomain_id;
1110 
1111 #ifdef LIBMESH_ENABLE_AMR
1112  elem->hack_p_level(p_level);
1113 
1114  elem->set_refinement_flag (cast_int<Elem::RefinementState>(rflag));
1115  elem->set_p_refinement_flag(cast_int<Elem::RefinementState>(pflag));
1116 
1117  // Set parent connections
1118  if (parent)
1119  {
1120  // We must specify a child_num, because we will have
1121  // skipped adding any preceding remote_elem children
1122  parent->add_child(elem, child_num);
1123  }
1124 #endif
1125 
1126  libmesh_assert(elem->n_nodes() == conn_data.size());
1127 
1128  // Connect all the nodes to this element
1129  for (std::size_t n=0; n<conn_data.size(); n++)
1130  elem->set_node(n) =
1131  mesh.node_ptr(cast_int<dof_id_type>(conn_data[n]));
1132 
1133  mesh.add_elem(elem);
1134  }
1135  }
1136 
1137  mesh.set_mesh_dimension(cast_int<unsigned char>(highest_elem_dim));
1138 }
TestClass subdomain_id_type
Definition: id_types.h:43
uint8_t processor_id_type
Definition: id_types.h:99
const class libmesh_nullptr_t libmesh_nullptr
static const unsigned int type_to_n_nodes_map[INVALID_ELEM]
Definition: elem.h:565
const dof_id_type n_nodes
Definition: tecplot_io.C:67
static const processor_id_type invalid_processor_id
Definition: dof_object.h:335
static std::unique_ptr< Elem > build(const ElemType type, Elem *p=libmesh_nullptr)
Definition: elem.C:239
uint8_t dof_id_type
Definition: id_types.h:64
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 814 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< MT >::mesh(), libMesh::MeshInput< MeshBase >::mesh(), 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().

Referenced by current_n_processors().

815 {
816  MeshBase & mesh = MeshInput<MeshBase>::mesh();
817 
818  // Hack for codes which don't look at all elem dimensions
819  uint16_t mesh_dimension;
820 
821  // Will this be a parallel input file? With how many processors? Stay tuned!
822  uint16_t input_parallel;
823  file_id_type input_n_procs;
824 
825  // We'll write a header file from processor 0 and broadcast.
826  if (this->processor_id() == 0)
827  {
828  Xdr io (name, this->binary() ? DECODE : READ);
829 
830  // read the version, but don't care about it
831  std::string input_version;
832  io.data(input_version);
833 
834  // read the data type, don't care about it this time
835  header_id_type data_size;
836  io.data (data_size);
837 
838  // read the dimension
839  io.data (mesh_dimension);
840 
841  // Read whether or not this is a parallel file
842  io.data(input_parallel);
843 
844  // With how many processors?
845  if (input_parallel)
846  io.data(input_n_procs);
847 
848  // read subdomain names
849  this->read_subdomain_names<file_id_type>(io);
850 
851  // read boundary names
852  BoundaryInfo & boundary_info = mesh.get_boundary_info();
853 
854  this->read_bc_names<file_id_type>(io, boundary_info, true); // sideset names
855  this->read_bc_names<file_id_type>(io, boundary_info, false); // nodeset names
856  }
857 
858  // broadcast data from processor 0, set values everywhere
859  this->comm().broadcast(mesh_dimension);
860  mesh.set_mesh_dimension(mesh_dimension);
861 
862  this->comm().broadcast(input_parallel);
863 
864  if (input_parallel)
865  this->comm().broadcast(input_n_procs);
866  else
867  input_n_procs = 1;
868 
869  std::map<subdomain_id_type, std::string> & subdomain_map =
870  mesh.set_subdomain_name_map();
871  this->comm().broadcast(subdomain_map);
872 
873  BoundaryInfo & boundary_info = mesh.get_boundary_info();
874  this->comm().broadcast(boundary_info.set_sideset_name_map());
875  this->comm().broadcast(boundary_info.set_nodeset_name_map());
876 
877  return input_parallel ? input_n_procs : 0;
878 }
std::string name(const ElemQuality q)
Definition: elem_quality.C:39
void broadcast(T &data, const unsigned int root_id=0) const
const Parallel::Communicator & comm() const
bool binary() const
processor_id_type processor_id() const
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 934 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().

Referenced by current_n_processors().

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

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

Referenced by current_n_processors().

1223 {
1224  // convenient reference to our mesh
1225  MeshBase & mesh = MeshInput<MeshBase>::mesh();
1226 
1227  // and our boundary info object
1228  BoundaryInfo & boundary_info = mesh.get_boundary_info();
1229 
1230  std::vector<file_id_type> node_id_list;
1231  std::vector<file_id_type> bc_id_list;
1232 
1233  io.data(node_id_list, "# node id list");
1234  io.data(bc_id_list, "# nodeset bc id list");
1235 
1236  for (std::size_t i=0; i<node_id_list.size(); i++)
1237  boundary_info.add_node
1238  (cast_int<dof_id_type>(node_id_list[i]),
1239  cast_int<boundary_id_type>(bc_id_list[i]));
1240 }
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.

Referenced by current_n_processors().

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

Definition at line 1142 of file checkpoint_io.C.

References libMesh::Elem::add_child(), libMesh::Xdr::data(), libMesh::MeshBase::elem_ref(), 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().

1143 {
1144  // convenient reference to our mesh
1145  MeshBase & mesh = MeshInput<MeshBase>::mesh();
1146 
1147  // Find the remote_elem neighbor links
1148  std::vector<file_id_type> elem_ids;
1149  std::vector<uint16_t> elem_sides;
1150 
1151  io.data(elem_ids, "# remote neighbor elem_ids");
1152  io.data(elem_sides, "# remote neighbor elem_sides");
1153 
1154  libmesh_assert_equal_to(elem_ids.size(), elem_sides.size());
1155 
1156  for (std::size_t i=0; i != elem_ids.size(); ++i)
1157  {
1158  Elem & elem = mesh.elem_ref(cast_int<dof_id_type>(elem_ids[i]));
1159  if (!elem.neighbor_ptr(elem_sides[i]))
1160  elem.set_neighbor(elem_sides[i],
1161  const_cast<RemoteElem *>(remote_elem));
1162  else
1163  libmesh_assert(!expect_all_remote);
1164  }
1165 
1166  // Find the remote_elem children links
1167  std::vector<file_id_type> parent_ids;
1168  std::vector<uint16_t> child_numbers;
1169 
1170  io.data(parent_ids, "# remote child parent_ids");
1171  io.data(child_numbers, "# remote child_numbers");
1172 
1173 #ifdef LIBMESH_ENABLE_AMR
1174  for (std::size_t i=0; i != parent_ids.size(); ++i)
1175  {
1176  Elem & elem = mesh.elem_ref(cast_int<dof_id_type>(parent_ids[i]));
1177 
1178  // We'd like to assert that no child pointer already exists to
1179  // be overwritten by remote_elem, but Elem doesn't actually have
1180  // an API that will return a child pointer without asserting
1181  // that it isn't NULL
1182  //
1183  const Elem * child = elem.raw_child_ptr(child_numbers[i]);
1184 
1185  if (!child)
1186  elem.add_child(const_cast<RemoteElem *>(remote_elem),
1187  child_numbers[i]);
1188  else
1189  libmesh_assert(!expect_all_remote);
1190  }
1191 #endif
1192 }
const RemoteElem * remote_elem
Definition: remote_elem.C:57
template<typename file_id_type >
void libMesh::CheckpointIO::read_subdomain_names ( Xdr io)
private

Read subdomain name information

Definition at line 904 of file checkpoint_io.C.

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

Referenced by current_n_processors().

905 {
906  MeshBase & mesh = MeshInput<MeshBase>::mesh();
907 
908  std::map<subdomain_id_type, std::string> & subdomain_map =
909  mesh.set_subdomain_name_map();
910 
911  std::vector<file_id_type> subdomain_ids;
912  subdomain_ids.reserve(subdomain_map.size());
913 
914  std::vector<std::string> subdomain_names;
915  subdomain_names.reserve(subdomain_map.size());
916 
917  file_id_type n_subdomain_names = 0;
918  io.data(n_subdomain_names, "# subdomain id to name map");
919 
920  if (n_subdomain_names)
921  {
922  io.data(subdomain_ids);
923  io.data(subdomain_names);
924 
925  for (std::size_t i=0; i<subdomain_ids.size(); i++)
926  subdomain_map[cast_int<subdomain_id_type>(subdomain_ids[i])] =
927  subdomain_names[i];
928  }
929 }
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 883 of file checkpoint_io.C.

Referenced by current_n_processors().

884 {
885  // read the nodal locations
886  this->read_nodes<file_id_type> (io);
887 
888  // read connectivity
889  this->read_connectivity<file_id_type> (io);
890 
891  // read remote_elem connectivity
892  this->read_remote_elem<file_id_type> (io, expect_all_remote);
893 
894  // read the boundary conditions
895  this->read_bcs<file_id_type> (io);
896 
897  // read the nodesets
898  this->read_nodesets<file_id_type> (io);
899 }
processor_id_type libMesh::CheckpointIO::select_split_config ( const std::string &  input_name,
header_id_type data_size 
)
private

Definition at line 182 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 current_n_processors(), and read().

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

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

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; }
std::string& libMesh::CheckpointIO::version ( )
inline

Definition at line 158 of file checkpoint_io.h.

References _version.

158 { return _version; }
void libMesh::CheckpointIO::write ( const std::string &  name)
virtual

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 266 of file checkpoint_io.C.

References _my_n_processors, _my_processor_ids, _parallel, _version, binary(), libMesh::Xdr::close(), libMesh::connect_children(), libMesh::connect_families(), libMesh::Xdr::data(), 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(), 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().

267 {
268  LOG_SCOPE("write()", "CheckpointIO");
269 
270  // convenient reference to our mesh
271  const MeshBase & mesh = MeshOutput<MeshBase>::mesh();
272 
273  // FIXME: For backwards compatibility, we'll assume for now that we
274  // only want to write distributed meshes in parallel. Later we can
275  // do a gather_to_zero() and support that case too.
276  _parallel = _parallel || !mesh.is_serial();
277 
278  processor_id_type use_n_procs = 1;
279  if (_parallel)
280  use_n_procs = _my_n_processors;
281 
282  std::string header_file_name = header_file(name, use_n_procs);
283  make_dir(name, use_n_procs);
284 
285  // We'll write a header file from processor 0 to make it easier to do unambiguous
286  // restarts later:
287  if (this->processor_id() == 0)
288  {
289  Xdr io (header_file_name, this->binary() ? ENCODE : WRITE);
290 
291  // write the version
292  io.data(_version, "# version");
293 
294  // write what kind of data type we're using
295  header_id_type data_size = sizeof(largest_id_type);
296  io.data(data_size, "# integer size");
297 
298  // Write out the max mesh dimension for backwards compatibility
299  // with code that sets it independently of element dimensions
300  {
301  uint16_t mesh_dimension = mesh.mesh_dimension();
302  io.data(mesh_dimension, "# dimensions");
303  }
304 
305  // Write out whether or not this is serial output
306  {
307  uint16_t parallel = _parallel;
308  io.data(parallel, "# parallel");
309  }
310 
311  // If we're writing out a parallel mesh then we need to write the number of processors
312  // so we can check it upon reading the file
313  if (_parallel)
314  {
316  io.data(n_procs, "# n_procs");
317  }
318 
319  // write subdomain names
320  this->write_subdomain_names(io);
321 
322  // write boundary id names
323  const BoundaryInfo & boundary_info = mesh.get_boundary_info();
324  write_bc_names(io, boundary_info, true); // sideset names
325  write_bc_names(io, boundary_info, false); // nodeset names
326  }
327 
328  // If this is a serial mesh written to a serial file then we're only
329  // going to write local data from processor 0. If this is a mesh being
330  // written in parallel then we're going to write from every
331  // processor.
332  std::vector<processor_id_type> ids_to_write;
333 
334  if (_parallel)
335  {
336  ids_to_write = _my_processor_ids;
337  }
338  else if (mesh.is_serial())
339  {
340  if (mesh.processor_id() == 0)
341  {
342  // placeholder
343  ids_to_write.push_back(0);
344  }
345  }
346  else
347  {
348  libmesh_error_msg("Cannot write serial checkpoint from distributed mesh");
349  }
350 
351  for (std::vector<processor_id_type>::const_iterator
352  id_it = ids_to_write.begin(), id_end = ids_to_write.end();
353  id_it != id_end; ++id_it)
354  {
355  const processor_id_type my_pid = *id_it;
356 
357  auto file_name = split_file(name, use_n_procs, my_pid);
358  Xdr io (file_name, this->binary() ? ENCODE : WRITE);
359 
360  std::set<const Elem *, CompareElemIdsByLevel> elements;
361 
362  // For serial files or for already-distributed meshs, we write
363  // everything we can see.
364  if (!_parallel || !mesh.is_serial())
365  elements.insert(mesh.elements_begin(), mesh.elements_end());
366  // For parallel files written from serial meshes we write what
367  // we'd be required to keep if we were to be deleting remote
368  // elements. This allows us to write proper parallel files even
369  // from a ReplicateMesh.
370  //
371  // WARNING: If we have a DistributedMesh which used
372  // "add_extra_ghost_elem" rather than ghosting functors to
373  // preserve elements and which is *also* currently serialized
374  // then we're not preserving those elements here. As a quick
375  // workaround user code should delete_remote_elements() before
376  // writing the checkpoint; as a long term workaround user code
377  // should use ghosting functors instead of extra_ghost_elem
378  // lists.
379  else
380  {
381  query_ghosting_functors(mesh, my_pid, false, elements);
383  connect_children(mesh, my_pid, elements);
385  connect_families(elements);
386  }
387 
388  std::set<const Node *> connected_nodes;
389  reconnect_nodes(elements, connected_nodes);
390 
391  // write the nodal locations
392  this->write_nodes (io, connected_nodes);
393 
394  // write connectivity
395  this->write_connectivity (io, elements);
396 
397  // write remote_elem connectivity
398  this->write_remote_elem (io, elements);
399 
400  // write the boundary condition information
401  this->write_bcs (io, elements);
402 
403  // write the nodeset information
404  this->write_nodesets (io, connected_nodes);
405 
406  // close it up
407  io.close();
408  }
409 
410  // this->comm().barrier();
411 }
std::string name(const ElemQuality q)
Definition: elem_quality.C:39
void write_nodes(Xdr &io, const std::set< const Node * > &nodeset) const
void write_nodesets(Xdr &io, const std::set< const Node * > &nodeset) const
void write_connectivity(Xdr &io, const std::set< const Elem *, CompareElemIdsByLevel > &elements) const
void connect_children(const MeshBase &mesh, processor_id_type pid, std::set< const Elem *, CompareElemIdsByLevel > &connected_elements)
void reconnect_nodes(const std::set< const Elem *, CompareElemIdsByLevel > &connected_elements, std::set< const Node * > &connected_nodes)
uint64_t largest_id_type
Definition: id_types.h:139
uint8_t processor_id_type
Definition: id_types.h:99
const MT & mesh() const
Definition: mesh_output.h:216
bool parallel() const
std::vector< processor_id_type > _my_processor_ids
void write_remote_elem(Xdr &io, const std::set< const Elem *, CompareElemIdsByLevel > &elements) const
void write_bc_names(Xdr &io, const BoundaryInfo &info, bool is_sideset) const
void write_subdomain_names(Xdr &io) const
static const processor_id_type invalid_processor_id
Definition: dof_object.h:335
processor_id_type _my_n_processors
void connect_families(std::set< const Elem *, CompareElemIdsByLevel > &connected_elements)
void write_bcs(Xdr &io, const std::set< const Elem *, CompareElemIdsByLevel > &elements) const
void query_ghosting_functors(const MeshBase &mesh, processor_id_type pid, bool newly_coarsened_only, std::set< const Elem *, CompareElemIdsByLevel > &connected_elements)
bool binary() const
processor_id_type processor_id() const
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 700 of file checkpoint_io.C.

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

Referenced by current_n_processors(), and write().

701 {
702  const std::map<boundary_id_type, std::string> & boundary_map = is_sideset ?
703  info.get_sideset_name_map() : info.get_nodeset_name_map();
704 
705  std::vector<largest_id_type> boundary_ids; boundary_ids.reserve(boundary_map.size());
706  std::vector<std::string> boundary_names; boundary_names.reserve(boundary_map.size());
707 
708  // We need to loop over the map and make sure that there aren't any invalid entries. Since we
709  // return writable references in boundary_info, it's possible for the user to leave some entity names
710  // blank. We can't write those to the XDA file.
711  largest_id_type n_boundary_names = 0;
712  std::map<boundary_id_type, std::string>::const_iterator it_end = boundary_map.end();
713  for (std::map<boundary_id_type, std::string>::const_iterator it = boundary_map.begin(); it != it_end; ++it)
714  {
715  if (!it->second.empty())
716  {
717  n_boundary_names++;
718  boundary_ids.push_back(it->first);
719  boundary_names.push_back(it->second);
720  }
721  }
722 
723  if (is_sideset)
724  io.data(n_boundary_names, "# sideset id to name map");
725  else
726  io.data(n_boundary_names, "# nodeset id to name map");
727  // Write out the ids and names in two vectors
728  if (n_boundary_names)
729  {
730  io.data(boundary_ids);
731  io.data(boundary_names);
732  }
733 }
uint64_t largest_id_type
Definition: id_types.h:139
void libMesh::CheckpointIO::write_bcs ( Xdr io,
const std::set< const Elem *, CompareElemIdsByLevel > &  elements 
) const
private

Write the side boundary conditions for part of a mesh

Definition at line 617 of file checkpoint_io.C.

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

Referenced by current_n_processors(), and write().

619 {
620  libmesh_assert (io.writing());
621 
622  // convenient reference to our mesh
623  const MeshBase & mesh = MeshOutput<MeshBase>::mesh();
624 
625  // and our boundary info object
626  const BoundaryInfo & boundary_info = mesh.get_boundary_info();
627 
628  std::vector<dof_id_type> full_element_id_list;
629  std::vector<uint16_t> full_side_list;
630  std::vector<boundary_id_type> full_bc_id_list;
631 
632  boundary_info.build_side_list(full_element_id_list, full_side_list, full_bc_id_list);
633 
634  std::size_t bc_size = full_element_id_list.size();
635  libmesh_assert_equal_to(bc_size, full_side_list.size());
636  libmesh_assert_equal_to(bc_size, full_bc_id_list.size());
637 
638  std::vector<largest_id_type> element_id_list;
639  std::vector<uint16_t> side_list;
640  std::vector<largest_id_type> bc_id_list;
641 
642  element_id_list.reserve(bc_size);
643  side_list.reserve(bc_size);
644  bc_id_list.reserve(bc_size);
645 
646  for (std::size_t i = 0; i != bc_size; ++i)
647  if (elements.count(mesh.elem_ptr(full_element_id_list[i])))
648  {
649  element_id_list.push_back(full_element_id_list[i]);
650  side_list.push_back(full_side_list[i]);
651  bc_id_list.push_back(full_bc_id_list[i]);
652  }
653 
654 
655  io.data(element_id_list, "# element ids for bcs");
656  io.data(side_list, "# sides of elements for bcs");
657  io.data(bc_id_list, "# bc ids");
658 }
const MT & mesh() const
Definition: mesh_output.h:216
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 495 of file checkpoint_io.C.

References libMesh::Xdr::data(), libMesh::Xdr::data_stream(), end, libMesh::DofObject::id(), libMesh::DofObject::invalid_processor_id, libmesh_nullptr, n_nodes, libMesh::Elem::n_nodes(), libMesh::Elem::node_id(), libMesh::Elem::p_level(), libMesh::Elem::p_refinement_flag(), libMesh::Elem::parent(), libMesh::DofObject::processor_id(), libMesh::Elem::refinement_flag(), libMesh::Elem::subdomain_id(), libMesh::Elem::type(), libMesh::DofObject::unique_id(), libMesh::Elem::which_child_am_i(), and libMesh::Xdr::writing().

Referenced by current_n_processors(), and write().

497 {
498  libmesh_assert (io.writing());
499 
500  // Put these out here to reduce memory churn
501  // id type pid subdomain_id parent_id
502  std::vector<largest_id_type> elem_data(6);
503  std::vector<largest_id_type> conn_data;
504 
505  largest_id_type n_elems_here = elements.size();
506 
507  io.data(n_elems_here, "# number of elements");
508 
509  for (std::set<const Elem *, CompareElemIdsByLevel>::const_iterator it = elements.begin(),
510  end = elements.end(); it != end; ++it)
511  {
512  const Elem & elem = **it;
513 
514  unsigned int n_nodes = elem.n_nodes();
515 
516  elem_data[0] = elem.id();
517  elem_data[1] = elem.type();
518  elem_data[2] = elem.processor_id();
519  elem_data[3] = elem.subdomain_id();
520 
521 #ifdef LIBMESH_ENABLE_AMR
522  if (elem.parent() != libmesh_nullptr)
523  {
524  elem_data[4] = elem.parent()->id();
525  elem_data[5] = elem.parent()->which_child_am_i(&elem);
526  }
527  else
528 #endif
529  {
530  elem_data[4] = DofObject::invalid_processor_id;
531  elem_data[5] = DofObject::invalid_processor_id;
532  }
533 
534  conn_data.resize(n_nodes);
535 
536  for (unsigned int i=0; i<n_nodes; i++)
537  conn_data[i] = elem.node_id(i);
538 
539  io.data_stream(&elem_data[0],
540  cast_int<unsigned int>(elem_data.size()),
541  cast_int<unsigned int>(elem_data.size()));
542 
543 #ifdef LIBMESH_ENABLE_UNIQUE_ID
544  largest_id_type unique_id = elem.unique_id();
545 
546  io.data(unique_id, "# unique id");
547 #endif
548 
549 #ifdef LIBMESH_ENABLE_AMR
550  uint16_t p_level = elem.p_level();
551  io.data(p_level, "# p_level");
552 
553  uint16_t rflag = elem.refinement_flag();
554  io.data(rflag, "# rflag");
555 
556  uint16_t pflag = elem.p_refinement_flag();
557  io.data(pflag, "# pflag");
558 #endif
559  io.data_stream(&conn_data[0],
560  cast_int<unsigned int>(conn_data.size()),
561  cast_int<unsigned int>(conn_data.size()));
562  }
563 }
uint64_t largest_id_type
Definition: id_types.h:139
const class libmesh_nullptr_t libmesh_nullptr
IterBase * end
const dof_id_type n_nodes
Definition: tecplot_io.C:67
static const processor_id_type invalid_processor_id
Definition: dof_object.h:335
virtual void libMesh::MeshOutput< MeshBase >::write_equation_systems ( const std::string &  ,
const EquationSystems ,
const std::set< std::string > *  system_names = libmesh_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.

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

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::NameBasedIO, libMesh::GmshIO, libMesh::Nemesis_IO, libMesh::VTKIO, libMesh::UCDIO, libMesh::GMVIO, libMesh::MEDITIO, libMesh::GnuPlotIO, and libMesh::TecplotIO.

Definition at line 96 of file mesh_output.h.

References libMesh::MeshOutput< MT >::ascii_precision(), libMesh::MeshOutput< MT >::mesh(), and libMesh::MeshOutput< MT >::write_nodal_data().

99  { libmesh_not_implemented(); }
virtual void libMesh::MeshOutput< MeshBase >::write_nodal_data ( const std::string &  ,
const NumericVector< Number > &  ,
const std::vector< std::string > &   
)
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.

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 450 of file checkpoint_io.C.

References libMesh::Xdr::data(), libMesh::Xdr::data_stream(), end, libMesh::DofObject::id(), libMesh::DofObject::processor_id(), and libMesh::DofObject::unique_id().

Referenced by current_n_processors(), and write().

452 {
453  largest_id_type n_nodes_here = nodeset.size();
454 
455  io.data(n_nodes_here, "# n_nodes on proc");
456 
457  // Will hold the node id and pid
458  std::vector<largest_id_type> id_pid(2);
459 
460  // For the coordinates
461  std::vector<Real> coords(LIBMESH_DIM);
462 
463  for (std::set<const Node *>::iterator it = nodeset.begin(),
464  end = nodeset.end(); it != end; ++it)
465  {
466  const Node & node = **it;
467 
468  id_pid[0] = node.id();
469  id_pid[1] = node.processor_id();
470 
471  io.data_stream(&id_pid[0], 2, 2);
472 
473 #ifdef LIBMESH_ENABLE_UNIQUE_ID
474  largest_id_type unique_id = node.unique_id();
475 
476  io.data(unique_id, "# unique id");
477 #endif
478 
479  coords[0] = node(0);
480 
481 #if LIBMESH_DIM > 1
482  coords[1] = node(1);
483 #endif
484 
485 #if LIBMESH_DIM > 2
486  coords[2] = node(2);
487 #endif
488 
489  io.data_stream(&coords[0], LIBMESH_DIM, 3);
490  }
491 }
uint64_t largest_id_type
Definition: id_types.h:139
IterBase * end
void libMesh::CheckpointIO::write_nodesets ( Xdr io,
const std::set< const Node * > &  nodeset 
) const
private

Write the nodal boundary conditions for part of a mesh

Definition at line 662 of file checkpoint_io.C.

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

Referenced by current_n_processors(), and write().

664 {
665  libmesh_assert (io.writing());
666 
667  // convenient reference to our mesh
668  const MeshBase & mesh = MeshOutput<MeshBase>::mesh();
669 
670  // and our boundary info object
671  const BoundaryInfo & boundary_info = mesh.get_boundary_info();
672 
673  std::vector<dof_id_type> full_node_id_list;
674  std::vector<boundary_id_type> full_bc_id_list;
675 
676  boundary_info.build_node_list(full_node_id_list, full_bc_id_list);
677 
678  std::size_t nodeset_size = full_node_id_list.size();
679  libmesh_assert_equal_to(nodeset_size, full_bc_id_list.size());
680 
681  std::vector<largest_id_type> node_id_list;
682  std::vector<largest_id_type> bc_id_list;
683 
684  node_id_list.reserve(nodeset_size);
685  bc_id_list.reserve(nodeset_size);
686 
687  for (std::size_t i = 0; i != nodeset_size; ++i)
688  if (nodeset.count(mesh.node_ptr(full_node_id_list[i])))
689  {
690  node_id_list.push_back(full_node_id_list[i]);
691  bc_id_list.push_back(full_bc_id_list[i]);
692  }
693 
694  io.data(node_id_list, "# node id list");
695  io.data(bc_id_list, "# nodeset bc id list");
696 }
const MT & mesh() const
Definition: mesh_output.h:216
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 566 of file checkpoint_io.C.

References libMesh::Elem::child_ptr(), libMesh::Xdr::data(), end, libMesh::Elem::has_children(), libMesh::DofObject::id(), libMesh::Elem::n_children(), libMesh::Elem::neighbor_ptr(), libMesh::remote_elem, libMesh::Elem::side_index_range(), and libMesh::Xdr::writing().

Referenced by current_n_processors(), and write().

568 {
569  libmesh_assert (io.writing());
570 
571  // Find the remote_elem neighbor and child links
572  std::vector<largest_id_type> elem_ids, parent_ids;
573  std::vector<uint16_t> elem_sides, child_numbers;
574 
575  for (std::set<const Elem *, CompareElemIdsByLevel>::const_iterator it = elements.begin(),
576  end = elements.end(); it != end; ++it)
577  {
578  const Elem & elem = **it;
579 
580  for (auto n : elem.side_index_range())
581  {
582  const Elem * neigh = elem.neighbor_ptr(n);
583  if (neigh == remote_elem ||
584  (neigh && !elements.count(neigh)))
585  {
586  elem_ids.push_back(elem.id());
587  elem_sides.push_back(n);
588  }
589  }
590 
591 #ifdef LIBMESH_ENABLE_AMR
592  if (elem.has_children())
593  {
594  const unsigned int nc = elem.n_children();
595  for (unsigned int c = 0; c != nc; ++c)
596  {
597  const Elem * child = elem.child_ptr(c);
598  if (child == remote_elem ||
599  (child && !elements.count(child)))
600  {
601  parent_ids.push_back(elem.id());
602  child_numbers.push_back(c);
603  }
604  }
605  }
606 #endif
607  }
608 
609  io.data(elem_ids, "# remote neighbor elem_ids");
610  io.data(elem_sides, "# remote neighbor elem_sides");
611  io.data(parent_ids, "# remote child parent_ids");
612  io.data(child_numbers, "# remote child_numbers");
613 }
IterBase * end
const RemoteElem * remote_elem
Definition: remote_elem.C:57
void libMesh::CheckpointIO::write_subdomain_names ( Xdr io) const
private

Write subdomain name information

Definition at line 413 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 current_n_processors(), and write().

414 {
415  {
416  const MeshBase & mesh = MeshOutput<MeshBase>::mesh();
417 
418  const std::map<subdomain_id_type, std::string> & subdomain_map = mesh.get_subdomain_name_map();
419 
420  std::vector<largest_id_type> subdomain_ids; subdomain_ids.reserve(subdomain_map.size());
421  std::vector<std::string> subdomain_names; subdomain_names.reserve(subdomain_map.size());
422 
423  // We need to loop over the map and make sure that there aren't any invalid entries. Since we
424  // return writable references in mesh_base, it's possible for the user to leave some entity names
425  // blank. We can't write those to the XDA file.
426  largest_id_type n_subdomain_names = 0;
427  std::map<subdomain_id_type, std::string>::const_iterator it_end = subdomain_map.end();
428  for (std::map<subdomain_id_type, std::string>::const_iterator it = subdomain_map.begin(); it != it_end; ++it)
429  {
430  if (!it->second.empty())
431  {
432  n_subdomain_names++;
433  subdomain_ids.push_back(it->first);
434  subdomain_names.push_back(it->second);
435  }
436  }
437 
438  io.data(n_subdomain_names, "# subdomain id to name map");
439  // Write out the ids and names in two vectors
440  if (n_subdomain_names)
441  {
442  io.data(subdomain_ids);
443  io.data(subdomain_names);
444  }
445  }
446 }
uint64_t largest_id_type
Definition: id_types.h:139
const MT & mesh() const
Definition: mesh_output.h:216

Member Data Documentation

bool libMesh::CheckpointIO::_binary
private

Definition at line 307 of file checkpoint_io.h.

Referenced by binary().

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 141 of file mesh_output.h.

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

processor_id_type libMesh::CheckpointIO::_my_n_processors
private

Definition at line 315 of file checkpoint_io.h.

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

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

Definition at line 312 of file checkpoint_io.h.

Referenced by current_processor_ids(), and write().

bool libMesh::CheckpointIO::_parallel
private

Definition at line 308 of file checkpoint_io.h.

Referenced by parallel(), and write().

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 150 of file mesh_output.h.

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

Definition at line 309 of file checkpoint_io.h.

Referenced by version(), and write().


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