https://mooseframework.inl.gov
Loading...
Searching...
No Matches
ADDiracKernel.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 "ADDiracKernel.h"
11#include "DiracKernelInfo.h"
12#include "Assembly.h"
13#include "SystemBase.h"
14#include "Problem.h"
15#include "MooseMesh.h"
16
17#include "libmesh/libmesh_common.h"
18#include "libmesh/quadrature.h"
19
22{
25 params.registerBase("DiracKernel");
26 return params;
27}
28
30 : DiracKernelBase(parameters),
31 MooseVariableInterface<Real>(this,
32 false,
33 "variable",
34 Moose::VarKindType::VAR_SOLVER,
35 Moose::VarFieldType::VAR_FIELD_STANDARD),
37 _var(this->mooseVariableField()),
38 _phi(_assembly.phi(_var)),
39 _test(_var.phi()),
40 _u(_var.adSln()),
41 _grad_u(_var.adGradSln())
42{
44
46
47 // Stateful material properties are not allowed on DiracKernels
49}
50
51void
56
57void
59{
61
63
64 for (const auto i : index_range(_ad_residuals))
65 _local_re(i) = raw_value(_ad_residuals[i]);
66
68}
69
70void
75
76void
85
86void
92
93void
99
100void
102{
103 _ad_residuals.resize(_test.size());
104 std::fill(_ad_residuals.begin(), _ad_residuals.end(), 0);
105
107
108 const std::vector<Real> * point_values =
110 unsigned int local_qp = 0;
111 Real point_value = 1.0;
112
113 for (_qp = 0; _qp < _qrule->n_points(); _qp++)
114 {
117 {
119 point_value = (*point_values)[local_qp++];
120
121 for (_i = 0; _i < _test.size(); _i++)
122 _ad_residuals[_i] += point_value * computeQpResidual();
123 }
124 }
125}
ADDiracKernel(const InputParameters &parameters)
virtual void computeResidual() override
Compute this object's contribution to the residual.
static InputParameters validParams()
const ADTemplateVariableTestValue< Real > & _test
Values of test functions at QPs.
virtual ADReal computeQpResidual()=0
Computes the residual contribution at the current quadrature point.
void computeADResiduals()
Computes the AD residuals for the current element.
virtual void jacobianSetup() override
Gets called just before the Jacobian is computed and before this object is asked to do its job.
void computeFullJacobian()
Computes the full Jacobian for the current element.
virtual void computeResidualAndJacobian() override
Compute this object's contribution to the residual and Jacobian simultaneously.
const Elem * _last_jacobian_elem
The element corresponding to previous Jacobian calculation.
virtual void computeJacobian() override
Compute this object's contribution to the diagonal Jacobian entries.
std::vector< ADReal > _ad_residuals
AD residuals for the current element.
MooseVariableField< Real > & _var
Variable this kernel acts on.
virtual void computeOffDiagJacobian(unsigned int jvar) override
Computes the off-diagonal Jacobian for variable jvar.
An interface for accessing Moose::Functors for systems that care about automatic differentiation,...
static InputParameters validParams()
DiracKernelBase is the base class for all DiracKernel type classes.
unsigned int _i
i-th, j-th index for enumerating shape and test functions
const Elem *const & _current_elem
Current element.
unsigned int _qp
Quadrature point index.
bool isActiveAtPoint(const Elem *elem, const Point &p)
Whether or not this DiracKernel has something to distribute at this Point.
const QBase *const & _qrule
Quadrature rule.
const MooseArray< Point > & _physical_point
Physical points.
const bool _drop_duplicate_points
drop duplicate points or consider them in residual and Jacobian
Point _current_point
The current point.
DiracKernelInfo _local_dirac_kernel_info
Place for storing Point/Elem information only for this DiracKernel.
static InputParameters validParams()
MultiPointMap & getPoints()
Returns a writeable reference to the _points container.
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system.
void registerBase(const std::string &value)
This method must be called from every base "Moose System" to create linkage with the Action System.
void statefulPropertiesAllowed(bool)
Derived classes can declare whether or not they work with stateful material properties.
virtual const std::vector< dof_id_type > & dofIndices() const
Get local DoF indices.
void scalingFactor(const std::vector< Real > &factor)
Set the scaling factor for this variable.
unsigned int number() const
Get variable number coming from libMesh.
void addMooseVariableDependency(MooseVariableFieldBase *var)
Call this function to add the passed in MooseVariableFieldBase as a variable that this object depends...
Interface for objects that need to get values of MooseVariables.
MooseVariableField< Real > & mooseVariableField()
Return the MooseVariableField object that this interface acts on.
Assembly & _assembly
Reference to this Kernel's assembly object.
SubProblem & _subproblem
Reference to this kernel's SubProblem.
virtual void precalculateResidual()
virtual void haveADObjects(bool have_ad_objects)
Method for setting whether we have any ad objects.
Definition SubProblem.h:775
void addJacobian(Assembly &assembly, const Residuals &residuals, const Indices &dof_indices, Real scaling_factor)
Add the provided residual derivatives into the Jacobian for the provided dof indices.
void accumulateTaggedLocalResidual()
Local residual blocks will be appended by adding the current local kernel residual.
void addResidualsAndJacobian(Assembly &assembly, const Residuals &residuals, const Indices &dof_indices, Real scaling_factor)
Add the provided incoming residuals and derivatives for the Jacobian, corresponding to the provided d...
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.
MOOSE now contains C++17 code, so give a reasonable error message stating what the user can do to add...