https://mooseframework.inl.gov
Loading...
Searching...
No Matches
ADKernelGrad.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 "ADKernelGrad.h"
11#include "MathUtils.h"
12#include "Assembly.h"
13#include "SystemBase.h"
14#include "ADUtils.h"
15
16// libmesh includes
17#include "libmesh/threads.h"
18
19template <typename T>
25
26template <typename T>
28 : ADKernelTempl<T>(parameters)
29{
30}
31
32template <typename T>
33void
35{
36 prepareVectorTag(_assembly, _var.number());
37
38 precalculateResidual();
39 const unsigned int n_test = _grad_test.size();
40 std::vector<Real> residuals(n_test);
41
42 if (_use_displaced_mesh)
43 for (_qp = 0; _qp < _qrule->n_points(); _qp++)
44 {
45 const auto value = precomputeQpResidual() * _ad_JxW[_qp] * _ad_coord[_qp];
46 for (_i = 0; _i < n_test; _i++) // target for auto vectorization
47 residuals[_i] += raw_value(MathUtils::dotProduct(value, _grad_test[_i][_qp]));
48 }
49 else
50 for (_qp = 0; _qp < _qrule->n_points(); _qp++)
51 {
52 const auto value = precomputeQpResidual() * _JxW[_qp] * _coord[_qp];
53 for (_i = 0; _i < n_test; _i++) // target for auto vectorization
54 residuals[_i] += raw_value(MathUtils::dotProduct(value, _regular_grad_test[_i][_qp]));
55 }
56
57 this->addResiduals(_assembly, residuals, _var.dofIndices(), _var.scalingFactor());
58
59 if (_has_save_in)
60 for (unsigned int i = 0; i < _save_in.size(); i++)
61 _save_in[i]->sys().solution().add_vector(residuals.data(), _save_in[i]->dofIndices());
62}
63
64template <typename T>
65void
67{
68 if (_residuals.size() != _grad_test.size())
69 _residuals.resize(_grad_test.size(), 0);
70 for (auto & r : _residuals)
71 r = 0;
72
73 precalculateResidual();
74 if (_use_displaced_mesh)
75 for (_qp = 0; _qp < _qrule->n_points(); _qp++)
76 {
77 const auto value = precomputeQpResidual() * _ad_JxW[_qp] * _ad_coord[_qp];
78 for (_i = 0; _i < _grad_test.size(); _i++)
79 _residuals[_i] += MathUtils::dotProduct(value, _grad_test[_i][_qp]);
80 }
81 else
82 for (_qp = 0; _qp < _qrule->n_points(); _qp++)
83 {
84 const auto value = precomputeQpResidual() * _JxW[_qp] * _coord[_qp];
85 for (_i = 0; _i < _grad_test.size(); _i++)
86 _residuals[_i] += MathUtils::dotProduct(value, _regular_grad_test[_i][_qp]);
87 }
88}
89
90template <typename T>
91void
93{
94 computeResidualsForJacobian();
95 this->addResidualsAndJacobian(_assembly, _residuals, _var.dofIndices(), _var.scalingFactor());
96}
97
98template <typename T>
101{
102 mooseError("Override precomputeQpResidual() in your ADKernelGrad derived class!");
103}
104
105template class ADKernelGradTempl<Real>;
DualNumber< Real, DNDerivativeType, true > ADReal
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application.
Definition MooseError.h:311
virtual ADReal computeQpResidual() override final
Compute this Kernel's contribution to the residual at the current quadrature point.
void computeResidual() override
Compute this object's contribution to the residual.
void computeResidualsForJacobian() override
compute the _residuals member for filling the Jacobian.
void computeResidualAndJacobian() override
Compute this object's contribution to the residual and Jacobian simultaneously.
ADKernelGradTempl(const InputParameters &parameters)
static InputParameters validParams()
static InputParameters validParams()
Definition ADKernel.C:24
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system.
libMesh::CompareTypes< T, T2 >::supertype dotProduct(const W< T > &a, const W2< T2 > &b)
Definition MathUtils.h:201