https://mooseframework.inl.gov
Loading...
Searching...
No Matches
Functions
DataIO.C File Reference

Go to the source code of this file.

Functions

template<>
void dataStore< mt_state > (std::ostream &stream, mt_state &foo, void *ctx)
 
template<>
void dataStore (std::ostream &stream, std::string &v, void *)
 
template<>
void dataStore (std::ostream &stream, VariableName &v, void *context)
 
template<>
void dataStore (std::ostream &stream, UserObjectName &v, void *context)
 
template<>
void dataStore (std::ostream &stream, FEType &v, void *context)
 
template<>
void dataStore (std::ostream &stream, std::vector< bool > &v, void *context)
 
template<>
void dataStore (std::ostream &stream, RankTwoTensor &rtt, void *context)
 
template<>
void dataStore (std::ostream &stream, RankThreeTensor &rtht, void *context)
 
template<>
void dataStore (std::ostream &stream, RankFourTensor &rft, void *context)
 
template<>
void dataStore (std::ostream &stream, ADReal &dn, void *context)
 
template<>
void dataStore (std::ostream &stream, const Elem *&e, void *context)
 
template<>
void dataStore (std::ostream &stream, const Node *&n, void *context)
 
template<>
void dataStore (std::ostream &stream, Elem *&e, void *context)
 
template<>
void dataStore (std::ostream &stream, Node *&n, void *context)
 
template<>
void dataStore (std::ostream &stream, std::stringstream &s, void *)
 
template<>
void dataStore (std::ostream &stream, torch::Tensor &t, void *context)
 
template<typename T >
void dataStore (std::ostream &stream, TensorValue< T > &v, void *context)
 
template void dataStore (std::ostream &stream, TensorValue< Real > &v, void *context)
 
template void dataStore (std::ostream &stream, TensorValue< ADReal > &v, void *context)
 
template<typename T >
void dataStore (std::ostream &stream, DenseMatrix< T > &v, void *context)
 
template void dataStore (std::ostream &stream, DenseMatrix< Real > &v, void *context)
 
template void dataStore (std::ostream &stream, DenseMatrix< ADReal > &v, void *context)
 
template<typename T >
void dataStore (std::ostream &stream, VectorValue< T > &v, void *context)
 
template void dataStore (std::ostream &stream, VectorValue< Real > &v, void *context)
 
template void dataStore (std::ostream &stream, VectorValue< ADReal > &v, void *context)
 
template<>
void dataStore (std::ostream &stream, const Point &p, void *context)
 
void dataStore (std::ostream &stream, libMesh::BoundingBox &bbox, void *context)
 
template<>
void dataStore (std::ostream &stream, Point &p, void *context)
 
template<>
void dataStore (std::ostream &stream, libMesh::Parameters &p, void *context)
 
template<>
void dataStore (std::ostream &stream, std::unique_ptr< libMesh::NumericVector< Number > > &v, void *context)
 
template<>
void dataLoad< mt_state > (std::istream &stream, mt_state &foo, void *ctx)
 
template<>
void dataLoad (std::istream &stream, std::string &v, void *)
 
template<>
void dataLoad (std::istream &stream, VariableName &v, void *context)
 
template<>
void dataLoad (std::istream &stream, UserObjectName &v, void *context)
 
template<>
void dataLoad (std::istream &stream, FEType &v, void *context)
 
template<>
void dataLoad (std::istream &stream, std::vector< bool > &v, void *context)
 
template<>
void dataLoad (std::istream &stream, ADReal &dn, void *context)
 
template<>
void dataLoad (std::istream &stream, const Elem *&e, void *context)
 
template<>
void dataLoad (std::istream &stream, const Node *&n, void *context)
 
template<>
void dataLoad (std::istream &stream, Elem *&e, void *context)
 
template<>
void dataLoad (std::istream &stream, Node *&n, void *context)
 
template<>
void dataLoad (std::istream &stream, std::stringstream &s, void *)
 
template<>
void dataLoad (std::istream &stream, torch::Tensor &t, void *context)
 
template<typename T >
void dataLoad (std::istream &stream, TensorValue< T > &v, void *context)
 
template void dataLoad (std::istream &stream, TensorValue< Real > &v, void *context)
 
template void dataLoad (std::istream &stream, TensorValue< ADReal > &v, void *context)
 
template<typename T >
void dataLoad (std::istream &stream, DenseMatrix< T > &v, void *context)
 
