13 #include <petscdmda.h> 21 params.
addClassDescription(
"Class which provides a Proper Orthogonal Decomposition-based mapping " 22 "between full-order and reduced-order spaces.");
24 "solution_storage",
"The name of the storage reporter where the snapshots are located.");
25 params.
addParam<std::vector<dof_id_type>>(
26 "num_modes_to_compute",
27 "The number of modes that this object should compute. " 28 "Modes with 0 eigenvalues are filtered out, so the real number of modes " 29 "might be lower than this. This is also used for setting the " 30 "subspace sizes for distributed singular value solves. By default, the subspace used for the " 31 "SVD is twice as big as the number of requested vectors. For more information see the SLEPc " 32 "manual. If not specified, only one mode is computed per variable.");
36 "The energy threshold for the automatic truncation of the number of modes. In general, the " 37 "lower this number is the more information is retained about the system by keeping more POD " 39 params.
addParam<std::string>(
"extra_slepc_options",
41 "Additional options for the singular/eigenvalue solvers in SLEPc.");
48 _num_modes(isParamValid(
"num_modes_to_compute")
51 _energy_threshold(getParam<
std::vector<
Real>>(
"energy_threshold")),
52 _left_basis_functions(declareModelData<
std::map<VariableName,
std::vector<DenseVector<
Real>>>>(
53 "left_basis_functions")),
54 _right_basis_functions(declareModelData<
std::map<VariableName,
std::vector<DenseVector<
Real>>>>(
55 "right_basis_functions")),
57 declareModelData<
std::map<VariableName,
std::vector<
Real>>>(
"singular_values")),
58 _extra_slepc_options(getParam<
std::string>(
"extra_slepc_options")),
59 _parallel_storage(isParamValid(
"solution_storage")
62 _pod(
StochasticTools::POD(_parallel_storage, _extra_slepc_options, _communicator))
67 paramError(
"num_modes",
"The number of modes should be defined for each variable!");
71 paramError(
"num_modes",
"The number of modes should always be a positive integer!");
77 "The energy thresholds should be defined for each variable!");
80 if (threshold < 0 || threshold >= 1)
82 "The energy thresholds should always be in the [0,1) range!");
85 #if PETSC_VERSION_LESS_THAN(3, 14, 0) 86 mooseError(
"PODMapping is not supported with PETSc version below 3.14!");
101 #
if !PETSC_VERSION_LESS_THAN(3, 14, 0)
106 #if !PETSC_VERSION_LESS_THAN(3, 14, 0) 110 "The parallel storage reporter is not supplied! We cannot build a mapping without data!");
116 mooseAssert(it !=
_variable_names.end(),
"Variable " + vname +
" is not in PODMapping!");
123 std::size_t num_modes_compute = (std::size_t)
_num_modes[var_i];
126 std::numeric_limits<Real>::epsilon();
142 const unsigned int global_sample_i,
143 std::vector<Real> & reduced_order_vector)
const 145 mooseAssert(
_parallel_storage,
"We need the parallel solution storage for this operation.");
147 "The bases for the requested variable are not available!");
156 reduced_order_vector.clear();
157 reduced_order_vector.resize(bases.size());
159 reduced_order_vector[base_i] = bases[base_i].dot(snapshot);
164 const DenseVector<Real> & full_order_vector,
165 std::vector<Real> & reduced_order_vector)
const 170 "The bases for the requested variable are not available!");
174 reduced_order_vector.clear();
175 reduced_order_vector.resize(bases.size());
177 reduced_order_vector[base_i] = bases[base_i].dot(full_order_vector);
182 const std::vector<Real> & reduced_order_vector,
183 DenseVector<Real> & full_order_vector)
const 187 "Variable " + vname +
" is not in PODMapping!");
192 mooseError(
"The number of supplied reduced-order coefficients (",
193 reduced_order_vector.size(),
194 ") is not the same as the number of basis functions (",
202 for (
auto base_i :
index_range(reduced_order_vector))
204 full_order_vector(dof_i) +=
208 const DenseVector<Real> &
213 "Variable " + vname +
" is not in PODMapping!");
218 "The POD for " + vname +
" only has " +
224 const DenseVector<Real> &
229 "Variable " + vname +
" is not in PODMapping!");
234 "The POD for " + vname +
" only has " +
240 const std::vector<DenseVector<Real>> &
245 mooseError(
"We are trying to access container for variable '",
247 "' but we don't have it in the POD mapping!");
251 const std::vector<DenseVector<Real>> &
256 mooseError(
"We are trying to access container for variable '",
258 "' but we don't have it in the POD mapping!");
262 const std::vector<Real> &
267 mooseError(
"We are trying to access container for variable '",
269 "' but we don't have it in the POD mapping!");
std::map< VariableName, bool > & _mapping_ready_to_use
Bool to decide if we already have the mapping built or not to make sure it is not computed multiple t...
const std::vector< Real > & singularValues(const VariableName &vname)
Return all of the singular values for a given variable.
const std::vector< DenseVector< Real > > & leftBasis(const VariableName &vname)
Return all of the left basis functions for a given variable.
static InputParameters validParams()
std::map< VariableName, std::vector< DenseVector< Real > > > & _left_basis_functions
Restartable container holding the basis functions for each variable.
virtual void buildMapping(const VariableName &vname) override
Abstract function for building mapping for a given variable.
bool isParamValid(const std::string &name) const
void checkIfReadyToUse(const VariableName &libmesh_dbg_var(vname)) const
Check if we have a mapping for the variable and if it is ready to be used.
PODMapping(const InputParameters ¶meters)
std::map< VariableName, std::vector< Real > > & _singular_values
Restartable container holding the singular values.
void paramError(const std::string ¶m, Args... args) const
void inverse_map(const VariableName &vname, const std::vector< Real > &reduced_order_vector, DenseVector< Real > &full_order_vector) const override
Method used for mapping reduced-order solutions for a given variable onto the full-order space...
const std::vector< dof_id_type > _num_modes
The number of modes which need to be computed.
const ParallelSolutionStorage *const _parallel_storage
Link to the parallel storage which holds the solution fields that are used for the SVD...
void map(const VariableName &vname, const DenseVector< Real > &full_order_vector, std::vector< Real > &reduced_order_vector) const override
Method used for mapping full-order solutions for a given variable onto a latent space.
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
const DenseVector< Real > & rightBasisFunction(const VariableName &vname, const unsigned int base_i)
Get the base_i-th right basis function for a given variable.
std::map< VariableName, std::vector< DenseVector< Real > > > & _right_basis_functions
Restartable container holding the basis functions for each variable.
Class which provides a Proper Orthogonal Decomposition (POD)-based mapping between full-order and red...
registerMooseObject("StochasticToolsApp", PODMapping)
void mooseError(Args &&... args) const
const std::vector< DenseVector< Real > > & getGlobalSample(unsigned int global_sample_i, const VariableName &variable) const
Get the serialized solution field which is associated with a given global sample index and variable...
const DenseVector< Real > & leftBasisFunction(const VariableName &vname, const unsigned int base_i)
Get the base_i-th left basis function for a given variable.
const std::vector< VariableName > & _variable_names
Storage for the names of the variables this mapping can handle.
This is an abstract base class for objects that provide mapping between a full-order and a latent spa...
const std::vector< DenseVector< Real > > & rightBasis(const VariableName &vname)
Return all of the right basis functions for a given variable.
static InputParameters validParams()
const StochasticTools::POD _pod
The POD object which can be used to compute the basis functions/vectors.
auto index_range(const T &sizable)
A Reporter which stores serialized solution fields for given variables in a distributed fashion...
const std::vector< Real > & _energy_threshold
The energy thresholds for truncation of the number of modes, defined by the user. ...