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 "WCNSLinearFVScalarTransportPhysics.h" 11 : #include "WCNSFVFlowPhysicsBase.h" 12 : #include "NS.h" 13 : 14 : registerNavierStokesPhysicsBaseTasks("NavierStokesApp", WCNSLinearFVScalarTransportPhysics); 15 : registerWCNSFVScalarTransportBaseTasks("NavierStokesApp", WCNSLinearFVScalarTransportPhysics); 16 : 17 : InputParameters 18 77 : WCNSLinearFVScalarTransportPhysics::validParams() 19 : { 20 77 : InputParameters params = WCNSFVScalarTransportPhysicsBase::validParams(); 21 77 : params.addClassDescription("Define the Navier Stokes weakly-compressible scalar field transport " 22 : "equation(s) using the linear finite volume discretization"); 23 154 : params.addParam<bool>("use_nonorthogonal_correction", 24 154 : true, 25 : "If the nonorthogonal correction should be used when computing the normal " 26 : "gradient, notably in the diffusion term."); 27 : 28 : // Not supported 29 77 : params.suppressParameter<MooseEnum>("preconditioning"); 30 : 31 77 : return params; 32 0 : } 33 : 34 77 : WCNSLinearFVScalarTransportPhysics::WCNSLinearFVScalarTransportPhysics( 35 77 : const InputParameters & parameters) 36 77 : : WCNSFVScalarTransportPhysicsBase(parameters) 37 : { 38 77 : if (_porous_medium_treatment) 39 0 : _flow_equations_physics->paramError("porous_medium_treatment", 40 : "Porous media scalar advection is currently unimplemented"); 41 77 : } 42 : 43 : void 44 77 : WCNSLinearFVScalarTransportPhysics::addSolverVariables() 45 : { 46 : // For compatibility with Modules/NavierStokesFV syntax 47 77 : if (!_has_scalar_equation) 48 0 : return; 49 : 50 77 : auto params = getFactory().getValidParams("MooseLinearVariableFVReal"); 51 77 : assignBlocks(params, _blocks); 52 : 53 191 : for (const auto name_i : index_range(_passive_scalar_names)) 54 : { 55 : // Dont add if the user already defined the variable 56 228 : if (!shouldCreateVariable(_passive_scalar_names[name_i], _blocks, /*error if aux*/ true)) 57 : { 58 0 : reportPotentiallyMissedParameters({"system_names", "passive_scalar_scaling"}, 59 : "MooseLinearVariableFVReal"); 60 0 : continue; 61 : } 62 : 63 114 : params.set<SolverSystemName>("solver_sys") = getSolverSystem(name_i); 64 228 : if (isParamValid("passive_scalar_scaling")) 65 0 : params.set<std::vector<Real>>("scaling") = { 66 0 : getParam<std::vector<Real>>("passive_scalar_scaling")[name_i]}; 67 : 68 228 : getProblem().addVariable("MooseLinearVariableFVReal", _passive_scalar_names[name_i], params); 69 : } 70 77 : } 71 : 72 : void 73 40 : WCNSLinearFVScalarTransportPhysics::addScalarTimeKernels() 74 : { 75 40 : std::string kernel_type = "LinearFVTimeDerivative"; 76 40 : InputParameters params = getFactory().getValidParams(kernel_type); 77 40 : assignBlocks(params, _blocks); 78 : 79 99 : for (const auto & vname : _passive_scalar_names) 80 : { 81 118 : params.set<LinearVariableName>("variable") = vname; 82 118 : if (shouldCreateTimeDerivative(vname, _blocks, /*error if already defined */ false)) 83 236 : getProblem().addLinearFVKernel(kernel_type, prefix() + "ins_" + vname + "_time", params); 84 : } 85 80 : } 86 : 87 : void 88 77 : WCNSLinearFVScalarTransportPhysics::addScalarAdvectionKernels() 89 : { 90 77 : const std::string kernel_type = "LinearFVScalarAdvection"; 91 77 : InputParameters params = getFactory().getValidParams(kernel_type); 92 : 93 77 : assignBlocks(params, _blocks); 94 154 : params.set<UserObjectName>("rhie_chow_user_object") = _flow_equations_physics->rhieChowUOName(); 95 154 : params.set<MooseEnum>("advected_interp_method") = 96 154 : getParam<MooseEnum>("passive_scalar_advection_interpolation"); 97 77 : setSlipVelocityParams(params); 98 : 99 191 : for (const auto & vname : _passive_scalar_names) 100 : { 101 228 : params.set<LinearVariableName>("variable") = vname; 102 456 : getProblem().addLinearFVKernel(kernel_type, prefix() + "ins_" + vname + "_advection", params); 103 : } 104 154 : } 105 : 106 : void 107 77 : WCNSLinearFVScalarTransportPhysics::addScalarDiffusionKernels() 108 : { 109 : // Direct specification of diffusion term 110 : const auto passive_scalar_diffusivities = 111 231 : getParam<std::vector<MooseFunctorName>>("passive_scalar_diffusivity"); 112 : 113 77 : if (passive_scalar_diffusivities.size()) 114 : { 115 58 : const std::string kernel_type = "LinearFVDiffusion"; 116 58 : InputParameters params = getFactory().getValidParams(kernel_type); 117 58 : assignBlocks(params, _blocks); 118 58 : params.set<bool>("use_nonorthogonal_correction") = 119 174 : getParam<bool>("use_nonorthogonal_correction"); 120 153 : for (const auto name_i : index_range(_passive_scalar_names)) 121 : { 122 190 : params.set<LinearVariableName>("variable") = _passive_scalar_names[name_i]; 123 95 : params.set<MooseFunctorName>("diffusion_coeff") = passive_scalar_diffusivities[name_i]; 124 190 : getProblem().addLinearFVKernel( 125 285 : kernel_type, prefix() + "ins_" + _passive_scalar_names[name_i] + "_diffusion", params); 126 : } 127 58 : } 128 77 : } 129 : 130 : void 131 9 : WCNSLinearFVScalarTransportPhysics::addScalarSourceKernels() 132 : { 133 9 : const std::string kernel_type = "LinearFVSource"; 134 9 : InputParameters params = getFactory().getValidParams(kernel_type); 135 9 : assignBlocks(params, _blocks); 136 : 137 27 : for (const auto scalar_i : index_range(_passive_scalar_names)) 138 : { 139 36 : params.set<LinearVariableName>("variable") = _passive_scalar_names[scalar_i]; 140 : 141 18 : if (_passive_scalar_sources.size()) 142 : { 143 : // Added for backward compatibility with former Modules/NavierStokesFV syntax 144 0 : params.set<MooseFunctorName>("source_density") = _passive_scalar_sources[scalar_i]; 145 0 : getProblem().addLinearFVKernel( 146 0 : kernel_type, prefix() + "ins_" + _passive_scalar_names[scalar_i] + "_source", params); 147 : } 148 : 149 18 : if (_passive_scalar_coupled_sources.size()) 150 36 : for (const auto i : index_range(_passive_scalar_coupled_sources[scalar_i])) 151 : { 152 36 : params.set<MooseFunctorName>("source_density") = 153 : _passive_scalar_coupled_sources[scalar_i][i]; 154 18 : if (_passive_scalar_sources_coef.size()) 155 0 : params.set<Real>("scaling_factor") = _passive_scalar_sources_coef[scalar_i][i]; 156 : 157 36 : getProblem().addLinearFVKernel(kernel_type, 158 54 : prefix() + "ins_" + _passive_scalar_names[scalar_i] + 159 54 : "_coupled_source_" + std::to_string(i), 160 : params); 161 : } 162 : } 163 18 : } 164 : 165 : void 166 77 : WCNSLinearFVScalarTransportPhysics::addScalarInletBC() 167 : { 168 77 : const auto & inlet_boundaries = _flow_equations_physics->getInletBoundaries(); 169 77 : if (inlet_boundaries.empty()) 170 : return; 171 : 172 : // Boundary checks 173 : // TODO: once we have vectors of MooseEnum, we could use the same templated check for types and 174 : // functors 175 56 : if (inlet_boundaries.size() * _passive_scalar_names.size() != _passive_scalar_inlet_types.size()) 176 0 : paramError( 177 : "passive_scalar_inlet_types", 178 0 : "The number of scalar inlet types (" + std::to_string(_passive_scalar_inlet_types.size()) + 179 0 : ") is not equal to the number of inlet boundaries (" + 180 0 : std::to_string(inlet_boundaries.size()) + ") times the number of passive scalars (" + 181 0 : std::to_string(_passive_scalar_names.size()) + ")"); 182 56 : if (_passive_scalar_names.size() != _passive_scalar_inlet_functors.size()) 183 0 : paramError("passive_scalar_inlet_functors", 184 0 : "The number of groups of inlet functors (" + 185 0 : std::to_string(_passive_scalar_inlet_functors.size()) + 186 0 : ") is not equal to the number of passive scalars (" + 187 0 : std::to_string(_passive_scalar_names.size()) + ")"); 188 : 189 149 : for (const auto name_i : index_range(_passive_scalar_names)) 190 : { 191 93 : if (inlet_boundaries.size() != _passive_scalar_inlet_functors[name_i].size()) 192 0 : paramError("passive_scalar_inlet_functors", 193 0 : "The number of inlet boundary functors for scalar '" + 194 0 : _passive_scalar_names[name_i] + 195 0 : "' does not match the number of inlet boundaries (" + 196 0 : std::to_string(_passive_scalar_inlet_functors[name_i].size()) + ")"); 197 : 198 93 : unsigned int num_inlets = inlet_boundaries.size(); 199 186 : for (unsigned int bc_ind = 0; bc_ind < num_inlets; ++bc_ind) 200 : { 201 93 : if (_passive_scalar_inlet_types[name_i * num_inlets + bc_ind] == "fixed-value") 202 : { 203 93 : const std::string bc_type = "LinearFVAdvectionDiffusionFunctorDirichletBC"; 204 93 : InputParameters params = getFactory().getValidParams(bc_type); 205 186 : params.set<LinearVariableName>("variable") = _passive_scalar_names[name_i]; 206 186 : params.set<MooseFunctorName>("functor") = _passive_scalar_inlet_functors[name_i][bc_ind]; 207 279 : params.set<std::vector<BoundaryName>>("boundary") = {inlet_boundaries[bc_ind]}; 208 : 209 186 : getProblem().addLinearFVBC( 210 93 : bc_type, _passive_scalar_names[name_i] + "_" + inlet_boundaries[bc_ind], params); 211 93 : } 212 0 : else if (_passive_scalar_inlet_types[name_i * num_inlets + bc_ind] == "flux-mass" || 213 0 : _passive_scalar_inlet_types[name_i * num_inlets + bc_ind] == "flux-velocity") 214 : { 215 0 : mooseError("Flux boundary conditions not supported at this time using the linear finite " 216 : "volume discretization"); 217 : } 218 : } 219 : } 220 : } 221 : 222 : void 223 77 : WCNSLinearFVScalarTransportPhysics::addScalarOutletBC() 224 : { 225 77 : const auto & outlet_boundaries = _flow_equations_physics->getOutletBoundaries(); 226 77 : if (outlet_boundaries.empty()) 227 : return; 228 : 229 112 : for (const auto & outlet_bdy : outlet_boundaries) 230 : { 231 56 : const std::string bc_type = "LinearFVAdvectionDiffusionOutflowBC"; 232 56 : InputParameters params = getFactory().getValidParams(bc_type); 233 168 : params.set<std::vector<BoundaryName>>("boundary") = {outlet_bdy}; 234 56 : params.set<bool>("use_two_term_expansion") = 235 168 : getParam<bool>("passive_scalar_two_term_bc_expansion"); 236 : 237 149 : for (const auto name_i : index_range(_passive_scalar_names)) 238 : { 239 186 : params.set<LinearVariableName>("variable") = _passive_scalar_names[name_i]; 240 186 : getProblem().addLinearFVBC(bc_type, _passive_scalar_names[name_i] + "_" + outlet_bdy, params); 241 : } 242 56 : } 243 : }