https://mooseframework.inl.gov
ADRayKernel.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 "ADRayKernel.h"
11 
12 // Local includes
13 #include "RayTracingStudy.h"
14 
15 // MOOSE includes
16 #include "Assembly.h"
17 #include "NonlinearSystemBase.h"
18 #include "ADUtils.h"
19 
20 template <typename T>
23 {
24  auto params = IntegralRayKernelBase::validParams();
26 
27  params.template addRequiredParam<NonlinearVariableName>(
28  "variable", "The name of the variable that this ADRayKernel operates on");
29 
30  return params;
31 }
32 
33 template <typename T>
35  : IntegralRayKernelBase(params),
36  MooseVariableInterface<T>(this,
37  false,
38  "variable",
42  TaggingInterface(this),
43  _var(this->mooseVariableField()),
44  _test(_var.phi()),
45  _u(_var.adSln()),
46  _grad_u(_var.adGradSln()),
47  _phi(_assembly.phi(_var))
48 {
49  // We do not allow RZ/RSPHERICAL because in the context of these coord
50  // systems there is no way to represent a line source - we would end up
51  // with a plane/surface source or a volumetric source, respectively.
52  // This is also why we do not multiply by _coord[_qp] in any of the
53  // integrations that follow.
54  for (const auto & subdomain_id : _mesh.meshSubdomains())
55  if (_fe_problem.getCoordSystem(subdomain_id) != Moose::COORD_XYZ)
56  mooseError("Not valid on coordinate systems other than XYZ");
57 
59 
61 
62  if (!isImplicit())
63  mooseError("ADRayKernels do not currently support explicit solves.");
64 }
65 
66 template <typename T>
67 void
69 {
70  mooseAssert(_current_subdomain_id == _assembly.currentSubdomainID(), "Subdomain IDs not in sync");
71  mooseAssert(_fe_problem.currentlyComputingJacobian() || _fe_problem.currentlyComputingResidual(),
72  "Not computing residual or Jacobian");
73 
74  if (_fe_problem.currentlyComputingJacobian())
75  computeJacobian();
76  else if (_fe_problem.currentlyComputingResidual())
77  computeResidual();
78 }
79 
80 template <typename T>
81 void
83 {
84  prepareVectorTag(_assembly, _var.number());
85 
86  precalculateResidual();
87  for (_qp = 0; _qp < _JxW.size(); _qp++)
88  for (_i = 0; _i < _test.size(); _i++)
89  _local_re(_i) += raw_value(_JxW[_qp] * computeQpResidual());
90 
91  accumulateTaggedLocalResidual();
92 }
93 
94 template <typename T>
95 void
97 {
98  _subproblem.prepareShapes(_var.number(), _tid);
99 
100  for (auto & r : _residuals)
101  r = 0;
102  _residuals.resize(_test.size(), 0);
103 
104  precalculateResidual();
105  for (_qp = 0; _qp < _JxW.size(); _qp++)
106  for (_i = 0; _i < _test.size(); _i++)
107  _residuals[_i] += _JxW[_qp] * computeQpResidual();
108 
109  addJacobian(_assembly, _residuals, _var.dofIndices(), _var.scalingFactor());
110 }
111 
112 template class ADRayKernelTempl<Real>;
113 
114 // Not implementing this until there is a use case and tests for it!
115 // template class ADRayKernelTempl<RealVectorValue>;
VarFieldType
Base class for a RayKernel that integrates along a Ray segment.
SubProblem & _subproblem
virtual void haveADObjects(bool have_ad_objects)
VAR_SOLVER
Base class for an AD ray kernel that contributes to the residual and/or Jacobian. ...
Definition: ADRayKernel.h:21
FEProblemBase & _fe_problem
The FEProblemBase.
void onSegment() override final
Called on each segment of a Ray.
Definition: ADRayKernel.C:68
auto raw_value(const Eigen::Map< T > &in)
static InputParameters validParams()
Definition: ADRayKernel.C:22
MooseVariableField< T > & variable()
The MooseVariable this RayKernel contributes to.
Definition: ADRayKernel.h:43
ADRayKernelTempl(const InputParameters &params)
Definition: ADRayKernel.C:34
MooseMesh & _mesh
The MooseMesh.
Real value(unsigned n, unsigned alpha, unsigned beta, Real x)
void computeResidual()
Computes and contributes to the residual for a segment.
Definition: ADRayKernel.C:82
VarKindType
static InputParameters validParams()
void addMooseVariableDependency(MooseVariableFieldBase *var)
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
void mooseError(Args &&... args) const
Moose::CoordinateSystemType getCoordSystem(SubdomainID sid) const
VAR_FIELD_STANDARD
static InputParameters validParams()
VAR_FIELD_VECTOR
void computeJacobian()
Computes and contributes to the Jacobian for a segment.
Definition: ADRayKernel.C:96
const std::set< SubdomainID > & meshSubdomains() const