https://mooseframework.inl.gov
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 
15 #include "libmesh/int_range.h"
16 
18 
19 namespace
20 {
21 void
22 storeGridFunction(std::ostream & stream, mfem::ParGridFunction & gridfunction, void * context)
23 {
24  const auto size = gridfunction.Size();
25  dataStore(stream, size, context);
26 
27  const auto * values = gridfunction.HostRead();
28  for (const auto i : make_range(size))
29  {
30  auto value = values[i];
31  dataStore(stream, value, context);
32  }
33 }
34 
35 void
36 loadGridFunction(std::istream & stream, mfem::ParGridFunction & gridfunction, void * context)
37 {
38  int size = 0;
39  dataLoad(stream, size, context);
40  mooseAssert(size == gridfunction.Size(),
41  "MFEM restartable GridFunction size mismatch during restore.");
42 
43  auto * values = gridfunction.HostWrite();
44  for (const auto i : make_range(size))
45  dataLoad(stream, values[i], context);
46 }
47 }
48 
49 template <>
50 void
51 dataStore(std::ostream & stream, Moose::MFEM::SolutionState & /*state*/, void * context)
52 {
53  auto * const data = static_cast<MFEMProblemData *>(context);
54 
55  auto num_gridfunctions = data->gridfunctions.size();
56  dataStore(stream, num_gridfunctions, context);
57  for (const auto & [name, gridfunction] : data->gridfunctions)
58  {
59  auto stored_name = name;
60  dataStore(stream, stored_name, context);
61  storeGridFunction(stream, *gridfunction, context);
62  }
63 
64  auto num_complex_gridfunctions = data->cmplx_gridfunctions.size();
65  dataStore(stream, num_complex_gridfunctions, context);
66  for (const auto & [name, gridfunction] : data->cmplx_gridfunctions)
67  {
68  auto stored_name = name;
69  dataStore(stream, stored_name, context);
70  storeGridFunction(stream, gridfunction->real(), context);
71  storeGridFunction(stream, gridfunction->imag(), context);
72  }
73 }
74 
75 template <>
76 void
77 dataLoad(std::istream & stream, Moose::MFEM::SolutionState & /*state*/, void * context)
78 {
79  auto * const data = static_cast<MFEMProblemData *>(context);
80 
81  int num_gridfunctions = 0;
82  dataLoad(stream, num_gridfunctions, context);
83  for (int i = 0; i < num_gridfunctions; ++i)
84  {
85  std::string name;
86  dataLoad(stream, name, context);
87  auto & gf = data->gridfunctions.GetRef(name);
88  loadGridFunction(stream, gf, context);
89  }
90 
91  int num_complex_gridfunctions = 0;
92  dataLoad(stream, num_complex_gridfunctions, context);
93  for (int i = 0; i < num_complex_gridfunctions; ++i)
94  {
95  std::string name;
96  dataLoad(stream, name, context);
97  auto & gf = data->cmplx_gridfunctions.GetRef(name);
98  loadGridFunction(stream, gf.real(), context);
99  loadGridFunction(stream, gf.imag(), context);
100  }
101 }
102 
103 #endif
std::string name(const ElemQuality q)
Base problem data struct.
void dataLoad(std::istream &stream, Moose::MFEM::SolutionState &, void *context)
Real value(unsigned n, unsigned alpha, unsigned beta, Real x)
void dataStore(std::ostream &stream, Moose::MFEM::SolutionState &, void *context)
IntRange< T > make_range(T beg, T end)
int size()
Returns the number of elements in the map.
Moose::MFEM::GridFunctions gridfunctions