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 "PorousFlowBasicAdvection.h" 11 : 12 : registerMooseObject("PorousFlowApp", PorousFlowBasicAdvection); 13 : registerMooseObject("PorousFlowApp", ADPorousFlowBasicAdvection); 14 : 15 : template <bool is_ad> 16 : InputParameters 17 133 : PorousFlowBasicAdvectionTempl<is_ad>::validParams() 18 : { 19 : InputParameters params = GenericKernel<is_ad>::validParams(); 20 266 : params.addRequiredParam<UserObjectName>( 21 : "PorousFlowDictator", "The UserObject that holds the list of PorousFlow variable names."); 22 266 : params.addParam<unsigned int>("phase", 0, "Use the Darcy velocity of this fluid phase"); 23 133 : params.addClassDescription( 24 : "Advective flux of a Variable using the Darcy velocity of the fluid phase"); 25 133 : return params; 26 0 : } 27 : 28 : template <bool is_ad> 29 71 : PorousFlowBasicAdvectionTempl<is_ad>::PorousFlowBasicAdvectionTempl( 30 : const InputParameters & parameters) 31 : : GenericKernel<is_ad>(parameters), 32 71 : _dictator(this->template getUserObject<PorousFlowDictator>("PorousFlowDictator")), 33 142 : _ph(this->template getParam<unsigned int>("phase")), 34 142 : _darcy_velocity(this->template getGenericMaterialProperty<std::vector<RealVectorValue>, is_ad>( 35 : "PorousFlow_darcy_velocity_qp")), 36 71 : _ddarcy_velocity_dvar( 37 : is_ad ? nullptr 38 64 : : &this->template getMaterialProperty<std::vector<std::vector<RealVectorValue>>>( 39 : "dPorousFlow_darcy_velocity_qp_dvar")), 40 71 : _ddarcy_velocity_dgradvar(is_ad ? nullptr 41 : : &this->template getMaterialProperty< 42 64 : std::vector<std::vector<std::vector<RealVectorValue>>>>( 43 71 : "dPorousFlow_darcy_velocity_qp_dgradvar")) 44 : { 45 71 : if (_ph >= _dictator.numPhases()) 46 2 : paramError("phase", 47 : "The Dictator proclaims that the maximum phase index in this simulation is ", 48 2 : _dictator.numPhases() - 1, 49 : " whereas you have used ", 50 2 : _ph, 51 : ". Remember that indexing starts at 0. The Dictator is watching you, to " 52 : "ensure your wellbeing."); 53 69 : } 54 : 55 : template <bool is_ad> 56 : GenericReal<is_ad> 57 5904 : PorousFlowBasicAdvectionTempl<is_ad>::computeQpResidual() 58 : { 59 5904 : return -_grad_test[_i][_qp] * _darcy_velocity[_qp][_ph] * _u[_qp]; 60 : } 61 : 62 : template <bool is_ad> 63 : Real 64 5152 : PorousFlowBasicAdvectionTempl<is_ad>::computeQpJacobian() 65 : { 66 : if constexpr (!is_ad) 67 : { 68 5152 : const Real result = -_grad_test[_i][_qp] * _darcy_velocity[_qp][_ph] * _phi[_j][_qp]; 69 5152 : return result + computeQpOffDiagJacobian(_var.number()); 70 : } 71 0 : return 0.0; 72 : } 73 : 74 : template <bool is_ad> 75 : Real 76 5376 : PorousFlowBasicAdvectionTempl<is_ad>::computeQpOffDiagJacobian(unsigned int jvar) 77 : { 78 : if constexpr (!is_ad) 79 : { 80 5376 : if (_dictator.notPorousFlowVariable(jvar)) 81 : return 0.0; 82 : 83 224 : const unsigned pvar = _dictator.porousFlowVariableNum(jvar); 84 224 : Real result = 85 224 : -_grad_test[_i][_qp] * (*_ddarcy_velocity_dvar)[_qp][_ph][pvar] * _phi[_j][_qp] * _u[_qp]; 86 896 : for (unsigned j = 0; j < LIBMESH_DIM; ++j) 87 672 : result -= _grad_test[_i][_qp] * 88 672 : ((*_ddarcy_velocity_dgradvar)[_qp][_ph][j][pvar] * _grad_phi[_j][_qp](j)) * _u[_qp]; 89 : 90 : return result; 91 : } 92 : else 93 : { 94 : libmesh_ignore(jvar); 95 0 : return 0.0; 96 : } 97 : } 98 : 99 : template class PorousFlowBasicAdvectionTempl<false>; 100 : template class PorousFlowBasicAdvectionTempl<true>;