Skip to content

Commit

Permalink
Address comments (idaholab#21801)
Browse files Browse the repository at this point in the history
  • Loading branch information
dschwen authored and MengnanLi91 committed Feb 21, 2023
1 parent f72b15b commit 1d75f0b
Show file tree
Hide file tree
Showing 8 changed files with 55 additions and 42 deletions.
@@ -0,0 +1,21 @@
# PointwiseRenormalizeVector

!syntax description /UserObjects/PointwiseRenormalizeVector

This user object can pointwise renormalize the solution for a set of variables, taking each variable as the component of a vector and scaling the variables to obtain the user specified L2-norm.

## Applications

For example in a micromagnetics simulation the magnetization director field is a vector field that should stay normalized, however the evolution equations might not be strictly norm conserving, requiring a renormalization at the end of each time step to avoid drift on the norm.

## Design

The PointwiseRenormalizeVector user object is derived from `GeneralUserObject` and iterates over all active local elements. On each element the DOF indices for all coupled variables are obtained. Starting with the first index for each variable we check of the DOF is local to the current processor and assemble the corresponing value from each variable into a vector. The L2-norm is calculated and the vector renormalized for the norm to match [!param](/UserObjects/PointwiseRenormalizeVector/norm), unless all soluton values are zero. This is repeated for all remaining DOF indices and for the old and older solution states.

!syntax parameters /UserObjects/PointwiseRenormalizeVector

!syntax inputs /UserObjects/PointwiseRenormalizeVector

!syntax children /UserObjects/PointwiseRenormalizeVector

!bibtex bibliography
21 changes: 0 additions & 21 deletions framework/doc/content/source/userobject/RenormalizeVector.md

This file was deleted.

Expand Up @@ -17,12 +17,12 @@ class NonlinearSystemBase;
/**
* Renormalization of a vector variable (i.e. a set of variables comprising a vector)
*/
class RenormalizeVector : public GeneralUserObject
class PointwiseRenormalizeVector : public GeneralUserObject
{
public:
static InputParameters validParams();

RenormalizeVector(const InputParameters & parameters);
PointwiseRenormalizeVector(const InputParameters & parameters);

void initialize() override;
void execute() override;
Expand Down
Expand Up @@ -7,17 +7,17 @@
//* Licensed under LGPL 2.1, please see LICENSE for details
//* https://www.gnu.org/licenses/lgpl-2.1.html

#include "RenormalizeVector.h"
#include "PointwiseRenormalizeVector.h"
#include "MooseError.h"
#include "NonlinearSystemBase.h"

#include "libmesh/numeric_vector.h"
#include "libmesh/int_range.h"

registerMooseObject("MooseApp", RenormalizeVector);
registerMooseObject("MooseApp", PointwiseRenormalizeVector);

InputParameters
RenormalizeVector::validParams()
PointwiseRenormalizeVector::validParams()
{
InputParameters params = GeneralUserObject::validParams();
params.addClassDescription(
Expand All @@ -27,17 +27,30 @@ RenormalizeVector::validParams()
return params;
}

RenormalizeVector::RenormalizeVector(const InputParameters & parameters)
PointwiseRenormalizeVector::PointwiseRenormalizeVector(const InputParameters & parameters)
: GeneralUserObject(parameters),
_mesh(_fe_problem.mesh()),
_var_names(getParam<std::vector<VariableName>>("v")),
_target_norm(getParam<Real>("norm")),
_nl_sys(_fe_problem.getNonlinearSystemBase()),
_sys(_nl_sys.system())
{
const MooseVariableFieldBase * first_var = nullptr;
for (const auto & var_name : _var_names)
{
auto & var = _fe_problem.getVariable(0, var_name);
if (!first_var)
first_var = &var;
else
{
// check order and family for consistency
if (first_var->feType() != var.feType())
paramError("v", "All supplied variables must be of the same order and family.");
// check block restriction for consistency
if (!first_var->hasBlocks(var.blocks()) || !var.hasBlocks(first_var->blocks()))
paramError("v", "All supplied variables must have the same block restriction.");
}

if (_sys.number() != var.sys().system().number())
paramError("v", "Variables must be all in the non-linear system.");

Expand All @@ -53,14 +66,14 @@ RenormalizeVector::RenormalizeVector(const InputParameters & parameters)
}

void
RenormalizeVector::initialize()
PointwiseRenormalizeVector::initialize()
{
// do one solution.close to get updated
_sys.solution->close();
}

void
RenormalizeVector::execute()
PointwiseRenormalizeVector::execute()
{
auto & dof_map = _sys.get_dof_map();
const auto local_dof_begin = dof_map.first_dof();
Expand Down Expand Up @@ -113,7 +126,7 @@ RenormalizeVector::execute()
}

void
RenormalizeVector::finalize()
PointwiseRenormalizeVector::finalize()
{
for (const auto s : make_range(3))
if (_nl_sys.hasSolutionState(s))
Expand Down
Expand Up @@ -48,7 +48,7 @@

[UserObjects]
[renormalize]
type = RenormalizeVector
type = PointwiseRenormalizeVector
v = 'v_x v_y'
execute_on = TIMESTEP_END
[]
Expand Down
11 changes: 11 additions & 0 deletions test/tests/userobjects/pointwise_renormalize_vector/tests
@@ -0,0 +1,11 @@
[Tests]
[test]
type = Exodiff
input = test.i
exodiff = test_out.e
design = PointwiseRenormalizeVector.md
issues = '#21801'
abs_zero = 1e-9
requirement = "The system shall be able to pointwise renormalize tuples of solution variables as a vector to a desired L2-norm"
[]
[]
11 changes: 0 additions & 11 deletions test/tests/userobjects/renormalize_vector/tests

This file was deleted.

0 comments on commit 1d75f0b

Please sign in to comment.