https://mooseframework.inl.gov
Loading...
Searching...
No Matches
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
20template <typename T>
23{
26
27 params.template addRequiredParam<NonlinearVariableName>(
28 "variable", "The name of the variable that this ADRayKernel operates on");
29
30 return params;
31}
32
33template <typename T>
35 : IntegralRayKernelBase(params),
37 false,
38 "variable",
39 Moose::VarKindType::VAR_SOLVER,
40 std::is_same<T, Real>::value ? Moose::VarFieldType::VAR_FIELD_STANDARD
41 : Moose::VarFieldType::VAR_FIELD_VECTOR),
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
66template <typename T>
67void
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
80template <typename T>
81void
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
94template <typename T>
95void
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
112template class ADRayKernelTempl<Real>;
113
114// Not implementing this until there is a use case and tests for it!
115// template class ADRayKernelTempl<RealVectorValue>;
const double T
Base class for an AD ray kernel that contributes to the residual and/or Jacobian.
Definition ADRayKernel.h:34
static InputParameters validParams()
Definition ADRayKernel.C:22
void onSegment() override final
Called on each segment of a Ray.
Definition ADRayKernel.C:68
ADRayKernelTempl(const InputParameters &params)
Definition ADRayKernel.C:34
void computeJacobian()
Computes and contributes to the Jacobian for a segment.
Definition ADRayKernel.C:96
void computeResidual()
Computes and contributes to the residual for a segment.
Definition ADRayKernel.C:82
MooseVariableField< T > & variable()
The MooseVariable this RayKernel contributes to.
Definition ADRayKernel.h:43
Base class for a RayKernel that integrates along a Ray segment.
static InputParameters validParams()
void mooseError(Args &&... args) const
const std::set< SubdomainID > & meshSubdomains() const
void addMooseVariableDependency(MooseVariableFieldBase *var)
FEProblemBase & _fe_problem
The FEProblemBase.
MooseMesh & _mesh
The MooseMesh.
virtual void haveADObjects(bool have_ad_objects)
Moose::CoordinateSystemType getCoordSystem(SubdomainID sid) const
SubProblem & _subproblem
static InputParameters validParams()