15 #include "libmesh/sparse_matrix.h" 24 params.
addClassDescription(
"Evaluates surrogate models and maps the results back to a full " 25 "solution field for given variables.");
26 params.
addParam<std::vector<UserObjectName>>(
27 "surrogate", std::vector<UserObjectName>(),
"The names of the surrogates for each variable.");
29 "mapping",
"The name of the mapping object which provides the inverse mapping function.");
32 "The names of the variables that this object is supposed to populate with the " 33 "reconstructed results.");
35 "variable_to_reconstruct",
36 "The names of the variables in the nonlinear system which we would like to approximate. This " 37 "is important for DoF information.");
40 "The input parameters for the surrogate. If no surrogate is supplied these are assumed to be " 41 "the coordinates in the latent space.");
51 _var_names_to_fill(getParam<
std::vector<VariableName>>(
"variable_to_fill")),
52 _var_names_to_reconstruct(getParam<
std::vector<VariableName>>(
"variable_to_reconstruct")),
53 _surrogate_model_names(getParam<
std::vector<UserObjectName>>(
"surrogate")),
54 _input_parameters(getParam<
std::vector<
Real>>(
"parameters"))
58 "The number of variables to fill should be the same as the number of entries in " 59 "`variable_to_reconstruct`");
64 "The number of surrogates should match the number of variables which need to be " 86 if (std::find(mapping_variable_names.begin(),
87 mapping_variable_names.end(),
91 "! Double check the training process and make sure that the mapping includes " 92 "the given variable!");
101 if (fe_type_reconstruct != fe_type_fill)
103 "The FEtype should match the ones defined for `variable_to_reconstruct`");
105 if (fe_type_reconstruct.family ==
SCALAR)
106 paramError(
"variable_to_fill",
"InverseMapping does not support SCALAR variables!");
119 std::unique_ptr<NumericVector<Number>> temporary_vector =
122 std::vector<Real> reduced_coefficients;
130 DenseVector<Real> reconstructed_solution;
150 if (dofs[dof_i] >= local_dof_begin && dofs[dof_i] < local_dof_end)
151 temporary_vector->set(dofs[dof_i], reconstructed_solution(dof_i));
157 unsigned int from_sys_num = var_to_reconstruct.
sys().
system().
number();
158 unsigned int from_var_num =
165 for (
const auto & node : to_mesh.local_node_ptr_range())
167 const auto n_dofs = node->n_dofs(to_sys_num, to_var_num);
176 const auto & to_dof_id = node->dof_number(to_sys_num, to_var_num, dof_i);
177 const auto & from_dof_id = node->dof_number(from_sys_num, from_var_num, dof_i);
180 var_to_fill.
sys().
solution().
set(to_dof_id, (*temporary_vector)(from_dof_id));
188 for (
auto & elem :
as_range(to_mesh.local_elements_begin(), to_mesh.local_elements_end()))
191 const auto n_dofs = elem->n_dofs(to_sys_num, to_var_num);
199 const auto & to_dof_id = elem->dof_number(to_sys_num, to_var_num, dof_i);
200 const auto & from_dof_id = elem->dof_number(from_sys_num, from_var_num, dof_i);
202 var_to_fill.
sys().
solution().
set(to_dof_id, (*temporary_vector)(from_dof_id));
const std::vector< VariableName > & _var_names_to_fill
The names of the variables which serve as a container for the reconstructed solution.
static InputParameters validParams()
NumericVector< Number > & solution()
VariableMappingBase & getMapping(const std::string &name) const
Get the mapping using the parameters of the moose object.
const std::vector< UserObjectName > & _surrogate_model_names
The names of the surrogate models for each variable.
virtual std::unique_ptr< NumericVector< Number > > zero_clone() const =0
virtual libMesh::System & system()=0
T & getSurrogateModelByName(const UserObjectName &name) const
Get a sampler with a given name.
const std::vector< Real > & _input_parameters
Input parameters for the surrogate models.
static InputParameters validParams()
virtual const std::string & name() const
virtual const MooseVariableFieldBase & getVariable(const THREAD_ID tid, const std::string &var_name, Moose::VarKindType expected_var_type=Moose::VarKindType::VAR_ANY, Moose::VarFieldType expected_var_field_type=Moose::VarFieldType::VAR_FIELD_ANY) const override
unsigned int variable_number(std::string_view var) const
registerMooseObject("StochasticToolsApp", InverseMapping)
unsigned int number() const
virtual void inverse_map(const VariableName &vname, const std::vector< Real > &reduced_order_vector, DenseVector< Real > &full_order_vector) const =0
Map a reduced-order vector (from the latent space) back to a full-order solution vector (in DenseVect...
void initialSetup() override
SimpleRange< IndexType > as_range(const std::pair< IndexType, IndexType > &p)
const std::vector< dof_id_type > & getVariableGlobalDoFs()
const std::vector< VariableName > & _var_names_to_reconstruct
The names of the variables in the nonlinear system whose reconstruction we are working on...
void paramError(const std::string ¶m, Args... args) const
InverseMapping(const InputParameters ¶ms)
VariableMappingBase * _mapping
Link to the mapping object which provides the inverse mapping function.
An interface class that helps getting access to Mapping objects.
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
Interface for objects that need to use samplers.
FEProblemBase & _fe_problem
A user object which takes a surrogate (or just user supplied values) to determine coordinates in a la...
std::vector< MooseVariableFieldBase * > _variable_to_reconstruct
Links to the MooseVariables from the nonlinear system whose dof numbering we need to populate the var...
std::vector< MooseVariableFieldBase * > _variable_to_fill
Links to the MooseVariables of the requested variables.
virtual const std::vector< VariableName > & getVariableNames()
Get the available variable names in this mapping.
IntRange< T > make_range(T beg, T end)
virtual MooseMesh & mesh() override
virtual void set(const numeric_index_type i, const Number value)=0
dof_id_type first_dof(const processor_id_type proc) const
void setVariableGlobalDoFs(const std::string &var_name)
const DofMap & get_dof_map() const
auto index_range(const T &sizable)
std::vector< SurrogateModel * > _surrogate_models
Links to the surrogate models which provide functions to determine the coordinates in the latent spac...