www.mooseframework.org
DiracKernel.C
Go to the documentation of this file.
1 //* This file is part of the MOOSE framework
2 //* https://www.mooseframework.org
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  _drop_duplicate_points(parameters.get<bool>("drop_duplicate_points")),
53  _point_not_found_behavior(
54  parameters.get<MooseEnum>("point_not_found_behavior").getEnum<PointNotFoundBehavior>())
55 {
57 
58  // Stateful material properties are not allowed on DiracKernels
60 }
61 
62 template <typename T>
63 void
65 {
66  prepareVectorTag(_assembly, _var.number());
67 
68  const std::vector<unsigned int> * multiplicities =
69  _drop_duplicate_points ? NULL : &_local_dirac_kernel_info.getPoints()[_current_elem].second;
70  unsigned int local_qp = 0;
71  Real multiplicity = 1.0;
72 
73  for (_qp = 0; _qp < _qrule->n_points(); _qp++)
74  {
75  _current_point = _physical_point[_qp];
76  if (isActiveAtPoint(_current_elem, _current_point))
77  {
78  if (!_drop_duplicate_points)
79  multiplicity = (*multiplicities)[local_qp++];
80 
81  for (_i = 0; _i < _test.size(); _i++)
82  _local_re(_i) += multiplicity * computeQpResidual();
83  }
84  }
85 
86  accumulateTaggedLocalResidual();
87 }
88 
89 template <typename T>
90 void
92 {
93  prepareMatrixTag(_assembly, _var.number(), _var.number());
94 
95  const std::vector<unsigned int> * multiplicities =
96  _drop_duplicate_points ? NULL : &_local_dirac_kernel_info.getPoints()[_current_elem].second;
97  unsigned int local_qp = 0;
98  Real multiplicity = 1.0;
99 
100  for (_qp = 0; _qp < _qrule->n_points(); _qp++)
101  {
102  _current_point = _physical_point[_qp];
103  if (isActiveAtPoint(_current_elem, _current_point))
104  {
105  if (!_drop_duplicate_points)
106  multiplicity = (*multiplicities)[local_qp++];
107 
108  for (_i = 0; _i < _test.size(); _i++)
109  for (_j = 0; _j < _phi.size(); _j++)
110  _local_ke(_i, _j) += multiplicity * computeQpJacobian();
111  }
112  }
113 
114  accumulateTaggedLocalMatrix();
115 }
116 
117 template <typename T>
118 void
120 {
121  if (jvar_num == _var.number())
122  {
123  computeJacobian();
124  }
125  else
126  {
127  prepareMatrixTag(_assembly, _var.number(), jvar_num);
128 
129  const std::vector<unsigned int> * multiplicities =
130  _drop_duplicate_points ? NULL : &_local_dirac_kernel_info.getPoints()[_current_elem].second;
131  unsigned int local_qp = 0;
132  Real multiplicity = 1.0;
133 
134  for (_qp = 0; _qp < _qrule->n_points(); _qp++)
135  {
136  _current_point = _physical_point[_qp];
137  if (isActiveAtPoint(_current_elem, _current_point))
138  {
139  if (!_drop_duplicate_points)
140  multiplicity = (*multiplicities)[local_qp++];
141 
142  for (_i = 0; _i < _test.size(); _i++)
143  for (_j = 0; _j < _phi.size(); _j++)
144  _local_ke(_i, _j) += multiplicity * computeQpOffDiagJacobian(jvar_num);
145  }
146  }
147 
148  accumulateTaggedLocalMatrix();
149  }
150 }
151 
152 template <typename T>
153 Real
155 {
156  return 0;
157 }
158 
159 template <typename T>
160 Real
162 {
163  return 0;
164 }
165 
166 // Explicitly instantiates the two versions of the DiracKernelTempl class
167 template class DiracKernelTempl<Real>;
168 template class DiracKernelTempl<RealVectorValue>;
VarFieldType
Definition: MooseTypes.h:634
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:284
T * get(const std::unique_ptr< T > &u)
The MooseUtils::get() specializations are used to support making forwards-compatible code changes fro...
Definition: MooseUtils.h:1147
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:154
virtual Real computeQpOffDiagJacobian(unsigned int jvar) override
This gets called by computeOffDiagJacobian() at each quadrature point.
Definition: DiracKernel.C:161
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:119
Real value(unsigned n, unsigned alpha, unsigned beta, Real x)
static InputParameters validParams()
VarKindType
Framework-wide stuff.
Definition: MooseTypes.h:627
This is a "smart" enum class intended to replace many of the shortcomings in the C++ enum type It sho...
Definition: MooseEnum.h:31
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:91
Interface for objects that need to get values of MooseVariables.
MooseVariableField< T > & mooseVariableField()
Return the MooseVariableField<T> 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:64
static InputParameters validParams()
Definition: DiracKernel.C:24