diff --git a/.gitignore b/.gitignore index c8f7e0178069..8de982f7ce75 100644 --- a/.gitignore +++ b/.gitignore @@ -200,6 +200,7 @@ python/MooseDocs/test/output !python/MooseDocs/test/gold/**/*.json !python/MooseDocs/test/gold/**/*.html !python/MooseDocs/test/gold/**/*.tex +.ruby-version # Chigger !python/chigger/tests/**/gold/*.png diff --git a/framework/include/base/MooseObject.h b/framework/include/base/MooseObject.h index 8aa961225230..94516e78bd6b 100644 --- a/framework/include/base/MooseObject.h +++ b/framework/include/base/MooseObject.h @@ -17,6 +17,10 @@ #include "libmesh/parallel_object.h" +#define usingMooseObjectMembers \ + using MooseObject::isParamValid; \ + using MooseObject::paramError + class MooseApp; class MooseObject; diff --git a/framework/include/bcs/ADFunctionPresetBC.h b/framework/include/bcs/ADFunctionPresetBC.h new file mode 100644 index 000000000000..7cc41c8f06fc --- /dev/null +++ b/framework/include/bcs/ADFunctionPresetBC.h @@ -0,0 +1,44 @@ +//* 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 ADFUNCTIONPRESETBC_H +#define ADFUNCTIONPRESETBC_H + +#include "ADPresetNodalBC.h" + +// Forward Declarations +template +class ADFunctionPresetBC; +class Function; + +declareADValidParams(ADFunctionPresetBC); + +/** + * Defines a boundary condition that forces the value to be a user specified + * function at the boundary. + */ +template +class ADFunctionPresetBC : public ADPresetNodalBC +{ +public: + ADFunctionPresetBC(const InputParameters & parameters); + +protected: + /** + * Evaluate the function at the current quadrature point and timestep. + */ + virtual ADReal computeQpValue() override; + + /// Function being used for evaluation of this BC + Function & _func; + + usingPresetNodalBCMembers; +}; + +#endif // ADFUNCTIONPRESETBC_H diff --git a/framework/include/bcs/ADIntegratedBC.h b/framework/include/bcs/ADIntegratedBC.h index 1339f245b8bd..065ec782101d 100644 --- a/framework/include/bcs/ADIntegratedBC.h +++ b/framework/include/bcs/ADIntegratedBC.h @@ -69,6 +69,8 @@ declareADValidParams(ADIntegratedBC); declareADValidParams(ADVectorIntegratedBC); #define usingTemplIntegratedBCMembers(type) \ + usingMooseObjectMembers; \ + usingCoupleableMembers; \ using ADIntegratedBCTempl::_test; \ using ADIntegratedBCTempl::_qp; \ using ADIntegratedBCTempl::_i; \ diff --git a/framework/include/bcs/ADNodalBC.h b/framework/include/bcs/ADNodalBC.h index 929934002428..e79aee3e5f99 100644 --- a/framework/include/bcs/ADNodalBC.h +++ b/framework/include/bcs/ADNodalBC.h @@ -53,14 +53,16 @@ declareADValidParams(ADNodalBC); declareADValidParams(ADVectorNodalBC); #define usingTemplNodalBCMembers(type) \ + usingMooseObjectMembers; \ using ADNodalBCTempl::_u; \ using ADNodalBCTempl::_var; \ using ADNodalBCTempl::_current_node; \ using ADNodalBCTempl::_t; \ + using ADNodalBCTempl::computeResidual; \ + using ADNodalBCTempl::computeJacobian; \ + using ADNodalBCTempl::computeOffDiagJacobian; \ using ADNodalBCTempl::getFunction; \ - using ADNodalBCTempl::variable; \ - using ADNodalBCTempl::paramError; \ - using ADNodalBCTempl::isParamValid + using ADNodalBCTempl::variable #define usingNodalBCMembers usingTemplNodalBCMembers(Real) #define usingVectorNodalBCMembers usingTemplNodalBCMembers(RealVectorValue) diff --git a/framework/include/bcs/ADPresetBC.h b/framework/include/bcs/ADPresetBC.h new file mode 100644 index 000000000000..78415ba7848e --- /dev/null +++ b/framework/include/bcs/ADPresetBC.h @@ -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 ADPRESETBC_H +#define ADPRESETBC_H + +#include "ADPresetNodalBC.h" + +template +class ADPresetBC; + +declareADValidParams(ADPresetBC); + +/** + * TODO: + */ +template +class ADPresetBC : public ADPresetNodalBC +{ +public: + ADPresetBC(const InputParameters & parameters); + +protected: + virtual ADReal computeQpValue() override; + + const Real & _value; + + usingPresetNodalBCMembers; +}; + +#endif // ADPRESETBC_H diff --git a/framework/include/bcs/ADPresetNodalBC.h b/framework/include/bcs/ADPresetNodalBC.h new file mode 100644 index 000000000000..a76933f0199d --- /dev/null +++ b/framework/include/bcs/ADPresetNodalBC.h @@ -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 ADPRESETNODALBC_H +#define ADPRESETNODALBC_H + +#include "ADNodalBC.h" + +#define usingPresetNodalBCMembers \ + usingNodalBCMembers; \ + using ADPresetNodalBC::computeQpValue + +template +class ADPresetNodalBC; + +declareADValidParams(ADPresetNodalBC); + +/** + * Base class for automatic differentiation nodal BCs that (pre)set the solution + * vector entries. + */ +template +class ADPresetNodalBC : public ADNodalBC +{ +public: + ADPresetNodalBC(const InputParameters & parameters); + + void computeValue(NumericVector & current_solution); + +protected: + virtual ADResidual computeQpResidual() override; + virtual ADReal computeQpValue() = 0; + + usingNodalBCMembers; +}; + +#endif // ADPRESETNODALBC_H diff --git a/framework/include/kernels/ADKernel.h b/framework/include/kernels/ADKernel.h index 00f41329abd5..23257a750cf2 100644 --- a/framework/include/kernels/ADKernel.h +++ b/framework/include/kernels/ADKernel.h @@ -16,6 +16,7 @@ #include "metaphysicl/dualnumber.h" #define usingTemplKernelMembers(type) \ + usingMooseObjectMembers; \ usingCoupleableMembers; \ using ADKernelTempl::_test; \ using ADKernelTempl::_qp; \ @@ -48,8 +49,6 @@ using ADKernelTempl::accumulateTaggedLocalResidual; \ using ADKernelTempl::accumulateTaggedLocalMatrix; \ using ADKernelTempl::variable; \ - using ADKernelTempl::paramError; \ - using ADKernelTempl::isParamValid; \ using ADKernelTempl::getFunction #define usingKernelMembers usingTemplKernelMembers(Real) diff --git a/framework/include/materials/ADMaterial.h b/framework/include/materials/ADMaterial.h index eb6fe30e501f..de81ba56abc9 100644 --- a/framework/include/materials/ADMaterial.h +++ b/framework/include/materials/ADMaterial.h @@ -17,6 +17,7 @@ #include "metaphysicl/dualnumber.h" #define usingMaterialMembers \ + usingMooseObjectMembers; \ usingCoupleableMembers; \ usingTransientInterfaceMembers; \ using ConsoleStreamInterface::_console; \ @@ -29,8 +30,6 @@ using ADMaterial::_fe_problem; \ using ADMaterial::_assembly; \ using ADMaterial::_mesh; \ - using ADMaterial::isParamValid; \ - using ADMaterial::paramError; \ using ADMaterial::copyDualNumbersToValues; \ using ADMaterial::getBlockCoordSystem diff --git a/framework/src/bcs/ADFunctionPresetBC.C b/framework/src/bcs/ADFunctionPresetBC.C new file mode 100644 index 000000000000..bbcbc2a7e9d2 --- /dev/null +++ b/framework/src/bcs/ADFunctionPresetBC.C @@ -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 + +#include "ADFunctionPresetBC.h" +#include "Function.h" + +registerADMooseObject("MooseApp", ADFunctionPresetBC); + +defineADValidParams( + ADFunctionPresetBC, + ADPresetNodalBC, + params.addRequiredParam("function", "The forcing function."); + params.addClassDescription( + "The same as FunctionDirichletBC except the value is applied before the solve begins");); + +template +ADFunctionPresetBC::ADFunctionPresetBC(const InputParameters & parameters) + : ADPresetNodalBC(parameters), _func(getFunction("function")) +{ +} + +template +ADReal +ADFunctionPresetBC::computeQpValue() +{ + return _func.value(_t, *_current_node); +} diff --git a/framework/src/bcs/ADPresetBC.C b/framework/src/bcs/ADPresetBC.C new file mode 100644 index 000000000000..a56b09043321 --- /dev/null +++ b/framework/src/bcs/ADPresetBC.C @@ -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.html + +#include "ADPresetBC.h" + +registerADMooseObject("MooseApp", ADPresetBC); + +defineADValidParams( + ADPresetBC, ADPresetNodalBC, params.addRequiredParam("value", "Value of the BC"); + params.declareControllable("value"); + params.addClassDescription( + "Similar to DirichletBC except the value is applied before the solve begins");); + +template +ADPresetBC::ADPresetBC(const InputParameters & parameters) + : ADPresetNodalBC(parameters), _value(adGetParam("value")) +{ +} + +template +ADReal +ADPresetBC::computeQpValue() +{ + return _value; +} diff --git a/framework/src/bcs/ADPresetNodalBC.C b/framework/src/bcs/ADPresetNodalBC.C new file mode 100644 index 000000000000..2f005075940b --- /dev/null +++ b/framework/src/bcs/ADPresetNodalBC.C @@ -0,0 +1,44 @@ +//* 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 "ADPresetNodalBC.h" + +// MOOSE includes +#include "MooseVariableFE.h" + +#include "libmesh/numeric_vector.h" + +defineADValidParams(ADPresetNodalBC, + ADNodalBC, + params.addClassDescription( + "Nodal boundary condition base class with preset solution vector values.")); + +template +ADPresetNodalBC::ADPresetNodalBC(const InputParameters & parameters) + : ADNodalBC(parameters) +{ +} + +template +void +ADPresetNodalBC::computeValue(NumericVector & current_solution) +{ + dof_id_type & dof_idx = _var.nodalDofIndex(); + current_solution.set(dof_idx, MetaPhysicL::raw_value(computeQpValue())); +} + +template +ADResidual +ADPresetNodalBC::computeQpResidual() +{ + return _u - computeQpValue(); +} + +// explicit instantiation is required for AD base classes +adBaseClass(ADPresetBC); diff --git a/modules/tensor_mechanics/doc/content/source/bcs/ADPressure.md b/modules/tensor_mechanics/doc/content/source/bcs/ADPressure.md new file mode 100644 index 000000000000..702c3219cc70 --- /dev/null +++ b/modules/tensor_mechanics/doc/content/source/bcs/ADPressure.md @@ -0,0 +1,24 @@ +# ADPressure + +!syntax description /ADBCs/ADPressure + +## Description + +The boundary condition, `ADPressure` applies a force to a mesh boundary in the +magnitude specified by the user. A `component` of the normal vector to the mesh +surface (0, 1, or 2 corresponding to the $\hat{x}$, $\hat{y}$, and $\hat{z}$ +vector components) is used to determine the direction in which to apply the +traction. The boundary condition is always applied to the displaced mesh and +uses forward mode automatic differentiation to compute an exact Jacobian +contribution (this is contingent on coupling only AD enabled objects in the +parameters). + +The magnitude of the `ADPressure` boundary condition can be specified as either +a constant scalar factor (use the input parameter `constant`), a factor from a +`function`, a factor from a `postprocessor`, or any combination thereof. + +!syntax parameters /ADBCs/ADPressure + +!syntax inputs /ADBCs/ADPressure + +!syntax children /ADBCs/ADPressure diff --git a/modules/tensor_mechanics/include/bcs/ADPressure.h b/modules/tensor_mechanics/include/bcs/ADPressure.h new file mode 100644 index 000000000000..11208e9e6544 --- /dev/null +++ b/modules/tensor_mechanics/include/bcs/ADPressure.h @@ -0,0 +1,49 @@ +//* 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 ADPRESSURE_H +#define ADPRESSURE_H + +#include "ADIntegratedBC.h" + +class Function; + +template +class ADPressure; + +declareADValidParams(ADPressure); + +/** + * ADPressure applies a pressure on a given boundary in the direction defined by component + */ +template +class ADPressure : public ADIntegratedBC +{ +public: + ADPressure(const InputParameters & parameters); + +protected: + ADResidual computeQpResidual() override; + + /// displacement component to apply the kernel to + const int _component; + + ///@{ Pressure value constant factor, function factor, and postprocessor factor + const Real _constant; + Function * const _function; + const PostprocessorValue * const _postprocessor; + ///@} + + /// _alpha Parameter for HHT time integration scheme + const Real _alpha; + + usingIntegratedBCMembers; +}; + +#endif // ADPRESSURE_H diff --git a/modules/tensor_mechanics/src/bcs/ADPressure.C b/modules/tensor_mechanics/src/bcs/ADPressure.C new file mode 100644 index 000000000000..689a8c91021c --- /dev/null +++ b/modules/tensor_mechanics/src/bcs/ADPressure.C @@ -0,0 +1,55 @@ +//* 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 "ADPressure.h" +#include "Function.h" +#include "MooseError.h" + +registerADMooseObject("TensorMechanicsApp", ADPressure); + +defineADValidParams( + ADPressure, + ADIntegratedBC, + params.addClassDescription("Applies a pressure on a given boundary in a given direction"); + params.addRequiredRangeCheckedParam("component", + "component <= 2", + "The component for the pressure"); + params.addParam("constant", 1.0, "The magnitude to use in computing the pressure"); + params.addParam("function", "The function that describes the pressure"); + params.addParam("postprocessor", + "Postprocessor that will supply the pressure value"); + params.addParam("alpha", 0.0, "alpha parameter required for HHT time integration scheme"); + params.set("use_displaced_mesh") = true;); + +template +ADPressure::ADPressure(const InputParameters & parameters) + : ADIntegratedBC(parameters), + _component(adGetParam("component")), + _constant(adGetParam("constant")), + _function(isParamValid("function") ? &this->getFunction("function") : nullptr), + _postprocessor(isParamValid("postprocessor") ? &this->getPostprocessorValue("postprocessor") + : nullptr), + _alpha(adGetParam("alpha")) +{ +} + +template +ADResidual +ADPressure::computeQpResidual() +{ + Real factor = _constant; + + if (_function) + factor *= _function->value(_t + _alpha * _dt, _q_point[_qp]); + + if (_postprocessor) + factor *= *_postprocessor; + + return factor * (_normals[_qp](_component) * _test[_i][_qp]); +} diff --git a/modules/tensor_mechanics/test/tests/ad_plastic/power_law_creep.i b/modules/tensor_mechanics/test/tests/ad_plastic/power_law_creep.i index 568edc3afd75..54a93edeac18 100644 --- a/modules/tensor_mechanics/test/tests/ad_plastic/power_law_creep.i +++ b/modules/tensor_mechanics/test/tests/ad_plastic/power_law_creep.i @@ -112,23 +112,23 @@ [../] [] -[BCs] +[ADBCs] [./no_disp_x] - type = PresetBC + type = ADPresetBC variable = disp_x boundary = left value = 0.0 [../] [./no_disp_y] - type = PresetBC + type = ADPresetBC variable = disp_y boundary = bottom value = 0.0 [../] [./pull_disp_y] - type = FunctionPresetBC + type = ADFunctionPresetBC variable = disp_y boundary = top function = pull diff --git a/modules/tensor_mechanics/test/tests/ad_plastic/tests b/modules/tensor_mechanics/test/tests/ad_plastic/tests index 68b9f2a7baca..40ca62d3bdef 100644 --- a/modules/tensor_mechanics/test/tests/ad_plastic/tests +++ b/modules/tensor_mechanics/test/tests/ad_plastic/tests @@ -38,7 +38,7 @@ type = 'PetscJacobianTester' input = 'power_law_creep.i' run_sim = 'True' - ratio_tol = 5e-6 + ratio_tol = 5e-8 difference_tol = 2e-2 cli_args = 'ADMaterials/elastic_strain/inelastic_models="creep_ten" Outputs/csv=false -snes_test_err 1e-9 -mat_fd_type ds' requirement = "The AD multiple inelastic stress calculator shall provide a correct jacobian for a single power law creep model" @@ -48,7 +48,7 @@ type = 'PetscJacobianTester' input = 'power_law_creep.i' run_sim = 'True' - ratio_tol = 5e-6 + ratio_tol = 5e-8 difference_tol = 2e-2 cli_args = 'ADMaterials/elastic_strain/inelastic_models="creep_ten creep_zero" Outputs/csv=false -snes_test_err 1e-9 -mat_fd_type ds' requirement = "The AD multiple inelastic stress calculator shall provide a correct jacobian for a single power law creep model and an additional zero creep power law model" @@ -58,7 +58,7 @@ type = 'PetscJacobianTester' input = 'power_law_creep.i' run_sim = 'True' - ratio_tol = 5e-6 + ratio_tol = 5e-8 difference_tol = 2e-2 cli_args = 'ADMaterials/elastic_strain/inelastic_models="creep_nine creep_one" Outputs/csv=false -snes_test_err 1e-9 -mat_fd_type ds' requirement = "The AD multiple inelastic stress calculator shall provide a correct jacobian for the linear combination of two power law creep models" @@ -68,7 +68,7 @@ type = 'PetscJacobianTester' input = 'power_law_creep.i' run_sim = 'True' - ratio_tol = 5e-6 + ratio_tol = 5e-8 difference_tol = 2e-2 cli_args = 'ADMaterials/elastic_strain/inelastic_models="creep_ten creep_ten2" ADMaterials/elastic_strain/cycle_models=true Outputs/csv=false -snes_test_err 1e-9 -mat_fd_type ds' requirement = "The AD multiple inelastic stress calculator shall provide a correct jacobian when cycling through two identical power law creep models"