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 "RayKernel.h" 11 : 12 : // Local includes 13 : #include "RayTracingStudy.h" 14 : 15 : // MOOSE includes 16 : #include "Assembly.h" 17 : #include "NonlinearSystemBase.h" 18 : 19 : template <typename T> 20 : InputParameters 21 682 : RayKernelTempl<T>::validParams() 22 : { 23 682 : auto params = IntegralRayKernelBase::validParams(); 24 682 : params += TaggingInterface::validParams(); 25 : 26 1364 : params.template addRequiredParam<NonlinearVariableName>( 27 : "variable", "The name of the variable that this RayKernel operates on"); 28 : 29 682 : return params; 30 0 : } 31 : 32 : template <typename T> 33 368 : RayKernelTempl<T>::RayKernelTempl(const InputParameters & params) 34 : : IntegralRayKernelBase(params), 35 : MooseVariableInterface<T>(this, 36 : false, 37 : "variable", 38 : Moose::VarKindType::VAR_SOLVER, 39 : std::is_same<T, Real>::value ? Moose::VarFieldType::VAR_FIELD_STANDARD 40 : : Moose::VarFieldType::VAR_FIELD_VECTOR), 41 : TaggingInterface(this), 42 736 : _var(*this->mooseVariable()), 43 368 : _u(_is_implicit ? _var.sln() : _var.slnOld()), 44 368 : _grad_u(_is_implicit ? _var.gradSln() : _var.gradSlnOld()), 45 368 : _test(_var.phi()), 46 368 : _grad_test(_var.gradPhi()), 47 368 : _phi(_assembly.phi(_var)), 48 736 : _grad_phi(_assembly.gradPhi(_var)) 49 : { 50 : // We do not allow RZ/RSPHERICAL because in the context of these coord 51 : // systems there is no way to represent a line source - we would end up 52 : // with a plane/surface source or a volumetric source, respectively. 53 : // This is also why we do not multiply by _coord[_qp] in any of the 54 : // integrations that follow. 55 734 : for (const auto & subdomain_id : _mesh.meshSubdomains()) 56 368 : if (_fe_problem.getCoordSystem(subdomain_id) != Moose::COORD_XYZ) 57 2 : mooseError("Not valid on coordinate systems other than XYZ"); 58 : 59 366 : addMooseVariableDependency(&variable()); 60 366 : } 61 : 62 : template <typename T> 63 : void 64 68941 : RayKernelTempl<T>::onSegment() 65 : { 66 : mooseAssert(_current_subdomain_id == _assembly.currentSubdomainID(), "Subdomain IDs not in sync"); 67 : mooseAssert(_fe_problem.currentlyComputingJacobian() || _fe_problem.currentlyComputingResidual(), 68 : "Not computing residual or Jacobian"); 69 : 70 68941 : if (_fe_problem.currentlyComputingJacobian()) 71 8472 : computeJacobian(); 72 60469 : else if (_fe_problem.currentlyComputingResidual()) 73 60469 : computeResidual(); 74 68941 : } 75 : 76 : template <typename T> 77 : void 78 60469 : RayKernelTempl<T>::computeResidual() 79 : { 80 60469 : prepareVectorTag(_assembly, _var.number()); 81 : 82 60469 : precalculateResidual(); 83 348425 : for (_i = 0; _i < _test.size(); ++_i) 84 863868 : for (_qp = 0; _qp < _q_point.size(); ++_qp) 85 575912 : _local_re(_i) += _JxW[_qp] * computeQpResidual(); 86 : 87 60469 : accumulateTaggedLocalResidual(); 88 60469 : } 89 : 90 : template <typename T> 91 : void 92 8472 : RayKernelTempl<T>::computeJacobian() 93 : { 94 8472 : if (!isImplicit()) 95 : return; 96 : 97 8472 : _subproblem.prepareShapes(_var.number(), _tid); 98 : 99 8472 : precalculateJacobian(); 100 : 101 8472 : const auto & ce = _fe_problem.couplingEntries(_tid, _nl->number()); 102 18330 : for (const auto & it : ce) 103 : { 104 9858 : MooseVariableFEBase & ivariable = *(it.first); 105 9858 : MooseVariableFEBase & jvariable = *(it.second); 106 : 107 : const auto ivar = ivariable.number(); 108 9858 : if (ivar != _var.number() || !jvariable.activeOnSubdomain(_current_subdomain_id)) 109 924 : continue; 110 : 111 : // This error should be caught by the coupleable interface 112 : mooseAssert(jvariable.count() == 1, "ArrayMooseVariable objects are not coupleable"); 113 : 114 : const auto jvar = jvariable.number(); 115 : 116 8934 : prepareMatrixTag(_assembly, _var.number(), jvar); 117 8934 : if (_local_ke.m() != _test.size()) 118 : return; 119 : 120 8934 : if (ivar == jvar) 121 : { 122 8472 : precalculateJacobian(); 123 51000 : for (_i = 0; _i < _test.size(); _i++) 124 281760 : for (_j = 0; _j < _phi.size(); _j++) 125 717696 : for (_qp = 0; _qp < _JxW.size(); _qp++) 126 478464 : _local_ke(_i, _j) += _JxW[_qp] * computeQpJacobian(); 127 : } 128 : else 129 : { 130 462 : precalculateOffDiagJacobian(jvar); 131 2310 : for (_i = 0; _i < _test.size(); _i++) 132 9240 : for (_j = 0; _j < _phi.size(); _j++) 133 22176 : for (_qp = 0; _qp < _JxW.size(); _qp++) 134 14784 : _local_ke(_i, _j) += _JxW[_qp] * computeQpOffDiagJacobian(jvar); 135 : } 136 : 137 8934 : accumulateTaggedLocalMatrix(); 138 : } 139 : } 140 : 141 : template class RayKernelTempl<Real>; 142 : // Not implementing this until there is a use case and tests for it! 143 : // template class RayKernelTempl<RealVectorValue>;