LCOV - code coverage report
Current view: top level - src/physics - WCNSFVScalarTransportPhysicsBase.C (source / functions) Hit Total Coverage
Test: idaholab/moose navier_stokes: 2bd28b Lines: 75 79 94.9 %
Date: 2025-10-23 22:11:45 Functions: 6 6 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        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_functors",
      35        1195 :       std::vector<std::vector<MooseFunctorName>>(),
      36             :       "Functors for inlet boundaries in the passive scalar equations.");
      37             : 
      38             :   // No need for the duplication
      39        2390 :   params.addParam<std::vector<MooseFunctorName>>("passive_scalar_source", "Passive scalar sources");
      40             : 
      41             :   // Spatial finite volume discretization scheme
      42        1195 :   params.transferParam<MooseEnum>(NSFVBase::validParams(),
      43             :                                   "passive_scalar_advection_interpolation");
      44        1195 :   params.transferParam<bool>(NSFVBase::validParams(), "passive_scalar_two_term_bc_expansion");
      45             : 
      46             :   // Nonlinear equation solver scaling
      47        2390 :   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        2390 :   params.addParamNamesToGroup("passive_scalar_names initial_scalar_variables", "Variable");
      54        2390 :   params.addParamNamesToGroup("passive_scalar_advection_interpolation passive_scalar_scaling "
      55             :                               "passive_scalar_two_term_bc_expansion",
      56             :                               "Numerical scheme");
      57        2390 :   params.addParamNamesToGroup("passive_scalar_inlet_types passive_scalar_inlet_functors",
      58             :                               "Inlet boundary");
      59             : 
      60        1195 :   return params;
      61           0 : }
      62             : 
      63        1195 : WCNSFVScalarTransportPhysicsBase::WCNSFVScalarTransportPhysicsBase(
      64        1195 :     const InputParameters & parameters)
      65             :   : NavierStokesPhysicsBase(parameters),
      66             :     WCNSFVCoupledAdvectionPhysicsHelper(this),
      67        1195 :     _passive_scalar_names(getParam<std::vector<NonlinearVariableName>>("passive_scalar_names")),
      68        3836 :     _has_scalar_equation(isParamValid("add_scalar_equation") ? getParam<bool>("add_scalar_equation")
      69         944 :                                                              : !usingNavierStokesFVSyntax()),
      70        2390 :     _passive_scalar_inlet_types(getParam<MultiMooseEnum>("passive_scalar_inlet_types")),
      71        2390 :     _passive_scalar_inlet_functors(
      72             :         getParam<std::vector<std::vector<MooseFunctorName>>>("passive_scalar_inlet_functors")),
      73        2390 :     _passive_scalar_sources(getParam<std::vector<MooseFunctorName>>("passive_scalar_source")),
      74        2390 :     _passive_scalar_coupled_sources(
      75             :         getParam<std::vector<std::vector<MooseFunctorName>>>("passive_scalar_coupled_source")),
      76        2390 :     _passive_scalar_sources_coef(
      77        1195 :         getParam<std::vector<std::vector<Real>>>("passive_scalar_coupled_source_coeff"))
      78             : {
      79        1195 :   if (_has_scalar_equation)
      80         917 :     for (const auto & scalar_name : _passive_scalar_names)
      81        1030 :       saveSolverVariableName(scalar_name);
      82             : 
      83             :   // For compatibility with Modules/NavierStokesFV syntax
      84        1195 :   if (!_has_scalar_equation)
      85             :     return;
      86             : 
      87             :   // These parameters must be passed for every passive scalar at a time
      88         802 :   checkVectorParamsSameLengthIfSet<NonlinearVariableName, MooseFunctorName>(
      89             :       "passive_scalar_names", "passive_scalar_diffusivity", true);
      90         798 :   checkVectorParamsSameLengthIfSet<NonlinearVariableName, std::vector<MooseFunctorName>>(
      91             :       "passive_scalar_names", "passive_scalar_coupled_source", true);
      92         794 :   checkVectorParamsSameLengthIfSet<NonlinearVariableName, MooseFunctorName>(
      93             :       "passive_scalar_names", "passive_scalar_source", true);
      94         792 :   checkVectorParamsSameLengthIfSet<NonlinearVariableName, Real>(
      95             :       "passive_scalar_names", "passive_scalar_scaling", true);
      96         790 :   checkVectorParamsSameLengthIfSet<NonlinearVariableName, FunctionName>(
      97             :       "passive_scalar_names", "initial_scalar_variables", true);
      98         786 :   checkVectorParamsSameLengthIfSet<NonlinearVariableName, std::vector<MooseFunctorName>>(
      99             :       "passive_scalar_names", "passive_scalar_inlet_functors", true);
     100         392 :   if (_passive_scalar_inlet_functors.size())
     101         720 :     checkTwoDVectorParamMultiMooseEnumSameLength<MooseFunctorName>(
     102             :         "passive_scalar_inlet_functors", "passive_scalar_inlet_types", false);
     103             : 
     104         388 :   if (_passive_scalar_sources_coef.size())
     105         308 :     checkTwoDVectorParamsSameLength<MooseFunctorName, Real>("passive_scalar_coupled_source",
     106             :                                                             "passive_scalar_coupled_source_coeff");
     107           0 : }
     108             : 
     109             : void
     110        1149 : WCNSFVScalarTransportPhysicsBase::addFVKernels()
     111             : {
     112             :   // For compatibility with Modules/NavierStokesFV syntax
     113        1149 :   if (!_has_scalar_equation)
     114             :     return;
     115             : 
     116         360 :   if (isTransient())
     117          67 :     addScalarTimeKernels();
     118             : 
     119         360 :   addScalarAdvectionKernels();
     120         360 :   addScalarDiffusionKernels();
     121         360 :   if (_passive_scalar_sources.size() || _passive_scalar_coupled_sources.size())
     122         228 :     addScalarSourceKernels();
     123             : }
     124             : 
     125             : void
     126        1141 : WCNSFVScalarTransportPhysicsBase::addFVBCs()
     127             : {
     128             :   // For compatibility with Modules/NavierStokesFV syntax
     129        1141 :   if (!_has_scalar_equation)
     130             :     return;
     131             : 
     132         352 :   addScalarInletBC();
     133             :   // There is typically no wall flux of passive scalars, similarly we rarely know
     134             :   // their concentrations at the outlet at the beginning of the simulation
     135             :   // TODO: we will know the outlet values in case of flow reversal. Implement scalar outlet
     136         352 :   addScalarWallBC();
     137         352 :   addScalarOutletBC();
     138             : }
     139             : 
     140             : void
     141        1155 : WCNSFVScalarTransportPhysicsBase::addInitialConditions()
     142             : {
     143             :   // For compatibility with Modules/NavierStokesFV syntax
     144        1155 :   if (!_has_scalar_equation)
     145         810 :     return;
     146         364 :   if (!_define_variables && parameters().isParamSetByUser("initial_scalar_variables"))
     147           0 :     paramError("initial_scalar_variables",
     148             :                "Scalar variables are defined externally of NavierStokesFV, so should their inital "
     149             :                "conditions");
     150             :   // do not set initial conditions if we load from file
     151         728 :   if (getParam<bool>("initialize_variables_from_mesh_file"))
     152             :     return;
     153             :   // do not set initial conditions if we are not defining variables
     154         345 :   if (!_define_variables)
     155             :     return;
     156             : 
     157         345 :   InputParameters params = getFactory().getValidParams("FunctionIC");
     158         345 :   assignBlocks(params, _blocks);
     159             : 
     160             :   // There are no default initial conditions for passive scalar variables, we however
     161             :   // must obey the user-defined initial conditions, even if we are restarting
     162         690 :   if (parameters().isParamSetByUser("initial_scalar_variables"))
     163             :   {
     164         333 :     for (unsigned int name_i = 0; name_i < _passive_scalar_names.size(); ++name_i)
     165             :     {
     166         408 :       params.set<VariableName>("variable") = _passive_scalar_names[name_i];
     167         408 :       params.set<FunctionName>("function") =
     168         204 :           getParam<std::vector<FunctionName>>("initial_scalar_variables")[name_i];
     169             : 
     170         408 :       getProblem().addInitialCondition("FunctionIC", _passive_scalar_names[name_i] + "_ic", params);
     171             :     }
     172             :   }
     173         345 : }
     174             : 
     175             : unsigned short
     176        3459 : WCNSFVScalarTransportPhysicsBase::getNumberAlgebraicGhostingLayersNeeded() const
     177             : {
     178        6918 :   unsigned short necessary_layers = getParam<unsigned short>("ghost_layers");
     179        3459 :   necessary_layers =
     180        3459 :       std::max(necessary_layers, _flow_equations_physics->getNumberAlgebraicGhostingLayersNeeded());
     181       10377 :   if (getParam<MooseEnum>("passive_scalar_advection_interpolation") == "skewness-corrected")
     182           0 :     necessary_layers = std::max(necessary_layers, (unsigned short)3);
     183             : 
     184        3459 :   return necessary_layers;
     185             : }

Generated by: LCOV version 1.14