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");
195 stream.write((
char *)&v,
sizeof(v));
196 mooseAssert(!stream.bad(),
"Failed to store");
199 template <
typename T>
203 mooseError(
"Attempting to store a raw pointer type: \"",
205 " *\" as restartable data!\nWrite a custom dataStore() template specialization!\n\n");
208 void dataStore(std::ostream & stream, Point & p,
void * context);
210 template <
typename T,
typename U>
212 dataStore(std::ostream & stream, std::pair<T, U> & p,
void * context)
218 template <
typename T>
220 dataStore(std::ostream & stream, std::vector<T> & v,
void * context)
223 unsigned int size = v.size();
226 for (
unsigned int i = 0; i < size; i++)
230 template <
typename T>
232 dataStore(std::ostream & stream, std::shared_ptr<T> & v,
void * context)
239 template <
typename T>
241 dataStore(std::ostream & stream, std::unique_ptr<T> & v,
void * context)
248 template <
typename T>
250 dataStore(std::ostream & stream, std::set<T> & s,
void * context)
253 unsigned int size = s.size();
256 typename std::set<T>::iterator it = s.begin();
257 typename std::set<T>::iterator end = s.end();
259 for (; it != end; ++it)
261 T & x =
const_cast<T &
>(*it);
266 template <
typename T>
268 dataStore(std::ostream & stream, std::list<T> & l,
void * context)
271 unsigned int size = l.size();
274 typename std::list<T>::iterator it = l.begin();
275 typename std::list<T>::iterator end = l.end();
277 for (; it != end; ++it)
279 T & x =
const_cast<T &
>(*it);
284 template <
typename T>
286 dataStore(std::ostream & stream, std::deque<T> & l,
void * context)
289 unsigned int size = l.size();
292 typename std::deque<T>::iterator it = l.begin();
293 typename std::deque<T>::iterator end = l.end();
295 for (; it != end; ++it)
297 T & x =
const_cast<T &
>(*it);
302 template <
typename T,
typename U>
304 dataStore(std::ostream & stream, std::map<T, U> & m,
void * context)
307 unsigned int size = m.size();
310 typename std::map<T, U>::iterator it = m.begin();
311 typename std::map<T, U>::iterator end = m.end();
313 for (; it != end; ++it)
315 T & key =
const_cast<T &
>(it->first);
323 template <
typename T,
typename U>
325 dataStore(std::ostream & stream, std::unordered_map<T, U> & m,
void * context)
328 unsigned int size = m.size();
331 typename std::unordered_map<T, U>::iterator it = m.begin();
332 typename std::unordered_map<T, U>::iterator end = m.end();
334 for (; it != end; ++it)
336 T & key =
const_cast<T &
>(it->first);
344 template <
typename T>
346 dataStore(std::ostream & stream, std::unordered_set<T> & s,
void * context)
349 std::size_t size = s.size();
352 for (
auto & element : s)
356 template <
typename T>
358 dataStore(std::ostream & stream, std::optional<T> & m,
void * context)
360 bool has_value = m.has_value();
367 template <
typename T,
typename U>
372 unsigned int size = m.size();
378 for (; it != end; ++it)
380 T & key =
const_cast<T &
>(it->first);
388 template <
typename T,
int Rows,
int Cols>
390 dataStore(std::ostream & stream, Eigen::Matrix<T, Rows, Cols> & v,
void * context)
392 auto m = cast_int<unsigned int>(v.rows());
394 auto n = cast_int<unsigned int>(v.cols());
406 void dataStore(std::ostream & stream, Real & v,
void * context);
408 void dataStore(std::ostream & stream, std::string & v,
void * context);
410 void dataStore(std::ostream & stream, VariableName & v,
void * context);
412 void dataStore(std::ostream & stream, UserObjectName & v,
void * context);
414 void dataStore(std::ostream & stream,
bool & v,
void * context);
418 void dataStore(std::ostream & stream, std::vector<bool> & v,
void * context);
420 void dataStore(std::ostream & stream,
const Elem *& e,
void * context);
422 void dataStore(std::ostream & stream,
const Node *& n,
void * context);
424 void dataStore(std::ostream & stream, Elem *& e,
void * context);
426 void dataStore(std::ostream & stream, Node *& n,
void * context);
428 void dataStore(std::ostream & stream, std::stringstream & s,
void * context);
449 template <std::
size_t N>
451 dataStore(std::ostream & stream, std::array<ADReal, N> & dn,
void * context)
453 for (std::size_t i = 0; i <
N; ++i)
457 template <std::
size_t N>
461 for (std::size_t i = 0; i <
N; ++i)
465 template <
typename T>
481 void dataStore(std::ostream & stream, Vec & v,
void * context);
483 template <
typename T>
485 dataStore(std::ostream & stream, DenseVector<T> & v,
void * context)
487 unsigned int m = v.size();
489 for (
unsigned int i = 0; i < v.size(); i++)
496 template <
typename T>
499 template <
typename T>
502 template <
typename T>
505 template <
typename T>
512 template <
typename T>
519 template <
typename T>
526 template <
typename T>
533 template <
typename T>
540 template <
typename T>
549 template <
typename T>
553 stream.read((
char *)&v,
sizeof(v));
554 mooseAssert(!stream.bad(),
"Failed to load");
557 template <
typename T>
561 mooseError(
"Attempting to load a raw pointer type: \"",
563 " *\" as restartable data!\nWrite a custom dataLoad() template specialization!\n\n");
566 template <
typename T,
typename U>
568 dataLoad(std::istream & stream, std::pair<T, U> & p,
void * context)
574 template <
typename T>
576 dataLoad(std::istream & stream, std::vector<T> & v,
void * context)
579 unsigned int size = 0;
584 for (
unsigned int i = 0; i < size; i++)
588 template <
typename T>
590 dataLoad(std::istream & stream, std::shared_ptr<T> & v,
void * context)
597 template <
typename T>
599 dataLoad(std::istream & stream, std::unique_ptr<T> & v,
void * context)
606 template <
typename T>
608 dataLoad(std::istream & stream, std::set<T> & s,
void * context)
611 unsigned int size = 0;
614 for (
unsigned int i = 0; i < size; i++)
618 s.insert(std::move(data));
622 template <
typename T>
624 dataLoad(std::istream & stream, std::list<T> & l,
void * context)
627 unsigned int size = 0;
630 for (
unsigned int i = 0; i < size; i++)
634 l.push_back(std::move(data));
638 template <
typename T>
640 dataLoad(std::istream & stream, std::deque<T> & l,
void * context)
643 unsigned int size = 0;
646 for (
unsigned int i = 0; i < size; i++)
650 l.push_back(std::move(data));
654 template <
typename T,
typename U>
656 dataLoad(std::istream & stream, std::map<T, U> & m,
void * context)
661 unsigned int size = 0;
664 for (
unsigned int i = 0; i < size; i++)
674 template <
typename T,
typename U>
676 dataLoad(std::istream & stream, std::unordered_map<T, U> & m,
void * context)
681 unsigned int size = 0;
684 for (
unsigned int i = 0; i < size; i++)
694 template <
typename T>
696 dataLoad(std::istream & stream, std::unordered_set<T> & s,
void * context)
701 std::size_t size = 0;
705 for (std::size_t i = 0; i < size; i++)
713 template <
typename T>
715 dataLoad(std::istream & stream, std::optional<T> & m,
void * context)
718 dataLoad(stream, has_value,
nullptr);
729 template <
typename T,
typename U>
734 unsigned int size = 0;
737 for (
unsigned int i = 0; i < size; i++)
747 template <
typename T,
int Rows,
int Cols>
749 dataLoad(std::istream & stream, Eigen::Matrix<T, Rows, Cols> & v,
void * context)
767 void dataLoad(std::istream & stream, Real & v,
void * );
769 void dataLoad(std::istream & stream, std::string & v,
void * );
771 void dataLoad(std::istream & stream, VariableName & v,
void * );
773 void dataLoad(std::istream & stream, UserObjectName & v,
void * );
775 void dataLoad(std::istream & stream,
bool & v,
void * );
779 void dataLoad(std::istream & stream, std::vector<bool> & v,
void * );
781 void dataLoad(std::istream & stream,
const Elem *& e,
void * context);
783 void dataLoad(std::istream & stream,
const Node *& e,
void * context);
785 void dataLoad(std::istream & stream, Elem *& e,
void * context);
787 void dataLoad(std::istream & stream, Node *& e,
void * context);
789 void dataLoad(std::istream & stream, std::stringstream & s,
void * context);
791 void dataLoad(std::istream & stream,
ADReal & dn,
void * context);
812 void dataLoad(std::istream & stream,
816 template <std::
size_t N>
818 dataLoad(std::istream & stream, std::array<ADReal, N> & dn,
void * context)
820 for (std::size_t i = 0; i <
N; ++i)
824 template <std::
size_t N>
828 for (std::size_t i = 0; i <
N; ++i)
832 template <
typename T>
847 void dataLoad(std::istream & stream, Vec & v,
void * context);
849 template <
typename T>
851 dataLoad(std::istream & stream, DenseVector<T> & v,
void * context)
856 for (
unsigned int i = 0; i < n; i++)
864 template <
typename T>
867 template <
typename T>
870 template <
typename T>
873 template <
typename T>
880 template <
typename T>
887 template <
typename T>
894 template <
typename T>
901 template <
typename T>
908 template <
typename T>
916 template <
typename P>
924 template <
typename P>
926 storeHelper(std::ostream & stream, std::vector<P> & data,
void * context)
932 template <
typename P>
934 storeHelper(std::ostream & stream, std::shared_ptr<P> & data,
void * context)
940 template <
typename P>
942 storeHelper(std::ostream & stream, std::unique_ptr<P> & data,
void * context)
948 template <
typename P>
950 storeHelper(std::ostream & stream, std::set<P> & data,
void * context)
956 template <
typename P,
typename Q>
958 storeHelper(std::ostream & stream, std::map<P, Q> & data,
void * context)
964 template <
typename P,
typename Q>
966 storeHelper(std::ostream & stream, std::unordered_map<P, Q> & data,
void * context)
972 template <
typename P>
974 storeHelper(std::ostream & stream, std::optional<P> & data,
void * context)
980 template <
typename P,
typename Q>
993 template <
typename T>
997 std::size_t size = data.
size();
1002 mooseAssert(data.
hasValue(i),
"Data doesn't have a value");
1008 template <
typename P>
1016 template <
typename P>
1018 loadHelper(std::istream & stream, std::vector<P> & data,
void * context)
1024 template <
typename P>
1026 loadHelper(std::istream & stream, std::shared_ptr<P> & data,
void * context)
1032 template <
typename P>
1034 loadHelper(std::istream & stream, std::unique_ptr<P> & data,
void * context)
1040 template <
typename P>
1042 loadHelper(std::istream & stream, std::set<P> & data,
void * context)
1048 template <
typename P,
typename Q>
1050 loadHelper(std::istream & stream, std::map<P, Q> & data,
void * context)
1056 template <
typename P,
typename Q>
1058 loadHelper(std::istream & stream, std::unordered_map<P, Q> & data,
void * context)
1064 template <
typename P>
1066 loadHelper(std::istream & stream, std::optional<P> & data,
void * context)
1072 template <
typename P,
typename Q>
1086 template <
typename T>
1098 void dataLoad(std::istream & stream, Point & p,
void * context);
1100 #ifndef TIMPI_HAVE_STRING_PACKING 1111 template <
typename T>
1115 static const unsigned int size_bytes = 4;
1121 unsigned int string_len =
reinterpret_cast<const unsigned char &
>(in[size_bytes - 1]);
1122 for (
signed int i = size_bytes - 2; i >= 0; --i)
1125 string_len +=
reinterpret_cast<const unsigned char &
>(in[i]);
1130 static unsigned int packed_size(
typename std::vector<T>::const_iterator in)
1132 return get_string_len(in) + size_bytes;
1137 return s.size() + size_bytes;
1140 template <
typename Iter>
1141 static void pack(
const std::basic_string<T> & b, Iter data_out,
const void *)
1143 unsigned int string_len = b.size();
1144 for (
unsigned int i = 0; i != size_bytes; ++i)
1146 *data_out++ = (string_len % 256);
1150 std::copy(b.begin(), b.end(), data_out);
1153 static std::basic_string<T>
unpack(
typename std::vector<T>::const_iterator in,
void *)
1155 unsigned int string_len = get_string_len(in);
1157 std::ostringstream oss;
1158 for (
unsigned int i = 0; i < string_len; ++i)
1159 oss << reinterpret_cast<const unsigned char &>(in[i + size_bytes]);
1161 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)
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)