https://mooseframework.inl.gov
Loading...
Searching...
No Matches
SingularTripletReporter.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
11#include "JsonIO.h"
12
14
17{
20
21 params.addClassDescription("Tool for accessing and outputting the singular triplets of a "
22 "singular value decomposition in PODMapping.");
23
24 params.addRequiredParam<UserObjectName>(
25 "pod_mapping", "The PODMapping object whose singular triplets should be printed.");
26
27 params.addRequiredParam<std::vector<VariableName>>(
28 "variables", "The names of the variables whose SVD should be printed.");
29
30 return params;
31}
32
34 : GeneralReporter(parameters),
35 MappingInterface(this),
36 _variable_names(getParam<std::vector<VariableName>>("variables")),
37 _left_singular_vectors(
38 declareValueByName<std::map<VariableName, std::vector<DenseVector<Real>>>>(
39 "left_singular_vectors", REPORTER_MODE_ROOT)),
40 _right_singular_vectors(
41 declareValueByName<std::map<VariableName, std::vector<DenseVector<Real>>>>(
42 "right_singular_vectors", REPORTER_MODE_ROOT)),
43 _singular_values(declareValueByName<std::map<VariableName, std::vector<Real>>>(
44 "singular_values", REPORTER_MODE_ROOT))
45
46{
47 for (const auto & vname : _variable_names)
48 {
49 _left_singular_vectors.emplace(vname, std::vector<DenseVector<Real>>());
50 _right_singular_vectors.emplace(vname, std::vector<DenseVector<Real>>());
51 _singular_values.emplace(vname, std::vector<Real>());
52 }
53}
54
55void
57{
58 _pod_mapping = dynamic_cast<PODMapping *>(&getMapping("pod_mapping"));
59
60 if (!_pod_mapping)
61 paramError("pod_mapping", "The given mapping is not a PODMapping!");
62
63 const auto & pod_mapping_variables = _pod_mapping->getVariableNames();
64 for (const auto & vname : _variable_names)
65 if (std::find(pod_mapping_variables.begin(), pod_mapping_variables.end(), vname) ==
66 pod_mapping_variables.end())
67 paramError("variables",
68 "The SVD of the requested variable " + vname +
69 " is not in the PODMapping object!");
70
71 for (const auto & vname : _variable_names)
72 {
73 _left_singular_vectors[vname].clear();
74 _right_singular_vectors[vname].clear();
75 _singular_values[vname].clear();
76 }
77}
78
79void
81{
82 for (const auto & vname : _variable_names)
83 {
86
87 const auto & left_modes = _pod_mapping->leftBasis(vname);
88 const auto & right_modes = _pod_mapping->rightBasis(vname);
89
90 for (auto mode_i : index_range(left_modes))
91 {
92 _left_singular_vectors[vname].push_back(left_modes[mode_i]);
93 _right_singular_vectors[vname].push_back(right_modes[mode_i]);
94 }
95 }
96}
const ReporterMode REPORTER_MODE_ROOT
registerMooseObject("StochasticToolsApp", SingularTripletReporter)
static InputParameters validParams()
void addRequiredParam(const std::string &name, const std::string &doc_string)
void addClassDescription(const std::string &doc_string)
An interface class that helps getting access to Mapping objects.
static InputParameters validParams()
VariableMappingBase & getMapping(const std::string &name) const
Get the mapping using the parameters of the moose object.
void paramError(const std::string &param, Args... args) const
Class which provides a Proper Orthogonal Decomposition (POD)-based mapping between full-order and red...
Definition PODMapping.h:24
const std::vector< Real > & singularValues(const VariableName &vname)
Return all of the singular values for a given variable.
Definition PODMapping.C:263
const std::vector< DenseVector< Real > > & rightBasis(const VariableName &vname)
Return all of the right basis functions for a given variable.
Definition PODMapping.C:252
virtual void buildMapping(const VariableName &vname) override
Abstract function for building mapping for a given variable.
Definition PODMapping.C:100
const std::vector< DenseVector< Real > > & leftBasis(const VariableName &vname)
Return all of the left basis functions for a given variable.
Definition PODMapping.C:241
Reporter class which can print Singular Value Decompositions from PODMapping objects.
static InputParameters validParams()
std::map< VariableName, std::vector< DenseVector< Real > > > & _right_singular_vectors
std::map< VariableName, std::vector< Real > > & _singular_values
PODMapping * _pod_mapping
Link to the PODMapping object which contains the SVDs.
const std::vector< VariableName > & _variable_names
The names of the variables whose SVD should be printed.
std::map< VariableName, std::vector< DenseVector< Real > > > & _left_singular_vectors
SingularTripletReporter(const InputParameters &parameters)
virtual const std::vector< VariableName > & getVariableNames()
Get the available variable names in this mapping.