LCOV - code coverage report
Current view: top level - src/physics - WCNSFVScalarTransportPhysicsBase.C (source / functions) Hit Total Coverage
Test: idaholab/moose navier_stokes: #32971 (54bef8) with base c6cf66 Lines: 85 89 95.5 %
Date: 2026-05-29 20:37:52 Functions: 7 7 100.0 %
Legend: Lines: hit not hit

          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         665 : WCNSFVScalarTransportPhysicsBase::validParams()
      18             : {
      19         665 :   InputParameters params = NavierStokesPhysicsBase::validParams();
      20         665 :   params += WCNSFVCoupledAdvectionPhysicsHelper::validParams();
      21         665 :   params.addClassDescription(
      22             :       "Define the Navier Stokes weakly-compressible scalar field transport equation(s)");
      23             : 
      24         665 :   params += NSFVBase::commonScalarFieldAdvectionParams();
      25             : 
      26             :   // TODO Remove the parameter once NavierStokesFV syntax has been removed
      27        1330 :   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         665 :   params.addParam<std::vector<std::vector<MooseFunctorName>>>(
      34             :       "passive_scalar_inlet_functors",
      35         665 :       std::vector<std::vector<MooseFunctorName>>(),
      36             :       "Functors for inlet boundaries in the passive scalar equations.");
      37             : 
      38             :   // No need for the duplication
      39        1330 :   params.addParam<std::vector<MooseFunctorName>>("passive_scalar_source", "Passive scalar sources");
      40             : 
      41             :   // Spatial finite volume discretization scheme
      42         665 :   params.transferParam<MooseEnum>(NSFVBase::validParams(),
      43             :                                   "passive_scalar_advection_interpolation");
      44         665 :   params.transferParam<bool>(NSFVBase::validParams(), "passive_scalar_two_term_bc_expansion");
      45             : 
      46             :   // Nonlinear equation solver scaling
      47        1330 :   params.addRangeCheckedParam<std::vector<Real>>(
      48             :       "passive_scalar_scaling",
      49             :       "passive_scalar_scaling > 0.0",
      50             :       "The scaling factor for the passive scalar field variables.");
      51             : 
      52             :   // Parameter groups
      53        1330 :   params.addParamNamesToGroup("passive_scalar_names initial_scalar_variables", "Variable");
      54        1330 :   params.addParamNamesToGroup("passive_scalar_advection_interpolation passive_scalar_scaling "
      55             :                               "passive_scalar_two_term_bc_expansion",
      56             :                               "Numerical scheme");
      57        1330 :   params.addParamNamesToGroup("passive_scalar_inlet_types passive_scalar_inlet_functors",
      58             :                               "Inlet boundary");
      59             : 
      60         665 :   return params;
      61           0 : }
      62             : 
      63         665 : WCNSFVScalarTransportPhysicsBase::WCNSFVScalarTransportPhysicsBase(
      64         665 :     const InputParameters & parameters)
      65             :   : NavierStokesPhysicsBase(parameters),
      66             :     WCNSFVCoupledAdvectionPhysicsHelper(this),
      67         665 :     _passive_scalar_names(getParam<std::vector<NonlinearVariableName>>("passive_scalar_names")),
      68        2161 :     _has_scalar_equation(isParamValid("add_scalar_equation") ? getParam<bool>("add_scalar_equation")
      69         499 :                                                              : !usingNavierStokesFVSyntax()),
      70        1330 :     _passive_scalar_inlet_types(getParam<MultiMooseEnum>("passive_scalar_inlet_types")),
      71        1330 :     _passive_scalar_inlet_functors(
      72             :         getParam<std::vector<std::vector<MooseFunctorName>>>("passive_scalar_inlet_functors")),
      73        1330 :     _passive_scalar_sources(getParam<std::vector<MooseFunctorName>>("passive_scalar_source")),
      74        1330 :     _passive_scalar_coupled_sources(
      75             :         getParam<std::vector<std::vector<MooseFunctorName>>>("passive_scalar_coupled_source")),
      76        1330 :     _passive_scalar_sources_coef(
      77         665 :         getParam<std::vector<std::vector<Real>>>("passive_scalar_coupled_source_coeff"))
      78             : {
      79         665 :   if (_has_scalar_equation)
      80         584 :     for (const auto & scalar_name : _passive_scalar_names)
      81         640 :       saveSolverVariableName(scalar_name);
      82             : 
      83             :   // For compatibility with Modules/NavierStokesFV syntax
      84         665 :   if (!_has_scalar_equation)
      85             :     return;
      86             : 
      87             :   // These parameters must be passed for every passive scalar at a time
      88         526 :   checkVectorParamsSameLengthIfSet<NonlinearVariableName, MooseFunctorName>(
      89             :       "passive_scalar_names", "passive_scalar_diffusivity", true);
      90         522 :   checkVectorParamsSameLengthIfSet<NonlinearVariableName, std::vector<MooseFunctorName>>(
      91             :       "passive_scalar_names", "passive_scalar_coupled_source", true);
      92         518 :   checkVectorParamsSameLengthIfSet<NonlinearVariableName, MooseFunctorName>(
      93             :       "passive_scalar_names", "passive_scalar_source", true);
      94         516 :   checkVectorParamsSameLengthIfSet<NonlinearVariableName, Real>(
      95             :       "passive_scalar_names", "passive_scalar_scaling", true);
      96         514 :   checkVectorParamsSameLengthIfSet<NonlinearVariableName, FunctionName>(
      97             :       "passive_scalar_names", "initial_scalar_variables", true);
      98         510 :   checkVectorParamsSameLengthIfSet<NonlinearVariableName, std::vector<MooseFunctorName>>(
      99             :       "passive_scalar_names", "passive_scalar_inlet_functors", true);
     100         254 :   if (_passive_scalar_inlet_functors.size())
     101         472 :     checkTwoDVectorParamMultiMooseEnumSameLength<MooseFunctorName>(
     102             :         "passive_scalar_inlet_functors", "passive_scalar_inlet_types", false);
     103             : 
     104         250 :   if (_passive_scalar_sources_coef.size())
     105         148 :     checkTwoDVectorParamsSameLength<MooseFunctorName, Real>("passive_scalar_coupled_source",
     106             :                                                             "passive_scalar_coupled_source_coeff");
     107             : 
     108         246 :   addRequiredPhysicsTask("get_turbulence_physics");
     109         246 :   addRequiredPhysicsTask("add_variables_physics");
     110         246 :   addRequiredPhysicsTask("add_ics_physics");
     111         246 :   addRequiredPhysicsTask("add_fv_kernel");
     112         492 :   addRequiredPhysicsTask("add_fv_bc");
     113           0 : }
     114             : 
     115             : void
     116        5741 : WCNSFVScalarTransportPhysicsBase::actOnAdditionalTasks()
     117             : {
     118             :   // Turbulence physics would not be initialized before this task
     119        5741 :   if (_current_task == "get_turbulence_physics")
     120             :   {
     121         639 :     _turbulence_physics = getCoupledTurbulencePhysics();
     122        1755 :     _has_turbulence_model = _turbulence_physics ? _turbulence_physics->hasTurbulenceModel() : false;
     123             :   }
     124        5741 : }
     125             : 
     126             : void
     127         619 : WCNSFVScalarTransportPhysicsBase::addFVKernels()
     128             : {
     129             :   // For compatibility with Modules/NavierStokesFV syntax
     130         619 :   if (!_has_scalar_equation)
     131             :     return;
     132             : 
     133         222 :   if (isTransient())
     134          38 :     addScalarTimeKernels();
     135             : 
     136         222 :   addScalarAdvectionKernels();
     137         222 :   addScalarDiffusionKernels();
     138         222 :   if (_passive_scalar_sources.size() || _passive_scalar_coupled_sources.size())
     139         147 :     addScalarSourceKernels();
     140             : }
     141             : 
     142             : void
     143         611 : WCNSFVScalarTransportPhysicsBase::addFVBCs()
     144             : {
     145             :   // For compatibility with Modules/NavierStokesFV syntax
     146         611 :   if (!_has_scalar_equation)
     147             :     return;
     148             : 
     149         214 :   addScalarInletBC();
     150             :   // There is typically no wall flux of passive scalars, similarly we rarely know
     151             :   // their concentrations at the outlet at the beginning of the simulation
     152             :   // TODO: we will know the outlet values in case of flow reversal. Implement scalar outlet
     153         214 :   addScalarWallBC();
     154         214 :   addScalarOutletBC();
     155             : }
     156             : 
     157             : void
     158         625 : WCNSFVScalarTransportPhysicsBase::addInitialConditions()
     159             : {
     160             :   // For compatibility with Modules/NavierStokesFV syntax
     161         625 :   if (!_has_scalar_equation)
     162         408 :     return;
     163         226 :   if (!_define_variables && parameters().isParamSetByUser("initial_scalar_variables"))
     164           0 :     paramError("initial_scalar_variables",
     165             :                "Scalar variables are defined externally of NavierStokesFV, so should their inital "
     166             :                "conditions");
     167             :   // do not set initial conditions if we load from file
     168         452 :   if (getParam<bool>("initialize_variables_from_mesh_file"))
     169             :     return;
     170             :   // do not set initial conditions if we are not defining variables
     171         217 :   if (!_define_variables)
     172             :     return;
     173             : 
     174         217 :   InputParameters params = getFactory().getValidParams("FunctionIC");
     175         217 :   assignBlocks(params, _blocks);
     176             : 
     177             :   // There are no default initial conditions for passive scalar variables, we however
     178             :   // must obey the user-defined initial conditions, even if we are restarting
     179         434 :   if (parameters().isParamSetByUser("initial_scalar_variables"))
     180             :   {
     181         198 :     for (unsigned int name_i = 0; name_i < _passive_scalar_names.size(); ++name_i)
     182             :     {
     183         236 :       params.set<VariableName>("variable") = _passive_scalar_names[name_i];
     184         236 :       params.set<FunctionName>("function") =
     185         118 :           getParam<std::vector<FunctionName>>("initial_scalar_variables")[name_i];
     186             : 
     187         236 :       getProblem().addInitialCondition("FunctionIC", _passive_scalar_names[name_i] + "_ic", params);
     188             :     }
     189             :   }
     190         217 : }
     191             : 
     192             : unsigned short
     193        1869 : WCNSFVScalarTransportPhysicsBase::getNumberAlgebraicGhostingLayersNeeded() const
     194             : {
     195        3738 :   unsigned short necessary_layers = getParam<unsigned short>("ghost_layers");
     196        1869 :   necessary_layers =
     197        1869 :       std::max(necessary_layers, _flow_equations_physics->getNumberAlgebraicGhostingLayersNeeded());
     198        5607 :   if (getParam<MooseEnum>("passive_scalar_advection_interpolation") == "skewness-corrected")
     199           0 :     necessary_layers = std::max(necessary_layers, (unsigned short)3);
     200             : 
     201        1869 :   return necessary_layers;
     202             : }

Generated by: LCOV version 1.14