https://mooseframework.inl.gov
Loading...
Searching...
No Matches
PODResidualTransfer.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
10// StochasticTools includes
11#include "PODResidualTransfer.h"
12#include "NonlinearSystemBase.h"
13
15
18{
20 params.addClassDescription("Transfers residual vectors from the sub-application to a "
21 "a container in the Trainer object.");
22 params.suppressParameter<MultiMooseEnum>("direction");
23 params.suppressParameter<MultiAppName>("multi_app");
24 return params;
25}
26
28 : PODSamplerSolutionTransfer(parameters)
29{
30 if (hasToMultiApp())
31 paramError("to_multi_app", "To and between multiapp directions are not implemented");
32}
33
34void
36{
37 const unsigned int total_base_num = _trainer.getSumBaseSize();
38
39 // Looping over sub-apps
40 for (unsigned int base_i = 0; base_i < total_base_num; ++base_i)
41 if (getFromMultiApp()->hasLocalApp(base_i))
42 transferResidual(base_i, base_i);
43}
44
45void
50
51void
52PODResidualTransfer::transferResidual(dof_id_type base_i, dof_id_type multi_app_i)
53{
54 const std::vector<std::string> & var_names = _trainer.getVarNames();
55 const std::vector<std::string> & tag_names = _trainer.getTagNames();
56 const std::vector<std::string> & tag_types = _trainer.getTagTypes();
57
58 // Getting reference to the non-linear system
59 FEProblemBase & app_problem = getFromMultiApp()->appProblemBase(multi_app_i);
60 NonlinearSystemBase & nl = app_problem.getNonlinearSystemBase(/*nl_sys_num=*/0);
61
62 // Looping over the residual tags and extracting the corresponding vector.
63 for (unsigned int tag_i = 0; tag_i < tag_names.size(); ++tag_i)
64 {
65 // If the tag corresponds to an independent operator, it is enough to
66 // transfer it once.
67 if (base_i > 0 && (tag_types[tag_i] == "src" || tag_types[tag_i] == "src_dir"))
68 continue;
69
70 TagID tag_id = app_problem.getVectorTagID(tag_names[tag_i]);
71
72 // Fetching the corresponding residual vector and extracting the parts for
73 // each variable.
74 NumericVector<Number> & full_residual = nl.getVector(tag_id);
75 std::vector<DenseVector<Real>> split_residual(var_names.size());
76
77 for (unsigned int var_i = 0; var_i < var_names.size(); ++var_i)
78 {
79 // Getting the DoF indices of the variable.
80 nl.setVariableGlobalDoFs(var_names[var_i]);
81 const std::vector<dof_id_type> & var_dofs = nl.getVariableGlobalDoFs();
82
83 // Extracting the corresponding part of the residual vector.
84 full_residual.localize(split_residual[var_i].get_values(), var_dofs);
85 }
86
87 // Inserting the contribution of this residual into the reduced operator in
88 // the trainer.
89 _trainer.addToReducedOperator(base_i, tag_i, split_residual);
90 }
91}
unsigned int TagID
registerMooseObject("StochasticToolsApp", PODResidualTransfer)
NonlinearSystemBase & getNonlinearSystemBase(const unsigned int sys_num)
void suppressParameter(const std::string &name)
void addClassDescription(const std::string &doc_string)
void paramError(const std::string &param, Args... args) const
bool hasToMultiApp() const
const std::shared_ptr< MultiApp > getFromMultiApp() const
unsigned int getSumBaseSize() const
Getting the overall base size, which is the sum of the individual bases.
const std::vector< std::string > & getTagTypes() const
const std::vector< std::string > & getVarNames() const
const std::vector< std::string > & getTagNames() const
void addToReducedOperator(unsigned int base_i, unsigned int tag_i, std::vector< DenseVector< Real > > &residual)
Adding the contribution of a residual to the reduced operators.
Transfers residuals for given variables and vector tags from a sub-subapplication to a PODReducedBasi...
static InputParameters validParams()
virtual void executeFromMultiapp() override
virtual void execute() override
Transfer callback that will transfer residuals with given tags from the subapplication.
PODResidualTransfer(const InputParameters &parameters)
void transferResidual(dof_id_type base_i, dof_id_type multi_app_i)
Adds the variable-residuals to the trainer.
Transfer solutions from sub-applications to a container in a Trainer.
static InputParameters validParams()
PODReducedBasisTrainer & _trainer
The trainer object to save the solution vector into or to fetch the artificial solution vectors from.
dof_id_type _global_index
Index for tracking the row index when using batch mode operation.
virtual TagID getVectorTagID(const TagName &tag_name) const
const std::vector< dof_id_type > & getVariableGlobalDoFs()
virtual NumericVector< Number > & getVector(const std::string &name)
void setVariableGlobalDoFs(const std::string &var_name)
processor_id_type processor_id() const