Permalink
Browse files

Merge pull request #12649 from tophmatthews/ad_density_12633

Added ADDensity
  • Loading branch information...
lindsayad committed Jan 11, 2019
2 parents 80c5a7c + 0c266fc commit e431f47cff2cfae78af6b69d6dce666c55e87e2a
Showing with 796 additions and 293 deletions.
  1. +3 −1 framework/include/kernels/ADKernel.h
  2. +4 −1 framework/include/materials/ADMaterial.h
  3. +0 −4 framework/include/variables/MooseVariableBase.h
  4. +8 −6 framework/include/variables/MooseVariableFE.h
  5. +0 −3 framework/src/loops/ComputeJacobianThread.C
  6. +0 −3 framework/src/loops/ComputeResidualThread.C
  7. +0 −1 framework/src/variables/MooseVariableBase.C
  8. +18 −7 framework/src/variables/MooseVariableFE.C
  9. +87 −0 modules/combined/test/tests/elastic_patch/ad_elastic_patch_plane_strain.i
  10. +86 −0 modules/combined/test/tests/elastic_patch/ad_elastic_patch_rspherical.i
  11. +98 −0 modules/combined/test/tests/elastic_patch/ad_elastic_patch_rz.i
  12. +100 −0 modules/combined/test/tests/elastic_patch/ad_elastic_patch_rz_nonlinear.i
  13. +7 −40 modules/combined/test/tests/elastic_patch/elastic_patch_plane_strain.i
  14. +1 −0 modules/combined/test/tests/elastic_patch/elastic_patch_plane_strain_sm.i
  15. +4 −49 modules/combined/test/tests/elastic_patch/elastic_patch_rspherical.i
  16. +3 −9 modules/combined/test/tests/elastic_patch/elastic_patch_rspherical_sm.i
  17. +8 −46 modules/combined/test/tests/elastic_patch/elastic_patch_rz.i
  18. +10 −51 modules/combined/test/tests/elastic_patch/elastic_patch_rz_nonlinear.i
  19. +1 −0 modules/combined/test/tests/elastic_patch/elastic_patch_rz_nonlinear_sm.i
  20. +1 −0 modules/combined/test/tests/elastic_patch/elastic_patch_rz_sm.i
  21. +1 −0 modules/combined/test/tests/elastic_patch/gold/ad_elastic_patch_plane_strain_out.e
  22. +1 −0 modules/combined/test/tests/elastic_patch/gold/ad_elastic_patch_rspherical_out.e
  23. +1 −0 modules/combined/test/tests/elastic_patch/gold/ad_elastic_patch_rz_nonlinear_out.e
  24. +1 −0 modules/combined/test/tests/elastic_patch/gold/ad_elastic_patch_rz_out.e
  25. BIN modules/combined/test/tests/elastic_patch/gold/elastic_patch_plane_strain_out.e
  26. BIN modules/combined/test/tests/elastic_patch/gold/elastic_patch_rspherical_out.e
  27. BIN modules/combined/test/tests/elastic_patch/gold/elastic_patch_rz_nonlinear_out.e
  28. BIN modules/combined/test/tests/elastic_patch/gold/elastic_patch_rz_out.e
  29. +90 −41 modules/combined/test/tests/elastic_patch/tests
  30. +0 −6 modules/combined/test/tests/evolving_mass_density/expand_compress_test_tensors.i
  31. +0 −6 modules/combined/test/tests/evolving_mass_density/rz_tensors.i
  32. +1 −7 modules/combined/test/tests/evolving_mass_density/shear_test_tensors.i
  33. +125 −6 modules/combined/test/tests/evolving_mass_density/tests
  34. +0 −6 modules/combined/test/tests/evolving_mass_density/uniform_expand_compress_test_tensors.i
  35. +12 −0 modules/misc/doc/content/source/materials/ADDensity.md
  36. +41 −0 modules/misc/include/materials/ADDensity.h
  37. +84 −0 modules/misc/src/materials/ADDensity.C
@@ -22,6 +22,7 @@
using ADKernel<compute_stage>::_grad_u; \
using ADKernel<compute_stage>::_JxW; \
using ADKernel<compute_stage>::_coord; \
using ADKernel<compute_stage>::_q_point; \
using ADKernel<compute_stage>::_local_re; \
using ADKernel<compute_stage>::_qrule; \
using ADKernel<compute_stage>::_save_in; \
@@ -31,7 +32,8 @@
using ADKernel<compute_stage>::coupledComponents; \
using ADKernel<compute_stage>::getBlockCoordSystem; \
using ADKernel<compute_stage>::paramError; \
using ADKernel<compute_stage>::isParamValid
using ADKernel<compute_stage>::isParamValid; \
using ADKernel<compute_stage>::isCoupled

