16 #include "libmesh/vector_value.h" 17 #include "libmesh/tensor_value.h" 19 #include "libmesh/elem.h" 20 #include "libmesh/petsc_vector.h" 21 #include "libmesh/enum_solver_package.h" 22 #include "libmesh/petsc_solver_exception.h" 30 stream.write((
char *)&v,
sizeof(v));
35 dataStore(std::ostream & stream, std::string & v,
void * )
38 unsigned int size = v.size();
39 stream.write((
char *)&size,
sizeof(size));
42 stream.write(v.c_str(),
sizeof(char) * size);
47 dataStore(std::ostream & stream, VariableName & v,
void * context)
49 auto &
name =
static_cast<std::string &
>(v);
55 dataStore(std::ostream & stream, UserObjectName & v,
void * context)
57 auto &
name =
static_cast<std::string &
>(v);
65 stream.write((
char *)&v,
sizeof(v));
70 dataStore(std::ostream & stream, std::vector<bool> & v,
void * context)
103 if (ADReal::do_derivatives)
105 auto & derivatives = dn.derivatives();
106 std::size_t size = derivatives.size();
108 for (MooseIndex(size) i = 0; i < size; ++i)
110 dataStore(stream, derivatives.raw_index(i), context);
111 dataStore(stream, derivatives.raw_at(i), context);
127 mooseError(
"Can't output Elems with invalid ids!");
144 mooseError(
"Can't output Nodes with invalid ids!");
161 mooseError(
"Can't output Elems with invalid ids!");
178 mooseError(
"Can't output Nodes with invalid ids!");
186 dataStore(std::ostream & stream, std::stringstream & s,
void * )
188 const std::string & s_str = s.str();
190 size_t s_size = s_str.size();
191 stream.write((
char *)&s_size,
sizeof(s_size));
193 stream.write(s_str.c_str(),
sizeof(char) * (s_str.size()));
196 template <
typename T>
211 template <
typename T>
215 unsigned int m = v.
m();
216 unsigned int n = v.
n();
217 stream.write((
char *)&m,
sizeof(m));
218 stream.write((
char *)&n,
sizeof(n));
219 for (
unsigned int i = 0; i < m; i++)
220 for (
unsigned int j = 0; j < n; j++)
230 template <
typename T>
262 stream.write((
char *)&size,
sizeof(size));
267 for (; it != end; ++it)
269 auto & key =
const_cast<std::string &
>(it->first);
270 auto type = it->second->type();
275 #define storescalar(ptype) \ 276 else if (it->second->type() == demangle(typeid(ptype).name())) storeHelper( \ 278 (dynamic_cast<libMesh::Parameters::Parameter<ptype> *>(MooseUtils::get(it->second)))->get(), \ 287 storescalar(
unsigned short);
288 storescalar(
unsigned int);
289 storescalar(
unsigned long);
304 bool have_vector = v.get();
309 mooseAssert(context,
"Needs a context of the communicator");
311 mooseAssert(&comm == &v->comm(),
"Inconsistent communicator");
314 mooseError(
"Cannot store ghosted numeric vectors");
317 unsigned int comm_size = comm.size();
325 mooseError(
"Can only store unique_ptrs of PetscVectors");
326 int solver_package_int = solver_package;
327 dataStore(stream, solver_package_int,
nullptr);
345 stream.read((
char *)&v,
sizeof(v));
350 dataLoad(std::istream & stream, std::string & v,
void * )
353 unsigned int size = 0;
354 stream.read((
char *)&size,
sizeof(size));
360 stream.read(&v[0],
sizeof(
char) * size);
365 dataLoad(std::istream & stream, VariableName & v,
void * context)
367 auto &
name =
static_cast<std::string &
>(v);
373 dataLoad(std::istream & stream, UserObjectName & v,
void * context)
375 auto &
name =
static_cast<std::string &
>(v);
383 stream.read((
char *)&v,
sizeof(v));
388 dataLoad(std::istream & stream, std::vector<bool> & v,
void * context)
398 dataLoad(stream, dn.value(), context);
400 if (ADReal::do_derivatives)
402 auto & derivatives = dn.derivatives();
403 std::size_t size = 0;
404 stream.read((
char *)&size,
sizeof(size));
405 derivatives.resize(size);
407 for (MooseIndex(derivatives) i = 0; i < derivatives.size(); ++i)
409 dataLoad(stream, derivatives.raw_index(i), context);
410 dataLoad(stream, derivatives.raw_at(i), context);
420 mooseError(
"Can only load Elem objects using a MooseMesh context!");
430 e =
mesh->elemPtr(
id);
440 mooseError(
"Can only load Node objects using a MooseMesh context!");
450 n =
mesh->nodePtr(
id);
460 mooseError(
"Can only load Elem objects using a MooseMesh context!");
470 e =
mesh->elemPtr(
id);
480 mooseError(
"Can only load Node objects using a MooseMesh context!");
490 n =
mesh->nodePtr(
id);
497 dataLoad(std::istream & stream, std::stringstream & s,
void * )
500 stream.read((
char *)&s_size,
sizeof(s_size));
502 std::unique_ptr<char[]> s_s = std::make_unique<char[]>(s_size);
503 stream.read(s_s.get(), s_size);
506 s.str(std::string());
507 s.write(s_s.get(), s_size);
510 template <
typename T>
528 template <
typename T>
532 unsigned int m = 0, n = 0;
533 stream.read((
char *)&m,
sizeof(m));
534 stream.read((
char *)&n,
sizeof(n));
536 for (
unsigned int i = 0; i < m; i++)
537 for (
unsigned int j = 0; j < n; j++)
548 template <
typename T>
583 unsigned int size = 0;
584 stream.read((
char *)&size,
sizeof(size));
586 for (
unsigned int i = 0; i < size; i++)
588 std::string key, type;
592 #define loadscalar(ptype) \ 593 else if (type == demangle(typeid(ptype).name())) do \ 595 ptype & value = p.set<ptype>(key); \ 596 loadHelper(stream, value, context); \ 606 loadscalar(
unsigned short);
607 loadscalar(
unsigned int);
608 loadscalar(
unsigned long);
619 dataLoad(stream, have_vector, context);
624 mooseAssert(context,
"Needs a context of the communicator");
627 mooseAssert(&comm == &v->comm(),
"Inconsistent communicator");
630 unsigned int comm_size;
631 dataLoad(stream, comm_size,
nullptr);
632 mooseAssert(comm.size() == comm_size,
"Inconsistent communicator size");
635 int solver_package_int;
636 dataLoad(stream, solver_package_int,
nullptr);
642 dataLoad(stream, local_size,
nullptr);
649 v->init(size, local_size);
652 mooseAssert(v->type() !=
GHOSTED,
"Cannot be ghosted");
656 mooseAssert(v->size() == size,
"Inconsistent size");
657 mooseAssert(v->local_size() == local_size,
"Inconsistent local size");
665 dataLoad(std::istream & stream, Vec & v,
void * context)
668 LibmeshPetscCallA(PETSC_COMM_WORLD, VecGetLocalSize(v, &local_size));
670 LibmeshPetscCallA(PETSC_COMM_WORLD, VecGetArray(v, &array));
671 for (PetscInt i = 0; i < local_size; i++)
672 dataLoad(stream, array[i], context);
674 LibmeshPetscCallA(PETSC_COMM_WORLD, VecRestoreArray(v, &array));
679 dataStore(std::ostream & stream, Vec & v,
void * context)
682 LibmeshPetscCallA(PETSC_COMM_WORLD, VecGetLocalSize(v, &local_size));
684 LibmeshPetscCallA(PETSC_COMM_WORLD, VecGetArray(v, &array));
685 for (PetscInt i = 0; i < local_size; i++)
688 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...
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 *)