Permalink
Browse files

Merge pull request #12634 from tophmatthews/ad_heat_12633

Added ADHeatConduction and tests.
  • Loading branch information...
lindsayad committed Jan 3, 2019
2 parents f64358c + 2eef764 commit ceabe6789e9a1c5bec7cc0d544bc29902b50f529
@@ -29,3 +29,6 @@ ADDiffusion<compute_stage>::computeQpResidual()
{
return _grad_u[_qp] * _grad_test[_i][_qp];
}

template class ADDiffusion<RESIDUAL>;
template class ADDiffusion<JACOBIAN>;
@@ -0,0 +1,22 @@
# ADHeatConduction

## Description

`ADHeatConduction` is the implementation of the heat diffusion equation in [HeatConduction](/HeatConduction.md) within the framework of automatic differentiation.
The `ADHeatConduction` kernel implements the heat equation given by Fourier's Law where The heat flux is given as
\begin{equation}
\mathbf{q} = - k\nabla T,
\end{equation}
where $k$ denotes the thermal conductivity of the material. $k$ can either be an `ADMaterial` or traditional `Material`.

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

!syntax description /ADKernels/ADHeatConduction<RESIDUAL>

!syntax parameters /ADKernels/ADHeatConduction<RESIDUAL>

!syntax inputs /ADKernels/ADHeatConduction<RESIDUAL>

!syntax children /ADKernels/ADHeatConduction<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 ADHEATCONDUCTION_H
#define ADHEATCONDUCTION_H

#include "ADDiffusion.h"

template <ComputeStage compute_stage>
class ADHeatConduction;

declareADValidParams(ADHeatConduction);

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

protected:
virtual ADResidual computeQpResidual() override;

const ADMaterialProperty(Real) & _thermal_conductivity;

usingKernelMembers;
};

#endif // ADHEATCONDUCTION_H
@@ -0,0 +1,31 @@
//* 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 "ADHeatConduction.h"

registerADMooseObject("HeatConductionApp", ADHeatConduction);

defineADValidParams(ADHeatConduction,
ADDiffusion,
params.addRequiredParam<MaterialPropertyName>(
"thermal_conductivity",
"the name of the thermal conductivity material property"););

template <ComputeStage compute_stage>
ADHeatConduction<compute_stage>::ADHeatConduction(const InputParameters & parameters)
: ADDiffusion<compute_stage>(parameters),
_thermal_conductivity(adGetADMaterialProperty<Real>("thermal_conductivity"))
{
}

template <ComputeStage compute_stage>
ADResidual
ADHeatConduction<compute_stage>::computeQpResidual()
{
return _thermal_conductivity[_qp] * ADDiffusion<compute_stage>::computeQpResidual();
}
@@ -0,0 +1,37 @@
//* 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 ADTHERMALCONDUCTIVITYTEST_H
#define ADTHERMALCONDUCTIVITYTEST_H

#include "ADMaterial.h"

// Forward Declarations
template <ComputeStage>
class ADThermalConductivityTest;

declareADValidParams(ADThermalConductivityTest);

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

protected:
virtual void computeQpProperties();

private:
ADMaterialProperty(Real) & _diffusivity;
const ADVariableValue & _temperature;
const ADVariableValue & _c;

usingMaterialMembers;
};

#endif // ADTHERMALCONDUCTIVITYTEST_H
@@ -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 "ADThermalConductivityTest.h"

registerADMooseObject("HeatConductionTestApp", ADThermalConductivityTest);

defineADValidParams(
ADThermalConductivityTest,
ADMaterial,
params.addRequiredCoupledVar("temperature", "Coupled temperature");
params.addRequiredCoupledVar(
"c", "Coupled variable used to help verify automatic differentiation capability"););

template <ComputeStage compute_stage>
ADThermalConductivityTest<compute_stage>::ADThermalConductivityTest(
const InputParameters & parameters)
: ADMaterial<compute_stage>(parameters),
_diffusivity(adDeclareADProperty<Real>("thermal_conductivity")),
_temperature(adCoupledValue("temperature")),
_c(adCoupledValue("c"))
{
}

template <ComputeStage compute_stage>
void
ADThermalConductivityTest<compute_stage>::computeQpProperties()
{
_diffusivity[_qp] = _temperature[_qp] * _c[_qp];
}
@@ -0,0 +1,66 @@
# This test solves a 1D transient heat equation with a complicated thermal
# conductivity in order to verify jacobian calculation via AD

[Mesh]
type = GeneratedMesh
dim = 2
nx = 3
ny = 3
[]

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

[ICs]
[./T_IC]
type = RandomIC
variable = T
[../]
[./c_IC]
type = RandomIC
variable = c
[../]
[]

[ADKernels]
[./HeatDiff]
type = ADHeatConduction
variable = T
thermal_conductivity = thermal_conductivity
[../]
[]

[Kernels]
[./c]
type = Diffusion
variable = c
[../]
[]

[ADMaterials]
[./k]
type = ADThermalConductivityTest
c = c
temperature = T
[../]
[]

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

[Executioner]
type = Transient
num_steps = 1
[]

[Outputs]
exodus = true
[]
@@ -0,0 +1,14 @@
[Tests]
[./stateful_jacobian]
type = 'PetscJacobianTester'
input = 'test.i'
ratio_tol = 1e-7
difference_tol = 1e-5
run_sim = True
petsc_version = '>=3.9'
requirement = 'AD heat conduction and the Jacobian shall be beautiful'
design = "jacobian_definition.md"
issues = "#5658 #12633"
allow_test_objects = true
[../]
[]
@@ -0,0 +1,101 @@
# 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 = ADHeatConduction
variable = T
thermal_conductivity = thermal_conductivity
[../]
[]

[Kernels]
[./HeatTdot]
type = HeatConductionTimeDerivative
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 = 'thermal_conductivity'
prop_values = '0.95' #copper in cal/(cm sec C)
block = 0
[../]
[./cp]
type = GenericConstantMaterial
prop_names = 'specific_heat'
prop_values = '0.092' #copper in cal/(g C)
block = 0
[../]
[./rho]
type = GenericConstantMaterial
prop_names = 'density'
prop_values = '8.92' #copper in g/(cm^3)
block = 0
[../]
[]

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

[Executioner]
type = Transient
scheme = bdf2
nl_rel_tol = 1e-12
l_tol = 1e-6
dt = 2
end_time = 100
petsc_options_iname = '-pc_type -pc_hypre_type'
petsc_options_value = 'hypre boomeramg'
[]

[Outputs]
exodus = true
perf_graph = true
[]
Oops, something went wrong.

0 comments on commit ceabe67

Please sign in to comment.