template void dataLoad (std::istream &stream, DenseMatrix< Real > &v, void *context)
 
template void dataLoad (std::istream &stream, DenseMatrix< ADReal > &v, void *context)
 
template<typename T >
void dataLoad (std::istream &stream, VectorValue< T > &v, void *context)
 
template void dataLoad (std::istream &stream, VectorValue< Real > &v, void *context)
 
template void dataLoad (std::istream &stream, VectorValue< ADReal > &v, void *context)
 
template<>
void dataLoad (std::istream &stream, Point &p, void *context)
 
void dataLoad (std::istream &stream, libMesh::BoundingBox &bbox, void *context)
 
template<>
void dataLoad (std::istream &stream, libMesh::Parameters &p, void *context)
 
template<>
void dataLoad (std::istream &stream, std::unique_ptr< libMesh::NumericVector< Number > > &v, void *context)
 
template<>
void dataLoad (std::istream &stream, Vec &v, void *context)
 
template<>
void dataStore (std::ostream &stream, Vec &v, void *context)
 

Function Documentation

◆ dataLoad() [1/26]

template<>
void dataLoad ( std::istream &  stream,
ADReal &  dn,
void *  context 
)

Definition at line 488 of file DataIO.C.

489{
490 dataLoad(stream, dn.value(), context);
491
492 if (ADReal::do_derivatives)
493 {
494 auto & derivatives = dn.derivatives();
495 std::size_t size = 0;
496 stream.read((char *)&size, sizeof(size));
497 derivatives.resize(size);
498
499 for (MooseIndex(derivatives) i = 0; i < derivatives.size(); ++i)
500 {
501 dataLoad(stream, derivatives.raw_index(i), context);
502 dataLoad(stream, derivatives.raw_at(i), context);
503 }
504 }
505}
void dataLoad(std::istream &stream, std::string &v, void *)
Definition DataIO.C:420

◆ dataLoad() [2/26]

template<>
void dataLoad ( std::istream &  stream,
const Elem *&  e,
void *  context 
)

Definition at line 509 of file DataIO.C.

510{
511 if (!context)
512 mooseError("Can only load Elem objects using a MooseMesh context!");
513
514 MooseMesh * mesh = static_cast<MooseMesh *>(context);
515
516 // TODO: Write out the unique ID of this element
518
519 dataLoad(stream, id, context);
520
522 e = mesh->elemPtr(id);
523 else
524 e = NULL;
525}
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application.
Definition MooseError.h:311
MooseMesh wraps a libMesh::Mesh object and enhances its capabilities by caching additional data and s...
Definition MooseMesh.h:95
static constexpr dof_id_type invalid_id
MeshBase & mesh
uint8_t dof_id_type

◆ dataLoad() [3/26]

template<>
void dataLoad ( std::istream &  stream,
const Node *&  n,
void *  context 
)

Definition at line 529 of file DataIO.C.

530{
531 if (!context)
532 mooseError("Can only load Node objects using a MooseMesh context!");
533
534 MooseMesh * mesh = static_cast<MooseMesh *>(context);
535
536 // TODO: Write out the unique ID of this nodeent
538
539 dataLoad(stream, id, context);
540
542 n = mesh->nodePtr(id);
543 else
544 n = NULL;
545}

◆ dataLoad() [4/26]

template void dataLoad ( std::istream &  stream,
DenseMatrix< ADReal > &  v,
void *  context 
)

◆ dataLoad() [5/26]

template void dataLoad ( std::istream &  stream,
DenseMatrix< Real > &  v,
void *  context 
)

◆ dataLoad() [6/26]

template<typename T >
void dataLoad ( std::istream &  stream,
DenseMatrix< T > &  v,
void *  context 
)

Definition at line 658 of file DataIO.C.

659{
660 unsigned int m = 0, n = 0;
661 stream.read((char *)&m, sizeof(m));
662 stream.read((char *)&n, sizeof(n));
663 v.resize(m, n);
664 for (unsigned int i = 0; i < m; i++)
665 for (unsigned int j = 0; j < n; j++)
666 {
667 T r = 0;
668 dataLoad(stream, r, context);
669 v(i, j) = r;
670 }
671}
void resize(const unsigned int new_m, const unsigned int new_n)

◆ dataLoad() [7/26]

template<>
void dataLoad ( std::istream &  stream,
Elem *&  e,
void *  context 
)

Definition at line 549 of file DataIO.C.

