Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge pull request #12649 from tophmatthews/ad_density_12633
Added ADDensity
  • Loading branch information
lindsayad committed Jan 11, 2019
2 parents 80c5a7c + 0c266fc commit e431f47
Show file tree
Hide file tree
Showing 37 changed files with 796 additions and 293 deletions.
4 changes: 3 additions & 1 deletion framework/include/kernels/ADKernel.h
Expand Up @@ -22,6 +22,7 @@
using ADKernel<compute_stage>::_grad_u; \ using ADKernel<compute_stage>::_grad_u; \
using ADKernel<compute_stage>::_JxW; \ using ADKernel<compute_stage>::_JxW; \
using ADKernel<compute_stage>::_coord; \ using ADKernel<compute_stage>::_coord; \
using ADKernel<compute_stage>::_q_point; \
using ADKernel<compute_stage>::_local_re; \ using ADKernel<compute_stage>::_local_re; \
using ADKernel<compute_stage>::_qrule; \ using ADKernel<compute_stage>::_qrule; \
using ADKernel<compute_stage>::_save_in; \ using ADKernel<compute_stage>::_save_in; \
Expand All @@ -31,7 +32,8 @@
using ADKernel<compute_stage>::coupledComponents; \ using ADKernel<compute_stage>::coupledComponents; \
using ADKernel<compute_stage>::getBlockCoordSystem; \ using ADKernel<compute_stage>::getBlockCoordSystem; \
using ADKernel<compute_stage>::paramError; \ using ADKernel<compute_stage>::paramError; \
using ADKernel<compute_stage>::isParamValid using ADKernel<compute_stage>::isParamValid; \
using ADKernel<compute_stage>::isCoupled


// forward declarations // forward declarations
template <ComputeStage compute_stage> template <ComputeStage compute_stage>
Expand Down
5 changes: 4 additions & 1 deletion framework/include/materials/ADMaterial.h
Expand Up @@ -20,12 +20,15 @@
using ADMaterial<compute_stage>::_qrule; \ using ADMaterial<compute_stage>::_qrule; \
using ADMaterial<compute_stage>::_JxW; \ using ADMaterial<compute_stage>::_JxW; \
using ADMaterial<compute_stage>::_coord; \ using ADMaterial<compute_stage>::_coord; \
using ADMaterial<compute_stage>::_q_point; \
using ADMaterial<compute_stage>::_assembly; \ using ADMaterial<compute_stage>::_assembly; \
using ADMaterial<compute_stage>::_mesh; \ using ADMaterial<compute_stage>::_mesh; \
using ADMaterial<compute_stage>::coupled; \ using ADMaterial<compute_stage>::coupled; \
using ADMaterial<compute_stage>::coupledComponents; \ using ADMaterial<compute_stage>::coupledComponents; \
using ADMaterial<compute_stage>::isParamValid; \ using ADMaterial<compute_stage>::isParamValid; \
using ADMaterial<compute_stage>::paramError using ADMaterial<compute_stage>::paramError; \
using ADMaterial<compute_stage>::isCoupled; \
using ADMaterial<compute_stage>::getBlockCoordSystem


// forward declarations // forward declarations
template <ComputeStage> template <ComputeStage>
Expand Down
4 changes: 0 additions & 4 deletions framework/include/variables/MooseVariableBase.h
Expand Up @@ -108,8 +108,6 @@ class MooseVariableBase
*/ */
virtual bool isVector() const = 0; virtual bool isVector() const = 0;


void computingJacobian(bool computing_jacobian) { _computing_jacobian = computing_jacobian; }

protected: protected:
/// variable number (from libMesh) /// variable number (from libMesh)
unsigned int _var_num; unsigned int _var_num;
Expand Down Expand Up @@ -137,8 +135,6 @@ class MooseVariableBase
/// scaling factor for this variable /// scaling factor for this variable
Real _scaling_factor; Real _scaling_factor;


bool _computing_jacobian;

/// Thread ID /// Thread ID
THREAD_ID _tid; THREAD_ID _tid;
}; };
Expand Down
14 changes: 8 additions & 6 deletions framework/include/variables/MooseVariableFE.h
Expand Up @@ -361,21 +361,21 @@ class MooseVariableFE : public MooseVariableFEBase
template <ComputeStage compute_stage> template <ComputeStage compute_stage>
const typename VariableValueType<compute_stage>::type & adSln() const typename VariableValueType<compute_stage>::type & adSln()
{ {
_need_ad_u = true; _need_ad = _need_ad_u = true;
return _ad_u; return _ad_u;
} }


