Permalink
Browse files

Merge pull request #12646 from tophmatthews/ad_diff_12633

Added ADMatDiffusion
  • Loading branch information...
lindsayad committed Jan 8, 2019
2 parents 898a11b + 17a9d19 commit 35aaa1be215ac1f7a405d4267e8ae54442803d48
@@ -0,0 +1,21 @@
# ADMatDiffusion

## Description

`ADMatDiffusion` implements the term
\begin{equation}
\nabla D(a,b,\dots) \nabla c,
\end{equation}
where the diffusion coefficient $D$ (`diffusivity`) is provided by a `Material` or `ADMaterial`.
$D$ can depend on arbitrary non-linear variables $a,b,\dots$ (`args`).
The complete Jacobian contributions are provided by automatic differentiation as long as $D$ is given using an `ADMaterial` derived object.

This class inherits from the [ADDiffusion](/ADDiffusion.md) class.

!syntax parameters /ADKernels/ADMatDiffusion<RESIDUAL>

!syntax inputs /ADKernels/ADMatDiffusion<RESIDUAL>

!syntax children /ADKernels/ADMatDiffusion<RESIDUAL>

!bibtex bibliography
@@ -0,0 +1,33 @@
//* 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 ADMATDIFFUSION_H
#define ADMATDIFFUSION_H

#include "ADDiffusion.h"

template <ComputeStage compute_stage>
class ADMatDiffusion;

declareADValidParams(ADMatDiffusion);

template <ComputeStage compute_stage>
class ADMatDiffusion : public ADDiffusion<compute_stage>
{
public:
ADMatDiffusion(const InputParameters & parameters);

protected:
virtual ADResidual computeQpResidual() override;

const ADMaterialProperty(Real) & _diffusivity;

usingKernelMembers;
};

#endif // ADMATDIFFUSION_H
@@ -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.htmlo
#include "ADMatDiffusion.h"

registerADMooseObject("MiscApp", ADMatDiffusion);

defineADValidParams(ADMatDiffusion,
ADDiffusion,
params.addRequiredParam<MaterialPropertyName>(
"diffusivity",
"the name of the diffusivity (or thermal conductivity, viscosity, etc. "
"depending on the physics) material property"););

template <ComputeStage compute_stage>
ADMatDiffusion<compute_stage>::ADMatDiffusion(const InputParameters & parameters)
: ADDiffusion<compute_stage>(parameters),
_diffusivity(adGetADMaterialProperty<Real>("diffusivity"))
{
}

template <ComputeStage compute_stage>
ADResidual
ADMatDiffusion<compute_stage>::computeQpResidual()
{
return _diffusivity[_qp] * ADDiffusion<compute_stage>::computeQpResidual();
}
@@ -0,0 +1,91 @@
# This test solves a 1D transient heat equation
# The error is caclulated by comparing to the analytical solution
# The problem setup and analytical solution are taken from "Advanced Engineering
# Mathematics, 10th edition" by Erwin Kreyszig.
# http://www.amazon.com/Advanced-Engineering-Mathematics-Erwin-Kreyszig/dp/0470458364
# It is Example 1 in section 12.6 on page 561

[Mesh]
type = GeneratedMesh
dim = 1
nx = 160
xmax = 80
[]

[Variables]
[./T]
[../]
[]

[ICs]
[./T_IC]
type = FunctionIC
variable = T
function = '100*sin(pi*x/80)'
[../]
[]

[ADKernels]
[./HeatDiff]
type = ADMatDiffusion
variable = T
diffusivity = diffusivity
[../]
[]

[Kernels]
[./dt]
type = TimeDerivative
variable = T
[../]
[]

[BCs]
[./left]
type = DirichletBC
variable = T
boundary = left
value = 0
[../]
[./right]
type = DirichletBC
variable = T
boundary = right
value = 0
[../]
[]

[Materials]
[./k]
type = GenericConstantMaterial
prop_names = 'diffusivity'
prop_values = '0.95'
block = 0
[../]
[]

[Preconditioning]
[./full]
type = SMP
full = true
[../]
[]

[Executioner]
type = Transient
scheme = bdf2
dt = 2
end_time = 100
[]

[Postprocessors]
[./error]
type = NodalL2Error
function = '100*sin(pi*x/80)*exp(-0.95*pi^2/80^2*t)'
variable = T
[../]
[]

[Outputs]
exodus = true
[]
@@ -0,0 +1,92 @@
# This test solves a 2D steady state heat equation
# The error is found by comparing to the analytical solution

# Note that the thermal conductivity, specific heat, and density in this problem
# Are set to 1, and need to be changed to the constants of the material being
# Analyzed

[Mesh]
type = GeneratedMesh
dim = 2
nx = 30
ny = 30
xmax = 2
ymax = 2
[]

[Variables]
[./T]
[../]
[]

[ADKernels]
[./HeatDiff]
type = ADMatDiffusion
variable = T
diffusivity = diffusivity
[../]
[]

[BCs]
[./left]
type = DirichletBC
variable = T
boundary = left
value = 0
[../]
[./right]
type = DirichletBC
variable = T
boundary = right
value = 0
[../]
[./bottom]
type = DirichletBC
variable = T
boundary = bottom
value = 0
[../]
[./top]
type = FunctionDirichletBC
variable = T
boundary = top
function = '10*sin(pi*x*0.5)'
[../]
[]

[Materials]
[./k]
type = GenericConstantMaterial
prop_names = diffusivity
prop_values = 1
[../]
[]


[Postprocessors]
[./nodal_error]
type = NodalL2Error
function = '10/(sinh(pi))*sin(pi*x*0.5)*sinh(pi*y*0.5)'
variable = T
[../]
[./elemental_error]
type = ElementL2Error
function = '10/(sinh(pi))*sin(pi*x*0.5)*sinh(pi*y*0.5)'
variable = T
[../]
[]

[Preconditioning]
[./full]
type = SMP
full = true
[../]
[]

[Executioner]
type = Steady
[]

[Outputs]
exodus = true
[]
@@ -26,7 +26,7 @@
exodiff = 'matdiffusion_out.e'
requirement = 'MOOSE shall provide a diffusion kernel that obtains the diffusion coefficient from a material property'
issues = '#12074'
design = 'MatDiffusion.md'
design = '/MatDiffusion.md'
[../]

[./testbodyforce]

0 comments on commit 35aaa1b

Please sign in to comment.