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" 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);
57 stream.write((
char *)&v,
sizeof(v));
62 dataStore(std::ostream & stream, std::vector<bool> & v,
void * context)
95 if (DualReal::do_derivatives)
97 auto & derivatives = dn.derivatives();
98 std::size_t size = derivatives.size();
100 for (MooseIndex(size) i = 0; i < size; ++i)
102 dataStore(stream, derivatives.raw_index(i), context);
103 dataStore(stream, derivatives.raw_at(i), context);
110 dataStore(std::ostream & stream,
const Elem *& e,
void * context)
119 mooseError(
"Can't output Elems with invalid ids!");
127 dataStore(std::ostream & stream,
const Node *& n,
void * context)
136 mooseError(
"Can't output Nodes with invalid ids!");
144 dataStore(std::ostream & stream, Elem *& e,
void * context)
153 mooseError(
"Can't output Elems with invalid ids!");
161 dataStore(std::ostream & stream, Node *& n,
void * context)
170 mooseError(
"Can't output Nodes with invalid ids!");
178 dataStore(std::ostream & stream, std::stringstream & s,
void * )
180 const std::string & s_str = s.str();
182 size_t s_size = s_str.size();
183 stream.write((
char *)&s_size,
sizeof(s_size));
185 stream.write(s_str.c_str(),
sizeof(char) * (s_str.size()));
192 unsigned int m = v.size();
193 stream.write((
char *)&m,
sizeof(m));
194 for (
unsigned int i = 0; i < v.size(); i++)
205 unsigned int m = v.rows();
206 stream.write((
char *)&m,
sizeof(m));
207 unsigned int n = v.cols();
208 stream.write((
char *)&n,
sizeof(n));
209 for (
unsigned int i = 0; i < m; i++)
210 for (
unsigned int j = 0; j < n; j++)
217 template <
typename T>
219 dataStore(std::ostream & stream, TensorValue<T> & v,
void * context)
229 template void dataStore(std::ostream & stream, TensorValue<Real> & v,
void * context);
230 template void dataStore(std::ostream & stream, TensorValue<DualReal> & v,
void * context);
232 template <
typename T>
234 dataStore(std::ostream & stream, DenseMatrix<T> & v,
void * context)
236 unsigned int m = v.m();
237 unsigned int n = v.n();
238 stream.write((
char *)&m,
sizeof(m));
239 stream.write((
char *)&n,
sizeof(n));
240 for (
unsigned int i = 0; i < m; i++)
241 for (
unsigned int j = 0; j < n; j++)
249 template void dataStore(std::ostream & stream, DenseMatrix<DualReal> & v,
void * context);
251 template <
typename T>
253 dataStore(std::ostream & stream, VectorValue<T> & v,
void * context)
265 template void dataStore(std::ostream & stream, VectorValue<DualReal> & v,
void * context);
268 dataStore(std::ostream & stream, Point & p,
void * context)
283 stream.write((
char *)&size,
sizeof(size));
288 for (; it != end; ++it)
290 auto & key =
const_cast<std::string &
>(it->first);
291 auto type = it->second->type();
296 #define storescalar(ptype) \ 297 else if (it->second->type() == demangle(typeid(ptype).name())) storeHelper( \ 299 (dynamic_cast<libMesh::Parameters::Parameter<ptype> *>(MooseUtils::get(it->second)))->get(), \ 308 storescalar(
unsigned short);
309 storescalar(
unsigned int);
310 storescalar(
unsigned long);
322 mooseAssert(v,
"Null vector");
323 mooseAssert(context,
"Needs a context of the communicator");
325 mooseAssert(&comm == &v->comm(),
"Inconsistent communicator");
328 mooseError(
"Cannot store ghosted numeric vectors");
331 unsigned int comm_size = comm.size();
339 mooseError(
"Can only store unique_ptrs of PetscVectors");
340 int solver_package_int = solver_package;
341 dataStore(stream, solver_package_int,
nullptr);
359 stream.read((
char *)&v,
sizeof(v));
364 dataLoad(std::istream & stream, std::string & v,
void * )
367 unsigned int size = 0;
368 stream.read((
char *)&size,
sizeof(size));
374 stream.read(&v[0],
sizeof(
char) * size);
379 dataLoad(std::istream & stream, VariableName & v,
void * context)
381 auto &
name =
static_cast<std::string &
>(v);
389 stream.read((
char *)&v,
sizeof(v));
394 dataLoad(std::istream & stream, std::vector<bool> & v,
void * context)
404 dataLoad(stream, dn.value(), context);
406 if (DualReal::do_derivatives)
408 auto & derivatives = dn.derivatives();
409 std::size_t size = 0;
410 stream.read((
char *)&size,
sizeof(size));
411 derivatives.resize(size);
413 for (MooseIndex(derivatives) i = 0; i < derivatives.size(); ++i)
415 dataLoad(stream, derivatives.raw_index(i), context);
416 dataLoad(stream, derivatives.raw_at(i), context);
423 dataLoad(std::istream & stream,
const Elem *& e,
void * context)
426 mooseError(
"Can only load Elem objects using a MooseMesh context!");
436 e =
mesh->elemPtr(
id);
443 dataLoad(std::istream & stream,
const Node *& n,
void * context)
446 mooseError(
"Can only load Node objects using a MooseMesh context!");
456 n =
mesh->nodePtr(
id);
463 dataLoad(std::istream & stream, Elem *& e,
void * context)
466 mooseError(
"Can only load Elem objects using a MooseMesh context!");
476 e =
mesh->elemPtr(
id);
483 dataLoad(std::istream & stream, Node *& n,
void * context)
486 mooseError(
"Can only load Node objects using a MooseMesh context!");
496 n =
mesh->nodePtr(
id);
503 dataLoad(std::istream & stream, std::stringstream & s,
void * )
506 stream.read((
char *)&s_size,
sizeof(s_size));
508 std::unique_ptr<char[]> s_s = std::make_unique<char[]>(s_size);
509 stream.read(s_s.get(), s_size);
512 s.str(std::string());
513 s.write(s_s.get(), s_size);
521 stream.read((
char *)&n,
sizeof(n));
523 for (
unsigned int i = 0; i < n; i++)
536 stream.read((
char *)&m,
sizeof(m));
538 stream.read((
char *)&n,
sizeof(n));
540 for (
unsigned int i = 0; i < m; i++)
541 for (
unsigned int j = 0; j < n; j++)
549 template <
typename T>
551 dataLoad(std::istream & stream, TensorValue<T> & v,
void * context)
564 template void dataLoad(std::istream & stream, TensorValue<Real> & v,
void * context);
565 template void dataLoad(std::istream & stream, TensorValue<DualReal> & v,
void * context);
567 template <
typename T>
569 dataLoad(std::istream & stream, DenseMatrix<T> & v,
void * context)
571 unsigned int m = 0, n = 0;
572 stream.read((
char *)&m,
sizeof(m));
573 stream.read((
char *)&n,
sizeof(n));
575 for (
unsigned int i = 0; i < m; i++)
576 for (
unsigned int j = 0; j < n; j++)
585 template void dataLoad(std::istream & stream, DenseMatrix<DualReal> & v,
void * context);
587 template <
typename T>
589 dataLoad(std::istream & stream, VectorValue<T> & v,
void * context)
602 template void dataLoad(std::istream & stream, VectorValue<DualReal> & v,
void * context);
605 dataLoad(std::istream & stream, Point & p,
void * context)
622 unsigned int size = 0;
623 stream.read((
char *)&size,
sizeof(size));
625 for (
unsigned int i = 0; i < size; i++)
627 std::string key, type;
631 #define loadscalar(ptype) \ 632 else if (type == demangle(typeid(ptype).name())) do \ 634 ptype & value = p.set<ptype>(key); \ 635 loadHelper(stream, value, context); \ 645 loadscalar(
unsigned short);
646 loadscalar(
unsigned int);
647 loadscalar(
unsigned long);
657 mooseAssert(context,
"Needs a context of the communicator");
660 mooseAssert(&comm == &v->comm(),
"Inconsistent communicator");
663 unsigned int comm_size;
664 dataLoad(stream, comm_size,
nullptr);
665 mooseAssert(comm.size() == comm_size,
"Inconsistent communicator size");
668 int solver_package_int;
669 dataLoad(stream, solver_package_int,
nullptr);
675 dataLoad(stream, local_size,
nullptr);
682 v->init(size, local_size);
685 mooseAssert(v->type() !=
GHOSTED,
"Cannot be ghosted");
689 mooseAssert(v->size() == size,
"Inconsistent size");
690 mooseAssert(v->local_size() == local_size,
"Inconsistent local size");
698 dataLoad(std::istream & stream, Vec & v,
void * context)
701 VecGetLocalSize(v, &local_size);
703 VecGetArray(v, &array);
704 for (PetscInt i = 0; i < local_size; i++)
705 dataLoad(stream, array[i], context);
707 VecRestoreArray(v, &array);
712 dataStore(std::ostream & stream, Vec & v,
void * context)
715 VecGetLocalSize(v, &local_size);
717 VecGetArray(v, &array);
718 for (PetscInt i = 0; i < local_size; i++)
721 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...
DualNumber< Real, DNDerivativeType, true > DualReal
static constexpr std::size_t dim
This is the dimension of all vector and tensor datastructures used in MOOSE.
T _coords[LIBMESH_DIM *LIBMESH_DIM]
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
static std::unique_ptr< NumericVector< Number > > build(const Parallel::Communicator &comm, const SolverPackage solver_package=libMesh::default_solver_package())
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
IntRange< T > make_range(T beg, T end)
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 *)