https://mooseframework.inl.gov
Loading...
Searching...
No Matches
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{
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
37void
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.
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
71void
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.
87
88 const auto & dof_indices = (_face_type == FaceInfo::VarFaceNeighbors::ELEM)
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}
MooseVariableFV< Real > & _var
const FaceInfo * _face_info
Holds information for the face we are currently examining.
Assembly & _assembly
Reference to assembly.
const ADVariableValue & _lambda
The Lagrange Multiplier value.
void computeResidual(const FaceInfo &fi) override final
Compute the residual on the supplied face.
void computeJacobian(const FaceInfo &fi) override final
Compute the jacobian on the supplied face.
const MooseVariableScalar & _lambda_var
The Lagrange Multiplier variable.
Provides an interface for computing residual contributions from finite volume numerical fluxes comput...
Definition FVFluxBC.h:27
ADRealVectorValue _normal
Definition FVFluxBC.h:47
FaceInfo::VarFaceNeighbors _face_type
The variable face type.
Definition FVFluxBC.h:60
virtual ADReal computeQpResidual()=0
static InputParameters validParams()
Definition FVFluxBC.C:17
This data structure is used to store geometric and variable related metadata about each cell face in ...
Definition FaceInfo.h:38
const Point & normal() const
Returns the unit normal vector for the face oriented outward from the face's elem element.
Definition FaceInfo.h:72
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:229
Real faceArea() const
Returns the face area of face id.
Definition FaceInfo.h:64
Real & faceCoord()
Sets/gets the coordinate transformation factor (for e.g.
Definition FaceInfo.h:68
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.
SystemBase & sys()
Get the system this variable is part of.
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.
virtual const std::vector< dof_id_type > & dofIndicesNeighbor() const final
Get neighbor DOF indices for currently selected element.
unsigned int number() const
Gets the number of this system.
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)