template <ComputeStage compute_stage> template <ComputeStage compute_stage>
const typename VariableGradientType<compute_stage>::type & adGradSln() const typename VariableGradientType<compute_stage>::type & adGradSln()
{ {
_need_ad_grad_u = true; _need_ad = _need_ad_grad_u = true;
return _ad_grad_u; return _ad_grad_u;
} }


template <ComputeStage compute_stage> template <ComputeStage compute_stage>
const typename VariableSecondType<compute_stage>::type & adSecondSln() const typename VariableSecondType<compute_stage>::type & adSecondSln()
{ {
_need_ad_second_u = true; _need_ad = _need_ad_second_u = true;
secondPhi(); secondPhi();
secondPhiFace(); secondPhiFace();
return _ad_second_u; return _ad_second_u;
Expand All @@ -384,21 +384,21 @@ class MooseVariableFE : public MooseVariableFEBase
template <ComputeStage compute_stage> template <ComputeStage compute_stage>
const typename VariableValueType<compute_stage>::type & adSlnNeighbor() const typename VariableValueType<compute_stage>::type & adSlnNeighbor()
{ {
_need_neighbor_ad_u = true; _need_neighbor_ad = _need_neighbor_ad_u = true;
return _neighbor_ad_u; return _neighbor_ad_u;
} }


template <ComputeStage compute_stage> template <ComputeStage compute_stage>
const typename VariableGradientType<compute_stage>::type & adGradSlnNeighbor() const typename VariableGradientType<compute_stage>::type & adGradSlnNeighbor()
{ {
_need_neighbor_ad_grad_u = true; _need_neighbor_ad = _need_neighbor_ad_grad_u = true;
return _neighbor_ad_grad_u; return _neighbor_ad_grad_u;
} }


template <ComputeStage compute_stage> template <ComputeStage compute_stage>
const typename VariableSecondType<compute_stage>::type & adSecondSlnNeighbor() const typename VariableSecondType<compute_stage>::type & adSecondSlnNeighbor()
{ {
_need_neighbor_ad_second_u = true; _need_neighbor_ad = _need_neighbor_ad_second_u = true;
secondPhiFaceNeighbor(); secondPhiFaceNeighbor();
return _neighbor_ad_second_u; return _neighbor_ad_second_u;
} }
Expand Down Expand Up @@ -810,9 +810,11 @@ class MooseVariableFE : public MooseVariableFEBase
bool _need_curl_old; bool _need_curl_old;
bool _need_curl_older; bool _need_curl_older;


bool _need_ad;
bool _need_ad_u; bool _need_ad_u;
bool _need_ad_grad_u; bool _need_ad_grad_u;
bool _need_ad_second_u; bool _need_ad_second_u;
bool _need_neighbor_ad;
bool _need_neighbor_ad_u; bool _need_neighbor_ad_u;
bool _need_neighbor_ad_grad_u; bool _need_neighbor_ad_grad_u;
bool _need_neighbor_ad_second_u; bool _need_neighbor_ad_second_u;
Expand Down
3 changes: 0 additions & 3 deletions framework/src/loops/ComputeJacobianThread.C
Expand Up @@ -172,9 +172,6 @@ ComputeJacobianThread::subdomainChanged()
_ibc_warehouse = &(_integrated_bcs.getMatrixTagsObjectWarehouse(_tags, _tid)); _ibc_warehouse = &(_integrated_bcs.getMatrixTagsObjectWarehouse(_tags, _tid));
_ik_warehouse = &(_interface_kernels.getMatrixTagsObjectWarehouse(_tags, _tid)); _ik_warehouse = &(_interface_kernels.getMatrixTagsObjectWarehouse(_tags, _tid));
} }

for (auto & var : needed_moose_vars)
var->computingJacobian(true);
} }


void void
Expand Down
3 changes: 0 additions & 3 deletions framework/src/loops/ComputeResidualThread.C
Expand Up @@ -99,9 +99,6 @@ ComputeResidualThread::subdomainChanged()
_ibc_warehouse = &(_integrated_bcs.getVectorTagsObjectWarehouse(_tags, _tid)); _ibc_warehouse = &(_integrated_bcs.getVectorTagsObjectWarehouse(_tags, _tid));
_ik_warehouse = &(_interface_kernels.getVectorTagsObjectWarehouse(_tags, _tid)); _ik_warehouse = &(_interface_kernels.getVectorTagsObjectWarehouse(_tags, _tid));
} }

