14#include "libmesh/numeric_vector.h"
15#include "libmesh/int_range.h"
24 "Pointwise renormalize the solution of a set of variables comprising a vector");
26 params.
addParam<Real>(
"norm", 1.0,
"Desired norm for the coupled variable vector");
34 _mesh(_fe_problem.
mesh()),
35 _var_names(getParam<
std::vector<VariableName>>(
"v")),
36 _target_norm(getParam<Real>(
"norm"))
47 if (first_var->
feType() != var.feType())
48 paramError(
"v",
"All supplied variables must be of the same order and family.");
50 if (!first_var->
hasBlocks(var.blockIDs()) || !var.hasBlocks(first_var->
blockIDs()))
51 paramError(
"v",
"All supplied variables must have the same block restriction.");
54 if (
_sys.
number() != var.sys().system().number())
55 paramError(
"v",
"Variables must be all in the non-linear system.");
60 for (
unsigned int p = 0; p < var.count(); ++p)
79 const auto local_dof_begin = dof_map.
first_dof();
80 const auto local_dof_end = dof_map.end_dof();
82 std::vector<std::vector<dof_id_type>> dof_indices(
_var_numbers.size());
90 dof_map.dof_indices(elem, dof_indices[i],
_var_numbers[i]);
93 mooseAssert(dof_indices[i].size() == dof_indices[0].size(),
94 "All specified variables should have the same number of DOFs");
98 for (
const auto s : make_range(3))
104 for (
const auto j : index_range(dof_indices[0]))
108 if (dof_indices[0][j] > local_dof_end || dof_indices[0][j] < local_dof_begin)
114 norm += Utility::pow<2>(solution(dof_indices[i][j]));
118 norm = std::sqrt(norm);
122 solution.set(dof_indices[i][j], solution(dof_indices[i][j]) / norm *
_target_norm);
131 for (
const auto s : make_range(3))
registerMooseObject("MooseApp", PointwiseRenormalizeVector)
bool hasBlocks(const SubdomainName &name) const
Test if the supplied block name is valid for this object.
virtual const std::set< SubdomainID > & blockIDs() const
Return the block subdomain ids for this object Note, if this is not block restricted,...
virtual ArrayMooseVariable & getArrayVariable(const THREAD_ID tid, const std::string &var_name) override
Returns the variable reference for requested ArrayMooseVariable which may be in any system.
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
Returns the variable reference for requested variable which must be of the expected_var_type (Nonline...
static InputParameters validParams()
void paramError(const std::string ¶m, Args... args) const
Emits an error prefixed with the file and line number of the given param (from the input file) along ...
const libMesh::ConstElemRange * getActiveLocalElementRange()
Return pointers to range objects for various types of ranges (local nodes, boundary elems,...
const libMesh::FEType & feType() const
Get the type of finite element object.
This class provides an interface for common operations on field variables of both FE and FV types wit...
Renormalization of a vector variable (i.e.
void initialize() override
Called before execute() is ever called so that data can be cleared.
const Real _target_norm
desired norm
static InputParameters validParams()
std::vector< unsigned int > _var_numbers
MooseMesh & _mesh
reference to the mesh
PointwiseRenormalizeVector(const InputParameters ¶meters)
void finalize() override
Finalize.
void execute() override
Execute method.
const std::vector< VariableName > & _var_names
names of the variables to renormalize
unsigned int number() const
Gets the number of this system.
virtual NumericVector< Number > & solutionState(const unsigned int state, Moose::SolutionIterationType iteration_type=Moose::SolutionIterationType::Time)
Get a state of the solution (0 = current, 1 = old, 2 = older, etc).
virtual bool hasSolutionState(const unsigned int state, Moose::SolutionIterationType iteration_type=Moose::SolutionIterationType::Time) const
Whether or not the system has the solution state (0 = current, 1 = old, 2 = older,...
void update()
Update the system (doing libMesh magic)
virtual libMesh::System & system()=0
Get the reference to the libMesh system.
FEProblemBase & _fe_problem
Reference to the FEProblemBase for this user object.
SystemBase & _sys
Reference to the system object for this user object.
dof_id_type first_dof(const processor_id_type proc) const
std::unique_ptr< NumericVector< Number > > solution
unsigned int variable_number(std::string_view var) const
const DofMap & get_dof_map() const