https://mooseframework.inl.gov
Public Types | Public Member Functions | Static Public Member Functions | Public Attributes | Protected Member Functions | Protected Attributes | List of all members
PODReducedBasisSurrogate Class Reference

#include <PODReducedBasisSurrogate.h>

Inheritance diagram for PODReducedBasisSurrogate:
[legend]

Public Types

typedef DataFileName DataFileParameterType
 

Public Member Functions

 PODReducedBasisSurrogate (const InputParameters &parameters)
 
void evaluateSolution (const std::vector< Real > &params)
 Get the reduced solution for a given parameter sample. More...
 
void evaluateSolution (const std::vector< Real > &params, DenseVector< Real > &inp_vector, std::string var_name)
 Get the reduced solution for a given parameter sample and reconstruct the approximate solution into a given vector. More...
 
const std::vector< DenseVector< Real > > & getApproximateSolution () const
 Get a reference to the approximate solutions. More...
 
Real getNodalQoI (std::string var_name, unsigned int qoi_type) const
 Get the nodal QoI of the reconstructed solution for a given variable. More...
 
virtual Real evaluate (const std::vector< Real > &x) const
 Evaluate surrogate model given a row of parameters. More...
 
virtual bool enabled () const
 
std::shared_ptr< MooseObjectgetSharedPtr ()
 
std::shared_ptr< const MooseObjectgetSharedPtr () const
 
MooseAppgetMooseApp () const
 
const std::string & type () const
 
virtual const std::string & name () const
 
std::string typeAndName () const
 
std::string errorPrefix (const std::string &error_type) const
 
void callMooseError (std::string msg, const bool with_prefix) const
 
MooseObjectParameterName uniqueParameterName (const std::string &parameter_name) const
 
const InputParametersparameters () const
 
MooseObjectName uniqueName () const
 
const T & getParam (const std::string &name) const
 
std::vector< std::pair< T1, T2 > > getParam (const std::string &param1, const std::string &param2) const
 
const T * queryParam (const std::string &name) const
 
const T & getRenamedParam (const std::string &old_name, const std::string &new_name) const
 
getCheckedPointerParam (const std::string &name, const std::string &error_string="") const
 
bool isParamValid (const std::string &name) const
 
bool isParamSetByUser (const std::string &nm) const
 
void paramError (const std::string &param, Args... args) const
 
void paramWarning (const std::string &param, Args... args) const
 
void paramInfo (const std::string &param, Args... args) const
 
void connectControllableParams (const std::string &parameter, const std::string &object_type, const std::string &object_name, const std::string &object_parameter) const
 
void mooseError (Args &&... args) const
 
void mooseErrorNonPrefixed (Args &&... args) const
 
void mooseDocumentedError (const std::string &repo_name, const unsigned int issue_num, Args &&... args) const
 
void mooseWarning (Args &&... args) const
 
void mooseWarningNonPrefixed (Args &&... args) const
 
void mooseDeprecated (Args &&... args) const
 
void mooseInfo (Args &&... args) const
 
std::string getDataFileName (const std::string &param) const
 
std::string getDataFileNameByName (const std::string &relative_path) const
 
std::string getDataFilePath (const std::string &relative_path) const
 
const Parallel::Communicator & comm () const
 
processor_id_type n_processors () const
 
processor_id_type processor_id () const
 
T & getSampler (const std::string &name)
 
SamplergetSampler (const std::string &name)
 
T & getSamplerByName (const SamplerName &name)
 
SamplergetSamplerByName (const SamplerName &name)
 
template<>
SurrogateModelgetSurrogateModel (const std::string &name) const
 
template<>
SurrogateTrainerBasegetSurrogateTrainer (const std::string &name) const
 
template<>
SurrogateModelgetSurrogateModelByName (const UserObjectName &name) const
 
template<>
SurrogateTrainerBasegetSurrogateTrainerByName (const UserObjectName &name) const
 
const std::string & modelMetaDataName () const
 Accessor for the name of the model meta data. More...
 
const FileName & getModelDataFileName () const
 Get the associated filename. More...
 
bool hasModelData () const
 Check if we need to load model data (if the filename parameter is used) More...
 
virtual void evaluate (const std::vector< Real > &x, std::vector< Real > &y) const
 Various evaluate methods that can be overriden. More...
 
virtual Real evaluate (const std::vector< Real > &x, Real &std) const
 Evaluate methods that also return predicted standard deviation (see GaussianProcess.h) More...
 
virtual void evaluate (const std::vector< Real > &x, std::vector< Real > &y, std::vector< Real > &) const
 
template<typename T = SurrogateModel>
T & getSurrogateModel (const std::string &name) const
 Get a SurrogateModel/Trainer with a given name. More...
 
template<typename T = SurrogateTrainerBase>
T & getSurrogateTrainer (const std::string &name) const
 
template<typename T = SurrogateModel>
T & getSurrogateModelByName (const UserObjectName &name) const
 Get a sampler with a given name. More...
 
template<typename T = SurrogateTrainerBase>
T & getSurrogateTrainerByName (const UserObjectName &name) const
 
