23 #include "libmesh/parallel.h" 24 #include "libmesh/parameters.h" 25 #include "libmesh/numeric_vector.h" 27 #ifdef LIBMESH_HAVE_CXX11_TYPE_TRAITS 28 #include <type_traits> 37 #include <unordered_map> 59 inline void storeHelper(std::ostream & stream, P & data,
void * context);
65 inline void storeHelper(std::ostream & stream, std::vector<P> & data,
void * context);
71 inline void storeHelper(std::ostream & stream, std::shared_ptr<P> & data,
void * context);
77 inline void storeHelper(std::ostream & stream, std::unique_ptr<P> & data,
void * context);
83 inline void storeHelper(std::ostream & stream, std::set<P> & data,
void * context);
88 template <
typename P,
typename Q>
89 inline void storeHelper(std::ostream & stream, std::map<P, Q> & data,
void * context);
94 template <
typename P,
typename Q>
95 inline void storeHelper(std::ostream & stream, std::unordered_map<P, Q> & data,
void * context);
100 template <
typename P>
101 inline void storeHelper(std::ostream & stream, std::optional<P> & data,
void * context);
106 template <
typename P,
typename Q>
112 template <
typename T>
118 template <
typename P>
119 inline void loadHelper(std::istream & stream, P & data,
void * context);
124 template <
typename P>
125 inline void loadHelper(std::istream & stream, std::vector<P> & data,
void * context);
130 template <
typename P>
131 inline void loadHelper(std::istream & stream, std::shared_ptr<P> & data,
void * context);
136 template <
typename P>
137 inline void loadHelper(std::istream & stream, std::unique_ptr<P> & data,
void * context);
142 template <
typename P>
143 inline void loadHelper(std::istream & stream, std::set<P> & data,
void * context);
148 template <
typename P,
typename Q>
149 inline void loadHelper(std::istream & stream, std::map<P, Q> & data,
void * context);
154 template <
typename P,
typename Q>
155 inline void loadHelper(std::istream & stream, std::unordered_map<P, Q> & data,
void * context);
160 template <
typename P>
161 inline void loadHelper(std::istream & stream, std::optional<P> & data,
void * context);
166 template <
typename P,
typename Q>
172 template <
typename T>
175 template <
typename T>
176 inline void dataStore(std::ostream & stream, T & v,
void * );
180 template <
typename T>
184 #ifdef LIBMESH_HAVE_CXX11_TYPE_TRAITS 185 static_assert(std::is_polymorphic<T>::value ==
false,
186 "Cannot serialize a class that has virtual " 187 "members!\nWrite a custom dataStore() " 188 "template specialization!\n\n");
189 static_assert(std::is_trivially_copyable<T>::value,
190 "Cannot serialize a class that is not trivially copyable!\nWrite a custom " 191 "dataStore() template specialization!\n\n");
195 stream.write((
char *)&v,
sizeof(v));
196 mooseAssert(!stream.bad(),
"Failed to store");
199 template <
typename T>
203 mooseError(
"Attempting to store a raw pointer type: \"",
205 " *\" as restartable data!\nWrite a custom dataStore() template specialization!\n\n");
208 void dataStore(std::ostream & stream, Point & p,
void * context);
210 template <
typename T,
typename U>
212 dataStore(std::ostream & stream, std::pair<T, U> & p,
void * context)
218 template <
typename T>
220 dataStore(std::ostream & stream, std::vector<T> & v,
void * context)
223 unsigned int size = v.size();
226 for (
unsigned int i = 0; i < size; i++)
230 template <
typename T>
232 dataStore(std::ostream & stream, std::shared_ptr<T> & v,
void * context)
239 template <
typename T>
241 dataStore(std::ostream & stream, std::unique_ptr<T> & v,
void * context)
248 template <
typename T>
250 dataStore(std::ostream & stream, std::set<T> & s,
void * context)
253 unsigned int size = s.size();
256 typename std::set<T>::iterator it = s.begin();
257 typename std::set<T>::iterator end = s.end();
259 for (; it != end; ++it)
261 T & x =
const_cast<T &
>(*it);
266 template <
typename T>
268 dataStore(std::ostream & stream, std::list<T> & l,
void * context)
271 unsigned int size = l.size();
274 typename std::list<T>::iterator it = l.begin();
275 typename std::list<T>::iterator end = l.end();
277 for (; it != end; ++it)
279 T & x =
const_cast<T &
>(*it);
284 template <
typename T>
286 dataStore(std::ostream & stream, std::deque<T> & l,
void * context)
289 unsigned int size = l.size();
292 typename std::deque<T>::iterator it = l.begin();
293 typename std::deque<T>::iterator end = l.end();
295 for (; it != end; ++it)
297 T & x =
const_cast<T &
>(*it);
302 template <
typename T,
typename U>
304 dataStore(std::ostream & stream, std::map<T, U> & m,
void * context)
307 unsigned int size = m.size();
310 typename std::map<T, U>::iterator it = m.begin();
311 typename std::map<T, U>::iterator end = m.end();
313 for (; it != end; ++it)
315 T & key =
const_cast<T &
>(it->first);
323 template <
typename T,
typename U>
325 dataStore(std::ostream & stream, std::unordered_map<T, U> & m,
void * context)
328 unsigned int size = m.size();
331 typename std::unordered_map<T, U>::iterator it = m.begin();
332 typename std::unordered_map<T, U>::iterator end = m.end();
334 for (; it != end; ++it)
336 T & key =
const_cast<T &
>(it->first);
344 template <
typename T>
346 dataStore(std::ostream & stream, std::optional<T> & m,
void * context)
348 bool has_value = m.has_value();
355 template <
typename T,
typename U>
360 unsigned int size = m.size();
366 for (; it != end; ++it)
368 T & key =
const_cast<T &
>(it->first);
378 void dataStore(std::ostream & stream, Real & v,
void * context);
380 void dataStore(std::ostream & stream, std::string & v,
void * context);
382 void dataStore(std::ostream & stream, VariableName & v,
void * context);
384 void dataStore(std::ostream & stream,
bool & v,
void * context);
388 void dataStore(std::ostream & stream, std::vector<bool> & v,
void * context);
390 void dataStore(std::ostream & stream,
const Elem *& e,
void * context);
392 void dataStore(std::ostream & stream,
const Node *& n,
void * context);
394 void dataStore(std::ostream & stream, Elem *& e,
void * context);
396 void dataStore(std::ostream & stream, Node *& n,
void * context);
398 void dataStore(std::ostream & stream, std::stringstream & s,
void * context);
422 template <std::
size_t N>
424 dataStore(std::ostream & stream, std::array<DualReal, N> & dn,
void * context)
426 for (std::size_t i = 0; i <
N; ++i)
430 template <std::
size_t N>
434 for (std::size_t i = 0; i <
N; ++i)
438 template <
typename T>
440 dataStore(std::ostream & stream, NumericVector<T> & v,
void * context)
446 for (
numeric_index_type i = v.first_local_index(); i < v.first_local_index() + size; i++)
454 void dataStore(std::ostream & stream, Vec & v,
void * context);
456 template <
typename T>
458 dataStore(std::ostream & stream, DenseVector<T> & v,
void * context)
460 unsigned int m = v.size();
462 for (
unsigned int i = 0; i < v.size(); i++)
469 template <
typename T>
470 void dataStore(std::ostream & stream, TensorValue<T> & v,
void * context);
472 template <
typename T>
473 void dataStore(std::ostream & stream, DenseMatrix<T> & v,
void * context);
475 template <
typename T>
476 void dataStore(std::ostream & stream, VectorValue<T> & v,
void * context);
478 template <
typename T>
485 template <
typename T>
492 template <
typename T>
499 template <
typename T>
506 template <
typename T>
513 template <
typename T>
522 template <
typename T>
526 stream.read((
char *)&v,
sizeof(v));
527 mooseAssert(!stream.bad(),
"Failed to load");
530 template <
typename T>
534 mooseError(
"Attempting to load a raw pointer type: \"",
536 " *\" as restartable data!\nWrite a custom dataLoad() template specialization!\n\n");
539 template <
typename T,
typename U>
541 dataLoad(std::istream & stream, std::pair<T, U> & p,
void * context)
547 template <
typename T>
549 dataLoad(std::istream & stream, std::vector<T> & v,
void * context)
552 unsigned int size = 0;
557 for (
unsigned int i = 0; i < size; i++)
561 template <
typename T>
563 dataLoad(std::istream & stream, std::shared_ptr<T> & v,
void * context)
570 template <
typename T>
572 dataLoad(std::istream & stream, std::unique_ptr<T> & v,
void * context)
579 template <
typename T>
581 dataLoad(std::istream & stream, std::set<T> & s,
void * context)
584 unsigned int size = 0;
587 for (
unsigned int i = 0; i < size; i++)
591 s.insert(std::move(data));
595 template <
typename T>
597 dataLoad(std::istream & stream, std::list<T> & l,
void * context)
600 unsigned int size = 0;
603 for (
unsigned int i = 0; i < size; i++)
607 l.push_back(std::move(data));
611 template <
typename T>
613 dataLoad(std::istream & stream, std::deque<T> & l,
void * context)
616 unsigned int size = 0;
619 for (
unsigned int i = 0; i < size; i++)
623 l.push_back(std::move(data));
627 template <
typename T,
typename U>
629 dataLoad(std::istream & stream, std::map<T, U> & m,
void * context)
634 unsigned int size = 0;
637 for (
unsigned int i = 0; i < size; i++)
647 template <
typename T,
typename U>
649 dataLoad(std::istream & stream, std::unordered_map<T, U> & m,
void * context)
654 unsigned int size = 0;
657 for (
unsigned int i = 0; i < size; i++)
667 template <
typename T>
669 dataLoad(std::istream & stream, std::optional<T> & m,
void * context)
672 dataLoad(stream, has_value,
nullptr);
683 template <
typename T,
typename U>
688 unsigned int size = 0;
691 for (
unsigned int i = 0; i < size; i++)
703 void dataLoad(std::istream & stream, Real & v,
void * );
705 void dataLoad(std::istream & stream, std::string & v,
void * );
707 void dataLoad(std::istream & stream, VariableName & v,
void * );
709 void dataLoad(std::istream & stream,
bool & v,
void * );
713 void dataLoad(std::istream & stream, std::vector<bool> & v,
void * );
715 void dataLoad(std::istream & stream,
const Elem *& e,
void * context);
717 void dataLoad(std::istream & stream,
const Node *& e,
void * context);
719 void dataLoad(std::istream & stream, Elem *& e,
void * context);
721 void dataLoad(std::istream & stream, Node *& e,
void * context);
723 void dataLoad(std::istream & stream, std::stringstream & s,
void * context);
750 void dataLoad(std::istream & stream,
754 template <std::
size_t N>
756 dataLoad(std::istream & stream, std::array<DualReal, N> & dn,
void * context)
758 for (std::size_t i = 0; i <
N; ++i)
762 template <std::
size_t N>
766 for (std::size_t i = 0; i <
N; ++i)
770 template <
typename T>
772 dataLoad(std::istream & stream, NumericVector<T> & v,
void * context)
775 for (
numeric_index_type i = v.first_local_index(); i < v.first_local_index() + size; i++)
785 void dataLoad(std::istream & stream, Vec & v,
void * context);
787 template <
typename T>
789 dataLoad(std::istream & stream, DenseVector<T> & v,
void * context)
794 for (
unsigned int i = 0; i < n; i++)
802 template <
typename T>
803 void dataLoad(std::istream & stream, TensorValue<T> & v,
void * context);
805 template <
typename T>
806 void dataLoad(std::istream & stream, DenseMatrix<T> & v,
void * context);
808 template <
typename T>
809 void dataLoad(std::istream & stream, VectorValue<T> & v,
void * context);
811 template <
typename T>
818 template <
typename T>
825 template <
typename T>
832 template <
typename T>
839 template <
typename T>
846 template <
typename T>
854 template <
typename P>
862 template <
typename P>
864 storeHelper(std::ostream & stream, std::vector<P> & data,
void * context)
870 template <
typename P>
872 storeHelper(std::ostream & stream, std::shared_ptr<P> & data,
void * context)
878 template <
typename P>
880 storeHelper(std::ostream & stream, std::unique_ptr<P> & data,
void * context)
886 template <
typename P>
888 storeHelper(std::ostream & stream, std::set<P> & data,
void * context)
894 template <
typename P,
typename Q>
896 storeHelper(std::ostream & stream, std::map<P, Q> & data,
void * context)
902 template <
typename P,
typename Q>
904 storeHelper(std::ostream & stream, std::unordered_map<P, Q> & data,
void * context)
910 template <
typename P>
912 storeHelper(std::ostream & stream, std::optional<P> & data,
void * context)
918 template <
typename P,
typename Q>
931 template <
typename T>
935 std::size_t size = data.
size();
940 mooseAssert(data.
hasValue(i),
"Data doesn't have a value");
946 template <
typename P>
954 template <
typename P>
956 loadHelper(std::istream & stream, std::vector<P> & data,
void * context)
962 template <
typename P>
964 loadHelper(std::istream & stream, std::shared_ptr<P> & data,
void * context)
970 template <
typename P>
972 loadHelper(std::istream & stream, std::unique_ptr<P> & data,
void * context)
978 template <
typename P>
980 loadHelper(std::istream & stream, std::set<P> & data,
void * context)
986 template <
typename P,
typename Q>
988 loadHelper(std::istream & stream, std::map<P, Q> & data,
void * context)
994 template <
typename P,
typename Q>
996 loadHelper(std::istream & stream, std::unordered_map<P, Q> & data,
void * context)
1002 template <
typename P>
1004 loadHelper(std::istream & stream, std::optional<P> & data,
void * context)
1010 template <
typename P,
typename Q>
1024 template <
typename T>
1036 void dataLoad(std::istream & stream, Point & p,
void * context);
1038 #ifndef TIMPI_HAVE_STRING_PACKING 1049 template <
typename T>
1053 static const unsigned int size_bytes = 4;
1059 unsigned int string_len =
reinterpret_cast<const unsigned char &
>(in[size_bytes - 1]);
1060 for (
signed int i = size_bytes - 2; i >= 0; --i)
1063 string_len +=
reinterpret_cast<const unsigned char &
>(in[i]);
1068 static unsigned int packed_size(
typename std::vector<T>::const_iterator in)
1070 return get_string_len(in) + size_bytes;
1075 return s.size() + size_bytes;
1078 template <
typename Iter>
1079 static void pack(
const std::basic_string<T> & b, Iter data_out,
const void *)
1081 unsigned int string_len = b.size();
1082 for (
unsigned int i = 0; i != size_bytes; ++i)
1084 *data_out++ = (string_len % 256);
1088 std::copy(b.begin(), b.end(), data_out);
1091 static std::basic_string<T>
unpack(
typename std::vector<T>::const_iterator in,
void *)
1093 unsigned int string_len = get_string_len(in);
1095 std::ostringstream oss;
1096 for (
unsigned int i = 0; i < string_len; ++i)
1097 oss << reinterpret_cast<const unsigned char &>(in[i + size_bytes]);
1099 in += size_bytes + string_len;
std::string name(const ElemQuality q)
RankFourTensorTempl is designed to handle any N-dimensional fourth order tensor, C.
const std::unique_ptr< T > & pointerValue(const std::size_t i) const
Returns a read-only reference to the underlying unique pointer at index i.
std::array< T, N2 > _vals
The values of the rank-four tensor.
HashMap is an abstraction for dictionary data type, we make it thread-safe by locking inserts...
This class defines a Tensor that can change its shape.
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application...
static std::basic_string< T > unpack(typename std::vector< T >::const_iterator in, void *)
DualNumber< Real, DNDerivativeType, true > DualReal
Storage container that stores a vector of unique pointers of T, but represents most of the public fac...
static unsigned int packable_size(const std::basic_string< T > &s, const void *)
The following methods are specializations for using the libMesh::Parallel::packed_range_* routines fo...
T _coords[LIBMESH_DIM *LIBMESH_DIM]
RankThreeTensor is designed to handle any N-dimensional third order tensor, r.
void resize(const std::size_t size)
Resizes the underlying vector.
void storeHelper(std::ostream &stream, P &data, void *context)
Scalar helper routine.
Real value(unsigned n, unsigned alpha, unsigned beta, Real x)
dof_id_type numeric_index_type
static unsigned int packed_size(typename std::vector< T >::const_iterator in)
SymmetricRankTwoTensorTempl is designed to handle the Stress or Strain Tensor for an anisotropic mate...
T _vals[N3]
The values of the rank-three tensor stored by index=((i * LIBMESH_DIM + j) * LIBMESH_DIM + k) ...
T _vals[N4]
The values of the rank-four tensor stored by index=(((i * LIBMESH_DIM + j) * LIBMESH_DIM + k) * LIBME...
Eigen::Matrix< Real, Eigen::Dynamic, Eigen::Dynamic > RealEigenMatrix
std::string demangle(const char *name)
void dataStore(std::ostream &stream, T &v, void *)
static void pack(const std::basic_string< T > &b, Iter data_out, const void *)
RankTwoTensorTempl is designed to handle the Stress or Strain Tensor for a fully anisotropic material...
SymmetricRankFourTensorTempl is designed to handle an N-dimensional fourth order tensor with minor sy...
static unsigned int get_string_len(typename std::vector< T >::const_iterator in)
Eigen::Matrix< Real, Eigen::Dynamic, 1 > RealEigenVector
void dataLoad(std::istream &stream, T &v, void *)
void loadHelper(std::istream &stream, P &data, void *context)
Scalar helper routine.
bool hasValue(const std::size_t i) const
auto index_range(const T &sizable)