forked from idaholab/moose
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Framework tests and ADBodyForce added (idaholab#13260)
- Loading branch information
1 parent
41245a0
commit f092616
Showing
17 changed files
with
550 additions
and
4 deletions.
There are no files selected for viewing
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,52 @@ | ||
//* 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 | ||
|
||
#ifndef ADBODYFORCE_H | ||
#define ADBODYFORCE_H | ||
|
||
#include "ADKernelValue.h" | ||
|
||
// Forward Declaration | ||
template <ComputeStage> | ||
class ADBodyForce; | ||
class Function; | ||
|
||
declareADValidParams(ADBodyForce); | ||
|
||
/** | ||
* This kernel implements a generic functional | ||
* body force term: | ||
* $ - c \cdof f \cdot \phi_i $ | ||
* | ||
* The coefficient and function both have defaults | ||
* equal to 1.0. | ||
*/ | ||
template <ComputeStage compute_stage> | ||
class ADBodyForce : public ADKernelValue<compute_stage> | ||
{ | ||
public: | ||
ADBodyForce(const InputParameters & parameters); | ||
|
||
protected: | ||
virtual ADReal precomputeQpResidual() override; | ||
|
||
/// Scale factor | ||
const Real & _scale; | ||
|
||
/// Optional function value | ||
Function & _function; | ||
|
||
/// Optional Postprocessor value | ||
const PostprocessorValue & _postprocessor; | ||
|
||
usingKernelValueMembers; | ||
using KernelBase::_q_point; | ||
}; | ||
|
||
#endif // ADBODYFORCE_H |
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
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,43 @@ | ||
//* 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 "ADBodyForce.h" | ||
|
||
#include "Function.h" | ||
|
||
registerADMooseObject("MooseApp", ADBodyForce); | ||
|
||
defineADValidParams( | ||
ADBodyForce, | ||
ADKernelValue, | ||
params.addClassDescription( | ||
"Demonstrates the multiple ways that scalar values can be introduced " | ||
"into kernels, e.g. (controllable) constants, functions, and " | ||
"postprocessors. Implements the weak form $(\\psi_i, -f)$."); | ||
params.addParam<Real>("value", 1.0, "Coefficient to multiply by the body force term"); | ||
params.addParam<FunctionName>("function", "1", "A function that describes the body force"); | ||
params.addParam<PostprocessorName>( | ||
"postprocessor", 1, "A postprocessor whose value is multiplied by the body force"); | ||
params.declareControllable("value");); | ||
|
||
template <ComputeStage compute_stage> | ||
ADBodyForce<compute_stage>::ADBodyForce(const InputParameters & parameters) | ||
: ADKernelValue<compute_stage>(parameters), | ||
_scale(adGetParam<Real>("value")), | ||
_function(getFunction("function")), | ||
_postprocessor(getPostprocessorValue("postprocessor")) | ||
{ | ||
} | ||
|
||
template <ComputeStage compute_stage> | ||
ADReal | ||
ADBodyForce<compute_stage>::precomputeQpResidual() | ||
{ | ||
return -_scale * _postprocessor * _function.value(_t, _q_point[_qp]); | ||
} |
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,69 @@ | ||
[Mesh] | ||
type = GeneratedMesh | ||
dim = 2 | ||
nx = 10 | ||
ny = 10 | ||
nz = 0 | ||
zmin = 0 | ||
zmax = 0 | ||
elem_type = QUAD4 | ||
[] | ||
|
||
[Variables] | ||
active = 'u' | ||
|
||
[./u] | ||
order = FIRST | ||
family = LAGRANGE | ||
[../] | ||
[] | ||
|
||
[Functions] | ||
[./left] | ||
type = ParsedFunction | ||
value = 'y' | ||
[../] | ||
|
||
[./right] | ||
type = ParsedFunction | ||
value = '1+y' | ||
[../] | ||
[] | ||
|
||
[Kernels] | ||
active = 'diff' | ||
|
||
[./diff] | ||
type = ADDiffusion | ||
variable = u | ||
[../] | ||
[] | ||
|
||
[BCs] | ||
active = 'left right' | ||
|
||
[./left] | ||
type = ADFunctionPresetBC | ||
variable = u | ||
boundary = 3 | ||
function = left | ||
[../] | ||
|
||
[./right] | ||
type = ADFunctionPresetBC | ||
variable = u | ||
boundary = 1 | ||
function = right | ||
[../] | ||
[] | ||
|
||
[Executioner] | ||
type = Steady | ||
|
||
solve_type = 'PJFNK' | ||
[] | ||
|
||
[Outputs] | ||
file_base = ad-bc_func_out | ||
exodus = true | ||
[] |
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,58 @@ | ||
[Mesh] | ||
type = GeneratedMesh | ||
dim = 2 | ||
nx = 2 | ||
ny = 2 | ||
nz = 0 | ||
zmin = 0 | ||
zmax = 0 | ||
elem_type = QUAD4 | ||
[] | ||
|
||
[Variables] | ||
active = 'u' | ||
|
||
[./u] | ||
order = FIRST | ||
family = LAGRANGE | ||
[../] | ||
[] | ||
|
||
[Kernels] | ||
active = 'diff' | ||
|
||
[./diff] | ||
type = ADDiffusion | ||
variable = u | ||
[../] | ||
[] | ||
|
||
[BCs] | ||
active = 'left right' | ||
|
||
# We will use PresetBCs | ||
[./left] | ||
type = ADPresetBC | ||
variable = u | ||
boundary = 3 | ||
value = 0 | ||
[../] | ||
|
||
[./right] | ||
type = ADPresetBC | ||
variable = u | ||
boundary = 1 | ||
value = 1 | ||
[../] | ||
[] | ||
|
||
[Executioner] | ||
type = Steady | ||
|
||
solve_type = 'PJFNK' | ||
[] | ||
|
||
[Outputs] | ||
file_base = ad-bc_preset_out | ||
exodus = true | ||
[] |
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 @@ | ||
bc_func_out.e |
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 @@ | ||
bc_preset_out.e |
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
90 changes: 90 additions & 0 deletions
90
test/tests/bcs/function_dirichlet_bc/ad-function_dirichlet_bc_test.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,90 @@ | ||
########################################################### | ||
# This is a test of Boundary Condition System. The | ||
# FunctionDirichletBC is used to contribute the residuals | ||
# to the boundary term operators in the weak form. | ||
# | ||
# @Requirement F3.40 | ||
########################################################### | ||
|
||
|
||
[Mesh] | ||
file = square.e | ||
uniform_refine = 4 | ||
[] | ||
|
||
[Variables] | ||
active = 'u' | ||
|
||
[./u] | ||
order = FIRST | ||
family = LAGRANGE | ||
[../] | ||
[] | ||
|
||
[Functions] | ||
active = 'ff_1 ff_2 forcing_func bc_func' | ||
|
||
[./ff_1] | ||
type = ParsedFunction | ||
value = alpha*alpha*pi | ||
vars = 'alpha' | ||
vals = '16' | ||
[../] | ||
|
||
[./ff_2] | ||
type = ParsedFunction | ||
value = pi*sin(alpha*pi*x) | ||
vars = 'alpha' | ||
vals = '16' | ||
[../] | ||
|
||
[./forcing_func] | ||
type = CompositeFunction | ||
functions = 'ff_1 ff_2' | ||
[../] | ||
|
||
[./bc_func] | ||
type = ParsedFunction | ||
value = sin(alpha*pi*x) | ||
vars = 'alpha' | ||
vals = '16' | ||
[../] | ||
[] | ||
|
||
[Kernels] | ||
active = 'diff forcing' | ||
|
||
[./diff] | ||
type = ADDiffusion | ||
variable = u | ||
[../] | ||
|
||
[./forcing] | ||
type = ADBodyForce | ||
variable = u | ||
function = forcing_func | ||
[../] | ||
[] | ||
|
||
[BCs] | ||
active = 'all' | ||
|
||
# Boundary Condition System | ||
[./all] | ||
type = ADFunctionDirichletBC | ||
variable = u | ||
boundary = '1 2' | ||
function = bc_func | ||
[../] | ||
[] | ||
|
||
[Executioner] | ||
type = Steady | ||
nl_rel_tol = 1e-12 | ||
[] | ||
|
||
[Outputs] | ||
execute_on = 'timestep_end' | ||
file_base = ad-out | ||
exodus = true | ||
[] |
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 @@ | ||
out.e |
Oops, something went wrong.