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
19#include "libmesh/libmesh_common.h"
20#include "libmesh/quadrature.h"
21
22template <typename T>
25{
27 if (std::is_same<T, Real>::value)
28 params.registerBase("DiracKernel");
29 else if (std::is_same<T, RealVectorValue>::value)
30 params.registerBase("VectorDiracKernel");
31 else
32 ::mooseError("unsupported DiracKernelTempl specialization");
33 return params;
34}
35
36template <typename T>
38 : DiracKernelBase(parameters),
40 false,
41 "variable",
42 Moose::VarKindType::VAR_SOLVER,
43 std::is_same<T, Real>::value ? Moose::VarFieldType::VAR_FIELD_STANDARD
44 : Moose::VarFieldType::VAR_FIELD_VECTOR),
45 _var(this->mooseVariableField()),
46 _phi(_assembly.phi(_var)),
47 _grad_phi(_assembly.gradPhi(_var)),
48 _test(_var.phi()),
49 _grad_test(_var.gradPhi()),
50 _u(_var.sln()),
51 _grad_u(_var.gradSln())
52{
54
55 // Stateful material properties are not allowed on DiracKernels
57}
58
59template <typename T>
60void
62{
63 prepareVectorTag(_assembly, _var.number());
64
65 const std::vector<Real> * point_values =
66 _drop_duplicate_points ? NULL : &_local_dirac_kernel_info.getPoints()[_current_elem].second;
67 unsigned int local_qp = 0;
68 Real point_value = 1.0;
69
70 for (_qp = 0; _qp < _qrule->n_points(); _qp++)
71 {
72 _current_point = _physical_point[_qp];
73 if (isActiveAtPoint(_current_elem, _current_point))
74 {
75 if (!_drop_duplicate_points)
76 point_value = (*point_values)[local_qp++];
77
78 for (_i = 0; _i < _test.size(); _i++)
79 _local_re(_i) += point_value * computeQpResidual();
80 }
81 }
82
83 accumulateTaggedLocalResidual();
84}
85
86template <typename T>
87void
89{
90 prepareMatrixTag(_assembly, _var.number(), _var.number());
91
92 const std::vector<Real> * point_values =
93 _drop_duplicate_points ? NULL : &_local_dirac_kernel_info.getPoints()[_current_elem].second;
94 unsigned int local_qp = 0;
95 Real point_value = 1.0;
96
97 for (_qp = 0; _qp < _qrule->n_points(); _qp++)
98 {
99 _current_point = _physical_point[_qp];
100 if (isActiveAtPoint(_current_elem, _current_point))
101 {
102 if (!_drop_duplicate_points)
103 point_value = (*point_values)[local_qp++];
104
105 for (_i = 0; _i < _test.size(); _i++)
106 for (_j = 0; _j < _phi.size(); _j++)
107 _local_ke(_i, _j) += point_value * computeQpJacobian();
108 }
109 }
110
111 accumulateTaggedLocalMatrix();
112}
113
114template <typename T>
115void
117{
118 if (jvar_num == _var.number())
119 {
120 computeJacobian();
121 }
122 else
123 {
124 prepareMatrixTag(_assembly, _var.number(), jvar_num);
125
126 const std::vector<Real> * point_values =
127 _drop_duplicate_points ? NULL : &_local_dirac_kernel_info.getPoints()[_current_elem].second;
128 unsigned int local_qp = 0;
129 Real point_value = 1.0;
130
131 for (_qp = 0; _qp < _qrule->n_points(); _qp++)
132 {
133 _current_point = _physical_point[_qp];
134 if (isActiveAtPoint(_current_elem, _current_point))
135 {
136 if (!_drop_duplicate_points)
137 point_value = (*point_values)[local_qp++];
138
139 for (_i = 0; _i < _test.size(); _i++)
140 for (_j = 0; _j < _phi.size(); _j++)
141 _local_ke(_i, _j) += point_value * computeQpOffDiagJacobian(jvar_num);
142 }
143 }
144
145 accumulateTaggedLocalMatrix();
146 }
147}
148
149template <typename T>
150Real
155
156template <typename T>
157Real
159{
160 return 0;
161}
162
163// Explicitly instantiates the two versions of the DiracKernelTempl class
164template 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 computeResidual() override
Computes the residual for the current element.
Definition DiracKernel.C:61
static InputParameters validParams()
Definition DiracKernel.C:24
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:37
virtual void computeJacobian() override
Computes the jacobian for the current element.
Definition DiracKernel.C:88
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...