Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #20120 from laagesen/intfunction_20065
Add ForcingFunctionAux AuxKernel
- Loading branch information
Showing
6 changed files
with
214 additions
and
0 deletions.
There are no files selected for viewing
23 changes: 23 additions & 0 deletions
23
framework/doc/content/source/auxkernels/ForcingFunctionAux.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# ForcingFunctionAux | ||
|
||
!syntax description /AuxKernels/ForcingFunctionAux | ||
|
||
This `AuxKernel` adds a forcing function to the value of an `AuxVariable` from the previous | ||
time step. For each time step $\delta t$, the value of the `AuxVariable` is computed as | ||
\begin{equation} | ||
V(t + \Delta t) = V(t) + f \Delta t | ||
\end{equation} | ||
where $V$ is the `AuxVariable` and $f$ is the forcing function. $f$ is a MOOSE `function` | ||
that is specified as an input parameter. | ||
|
||
## Example Input File Syntax | ||
|
||
In this example, value of a postprocessor is supplied to the forcing function f used by the `ForcingFunctionAux` `AuxKernel`, which increments the `AuxVariable` T. | ||
|
||
!listing /test/tests/auxkernels/forcing_function_aux/forcing_function_aux.i block=AuxKernels | ||
|
||
!syntax parameters /AuxKernels/ForcingFunctionAux | ||
|
||
!syntax inputs /AuxKernels/ForcingFunctionAux | ||
|
||
!syntax children /AuxKernels/ForcingFunctionAux |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
//* 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 | ||
|
||
#include "FunctionAux.h" | ||
|
||
/** | ||
* Add a forcing function to the previous time step value of an AuxVariable | ||
*/ | ||
class ForcingFunctionAux : public FunctionAux | ||
{ | ||
public: | ||
static InputParameters validParams(); | ||
|
||
ForcingFunctionAux(const InputParameters & parameters); | ||
|
||
protected: | ||
virtual Real computeValue() override; | ||
|
||
/// AuxVariable value at previous time step | ||
const VariableValue & _u_old; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
//* 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 "ForcingFunctionAux.h" | ||
#include "Function.h" | ||
|
||
registerMooseObject("MooseApp", ForcingFunctionAux); | ||
|
||
InputParameters | ||
ForcingFunctionAux::validParams() | ||
{ | ||
InputParameters params = FunctionAux::validParams(); | ||
params.addClassDescription("Auxiliary Kernel that adds a forcing function to the value of an " | ||
"AuxVariable from the previous time step."); | ||
return params; | ||
} | ||
|
||
ForcingFunctionAux::ForcingFunctionAux(const InputParameters & parameters) | ||
: FunctionAux(parameters), _u_old(uOld()) | ||
{ | ||
if (isNodal()) | ||
paramError("variable", "The variable must be elemental"); | ||
} | ||
|
||
Real | ||
ForcingFunctionAux::computeValue() | ||
{ | ||
return _u_old[_qp] + _dt * _func.value(_t, _q_point[_qp]); | ||
} |
117 changes: 117 additions & 0 deletions
117
test/tests/auxkernels/forcing_function_aux/forcing_function_aux.i
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
# This is a test of the ForcingFunctionAux AuxKernel. | ||
# The diffusion equation for u is solved with boundary conditions to force a gradient | ||
# du/dx = 2, which is constant in time. | ||
# du/dx is integrated over the unit square domain using a postprocessor, resulting in 2. | ||
# The value of this postprocessor is supplied to the forcing function f used by | ||
# the ForcingFunctionAux AuxKernel, which increments the AuxVariable T. | ||
# Since the time step is 1, the value of T increases by 2 for each time step. | ||
|
||
[Mesh] | ||
type = GeneratedMesh | ||
dim = 2 | ||
nx = 10 | ||
ny = 10 | ||
[] | ||
|
||
[Variables] | ||
[./u] | ||
[../] | ||
[] | ||
|
||
[AuxVariables] | ||
[./grad_u_x] | ||
order = CONSTANT | ||
family = MONOMIAL | ||
initial_condition = 2 | ||
[../] | ||
[./T] | ||
order = CONSTANT | ||
family = MONOMIAL | ||
initial_condition = 100 | ||
[../] | ||
[] | ||
|
||
[Functions] | ||
[./u_ic_func] | ||
type = ParsedFunction | ||
value = '2*x' | ||
[../] | ||
[./f] | ||
type = ParsedFunction | ||
vars = f | ||
vals = grad_int | ||
value = f | ||
[../] | ||
[] | ||
|
||
[ICs] | ||
[./u_ic] | ||
type = FunctionIC | ||
variable = u | ||
function = u_ic_func | ||
[../] | ||
[] | ||
|
||
[Kernels] | ||
[./dudt] | ||
type = TimeDerivative | ||
variable = u | ||
[../] | ||
[./diff] | ||
type = Diffusion | ||
variable = u | ||
[../] | ||
[] | ||
|
||
[AuxKernels] | ||
[./grad_u_x_aux] | ||
type = VariableGradientComponent | ||
variable = grad_u_x | ||
component = x | ||
gradient_variable = u | ||
[../] | ||
[./T_increment] | ||
type = ForcingFunctionAux | ||
variable = T | ||
function = f | ||
[../] | ||
[] | ||
|
||
[Postprocessors] | ||
[./grad_int] | ||
type = ElementIntegralVariablePostprocessor | ||
variable = grad_u_x | ||
execute_on = 'INITIAL TIMESTEP_END' | ||
[../] | ||
[] | ||
|
||
[BCs] | ||
[./left] | ||
type = DirichletBC | ||
variable = u | ||
boundary = left | ||
value = 0 | ||
[../] | ||
[./right] | ||
type = DirichletBC | ||
variable = u | ||
boundary = right | ||
value = 2 | ||
[../] | ||
[] | ||
|
||
[Executioner] | ||
type = Transient | ||
scheme = bdf2 | ||
solve_type = PJFNK | ||
petsc_options_iname = '-pc_type -pc_hypre_type' | ||
petsc_options_value = 'hypre boomeramg' | ||
nl_abs_tol = 1e-10 | ||
num_steps = 2 | ||
dt = 1 | ||
[] | ||
|
||
[Outputs] | ||
exodus = true | ||
[] | ||
|
Binary file added
BIN
+53.7 KB
test/tests/auxkernels/forcing_function_aux/gold/forcing_function_aux_out.e
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
[Tests] | ||
issues = '#20065' | ||
design = 'auxkernels/ForcingFunctionAux.md' | ||
[./forcing_function_aux] | ||
type = 'Exodiff' | ||
input = 'forcing_function_aux.i' | ||
exodiff = 'forcing_function_aux_out.e' | ||
requirement = "MOOSE shall include the ability to increase the value of an AuxVariable from the previous time step using a forcing function." | ||
[../] | ||
[] |