550{
551 if (!context)
552 mooseError("Can only load Elem objects using a MooseMesh context!");
553
554 MooseMesh * mesh = static_cast<MooseMesh *>(context);
555
556 // TODO: Write out the unique ID of this element
558
559 dataLoad(stream, id, context);
560
562 e = mesh->elemPtr(id);
563 else
564 e = NULL;
565}

◆ dataLoad() [8/26]

template<>
void dataLoad ( std::istream &  stream,
FEType &  v,
void *  context 
)

Definition at line 451 of file DataIO.C.

452{
453 int order = 0;
454 dataLoad(stream, order, context);
455 v.order = order;
456
457 dataLoad(stream, v.family, context);
458
459#ifdef LIBMESH_ENABLE_INFINITE_ELEMENTS
460 int radial_order = 0;
461 dataLoad(stream, radial_order, context);
462 v.radial_order = radial_order;
463
464 dataLoad(stream, v.radial_family, context);
465 dataLoad(stream, v.inf_map, context);
466#endif
467
468 dataLoad(stream, v.p_refinement, context);
469}

◆ dataLoad() [9/26]

void dataLoad ( std::istream &  stream,
libMesh::BoundingBox &  bbox,
void *  context 
)

Definition at line 702 of file DataIO.C.

703{
704 dataLoad(stream, cast_ref<std::pair<Point, Point> &>(bbox), context);
705}

◆ dataLoad() [10/26]

template<>
void dataLoad ( std::istream &  stream,
libMesh::Parameters &  p,
void *  context 
)

Definition at line 709 of file DataIO.C.

710{
711 p.clear();
712
713 // First read the size of the map
714 unsigned int size = 0;
715 stream.read((char *)&size, sizeof(size));
716
717 for (unsigned int i = 0; i < size; i++)
718 {
719 std::string key, type;
720 dataLoad(stream, key, context);
721 dataLoad(stream, type, context);
722
723#define loadscalar(ptype) \
724 else if (type == demangle(typeid(ptype).name())) do \
725 { \
726 ptype & value = p.set<ptype>(key); \
727 dataLoad(stream, value, context); \
728 } \
729 while (0)
730
731 if (false)
732 ;
733 loadscalar(Real);
734 loadscalar(short);
735 loadscalar(int);
736 loadscalar(long);
737 loadscalar(unsigned short);
738 loadscalar(unsigned int);
739 loadscalar(unsigned long);
740
741#undef loadscalar
742 }
743}
virtual void clear()

◆ dataLoad() [11/26]

template<>
void dataLoad ( std::istream &  stream,
Node *&  n,
void *  context 
)

Definition at line 569 of file DataIO.C.

570{
571 if (!context)
572 mooseError("Can only load Node objects using a MooseMesh context!");
573
574 MooseMesh * mesh = static_cast<MooseMesh *>(context);
575
576 // TODO: Write out the unique ID of this nodeent
578
579 dataLoad(stream, id, context);
580
582 n = mesh->nodePtr(id);
583 else
584 n = NULL;
585}

◆ dataLoad() [12/26]

template<>
void dataLoad ( std::istream &  stream,
Point &  p,
void *  context 
)

Definition at line 695 of file DataIO.C.

696{
697 for (const auto i : make_range(Moose::dim))
698 dataLoad(stream, p(i), context);
699}
unsigned int dim
MOOSE now contains C++17 code, so give a reasonable error message stating what the user can do to add...
IntRange< T > make_range(T beg, T end)

◆ dataLoad() [13/26]

template<>
void dataLoad ( std::istream &  stream,
std::string &  v,
void *   
)

Definition at line 420 of file DataIO.C.

421{
422 // Read the size of the string
423 unsigned int size = 0;
424 stream.read((char *)&size, sizeof(size));
425
426 // Resize the string data
427 v.resize(size);
428
429 // Read the string
430 stream.read(&v[0], sizeof(char) * size);
431}

Referenced by dataLoad(), dataLoad(), dataLoad(), dataLoad(), dataLoad(), dataLoad(), dataLoad(), dataLoad(), dataLoad(), dataLoad(), dataLoad(), dataLoad(), dataLoad(), dataLoad(), dataLoad(), dataLoad(), dataLoad(), dataLoad(), and dataLoad< mt_state >().

◆ dataLoad() [14/26]

template<>
void dataLoad ( std::istream &  stream,
std::stringstream &  s,
void *  context 
)

Definition at line 589 of file DataIO.C.

