19 #include "libmesh/checkpoint_io.h" 20 #include "libmesh/boundary_info.h" 21 #include "libmesh/distributed_mesh.h" 22 #include "libmesh/elem.h" 23 #include "libmesh/enum_xdr_mode.h" 24 #include "libmesh/libmesh_logging.h" 25 #include "libmesh/mesh_base.h" 26 #include "libmesh/mesh_communication.h" 27 #include "libmesh/mesh_tools.h" 28 #include "libmesh/node.h" 29 #include "libmesh/parallel.h" 30 #include "libmesh/partitioner.h" 31 #include "libmesh/metis_partitioner.h" 32 #include "libmesh/remote_elem.h" 33 #include "libmesh/xdr_io.h" 34 #include "libmesh/xdr_cxx.h" 35 #include "libmesh/utility.h" 36 #include "libmesh/int_range.h" 47 #include <unordered_map> 48 #include <unordered_set> 49 #ifdef LIBMESH_HAVE_DIRECT_H 52 #ifdef LIBMESH_HAVE_UNISTD_H 64 if (nsplits % size == 0)
66 nchunks = nsplits / size;
67 first_chunk = libMesh::cast_int<libMesh::processor_id_type>(nchunks * rank);
74 nchunks = libMesh::cast_int<libMesh::processor_id_type>(nsplits / size + 1);
75 first_chunk = libMesh::cast_int<libMesh::processor_id_type>(nchunks * rank);
79 nchunks = nsplits / size;
81 first_chunk = libMesh::cast_int<libMesh::processor_id_type>
82 (std::max((
int)((nchunks + 1) * (nsplits % size) + nchunks * (rank - nsplits % size)),
83 (1 - (
int)nchunks) * std::numeric_limits<int>::max()));
87 std::string_view extension(std::string_view s)
89 auto pos = s.rfind(
".");
90 if (pos == std::string::npos)
92 return s.substr(pos, s.size() - pos);
97 return input_name +
"/" + std::to_string(n_procs);
103 return (split_dir(input_name, n_procs) +
"/header").append(extension(input_name));
107 split_file(
const std::string & input_name,
111 return (split_dir(input_name, n_procs) +
"/split-" + std::to_string(n_procs) +
"-" +
112 std::to_string(proc_id)).append(extension(input_name));
120 (ret != 0 && ret != -1,
121 "Failed to create mesh split directory '" << input_name <<
"': " << std::strerror(ret));
123 auto dir_name = split_dir(input_name, n_procs);
126 libmesh_warning(
"In CheckpointIO::write, directory '" 127 << dir_name <<
"' already exists, overwriting contents.");
130 (ret != 0,
"Failed to create mesh split directory '" << dir_name <<
"': " << std::strerror(ret));
152 auto cpr = std::make_unique<CheckpointIO>(
mesh);
153 cpr->current_processor_ids().clear();
154 for (
processor_id_type i = my_first_chunk; i < my_first_chunk + my_num_chunks; i++)
155 cpr->current_processor_ids().push_back(i);
156 cpr->current_n_processors() = nsplits;
157 cpr->parallel() =
true;
170 _version (
"checkpoint-1.5"),
171 _my_processor_ids (1, processor_id()),
172 _my_n_processors (
mesh.is_replicated() ? 1 : n_processors())
182 _version (
"checkpoint-1.5"),
183 _my_processor_ids (1, processor_id()),
184 _my_n_processors (
mesh.is_replicated() ? 1 : n_processors())
192 std::string header_name;
201 std::ifstream in (header_name.c_str());
205 auto orig_header_name = header_name;
206 header_name = header_file(input_name, 1);
207 std::ifstream in2 (header_name.c_str());
208 libmesh_error_msg_if(!in2.good(),
209 "ERROR: Neither one of the following files can be located:\n\t'" 210 << orig_header_name <<
"' nor\n\t'" << input_name <<
"'\n" 211 <<
"If you are running a parallel job, double check that you've " 213 <<
"Note: One of paths above may refer to a valid directory on your " 214 <<
"system, however we are attempting to read a valid header file.");
221 std::string input_version;
222 io.
data(input_version);
236 input_n_procs = this->read_header<uint16_t>(header_name);
239 input_n_procs = this->read_header<uint32_t>(header_name);
242 input_n_procs = this->read_header<uint64_t>(header_name);
250 return cast_int<processor_id_type>(input_n_procs);
255 auto header = header_file(input_name, n_procs);
256 auto ret = std::remove(header.c_str());
258 libmesh_warning(
"Failed to clean up checkpoint header '" << header <<
"': " << std::strerror(ret));
262 auto split = split_file(input_name, n_procs, i);
263 ret = std::remove(
split.c_str());
265 libmesh_warning(
"Failed to clean up checkpoint split file '" <<
split <<
"': " << std::strerror(ret));
268 auto dir = split_dir(input_name, n_procs);
269 ret = rmdir(dir.c_str());
271 libmesh_warning(
"Failed to clean up checkpoint split dir '" << dir <<
"': " << std::strerror(ret));
275 rmdir(input_name.c_str());
281 return (this->
version().find(
"1.5") != std::string::npos);
287 LOG_SCOPE(
"write()",
"CheckpointIO");
301 std::string header_file_name = header_file(
name, use_n_procs);
302 make_dir(
name, use_n_procs);
315 io.
data(data_size,
"# integer size");
321 io.
data(mesh_dimension,
"# dimensions");
335 io.
data(n_procs,
"# n_procs");
349 if (write_extra_integers)
352 io.
data(n_node_integers,
"# n_extra_integers per node");
354 std::vector<std::string> node_integer_names;
355 for (
unsigned int i=0; i != n_node_integers; ++i)
358 io.
data(node_integer_names);
361 io.
data(n_elem_integers,
"# n_extra_integers per elem");
363 std::vector<std::string> elem_integer_names;
364 for (
unsigned int i=0; i != n_elem_integers; ++i)
367 io.
data(elem_integer_names);
377 std::vector<processor_id_type> ids_to_write;
385 typedef std::remove_const<MeshBase::const_element_iterator::value_type>::type nc_v_t;
386 std::unordered_map<processor_id_type, std::vector<nc_v_t>> elements_on_pid;
392 elements_on_pid[p].clear();
393 auto eop_end = elements_on_pid.end();
394 for (
auto & elem :
mesh.element_ptr_range())
397 if (
auto eop_it = elements_on_pid.find(p);
399 eop_it->second.push_back(elem);
407 ids_to_write.push_back(0);
412 libmesh_error_msg(
"Cannot write serial checkpoint from distributed mesh");
418 std::vector<std::tuple<dof_id_type, unsigned short int, boundary_id_type>>
420 std::vector<std::tuple<dof_id_type, boundary_id_type>>
423 for (
const auto & my_pid : ids_to_write)
425 auto file_name = split_file(
name, use_n_procs, my_pid);
428 std::set<const Elem *, CompareElemIdsByLevel> elements;
433 elements.insert(
mesh.elements_begin(),
mesh.elements_end());
451 if (
const auto elements_vec_it = elements_on_pid.find(p);
452 elements_vec_it != elements_on_pid.end())
454 auto & p_elements = elements_vec_it->second;
460 v_t * elempp = p_elements.data();
461 v_t * elemend = elempp + p_elements.size();
474 (
mesh, p, active_pid_elements_begin,
475 active_pid_elements_end, elements);
477 pid_elements_end, elements);
495 this->
write_bcs (io, elements, bc_triples);
514 std::vector<largest_id_type> subdomain_ids; subdomain_ids.reserve(subdomain_map.size());
515 std::vector<std::string> subdomain_names; subdomain_names.reserve(subdomain_map.size());
521 for (
const auto & [
id,
name] : subdomain_map)
525 subdomain_ids.push_back(
id);
526 subdomain_names.push_back(
name);
529 io.
data(n_subdomain_names,
"# subdomain id to name map");
531 if (n_subdomain_names)
533 io.
data(subdomain_ids);
534 io.
data(subdomain_names);
546 io.
data(n_nodes_here,
"# n_nodes on proc");
549 const unsigned int n_extra_integers =
553 std::vector<largest_id_type> id_pid(2 + n_extra_integers);
556 std::vector<Real> coords(LIBMESH_DIM);
558 for (
const auto & node : nodeset)
560 id_pid[0] = node->id();
561 id_pid[1] = node->processor_id();
563 libmesh_assert_equal_to(n_extra_integers, node->n_extra_integers());
564 for (
unsigned int i=0; i != n_extra_integers; ++i)
565 id_pid[2+i] = node->get_extra_integer(i);
567 io.
data_stream(id_pid.data(), 2 + n_extra_integers, 2 + n_extra_integers);
569 #ifdef LIBMESH_ENABLE_UNIQUE_ID 572 io.
data(unique_id,
"# unique id");
575 coords[0] = (*node)(0);
578 coords[1] = (*node)(1);
582 coords[2] = (*node)(2);
592 const std::set<const Elem *, CompareElemIdsByLevel> & elements)
const 597 const unsigned int n_extra_integers =
602 std::vector<largest_id_type> elem_data(6 + n_extra_integers);
603 std::vector<largest_id_type> conn_data;
607 io.
data(n_elems_here,
"# number of elements");
609 for (
const auto & elem : elements)
611 unsigned int n_nodes = elem->n_nodes();
613 elem_data[0] = elem->id();
614 elem_data[1] = elem->type();
615 elem_data[2] = elem->processor_id();
616 elem_data[3] = elem->subdomain_id();
618 #ifdef LIBMESH_ENABLE_AMR 619 if (elem->parent() !=
nullptr)
621 elem_data[4] = elem->parent()->id();
622 elem_data[5] = elem->parent()->which_child_am_i(elem);
631 for (
unsigned int i=0; i != n_extra_integers; ++i)
632 elem_data[6+i] = elem->get_extra_integer(i);
636 for (
unsigned int i=0; i<
n_nodes; i++)
637 conn_data[i] = elem->node_id(i);
640 cast_int<unsigned int>(elem_data.size()),
641 cast_int<unsigned int>(elem_data.size()));
643 #ifdef LIBMESH_ENABLE_UNIQUE_ID 646 io.
data(unique_id,
"# unique id");
649 #ifdef LIBMESH_ENABLE_AMR 650 uint16_t p_level = cast_int<uint16_t>(elem->p_level());
651 io.
data(p_level,
"# p_level");
653 uint16_t rflag = elem->refinement_flag();
654 io.
data(rflag,
"# rflag");
656 uint16_t pflag = elem->p_refinement_flag();
657 io.
data(pflag,
"# pflag");
660 cast_int<unsigned int>(conn_data.size()),
661 cast_int<unsigned int>(conn_data.size()));
667 const std::set<const Elem *, CompareElemIdsByLevel> & elements)
const 672 std::vector<largest_id_type> elem_ids, parent_ids;
673 std::vector<uint16_t> elem_sides, child_numbers;
675 for (
const auto & elem : elements)
677 for (
auto n : elem->side_index_range())
681 (neigh && !elements.count(neigh)))
683 elem_ids.push_back(elem->id());
684 elem_sides.push_back(n);
688 #ifdef LIBMESH_ENABLE_AMR 689 if (elem->has_children())
691 for (
unsigned short c = 0,
692 nc = cast_int<unsigned short>(elem->n_children());
697 (child && !elements.count(child)))
699 parent_ids.push_back(elem->id());
700 child_numbers.push_back(c);
707 io.
data(elem_ids,
"# remote neighbor elem_ids");
708 io.
data(elem_sides,
"# remote neighbor elem_sides");
709 io.
data(parent_ids,
"# remote child parent_ids");
710 io.
data(child_numbers,
"# remote child_numbers");
716 const std::set<const Elem *, CompareElemIdsByLevel> & elements,
717 const std::vector<std::tuple<dof_id_type, unsigned short int, boundary_id_type>> & bc_triples)
const 722 std::size_t bc_size = bc_triples.size();
724 std::vector<largest_id_type> element_id_list;
725 std::vector<uint16_t> side_list;
726 std::vector<largest_id_type> bc_id_list;
728 element_id_list.reserve(bc_size);
729 side_list.reserve(bc_size);
730 bc_id_list.reserve(bc_size);
732 std::unordered_set<dof_id_type> elems;
733 for (
auto & e : elements)
734 elems.insert(e->id());
736 for (
const auto & t : bc_triples)
737 if (elems.count(std::get<0>(t)))
739 element_id_list.push_back(std::get<0>(t));
740 side_list.push_back(std::get<1>(t));
741 bc_id_list.push_back(std::get<2>(t));
745 io.
data(element_id_list,
"# element ids for bcs");
746 io.
data(side_list,
"# sides of elements for bcs");
747 io.
data(bc_id_list,
"# bc ids");
754 const std::vector<std::tuple<dof_id_type, boundary_id_type>> & bc_tuples)
const 762 std::size_t nodeset_size = bc_tuples.size();
764 std::vector<largest_id_type> node_id_list;
765 std::vector<largest_id_type> bc_id_list;
767 node_id_list.reserve(nodeset_size);
768 bc_id_list.reserve(nodeset_size);
770 for (
const auto & t : bc_tuples)
773 node_id_list.push_back(std::get<0>(t));
774 bc_id_list.push_back(std::get<1>(t));
777 io.
data(node_id_list,
"# node id list");
778 io.
data(bc_id_list,
"# nodeset bc id list");
785 const std::map<boundary_id_type, std::string> & boundary_map = is_sideset ?
786 info.get_sideset_name_map() :
info.get_nodeset_name_map();
788 std::vector<largest_id_type> boundary_ids; boundary_ids.reserve(boundary_map.size());
789 std::vector<std::string> boundary_names; boundary_names.reserve(boundary_map.size());
795 for (
const auto & [
id,
name] : boundary_map)
799 boundary_ids.push_back(
id);
800 boundary_names.push_back(
name);
804 io.
data(n_boundary_names,
"# sideset id to name map");
806 io.
data(n_boundary_names,
"# nodeset id to name map");
808 if (n_boundary_names)
810 io.
data(boundary_ids);
811 io.
data(boundary_names);
817 LOG_SCOPE(
"read()",
"CheckpointIO");
825 auto header_name = header_file(input_name, input_n_procs);
826 bool input_parallel = input_n_procs > 0;
845 proc_id = cast_int<processor_id_type>(proc_id + stride))
847 auto file_name = split_file(input_name, input_n_procs, proc_id);
850 std::ifstream in (file_name.c_str());
852 libmesh_error_msg_if(!in.good(),
"ERROR: cannot locate specified file:\n\t" << file_name);
858 const bool expect_all_remote =
866 this->read_subfile<uint16_t>(io, expect_all_remote);
869 this->read_subfile<uint32_t>(io, expect_all_remote);
872 this->read_subfile<uint64_t>(io, expect_all_remote);
901 template <
typename file_
id_type>
907 uint16_t mesh_dimension;
910 uint16_t input_parallel;
911 file_id_type input_n_procs;
913 std::vector<std::string> node_integer_names, elem_integer_names;
921 std::string input_version;
922 io.
data(input_version);
929 io.
data (mesh_dimension);
932 io.
data(input_parallel);
936 io.
data(input_n_procs);
939 this->read_subdomain_names<file_id_type>(io);
944 this->read_bc_names<file_id_type>(io, boundary_info,
true);
945 this->read_bc_names<file_id_type>(io, boundary_info,
false);
948 std::swap(input_version, this->
version());
950 std::swap(input_version, this->
version());
952 if (read_extra_integers)
953 this->read_integers_names<file_id_type>
954 (io, node_integer_names, elem_integer_names);
968 std::map<subdomain_id_type, std::string> & subdomain_map =
979 for (
auto & int_name : node_integer_names)
982 for (
auto & int_name : elem_integer_names)
985 return input_parallel ? input_n_procs : 0;
990 template <
typename file_
id_type>
994 this->read_nodes<file_id_type> (io);
997 this->read_connectivity<file_id_type> (io);
1000 this->read_remote_elem<file_id_type> (io, expect_all_remote);
1003 this->read_bcs<file_id_type> (io);
1006 this->read_nodesets<file_id_type> (io);
1011 template <
typename file_
id_type>
1016 std::map<subdomain_id_type, std::string> & subdomain_map =
1019 std::vector<file_id_type> subdomain_ids;
1020 subdomain_ids.reserve(subdomain_map.size());
1022 std::vector<std::string> subdomain_names;
1023 subdomain_names.reserve(subdomain_map.size());
1025 file_id_type n_subdomain_names = 0;
1026 io.
data(n_subdomain_names,
"# subdomain id to name map");
1028 if (n_subdomain_names)
1030 io.
data(subdomain_ids);
1031 io.
data(subdomain_names);
1034 subdomain_map[cast_int<subdomain_id_type>(subdomain_ids[i])] =
1041 template <
typename file_
id_type>
1047 file_id_type n_nodes_here;
1048 io.
data(n_nodes_here,
"# n_nodes on proc");
1052 const unsigned int n_extra_integers =
1056 std::vector<file_id_type> id_pid(2 + n_extra_integers);
1059 std::vector<Real> coords(LIBMESH_DIM);
1061 for (
unsigned int i=0; i<n_nodes_here; i++)
1063 io.
data_stream(id_pid.data(), 2 + n_extra_integers, 2 + n_extra_integers);
1065 #ifdef LIBMESH_ENABLE_UNIQUE_ID 1066 file_id_type unique_id = 0;
1067 io.
data(unique_id,
"# unique id");
1070 io.
data_stream(coords.data(), LIBMESH_DIM, LIBMESH_DIM);
1083 const dof_id_type id = cast_int<dof_id_type>(id_pid[0]);
1098 libmesh_assert_equal_to(pid, old_node->processor_id());
1100 libmesh_assert_equal_to(n_extra_integers, old_node->n_extra_integers());
1102 for (
unsigned int ei=0; ei != n_extra_integers; ++ei)
1104 const dof_id_type extra_int = cast_int<dof_id_type>(id_pid[2+ei]);
1105 libmesh_assert_equal_to(extra_int, old_node->get_extra_integer(ei));
1109 #ifdef LIBMESH_ENABLE_UNIQUE_ID 1110 libmesh_assert_equal_to(unique_id, old_node->unique_id());
1118 #ifdef LIBMESH_ENABLE_UNIQUE_ID 1124 for (
unsigned int ei=0; ei != n_extra_integers; ++ei)
1126 const dof_id_type extra_int = cast_int<dof_id_type>(id_pid[2+ei]);
1135 template <
typename file_
id_type>
1143 const unsigned int n_extra_integers =
1146 file_id_type n_elems_here;
1147 io.
data(n_elems_here);
1150 unsigned int highest_elem_dim = 1;
1155 bool file_is_broken =
false;
1157 for (
unsigned int i=0; i<n_elems_here; i++)
1160 std::vector<file_id_type> elem_data(6 + n_extra_integers);
1162 (elem_data.data(), cast_int<unsigned int>(elem_data.size()),
1163 cast_int<unsigned int>(elem_data.size()));
1165 #ifdef LIBMESH_ENABLE_UNIQUE_ID 1166 file_id_type unique_id = 0;
1167 io.
data(unique_id,
"# unique id");
1170 #ifdef LIBMESH_ENABLE_AMR 1171 uint16_t p_level = 0;
1172 io.
data(p_level,
"# p_level");
1174 uint16_t rflag, pflag;
1175 io.
data(rflag,
"# rflag");
1176 io.
data(pflag,
"# pflag");
1181 libmesh_not_implemented_msg(
"Support for Polygons/Polyhedra not yet implemented");
1184 std::vector<file_id_type> conn_data(
n_nodes);
1186 (conn_data.data(), cast_int<unsigned int>(conn_data.size()),
1187 cast_int<unsigned int>(conn_data.size()));
1190 cast_int<dof_id_type> (elem_data[0]);
1192 static_cast<ElemType> (elem_data[1]);
1194 cast_int<processor_id_type>
1197 cast_int<subdomain_id_type>(elem_data[3]);
1201 if (i == 0 && elem_data[4] == 65535)
1202 file_is_broken =
true;
1209 (file_is_broken && elem_data[4] == 65535)) ?
1210 nullptr :
mesh.
elem_ptr(cast_int<dof_id_type>(elem_data[4]));
1212 const unsigned short int child_num =
1214 (file_is_broken && elem_data[5] == 65535)) ?
1215 static_cast<unsigned short>(-1) :
1216 cast_int<unsigned short>(elem_data[5]);
1219 libmesh_assert_equal_to
1220 (child_num, static_cast<unsigned short>(-1));
1232 libmesh_assert_equal_to(elem_type, old_elem->
type());
1233 libmesh_assert_equal_to(proc_id, old_elem->
processor_id());
1234 libmesh_assert_equal_to(subdomain_id, old_elem->
subdomain_id());
1236 libmesh_assert_equal_to(parent, old_elem->
parent());
1242 for (
unsigned int ei=0; ei != n_extra_integers; ++ei)
1244 const dof_id_type extra_int = cast_int<dof_id_type>(elem_data[6+ei]);
1249 libmesh_assert_equal_to(old_elem->
n_nodes(), conn_data.size());
1251 for (
unsigned int n=0,
1252 n_conn = cast_int<unsigned int>(conn_data.size());
1254 libmesh_assert_equal_to
1256 cast_int<dof_id_type>(conn_data[n]));
1263 #ifdef LIBMESH_ENABLE_UNIQUE_ID 1264 elem->set_unique_id(unique_id);
1267 if (elem->dim() > highest_elem_dim)
1268 highest_elem_dim = elem->dim();
1270 elem->set_id() = id;
1271 elem->processor_id() = proc_id;
1272 elem->subdomain_id() = subdomain_id;
1274 #ifdef LIBMESH_ENABLE_AMR 1275 elem->hack_p_level(p_level);
1277 elem->set_refinement_flag (cast_int<Elem::RefinementState>(rflag));
1278 elem->set_p_refinement_flag(cast_int<Elem::RefinementState>(pflag));
1285 parent->
add_child(elem.get(), child_num);
1294 for (
unsigned int n=0,
1295 n_conn = cast_int<unsigned int>(conn_data.size());
1303 for (
unsigned int ei=0; ei != n_extra_integers; ++ei)
1305 const dof_id_type extra_int = cast_int<dof_id_type>(elem_data[6+ei]);
1315 template <
typename file_
id_type>
1322 std::vector<file_id_type> elem_ids;
1323 std::vector<uint16_t> elem_sides;
1325 io.
data(elem_ids,
"# remote neighbor elem_ids");
1326 io.
data(elem_sides,
"# remote neighbor elem_sides");
1328 libmesh_assert_equal_to(elem_ids.size(), elem_sides.size());
1341 std::vector<file_id_type> parent_ids;
1342 std::vector<uint16_t> child_numbers;
1344 io.
data(parent_ids,
"# remote child parent_ids");
1345 io.
data(child_numbers,
"# remote child_numbers");
1347 #ifdef LIBMESH_ENABLE_AMR 1369 template <
typename file_
id_type>
1378 std::vector<file_id_type> element_id_list;
1379 std::vector<uint16_t> side_list;
1380 std::vector<file_id_type> bc_id_list;
1382 io.
data(element_id_list,
"# element ids for bcs");
1383 io.
data(side_list,
"# sides of elements for bcs");
1384 io.
data(bc_id_list,
"# bc ids");
1388 (cast_int<dof_id_type>(element_id_list[i]), side_list[i],
1389 cast_int<boundary_id_type>(bc_id_list[i]));
1394 template <
typename file_
id_type>
1403 std::vector<file_id_type> node_id_list;
1404 std::vector<file_id_type> bc_id_list;
1406 io.
data(node_id_list,
"# node id list");
1407 io.
data(bc_id_list,
"# nodeset bc id list");
1411 (cast_int<dof_id_type>(node_id_list[i]),
1412 cast_int<boundary_id_type>(bc_id_list[i]));
1417 template <
typename file_
id_type>
1420 std::map<boundary_id_type, std::string> & boundary_map = is_sideset ?
1421 info.set_sideset_name_map() :
info.set_nodeset_name_map();
1423 std::vector<file_id_type> boundary_ids;
1424 std::vector<std::string> boundary_names;
1426 file_id_type n_boundary_names = 0;
1429 io.
data(n_boundary_names,
"# sideset id to name map");
1431 io.
data(n_boundary_names,
"# nodeset id to name map");
1433 if (n_boundary_names)
1435 io.
data(boundary_ids);
1436 io.
data(boundary_names);
1441 boundary_map[cast_int<boundary_id_type>(boundary_ids[i])] =
1446 template <
typename file_
id_type>
1449 std::vector<std::string> & node_integer_names,
1450 std::vector<std::string> & elem_integer_names)
1452 file_id_type n_node_integers, n_elem_integers;
1454 io.
data(n_node_integers,
"# n_extra_integers per node");
1455 io.
data(node_integer_names);
1456 io.
data(n_elem_integers,
"# n_extra_integers per elem");
1457 io.
data(elem_integer_names);
1464 unsigned int max_level = 0;
1466 for (
const auto & elem :
as_range(begin, end))
1467 max_level = std::max(elem->level(), max_level);
1469 return max_level + 1;
std::string name(const ElemQuality q)
This function returns a string containing some name for q.
ElemType
Defines an enum for geometric element types.
unique_id_type & set_unique_id()
virtual void write(const std::string &name) override
This method implements writing a mesh to a specified file.
const Elem * parent() const
const std::string & version() const
Get/Set the version string.
A Node is like a Point, but with more information.
const unsigned int invalid_uint
A number which is used quite often to represent an invalid or uninitialized value for an unsigned int...
void write_remote_elem(Xdr &io, const std::set< const Elem *, CompareElemIdsByLevel > &elements) const
Write the remote_elem neighbor and child links for part of a mesh.
unsigned int n_node_integers() const
void write_connectivity(Xdr &io, const std::set< const Elem *, CompareElemIdsByLevel > &elements) const
Write the connectivity for part of a mesh.
void skip_partitioning(bool skip)
If true is passed in then nothing on this mesh will be (re)partitioned.
The definition of the const_element_iterator struct.
void write_nodes(Xdr &io, const connected_node_set_type &nodeset) const
Write the nodal locations for part of a mesh.
virtual void read(const std::string &input_name) override
This method implements reading a mesh from a specified file.
void close()
Closes the file if it is open.
unsigned int add_elem_integer(std::string name, bool allocate_data=true, dof_id_type default_value=DofObject::invalid_id)
Register an integer datum (of type dof_id_type) to be added to each element in the mesh...
unsigned int n_elem_integers() const
This is the base class from which all geometric element types are derived.
void add_child(Elem *elem)
Adds a child pointer to the array of children of this element.
processor_id_type rank() const
const Parallel::Communicator & comm() const
int mkdir(const char *pathname)
Create a directory.
Used to iterate over non-nullptr, active entries in a container.
This class defines an abstract interface for Mesh output.
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
Write the side boundary conditions for part of a mesh.
void read_bc_names(Xdr &io, BoundaryInfo &info, bool is_sideset)
Read boundary names information (sideset and nodeset)
The libMesh namespace provides an interface to certain functionality in the library.
void read_remote_elem(Xdr &io, bool expect_all_remote)
Read the remote_elem neighbor and child links for a parallel, distributed mesh.
const BoundaryInfo & get_boundary_info() const
The information about boundary ids on the mesh.
bool parallel() const
Get/Set the flag indicating if we should read/write binary.
unsigned int n_active_levels_in(MeshBase::const_element_iterator begin, MeshBase::const_element_iterator end) const
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
Add a new Node at Point p to the end of the vertex array, with processor_id procid.
static const unsigned int type_to_n_nodes_map[INVALID_ELEM]
This array maps the integer representation of the ElemType enum to the number of nodes in the element...
Used to iterate over non-nullptr entries in a container.
const std::string & get_elem_integer_name(unsigned int i) const
processor_id_type select_split_config(const std::string &input_name, header_id_type &data_size)
uint8_t processor_id_type
This is the MeshBase class.
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
Creates a list of element numbers, sides, and ids for those sides.
virtual void set_distributed()
Asserts that not all elements and nodes of the mesh necessarily exist on the current processor...
virtual void partition(const unsigned int n_parts)
Call the default partitioner (currently metis_partition()).
void data(T &a, std::string_view comment="")
Inputs or outputs a single value.
processor_id_type size() const
std::vector< processor_id_type > _my_processor_ids
std::map< boundary_id_type, std::string > & set_sideset_name_map()
processor_id_type n_processors() const
virtual bool is_serial() const
void libmesh_ignore(const Args &...)
void build_node_list(std::vector< dof_id_type > &node_id_list, std::vector< boundary_id_type > &bc_id_list) const
Creates a list of nodes and ids for those nodes.
void add_node(const Node *node, const boundary_id_type id)
Add Node node with boundary id id to the boundary information data structures.
const dof_id_type n_nodes
This is the MeshCommunication class.
void query_ghosting_functors(const MeshBase &mesh, processor_id_type pid, MeshBase::const_element_iterator elem_it, MeshBase::const_element_iterator elem_end, connected_elem_set_type &connected_elements)
const std::map< subdomain_id_type, std::string > & get_subdomain_name_map() const
void write_subdomain_names(Xdr &io) const
Write subdomain name information.
virtual unsigned int n_nodes() const =0
static const processor_id_type invalid_processor_id
An invalid processor_id to distinguish DoFs that have not been assigned to a processor.
processor_id_type _my_n_processors
virtual Elem * add_elem(Elem *e)=0
Add elem e to the end of the element array.
static std::unique_ptr< Elem > build(const ElemType type, Elem *p=nullptr)
SimpleRange< IndexType > as_range(const std::pair< IndexType, IndexType > &p)
Helper function that allows us to treat a homogenous pair as a range.
virtual const Node * query_node_ptr(const dof_id_type i) const =0
CheckpointIO(MeshBase &, const bool=false)
Constructor.
The BoundaryInfo class contains information relevant to boundary conditions including storing faces...
static void cleanup(const std::string &input_name, processor_id_type n_procs)
Used to remove a checkpoint directory and its corresponding files.
void write_nodesets(Xdr &io, const connected_node_set_type &nodeset, const std::vector< std::tuple< dof_id_type, boundary_id_type >> &bc_tuples) const
Write the nodal boundary conditions for part of a mesh.
void write_bc_names(Xdr &io, const BoundaryInfo &info, bool is_sideset) const
Write boundary names information (sideset and nodeset)
void set_mesh_dimension(unsigned char d)
Resets the logical dimension of the mesh.
void set_neighbor(const unsigned int i, Elem *n)
Assigns n as the neighbor.
An object whose state is distributed along a set of processors.
file_id_type read_header(const std::string &name)
Read header data on processor 0, then broadcast.
void broadcast(T &data, const unsigned int root_id=0, const bool identical_sizes=false) const
This class implements a C++ interface to the XDR (eXternal Data Representation) format.
void connect_children(const MeshBase &mesh, MeshBase::const_element_iterator elem_it, MeshBase::const_element_iterator elem_end, connected_elem_set_type &connected_elements)
std::set< const Node * > connected_node_set_type
virtual const Elem * elem_ptr(const dof_id_type i) const =0
tbb::split split
Dummy "splitting object" used to distinguish splitting constructors from copy constructors.
void read_subdomain_names(Xdr &io)
Read subdomain name information.
bool version_at_least_1_5() const
void read_bcs(Xdr &io)
Read the boundary conditions for a parallel, distributed mesh.
const Elem * neighbor_ptr(unsigned int i) const
unsigned int recalculate_n_partitions()
In a few (very rare) cases, the user may have manually tagged the elements with specific processor ID...
std::unique_ptr< CheckpointIO > split_mesh(MeshBase &mesh, processor_id_type nsplits)
split_mesh takes the given initialized/opened mesh and partitions it into nsplits pieces or chunks...
const Elem * raw_child_ptr(unsigned int i) const
void read_subfile(Xdr &io, bool expect_all_remote)
Read a non-header file.
virtual const Elem * query_elem_ptr(const dof_id_type i) const =0
subdomain_id_type subdomain_id() const
void read_nodesets(Xdr &io)
Read the nodeset conditions for a parallel, distributed mesh.
void read_nodes(Xdr &io)
Read the nodal locations for a parallel, distributed mesh.
std::map< boundary_id_type, std::string > & set_nodeset_name_map()
virtual bool is_replicated() const
void broadcast(MeshBase &) const
Finds all the processors that may contain elements that neighbor my elements.
void add_side(const dof_id_type elem, const unsigned short int side, const boundary_id_type id)
Add side side of element number elem with boundary id id to the boundary information data structure...
virtual const Elem & elem_ref(const dof_id_type i) const
unsigned int mesh_dimension() const
void connect_element_dependencies(const MeshBase &mesh, connected_elem_set_type &connected_elements, connected_node_set_type &connected_nodes)
unsigned int add_node_integer(std::string name, bool allocate_data=true, dof_id_type default_value=DofObject::invalid_id)
Register an integer datum (of type dof_id_type) to be added to each node in the mesh.
const std::string & get_node_integer_name(unsigned int i) const
unsigned int n_extra_integers() const
Returns how many extra integers are associated to the DofObject.
void read_integers_names(Xdr &io, std::vector< std::string > &node_integer_names, std::vector< std::string > &elem_integer_names)
Read extra integers names information.
bool binary() const
Get/Set the flag indicating if we should read/write binary.
virtual void update_post_partitioning()
Recalculate any cached data after elements and nodes have been repartitioned.
virtual dof_id_type n_elem() const =0
virtual const Node * node_ptr(const dof_id_type i) const =0
processor_id_type processor_id() const
void read_connectivity(Xdr &io)
Read the connectivity for a parallel, distributed mesh.
void data_stream(T *val, const unsigned int len, const unsigned int line_break=libMesh::invalid_uint)
Inputs or outputs a raw data stream.
virtual ~CheckpointIO()
Destructor.
const DofMap &dof_map LIBMESH_COMMA unsigned int std::string & set_subdomain_name_map()
processor_id_type processor_id() const
virtual ElemType type() const =0
A Point defines a location in LIBMESH_DIM dimensional Real space.
dof_id_type node_id(const unsigned int i) const
auto index_range(const T &sizable)
Helper function that returns an IntRange<std::size_t> representing all the indices of the passed-in v...
void set_extra_integer(const unsigned int index, const dof_id_type value)
Sets the value on this object of the extra integer associated with index, which should have been obta...
dof_id_type get_extra_integer(const unsigned int index) const
Gets the value on this object of the extra integer associated with index, which should have been obta...
const Elem * child_ptr(unsigned int i) const
const RemoteElem * remote_elem