Skip to content

Commit

Permalink
Framework tests and ADBodyForce added (idaholab#13260)
Browse files Browse the repository at this point in the history
  • Loading branch information
tophmatthews committed Apr 22, 2019
1 parent 41245a0 commit f092616
Show file tree
Hide file tree
Showing 17 changed files with 550 additions and 4 deletions.
52 changes: 52 additions & 0 deletions framework/include/kernels/ADBodyForce.h
@@ -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
5 changes: 3 additions & 2 deletions framework/include/kernels/ADKernel.h
Expand Up @@ -53,8 +53,9 @@
using ADKernelTempl<type, compute_stage>::accumulateTaggedLocalMatrix; \
using ADKernelTempl<type, compute_stage>::variable; \
using ADKernelTempl<type, compute_stage>::paramError; \
using ADKernelTempl<type, compute_stage>::isParamValid
using ADKernelTempl<type, compute_stage>::getFunction
using ADKernelTempl<type, compute_stage>::isParamValid; \
using ADKernelTempl<type, compute_stage>::getFunction; \
using ADKernelTempl<type, compute_stage>::getPostprocessorValue

#define usingKernelMembers usingTemplKernelMembers(Real)
#define usingVectorKernelMembers usingTemplKernelMembers(RealVectorValue)
Expand Down
43 changes: 43 additions & 0 deletions framework/src/kernels/ADBodyForce.C
@@ -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]);
}
69 changes: 69 additions & 0 deletions test/tests/bcs/bc_preset_nodal/ad-bc_function_preset.i
@@ -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
[]
58 changes: 58 additions & 0 deletions test/tests/bcs/bc_preset_nodal/ad-bc_preset_nodal.i
@@ -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
[]
1 change: 1 addition & 0 deletions test/tests/bcs/bc_preset_nodal/gold/ad-bc_func_out.e
1 change: 1 addition & 0 deletions test/tests/bcs/bc_preset_nodal/gold/ad-bc_preset_out.e
39 changes: 38 additions & 1 deletion test/tests/bcs/bc_preset_nodal/tests
Expand Up @@ -7,12 +7,49 @@
design = 'bcs/FunctionPresetBC.md'
requirement = "MOOSE shall support setting Dirichlet type boundary conditions, supplied as a function, directly to the solution vector prior to the solve."
[../]

[./bc_preset_nodal_test]
type = 'Exodiff'
input = 'bc_preset_nodal.i'
exodiff = 'bc_preset_out.e'
design = 'bcs/PresetBC.md'
requirement = "MOOSE shall support setting Dirichlet type boundary conditions directly to the solution vector prior to the solve."
[../]

[./ad-bc_function_nodal_test]
type = 'Exodiff'
input = 'ad-bc_function_preset.i'
exodiff = 'ad-bc_func_out.e'
design = 'bcs/ADFunctionPresetBC.md'
issues = '#13261'
requirement = "MOOSE shall support setting AD Dirichlet type boundary conditions, supplied as a function, directly to the solution vector prior to the solve."
[../]
[./ad-bc_preset_nodal_test]
type = 'Exodiff'
input = 'ad-bc_preset_nodal.i'
exodiff = 'ad-bc_preset_out.e'
design = 'bcs/ADPresetBC.md'
issues = '#13261'
requirement = "MOOSE shall support setting AD Dirichlet type boundary conditions directly to the solution vector prior to the solve."
[../]

[./ad-bc_function_nodal_test-jac]
type = 'PetscJacobianTester'
input = 'ad-bc_function_preset.i'
run_sim = True
ratio_tol = 1e-7
difference_tol = 1e-6
design = 'bcs/ADFunctionPresetBC.md jacobian_definition.md'
issues = '#13261'
requirement = "MOOSE shall support setting AD Dirichlet type boundary conditions, supplied as a function, directly to the solution vector prior to the solve and have perfect Jacobians."
[../]
[./ad-bc_preset_nodal_test-jac]
type = 'PetscJacobianTester'
input = 'ad-bc_preset_nodal.i'
run_sim = True
ratio_tol = 1e-7
difference_tol = 1e-6
design = 'bcs/ADPresetBC.md jacobian_definition.md'
issues = '#13261'
requirement = "MOOSE shall support setting AD Dirichlet type boundary conditions directly to the solution vector prior to the solve and have perfect Jacobians."
[../]
[]
@@ -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
[]
1 change: 1 addition & 0 deletions test/tests/bcs/function_dirichlet_bc/gold/ad-out.e

0 comments on commit f092616

Please sign in to comment.