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> 38 #include <unordered_set> 60 inline void storeHelper(std::ostream & stream, P & data,
void * context);
66 inline void storeHelper(std::ostream & stream, std::vector<P> & data,
void * context);
72 inline void storeHelper(std::ostream & stream, std::shared_ptr<P> & data,
void * context);
78 inline void storeHelper(std::ostream & stream, std::unique_ptr<P> & data,
void * context);
84 inline void storeHelper(std::ostream & stream, std::set<P> & data,
void * context);
89 template <
typename P,
typename Q>
90 inline void storeHelper(std::ostream & stream, std::map<P, Q> & data,
void * context);
95 template <
typename P,
typename Q>
96 inline void storeHelper(std::ostream & stream, std::unordered_map<P, Q> & data,
void * context);
101 template <
typename P>
102 inline void storeHelper(std::ostream & stream, std::optional<P> & data,
void * context);
107 template <
typename P,
typename Q>
113 template <
typename T>
119 template <
typename P>
120 inline void loadHelper(std::istream & stream, P & data,
void * context);
125 template <
typename P>
126 inline void loadHelper(std::istream & stream, std::vector<P> & data,
void * context);
131 template <
typename P>
132 inline void loadHelper(std::istream & stream, std::shared_ptr<P> & data,
void * context);
137 template <
typename P>
138 inline void loadHelper(std::istream & stream, std::unique_ptr<P> & data,
void * context);
143 template <
typename P>
144 inline void loadHelper(std::istream & stream, std::set<P> & data,
void * context);
149 template <
typename P,
typename Q>
150 inline void loadHelper(std::istream & stream, std::map<P, Q> & data,
void * context);
155 template <
typename P,
typename Q>
156 inline void loadHelper(std::istream & stream, std::unordered_map<P, Q> & data,
void * context);
161 template <
typename P>
162 inline void loadHelper(std::istream & stream, std::optional<P> & data,
void * context);
167 template <
typename P,
typename Q>
173 template <
typename T>
176 template <
typename T>
177 inline void dataStore(std::ostream & stream, T & v,
void * );
181 template <
typename T>
185 #ifdef LIBMESH_HAVE_CXX11_TYPE_TRAITS 186 static_assert(std::is_polymorphic<T>::value ==
false,
187 "Cannot serialize a class that has virtual " 188 "members!\nWrite a custom dataStore() " 189 "template specialization!\n\n");
190 static_assert(std::is_trivially_copyable<T>::value,
191 "Cannot serialize a class that is not trivially copyable!\nWrite a custom " 192 "dataStore() template specialization!\n\n");
196 stream.write((
char *)&v,
sizeof(v));
197 mooseAssert(!stream.bad(),
"Failed to store");
200 template <
typename T>
204 mooseError(
"Attempting to store a raw pointer type: \"",
206 " *\" as restartable data!\nWrite a custom dataStore() template specialization!\n\n");
209 void dataStore(std::ostream & stream, Point & p,
void * context);
211 template <
typename T,
typename U>
213 dataStore(std::ostream & stream, std::pair<T, U> & p,
void * context)
219 template <
typename T>
221 dataStore(std::ostream & stream, std::vector<T> & v,
void * context)
224 unsigned int size = v.size();
227 for (
unsigned int i = 0; i < size; i++)
231 template <
typename T>
233 dataStore(std::ostream & stream, std::shared_ptr<T> & v,
void * context)
240 template <
typename T>
242 dataStore(std::ostream & stream, std::unique_ptr<T> & v,
void * context)
249 template <
typename T>
251 dataStore(std::ostream & stream, std::set<T> & s,
void * context)
254 unsigned int size = s.size();
257 typename std::set<T>::iterator it = s.begin();
258 typename std::set<T>::iterator end = s.end();
260 for (; it != end; ++it)
262 T & x =
const_cast<T &
>(*it);
267 template <
typename T>
269 dataStore(std::ostream & stream, std::list<T> & l,
void * context)
272 unsigned int size = l.size();
275 typename std::list<T>::iterator it = l.begin();
276 typename std::list<T>::iterator end = l.end();
278 for (; it != end; ++it)
280 T & x =
const_cast<T &
>(*it);
285 template <
typename T>
287 dataStore(std::ostream & stream, std::deque<T> & l,
void * context)
290 unsigned int size = l.size();
293 typename std::deque<T>::iterator it = l.begin();
294 typename std::deque<T>::iterator end = l.end();
296 for (; it != end; ++it)
298 T & x =
const_cast<T &
>(*it);
303 template <
typename T,
typename U>
305 dataStore(std::ostream & stream, std::map<T, U> & m,
void * context)
308 unsigned int size = m.size();
311 typename std::map<T, U>::iterator it = m.begin();
312 typename std::map<T, U>::iterator end = m.end();
314 for (; it != end; ++it)
316 T & key =
const_cast<T &
>(it->first);
324 template <
typename T,
typename U>
326 dataStore(std::ostream & stream, std::unordered_map<T, U> & m,
void * context)
329 unsigned int size = m.size();
332 typename std::unordered_map<T, U>::iterator it = m.begin();
333 typename std::unordered_map<T, U>::iterator end = m.end();
335 for (; it != end; ++it)
337 T & key =
const_cast<T &
>(it->first);
345 template <
typename T>
347 dataStore(std::ostream & stream, std::unordered_set<T> & s,
void * context)
350 std::size_t size = s.size();
353 for (
auto & element : s)
357 template <
typename T>
359 dataStore(std::ostream & stream, std::optional<T> & m,
void * context)
361 bool has_value = m.has_value();
368 template <
typename T,
typename U>
373 unsigned int size = m.size();
379 for (; it != end; ++it)
381 T & key =
const_cast<T &
>(it->first);
391 void dataStore(std::ostream & stream, Real & v,
void * context);
393 void dataStore(std::ostream & stream, std::string & v,
void * context);
395 void dataStore(std::ostream & stream, VariableName & v,
void * context);
397 void dataStore(std::ostream & stream, UserObjectName & v,
void * context);
399 void dataStore(std::ostream & stream,
bool & v,
void * context);
403 void dataStore(std::ostream & stream, std::vector<bool> & v,
void * context);
405 void dataStore(std::ostream & stream,
const Elem *& e,
void * context);
407 void dataStore(std::ostream & stream,
const Node *& n,
void * context);
409 void dataStore(std::ostream & stream, Elem *& e,
void * context);
411 void dataStore(std::ostream & stream, Node *& n,
void * context);
413 void dataStore(std::ostream & stream, std::stringstream & s,
void * context);
438 template <std::
size_t N>
440 dataStore(std::ostream & stream, std::array<ADReal, N> & dn,
void * context)
442 for (std::size_t i = 0; i <
N; ++i)
446 template <std::
size_t N>
450 for (std::size_t i = 0; i <
N; ++i)
454 template <
typename T>
470 void dataStore(std::ostream & stream, Vec & v,
void * context);
472 template <
typename T>
474 dataStore(std::ostream & stream, DenseVector<T> & v,
void * context)
476 unsigned int m = v.size();
478 for (
unsigned int i = 0; i < v.size(); i++)
485 template <
typename T>
488 template <
typename T>
491 template <
typename T>
494 template <
typename T>
501 template <
typename T>
508 template <
typename T>
515 template <
typename T>
522 template <
typename T>
529 template <
typename T>
538 template <
typename T>
542 stream.read((
char *)&v,
sizeof(v));
543 mooseAssert(!stream.bad(),
"Failed to load");
546 template <
typename T>
550 mooseError(
"Attempting to load a raw pointer type: \"",
552 " *\" as restartable data!\nWrite a custom dataLoad() template specialization!\n\n");
555 template <
typename T,
typename U>
557 dataLoad(std::istream & stream, std::pair<T, U> & p,
void * context)
563 template <
typename T>
565 dataLoad(std::istream & stream, std::vector<T> & v,
void * context)
568 unsigned int size = 0;
573 for (
unsigned int i = 0; i < size; i++)
577 template <
typename T>
579 dataLoad(std::istream & stream, std::shared_ptr<T> & v,
void * context)
586 template <
typename T>
588 dataLoad(std::istream & stream, std::unique_ptr<T> & v,
void * context)
595 template <
typename T>
597 dataLoad(std::istream & stream, std::set<T> & s,
void * context)
600 unsigned int size = 0;
603 for (
unsigned int i = 0; i < size; i++)
607 s.insert(std::move(data));
611 template <
typename T>
613 dataLoad(std::istream & stream, std::list<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>
629 dataLoad(std::istream & stream, std::deque<T> & l,
void * context)
632 unsigned int size = 0;
635 for (
unsigned int i = 0; i < size; i++)
639 l.push_back(std::move(data));
643 template <
typename T,
typename U>
645 dataLoad(std::istream & stream, std::map<T, U> & m,
void * context)
650 unsigned int size = 0;
653 for (
unsigned int i = 0; i < size; i++)
663 template <
typename T,
typename U>
665 dataLoad(std::istream & stream, std::unordered_map<T, U> & m,
void * context)
670 unsigned int size = 0;
673 for (
unsigned int i = 0; i < size; i++)
683 template <
typename T>
685 dataLoad(std::istream & stream, std::unordered_set<T> & s,
void * context)
690 std::size_t size = 0;
694 for (std::size_t i = 0; i < size; i++)
702 template <
typename T>
704 dataLoad(std::istream & stream, std::optional<T> & m,
void * context)
707 dataLoad(stream, has_value,
nullptr);
718 template <
typename T,
typename U>
723 unsigned int size = 0;
726 for (
unsigned int i = 0; i < size; i++)
738 void dataLoad(std::istream & stream, Real & v,
void * );
740 void dataLoad(std::istream & stream, std::string & v,
void * );
742 void dataLoad(std::istream & stream, VariableName & v,
void * );
744 void dataLoad(std::istream & stream, UserObjectName & v,
void * );
746 void dataLoad(std::istream & stream,
bool & v,
void * );
750 void dataLoad(std::istream & stream, std::vector<bool> & v,
void * );
752 void dataLoad(std::istream & stream,
const Elem *& e,
void * context);
754 void dataLoad(std::istream & stream,
const Node *& e,
void * context);
756 void dataLoad(std::istream & stream, Elem *& e,
void * context);
758 void dataLoad(std::istream & stream, Node *& e,
void * context);
760 void dataLoad(std::istream & stream, std::stringstream & s,
void * context);
762 void dataLoad(std::istream & stream,
ADReal & dn,
void * context);
787 void dataLoad(std::istream & stream,
791 template <std::
size_t N>
793 dataLoad(std::istream & stream, std::array<ADReal, N> & dn,
void * context)
795 for (std::size_t i = 0; i <
N; ++i)
799 template <std::
size_t N>
803 for (std::size_t i = 0; i <
N; ++i)
807 template <
typename T>
822 void dataLoad(std::istream & stream, Vec & v,
void * context);
824 template <
typename T>
826 dataLoad(std::istream & stream, DenseVector<T> & v,
void * context)
831 for (
unsigned int i = 0; i < n; i++)
839 template <
typename T>
842 template <
typename T>
845 template <
typename T>
848 template <
typename T>
855 template <
typename T>
862 template <
typename T>
869 template <
typename T>
876 template <
typename T>
883 template <
typename T>
891 template <
typename P>
899 template <
typename P>
901 storeHelper(std::ostream & stream, std::vector<P> & data,
void * context)
907 template <
typename P>
909 storeHelper(std::ostream & stream, std::shared_ptr<P> & data,
void * context)
915 template <
typename P>
917 storeHelper(std::ostream & stream, std::unique_ptr<P> & data,
void * context)
923 template <
typename P>
925 storeHelper(std::ostream & stream, std::set<P> & data,
void * context)
931 template <
typename P,
typename Q>
933 storeHelper(std::ostream & stream, std::map<P, Q> & data,
void * context)
939 template <
typename P,
typename Q>
941 storeHelper(std::ostream & stream, std::unordered_map<P, Q> & data,
void * context)
947 template <
typename P>
949 storeHelper(std::ostream & stream, std::optional<P> & data,
void * context)
955 template <
typename P,
typename Q>
968 template <
typename T>
972 std::size_t size = data.
size();
977 mooseAssert(data.
hasValue(i),
"Data doesn't have a value");
983 template <
typename P>
991 template <
typename P>
993 loadHelper(std::istream & stream, std::vector<P> & data,
void * context)
999 template <
typename P>
1001 loadHelper(std::istream & stream, std::shared_ptr<P> & data,
void * context)
1007 template <
typename P>
1009 loadHelper(std::istream & stream, std::unique_ptr<P> & data,
void * context)
1015 template <
typename P>
1017 loadHelper(std::istream & stream, std::set<P> & data,
void * context)
1023 template <
typename P,
typename Q>
1025 loadHelper(std::istream & stream, std::map<P, Q> & data,
void * context)
1031 template <
typename P,
typename Q>
1033 loadHelper(std::istream & stream, std::unordered_map<P, Q> & data,
void * context)
1039 template <
typename P>
1041 loadHelper(std::istream & stream, std::optional<P> & data,
void * context)
1047 template <
typename P,
typename Q>
1061 template <
typename T>
1073 void dataLoad(std::istream & stream, Point & p,
void * context);
1075 #ifndef TIMPI_HAVE_STRING_PACKING 1086 template <
typename T>
1090 static const unsigned int size_bytes = 4;
1096 unsigned int string_len =
reinterpret_cast<const unsigned char &
>(in[size_bytes - 1]);
1097 for (
signed int i = size_bytes - 2; i >= 0; --i)
1100 string_len +=
reinterpret_cast<const unsigned char &
>(in[i]);
1105 static unsigned int packed_size(
typename std::vector<T>::const_iterator in)
1107 return get_string_len(in) + size_bytes;
1112 return s.size() + size_bytes;
1115 template <
typename Iter>
1116 static void pack(
const std::basic_string<T> & b, Iter data_out,
const void *)
1118 unsigned int string_len = b.size();
1119 for (
unsigned int i = 0; i != size_bytes; ++i)
1121 *data_out++ = (string_len % 256);
1125 std::copy(b.begin(), b.end(), data_out);
1128 static std::basic_string<T>
unpack(
typename std::vector<T>::const_iterator in,
void *)
1130 unsigned int string_len = get_string_len(in);
1132 std::ostringstream oss;
1133 for (
unsigned int i = 0; i < string_len; ++i)
1134 oss << reinterpret_cast<const unsigned char &>(in[i + size_bytes]);
1136 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...
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 *)
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...
static unsigned int get_string_len(typename std::vector< T >::const_iterator in)
Eigen::Matrix< Real, Eigen::Dynamic, 1 > RealEigenVector
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)