590{
591 size_t s_size = 0;
592 stream.read((char *)&s_size, sizeof(s_size));
593
594 std::unique_ptr<char[]> s_s = std::make_unique<char[]>(s_size);
595 stream.read(s_s.get(), s_size);
596
597 // Clear the stringstream before loading new data into it.
598 s.str(std::string());
599 s.write(s_s.get(), s_size);
600}

◆ dataLoad() [15/26]

template<>
void dataLoad ( std::istream &  stream,
std::unique_ptr< libMesh::NumericVector< Number > > &  v,
void *  context 
)

Definition at line 747 of file DataIO.C.

748{
749 bool have_vector;
750 dataLoad(stream, have_vector, context);
751
752 if (!have_vector)
753 return;
754
755 mooseAssert(context, "Needs a context of the communicator");
756 const auto & comm = *static_cast<const libMesh::Parallel::Communicator *>(context);
757 if (v)
758 mooseAssert(&comm == &v->comm(), "Inconsistent communicator");
759
760 // Load the communicator size for consistency checks
761 unsigned int comm_size;
762 dataLoad(stream, comm_size, nullptr);
763 mooseAssert(comm.size() == comm_size, "Inconsistent communicator size");
764
765 // Load the solver package to build the vector
766 int solver_package_int;
767 dataLoad(stream, solver_package_int, nullptr);
768 libMesh::SolverPackage solver_package = static_cast<libMesh::SolverPackage>(solver_package_int);
769
770 // Load the sizes
771 dof_id_type size, local_size;
772 dataLoad(stream, size, nullptr);
773 dataLoad(stream, local_size, nullptr);
774
775 // Construct the vector given the type, only if we need to. v could be non-null here
776 // if we're advancing back and loading a backup
777 if (!v)
778 {
779 v = NumericVector<Number>::build(comm, solver_package);
780 v->init(size, local_size);
781 }
782 else
783 mooseAssert(v->type() != GHOSTED, "Cannot be ghosted");
784
785 // Make sure that the sizes are consistent; this will happen if we're calling this
786 // on a vector that has already been loaded previously
787 mooseAssert(v->size() == size, "Inconsistent size");
788 mooseAssert(v->local_size() == local_size, "Inconsistent local size");
789
790 // Now that we have an initialized vector, fill the entries
791 dataLoad(stream, *v, nullptr);
792}

◆ dataLoad() [16/26]

template<>
void dataLoad ( std::istream &  stream,
std::vector< bool > &  v,
void *  context 
)

Definition at line 473 of file DataIO.C.

474{
475 std::size_t size = 0;
476 dataLoad(stream, size, nullptr);
477 v.resize(size);
478 for (std::size_t i = 0; i < size; i++)
479 {
480 bool b;
481 dataLoad(stream, b, context);
482 v[i] = b;
483 }
484}

◆ dataLoad() [17/26]

template void dataLoad ( std::istream &  stream,
TensorValue< ADReal > &  v,
void *  context 
)

◆ dataLoad() [18/26]

template void dataLoad ( std::istream &  stream,
TensorValue< Real > &  v,
void *  context 
)

◆ dataLoad() [19/26]

template<typename T >
void dataLoad ( std::istream &  stream,
TensorValue< T > &  v,
void *  context 
)

Definition at line 640 of file DataIO.C.

641{
642 // Obviously if someone loads data with different LIBMESH_DIM than was used for saving them, it
643 // won't work.
644 for (const auto i : make_range(Moose::dim))
645 for (const auto j : make_range(Moose::dim))
646 {
647 T r = 0;
648 dataLoad(stream, r, context);
649 v(i, j) = r;
650 }
651}
for(PetscInt i=0;i< nvars;++i)

◆ dataLoad() [20/26]

template<>
void dataLoad ( std::istream &  stream,
torch::Tensor &  t,
void *  context 
)

Definition at line 605 of file DataIO.C.

606{
607 bool defined = false;
608 dataLoad(stream, defined, nullptr);
609 if (!defined)
610 {
611 t = torch::Tensor(); // undefined tensor
612 return;
613 }
614
615 unsigned int rank = 0;
616 dataLoad(stream, rank, nullptr);
617
618 std::vector<int64_t> sizes(rank);
619 for (unsigned int dim = 0; dim < rank; ++dim)
620 {
621 unsigned int size = 0;
622 dataLoad(stream, size, nullptr);
623 sizes[dim] = size;
624 }
625
626 t = torch::empty(sizes, at::kDouble);
627 auto flattened = t.reshape({t.numel()});
628 auto t_accessor = flattened.accessor<Real, 1>();
629 for (int64_t i = 0; i < flattened.numel(); ++i)
630 {
631 Real r = 0;
632 dataLoad(stream, r, context);
633 t_accessor[i] = r;
634 }
635}
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real

