Skip to content

Commit

Permalink
Merge pull request #28338 from kyleeswanson/Correcters
Browse files Browse the repository at this point in the history
Add `Correctors` syntax
  • Loading branch information
hugary1995 authored Aug 15, 2024
2 parents ab2fa18 + cdb2752 commit a347719
Show file tree
Hide file tree
Showing 26 changed files with 143 additions and 71 deletions.
6 changes: 6 additions & 0 deletions framework/doc/content/source/actions/AddCorrectorAction.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# AddCorrectorAction

Adds `Corrector` objects to the simulation that are listed under `Correctors/` in the input file.
This action adds them to the [Problem](FEProblem.md).

!syntax parameters /Correctors/AddCorrectorAction
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# PointwiseRenormalizeVector

!syntax description /Correctors/PointwiseRenormalizeVector

This `Corrector` 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 corrector 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 corresponding value from each variable into a vector. The L2-norm is calculated and the vector renormalized for the norm to match [!param](/Correctors/PointwiseRenormalizeVector/norm), unless all solution values are zero. This is repeated for all remaining DOF indices and for the old and older solution states.

!syntax parameters /Correctors/PointwiseRenormalizeVector

!syntax inputs /Correctors/PointwiseRenormalizeVector

!syntax children /Correctors/PointwiseRenormalizeVector

!bibtex bibliography

This file was deleted.

17 changes: 17 additions & 0 deletions framework/doc/content/syntax/Correctors/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Correctors

The `Correctors` system is designed to modify the values of nonlinear variable solutions.
This can be as part of a predictor-corrector time integration scheme for example.

!alert note
Correctors are [UserObjects](UserObjects/index.md) behind the scene. They simply have a dedicated role and syntax.

