21 #include "libmesh/xdr_io.h"
24 #include "libmesh/boundary_info.h"
25 #include "libmesh/elem.h"
26 #include "libmesh/enum_xdr_mode.h"
27 #include "libmesh/int_range.h"
28 #include "libmesh/libmesh_logging.h"
29 #include "libmesh/mesh_base.h"
30 #include "libmesh/mesh_tools.h"
31 #include "libmesh/node.h"
32 #include "libmesh/partitioner.h"
33 #include "libmesh/xdr_cxx.h"
54 template <
class T,
class U>
55 struct libmesh_type_is_same {
56 static const bool value =
false;
60 struct libmesh_type_is_same<T, T> {
61 static const bool value =
true;
82 _write_serial (false),
83 _write_parallel (false),
84 #ifdef LIBMESH_ENABLE_UNIQUE_ID
85 _write_unique_id (true),
87 _write_unique_id (false),
90 _version (
"libMesh-1.3.0"),
91 _bc_file_name (
"n/a"),
92 _partition_map_file (
"n/a"),
93 _subdomain_map_file (
"n/a"),
118 libmesh_error_msg(
"We don't support writing parallel files in the legacy format.");
122 START_LOG(
"write()",
"XdrIO");
144 if ((n_side_bcs || n_edge_bcs || n_shellface_bcs || n_nodesets) &&
158 if ((n_p_levels > 1) &&
165 std::string full_ver = this->
version() + (write_parallel_files ?
" parallel" :
"");
169 io.
data (max_node_id,
"# number of nodes");
185 io.
data (write_size,
"# type size");
187 io.
data (write_partitioning ? write_size : zero_size,
"# pid size");
188 io.
data (write_subdomain_id ? write_size : zero_size,
"# sid size");
189 io.
data (write_p_level ? write_size : zero_size,
"# p-level size");
191 io.
data (write_bcs ? write_size : zero_size,
"# eid size");
192 io.
data (write_bcs ? write_size : zero_size,
"# side size");
193 io.
data (write_bcs ? write_size : zero_size,
"# bid size");
196 if (write_parallel_files)
200 libMesh::out <<
"Warning! Parallel xda/xdr is not yet implemented.\n";
201 libMesh::out <<
"Writing a serialized file instead." << std::endl;
248 STOP_LOG(
"write()",
"XdrIO");
255 this->
comm().barrier();
268 std::vector<new_header_id_type> subdomain_ids;
269 subdomain_ids.reserve(subdomain_map.size());
271 std::vector<std::string> subdomain_names;
272 subdomain_names.reserve(subdomain_map.size());
278 for (
const auto & pr : subdomain_map)
279 if (!pr.second.empty())
282 subdomain_ids.push_back(pr.first);
283 subdomain_names.push_back(pr.second);
286 io.
data(n_subdomain_names,
"# subdomain id to name map");
288 if (n_subdomain_names)
290 io.
data(subdomain_ids);
291 io.
data(subdomain_names);
321 n_global_elem_at_level[level] =
325 this->
comm().sum(n_global_elem_at_level[level]);
327 tot_n_elem += n_global_elem_at_level[level];
329 libmesh_assert_less_equal (n_global_elem_at_level[level],
n_elem);
330 libmesh_assert_less_equal (tot_n_elem,
n_elem);
333 std::vector<xdr_id_type>
334 xfer_conn, recv_conn;
335 std::vector<dof_id_type>
337 std::vector<xdr_id_type> output_buffer;
338 std::vector<std::size_t>
341 #ifdef LIBMESH_ENABLE_AMR
342 typedef std::map<dof_id_type, std::pair<processor_id_type, dof_id_type>> id_map_type;
343 id_map_type parent_id_map, child_id_map;
354 #ifdef LIBMESH_ENABLE_AMR
355 parent_id_map[elem->id()] = std::make_pair(this->
processor_id(),
360 xfer_conn.push_back(my_next_elem);
362 std::size_t my_size = xfer_conn.size();
363 this->
comm().gather (0, my_next_elem, n_elem_on_proc);
364 this->
comm().gather (0, my_size, xfer_buf_sizes);
366 processor_offsets[0] = 0;
368 processor_offsets[pid] = processor_offsets[pid-1] + n_elem_on_proc[pid-1];
376 std::string comment =
"# n_elem at level 0", legend =
", [ type ";
379 if (write_partitioning)
381 if (write_subdomain_id)
384 legend +=
"p_level ";
385 legend +=
"(n0 ... nN-1) ]";
387 io.
data (n_global_elem_at_level[0], comment.c_str());
392 recv_conn.resize(xfer_buf_sizes[pid]);
394 recv_conn = xfer_conn;
396 this->
comm().receive (pid, recv_conn);
403 const xdr_id_type n_elem_received = recv_conn.back();
404 std::vector<xdr_id_type>::const_iterator recv_conn_iter = recv_conn.begin();
406 for (
xdr_id_type elem=0; elem<n_elem_received; elem++, next_global_elem++)
408 output_buffer.clear();
415 output_buffer.push_back(*recv_conn_iter);
420 output_buffer.push_back(*recv_conn_iter);
424 if (write_partitioning)
425 output_buffer.push_back(*recv_conn_iter);
429 if (write_subdomain_id)
430 output_buffer.push_back(*recv_conn_iter);
433 #ifdef LIBMESH_ENABLE_AMR
436 output_buffer.push_back(*recv_conn_iter);
440 output_buffer.push_back(*recv_conn_iter);
443 (output_buffer.data(),
444 cast_int<unsigned int>(output_buffer.size()),
445 cast_int<unsigned int>(output_buffer.size()));
451 this->
comm().send (0, xfer_conn);
453 #ifdef LIBMESH_ENABLE_AMR
465 if (!parent->active())
467 id_map_type::iterator pos = parent_id_map.find(parent->id());
471 parent_id_map.erase(pos);
473 for (
auto & child : parent->child_ref_range())
475 pack_element (xfer_conn, &child, parent_id, parent_pid);
480 child_id_map[child.id()] = std::make_pair (child.processor_id(),
481 my_n_elem_written_at_level++);
485 xfer_conn.push_back(my_n_elem_written_at_level);
486 my_size = xfer_conn.size();
487 this->
comm().gather (0, my_size, xfer_buf_sizes);
495 std::sprintf(buf,
"# n_elem at level %u", level);
496 std::string comment(buf), legend =
", [ type ";
501 if (write_partitioning)
503 if (write_subdomain_id)
506 legend +=
"p_level ";
507 legend +=
"(n0 ... nN-1) ]";
509 io.
data (n_global_elem_at_level[level], comment.c_str());
514 recv_conn.resize(xfer_buf_sizes[pid]);
516 recv_conn = xfer_conn;
518 this->
comm().receive (pid, recv_conn);
525 const xdr_id_type n_elem_received = recv_conn.back();
526 std::vector<xdr_id_type>::const_iterator recv_conn_iter = recv_conn.begin();
528 for (
xdr_id_type elem=0; elem<n_elem_received; elem++, next_global_elem++)
530 output_buffer.clear();
537 output_buffer.push_back(*recv_conn_iter);
542 output_buffer.push_back(*recv_conn_iter);
546 const xdr_id_type parent_local_id = *recv_conn_iter;
553 output_buffer.push_back (parent_local_id+processor_offsets[parent_pid]);
556 if (write_partitioning)
557 output_buffer.push_back(*recv_conn_iter);
561 if (write_subdomain_id)
562 output_buffer.push_back(*recv_conn_iter);
567 output_buffer.push_back(*recv_conn_iter);
571 output_buffer.push_back(*recv_conn_iter);
574 (output_buffer.data(),
575 cast_int<unsigned int>(output_buffer.size()),
576 cast_int<unsigned int>(output_buffer.size()));
582 this->
comm().send (0, xfer_conn);
585 processor_offsets[0] = processor_offsets.back() + n_elem_on_proc.back();
586 this->
comm().gather (0, my_n_elem_written_at_level, n_elem_on_proc);
588 processor_offsets[pid] = processor_offsets[pid-1] + n_elem_on_proc[pid-1];
594 std::map<processor_id_type, std::vector<dof_id_type>> requested_ids;
598 if (!child_id_map.count(elem->id()))
600 libmesh_assert_not_equal_to (elem->parent()->processor_id(), this->
processor_id());
603 requested_ids[pid].push_back(elem->id());
606 auto gather_functor =
609 const std::vector<dof_id_type> & ids,
610 std::vector<dof_id_type> &
data)
612 const std::size_t ids_size = ids.size();
613 data.resize(ids_size);
616 for (std::size_t i=0; i != ids_size; i++)
619 libmesh_assert_equal_to (child_id_map[ids[i]].first, pid);
621 data[i] = child_id_map[ids[i]].second;
625 auto action_functor =
628 const std::vector<dof_id_type> & ids,
629 const std::vector<dof_id_type> &
data)
631 std::size_t data_size =
data.size();
633 for (std::size_t i=0; i != data_size; i++)
634 child_id_map[ids[i]] =
635 std::make_pair (pid,
data[i]);
640 Parallel::pull_parallel_vector_data
641 (this->
comm(), requested_ids, gather_functor, action_functor, ex);
645 parent_id_map.swap(child_id_map);
646 child_id_map.clear();
649 #endif // LIBMESH_ENABLE_AMR
651 libmesh_assert_equal_to (next_global_elem,
n_elem);
663 std::vector<dof_id_type> xfer_ids;
664 std::vector<Real> xfer_coords;
665 std::vector<Real> & coords=xfer_coords;
667 std::vector<std::vector<dof_id_type>> recv_ids (this->
n_processors());
668 std::vector<std::vector<Real>> recv_coords(this->
n_processors());
670 #ifdef LIBMESH_ENABLE_UNIQUE_ID
671 std::vector<xdr_id_type> xfer_unique_ids;
672 std::vector<xdr_id_type> & unique_ids=xfer_unique_ids;
673 std::vector<std::vector<xdr_id_type>> recv_unique_ids (this->
n_processors());
674 #endif // LIBMESH_ENABLE_UNIQUE_ID
676 std::size_t n_written=0;
681 for (std::size_t blk=0, last_node=0; last_node<max_node_id; blk++)
683 const std::size_t first_node = blk*
io_blksize;
684 last_node = std::min((blk+1)*
io_blksize, std::size_t(max_node_id));
686 const std::size_t tot_id_size = last_node - first_node;
692 for (; node_iter != nodes_end; ++node_iter)
694 const Node & node = **node_iter;
695 libmesh_assert_greater_equal(node.
id(), first_node);
696 if (node.
id() >= last_node)
699 xfer_ids.push_back(node.
id());
700 xfer_coords.push_back(node(0));
702 xfer_coords.push_back(node(1));
705 xfer_coords.push_back(node(2));
711 std::vector<std::size_t> ids_size;
713 const std::size_t my_ids_size = xfer_ids.size();
716 this->
comm().gather (0, my_ids_size, ids_size);
720 std::vector<Parallel::Request>
725 id_tag =
mesh.
comm().get_unique_tag(),
726 coord_tag =
mesh.
comm().get_unique_tag();
733 recv_ids[pid].resize(ids_size[pid]);
734 recv_coords[pid].resize(ids_size[pid]*LIBMESH_DIM);
738 recv_ids[0] = xfer_ids;
739 recv_coords[0] = xfer_coords;
743 this->
comm().receive (pid, recv_ids[pid],
744 id_request_handles[pid-1],
746 this->
comm().receive (pid, recv_coords[pid],
747 coord_request_handles[pid-1],
755 this->
comm().send(0, xfer_ids, id_tag);
756 this->
comm().send(0, xfer_coords, coord_tag);
766 Parallel::wait (id_request_handles);
767 Parallel::wait (coord_request_handles);
771 libmesh_assert_equal_to(recv_coords[pid].size(),
772 recv_ids[pid].size()*LIBMESH_DIM);
782 coords.resize (3*tot_id_size, std::numeric_limits<Real>::quiet_NaN());
787 libmesh_assert_less_equal(first_node, recv_ids[pid][
idx]);
788 const std::size_t local_idx = recv_ids[pid][
idx] - first_node;
789 libmesh_assert_less(local_idx, tot_id_size);
791 libmesh_assert_less ((3*local_idx+2), coords.size());
792 libmesh_assert_less ((LIBMESH_DIM*
idx+LIBMESH_DIM-1), recv_coords[pid].size());
794 coords[3*local_idx+0] = recv_coords[pid][LIBMESH_DIM*
idx+0];
796 coords[3*local_idx+1] = recv_coords[pid][LIBMESH_DIM*
idx+1];
798 coords[3*local_idx+1] = 0.;
801 coords[3*local_idx+2] = recv_coords[pid][LIBMESH_DIM*
idx+2];
803 coords[3*local_idx+2] = 0.;
809 io.
data_stream (coords.empty() ? nullptr : coords.data(),
810 cast_int<unsigned int>(coords.size()), 3);
815 libmesh_assert_less_equal (n_written, max_node_id);
817 #ifdef LIBMESH_ENABLE_UNIQUE_ID
819 unsigned short write_unique_ids = 1;
821 unsigned short write_unique_ids = 0;
824 io.
data (write_unique_ids,
"# presence of unique ids");
826 #ifdef LIBMESH_ENABLE_UNIQUE_ID
831 for (std::size_t blk=0, last_node=0; last_node<max_node_id; blk++)
833 const std::size_t first_node = blk*
io_blksize;
834 last_node = std::min((blk+1)*
io_blksize, std::size_t(max_node_id));
836 const std::size_t tot_id_size = last_node - first_node;
840 xfer_ids.reserve(tot_id_size);
841 xfer_unique_ids.clear();
842 xfer_unique_ids.reserve(tot_id_size);
844 for (; node_iter != nodes_end; ++node_iter)
846 const Node & node = **node_iter;
847 libmesh_assert_greater_equal(node.
id(), first_node);
848 if (node.
id() >= last_node)
851 xfer_ids.push_back(node.
id());
852 xfer_unique_ids.push_back(node.
unique_id());
857 std::vector<std::size_t> ids_size;
859 const std::size_t my_ids_size = xfer_ids.size();
862 this->
comm().gather (0, my_ids_size, ids_size);
866 std::vector<Parallel::Request>
871 unique_id_tag =
mesh.
comm().get_unique_tag(),
872 id_tag =
mesh.
comm().get_unique_tag();
879 recv_ids[pid].resize(ids_size[pid]);
880 recv_unique_ids[pid].resize(ids_size[pid]);
884 recv_ids[0] = xfer_ids;
885 recv_unique_ids[0] = xfer_unique_ids;
889 this->
comm().receive (pid, recv_ids[pid],
890 id_request_handles[pid-1],
892 this->
comm().receive (pid, recv_unique_ids[pid],
893 unique_id_request_handles[pid-1],
901 this->
comm().send(0, xfer_ids, id_tag);
902 this->
comm().send(0, xfer_unique_ids, unique_id_tag);
912 Parallel::wait (id_request_handles);
913 Parallel::wait (unique_id_request_handles);
917 libmesh_assert_equal_to
918 (recv_ids[pid].size(), recv_unique_ids[pid].size());
921 libmesh_assert_less_equal
922 (tot_id_size, std::min(
io_blksize, std::size_t(max_node_id)));
931 libmesh_assert_less_equal(first_node, recv_ids[pid][
idx]);
932 const std::size_t local_idx = recv_ids[pid][
idx] - first_node;
933 libmesh_assert_less (local_idx, unique_ids.size());
935 unique_ids[local_idx] = recv_unique_ids[pid][
idx];
940 io.
data_stream (unique_ids.empty() ? nullptr : unique_ids.data(),
941 cast_int<unsigned int>(unique_ids.size()), 1);
946 libmesh_assert_less_equal (n_written, max_node_id);
948 #endif // LIBMESH_ENABLE_UNIQUE_ID
969 std::stringstream comment_string;
970 comment_string <<
"# number of " << bc_type <<
" boundary conditions";
971 io.
data (n_bcs_out, comment_string.str().c_str());
977 std::vector<xdr_id_type> xfer_bcs, recv_bcs;
978 std::vector<std::size_t> bc_sizes(this->
n_processors());
981 std::vector<boundary_id_type> bc_ids;
988 if (bc_type ==
"side")
990 for (
auto s : elem->side_index_range())
993 for (
const auto & bc_id : bc_ids)
996 xfer_bcs.push_back (n_local_level_0_elem);
997 xfer_bcs.push_back (s) ;
998 xfer_bcs.push_back (bc_id);
1002 else if (bc_type ==
"edge")
1004 for (
auto e : elem->edge_index_range())
1007 for (
const auto & bc_id : bc_ids)
1010 xfer_bcs.push_back (n_local_level_0_elem);
1011 xfer_bcs.push_back (e) ;
1012 xfer_bcs.push_back (bc_id);
1016 else if (bc_type ==
"shellface")
1018 for (
unsigned short sf=0; sf<2; sf++)
1021 for (
const auto & bc_id : bc_ids)
1024 xfer_bcs.push_back (n_local_level_0_elem);
1025 xfer_bcs.push_back (sf) ;
1026 xfer_bcs.push_back (bc_id);
1032 libmesh_error_msg(
"bc_type not recognized: " + bc_type);
1036 n_local_level_0_elem++;
1039 xfer_bcs.push_back(n_local_level_0_elem);
1040 std::size_t my_size = xfer_bcs.size();
1041 this->
comm().gather (0, my_size, bc_sizes);
1050 recv_bcs.resize(bc_sizes[pid]);
1052 recv_bcs = xfer_bcs;
1054 this->
comm().receive (pid, recv_bcs);
1057 = cast_int<dof_id_type>(recv_bcs.back());
1058 recv_bcs.pop_back();
1060 for (std::size_t
idx=0, rbs=recv_bcs.size();
idx<rbs;
idx += 3, n_bcs_out++)
1061 recv_bcs[
idx+0] += elem_offset;
1063 io.
data_stream (recv_bcs.empty() ? nullptr : recv_bcs.data(),
1064 cast_int<unsigned int>(recv_bcs.size()), 3);
1065 elem_offset += my_n_local_level_0_elem;
1067 libmesh_assert_equal_to (n_bcs, n_bcs_out);
1070 this->
comm().send (0, xfer_bcs);
1111 io.
data (n_nodesets_out,
"# number of nodesets");
1114 if (!n_nodesets)
return;
1116 std::vector<xdr_id_type> xfer_bcs, recv_bcs;
1117 std::vector<std::size_t> bc_sizes(this->
n_processors());
1120 std::vector<boundary_id_type> nodeset_ids;
1126 for (
const auto & bc_id : nodeset_ids)
1129 xfer_bcs.push_back (node->id());
1130 xfer_bcs.push_back (bc_id);
1134 xfer_bcs.push_back(n_node);
1135 std::size_t my_size = xfer_bcs.size();
1136 this->
comm().gather (0, my_size, bc_sizes);
1145 recv_bcs.resize(bc_sizes[pid]);
1147 recv_bcs = xfer_bcs;
1149 this->
comm().receive (pid, recv_bcs);
1152 cast_int<dof_id_type>(recv_bcs.back());
1153 recv_bcs.pop_back();
1155 for (std::size_t
idx=0, rbs=recv_bcs.size();
idx<rbs;
idx += 2, n_nodesets_out++)
1156 recv_bcs[
idx+0] += node_offset;
1158 io.
data_stream (recv_bcs.empty() ? nullptr : recv_bcs.data(),
1159 cast_int<unsigned int>(recv_bcs.size()), 2);
1160 node_offset += my_n_node;
1162 libmesh_assert_equal_to (n_nodesets, n_nodesets_out);
1165 this->
comm().send (0, xfer_bcs);
1174 const std::map<boundary_id_type, std::string> & boundary_map = is_sideset ?
1177 std::vector<new_header_id_type> boundary_ids;
1178 boundary_ids.reserve(boundary_map.size());
1180 std::vector<std::string> boundary_names;
1181 boundary_names.reserve(boundary_map.size());
1187 for (
const auto & pr : boundary_map)
1188 if (!pr.second.empty())
1191 boundary_ids.push_back(pr.first);
1192 boundary_names.push_back(pr.second);
1196 io.
data(n_boundary_names,
"# sideset id to name map");
1198 io.
data(n_boundary_names,
"# nodeset id to name map");
1200 if (n_boundary_names)
1202 io.
data(boundary_ids);
1203 io.
data(boundary_names);
1212 LOG_SCOPE(
"read()",
"XdrIO");
1233 libmesh_error_msg(
"We no longer support reading files in the legacy format.");
1237 std::vector<new_header_id_type> meta_data(10,
sizeof(
xdr_id_type));
1244 std::vector<old_header_id_type> old_data(10,
sizeof(
xdr_id_type));
1248 meta_data.assign(old_data.begin(), old_data.end());
1276 uint32_t type_size = 0;
1305 uint64_t type_size = 0;
1339 template <
typename T>
1342 LOG_SCOPE(
"read_header()",
"XdrIO");
1351 io.
data (meta_data[pos++]);
1352 io.
data (meta_data[pos++]);
1360 io.
data (meta_data[pos++],
"# type size");
1361 io.
data (meta_data[pos++],
"# uid size");
1362 io.
data (meta_data[pos++],
"# pid size");
1363 io.
data (meta_data[pos++],
"# sid size");
1364 io.
data (meta_data[pos++],
"# p-level size");
1366 io.
data (meta_data[pos++],
"# eid size");
1367 io.
data (meta_data[pos++],
"# side size");
1368 io.
data (meta_data[pos++],
"# bid size");
1373 this->
comm().broadcast (meta_data);
1382 const T &
n_elem = meta_data[0];
1383 const T &
n_nodes = meta_data[1];
1406 if (read_entity_info)
1411 std::vector<new_header_id_type> subdomain_ids;
1412 std::vector<std::string> subdomain_names;
1417 if (use_new_header_type)
1418 io.
data(n_subdomain_names);
1423 n_subdomain_names = temp;
1426 subdomain_ids.resize(n_subdomain_names);
1427 subdomain_names.resize(n_subdomain_names);
1429 if (n_subdomain_names)
1431 if (use_new_header_type)
1432 io.
data(subdomain_ids);
1435 std::vector<old_header_id_type> temp;
1437 subdomain_ids.assign(temp.begin(), temp.end());
1440 io.
data(subdomain_names);
1445 this->
comm().broadcast(n_subdomain_names);
1446 if (n_subdomain_names == 0)
1449 subdomain_ids.resize(n_subdomain_names);
1450 subdomain_names.resize(n_subdomain_names);
1451 this->
comm().broadcast(subdomain_ids);
1452 this->
comm().broadcast(subdomain_names);
1457 for (
unsigned int i=0; i<n_subdomain_names; ++i)
1458 subdomain_map.insert(std::make_pair(subdomain_ids[i], subdomain_names[i]));
1463 template <
typename T>
1482 std::vector<T> conn, input_buffer(100 );
1487 const size_t unique_id_size_index = 3;
1489 const bool read_unique_id =
1491 sizes[unique_id_size_index];
1493 T n_elem_at_level=0, n_processed_at_level=0;
1494 for (
dof_id_type blk=0, first_elem=0, last_elem=0;
1497 first_elem = cast_int<dof_id_type>(blk*
io_blksize);
1498 last_elem = cast_int<dof_id_type>(std::min(cast_int<std::size_t>((blk+1)*
io_blksize),
1499 cast_int<std::size_t>(
n_elem)));
1504 for (
dof_id_type e=first_elem; e<last_elem; e++, n_processed_at_level++)
1506 if (n_processed_at_level == n_elem_at_level)
1509 io.
data (n_elem_at_level);
1510 n_processed_at_level = 0;
1514 unsigned int pos = 0;
1528 input_buffer[pos++] = static_cast<T>(-1);
1531 if (read_partitioning)
1534 input_buffer[pos++] = 0;
1537 if (read_subdomain_id)
1540 input_buffer[pos++] = 0;
1546 input_buffer[pos++] = 0;
1551 conn.insert (conn.end(),
1552 input_buffer.begin(),
1556 std::size_t conn_size = conn.size();
1557 this->
comm().broadcast(conn_size);
1558 conn.resize (conn_size);
1559 this->
comm().broadcast (conn);
1562 typename std::vector<T>::const_iterator it = conn.begin();
1565 const ElemType elem_type = static_cast<ElemType>(*it); ++it;
1566 #ifdef LIBMESH_ENABLE_UNIQUE_ID
1574 #ifdef LIBMESH_ENABLE_UNIQUE_ID
1575 unique_id = cast_int<unique_id_type>(*it);
1580 (*it == static_cast<T>(-1)) ?
1582 cast_int<dof_id_type>(*it);
1585 cast_int<processor_id_type>(*it);
1588 cast_int<subdomain_id_type>(*it);
1590 #ifdef LIBMESH_ENABLE_AMR
1591 const unsigned int p_level =
1592 cast_int<unsigned int>(*it);
1602 #ifdef LIBMESH_ENABLE_UNIQUE_ID
1607 #ifdef LIBMESH_ENABLE_AMR
1618 for (
unsigned int n=0, n_n = elem->
n_nodes(); n != n_n;
1622 cast_int<dof_id_type>(*it);
1634 for (
unsigned char i=0; i!=4; ++i)
1640 libmesh_error_msg(
"Cannot open dimension " \
1642 <<
" mesh file when configured without " \
1671 std::vector<dof_id_type> needed_nodes; needed_nodes.reserve (
mesh.
n_nodes());
1674 needed_nodes.push_back(node->id());
1676 std::sort (needed_nodes.begin(), needed_nodes.end());
1679 libmesh_assert (std::unique(needed_nodes.begin(), needed_nodes.end()) == needed_nodes.end());
1683 std::vector<Real> coords;
1684 std::pair<std::vector<dof_id_type>::iterator,
1685 std::vector<dof_id_type>::iterator> pos;
1686 pos.first = needed_nodes.begin();
1689 for (std::size_t blk=0, first_node=0, last_node=0; last_node<
n_nodes; blk++)
1694 coords.resize(3*(last_node - first_node));
1697 io.
data_stream (coords.empty() ? nullptr : coords.data(),
1698 cast_int<unsigned int>(coords.size()));
1703 this->
comm().broadcast (coords);
1705 for (std::size_t n=first_node,
idx=0; n<last_node; n++,
idx+=3)
1710 pos = std::equal_range (pos.first, needed_nodes.end(), n);
1712 if (pos.first != pos.second)
1714 libmesh_assert_equal_to (*pos.first, n);
1730 unsigned short read_unique_ids;
1733 io.
data (read_unique_ids);
1735 this->
comm().broadcast (read_unique_ids);
1738 if (!read_unique_ids)
1741 std::vector<uint32_t> unique_32;
1742 std::vector<uint64_t> unique_64;
1745 pos.first = needed_nodes.begin();
1747 for (std::size_t blk=0, first_node=0, last_node=0; last_node<
n_nodes; blk++)
1755 unique_64.resize(last_node - first_node);
1757 unique_32.resize(last_node - first_node);
1762 io.
data_stream (unique_64.empty() ? nullptr : unique_64.data(),
1763 cast_int<unsigned int>(unique_64.size()));
1765 io.
data_stream (unique_32.empty() ? nullptr : unique_32.data(),
1766 cast_int<unsigned int>(unique_32.size()));
1769 #ifdef LIBMESH_ENABLE_UNIQUE_ID
1771 this->
comm().broadcast (unique_64);
1773 this->
comm().broadcast (unique_32);
1775 for (std::size_t n=first_node,
idx=0; n<last_node; n++,
idx++)
1780 pos = std::equal_range (pos.first, needed_nodes.end(), n);
1782 if (pos.first != pos.second)
1784 libmesh_assert_equal_to (*pos.first, n);
1793 #endif // LIBMESH_ENABLE_UNIQUE_ID
1800 template <
typename T>
1816 std::vector<T> input_buffer;
1830 this->
comm().broadcast (n_bcs);
1832 for (std::size_t blk=0, first_bc=0, last_bc=0; last_bc<n_bcs; blk++)
1835 last_bc = std::min((blk+1)*
io_blksize, std::size_t(n_bcs));
1837 input_buffer.resize (3*(last_bc - first_bc));
1840 io.
data_stream (input_buffer.empty() ? nullptr : input_buffer.data(),
1841 cast_int<unsigned int>(input_buffer.size()));
1843 this->
comm().broadcast (input_buffer);
1850 for (std::size_t
idx=0, ibs=input_buffer.size();
idx<ibs;
idx+=3)
1853 cast_int<dof_id_type>(input_buffer[
idx+0]);
1854 const unsigned short side =
1855 cast_int<unsigned short>(input_buffer[
idx+1]);
1857 cast_int<boundary_id_type>(input_buffer[
idx+2]);
1863 if (bc_type ==
"side")
1865 libmesh_assert_less (side, elem->
n_sides());
1866 boundary_info.
add_side (elem, side, bc_id);
1868 else if (bc_type ==
"edge")
1870 libmesh_assert_less (side, elem->
n_edges());
1871 boundary_info.
add_edge (elem, side, bc_id);
1873 else if (bc_type ==
"shellface")
1876 libmesh_assert_less(side, 2);
1882 libmesh_error_msg(
"bc_type not recognized: " + bc_type);
1885 input_buffer.clear();
1891 template <
typename T>
1899 template <
typename T>
1907 template <
typename T>
1915 template <
typename T>
1931 std::vector<T> input_buffer;
1937 io.
data (n_nodesets);
1945 this->
comm().broadcast (n_nodesets);
1947 for (std::size_t blk=0, first_bc=0, last_bc=0; last_bc<n_nodesets; blk++)
1950 last_bc = std::min((blk+1)*
io_blksize, std::size_t(n_nodesets));
1952 input_buffer.resize (2*(last_bc - first_bc));
1955 io.
data_stream (input_buffer.empty() ? nullptr : input_buffer.data(),
1956 cast_int<unsigned int>(input_buffer.size()));
1958 this->
comm().broadcast (input_buffer);
1963 for (std::size_t
idx=0, ibs=input_buffer.size();
idx<ibs;
idx+=2)
1966 cast_int<dof_id_type>(input_buffer[
idx+0]);
1968 cast_int<boundary_id_type>(input_buffer[
idx+1]);
1972 boundary_info.
add_node (node, bc_id);
1974 input_buffer.clear();
1984 if (read_entity_info)
1987 std::vector<new_header_id_type> boundary_ids;
1988 std::vector<std::string> boundary_names;
1993 if (use_new_header_type)
1994 io.
data(n_boundary_names);
1999 n_boundary_names = temp;
2002 boundary_names.resize(n_boundary_names);
2004 if (n_boundary_names)
2006 if (use_new_header_type)
2007 io.
data(boundary_ids);
2010 std::vector<old_header_id_type> temp(n_boundary_names);
2012 boundary_ids.assign(temp.begin(), temp.end());
2014 io.
data(boundary_names);
2019 this->
comm().broadcast(n_boundary_names);
2020 if (n_boundary_names == 0)
2023 boundary_ids.resize(n_boundary_names);
2024 boundary_names.resize(n_boundary_names);
2025 this->
comm().broadcast(boundary_ids);
2026 this->
comm().broadcast(boundary_names);
2029 std::map<boundary_id_type, std::string> & boundary_map = is_sideset ?
2032 for (
unsigned int i=0; i<n_boundary_names; ++i)
2033 boundary_map.insert(std::make_pair(cast_int<boundary_id_type>(boundary_ids[i]), boundary_names[i]));
2045 conn.push_back(elem->
n_nodes());
2047 conn.push_back (elem->
type());
2056 conn.push_back (parent_id);
2058 conn.push_back (parent_pid);
2064 #ifdef LIBMESH_ENABLE_AMR
2065 conn.push_back (elem->
p_level());
2069 conn.push_back (elem->
node_id(n));
2075 (this->
version().find(
"0.9.2") != std::string::npos) ||
2076 (this->
version().find(
"0.9.6") != std::string::npos) ||
2077 (this->
version().find(
"1.1.0") != std::string::npos) ||
2078 (this->
version().find(
"1.3.0") != std::string::npos);
2084 (this->
version().find(
"0.9.6") != std::string::npos) ||
2085 (this->
version().find(
"1.1.0") != std::string::npos) ||
2086 (this->
version().find(
"1.3.0") != std::string::npos);
2092 (this->
version().find(
"1.1.0") != std::string::npos) ||
2093 (this->
version().find(
"1.3.0") != std::string::npos);
2099 (this->
version().find(
"1.3.0") != std::string::npos);