Skip to content
Permalink
Browse files

Merge pull request #13142 from dschwen/adsplitch_13138

AD enabled split Cahn-Hilliard phase field model
  • Loading branch information...
lindsayad committed Mar 29, 2019
2 parents 79d512b + cc1a3e8 commit b280903be631439e71ddd370eec527dde50c9f68
Showing with 1,010 additions and 45 deletions.
  1. +47 −0 framework/doc/content/source/kernels/ADCoupledTimeDerivative.md
  2. +38 −0 framework/include/kernels/ADCoupledTimeDerivative.h
  3. +32 −0 framework/src/kernels/ADCoupledTimeDerivative.C
  4. +27 −0 modules/phase_field/doc/content/source/kernels/ADSplitCHParsed.md
  5. +27 −0 modules/phase_field/doc/content/source/kernels/ADSplitCHWRes.md
  6. +14 −0 modules/phase_field/doc/content/source/kernels/ADSplitCHWResAniso.md
  7. +16 −7 modules/phase_field/doc/content/source/kernels/SplitCHParsed.md
  8. +23 −0 modules/phase_field/doc/content/source/materials/ADMathFreeEnergy.md
  9. +6 −7 modules/phase_field/doc/content/source/materials/MathFreeEnergy.md
  10. +0 −2 modules/phase_field/doc/hidden.yml
  11. +43 −0 modules/phase_field/include/kernels/ADSplitCHBase.h
  12. +45 −0 modules/phase_field/include/kernels/ADSplitCHCRes.h
  13. +46 −0 modules/phase_field/include/kernels/ADSplitCHParsed.h
  14. +28 −0 modules/phase_field/include/kernels/ADSplitCHWRes.h
  15. +28 −0 modules/phase_field/include/kernels/ADSplitCHWResAniso.h
  16. +62 −0 modules/phase_field/include/kernels/ADSplitCHWResBase.h
  17. +51 −0 modules/phase_field/include/materials/ADMathFreeEnergy.h
  18. +37 −0 modules/phase_field/src/kernels/ADSplitCHBase.C
  19. +40 −0 modules/phase_field/src/kernels/ADSplitCHCRes.C
  20. +36 −0 modules/phase_field/src/kernels/ADSplitCHParsed.C
  21. +24 −0 modules/phase_field/src/kernels/ADSplitCHWRes.C
  22. +24 −0 modules/phase_field/src/kernels/ADSplitCHWResAniso.C
  23. +19 −0 modules/phase_field/src/kernels/ADSplitCHWResBase.C
  24. +38 −0 modules/phase_field/src/materials/ADMathFreeEnergy.C
  25. +102 −0 modules/phase_field/test/tests/phase_field_kernels/ADSplitCahnHilliard.i
  26. +13 −17 modules/phase_field/test/tests/phase_field_kernels/SplitCahnHilliard.i
  27. BIN modules/phase_field/test/tests/phase_field_kernels/gold/SplitCahnHilliard_out.e
  28. +66 −12 modules/phase_field/test/tests/phase_field_kernels/tests
  29. +66 −0 test/tests/kernels/coupled_time_derivative/ad_coupled_time_derivative_test.i
  30. +12 −0 test/tests/kernels/coupled_time_derivative/tests
@@ -0,0 +1,47 @@
# ADCoupledTimeDerivative

## Description

The `ADCoupledTimeDerivative` kernel is very similar to the
[`TimeDerivative`](/TimeDerivative.md) kernel with the exception that the time
derivative operator is applied to a coupled variable $v$ instead of the kernel
variable $u$ which the `ADCoupledTimeDerivative` residual is assigned to.
Consequently, the strong form on the the domain $\Omega$ is

\begin{equation}
\underbrace{\frac{\partial v}{\partial t}}_{\textrm{ADCoupledTimeDerivative}} +
\sum_{i=1}^n \beta_i = 0 \in \Omega
\label{strong}
\end{equation}
where the second term on the left hand side corresponds to the
strong forms of other kernels. The `ADCoupledTimeDerivative` weak form is then

\begin{equation}
R_i(u_h) = \bigg(\psi_i, \frac{\partial v_h}{\partial t}\bigg) \quad \forall
\psi_i,
\label{weak}
\end{equation}
where the $\psi_i$ are test functions and $u_h \in \mathcal{S}^h$ is the finite
element solution of the weak formulation.

The Jacobian contribution is computed using forward mode automatic
differentiation.

## Example Syntax

`ADCoupledTimeDerivative` is used for example in the split Cahn Hilliard
equations for phase field calculations. The syntax is simple, taking its type
(`ADCoupledTimeDerivative`), the kernel variable which the
`ADCoupledTimeDerivative` residual is assigned to, and the coupled variable `v`
that the time derivative operator acts upon. Example syntax can be found in the
kernel block below:

!listing
test/tests/kernels/coupled_time_derivative/ad_coupled_time_derivative_test.i
block=Kernels label=false

!syntax parameters /Kernels/ADCoupledTimeDerivative<RESIDUAL>