template<typename T , typename... Args>
T & declareModelData (const std::string &data_name, Args &&... args)
 Declare model data for loading from file as well as restart. More...
 
template<typename T , typename... Args>
const T & getModelData (const std::string &data_name, Args &&... args) const
 Retrieve model data from the interface. More...
 

Static Public Member Functions

static InputParameters validParams ()
 
static MooseEnum defaultPredictorTypes ()
 
static MooseEnum defaultResponseTypes ()
 

Public Attributes

const ConsoleStream _console
 

Protected Member Functions

void initializeReducedSystem ()
 Initialize reduced matrices, vectors and additional containers. More...
 
void initializeApproximateSolution ()
 Initialize approximate solution vector. More...
 
void solveReducedSystem (const std::vector< Real > &params)
 Assemble and solve the reduced equation system. More...
 
void reconstructApproximateSolution ()
 Reconstruct the approximate solution vector using the stored coefficients. More...
 
void reconstructApproximateSolution (DenseVector< Real > &inp_vector, std::string var_name)
 Reconstruct the approximate solution vector into an input vector. More...
 

Protected Attributes

std::vector< std::string > _change_rank
 A vector containing the number of basis functions each variable should use. More...
 
std::vector< unsigned int_new_ranks
 The new rank the variable should have. More...
 
std::vector< unsigned int_final_ranks
 The final rank that should be used for every variable. More...
 
std::vector< unsigned int_comulative_ranks
 Comulative ranks of the system. Used for indexing only. More...
 
const std::vector< std::string > & _var_names
 Vector containing the names of the variables we want to reconstruct. More...
 
const std::vector< std::string > & _tag_types
 Strings describing which operator is indepedent of the solution and which corresponds to a reduced DirichletBC operator. More...
 
const std::vector< std::vector< DenseVector< Real > > > & _base
 The basis vectors for all the variables. More...
 
const std::vector< DenseMatrix< Real > > & _red_operators
 The reduced operators in the same order as given in tag_types. More...
 
DenseVector< Real_coeffs
 Coefficients of the reduced order model. More...
 
DenseMatrix< Real_sys_mx
 The reduced system matrix. More...
 
DenseVector< Real_rhs
 The reduced right hand side. More...
 
std::vector< DenseVector< Real > > _approx_solution
 Reconstructed solution for each variable. More...
 
const Real _penalty
 Penalty parameter for Dirichlet BCs. More...
 
bool _initialized
 Switch that is set to see if the ROM matrices and vectors are initialized. More...
 
const bool & _enabled
 
MooseApp_app
 
const std::string _type
 
const std::string _name
 
const InputParameters_pars
 
Factory_factory
 
ActionFactory_action_factory
 
const Parallel::Communicator & _communicator
 

Detailed Description

Definition at line 14 of file PODReducedBasisSurrogate.h.

Constructor & Destructor Documentation

◆ PODReducedBasisSurrogate()

PODReducedBasisSurrogate::PODReducedBasisSurrogate ( const InputParameters parameters)

Definition at line 31 of file PODReducedBasisSurrogate.C.

33  _change_rank(getParam<std::vector<std::string>>("change_rank")),
34  _new_ranks(getParam<std::vector<unsigned int>>("new_ranks")),
35  _var_names(getModelData<std::vector<std::string>>("_var_names")),
36  _tag_types(getModelData<std::vector<std::string>>("_tag_types")),
37  _base(getModelData<std::vector<std::vector<DenseVector<Real>>>>("_base")),
38  _red_operators(getModelData<std::vector<DenseMatrix<Real>>>("_red_operators")),
39  _penalty(getParam<Real>("penalty")),
40  _initialized(false)
41 {
42  if (_change_rank.size() != _new_ranks.size())
43  paramError("new_ranks",
44  "The size of 'new_ranks' is not equal to the ",
45  "size of 'change_rank' ",
46  _new_ranks.size(),
47  " != ",
48  _change_rank.size());
49 
50  for (unsigned int var_i = 0; var_i < _new_ranks.size(); ++var_i)
51  if (_new_ranks[var_i] == 0)
52  paramError("new_ranks", "The values should be greater than 0!");
53 }
const Real _penalty
Penalty parameter for Dirichlet BCs.
const T & getModelData(const std::string &data_name, Args &&... args) const
Retrieve model data from the interface.
const std::vector< std::string > & _tag_types
Strings describing which operator is indepedent of the solution and which corresponds to a reduced Di...
const std::vector< std::vector< DenseVector< Real > > > & _base
The basis vectors for all the variables.
const T & getParam(const std::string &name) const
const std::vector< DenseMatrix< Real > > & _red_operators
The reduced operators in the same order as given in tag_types.
void paramError(const std::string &param, Args... args) const
const std::vector< std::string > & _var_names
Vector containing the names of the variables we want to reconstruct.
bool _initialized
Switch that is set to see if the ROM matrices and vectors are initialized.
const InputParameters & parameters() const
SurrogateModel(const InputParameters &parameters)
std::vector< std::string > _change_rank
A vector containing the number of basis functions each variable should use.
std::vector< unsigned int > _new_ranks
The new rank the variable should have.

