24 #include "libmesh/parallel.h" 25 #include "libmesh/parameters.h" 26 #include "libmesh/numeric_vector.h" 28 #ifdef LIBMESH_HAVE_CXX11_TYPE_TRAITS 29 #include <type_traits> 38 #include <unordered_map> 39 #include <unordered_set> 62 inline void storeHelper(std::ostream & stream,
P & data,
void * context);
68 inline void storeHelper(std::ostream & stream, std::vector<P> & data,
void * context);
74 inline void storeHelper(std::ostream & stream, std::shared_ptr<P> & data,
void * context);
80 inline void storeHelper(std::ostream & stream, std::unique_ptr<P> & data,
void * context);
86 inline void storeHelper(std::ostream & stream, std::set<P> & data,
void * context);
91 template <
typename P,
typename Q>
92 inline void storeHelper(std::ostream & stream, std::map<P, Q> & data,
void * context);
97 template <
typename P,
typename Q>
98 inline void storeHelper(std::ostream & stream, std::unordered_map<P, Q> & data,
void * context);
103 template <
typename P>
104 inline void storeHelper(std::ostream & stream, std::optional<P> & data,
void * context);
109 template <
typename P,
typename Q>
115 template <
typename T>
121 template <
typename P>
122 inline void loadHelper(std::istream & stream,
P & data,
void * context);
127 template <
typename P>
128 inline void loadHelper(std::istream & stream, std::vector<P> & data,
void * context);
133 template <
typename P>
134 inline void loadHelper(std::istream & stream, std::shared_ptr<P> & data,
void * context);
139 template <
typename P>
140 inline void loadHelper(std::istream & stream, std::unique_ptr<P> & data,
void * context);
145 template <
typename P>
146 inline void loadHelper(std::istream & stream, std::set<P> & data,
void * context);
151 template <
typename P,
typename Q>
152 inline void loadHelper(std::istream & stream, std::map<P, Q> & data,
void * context);
157 template <
typename P,
typename Q>
158 inline void loadHelper(std::istream & stream, std::unordered_map<P, Q> & data,
void * context);
163 template <
typename P>
164 inline void loadHelper(std::istream & stream, std::optional<P> & data,
void * context);
169 template <
typename P,
typename Q>
175 template <
typename T>
178 template <
typename T>
179 inline void dataStore(std::ostream & stream, T & v,
void * );
183 template <
typename T>
187 #ifdef LIBMESH_HAVE_CXX11_TYPE_TRAITS 188 static_assert(std::is_polymorphic<T>::value ==
false,
189 "Cannot serialize a class that has virtual " 190 "members!\nWrite a custom dataStore() " 191 "template specialization!\n\n");
192 static_assert(std::is_trivially_copyable<T>::value,
193 "Cannot serialize a class that is not trivially copyable!\nWrite a custom " 194 "dataStore() template specialization!\n\n");
197 stream.write((
char *)&v,
sizeof(v));
198 mooseAssert(!stream.bad(),
"Failed to store");
201 template <
typename T>
205 mooseError(
"Attempting to store a raw pointer type: \"",
207 " *\" as restartable data!\nWrite a custom dataStore() template specialization!\n\n");
210 void dataStore(std::ostream & stream, Point & p,
void * context);
212 template <
typename T,
typename U>
214 dataStore(std::ostream & stream, std::pair<T, U> & p,
void * context)
220 template <
typename T>
222 dataStore(std::ostream & stream, std::vector<T> & v,
void * context)
225 unsigned int size = v.size();
228 for (
unsigned int i = 0; i < size; i++)
232 template <
typename T>
234 dataStore(std::ostream & stream, std::shared_ptr<T> & v,
void * context)
241 template <
typename T>
243 dataStore(std::ostream & stream, std::unique_ptr<T> & v,
void * context)
250 template <
typename T>
252 dataStore(std::ostream & stream, std::set<T> & s,
void * context)
255 unsigned int size = s.size();
258 typename std::set<T>::iterator it = s.begin();
259 typename std::set<T>::iterator end = s.end();
261 for (; it != end; ++it)
263 T & x =
const_cast<T &
>(*it);
268 template <
typename T>
270 dataStore(std::ostream & stream, std::list<T> & l,
void * context)
273 unsigned int size = l.size();
276 typename std::list<T>::iterator it = l.begin();
277 typename std::list<T>::iterator end = l.end();
279 for (; it != end; ++it)
281 T & x =
const_cast<T &
>(*it);
286 template <
typename T>
288 dataStore(std::ostream & stream, std::deque<T> & l,
void * context)
291 unsigned int size = l.size();
294 typename std::deque<T>::iterator it = l.begin();
295 typename std::deque<T>::iterator end = l.end();
297 for (; it != end; ++it)
299 T & x =
const_cast<T &
>(*it);
304 template <
typename T,
typename U>
306 dataStore(std::ostream & stream, std::map<T, U> & m,
void * context)
309 unsigned int size = m.size();
312 typename std::map<T, U>::iterator it = m.begin();
313 typename std::map<T, U>::iterator end = m.end();
315 for (; it != end; ++it)
317 T & key =
const_cast<T &
>(it->first);
325 template <
typename T,
typename U>
327 dataStore(std::ostream & stream, std::unordered_map<T, U> & m,
void * context)
330 unsigned int size = m.size();
333 typename std::unordered_map<T, U>::iterator it = m.begin();
334 typename std::unordered_map<T, U>::iterator end = m.end();
336 for (; it != end; ++it)
338 T & key =
const_cast<T &
>(it->first);
346 template <
typename T>
348 dataStore(std::ostream & stream, std::unordered_set<T> & s,
void * context)
351 std::size_t size = s.size();
354 for (
auto & element : s)
358 template <
typename T>
360 dataStore(std::ostream & stream, std::optional<T> & m,
void * context)
362 bool has_value = m.has_value();
369 template <
typename T,
typename U>
374 unsigned int size = m.size();
380 for (; it != end; ++it)
382 T & key =
const_cast<T &
>(it->first);
390 template <
typename T,
int Rows,
int Cols>
392 dataStore(std::ostream & stream, Eigen::Matrix<T, Rows, Cols> & v,
void * context)
394 auto m = cast_int<unsigned int>(v.rows());
396 auto n = cast_int<unsigned int>(v.cols());
406 template <
typename T>
410 dataStore(stream,
static_cast<Eigen::Matrix<T, 2, 1> &
>(v), context);
415 void dataStore(std::ostream & stream, Real & v,
void * context);
417 void dataStore(std::ostream & stream, std::string & v,
void * context);
419 void dataStore(std::ostream & stream, VariableName & v,
void * context);
421 void dataStore(std::ostream & stream, UserObjectName & v,
void * context);
423 void dataStore(std::ostream & stream,
bool & v,
void * context);
429 void dataStore(std::ostream & stream, std::vector<bool> & v,
void * context);
431 void dataStore(std::ostream & stream,
const Elem *& e,
void * context);
433 void dataStore(std::ostream & stream,
const Node *& n,
void * context);
435 void dataStore(std::ostream & stream, Elem *& e,
void * context);
437 void dataStore(std::ostream & stream, Node *& n,
void * context);
439 void dataStore(std::ostream & stream, std::stringstream & s,
void * context);
460 template <std::
size_t N>
462 dataStore(std::ostream & stream, std::array<ADReal, N> & dn,
void * context)
464 for (std::size_t i = 0; i <
N; ++i)
468 template <std::
size_t N>
472 for (std::size_t i = 0; i <
N; ++i)
476 template <
typename T>
492 void dataStore(std::ostream & stream, Vec & v,
void * context);
494 template <
typename T>
496 dataStore(std::ostream & stream, DenseVector<T> & v,
void * context)
498 unsigned int m = v.size();
500 for (
unsigned int i = 0; i < v.size(); i++)
507 template <
typename T>
510 template <
typename T>
513 template <
typename T>
516 template <
typename T>
523 template <
typename T>
530 template <
typename T>
537 template <
typename T>
544 template <
typename T>
551 template <
typename T>
560 template <
typename T>
564 stream.read((
char *)&v,
sizeof(v));
565 mooseAssert(!stream.bad(),
"Failed to load");
568 template <
typename T>
572 mooseError(
"Attempting to load a raw pointer type: \"",
574 " *\" as restartable data!\nWrite a custom dataLoad() template specialization!\n\n");
577 template <
typename T,
typename U>
579 dataLoad(std::istream & stream, std::pair<T, U> & p,
void * context)
585 template <
typename T>
587 dataLoad(std::istream & stream, std::vector<T> & v,
void * context)
590 unsigned int size = 0;
595 for (
unsigned int i = 0; i < size; i++)
599 template <
typename T>
601 dataLoad(std::istream & stream, std::shared_ptr<T> & v,
void * context)
608 template <
typename T>
610 dataLoad(std::istream & stream, std::unique_ptr<T> & v,
void * context)
617 template <
typename T>
619 dataLoad(std::istream & stream, std::set<T> & s,
void * context)
622 unsigned int size = 0;
625 for (
unsigned int i = 0; i < size; i++)
629 s.insert(std::move(data));
633 template <
typename T>
635 dataLoad(std::istream & stream, std::list<T> & l,
void * context)
638 unsigned int size = 0;
641 for (
unsigned int i = 0; i < size; i++)
645 l.push_back(std::move(data));
649 template <
typename T>
651 dataLoad(std::istream & stream, std::deque<T> & l,
void * context)
654 unsigned int size = 0;
657 for (
unsigned int i = 0; i < size; i++)
661 l.push_back(std::move(data));
665 template <
typename T,
typename U>
667 dataLoad(std::istream & stream, std::map<T, U> & m,
void * context)
672 unsigned int size = 0;
675 for (
unsigned int i = 0; i < size; i++)
685 template <
typename T,
typename U>
687 dataLoad(std::istream & stream, std::unordered_map<T, U> & m,
void * context)
692 unsigned int size = 0;
695 for (
unsigned int i = 0; i < size; i++)
705 template <
typename T>
707 dataLoad(std::istream & stream, std::unordered_set<T> & s,
void * context)
712 std::size_t size = 0;
716 for (std::size_t i = 0; i < size; i++)
724 template <
typename T>
726 dataLoad(std::istream & stream, std::optional<T> & m,
void * context)
729 dataLoad(stream, has_value,
nullptr);
740 template <
typename T,
typename U>
745 unsigned int size = 0;
748 for (
unsigned int i = 0; i < size; i++)
758 template <
typename T,
int Rows,
int Cols>
760 dataLoad(std::istream & stream, Eigen::Matrix<T, Rows, Cols> & v,
void * context)
776 template <
typename T>
780 dataLoad(stream,
static_cast<Eigen::Matrix<T, 2, 1> &
>(v), context);
785 void dataLoad(std::istream & stream, Real & v,
void * );
787 void dataLoad(std::istream & stream, std::string & v,
void * );
789 void dataLoad(std::istream & stream, VariableName & v,
void * );
791 void dataLoad(std::istream & stream, UserObjectName & v,
void * );
793 void dataLoad(std::istream & stream,
bool & v,
void * );
799 void dataLoad(std::istream & stream, std::vector<bool> & v,
void * );
801 void dataLoad(std::istream & stream,
const Elem *& e,
void * context);
803 void dataLoad(std::istream & stream,
const Node *& e,
void * context);
805 void dataLoad(std::istream & stream, Elem *& e,
void * context);
807 void dataLoad(std::istream & stream, Node *& e,
void * context);
809 void dataLoad(std::istream & stream, std::stringstream & s,
void * context);
811 void dataLoad(std::istream & stream,
ADReal & dn,
void * context);
832 void dataLoad(std::istream & stream,
836 template <std::
size_t N>
838 dataLoad(std::istream & stream, std::array<ADReal, N> & dn,
void * context)
840 for (std::size_t i = 0; i <
N; ++i)
844 template <std::
size_t N>
848 for (std::size_t i = 0; i <
N; ++i)
852 template <
typename T>
867 void dataLoad(std::istream & stream, Vec & v,
void * context);
869 template <
typename T>
871 dataLoad(std::istream & stream, DenseVector<T> & v,
void * context)
876 for (
unsigned int i = 0; i < n; i++)
884 template <
typename T>
887 template <
typename T>
890 template <
typename T>
893 template <
typename T>
900 template <
typename T>
907 template <
typename T>
914 template <
typename T>
921 template <
typename T>
928 template <
typename T>
936 template <
typename P>
944 template <
typename P>
946 storeHelper(std::ostream & stream, std::vector<P> & data,
void * context)
952 template <
typename P>
954 storeHelper(std::ostream & stream, std::shared_ptr<P> & data,
void * context)
960 template <
typename P>
962 storeHelper(std::ostream & stream, std::unique_ptr<P> & data,
void * context)
968 template <
typename P>
970 storeHelper(std::ostream & stream, std::set<P> & data,
void * context)
976 template <
typename P,
typename Q>
978 storeHelper(std::ostream & stream, std::map<P, Q> & data,
void * context)
984 template <
typename P,
typename Q>
986 storeHelper(std::ostream & stream, std::unordered_map<P, Q> & data,
void * context)
992 template <
typename P>
994 storeHelper(std::ostream & stream, std::optional<P> & data,
void * context)
1000 template <
typename P,
typename Q>
1013 template <
typename T>
1017 std::size_t size = data.
size();
1022 mooseAssert(data.
hasValue(i),
"Data doesn't have a value");
1028 template <
typename P>
1036 template <
typename P>
1038 loadHelper(std::istream & stream, std::vector<P> & data,
void * context)
1044 template <
typename P>
1046 loadHelper(std::istream & stream, std::shared_ptr<P> & data,
void * context)
1052 template <
typename P>
1054 loadHelper(std::istream & stream, std::unique_ptr<P> & data,
void * context)
1060 template <
typename P>
1062 loadHelper(std::istream & stream, std::set<P> & data,
void * context)
1068 template <
typename P,
typename Q>
1070 loadHelper(std::istream & stream, std::map<P, Q> & data,
void * context)
1076 template <
typename P,
typename Q>
1078 loadHelper(std::istream & stream, std::unordered_map<P, Q> & data,
void * context)
1084 template <
typename P>
1086 loadHelper(std::istream & stream, std::optional<P> & data,
void * context)
1092 template <
typename P,
typename Q>
1106 template <
typename T>
1118 void dataLoad(std::istream & stream, Point & p,
void * context);
1120 #ifndef TIMPI_HAVE_STRING_PACKING 1131 template <
typename T>
1135 static const unsigned int size_bytes = 4;
1141 unsigned int string_len =
reinterpret_cast<const unsigned char &
>(in[size_bytes - 1]);
1142 for (
signed int i = size_bytes - 2; i >= 0; --i)
1145 string_len +=
reinterpret_cast<const unsigned char &
>(in[i]);
1150 static unsigned int packed_size(
typename std::vector<T>::const_iterator in)
1152 return get_string_len(in) + size_bytes;
1157 return s.size() + size_bytes;
1160 template <
typename Iter>
1161 static void pack(
const std::basic_string<T> & b, Iter data_out,
const void *)
1163 unsigned int string_len = b.size();
1164 for (
unsigned int i = 0; i != size_bytes; ++i)
1166 *data_out++ = (string_len % 256);
1170 std::copy(b.begin(), b.end(), data_out);
1173 static std::basic_string<T>
unpack(
typename std::vector<T>::const_iterator in,
void *)
1175 unsigned int string_len = get_string_len(in);
1177 std::ostringstream oss;
1178 for (
unsigned int i = 0; i < string_len; ++i)
1179 oss << reinterpret_cast<const unsigned char &>(in[i + size_bytes]);
1181 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 *)
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]
DualNumber< Real, DNDerivativeType, true > ADReal
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...
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 *)
virtual numeric_index_type first_local_index() const=0
RankTwoTensorTempl is designed to handle the Stress or Strain Tensor for a fully anisotropic material...
virtual numeric_index_type local_size() const=0
SymmetricRankFourTensorTempl is designed to handle an N-dimensional fourth order tensor with minor sy...
IntRange< T > make_range(T beg, T end)
static unsigned int get_string_len(typename std::vector< T >::const_iterator in)
A two-component zero initialized vector used for tangential quantities.
virtual void set(const numeric_index_type i, const T value)=0
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)