https://mooseframework.inl.gov
Loading...
Searching...
No Matches
SecondDerivativeRegularization.C
Go to the documentation of this file.
1//* This file is part of the MOOSE framework
2//* https://mooseframework.inl.gov
3//*
4//* All rights reserved, see COPYRIGHT for full restrictions
5//* https://github.com/idaholab/moose/blob/master/COPYRIGHT
6//*
7//* Licensed under LGPL 2.1, please see LICENSE for details
8//* https://www.gnu.org/licenses/lgpl-2.1.html
9
11
14
15namespace
16{
17
18Real
19defaultLuluFactor(const unsigned int dim)
20{
21 return 1.0 / static_cast<Real>(dim);
22}
23
24template <bool is_ad, typename Variable>
26secondSln(Variable & var)
27{
28 if constexpr (is_ad)
29 return var.adSecondSln();
30 else
31 return var.secondSln();
32}
33
35template <typename SolutionSecond, typename TestSecond>
36auto
37regularization(const SolutionSecond & second_u,
38 const TestSecond & second_test,
40 const Real lulu_factor)
41{
42 switch (type)
43 {
45 return second_u.contract(second_test);
47 return second_u.tr() * second_test.tr();
49 // HuHu-LuLu keeps the Hessian contraction and subtracts a scaled Laplacian contraction.
50 return second_u.contract(second_test) - lulu_factor * second_u.tr() * second_test.tr();
51 }
52
53 mooseError("Unknown second-derivative regularization type.");
54}
55}
56
57template <bool is_ad>
60{
62 params.addClassDescription("Adds a second-derivative regularization term using HuHu, LuLu, "
63 "or HuHu-LuLu Hessian/Laplacian contractions.");
65 "regularization",
66 MooseEnum("huhu=0 lulu=1 huhu_lulu=2"),
67 "Regularization type to apply: 'huhu' for Hessian-Hessian, 'lulu' for "
68 "Laplacian-Laplacian, or 'huhu_lulu' for HuHu minus a scaled LuLu correction.");
70 "coefficient", "coefficient >= 0", "Coefficient multiplying the regularization term.");
71 params.addParam<Real>("lulu_factor",
72 "Factor multiplying the LuLu correction for 'huhu_lulu'. If omitted, "
73 "defaults to 1 / dim, where dim is the mesh dimension.");
74 return params;
75}
76
77template <bool is_ad>
79 const InputParameters & parameters)
80 : GenericKernel<is_ad>(parameters),
81 _regularization_type(this->template getParam<MooseEnum>("regularization")
82 .template getEnum<SecondDerivativeRegularizationType>()),
83 _coefficient(this->template getParam<Real>("coefficient")),
84 _dim(this->_mesh.dimension()),
85 _lulu_factor(this->isParamValid("lulu_factor") ? this->template getParam<Real>("lulu_factor")
86 : defaultLuluFactor(_dim)),
87 _second_u(secondSln<is_ad>(this->_var)),
88 _second_test(this->secondTest()),
89 _second_phi(this->_var.secondPhi())
90{
92 this->isParamValid("lulu_factor"))
93 this->paramError("lulu_factor", "Only used when 'regularization = huhu_lulu'.");
94
96 _lulu_factor > defaultLuluFactor(_dim))
97 this->mooseWarning("The 'lulu_factor' parameter is larger than 1 / dim. This may cause "
98 "negative strain energy contributions for the HuHu-LuLu regularization.");
99}
100
101template <bool is_ad>
104{
105 return _coefficient *
106 regularization(_second_u[_qp], _second_test[_i][_qp], _regularization_type, _lulu_factor);
107}
108
109template <bool is_ad>
110Real
112{
113 mooseAssert(!is_ad,
114 "In ADSecondDerivativeRegularization, computeQpJacobian should not be called. Check "
115 "computeJacobian implementation.");
116 return _coefficient *
117 regularization(
118 _second_phi[_j][_qp], _second_test[_i][_qp], _regularization_type, _lulu_factor);
119}
120
void mooseError(Args &&... args)
Moose::GenericType< VariableSecond, is_ad > GenericVariableSecond
Moose::GenericType< Real, is_ad > GenericReal
registerMooseObject("SolidMechanicsApp", SecondDerivativeRegularization)
unsigned int dim
static InputParameters validParams()
void addRequiredRangeCheckedParam(const std::string &name, const std::string &parsed_function, const std::string &doc_string)
void addRequiredParam(const std::string &name, const std::string &doc_string)
void addParam(const std::string &name, const std::initializer_list< typename T::value_type > &value, const std::string &doc_string)
void addClassDescription(const std::string &doc_string)
void paramError(const std::string &param, Args... args) const
void mooseWarning(Args &&... args) const
bool isParamValid(const std::string &name) const
Adds regularization terms based on Hessian and Laplacian contractions of a scalar nonlinear variable.
SecondDerivativeRegularizationTempl(const InputParameters &parameters)
const unsigned int _dim
Mesh dimension used for the default LuLu factor.
virtual GenericReal< is_ad > computeQpResidual() override
const Real _lulu_factor
LuLu correction factor used only by HuHu-LuLu.
const SecondDerivativeRegularizationType _regularization_type
Selected regularization contraction.