for (auto & var : needed_moose_vars)
var->computingJacobian(false);
} }


void void
Expand Down
1 change: 0 additions & 1 deletion framework/src/variables/MooseVariableBase.C
Expand Up @@ -29,7 +29,6 @@ MooseVariableBase::MooseVariableBase(unsigned int var_num,
_dof_map(sys.dofMap()), _dof_map(sys.dofMap()),
_mesh(_subproblem.mesh()), _mesh(_subproblem.mesh()),
_scaling_factor(1.0), _scaling_factor(1.0),
_computing_jacobian(false),
_tid(tid) _tid(tid)
{ {
} }
Expand Down
25 changes: 18 additions & 7 deletions framework/src/variables/MooseVariableFE.C
Expand Up @@ -46,9 +46,11 @@ MooseVariableFE<OutputType>::MooseVariableFE(unsigned int var_num,
_need_curl(false), _need_curl(false),
_need_curl_old(false), _need_curl_old(false),
_need_curl_older(false), _need_curl_older(false),
_need_ad(false),
_need_ad_u(false), _need_ad_u(false),
_need_ad_grad_u(false), _need_ad_grad_u(false),
_need_ad_second_u(false), _need_ad_second_u(false),
_need_neighbor_ad(false),
_need_neighbor_ad_u(false), _need_neighbor_ad_u(false),
_need_neighbor_ad_grad_u(false), _need_neighbor_ad_grad_u(false),
_need_neighbor_ad_second_u(false), _need_neighbor_ad_second_u(false),
Expand Down Expand Up @@ -1356,7 +1358,7 @@ MooseVariableFE<OutputType>::computeValuesHelper(QBase *& qrule,
} }


// Automatic differentiation // Automatic differentiation
if (_need_ad_u && _computing_jacobian) if (_need_ad && _subproblem.currentlyComputingJacobian())
computeAD(num_dofs, nqp); computeAD(num_dofs, nqp);
} }


