https://mooseframework.inl.gov
FVBoundaryScalarLagrangeMultiplierConstraint.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 #include "SystemBase.h"
16 
19 {
21  params.addClassDescription(
22  "Base class for imposing constraints using scalar Lagrange multipliers");
23  params.addParam<PostprocessorName>("phi0", "0", "The value that the constraint will enforce.");
24  params.addRequiredCoupledVar("lambda", "Lagrange multiplier variable");
25  return params;
26 }
27 
29  const InputParameters & parameters)
30  : FVFluxBC(parameters),
31  _phi0(getPostprocessorValue("phi0")),
32  _lambda_var(*getScalarVar("lambda", 0)),
33  _lambda(adCoupledScalarValue("lambda"))
34 {
35 }
36 
37 void
39 {
40  _face_info = &fi;
41  _normal = fi.normal();
42  _face_type = fi.faceType(std::make_pair(_var.number(), _var.sys().number()));
43 
44  // For FV flux kernels, the normal is always oriented outward from the lower-id
45  // element's perspective. But for BCs, there is only a Jacobian
46  // contribution to one element (one side of the face). Because of this, we
47  // make an exception and orient the normal to point outward from whichever
48  // side of the face the BC's variable is defined on; we flip it if this
49  // variable is defined on the neighbor side of the face (instead of elem) since
50  // the FaceInfo normal polarity is always oriented with respect to the lower-id element.
52  _normal = -_normal;
53 
54  // Primal
56  mooseAssert(_local_re.size() == 1, "We should only have a single dof");
57  mooseAssert(_lambda.size() == 1 && _lambda_var.order() == 1,
58  "The lambda variable should be first order");
61 
62  // LM
63  const auto lm_r = MetaPhysicL::raw_value(computeQpResidual()) * fi.faceArea() * fi.faceCoord();
64  mooseAssert(_lambda_var.dofIndices().size() == 1, "We should only have a single dof");
66  std::array<Real, 1>{{lm_r}},
69 }
70 
71 void
73 {
74  _face_info = &fi;
75  _normal = fi.normal();
76  _face_type = fi.faceType(std::make_pair(_var.number(), _var.sys().number()));
77 
78  // For FV flux kernels, the normal is always oriented outward from the lower-id
79  // element's perspective. But for BCs, there is only a Jacobian
80  // contribution to one element (one side of the face). Because of this, we
81  // make an exception and orient the normal to point outward from whichever
82  // side of the face the BC's variable is defined on; we flip it if this
83  // variable is defined on the neighbor side of the face (instead of elem) since
84  // the FaceInfo normal polarity is always oriented with respect to the lower-id element.
86  _normal = -_normal;
87 
88  const auto & dof_indices = (_face_type == FaceInfo::VarFaceNeighbors::ELEM)
89  ? _var.dofIndices()
91 
92  mooseAssert(dof_indices.size() == 1, "We're currently built to use CONSTANT MONOMIALS");
93 
94  // Primal
95  mooseAssert(_lambda.size() == 1 && _lambda_var.order() == 1,
96  "The lambda variable should be first order");
97  const auto primal_r = _lambda[0] * (fi.faceArea() * fi.faceCoord());
99  _assembly, std::array<ADReal, 1>{{primal_r}}, dof_indices, _var.scalingFactor());
100 
101  // LM
102  const auto lm_r = computeQpResidual() * (fi.faceArea() * fi.faceCoord());
103  mooseAssert(_lambda_var.dofIndices().size() == 1, "We should only have one dof");
105  std::array<ADReal, 1>{{lm_r}},
108 }
virtual const std::vector< dof_id_type > & dofIndicesNeighbor() const final
Get neighbor DOF indices for currently selected element.
void computeResidual(const FaceInfo &fi) override final
Compute the residual on the supplied face.
const FaceInfo * _face_info
Holds information for the face we are currently examining.
FaceInfo::VarFaceNeighbors _face_type
The variable face type.
Definition: FVFluxBC.h:73
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 accumulateTaggedLocalResidual()
Local residual blocks will be appended by adding the current local kernel residual.
static InputParameters validParams()
Definition: FVFluxBC.C:17
unsigned int number() const
Get variable number coming from libMesh.
Assembly & _assembly
Reference to assembly.
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.
auto raw_value(const Eigen::Map< T > &in)
Definition: EigenADReal.h:73
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
MooseVariableFV< Real > & _var
Real & faceCoord()
Sets/gets the coordinate transformation factor (for e.g.
Definition: FaceInfo.h:64
Real faceArea() const
Returns the face area of face id.
Definition: FaceInfo.h:60
This data structure is used to store geometric and variable related metadata about each cell face in ...
Definition: FaceInfo.h:36
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.
ADRealVectorValue _normal
Definition: FVFluxBC.h:49
Provides an interface for computing residual contributions from finite volume numerical fluxes comput...
Definition: FVFluxBC.h:23
const Point & normal() const
Returns the unit normal vector for the face oriented outward from the face&#39;s elem element...
Definition: FaceInfo.h:68
unsigned int number() const
Gets the number of this system.
Definition: SystemBase.C:1159
const ADVariableValue & _lambda
The Lagrange Multiplier value.
void addRequiredCoupledVar(const std::string &name, const std::string &doc_string)
This method adds a coupled variable name pair.
libMesh::Order order() const
Get the order of this variable Note: Order enum can be implicitly converted to unsigned int...
const MooseVariableScalar & _lambda_var
The Lagrange Multiplier variable.
DenseVector< Number > _local_re
Holds local residual entries as they are accumulated by this Kernel.
virtual unsigned int size() const override final
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...
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 computeJacobian(const FaceInfo &fi) override final
Compute the jacobian on the supplied face.
void prepareVectorTag(Assembly &assembly, unsigned int ivar)
Prepare data for computing element residual according to active tags.
SystemBase & sys()
Get the system this variable is part of.
virtual ADReal computeQpResidual()=0
void scalingFactor(const std::vector< Real > &factor)
Set the scaling factor for this variable.
virtual const std::vector< dof_id_type > & dofIndices() const final
Get local DoF indices.
VarFaceNeighbors faceType(const std::pair< unsigned int, unsigned int > &var_sys) const
Returns which side(s) the given variable-system number pair is defined on for this face...
Definition: FaceInfo.h:225