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 "Backup.h"
18 #include "RankTwoTensor.h"
19 #include "RankThreeTensor.h"
20 #include "RankFourTensor.h"
21 #include "MooseADWrapper.h"
22 
23 #include "libmesh/parallel.h"
24 #ifdef LIBMESH_HAVE_CXX11_TYPE_TRAITS
25 #include <type_traits>
26 #endif
27 
28 // C++ includes
29 #include <string>
30 #include <vector>
31 #include <list>
32 #include <iostream>
33 #include <map>
34 #include <unordered_map>
35 #include <memory>
36 
37 // Forward declarations
38 template <typename>
41 
42 namespace libMesh
43 {
44 template <typename T>
45 class NumericVector;
46 template <typename T>
48 template <typename T>
49 class DenseVector;
50 template <typename T>
51 class VectorValue;
52 template <typename T>
54 class Elem;
55 class Point;
56 }
57 
61 template <typename P>
62 inline void storeHelper(std::ostream & stream, P & data, void * context);
63 
67 template <typename P>
68 inline void storeHelper(std::ostream & stream, std::vector<P> & data, void * context);
69 
73 template <typename P>
74 inline void storeHelper(std::ostream & stream, std::shared_ptr<P> & data, void * context);
75 
79 template <typename P>
80 inline void storeHelper(std::ostream & stream, std::unique_ptr<P> & data, void * context);
81 
85 template <typename P>
86 inline void storeHelper(std::ostream & stream, std::set<P> & data, void * context);
87 
91 template <typename P, typename Q>
92 inline void storeHelper(std::ostream & stream, std::map<P, Q> & data, void * context);
93 
97 template <typename P, typename Q>
98 inline void storeHelper(std::ostream & stream, std::unordered_map<P, Q> & data, void * context);
99 
103 template <typename P, typename Q>
104 inline void storeHelper(std::ostream & stream, HashMap<P, Q> & data, void * context);
105 
109 template <typename P>
110 inline void loadHelper(std::istream & stream, P & data, void * context);
111 
115 template <typename P>
116 inline void loadHelper(std::istream & stream, std::vector<P> & data, void * context);
117 
121 template <typename P>
122 inline void loadHelper(std::istream & stream, std::shared_ptr<P> & data, void * context);
123 
127 template <typename P>
128 inline void loadHelper(std::istream & stream, std::unique_ptr<P> & data, void * context);
129 
133 template <typename P>
134 inline void loadHelper(std::istream & stream, std::set<P> & data, void * context);
135 
139 template <typename P, typename Q>
140 inline void loadHelper(std::istream & stream, std::map<P, Q> & data, void * context);
141 
145 template <typename P, typename Q>
146 inline void loadHelper(std::istream & stream, std::unordered_map<P, Q> & data, void * context);
147 
151 template <typename P, typename Q>
152 inline void loadHelper(std::istream & stream, HashMap<P, Q> & data, void * context);
153 
154 template <typename T>
155 inline void dataStore(std::ostream & stream, T & v, void * /*context*/);
156 
157 // DO NOT MODIFY THE NEXT LINE - It is used by MOOSEDocs
158 // *************** Global Store Declarations *****************
159 template <typename T>
160 inline void
161 dataStore(std::ostream & stream, T & v, void * /*context*/)
162 {
163 #ifdef LIBMESH_HAVE_CXX11_TYPE_TRAITS
164  static_assert(std::is_polymorphic<T>::value == false,
165  "Cannot serialize a class that has virtual "
166  "members!\nWrite a custom dataStore() "
167  "template specialization!\n\n");
168  static_assert(std::is_trivially_copyable<T>::value,
169  "Cannot serialize a class that is not trivially copyable!\nWrite a custom "
170  "dataStore() template specialization!\n\n");
171 #endif
172 
173  // Moose::out<<"Generic dataStore"<<std::endl;
174  stream.write((char *)&v, sizeof(v));
175 }
176 
177 template <typename T>
178 inline void
179 dataStore(std::ostream & /*stream*/, T *& /*v*/, void * /*context*/)
180 {
181  mooseError("Attempting to store a raw pointer type: \"",
182  demangle(typeid(T).name()),
183  " *\" as restartable data!\nWrite a custom dataStore() template specialization!\n\n");
184 }
185 
186 void dataStore(std::ostream & stream, Point & p, void * context);
187 
188 template <typename T, typename U>
189 inline void
190 dataStore(std::ostream & stream, std::pair<T, U> & p, void * context)
191 {
192  storeHelper(stream, p.first, context);
193  storeHelper(stream, p.second, context);
194 }
195 
196 template <typename T>
197 inline void
198 dataStore(std::ostream & stream, std::vector<T> & v, void * context)
199 {
200  // First store the size of the vector
201  unsigned int size = v.size();
202  stream.write((char *)&size, sizeof(size));
203 
204  for (unsigned int i = 0; i < size; i++)
205  storeHelper(stream, v[i], context);
206 }
207 
208 template <typename T>
209 inline void
210 dataStore(std::ostream & stream, std::shared_ptr<T> & v, void * context)
211 {
212  T * tmp = v.get();
213 
214  storeHelper(stream, tmp, context);
215 }
216 
217 template <typename T>
218 inline void
219 dataStore(std::ostream & stream, std::unique_ptr<T> & v, void * context)
220 {
221  T * tmp = v.get();
222 
223  storeHelper(stream, tmp, context);
224 }
225 
226 template <typename T>
227 inline void
228 dataStore(std::ostream & stream, std::set<T> & s, void * context)
229 {
230  // First store the size of the set
231  unsigned int size = s.size();
232  stream.write((char *)&size, sizeof(size));
233 
234  typename std::set<T>::iterator it = s.begin();
235  typename std::set<T>::iterator end = s.end();
236 
237  for (; it != end; ++it)
238  {
239  T & x = const_cast<T &>(*it);
240  storeHelper(stream, x, context);
241  }
242 }
243 
244 template <typename T>
245 inline void
246 dataStore(std::ostream & stream, std::list<T> & l, void * context)
247 {
248  // First store the size of the set
249  unsigned int size = l.size();
250  stream.write((char *)&size, sizeof(size));
251 
252  typename std::list<T>::iterator it = l.begin();
253  typename std::list<T>::iterator end = l.end();
254 
255  for (; it != end; ++it)
256  {
257  T & x = const_cast<T &>(*it);
258  storeHelper(stream, x, context);
259  }
260 }
261 
262 template <typename T, typename U>
263 inline void
264 dataStore(std::ostream & stream, std::map<T, U> & m, void * context)
265 {
266  // First store the size of the map
267  unsigned int size = m.size();
268  stream.write((char *)&size, sizeof(size));
269 
270  typename std::map<T, U>::iterator it = m.begin();
271  typename std::map<T, U>::iterator end = m.end();
272 
273  for (; it != end; ++it)
274  {
275  T & key = const_cast<T &>(it->first);
276 
277  storeHelper(stream, key, context);
278 
279  storeHelper(stream, it->second, context);
280  }
281 }
282 
283 template <typename T, typename U>
284 inline void
285 dataStore(std::ostream & stream, std::unordered_map<T, U> & m, void * context)
286 {
287  // First store the size of the map
288  unsigned int size = m.size();
289  stream.write((char *)&size, sizeof(size));
290 
291  typename std::unordered_map<T, U>::iterator it = m.begin();
292  typename std::unordered_map<T, U>::iterator end = m.end();
293 
294  for (; it != end; ++it)
295  {
296  T & key = const_cast<T &>(it->first);
297 
298  storeHelper(stream, key, context);
299 
300  storeHelper(stream, it->second, context);
301  }
302 }
303 
304 template <typename T, typename U>
305 inline void
306 dataStore(std::ostream & stream, HashMap<T, U> & m, void * context)
307 {
308  // First store the size of the map
309  unsigned int size = m.size();
310  stream.write((char *)&size, sizeof(size));
311 
312  typename HashMap<T, U>::iterator it = m.begin();
313  typename HashMap<T, U>::iterator end = m.end();
314 
315  for (; it != end; ++it)
316  {
317  T & key = const_cast<T &>(it->first);
318 
319  storeHelper(stream, key, context);
320 
321  storeHelper(stream, it->second, context);
322  }
323 }
324 
325 // Specializations (defined in .C)
326 template <>
327 void dataStore(std::ostream & stream, Real & v, void * /*context*/);
328 template <>
329 void dataStore(std::ostream & stream, std::string & v, void * /*context*/);
330 template <>
331 void dataStore(std::ostream & stream, ColumnMajorMatrix & v, void * /*context*/);
332 template <>
333 void dataStore(std::ostream & stream, const Elem *& e, void * context);
334 template <>
335 void dataStore(std::ostream & stream, const Node *& n, void * context);
336 template <>
337 void dataStore(std::ostream & stream, Elem *& e, void * context);
338 template <>
339 void dataStore(std::ostream & stream, Node *& n, void * context);
340 template <>
341 void dataStore(std::ostream & stream, std::stringstream & s, void * context);
342 template <>
343 void dataStore(std::ostream & stream, std::stringstream *& s, void * context);
344 template <>
345 void dataStore(std::ostream & stream, DualReal & dn, void * context);
346 
347 template <std::size_t N>
348 inline void
349 dataStore(std::ostream & stream, DualReal (&dn)[N], void * context)
350 {
351  for (std::size_t i = 0; i < N; ++i)
352  dataStore(stream, dn[i], context);
353 }
354 
355 template <typename T>
356 void
357 dataStore(std::ostream & stream, NumericVector<T> & v, void * context)
358 {
359  v.close();
360 
361  numeric_index_type size = v.local_size();
362 
363  for (numeric_index_type i = v.first_local_index(); i < v.first_local_index() + size; i++)
364  {
365  T r = v(i);
366  dataStore(stream, r, context);
367  }
368 }
369 
370 template <typename T>
371 void
372 dataStore(std::ostream & stream, DenseVector<T> & v, void * context)
373 {
374  unsigned int m = v.size();
375  stream.write((char *)&m, sizeof(m));
376  for (unsigned int i = 0; i < v.size(); i++)
377  {
378  T r = v(i);
379  dataStore(stream, r, context);
380  }
381 }
382 
383 template <typename T>
384 void dataStore(std::ostream & stream, TensorValue<T> & v, void * context);
385 
386 template <typename T>
387 void dataStore(std::ostream & stream, DenseMatrix<T> & v, void * context);
388 
389 template <typename T>
390 void dataStore(std::ostream & stream, VectorValue<T> & v, void * context);
391 
392 template <typename T>
393 void
394 dataStore(std::ostream & stream, RankTwoTensorTempl<T> & rtt, void * context)
395 {
396  dataStore(stream, rtt._coords, context);
397 }
398 
399 template <typename T>
400 void
401 dataStore(std::ostream & stream, RankThreeTensorTempl<T> & rtt, void * context)
402 {
403  dataStore(stream, rtt._vals, context);
404 }
405 
406 template <typename T>
407 void
408 dataStore(std::ostream & stream, RankFourTensorTempl<T> & rft, void * context)
409 {
410  dataStore(stream, rft._vals, context);
411 }
412 
413 template <typename T>
414 inline void
415 dataStore(std::ostream & stream, MooseADWrapper<T> & dn_wrapper, void * context)
416 {
417  dataStore(stream, dn_wrapper.value(), context);
418  if (dn_wrapper._dual_number)
419  {
420  unsigned int m = 1;
421  stream.write((char *)&m, sizeof(m));
422  dataStore(stream, *dn_wrapper._dual_number, context);
423  }
424  else
425  {
426  unsigned int m = 0;
427  stream.write((char *)&m, sizeof(m));
428  }
429 }
430 
431 // DO NOT MODIFY THE NEXT LINE - It is used by MOOSEDocs
432 // *************** Global Load Declarations *****************
433 template <typename T>
434 inline void
435 dataLoad(std::istream & stream, T & v, void * /*context*/)
436 {
437  stream.read((char *)&v, sizeof(v));
438 }
439 
440 template <typename T>
441 void
442 dataLoad(std::istream & /*stream*/, T *& /*v*/, void * /*context*/)
443 {
444  mooseError("Attempting to load a raw pointer type: \"",
445  demangle(typeid(T).name()),
446  " *\" as restartable data!\nWrite a custom dataLoad() template specialization!\n\n");
447 }
448 
449 template <typename T, typename U>
450 inline void
451 dataLoad(std::istream & stream, std::pair<T, U> & p, void * context)
452 {
453  loadHelper(stream, p.first, context);
454  loadHelper(stream, p.second, context);
455 }
456 
457 template <typename T>
458 inline void
459 dataLoad(std::istream & stream, std::vector<T> & v, void * context)
460 {
461  // First read the size of the vector
462  unsigned int size = 0;
463  stream.read((char *)&size, sizeof(size));
464 
465  v.resize(size);
466 
467  for (unsigned int i = 0; i < size; i++)
468  loadHelper(stream, v[i], context);
469 }
470 
471 template <typename T>
472 inline void
473 dataLoad(std::istream & stream, std::shared_ptr<T> & v, void * context)
474 {
475  T * tmp = v.get();
476 
477  loadHelper(stream, tmp, context);
478 }
479 
480 template <typename T>
481 inline void
482 dataLoad(std::istream & stream, std::unique_ptr<T> & v, void * context)
483 {
484  T * tmp = v.get();
485 
486  loadHelper(stream, tmp, context);
487 }
488 
489 template <typename T>
490 inline void
491 dataLoad(std::istream & stream, std::set<T> & s, void * context)
492 {
493  // First read the size of the set
494  unsigned int size = 0;
495  stream.read((char *)&size, sizeof(size));
496 
497  for (unsigned int i = 0; i < size; i++)
498  {
499  T data;
500  loadHelper(stream, data, context);
501  s.insert(std::move(data));
502  }
503 }
504 
505 template <typename T>
506 inline void
507 dataLoad(std::istream & stream, std::list<T> & l, void * context)
508 {
509  // First read the size of the set
510  unsigned int size = 0;
511  stream.read((char *)&size, sizeof(size));
512 
513  for (unsigned int i = 0; i < size; i++)
514  {
515  T data;
516  loadHelper(stream, data, context);
517  l.push_back(std::move(data));
518  }
519 }
520 
521 template <typename T, typename U>
522 inline void
523 dataLoad(std::istream & stream, std::map<T, U> & m, void * context)
524 {
525  m.clear();
526 
527  // First read the size of the map
528  unsigned int size = 0;
529  stream.read((char *)&size, sizeof(size));
530 
531  for (unsigned int i = 0; i < size; i++)
532  {
533  T key;
534  loadHelper(stream, key, context);
535 
536  U & value = m[key];
537  loadHelper(stream, value, context);
538  }
539 }
540 
541 template <typename T, typename U>
542 inline void
543 dataLoad(std::istream & stream, std::unordered_map<T, U> & m, void * context)
544 {
545  m.clear();
546 
547  // First read the size of the map
548  unsigned int size = 0;
549  stream.read((char *)&size, sizeof(size));
550 
551  for (unsigned int i = 0; i < size; i++)
552  {
553  T key;
554  loadHelper(stream, key, context);
555 
556  U & value = m[key];
557  loadHelper(stream, value, context);
558  }
559 }
560 
561 template <typename T, typename U>
562 inline void
563 dataLoad(std::istream & stream, HashMap<T, U> & m, void * context)
564 {
565  // First read the size of the map
566  unsigned int size = 0;
567  stream.read((char *)&size, sizeof(size));
568 
569  for (unsigned int i = 0; i < size; i++)
570  {
571  T key;
572  loadHelper(stream, key, context);
573 
574  U & value = m[key];
575  loadHelper(stream, value, context);
576  }
577 }
578 
579 // Specializations (defined in .C)
580 template <>
581 void dataLoad(std::istream & stream, Real & v, void * /*context*/);
582 template <>
583 void dataLoad(std::istream & stream, std::string & v, void * /*context*/);
584 template <>
585 void dataLoad(std::istream & stream, ColumnMajorMatrix & v, void * /*context*/);
586 template <>
587 void dataLoad(std::istream & stream, const Elem *& e, void * context);
588 template <>
589 void dataLoad(std::istream & stream, const Node *& e, void * context);
590 template <>
591 void dataLoad(std::istream & stream, Elem *& e, void * context);
592 template <>
593 void dataLoad(std::istream & stream, Node *& e, void * context);
594 template <>
595 void dataLoad(std::istream & stream, std::stringstream & s, void * context);
596 template <>
597 void dataLoad(std::istream & stream, std::stringstream *& s, void * context);
598 template <>
599 void dataLoad(std::istream & stream, DualReal & dn, void * context);
600 
601 template <typename T>
602 void
603 dataLoad(std::istream & stream, NumericVector<T> & v, void * context)
604 {
605  numeric_index_type size = v.local_size();
606  for (numeric_index_type i = v.first_local_index(); i < v.first_local_index() + size; i++)
607  {
608  T r = 0;
609  dataLoad(stream, r, context);
610  v.set(i, r);
611  }
612  v.close();
613 }
614 
615 template <typename T>
616 void
617 dataLoad(std::istream & stream, DenseVector<T> & v, void * context)
618 {
619  unsigned int n = 0;
620  stream.read((char *)&n, sizeof(n));
621  v.resize(n);
622  for (unsigned int i = 0; i < n; i++)
623  {
624  T r = 0;
625  dataLoad(stream, r, context);
626  v(i) = r;
627  }
628 }
629 
630 template <typename T>
631 void dataLoad(std::istream & stream, TensorValue<T> & v, void * context);
632 
633 template <typename T>
634 void dataLoad(std::istream & stream, DenseMatrix<T> & v, void * context);
635 
636 template <typename T>
637 void dataLoad(std::istream & stream, VectorValue<T> & v, void * context);
638 
639 template <typename T>
640 void
641 dataLoad(std::istream & stream, RankTwoTensorTempl<T> & rtt, void * context)
642 {
643  dataLoad(stream, rtt._coords, context);
644 }
645 
646 template <typename T>
647 void
648 dataLoad(std::istream & stream, RankThreeTensorTempl<T> & rtt, void * context)
649 {
650  dataLoad(stream, rtt._vals, context);
651 }
652 
653 template <typename T>
654 void
655 dataLoad(std::istream & stream, RankFourTensorTempl<T> & rft, void * context)
656 {
657  dataLoad(stream, rft._vals, context);
658 }
659 
660 template <typename T>
661 inline void
662 dataLoad(std::istream & stream, MooseADWrapper<T> & dn_wrapper, void * context)
663 {
664  dataLoad(stream, dn_wrapper.value(), context);
665  unsigned int n = 0;
666  stream.read((char *)&n, sizeof(n));
667  if (n)
668  {
669  dn_wrapper._dual_number = libmesh_make_unique<typename MooseADWrapper<T>::DNType>();
670  dataLoad(stream, *dn_wrapper._dual_number, context);
671  }
672 }
673 
674 // Scalar Helper Function
675 template <typename P>
676 inline void
677 storeHelper(std::ostream & stream, P & data, void * context)
678 {
679  dataStore(stream, data, context);
680 }
681 
682 // Vector Helper Function
683 template <typename P>
684 inline void
685 storeHelper(std::ostream & stream, std::vector<P> & data, void * context)
686 {
687  dataStore(stream, data, context);
688 }
689 
690 // std::shared_ptr Helper Function
691 template <typename P>
692 inline void
693 storeHelper(std::ostream & stream, std::shared_ptr<P> & data, void * context)
694 {
695  dataStore(stream, data, context);
696 }
697 
698 // std::unique Helper Function
699 template <typename P>
700 inline void
701 storeHelper(std::ostream & stream, std::unique_ptr<P> & data, void * context)
702 {
703  dataStore(stream, data, context);
704 }
705 
706 // Set Helper Function
707 template <typename P>
708 inline void
709 storeHelper(std::ostream & stream, std::set<P> & data, void * context)
710 {
711  dataStore(stream, data, context);
712 }
713 
714 // Map Helper Function
715 template <typename P, typename Q>
716 inline void
717 storeHelper(std::ostream & stream, std::map<P, Q> & data, void * context)
718 {
719  dataStore(stream, data, context);
720 }
721 
722 // Unordered_map Helper Function
723 template <typename P, typename Q>
724 inline void
725 storeHelper(std::ostream & stream, std::unordered_map<P, Q> & data, void * context)
726 {
727  dataStore(stream, data, context);
728 }
729 
730 // HashMap Helper Function
731 template <typename P, typename Q>
732 inline void
733 storeHelper(std::ostream & stream, HashMap<P, Q> & data, void * context)
734 {
735  dataStore(stream, data, context);
736 }
737 
738 // Scalar Helper Function
739 template <typename P>
740 inline void
741 loadHelper(std::istream & stream, P & data, void * context)
742 {
743  dataLoad(stream, data, context);
744 }
745 
746 // Vector Helper Function
747 template <typename P>
748 inline void
749 loadHelper(std::istream & stream, std::vector<P> & data, void * context)
750 {
751  dataLoad(stream, data, context);
752 }
753 
754 // std::shared_ptr Helper Function
755 template <typename P>
756 inline void
757 loadHelper(std::istream & stream, std::shared_ptr<P> & data, void * context)
758 {
759  dataLoad(stream, data, context);
760 }
761 
762 // Unique Pointer Helper Function
763 template <typename P>
764 inline void
765 loadHelper(std::istream & stream, std::unique_ptr<P> & data, void * context)
766 {
767  dataLoad(stream, data, context);
768 }
769 
770 // Set Helper Function
771 template <typename P>
772 inline void
773 loadHelper(std::istream & stream, std::set<P> & data, void * context)
774 {
775  dataLoad(stream, data, context);
776 }
777 
778 // Map Helper Function
779 template <typename P, typename Q>
780 inline void
781 loadHelper(std::istream & stream, std::map<P, Q> & data, void * context)
782 {
783  dataLoad(stream, data, context);
784 }
785 
786 // Unordered_map Helper Function
787 template <typename P, typename Q>
788 inline void
789 loadHelper(std::istream & stream, std::unordered_map<P, Q> & data, void * context)
790 {
791  dataLoad(stream, data, context);
792 }
793 
794 // HashMap Helper Function
795 template <typename P, typename Q>
796 inline void
797 loadHelper(std::istream & stream, HashMap<P, Q> & data, void * context)
798 {
799  dataLoad(stream, data, context);
800 }
801 
802 // Specializations for Backup type
803 template <>
804 inline void
805 dataStore(std::ostream & stream, Backup *& backup, void * context)
806 {
807  dataStore(stream, backup->_system_data, context);
808 
809  for (unsigned int i = 0; i < backup->_restartable_data.size(); i++)
810  dataStore(stream, backup->_restartable_data[i], context);
811 }
812 
813 template <>
814 inline void
815 dataLoad(std::istream & stream, Backup *& backup, void * context)
816 {
817  dataLoad(stream, backup->_system_data, context);
818 
819  for (unsigned int i = 0; i < backup->_restartable_data.size(); i++)
820  dataLoad(stream, backup->_restartable_data[i], context);
821 }
822 
823 void dataLoad(std::istream & stream, Point & p, void * context);
824 
831 namespace libMesh
832 {
833 namespace Parallel
834 {
835 template <typename T>
836 class Packing<std::basic_string<T>>
837 {
838 public:
839  static const unsigned int size_bytes = 4;
840 
841  typedef T buffer_type;
842 
843  static unsigned int get_string_len(typename std::vector<T>::const_iterator in)
844  {
845  unsigned int string_len = reinterpret_cast<const unsigned char &>(in[size_bytes - 1]);
846  for (signed int i = size_bytes - 2; i >= 0; --i)
847  {
848  string_len *= 256;
849  string_len += reinterpret_cast<const unsigned char &>(in[i]);
850  }
851  return string_len;
852  }
853 
854  static unsigned int packed_size(typename std::vector<T>::const_iterator in)
855  {
856  return get_string_len(in) + size_bytes;
857  }
858 
859  static unsigned int packable_size(const std::basic_string<T> & s, const void *)
860  {
861  return s.size() + size_bytes;
862  }
863 
864  template <typename Iter>
865  static void pack(const std::basic_string<T> & b, Iter data_out, const void *)
866  {
867  unsigned int string_len = b.size();
868  for (unsigned int i = 0; i != size_bytes; ++i)
869  {
870  *data_out++ = (string_len % 256);
871  string_len /= 256;
872  }
873 
874  std::copy(b.begin(), b.end(), data_out);
875  }
876 
877  static std::basic_string<T> unpack(typename std::vector<T>::const_iterator in, void *)
878  {
879  unsigned int string_len = get_string_len(in);
880 
881  std::ostringstream oss;
882  for (unsigned int i = 0; i < string_len; ++i)
883  oss << reinterpret_cast<const unsigned char &>(in[i + size_bytes]);
884 
885  in += size_bytes + string_len;
886 
887  return oss.str();
888  }
889 };
890 
891 } // namespace Parallel
892 
893 } // namespace libMesh
894 
RankFourTensorTempl is designed to handle any N-dimensional fourth order tensor, C.
Definition: MooseTypes.h:115
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.
PetscInt N
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application...
Definition: MooseError.h:207
static std::basic_string< T > unpack(typename std::vector< T >::const_iterator in, void *)
Definition: DataIO.h:877
static unsigned int packable_size(const std::basic_string< T > &s, const void *)
Definition: DataIO.h:859
DualNumber< Real, NumberArray< AD_MAX_DOFS_PER_ELEM, Real > > DualReal
Definition: DualReal.h:29
The following methods are specializations for using the libMesh::Parallel::packed_range_* routines fo...
static PetscErrorCode Vec x
std::stringstream _system_data
Stream for holding binary blob data for the simulation.
Definition: Backup.h:28
RankThreeTensor is designed to handle any N-dimensional third order tensor, r.
void storeHelper(std::ostream &stream, P &data, void *context)
Scalar helper routine.
Definition: DataIO.h:677
PetscInt m
static unsigned int packed_size(typename std::vector< T >::const_iterator in)
Definition: DataIO.h:854
T _vals[N3]
The values of the rank-three tensor stored by index=((i * LIBMESH_DIM + j) * LIBMESH_DIM + k) ...
const T & value() const
Returns the value for any case where a MaterialProperty is requested as a regular (non-AD) property...
T _vals[N4]
The values of the rank-four tensor stored by index=(((i * LIBMESH_DIM + j) * LIBMESH_DIM + k) * LIBME...
void dataStore(std::ostream &stream, T &v, void *)
Definition: DataIO.h:161
static void pack(const std::basic_string< T > &b, Iter data_out, const void *)
Definition: DataIO.h:865
Helper class to hold streams for Backup and Restore operations.
Definition: Backup.h:20
RankTwoTensorTempl is designed to handle the Stress or Strain Tensor for a fully anisotropic material...
Definition: MooseTypes.h:111
PetscInt n
std::vector< std::unique_ptr< std::stringstream > > _restartable_data
Vector of streams for holding individual thread data for the simulation.
Definition: Backup.h:33
static unsigned int get_string_len(typename std::vector< T >::const_iterator in)
Definition: DataIO.h:843
ColumnMajorMatrixTempl< Real > ColumnMajorMatrix
Definition: DataIO.h:39
void dataLoad(std::istream &stream, T &v, void *)
Definition: DataIO.h:435
void loadHelper(std::istream &stream, P &data, void *context)
Scalar helper routine.
Definition: DataIO.h:741
std::unique_ptr< T > _dual_number