https://mooseframework.inl.gov
Loading...
Searching...
No Matches
BoundaryIntegralValueConstraint.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
14#include <array>
15
17
20{
23 "Enforces a prescribed average value for a finite element variable on a boundary using a "
24 "scalar Lagrange multiplier.");
25 params.addParam<PostprocessorName>("phi0", "0", "The value that the constraint will enforce.");
26 params.addRequiredCoupledVar("lambda", "Lagrange multiplier scalar variable");
27 return params;
28}
29
31 : IntegratedBC(parameters),
32 _phi0(getPostprocessorValue("phi0")),
33 _lambda_var(*getScalarVar("lambda", 0)),
34 _lambda(coupledScalarValue("lambda"))
35{
36 if (_lambda_var.order() != 1)
37 paramError("lambda", "The lambda variable must be a first-order scalar variable.");
38}
39
40std::set<std::string>
45
46Real
51
52void
58
59void
65
66void
75
76void
78{
80
81 if (_is_implicit)
82 {
86
87 // The residual-and-Jacobian-together path bypasses ComputeFullJacobianThread, so assemble the
88 // scalar off-diagonal blocks here.
91 }
92}
93
94void
96{
97 mooseAssert(_lambda_var.dofIndices().size() == 1, "The lambda variable should have one dof");
98
99 std::array<Real, 1> residual{{0.0}};
100
101 for (_qp = 0; _qp < _qrule->n_points(); _qp++)
102 residual[0] += _JxW[_qp] * _coord[_qp] * (_u[_qp] - _phi0);
103
105}
106
107void
109{
110 mooseAssert(_lambda_var.dofIndices().size() == 1, "The lambda variable should have one dof");
111
112 DenseMatrix<Real> zero(1, 1);
114 zero,
118}
119
120void
122{
123 mooseAssert(_lambda_var.dofIndices().size() == 1, "The lambda variable should have one dof");
124
125 DenseMatrix<Real> jacobian(_test.size(), 1);
126
127 for (_qp = 0; _qp < _qrule->n_points(); _qp++)
128 for (_i = 0; _i < _test.size(); _i++)
129 jacobian(_i, 0) += _JxW[_qp] * _coord[_qp] * _test[_i][_qp];
130
133}
134
135void
137{
138 mooseAssert(_lambda_var.dofIndices().size() == 1, "The lambda variable should have one dof");
139
140 DenseMatrix<Real> jacobian(1, _phi.size());
141
142 for (_qp = 0; _qp < _qrule->n_points(); _qp++)
143 for (_j = 0; _j < _phi.size(); _j++)
144 jacobian(0, _j) += _JxW[_qp] * _coord[_qp] * _phi[_j][_qp];
145
147 jacobian,
151}
registerMooseObject("MooseApp", BoundaryIntegralValueConstraint)
Enforces the average value of a finite element variable on a boundary using a scalar Lagrange multipl...
virtual void computeResidualAndJacobian() override
Compute this object's contribution to the residual and Jacobian simultaneously.
const VariableValue & _lambda
Lagrange multiplier scalar variable value.
void computeScalarResidual()
Compute the Lagrange multiplier residual contribution.
void computeScalarFieldJacobian()
Compute the Jacobian contribution from the field variable to the Lagrange multiplier equation.
virtual void computeResidual() override
Compute this object's contribution to the residual.
BoundaryIntegralValueConstraint(const InputParameters &parameters)
virtual void computeOffDiagJacobian(unsigned int jvar) override
Computes d-ivar-residual / d-jvar...
const MooseVariableScalar & _lambda_var
Lagrange multiplier scalar variable.
void computeScalarJacobian()
Compute the zero diagonal block for the Lagrange multiplier equation.
virtual Real computeQpResidual() override
Method for computing the residual at quadrature points.
virtual std::set< std::string > additionalROVariables() override
const PostprocessorValue & _phi0
The value that the boundary average of the field variable is constrained to.
void computeFieldScalarJacobian()
Compute the Jacobian contribution from the Lagrange multiplier to the field equation.
virtual void computeOffDiagJacobianScalar(unsigned int jvar) override
Computes jacobian block with respect to a scalar variable.
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.
const QBase *const & _qrule
active quadrature rule
unsigned int _qp
quadrature point index
const MooseArray< Real > & _JxW
transformed Jacobian weights
void prepareShapes(unsigned int var_num) override final
Prepare shape functions.
unsigned int _i
i-th, j-th index for enumerating test and shape functions
const MooseArray< Real > & _coord
coordinate transformation
Base class for deriving any boundary condition of a integrated type.
MooseVariable & _var
const VariableValue & _u
the values of the unknown variable this BC is acting on
static InputParameters validParams()
virtual void computeJacobian() override
Compute this object's contribution to the diagonal Jacobian entries.
virtual void computeResidual() override
Compute this object's contribution to the residual.
const VariablePhiValue & _phi
shape function values (in QPs)
const VariableTestValue & _test
test function values (in QPs)
const std::string & name() const
Get the name of the class.
Definition MooseBase.h:103
void paramError(const std::string &param, Args... args) const
Emits an error prefixed with the file and line number of the given param (from the input file) along ...
Definition MooseBase.h:457
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.
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 addResiduals(Assembly &assembly, const Residuals &residuals, const Indices &dof_indices, Real scaling_factor)
Add the provided incoming residuals corresponding to the provided dof indices.
bool _is_implicit
If the object is using implicit or explicit form.