11 #include "MooseConfig.h" 17 #include "libmesh/vector_value.h" 18 #include "libmesh/tensor_value.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));
71 dataStore(std::ostream & stream, std::vector<bool> & v,
void * context)
104 if (ADReal::do_derivatives)
106 auto & derivatives = dn.derivatives();
107 std::size_t size = derivatives.size();
109 for (MooseIndex(size) i = 0; i < size; ++i)
111 dataStore(stream, derivatives.raw_index(i), context);
112 dataStore(stream, derivatives.raw_at(i), context);
128 mooseError(
"Can't output Elems with invalid ids!");
145 mooseError(
"Can't output Nodes with invalid ids!");
162 mooseError(
"Can't output Elems with invalid ids!");
179 mooseError(
"Can't output Nodes with invalid ids!");
187 dataStore(std::ostream & stream, std::stringstream & s,
void * )
189 const std::string & s_str = s.str();
191 size_t s_size = s_str.size();
192 stream.write((
char *)&s_size,
sizeof(s_size));
194 stream.write(s_str.c_str(),
sizeof(char) * (s_str.size()));
201 unsigned int m = v.size();
202 stream.write((
char *)&m,
sizeof(m));
203 for (
unsigned int i = 0; i < v.size(); i++)
214 unsigned int m = v.rows();
215 stream.write((
char *)&m,
sizeof(m));
216 unsigned int n = v.cols();
217 stream.write((
char *)&n,
sizeof(n));
218 for (
unsigned int i = 0; i < m; i++)
219 for (
unsigned int j = 0; j < n; j++)
226 template <
typename T>
241 template <
typename T>
245 unsigned int m = v.
m();
246 unsigned int n = v.
n();
247 stream.write((
char *)&m,
sizeof(m));
248 stream.write((
char *)&n,
sizeof(n));
249 for (
unsigned int i = 0; i < m; i++)
250 for (
unsigned int j = 0; j < n; j++)
260 template <
typename T>
292 stream.write((
char *)&size,
sizeof(size));
297 for (; it != end; ++it)
299 auto & key =
const_cast<std::string &
>(it->first);
300 auto type = it->second->type();
305 #define storescalar(ptype) \ 306 else if (it->second->type() == demangle(typeid(ptype).name())) storeHelper( \ 308 (dynamic_cast<libMesh::Parameters::Parameter<ptype> *>(MooseUtils::get(it->second)))->get(), \ 317 storescalar(
unsigned short);
318 storescalar(
unsigned int);
319 storescalar(
unsigned long);
334 bool have_vector = v.get();
339 mooseAssert(context,
"Needs a context of the communicator");
341 mooseAssert(&comm == &v->comm(),
"Inconsistent communicator");
344 mooseError(
"Cannot store ghosted numeric vectors");
347 unsigned int comm_size = comm.size();
355 mooseError(
"Can only store unique_ptrs of PetscVectors");
356 int solver_package_int = solver_package;
357 dataStore(stream, solver_package_int,
nullptr);
375 stream.read((
char *)&v,
sizeof(v));
380 dataLoad(std::istream & stream, std::string & v,
void * )
383 unsigned int size = 0;
384 stream.read((
char *)&size,
sizeof(size));
390 stream.read(&v[0],
sizeof(
char) * size);
395 dataLoad(std::istream & stream, VariableName & v,
void * context)
397 auto &
name =
static_cast<std::string &
>(v);
403 dataLoad(std::istream & stream, UserObjectName & v,
void * context)
405 auto &
name =
static_cast<std::string &
>(v);
413 stream.read((
char *)&v,
sizeof(v));
418 dataLoad(std::istream & stream, std::vector<bool> & v,
void * context)
428 dataLoad(stream, dn.value(), context);
430 if (ADReal::do_derivatives)
432 auto & derivatives = dn.derivatives();
433 std::size_t size = 0;
434 stream.read((
char *)&size,
sizeof(size));
435 derivatives.resize(size);
437 for (MooseIndex(derivatives) i = 0; i < derivatives.size(); ++i)
439 dataLoad(stream, derivatives.raw_index(i), context);
440 dataLoad(stream, derivatives.raw_at(i), context);
450 mooseError(
"Can only load Elem objects using a MooseMesh context!");
460 e =
mesh->elemPtr(
id);
470 mooseError(
"Can only load Node objects using a MooseMesh context!");
480 n =
mesh->nodePtr(
id);
490 mooseError(
"Can only load Elem objects using a MooseMesh context!");
500 e =
mesh->elemPtr(
id);
510 mooseError(
"Can only load Node objects using a MooseMesh context!");
520 n =
mesh->nodePtr(
id);
527 dataLoad(std::istream & stream, std::stringstream & s,
void * )
530 stream.read((
char *)&s_size,
sizeof(s_size));
532 std::unique_ptr<char[]> s_s = std::make_unique<char[]>(s_size);
533 stream.read(s_s.get(), s_size);
536 s.str(std::string());
537 s.write(s_s.get(), s_size);
545 stream.read((
char *)&n,
sizeof(n));
547 for (
unsigned int i = 0; i < n; i++)
560 stream.read((
char *)&m,
sizeof(m));
562 stream.read((
char *)&n,
sizeof(n));
564 for (
unsigned int i = 0; i < m; i++)
565 for (
unsigned int j = 0; j < n; j++)
573 template <
typename T>
591 template <
typename T>
595 unsigned int m = 0, n = 0;
596 stream.read((
char *)&m,
sizeof(m));
597 stream.read((
char *)&n,
sizeof(n));
599 for (
unsigned int i = 0; i < m; i++)
600 for (
unsigned int j = 0; j < n; j++)
611 template <
typename T>
646 unsigned int size = 0;
647 stream.read((
char *)&size,
sizeof(size));
649 for (
unsigned int i = 0; i < size; i++)
651 std::string key, type;
655 #define loadscalar(ptype) \ 656 else if (type == demangle(typeid(ptype).name())) do \ 658 ptype & value = p.set<ptype>(key); \ 659 loadHelper(stream, value, context); \ 669 loadscalar(
unsigned short);
670 loadscalar(
unsigned int);
671 loadscalar(
unsigned long);
682 dataLoad(stream, have_vector, context);
687 mooseAssert(context,
"Needs a context of the communicator");
690 mooseAssert(&comm == &v->comm(),
"Inconsistent communicator");
693 unsigned int comm_size;
694 dataLoad(stream, comm_size,
nullptr);
695 mooseAssert(comm.size() == comm_size,
"Inconsistent communicator size");
698 int solver_package_int;
699 dataLoad(stream, solver_package_int,
nullptr);
705 dataLoad(stream, local_size,
nullptr);
712 v->init(size, local_size);
715 mooseAssert(v->type() !=
GHOSTED,
"Cannot be ghosted");
719 mooseAssert(v->size() == size,
"Inconsistent size");
720 mooseAssert(v->local_size() == local_size,
"Inconsistent local size");
728 dataLoad(std::istream & stream, Vec & v,
void * context)
731 LibmeshPetscCallA(PETSC_COMM_WORLD, VecGetLocalSize(v, &local_size));
733 LibmeshPetscCallA(PETSC_COMM_WORLD, VecGetArray(v, &array));
734 for (PetscInt i = 0; i < local_size; i++)
735 dataLoad(stream, array[i], context);
737 LibmeshPetscCallA(PETSC_COMM_WORLD, VecRestoreArray(v, &array));
742 dataStore(std::ostream & stream, Vec & v,
void * context)
745 LibmeshPetscCallA(PETSC_COMM_WORLD, VecGetLocalSize(v, &local_size));
747 LibmeshPetscCallA(PETSC_COMM_WORLD, VecGetArray(v, &array));
748 for (PetscInt i = 0; i < local_size; i++)
751 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 *)