Expand All @@ -1372,7 +1374,8 @@ void
MooseVariableFE<Real>::computeAD(const unsigned int & num_dofs, const unsigned int & nqp) MooseVariableFE<Real>::computeAD(const unsigned int & num_dofs, const unsigned int & nqp)
{ {
_ad_dofs.resize(num_dofs); _ad_dofs.resize(num_dofs);
_ad_u.resize(nqp); if (_need_ad_u)
_ad_u.resize(nqp);


if (_need_ad_grad_u) if (_need_ad_grad_u)
_ad_grad_u.resize(nqp); _ad_grad_u.resize(nqp);
Expand All @@ -1390,7 +1393,8 @@ MooseVariableFE<Real>::computeAD(const unsigned int & num_dofs, const unsigned i


for (unsigned int qp = 0; qp < nqp; qp++) for (unsigned int qp = 0; qp < nqp; qp++)
{ {
_ad_u[qp] = 0; if (_need_ad_u)
_ad_u[qp] = 0;


if (_need_ad_grad_u) if (_need_ad_grad_u)
_ad_grad_u[qp] = 0; _ad_grad_u[qp] = 0;
Expand All @@ -1412,7 +1416,8 @@ MooseVariableFE<Real>::computeAD(const unsigned int & num_dofs, const unsigned i
{ {
for (unsigned int qp = 0; qp < nqp; qp++) for (unsigned int qp = 0; qp < nqp; qp++)
{ {
_ad_u[qp] += _ad_dofs[i] * _phi[i][qp]; if (_need_ad_u)
_ad_u[qp] += _ad_dofs[i] * _phi[i][qp];


if (_need_ad_grad_u) if (_need_ad_grad_u)
_ad_grad_u[qp] += _ad_dofs[i] * _grad_phi[i][qp]; _ad_grad_u[qp] += _ad_dofs[i] * _grad_phi[i][qp];
Expand All @@ -1435,7 +1440,8 @@ void
MooseVariableFE<Real>::computeADNeighbor(const unsigned int & num_dofs, const unsigned int & nqp) MooseVariableFE<Real>::computeADNeighbor(const unsigned int & num_dofs, const unsigned int & nqp)
{ {
_neighbor_ad_dofs.resize(num_dofs); _neighbor_ad_dofs.resize(num_dofs);
_neighbor_ad_u.resize(nqp); if (_need_neighbor_ad_u)
_neighbor_ad_u.resize(nqp);


if (_need_neighbor_ad_grad_u) if (_need_neighbor_ad_grad_u)
_neighbor_ad_grad_u.resize(nqp); _neighbor_ad_grad_u.resize(nqp);
Expand All @@ -1453,7 +1459,8 @@ MooseVariableFE<Real>::computeADNeighbor(const unsigned int & num_dofs, const un


for (unsigned int qp = 0; qp < nqp; qp++) for (unsigned int qp = 0; qp < nqp; qp++)
{ {
_neighbor_ad_u[qp] = 0; if (_need_neighbor_ad_u)
_neighbor_ad_u[qp] = 0;


if (_need_neighbor_ad_grad_u) if (_need_neighbor_ad_grad_u)
_neighbor_ad_grad_u[qp] = 0; _neighbor_ad_grad_u[qp] = 0;
Expand All @@ -1475,7 +1482,8 @@ MooseVariableFE<Real>::computeADNeighbor(const unsigned int & num_dofs, const un
{ {
for (unsigned int qp = 0; qp < nqp; qp++) for (unsigned int qp = 0; qp < nqp; qp++)
{ {
_neighbor_ad_u[qp] += _neighbor_ad_dofs[i] * _phi_neighbor[i][qp]; if (_need_neighbor_ad_u)
_neighbor_ad_u[qp] += _neighbor_ad_dofs[i] * _phi_neighbor[i][qp];


if (_need_neighbor_ad_grad_u) if (_need_neighbor_ad_grad_u)
_neighbor_ad_grad_u[qp] += _neighbor_ad_dofs[i] * _grad_phi_neighbor[i][qp]; _neighbor_ad_grad_u[qp] += _neighbor_ad_dofs[i] * _grad_phi_neighbor[i][qp];
Expand Down Expand Up @@ -1771,6 +1779,9 @@ MooseVariableFE<OutputType>::computeNeighborValuesHelper(QBase *& qrule,
} }
} }
} }

if (_need_neighbor_ad && _subproblem.currentlyComputingJacobian())
computeADNeighbor(num_dofs, nqp);
} }


template <typename OutputType> template <typename OutputType>
Expand Down
@@ -0,0 +1,87 @@
#
# This problem is taken from the Abaqus verification manual:
# "1.5.1 Membrane patch test"
# The stress solution is given as:
# xx = yy = 1600
# zz = 800
# xy = 400
# yz = zx = 0
#
# Since the strain is 1e-3 in both directions, the new density should be
# new_density = original_density * V_0 / V
# new_density = 0.283 / (1 + 1e-3 + 1e-3) = 0.282435

[GlobalParams]
displacements = 'disp_x disp_y'
temperature = temp
[]

[Mesh]
file = elastic_patch_rz.e
[]

[Variables]
[./temp]
initial_condition = 117.56
[../]
[]

[Modules/TensorMechanics/Master/All]
strain = SMALL
incremental = true
planar_formulation = PLANE_STRAIN
add_variables = true
generate_output = 'stress_xx stress_yy stress_zz stress_xy stress_yz stress_zx'
[]

[Kernels]
[./heat]
type = TimeDerivative
variable = temp
[../]
[]

[BCs]
[./ur]
type = FunctionDirichletBC
variable = disp_x
boundary = 10
function = '1e-3*(x+0.5*y)'
[../]
[./uz]
type = FunctionDirichletBC
variable = disp_y
boundary = 10
function = '1e-3*(y+0.5*x)'
[../]
[]

[Materials]
[./elasticity_tensor]
type = ComputeIsotropicElasticityTensor
youngs_modulus = 1e6
poissons_ratio = 0.25
[../]
[./stress]
type = ComputeStrainIncrementBasedStress
[../]
[]

[ADMaterials]
[./density]
type = ADDensity
density = 0.283
outputs = all
[../]
[]

[Executioner]
type = Transient
solve_type = 'PJFNK'

end_time = 1.0
[]

[Outputs]
exodus = true
[]

0 comments on commit e431f47

Please sign in to comment.