Member Function Documentation

◆ declareModelData()

template<typename T , typename... Args>
T & RestartableModelInterface::declareModelData ( const std::string &  data_name,
Args &&...  args 
)
inherited

Declare model data for loading from file as well as restart.

Definition at line 78 of file RestartableModelInterface.h.

79 {
80  return _model_restartable.declareRestartableData<T>(data_name, std::forward<Args>(args)...);
81 }
T & declareRestartableData(const std::string &data_name, Args &&... args)
Declare a piece of data as "restartable" and initialize it.
PublicRestartable _model_restartable
Member for interfacing with the framework&#39;s restartable system.

◆ defaultPredictorTypes()

static MooseEnum SurrogateModel::defaultPredictorTypes ( )
inlinestaticinherited

Definition at line 27 of file SurrogateModel.h.

27 { return MooseEnum("real"); }

◆ defaultResponseTypes()

static MooseEnum SurrogateModel::defaultResponseTypes ( )
inlinestaticinherited

Definition at line 28 of file SurrogateModel.h.

Referenced by EvaluateSurrogate::validParams().

28 { return MooseEnum("real vector_real"); }

◆ evaluate() [1/4]

virtual Real SurrogateModel::evaluate ( const std::vector< Real > &  x) const
inlinevirtualinherited

Evaluate surrogate model given a row of parameters.

Reimplemented in LibtorchANNSurrogate, PolynomialChaos, GaussianProcessSurrogate, PolynomialRegressionSurrogate, and NearestPointSurrogate.

Definition at line 33 of file SurrogateModel.h.

Referenced by SurrogateModelScalarAux::computeValue(), SurrogateTrainer::evaluateModelError(), BiFidelityActiveLearningGPDecision::facilitateDecision(), and ActiveLearningGPDecision::facilitateDecision().

34  {
35  evaluateError(x, Real());
36  return 0.0;
37  };
void evaluateError(P x, R y, bool with_std=false) const
const std::vector< double > x
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real

◆ evaluate() [2/4]

virtual void SurrogateModel::evaluate ( const std::vector< Real > &  x,
std::vector< Real > &  y 
) const
inlinevirtualinherited

Various evaluate methods that can be overriden.

Reimplemented in GaussianProcessSurrogate, PolynomialRegressionSurrogate, and NearestPointSurrogate.

Definition at line 43 of file SurrogateModel.h.

44  {
45  evaluateError(x, y);
46  }
void evaluateError(P x, R y, bool with_std=false) const
const std::vector< double > y
const std::vector< double > x

◆ evaluate() [3/4]

virtual Real SurrogateModel::evaluate ( const std::vector< Real > &  x,
Real std 
) const
inlinevirtualinherited

Evaluate methods that also return predicted standard deviation (see GaussianProcess.h)

Reimplemented in GaussianProcessSurrogate.

Definition at line 53 of file SurrogateModel.h.

54  {
55  evaluateError(x, std, true);
56  return 0.0;
57  }
void evaluateError(P x, R y, bool with_std=false) const
const std::vector< double > x

◆ evaluate() [4/4]

virtual void SurrogateModel::evaluate ( const std::vector< Real > &  x,
std::vector< Real > &  y,
std::vector< Real > &   
) const
inlinevirtualinherited

Reimplemented in GaussianProcessSurrogate.

Definition at line 59 of file SurrogateModel.h.

60  {
61  evaluateError(x, y, true);
62  }
void evaluateError(P x, R y, bool with_std=false) const
const std::vector< double > y
const std::vector< double > x

◆ evaluateSolution() [1/2]

void PODReducedBasisSurrogate::evaluateSolution ( const std::vector< Real > &  params)

Get the reduced solution for a given parameter sample.

Definition at line 56 of file PODReducedBasisSurrogate.C.

57 {
58  if (!_initialized)
59  {
60  // The containers are initialized (if needed).
63  _initialized = true;
64  }
65 
66  // Assembling and solving the reduced equation system.
67  solveReducedSystem(params);
68 
69  // Reconstructing the approximate solutions for every variable.
71 }
void reconstructApproximateSolution()
Reconstruct the approximate solution vector using the stored coefficients.
void initializeApproximateSolution()
Initialize approximate solution vector.
bool _initialized
Switch that is set to see if the ROM matrices and vectors are initialized.
void initializeReducedSystem()
Initialize reduced matrices, vectors and additional containers.
void solveReducedSystem(const std::vector< Real > &params)
Assemble and solve the reduced equation system.

◆ evaluateSolution() [2/2]

void PODReducedBasisSurrogate::evaluateSolution ( const std::vector< Real > &  params,
DenseVector< Real > &  inp_vector,
std::string  var_name 
)

Get the reduced solution for a given parameter sample and reconstruct the approximate solution into a given vector.

Definition at line 74 of file PODReducedBasisSurrogate.C.

