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 
21 namespace libMesh
22 {
23 class DofObject;
24 class EquationSystems;
25 class MeshBase;
26 }
27 
32 {
33 public:
35 
39  struct VectorHeader
40  {
41  bool operator==(const VectorHeader & other) const
42  {
43  return name == other.name && projections == other.projections &&
44  variable_offset == other.variable_offset && vector == other.vector;
45  }
46 
48  std::string name;
54  std::map<std::string, std::size_t> variable_offset;
57  };
58 
63  {
64  bool operator==(const VariableHeader & other) const
65  {
66  return name == other.name && type == other.type && size == other.size &&
67  variable == other.variable;
68  }
69 
71  std::string name;
75  std::size_t size = 0;
77  const libMesh::Variable * variable = nullptr;
78  };
79 
83  struct SystemHeader
84  {
85  bool operator==(const SystemHeader & other) const
86  {
87  return name == other.name && type == other.type && variables == other.variables &&
88  vectors == other.vectors;
89  }
90 
92  std::string name;
94  std::string type;
96  std::map<std::string, RestartableEquationSystems::VariableHeader> variables;
98  std::map<std::string, RestartableEquationSystems::VectorHeader> vectors;
100  static const std::string system_solution_name;
101  };
102 
107  {
108  bool operator==(const EquationSystemsHeader & other) const { return systems == other.systems; }
109 
111  std::map<std::string, RestartableEquationSystems::SystemHeader> systems;
113  std::size_t data_size = 0;
114  };
115 
119  void store(std::ostream & stream) const;
123  void load(std::istream & stream);
124 
128  libMesh::EquationSystems & es() { return _es; }
130  const libMesh::EquationSystems & es() const { return _es; }
132 
143  void setLoadAllVectors(const bool load_all_vectors) { _load_all_vectors = load_all_vectors; }
144 
145 private:
147  EquationSystemsHeader
148  buildHeader(const std::vector<const libMesh::DofObject *> & ordered_objects) const;
149 
151  std::vector<const libMesh::DofObject *> orderDofObjects() const;
152 
153  void restore(const SystemHeader & from_sys_header,
154  const VectorHeader & from_vec_header,
155  const VariableHeader & from_var_header,
156  const libMesh::System & to_sys,
158  const libMesh::Variable & to_var,
159  std::istream & stream);
160 
163 
169  std::vector<const libMesh::DofObject *> _loaded_ordered_objects;
172 };
173 
174 void dataStore(std::ostream & stream, RestartableEquationSystems & res, void *);
175 void dataLoad(std::istream & stream, RestartableEquationSystems & res, void *);
176 
177 void dataStore(std::ostream & stream,
179  void *);
180 void
181 dataLoad(std::istream & stream, RestartableEquationSystems::EquationSystemsHeader & header, void *);
182 
183 void dataStore(std::ostream & stream, RestartableEquationSystems::SystemHeader & header, void *);
184 void dataLoad(std::istream & stream, RestartableEquationSystems::SystemHeader & header, void *);
185 
186 void dataStore(std::ostream & stream, RestartableEquationSystems::VariableHeader & header, void *);
187 void dataLoad(std::istream & stream, RestartableEquationSystems::VariableHeader & header, void *);
188 
189 void dataStore(std::ostream & stream, RestartableEquationSystems::VectorHeader & header, void *);
190 void dataLoad(std::istream & stream, RestartableEquationSystems::VectorHeader & header, void *);
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.
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
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 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::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.