// forward declarations
template <ComputeStage compute_stage>
@@ -20,12 +20,15 @@
using ADMaterial<compute_stage>::_qrule; \
using ADMaterial<compute_stage>::_JxW; \
using ADMaterial<compute_stage>::_coord; \
using ADMaterial<compute_stage>::_q_point; \
using ADMaterial<compute_stage>::_assembly; \
using ADMaterial<compute_stage>::_mesh; \
using ADMaterial<compute_stage>::coupled; \
using ADMaterial<compute_stage>::coupledComponents; \
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
template <ComputeStage>
@@ -108,8 +108,6 @@ class MooseVariableBase
*/
virtual bool isVector() const = 0;

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

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

bool _computing_jacobian;

/// Thread ID
THREAD_ID _tid;
};
@@ -361,21 +361,21 @@ class MooseVariableFE : public MooseVariableFEBase
template <ComputeStage compute_stage>
const typename VariableValueType<compute_stage>::type & adSln()
{
_need_ad_u = true;
_need_ad = _need_ad_u = true;
return _ad_u;
}

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

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

template <ComputeStage compute_stage>
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;
}

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

bool _need_ad;
bool _need_ad_u;
bool _need_ad_grad_u;
bool _need_ad_second_u;
bool _need_neighbor_ad;
bool _need_neighbor_ad_u;
bool _need_neighbor_ad_grad_u;
bool _need_neighbor_ad_second_u;
@@ -172,9 +172,6 @@ ComputeJacobianThread::subdomainChanged()
_ibc_warehouse = &(_integrated_bcs.getMatrixTagsObjectWarehouse(_tags, _tid));
_ik_warehouse = &(_interface_kernels.getMatrixTagsObjectWarehouse(_tags, _tid));
}

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

void
@@ -99,9 +99,6 @@ ComputeResidualThread::subdomainChanged()
_ibc_warehouse = &(_integrated_bcs.getVectorTagsObjectWarehouse(_tags, _tid));
_ik_warehouse = &(_interface_kernels.getVectorTagsObjectWarehouse(_tags, _tid));
}

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

void
@@ -29,7 +29,6 @@ MooseVariableBase::MooseVariableBase(unsigned int var_num,
_dof_map(sys.dofMap()),
_mesh(_subproblem.mesh()),
_scaling_factor(1.0),
_computing_jacobian(false),
_tid(tid)
{
}
@@ -46,9 +46,11 @@ MooseVariableFE<OutputType>::MooseVariableFE(unsigned int var_num,
_need_curl(false),
_need_curl_old(false),
_need_curl_older(false),
_need_ad(false),
_need_ad_u(false),
_need_ad_grad_u(false),
_need_ad_second_u(false),
_need_neighbor_ad(false),
_need_neighbor_ad_u(false),
_need_neighbor_ad_grad_u(false),
_need_neighbor_ad_second_u(false),
@@ -1356,7 +1358,7 @@ MooseVariableFE<OutputType>::computeValuesHelper(QBase *& qrule,
}

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

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

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

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)
_ad_grad_u[qp] = 0;
@@ -1412,7 +1416,8 @@ MooseVariableFE<Real>::computeAD(const unsigned int & num_dofs, const unsigned i
{
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)
_ad_grad_u[qp] += _ad_dofs[i] * _grad_phi[i][qp];
@@ -1435,7 +1440,8 @@ void
MooseVariableFE<Real>::computeADNeighbor(const unsigned int & num_dofs, const unsigned int & nqp)
{
_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)
_neighbor_ad_grad_u.resize(nqp);
@@ -1453,7 +1459,8 @@ MooseVariableFE<Real>::computeADNeighbor(const unsigned int & num_dofs, const un

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)
_neighbor_ad_grad_u[qp] = 0;
@@ -1475,7 +1482,8 @@ MooseVariableFE<Real>::computeADNeighbor(const unsigned int & num_dofs, const un
{
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)
_neighbor_ad_grad_u[qp] += _neighbor_ad_dofs[i] * _grad_phi_neighbor[i][qp];
@@ -1771,6 +1779,9 @@ MooseVariableFE<OutputType>::computeNeighborValuesHelper(QBase *& qrule,
}
}
}

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

template <typename OutputType>
@@ -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
[]
Oops, something went wrong.

0 comments on commit e431f47

Please sign in to comment.