https://mooseframework.inl.gov
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 
22 template <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 
36 template <typename T>
38  : DiracKernelBase(parameters),
39  MooseVariableInterface<T>(this,
40  false,
41  "variable",
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 
59 template <typename T>
60 void
62 {
63  prepareVectorTag(_assembly, _var.number());
64 
65  const std::vector<unsigned int> * multiplicities =
66  _drop_duplicate_points ? NULL : &_local_dirac_kernel_info.getPoints()[_current_elem].second;
67  unsigned int local_qp = 0;
68  Real multiplicity = 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  multiplicity = (*multiplicities)[local_qp++];
77 
78  for (_i = 0; _i < _test.size(); _i++)
79  _local_re(_i) += multiplicity * computeQpResidual();
80  }
81  }
82 
83  accumulateTaggedLocalResidual();
84 }
85 
86 template <typename T>
87 void
89 {
90  prepareMatrixTag(_assembly, _var.number(), _var.number());
91 
92  const std::vector<unsigned int> * multiplicities =
93  _drop_duplicate_points ? NULL : &_local_dirac_kernel_info.getPoints()[_current_elem].second;
94  unsigned int local_qp = 0;
95  Real multiplicity = 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  multiplicity = (*multiplicities)[local_qp++];
104 
105  for (_i = 0; _i < _test.size(); _i++)
106  for (_j = 0; _j < _phi.size(); _j++)
107  _local_ke(_i, _j) += multiplicity * computeQpJacobian();
108  }
109  }
110 
111  accumulateTaggedLocalMatrix();
112 }
113 
114 template <typename T>
115 void
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<unsigned int> * multiplicities =
127  _drop_duplicate_points ? NULL : &_local_dirac_kernel_info.getPoints()[_current_elem].second;
128  unsigned int local_qp = 0;
129  Real multiplicity = 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  multiplicity = (*multiplicities)[local_qp++];
138 
139  for (_i = 0; _i < _test.size(); _i++)
140  for (_j = 0; _j < _phi.size(); _j++)
141  _local_ke(_i, _j) += multiplicity * computeQpOffDiagJacobian(jvar_num);
142  }
143  }
144 
145  accumulateTaggedLocalMatrix();
146  }
147 }
148 
149 template <typename T>
150 Real
152 {
153  return 0;
154 }
155 
156 template <typename T>
157 Real
159 {
160  return 0;
161 }
162 
163 // Explicitly instantiates the two versions of the DiracKernelTempl class
164 template class DiracKernelTempl<Real>;
165 template class DiracKernelTempl<RealVectorValue>;
VarFieldType
Definition: MooseTypes.h:770
DiracKernelTempl(const InputParameters &parameters)
Definition: DiracKernel.C:37
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application...
Definition: MooseError.h:323
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
virtual Real computeQpJacobian()
This is the virtual that derived classes should override for computing the Jacobian.
Definition: DiracKernel.C:151
void registerBase(const std::string &value)
This method must be called from every base "Moose System" to create linkage with the Action System...
virtual void computeOffDiagJacobian(unsigned int jvar) override
Computes the off-diagonal Jacobian for variable jvar.
Definition: DiracKernel.C:116
Real value(unsigned n, unsigned alpha, unsigned beta, Real x)
static InputParameters validParams()
VarKindType
Framework-wide stuff.
Definition: MooseTypes.h:763
virtual Real computeQpOffDiagJacobian(unsigned int jvar)
This gets called by computeOffDiagJacobian() at each quadrature point.
Definition: DiracKernel.C:158
A DiracKernel is used when you need to add contributions to the residual by means of multiplying some...
Definition: DiracKernel.h:19
void addMooseVariableDependency(MooseVariableFieldBase *var)
Call this function to add the passed in MooseVariableFieldBase as a variable that this object depends...
void statefulPropertiesAllowed(bool)
Derived classes can declare whether or not they work with stateful material properties.
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
virtual void computeJacobian() override
Computes the jacobian for the current element.
Definition: DiracKernel.C:88
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...
DiracKernelBase is the base class for all DiracKernel type classes.
virtual void computeResidual() override
Computes the residual for the current element.
Definition: DiracKernel.C:61
static InputParameters validParams()
Definition: DiracKernel.C:24