https://mooseframework.inl.gov
Loading...
Searching...
No Matches
FVScalarLagrangeMultiplierConstraint.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
12#include "MooseVariableScalar.h"
13#include "MooseVariableFV.h"
14#include "Assembly.h"
15
18{
21 "Base class for imposing constraints using scalar Lagrange multipliers");
22 params.addParam<PostprocessorName>("phi0", "0", "The value that the constraint will enforce.");
23 params.addRequiredCoupledVar("lambda", "Lagrange multiplier variable");
24 return params;
25}
26
28 const InputParameters & parameters)
29 : FVQpElementalKernel(parameters),
30 _phi0(getPostprocessorValue("phi0")),
31 _lambda_var(*getScalarVar("lambda", 0)),
32 _lambda(adCoupledScalarValue("lambda"))
33{
34}
35
36void
38{
39 const auto volume = _assembly.elemVolume();
41 std::array<ADReal, 1>{{_lambda[0] * volume}},
45 std::array<ADReal, 1>{{computeQpResidual() * volume}},
48}
49
50void
52{
53 // Primal residual
55 mooseAssert(_local_re.size() == 1, "We should only have a single dof");
56 mooseAssert(_lambda.size() == 1 && _lambda_var.order() == 1,
57 "The lambda variable should be first order");
60
61 // LM residual. We may not have any actual ScalarKernels in our simulation so we need to manually
62 // make sure the scalar residuals get cached for later addition
64 mooseAssert(_lambda_var.dofIndices().size() == 1, "We should only have a single dof");
66 std::array<Real, 1>{{lm_r}},
69}
70
71void
75
76void
78{
79 // Primal
80 mooseAssert(_lambda.size() == 1 && _lambda_var.order() == 1,
81 "The lambda variable should be first order");
82 const auto primal_r = _lambda[0] * _assembly.elemVolume();
83 mooseAssert(_var.dofIndices().size() == 1, "We should only have one dof");
85 _assembly, std::array<ADReal, 1>{{primal_r}}, _var.dofIndices(), _var.scalingFactor());
86
87 // LM
88 const auto lm_r = computeQpResidual() * _assembly.elemVolume();
89 mooseAssert(_lambda_var.dofIndices().size() == 1, "We should only have one dof");
91 std::array<ADReal, 1>{{lm_r}},
94}
const Real & elemVolume() const
Returns the reference to the current element volume.
Definition Assembly.h:440
MooseVariableFV< Real > & _var
Base class for FV elemental kernels that need qp-indexed solution values.
static InputParameters validParams()
ADReal computeQpResidual() override=0
This is the primary function that must be implemented for flux kernel terms.
void computeResidual() override final
Usually you should not override these functions - they have some tricky stuff in them that you don't ...
void computeJacobian() override final
Compute this object's contribution to the diagonal Jacobian entries.
FVScalarLagrangeMultiplierConstraint(const InputParameters &parameters)
void computeResidualAndJacobian() override final
Compute this object's contribution to the residual and Jacobian simultaneously.
const MooseVariableScalar & _lambda_var
The Lagrange Multiplier variable.
const ADVariableValue & _lambda
The Lagrange Multiplier value.
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system.
void addRequiredCoupledVar(const std::string &name, const std::string &doc_string)
This method adds a coupled variable name pair.
void addParam(const std::string &name, const S &value, const std::string &doc_string)
These methods add an optional parameter and a documentation string to the InputParameters object.
void addClassDescription(const std::string &doc_string)
This method adds a description of the class that will be displayed in the input file syntax dump.
unsigned int size() const
The number of elements that can currently be stored in the array.
Definition MooseArray.h:259
virtual const std::vector< dof_id_type > & dofIndices() const
Get local DoF indices.
void scalingFactor(const std::vector< Real > &factor)
Set the scaling factor for this variable.
libMesh::Order order() const
Get the order of this variable Note: Order enum can be implicitly converted to unsigned int.
unsigned int number() const
Get variable number coming from libMesh.
virtual const std::vector< dof_id_type > & dofIndices() const final
Get local DoF indices.
Assembly & _assembly
Reference to this Kernel's assembly object.
void addJacobian(Assembly &assembly, const Residuals &residuals, const Indices &dof_indices, Real scaling_factor)
Add the provided residual derivatives into the Jacobian for the provided dof indices.
void accumulateTaggedLocalResidual()
Local residual blocks will be appended by adding the current local kernel residual.
void addResidualsAndJacobian(Assembly &assembly, const Residuals &residuals, const Indices &dof_indices, Real scaling_factor)
Add the provided incoming residuals and derivatives for the Jacobian, corresponding to the provided d...
void addResiduals(Assembly &assembly, const Residuals &residuals, const Indices &dof_indices, Real scaling_factor)
Add the provided incoming residuals corresponding to the provided dof indices.
void prepareVectorTag(Assembly &assembly, unsigned int ivar)
Prepare data for computing element residual according to active tags.
DenseVector< Number > _local_re
Holds local residual entries as they are accumulated by this Kernel.
virtual unsigned int size() const override final
auto raw_value(const Eigen::Map< T > &in)