64 const std::size_t max_io_blksize = 256000;
72 struct CompareDofObjectsByID
74 bool operator()(
const DofObject * a,
75 const DofObject * b)
const 80 return a->id() < b->id();
87 template <
typename InValType>
92 std::vector<InValType> & _data;
102 if (_data.empty())
return;
103 _io.
data_stream (_data.data(), cast_int<unsigned int>(_data.size()));
116 const std::string & version,
117 const bool read_header_in,
118 const bool read_additional_data,
119 const bool read_legacy_format)
160 const bool read_ifem_info =
161 (version.rfind(
" with infinite elements") < version.size()) ||
176 for (
unsigned int var=0; var<nv; var++)
180 std::string var_name;
186 std::set<subdomain_id_type> domains;
187 if (io.
version() >= LIBMESH_VERSION_ID(0,7,2))
189 std::vector<subdomain_id_type> domain_array;
191 io.
data (domain_array);
192 for (
const auto &
id : domain_array)
228 if (read_legacy_format)
234 libMesh::out <<
"*****************************************************************\n" 235 <<
"* WARNING: reading a potentially incompatible restart file!!! *\n" 236 <<
"* contact libmesh-users@lists.sourceforge.net for more details *\n" 237 <<
"*****************************************************************" 247 io.
data (radial_fam);
254 #ifdef LIBMESH_ENABLE_INFINITE_ELEMENTS 276 unsigned int nvecs=0;
286 for (
unsigned int vec=0; vec<nvecs; vec++)
290 std::string vec_name;
295 if (read_additional_data)
309 #ifdef LIBMESH_ENABLE_DEPRECATED 311 const bool read_additional_data)
313 libmesh_deprecated();
329 std::vector<Number> global_vector;
330 std::vector<Number> reordered_vector;
336 io.
data (global_vector);
342 reordered_vector.resize(global_vector.size());
347 libmesh_assert_equal_to (global_vector.size(), this->
n_dofs());
351 const unsigned int sys = this->
number();
352 const unsigned int nv = cast_int<unsigned int>
354 libmesh_assert_less_equal (nv, this->
n_vars());
356 for (
unsigned int data_var=0; data_var<nv; data_var++)
361 for (
auto & node : this->
get_mesh().node_ptr_range())
362 for (
unsigned int index=0; index<node->n_comp(sys,var); index++)
364 libmesh_assert_not_equal_to (node->dof_number(sys, var, index),
367 libmesh_assert_less (cnt, global_vector.size());
369 reordered_vector[node->dof_number(sys, var, index)] =
370 global_vector[cnt++];
374 for (
auto & elem : this->
get_mesh().active_element_ptr_range())
375 for (
unsigned int index=0; index<elem->n_comp(sys,var); index++)
377 libmesh_assert_not_equal_to (elem->dof_number(sys, var, index),
380 libmesh_assert_less (cnt, global_vector.size());
382 reordered_vector[elem->dof_number(sys, var, index)] =
383 global_vector[cnt++];
387 *(this->
solution) = reordered_vector;
396 const std::size_t nvecs = this->
_vectors.size();
402 if (read_additional_data && nvecs &&
405 (
"Additional vectors in file do not match system");
407 std::map<std::string, NumericVector<Number> *>::iterator
417 std::fill (global_vector.begin(), global_vector.end(),
libMesh::zero);
420 io.
data (global_vector);
425 if (read_additional_data && nvecs)
432 std::fill (reordered_vector.begin(),
433 reordered_vector.end(),
436 reordered_vector.resize(global_vector.size());
438 libmesh_assert_equal_to (global_vector.size(), this->
n_dofs());
442 const unsigned int sys = this->
number();
443 const unsigned int nv = cast_int<unsigned int>
445 libmesh_assert_less_equal (nv, this->
n_vars());
447 for (
unsigned int data_var=0; data_var<nv; data_var++)
451 for (
auto & node : this->
get_mesh().node_ptr_range())
452 for (
unsigned int index=0; index<node->n_comp(sys,var); index++)
454 libmesh_assert_not_equal_to (node->dof_number(sys, var, index),
457 libmesh_assert_less (cnt, global_vector.size());
459 reordered_vector[node->dof_number(sys, var, index)] =
460 global_vector[cnt++];
464 for (
auto & elem : this->
get_mesh().active_element_ptr_range())
465 for (
unsigned int index=0; index<elem->n_comp(sys,var); index++)
467 libmesh_assert_not_equal_to (elem->dof_number(sys, var, index),
470 libmesh_assert_less (cnt, global_vector.size());
472 reordered_vector[elem->dof_number(sys, var, index)] =
473 global_vector[cnt++];
478 *(pos->second) = reordered_vector;
492 template <
typename InValType>
494 const bool read_additional_data)
530 std::vector<const DofObject *> ordered_nodes, ordered_elements;
532 std::set<const DofObject *, CompareDofObjectsByID>
533 ordered_nodes_set (this->
get_mesh().local_nodes_begin(),
534 this->
get_mesh().local_nodes_end());
536 ordered_nodes.insert(ordered_nodes.end(),
537 ordered_nodes_set.begin(),
538 ordered_nodes_set.end());
541 std::set<const DofObject *, CompareDofObjectsByID>
542 ordered_elements_set (this->
get_mesh().local_elements_begin(),
543 this->
get_mesh().local_elements_end());
545 ordered_elements.insert(ordered_elements.end(),
546 ordered_elements_set.begin(),
547 ordered_elements_set.end());
551 std::vector<InValType> io_buffer;
559 total_read_size += cast_int<dof_id_type>(io_buffer.size());
561 const unsigned int sys_num = this->
number();
562 const unsigned int nv = cast_int<unsigned int>
564 libmesh_assert_less_equal (nv, this->
n_vars());
569 for (
unsigned int data_var=0; data_var<nv; data_var++)
575 for (
const auto & node : ordered_nodes)
576 for (
unsigned int comp=0; comp<node->n_comp(sys_num, var); comp++)
578 libmesh_assert_not_equal_to (node->dof_number(sys_num, var, comp),
580 libmesh_assert_less (cnt, io_buffer.size());
581 this->
solution->set(node->dof_number(sys_num, var, comp), io_buffer[cnt++]);
585 for (
const auto & elem : ordered_elements)
586 for (
unsigned int comp=0; comp<elem->n_comp(sys_num, var); comp++)
588 libmesh_assert_not_equal_to (elem->dof_number(sys_num, var, comp),
590 libmesh_assert_less (cnt, io_buffer.size());
591 this->
solution->set(elem->dof_number(sys_num, var, comp), io_buffer[cnt++]);
597 for (
unsigned int data_var=0; data_var<nv; data_var++)
605 std::vector<dof_id_type> SCALAR_dofs;
608 for (std::size_t i=0; i<SCALAR_dofs.size(); i++)
609 this->
solution->set(SCALAR_dofs[i], io_buffer[cnt++]);
623 const std::size_t nvecs = this->
_vectors.size();
629 if (read_additional_data && nvecs &&
632 (
"Additional vectors in file do not match system");
634 std::map<std::string, NumericVector<Number> *>::const_iterator
648 total_read_size += cast_int<dof_id_type>(io_buffer.size());
653 if (read_additional_data && nvecs)
656 for (
unsigned int data_var=0; data_var<nv; data_var++)
662 for (
const auto & node : ordered_nodes)
663 for (
unsigned int comp=0; comp<node->n_comp(sys_num, var); comp++)
665 libmesh_assert_not_equal_to (node->dof_number(sys_num, var, comp),
667 libmesh_assert_less (cnt, io_buffer.size());
668 pos->second->set(node->dof_number(sys_num, var, comp), io_buffer[cnt++]);
672 for (
const auto & elem : ordered_elements)
673 for (
unsigned int comp=0; comp<elem->n_comp(sys_num, var); comp++)
675 libmesh_assert_not_equal_to (elem->dof_number(sys_num, var, comp),
677 libmesh_assert_less (cnt, io_buffer.size());
678 pos->second->set(elem->dof_number(sys_num, var, comp), io_buffer[cnt++]);
684 for (
unsigned int data_var=0; data_var<nv; data_var++)
692 std::vector<dof_id_type> SCALAR_dofs;
695 for (std::size_t sd=0; sd<SCALAR_dofs.size(); sd++)
696 pos->second->set(SCALAR_dofs[sd], io_buffer[cnt++]);
702 pos->second->close();
724 template <
typename InValType>
726 const bool read_additional_data)
739 parallel_object_only();
750 this->read_serialized_vector<InValType>(io, this->
solution.get());
754 io.comment (comment);
762 const std::size_t nvecs = this->
_vectors.size();
768 if (read_additional_data && nvecs &&
771 (
"Additional vectors in file do not match system");
773 std::map<std::string, NumericVector<Number> *>::const_iterator
782 this->read_serialized_vector<InValType>
783 (io, (read_additional_data && nvecs) ? pos->second :
nullptr);
787 io.comment (comment);
810 template <
typename iterator_type,
typename InValType>
812 const iterator_type begin,
813 const iterator_type
end,
817 const unsigned int var_to_read)
const 839 vars_to_read.clear();
840 vars_to_read.push_back(var_to_read);
845 num_vecs = cast_int<unsigned int>(vecs.size());
847 io_blksize = cast_int<dof_id_type>(
std::min(max_io_blksize, static_cast<std::size_t>(n_objs))),
848 num_blks = cast_int<unsigned int>(std::ceil(static_cast<double>(n_objs)/
849 static_cast<double>(io_blksize)));
853 std::size_t n_read_values=0;
855 std::vector<std::vector<dof_id_type>> xfer_ids(num_blks);
856 std::vector<std::vector<Number>> recv_vals(num_blks);
857 std::vector<Parallel::Request>
858 id_requests(num_blks), val_requests(num_blks);
859 std::vector<Parallel::MessageTag>
860 id_tags(num_blks), val_tags(num_blks);
866 std::vector<std::size_t>
867 xfer_ids_size (num_blks,0),
868 recv_vals_size (num_blks,0);
871 for (iterator_type it=begin; it!=
end; ++it)
875 block =
id/io_blksize;
877 libmesh_assert_less (block, num_blks);
879 xfer_ids_size[block] += 2;
882 for (
const auto & var : vars_to_read)
883 n_comp_tot += (*it)->n_comp(sys_num, var);
885 recv_vals_size[block] += n_comp_tot*num_vecs;
890 std::vector<std::size_t> tot_vals_size(recv_vals_size);
891 this->
comm().
sum (tot_vals_size);
903 first_object = blk*io_blksize,
904 last_object =
std::min(cast_int<dof_id_type>((blk+1)*io_blksize), n_objs);
907 std::vector<dof_id_type> & ids (xfer_ids[blk]);
908 std::vector<Number> & vals (recv_vals[blk]);
912 ids.clear(); ids.reserve (xfer_ids_size[blk]);
913 vals.resize(recv_vals_size[blk]);
915 if (recv_vals_size[blk] != 0)
916 for (iterator_type it=begin; it!=
end; ++it)
917 if (((*it)->id() >= first_object) &&
918 ((*it)->id() < last_object))
920 ids.push_back((*it)->id());
922 unsigned int n_comp_tot=0;
924 for (
const auto & var : vars_to_read)
925 n_comp_tot += (*it)->n_comp(sys_num, var);
927 ids.push_back (n_comp_tot*num_vecs);
930 #ifdef LIBMESH_HAVE_MPI 935 this->
comm().
send (0, ids, id_requests[blk], id_tags[blk]);
938 this->
comm().
receive (0, vals, val_requests[blk], val_tags[blk]);
948 std::vector<std::vector<dof_id_type>> recv_ids (this->
n_processors());
949 std::vector<std::vector<Number>> send_vals (this->
n_processors());
950 std::vector<Parallel::Request> reply_requests (this->
n_processors());
951 std::vector<unsigned int> obj_val_offsets;
952 std::vector<Number> input_vals;
953 std::vector<InValType> input_vals_tmp;
960 first_object = blk*io_blksize,
961 last_object =
std::min(cast_int<dof_id_type>((blk+1)*io_blksize), n_objs),
962 n_objects_blk = last_object - first_object;
970 input_vals.resize(tot_vals_size[blk]);
971 input_vals_tmp.resize(tot_vals_size[blk]);
974 ThreadedIO<InValType> threaded_io(io, input_vals_tmp);
980 obj_val_offsets.resize (n_objects_blk); std::fill (obj_val_offsets.begin(), obj_val_offsets.end(), 0);
984 std::size_t n_vals_blk = 0;
988 for (
unsigned int comm_step=0; comm_step<this->
n_processors(); comm_step++)
990 #ifdef LIBMESH_HAVE_MPI 993 std::vector<dof_id_type> & ids (recv_ids[id_status.
source()]);
994 std::size_t & n_vals_proc (recv_vals_size[id_status.
source()]);
998 std::vector<dof_id_type> & ids (recv_ids[0]);
999 std::size_t & n_vals_proc (recv_vals_size[0]);
1000 ids = xfer_ids[blk];
1007 for (std::size_t
idx=0;
idx<ids.size();
idx+=2)
1010 local_idx = ids[
idx+0]-first_object,
1011 n_vals_tot_allvecs = ids[
idx+1];
1013 libmesh_assert_less (local_idx, n_objects_blk);
1015 obj_val_offsets[local_idx] = n_vals_tot_allvecs;
1016 n_vals_proc += n_vals_tot_allvecs;
1020 n_vals_blk += n_vals_proc;
1027 std::partial_sum(obj_val_offsets.begin(), obj_val_offsets.end(),
1028 obj_val_offsets.begin());
1030 libmesh_assert_equal_to (n_vals_blk, obj_val_offsets.back());
1031 libmesh_assert_equal_to (n_vals_blk, tot_vals_size[blk]);
1036 for (std::size_t i_val=0; i_val<input_vals.size(); i_val++)
1037 input_vals[i_val] = input_vals_tmp[i_val];
1039 n_read_values += input_vals.size();
1044 const std::vector<dof_id_type> & ids (recv_ids[proc]);
1045 std::vector<Number> & vals (send_vals[proc]);
1046 const std::size_t & n_vals_proc (recv_vals_size[proc]);
1048 vals.clear(); vals.reserve(n_vals_proc);
1050 for (std::size_t
idx=0;
idx<ids.size();
idx+=2)
1053 local_idx = ids[
idx+0]-first_object,
1054 n_vals_tot_allvecs = ids[
idx+1];
1056 std::vector<Number>::const_iterator in_vals(input_vals.begin());
1058 std::advance (in_vals, obj_val_offsets[local_idx-1]);
1060 for (
unsigned int val=0; val<n_vals_tot_allvecs; val++, ++in_vals)
1062 libmesh_assert (in_vals != input_vals.end());
1064 vals.push_back(*in_vals);
1068 #ifdef LIBMESH_HAVE_MPI 1070 this->
comm().
send (proc, vals, reply_requests[proc], val_tags[blk]);
1072 recv_vals[blk] = vals;
1081 const std::vector<Number> & vals (recv_vals[blk]);
1082 std::vector<Number>::const_iterator val_it(vals.begin());
1084 if (!recv_vals[blk].empty())
1085 for (iterator_type it=begin; it!=
end; ++it)
1086 if (((*it)->id() >= first_object) &&
1087 ((*it)->id() < last_object))
1089 for (
auto & vec : vecs)
1090 for (
const auto & var : vars_to_read)
1092 const unsigned int n_comp = (*it)->n_comp(sys_num, var);
1094 for (
unsigned int comp=0; comp<n_comp; comp++, ++val_it)
1096 const dof_id_type dof_index = (*it)->dof_number (sys_num, var, comp);
1097 libmesh_assert (val_it != vals.end());
1100 libmesh_assert_greater_equal (dof_index, vec->first_local_index());
1101 libmesh_assert_less (dof_index, vec->last_local_index());
1103 vec->set (dof_index, *val_it);
1116 return n_read_values;
1125 unsigned int n_assigned_vals = 0;
1129 std::vector<Number> input_buffer(n_SCALAR_dofs);
1131 io.
data_stream(input_buffer.data(), n_SCALAR_dofs);
1133 #ifdef LIBMESH_HAVE_MPI 1152 std::vector<dof_id_type> SCALAR_dofs;
1155 for (std::size_t i=0; i<SCALAR_dofs.size(); i++)
1158 vec->
set (SCALAR_dofs[i], input_buffer[i]);
1163 return n_assigned_vals;
1167 template <
typename InValType>
1171 parallel_object_only();
1183 libmesh_assert (io.
reading());
1186 unsigned int vector_length=0;
1188 std::size_t n_assigned_vals=0;
1193 io.
data(vector_length,
"# vector length");
1196 const unsigned int nv = cast_int<unsigned int>
1202 libmesh_assert_less_equal (nv, this->
n_vars());
1205 if (io.
version() >= LIBMESH_VERSION_ID(0,7,4))
1213 this->
get_mesh().local_nodes_begin(),
1214 this->
get_mesh().local_nodes_end(),
1226 this->
get_mesh().local_elements_begin(),
1227 this->
get_mesh().local_elements_end(),
1237 for (
unsigned int data_var=0; data_var<nv; data_var++)
1248 this->
get_mesh().local_nodes_begin(),
1249 this->
get_mesh().local_nodes_end(),
1262 this->
get_mesh().local_elements_begin(),
1263 this->
get_mesh().local_elements_end(),
1274 for (
unsigned int data_var=0; data_var<nv; data_var++)
1290 this->
comm().
sum (n_assigned_vals);
1291 libmesh_assert_equal_to (n_assigned_vals, vector_length);
1294 return vector_length;
1300 const std::string & ,
1301 const bool write_additional_data)
const 1336 libmesh_assert (io.
writing());
1344 std::string comment;
1352 comment =
"# No. of Variables in System \"";
1353 comment += this->
name();
1356 unsigned int nv = this->
n_vars();
1357 io.
data (nv, comment.c_str());
1361 for (
unsigned int var=0; var<this->
n_vars(); var++)
1367 comment =
"# Name, Variable No. ";
1368 std::sprintf(buf,
"%u", var);
1370 comment +=
", System \"";
1371 comment += this->
name();
1375 io.
data (var_name, comment.c_str());
1381 comment =
"# Subdomains, Variable \"";
1384 comment +=
"\", System \"";
1385 comment += this->
name();
1389 std::vector<subdomain_id_type> domain_array;
1390 domain_array.assign(domains.begin(), domains.end());
1391 io.
data (domain_array, comment.c_str());
1399 comment =
"# Approximation Order, Variable \"";
1402 comment +=
"\", System \"";
1403 comment += this->
name();
1407 io.
data (order, comment.c_str());
1411 #ifdef LIBMESH_ENABLE_INFINITE_ELEMENTS 1415 comment =
"# Radial Approximation Order, Variable \"";
1418 comment +=
"\", System \"";
1419 comment += this->
name();
1423 io.
data (rad_order, comment.c_str());
1432 comment =
"# FE Family, Variable \"";
1435 comment +=
"\", System \"";
1436 comment += this->
name();
1440 int fam =
static_cast<int>(type.
family);
1441 io.
data (fam, comment.c_str());
1443 #ifdef LIBMESH_ENABLE_INFINITE_ELEMENTS 1445 comment =
"# Radial FE Family, Variable \"";
1448 comment +=
"\", System \"";
1449 comment += this->
name();
1453 io.
data (radial_fam, comment.c_str());
1455 comment =
"# Infinite Mapping Type, Variable \"";
1458 comment +=
"\", System \"";
1459 comment += this->
name();
1462 int i_map =
static_cast<int>(type.
inf_map);
1463 io.
data (i_map, comment.c_str());
1475 comment =
"# No. of Additional Vectors, System \"";
1476 comment += this->
name();
1479 unsigned int nvecs = write_additional_data ? this->
n_vectors () : 0;
1480 io.
data (nvecs, comment.c_str());
1483 if (write_additional_data)
1490 comment =
"# Name of ";
1491 std::sprintf(buf,
"%d", cnt++);
1493 comment +=
"th vector";
1494 std::string vec_name = pr.first;
1496 io.
data (vec_name, comment.c_str());
1505 const bool write_additional_data)
const 1530 std::string comment;
1532 libmesh_assert (io.
writing());
1534 std::vector<Number> io_buffer; io_buffer.reserve(this->
solution->local_size());
1544 std::vector<const DofObject *> ordered_nodes, ordered_elements;
1546 std::set<const DofObject *, CompareDofObjectsByID>
1547 ordered_nodes_set (this->
get_mesh().local_nodes_begin(),
1548 this->
get_mesh().local_nodes_end());
1550 ordered_nodes.insert(ordered_nodes.end(),
1551 ordered_nodes_set.begin(),
1552 ordered_nodes_set.end());
1555 std::set<const DofObject *, CompareDofObjectsByID>
1556 ordered_elements_set (this->
get_mesh().local_elements_begin(),
1557 this->
get_mesh().local_elements_end());
1559 ordered_elements.insert(ordered_elements.end(),
1560 ordered_elements_set.begin(),
1561 ordered_elements_set.end());
1564 const unsigned int sys_num = this->
number();
1565 const unsigned int nv = this->
n_vars();
1568 for (
unsigned int var=0; var<nv; var++)
1572 for (
const auto & node : ordered_nodes)
1573 for (
unsigned int comp=0; comp<node->n_comp(sys_num, var); comp++)
1575 libmesh_assert_not_equal_to (node->dof_number(sys_num, var, comp),
1578 io_buffer.push_back((*this->
solution)(node->dof_number(sys_num, var, comp)));
1582 for (
const auto & elem : ordered_elements)
1583 for (
unsigned int comp=0; comp<elem->n_comp(sys_num, var); comp++)
1585 libmesh_assert_not_equal_to (elem->dof_number(sys_num, var, comp),
1588 io_buffer.push_back((*this->
solution)(elem->dof_number(sys_num, var, comp)));
1593 for (
unsigned int var=0; var<this->
n_vars(); var++)
1599 std::vector<dof_id_type> SCALAR_dofs;
1602 for (std::size_t i=0; i<SCALAR_dofs.size(); i++)
1603 io_buffer.push_back((*this->solution)(SCALAR_dofs[i]));
1614 comment =
"# System \"";
1615 comment += this->
name();
1616 comment +=
"\" Solution Vector";
1619 io.
data (io_buffer, comment.c_str());
1624 if (write_additional_data)
1629 io_buffer.reserve(pr.second->local_size());
1632 for (
unsigned int var=0; var<nv; var++)
1636 for (
const auto & node : ordered_nodes)
1637 for (
unsigned int comp=0; comp<node->n_comp(sys_num, var); comp++)
1639 libmesh_assert_not_equal_to (node->dof_number(sys_num, var, comp),
1642 io_buffer.push_back((*pr.second)(node->dof_number(sys_num, var, comp)));
1646 for (
const auto & elem : ordered_elements)
1647 for (
unsigned int comp=0; comp<elem->n_comp(sys_num, var); comp++)
1649 libmesh_assert_not_equal_to (elem->dof_number(sys_num, var, comp),
1652 io_buffer.push_back((*pr.second)(elem->dof_number(sys_num, var, comp)));
1657 for (
unsigned int var=0; var<this->
n_vars(); var++)
1663 std::vector<dof_id_type> SCALAR_dofs;
1666 for (std::size_t i=0; i<SCALAR_dofs.size(); i++)
1667 io_buffer.push_back((*pr.second)(SCALAR_dofs[i]));
1678 comment =
"# System \"";
1679 comment += this->
name();
1680 comment +=
"\" Additional Vector \"";
1681 comment += pr.first;
1685 io.
data (io_buffer, comment.c_str());
1705 const bool write_additional_data)
const 1720 parallel_object_only();
1721 std::string comment;
1733 comment =
"# System \"";
1734 comment += this->
name();
1735 comment +=
"\" Solution Vector";
1741 if (write_additional_data)
1743 std::map<std::string, NumericVector<Number> *>::const_iterator
1746 for (; pos != this->
_vectors.end(); ++pos)
1754 comment =
"# System \"";
1755 comment += this->
name();
1756 comment +=
"\" Additional Vector \"";
1757 comment += pos->first;
1814 template <
typename iterator_type>
1817 const iterator_type begin,
1818 const iterator_type
end,
1820 const unsigned int var_to_write)
const 1822 parallel_object_only();
1840 std::vector<unsigned int> vars_to_write(1, var_to_write);
1844 vars_to_write.clear(); vars_to_write.reserve(this->
n_vars());
1845 for (
unsigned int var=0; var<this->
n_vars(); var++)
1846 vars_to_write.push_back(var);
1849 const dof_id_type io_blksize = cast_int<dof_id_type>
1850 (
std::min(max_io_blksize, static_cast<std::size_t>(n_objs)));
1853 sys_num = this->
number(),
1854 num_vecs = cast_int<unsigned int>(vecs.size()),
1855 num_blks = cast_int<unsigned int>(std::ceil(static_cast<double>(n_objs)/
1856 static_cast<double>(io_blksize)));
1863 std::size_t written_length=0;
1864 std::vector<std::vector<dof_id_type>> xfer_ids(num_blks);
1865 std::vector<std::vector<Number>> send_vals(num_blks);
1866 std::vector<Parallel::Request>
1867 id_requests(num_blks), val_requests(num_blks);
1868 std::vector<Parallel::MessageTag>
1869 id_tags(num_blks), val_tags(num_blks);
1875 std::vector<unsigned int>
1876 xfer_ids_size (num_blks,0),
1877 send_vals_size (num_blks,0);
1879 for (iterator_type it=begin; it!=
end; ++it)
1883 block =
id/io_blksize;
1885 libmesh_assert_less (block, num_blks);
1887 xfer_ids_size[block] += 2;
1889 unsigned int n_comp_tot=0;
1891 for (
const auto & var : vars_to_write)
1892 n_comp_tot += (*it)->n_comp(sys_num, var);
1894 send_vals_size[block] += n_comp_tot*num_vecs;
1901 for (
unsigned int blk=0; blk<num_blks; blk++)
1908 first_object = blk*io_blksize,
1909 last_object =
std::min(cast_int<dof_id_type>((blk+1)*io_blksize), n_objs);
1912 std::vector<dof_id_type> & ids (xfer_ids[blk]);
1913 std::vector<Number> & vals (send_vals[blk]);
1917 ids.clear(); ids.reserve (xfer_ids_size[blk]);
1918 vals.clear(); vals.reserve (send_vals_size[blk]);
1920 if (send_vals_size[blk] != 0)
1921 for (iterator_type it=begin; it!=
end; ++it)
1922 if (((*it)->id() >= first_object) &&
1923 ((*it)->id() < last_object))
1925 ids.push_back((*it)->id());
1929 unsigned int n_comp_tot=0;
1931 for (
const auto & var : vars_to_write)
1932 n_comp_tot += (*it)->n_comp(sys_num, var);
1934 ids.push_back (n_comp_tot*num_vecs);
1938 for (
const auto & vec : vecs)
1939 for (
const auto & var : vars_to_write)
1941 const unsigned int n_comp = (*it)->n_comp(sys_num, var);
1943 for (
unsigned int comp=0; comp<n_comp; comp++)
1945 libmesh_assert_greater_equal ((*it)->dof_number(sys_num, var, comp), vec->first_local_index());
1946 libmesh_assert_less ((*it)->dof_number(sys_num, var, comp), vec->last_local_index());
1947 vals.push_back((*vec)((*it)->dof_number(sys_num, var, comp)));
1952 #ifdef LIBMESH_HAVE_MPI 1957 this->
comm().
send (0, ids, id_requests[blk], id_tags[blk]);
1958 this->
comm().
send (0, vals, val_requests[blk], val_tags[blk]);
1965 std::vector<std::vector<dof_id_type>> recv_ids (this->
n_processors());
1966 std::vector<std::vector<Number>> recv_vals (this->
n_processors());
1967 std::vector<unsigned int> obj_val_offsets;
1968 std::vector<Number> output_vals;
1971 ThreadedIO<Number> threaded_io(io, output_vals);
1972 std::unique_ptr<Threads::Thread> async_io;
1974 for (
unsigned int blk=0; blk<num_blks; blk++)
1979 first_object = cast_int<dof_id_type>(blk*io_blksize),
1980 last_object =
std::min(cast_int<dof_id_type>((blk+1)*io_blksize), n_objs),
1981 n_objects_blk = last_object - first_object;
1986 obj_val_offsets.resize (n_objects_blk); std::fill (obj_val_offsets.begin(), obj_val_offsets.end(), 0);
1988 std::size_t n_val_recvd_blk=0;
1991 for (
unsigned int comm_step=0; comm_step<this->
n_processors(); comm_step++)
1993 #ifdef LIBMESH_HAVE_MPI 1996 std::vector<dof_id_type> & ids (recv_ids[id_status.
source()]);
1999 std::vector<dof_id_type> & ids (recv_ids[0]);
2000 ids = xfer_ids[blk];
2005 for (std::size_t
idx=0;
idx<ids.size();
idx+=2)
2008 local_idx = ids[
idx+0]-first_object,
2009 n_vals_tot_allvecs = ids[
idx+1];
2011 libmesh_assert_less (local_idx, n_objects_blk);
2012 libmesh_assert_less (local_idx, obj_val_offsets.size());
2014 obj_val_offsets[local_idx] = n_vals_tot_allvecs;
2017 #ifdef LIBMESH_HAVE_MPI 2020 std::vector<Number> & vals (recv_vals[val_status.
source()]);
2024 std::vector<Number> & vals (recv_vals[0]);
2025 vals = send_vals[blk];
2028 n_val_recvd_blk += vals.size();
2034 std::partial_sum(obj_val_offsets.begin(), obj_val_offsets.end(),
2035 obj_val_offsets.begin());
2039 if (async_io.get()) async_io->join();
2043 output_vals.resize(n_val_recvd_blk);
2046 for (
unsigned int proc=0; proc<this->
n_processors(); proc++)
2048 const std::vector<dof_id_type> & ids (recv_ids [proc]);
2049 const std::vector<Number> & vals(recv_vals[proc]);
2050 std::vector<Number>::const_iterator proc_vals(vals.begin());
2052 for (std::size_t
idx=0;
idx<ids.size();
idx+=2)
2055 local_idx = ids[
idx+0]-first_object,
2056 n_vals_tot_allvecs = ids[
idx+1];
2060 std::vector<Number>::iterator out_vals(output_vals.begin());
2062 std::advance (out_vals, obj_val_offsets[local_idx-1]);
2064 for (
unsigned int val=0; val<n_vals_tot_allvecs; val++, ++out_vals, ++proc_vals)
2066 libmesh_assert (out_vals != output_vals.end());
2067 libmesh_assert (proc_vals != vals.end());
2068 *out_vals = *proc_vals;
2076 written_length += output_vals.size();
2096 return written_length;
2102 const unsigned int var,
2105 unsigned int written_length=0;
2106 std::vector<Number> vals;
2111 std::vector<dof_id_type> SCALAR_dofs;
2113 const unsigned int n_scalar_dofs = cast_int<unsigned int>
2114 (SCALAR_dofs.size());
2116 for (
unsigned int i=0; i<n_scalar_dofs; i++)
2118 vals.push_back( vec(SCALAR_dofs[i]) );
2122 #ifdef LIBMESH_HAVE_MPI 2136 this->
comm().
send(0, vals, val_tag);
2145 const unsigned int vals_size =
2146 cast_int<unsigned int>(vals.size());
2148 written_length += vals_size;
2151 return written_length;
2159 parallel_object_only();
2161 libmesh_assert (io.
writing());
2170 written_length += cast_int<dof_id_type>
2173 this->
get_mesh().local_nodes_begin(),
2174 this->
get_mesh().local_nodes_end(),
2179 written_length += cast_int<dof_id_type>
2182 this->
get_mesh().local_elements_begin(),
2183 this->
get_mesh().local_elements_end(),
2188 for (
unsigned int var=0; var<this->
n_vars(); var++)
2196 libmesh_assert_equal_to (written_length, vec_length);
2198 return written_length;
2202 template <
typename InValType>
2206 parallel_object_only();
2219 libmesh_assert (io.
reading());
2224 unsigned int num_vecs=0;
2230 io.
data(vector_length);
2232 libmesh_assert_equal_to (num_vecs, vectors.size());
2236 libmesh_assert_not_equal_to (vectors[0], 0);
2237 libmesh_assert_equal_to (vectors[0]->size(), vector_length);
2250 std::size_t read_length = 0;
2256 this->
get_mesh().local_nodes_begin(),
2257 this->
get_mesh().local_nodes_end(),
2266 this->
get_mesh().local_elements_begin(),
2267 this->
get_mesh().local_elements_end(),
2274 for (std::size_t vec=0; vec<vectors.size(); vec++)
2275 for (
unsigned int var=0; var<this->
n_vars(); var++)
2278 libmesh_assert_not_equal_to (vectors[vec], 0);
2286 for (std::size_t vec=0; vec<vectors.size(); vec++)
2288 libmesh_assert_not_equal_to (vectors[vec], 0);
2289 vectors[vec]->close();
2300 parallel_object_only();
2302 libmesh_assert (io.
writing());
2309 std::size_t written_length = 0;
2314 n_vec = cast_int<unsigned int>(vectors.size());
2316 vec_size = vectors.empty() ? 0 : vectors[0]->size();
2318 io.
data(n_vec,
"# number of vectors");
2320 io.
data(vec_size,
"# vector length");
2328 this->
get_mesh().local_nodes_begin(),
2329 this->
get_mesh().local_nodes_end(),
2337 this->
get_mesh().local_elements_begin(),
2338 this->
get_mesh().local_elements_end(),
2343 for (std::size_t vec=0; vec<vectors.size(); vec++)
2344 for (
unsigned int var=0; var<this->
n_vars(); var++)
2347 libmesh_assert_not_equal_to (vectors[vec], 0);
2353 return written_length;
2359 template void System::read_parallel_data<Number> (
Xdr & io,
const bool read_additional_data);
2360 template void System::read_serialized_data<Number> (
Xdr & io,
const bool read_additional_data);
2362 template std::size_t System::read_serialized_vectors<Number> (
Xdr & io,
const std::vector<NumericVector<Number> *> & vectors)
const;
2363 #ifdef LIBMESH_USE_COMPLEX_NUMBERS 2364 template void System::read_parallel_data<Real> (
Xdr & io,
const bool read_additional_data);
2365 template void System::read_serialized_data<Real> (
Xdr & io,
const bool read_additional_data);
2367 template std::size_t System::read_serialized_vectors<Real> (
Xdr & io,
const std::vector<NumericVector<Number> *> & vectors)
const;
Manages the family, order, etc. parameters for a given FE.
void data(T &a, const char *comment="")
void send(const unsigned int dest_processor_id, const T &buf, const MessageTag &tag=no_tag) const
void wait(std::vector< Request > &r)
void write_serialized_data(Xdr &io, const bool write_additional_data=true) const
void write_parallel_data(Xdr &io, const bool write_additional_data) const
const Variable & variable(unsigned int var) const
const unsigned int invalid_uint
const unsigned int any_source
void comment(std::string &)
std::size_t read_serialized_blocked_dof_objects(const dof_id_type n_objects, const iterator_type begin, const iterator_type end, const InValType dummy, Xdr &io, const std::vector< NumericVector< Number > *> &vecs, const unsigned int var_to_read=libMesh::invalid_uint) const
virtual numeric_index_type size() const =0
OrderWrapper radial_order
unsigned int write_SCALAR_dofs(const NumericVector< Number > &vec, const unsigned int var, Xdr &io) const
uint8_t processor_id_type
const Parallel::Communicator & comm() const
void read_legacy_data(Xdr &io, const bool read_additional_data=true)
MessageTag get_unique_tag(int tagvalue) const
const MeshBase & get_mesh() const
dof_id_type n_dofs() const
void SCALAR_dof_indices(std::vector< dof_id_type > &di, const unsigned int vn, const bool old_dofs=false) const
Tnew cast_int(Told oldvar)
Manages the degrees of freedom (DOFs) in a simulation.
processor_id_type n_processors() const
const dof_id_type n_nodes
unsigned int number() const
NumericVector< Number > & add_vector(const std::string &vec_name, const bool projections=true, const ParallelType type=PARALLEL)
const std::set< subdomain_id_type > & active_subdomains() const
dof_id_type numeric_index_type
void read_header(Xdr &io, const std::string &version, const bool read_header=true, const bool read_additional_data=true, const bool read_legacy_format=false)
unsigned int n_vectors() const
unsigned short int variable_number(const std::string &var) const
numeric_index_type read_serialized_vector(Xdr &io, NumericVector< Number > *vec)
std::unique_ptr< NumericVector< Number > > solution
static const dof_id_type invalid_id
unsigned int _additional_data_written
const std::string & variable_name(const unsigned int i) const
std::size_t read_serialized_vectors(Xdr &io, const std::vector< NumericVector< Number > *> &vectors) const
C++ interface for the XDR (eXternal Data Representation) format.
std::size_t write_serialized_vectors(Xdr &io, const std::vector< const NumericVector< Number > *> &vectors) const
void read_parallel_data(Xdr &io, const bool read_additional_data)
ParallelType type() const
const FEType & variable_type(const unsigned int i) const
std::map< std::string, NumericVector< Number > *> _vectors
Status receive(const unsigned int dest_processor_id, T &buf, const MessageTag &tag=any_tag) const
unsigned int mesh_dimension() const
unsigned int read_SCALAR_dofs(const unsigned int var, Xdr &io, NumericVector< Number > *vec) const
virtual void set(const numeric_index_type i, const T value)=0
bool on_command_line(std::string arg)
const std::string & name() const
unsigned int n_vars() const
unsigned int add_variable(const std::string &var, const FEType &type, const std::set< subdomain_id_type > *const active_subdomains=nullptr)
virtual dof_id_type n_elem() const =0
processor_id_type processor_id() const
void data_stream(T *val, const unsigned int len, const unsigned int line_break=libMesh::invalid_uint)
OStreamProxy out(std::cout)
const DofMap & get_dof_map() const
long double min(long double a, double b)
void read_serialized_data(Xdr &io, const bool read_additional_data=true)
void broadcast(T &data, const unsigned int root_id=0) const
virtual dof_id_type n_nodes() const =0
std::size_t write_serialized_blocked_dof_objects(const std::vector< const NumericVector< Number > *> &vecs, const dof_id_type n_objects, const iterator_type begin, const iterator_type end, Xdr &io, const unsigned int var_to_write=libMesh::invalid_uint) const
std::vector< unsigned int > _written_var_indices
void write_header(Xdr &io, const std::string &version, const bool write_additional_data) const
const FEType & type() const
dof_id_type write_serialized_vector(Xdr &io, const NumericVector< Number > &vec) const