https://mooseframework.inl.gov
Loading...
Searching...
No Matches
DiracKernel.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// Moose includes
11#include "DiracKernel.h"
12#include "Assembly.h"
13#include "DiracKernelBase.h"
14#include "MooseError.h"
15#include "SystemBase.h"
16#include "Problem.h"
17#include "MooseMesh.h"
18#include "FEProblemBase.h"
19
20#include "libmesh/libmesh_common.h"
21#include "libmesh/quadrature.h"
22
23template <typename T>
26{
28 if (std::is_same<T, Real>::value)
29 params.registerBase("DiracKernel");
30 else if (std::is_same<T, RealVectorValue>::value)
31 params.registerBase("VectorDiracKernel");
32 else
33 ::mooseError("unsupported DiracKernelTempl specialization");
34 return params;
35}
36
37template <typename T>
39 : DiracKernelBase(parameters),
41 false,
42 "variable",
43 Moose::VarKindType::VAR_SOLVER,
44 std::is_same<T, Real>::value ? Moose::VarFieldType::VAR_FIELD_STANDARD
45 : Moose::VarFieldType::VAR_FIELD_VECTOR),
46 _var(this->mooseVariableField()),
47 _phi(_assembly.phi(_var)),
48 _grad_phi(_assembly.gradPhi(_var)),
49 _test(_var.phi()),
50 _grad_test(_var.gradPhi()),
51 _u(_var.sln()),
52 _grad_u(_var.gradSln())
53{
55
56 // Stateful material properties are not allowed on DiracKernels
58}
59
60template <typename T>
61void
63{
64 prepareVectorTag(_assembly, _var.number());
65
66 const std::vector<Real> * point_values =
67 _drop_duplicate_points ? NULL : &_local_dirac_kernel_info.getPoints()[_current_elem].second;
68 unsigned int local_qp = 0;
69 Real point_value = 1.0;
70
71 for (_qp = 0; _qp < _qrule->n_points(); _qp++)
72 {
73 _current_point = _physical_point[_qp];
74 if (isActiveAtPoint(_current_elem, _current_point))
75 {
76 if (!_drop_duplicate_points)
77 point_value = (*point_values)[local_qp++];
78
79 for (_i = 0; _i < _test.size(); _i++)
80 _local_re(_i) += point_value * computeQpResidual();
81 }
82 }
83
84 accumulateTaggedLocalResidual();
85}
86
87template <typename T>
88void
90{
91 prepareMatrixTag(_assembly, _var.number(), _var.number());
92
93 const std::vector<Real> * point_values =
94 _drop_duplicate_points ? NULL : &_local_dirac_kernel_info.getPoints()[_current_elem].second;
95 unsigned int local_qp = 0;
96 Real point_value = 1.0;
97
98 for (_qp = 0; _qp < _qrule->n_points(); _qp++)
99 {
100 _current_point = _physical_point[_qp];
101 if (isActiveAtPoint(_current_elem, _current_point))
102 {
103 if (!_drop_duplicate_points)
104 point_value = (*point_values)[local_qp++];
105
106 for (_i = 0; _i < _test.size(); _i++)
107 for (_j = 0; _j < _phi.size(); _j++)
108 _local_ke(_i, _j) += point_value * computeQpJacobian();
109 }
110 }
111
112 accumulateTaggedLocalMatrix();
113}
114
115template <typename T>
116void
118{
119 if (jvar_num == _var.number())
120 {
121 computeJacobian();
122 }
123 else
124 {
125 prepareMatrixTag(_assembly, _var.number(), jvar_num);
126
127 const std::vector<Real> * point_values =
128 _drop_duplicate_points ? NULL : &_local_dirac_kernel_info.getPoints()[_current_elem].second;
129 unsigned int local_qp = 0;
130 Real point_value = 1.0;
131
132 for (_qp = 0; _qp < _qrule->n_points(); _qp++)
133 {
134 _current_point = _physical_point[_qp];
135 if (isActiveAtPoint(_current_elem, _current_point))
136 {
137 if (!_drop_duplicate_points)
138 point_value = (*point_values)[local_qp++];
139
140 for (_i = 0; _i < _test.size(); _i++)
141 for (_j = 0; _j < _phi.size(); _j++)
142 _local_ke(_i, _j) += point_value * computeQpOffDiagJacobian(jvar_num);
143 }
144 }
145
146 accumulateTaggedLocalMatrix();
147 }
148}
149
150template <typename T>
151void
153{
154 computeResidual();
155
156 const auto subdomain = _current_elem->subdomain_id();
157
158 for (const auto & [ivariable, jvariable] : _fe_problem.couplingEntries(_tid, _sys.number()))
159 {
160 const unsigned int ivar = ivariable->number();
161 const unsigned int jvar = jvariable->number();
162
163 if (ivar != _var.number() || !ivariable->activeOnSubdomain(subdomain) ||
164 !jvariable->activeOnSubdomain(subdomain) || jvariable->numberOfDofs() == 0)
165 continue;
166
167 prepareShapes(jvar);
168 computeOffDiagJacobian(jvar);
169 }
170}
171
172template <typename T>
173Real
178
179template <typename T>
180Real
182{
183 return 0;
184}
185
186// Explicitly instantiates the two versions of the DiracKernelTempl class
187template class DiracKernelTempl<Real>;
DiracKernelBase is the base class for all DiracKernel type classes.
static InputParameters validParams()
A DiracKernel is used when you need to add contributions to the residual by means of multiplying some...
Definition DiracKernel.h:33
virtual void computeResidualAndJacobian() override
Computes the residual and Jacobian together for the current element.
virtual void computeResidual() override
Computes the residual for the current element.
Definition DiracKernel.C:62
static InputParameters validParams()
Definition DiracKernel.C:25
virtual Real computeQpJacobian()
This is the virtual that derived classes should override for computing the Jacobian.
virtual void computeOffDiagJacobian(unsigned int jvar) override
Computes the off-diagonal Jacobian for variable jvar.
DiracKernelTempl(const InputParameters &parameters)
Definition DiracKernel.C:38
virtual void computeJacobian() override
Computes the jacobian for the current element.
Definition DiracKernel.C:89
virtual Real computeQpOffDiagJacobian(unsigned int jvar)
This gets called by computeOffDiagJacobian() at each quadrature point.
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system.
void registerBase(const std::string &value)
This method must be called from every base "Moose System" to create linkage with the Action System.
void statefulPropertiesAllowed(bool)
Derived classes can declare whether or not they work with stateful material properties.
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.
MooseVariableField< T > & mooseVariableField()
Return the MooseVariableField object that this interface acts on.
MOOSE now contains C++17 code, so give a reasonable error message stating what the user can do to add...