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 "WCNSFVScalarTransportPhysicsBase.h" 11 : #include "WCNSFVCoupledAdvectionPhysicsHelper.h" 12 : #include "WCNSFVFlowPhysics.h" 13 : #include "NSFVBase.h" 14 : #include "NS.h" 15 : 16 : InputParameters 17 1195 : WCNSFVScalarTransportPhysicsBase::validParams() 18 : { 19 1195 : InputParameters params = NavierStokesPhysicsBase::validParams(); 20 1195 : params += WCNSFVCoupledAdvectionPhysicsHelper::validParams(); 21 1195 : params.addClassDescription( 22 : "Define the Navier Stokes weakly-compressible scalar field transport equation(s)"); 23 : 24 1195 : params += NSFVBase::commonScalarFieldAdvectionParams(); 25 : 26 : // TODO Remove the parameter once NavierStokesFV syntax has been removed 27 2390 : params.addParam<bool>( 28 : "add_scalar_equation", 29 : "Whether to add the scalar transport equation. This parameter is not necessary if " 30 : "using the Physics syntax"); 31 : 32 : // These parameters are not shared because the NSFVPhysics use functors 33 1195 : params.addParam<std::vector<std::vector<MooseFunctorName>>>( 34 : "passive_scalar_inlet_function", 35 1195 : std::vector<std::vector<MooseFunctorName>>(), 36 : "Functors for inlet boundaries in the passive scalar equations."); 37 : 38 : // New functor boundary conditions 39 2390 : params.deprecateParam( 40 : "passive_scalar_inlet_function", "passive_scalar_inlet_functors", "01/01/2025"); 41 : 42 : // No need for the duplication 43 2390 : params.addParam<std::vector<MooseFunctorName>>("passive_scalar_source", "Passive scalar sources"); 44 : 45 : // Spatial finite volume discretization scheme 46 1195 : params.transferParam<MooseEnum>(NSFVBase::validParams(), 47 : "passive_scalar_advection_interpolation"); 48 1195 : params.transferParam<bool>(NSFVBase::validParams(), "passive_scalar_two_term_bc_expansion"); 49 : 50 : // Nonlinear equation solver scaling 51 2390 : params.addRangeCheckedParam<std::vector<Real>>( 52 : "passive_scalar_scaling", 53 : "passive_scalar_scaling > 0.0", 54 : "The scaling factor for the passive scalar field variables."); 55 : 56 : // Parameter groups 57 2390 : params.addParamNamesToGroup("passive_scalar_names initial_scalar_variables", "Variable"); 58 2390 : params.addParamNamesToGroup("passive_scalar_advection_interpolation passive_scalar_scaling " 59 : "passive_scalar_two_term_bc_expansion", 60 : "Numerical scheme"); 61 2390 : params.addParamNamesToGroup("passive_scalar_inlet_types passive_scalar_inlet_functors", 62 : "Inlet boundary"); 63 : 64 1195 : return params; 65 0 : } 66 : 67 1195 : WCNSFVScalarTransportPhysicsBase::WCNSFVScalarTransportPhysicsBase( 68 1195 : const InputParameters & parameters) 69 : : NavierStokesPhysicsBase(parameters), 70 : WCNSFVCoupledAdvectionPhysicsHelper(this), 71 1195 : _passive_scalar_names(getParam<std::vector<NonlinearVariableName>>("passive_scalar_names")), 72 3836 : _has_scalar_equation(isParamValid("add_scalar_equation") ? getParam<bool>("add_scalar_equation") 73 944 : : !usingNavierStokesFVSyntax()), 74 2390 : _passive_scalar_inlet_types(getParam<MultiMooseEnum>("passive_scalar_inlet_types")), 75 2390 : _passive_scalar_inlet_functors( 76 : getParam<std::vector<std::vector<MooseFunctorName>>>("passive_scalar_inlet_functors")), 77 2390 : _passive_scalar_sources(getParam<std::vector<MooseFunctorName>>("passive_scalar_source")), 78 2390 : _passive_scalar_coupled_sources( 79 : getParam<std::vector<std::vector<MooseFunctorName>>>("passive_scalar_coupled_source")), 80 2390 : _passive_scalar_sources_coef( 81 1195 : getParam<std::vector<std::vector<Real>>>("passive_scalar_coupled_source_coeff")) 82 : { 83 1195 : if (_has_scalar_equation) 84 917 : for (const auto & scalar_name : _passive_scalar_names) 85 1030 : saveSolverVariableName(scalar_name); 86 : 87 : // For compatibility with Modules/NavierStokesFV syntax 88 1195 : if (!_has_scalar_equation) 89 : return; 90 : 91 : // These parameters must be passed for every passive scalar at a time 92 802 : checkVectorParamsSameLengthIfSet<NonlinearVariableName, MooseFunctorName>( 93 : "passive_scalar_names", "passive_scalar_diffusivity", true); 94 798 : checkVectorParamsSameLengthIfSet<NonlinearVariableName, std::vector<MooseFunctorName>>( 95 : "passive_scalar_names", "passive_scalar_coupled_source", true); 96 794 : checkVectorParamsSameLengthIfSet<NonlinearVariableName, MooseFunctorName>( 97 : "passive_scalar_names", "passive_scalar_source", true); 98 792 : checkVectorParamsSameLengthIfSet<NonlinearVariableName, Real>( 99 : "passive_scalar_names", "passive_scalar_scaling", true); 100 790 : checkVectorParamsSameLengthIfSet<NonlinearVariableName, FunctionName>( 101 : "passive_scalar_names", "initial_scalar_variables", true); 102 786 : checkVectorParamsSameLengthIfSet<NonlinearVariableName, std::vector<MooseFunctorName>>( 103 : "passive_scalar_names", "passive_scalar_inlet_functors", true); 104 392 : if (_passive_scalar_inlet_functors.size()) 105 720 : checkTwoDVectorParamMultiMooseEnumSameLength<MooseFunctorName>( 106 : "passive_scalar_inlet_functors", "passive_scalar_inlet_types", false); 107 : 108 388 : if (_passive_scalar_sources_coef.size()) 109 308 : checkTwoDVectorParamsSameLength<MooseFunctorName, Real>("passive_scalar_coupled_source", 110 : "passive_scalar_coupled_source_coeff"); 111 0 : } 112 : 113 : void 114 1149 : WCNSFVScalarTransportPhysicsBase::addFVKernels() 115 : { 116 : // For compatibility with Modules/NavierStokesFV syntax 117 1149 : if (!_has_scalar_equation) 118 : return; 119 : 120 360 : if (isTransient()) 121 67 : addScalarTimeKernels(); 122 : 123 360 : addScalarAdvectionKernels(); 124 360 : addScalarDiffusionKernels(); 125 360 : if (_passive_scalar_sources.size() || _passive_scalar_coupled_sources.size()) 126 228 : addScalarSourceKernels(); 127 : } 128 : 129 : void 130 1141 : WCNSFVScalarTransportPhysicsBase::addFVBCs() 131 : { 132 : // For compatibility with Modules/NavierStokesFV syntax 133 1141 : if (!_has_scalar_equation) 134 : return; 135 : 136 352 : addScalarInletBC(); 137 : // There is typically no wall flux of passive scalars, similarly we rarely know 138 : // their concentrations at the outlet at the beginning of the simulation 139 : // TODO: we will know the outlet values in case of flow reversal. Implement scalar outlet 140 352 : addScalarWallBC(); 141 352 : addScalarOutletBC(); 142 : } 143 : 144 : void 145 1155 : WCNSFVScalarTransportPhysicsBase::addInitialConditions() 146 : { 147 : // For compatibility with Modules/NavierStokesFV syntax 148 1155 : if (!_has_scalar_equation) 149 810 : return; 150 364 : if (!_define_variables && parameters().isParamSetByUser("initial_scalar_variables")) 151 0 : paramError("initial_scalar_variables", 152 : "Scalar variables are defined externally of NavierStokesFV, so should their inital " 153 : "conditions"); 154 : // do not set initial conditions if we load from file 155 728 : if (getParam<bool>("initialize_variables_from_mesh_file")) 156 : return; 157 : // do not set initial conditions if we are not defining variables 158 345 : if (!_define_variables) 159 : return; 160 : 161 345 : InputParameters params = getFactory().getValidParams("FunctionIC"); 162 345 : assignBlocks(params, _blocks); 163 : 164 : // There are no default initial conditions for passive scalar variables, we however 165 : // must obey the user-defined initial conditions, even if we are restarting 166 690 : if (parameters().isParamSetByUser("initial_scalar_variables")) 167 : { 168 333 : for (unsigned int name_i = 0; name_i < _passive_scalar_names.size(); ++name_i) 169 : { 170 408 : params.set<VariableName>("variable") = _passive_scalar_names[name_i]; 171 408 : params.set<FunctionName>("function") = 172 204 : getParam<std::vector<FunctionName>>("initial_scalar_variables")[name_i]; 173 : 174 408 : getProblem().addInitialCondition("FunctionIC", _passive_scalar_names[name_i] + "_ic", params); 175 : } 176 : } 177 345 : } 178 : 179 : unsigned short 180 3459 : WCNSFVScalarTransportPhysicsBase::getNumberAlgebraicGhostingLayersNeeded() const 181 : { 182 6918 : unsigned short necessary_layers = getParam<unsigned short>("ghost_layers"); 183 3459 : necessary_layers = 184 3459 : std::max(necessary_layers, _flow_equations_physics->getNumberAlgebraicGhostingLayersNeeded()); 185 10377 : if (getParam<MooseEnum>("passive_scalar_advection_interpolation") == "skewness-corrected") 186 0 : necessary_layers = std::max(necessary_layers, (unsigned short)3); 187 : 188 3459 : return necessary_layers; 189 : }