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

Generated by: LCOV version 1.14