77 {
78  if (!_initialized)
79  {
80  // The containers are initialized (if needed).
82  _initialized = true;
83  }
84 
85  // Assembling and solving the reduced equation system.
86  solveReducedSystem(params);
87 
88  // Reconstructing the approximate solutions for every variable.
89  reconstructApproximateSolution(inp_vector, var_name);
90 }
void reconstructApproximateSolution()
Reconstruct the approximate solution vector using the stored coefficients.
bool _initialized
Switch that is set to see if the ROM matrices and vectors are initialized.
void initializeReducedSystem()
Initialize reduced matrices, vectors and additional containers.
void solveReducedSystem(const std::vector< Real > &params)
Assemble and solve the reduced equation system.

◆ getApproximateSolution()

const std::vector<DenseVector<Real> >& PODReducedBasisSurrogate::getApproximateSolution ( ) const
inline

Get a reference to the approximate solutions.

Definition at line 31 of file PODReducedBasisSurrogate.h.

31 { return _approx_solution; }
std::vector< DenseVector< Real > > _approx_solution
Reconstructed solution for each variable.

◆ getModelData()

template<typename T , typename... Args>
const T & RestartableModelInterface::getModelData ( const std::string &  data_name,
Args &&...  args 
) const
inherited

Retrieve model data from the interface.

Definition at line 85 of file RestartableModelInterface.h.

86 {
87  return _model_restartable.getRestartableData<T>(data_name, std::forward<Args>(args)...);
88 }
const T & getRestartableData(const std::string &data_name) const
Declare a piece of data as "restartable" and initialize it Similar to declareRestartableData but retu...
PublicRestartable _model_restartable
Member for interfacing with the framework&#39;s restartable system.

◆ getModelDataFileName()

const FileName & RestartableModelInterface::getModelDataFileName ( ) const
inherited

Get the associated filename.

Definition at line 33 of file RestartableModelInterface.C.

34 {
35  return _model_object.getParam<FileName>("filename");
36 }
const T & getParam(const std::string &name) const
const MooseObject & _model_object
Reference to the MooseObject that uses this interface.

◆ getNodalQoI()

Real PODReducedBasisSurrogate::getNodalQoI ( std::string  var_name,
unsigned int  qoi_type 
) const

Get the nodal QoI of the reconstructed solution for a given variable.

Definition at line 255 of file PODReducedBasisSurrogate.C.

256 {
257  Real val = 0.0;
258 
259  auto it = std::find(_var_names.begin(), _var_names.end(), var_name);
260  if (it == _var_names.end())
261  mooseError("Variable '", var_name, "' not found!");
262 
263  switch (qoi_type)
264  {
265  case 0:
266  val = _approx_solution[it - _var_names.begin()].max();
267  break;
268 
269  case 1:
270  val = _approx_solution[it - _var_names.begin()].min();
271  break;
272 
273  case 2:
274  val = _approx_solution[it - _var_names.begin()].l1_norm();
275  break;
276 
277  case 3:
278  val = _approx_solution[it - _var_names.begin()].l2_norm();
279  break;
280 
281  case 4:
282  val = _approx_solution[it - _var_names.begin()].linfty_norm();
283  break;
284  }
285 
286  return (val);
287 }
std::vector< DenseVector< Real > > _approx_solution
Reconstructed solution for each variable.
const std::vector< std::string > & _var_names
Vector containing the names of the variables we want to reconstruct.
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
void mooseError(Args &&... args) const

◆ getSurrogateModel() [1/2]

template<>
SurrogateModel& SurrogateModelInterface::getSurrogateModel ( const std::string &  name) const
inherited

Definition at line 46 of file SurrogateModelInterface.C.

47 {
48  return getSurrogateModelByName<SurrogateModel>(_smi_params.get<UserObjectName>(name));
49 }
const InputParameters & _smi_params
Parameters of the object with this interface.
std::vector< std::pair< R1, R2 > > get(const std::string &param1, const std::string &param2) const
const std::string name
Definition: Setup.h:20

◆ getSurrogateModel() [2/2]

template<typename T >
T & SurrogateModelInterface::getSurrogateModel ( const std::string &  name) const
inherited

Get a SurrogateModel/Trainer with a given name.

Parameters
nameThe name of the parameter key of the sampler to retrieve
Returns
The sampler with name associated with the parameter 'name'

Definition at line 81 of file SurrogateModelInterface.h.

Referenced by SurrogateTrainer::initialize().

82 {
83  return getSurrogateModelByName<T>(_smi_params.get<UserObjectName>(name));
84 }
const InputParameters & _smi_params
Parameters of the object with this interface.
std::vector< std::pair< R1, R2 > > get(const std::string &param1, const std::string &param2) const
const std::string name
Definition: Setup.h:20

◆ getSurrogateModelByName() [1/2]

template<>
SurrogateModel& SurrogateModelInterface::getSurrogateModelByName ( const UserObjectName &  name) const
inherited

Definition at line 31 of file SurrogateModelInterface.C.

