diff --git a/framework/doc/content/source/actions/AddCorrectorAction.md b/framework/doc/content/source/actions/AddCorrectorAction.md new file mode 100644 index 000000000000..99194010999d --- /dev/null +++ b/framework/doc/content/source/actions/AddCorrectorAction.md @@ -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 diff --git a/framework/doc/content/source/correctors/PointwiseRenormalizeVector.md b/framework/doc/content/source/correctors/PointwiseRenormalizeVector.md new file mode 100644 index 000000000000..a292a4a1abc5 --- /dev/null +++ b/framework/doc/content/source/correctors/PointwiseRenormalizeVector.md @@ -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 diff --git a/framework/doc/content/source/userobjects/PointwiseRenormalizeVector.md b/framework/doc/content/source/userobjects/PointwiseRenormalizeVector.md deleted file mode 100644 index a6d3fee57e75..000000000000 --- a/framework/doc/content/source/userobjects/PointwiseRenormalizeVector.md +++ /dev/null @@ -1,21 +0,0 @@ -# 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 corresponding 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 solution 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 diff --git a/framework/doc/content/syntax/Correctors/index.md b/framework/doc/content/syntax/Correctors/index.md new file mode 100644 index 000000000000..cf99c897d442 --- /dev/null +++ b/framework/doc/content/syntax/Correctors/index.md @@ -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 \ No newline at end of file diff --git a/framework/include/actions/AddAuxVariableAction.h b/framework/include/actions/AddAuxVariableAction.h index 601424ee9b41..ae371719e61a 100644 --- a/framework/include/actions/AddAuxVariableAction.h +++ b/framework/include/actions/AddAuxVariableAction.h @@ -18,9 +18,6 @@ class AddAuxVariableAction : public AddVariableAction { public: - /** - * Class constructor - */ static InputParameters validParams(); AddAuxVariableAction(const InputParameters & params); diff --git a/framework/include/actions/AddControlAction.h b/framework/include/actions/AddControlAction.h index 9d71cf956265..c9b88b710062 100644 --- a/framework/include/actions/AddControlAction.h +++ b/framework/include/actions/AddControlAction.h @@ -21,10 +21,6 @@ class AddControlAction : public MooseObjectAction { public: - /** - * Class constructor - * @param params Parameters for this Action - */ static InputParameters validParams(); AddControlAction(const InputParameters & parameters); diff --git a/framework/include/actions/AddCorrectorAction.h b/framework/include/actions/AddCorrectorAction.h new file mode 100644 index 000000000000..441738ce341a --- /dev/null +++ b/framework/include/actions/AddCorrectorAction.h @@ -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; +}; diff --git a/framework/include/actions/AddExternalAuxVariableAction.h b/framework/include/actions/AddExternalAuxVariableAction.h index ca1b93607210..fa87d241262b 100644 --- a/framework/include/actions/AddExternalAuxVariableAction.h +++ b/framework/include/actions/AddExternalAuxVariableAction.h @@ -18,9 +18,6 @@ class AddExternalAuxVariableAction : public Action { public: - /** - * Class constructor - */ static InputParameters validParams(); AddExternalAuxVariableAction(const InputParameters & params); diff --git a/framework/include/actions/AddOutputAction.h b/framework/include/actions/AddOutputAction.h index dda4d100477d..2c0444827175 100644 --- a/framework/include/actions/AddOutputAction.h +++ b/framework/include/actions/AddOutputAction.h @@ -18,9 +18,6 @@ class AddOutputAction : public MooseObjectAction { public: - /** - * Class constructor - */ static InputParameters validParams(); AddOutputAction(const InputParameters & params); diff --git a/framework/include/actions/AddVariableAction.h b/framework/include/actions/AddVariableAction.h index f626dcafe838..e43e764d2517 100644 --- a/framework/include/actions/AddVariableAction.h +++ b/framework/include/actions/AddVariableAction.h @@ -19,9 +19,6 @@ class AddVariableAction : public MooseObjectAction { public: - /** - * Class constructor - */ static InputParameters validParams(); AddVariableAction(const InputParameters & params); diff --git a/framework/include/actions/CheckOutputAction.h b/framework/include/actions/CheckOutputAction.h index ab00de715cd8..00625efbfa79 100644 --- a/framework/include/actions/CheckOutputAction.h +++ b/framework/include/actions/CheckOutputAction.h @@ -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); diff --git a/framework/include/actions/CommonOutputAction.h b/framework/include/actions/CommonOutputAction.h index 9193573300bf..69a59e781cbc 100644 --- a/framework/include/actions/CommonOutputAction.h +++ b/framework/include/actions/CommonOutputAction.h @@ -24,9 +24,6 @@ class CommonOutputAction : public Action { public: - /** - * Class constructor - */ static InputParameters validParams(); CommonOutputAction(const InputParameters & params); diff --git a/framework/include/actions/SetupRecoverFileBaseAction.h b/framework/include/actions/SetupRecoverFileBaseAction.h index 58c80d6d7d20..30fa9dff6e1f 100644 --- a/framework/include/actions/SetupRecoverFileBaseAction.h +++ b/framework/include/actions/SetupRecoverFileBaseAction.h @@ -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); diff --git a/framework/include/userobjects/PointwiseRenormalizeVector.h b/framework/include/correctors/PointwiseRenormalizeVector.h similarity index 100% rename from framework/include/userobjects/PointwiseRenormalizeVector.h rename to framework/include/correctors/PointwiseRenormalizeVector.h diff --git a/framework/include/physics/PhysicsBase.h b/framework/include/physics/PhysicsBase.h index 159776beb898..408b2beb760a 100644 --- a/framework/include/physics/PhysicsBase.h +++ b/framework/include/physics/PhysicsBase.h @@ -192,6 +192,7 @@ class PhysicsBase : public Action, public InputParametersChecksUtilsaddUserObject(_type, _name, _moose_object_pars); +} diff --git a/framework/src/base/Moose.C b/framework/src/base/Moose.C index 6b1ffdad20f5..42d92c12ac3f 100644 --- a/framework/src/base/Moose.C +++ b/framework/src/base/Moose.C @@ -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); @@ -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)" @@ -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"); diff --git a/framework/src/userobjects/PointwiseRenormalizeVector.C b/framework/src/correctors/PointwiseRenormalizeVector.C similarity index 99% rename from framework/src/userobjects/PointwiseRenormalizeVector.C rename to framework/src/correctors/PointwiseRenormalizeVector.C index 54763001f344..7ae8be1fa3a4 100644 --- a/framework/src/userobjects/PointwiseRenormalizeVector.C +++ b/framework/src/correctors/PointwiseRenormalizeVector.C @@ -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("norm", 1.0, "Desired norm for the coupled variable vector"); + params.registerBase("Corrector"); + return params; } diff --git a/framework/src/physics/PhysicsBase.C b/framework/src/physics/PhysicsBase.C index 3581fee97f1b..d4d7d2d89d0d 100644 --- a/framework/src/physics/PhysicsBase.C +++ b/framework/src/physics/PhysicsBase.C @@ -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(); diff --git a/modules/doc/config.yml b/modules/doc/config.yml index a3b31776bbcf..b90b54877d73 100644 --- a/modules/doc/config.yml +++ b/modules/doc/config.yml @@ -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 diff --git a/modules/navier_stokes/doc/content/source/correctors/NSPressurePin.md b/modules/navier_stokes/doc/content/source/correctors/NSPressurePin.md new file mode 100644 index 000000000000..b7da02e9ffb3 --- /dev/null +++ b/modules/navier_stokes/doc/content/source/correctors/NSPressurePin.md @@ -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 diff --git a/modules/navier_stokes/doc/content/source/userobjects/NSPressurePin.md b/modules/navier_stokes/doc/content/source/userobjects/NSPressurePin.md deleted file mode 100644 index 00dab9ae3598..000000000000 --- a/modules/navier_stokes/doc/content/source/userobjects/NSPressurePin.md +++ /dev/null @@ -1,22 +0,0 @@ -# NSPressurePin - -!syntax description /UserObjects/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](/UserObjects/NSPressurePin/phi0) parameter value -- by offsetting the pressure variable to make its value equal to the [!param](/UserObjects/NSPressurePin/phi0) parameter value in the element - containing the point specified by the [!param](/UserObjects/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 /UserObjects/NSPressurePin - -!syntax inputs /UserObjects/NSPressurePin - -!syntax children /UserObjects/NSPressurePin diff --git a/modules/navier_stokes/include/userobjects/NSPressurePin.h b/modules/navier_stokes/include/correctors/NSPressurePin.h similarity index 100% rename from modules/navier_stokes/include/userobjects/NSPressurePin.h rename to modules/navier_stokes/include/correctors/NSPressurePin.h diff --git a/modules/navier_stokes/include/physics/WCNSFVFlowPhysics.h b/modules/navier_stokes/include/physics/WCNSFVFlowPhysics.h index c513b5c2fc49..f02db5d3eb9f 100644 --- a/modules/navier_stokes/include/physics/WCNSFVFlowPhysics.h +++ b/modules/navier_stokes/include/physics/WCNSFVFlowPhysics.h @@ -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 diff --git a/modules/navier_stokes/src/userobjects/NSPressurePin.C b/modules/navier_stokes/src/correctors/NSPressurePin.C similarity index 99% rename from modules/navier_stokes/src/userobjects/NSPressurePin.C rename to modules/navier_stokes/src/correctors/NSPressurePin.C index be5897ff4908..b5478e4d0113 100644 --- a/modules/navier_stokes/src/userobjects/NSPressurePin.C +++ b/modules/navier_stokes/src/correctors/NSPressurePin.C @@ -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; } diff --git a/modules/navier_stokes/src/physics/WCNSFVFlowPhysics.C b/modules/navier_stokes/src/physics/WCNSFVFlowPhysics.C index 154e0c102c28..2fedb313625c 100644 --- a/modules/navier_stokes/src/physics/WCNSFVFlowPhysics.C +++ b/modules/navier_stokes/src/physics/WCNSFVFlowPhysics.C @@ -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"); @@ -1149,7 +1150,11 @@ WCNSFVFlowPhysics::addUserObjects() { // Rhie Chow user object for interpolation velocities addRhieChowUserObjects(); +} +void +WCNSFVFlowPhysics::addCorrectors() +{ if (!_has_flow_equations) return;