!syntax inputs /Kernels/ADCoupledTimeDerivative<RESIDUAL>

!syntax children /Kernels/ADCoupledTimeDerivative<RESIDUAL>
@@ -0,0 +1,38 @@
//* 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 ADCOUPLEDTIMEDERIVATIVE_H
#define ADCOUPLEDTIMEDERIVATIVE_H

#include "ADKernelValue.h"

// Forward Declaration
template <ComputeStage>
class ADCoupledTimeDerivative;

declareADValidParams(ADCoupledTimeDerivative);

/**
* This calculates the time derivative for a coupled variable
**/
template <ComputeStage compute_stage>
class ADCoupledTimeDerivative : public ADKernelValue<compute_stage>
{
public:
ADCoupledTimeDerivative(const InputParameters & parameters);

protected:
virtual ADReal precomputeQpResidual() override;

const ADVariableValue & _v_dot;

usingKernelValueMembers;
};

#endif // ADCOUPLEDTIMEDERIVATIVE_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.html

#include "ADCoupledTimeDerivative.h"

registerADMooseObject("MooseApp", ADCoupledTimeDerivative);

defineADValidParams(
ADCoupledTimeDerivative,
ADKernelValue,
params.addClassDescription("Time derivative Kernel that acts on a coupled variable. Weak form: "
"$(\\psi_i, \\frac{\\partial v_h}{\\partial t})$.");
params.addRequiredCoupledVar("v", "Coupled variable"););

template <ComputeStage compute_stage>
ADCoupledTimeDerivative<compute_stage>::ADCoupledTimeDerivative(const InputParameters & parameters)
: ADKernelValue<compute_stage>(parameters), _v_dot(adCoupledDot("v"))
{
}

template <ComputeStage compute_stage>
ADReal
ADCoupledTimeDerivative<compute_stage>::precomputeQpResidual()
{
return _v_dot[_qp];
}
@@ -0,0 +1,27 @@
# ADSplitCHParsed

!syntax description /Kernels/ADSplitCHParsed<RESIDUAL>

Implements the weak form

\begin{equation}
(\frac{\partial F}{\partial c}, \psi) - (\mu,\psi) + (\kappa\nabla c,\nabla\psi)
\end{equation}

where $c$ is the concentration variable the kernel is operating on, $F$ is a
free energy material property (with accompanying derivative properties), $\mu$
is the chemical potential variable, and $\kappa$ is the gradient energy
coefficient.

It is used together with [`ADSplitCHWRes`](/ADSplitCHWRes.md) and
[`ADCoupledTimeDerivative`](/ADCoupledTimeDerivative.md) to set up a system of
two first order PDEs using a concentration order parameter and a chemical
potential variable.

!syntax parameters /Kernels/ADSplitCHParsed<RESIDUAL>

!syntax inputs /Kernels/ADSplitCHParsed<RESIDUAL>

!syntax children /Kernels/ADSplitCHParsed<RESIDUAL>

!bibtex bibliography
@@ -0,0 +1,27 @@
# ADSplitCHWRes

!syntax description /Kernels/ADSplitCHWRes<RESIDUAL>

This kernel implements the weak form

\begin{equation}
(M \nabla u, \nabla\psi)
\end{equation}

for the a reverse split Cahn-Hilliard equation, where the kernel variable $u$ is
a chemical potential and $M$ (`mob_name`) is a scalar mobility. It is used
together with [`ADSplitCHParsed`](/ADSplitCHParsed.md) and
[`ADCoupledTimeDerivative`](/ADCoupledTimeDerivative.md) to set up a system of
two first order PDEs using a concentration order parameter and a chemical
potential variable.

For an implementation with an anisotropic (tensorial) mobility see
[`ADSplitCHWResAniso`](/ADSplitCHWResAniso.md).

!syntax parameters /Kernels/ADSplitCHWRes<RESIDUAL>

!syntax inputs /Kernels/ADSplitCHWRes<RESIDUAL>

!syntax children /Kernels/ADSplitCHWRes<RESIDUAL>

!bibtex bibliography
@@ -0,0 +1,14 @@
# ADSplitCHWResAniso

!syntax description /Kernels/ADSplitCHWResAniso<RESIDUAL>

This is anisotropic version of [`ADSplitCHWRes`](/ADSplitCHWRes.md) and expects
a tensor valued mobility $M$.

!syntax parameters /Kernels/ADSplitCHWResAniso<RESIDUAL>

!syntax inputs /Kernels/ADSplitCHWResAniso<RESIDUAL>

!syntax children /Kernels/ADSplitCHWResAniso<RESIDUAL>

!bibtex bibliography
@@ -1,14 +1,23 @@
<!-- MOOSE Documentation Stub: Remove this when content is added. -->

# SplitCHParsed

!alert construction title=Undocumented Class
The SplitCHParsed has not been documented. The content contained on this page
includes the basic documentation associated with a MooseObject; however, what is contained is
ultimately determined by what is necessary to make the documentation clear for users.

!syntax description /Kernels/SplitCHParsed

Implements the weak form