◆ dataLoad() [21/26]

template<>
void dataLoad ( std::istream &  stream,
UserObjectName &  v,
void *  context 
)

Definition at line 443 of file DataIO.C.

444{
445 auto & name = cast_ref<std::string &>(v);
446 dataLoad(stream, name, context);
447}
std::string name(const ElemQuality q)

◆ dataLoad() [22/26]

template<>
void dataLoad ( std::istream &  stream,
VariableName &  v,
void *  context 
)

Definition at line 435 of file DataIO.C.

436{
437 auto & name = cast_ref<std::string &>(v);
438 dataLoad(stream, name, context);
439}

◆ dataLoad() [23/26]

template<>
void dataLoad ( std::istream &  stream,
Vec &  v,
void *  context 
)

Definition at line 796 of file DataIO.C.

797{
798 PetscInt local_size;
799 LibmeshPetscCallA(PETSC_COMM_WORLD, VecGetLocalSize(v, &local_size));
800 PetscScalar * array;
801 LibmeshPetscCallA(PETSC_COMM_WORLD, VecGetArray(v, &array));
802 for (PetscInt i = 0; i < local_size; i++)
803 dataLoad(stream, array[i], context);
804
805 LibmeshPetscCallA(PETSC_COMM_WORLD, VecRestoreArray(v, &array));
806}

◆ dataLoad() [24/26]

template void dataLoad ( std::istream &  stream,
VectorValue< ADReal > &  v,
void *  context 
)

◆ dataLoad() [25/26]

template void dataLoad ( std::istream &  stream,
VectorValue< Real > &  v,
void *  context 
)

◆ dataLoad() [26/26]

template<typename T >
void dataLoad ( std::istream &  stream,
VectorValue< T > &  v,
void *  context 
)

Definition at line 678 of file DataIO.C.

679{
680 // Obviously if someone loads data with different LIBMESH_DIM than was used for saving them, it
681 // won't work.
682 for (const auto i : make_range(Moose::dim))
683 {
684 T r = 0;
685 dataLoad(stream, r, context);
686 v(i) = r;
687 }
688}

◆ dataLoad< mt_state >()

template<>
void dataLoad< mt_state > ( std::istream &  stream,
mt_state &  foo,
void *  ctx 
)

Definition at line 410 of file DataIO.C.

412{
413 dataLoad(stream, foo.statevec, ctx);
414 dataLoad(stream, foo.stateptr, ctx);
415 dataLoad(stream, foo.initialized, ctx);
416}

◆ dataStore() [1/30]

template<>
void dataStore ( std::ostream &  stream,
ADReal &  dn,
void *  context 
)

Definition at line 123 of file DataIO.C.

124{
125 dataStore(stream, dn.value(), context);
126
127 if (ADReal::do_derivatives)
128 {
129 auto & derivatives = dn.derivatives();
130 std::size_t size = derivatives.size();
131 dataStore(stream, size, context);
132 for (MooseIndex(size) i = 0; i < size; ++i)
133 {
134 dataStore(stream, derivatives.raw_index(i), context);
135 dataStore(stream, derivatives.raw_at(i), context);
136 }
137 }
138}
void dataStore(std::ostream &stream, std::string &v, void *)
Definition DataIO.C:39

◆ dataStore() [2/30]

template<>
void dataStore ( std::ostream &  stream,
const Elem *&  e,
void *  context 
)

Definition at line 142 of file DataIO.C.

143{
144 // TODO: Write out the unique ID of this elem
146
147 if (e)
148 {
149 id = e->id();
151 mooseError("Can't output Elems with invalid ids!");
152 }
153
154 dataStore(stream, id, context);
155}

◆ dataStore() [3/30]

template<>
void dataStore ( std::ostream &  stream,
const Node *&  n,
void *  context 
)

Definition at line 159 of file DataIO.C.

160{
161 // TODO: Write out the unique ID of this node
163
164 if (n)
165 {
166 id = n->id();
168 mooseError("Can't output Nodes with invalid ids!");
169 }
170
171 dataStore(stream, id, context);
172}

◆ dataStore() [4/30]

template<>
void dataStore ( std::ostream &  stream,
const Point &  p,
void *  context 
)

