24#include "libmesh/parallel.h"
25#include "libmesh/parameters.h"
26#include "libmesh/numeric_vector.h"
30#ifdef LIBMESH_HAVE_CXX11_TYPE_TRAITS
40#include <unordered_map>
41#include <unordered_set>
61#ifdef MOOSE_MFEM_ENABLED
74inline void storeHelper(std::ostream & stream,
P & data,
void * context);
80inline void storeHelper(std::ostream & stream, std::vector<P> & data,
void * context);
86inline void storeHelper(std::ostream & stream, std::shared_ptr<P> & data,
void * context);
92inline void storeHelper(std::ostream & stream, std::unique_ptr<P> & data,
void * context);
98inline void storeHelper(std::ostream & stream, std::set<P> & data,
void * context);
103template <
typename P,
typename Q>
104inline void storeHelper(std::ostream & stream, std::map<P, Q> & data,
void * context);
109template <
typename P,
typename Q>
110inline void storeHelper(std::ostream & stream, std::unordered_map<P, Q> & data,
void * context);
116inline void storeHelper(std::ostream & stream, std::optional<P> & data,
void * context);
121template <
typename P,
typename Q>
134inline void loadHelper(std::istream & stream,
P & data,
void * context);
140inline void loadHelper(std::istream & stream, std::vector<P> & data,
void * context);
146inline void loadHelper(std::istream & stream, std::shared_ptr<P> & data,
void * context);
152inline void loadHelper(std::istream & stream, std::unique_ptr<P> & data,
void * context);
158inline void loadHelper(std::istream & stream, std::set<P> & data,
void * context);
163template <
typename P,
typename Q>
164inline void loadHelper(std::istream & stream, std::map<P, Q> & data,
void * context);
169template <
typename P,
typename Q>
170inline void loadHelper(std::istream & stream, std::unordered_map<P, Q> & data,
void * context);
176inline void loadHelper(std::istream & stream, std::optional<P> & data,
void * context);
181template <
typename P,
typename Q>
191inline void dataStore(std::ostream & stream, T & v,
void * );
199#ifdef LIBMESH_HAVE_CXX11_TYPE_TRAITS
200 static_assert(std::is_polymorphic<T>::value ==
false,
201 "Cannot serialize a class that has virtual "
202 "members!\nWrite a custom dataStore() "
203 "template specialization!\n\n");
204 static_assert(std::is_trivially_copyable<T>::value,
205 "Cannot serialize a class that is not trivially copyable!\nWrite a custom "
206 "dataStore() template specialization!\n\n");
209 stream.write((
char *)&v,
sizeof(v));
210 mooseAssert(!stream.bad(),
"Failed to store");
214#define dataStoreEnum(EnumType, IntType) \
216inline void dataStore(std::ostream & stream, EnumType & enum_type, void * ctx) \
218 auto stored = static_cast<IntType>(enum_type); \
219 dataStore(stream, stored, ctx); \
227 mooseError(
"Attempting to store a raw pointer type: \"",
229 " *\" as restartable data!\nWrite a custom dataStore() template specialization!\n\n");
232void dataStore(std::ostream & stream, Point & p,
void * context);
236template <
typename T,
typename U>
238dataStore(std::ostream & stream, std::pair<T, U> & p,
void * context)
246dataStore(std::ostream & stream, std::vector<T> & v,
void * context)
249 unsigned int size = v.size();
252 for (
unsigned int i = 0; i < size; i++)
258dataStore(std::ostream & stream, std::shared_ptr<T> & v,
void * context)
267dataStore(std::ostream & stream, std::unique_ptr<T> & v,
void * context)
276dataStore(std::ostream & stream, std::set<T> & s,
void * context)
279 unsigned int size = s.size();
282 typename std::set<T>::iterator it = s.begin();
283 typename std::set<T>::iterator end = s.end();
285 for (; it != end; ++it)
287 T & x =
const_cast<T &
>(*it);
294dataStore(std::ostream & stream, std::list<T> & l,
void * context)
297 unsigned int size = l.size();
300 typename std::list<T>::iterator it = l.begin();
301 typename std::list<T>::iterator end = l.end();
303 for (; it != end; ++it)
305 T & x =
const_cast<T &
>(*it);
312dataStore(std::ostream & stream, std::deque<T> & l,
void * context)
315 unsigned int size = l.size();
318 typename std::deque<T>::iterator it = l.begin();
319 typename std::deque<T>::iterator end = l.end();
321 for (; it != end; ++it)
323 T & x =
const_cast<T &
>(*it);
328template <
typename T,
typename U>
330dataStore(std::ostream & stream, std::map<T, U> & m,
void * context)
333 unsigned int size = m.size();
336 typename std::map<T, U>::iterator it = m.begin();
337 typename std::map<T, U>::iterator end = m.end();
339 for (; it != end; ++it)
341 T & key =
const_cast<T &
>(it->first);
349template <
typename T,
typename U>
351dataStore(std::ostream & stream, std::unordered_map<T, U> & m,
void * context)
354 unsigned int size = m.size();
357 typename std::unordered_map<T, U>::iterator it = m.begin();
358 typename std::unordered_map<T, U>::iterator end = m.end();
360 for (; it != end; ++it)
362 T & key =
const_cast<T &
>(it->first);
372dataStore(std::ostream & stream, std::unordered_set<T> & s,
void * context)
375 std::size_t size = s.size();
378 for (
auto & element : s)
384dataStore(std::ostream & stream, std::optional<T> & m,
void * context)
386 bool has_value = m.has_value();
393template <
typename T,
typename U>
398 unsigned int size = m.size();
404 for (; it != end; ++it)
406 T & key =
const_cast<T &
>(it->first);
414template <
typename T,
int Rows,
int Cols>
416dataStore(std::ostream & stream, Eigen::Matrix<T, Rows, Cols> & v,
void * context)
418 auto m = cast_int<unsigned int>(v.rows());
420 auto n = cast_int<unsigned int>(v.cols());
422 for (
const auto i : make_range(m))
423 for (
const auto j : make_range(n))
434 dataStore(stream,
static_cast<Eigen::Matrix<T, 2, 1> &
>(v), context);
439void dataStore(std::ostream & stream, Real & v,
void * context);
441void dataStore(std::ostream & stream, std::string & v,
void * context);
443void dataStore(std::ostream & stream, VariableName & v,
void * context);
445void dataStore(std::ostream & stream, UserObjectName & v,
void * context);
447void dataStore(std::ostream & stream,
bool & v,
void * context);
453void dataStore(std::ostream & stream, std::vector<bool> & v,
void * context);
455void dataStore(std::ostream & stream,
const Elem *& e,
void * context);
457void dataStore(std::ostream & stream,
const Node *& n,
void * context);
459void dataStore(std::ostream & stream, Elem *& e,
void * context);
461void dataStore(std::ostream & stream, Node *& n,
void * context);
463void dataStore(std::ostream & stream, std::stringstream & s,
void * context);
466#ifdef MOOSE_LIBTORCH_ENABLED
468void dataStore(std::ostream & stream, torch::Tensor & t,
void * context);
472#ifdef MOOSE_MFEM_ENABLED
492template <std::
size_t N>
494dataStore(std::ostream & stream, std::array<ADReal, N> & dn,
void * context)
496 for (std::size_t i = 0; i < N; ++i)
500template <std::
size_t N>
504 for (std::size_t i = 0; i < N; ++i)
524void dataStore(std::ostream & stream, Vec & v,
void * context);
528dataStore(std::ostream & stream, DenseVector<T> & v,
void * context)
530 unsigned int m = v.size();
532 for (
unsigned int i = 0; i < v.size(); i++)
596 stream.read((
char *)&v,
sizeof(v));
597 mooseAssert(!stream.bad(),
"Failed to load");
601#define dataLoadEnum(EnumType, IntType) \
603inline void dataLoad(std::istream & stream, EnumType & enum_type, void * ctx) \
606 dataLoad(stream, loaded, ctx); \
607 enum_type = static_cast<EnumType>(loaded); \
615 mooseError(
"Attempting to load a raw pointer type: \"",
617 " *\" as restartable data!\nWrite a custom dataLoad() template specialization!\n\n");
620template <
typename T,
typename U>
622dataLoad(std::istream & stream, std::pair<T, U> & p,
void * context)
630dataLoad(std::istream & stream, std::vector<T> & v,
void * context)
633 unsigned int size = 0;
638 for (
unsigned int i = 0; i < size; i++)
644dataLoad(std::istream & stream, std::shared_ptr<T> & v,
void * context)
653dataLoad(std::istream & stream, std::unique_ptr<T> & v,
void * context)
662dataLoad(std::istream & stream, std::set<T> & s,
void * context)
665 unsigned int size = 0;
668 for (
unsigned int i = 0; i < size; i++)
672 s.insert(std::move(data));
678dataLoad(std::istream & stream, std::list<T> & l,
void * context)
681 unsigned int size = 0;
684 for (
unsigned int i = 0; i < size; i++)
688 l.push_back(std::move(data));
694dataLoad(std::istream & stream, std::deque<T> & l,
void * context)
697 unsigned int size = 0;
700 for (
unsigned int i = 0; i < size; i++)
704 l.push_back(std::move(data));
708template <
typename T,
typename U>
710dataLoad(std::istream & stream, std::map<T, U> & m,
void * context)
715 unsigned int size = 0;
718 for (
unsigned int i = 0; i < size; i++)
728template <
typename T,
typename U>
730dataLoad(std::istream & stream, std::unordered_map<T, U> & m,
void * context)
735 unsigned int size = 0;
738 for (
unsigned int i = 0; i < size; i++)
750dataLoad(std::istream & stream, std::unordered_set<T> & s,
void * context)
755 std::size_t size = 0;
759 for (std::size_t i = 0; i < size; i++)
769dataLoad(std::istream & stream, std::optional<T> & m,
void * context)
772 dataLoad(stream, has_value,
nullptr);
783template <
typename T,
typename U>
788 unsigned int size = 0;
791 for (
unsigned int i = 0; i < size; i++)
801template <
typename T,
int Rows,
int Cols>
803dataLoad(std::istream & stream, Eigen::Matrix<T, Rows, Cols> & v,
void * context)
810 for (
const auto i : make_range(m))
811 for (
const auto j : make_range(n))
823 dataLoad(stream,
static_cast<Eigen::Matrix<T, 2, 1> &
>(v), context);
828void dataLoad(std::istream & stream, Real & v,
void * );
830void dataLoad(std::istream & stream, std::string & v,
void * );
832void dataLoad(std::istream & stream, VariableName & v,
void * );
834void dataLoad(std::istream & stream, UserObjectName & v,
void * );
836void dataLoad(std::istream & stream,
bool & v,
void * );
842void dataLoad(std::istream & stream, std::vector<bool> & v,
void * );
844void dataLoad(std::istream & stream,
const Elem *& e,
void * context);
846void dataLoad(std::istream & stream,
const Node *& e,
void * context);
848void dataLoad(std::istream & stream, Elem *& e,
void * context);
850void dataLoad(std::istream & stream, Node *& e,
void * context);
852void dataLoad(std::istream & stream, std::stringstream & s,
void * context);
855#ifdef MOOSE_LIBTORCH_ENABLED
857void dataLoad(std::istream & stream, torch::Tensor & t,
void * context);
861#ifdef MOOSE_MFEM_ENABLED
887template <std::
size_t N>
889dataLoad(std::istream & stream, std::array<ADReal, N> & dn,
void * context)
891 for (std::size_t i = 0; i < N; ++i)
895template <std::
size_t N>
899 for (std::size_t i = 0; i < N; ++i)
918void dataLoad(std::istream & stream, Vec & v,
void * context);
922dataLoad(std::istream & stream, DenseVector<T> & v,
void * context)
927 for (
unsigned int i = 0; i < n; i++)
997storeHelper(std::ostream & stream, std::vector<P> & data,
void * context)
1003template <
typename P>
1005storeHelper(std::ostream & stream, std::shared_ptr<P> & data,
void * context)
1011template <
typename P>
1013storeHelper(std::ostream & stream, std::unique_ptr<P> & data,
void * context)
1019template <
typename P>
1027template <
typename P,
typename Q>
1029storeHelper(std::ostream & stream, std::map<P, Q> & data,
void * context)
1035template <
typename P,
typename Q>
1037storeHelper(std::ostream & stream, std::unordered_map<P, Q> & data,
void * context)
1043template <
typename P>
1045storeHelper(std::ostream & stream, std::optional<P> & data,
void * context)
1051template <
typename P,
typename Q>
1064template <
typename T>
1068 std::size_t size = data.
size();
1071 for (
const auto i : index_range(data))
1073 mooseAssert(data.
hasValue(i),
"Data doesn't have a value");
1079template <
typename P>
1087template <
typename P>
1089loadHelper(std::istream & stream, std::vector<P> & data,
void * context)
1095template <
typename P>
1097loadHelper(std::istream & stream, std::shared_ptr<P> & data,
void * context)
1103template <
typename P>
1105loadHelper(std::istream & stream, std::unique_ptr<P> & data,
void * context)
1111template <
typename P>
1113loadHelper(std::istream & stream, std::set<P> & data,
void * context)
1119template <
typename P,
typename Q>
1121loadHelper(std::istream & stream, std::map<P, Q> & data,
void * context)
1127template <
typename P,
typename Q>
1129loadHelper(std::istream & stream, std::unordered_map<P, Q> & data,
void * context)
1135template <
typename P>
1137loadHelper(std::istream & stream, std::optional<P> & data,
void * context)
1143template <
typename P,
typename Q>
1157template <
typename T>
1165 for (
const auto i : index_range(data))
1169void dataLoad(std::istream & stream, Point & p,
void * context);
1173#ifndef TIMPI_HAVE_STRING_PACKING
1184template <
typename T>
1188 static const unsigned int size_bytes = 4;
1194 unsigned int string_len =
reinterpret_cast<const unsigned char &
>(in[size_bytes - 1]);
1195 for (
signed int i = size_bytes - 2; i >= 0; --i)
1198 string_len +=
reinterpret_cast<const unsigned char &
>(in[i]);
1203 static unsigned int packed_size(
typename std::vector<T>::const_iterator in)
1205 return get_string_len(in) + size_bytes;
1210 return s.size() + size_bytes;
1213 template <
typename Iter>
1214 static void pack(
const std::basic_string<T> & b, Iter data_out,
const void *)
1216 unsigned int string_len = b.size();
1217 for (
unsigned int i = 0; i != size_bytes; ++i)
1219 *data_out++ = (string_len % 256);
1223 std::copy(b.begin(), b.end(), data_out);
1226 static std::basic_string<T>
unpack(
typename std::vector<T>::const_iterator in,
void *)
1228 unsigned int string_len = get_string_len(in);
1230 std::ostringstream oss;
1231 for (
unsigned int i = 0; i < string_len; ++i)
1232 oss <<
reinterpret_cast<const unsigned char &
>(in[i + size_bytes]);
1234 in += size_bytes + string_len;
DualNumber< Real, DNDerivativeType, true > ADReal
void dataLoad(std::istream &stream, T &v, void *)
void dataStore(std::ostream &stream, T &v, void *)
void storeHelper(std::ostream &stream, P &data, void *context)
Scalar helper routine.
void loadHelper(std::istream &stream, P &data, void *context)
Scalar helper routine.
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application.
This class defines a Tensor that can change its shape.
A two-component zero initialized vector used for tangential quantities.
HashMap is an abstraction for dictionary data type, we make it thread-safe by locking inserts.
RankFourTensorTempl is designed to handle any N-dimensional fourth order tensor, C.
T _vals[N4]
The values of the rank-four tensor stored by index=(((i * LIBMESH_DIM + j) * LIBMESH_DIM + k) * LIBME...
RankThreeTensor is designed to handle any N-dimensional third order tensor, r.
T _vals[N3]
The values of the rank-three tensor stored by index=((i * LIBMESH_DIM + j) * LIBMESH_DIM + k)
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...
std::array< T, N2 > _vals
The values of the rank-four tensor.
SymmetricRankTwoTensorTempl is designed to handle the Stress or Strain Tensor for an anisotropic mate...
Storage container that stores a vector of unique pointers of T, but represents most of the public fac...
void resize(const std::size_t size)
Resizes the underlying vector.
bool hasValue(const std::size_t i) const
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.
virtual void set(const numeric_index_type i, const T value)=0
virtual numeric_index_type local_size() const=0
virtual numeric_index_type first_local_index() const=0
static unsigned int packed_size(typename std::vector< T >::const_iterator in)
static void pack(const std::basic_string< T > &b, Iter data_out, const void *)
static unsigned int get_string_len(typename std::vector< T >::const_iterator in)
static std::basic_string< T > unpack(typename std::vector< T >::const_iterator in, void *)
static unsigned int packable_size(const std::basic_string< T > &s, const void *)
T _coords[LIBMESH_DIM *LIBMESH_DIM]
Utilities for converting between vector(s) of libMesh Points and MFEM Vector(s).
The following methods are specializations for using the libMesh::Parallel::packed_range_* routines fo...
std::string demangle(const char *name)