https://mooseframework.inl.gov
DataIO.h
Go to the documentation of this file.
1 //* This file is part of the MOOSE framework
2 //* https://mooseframework.inl.gov
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 "ADReal.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 <unordered_set>
39 #include <memory>
40 #include <optional>
41 
42 namespace libMesh
43 {
44 template <typename T>
45 class DenseMatrix;
46 template <typename T>
47 class DenseVector;
48 template <typename T>
49 class VectorValue;
50 template <typename T>
51 class TensorValue;
52 class Elem;
53 class Point;
54 }
55 
59 template <typename P>
60 inline void storeHelper(std::ostream & stream, P & data, void * context);
61 
65 template <typename P>
66 inline void storeHelper(std::ostream & stream, std::vector<P> & data, void * context);
67 
71 template <typename P>
72 inline void storeHelper(std::ostream & stream, std::shared_ptr<P> & data, void * context);
73 
77 template <typename P>
78 inline void storeHelper(std::ostream & stream, std::unique_ptr<P> & data, void * context);
79 
83 template <typename P>
84 inline void storeHelper(std::ostream & stream, std::set<P> & data, void * context);
85 
89 template <typename P, typename Q>
90 inline void storeHelper(std::ostream & stream, std::map<P, Q> & data, void * context);
91 
95 template <typename P, typename Q>
96 inline void storeHelper(std::ostream & stream, std::unordered_map<P, Q> & data, void * context);
97 
101 template <typename P>
102 inline void storeHelper(std::ostream & stream, std::optional<P> & data, void * context);
103 
107 template <typename P, typename Q>
108 inline void storeHelper(std::ostream & stream, HashMap<P, Q> & data, void * context);
109 
113 template <typename T>
114 inline void storeHelper(std::ostream & stream, UniqueStorage<T> & data, void * context);
115 
119 template <typename P>
120 inline void loadHelper(std::istream & stream, P & data, void * context);
121 
125 template <typename P>
126 inline void loadHelper(std::istream & stream, std::vector<P> & data, void * context);
127 
131 template <typename P>
132 inline void loadHelper(std::istream & stream, std::shared_ptr<P> & data, void * context);
133 
137 template <typename P>
138 inline void loadHelper(std::istream & stream, std::unique_ptr<P> & data, void * context);
139 
143 template <typename P>
144 inline void loadHelper(std::istream & stream, std::set<P> & data, void * context);
145 
149 template <typename P, typename Q>
150 inline void loadHelper(std::istream & stream, std::map<P, Q> & data, void * context);
151 
155 template <typename P, typename Q>
156 inline void loadHelper(std::istream & stream, std::unordered_map<P, Q> & data, void * context);
157 
161 template <typename P>
162 inline void loadHelper(std::istream & stream, std::optional<P> & data, void * context);
163 
167 template <typename P, typename Q>
168 inline void loadHelper(std::istream & stream, HashMap<P, Q> & data, void * context);
169 
173 template <typename T>
174 inline void loadHelper(std::istream & stream, UniqueStorage<T> & data, void * context);
175 
176 template <typename T>
177 inline void dataStore(std::ostream & stream, T & v, void * /*context*/);
178 
179 // DO NOT MODIFY THE NEXT LINE - It is used by MOOSEDocs
180 // *************** Global Store Declarations *****************
181 template <typename T>
182 inline void
183 dataStore(std::ostream & stream, T & v, void * /*context*/)
184 {
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");
193 #endif
194 
195  // Moose::out<<"Generic dataStore"<<std::endl;
196  stream.write((char *)&v, sizeof(v));
197  mooseAssert(!stream.bad(), "Failed to store");
198 }
199 
200 template <typename T>
201 inline void
202 dataStore(std::ostream & /*stream*/, T *& /*v*/, void * /*context*/)
203 {
204  mooseError("Attempting to store a raw pointer type: \"",
205  libMesh::demangle(typeid(T).name()),
206  " *\" as restartable data!\nWrite a custom dataStore() template specialization!\n\n");
207 }
208 
209 void dataStore(std::ostream & stream, Point & p, void * context);
210 
211 template <typename T, typename U>
212 inline void
213 dataStore(std::ostream & stream, std::pair<T, U> & p, void * context)
214 {
215  storeHelper(stream, p.first, context);
216  storeHelper(stream, p.second, context);
217 }
218 
219 template <typename T>
220 inline void
221 dataStore(std::ostream & stream, std::vector<T> & v, void * context)
222 {
223  // First store the size of the vector
224  unsigned int size = v.size();
225  dataStore(stream, size, nullptr);
226 
227  for (unsigned int i = 0; i < size; i++)
228  storeHelper(stream, v[i], context);
229 }
230 
231 template <typename T>
232 inline void
233 dataStore(std::ostream & stream, std::shared_ptr<T> & v, void * context)
234 {
235  T * tmp = v.get();
236 
237  storeHelper(stream, tmp, context);
238 }
239 
240 template <typename T>
241 inline void
242 dataStore(std::ostream & stream, std::unique_ptr<T> & v, void * context)
243 {
244  T * tmp = v.get();
245 
246  storeHelper(stream, tmp, context);
247 }
248 
249 template <typename T>
250 inline void
251 dataStore(std::ostream & stream, std::set<T> & s, void * context)
252 {
253  // First store the size of the set
254  unsigned int size = s.size();
255  dataStore(stream, size, nullptr);
256 
257  typename std::set<T>::iterator it = s.begin();
258  typename std::set<T>::iterator end = s.end();
259 
260  for (; it != end; ++it)
261  {
262  T & x = const_cast<T &>(*it);
263  storeHelper(stream, x, context);
264  }
265 }
266 
267 template <typename T>
268 inline void
269 dataStore(std::ostream & stream, std::list<T> & l, void * context)
270 {
271  // First store the size of the set
272  unsigned int size = l.size();
273  dataStore(stream, size, nullptr);
274 
275  typename std::list<T>::iterator it = l.begin();
276  typename std::list<T>::iterator end = l.end();
277 
278  for (; it != end; ++it)
279  {
280  T & x = const_cast<T &>(*it);
281  storeHelper(stream, x, context);
282  }
283 }
284 
285 template <typename T>
286 inline void
287 dataStore(std::ostream & stream, std::deque<T> & l, void * context)
288 {
289  // First store the size of the container
290  unsigned int size = l.size();
291  dataStore(stream, size, nullptr);
292 
293  typename std::deque<T>::iterator it = l.begin();
294  typename std::deque<T>::iterator end = l.end();
295 
296  for (; it != end; ++it)
297  {
298  T & x = const_cast<T &>(*it);
299  storeHelper(stream, x, context);
300  }
301 }
302 
303 template <typename T, typename U>
304 inline void
305 dataStore(std::ostream & stream, std::map<T, U> & m, void * context)
306 {
307  // First store the size of the map
308  unsigned int size = m.size();
309  dataStore(stream, size, nullptr);
310 
311  typename std::map<T, U>::iterator it = m.begin();
312  typename std::map<T, U>::iterator end = m.end();
313 
314  for (; it != end; ++it)
315  {
316  T & key = const_cast<T &>(it->first);
317 
318  storeHelper(stream, key, context);
319 
320  storeHelper(stream, it->second, context);
321  }
322 }
323 
324 template <typename T, typename U>
325 inline void
326 dataStore(std::ostream & stream, std::unordered_map<T, U> & m, void * context)
327 {
328  // First store the size of the map
329  unsigned int size = m.size();
330  dataStore(stream, size, nullptr);
331 
332  typename std::unordered_map<T, U>::iterator it = m.begin();
333  typename std::unordered_map<T, U>::iterator end = m.end();
334 
335  for (; it != end; ++it)
336  {
337  T & key = const_cast<T &>(it->first);
338 
339  storeHelper(stream, key, context);
340 
341  storeHelper(stream, it->second, context);
342  }
343 }
344 
345 template <typename T>
346 inline void
347 dataStore(std::ostream & stream, std::unordered_set<T> & s, void * context)
348 {
349  // First store the size of the set
350  std::size_t size = s.size();
351  dataStore(stream, size, nullptr);
352 
353  for (auto & element : s)
354  dataStore(stream, element, context);
355 }
356 
357 template <typename T>
358 inline void
359 dataStore(std::ostream & stream, std::optional<T> & m, void * context)
360 {
361  bool has_value = m.has_value();
362  dataStore(stream, has_value, nullptr);
363 
364  if (has_value)
365  storeHelper(stream, *m, context);
366 }
367 
368 template <typename T, typename U>
369 inline void
370 dataStore(std::ostream & stream, HashMap<T, U> & m, void * context)
371 {
372  // First store the size of the map
373  unsigned int size = m.size();
374  dataStore(stream, size, nullptr);
375 
376  typename HashMap<T, U>::iterator it = m.begin();
377  typename HashMap<T, U>::iterator end = m.end();
378 
379  for (; it != end; ++it)
380  {
381  T & key = const_cast<T &>(it->first);
382 
383  storeHelper(stream, key, context);
384 
385  storeHelper(stream, it->second, context);
386  }
387 }
388 
389 // Specializations (defined in .C)
390 template <>
391 void dataStore(std::ostream & stream, Real & v, void * context);
392 template <>
393 void dataStore(std::ostream & stream, std::string & v, void * context);
394 template <>
395 void dataStore(std::ostream & stream, VariableName & v, void * context);
396 template <>
397 void dataStore(std::ostream & stream, UserObjectName & v, void * context);
398 template <>
399 void dataStore(std::ostream & stream, bool & v, void * context);
400 // Vectors of bools are special
401 // https://en.wikipedia.org/w/index.php?title=Sequence_container_(C%2B%2B)&oldid=767869909#Specialization_for_bool
402 template <>
403 void dataStore(std::ostream & stream, std::vector<bool> & v, void * context);
404 template <>
405 void dataStore(std::ostream & stream, const Elem *& e, void * context);
406 template <>
407 void dataStore(std::ostream & stream, const Node *& n, void * context);
408 template <>
409 void dataStore(std::ostream & stream, Elem *& e, void * context);
410 template <>
411 void dataStore(std::ostream & stream, Node *& n, void * context);
412 template <>
413 void dataStore(std::ostream & stream, std::stringstream & s, void * context);
414 template <>
415 void dataStore(std::ostream & stream, ADReal & dn, void * context);
416 template <>
417 void dataStore(std::ostream & stream, RealEigenVector & v, void * context);
418 template <>
419 void dataStore(std::ostream & stream, RealEigenMatrix & v, void * context);
420 template <>
421 void dataStore(std::ostream & stream, libMesh::Parameters & p, void * context);
422 
423 template <>
434 void dataStore(std::ostream & stream,
435  std::unique_ptr<libMesh::NumericVector<libMesh::Number>> & v,
436  void * context);
437 
438 template <std::size_t N>
439 inline void
440 dataStore(std::ostream & stream, std::array<ADReal, N> & dn, void * context)
441 {
442  for (std::size_t i = 0; i < N; ++i)
443  dataStore(stream, dn[i], context);
444 }
445 
446 template <std::size_t N>
447 inline void
448 dataStore(std::ostream & stream, ADReal (&dn)[N], void * context)
449 {
450  for (std::size_t i = 0; i < N; ++i)
451  dataStore(stream, dn[i], context);
452 }
453 
454 template <typename T>
455 void
456 dataStore(std::ostream & stream, libMesh::NumericVector<T> & v, void * context)
457 {
458  v.close();
459 
460  numeric_index_type size = v.local_size();
461 
462  for (numeric_index_type i = v.first_local_index(); i < v.first_local_index() + size; i++)
463  {
464  T r = v(i);
465  dataStore(stream, r, context);
466  }
467 }
468 
469 template <>
470 void dataStore(std::ostream & stream, Vec & v, void * context);
471 
472 template <typename T>
473 void
474 dataStore(std::ostream & stream, DenseVector<T> & v, void * context)
475 {
476  unsigned int m = v.size();
477  dataStore(stream, m, nullptr);
478  for (unsigned int i = 0; i < v.size(); i++)
479  {
480  T r = v(i);
481  dataStore(stream, r, context);
482  }
483 }
484 
485 template <typename T>
486 void dataStore(std::ostream & stream, libMesh::TensorValue<T> & v, void * context);
487 
488 template <typename T>
489 void dataStore(std::ostream & stream, libMesh::DenseMatrix<T> & v, void * context);
490 
491 template <typename T>
492 void dataStore(std::ostream & stream, libMesh::VectorValue<T> & v, void * context);
493 
494 template <typename T>
495 void
496 dataStore(std::ostream & stream, RankTwoTensorTempl<T> & rtt, void * context)
497 {
498  dataStore(stream, rtt._coords, context);
499 }
500 
501 template <typename T>
502 void
503 dataStore(std::ostream & stream, RankThreeTensorTempl<T> & rtt, void * context)
504 {
505  dataStore(stream, rtt._vals, context);
506 }
507 
508 template <typename T>
509 void
510 dataStore(std::ostream & stream, RankFourTensorTempl<T> & rft, void * context)
511 {
512  dataStore(stream, rft._vals, context);
513 }
514 
515 template <typename T>
516 void
517 dataStore(std::ostream & stream, SymmetricRankTwoTensorTempl<T> & srtt, void * context)
518 {
519  dataStore(stream, srtt._vals, context);
520 }
521 
522 template <typename T>
523 void
524 dataStore(std::ostream & stream, SymmetricRankFourTensorTempl<T> & srft, void * context)
525 {
526  dataStore(stream, srft._vals, context);
527 }
528 
529 template <typename T>
530 void
531 dataStore(std::ostream & stream, ColumnMajorMatrixTempl<T> & cmm, void * context)
532 {
533  dataStore(stream, cmm._values, context);
534 }
535 
536 // DO NOT MODIFY THE NEXT LINE - It is used by MOOSEDocs
537 // *************** Global Load Declarations *****************
538 template <typename T>
539 inline void
540 dataLoad(std::istream & stream, T & v, void * /*context*/)
541 {
542  stream.read((char *)&v, sizeof(v));
543  mooseAssert(!stream.bad(), "Failed to load");
544 }
545 
546 template <typename T>
547 void
548 dataLoad(std::istream & /*stream*/, T *& /*v*/, void * /*context*/)
549 {
550  mooseError("Attempting to load a raw pointer type: \"",
551  libMesh::demangle(typeid(T).name()),
552  " *\" as restartable data!\nWrite a custom dataLoad() template specialization!\n\n");
553 }
554 
555 template <typename T, typename U>
556 inline void
557 dataLoad(std::istream & stream, std::pair<T, U> & p, void * context)
558 {
559  loadHelper(stream, p.first, context);
560  loadHelper(stream, p.second, context);
561 }
562 
563 template <typename T>
564 inline void
565 dataLoad(std::istream & stream, std::vector<T> & v, void * context)
566 {
567  // First read the size of the vector
568  unsigned int size = 0;
569  dataLoad(stream, size, nullptr);
570 
571  v.resize(size);
572 
573  for (unsigned int i = 0; i < size; i++)
574  loadHelper(stream, v[i], context);
575 }
576 
577 template <typename T>
578 inline void
579 dataLoad(std::istream & stream, std::shared_ptr<T> & v, void * context)
580 {
581  T * tmp = v.get();
582 
583  loadHelper(stream, tmp, context);
584 }
585 
586 template <typename T>
587 inline void
588 dataLoad(std::istream & stream, std::unique_ptr<T> & v, void * context)
589 {
590  T * tmp = v.get();
591 
592  loadHelper(stream, tmp, context);
593 }
594 
595 template <typename T>
596 inline void
597 dataLoad(std::istream & stream, std::set<T> & s, 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  s.insert(std::move(data));
608  }
609 }
610 
611 template <typename T>
612 inline void
613 dataLoad(std::istream & stream, std::list<T> & l, void * context)
614 {
615  // First read the size of the set
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>
628 inline void
629 dataLoad(std::istream & stream, std::deque<T> & l, void * context)
630 {
631  // First read the size of the container
632  unsigned int size = 0;
633  dataLoad(stream, size, nullptr);
634 
635  for (unsigned int i = 0; i < size; i++)
636  {
637  T data;
638  loadHelper(stream, data, context);
639  l.push_back(std::move(data));
640  }
641 }
642 
643 template <typename T, typename U>
644 inline void
645 dataLoad(std::istream & stream, std::map<T, U> & m, void * context)
646 {
647  m.clear();
648 
649  // First read the size of the map
650  unsigned int size = 0;
651  dataLoad(stream, size, nullptr);
652 
653  for (unsigned int i = 0; i < size; i++)
654  {
655  T key;
656  loadHelper(stream, key, context);
657 
658  U & value = m[key];
659  loadHelper(stream, value, context);
660  }
661 }
662 
663 template <typename T, typename U>
664 inline void
665 dataLoad(std::istream & stream, std::unordered_map<T, U> & m, void * context)
666 {
667  m.clear();
668 
669  // First read the size of the map
670  unsigned int size = 0;
671  dataLoad(stream, size, nullptr);
672 
673  for (unsigned int i = 0; i < size; i++)
674  {
675  T key;
676  loadHelper(stream, key, context);
677 
678  U & value = m[key];
679  loadHelper(stream, value, context);
680  }
681 }
682 
683 template <typename T>
684 inline void
685 dataLoad(std::istream & stream, std::unordered_set<T> & s, void * context)
686 {
687  s.clear();
688 
689  // First read the size of the set
690  std::size_t size = 0;
691  dataLoad(stream, size, nullptr);
692  s.reserve(size);
693 
694  for (std::size_t i = 0; i < size; i++)
695  {
696  T element;
697  dataLoad(stream, element, context);
698  s.insert(element);
699  }
700 }
701 
702 template <typename T>
703 inline void
704 dataLoad(std::istream & stream, std::optional<T> & m, void * context)
705 {
706  bool has_value;
707  dataLoad(stream, has_value, nullptr);
708 
709  if (has_value)
710  {
711  m = T{};
712  loadHelper(stream, *m, context);
713  }
714  else
715  m.reset();
716 }
717 
718 template <typename T, typename U>
719 inline void
720 dataLoad(std::istream & stream, HashMap<T, U> & m, void * context)
721 {
722  // First read the size of the map
723  unsigned int size = 0;
724  dataLoad(stream, size, nullptr);
725 
726  for (unsigned int i = 0; i < size; i++)
727  {
728  T key;
729  loadHelper(stream, key, context);
730 
731  U & value = m[key];
732  loadHelper(stream, value, context);
733  }
734 }
735 
736 // Specializations (defined in .C)
737 template <>
738 void dataLoad(std::istream & stream, Real & v, void * /*context*/);
739 template <>
740 void dataLoad(std::istream & stream, std::string & v, void * /*context*/);
741 template <>
742 void dataLoad(std::istream & stream, VariableName & v, void * /*context*/);
743 template <>
744 void dataLoad(std::istream & stream, UserObjectName & v, void * /*context*/);
745 template <>
746 void dataLoad(std::istream & stream, bool & v, void * /*context*/);
747 // Vectors of bools are special
748 // https://en.wikipedia.org/w/index.php?title=Sequence_container_(C%2B%2B)&oldid=767869909#Specialization_for_bool
749 template <>
750 void dataLoad(std::istream & stream, std::vector<bool> & v, void * /*context*/);
751 template <>
752 void dataLoad(std::istream & stream, const Elem *& e, void * context);
753 template <>
754 void dataLoad(std::istream & stream, const Node *& e, void * context);
755 template <>
756 void dataLoad(std::istream & stream, Elem *& e, void * context);
757 template <>
758 void dataLoad(std::istream & stream, Node *& e, void * context);
759 template <>
760 void dataLoad(std::istream & stream, std::stringstream & s, void * context);
761 template <>
762 void dataLoad(std::istream & stream, ADReal & dn, void * context);
763 template <>
764 void dataLoad(std::istream & stream, RealEigenVector & v, void * context);
765 template <>
766 void dataLoad(std::istream & stream, RealEigenMatrix & v, void * context);
767 template <>
768 void dataLoad(std::istream & stream, libMesh::Parameters & p, void * context);
769 template <>
787 void dataLoad(std::istream & stream,
788  std::unique_ptr<libMesh::NumericVector<libMesh::Number>> & v,
789  void * context);
790 
791 template <std::size_t N>
792 inline void
793 dataLoad(std::istream & stream, std::array<ADReal, N> & dn, void * context)
794 {
795  for (std::size_t i = 0; i < N; ++i)
796  dataLoad(stream, dn[i], context);
797 }
798 
799 template <std::size_t N>
800 inline void
801 dataLoad(std::istream & stream, ADReal (&dn)[N], void * context)
802 {
803  for (std::size_t i = 0; i < N; ++i)
804  dataLoad(stream, dn[i], context);
805 }
806 
807 template <typename T>
808 void
809 dataLoad(std::istream & stream, libMesh::NumericVector<T> & v, void * context)
810 {
811  numeric_index_type size = v.local_size();
812  for (numeric_index_type i = v.first_local_index(); i < v.first_local_index() + size; i++)
813  {
814  T r = 0;
815  dataLoad(stream, r, context);
816  v.set(i, r);
817  }
818  v.close();
819 }
820 
821 template <>
822 void dataLoad(std::istream & stream, Vec & v, void * context);
823 
824 template <typename T>
825 void
826 dataLoad(std::istream & stream, DenseVector<T> & v, void * context)
827 {
828  unsigned int n = 0;
829  dataLoad(stream, n, nullptr);
830  v.resize(n);
831  for (unsigned int i = 0; i < n; i++)
832  {
833  T r = 0;
834  dataLoad(stream, r, context);
835  v(i) = r;
836  }
837 }
838 
839 template <typename T>
840 void dataLoad(std::istream & stream, libMesh::TensorValue<T> & v, void * context);
841 
842 template <typename T>
843 void dataLoad(std::istream & stream, libMesh::DenseMatrix<T> & v, void * context);
844 
845 template <typename T>
846 void dataLoad(std::istream & stream, libMesh::VectorValue<T> & v, void * context);
847 
848 template <typename T>
849 void
850 dataLoad(std::istream & stream, RankTwoTensorTempl<T> & rtt, void * context)
851 {
852  dataLoad(stream, rtt._coords, context);
853 }
854 
855 template <typename T>
856 void
857 dataLoad(std::istream & stream, RankThreeTensorTempl<T> & rtt, void * context)
858 {
859  dataLoad(stream, rtt._vals, context);
860 }
861 
862 template <typename T>
863 void
864 dataLoad(std::istream & stream, RankFourTensorTempl<T> & rft, void * context)
865 {
866  dataLoad(stream, rft._vals, context);
867 }
868 
869 template <typename T>
870 void
871 dataLoad(std::istream & stream, SymmetricRankTwoTensorTempl<T> & rtt, void * context)
872 {
873  dataLoad(stream, rtt._vals, context);
874 }
875 
876 template <typename T>
877 void
878 dataLoad(std::istream & stream, SymmetricRankFourTensorTempl<T> & rft, void * context)
879 {
880  dataLoad(stream, rft._vals, context);
881 }
882 
883 template <typename T>
884 void
885 dataLoad(std::istream & stream, ColumnMajorMatrixTempl<T> & cmm, void * context)
886 {
887  dataLoad(stream, cmm._values, context);
888 }
889 
890 // Scalar Helper Function
891 template <typename P>
892 inline void
893 storeHelper(std::ostream & stream, P & data, void * context)
894 {
895  dataStore(stream, data, context);
896 }
897 
898 // Vector Helper Function
899 template <typename P>
900 inline void
901 storeHelper(std::ostream & stream, std::vector<P> & data, void * context)
902 {
903  dataStore(stream, data, context);
904 }
905 
906 // std::shared_ptr Helper Function
907 template <typename P>
908 inline void
909 storeHelper(std::ostream & stream, std::shared_ptr<P> & data, void * context)
910 {
911  dataStore(stream, data, context);
912 }
913 
914 // std::unique Helper Function
915 template <typename P>
916 inline void
917 storeHelper(std::ostream & stream, std::unique_ptr<P> & data, void * context)
918 {
919  dataStore(stream, data, context);
920 }
921 
922 // Set Helper Function
923 template <typename P>
924 inline void
925 storeHelper(std::ostream & stream, std::set<P> & data, void * context)
926 {
927  dataStore(stream, data, context);
928 }
929 
930 // Map Helper Function
931 template <typename P, typename Q>
932 inline void
933 storeHelper(std::ostream & stream, std::map<P, Q> & data, void * context)
934 {
935  dataStore(stream, data, context);
936 }
937 
938 // Unordered_map Helper Function
939 template <typename P, typename Q>
940 inline void
941 storeHelper(std::ostream & stream, std::unordered_map<P, Q> & data, void * context)
942 {
943  dataStore(stream, data, context);
944 }
945 
946 // Optional Helper Function
947 template <typename P>
948 inline void
949 storeHelper(std::ostream & stream, std::optional<P> & data, void * context)
950 {
951  dataStore(stream, data, context);
952 }
953 
954 // HashMap Helper Function
955 template <typename P, typename Q>
956 inline void
957 storeHelper(std::ostream & stream, HashMap<P, Q> & data, void * context)
958 {
959  dataStore(stream, data, context);
960 }
961 
968 template <typename T>
969 inline void
970 storeHelper(std::ostream & stream, UniqueStorage<T> & data, void * context)
971 {
972  std::size_t size = data.size();
973  dataStore(stream, size, nullptr);
974 
975  for (const auto i : index_range(data))
976  {
977  mooseAssert(data.hasValue(i), "Data doesn't have a value");
978  storeHelper(stream, data.pointerValue(i), context);
979  }
980 }
981 
982 // Scalar Helper Function
983 template <typename P>
984 inline void
985 loadHelper(std::istream & stream, P & data, void * context)
986 {
987  dataLoad(stream, data, context);
988 }
989 
990 // Vector Helper Function
991 template <typename P>
992 inline void
993 loadHelper(std::istream & stream, std::vector<P> & data, void * context)
994 {
995  dataLoad(stream, data, context);
996 }
997 
998 // std::shared_ptr Helper Function
999 template <typename P>
1000 inline void
1001 loadHelper(std::istream & stream, std::shared_ptr<P> & data, void * context)
1002 {
1003  dataLoad(stream, data, context);
1004 }
1005 
1006 // Unique Pointer Helper Function
1007 template <typename P>
1008 inline void
1009 loadHelper(std::istream & stream, std::unique_ptr<P> & data, void * context)
1010 {
1011  dataLoad(stream, data, context);
1012 }
1013 
1014 // Set Helper Function
1015 template <typename P>
1016 inline void
1017 loadHelper(std::istream & stream, std::set<P> & data, void * context)
1018 {
1019  dataLoad(stream, data, context);
1020 }
1021 
1022 // Map Helper Function
1023 template <typename P, typename Q>
1024 inline void
1025 loadHelper(std::istream & stream, std::map<P, Q> & data, void * context)
1026 {
1027  dataLoad(stream, data, context);
1028 }
1029 
1030 // Unordered_map Helper Function
1031 template <typename P, typename Q>
1032 inline void
1033 loadHelper(std::istream & stream, std::unordered_map<P, Q> & data, void * context)
1034 {
1035  dataLoad(stream, data, context);
1036 }
1037 
1038 // Optional Helper Function
1039 template <typename P>
1040 inline void
1041 loadHelper(std::istream & stream, std::optional<P> & data, void * context)
1042 {
1043  dataLoad(stream, data, context);
1044 }
1045 
1046 // HashMap Helper Function
1047 template <typename P, typename Q>
1048 inline void
1049 loadHelper(std::istream & stream, HashMap<P, Q> & data, void * context)
1050 {
1051  dataLoad(stream, data, context);
1052 }
1053 
1061 template <typename T>
1062 inline void
1063 loadHelper(std::istream & stream, UniqueStorage<T> & data, void * context)
1064 {
1065  std::size_t size;
1066  dataLoad(stream, size, nullptr);
1067  data.resize(size);
1068 
1069  for (const auto i : index_range(data))
1070  loadHelper(stream, data.pointerValue(i), context);
1071 }
1072 
1073 void dataLoad(std::istream & stream, Point & p, void * context);
1074 
1075 #ifndef TIMPI_HAVE_STRING_PACKING
1076 
1082 namespace libMesh
1083 {
1084 namespace Parallel
1085 {
1086 template <typename T>
1087 class Packing<std::basic_string<T>>
1088 {
1089 public:
1090  static const unsigned int size_bytes = 4;
1091 
1092  typedef T buffer_type;
1093 
1094  static unsigned int get_string_len(typename std::vector<T>::const_iterator in)
1095  {
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)
1098  {
1099  string_len *= 256;
1100  string_len += reinterpret_cast<const unsigned char &>(in[i]);
1101  }
1102  return string_len;
1103  }
1104 
1105  static unsigned int packed_size(typename std::vector<T>::const_iterator in)
1106  {
1107  return get_string_len(in) + size_bytes;
1108  }
1109 
1110  static unsigned int packable_size(const std::basic_string<T> & s, const void *)
1111  {
1112  return s.size() + size_bytes;
1113  }
1114 
1115  template <typename Iter>
1116  static void pack(const std::basic_string<T> & b, Iter data_out, const void *)
1117  {
1118  unsigned int string_len = b.size();
1119  for (unsigned int i = 0; i != size_bytes; ++i)
1120  {
1121  *data_out++ = (string_len % 256);
1122  string_len /= 256;
1123  }
1124 
1125  std::copy(b.begin(), b.end(), data_out);
1126  }
1127 
1128  static std::basic_string<T> unpack(typename std::vector<T>::const_iterator in, void *)
1129  {
1130  unsigned int string_len = get_string_len(in);
1131 
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]);
1135 
1136  in += size_bytes + string_len;
1137 
1138  return oss.str();
1139  }
1140 };
1141 
1142 } // namespace Parallel
1143 
1144 } // namespace libMesh
1145 
1146 #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:302
static std::basic_string< T > unpack(typename std::vector< T >::const_iterator in, void *)
Definition: DataIO.h:1128
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:1110
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
Definition: ADRealForward.h:46
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:893
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:1105
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:149
std::string demangle(const char *name)
virtual void close()=0
void dataStore(std::ostream &stream, T &v, void *)
Definition: DataIO.h:183
static void pack(const std::basic_string< T > &b, Iter data_out, const void *)
Definition: DataIO.h:1116
virtual numeric_index_type first_local_index() const=0
RankTwoTensorTempl is designed to handle the Stress or Strain Tensor for a fully anisotropic material...
Definition: RankTwoTensor.h:87
std::vector< T > _values
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)
Definition: DataIO.h:1094
Eigen::Matrix< Real, Eigen::Dynamic, 1 > RealEigenVector
Definition: MooseTypes.h:146
virtual void set(const numeric_index_type i, const T value)=0
void dataLoad(std::istream &stream, T &v, void *)
Definition: DataIO.h:540
void loadHelper(std::istream &stream, P &data, void *context)
Scalar helper routine.
Definition: DataIO.h:985
bool hasValue(const std::size_t i) const
auto index_range(const T &sizable)