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 "WCNSFVFluxBCBase.h" 11 : #include "NS.h" 12 : 13 : InputParameters 14 1558 : WCNSFVFluxBCBase::validParams() 15 : { 16 1558 : InputParameters params = FVFluxBC::validParams(); 17 1558 : params += INSFVFlowBC::validParams(); 18 3116 : params.addParam<Real>("scaling_factor", 1, "To scale the mass flux"); 19 : 20 3116 : params.addParam<PostprocessorName>("velocity_pp", "Postprocessor with the inlet velocity norm"); 21 1558 : params.addParam<Point>( 22 : "direction", 23 1558 : Point(), 24 : "The direction of the flow at the boundary. This is mainly used for cases when an inlet " 25 : "angle needs to be defined with respect to the normal and when a boundary is defined on an " 26 : "internal face where the normal can point in both directions. Use positive mass flux and " 27 : "velocity magnitude if the flux aligns with this direction vector."); 28 1558 : params.addRequiredParam<MooseFunctorName>(NS::velocity_x, "The x-axis velocity"); 29 1558 : params.addParam<MooseFunctorName>(NS::velocity_y, "The y-axis velocity"); 30 1558 : params.addParam<MooseFunctorName>(NS::velocity_z, "The z-axis velocity"); 31 3116 : params.addParam<PostprocessorName>("mdot_pp", "Postprocessor with the inlet mass flow rate"); 32 3116 : params.addParam<PostprocessorName>("area_pp", "Inlet area as a postprocessor"); 33 1558 : params.addRequiredParam<MooseFunctorName>(NS::density, "Density functor"); 34 : 35 1558 : return params; 36 0 : } 37 : 38 930 : WCNSFVFluxBCBase::WCNSFVFluxBCBase(const InputParameters & params) 39 : : FVFluxBC(params), 40 : INSFVFlowBC(params), 41 930 : _scaling_factor(getParam<Real>("scaling_factor")), 42 2197 : _velocity_pp(isParamValid("velocity_pp") ? &getPostprocessorValue("velocity_pp") : nullptr), 43 2422 : _mdot_pp(isParamValid("mdot_pp") ? &getPostprocessorValue("mdot_pp") : nullptr), 44 2493 : _area_pp(isParamValid("area_pp") ? &getPostprocessorValue("area_pp") : nullptr), 45 930 : _rho(getFunctor<ADReal>(NS::density)), 46 1860 : _direction(getParam<Point>("direction")), 47 930 : _direction_specified_by_user(params.isParamSetByUser("direction")), 48 930 : _vel_x(getFunctor<ADReal>(NS::velocity_x)), 49 1860 : _vel_y(isParamValid(NS::velocity_y) ? &getFunctor<ADReal>(NS::velocity_y) : nullptr), 50 1860 : _vel_z(isParamValid(NS::velocity_z) ? &getFunctor<ADReal>(NS::velocity_z) : nullptr) 51 : { 52 930 : if (_direction_specified_by_user && !MooseUtils::absoluteFuzzyEqual(_direction.norm(), 1.0, 1e-6)) 53 8 : paramError("direction", "The direction should be a unit vector with a tolerance of 1e-6!"); 54 : 55 : // Density is often set as global parameters so it is not checked 56 922 : if (_mdot_pp && _velocity_pp) 57 4 : mooseWarning("If setting the mass flow rate directly, no need for inlet velocity"); 58 : 59 918 : if (_subproblem.mesh().dimension() >= 2 && !_vel_y) 60 0 : mooseError("In two or more dimensions, the y-component of the velocity must be supplied."); 61 918 : if (_subproblem.mesh().dimension() == 3 && !_vel_z) 62 0 : mooseError("In three dimensions, the z-component of the velocity must be supplied."); 63 918 : } 64 : 65 : // inflow is decided based on the sign of mdot or velocity postprocessors 66 : // depending on what is provided 67 : bool 68 26091 : WCNSFVFluxBCBase::isInflow() const 69 : { 70 26091 : if (_mdot_pp) 71 18189 : return *_mdot_pp >= 0; 72 7902 : else if (_velocity_pp) 73 7902 : return *_velocity_pp >= 0; 74 : 75 0 : mooseError("Either mdot_pp or velocity_pp need to be provided OR this function must be " 76 : "overridden in derived classes if other input parameter combinations are valid. " 77 : "Neither mdot_pp nor velocity_pp are provided."); 78 : return true; 79 : } 80 : 81 : ADRealVectorValue 82 2316 : WCNSFVFluxBCBase::varVelocity(const Moose::StateArg & state) const 83 : { 84 2316 : const auto boundary_face = singleSidedFaceArg(); 85 : 86 4632 : ADRealVectorValue v(_vel_x(boundary_face, state)); 87 2316 : if (_vel_y) 88 2316 : v(1) = (*_vel_y)(boundary_face, state); 89 2316 : if (_vel_z) 90 0 : v(2) = (*_vel_z)(boundary_face, state); 91 2316 : return v; 92 : } 93 : 94 : ADReal 95 31970 : WCNSFVFluxBCBase::inflowMassFlux(const Moose::StateArg & state) const 96 : { 97 31970 : checkForInternalDirection(); 98 31964 : if (_mdot_pp) 99 21432 : return *_mdot_pp / *_area_pp; 100 10532 : const ADRealVectorValue incoming_vector = !_direction_specified_by_user ? _normal : _direction; 101 10532 : const ADReal cos_angle = std::abs(incoming_vector * _normal); 102 21064 : return _rho(singleSidedFaceArg(), state) * (*_velocity_pp) * cos_angle; 103 : } 104 : 105 : ADReal 106 22774 : WCNSFVFluxBCBase::inflowSpeed(const Moose::StateArg & state) const 107 : { 108 22774 : checkForInternalDirection(); 109 22768 : const ADRealVectorValue incoming_vector = !_direction_specified_by_user ? _normal : _direction; 110 22768 : const ADReal cos_angle = std::abs(incoming_vector * _normal); 111 22768 : if (_mdot_pp) 112 46434 : return *_mdot_pp / (*_area_pp * _rho(singleSidedFaceArg(), state) * cos_angle); 113 : 114 7290 : return (*_velocity_pp) * cos_angle; 115 : } 116 : 117 : void 118 10705 : WCNSFVFluxBCBase::residualSetup() 119 : { 120 10705 : if (_area_pp) 121 7987 : if (MooseUtils::absoluteFuzzyEqual(*_area_pp, 0)) 122 0 : mooseError("Surface area is 0"); 123 10705 : FVFluxBC::residualSetup(); 124 10705 : } 125 : 126 : void 127 7258 : WCNSFVFluxBCBase::jacobianSetup() 128 : { 129 7258 : if (_area_pp) 130 5270 : if (MooseUtils::absoluteFuzzyEqual(*_area_pp, 0)) 131 0 : mooseError("Surface area is 0"); 132 7258 : FVFluxBC::jacobianSetup(); 133 7258 : }