16 #include "libmesh/vector_value.h" 17 #include "libmesh/tensor_value.h" 18 #include "libmesh/fe_type.h" 20 #include "libmesh/elem.h" 21 #include "libmesh/petsc_vector.h" 22 #include "libmesh/enum_solver_package.h" 23 #include "libmesh/petsc_solver_exception.h" 31 stream.write((
char *)&v,
sizeof(v));
36 dataStore(std::ostream & stream, std::string & v,
void * )
39 unsigned int size = v.size();
40 stream.write((
char *)&size,
sizeof(size));
43 stream.write(v.c_str(),
sizeof(char) * size);
48 dataStore(std::ostream & stream, VariableName & v,
void * context)
50 auto &
name =
static_cast<std::string &
>(v);
56 dataStore(std::ostream & stream, UserObjectName & v,
void * context)
58 auto &
name =
static_cast<std::string &
>(v);
66 stream.write((
char *)&v,
sizeof(v));
79 #ifdef LIBMESH_ENABLE_INFINITE_ELEMENTS 84 dataStore(stream, radial_family, context);
96 dataStore(std::ostream & stream, std::vector<bool> & v,
void * context)
129 if (ADReal::do_derivatives)
131 auto & derivatives = dn.derivatives();
132 std::size_t size = derivatives.size();
134 for (MooseIndex(size) i = 0; i < size; ++i)
136 dataStore(stream, derivatives.raw_index(i), context);
137 dataStore(stream, derivatives.raw_at(i), context);
153 mooseError(
"Can't output Elems with invalid ids!");
170 mooseError(
"Can't output Nodes with invalid ids!");
187 mooseError(
"Can't output Elems with invalid ids!");
204 mooseError(
"Can't output Nodes with invalid ids!");
212 dataStore(std::ostream & stream, std::stringstream & s,
void * )
214 const std::string & s_str = s.str();
216 size_t s_size = s_str.size();
217 stream.write((
char *)&s_size,
sizeof(s_size));
219 stream.write(s_str.c_str(),
sizeof(char) * (s_str.size()));
222 template <
typename T>
237 template <
typename T>
241 unsigned int m = v.
m();
242 unsigned int n = v.
n();
243 stream.write((
char *)&m,
sizeof(m));
244 stream.write((
char *)&n,
sizeof(n));
245 for (
unsigned int i = 0; i < m; i++)
246 for (
unsigned int j = 0; j < n; j++)
256 template <
typename T>
288 stream.write((
char *)&size,
sizeof(size));
293 for (; it != end; ++it)
295 auto & key =
const_cast<std::string &
>(it->first);
296 auto type = it->second->type();
301 #define storescalar(ptype) \ 302 else if (it->second->type() == demangle(typeid(ptype).name())) storeHelper( \ 304 (dynamic_cast<libMesh::Parameters::Parameter<ptype> *>(MooseUtils::get(it->second)))->get(), \ 313 storescalar(
unsigned short);
314 storescalar(
unsigned int);
315 storescalar(
unsigned long);
330 bool have_vector = v.get();
335 mooseAssert(context,
"Needs a context of the communicator");
337 mooseAssert(&comm == &v->comm(),
"Inconsistent communicator");
340 mooseError(
"Cannot store ghosted numeric vectors");
343 unsigned int comm_size = comm.size();
351 mooseError(
"Can only store unique_ptrs of PetscVectors");
352 int solver_package_int = solver_package;
353 dataStore(stream, solver_package_int,
nullptr);
371 stream.read((
char *)&v,
sizeof(v));
376 dataLoad(std::istream & stream, std::string & v,
void * )
379 unsigned int size = 0;
380 stream.read((
char *)&size,
sizeof(size));
386 stream.read(&v[0],
sizeof(
char) * size);
391 dataLoad(std::istream & stream, VariableName & v,
void * context)
393 auto &
name =
static_cast<std::string &
>(v);
399 dataLoad(std::istream & stream, UserObjectName & v,
void * context)
401 auto &
name =
static_cast<std::string &
>(v);
409 stream.read((
char *)&v,
sizeof(v));
422 #ifdef LIBMESH_ENABLE_INFINITE_ELEMENTS 423 int radial_order = 0;
424 dataLoad(stream, radial_order, context);
436 dataLoad(std::istream & stream, std::vector<bool> & v,
void * context)
446 dataLoad(stream, dn.value(), context);
448 if (ADReal::do_derivatives)
450 auto & derivatives = dn.derivatives();
451 std::size_t size = 0;
452 stream.read((
char *)&size,
sizeof(size));
453 derivatives.resize(size);
455 for (MooseIndex(derivatives) i = 0; i < derivatives.size(); ++i)
457 dataLoad(stream, derivatives.raw_index(i), context);
458 dataLoad(stream, derivatives.raw_at(i), context);
468 mooseError(
"Can only load Elem objects using a MooseMesh context!");
478 e =
mesh->elemPtr(
id);
488 mooseError(
"Can only load Node objects using a MooseMesh context!");
498 n =
mesh->nodePtr(
id);
508 mooseError(
"Can only load Elem objects using a MooseMesh context!");
518 e =
mesh->elemPtr(
id);
528 mooseError(
"Can only load Node objects using a MooseMesh context!");
538 n =
mesh->nodePtr(
id);
545 dataLoad(std::istream & stream, std::stringstream & s,
void * )
548 stream.read((
char *)&s_size,
sizeof(s_size));
550 std::unique_ptr<char[]> s_s = std::make_unique<char[]>(s_size);
551 stream.read(s_s.get(), s_size);
554 s.str(std::string());
555 s.write(s_s.get(), s_size);
558 template <
typename T>
576 template <
typename T>
580 unsigned int m = 0, n = 0;
581 stream.read((
char *)&m,
sizeof(m));
582 stream.read((
char *)&n,
sizeof(n));
584 for (
unsigned int i = 0; i < m; i++)
585 for (
unsigned int j = 0; j < n; j++)
596 template <
typename T>
631 unsigned int size = 0;
632 stream.read((
char *)&size,
sizeof(size));
634 for (
unsigned int i = 0; i < size; i++)
636 std::string key, type;
640 #define loadscalar(ptype) \ 641 else if (type == demangle(typeid(ptype).name())) do \ 643 ptype & value = p.set<ptype>(key); \ 644 loadHelper(stream, value, context); \ 654 loadscalar(
unsigned short);
655 loadscalar(
unsigned int);
656 loadscalar(
unsigned long);
667 dataLoad(stream, have_vector, context);
672 mooseAssert(context,
"Needs a context of the communicator");
675 mooseAssert(&comm == &v->comm(),
"Inconsistent communicator");
678 unsigned int comm_size;
679 dataLoad(stream, comm_size,
nullptr);
680 mooseAssert(comm.size() == comm_size,
"Inconsistent communicator size");
683 int solver_package_int;
684 dataLoad(stream, solver_package_int,
nullptr);
690 dataLoad(stream, local_size,
nullptr);
697 v->init(size, local_size);
700 mooseAssert(v->type() !=
GHOSTED,
"Cannot be ghosted");
704 mooseAssert(v->size() == size,
"Inconsistent size");
705 mooseAssert(v->local_size() == local_size,
"Inconsistent local size");
713 dataLoad(std::istream & stream, Vec & v,
void * context)
716 LibmeshPetscCallA(PETSC_COMM_WORLD, VecGetLocalSize(v, &local_size));
718 LibmeshPetscCallA(PETSC_COMM_WORLD, VecGetArray(v, &array));
719 for (PetscInt i = 0; i < local_size; i++)
720 dataLoad(stream, array[i], context);
722 LibmeshPetscCallA(PETSC_COMM_WORLD, VecRestoreArray(v, &array));
727 dataStore(std::ostream & stream, Vec & v,
void * context)
730 LibmeshPetscCallA(PETSC_COMM_WORLD, VecGetLocalSize(v, &local_size));
732 LibmeshPetscCallA(PETSC_COMM_WORLD, VecGetArray(v, &array));
733 for (PetscInt i = 0; i < local_size; i++)
736 LibmeshPetscCallA(PETSC_COMM_WORLD, VecRestoreArray(v, &array));
std::string name(const ElemQuality q)
RankFourTensorTempl is designed to handle any N-dimensional fourth order tensor, C.
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application...
OrderWrapper radial_order
static constexpr std::size_t dim
This is the dimension of all vector and tensor datastructures used in MOOSE.
The following methods are specializations for using the libMesh::Parallel::packed_range_* routines fo...
T _coords[LIBMESH_DIM *LIBMESH_DIM]
DualNumber< Real, DNDerivativeType, true > ADReal
RankThreeTensor is designed to handle any N-dimensional third order tensor, r.
void storeHelper(std::ostream &stream, P &data, void *context)
Scalar helper routine.
static constexpr dof_id_type invalid_id
void dataLoad(std::istream &stream, Real &v, void *)
MooseMesh wraps a libMesh::Mesh object and enhances its capabilities by caching additional data and s...
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...
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
void resize(const unsigned int new_m, const unsigned int new_n)
IntRange< T > make_range(T beg, T end)
static std::unique_ptr< NumericVector< T > > build(const Parallel::Communicator &comm, SolverPackage solver_package=libMesh::default_solver_package(), ParallelType parallel_type=AUTOMATIC)
std::size_t n_parameters() const
void loadHelper(std::istream &stream, P &data, void *context)
Scalar helper routine.
void dataStore(std::ostream &stream, Real &v, void *)