Loading [MathJax]/extensions/tex2jax.js
https://mooseframework.inl.gov
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Pages
ADNodalKernel.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 "ADNodalKernel.h"
11 #include "SubProblem.h"
12 #include "SystemBase.h"
13 #include "MooseVariableFE.h"
14 #include "Assembly.h"
15 
16 #include "metaphysicl/raw_type.h"
17 
20 {
21  auto params = NodalKernelBase::validParams();
23  return params;
24 }
25 
27  : NodalKernelBase(parameters), ADFunctorInterface(this), _u(_var.adDofValues())
28 {
29  if (getParam<std::vector<AuxVariableName>>("save_in").size())
30  paramError("save_in",
31  "ADNodalKernels do not support save_in. Please use the tagging system instead.");
32  if (getParam<std::vector<AuxVariableName>>("diag_save_in").size())
33  paramError(
34  "diag_save_in",
35  "ADNodalKernels do not support diag_save_in. Please use the tagging system instead.");
36 }
37 
38 void
40 {
41  if (_var.isNodalDefined())
42  {
43  const auto dof_idx = _var.nodalDofIndex();
44  _qp = 0;
47  std::array<Real, 1>{{res}},
48  std::array<dof_id_type, 1>{{dof_idx}},
50  }
51 }
52 
53 void
55 {
56  if (_var.isNodalDefined())
57  {
58  const auto dof_idx = _var.nodalDofIndex();
59  _qp = 0;
60  const auto res = computeQpResidual();
62  std::array<ADReal, 1>{{res}},
63  std::array<dof_id_type, 1>{{dof_idx}},
65  }
66 }
67 
68 void
69 ADNodalKernel::computeOffDiagJacobian(const unsigned int jvar)
70 {
71  if (jvar == _var.number())
73 }
unsigned int number() const
Get variable number coming from libMesh.
void addResiduals(Assembly &assembly, const Residuals &residuals, const Indices &dof_indices, Real scaling_factor)
Add the provided incoming residuals corresponding to the provided dof indices.
static InputParameters validParams()
auto raw_value(const Eigen::Map< T > &in)
Definition: EigenADReal.h:73
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
MooseVariable & _var
variable this works on
An interface for accessing Moose::Functors for systems that care about automatic differentiation, e.g.
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.
virtual ADReal computeQpResidual()=0
The user can override this function to compute the residual at a node.
void computeOffDiagJacobian(unsigned int jvar) override final
This method simply routes to computeJacobian whenever jvar == _var.number() since global AD computes ...
Definition: ADNodalKernel.C:69
const T & getParam(const std::string &name) const
Retrieve a parameter for the object.
void paramError(const std::string &param, Args... args) const
Emits an error prefixed with the file and line number of the given param (from the input file) along ...
Assembly & _assembly
Reference to this Kernel&#39;s assembly object.
static InputParameters validParams()
Class constructor.
Definition: ADNodalKernel.C:19
static InputParameters validParams()
Class constructor.
Base class for creating new types of nodal kernels.
virtual bool isNodalDefined() const override
Is this variable defined at nodes.
const dof_id_type & nodalDofIndex() const override
ADNodalKernel(const InputParameters &parameters)
Definition: ADNodalKernel.C:26
void computeJacobian() override
Compute the Jacobian at one node.
Definition: ADNodalKernel.C:54
unsigned int _qp
Quadrature point index.
void scalingFactor(const std::vector< Real > &factor)
Set the scaling factor for this variable.
void computeResidual() override
Compute the residual at the current node.
Definition: ADNodalKernel.C:39