Definition at line 305 of file DataIO.C.

306{
307 for (const auto i : make_range(Moose::dim))
308 dataStore(stream, p(i), context);
309}

◆ dataStore() [5/30]

template void dataStore ( std::ostream &  stream,
DenseMatrix< ADReal > &  v,
void *  context 
)

◆ dataStore() [6/30]

template void dataStore ( std::ostream &  stream,
DenseMatrix< Real > &  v,
void *  context 
)

◆ dataStore() [7/30]

template<typename T >
void dataStore ( std::ostream &  stream,
DenseMatrix< T > &  v,
void *  context 
)

Definition at line 270 of file DataIO.C.

271{
272 unsigned int m = v.m();
273 unsigned int n = v.n();
274 stream.write((char *)&m, sizeof(m));
275 stream.write((char *)&n, sizeof(n));
276 for (unsigned int i = 0; i < m; i++)
277 for (unsigned int j = 0; j < n; j++)
278 {
279 T r = v(i, j);
280 dataStore(stream, r, context);
281 }
282}
unsigned int n() const
unsigned int m() const

◆ dataStore() [8/30]

template<>
void dataStore ( std::ostream &  stream,
Elem *&  e,
void *  context 
)

Definition at line 176 of file DataIO.C.

177{
178 // TODO: Write out the unique ID of this elem
180
181 if (e)
182 {
183 id = e->id();
185 mooseError("Can't output Elems with invalid ids!");
186 }
187
188 dataStore(stream, id, context);
189}

◆ dataStore() [9/30]

template<>
void dataStore ( std::ostream &  stream,
FEType &  v,
void *  context 
)

Definition at line 67 of file DataIO.C.

68{
69 auto order = v.order.get_order();
70 dataStore(stream, order, context);
71
72 auto family = v.family;
73 dataStore(stream, family, context);
74
75#ifdef LIBMESH_ENABLE_INFINITE_ELEMENTS
76 auto radial_order = v.radial_order.get_order();
77 dataStore(stream, radial_order, context);
78
79 auto radial_family = v.radial_family;
80 dataStore(stream, radial_family, context);
81
82 auto inf_map = v.inf_map;
83 dataStore(stream, inf_map, context);
84#endif
85
86 auto p_refinement = v.p_refinement;
87 dataStore(stream, p_refinement, context);
88}

◆ dataStore() [10/30]

void dataStore ( std::ostream &  stream,
libMesh::BoundingBox &  bbox,
void *  context 
)

Definition at line 312 of file DataIO.C.

313{
314 dataStore(stream, cast_ref<std::pair<Point, Point> &>(bbox), context);
315}

◆ dataStore() [11/30]

template<>
void dataStore ( std::ostream &  stream,
libMesh::Parameters &  p,
void *  context 
)

Definition at line 326 of file DataIO.C.

327{
328 // First store the size of the map
329 unsigned int size = p.n_parameters();
330 stream.write((char *)&size, sizeof(size));
331
332 auto it = p.begin();
333 auto end = p.end();
334
335 for (; it != end; ++it)
336 {
337 auto & key = const_cast<std::string &>(it->first);
338 auto type = it->second->type();
339
340 dataStore(stream, key, context);
341 dataStore(stream, type, context);
342
343#define storescalar(ptype) \
344 else if (it->second->type() == demangle(typeid(ptype).name())) dataStore( \
345 stream, \
346 (dynamic_cast<libMesh::Parameters::Parameter<ptype> *>(MooseUtils::get(it->second)))->get(), \
347 context)
348
349 if (false)
350 ;
351 storescalar(Real);
352 storescalar(short);
353 storescalar(int);
354 storescalar(long);
355 storescalar(unsigned short);
356 storescalar(unsigned int);
357 storescalar(unsigned long);
358
359#undef storescalar
360 }
361}
std::size_t n_parameters() const

◆ dataStore() [12/30]

template<>
void dataStore ( std::ostream &  stream,
Node *&  n,
void *  context 
)

Definition at line 193 of file DataIO.C.

194{
195 // TODO: Write out the unique ID of this node
197
198 if (n)
199 {
200 id = n->id();
202 mooseError("Can't output Nodes with invalid ids!");
203 }
204
205 dataStore(stream, id, context);
206}

◆ dataStore() [13/30]

template<>
void dataStore ( std::ostream &  stream,
Point &  p,
void *  context 
)

Definition at line 319 of file DataIO.C.