32 {
33  std::vector<SurrogateModel *> models;
35  .query()
36  .condition<AttribName>(name)
37  .condition<AttribSystem>("SurrogateModel")
38  .queryInto(models);
39  if (models.empty())
40  mooseError("Unable to find a SurrogateModel object with the name '" + name + "'");
41  return *(models[0]);
42 }
void mooseError(Args &&... args)
FEProblemBase & _smi_feproblem
Reference to FEProblemBase instance.
TheWarehouse & theWarehouse() const
const std::string name
Definition: Setup.h:20
Query query()

◆ getSurrogateModelByName() [2/2]

template<typename T >
T & SurrogateModelInterface::getSurrogateModelByName ( const UserObjectName &  name) const
inherited

Get a sampler with a given name.

Parameters
nameThe name of the sampler to retrieve
Returns
The sampler with name 'name'

Definition at line 88 of file SurrogateModelInterface.h.

Referenced by CrossValidationScores::CrossValidationScores(), EvaluateSurrogate::EvaluateSurrogate(), and InverseMapping::initialSetup().

89 {
90  std::vector<T *> models;
92  .query()
93  .condition<AttribName>(name)
94  .condition<AttribSystem>("SurrogateModel")
95  .queryInto(models);
96  if (models.empty())
97  mooseError("Unable to find a SurrogateModel object of type " + std::string(typeid(T).name()) +
98  " with the name '" + name + "'");
99  return *(models[0]);
100 }
void mooseError(Args &&... args)
FEProblemBase & _smi_feproblem
Reference to FEProblemBase instance.
TheWarehouse & theWarehouse() const
const std::string name
Definition: Setup.h:20
Query query()

◆ getSurrogateTrainer() [1/2]

template<typename T >
T & SurrogateModelInterface::getSurrogateTrainer ( const std::string &  name) const
inherited

Definition at line 104 of file SurrogateModelInterface.h.

105 {
106  return getSurrogateTrainerByName<T>(_smi_params.get<UserObjectName>(name));
107 }
const InputParameters & _smi_params
Parameters of the object with this interface.
std::vector< std::pair< R1, R2 > > get(const std::string &param1, const std::string &param2) const
const std::string name
Definition: Setup.h:20

◆ getSurrogateTrainer() [2/2]

template<>
SurrogateTrainerBase& SurrogateModelInterface::getSurrogateTrainer ( const std::string &  name) const
inherited

Definition at line 60 of file SurrogateModelInterface.C.

61 {
62  return getSurrogateTrainerByName<SurrogateTrainerBase>(_smi_params.get<UserObjectName>(name));
63 }
const InputParameters & _smi_params
Parameters of the object with this interface.
std::vector< std::pair< R1, R2 > > get(const std::string &param1, const std::string &param2) const
const std::string name
Definition: Setup.h:20

◆ getSurrogateTrainerByName() [1/2]

template<>
SurrogateTrainerBase& SurrogateModelInterface::getSurrogateTrainerByName ( const UserObjectName &  name) const
inherited

Definition at line 53 of file SurrogateModelInterface.C.

54 {
56 }
T & getUserObject(const std::string &name, unsigned int tid=0) const
FEProblemBase & _smi_feproblem
Reference to FEProblemBase instance.
const std::string name
Definition: Setup.h:20
This is the base trainer class whose main functionality is the API for declaring model data...

◆ getSurrogateTrainerByName() [2/2]

template<typename T >
T & SurrogateModelInterface::getSurrogateTrainerByName ( const UserObjectName &  name) const
inherited

Definition at line 111 of file SurrogateModelInterface.h.

Referenced by SurrogateTrainerOutput::output().

112 {
113  SurrogateTrainerBase * base_ptr =
115  T * obj_ptr = dynamic_cast<T *>(base_ptr);
116  if (!obj_ptr)
117  mooseError("Failed to find a SurrogateTrainer object of type " + std::string(typeid(T).name()) +
118  " with the name '",
119  name,
120  "' for the desired type.");
121  return *obj_ptr;
122 }
T & getUserObject(const std::string &name, unsigned int tid=0) const
void mooseError(Args &&... args)
FEProblemBase & _smi_feproblem
Reference to FEProblemBase instance.
const std::string name
Definition: Setup.h:20
const THREAD_ID _smi_tid
Thread ID.
This is the base trainer class whose main functionality is the API for declaring model data...

◆ hasModelData()

bool RestartableModelInterface::hasModelData ( ) const
inherited

Check if we need to load model data (if the filename parameter is used)

Definition at line 39 of file RestartableModelInterface.C.

40 {
41  return _model_object.isParamValid("filename");
42 }
bool isParamValid(const std::string &name) const
const MooseObject & _model_object
Reference to the MooseObject that uses this interface.

◆ initializeApproximateSolution()

void PODReducedBasisSurrogate::initializeApproximateSolution ( )
protected

Initialize approximate solution vector.

Definition at line 135 of file PODReducedBasisSurrogate.C.

Referenced by evaluateSolution().

