https://mooseframework.inl.gov
Loading...
Searching...
No Matches
KernelValue.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#include "KernelValue.h"
11#include "Assembly.h"
12#include "SystemBase.h"
13#include "libmesh/quadrature.h"
14
20
21KernelValue::KernelValue(const InputParameters & parameters) : Kernel(parameters) {}
22
23void
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 for (const auto & var : _save_in)
40 var->sys().solution().add_vector(_local_re, var->dofIndices());
41}
42
43void
45{
47
48 const unsigned int n_test = _test.size();
49 for (_qp = 0; _qp < _qrule->n_points(); _qp++)
50 for (_j = 0; _j < _phi.size(); _j++)
51 {
53 for (_i = 0; _i < n_test; _i++) // target for auto vectorization
54 _local_ke(_i, _j) += value * _test[_i][_qp];
55 }
56
58
60 {
61 unsigned int rows = _local_ke.m();
62 DenseVector<Number> diag(rows);
63 for (unsigned int i = 0; i < rows; i++) // target for auto vectorization
64 diag(i) = _local_ke(i, i);
65
66 for (const auto & var : _diag_save_in)
67 var->sys().solution().add_vector(diag, var->dofIndices());
68 }
69}
70
71void
72KernelValue::computeOffDiagJacobian(const unsigned int jvar_num)
73{
74 const auto & jvar = getVariable(jvar_num);
75
76 if (jvar_num == _var.number())
78 else
79 {
81 // This (undisplaced) jvar could potentially yield the wrong phi size if this object is acting
82 // on the displaced mesh
83 auto phi_size = jvar.dofIndices().size();
84
85 for (_j = 0; _j < phi_size; _j++)
86 for (_qp = 0; _qp < _qrule->n_points(); _qp++)
87 for (_i = 0; _i < _test.size(); _i++)
90 }
91}
92
93Real
95{
96 mooseError("Override precomputeQpResidual() in your KernelValue derived class!");
97}
98
99Real
101{
102 return 0.0;
103}
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application.
Definition MooseError.h:311
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system.
std::vector< MooseVariableFEBase * > _save_in
Definition KernelBase.h:65
bool _has_diag_save_in
The aux variables to save the diagonal Jacobian contributions to.
Definition KernelBase.h:69
const MooseArray< Real > & _coord
The scaling factor to convert from cartesian to another coordinate system (e.g rz,...
Definition KernelBase.h:55
unsigned int _qp
The current quadrature point index.
Definition KernelBase.h:43
bool _has_save_in
The aux variables to save the residual contributions to.
Definition KernelBase.h:64
const MooseArray< Real > & _JxW
The current quadrature point weight value.
Definition KernelBase.h:52
unsigned int _j
current index for the shape function
Definition KernelBase.h:61
std::vector< MooseVariableFEBase * > _diag_save_in
Definition KernelBase.h:70
unsigned int _i
current index for the test function
Definition KernelBase.h:58
const QBase *const & _qrule
active quadrature rule
Definition KernelBase.h:49
virtual Real computeQpResidual() final
Compute this Kernel's contribution to the residual at the current quadrature point.
Definition KernelValue.C:94
static InputParameters validParams()
Definition KernelValue.C:16
virtual void computeResidual() override
Compute this Kernel's contribution to the residual.
Definition KernelValue.C:24
virtual void computeOffDiagJacobian(unsigned int jvar) override
Computes d-residual / d-jvar... storing the result in Ke.
Definition KernelValue.C:72
KernelValue(const InputParameters &parameters)
Factory constructor initializes all internal references needed for residual computation.
Definition KernelValue.C:21
virtual void computeJacobian() override
Compute this Kernel's contribution to the diagonal Jacobian entries.
Definition KernelValue.C:44
virtual Real precomputeQpResidual()=0
Called before forming the residual for an element.
virtual Real precomputeQpJacobian()
Called before forming the jacobian for an element.
MooseVariable & _var
This is a regular kernel so we cast to a regular MooseVariable.
Definition Kernel.h:72
const VariablePhiValue & _phi
the current shape functions
Definition Kernel.h:81
virtual Real computeQpOffDiagJacobian(unsigned int)
For coupling standard variables.
Definition Kernel.h:56
const VariableTestValue & _test
the current test function
Definition Kernel.h:75
static InputParameters validParams()
Definition Kernel.C:24
unsigned int number() const
Get variable number coming from libMesh.
virtual const OutputTools< Real >::VariableValue & value()
The value of the variable this object is operating on.
Assembly & _assembly
Reference to this Kernel's assembly object.
const MooseVariableFieldBase & getVariable(unsigned int jvar_num) const
Retrieve the variable object from our system associated with jvar_num.
DenseMatrix< Number > _local_ke
Holds local Jacobian entries as they are accumulated by this Kernel.
void accumulateTaggedLocalMatrix()
Local Jacobian blocks will be appended by adding the current local kernel Jacobian.
void prepareMatrixTag(Assembly &assembly, unsigned int ivar, unsigned int jvar)
Prepare data for computing element jacobian according to the active tags.
void accumulateTaggedLocalResidual()
Local residual blocks will be appended by adding the current local kernel residual.
void prepareVectorTag(Assembly &assembly, unsigned int ivar)
Prepare data for computing element residual according to active tags.
DenseVector< Number > _local_re
Holds local residual entries as they are accumulated by this Kernel.
unsigned int m() const