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 "LinearFVScalarAdvection.h" 11 : #include "MooseLinearVariableFV.h" 12 : #include "NSFVUtils.h" 13 : #include "NS.h" 14 : 15 : registerMooseObject("NavierStokesApp", LinearFVScalarAdvection); 16 : 17 : InputParameters 18 441 : LinearFVScalarAdvection::validParams() 19 : { 20 441 : InputParameters params = LinearFVFluxKernel::validParams(); 21 441 : params.addClassDescription("Represents the matrix and right hand side contributions of an " 22 : "advection term for a passive scalar."); 23 882 : params.addRequiredParam<UserObjectName>( 24 : "rhie_chow_user_object", 25 : "The rhie-chow user-object which is used to determine the face velocity."); 26 441 : params += Moose::FV::advectedInterpolationParameter(); 27 882 : params.addParam<MooseFunctorName>("u_slip", "The slip-velocity in the x direction."); 28 882 : params.addParam<MooseFunctorName>("v_slip", "The slip-velocity in the y direction."); 29 882 : params.addParam<MooseFunctorName>("w_slip", "The slip-velocity in the z direction."); 30 441 : return params; 31 0 : } 32 : 33 239 : LinearFVScalarAdvection::LinearFVScalarAdvection(const InputParameters & params) 34 : : LinearFVFluxKernel(params), 35 239 : _mass_flux_provider(getUserObject<RhieChowMassFlux>("rhie_chow_user_object")), 36 239 : _advected_interp_coeffs(std::make_pair<Real, Real>(0, 0)), 37 239 : _volumetric_face_flux(0.0), 38 596 : _u_slip(isParamValid("u_slip") ? &getFunctor<ADReal>("u_slip") : nullptr), 39 596 : _v_slip(isParamValid("v_slip") ? &getFunctor<ADReal>("v_slip") : nullptr), 40 478 : _w_slip(isParamValid("w_slip") ? &getFunctor<ADReal>("w_slip") : nullptr), 41 717 : _add_slip_model(isParamValid("u_slip") ? true : false) 42 : { 43 239 : Moose::FV::setInterpolationMethod(*this, _advected_interp_method, "advected_interp_method"); 44 239 : } 45 : 46 : Real 47 4929114 : LinearFVScalarAdvection::computeElemMatrixContribution() 48 : { 49 4929114 : return _advected_interp_coeffs.first * _volumetric_face_flux * _current_face_area; 50 : } 51 : 52 : Real 53 4929114 : LinearFVScalarAdvection::computeNeighborMatrixContribution() 54 : { 55 4929114 : return _advected_interp_coeffs.second * _volumetric_face_flux * _current_face_area; 56 : } 57 : 58 : Real 59 4929114 : LinearFVScalarAdvection::computeElemRightHandSideContribution() 60 : { 61 4929114 : return 0.0; 62 : } 63 : 64 : Real 65 4929114 : LinearFVScalarAdvection::computeNeighborRightHandSideContribution() 66 : { 67 4929114 : return 0.0; 68 : } 69 : 70 : Real 71 699084 : LinearFVScalarAdvection::computeBoundaryMatrixContribution(const LinearFVBoundaryCondition & bc) 72 : { 73 : const auto * const adv_bc = static_cast<const LinearFVAdvectionDiffusionBC *>(&bc); 74 : mooseAssert(adv_bc, "This should be a valid BC!"); 75 : 76 699084 : const auto boundary_value_matrix_contrib = adv_bc->computeBoundaryValueMatrixContribution(); 77 : 78 : // We support internal boundaries too so we have to make sure the normal points always outward 79 699084 : const auto factor = (_current_face_type == FaceInfo::VarFaceNeighbors::ELEM) ? 1.0 : -1.0; 80 : 81 699084 : return boundary_value_matrix_contrib * factor * _volumetric_face_flux * _current_face_area; 82 : } 83 : 84 : Real 85 699084 : LinearFVScalarAdvection::computeBoundaryRHSContribution(const LinearFVBoundaryCondition & bc) 86 : { 87 : const auto * const adv_bc = static_cast<const LinearFVAdvectionDiffusionBC *>(&bc); 88 : mooseAssert(adv_bc, "This should be a valid BC!"); 89 : 90 : // We support internal boundaries too so we have to make sure the normal points always outward 91 699084 : const auto factor = (_current_face_type == FaceInfo::VarFaceNeighbors::ELEM ? 1.0 : -1.0); 92 : 93 699084 : const auto boundary_value_rhs_contrib = adv_bc->computeBoundaryValueRHSContribution(); 94 699084 : return -boundary_value_rhs_contrib * factor * _volumetric_face_flux * _current_face_area; 95 : } 96 : 97 : void 98 6326382 : LinearFVScalarAdvection::setupFaceData(const FaceInfo * face_info) 99 : { 100 6326382 : LinearFVFluxKernel::setupFaceData(face_info); 101 : 102 : // Caching the velocity on the face which will be reused in the advection term's matrix and right 103 : // hand side contributions 104 6326382 : _volumetric_face_flux = _mass_flux_provider.getVolumetricFaceFlux(*face_info); 105 : 106 : // Adjust volumetric face flux using the slip velocity 107 : // TODO: add boundaries 108 8906718 : if (_u_slip && face_info->neighborPtr()) 109 : { 110 2580336 : const auto state = determineState(); 111 : Moose::FaceArg face_arg; 112 : // TODO Add boundary treatment to be able select two-term expansion if desired 113 2580336 : face_arg = Moose::FaceArg{face_info, 114 : Moose::FV::LimiterType::CentralDifference, 115 : true, 116 : false, 117 : face_info->neighborPtr(), 118 : nullptr}; 119 : 120 : RealVectorValue velocity_slip_vel_vec; 121 : if (_u_slip) 122 2580336 : velocity_slip_vel_vec(0) = (*_u_slip)(face_arg, state).value(); 123 2580336 : if (_v_slip) 124 2580336 : velocity_slip_vel_vec(1) = (*_v_slip)(face_arg, state).value(); 125 2580336 : if (_w_slip) 126 0 : velocity_slip_vel_vec(2) = (*_w_slip)(face_arg, state).value(); 127 2580336 : _volumetric_face_flux += velocity_slip_vel_vec * face_info->normal(); 128 : } 129 : 130 : // Caching the interpolation coefficients so they will be reused for the matrix and right hand 131 : // side terms 132 : _advected_interp_coeffs = 133 6326382 : interpCoeffs(_advected_interp_method, *_current_face_info, true, _volumetric_face_flux); 134 6326382 : }