https://mooseframework.inl.gov
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 {
22  params.addClassDescription(
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 
40 std::set<std::string>
42 {
43  return {_lambda_var.name()};
44 }
45 
46 Real
48 {
49  return _lambda[0] * _test[_i][_qp];
50 }
51 
52 void
54 {
57 }
58 
59 void
61 {
62  if (jvar == _var.number())
64 }
65 
66 void
68 {
69  if (jvar == _lambda_var.number())
70  {
73  }
74 }
75 
76 void
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 
94 void
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 
107 void
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 
120 void
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 
131  addJacobian(
133 }
134 
135 void
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,
149  _var.dofIndices(),
151 }
const VariableTestValue & _test
test function values (in QPs)
Definition: IntegratedBC.h:97
const MooseVariableScalar & _lambda_var
Lagrange multiplier scalar variable.
virtual void computeResidual() override
Compute this object&#39;s contribution to the residual.
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:467
virtual void computeOffDiagJacobian(unsigned int jvar) override
Computes d-ivar-residual / d-jvar...
virtual void computeOffDiagJacobianScalar(unsigned int jvar) override
Computes jacobian block with respect to a scalar variable.
unsigned int number() const
Get variable number coming from libMesh.
Enforces the average value of a finite element variable on a boundary using a scalar Lagrange multipl...
void computeScalarJacobian()
Compute the zero diagonal block for the Lagrange multiplier equation.
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 computeFieldScalarJacobian()
Compute the Jacobian contribution from the Lagrange multiplier to the field equation.
static InputParameters validParams()
Definition: IntegratedBC.C:23
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
unsigned int _i
i-th, j-th index for enumerating test and shape functions
void computeScalarFieldJacobian()
Compute the Jacobian contribution from the field variable to the Lagrange multiplier equation...
const Number zero
const VariablePhiValue & _phi
shape function values (in QPs)
Definition: IntegratedBC.h:90
unsigned int _qp
quadrature point index
virtual void computeJacobian() override
Compute this object&#39;s contribution to the diagonal Jacobian entries.
Definition: IntegratedBC.C:106
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.
const std::string & name() const
Get the name of the class.
Definition: MooseBase.h:103
unsigned int size() const
The number of elements that can currently be stored in the array.
Definition: MooseArray.h:259
const std::vector< dof_id_type > & dofIndices() const final
Get local DoF indices.
virtual void computeResidualAndJacobian() override
Compute this object&#39;s contribution to the residual and Jacobian simultaneously.
virtual const std::vector< dof_id_type > & dofIndices() const
Get local DoF indices.
registerMooseObject("MooseApp", BoundaryIntegralValueConstraint)
Base class for deriving any boundary condition of a integrated type.
Definition: IntegratedBC.h:18
void prepareShapes(unsigned int var_num) override final
Prepare shape functions.
const MooseArray< Real > & _coord
coordinate transformation
Assembly & _assembly
Reference to this Kernel&#39;s assembly object.
void computeScalarResidual()
Compute the Lagrange multiplier residual contribution.
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...
MooseVariable & _var
Definition: IntegratedBC.h:82
const QBase *const & _qrule
active quadrature rule
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
virtual std::set< std::string > additionalROVariables() override
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...
virtual void computeResidual() override
Compute this object&#39;s contribution to the residual.
Definition: IntegratedBC.C:85
const VariableValue & _lambda
Lagrange multiplier scalar variable value.
const PostprocessorValue & _phi0
The value that the boundary average of the field variable is constrained to.
BoundaryIntegralValueConstraint(const InputParameters &parameters)
bool _is_implicit
If the object is using implicit or explicit form.
const VariableValue & _u
the values of the unknown variable this BC is acting on
Definition: IntegratedBC.h:104
const MooseArray< Real > & _JxW
transformed Jacobian weights
void scalingFactor(const std::vector< Real > &factor)
Set the scaling factor for this variable.
virtual Real computeQpResidual() override
Method for computing the residual at quadrature points.