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 "RhieChowInterpolatorBase.h" 11 : #include "INSFVAttributes.h" 12 : #include "GatherRCDataElementThread.h" 13 : #include "GatherRCDataFaceThread.h" 14 : #include "SubProblem.h" 15 : #include "MooseMesh.h" 16 : #include "SystemBase.h" 17 : #include "NS.h" 18 : #include "Assembly.h" 19 : #include "INSFVVelocityVariable.h" 20 : #include "INSFVPressureVariable.h" 21 : #include "PiecewiseByBlockLambdaFunctor.h" 22 : #include "VectorCompositeFunctor.h" 23 : #include "FVElementalKernel.h" 24 : 25 : #include "libmesh/mesh_base.h" 26 : #include "libmesh/elem_range.h" 27 : #include "libmesh/parallel_algebra.h" 28 : #include "libmesh/remote_elem.h" 29 : #include "metaphysicl/dualsemidynamicsparsenumberarray.h" 30 : #include "metaphysicl/parallel_dualnumber.h" 31 : #include "metaphysicl/parallel_dynamic_std_array_wrapper.h" 32 : #include "metaphysicl/parallel_semidynamicsparsenumberarray.h" 33 : #include "timpi/parallel_sync.h" 34 : 35 : using namespace libMesh; 36 : 37 : InputParameters 38 16050 : RhieChowInterpolatorBase::validParams() 39 : { 40 16050 : auto params = RhieChowFaceFluxProvider::validParams(); 41 16050 : params += TaggingInterface::validParams(); 42 16050 : params += ADFunctorInterface::validParams(); 43 : 44 16050 : params.addClassDescription( 45 : "Computes the Rhie-Chow velocity based on gathered 'a' coefficient data."); 46 : 47 : // Avoid uninitialized residual objects 48 16050 : params.suppressParameter<bool>("force_preic"); 49 : 50 16050 : params.addRequiredParam<VariableName>(NS::pressure, "The pressure variable."); 51 32100 : params.addRequiredParam<VariableName>("u", "The x-component of velocity"); 52 32100 : params.addParam<VariableName>("v", "The y-component of velocity"); 53 32100 : params.addParam<VariableName>("w", "The z-component of velocity"); 54 : 55 32100 : MooseEnum velocity_interp_method("average rc", "rc"); 56 32100 : params.addParam<MooseEnum>( 57 : "velocity_interp_method", 58 : velocity_interp_method, 59 : "The interpolation to use for the velocity. Options are " 60 : "'average' and 'rc' which stands for Rhie-Chow. The default is Rhie-Chow."); 61 : 62 16050 : return params; 63 16050 : } 64 : 65 8029 : RhieChowInterpolatorBase::RhieChowInterpolatorBase(const InputParameters & params) 66 : : RhieChowFaceFluxProvider(params), 67 : TaggingInterface(this), 68 : ADFunctorInterface(this), 69 16058 : _moose_mesh(UserObject::_subproblem.mesh()), 70 8029 : _mesh(_moose_mesh.getMesh()), 71 8029 : _dim(blocksMaxDimension()), 72 8029 : _p(dynamic_cast<INSFVPressureVariable *>( 73 8029 : &UserObject::_subproblem.getVariable(0, getParam<VariableName>(NS::pressure)))), 74 8029 : _u(dynamic_cast<INSFVVelocityVariable *>( 75 16058 : &UserObject::_subproblem.getVariable(0, getParam<VariableName>("u")))), 76 23317 : _v(isParamValid("v") ? dynamic_cast<INSFVVelocityVariable *>( 77 29806 : &UserObject::_subproblem.getVariable(0, getParam<VariableName>("v"))) 78 : : nullptr), 79 16172 : _w(isParamValid("w") ? dynamic_cast<INSFVVelocityVariable *>( 80 8371 : &UserObject::_subproblem.getVariable(0, getParam<VariableName>("w"))) 81 : : nullptr), 82 8029 : _ps(libMesh::n_threads(), nullptr), 83 8029 : _us(libMesh::n_threads(), nullptr), 84 8029 : _vs(libMesh::n_threads(), nullptr), 85 8029 : _ws(libMesh::n_threads(), nullptr), 86 16058 : _displaced(dynamic_cast<DisplacedProblem *>(&(UserObject::_subproblem))) 87 : { 88 8029 : if (!_p) 89 0 : paramError(NS::pressure, "the pressure must be a INSFVPressureVariable."); 90 8029 : checkBlocks(*_p); 91 : 92 8027 : if (!_u) 93 0 : paramError("u", "the u velocity must be an INSFVVelocityVariable."); 94 8027 : checkBlocks(*_u); 95 8025 : _var_numbers.push_back(_u->number()); 96 : 97 8025 : if (_dim >= 2) 98 : { 99 7255 : if (!_v) 100 0 : mooseError("In two or more dimensions, the v velocity must be supplied and it must be an " 101 : "INSFVVelocityVariable."); 102 7255 : checkBlocks(*_v); 103 7255 : _var_numbers.push_back(_v->number()); 104 : } 105 : 106 8025 : if (_dim >= 3) 107 : { 108 114 : if (!_w) 109 0 : mooseError("In three-dimensions, the w velocity must be supplied and it must be an " 110 : "INSFVVelocityVariable."); 111 114 : checkBlocks(*_w); 112 114 : _var_numbers.push_back(_w->number()); 113 : } 114 : 115 8025 : fillContainer(NS::pressure, _ps); 116 8025 : fillContainer("u", _us); 117 : 118 8025 : if (_dim >= 2) 119 : { 120 7255 : fillContainer("v", _vs); 121 7255 : if (_v->faceInterpolationMethod() != _u->faceInterpolationMethod()) 122 0 : mooseError("x and y velocity component face interpolation methods do not match"); 123 : 124 7255 : if (_dim >= 3) 125 : { 126 114 : fillContainer("w", _ws); 127 114 : if (_w->faceInterpolationMethod() != _u->faceInterpolationMethod()) 128 0 : mooseError("x and z velocity component face interpolation methods do not match"); 129 : } 130 : } 131 : 132 8025 : if (&(UserObject::_subproblem) != &(TaggingInterface::_subproblem)) 133 0 : mooseError("Different subproblems in RhieChowInterpolatorBase!"); 134 : 135 8025 : const auto & velocity_interp_method = params.get<MooseEnum>("velocity_interp_method"); 136 8025 : if (velocity_interp_method == "average") 137 21 : _velocity_interp_method = Moose::FV::InterpMethod::Average; 138 8004 : else if (velocity_interp_method == "rc") 139 8004 : _velocity_interp_method = Moose::FV::InterpMethod::RhieChow; 140 8025 : } 141 : 142 : Real 143 26489 : RhieChowInterpolatorBase::getVolumetricFaceFlux(const Moose::FV::InterpMethod m, 144 : const FaceInfo & fi, 145 : const Moose::StateArg & time, 146 : const THREAD_ID tid, 147 : bool subtract_mesh_velocity) const 148 : { 149 26489 : return raw_value(this->getVelocity(m, fi, time, tid, subtract_mesh_velocity)) * fi.normal(); 150 : }