136 {
137  _approx_solution.resize(_var_names.size());
138  for (unsigned int var_i = 0; var_i < _var_names.size(); var_i++)
139  _approx_solution[var_i] = DenseVector<Real>(_base[var_i][0].size());
140 }
std::vector< DenseVector< Real > > _approx_solution
Reconstructed solution for each variable.
const std::vector< std::vector< DenseVector< Real > > > & _base
The basis vectors for all the variables.
const std::vector< std::string > & _var_names
Vector containing the names of the variables we want to reconstruct.

◆ initializeReducedSystem()

void PODReducedBasisSurrogate::initializeReducedSystem ( )
protected

Initialize reduced matrices, vectors and additional containers.

Definition at line 93 of file PODReducedBasisSurrogate.C.

Referenced by evaluateSolution().

94 {
95  // Storing important indices for the assembly loops.
96  _final_ranks.resize(_var_names.size());
97  _comulative_ranks.resize(_var_names.size());
98  unsigned int sum_ranks = 0;
99 
100  // Checking if the user wants to overwrite the original ranks for the
101  // variables.
102  for (unsigned int var_i = 0; var_i < _var_names.size(); ++var_i)
103  {
104  _final_ranks[var_i] = _base[var_i].size();
105  for (unsigned int var_j = 0; var_j < _change_rank.size(); ++var_j)
106  {
107  if (_change_rank[var_j] == _var_names[var_i])
108  {
109  if (_new_ranks[var_j] > _base[var_i].size())
110  {
111  mooseWarning("The specified new rank (",
112  _new_ranks[var_j],
113  ") for variable '",
114  _var_names[var_i],
115  "' is higher than the original rank (",
116  _base[var_i].size(),
117  ")! Switched to original rank.");
118  break;
119  }
120 
121  _final_ranks[var_i] = _new_ranks[var_j];
122  }
123  }
124  sum_ranks += _final_ranks[var_i];
125  _comulative_ranks[var_i] = sum_ranks;
126  }
127 
128  // Resizing containers to match the newly prescribed ranks.
129  _sys_mx = DenseMatrix<Real>(sum_ranks, sum_ranks);
130  _rhs = DenseVector<Real>(sum_ranks);
131  _coeffs = DenseVector<Real>(sum_ranks);
132 }
DenseVector< Real > _rhs
The reduced right hand side.
void mooseWarning(Args &&... args) const
std::vector< unsigned int > _final_ranks
The final rank that should be used for every variable.
const std::vector< std::vector< DenseVector< Real > > > & _base
The basis vectors for all the variables.
DenseMatrix< Real > _sys_mx
The reduced system matrix.
const std::vector< std::string > & _var_names
Vector containing the names of the variables we want to reconstruct.
DenseVector< Real > _coeffs
Coefficients of the reduced order model.
std::vector< std::string > _change_rank
A vector containing the number of basis functions each variable should use.
std::vector< unsigned int > _new_ranks
The new rank the variable should have.
std::vector< unsigned int > _comulative_ranks
Comulative ranks of the system. Used for indexing only.

◆ modelMetaDataName()

const std::string& RestartableModelInterface::modelMetaDataName ( ) const
inlineinherited

Accessor for the name of the model meta data.

Definition at line 47 of file RestartableModelInterface.h.

Referenced by SurrogateTrainerOutput::output(), and MappingOutput::output().

47 { return _model_meta_data_name; }
const std::string _model_meta_data_name
The model meta data name.

◆ reconstructApproximateSolution() [1/2]

void PODReducedBasisSurrogate::reconstructApproximateSolution ( )
protected

Reconstruct the approximate solution vector using the stored coefficients.

Definition at line 204 of file PODReducedBasisSurrogate.C.

Referenced by evaluateSolution().

205 {
206  unsigned int counter = 0;
207  for (unsigned int var_i = 0; var_i < _var_names.size(); var_i++)
208  {
209  _approx_solution[var_i].zero();
210 
211  // This also takes into account the potential truncation of the bases by
212  // the user.
213  for (unsigned int base_i = 0; base_i < _final_ranks[var_i]; ++base_i)
214  {
215  for (unsigned int dof_i = 0; dof_i < _base[var_i][base_i].size(); ++dof_i)
216  _approx_solution[var_i](dof_i) += _coeffs(counter) * _base[var_i][base_i](dof_i);
217  counter++;
218  }
219  }
220 }
std::vector< DenseVector< Real > > _approx_solution
Reconstructed solution for each variable.
std::vector< unsigned int > _final_ranks
The final rank that should be used for every variable.
const std::vector< std::vector< DenseVector< Real > > > & _base
The basis vectors for all the variables.
const std::vector< std::string > & _var_names
Vector containing the names of the variables we want to reconstruct.
DenseVector< Real > _coeffs
Coefficients of the reduced order model.

◆ reconstructApproximateSolution() [2/2]

void PODReducedBasisSurrogate::reconstructApproximateSolution ( DenseVector< Real > &  inp_vector,
std::string  var_name 
)
protected

Reconstruct the approximate solution vector into an input vector.

Definition at line 223 of file PODReducedBasisSurrogate.C.

