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()));
200 unsigned int m = v.size();
201 stream.write((
char *)&m,
sizeof(m));
202 for (
unsigned int i = 0; i < v.size(); i++)
213 unsigned int m = v.rows();
214 stream.write((
char *)&m,
sizeof(m));
215 unsigned int n = v.cols();
216 stream.write((
char *)&n,
sizeof(n));
217 for (
unsigned int i = 0; i < m; i++)
218 for (
unsigned int j = 0; j < n; j++)
225 template <
typename T>
240 template <
typename T>
244 unsigned int m = v.
m();
245 unsigned int n = v.
n();
246 stream.write((
char *)&m,
sizeof(m));
247 stream.write((
char *)&n,
sizeof(n));
248 for (
unsigned int i = 0; i < m; i++)
249 for (
unsigned int j = 0; j < n; j++)
259 template <
typename T>
291 stream.write((
char *)&size,
sizeof(size));
296 for (; it != end; ++it)
298 auto & key =
const_cast<std::string &
>(it->first);
299 auto type = it->second->type();
304 #define storescalar(ptype) \ 305 else if (it->second->type() == demangle(typeid(ptype).name())) storeHelper( \ 307 (dynamic_cast<libMesh::Parameters::Parameter<ptype> *>(MooseUtils::get(it->second)))->get(), \ 316 storescalar(
unsigned short);
317 storescalar(
unsigned int);
318 storescalar(
unsigned long);
333 bool have_vector = v.get();
338 mooseAssert(context,
"Needs a context of the communicator");
340 mooseAssert(&comm == &v->comm(),
"Inconsistent communicator");
343 mooseError(
"Cannot store ghosted numeric vectors");
346 unsigned int comm_size = comm.size();
354 mooseError(
"Can only store unique_ptrs of PetscVectors");
355 int solver_package_int = solver_package;
356 dataStore(stream, solver_package_int,
nullptr);
374 stream.read((
char *)&v,
sizeof(v));
379 dataLoad(std::istream & stream, std::string & v,
void * )
382 unsigned int size = 0;
383 stream.read((
char *)&size,
sizeof(size));
389 stream.read(&v[0],
sizeof(
char) * size);
394 dataLoad(std::istream & stream, VariableName & v,
void * context)
396 auto &
name =
static_cast<std::string &
>(v);
402 dataLoad(std::istream & stream, UserObjectName & v,
void * context)
404 auto &
name =
static_cast<std::string &
>(v);
412 stream.read((
char *)&v,
sizeof(v));
417 dataLoad(std::istream & stream, std::vector<bool> & v,
void * context)
427 dataLoad(stream, dn.value(), context);
429 if (ADReal::do_derivatives)
431 auto & derivatives = dn.derivatives();
432 std::size_t size = 0;
433 stream.read((
char *)&size,
sizeof(size));
434 derivatives.resize(size);
436 for (MooseIndex(derivatives) i = 0; i < derivatives.size(); ++i)
438 dataLoad(stream, derivatives.raw_index(i), context);
439 dataLoad(stream, derivatives.raw_at(i), context);
449 mooseError(
"Can only load Elem objects using a MooseMesh context!");
459 e =
mesh->elemPtr(
id);
469 mooseError(
"Can only load Node objects using a MooseMesh context!");
479 n =
mesh->nodePtr(
id);
489 mooseError(
"Can only load Elem objects using a MooseMesh context!");
499 e =
mesh->elemPtr(
id);
509 mooseError(
"Can only load Node objects using a MooseMesh context!");
519 n =
mesh->nodePtr(
id);
526 dataLoad(std::istream & stream, std::stringstream & s,
void * )
529 stream.read((
char *)&s_size,
sizeof(s_size));
531 std::unique_ptr<char[]> s_s = std::make_unique<char[]>(s_size);
532 stream.read(s_s.get(), s_size);
535 s.str(std::string());
536 s.write(s_s.get(), s_size);
544 stream.read((
char *)&n,
sizeof(n));
546 for (
unsigned int i = 0; i < n; i++)
559 stream.read((
char *)&m,
sizeof(m));
561 stream.read((
char *)&n,
sizeof(n));
563 for (
unsigned int i = 0; i < m; i++)
564 for (
unsigned int j = 0; j < n; j++)
572 template <
typename T>
590 template <
typename T>
594 unsigned int m = 0, n = 0;
595 stream.read((
char *)&m,
sizeof(m));
596 stream.read((
char *)&n,
sizeof(n));
598 for (
unsigned int i = 0; i < m; i++)
599 for (
unsigned int j = 0; j < n; j++)
610 template <
typename T>
645 unsigned int size = 0;
646 stream.read((
char *)&size,
sizeof(size));
648 for (
unsigned int i = 0; i < size; i++)
650 std::string key, type;
654 #define loadscalar(ptype) \ 655 else if (type == demangle(typeid(ptype).name())) do \ 657 ptype & value = p.set<ptype>(key); \ 658 loadHelper(stream, value, context); \ 668 loadscalar(
unsigned short);
669 loadscalar(
unsigned int);
670 loadscalar(
unsigned long);
681 dataLoad(stream, have_vector, context);
686 mooseAssert(context,
"Needs a context of the communicator");
689 mooseAssert(&comm == &v->comm(),
"Inconsistent communicator");
692 unsigned int comm_size;
693 dataLoad(stream, comm_size,
nullptr);
694 mooseAssert(comm.size() == comm_size,
"Inconsistent communicator size");
697 int solver_package_int;
698 dataLoad(stream, solver_package_int,
nullptr);
704 dataLoad(stream, local_size,
nullptr);
711 v->init(size, local_size);
714 mooseAssert(v->type() !=
GHOSTED,
"Cannot be ghosted");
718 mooseAssert(v->size() == size,
"Inconsistent size");
719 mooseAssert(v->local_size() == local_size,
"Inconsistent local size");
727 dataLoad(std::istream & 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++)
734 dataLoad(stream, array[i], context);
736 LibmeshPetscCallA(PETSC_COMM_WORLD, VecRestoreArray(v, &array));
741 dataStore(std::ostream & stream, Vec & v,
void * context)
744 LibmeshPetscCallA(PETSC_COMM_WORLD, VecGetLocalSize(v, &local_size));
746 LibmeshPetscCallA(PETSC_COMM_WORLD, VecGetArray(v, &array));
747 for (PetscInt i = 0; i < local_size; i++)
750 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.
void dataLoad(std::istream &stream, Real &v, void *)
MooseMesh wraps a libMesh::Mesh object and enhances its capabilities by caching additional data and s...
static const dof_id_type invalid_id
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
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)
Eigen::Matrix< Real, Eigen::Dynamic, 1 > RealEigenVector
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 *)