https://mooseframework.inl.gov
Loading...
Searching...
No Matches
SolutionStateData.C
Go to the documentation of this file.
1//* This file is part of the MOOSE framework
2//* https://mooseframework.inl.gov
3//*
4//* All rights reserved, see COPYRIGHT for full restrictions
5//* https://github.com/idaholab/moose/blob/master/COPYRIGHT
6//*
7//* Licensed under LGPL 2.1, please see LICENSE for details
8//* https://www.gnu.org/licenses/lgpl-2.1.html
9
10#ifdef MOOSE_MFEM_ENABLED
11
12#include "DataIO.h"
13#include "MFEMProblemData.h"
14
15namespace
16{
17void
18storeGridFunction(std::ostream & stream, mfem::ParGridFunction & gridfunction, void * context)
19{
20 const auto size = gridfunction.Size();
21 dataStore(stream, size, context);
22
23 const auto * values = gridfunction.HostRead();
24 for (const auto i : make_range(size))
25 {
26 auto value = values[i];
27 dataStore(stream, value, context);
28 }
29}
30
31void
32loadGridFunction(std::istream & stream, mfem::ParGridFunction & gridfunction, void * context)
33{
34 int size = 0;
35 dataLoad(stream, size, context);
36 mooseAssert(size == gridfunction.Size(),
37 "MFEM restartable GridFunction size mismatch during restore.");
38
39 auto * values = gridfunction.HostWrite();
40 for (const auto i : make_range(size))
41 dataLoad(stream, values[i], context);
42}
43}
44
45template <>
46void
47dataStore(std::ostream & stream, Moose::MFEM::SolutionState & /*state*/, void * context)
48{
49 auto * const data = static_cast<MFEMProblemData *>(context);
50
51 auto num_gridfunctions = data->gridfunctions.size();
52 dataStore(stream, num_gridfunctions, context);
53 for (const auto & [name, gridfunction] : data->gridfunctions)
54 {
55 auto stored_name = name;
56 dataStore(stream, stored_name, context);
57 storeGridFunction(stream, *gridfunction, context);
58 }
59
60 auto num_complex_gridfunctions = data->cmplx_gridfunctions.size();
61 dataStore(stream, num_complex_gridfunctions, context);
62 for (const auto & [name, gridfunction] : data->cmplx_gridfunctions)
63 {
64 auto stored_name = name;
65 dataStore(stream, stored_name, context);
66 storeGridFunction(stream, gridfunction->real(), context);
67 storeGridFunction(stream, gridfunction->imag(), context);
68 }
69}
70
71template <>
72void
73dataLoad(std::istream & stream, Moose::MFEM::SolutionState & /*state*/, void * context)
74{
75 auto * const data = static_cast<MFEMProblemData *>(context);
76
77 int num_gridfunctions = 0;
78 dataLoad(stream, num_gridfunctions, context);
79 for ([[maybe_unused]] const auto i : make_range(num_gridfunctions))
80 {
81 std::string name;
82 dataLoad(stream, name, context);
83 auto & gf = data->gridfunctions.GetRef(name);
84 loadGridFunction(stream, gf, context);
85 }
86
87 int num_complex_gridfunctions = 0;
88 dataLoad(stream, num_complex_gridfunctions, context);
89 for ([[maybe_unused]] const auto i : make_range(num_complex_gridfunctions))
90 {
91 std::string name;
92 dataLoad(stream, name, context);
93 auto & gf = data->cmplx_gridfunctions.GetRef(name);
94 loadGridFunction(stream, gf.real(), context);
95 loadGridFunction(stream, gf.imag(), context);
96 }
97}
98
99#endif
std::array< Real, 2 > values
Definition MortarUtils.C:52
void dataStore(std::ostream &stream, Moose::MFEM::SolutionState &, void *context)
void dataLoad(std::istream &stream, Moose::MFEM::SolutionState &, void *context)
int size()
Returns the number of elements in the map.
Real value(unsigned n, unsigned alpha, unsigned beta, Real x)
IntRange< T > make_range(T beg, T end)
Base problem data struct.
Moose::MFEM::GridFunctions gridfunctions