24 #include "libmesh/parallel.h" 25 #include "libmesh/parameters.h" 26 #include "libmesh/numeric_vector.h" 30 #ifdef LIBMESH_HAVE_CXX11_TYPE_TRAITS 31 #include <type_traits> 40 #include <unordered_map> 41 #include <unordered_set> 60 #ifdef MOOSE_MFEM_ENABLED 73 inline void storeHelper(std::ostream & stream, P & data,
void * context);
79 inline void storeHelper(std::ostream & stream, std::vector<P> & data,
void * context);
85 inline void storeHelper(std::ostream & stream, std::shared_ptr<P> & data,
void * context);
91 inline void storeHelper(std::ostream & stream, std::unique_ptr<P> & data,
void * context);
97 inline void storeHelper(std::ostream & stream, std::set<P> & data,
void * context);
102 template <
typename P,
typename Q>
103 inline void storeHelper(std::ostream & stream, std::map<P, Q> & data,
void * context);
108 template <
typename P,
typename Q>
109 inline void storeHelper(std::ostream & stream, std::unordered_map<P, Q> & data,
void * context);
114 template <
typename P>
115 inline void storeHelper(std::ostream & stream, std::optional<P> & data,
void * context);
120 template <
typename P,
typename Q>
126 template <
typename T>
132 template <
typename P>
133 inline void loadHelper(std::istream & stream, P & data,
void * context);
138 template <
typename P>
139 inline void loadHelper(std::istream & stream, std::vector<P> & data,
void * context);
144 template <
typename P>
145 inline void loadHelper(std::istream & stream, std::shared_ptr<P> & data,
void * context);
150 template <
typename P>
151 inline void loadHelper(std::istream & stream, std::unique_ptr<P> & data,
void * context);
156 template <
typename P>
157 inline void loadHelper(std::istream & stream, std::set<P> & data,
void * context);
162 template <
typename P,
typename Q>
163 inline void loadHelper(std::istream & stream, std::map<P, Q> & data,
void * context);
168 template <
typename P,
typename Q>
169 inline void loadHelper(std::istream & stream, std::unordered_map<P, Q> & data,
void * context);
174 template <
typename P>
175 inline void loadHelper(std::istream & stream, std::optional<P> & data,
void * context);
180 template <
typename P,
typename Q>
186 template <
typename T>
189 template <
typename T>
190 inline void dataStore(std::ostream & stream, T & v,
void * );
194 template <
typename T>
198 #ifdef LIBMESH_HAVE_CXX11_TYPE_TRAITS 199 static_assert(std::is_polymorphic<T>::value ==
false,
200 "Cannot serialize a class that has virtual " 201 "members!\nWrite a custom dataStore() " 202 "template specialization!\n\n");
203 static_assert(std::is_trivially_copyable<T>::value,
204 "Cannot serialize a class that is not trivially copyable!\nWrite a custom " 205 "dataStore() template specialization!\n\n");
208 stream.write((
char *)&v,
sizeof(v));
209 mooseAssert(!stream.bad(),
"Failed to store");
212 template <
typename T>
216 mooseError(
"Attempting to store a raw pointer type: \"",
218 " *\" as restartable data!\nWrite a custom dataStore() template specialization!\n\n");
221 void dataStore(std::ostream & stream, Point & p,
void * context);
223 template <
typename T,
typename U>
225 dataStore(std::ostream & stream, std::pair<T, U> & p,
void * context)
231 template <
typename T>
233 dataStore(std::ostream & stream, std::vector<T> & v,
void * context)
236 unsigned int size = v.size();
239 for (
unsigned int i = 0; i < size; i++)
243 template <
typename T>
245 dataStore(std::ostream & stream, std::shared_ptr<T> & v,
void * context)
252 template <
typename T>
254 dataStore(std::ostream & stream, std::unique_ptr<T> & v,
void * context)
261 template <
typename T>
263 dataStore(std::ostream & stream, std::set<T> & s,
void * context)
266 unsigned int size = s.size();
269 typename std::set<T>::iterator it = s.begin();
270 typename std::set<T>::iterator end = s.end();
272 for (; it != end; ++it)
274 T & x =
const_cast<T &
>(*it);
279 template <
typename T>
281 dataStore(std::ostream & stream, std::list<T> & l,
void * context)
284 unsigned int size = l.size();
287 typename std::list<T>::iterator it = l.begin();
288 typename std::list<T>::iterator end = l.end();
290 for (; it != end; ++it)
292 T & x =
const_cast<T &
>(*it);
297 template <
typename T>
299 dataStore(std::ostream & stream, std::deque<T> & l,
void * context)
302 unsigned int size = l.size();
305 typename std::deque<T>::iterator it = l.begin();
306 typename std::deque<T>::iterator end = l.end();
308 for (; it != end; ++it)
310 T & x =
const_cast<T &
>(*it);
315 template <
typename T,
typename U>
317 dataStore(std::ostream & stream, std::map<T, U> & m,
void * context)
320 unsigned int size = m.size();
323 typename std::map<T, U>::iterator it = m.begin();
324 typename std::map<T, U>::iterator end = m.end();
326 for (; it != end; ++it)
328 T & key =
const_cast<T &
>(it->first);
336 template <
typename T,
typename U>
338 dataStore(std::ostream & stream, std::unordered_map<T, U> & m,
void * context)
341 unsigned int size = m.size();
344 typename std::unordered_map<T, U>::iterator it = m.begin();
345 typename std::unordered_map<T, U>::iterator end = m.end();
347 for (; it != end; ++it)
349 T & key =
const_cast<T &
>(it->first);
357 template <
typename T>
359 dataStore(std::ostream & stream, std::unordered_set<T> & s,
void * context)
362 std::size_t size = s.size();
365 for (
auto & element : s)
369 template <
typename T>
371 dataStore(std::ostream & stream, std::optional<T> & m,
void * context)
373 bool has_value = m.has_value();
380 template <
typename T,
typename U>
385 unsigned int size = m.size();
391 for (; it != end; ++it)
393 T & key =
const_cast<T &
>(it->first);
401 template <
typename T,
int Rows,
int Cols>
403 dataStore(std::ostream & stream, Eigen::Matrix<T, Rows, Cols> & v,
void * context)
405 auto m = cast_int<unsigned int>(v.rows());
407 auto n = cast_int<unsigned int>(v.cols());
417 template <
typename T>
421 dataStore(stream,
static_cast<Eigen::Matrix<T, 2, 1> &
>(v), context);
426 void dataStore(std::ostream & stream, Real & v,
void * context);
428 void dataStore(std::ostream & stream, std::string & v,
void * context);
430 void dataStore(std::ostream & stream, VariableName & v,
void * context);
432 void dataStore(std::ostream & stream, UserObjectName & v,
void * context);
434 void dataStore(std::ostream & stream,
bool & v,
void * context);
440 void dataStore(std::ostream & stream, std::vector<bool> & v,
void * context);
442 void dataStore(std::ostream & stream,
const Elem *& e,
void * context);
444 void dataStore(std::ostream & stream,
const Node *& n,
void * context);
446 void dataStore(std::ostream & stream, Elem *& e,
void * context);
448 void dataStore(std::ostream & stream, Node *& n,
void * context);
450 void dataStore(std::ostream & stream, std::stringstream & s,
void * context);
453 #ifdef MOOSE_LIBTORCH_ENABLED 455 void dataStore(std::ostream & stream, torch::Tensor & t,
void * context);
459 #ifdef MOOSE_MFEM_ENABLED 479 template <std::
size_t N>
481 dataStore(std::ostream & stream, std::array<ADReal, N> & dn,
void * context)
483 for (std::size_t i = 0; i <
N; ++i)
487 template <std::
size_t N>
491 for (std::size_t i = 0; i <
N; ++i)
495 template <
typename T>
511 void dataStore(std::ostream & stream, Vec & v,
void * context);
513 template <
typename T>
515 dataStore(std::ostream & stream, DenseVector<T> & v,
void * context)
517 unsigned int m = v.size();
519 for (
unsigned int i = 0; i < v.size(); i++)
526 template <
typename T>
529 template <
typename T>
532 template <
typename T>
535 template <
typename T>
542 template <
typename T>
549 template <
typename T>
556 template <
typename T>
563 template <
typename T>
570 template <
typename T>
579 template <
typename T>
583 stream.read((
char *)&v,
sizeof(v));
584 mooseAssert(!stream.bad(),
"Failed to load");
587 template <
typename T>
591 mooseError(
"Attempting to load a raw pointer type: \"",
593 " *\" as restartable data!\nWrite a custom dataLoad() template specialization!\n\n");
596 template <
typename T,
typename U>
598 dataLoad(std::istream & stream, std::pair<T, U> & p,
void * context)
604 template <
typename T>
606 dataLoad(std::istream & stream, std::vector<T> & v,
void * context)
609 unsigned int size = 0;
614 for (
unsigned int i = 0; i < size; i++)
618 template <
typename T>
620 dataLoad(std::istream & stream, std::shared_ptr<T> & v,
void * context)
627 template <
typename T>
629 dataLoad(std::istream & stream, std::unique_ptr<T> & v,
void * context)
636 template <
typename T>
638 dataLoad(std::istream & stream, std::set<T> & s,
void * context)
641 unsigned int size = 0;
644 for (
unsigned int i = 0; i < size; i++)
648 s.insert(std::move(data));
652 template <
typename T>
654 dataLoad(std::istream & stream, std::list<T> & l,
void * context)
657 unsigned int size = 0;
660 for (
unsigned int i = 0; i < size; i++)
664 l.push_back(std::move(data));
668 template <
typename T>
670 dataLoad(std::istream & stream, std::deque<T> & l,
void * context)
673 unsigned int size = 0;
676 for (
unsigned int i = 0; i < size; i++)
680 l.push_back(std::move(data));
684 template <
typename T,
typename U>
686 dataLoad(std::istream & stream, std::map<T, U> & m,
void * context)
691 unsigned int size = 0;
694 for (
unsigned int i = 0; i < size; i++)
704 template <
typename T,
typename U>
706 dataLoad(std::istream & stream, std::unordered_map<T, U> & m,
void * context)
711 unsigned int size = 0;
714 for (
unsigned int i = 0; i < size; i++)
724 template <
typename T>
726 dataLoad(std::istream & stream, std::unordered_set<T> & s,
void * context)
731 std::size_t size = 0;
735 for (std::size_t i = 0; i < size; i++)
743 template <
typename T>
745 dataLoad(std::istream & stream, std::optional<T> & m,
void * context)
748 dataLoad(stream, has_value,
nullptr);
759 template <
typename T,
typename U>
764 unsigned int size = 0;
767 for (
unsigned int i = 0; i < size; i++)
777 template <
typename T,
int Rows,
int Cols>
779 dataLoad(std::istream & stream, Eigen::Matrix<T, Rows, Cols> & v,
void * context)
795 template <
typename T>
799 dataLoad(stream,
static_cast<Eigen::Matrix<T, 2, 1> &
>(v), context);
804 void dataLoad(std::istream & stream, Real & v,
void * );
806 void dataLoad(std::istream & stream, std::string & v,
void * );
808 void dataLoad(std::istream & stream, VariableName & v,
void * );
810 void dataLoad(std::istream & stream, UserObjectName & v,
void * );
812 void dataLoad(std::istream & stream,
bool & v,
void * );
818 void dataLoad(std::istream & stream, std::vector<bool> & v,
void * );
820 void dataLoad(std::istream & stream,
const Elem *& e,
void * context);
822 void dataLoad(std::istream & stream,
const Node *& e,
void * context);
824 void dataLoad(std::istream & stream, Elem *& e,
void * context);
826 void dataLoad(std::istream & stream, Node *& e,
void * context);
828 void dataLoad(std::istream & stream, std::stringstream & s,
void * context);
830 void dataLoad(std::istream & stream,
ADReal & dn,
void * context);
831 #ifdef MOOSE_LIBTORCH_ENABLED 833 void dataLoad(std::istream & stream, torch::Tensor & t,
void * context);
837 #ifdef MOOSE_MFEM_ENABLED 859 void dataLoad(std::istream & stream,
863 template <std::
size_t N>
865 dataLoad(std::istream & stream, std::array<ADReal, N> & dn,
void * context)
867 for (std::size_t i = 0; i <
N; ++i)
871 template <std::
size_t N>
875 for (std::size_t i = 0; i <
N; ++i)
879 template <
typename T>
894 void dataLoad(std::istream & stream, Vec & v,
void * context);
896 template <
typename T>
898 dataLoad(std::istream & stream, DenseVector<T> & v,
void * context)
903 for (
unsigned int i = 0; i < n; i++)
911 template <
typename T>
914 template <
typename T>
917 template <
typename T>
920 template <
typename T>
927 template <
typename T>
934 template <
typename T>
941 template <
typename T>
948 template <
typename T>
955 template <
typename T>
963 template <
typename P>
971 template <
typename P>
973 storeHelper(std::ostream & stream, std::vector<P> & data,
void * context)
979 template <
typename P>
981 storeHelper(std::ostream & stream, std::shared_ptr<P> & data,
void * context)
987 template <
typename P>
989 storeHelper(std::ostream & stream, std::unique_ptr<P> & data,
void * context)
995 template <
typename P>
997 storeHelper(std::ostream & stream, std::set<P> & data,
void * context)
1003 template <
typename P,
typename Q>
1005 storeHelper(std::ostream & stream, std::map<P, Q> & data,
void * context)
1011 template <
typename P,
typename Q>
1013 storeHelper(std::ostream & stream, std::unordered_map<P, Q> & data,
void * context)
1019 template <
typename P>
1021 storeHelper(std::ostream & stream, std::optional<P> & data,
void * context)
1027 template <
typename P,
typename Q>
1040 template <
typename T>
1044 std::size_t size = data.
size();
1049 mooseAssert(data.
hasValue(i),
"Data doesn't have a value");
1055 template <
typename P>
1063 template <
typename P>
1065 loadHelper(std::istream & stream, std::vector<P> & data,
void * context)
1071 template <
typename P>
1073 loadHelper(std::istream & stream, std::shared_ptr<P> & data,
void * context)
1079 template <
typename P>
1081 loadHelper(std::istream & stream, std::unique_ptr<P> & data,
void * context)
1087 template <
typename P>
1089 loadHelper(std::istream & stream, std::set<P> & data,
void * context)
1095 template <
typename P,
typename Q>
1097 loadHelper(std::istream & stream, std::map<P, Q> & data,
void * context)
1103 template <
typename P,
typename Q>
1105 loadHelper(std::istream & stream, std::unordered_map<P, Q> & data,
void * context)
1111 template <
typename P>
1113 loadHelper(std::istream & stream, std::optional<P> & data,
void * context)
1119 template <
typename P,
typename Q>
1133 template <
typename T>
1145 void dataLoad(std::istream & stream, Point & p,
void * context);
1147 #ifndef TIMPI_HAVE_STRING_PACKING 1158 template <
typename T>
1162 static const unsigned int size_bytes = 4;
1168 unsigned int string_len =
reinterpret_cast<const unsigned char &
>(in[size_bytes - 1]);
1169 for (
signed int i = size_bytes - 2; i >= 0; --i)
1172 string_len +=
reinterpret_cast<const unsigned char &
>(in[i]);
1177 static unsigned int packed_size(
typename std::vector<T>::const_iterator in)
1179 return get_string_len(in) + size_bytes;
1184 return s.size() + size_bytes;
1187 template <
typename Iter>
1188 static void pack(
const std::basic_string<T> & b, Iter data_out,
const void *)
1190 unsigned int string_len = b.size();
1191 for (
unsigned int i = 0; i != size_bytes; ++i)
1193 *data_out++ = (string_len % 256);
1197 std::copy(b.begin(), b.end(), data_out);
1200 static std::basic_string<T>
unpack(
typename std::vector<T>::const_iterator in,
void *)
1202 unsigned int string_len = get_string_len(in);
1204 std::ostringstream oss;
1205 for (
unsigned int i = 0; i < string_len; ++i)
1206 oss << reinterpret_cast<const unsigned char &>(in[i + size_bytes]);
1208 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.
Utilities for converting between vector(s) of libMesh Points and MFEM Vector(s).
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)