https://mooseframework.inl.gov
Loading...
Searching...
No Matches
IntegratedBC.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
10#include "IntegratedBC.h"
11
12// MOOSE includes
13#include "Assembly.h"
14#include "SubProblem.h"
15#include "SystemBase.h"
16#include "MooseVariableFE.h"
17#include "MooseVariableScalar.h"
18#include "FEProblemBase.h"
19
20#include "libmesh/quadrature.h"
21
28
30 : IntegratedBCBase(parameters),
31 MooseVariableInterface<Real>(this,
32 false,
33 "variable",
34 Moose::VarKindType::VAR_SOLVER,
35 Moose::VarFieldType::VAR_FIELD_STANDARD),
36 _var(*mooseVariable()),
37 _normals(_assembly.normals()),
38 _phi(_assembly.phiFace(_var)),
39 _grad_phi(_assembly.gradPhiFace(_var)),
40 _test(_var.phiFace()),
41 _grad_test(_var.gradPhiFace()),
42 _u(_is_implicit ? _var.sln() : _var.slnOld()),
43 _grad_u(_is_implicit ? _var.gradSln() : _var.gradSlnOld())
44{
46
47 _save_in.resize(_save_in_strings.size());
49
50 for (unsigned int i = 0; i < _save_in_strings.size(); i++)
51 {
53
54 if (var->feType() != _var.feType())
56 "save_in",
57 "saved-in auxiliary variable is incompatible with the object's nonlinear variable: ",
59 _save_in[i] = var;
62 }
63
64 _has_save_in = _save_in.size() > 0;
65
66 for (unsigned int i = 0; i < _diag_save_in_strings.size(); i++)
67 {
69
70 if (var->feType() != _var.feType())
72 "diag_save_in",
73 "saved-in auxiliary variable is incompatible with the object's nonlinear variable: ",
75
76 _diag_save_in[i] = var;
79 }
80
82}
83
84void
86{
88
90
91 for (_qp = 0; _qp < _qrule->n_points(); _qp++)
92 {
94 for (_i = 0; _i < _test.size(); _i++)
96 }
97
99
100 if (_has_save_in)
101 for (unsigned int i = 0; i < _save_in.size(); i++)
102 _save_in[i]->sys().solution().add_vector(_local_re, _save_in[i]->dofIndices());
103}
104
105void
107{
109
111
112 for (_qp = 0; _qp < _qrule->n_points(); _qp++)
113 {
115 for (_i = 0; _i < _test.size(); _i++)
116 for (_j = 0; _j < _phi.size(); _j++)
118 }
119
121
123 {
124 unsigned int rows = _local_ke.m();
125 DenseVector<Number> diag(rows);
126 for (unsigned int i = 0; i < rows; i++)
127 diag(i) = _local_ke(i, i);
128
129 for (unsigned int i = 0; i < _diag_save_in.size(); i++)
130 _diag_save_in[i]->sys().solution().add_vector(diag, _diag_save_in[i]->dofIndices());
131 }
132}
133
134void
135IntegratedBC::computeOffDiagJacobian(const unsigned int jvar_num)
136{
137 const auto & jvar = getVariable(jvar_num);
138
139 if (jvar_num == _var.number())
140 {
142 return;
143 }
144
146
148
149 const auto n_dofs = jvar.dofIndices().size();
150 const auto phi_size = n_dofs / jvar.count();
151 mooseAssert(n_dofs == _local_ke.n(),
152 "The size of the phi container does not match the number of local Jacobian columns");
153
154 for (_qp = 0; _qp < _qrule->n_points(); _qp++)
155 {
157 for (_i = 0; _i < _test.size(); _i++)
158 for (_j = 0; _j < phi_size; _j++)
160 }
161
163}
164
165void
167{
169
171 for (_qp = 0; _qp < _qrule->n_points(); _qp++)
172 for (_i = 0; _i < _test.size(); _i++)
173 for (_j = 0; _j < jv.order(); _j++)
175
177}
178
179void
181{
183
184 for (const auto & [ivariable, jvariable] : _fe_problem.couplingEntries(_tid, _sys.number()))
185 {
186 const unsigned int ivar = ivariable->number();
187 const unsigned int jvar = jvariable->number();
188
189 if (ivar != _var.number())
190 continue;
191
192 if (_is_implicit)
193 {
194 prepareShapes(jvar);
196 }
197 }
198
200}
std::vector< std::pair< MooseVariableFieldBase *, MooseVariableFieldBase * > > & couplingEntries(const THREAD_ID tid, const unsigned int nl_sys_num)
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system.
Base class for deriving any boundary condition of a integrated type.
static InputParameters validParams()
bool _has_diag_save_in
The aux variables to save the diagonal Jacobian contributions to.
std::vector< AuxVariableName > _diag_save_in_strings
const QBase *const & _qrule
active quadrature rule
bool _has_save_in
The aux variables to save the residual contributions to.
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
std::vector< AuxVariableName > _save_in_strings
std::vector< MooseVariableFEBase * > _diag_save_in
std::vector< MooseVariableFEBase * > _save_in
const MooseArray< Real > & _coord
coordinate transformation
void computeOffDiagJacobianScalar(unsigned int jvar) override
Computes jacobian block with respect to a scalar variable.
virtual void precalculateQpOffDiagJacobian(const MooseVariableFEBase &)
Insertion point for evaluations that depend on qp but are independent of the test and shape functions...
virtual Real computeQpOffDiagJacobianScalar(unsigned int jvar)
Method for computing an off-diagonal jacobian component from a scalar var.
MooseVariable & _var
virtual void computeOffDiagJacobian(unsigned int jvar) override
Computes d-ivar-residual / d-jvar...
virtual void precalculateQpJacobian()
Insertion point for evaluations that depend on qp but are independent of the test and shape functions...
static InputParameters validParams()
virtual void computeResidualAndJacobian() override
Compute this object's contribution to the residual and Jacobian simultaneously.
virtual Real computeQpJacobian()
Method for computing the diagonal Jacobian at quadrature points.
IntegratedBC(const InputParameters &parameters)
virtual Real computeQpOffDiagJacobian(unsigned int)
Method for computing an off-diagonal jacobian component at quadrature points.
virtual Real computeQpResidual()=0
Method for computing the residual at quadrature points.
virtual void computeJacobian() override
Compute this object's contribution to the diagonal Jacobian entries.
virtual void precalculateQpResidual()
Insertion point for evaluations that depend on qp but are independent of the test functions.
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)
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
const libMesh::FEType & feType() const
Get the type of finite element object.
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.
void addMooseVariableDependency(MooseVariableFieldBase *var)
Call this function to add the passed in MooseVariableFieldBase as a variable that this object depends...
Interface for objects that need to get values of MooseVariables.
MooseVariableFE< Real > * mooseVariable() const
Return the MooseVariableFE object that this interface acts on.
Class for scalar variables (they are different).
THREAD_ID _tid
The thread ID for this kernel.
virtual void precalculateJacobian()
Assembly & _assembly
Reference to this Kernel's assembly object.
const MooseVariableFieldBase & getVariable(unsigned int jvar_num) const
Retrieve the variable object from our system associated with jvar_num.
SubProblem & _subproblem
Reference to this kernel's SubProblem.
SystemBase & _sys
Reference to the EquationSystem object.
virtual void precalculateOffDiagJacobian(unsigned int)
virtual void precalculateResidual()
FEProblemBase & _fe_problem
Reference to this kernel's FEProblemBase.
virtual MooseVariable & getStandardVariable(const THREAD_ID tid, const std::string &var_name)=0
Returns the variable reference for requested MooseVariable which may be in any system.
virtual void addVariableToZeroOnJacobian(std::string var_name)
Adds this variable to the list of variables to be zeroed during each Jacobian evaluation.
Definition SystemBase.C:181
virtual void addVariableToZeroOnResidual(std::string var_name)
Adds this variable to the list of variables to be zeroed during each residual evaluation.
Definition SystemBase.C:175
unsigned int number() const
Gets the number of this system.
virtual MooseVariableScalar & getScalarVariable(THREAD_ID tid, const std::string &var_name) const
Gets a reference to a scalar variable with specified number.
Definition SystemBase.C:146
DenseMatrix< Number > _local_ke
Holds local Jacobian entries as they are accumulated by this Kernel.
void accumulateTaggedLocalMatrix()
Local Jacobian blocks will be appended by adding the current local kernel Jacobian.
void prepareMatrixTag(Assembly &assembly, unsigned int ivar, unsigned int jvar)
Prepare data for computing element jacobian according to the active tags.
void accumulateTaggedLocalResidual()
Local residual blocks will be appended by adding the current local kernel residual.
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.
bool _is_implicit
If the object is using implicit or explicit form.
unsigned int n() const
unsigned int m() const
MOOSE now contains C++17 code, so give a reasonable error message stating what the user can do to add...
std::string incompatVarMsg(MooseVariableFieldBase &var1, MooseVariableFieldBase &var2)
Builds and returns a string of the form:
Definition MooseError.C:26