https://mooseframework.inl.gov
RestartableEquationSystems.h
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 #pragma once
11 
12 #include <set>
13 #include <string>
14 #include <unordered_map>
15 #include <iostream>
16 
17 #include "libmesh/enum_order.h"
18 #include "libmesh/fe_type.h"
19 #include "libmesh/equation_systems.h"
20 #include "nlohmann/json.h"
21 
22 namespace libMesh
23 {
24 class DofObject;
25 class EquationSystems;
26 class MeshBase;
27 }
28 
33 {
34 public:
36 
40  struct VectorHeader
41  {
42  bool operator==(const VectorHeader & other) const
43  {
44  return name == other.name && projections == other.projections &&
45  variable_offset == other.variable_offset && vector == other.vector;
46  }
47 
49  std::string name;
55  std::map<std::string, std::size_t> variable_offset;
58  };
59 
64  {
65  bool operator==(const VariableHeader & other) const
66  {
67  return name == other.name && type == other.type && size == other.size &&
68  variable == other.variable;
69  }
70 
72  std::string name;
76  std::size_t size = 0;
78  const libMesh::Variable * variable = nullptr;
79  };
80 
84  struct SystemHeader
85  {
86  bool operator==(const SystemHeader & other) const
87  {
88  return name == other.name && type == other.type && variables == other.variables &&
89  vectors == other.vectors;
90  }
91 
93  std::string name;
95  std::string type;
97  std::map<std::string, RestartableEquationSystems::VariableHeader> variables;
99  std::map<std::string, RestartableEquationSystems::VectorHeader> vectors;
101  static const std::string system_solution_name;
102  };
103 
108  {
109  bool operator==(const EquationSystemsHeader & other) const { return systems == other.systems; }
110 
112  std::map<std::string, RestartableEquationSystems::SystemHeader> systems;
114  std::size_t data_size = 0;
115  };
116 
120  void store(std::ostream & stream) const;
124  void load(std::istream & stream);
125 
129  libMesh::EquationSystems & es() { return _es; }
131  const libMesh::EquationSystems & es() const { return _es; }
133 
144  void setLoadAllVectors(const bool load_all_vectors) { _load_all_vectors = load_all_vectors; }
145 
147  bool isVariableRestored(const std::string & system_name,
148  const std::string & vector_name,
149  const std::string & variable_name) const;
150 
152  const std::set<std::tuple<std::string, std::string, std::string>> & getLoadedVariables() const
153  {
154  return _loaded_variables;
155  }
156 
157 private:
159  EquationSystemsHeader
160  buildHeader(const std::vector<const libMesh::DofObject *> & ordered_objects) const;
161 
163  std::vector<const libMesh::DofObject *> orderDofObjects() const;
164 
165  void restore(const SystemHeader & from_sys_header,
166  const VectorHeader & from_vec_header,
167  const VariableHeader & from_var_header,
168  const libMesh::System & to_sys,
170  const libMesh::Variable & to_var,
171  std::istream & stream);
172 
175 
181  std::vector<const libMesh::DofObject *> _loaded_ordered_objects;
184 
186  std::set<std::tuple<std::string, std::string, std::string>> _loaded_variables;
187 };
188 
189 void dataStore(std::ostream & stream, RestartableEquationSystems & res, void *);
190 void dataLoad(std::istream & stream, RestartableEquationSystems & res, void *);
191 
192 void dataStore(std::ostream & stream,
194  void *);
195 void
196 dataLoad(std::istream & stream, RestartableEquationSystems::EquationSystemsHeader & header, void *);
197 
198 void dataStore(std::ostream & stream, RestartableEquationSystems::SystemHeader & header, void *);
199 void dataLoad(std::istream & stream, RestartableEquationSystems::SystemHeader & header, void *);
200 
201 void dataStore(std::ostream & stream, RestartableEquationSystems::VariableHeader & header, void *);
202 void dataLoad(std::istream & stream, RestartableEquationSystems::VariableHeader & header, void *);
203 
204 void dataStore(std::ostream & stream, RestartableEquationSystems::VectorHeader & header, void *);
205 void dataLoad(std::istream & stream, RestartableEquationSystems::VectorHeader & header, void *);
206 
207 void to_json(nlohmann::json & json, const RestartableEquationSystems & res);
bool operator==(const SystemHeader &other) const
libMesh::FEType type
The type of the stored variable.
void store(std::ostream &stream) const
Stores the EquationSystems to the given stream.
void restore(const SystemHeader &from_sys_header, const VectorHeader &from_vec_header, const VariableHeader &from_var_header, const libMesh::System &to_sys, libMesh::NumericVector< libMesh::Number > &to_vec, const libMesh::Variable &to_var, std::istream &stream)
std::size_t data_size
The total size of data for this EquationSystems.
std::size_t _loaded_stream_data_begin
The starting position for the vector data in the input stream.
const std::set< std::tuple< std::string, std::string, std::string > > & getLoadedVariables() const
Returns the set of variables that were loaded during the load() function. Each set of variables conta...
std::size_t size
The size of this variable&#39;s data.
MeshBase & mesh
The following methods are specializations for using the libMesh::Parallel::packed_range_* routines fo...
bool projections
The projection flag (whether or not it should be projected or zeroed)
const libMesh::NumericVector< libMesh::Number > * vector
The underlying vector (only valid during store, not used in load)
std::string name
The name of the stored vector.
libMesh::EquationSystems _es
The underlying EquationSystems.
bool operator==(const VariableHeader &other) const
void to_json(nlohmann::json &json, const RestartableEquationSystems &res)
std::string name
The name of the stored variable.
std::map< std::string, RestartableEquationSystems::SystemHeader > systems
The stored systems in the equation systems.
RestartableEquationSystems(libMesh::MeshBase &mesh)
std::string name
The name of the stored system.
void dataStore(std::ostream &stream, RestartableEquationSystems &res, void *)
std::map< std::string, RestartableEquationSystems::VectorHeader > vectors
The stored vectors in the system.
static const std::string system_solution_name
Special name for a vector that is the system solution vector.
const libMesh::EquationSystems & es() const
std::map< std::string, RestartableEquationSystems::VariableHeader > variables
The stored variables in the system.
bool isVariableRestored(const std::string &system_name, const std::string &vector_name, const std::string &variable_name) const
Checks whether variable was successfully restored from a restart file.
bool operator==(const EquationSystemsHeader &other) const
void load(std::istream &stream)
Loads the EquationSystems from the given stream.
Represents a stored system in restart.
std::string type
The type of the stored system.
EquationSystemsHeader _loaded_header
The loaded header.
libMesh::ParallelType type
The type of the stored vector.
bool _load_all_vectors
Whether or not to load all of the vectors, including ones that haven&#39;t been added yet...
const libMesh::Variable * variable
The underlying variable (only valid during store, not used in load)
void setLoadAllVectors(const bool load_all_vectors)
Sets whether or not all vectors are to be loaded.
Wrapper class that owns a libMesh EquationSystem and adds advanced restart capability to it...
bool operator==(const VectorHeader &other) const
std::vector< const libMesh::DofObject * > _loaded_ordered_objects
The object ordering for this data.
std::vector< const libMesh::DofObject * > orderDofObjects() const
Internal method for ordering the DofObjects by ID (elems and the nodes)
libMesh::EquationSystems & es()
std::set< std::tuple< std::string, std::string, std::string > > _loaded_variables
The variables that were loaded in load(); [system name, vector name, variable name].
std::map< std::string, std::size_t > variable_offset
The position of each variable for this vector (relative to the start of the data) ...
Represents a stored EquationSystems in restart.
Represents a stored variable in restart.
void dataLoad(std::istream &stream, RestartableEquationSystems &res, void *)
EquationSystemsHeader buildHeader(const std::vector< const libMesh::DofObject *> &ordered_objects) const
Internal method for building the header struct.
Represents a stored variable in restart.