\begin{equation}
(\frac{\partial F}{\partial c}, \psi) - (\mu,\psi) + (\kappa\nabla c,\nabla\psi)
\end{equation}

where $c$ is the concentration variable the kernel is operating on, $F$ is a
free energy material property (with accompanying derivative properties), $\mu$
is the chemical potential variable, and $\kappa$ is the gradient energy
coefficient.

It is used together with [`SplitCHWRes`](/SplitCHWRes.md) and
[`CoupledTimeDerivative`](/CoupledTimeDerivative.md) to set up a system of two
first order PDEs using a concentration order parameter and a chemical potential
variable.

!syntax parameters /Kernels/SplitCHParsed

!syntax inputs /Kernels/SplitCHParsed
@@ -0,0 +1,23 @@
# ADMathFreeEnergy

This material implements an analytical double well free energy

\begin{equation}
F = \frac14(1 + c)^2(1 - c)^2
\end{equation}

and its first order derivatives. Both provided properties furthermore come with
forward mode automatic derivatives with respect to all degrees of freedom on the
current element.

This free energy can be used with the AD version of the split Cahn-Hilliard
equation ([`ADSplitCHWRes`](/ADSplitCHWRes.md) and
[`ADSplitCHParsed`](/ADSplitCHParsed.md)).

!syntax parameters /Materials/ADMathFreeEnergy<RESIDUAL>

!syntax inputs /Materials/ADMathFreeEnergy<RESIDUAL>

!syntax children /Materials/ADMathFreeEnergy<RESIDUAL>

!bibtex bibliography
@@ -1,13 +1,12 @@
<!-- MOOSE Documentation Stub: Remove this when content is added. -->

# MathFreeEnergy

!alert construction title=Undocumented Class
The MathFreeEnergy has not been documented. The content contained on this page
includes the basic documentation associated with a MooseObject; however, what is contained is
ultimately determined by what is necessary to make the documentation clear for users.
This material implements an analytical double well free energy

\begin{equation}
F = \frac14(1 + c)^2(1 - c)^2
\end{equation}

!syntax description /Materials/MathFreeEnergy
and its up to third order derivatives.

!syntax parameters /Materials/MathFreeEnergy

@@ -79,7 +79,6 @@
- /Kernels/SingleGrainRigidBodyMotion
- /Kernels/SoretDiffusion
- /Kernels/SplitCHMath
- /Kernels/SplitCHParsed
- /Kernels/SwitchingFunctionConstraintEta
- /Kernels/SwitchingFunctionConstraintLagrange
- /Kernels/SwitchingFunctionPenalty
@@ -114,7 +113,6 @@
- /Materials/InterfaceOrientationMaterial
- /Materials/KKSXeVacSolidMaterial
- /Materials/MathEBFreeEnergy
- /Materials/MathFreeEnergy
- /Materials/PFCRFFMaterial
- /Materials/PFCTradMaterial
- /Materials/PFFracBulkRateMaterial
@@ -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

#ifndef ADSPLITCHBASE_H
#define ADSPLITCHBASE_H

#include "ADKernel.h"

#define usingSplitCHBaseMembers \
usingKernelMembers; \
using ADSplitCHBase<compute_stage>::computeQpResidual; \
using ADSplitCHBase<compute_stage>::computeDFDC

// Forward Declarations
template <ComputeStage>
class ADSplitCHBase;

declareADValidParams(ADSplitCHBase);

/**
* The pair, ADSplitCHCRes and ADSplitCHWRes, splits the Cahn-Hilliard equation
* by replacing chemical potential with 'w'.
*/
template <ComputeStage compute_stage>
class ADSplitCHBase : public ADKernel<compute_stage>
{
public:
ADSplitCHBase(const InputParameters & parameters);

protected:
virtual ADReal computeQpResidual();
virtual ADReal computeDFDC();

usingKernelMembers;
};

#endif // ADSPLITCHBASE_H
@@ -0,0 +1,45 @@
//* 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 ADSPLITCHCRES_H
#define ADSPLITCHCRES_H

#include "ADSplitCHBase.h"

#define usingSplitCHCResMembers \
usingSplitCHBaseMembers; \
using ADSplitCHCRes<compute_stage>::_kappa; \
using ADSplitCHCRes<compute_stage>::_w

// Forward Declarations
template <ComputeStage>
class ADSplitCHCRes;

declareADValidParams(ADSplitCHCRes);

/**
* The pair, ADSplitCHCRes and ADSplitCHWRes, splits the Cahn-Hilliard equation
* by replacing chemical potential with 'w'.
*/
template <ComputeStage compute_stage>
class ADSplitCHCRes : public ADSplitCHBase<compute_stage>
{
public:
ADSplitCHCRes(const InputParameters & parameters);

protected:
virtual ADReal computeQpResidual();

const ADMaterialProperty(Real) & _kappa;
const ADVariableValue & _w;

usingSplitCHBaseMembers;
};

#endif // ADSPLITCHCRES_H
Oops, something went wrong.

0 comments on commit b280903

Please sign in to comment.
You can’t perform that action at this time.