24#include "libmesh/parallel.h"
25#include "libmesh/parameters.h"
26#include "libmesh/numeric_vector.h"
27#include "libmesh/enum_elem_quality.h"
28#include "libmesh/enum_elem_type.h"
29#include "libmesh/enum_inf_map_type.h"
33#ifdef LIBMESH_HAVE_CXX11_TYPE_TRAITS
43#include <unordered_map>
44#include <unordered_set>
66#ifdef MOOSE_MFEM_ENABLED
75inline void dataStore(std::ostream & stream, T & v,
void * );
83 static_assert(
sizeof(T) == 0,
"You must write a dataStore specialization for your type");
94 stream.write((
char *)&v,
sizeof(v));
95 mooseAssert(!stream.bad(),
"Failed to store");
101#define dataStoreSizeofSpecialization(Type) \
104dataStore(std::ostream & stream, Type & v, void *) \
106 moose::internal::dataStoreSizeof(stream, v); \
110dataStore(std::ostream & stream, const Type & v, void *) \
112 moose::internal::dataStoreSizeof(stream, v); \
115dataStoreSizeofSpecialization(
bool)
116dataStoreSizeofSpecialization(
char)
117dataStoreSizeofSpecialization(
signed char)
118dataStoreSizeofSpecialization(
short int)
119dataStoreSizeofSpecialization(
int)
120dataStoreSizeofSpecialization(
long int)
121dataStoreSizeofSpecialization(
long long int)
122dataStoreSizeofSpecialization(
unsigned char)
123dataStoreSizeofSpecialization(
short unsigned int)
124dataStoreSizeofSpecialization(
unsigned int)
125dataStoreSizeofSpecialization(
long unsigned int)
126dataStoreSizeofSpecialization(
long long unsigned int)
127dataStoreSizeofSpecialization(
float)
128dataStoreSizeofSpecialization(
double)
129dataStoreSizeofSpecialization(
long double)
131#define dataStoreEnum(EnumType, IntType) \
133inline void dataStore(std::ostream & stream, EnumType & enum_type, void * ctx) \
135 auto stored = static_cast<IntType>(enum_type); \
136 dataStore(stream, stored, ctx); \
148void dataStore(std::ostream &, mt_state &,
void *);
156void dataStore(std::ostream & stream, std::string & v,
void * context);
158void dataStore(std::ostream & stream, VariableName & v,
void * context);
160void dataStore(std::ostream & stream, UserObjectName & v,
void * context);
164void dataStore(std::ostream & stream,
const Elem *& e,
void * context);
166void dataStore(std::ostream & stream,
const Node *& n,
void * context);
168void dataStore(std::ostream & stream, Elem *& e,
void * context);
170void dataStore(std::ostream & stream, Node *& n,
void * context);
172void dataStore(std::ostream & stream, std::stringstream & s,
void * context);
179void dataStore(std::ostream & stream, std::shared_ptr<T> & v,
void * context);
182void dataStore(std::ostream & stream, std::unique_ptr<T> & v,
void * context);
212void dataStore(std::ostream & stream, std::vector<T> & v,
void * context);
215void dataStore(std::ostream & stream, std::set<T> & s,
void * context);
218void dataStore(std::ostream & stream, std::list<T> & l,
void * context);
221void dataStore(std::ostream & stream, std::deque<T> & l,
void * context);
223template <
typename T,
typename U>
224void dataStore(std::ostream & stream, std::map<T, U> & m,
void * context);
226template <
typename T,
typename U>
227void dataStore(std::ostream & stream, std::unordered_map<T, U> & m,
void * context);
230void dataStore(std::ostream & stream, std::unordered_set<T> & s,
void * context);
232template <
typename T, std::
size_t N>
233void dataStore(std::ostream & stream, std::array<T, N> & arr,
void * context);
235template <
typename T,
int Rows,
int Cols>
236void dataStore(std::ostream & stream, Eigen::Matrix<T, Rows, Cols> & v,
void * context);
242 mooseError(
"Attempting to store a raw pointer type: \"",
244 " *\" as restartable data!\nWrite a custom dataStore() template specialization!\n\n");
250template <
typename T,
typename U>
252dataStore(std::ostream & stream, std::pair<T, U> & p,
void * context)
261dataStore(std::ostream & ostream, std::vector<bool> & v,
void * ctx)
263 unsigned int size = v.size();
266 for (
const bool val : v)
272dataStore(std::ostream & stream, std::vector<T> & v,
void * context)
275 unsigned int size = v.size();
278 for (
unsigned int i = 0; i < size; i++)
284dataStore(std::ostream & stream, std::shared_ptr<T> & v,
void * context)
293dataStore(std::ostream & stream, std::unique_ptr<T> & v,
void * context)
302dataStore(std::ostream & stream, std::set<T> & s,
void * context)
305 unsigned int size = s.size();
308 typename std::set<T>::iterator it = s.begin();
309 typename std::set<T>::iterator end = s.end();
311 for (; it != end; ++it)
313 T & x =
const_cast<T &
>(*it);
320dataStore(std::ostream & stream, std::list<T> & l,
void * context)
323 unsigned int size = l.size();
326 typename std::list<T>::iterator it = l.begin();
327 typename std::list<T>::iterator end = l.end();
329 for (; it != end; ++it)
331 T & x =
const_cast<T &
>(*it);
338dataStore(std::ostream & stream, std::deque<T> & l,
void * context)
341 unsigned int size = l.size();
344 typename std::deque<T>::iterator it = l.begin();
345 typename std::deque<T>::iterator end = l.end();
347 for (; it != end; ++it)
349 T & x =
const_cast<T &
>(*it);
354template <
typename T,
typename U>
356dataStore(std::ostream & stream, std::map<T, U> & m,
void * context)
359 unsigned int size = m.size();
362 typename std::map<T, U>::iterator it = m.begin();
363 typename std::map<T, U>::iterator end = m.end();
365 for (; it != end; ++it)
367 T & key =
const_cast<T &
>(it->first);
375template <
typename T,
typename U>
377dataStore(std::ostream & stream, std::unordered_map<T, U> & m,
void * context)
380 unsigned int size = m.size();
383 typename std::unordered_map<T, U>::iterator it = m.begin();
384 typename std::unordered_map<T, U>::iterator end = m.end();
386 for (; it != end; ++it)
388 T & key =
const_cast<T &
>(it->first);
398dataStore(std::ostream & stream, std::unordered_set<T> & s,
void * context)
401 std::size_t size = s.size();
404 for (
auto & element : s)
410dataStore(std::ostream & stream, std::optional<T> & m,
void * context)
412 bool has_value = m.has_value();
419template <
typename T,
typename U>
424 unsigned int size = m.size();
430 for (; it != end; ++it)
432 T & key =
const_cast<T &
>(it->first);
440template <
typename T,
int Rows,
int Cols>
442dataStore(std::ostream & stream, Eigen::Matrix<T, Rows, Cols> & v,
void * context)
444 auto m = cast_int<unsigned int>(v.rows());
446 auto n = cast_int<unsigned int>(v.cols());
448 for (
const auto i : make_range(m))
449 for (
const auto j : make_range(n))
465void dataStore(std::ostream & stream, Real & v,
void * context);
467void dataStore(std::ostream & stream, std::string & v,
void * context);
469void dataStore(std::ostream & stream, VariableName & v,
void * context);
471void dataStore(std::ostream & stream, UserObjectName & v,
void * context);
473void dataStore(std::ostream & stream,
bool & v,
void * context);
477void dataStore(std::ostream & stream,
const Elem *& e,
void * context);
479void dataStore(std::ostream & stream,
const Node *& n,
void * context);
481void dataStore(std::ostream & stream, Elem *& e,
void * context);
483void dataStore(std::ostream & stream, Node *& n,
void * context);
485void dataStore(std::ostream & stream, std::stringstream & s,
void * context);
488#ifdef MOOSE_LIBTORCH_ENABLED
490void dataStore(std::ostream & stream, torch::Tensor & t,
void * context);
494#ifdef MOOSE_MFEM_ENABLED
514template <
typename T, std::
size_t N>
516dataStore(std::ostream & stream, T (&arr)[N],
void * context)
518 for (std::size_t i = 0; i < N; ++i)
522template <
typename T, std::
size_t N>
524dataStore(std::ostream & stream, std::array<T, N> & arr,
void * context)
526 for (std::size_t i = 0; i < N; ++i)
546void dataStore(std::ostream & stream, Vec & v,
void * context);
550dataStore(std::ostream & stream, DenseVector<T> & v,
void * context)
552 unsigned int m = v.size();
554 for (
unsigned int i = 0; i < v.size(); i++)
613 std::size_t size = data.
size();
616 for (
const auto i : index_range(data))
618 mooseAssert(data.
hasValue(i),
"Data doesn't have a value");
629 static_assert(
sizeof(T) == 0,
"Must write dataLoad specialization");
640 stream.read((
char *)&v,
sizeof(v));
641 mooseAssert(!stream.bad(),
"Failed to load");
647#define dataLoadSizeofSpecialization(Type) \
650dataLoad(std::istream & stream, Type & v, void *) \
652 moose::internal::dataLoadSizeof(stream, v); \
661dataLoadSizeofSpecialization(
bool)
662dataLoadSizeofSpecialization(
char)
663dataLoadSizeofSpecialization(
signed char)
664dataLoadSizeofSpecialization(
short int)
665dataLoadSizeofSpecialization(
int)
666dataLoadSizeofSpecialization(
long int)
667dataLoadSizeofSpecialization(
long long int)
668dataLoadSizeofSpecialization(
unsigned char)
669dataLoadSizeofSpecialization(
short unsigned int)
670dataLoadSizeofSpecialization(
unsigned int)
671dataLoadSizeofSpecialization(
long unsigned int)
672dataLoadSizeofSpecialization(
long long unsigned int)
673dataLoadSizeofSpecialization(
float)
674dataLoadSizeofSpecialization(
double)
675dataLoadSizeofSpecialization(
long double)
677#define dataLoadEnum(EnumType, IntType) \
679inline void dataLoad(std::istream & stream, EnumType & enum_type, void * ctx) \
682 dataLoad(stream, loaded, ctx); \
683 enum_type = static_cast<EnumType>(loaded); \
695void dataLoad(std::istream &, mt_state &,
void *);
700void dataLoad(std::istream & stream, std::string & v,
void * );
702void dataLoad(std::istream & stream, VariableName & v,
void * );
704void dataLoad(std::istream & stream, UserObjectName & v,
void * );
708void dataLoad(std::istream & stream,
const Elem *& e,
void * context);
710void dataLoad(std::istream & stream,
const Node *& e,
void * context);
712void dataLoad(std::istream & stream, Elem *& e,
void * context);
714void dataLoad(std::istream & stream, Node *& e,
void * context);
716void dataLoad(std::istream & stream, std::stringstream & s,
void * context);
725void dataLoad(std::istream & stream, std::shared_ptr<T> & v,
void * context);
728void dataLoad(std::istream & stream, std::unique_ptr<T> & v,
void * context);
765void dataLoad(std::istream & stream, std::vector<T> & v,
void * context);
768void dataLoad(std::istream & stream, std::set<T> & s,
void * context);
771void dataLoad(std::istream & stream, std::list<T> & l,
void * context);
774void dataLoad(std::istream & stream, std::deque<T> & l,
void * context);
776template <
typename T,
typename U>
777void dataLoad(std::istream & stream, std::map<T, U> & m,
void * context);
779template <
typename T,
typename U>
780void dataLoad(std::istream & stream, std::unordered_map<T, U> & m,
void * context);
783void dataLoad(std::istream & stream, std::unordered_set<T> & s,
void * context);
785template <
typename T, std::
size_t N>
786void dataLoad(std::istream & stream, std::array<T, N> & arr,
void * context);
788template <
typename T,
int Rows,
int Cols>
789void dataLoad(std::istream & stream, Eigen::Matrix<T, Rows, Cols> & v,
void * context);
795 mooseError(
"Attempting to load a raw pointer type: \"",
797 " *\" as restartable data!\nWrite a custom dataLoad() template specialization!\n\n");
801template <
typename T,
typename U>
803dataLoad(std::istream & stream, std::pair<T, U> & p,
void * context)
806 dataLoad(stream, p.second, context);
812dataLoad(std::istream & stream, std::vector<bool> & v,
void * context)
815 unsigned int size = 0;
821 for (
unsigned int i = 0; i < size; i++)
830dataLoad(std::istream & stream, std::vector<T> & v,
void * context)
833 unsigned int size = 0;
838 for (
unsigned int i = 0; i < size; i++)
844dataLoad(std::istream & stream, std::shared_ptr<T> & v,
void * context)
853dataLoad(std::istream & stream, std::unique_ptr<T> & v,
void * context)
862dataLoad(std::istream & stream, std::set<T> & s,
void * context)
865 unsigned int size = 0;
868 for (
unsigned int i = 0; i < size; i++)
872 s.insert(std::move(data));
878dataLoad(std::istream & stream, std::list<T> & l,
void * context)
881 unsigned int size = 0;
884 for (
unsigned int i = 0; i < size; i++)
888 l.push_back(std::move(data));
894dataLoad(std::istream & stream, std::deque<T> & l,
void * context)
897 unsigned int size = 0;
900 for (
unsigned int i = 0; i < size; i++)
904 l.push_back(std::move(data));
908template <
typename T,
typename U>
910dataLoad(std::istream & stream, std::map<T, U> & m,
void * context)
915 unsigned int size = 0;
918 for (
unsigned int i = 0; i < size; i++)
928template <
typename T,
typename U>
930dataLoad(std::istream & stream, std::unordered_map<T, U> & m,
void * context)
935 unsigned int size = 0;
938 for (
unsigned int i = 0; i < size; i++)
950dataLoad(std::istream & stream, std::unordered_set<T> & s,
void * context)
955 std::size_t size = 0;
959 for (std::size_t i = 0; i < size; i++)
969dataLoad(std::istream & stream, std::optional<T> & m,
void * context)
972 dataLoad(stream, has_value,
nullptr);
983template <
typename T,
typename U>
988 unsigned int size = 0;
991 for (
unsigned int i = 0; i < size; i++)
1001template <
typename T,
int Rows,
int Cols>
1003dataLoad(std::istream & stream, Eigen::Matrix<T, Rows, Cols> & v,
void * context)
1010 for (
const auto i : make_range(m))
1011 for (
const auto j : make_range(n))
1019template <
typename T>
1028void dataLoad(std::istream & stream, Real & v,
void * );
1030void dataLoad(std::istream & stream, std::string & v,
void * );
1032void dataLoad(std::istream & stream, VariableName & v,
void * );
1034void dataLoad(std::istream & stream, UserObjectName & v,
void * );
1036void dataLoad(std::istream & stream,
bool & v,
void * );
1040void dataLoad(std::istream & stream,
const Elem *& e,
void * context);
1042void dataLoad(std::istream & stream,
const Node *& e,
void * context);
1044void dataLoad(std::istream & stream, Elem *& e,
void * context);
1046void dataLoad(std::istream & stream, Node *& e,
void * context);
1048void dataLoad(std::istream & stream, std::stringstream & s,
void * context);
1050void dataLoad(std::istream & stream,
ADReal & dn,
void * context);
1051#ifdef MOOSE_LIBTORCH_ENABLED
1053void dataLoad(std::istream & stream, torch::Tensor & t,
void * context);
1057#ifdef MOOSE_MFEM_ENABLED
1083template <
typename T, std::
size_t N>
1085dataLoad(std::istream & stream, std::array<T, N> & arr,
void * context)
1087 for (std::size_t i = 0; i < N; ++i)
1091template <
typename T, std::
size_t N>
1093dataLoad(std::istream & stream, T (&arr)[N],
void * context)
1095 for (std::size_t i = 0; i < N; ++i)
1099template <
typename T>
1114void dataLoad(std::istream & stream, Vec & v,
void * context);
1116template <
typename T>
1118dataLoad(std::istream & stream, DenseVector<T> & v,
void * context)
1123 for (
unsigned int i = 0; i < n; i++)
1131template <
typename T>
1138template <
typename T>
1145template <
typename T>
1152template <
typename T>
1159template <
typename T>
1166template <
typename T>
1180template <
typename T>
1188 for (
const auto i : index_range(data))
1193#ifndef TIMPI_HAVE_STRING_PACKING
1204template <
typename T>
1208 static const unsigned int size_bytes = 4;
1214 unsigned int string_len =
reinterpret_cast<const unsigned char &
>(in[size_bytes - 1]);
1215 for (
signed int i = size_bytes - 2; i >= 0; --i)
1218 string_len +=
reinterpret_cast<const unsigned char &
>(in[i]);
1223 static unsigned int packed_size(
typename std::vector<T>::const_iterator in)
1225 return get_string_len(in) + size_bytes;
1230 return s.size() + size_bytes;
1233 template <
typename Iter>
1234 static void pack(
const std::basic_string<T> & b, Iter data_out,
const void *)
1236 unsigned int string_len = b.size();
1237 for (
unsigned int i = 0; i != size_bytes; ++i)
1239 *data_out++ = (string_len % 256);
1243 std::copy(b.begin(), b.end(), data_out);
1246 static std::basic_string<T>
unpack(
typename std::vector<T>::const_iterator in,
void *)
1248 unsigned int string_len = get_string_len(in);
1250 std::ostringstream oss;
1251 for (
unsigned int i = 0; i < string_len; ++i)
1252 oss <<
reinterpret_cast<const unsigned char &
>(in[i + size_bytes]);
1254 in += size_bytes + string_len;
DualNumber< Real, DNDerivativeType, true > ADReal
void dataStore(std::ostream &stream, T &v, void *)
void dataLoad(std::istream &, T &, void *)
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...
Tnew cast_ref(Told &oldvar)
std::string demangle(const char *name)
void dataStoreSizeof(std::ostream &stream, T &v)
void dataLoadSizeof(std::istream &stream, T &v)