Line data Source code
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> 21 : InputParameters 22 55 : ADRayKernelTempl<T>::validParams() 23 : { 24 55 : auto params = IntegralRayKernelBase::validParams(); 25 55 : params += TaggingInterface::validParams(); 26 : 27 110 : params.template addRequiredParam<NonlinearVariableName>( 28 : "variable", "The name of the variable that this ADRayKernel operates on"); 29 : 30 55 : return params; 31 0 : } 32 : 33 : template <typename T> 34 31 : ADRayKernelTempl<T>::ADRayKernelTempl(const InputParameters & params) 35 : : IntegralRayKernelBase(params), 36 : MooseVariableInterface<T>(this, 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 62 : _var(this->mooseVariableField()), 44 31 : _test(_var.phi()), 45 31 : _u(_var.adSln()), 46 31 : _grad_u(_var.adGradSln()), 47 93 : _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 60 : for (const auto & subdomain_id : _mesh.meshSubdomains()) 55 31 : if (_fe_problem.getCoordSystem(subdomain_id) != Moose::COORD_XYZ) 56 2 : mooseError("Not valid on coordinate systems other than XYZ"); 57 : 58 29 : _subproblem.haveADObjects(true); 59 : 60 29 : addMooseVariableDependency(&variable()); 61 : 62 29 : if (!isImplicit()) 63 2 : mooseError("ADRayKernels do not currently support explicit solves."); 64 27 : } 65 : 66 : template <typename T> 67 : void 68 11162 : ADRayKernelTempl<T>::onSegment() 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 11162 : if (_fe_problem.currentlyComputingJacobian()) 75 426 : computeJacobian(); 76 10736 : else if (_fe_problem.currentlyComputingResidual()) 77 10736 : computeResidual(); 78 11162 : } 79 : 80 : template <typename T> 81 : void 82 10736 : ADRayKernelTempl<T>::computeResidual() 83 : { 84 10736 : prepareVectorTag(_assembly, _var.number()); 85 : 86 10736 : precalculateResidual(); 87 31680 : for (_qp = 0; _qp < _JxW.size(); _qp++) 88 103136 : for (_i = 0; _i < _test.size(); _i++) 89 164384 : _local_re(_i) += raw_value(_JxW[_qp] * computeQpResidual()); 90 : 91 10736 : accumulateTaggedLocalResidual(); 92 10736 : } 93 : 94 : template <typename T> 95 : void 96 426 : ADRayKernelTempl<T>::computeJacobian() 97 : { 98 426 : _subproblem.prepareShapes(_var.number(), _tid); 99 : 100 1774 : for (auto & r : _residuals) 101 1348 : r = 0; 102 426 : _residuals.resize(_test.size(), 0); 103 : 104 426 : precalculateResidual(); 105 1182 : for (_qp = 0; _qp < _JxW.size(); _qp++) 106 3492 : for (_i = 0; _i < _test.size(); _i++) 107 5472 : _residuals[_i] += _JxW[_qp] * computeQpResidual(); 108 : 109 426 : addJacobian(_assembly, _residuals, _var.dofIndices(), _var.scalingFactor()); 110 426 : } 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>;