320{
321 dataStore(stream, const_cast<const Point &>(p), context);
322}

◆ dataStore() [14/30]

template<>
void dataStore ( std::ostream &  stream,
RankFourTensor &  rft,
void *  context 
)

Definition at line 116 of file DataIO.C.

117{
118 dataStore(stream, rft._vals, context);
119}
T _vals[N4]
The values of the rank-four tensor stored by index=(((i * LIBMESH_DIM + j) * LIBMESH_DIM + k) * LIBME...

◆ dataStore() [15/30]

template<>
void dataStore ( std::ostream &  stream,
RankThreeTensor &  rtht,
void *  context 
)

Definition at line 109 of file DataIO.C.

110{
111 dataStore(stream, rtht._vals, context);
112}
T _vals[N3]
The values of the rank-three tensor stored by index=((i * LIBMESH_DIM + j) * LIBMESH_DIM + k)

◆ dataStore() [16/30]

template<>
void dataStore ( std::ostream &  stream,
RankTwoTensor &  rtt,
void *  context 
)

Definition at line 102 of file DataIO.C.

103{
104 dataStore(stream, rtt._coords, context);
105}
T _coords[LIBMESH_DIM *LIBMESH_DIM]

◆ dataStore() [17/30]

template<>
void dataStore ( std::ostream &  stream,
std::string &  v,
void *  context 
)

Definition at line 39 of file DataIO.C.

40{
41 // Write the size of the string
42 unsigned int size = v.size();
43 stream.write((char *)&size, sizeof(size));
44
45 // Write the string (Do not store the null byte)
46 stream.write(v.c_str(), sizeof(char) * size);
47}

Referenced by dataStore(), dataStore(), dataStore(), dataStore(), dataStore(), dataStore(), dataStore(), dataStore(), dataStore(), dataStore(), dataStore(), dataStore(), dataStore(), dataStore(), dataStore(), dataStore(), dataStore(), dataStore(), dataStore(), dataStore(), dataStore(), dataStore(), and dataStore< mt_state >().

◆ dataStore() [18/30]

template<>
void dataStore ( std::ostream &  stream,
std::stringstream &  s,
void *  context 
)

Definition at line 210 of file DataIO.C.

211{
212 const std::string & s_str = s.str();
213
214 size_t s_size = s_str.size();
215 stream.write((char *)&s_size, sizeof(s_size));
216
217 stream.write(s_str.c_str(), sizeof(char) * (s_str.size()));
218}

◆ dataStore() [19/30]

template<>
void dataStore ( std::ostream &  stream,
std::unique_ptr< libMesh::NumericVector< Number > > &  v,
void *  context 
)

Definition at line 365 of file DataIO.C.

368{
369 // Classes may declare unique pointers to vectors as restartable data and never actually create
370 // vector instances. This happens for example in the `TimeIntegrator` class where subvector
371 // instances are only created if multiple time integrators are present
372 bool have_vector = v.get();
373 dataStore(stream, have_vector, context);
374 if (!have_vector)
375 return;
376
377 mooseAssert(context, "Needs a context of the communicator");
378 const auto & comm = *static_cast<const libMesh::Parallel::Communicator *>(context);
379 mooseAssert(&comm == &v->comm(), "Inconsistent communicator");
380
381 if (v->type() == GHOSTED)
382 mooseError("Cannot store ghosted numeric vectors");
383
384 // Store the communicator size for sanity checking later
385 unsigned int comm_size = comm.size();
386 dataStore(stream, comm_size, nullptr);
387
388 // Store the solver package so that we know what vector type to construct
389 libMesh::SolverPackage solver_package;
390 if (dynamic_cast<libMesh::PetscVector<Number> *>(v.get()))
391 solver_package = libMesh::PETSC_SOLVERS;
392 else
393 mooseError("Can only store unique_ptrs of PetscVectors");
394 int solver_package_int = solver_package;
395 dataStore(stream, solver_package_int, nullptr);
396
397 // Store the sizes
398 dof_id_type size = v->size();
399 dataStore(stream, size, nullptr);
400 dof_id_type local_size = v->local_size();
401 dataStore(stream, local_size, nullptr);
402
403 // Store the vector itself
404 dataStore(stream, *v, nullptr);
405}

◆ dataStore() [20/30]

template<>
void dataStore ( std::ostream &  stream,
std::vector< bool > &  v,
void *  context 
)

Definition at line 92 of file DataIO.C.

93{
94 std::size_t size = v.size();
95 dataStore(stream, size, nullptr);
96 for (bool b : v)
97 dataStore(stream, b, context);
98}

◆ dataStore() [21/30]

template void dataStore ( std::ostream &  stream,
TensorValue< ADReal > &  v,
void *  context 
)

◆ dataStore() [22/30]

template void dataStore ( std::ostream &  stream,
TensorValue< Real > &  v,
void *  context 
)

◆ dataStore() [23/30]

template<typename T >
void dataStore ( std::ostream &  stream,
TensorValue< T > &  v,
void *  context 
)

Definition at line 255 of file DataIO.C.

256{
257 for (const auto i : make_range(Moose::dim))
258 for (const auto j : make_range(Moose::dim))
259 {
260 T r = v(i, j);
261 dataStore(stream, r, context);
262 }
263}

◆ dataStore() [24/30]

template<>
void dataStore ( std::ostream &  stream,
torch::Tensor &  t,
void *  context 
)

Definition at line 223 of file DataIO.C.

224{
225 const bool defined = t.defined();
226 dataStore(stream, defined, nullptr);
227
228 if (!defined)
229 return;
230
231 const auto tensor = LibtorchUtils::toCPUContiguous(t);
232 mooseAssert(tensor.scalar_type() == at::kDouble,
233 "Restart storage currently supports only double tensors.");
234
235 auto rank = cast_int<unsigned int>(tensor.dim());
236 dataStore(stream, rank, nullptr);
237 for (unsigned int dim = 0; dim < rank; ++dim)
238 {
239 auto size = cast_int<unsigned int>(tensor.sizes()[dim]);
240 dataStore(stream, size, nullptr);
241 }
242
243 const auto flattened = tensor.reshape({tensor.numel()});
244 const auto t_accessor = flattened.accessor<Real, 1>();
245 for (int64_t i = 0; i < flattened.numel(); ++i)
246 {
247 Real r = t_accessor[i];
248 dataStore(stream, r, context);
249 }
250}
torch::Tensor toCPUContiguous(const torch::Tensor &tensor)
Return a detached contiguous CPU copy of a tensor.

◆ dataStore() [25/30]

template<>
void dataStore ( std::ostream &  stream,
UserObjectName &  v,
void *  context 
)

Definition at line 59 of file DataIO.C.

60{
61 auto & name = cast_ref<std::string &>(v);
62 dataStore(stream, name, context);
63}

◆ dataStore() [26/30]

template<>
void dataStore ( std::ostream &  stream,
VariableName &  v,
void *  context 
)

Definition at line 51 of file DataIO.C.

52{
53 auto & name = cast_ref<std::string &>(v);
54 dataStore(stream, name, context);
55}

◆ dataStore() [27/30]

template<>
void dataStore ( std::ostream &  stream,
Vec &  v,
void *  context 
)

Definition at line 810 of file DataIO.C.

811{
812 PetscInt local_size;
813 LibmeshPetscCallA(PETSC_COMM_WORLD, VecGetLocalSize(v, &local_size));
814 PetscScalar * array;
815 LibmeshPetscCallA(PETSC_COMM_WORLD, VecGetArray(v, &array));
816 for (PetscInt i = 0; i < local_size; i++)
817 dataStore(stream, array[i], context);
818
819 LibmeshPetscCallA(PETSC_COMM_WORLD, VecRestoreArray(v, &array));
820}

◆ dataStore() [28/30]

template void dataStore ( std::ostream &  stream,
VectorValue< ADReal > &  v,
void *  context 
)

◆ dataStore() [29/30]

template void dataStore ( std::ostream &  stream,
VectorValue< Real > &  v,
void *  context 
)

◆ dataStore() [30/30]

template<typename T >
void dataStore ( std::ostream &  stream,
VectorValue< T > &  v,
void *  context 
)

Definition at line 289 of file DataIO.C.

290{
291 // Obviously if someone loads data with different LIBMESH_DIM than was used for saving them, it
292 // won't work.
293 for (const auto i : make_range(Moose::dim))
294 {
295 T r = v(i);
296 dataStore(stream, r, context);
297 }
298}

◆ dataStore< mt_state >()

template<>
void dataStore< mt_state > ( std::ostream &  stream,
mt_state &  foo,
void *  ctx 
)

Definition at line 29 of file DataIO.C.

31{
32 dataStore(stream, foo.statevec, ctx);
33 dataStore(stream, foo.stateptr, ctx);
34 dataStore(stream, foo.initialized, ctx);
35}