Skip to content
Permalink
Browse files

Merge pull request #13105 from veeshy/12996_ad_aux_dot_fix

12996 ad aux dot fix
  • Loading branch information...
lindsayad committed Mar 29, 2019
2 parents 4e969ef + de73171 commit 79d512bf158985223ca09eeeb4816fcb717a7169
@@ -741,16 +741,16 @@ class MooseVariableFE : public MooseVariableFEBase
virtual void computeNodalValues() override;
virtual void computeNodalNeighborValues() override;

void computeAD(const unsigned int & num_dofs,
const unsigned int & nqp,
const bool & is_transient,
void computeAD(const unsigned int num_dofs,
const unsigned int nqp,
const bool is_transient,
const FieldVariablePhiValue & phi,
const FieldVariablePhiGradient & grad_phi,
const FieldVariablePhiSecond *& second_phi,
const typename VariableTestGradientType<OutputType, JACOBIAN>::type & ad_grad_phi);
void computeADNeighbor(const unsigned int & num_dofs,
const unsigned int & nqp,
const bool & is_transient,
void computeADNeighbor(const unsigned int num_dofs,
const unsigned int nqp,
const bool is_transient,
const FieldVariablePhiValue & phi,
const FieldVariablePhiGradient & grad_phi,
const FieldVariablePhiSecond *& second_phi);
@@ -1322,9 +1322,9 @@ MooseVariableFE<OutputType>::computeValuesHelper(
template <typename OutputType>
void
MooseVariableFE<OutputType>::computeAD(
const unsigned int & num_dofs,
const unsigned int & nqp,
const bool & is_transient,
const unsigned int num_dofs,
const unsigned int nqp,
const bool is_transient,
const FieldVariablePhiValue & phi,
const FieldVariablePhiGradient & grad_phi,
const FieldVariablePhiSecond *& second_phi,
@@ -1409,17 +1409,21 @@ MooseVariableFE<OutputType>::computeAD(
_ad_second_u[qp] += _ad_dof_values[i] * (*second_phi)[i][qp];
}

if (is_transient)
if (is_transient && _time_integrator)
_ad_u_dot[qp] += phi[i][qp] * _ad_dofs_dot[i];
}
}

if (is_transient && !_time_integrator)
for (MooseIndex(nqp) qp = 0; qp < nqp; ++qp)
_ad_u_dot[qp] = _u_dot[qp];
}

template <typename OutputType>
void
MooseVariableFE<OutputType>::computeADNeighbor(const unsigned int & num_dofs,
const unsigned int & nqp,
const bool & is_transient,
MooseVariableFE<OutputType>::computeADNeighbor(const unsigned int num_dofs,
const unsigned int nqp,
const bool is_transient,
const FieldVariablePhiValue & phi,
const FieldVariablePhiGradient & grad_phi,
const FieldVariablePhiSecond *& second_phi)
@@ -1456,10 +1460,7 @@ MooseVariableFE<OutputType>::computeADNeighbor(const unsigned int & num_dofs,
_neighbor_ad_second_u[qp] = _ad_zero;

if (is_transient)
{
_neighbor_ad_dofs_dot[qp] = _ad_zero;
_neighbor_ad_u_dot[qp] = _ad_zero;
}
}

for (unsigned int i = 0; i < num_dofs; i++)
@@ -1492,10 +1493,14 @@ MooseVariableFE<OutputType>::computeADNeighbor(const unsigned int & num_dofs,
if (_need_neighbor_ad_second_u)
_neighbor_ad_second_u[qp] += _neighbor_ad_dof_values[i] * (*second_phi)[i][qp];

if (is_transient)
if (is_transient && _time_integrator)
_neighbor_ad_u_dot[qp] += phi[i][qp] * _neighbor_ad_dofs_dot[i];
}
}

if (is_transient && !_time_integrator)
for (MooseIndex(nqp) qp = 0; qp < nqp; ++qp)
_neighbor_ad_u_dot[qp] = _u_dot_neighbor[qp];
}

template <typename OutputType>
@@ -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 ADCOUPLEDTIMETEST_H
#define ADCOUPLEDTIMETEST_H

#include "ADTimeKernel.h"

template <ComputeStage>
class ADCoupledTimeTest;

declareADValidParams(ADCoupledTimeTest);

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

protected:
virtual ADResidual precomputeQpResidual() override;

const ADVariableValue & _v_dot;

usingKernelMembers;
};

#endif /* ADCOUPLEDTIMETEST_H */
@@ -0,0 +1,28 @@
//* 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 "ADCoupledTimeTest.h"

registerADMooseObject("MooseTestApp", ADCoupledTimeTest);

defineADValidParams(ADCoupledTimeTest,
ADTimeKernel,
params.addCoupledVar("v", 2.0, "The coupled variable."););

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

template <ComputeStage compute_stage>
ADResidual
ADCoupledTimeTest<compute_stage>::precomputeQpResidual()
{
return _v_dot[_qp];
}
@@ -0,0 +1,89 @@
###########################################################
# This is a simple test of the ADCoupledTimeTest kernel.
# The expected solution for the variable v is
# v(x) = 1/2 * (x^2 + x)
###########################################################

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

[Variables]
[./v]
[../]
[]

[AuxVariables]
[./u]
[../]
[]

[Functions]
[./u]
type = ParsedFunction
value = 't'
[../]
[]

[AuxKernels]
[./u]
type = FunctionAux
variable = u
function = u
[../]
[]

[Kernels]
[./time_v]
type = ADCoupledTimeTest
variable = v
v = u
[../]
[./diff_v]
type = ADDiffusion
variable = v
[../]
[]

[BCs]
[./left]
type = DirichletBC
variable = v
boundary = 'left'
value = 0
[../]
[./right]
type = DirichletBC
variable = v
boundary = 'right'
value = 1
[../]
[]

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

[Postprocessors]
[./l2]
type = ElementL2Error
variable = v
function = '1/2 * (x^2 + x)'
[../]
[]

[Executioner]
type = Transient
num_steps = 1
solve_type = 'NEWTON'
[]

[Outputs]
exodus = true
[]
@@ -28,4 +28,13 @@
design = "jacobian_definition.md"
issues = "#12852"
[]
[test_coupled_dot_aux]
type = 'Exodiff'
input = 'ad_aux_coupled_time_value.i'
exodiff = 'ad_aux_coupled_time_value_out.e'
requirement = "We shall be able to get dot aux variable values through adCoupledValue with the knowledge that the time derivatives will always be zero"
design = "jacobian_definition.md"
issues = "#12996"
max_parallel = 4
[]
[]

0 comments on commit 79d512b

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