www.mooseframework.org
DataIO.h
Go to the documentation of this file.
1 //* This file is part of the MOOSE framework
2 //* https://www.mooseframework.org
3 //*
4 //* All rights reserved, see COPYRIGHT for full restrictions
5 //* https://github.com/idaholab/moose/blob/master/COPYRIGHT
6 //*
7 //* Licensed under LGPL 2.1, please see LICENSE for details
8 //* https://www.gnu.org/licenses/lgpl-2.1.html
9 
10 #pragma once
11 
12 // MOOSE includes
13 #include "DualReal.h"
14 #include "MooseTypes.h"
15 #include "HashMap.h"
16 #include "MooseError.h"
17 #include "RankTwoTensor.h"
18 #include "RankThreeTensor.h"
19 #include "RankFourTensor.h"
20 #include "ColumnMajorMatrix.h"
21 #include "UniqueStorage.h"
22 
23 #include "libmesh/parallel.h"
24 #include "libmesh/parameters.h"
25 #include "libmesh/numeric_vector.h"
26 
27 #ifdef LIBMESH_HAVE_CXX11_TYPE_TRAITS
28 #include <type_traits>
29 #endif
30 
31 // C++ includes
32 #include <string>
33 #include <vector>
34 #include <list>
35 #include <iostream>
36 #include <map>
37 #include <unordered_map>
38 #include <memory>
39 #include <optional>
40 
41 namespace libMesh
42 {
43 template <typename T>
44 class DenseMatrix;
45 template <typename T>
46 class DenseVector;
47 template <typename T>
48 class VectorValue;
49 template <typename T>
50 class TensorValue;
51 class Elem;
52 class Point;
53 }
54 
58 template <typename P>
59 inline void storeHelper(std::ostream & stream, P & data, void * context);
60 
64 template <typename P>
65 inline void storeHelper(std::ostream & stream, std::vector<P> & data, void * context);
66 
70 template <typename P>
71 inline void storeHelper(std::ostream & stream, std::shared_ptr<P> & data, void * context);
72 
76 template <typename P>
77 inline void storeHelper(std::ostream & stream, std::unique_ptr<P> & data, void * context);
78 
82 template <typename P>
83 inline void storeHelper(std::ostream & stream, std::set<P> & data, void * context);
84 
88 template <typename P, typename Q>
89 inline void storeHelper(std::ostream & stream, std::map<P, Q> & data, void * context);
90 
94 template <typename P, typename Q>
95 inline void storeHelper(std::ostream & stream, std::unordered_map<P, Q> & data, void * context);
96 
100 template <typename P>
101 inline void storeHelper(std::ostream & stream, std::optional<P> & data, void * context);
102 
106 template <typename P, typename Q>
107 inline void storeHelper(std::ostream & stream, HashMap<P, Q> & data, void * context);
108 
112 template <typename T>
113 inline void storeHelper(std::ostream & stream, UniqueStorage<T> & data, void * context);
114 
118 template <typename P>
119 inline void loadHelper(std::istream & stream, P & data, void * context);
120 
124 template <typename P>
125 inline void loadHelper(std::istream & stream, std::vector<P> & data, void * context);
126 
130 template <typename P>
131 inline void loadHelper(std::istream & stream, std::shared_ptr<P> & data, void * context);
132 
136 template <typename P>
137 inline void loadHelper(std::istream & stream, std::unique_ptr<P> & data, void * context);
138 
142 template <typename P>
143 inline void loadHelper(std::istream & stream, std::set<P> & data, void * context);
144 
148 template <typename P, typename Q>
149 inline void loadHelper(std::istream & stream, std::map<P, Q> & data, void * context);
150 
154 template <typename P, typename Q>
155 inline void loadHelper(std::istream & stream, std::unordered_map<P, Q> & data, void * context);
156 
160 template <typename P>
161 inline void loadHelper(std::istream & stream, std::optional<P> & data, void * context);
162 
166 template <typename P, typename Q>
167 inline void loadHelper(std::istream & stream, HashMap<P, Q> & data, void * context);
168 
172 template <typename T>
173 inline void loadHelper(std::istream & stream, UniqueStorage<T> & data, void * context);
174 
175 template <typename T>
176 inline void dataStore(std::ostream & stream, T & v, void * /*context*/);
177 
178 // DO NOT MODIFY THE NEXT LINE - It is used by MOOSEDocs
179 // *************** Global Store Declarations *****************
180 template <typename T>
181 inline void
182 dataStore(std::ostream & stream, T & v, void * /*context*/)
183 {
184 #ifdef LIBMESH_HAVE_CXX11_TYPE_TRAITS
185  static_assert(std::is_polymorphic<T>::value == false,
186  "Cannot serialize a class that has virtual "
187  "members!\nWrite a custom dataStore() "
188  "template specialization!\n\n");
189  static_assert(std::is_trivially_copyable<T>::value,
190  "Cannot serialize a class that is not trivially copyable!\nWrite a custom "
191  "dataStore() template specialization!\n\n");
192 #endif
193 
194  // Moose::out<<"Generic dataStore"<<std::endl;
195  stream.write((char *)&v, sizeof(v));
196  mooseAssert(!stream.bad(), "Failed to store");
197 }
198 
199 template <typename T>
200 inline void
201 dataStore(std::ostream & /*stream*/, T *& /*v*/, void * /*context*/)
202 {
203  mooseError("Attempting to store a raw pointer type: \"",
204  demangle(typeid(T).name()),
205  " *\" as restartable data!\nWrite a custom dataStore() template specialization!\n\n");
206 }
207 
208 void dataStore(std::ostream & stream, Point & p, void * context);
209 
210 template <typename T, typename U>
211 inline void
212 dataStore(std::ostream & stream, std::pair<T, U> & p, void * context)
213 {
214  storeHelper(stream, p.first, context);
215  storeHelper(stream, p.second, context);
216 }
217 
218 template <typename T>
219 inline void
220 dataStore(std::ostream & stream, std::vector<T> & v, void * context)
221 {
222  // First store the size of the vector
223  unsigned int size = v.size();
224  dataStore(stream, size, nullptr);
225 
226  for (unsigned int i = 0; i < size; i++)
227  storeHelper(stream, v[i], context);
228 }
229 
230 template <typename T>
231 inline void
232 dataStore(std::ostream & stream, std::shared_ptr<T> & v, void * context)
233 {
234  T * tmp = v.get();
235 
236  storeHelper(stream, tmp, context);
237 }
238 
239 template <typename T>
240 inline void
241 dataStore(std::ostream & stream, std::unique_ptr<T> & v, void * context)
242 {
243  T * tmp = v.get();
244 
245  storeHelper(stream, tmp, context);
246 }
247 
248 template <typename T>
249 inline void
250 dataStore(std::ostream & stream, std::set<T> & s, void * context)
251 {
252  // First store the size of the set
253  unsigned int size = s.size();
254  dataStore(stream, size, nullptr);
255 
256  typename std::set<T>::iterator it = s.begin();
257  typename std::set<T>::iterator end = s.end();
258 
259  for (; it != end; ++it)
260  {
261  T & x = const_cast<T &>(*it);
262  storeHelper(stream, x, context);
263  }
264 }
265 
266 template <typename T>
267 inline void
268 dataStore(std::ostream & stream, std::list<T> & l, void * context)
269 {
270  // First store the size of the set
271  unsigned int size = l.size();
272  dataStore(stream, size, nullptr);
273 
274  typename std::list<T>::iterator it = l.begin();
275  typename std::list<T>::iterator end = l.end();
276 
277  for (; it != end; ++it)
278  {
279  T & x = const_cast<T &>(*it);
280  storeHelper(stream, x, context);
281  }
282 }
283 
284 template <typename T>
285 inline void
286 dataStore(std::ostream & stream, std::deque<T> & l, void * context)
287 {
288  // First store the size of the container
289  unsigned int size = l.size();
290  dataStore(stream, size, nullptr);
291 
292  typename std::deque<T>::iterator it = l.begin();
293  typename std::deque<T>::iterator end = l.end();
294 
295  for (; it != end; ++it)
296  {
297  T & x = const_cast<T &>(*it);
298  storeHelper(stream, x, context);
299  }
300 }
301 
302 template <typename T, typename U>
303 inline void
304 dataStore(std::ostream & stream, std::map<T, U> & m, void * context)
305 {
306  // First store the size of the map
307  unsigned int size = m.size();
308  dataStore(stream, size, nullptr);
309 
310  typename std::map<T, U>::iterator it = m.begin();
311  typename std::map<T, U>::iterator end = m.end();
312 
313  for (; it != end; ++it)
314  {
315  T & key = const_cast<T &>(it->first);
316 
317  storeHelper(stream, key, context);
318 
319  storeHelper(stream, it->second, context);
320  }
321 }
322 
323 template <typename T, typename U>
324 inline void
325 dataStore(std::ostream & stream, std::unordered_map<T, U> & m, void * context)
326 {
327  // First store the size of the map
328  unsigned int size = m.size();
329  dataStore(stream, size, nullptr);
330 
331  typename std::unordered_map<T, U>::iterator it = m.begin();
332  typename std::unordered_map<T, U>::iterator end = m.end();
333 
334  for (; it != end; ++it)
335  {
336  T & key = const_cast<T &>(it->first);
337 
338  storeHelper(stream, key, context);
339 
340  storeHelper(stream, it->second, context);
341  }
342 }
343 
344 template <typename T>
345 inline void
346 dataStore(std::ostream & stream, std::optional<T> & m, void * context)
347 {
348  bool has_value = m.has_value();
349  dataStore(stream, has_value, nullptr);
350 
351  if (has_value)
352  storeHelper(stream, *m, context);
353 }
354 
355 template <typename T, typename U>
356 inline void
357 dataStore(std::ostream & stream, HashMap<T, U> & m, void * context)
358 {
359  // First store the size of the map
360  unsigned int size = m.size();
361  dataStore(stream, size, nullptr);
362 
363  typename HashMap<T, U>::iterator it = m.begin();
364  typename HashMap<T, U>::iterator end = m.end();
365 
366  for (; it != end; ++it)
367  {
368  T & key = const_cast<T &>(it->first);
369 
370  storeHelper(stream, key, context);
371 
372  storeHelper(stream, it->second, context);
373  }
374 }
375 
376 // Specializations (defined in .C)
377 template <>
378 void dataStore(std::ostream & stream, Real & v, void * context);
379 template <>
380 void dataStore(std::ostream & stream, std::string & v, void * context);
381 template <>
382 void dataStore(std::ostream & stream, VariableName & v, void * context);
383 template <>
384 void dataStore(std::ostream & stream, bool & v, void * context);
385 // Vectors of bools are special
386 // https://en.wikipedia.org/w/index.php?title=Sequence_container_(C%2B%2B)&oldid=767869909#Specialization_for_bool
387 template <>
388 void dataStore(std::ostream & stream, std::vector<bool> & v, void * context);
389 template <>
390 void dataStore(std::ostream & stream, const Elem *& e, void * context);
391 template <>
392 void dataStore(std::ostream & stream, const Node *& n, void * context);
393 template <>
394 void dataStore(std::ostream & stream, Elem *& e, void * context);
395 template <>
396 void dataStore(std::ostream & stream, Node *& n, void * context);
397 template <>
398 void dataStore(std::ostream & stream, std::stringstream & s, void * context);
399 template <>
400 void dataStore(std::ostream & stream, DualReal & dn, void * context);
401 template <>
402 void dataStore(std::ostream & stream, RealEigenVector & v, void * context);
403 template <>
404 void dataStore(std::ostream & stream, RealEigenMatrix & v, void * context);
405 template <>
406 void dataStore(std::ostream & stream, libMesh::Parameters & p, void * context);
407 template <>
418 void dataStore(std::ostream & stream,
419  std::unique_ptr<libMesh::NumericVector<Number>> & v,
420  void * context);
421 
422 template <std::size_t N>
423 inline void
424 dataStore(std::ostream & stream, std::array<DualReal, N> & dn, void * context)
425 {
426  for (std::size_t i = 0; i < N; ++i)
427  dataStore(stream, dn[i], context);
428 }
429 
430 template <std::size_t N>
431 inline void
432 dataStore(std::ostream & stream, DualReal (&dn)[N], void * context)
433 {
434  for (std::size_t i = 0; i < N; ++i)
435  dataStore(stream, dn[i], context);
436 }
437 
438 template <typename T>
439 void
440 dataStore(std::ostream & stream, NumericVector<T> & v, void * context)
441 {
442  v.close();
443 
444  numeric_index_type size = v.local_size();
445 
446  for (numeric_index_type i = v.first_local_index(); i < v.first_local_index() + size; i++)
447  {
448  T r = v(i);
449  dataStore(stream, r, context);
450  }
451 }
452 
453 template <>
454 void dataStore(std::ostream & stream, Vec & v, void * context);
455 
456 template <typename T>
457 void
458 dataStore(std::ostream & stream, DenseVector<T> & v, void * context)
459 {
460  unsigned int m = v.size();
461  dataStore(stream, m, nullptr);
462  for (unsigned int i = 0; i < v.size(); i++)
463  {
464  T r = v(i);
465  dataStore(stream, r, context);
466  }
467 }
468 
469 template <typename T>
470 void dataStore(std::ostream & stream, TensorValue<T> & v, void * context);
471 
472 template <typename T>
473 void dataStore(std::ostream & stream, DenseMatrix<T> & v, void * context);
474 
475 template <typename T>
476 void dataStore(std::ostream & stream, VectorValue<T> & v, void * context);
477 
478 template <typename T>
479 void
480 dataStore(std::ostream & stream, RankTwoTensorTempl<T> & rtt, void * context)
481 {
482  dataStore(stream, rtt._coords, context);
483 }
484 
485 template <typename T>
486 void
487 dataStore(std::ostream & stream, RankThreeTensorTempl<T> & rtt, void * context)
488 {
489  dataStore(stream, rtt._vals, context);
490 }
491 
492 template <typename T>
493 void
494 dataStore(std::ostream & stream, RankFourTensorTempl<T> & rft, void * context)
495 {
496  dataStore(stream, rft._vals, context);
497 }
498 
499 template <typename T>
500 void
501 dataStore(std::ostream & stream, SymmetricRankTwoTensorTempl<T> & srtt, void * context)
502 {
503  dataStore(stream, srtt._vals, context);
504 }
505 
506 template <typename T>
507 void
508 dataStore(std::ostream & stream, SymmetricRankFourTensorTempl<T> & srft, void * context)
509 {
510  dataStore(stream, srft._vals, context);
511 }
512 
513 template <typename T>
514 void
515 dataStore(std::ostream & stream, ColumnMajorMatrixTempl<T> & cmm, void * context)
516 {
517  dataStore(stream, cmm._values, context);
518 }
519 
520 // DO NOT MODIFY THE NEXT LINE - It is used by MOOSEDocs
521 // *************** Global Load Declarations *****************
522 template <typename T>
523 inline void
524 dataLoad(std::istream & stream, T & v, void * /*context*/)
525 {
526  stream.read((char *)&v, sizeof(v));
527  mooseAssert(!stream.bad(), "Failed to load");
528 }
529 
530 template <typename T>
531 void
532 dataLoad(std::istream & /*stream*/, T *& /*v*/, void * /*context*/)
533 {
534  mooseError("Attempting to load a raw pointer type: \"",
535  demangle(typeid(T).name()),
536  " *\" as restartable data!\nWrite a custom dataLoad() template specialization!\n\n");
537 }
538 
539 template <typename T, typename U>
540 inline void
541 dataLoad(std::istream & stream, std::pair<T, U> & p, void * context)
542 {
543  loadHelper(stream, p.first, context);
544  loadHelper(stream, p.second, context);
545 }
546 
547 template <typename T>
548 inline void
549 dataLoad(std::istream & stream, std::vector<T> & v, void * context)
550 {
551  // First read the size of the vector
552  unsigned int size = 0;
553  dataLoad(stream, size, nullptr);
554 
555  v.resize(size);
556 
557  for (unsigned int i = 0; i < size; i++)
558  loadHelper(stream, v[i], context);
559 }
560 
561 template <typename T>
562 inline void
563 dataLoad(std::istream & stream, std::shared_ptr<T> & v, void * context)
564 {
565  T * tmp = v.get();
566 
567  loadHelper(stream, tmp, context);
568 }
569 
570 template <typename T>
571 inline void
572 dataLoad(std::istream & stream, std::unique_ptr<T> & v, void * context)
573 {
574  T * tmp = v.get();
575 
576  loadHelper(stream, tmp, context);
577 }
578 
579 template <typename T>
580 inline void
581 dataLoad(std::istream & stream, std::set<T> & s, void * context)
582 {
583  // First read the size of the set
584  unsigned int size = 0;
585  dataLoad(stream, size, nullptr);
586 
587  for (unsigned int i = 0; i < size; i++)
588  {
589  T data;
590  loadHelper(stream, data, context);
591  s.insert(std::move(data));
592  }
593 }
594 
595 template <typename T>
596 inline void
597 dataLoad(std::istream & stream, std::list<T> & l, void * context)
598 {
599  // First read the size of the set
600  unsigned int size = 0;
601  dataLoad(stream, size, nullptr);
602 
603  for (unsigned int i = 0; i < size; i++)
604  {
605  T data;
606  loadHelper(stream, data, context);
607  l.push_back(std::move(data));
608  }
609 }
610 
611 template <typename T>
612 inline void
613 dataLoad(std::istream & stream, std::deque<T> & l, void * context)
614 {
615  // First read the size of the container
616  unsigned int size = 0;
617  dataLoad(stream, size, nullptr);
618 
619  for (unsigned int i = 0; i < size; i++)
620  {
621  T data;
622  loadHelper(stream, data, context);
623  l.push_back(std::move(data));
624  }
625 }
626 
627 template <typename T, typename U>
628 inline void
629 dataLoad(std::istream & stream, std::map<T, U> & m, void * context)
630 {
631  m.clear();
632 
633  // First read the size of the map
634  unsigned int size = 0;
635  dataLoad(stream, size, nullptr);
636 
637  for (unsigned int i = 0; i < size; i++)
638  {
639  T key;
640  loadHelper(stream, key, context);
641 
642  U & value = m[key];
643  loadHelper(stream, value, context);
644  }
645 }
646 
647 template <typename T, typename U>
648 inline void
649 dataLoad(std::istream & stream, std::unordered_map<T, U> & m, void * context)
650 {
651  m.clear();
652 
653  // First read the size of the map
654  unsigned int size = 0;
655  dataLoad(stream, size, nullptr);
656 
657  for (unsigned int i = 0; i < size; i++)
658  {
659  T key;
660  loadHelper(stream, key, context);
661 
662  U & value = m[key];
663  loadHelper(stream, value, context);
664  }
665 }
666 
667 template <typename T>
668 inline void
669 dataLoad(std::istream & stream, std::optional<T> & m, void * context)
670 {
671  bool has_value;
672  dataLoad(stream, has_value, nullptr);
673 
674  if (has_value)
675  {
676  m = T{};
677  loadHelper(stream, *m, context);
678  }
679  else
680  m.reset();
681 }
682 
683 template <typename T, typename U>
684 inline void
685 dataLoad(std::istream & stream, HashMap<T, U> & m, void * context)
686 {
687  // First read the size of the map
688  unsigned int size = 0;
689  dataLoad(stream, size, nullptr);
690 
691  for (unsigned int i = 0; i < size; i++)
692  {
693  T key;
694  loadHelper(stream, key, context);
695 
696  U & value = m[key];
697  loadHelper(stream, value, context);
698  }
699 }
700 
701 // Specializations (defined in .C)
702 template <>
703 void dataLoad(std::istream & stream, Real & v, void * /*context*/);
704 template <>
705 void dataLoad(std::istream & stream, std::string & v, void * /*context*/);
706 template <>
707 void dataLoad(std::istream & stream, VariableName & v, void * /*context*/);
708 template <>
709 void dataLoad(std::istream & stream, bool & v, void * /*context*/);
710 // Vectors of bools are special
711 // https://en.wikipedia.org/w/index.php?title=Sequence_container_(C%2B%2B)&oldid=767869909#Specialization_for_bool
712 template <>
713 void dataLoad(std::istream & stream, std::vector<bool> & v, void * /*context*/);
714 template <>
715 void dataLoad(std::istream & stream, const Elem *& e, void * context);
716 template <>
717 void dataLoad(std::istream & stream, const Node *& e, void * context);
718 template <>
719 void dataLoad(std::istream & stream, Elem *& e, void * context);
720 template <>
721 void dataLoad(std::istream & stream, Node *& e, void * context);
722 template <>
723 void dataLoad(std::istream & stream, std::stringstream & s, void * context);
724 template <>
725 void dataLoad(std::istream & stream, DualReal & dn, void * context);
726 template <>
727 void dataLoad(std::istream & stream, RealEigenVector & v, void * context);
728 template <>
729 void dataLoad(std::istream & stream, RealEigenMatrix & v, void * context);
730 template <>
731 void dataLoad(std::istream & stream, libMesh::Parameters & p, void * context);
732 template <>
750 void dataLoad(std::istream & stream,
751  std::unique_ptr<libMesh::NumericVector<Number>> & v,
752  void * context);
753 
754 template <std::size_t N>
755 inline void
756 dataLoad(std::istream & stream, std::array<DualReal, N> & dn, void * context)
757 {
758  for (std::size_t i = 0; i < N; ++i)
759  dataLoad(stream, dn[i], context);
760 }
761 
762 template <std::size_t N>
763 inline void
764 dataLoad(std::istream & stream, DualReal (&dn)[N], void * context)
765 {
766  for (std::size_t i = 0; i < N; ++i)
767  dataLoad(stream, dn[i], context);
768 }
769 
770 template <typename T>
771 void
772 dataLoad(std::istream & stream, NumericVector<T> & v, void * context)
773 {
774  numeric_index_type size = v.local_size();
775  for (numeric_index_type i = v.first_local_index(); i < v.first_local_index() + size; i++)
776  {
777  T r = 0;
778  dataLoad(stream, r, context);
779  v.set(i, r);
780  }
781  v.close();
782 }
783 
784 template <>
785 void dataLoad(std::istream & stream, Vec & v, void * context);
786 
787 template <typename T>
788 void
789 dataLoad(std::istream & stream, DenseVector<T> & v, void * context)
790 {
791  unsigned int n = 0;
792  dataLoad(stream, n, nullptr);
793  v.resize(n);
794  for (unsigned int i = 0; i < n; i++)
795  {
796  T r = 0;
797  dataLoad(stream, r, context);
798  v(i) = r;
799  }
800 }
801 
802 template <typename T>
803 void dataLoad(std::istream & stream, TensorValue<T> & v, void * context);
804 
805 template <typename T>
806 void dataLoad(std::istream & stream, DenseMatrix<T> & v, void * context);
807 
808 template <typename T>
809 void dataLoad(std::istream & stream, VectorValue<T> & v, void * context);
810 
811 template <typename T>
812 void
813 dataLoad(std::istream & stream, RankTwoTensorTempl<T> & rtt, void * context)
814 {
815  dataLoad(stream, rtt._coords, context);
816 }
817 
818 template <typename T>
819 void
820 dataLoad(std::istream & stream, RankThreeTensorTempl<T> & rtt, void * context)
821 {
822  dataLoad(stream, rtt._vals, context);
823 }
824 
825 template <typename T>
826 void
827 dataLoad(std::istream & stream, RankFourTensorTempl<T> & rft, void * context)
828 {
829  dataLoad(stream, rft._vals, context);
830 }
831 
832 template <typename T>
833 void
834 dataLoad(std::istream & stream, SymmetricRankTwoTensorTempl<T> & rtt, void * context)
835 {
836  dataLoad(stream, rtt._vals, context);
837 }
838 
839 template <typename T>
840 void
841 dataLoad(std::istream & stream, SymmetricRankFourTensorTempl<T> & rft, void * context)
842 {
843  dataLoad(stream, rft._vals, context);
844 }
845 
846 template <typename T>
847 void
848 dataLoad(std::istream & stream, ColumnMajorMatrixTempl<T> & cmm, void * context)
849 {
850  dataLoad(stream, cmm._values, context);
851 }
852 
853 // Scalar Helper Function
854 template <typename P>
855 inline void
856 storeHelper(std::ostream & stream, P & data, void * context)
857 {
858  dataStore(stream, data, context);
859 }
860 
861 // Vector Helper Function
862 template <typename P>
863 inline void
864 storeHelper(std::ostream & stream, std::vector<P> & data, void * context)
865 {
866  dataStore(stream, data, context);
867 }
868 
869 // std::shared_ptr Helper Function
870 template <typename P>
871 inline void
872 storeHelper(std::ostream & stream, std::shared_ptr<P> & data, void * context)
873 {
874  dataStore(stream, data, context);
875 }
876 
877 // std::unique Helper Function
878 template <typename P>
879 inline void
880 storeHelper(std::ostream & stream, std::unique_ptr<P> & data, void * context)
881 {
882  dataStore(stream, data, context);
883 }
884 
885 // Set Helper Function
886 template <typename P>
887 inline void
888 storeHelper(std::ostream & stream, std::set<P> & data, void * context)
889 {
890  dataStore(stream, data, context);
891 }
892 
893 // Map Helper Function
894 template <typename P, typename Q>
895 inline void
896 storeHelper(std::ostream & stream, std::map<P, Q> & data, void * context)
897 {
898  dataStore(stream, data, context);
899 }
900 
901 // Unordered_map Helper Function
902 template <typename P, typename Q>
903 inline void
904 storeHelper(std::ostream & stream, std::unordered_map<P, Q> & data, void * context)
905 {
906  dataStore(stream, data, context);
907 }
908 
909 // Optional Helper Function
910 template <typename P>
911 inline void
912 storeHelper(std::ostream & stream, std::optional<P> & data, void * context)
913 {
914  dataStore(stream, data, context);
915 }
916 
917 // HashMap Helper Function
918 template <typename P, typename Q>
919 inline void
920 storeHelper(std::ostream & stream, HashMap<P, Q> & data, void * context)
921 {
922  dataStore(stream, data, context);
923 }
924 
931 template <typename T>
932 inline void
933 storeHelper(std::ostream & stream, UniqueStorage<T> & data, void * context)
934 {
935  std::size_t size = data.size();
936  dataStore(stream, size, nullptr);
937 
938  for (const auto i : index_range(data))
939  {
940  mooseAssert(data.hasValue(i), "Data doesn't have a value");
941  storeHelper(stream, data.pointerValue(i), context);
942  }
943 }
944 
945 // Scalar Helper Function
946 template <typename P>
947 inline void
948 loadHelper(std::istream & stream, P & data, void * context)
949 {
950  dataLoad(stream, data, context);
951 }
952 
953 // Vector Helper Function
954 template <typename P>
955 inline void
956 loadHelper(std::istream & stream, std::vector<P> & data, void * context)
957 {
958  dataLoad(stream, data, context);
959 }
960 
961 // std::shared_ptr Helper Function
962 template <typename P>
963 inline void
964 loadHelper(std::istream & stream, std::shared_ptr<P> & data, void * context)
965 {
966  dataLoad(stream, data, context);
967 }
968 
969 // Unique Pointer Helper Function
970 template <typename P>
971 inline void
972 loadHelper(std::istream & stream, std::unique_ptr<P> & data, void * context)
973 {
974  dataLoad(stream, data, context);
975 }
976 
977 // Set Helper Function
978 template <typename P>
979 inline void
980 loadHelper(std::istream & stream, std::set<P> & data, void * context)
981 {
982  dataLoad(stream, data, context);
983 }
984 
985 // Map Helper Function
986 template <typename P, typename Q>
987 inline void
988 loadHelper(std::istream & stream, std::map<P, Q> & data, void * context)
989 {
990  dataLoad(stream, data, context);
991 }
992 
993 // Unordered_map Helper Function
994 template <typename P, typename Q>
995 inline void
996 loadHelper(std::istream & stream, std::unordered_map<P, Q> & data, void * context)
997 {
998  dataLoad(stream, data, context);
999 }
1000 
1001 // Optional Helper Function
1002 template <typename P>
1003 inline void
1004 loadHelper(std::istream & stream, std::optional<P> & data, void * context)
1005 {
1006  dataLoad(stream, data, context);
1007 }
1008 
1009 // HashMap Helper Function
1010 template <typename P, typename Q>
1011 inline void
1012 loadHelper(std::istream & stream, HashMap<P, Q> & data, void * context)
1013 {
1014  dataLoad(stream, data, context);
1015 }
1016 
1024 template <typename T>
1025 inline void
1026 loadHelper(std::istream & stream, UniqueStorage<T> & data, void * context)
1027 {
1028  std::size_t size;
1029  dataLoad(stream, size, nullptr);
1030  data.resize(size);
1031 
1032  for (const auto i : index_range(data))
1033  loadHelper(stream, data.pointerValue(i), context);
1034 }
1035 
1036 void dataLoad(std::istream & stream, Point & p, void * context);
1037 
1038 #ifndef TIMPI_HAVE_STRING_PACKING
1039 
1045 namespace libMesh
1046 {
1047 namespace Parallel
1048 {
1049 template <typename T>
1050 class Packing<std::basic_string<T>>
1051 {
1052 public:
1053  static const unsigned int size_bytes = 4;
1054 
1055  typedef T buffer_type;
1056 
1057  static unsigned int get_string_len(typename std::vector<T>::const_iterator in)
1058  {
1059  unsigned int string_len = reinterpret_cast<const unsigned char &>(in[size_bytes - 1]);
1060  for (signed int i = size_bytes - 2; i >= 0; --i)
1061  {
1062  string_len *= 256;
1063  string_len += reinterpret_cast<const unsigned char &>(in[i]);
1064  }
1065  return string_len;
1066  }
1067 
1068  static unsigned int packed_size(typename std::vector<T>::const_iterator in)
1069  {
1070  return get_string_len(in) + size_bytes;
1071  }
1072 
1073  static unsigned int packable_size(const std::basic_string<T> & s, const void *)
1074  {
1075  return s.size() + size_bytes;
1076  }
1077 
1078  template <typename Iter>
1079  static void pack(const std::basic_string<T> & b, Iter data_out, const void *)
1080  {
1081  unsigned int string_len = b.size();
1082  for (unsigned int i = 0; i != size_bytes; ++i)
1083  {
1084  *data_out++ = (string_len % 256);
1085  string_len /= 256;
1086  }
1087 
1088  std::copy(b.begin(), b.end(), data_out);
1089  }
1090 
1091  static std::basic_string<T> unpack(typename std::vector<T>::const_iterator in, void *)
1092  {
1093  unsigned int string_len = get_string_len(in);
1094 
1095  std::ostringstream oss;
1096  for (unsigned int i = 0; i < string_len; ++i)
1097  oss << reinterpret_cast<const unsigned char &>(in[i + size_bytes]);
1098 
1099  in += size_bytes + string_len;
1100 
1101  return oss.str();
1102  }
1103 };
1104 
1105 } // namespace Parallel
1106 
1107 } // namespace libMesh
1108 
1109 #endif
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...
Definition: HashMap.h:18
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...
Definition: MooseError.h:299
static std::basic_string< T > unpack(typename std::vector< T >::const_iterator in, void *)
Definition: DataIO.h:1091
DualNumber< Real, DNDerivativeType, true > DualReal
Definition: DualReal.h:49
Storage container that stores a vector of unique pointers of T, but represents most of the public fac...
Definition: UniqueStorage.h:18
static unsigned int packable_size(const std::basic_string< T > &s, const void *)
Definition: DataIO.h:1073
The following methods are specializations for using the libMesh::Parallel::packed_range_* routines fo...
T _coords[LIBMESH_DIM *LIBMESH_DIM]
std::size_t size() const
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.
Definition: DataIO.h:856
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)
Definition: DataIO.h:1068
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
Definition: MooseTypes.h:141
std::string demangle(const char *name)
void dataStore(std::ostream &stream, T &v, void *)
Definition: DataIO.h:182
static void pack(const std::basic_string< T > &b, Iter data_out, const void *)
Definition: DataIO.h:1079
RankTwoTensorTempl is designed to handle the Stress or Strain Tensor for a fully anisotropic material...
Definition: RankTwoTensor.h:79
std::vector< T > _values
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)
Definition: DataIO.h:1057
Eigen::Matrix< Real, Eigen::Dynamic, 1 > RealEigenVector
Definition: MooseTypes.h:138
void dataLoad(std::istream &stream, T &v, void *)
Definition: DataIO.h:524
void loadHelper(std::istream &stream, P &data, void *context)
Scalar helper routine.
Definition: DataIO.h:948
bool hasValue(const std::size_t i) const
auto index_range(const T &sizable)