https://mooseframework.inl.gov
Loading...
Searching...
No Matches
LMKernel.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
10#include "LMKernel.h"
11#include "Assembly.h"
12#include "MooseVariable.h"
13#include "InputParameters.h"
14#include "MooseArray.h"
15#include "SystemBase.h"
16
17#include "libmesh/quadrature.h"
18
21{
22 auto params = ADKernelValue::validParams();
23 params.addRequiredCoupledVar("lm_variable", "The lagrange multiplier variable");
24 params.addParam<bool>(
25 "lm_sign_positive",
26 true,
27 "Whether to use a positive sign when adding this object's residual to the Lagrange "
28 "multiplier constraint equation. Positive or negative sign should be chosen such that the "
29 "diagonals for the LM block of the matrix are positive");
30 return params;
31}
32
34 : ADKernelValue(parameters),
35 _lm_var(*getVar("lm_variable", 0)),
36 _lm(adCoupledValue("lm_variable")),
37 _lm_test(_lm_var.phi()),
38 _lm_sign(getParam<bool>("lm_sign_positive") ? 1. : -1)
39{
40}
41
42void
44{
45 std::vector<Real> strong_residuals(_qrule->n_points());
46
48
49 for (_qp = 0; _qp < _qrule->n_points(); ++_qp)
50 strong_residuals[_qp] =
52
53 // Primal residual
55
56 for (_qp = 0; _qp < _qrule->n_points(); ++_qp)
57 for (_i = 0; _i < _test.size(); _i++)
58 _local_re(_i) += _test[_i][_qp] * strong_residuals[_qp];
59
61
62 // LM residual
64
65 for (_qp = 0; _qp < _qrule->n_points(); ++_qp)
66 for (_i = 0; _i < _lm_test.size(); _i++)
67 _local_re(_i) += _lm_sign * _lm_test[_i][_qp] * strong_residuals[_qp];
68
70}
71
72void
74{
75 std::vector<ADReal> strong_residuals(_qrule->n_points());
76 const auto resid_size = _test.size() + _lm_test.size();
77 mooseAssert(resid_size == (_var.dofIndices().size() + _lm_var.dofIndices().size()),
78 "The test function sizes and the dof indices sizes should match.");
79
80 if (_residuals.size() != resid_size)
81 _residuals.resize(resid_size, 0);
82
83 // Resizing a std:vector doesn't zero everything
84 for (auto & r : _residuals)
85 r = 0;
86
88 _all_dof_indices.insert(
89 _all_dof_indices.end(), _lm_var.dofIndices().begin(), _lm_var.dofIndices().end());
90
92
93 for (_qp = 0; _qp < _qrule->n_points(); ++_qp)
94 strong_residuals[_qp] = this->precomputeQpResidual() * _ad_JxW[_qp] * _ad_coord[_qp];
95
96 // Primal
97 for (_qp = 0; _qp < _qrule->n_points(); ++_qp)
98 for (_i = 0; _i < _test.size(); _i++)
99 _residuals[_i] += strong_residuals[_qp] * _test[_i][_qp];
100
101 // LM
102 for (_qp = 0; _qp < _qrule->n_points(); ++_qp)
103 for (_i = 0; _i < _lm_test.size(); _i++)
104 _residuals[_test.size() + _i] += _lm_sign * strong_residuals[_qp] * _lm_test[_i][_qp];
105}
const ADTemplateVariableTestValue< T > & _test
std::vector< ADReal > _residuals
MooseVariableFE< T > & _var
const MooseArray< ADReal > & _ad_JxW
const MooseArray< ADReal > & _ad_coord
static InputParameters validParams()
virtual OutputTools< typenameMoose::ADType< T >::type >::OutputValue precomputeQpResidual()=0
unsigned int _qp
unsigned int _i
const QBase *const & _qrule
LMKernel(const InputParameters &parameters)
Definition LMKernel.C:33
std::vector< dof_id_type > _all_dof_indices
The union of the primary var dof indices as well as the LM dof indices.
Definition LMKernel.h:48
void computeResidual() override
Definition LMKernel.C:43
MooseVariable & _lm_var
The Lagrange multiplier variable.
Definition LMKernel.h:31
void computeResidualsForJacobian() override
Definition LMKernel.C:73
const Real _lm_sign
The sign (either +1 or -1) applied to this object's residual when adding to the Lagrange multiplier c...
Definition LMKernel.h:42
static InputParameters validParams()
Definition LMKernel.C:20
const VariableTestValue & _lm_test
The values of the Lagrange multiplier test functions at quadrature points.
Definition LMKernel.h:37
unsigned int number() const
const std::vector< dof_id_type > & dofIndices() const final
Assembly & _assembly
virtual void precalculateResidual()
void accumulateTaggedLocalResidual()
void prepareVectorTag(Assembly &assembly, unsigned int ivar)
DenseVector< Number > _local_re
auto raw_value(const Eigen::Map< T > &in)