!alert note
Please let us know on [GitHub Discussions](https://github.com/idaholab/moose/discussions)
how you are using the `Correctors` system so we can include your techniques on this page!

!syntax list /Correctors objects=True actions=False subsystems=False

!syntax list /Correctors objects=False actions=False subsystems=True

!syntax list /Correctors objects=False actions=True subsystems=False
3 changes: 0 additions & 3 deletions framework/include/actions/AddAuxVariableAction.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,6 @@
class AddAuxVariableAction : public AddVariableAction
{
public:
/**
* Class constructor
*/
static InputParameters validParams();

AddAuxVariableAction(const InputParameters & params);
Expand Down
4 changes: 0 additions & 4 deletions framework/include/actions/AddControlAction.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,6 @@
class AddControlAction : public MooseObjectAction
{
public:
/**
* Class constructor
* @param params Parameters for this Action
*/
static InputParameters validParams();

AddControlAction(const InputParameters & parameters);
Expand Down
27 changes: 27 additions & 0 deletions framework/include/actions/AddCorrectorAction.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
//* This file is part of the MOOSE framework
//* https://www.mooseframework.org
//*
//* All rights reserved, see COPYRIGHT for full restrictions
//* https://github.com/idaholab/moose/blob/master/COPYRIGHT
//*
//* Licensed under LGPL 2.1, please see LICENSE for details
//* https://www.gnu.org/licenses/lgpl-2.1.html

#pragma once

// MOOSE includes
#include "MooseObjectAction.h"

/**
* Action for creating Corrector, a UserObject
* designed for modifying nonlinear variable solutions, for example outside of the nonlinear solve
*/
class AddCorrectorAction : public MooseObjectAction
{
public:
static InputParameters validParams();

AddCorrectorAction(const InputParameters & params);

virtual void act() override;
};
3 changes: 0 additions & 3 deletions framework/include/actions/AddExternalAuxVariableAction.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,6 @@
class AddExternalAuxVariableAction : public Action
{
public:
/**
* Class constructor
*/
static InputParameters validParams();

AddExternalAuxVariableAction(const InputParameters & params);
Expand Down
3 changes: 0 additions & 3 deletions framework/include/actions/AddOutputAction.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,6 @@
class AddOutputAction : public MooseObjectAction
{
public:
/**
* Class constructor
*/
static InputParameters validParams();

AddOutputAction(const InputParameters & params);
Expand Down
3 changes: 0 additions & 3 deletions framework/include/actions/AddVariableAction.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,6 @@
class AddVariableAction : public MooseObjectAction
{
public:
/**
* Class constructor
*/
static InputParameters validParams();

AddVariableAction(const InputParameters & params);
Expand Down
4 changes: 0 additions & 4 deletions framework/include/actions/CheckOutputAction.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,6 @@
class CheckOutputAction : public Action
{
public:
/**
* Class constructor
* @param params Input parameters for this object
*/
static InputParameters validParams();

CheckOutputAction(const InputParameters & params);
Expand Down
3 changes: 0 additions & 3 deletions framework/include/actions/CommonOutputAction.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,6 @@
class CommonOutputAction : public Action
{
public:
/**
* Class constructor
*/
static InputParameters validParams();

CommonOutputAction(const InputParameters & params);
Expand Down
4 changes: 0 additions & 4 deletions framework/include/actions/SetupRecoverFileBaseAction.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,6 @@
class SetupRecoverFileBaseAction : public Action
{
public:
/**
* Class constructor
* @param params Input parameters for this action
*/
static InputParameters validParams();

SetupRecoverFileBaseAction(const InputParameters & params);
Expand Down
1 change: 1 addition & 0 deletions framework/include/physics/PhysicsBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,7 @@ class PhysicsBase : public Action, public InputParametersChecksUtils<PhysicsBase
virtual void addMaterials() {}
virtual void addFunctorMaterials() {}
virtual void addUserObjects() {}
virtual void addCorrectors() {}
virtual void addMultiApps() {}
virtual void addTransfers() {}
virtual void addPostprocessors() {}
Expand Down
32 changes: 32 additions & 0 deletions framework/src/actions/AddCorrectorAction.C
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
//* This file is part of the MOOSE framework
//* https://www.mooseframework.org
//*
//* All rights reserved, see COPYRIGHT for full restrictions
//* https://github.com/idaholab/moose/blob/master/COPYRIGHT
//*
//* Licensed under LGPL 2.1, please see LICENSE for details
//* https://www.gnu.org/licenses/lgpl-2.1.html

#include "AddCorrectorAction.h"
#include "FEProblem.h"

registerMooseAction("MooseApp", AddCorrectorAction, "add_corrector");

InputParameters
AddCorrectorAction::validParams()
{
InputParameters params = MooseObjectAction::validParams();
params.addClassDescription("Add a Corrector object to the simulation.");
return params;
}

AddCorrectorAction::AddCorrectorAction(const InputParameters & params) : MooseObjectAction(params)
{
}

void
AddCorrectorAction::act()
{
// Correctors are user objects in the backend
_problem->addUserObject(_type, _name, _moose_object_pars);
}
6 changes: 5 additions & 1 deletion framework/src/base/Moose.C
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,8 @@ addActionTypes(Syntax & syntax)
registerMooseObjectTask("add_mesh_division", MeshDivision, false);
registerMooseObjectTask("add_user_object", UserObject, false);
appendMooseObjectTask ("add_user_object", Postprocessor);
appendDeprecatedMooseObjectTask("add_user_object", Corrector);
registerMooseObjectTask("add_corrector", Corrector, false);

registerMooseObjectTask("add_postprocessor", Postprocessor, false);
registerMooseObjectTask("add_vector_postprocessor", VectorPostprocessor, false);
Expand Down Expand Up @@ -325,7 +327,7 @@ addActionTypes(Syntax & syntax)
"(setup_variable_complete)"
"(setup_quadrature)"
"(add_periodic_bc)"
"(add_user_object)"
"(add_user_object, add_corrector)"
"(add_distribution)"
"(add_sampler)"
"(setup_function_complete)"
Expand Down Expand Up @@ -576,6 +578,8 @@ associateSyntaxInner(Syntax & syntax, ActionFactory & /*action_factory*/)
registerSyntax("AddControlAction", "Controls/*");
registerSyntax("AddBoundAction", "Bounds/*");
registerSyntax("AddBoundsVectorsAction", "Bounds");
registerSyntax("AddCorrectorAction", "Correctors/*");
syntax.registerSyntaxType("Correctors/*", "UserObjectName");

registerSyntax("AddNodalNormalsAction", "NodalNormals");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ PointwiseRenormalizeVector::validParams()
"Pointwise renormalize the solution of a set of variables comprising a vector");
params.addCoupledVar("v", "Variables comprising the vector");
params.addParam<Real>("norm", 1.0, "Desired norm for the coupled variable vector");
params.registerBase("Corrector");

return params;
}

Expand Down
2 changes: 2 additions & 0 deletions framework/src/physics/PhysicsBase.C
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,8 @@ PhysicsBase::act()
addFunctions();
else if (_current_task == "add_user_object")
addUserObjects();
else if (_current_task == "add_corrector")
addCorrectors();

else if (_current_task == "add_aux_variable")
addAuxiliaryVariables();
Expand Down
1 change: 1 addition & 0 deletions modules/doc/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ Extensions:
constraints: syntax/Constraints/index.md
controllogic: syntax/ControlLogic/index.md
controls: syntax/Controls/index.md
correctors: syntax/Correctors/index.md
dampers: syntax/Dampers/index.md
dgkernels: syntax/DGKernels/index.md
dirackernels: syntax/DiracKernels/index.md
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# NSPressurePin

!syntax description /Correctors/NSPressurePin

## Overview

The `NSPressurePin` can pin the pressure in two modes:

- by offsetting the pressure variable to make it have an average equal to the [!param](/Correctors/NSPressurePin/phi0) parameter value
- by offsetting the pressure variable to make its value equal to the [!param](/Correctors/NSPressurePin/phi0) parameter value in the element
containing the point specified by the [!param](/Correctors/NSPressurePin/point) parameter.


!alert note
In the [NSFVAction.md], a `NSPressurePin` can be used by setting the [!param](/Modules/NavierStokesFV/pinned_pressure_type) parameter
to `average-uo` or `point-value-uo` respectively.

!syntax parameters /Correctors/NSPressurePin

!syntax inputs /Correctors/NSPressurePin

!syntax children /Correctors/NSPressurePin

This file was deleted.

1 change: 1 addition & 0 deletions modules/navier_stokes/include/physics/WCNSFVFlowPhysics.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ class WCNSFVFlowPhysics final : public NavierStokesPhysicsBase
void addFVBCs() override;
void addMaterials() override;
void addUserObjects() override;
void addCorrectors() override;
void addPostprocessors() override;

/// Function adding kernels for the incompressible continuity equation
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ NSPressurePin::validParams()
"pressure_average", "A postprocessor that computes the average of the pressure variable");

params.addClassDescription("Pins the pressure after a solve");
params.registerBase("Corrector");

return params;
}
Expand Down
5 changes: 5 additions & 0 deletions modules/navier_stokes/src/physics/WCNSFVFlowPhysics.C
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ registerMooseAction("NavierStokesApp", WCNSFVFlowPhysics, "add_fv_kernel");
registerMooseAction("NavierStokesApp", WCNSFVFlowPhysics, "add_fv_bc");
registerMooseAction("NavierStokesApp", WCNSFVFlowPhysics, "add_material");
registerMooseAction("NavierStokesApp", WCNSFVFlowPhysics, "add_user_object");
registerMooseAction("NavierStokesApp", WCNSFVFlowPhysics, "add_corrector");
registerMooseAction("NavierStokesApp", WCNSFVFlowPhysics, "add_postprocessor");
registerMooseAction("NavierStokesApp", WCNSFVFlowPhysics, "get_turbulence_physics");

Expand Down Expand Up @@ -1149,7 +1150,11 @@ WCNSFVFlowPhysics::addUserObjects()
{
// Rhie Chow user object for interpolation velocities
addRhieChowUserObjects();
}

void
WCNSFVFlowPhysics::addCorrectors()
{
if (!_has_flow_equations)
return;

Expand Down

0 comments on commit a347719

Please sign in to comment.