https://mooseframework.inl.gov
Loading...
Searching...
No Matches
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
22namespace libMesh
23{
24class DofObject;
25class EquationSystems;
26class MeshBase;
27}
28
33{
34public:
36
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
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
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
157private:
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
189void dataStore(std::ostream & stream, RestartableEquationSystems & res, void *);
190void dataLoad(std::istream & stream, RestartableEquationSystems & res, void *);
191
192void dataStore(std::ostream & stream,
194 void *);
195void
196dataLoad(std::istream & stream, RestartableEquationSystems::EquationSystemsHeader & header, void *);
197
198void dataStore(std::ostream & stream, RestartableEquationSystems::SystemHeader & header, void *);
199void dataLoad(std::istream & stream, RestartableEquationSystems::SystemHeader & header, void *);
200
201void dataStore(std::ostream & stream, RestartableEquationSystems::VariableHeader & header, void *);
202void dataLoad(std::istream & stream, RestartableEquationSystems::VariableHeader & header, void *);
203
204void dataStore(std::ostream & stream, RestartableEquationSystems::VectorHeader & header, void *);
205void dataLoad(std::istream & stream, RestartableEquationSystems::VectorHeader & header, void *);
206
207void to_json(nlohmann::json & json, const RestartableEquationSystems & res);
void dataLoad(std::istream &stream, RestartableEquationSystems &res, void *)
void to_json(nlohmann::json &json, const RestartableEquationSystems &res)
void dataStore(std::ostream &stream, RestartableEquationSystems &res, void *)
Wrapper class that owns a libMesh EquationSystem and adds advanced restart capability to it.
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.
std::vector< const libMesh::DofObject * > orderDofObjects() const
Internal method for ordering the DofObjects by ID (elems and the nodes)
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)
libMesh::EquationSystems & es()
const libMesh::EquationSystems & es() const
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].
void setLoadAllVectors(const bool load_all_vectors)
Sets whether or not all vectors are to be loaded.
void store(std::ostream &stream) const
Stores the EquationSystems to the given stream.
bool _load_all_vectors
Whether or not to load all of the vectors, including ones that haven't been added yet.
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 _loaded_stream_data_begin
The starting position for the vector data in the input stream.
EquationSystemsHeader _loaded_header
The loaded header.
void load(std::istream &stream)
Loads the EquationSystems from the given stream.
libMesh::EquationSystems _es
The underlying EquationSystems.
EquationSystemsHeader buildHeader(const std::vector< const libMesh::DofObject * > &ordered_objects) const
Internal method for building the header struct.
std::vector< const libMesh::DofObject * > _loaded_ordered_objects
The object ordering for this data.
MeshBase & mesh
The following methods are specializations for using the libMesh::Parallel::packed_range_* routines fo...
Represents a stored EquationSystems in restart.
std::map< std::string, RestartableEquationSystems::SystemHeader > systems
The stored systems in the equation systems.
bool operator==(const EquationSystemsHeader &other) const
std::size_t data_size
The total size of data for this EquationSystems.
Represents a stored system in restart.
std::map< std::string, RestartableEquationSystems::VariableHeader > variables
The stored variables in the system.
std::string type
The type of the stored system.
bool operator==(const SystemHeader &other) const
static const std::string system_solution_name
Special name for a vector that is the system solution vector.
std::string name
The name of the stored system.
std::map< std::string, RestartableEquationSystems::VectorHeader > vectors
The stored vectors in the system.
Represents a stored variable in restart.
bool operator==(const VariableHeader &other) const
const libMesh::Variable * variable
The underlying variable (only valid during store, not used in load)
std::size_t size
The size of this variable's data.
std::string name
The name of the stored variable.
libMesh::FEType type
The type of the stored variable.
Represents a stored variable in restart.
bool operator==(const VectorHeader &other) const
std::string name
The name of the stored vector.
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)
libMesh::ParallelType type
The type of the stored vector.
std::map< std::string, std::size_t > variable_offset
The position of each variable for this vector (relative to the start of the data)