225 {
226  auto it = std::find(_var_names.begin(), _var_names.end(), var_name);
227  if (it == _var_names.end())
228  mooseError("Variable '", var_name, "' does not exist in the POD-RB surrogate!");
229 
230  unsigned int var_i = std::distance(_var_names.begin(), it);
231 
232  if (inp_vector.size() != _base[var_i][0].size())
233  mooseError("The size of the input vector (",
234  inp_vector.size(),
235  ") for variable '",
236  var_name,
237  "' does not match the size of the stored base vector (",
238  _base[var_i][0].size(),
239  ") in POD-RB surrogate!");
240 
241  inp_vector.zero();
242 
243  unsigned int base_begin = 0;
244  if (var_i != 0)
245  base_begin = _comulative_ranks[var_i - 1];
246 
247  for (unsigned int base_i = 0; base_i < _final_ranks[var_i]; ++base_i)
248  {
249  for (unsigned int dof_i = 0; dof_i < inp_vector.size(); ++dof_i)
250  inp_vector(dof_i) += _coeffs(base_i + base_begin) * _base[var_i][base_i](dof_i);
251  }
252 }
std::vector< unsigned int > _final_ranks
The final rank that should be used for every variable.
const std::vector< std::vector< DenseVector< Real > > > & _base
The basis vectors for all the variables.
const std::vector< std::string > & _var_names
Vector containing the names of the variables we want to reconstruct.
DenseVector< Real > _coeffs
Coefficients of the reduced order model.
void mooseError(Args &&... args) const
std::vector< unsigned int > _comulative_ranks
Comulative ranks of the system. Used for indexing only.

◆ solveReducedSystem()

void PODReducedBasisSurrogate::solveReducedSystem ( const std::vector< Real > &  params)
protected

Assemble and solve the reduced equation system.

Definition at line 143 of file PODReducedBasisSurrogate.C.

Referenced by evaluateSolution().

144 {
145  // Cleaning the containers of the system matrix and right hand side.
146  _sys_mx.zero();
147  _rhs.zero();
148 
149  // The assumption here is that the reduced operators in the trainer were
150  // assembled in the order of the parameters. Also, if the number of
151  // parameters is fewer than the number of operators, the operator will
152  // just be added without scaling.
153  for (unsigned int i = 0; i < _red_operators.size(); ++i)
154  {
155  unsigned int row_start = 0;
156 
157  // Checking if the reduced operator corresponds to a Dirichlet BC, if
158  // yes introduce the penalty factor.
159  Real factor = 1.0;
160  if (_tag_types[i] == "op_dir" || _tag_types[i] == "src_dir")
161  factor = _penalty;
162 
163  // If the user decreased the rank of the reduced bases manually, some parts
164  // of the initial reduced operators have to be omited.
165  for (unsigned int var_i = 0; var_i < _var_names.size(); ++var_i)
166  {
167  for (unsigned int row_i = row_start; row_i < _comulative_ranks[var_i]; row_i++)
168  {
169  if (_tag_types[i] == "op" || _tag_types[i] == "op_dir")
170  {
171 
172  unsigned int col_start = 0;
173 
174  for (unsigned int var_j = 0; var_j < _var_names.size(); ++var_j)
175  {
176  for (unsigned int col_i = col_start; col_i < _comulative_ranks[var_j]; col_i++)
177  {
178  if (i < params.size())
179  _sys_mx(row_i, col_i) += params[i] * factor * _red_operators[i](row_i, col_i);
180  else
181  _sys_mx(row_i, col_i) += factor * _red_operators[i](row_i, col_i);
182  }
183 
184  col_start = _comulative_ranks[var_j];
185  }
186  }
187  else
188  {
189  if (i < params.size())
190  _rhs(row_i) -= params[i] * factor * _red_operators[i](row_i, 0);
191  else
192  _rhs(row_i) -= factor * _red_operators[i](row_i, 0);
193  }
194  row_start = _comulative_ranks[var_i];
195  }
196  }
197  }
198 
199  // Solving the reduced system.
201 }
virtual void zero() override final
DenseVector< Real > _rhs
The reduced right hand side.
const Real _penalty
Penalty parameter for Dirichlet BCs.
const std::vector< std::string > & _tag_types
Strings describing which operator is indepedent of the solution and which corresponds to a reduced Di...
const std::vector< DenseMatrix< Real > > & _red_operators
The reduced operators in the same order as given in tag_types.
DenseMatrix< Real > _sys_mx
The reduced system matrix.
const std::vector< std::string > & _var_names
Vector containing the names of the variables we want to reconstruct.
void lu_solve(const DenseVector< Real > &b, DenseVector< Real > &x)
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
DenseVector< Real > _coeffs
Coefficients of the reduced order model.
std::vector< unsigned int > _comulative_ranks
Comulative ranks of the system. Used for indexing only.

◆ validParams()

InputParameters PODReducedBasisSurrogate::validParams ( )
static

Definition at line 15 of file PODReducedBasisSurrogate.C.

