LCOV - code coverage report
Current view: top level - src/physics - WCNSFVScalarTransportPhysics.C (source / functions) Hit Total Coverage
Test: idaholab/moose navier_stokes: 9fc4b0 Lines: 130 149 87.2 %
Date: 2025-08-14 10:14:56 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 "WCNSFVScalarTransportPhysics.h"
      11             : #include "WCNSFVFlowPhysicsBase.h"
      12             : #include "NSFVBase.h"
      13             : #include "NS.h"
      14             : 
      15             : registerNavierStokesPhysicsBaseTasks("NavierStokesApp", WCNSFVScalarTransportPhysics);
      16             : registerWCNSFVScalarTransportBaseTasks("NavierStokesApp", WCNSFVScalarTransportPhysics);
      17             : 
      18             : InputParameters
      19        1118 : WCNSFVScalarTransportPhysics::validParams()
      20             : {
      21        1118 :   InputParameters params = WCNSFVScalarTransportPhysicsBase::validParams();
      22        1118 :   params.addClassDescription("Define the Navier Stokes weakly-compressible scalar field transport "
      23             :                              "equation(s) using the nonlinear finite volume discretization");
      24        1118 :   params.transferParam<MooseEnum>(NSFVBase::validParams(), "passive_scalar_face_interpolation");
      25        2236 :   params.addParamNamesToGroup("passive_scalar_face_interpolation", "Numerical scheme");
      26        1118 :   return params;
      27           0 : }
      28             : 
      29        1118 : WCNSFVScalarTransportPhysics::WCNSFVScalarTransportPhysics(const InputParameters & parameters)
      30        1118 :   : WCNSFVScalarTransportPhysicsBase(parameters)
      31             : {
      32        1100 : }
      33             : 
      34             : void
      35        1092 : WCNSFVScalarTransportPhysics::addSolverVariables()
      36             : {
      37             :   // For compatibility with Modules/NavierStokesFV syntax
      38        1092 :   if (!_has_scalar_equation)
      39         793 :     return;
      40             : 
      41         299 :   auto params = getFactory().getValidParams("INSFVScalarFieldVariable");
      42         299 :   assignBlocks(params, _blocks);
      43         598 :   params.set<MooseEnum>("face_interp_method") =
      44         598 :       getParam<MooseEnum>("passive_scalar_face_interpolation");
      45         299 :   params.set<bool>("two_term_boundary_expansion") =
      46         897 :       getParam<bool>("passive_scalar_two_term_bc_expansion");
      47             : 
      48         674 :   for (const auto name_i : index_range(_passive_scalar_names))
      49             :   {
      50             :     // Dont add if the user already defined the variable
      51         750 :     if (!shouldCreateVariable(_passive_scalar_names[name_i], _blocks, /*error if aux*/ true))
      52             :     {
      53          19 :       reportPotentiallyMissedParameters({"system_names", "passive_scalar_scaling"},
      54             :                                         "INSFVScalarFieldVariable");
      55          19 :       continue;
      56             :     }
      57             : 
      58         356 :     params.set<SolverSystemName>("solver_sys") = getSolverSystem(name_i);
      59         712 :     if (isParamValid("passive_scalar_scaling"))
      60           0 :       params.set<std::vector<Real>>("scaling") = {
      61           0 :           getParam<std::vector<Real>>("passive_scalar_scaling")[name_i]};
      62             : 
      63         712 :     getProblem().addVariable("INSFVScalarFieldVariable", _passive_scalar_names[name_i], params);
      64             :   }
      65         299 : }
      66             : 
      67             : void
      68          27 : WCNSFVScalarTransportPhysics::addScalarTimeKernels()
      69             : {
      70          54 :   for (const auto & vname : _passive_scalar_names)
      71             :   {
      72          27 :     const std::string kernel_type = "FVFunctorTimeKernel";
      73          27 :     InputParameters params = getFactory().getValidParams(kernel_type);
      74          27 :     assignBlocks(params, _blocks);
      75          54 :     params.set<NonlinearVariableName>("variable") = vname;
      76             : 
      77          54 :     if (shouldCreateTimeDerivative(vname, _blocks, /* error if already defined */ false))
      78         108 :       getProblem().addFVKernel(kernel_type, prefix() + "ins_" + vname + "_time", params);
      79          27 :   }
      80          27 : }
      81             : 
      82             : void
      83         283 : WCNSFVScalarTransportPhysics::addScalarAdvectionKernels()
      84             : {
      85             :   const std::string kernel_type =
      86         547 :       _porous_medium_treatment ? "PINSFVScalarFieldAdvection" : "INSFVScalarFieldAdvection";
      87         283 :   InputParameters params = getFactory().getValidParams(kernel_type);
      88             : 
      89         283 :   assignBlocks(params, _blocks);
      90         283 :   params.set<MooseEnum>("velocity_interp_method") = _velocity_interpolation;
      91         566 :   params.set<UserObjectName>("rhie_chow_user_object") = _flow_equations_physics->rhieChowUOName();
      92         566 :   params.set<MooseEnum>("advected_interp_method") =
      93         566 :       getParam<MooseEnum>("passive_scalar_advection_interpolation");
      94         283 :   setSlipVelocityParams(params);
      95         283 :   if (_porous_medium_treatment)
      96          19 :     params.set<MooseFunctorName>(NS::porosity) =
      97          38 :         _flow_equations_physics->getPorosityFunctorName(/*smoothed=*/true);
      98             : 
      99         642 :   for (const auto & vname : _passive_scalar_names)
     100             :   {
     101         359 :     params.set<NonlinearVariableName>("variable") = vname;
     102        1436 :     getProblem().addFVKernel(kernel_type, prefix() + "ins_" + vname + "_advection", params);
     103             :   }
     104         566 : }
     105             : 
     106             : void
     107         283 : WCNSFVScalarTransportPhysics::addScalarDiffusionKernels()
     108             : {
     109             :   // Direct specification of diffusion term
     110             :   const auto passive_scalar_diffusivities =
     111         849 :       getParam<std::vector<MooseFunctorName>>("passive_scalar_diffusivity");
     112             : 
     113         283 :   if (passive_scalar_diffusivities.size())
     114             :   {
     115         242 :     const std::string kernel_type = "FVDiffusion";
     116         242 :     InputParameters params = getFactory().getValidParams(kernel_type);
     117         242 :     assignBlocks(params, _blocks);
     118         560 :     for (const auto name_i : index_range(_passive_scalar_names))
     119             :     {
     120         636 :       params.set<NonlinearVariableName>("variable") = _passive_scalar_names[name_i];
     121         318 :       params.set<MooseFunctorName>("coeff") = passive_scalar_diffusivities[name_i];
     122         636 :       getProblem().addFVKernel(
     123         954 :           kernel_type, prefix() + "ins_" + _passive_scalar_names[name_i] + "_diffusion", params);
     124             :     }
     125         242 :   }
     126         283 : }
     127             : 
     128             : void
     129         219 : WCNSFVScalarTransportPhysics::addScalarSourceKernels()
     130             : {
     131         219 :   const std::string kernel_type = "FVCoupledForce";
     132         219 :   InputParameters params = getFactory().getValidParams(kernel_type);
     133         219 :   assignBlocks(params, _blocks);
     134             : 
     135         514 :   for (const auto scalar_i : index_range(_passive_scalar_names))
     136             :   {
     137         590 :     params.set<NonlinearVariableName>("variable") = _passive_scalar_names[scalar_i];
     138         295 :     if (_passive_scalar_sources.size())
     139             :     {
     140             :       // Added for backward compatibility with former Modules/NavierStokesFV syntax
     141         276 :       params.set<MooseFunctorName>("v") = _passive_scalar_sources[scalar_i];
     142         552 :       getProblem().addFVKernel(
     143         828 :           kernel_type, prefix() + "ins_" + _passive_scalar_names[scalar_i] + "_source", params);
     144             :     }
     145             : 
     146             :     // Sufficient for all intents and purposes
     147         295 :     if (_passive_scalar_coupled_sources.size())
     148         456 :       for (const auto i : index_range(_passive_scalar_coupled_sources[scalar_i]))
     149             :       {
     150         456 :         params.set<MooseFunctorName>("v") = _passive_scalar_coupled_sources[scalar_i][i];
     151         228 :         if (_passive_scalar_sources_coef.size())
     152         228 :           params.set<Real>("coef") = _passive_scalar_sources_coef[scalar_i][i];
     153         456 :         getProblem().addFVKernel(kernel_type,
     154         684 :                                  prefix() + "ins_" + _passive_scalar_names[scalar_i] +
     155         684 :                                      "_coupled_source_" + std::to_string(i),
     156             :                                  params);
     157             :       }
     158             :   }
     159         438 : }
     160             : 
     161             : void
     162         275 : WCNSFVScalarTransportPhysics::addScalarInletBC()
     163             : {
     164         275 :   const auto & inlet_boundaries = _flow_equations_physics->getInletBoundaries();
     165         275 :   if (inlet_boundaries.empty())
     166             :     return;
     167             : 
     168             :   // Boundary checks
     169             :   // TODO: once we have vectors of MooseEnum, we could use the same templated check for types and
     170             :   // functors
     171         266 :   if (inlet_boundaries.size() * _passive_scalar_names.size() != _passive_scalar_inlet_types.size())
     172           0 :     paramError(
     173             :         "passive_scalar_inlet_types",
     174           0 :         "The number of scalar inlet types (" + std::to_string(_passive_scalar_inlet_types.size()) +
     175           0 :             ") is not equal to the number of inlet boundaries (" +
     176           0 :             std::to_string(inlet_boundaries.size()) + ") times the number of passive scalars (" +
     177           0 :             std::to_string(_passive_scalar_names.size()) + ")");
     178         266 :   if (_passive_scalar_names.size() != _passive_scalar_inlet_functors.size())
     179           0 :     paramError("passive_scalar_inlet_functors",
     180           0 :                "The number of groups of inlet functors (" +
     181           0 :                    std::to_string(_passive_scalar_inlet_functors.size()) +
     182           0 :                    ") is not equal to the number of passive scalars (" +
     183           0 :                    std::to_string(_passive_scalar_names.size()) + ")");
     184             : 
     185         608 :   for (const auto name_i : index_range(_passive_scalar_names))
     186             :   {
     187         342 :     if (inlet_boundaries.size() != _passive_scalar_inlet_functors[name_i].size())
     188           0 :       paramError("passive_scalar_inlet_functors",
     189           0 :                  "The number of inlet boundary functors for scalar '" +
     190           0 :                      _passive_scalar_names[name_i] +
     191           0 :                      "' does not match the number of inlet boundaries (" +
     192           0 :                      std::to_string(_passive_scalar_inlet_functors[name_i].size()) + ")");
     193             : 
     194             :     unsigned int flux_bc_counter = 0;
     195         342 :     unsigned int num_inlets = inlet_boundaries.size();
     196         684 :     for (unsigned int bc_ind = 0; bc_ind < num_inlets; ++bc_ind)
     197             :     {
     198         342 :       if (_passive_scalar_inlet_types[name_i * num_inlets + bc_ind] == "fixed-value")
     199             :       {
     200         288 :         const std::string bc_type = "FVADFunctorDirichletBC";
     201         288 :         InputParameters params = getFactory().getValidParams(bc_type);
     202         576 :         params.set<NonlinearVariableName>("variable") = _passive_scalar_names[name_i];
     203         576 :         params.set<MooseFunctorName>("functor") = _passive_scalar_inlet_functors[name_i][bc_ind];
     204         864 :         params.set<std::vector<BoundaryName>>("boundary") = {inlet_boundaries[bc_ind]};
     205             : 
     206         576 :         getProblem().addFVBC(
     207         288 :             bc_type, _passive_scalar_names[name_i] + "_" + inlet_boundaries[bc_ind], params);
     208         288 :       }
     209          54 :       else if (_passive_scalar_inlet_types[name_i * num_inlets + bc_ind] == "flux-mass" ||
     210           9 :                _passive_scalar_inlet_types[name_i * num_inlets + bc_ind] == "flux-velocity")
     211             :       {
     212          54 :         const auto flux_inlet_directions = _flow_equations_physics->getFluxInletDirections();
     213          54 :         const auto flux_inlet_pps = _flow_equations_physics->getFluxInletPPs();
     214             : 
     215          54 :         const std::string bc_type = "WCNSFVScalarFluxBC";
     216          54 :         InputParameters params = getFactory().getValidParams(bc_type);
     217         108 :         params.set<NonlinearVariableName>("variable") = _passive_scalar_names[name_i];
     218         108 :         params.set<MooseFunctorName>("passive_scalar") = _passive_scalar_names[name_i];
     219          54 :         if (flux_inlet_directions.size())
     220          18 :           params.set<Point>("direction") = flux_inlet_directions[flux_bc_counter];
     221          54 :         if (_passive_scalar_inlet_types[name_i * num_inlets + bc_ind] == "flux-mass")
     222             :         {
     223          45 :           params.set<PostprocessorName>("mdot_pp") = flux_inlet_pps[flux_bc_counter];
     224         180 :           params.set<PostprocessorName>("area_pp") = "area_pp_" + inlet_boundaries[bc_ind];
     225             :         }
     226             :         else
     227          18 :           params.set<PostprocessorName>("velocity_pp") = flux_inlet_pps[flux_bc_counter];
     228             : 
     229          54 :         params.set<MooseFunctorName>(NS::density) = _density_name;
     230         108 :         params.set<PostprocessorName>("scalar_value_pp") =
     231         108 :             _passive_scalar_inlet_functors[name_i][bc_ind];
     232         162 :         params.set<std::vector<BoundaryName>>("boundary") = {inlet_boundaries[bc_ind]};
     233             : 
     234          54 :         params.set<MooseFunctorName>(NS::velocity_x) = _velocity_names[0];
     235          54 :         if (dimension() > 1)
     236         108 :           params.set<MooseFunctorName>(NS::velocity_y) = _velocity_names[1];
     237          54 :         if (dimension() > 2)
     238           0 :           params.set<MooseFunctorName>(NS::velocity_z) = _velocity_names[2];
     239             : 
     240         108 :         getProblem().addFVBC(bc_type,
     241         108 :                              prefix() + _passive_scalar_names[name_i] + "_" +
     242             :                                  inlet_boundaries[bc_ind],
     243             :                              params);
     244          54 :         flux_bc_counter += 1;
     245         108 :       }
     246             :     }
     247             :   }
     248             : }
     249             : 
     250             : void
     251         275 : WCNSFVScalarTransportPhysics::addScalarOutletBC()
     252             : {
     253             :   // Advection outlet is naturally handled by the advection flux kernel
     254         275 :   return;
     255             : }

Generated by: LCOV version 1.14