www.mooseframework.org
KernelValue.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 #include "KernelValue.h"
11 #include "Assembly.h"
12 #include "SystemBase.h"
13 #include "libmesh/quadrature.h"
14 
17 {
18  return Kernel::validParams();
19 }
20 
21 KernelValue::KernelValue(const InputParameters & parameters) : Kernel(parameters) {}
22 
23 void
25 {
27 
28  const unsigned int n_test = _test.size();
29  for (_qp = 0; _qp < _qrule->n_points(); _qp++)
30  {
32  for (_i = 0; _i < n_test; _i++) // target for auto vectorization
33  _local_re(_i) += value * _test[_i][_qp];
34  }
35 
37 
38  if (_has_save_in)
39  {
40  Threads::spin_mutex::scoped_lock lock(Threads::spin_mtx);
41  for (const auto & var : _save_in)
42  var->sys().solution().add_vector(_local_re, var->dofIndices());
43  }
44 }
45 
46 void
48 {
50 
51  const unsigned int n_test = _test.size();
52  for (_qp = 0; _qp < _qrule->n_points(); _qp++)
53  for (_j = 0; _j < _phi.size(); _j++)
54  {
56  for (_i = 0; _i < n_test; _i++) // target for auto vectorization
57  _local_ke(_i, _j) += value * _test[_i][_qp];
58  }
59 
61 
63  {
64  unsigned int rows = _local_ke.m();
65  DenseVector<Number> diag(rows);
66  for (unsigned int i = 0; i < rows; i++) // target for auto vectorization
67  diag(i) = _local_ke(i, i);
68 
69  Threads::spin_mutex::scoped_lock lock(Threads::spin_mtx);
70  for (const auto & var : _diag_save_in)
71  var->sys().solution().add_vector(diag, var->dofIndices());
72  }
73 }
74 
75 void
76 KernelValue::computeOffDiagJacobian(const unsigned int jvar_num)
77 {
78  const auto & jvar = getVariable(jvar_num);
79 
80  if (jvar_num == _var.number())
82  else
83  {
84  prepareMatrixTag(_assembly, _var.number(), jvar_num);
85  // This (undisplaced) jvar could potentially yield the wrong phi size if this object is acting
86  // on the displaced mesh
87  auto phi_size = jvar.dofIndices().size();
88 
89  for (_j = 0; _j < phi_size; _j++)
90  for (_qp = 0; _qp < _qrule->n_points(); _qp++)
91  for (_i = 0; _i < _test.size(); _i++)
94  }
95 }
96 
97 Real
99 {
100  mooseError("Override precomputeQpResidual() in your KernelValue derived class!");
101 }
102 
103 Real
105 {
106  return 0.0;
107 }
static InputParameters validParams()
Definition: Kernel.C:23
void accumulateTaggedLocalResidual()
Local residual blocks will be appended by adding the current local kernel residual.
MooseVariable & _var
This is a regular kernel so we cast to a regular MooseVariable.
Definition: Kernel.h:72
std::vector< MooseVariableFEBase * > _save_in
Definition: KernelBase.h:64
const MooseArray< Real > & _JxW
The current quadrature point weight value.
Definition: KernelBase.h:51
unsigned int number() const
Get variable number coming from libMesh.
virtual Real computeQpOffDiagJacobian(unsigned int)
For coupling standard variables.
Definition: Kernel.h:56
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
unsigned int m() const
virtual void computeOffDiagJacobian(unsigned int jvar) override
Computes d-residual / d-jvar... storing the result in Ke.
Definition: KernelValue.C:76
bool _has_diag_save_in
The aux variables to save the diagonal Jacobian contributions to.
Definition: KernelBase.h:68
DenseMatrix< Number > _local_ke
Holds local Jacobian entries as they are accumulated by this Kernel.
const MooseVariableFieldBase & getVariable(unsigned int jvar_num) const
Retrieve the variable object from our system associated with jvar_num.
unsigned int size() const
The number of elements that can currently be stored in the array.
Definition: MooseArray.h:256
const VariableTestValue & _test
the current test function
Definition: Kernel.h:75
KernelValue(const InputParameters &parameters)
Factory constructor initializes all internal references needed for residual computation.
Definition: KernelValue.C:21
std::vector< MooseVariableFEBase * > _diag_save_in
Definition: KernelBase.h:69
const QBase *const & _qrule
active quadrature rule
Definition: KernelBase.h:48
bool _has_save_in
The aux variables to save the residual contributions to.
Definition: KernelBase.h:63
unsigned int _i
current index for the test function
Definition: KernelBase.h:57
virtual const OutputTools< Real >::VariableValue & value()
The value of the variable this object is operating on.
void accumulateTaggedLocalMatrix()
Local Jacobian blocks will be appended by adding the current local kernel Jacobian.
virtual void computeJacobian() override
Compute this Kernel&#39;s contribution to the diagonal Jacobian entries.
Definition: KernelValue.C:47
virtual Real precomputeQpJacobian()
Called before forming the jacobian for an element.
Definition: KernelValue.C:104
const MooseArray< Real > & _coord
The scaling factor to convert from cartesian to another coordinate system (e.g rz, spherical, etc.)
Definition: KernelBase.h:54
Assembly & _assembly
Reference to this Kernel&#39;s assembly object.
unsigned int _j
current index for the shape function
Definition: KernelBase.h:60
virtual void computeResidual() override
Compute this Kernel&#39;s contribution to the residual.
Definition: KernelValue.C:24
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
DenseVector< Number > _local_re
Holds local residual entries as they are accumulated by this Kernel.
Definition: Kernel.h:15
void mooseError(Args &&... args) const
Emits an error prefixed with object name and type.
virtual Real computeQpResidual() final
Compute this Kernel&#39;s contribution to the residual at the current quadrature point.
Definition: KernelValue.C:98
void prepareVectorTag(Assembly &assembly, unsigned int ivar)
Prepare data for computing element residual according to active tags.
void prepareMatrixTag(Assembly &assembly, unsigned int ivar, unsigned int jvar)
Prepare data for computing element jacobian according to the active tags.
virtual Real precomputeQpResidual()=0
Called before forming the residual for an element.
const VariablePhiValue & _phi
the current shape functions
Definition: Kernel.h:81
static InputParameters validParams()
Definition: KernelValue.C:16
unsigned int _qp
The current quadrature point index.
Definition: KernelBase.h:42