16 {
18  params.addClassDescription("Evaluates POD-RB surrogate model with reduced operators "
19  "computed from PODReducedBasisTrainer.");
20  params.addParam<std::vector<std::string>>("change_rank",
21  std::vector<std::string>(0),
22  "Names of variables whose rank should be changed.");
23  params.addParam<std::vector<unsigned int>>(
24  "new_ranks",
25  std::vector<unsigned int>(0),
26  "The new ranks that each variable in 'change_rank' shall have.");
27  params.addParam<Real>("penalty", 1e5, "The penalty parameter for Dirichlet BCs.");
28  return params;
29 }
void addParam(const std::string &name, const std::initializer_list< typename T::value_type > &value, const std::string &doc_string)
static InputParameters validParams()
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
void addClassDescription(const std::string &doc_string)

Member Data Documentation

◆ _approx_solution

std::vector<DenseVector<Real> > PODReducedBasisSurrogate::_approx_solution
protected

Reconstructed solution for each variable.

Definition at line 89 of file PODReducedBasisSurrogate.h.

Referenced by getApproximateSolution(), getNodalQoI(), initializeApproximateSolution(), and reconstructApproximateSolution().

◆ _base

const std::vector<std::vector<DenseVector<Real> > >& PODReducedBasisSurrogate::_base
protected

The basis vectors for all the variables.

Definition at line 74 of file PODReducedBasisSurrogate.h.

Referenced by initializeApproximateSolution(), initializeReducedSystem(), and reconstructApproximateSolution().

◆ _change_rank

std::vector<std::string> PODReducedBasisSurrogate::_change_rank
protected

A vector containing the number of basis functions each variable should use.

This is optional, used only to override the base numbers from the training data.

Definition at line 55 of file PODReducedBasisSurrogate.h.

Referenced by initializeReducedSystem(), and PODReducedBasisSurrogate().

◆ _coeffs

DenseVector<Real> PODReducedBasisSurrogate::_coeffs
protected

Coefficients of the reduced order model.

Definition at line 80 of file PODReducedBasisSurrogate.h.

Referenced by initializeReducedSystem(), reconstructApproximateSolution(), and solveReducedSystem().

◆ _comulative_ranks

std::vector<unsigned int> PODReducedBasisSurrogate::_comulative_ranks
protected

Comulative ranks of the system. Used for indexing only.

Definition at line 64 of file PODReducedBasisSurrogate.h.

Referenced by initializeReducedSystem(), reconstructApproximateSolution(), and solveReducedSystem().

◆ _final_ranks

std::vector<unsigned int> PODReducedBasisSurrogate::_final_ranks
protected

The final rank that should be used for every variable.

Definition at line 61 of file PODReducedBasisSurrogate.h.

Referenced by initializeReducedSystem(), and reconstructApproximateSolution().

◆ _initialized

bool PODReducedBasisSurrogate::_initialized
protected

Switch that is set to see if the ROM matrices and vectors are initialized.

Definition at line 95 of file PODReducedBasisSurrogate.h.

Referenced by evaluateSolution().

◆ _new_ranks

std::vector<unsigned int> PODReducedBasisSurrogate::_new_ranks
protected

The new rank the variable should have.

Definition at line 58 of file PODReducedBasisSurrogate.h.

Referenced by initializeReducedSystem(), and PODReducedBasisSurrogate().

◆ _penalty

const Real PODReducedBasisSurrogate::_penalty
protected

Penalty parameter for Dirichlet BCs.

Definition at line 92 of file PODReducedBasisSurrogate.h.

Referenced by solveReducedSystem().

◆ _red_operators

const std::vector<DenseMatrix<Real> >& PODReducedBasisSurrogate::_red_operators
protected

The reduced operators in the same order as given in tag_types.

Definition at line 77 of file PODReducedBasisSurrogate.h.

Referenced by solveReducedSystem().

◆ _rhs

DenseVector<Real> PODReducedBasisSurrogate::_rhs
protected

The reduced right hand side.

Definition at line 86 of file PODReducedBasisSurrogate.h.

Referenced by initializeReducedSystem(), and solveReducedSystem().

◆ _sys_mx

DenseMatrix<Real> PODReducedBasisSurrogate::_sys_mx
protected

The reduced system matrix.

Definition at line 83 of file PODReducedBasisSurrogate.h.

Referenced by initializeReducedSystem(), and solveReducedSystem().

◆ _tag_types

const std::vector<std::string>& PODReducedBasisSurrogate::_tag_types
protected

Strings describing which operator is indepedent of the solution and which corresponds to a reduced DirichletBC operator.

Definition at line 71 of file PODReducedBasisSurrogate.h.

Referenced by solveReducedSystem().

◆ _var_names

const std::vector<std::string>& PODReducedBasisSurrogate::_var_names
protected

Vector containing the names of the variables we want to reconstruct.

Definition at line 67 of file PODReducedBasisSurrogate.h.

Referenced by getNodalQoI(), initializeApproximateSolution(), initializeReducedSystem(), reconstructApproximateSolution(), and solveReducedSystem().


The documentation for this class was generated from the following files: