LCOV - code coverage report
Current view: top level - src/actions - CNSAction.C (source / functions) Hit Total Coverage
Test: idaholab/moose navier_stokes: #32971 (54bef8) with base c6cf66 Lines: 421 440 95.7 %
Date: 2026-05-29 20:37:52 Functions: 28 28 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             : // Navier-Stokes includes
      11             : #include "CNSAction.h"
      12             : 
      13             : #include "NS.h"
      14             : #include "AddVariableAction.h"
      15             : #include "MooseObject.h"
      16             : 
      17             : // MOOSE includes
      18             : #include "FEProblem.h"
      19             : 
      20             : #include "libmesh/fe.h"
      21             : #include "libmesh/vector_value.h"
      22             : #include "libmesh/string_to_enum.h"
      23             : 
      24             : using namespace libMesh;
      25             : 
      26             : registerMooseAction("NavierStokesApp", CNSAction, "add_navier_stokes_variables");
      27             : registerMooseAction("NavierStokesApp", CNSAction, "add_navier_stokes_kernels");
      28             : registerMooseAction("NavierStokesApp", CNSAction, "add_navier_stokes_bcs");
      29             : registerMooseAction("NavierStokesApp", CNSAction, "add_navier_stokes_ics");
      30             : 
      31             : InputParameters
      32           9 : CNSAction::validParams()
      33             : {
      34           9 :   InputParameters params = Action::validParams();
      35           9 :   params.addClassDescription("This class allows us to have a section of the input file like the "
      36             :                              "following which automatically adds Kernels and AuxKernels for all "
      37             :                              "the required nonlinear and auxiliary variables.");
      38             : 
      39          18 :   MooseEnum type("steady-state transient", "steady-state");
      40          18 :   params.addParam<MooseEnum>("equation_type", type, "Navier-Stokes equation type");
      41             : 
      42          18 :   params.addParam<std::vector<SubdomainName>>(
      43             :       "block", {}, "The list of block ids (SubdomainID) on which NS equation is defined on");
      44             : 
      45          18 :   params.addRequiredParam<UserObjectName>("fluid_properties",
      46             :                                           "The name of the user object for fluid properties");
      47             : 
      48           9 :   params.addParam<std::vector<BoundaryName>>(
      49           9 :       "stagnation_boundary", std::vector<BoundaryName>(), "Stagnation boundaries");
      50           9 :   params.addParam<std::vector<Real>>(
      51           9 :       "stagnation_pressure", std::vector<Real>(), "Pressure on stagnation boundaries");
      52           9 :   params.addParam<std::vector<Real>>(
      53           9 :       "stagnation_temperature", std::vector<Real>(), "Temperature on stagnation boundaries");
      54           9 :   params.addParam<std::vector<Real>>(
      55           9 :       "stagnation_flow_direction", std::vector<Real>(), "Flow directions on stagnation boundaries");
      56           9 :   params.addParam<std::vector<BoundaryName>>(
      57           9 :       "no_penetration_boundary", std::vector<BoundaryName>(), "No-penetration boundaries");
      58           9 :   params.addParam<std::vector<BoundaryName>>(
      59           9 :       "static_pressure_boundary", std::vector<BoundaryName>(), "Static pressure boundaries");
      60           9 :   params.addParam<std::vector<Real>>(
      61           9 :       "static_pressure", std::vector<Real>(), "Static pressure on boundaries");
      62             : 
      63          27 :   MooseEnum families(AddVariableAction::getNonlinearVariableFamilies(), "LAGRANGE");
      64          27 :   MooseEnum orders(AddVariableAction::getNonlinearVariableOrders(), "FIRST");
      65          18 :   params.addParam<MooseEnum>(
      66             :       "family", families, "Specifies the family of FE shape functions to use for this variable");
      67          18 :   params.addParam<MooseEnum>("order",
      68             :                              orders,
      69             :                              "Specifies the order of the FE shape function to use "
      70             :                              "for this variable (additional orders not listed are "
      71             :                              "allowed)");
      72          18 :   params.addParam<Real>("density_scaling", 1, "Scaling for the density variable");
      73           9 :   params.addParam<RealVectorValue>(
      74           9 :       "momentum_scaling", RealVectorValue(1, 1, 1), "Scaling for the momentum variables");
      75          18 :   params.addParam<Real>("total_energy_density_scaling", 1, "Scaling for the total-energy variable");
      76             : 
      77          18 :   params.addRequiredParam<Real>("initial_pressure",
      78             :                                 "The initial pressure, assumed constant everywhere");
      79          18 :   params.addRequiredParam<Real>("initial_temperature",
      80             :                                 "The initial temperature, assumed constant everywhere");
      81          18 :   params.addRequiredParam<RealVectorValue>("initial_velocity",
      82             :                                            "The initial velocity, assumed constant everywhere");
      83             : 
      84          18 :   params.addParamNamesToGroup("equation_type block fluid_properties", "Base");
      85          18 :   params.addParamNamesToGroup(
      86             :       "stagnation_boundary stagnation_pressure stagnation_temperature "
      87             :       "stagnation_flow_direction no_penetration_boundary static_pressure_boundary static_pressure",
      88             :       "BoundaryCondition");
      89          18 :   params.addParamNamesToGroup(
      90             :       "family order density_scaling momentum_scaling total_energy_density_scaling", "Variable");
      91          18 :   params.addParam<std::string>("pressure_variable_name",
      92             :                                "A name for the pressure variable. If this is not provided, a "
      93             :                                "sensible default will be used.");
      94           9 :   return params;
      95           9 : }
      96             : 
      97           9 : CNSAction::CNSAction(const InputParameters & parameters)
      98             :   : Action(parameters),
      99           9 :     _type(getParam<MooseEnum>("equation_type")),
     100           9 :     _fp_name(getParam<UserObjectName>("fluid_properties")),
     101          18 :     _blocks(getParam<std::vector<SubdomainName>>("block")),
     102          18 :     _stagnation_boundary(getParam<std::vector<BoundaryName>>("stagnation_boundary")),
     103          18 :     _stagnation_pressure(getParam<std::vector<Real>>("stagnation_pressure")),
     104          18 :     _stagnation_temperature(getParam<std::vector<Real>>("stagnation_temperature")),
     105          18 :     _stagnation_direction(getParam<std::vector<Real>>("stagnation_flow_direction")),
     106          18 :     _no_penetration_boundary(getParam<std::vector<BoundaryName>>("no_penetration_boundary")),
     107          18 :     _static_pressure_boundary(getParam<std::vector<BoundaryName>>("static_pressure_boundary")),
     108          18 :     _static_pressure(getParam<std::vector<Real>>("static_pressure")),
     109          27 :     _fe_type(Utility::string_to_enum<Order>(getParam<MooseEnum>("order")),
     110           9 :              Utility::string_to_enum<FEFamily>(getParam<MooseEnum>("family"))),
     111          18 :     _initial_pressure(getParam<Real>("initial_pressure")),
     112          18 :     _initial_temperature(getParam<Real>("initial_temperature")),
     113          18 :     _initial_velocity(getParam<RealVectorValue>("initial_velocity")),
     114          36 :     _pressure_variable_name(isParamValid("pressure_variable_name")
     115           9 :                                 ? getParam<std::string>("pressure_variable_name")
     116           9 :                                 : "p")
     117             : {
     118           9 :   if (_stagnation_pressure.size() != _stagnation_boundary.size())
     119           0 :     paramError("stagnation_pressure",
     120             :                "Size is not the same as the number of boundaries in 'stagnation_boundary'");
     121           9 :   if (_stagnation_temperature.size() != _stagnation_boundary.size())
     122           0 :     paramError("stagnation_temperature",
     123             :                "Size is not the same as the number of boundaries in 'stagnation_boundary'");
     124           9 :   if (_static_pressure.size() != _static_pressure_boundary.size())
     125           0 :     paramError("static_pressure",
     126             :                "Size is not the same as the number of boundaries in 'static_pressure_boundary'");
     127           9 : }
     128             : 
     129             : void
     130          36 : CNSAction::act()
     131             : {
     132          36 :   if (_current_task == "add_navier_stokes_variables")
     133             :   {
     134           9 :     _dim = _mesh->dimension();
     135           9 :     for (const auto & subdomain_name : _blocks)
     136             :     {
     137           0 :       SubdomainID id = _mesh->getSubdomainID(subdomain_name);
     138           0 :       _block_ids.insert(id);
     139             :     }
     140           9 :     if (_stagnation_direction.size() != _stagnation_boundary.size() * _dim)
     141           0 :       paramError("stagnation_flow_direction",
     142             :                  "Size is not the same as the number of boundaries in 'stagnation_boundary' times "
     143             :                  "the mesh dimension");
     144             : 
     145             :     // FIXME: need to check boundaries are non-overlapping and enclose the blocks
     146             : 
     147           9 :     auto var_type = AddVariableAction::variableType(_fe_type);
     148           9 :     auto base_params = _factory.getValidParams(var_type);
     149           9 :     base_params.set<MooseEnum>("order") = _fe_type.order.get_order();
     150          18 :     base_params.set<MooseEnum>("family") = Moose::stringify(_fe_type.family);
     151           9 :     if (_block_ids.size() != 0)
     152           0 :       for (const SubdomainID & id : _block_ids)
     153           0 :         base_params.set<std::vector<SubdomainName>>("block").push_back(Moose::stringify(id));
     154             : 
     155             :     // add primal variables
     156           9 :     InputParameters params(base_params);
     157          27 :     params.set<std::vector<Real>>("scaling") = {getParam<Real>("density_scaling")};
     158           9 :     _problem->addVariable(var_type, NS::density, params);
     159             : 
     160          18 :     auto mscaling = getParam<RealVectorValue>("momentum_scaling");
     161           9 :     params.set<std::vector<Real>>("scaling") = {mscaling(0)};
     162           9 :     _problem->addVariable(var_type, NS::momentum_x, params);
     163           9 :     if (_dim >= 2)
     164             :     {
     165           9 :       params.set<std::vector<Real>>("scaling") = {mscaling(1)};
     166           9 :       _problem->addVariable(var_type, NS::momentum_y, params);
     167             :     }
     168           9 :     if (_dim >= 3)
     169             :     {
     170           0 :       params.set<std::vector<Real>>("scaling") = {mscaling(2)};
     171           0 :       _problem->addVariable(var_type, NS::momentum_z, params);
     172             :     }
     173          27 :     params.set<std::vector<Real>>("scaling") = {getParam<Real>("total_energy_density_scaling")};
     174           9 :     _problem->addVariable(var_type, NS::total_energy_density, params);
     175             : 
     176             :     // Add Aux variables.  These are all required in order for the code
     177             :     // to run, so they should not be independently selectable by the
     178             :     // user.
     179           9 :     _problem->addAuxVariable(var_type, NS::velocity_x, base_params);
     180           9 :     if (_dim >= 2)
     181           9 :       _problem->addAuxVariable(var_type, NS::velocity_y, base_params);
     182           9 :     if (_dim >= 3)
     183           0 :       _problem->addAuxVariable(var_type, NS::velocity_z, base_params);
     184           9 :     _problem->addAuxVariable(var_type, _pressure_variable_name, base_params);
     185           9 :     _problem->addAuxVariable(var_type, NS::temperature, base_params);
     186           9 :     _problem->addAuxVariable(var_type, NS::specific_total_enthalpy, base_params);
     187           9 :     _problem->addAuxVariable(var_type, NS::mach_number, base_params);
     188             : 
     189             :     // Needed for FluidProperties calculations
     190           9 :     _problem->addAuxVariable(var_type, NS::specific_internal_energy, base_params);
     191           9 :     _problem->addAuxVariable(var_type, NS::specific_volume, base_params);
     192           9 :   }
     193             : 
     194          36 :   if (_current_task == "add_navier_stokes_kernels")
     195             :   {
     196           9 :     if (_type == "transient")
     197           9 :       addNSTimeKernels();
     198             : 
     199             :     // Add all the inviscid flux Kernels.
     200           9 :     addNSMassInviscidFlux();
     201           9 :     addNSEnergyInviscidFlux();
     202          27 :     for (unsigned int component = 0; component < _dim; ++component)
     203          18 :       addNSMomentumInviscidFlux(component);
     204             : 
     205             :     // Add SUPG Kernels
     206           9 :     addNSSUPGMass();
     207           9 :     addNSSUPGEnergy();
     208          27 :     for (unsigned int component = 0; component < _dim; ++component)
     209          18 :       addNSSUPGMomentum(component);
     210             : 
     211             :     // Add AuxKernels.
     212           9 :     addPressureOrTemperatureAux("PressureAux");
     213           9 :     addPressureOrTemperatureAux("TemperatureAux");
     214           9 :     addSpecificTotalEnthalpyAux();
     215           9 :     addNSMachAux();
     216           9 :     addNSInternalEnergyAux();
     217           9 :     addSpecificVolumeComputation();
     218          27 :     for (unsigned int component = 0; component < _dim; ++component)
     219          18 :       addNSVelocityAux(component);
     220             :   }
     221             : 
     222          36 :   if (_current_task == "add_navier_stokes_bcs")
     223             :   {
     224           9 :     if (_stagnation_boundary.size() > 0)
     225             :     {
     226           9 :       addNSMassWeakStagnationBC();
     227           9 :       addNSEnergyWeakStagnationBC();
     228          27 :       for (unsigned int component = 0; component < _dim; ++component)
     229          18 :         addNSMomentumWeakStagnationBC(component);
     230             :     }
     231             : 
     232           9 :     if (_no_penetration_boundary.size() > 0)
     233             :     {
     234          27 :       for (unsigned int component = 0; component < _dim; ++component)
     235          18 :         addNoPenetrationBC(component);
     236             :     }
     237             : 
     238           9 :     if (_static_pressure_boundary.size() > 0)
     239             :     {
     240           9 :       addNSMassUnspecifiedNormalFlowBC();
     241           9 :       addNSEnergyInviscidSpecifiedPressureBC();
     242          27 :       for (unsigned int component = 0; component < _dim; ++component)
     243          18 :         addNSMomentumInviscidSpecifiedPressureBC(component);
     244             :     }
     245             :   }
     246             : 
     247          36 :   if (_current_task == "add_navier_stokes_ics")
     248             :   {
     249             :     // add ICs for primal variables
     250             :     std::vector<VariableName> vars;
     251           9 :     vars.push_back(NS::density);
     252           9 :     vars.push_back(NS::momentum_x);
     253           9 :     if (_dim >= 2)
     254           9 :       vars.push_back(NS::momentum_y);
     255           9 :     if (_dim >= 3)
     256           0 :       vars.push_back(NS::momentum_z);
     257           9 :     vars.push_back(NS::total_energy_density);
     258          45 :     for (const auto & name : vars)
     259             :     {
     260          36 :       InputParameters params = _factory.getValidParams("NSInitialCondition");
     261          36 :       params.set<VariableName>("variable") = name;
     262          36 :       params.set<Real>("initial_pressure") = _initial_pressure;
     263          36 :       params.set<Real>("initial_temperature") = _initial_temperature;
     264          36 :       params.set<RealVectorValue>("initial_velocity") = _initial_velocity;
     265          36 :       params.set<UserObjectName>("fluid_properties") = _fp_name;
     266          72 :       _problem->addInitialCondition("NSInitialCondition", name + std::string("_ic"), params);
     267          36 :     }
     268             : 
     269             :     // add ICs for aux variables (possibly we do not need this)
     270             :     std::vector<VariableName> auxs;
     271           9 :     auxs.push_back(NS::velocity_x);
     272           9 :     if (_dim >= 2)
     273           9 :       auxs.push_back(NS::velocity_y);
     274           9 :     if (_dim >= 3)
     275           0 :       auxs.push_back(NS::velocity_z);
     276             : 
     277          18 :     auxs.push_back(_pressure_variable_name);
     278           9 :     auxs.push_back(NS::temperature);
     279           9 :     auxs.push_back(NS::specific_total_enthalpy);
     280           9 :     auxs.push_back(NS::mach_number);
     281             : 
     282             :     // Needed for FluidProperties calculations
     283           9 :     auxs.push_back(NS::specific_internal_energy);
     284           9 :     auxs.push_back(NS::specific_volume);
     285          81 :     for (const auto & name : auxs)
     286             :     {
     287          72 :       InputParameters params = _factory.getValidParams("NSInitialCondition");
     288          72 :       params.set<VariableName>("variable") = name;
     289          72 :       params.set<Real>("initial_pressure") = _initial_pressure;
     290          72 :       params.set<Real>("initial_temperature") = _initial_temperature;
     291          72 :       params.set<RealVectorValue>("initial_velocity") = _initial_velocity;
     292          72 :       params.set<UserObjectName>("fluid_properties") = _fp_name;
     293          72 :       if (name == _pressure_variable_name)
     294          18 :         params.set<MooseEnum>("variable_type") = NS::pressure;
     295         144 :       _problem->addInitialCondition("NSInitialCondition", name + std::string("_ic"), params);
     296          72 :     }
     297           9 :   }
     298          36 : }
     299             : 
     300             : void
     301           9 : CNSAction::addNSTimeKernels()
     302             : {
     303           9 :   const std::string kernel_type = "TimeDerivative";
     304           9 :   InputParameters params = _factory.getValidParams(kernel_type);
     305          18 :   params.set<std::vector<SubdomainName>>("block") = _blocks;
     306             : 
     307          18 :   params.set<NonlinearVariableName>("variable") = NS::density;
     308          18 :   _problem->addKernel(kernel_type, NS::density + "_time_deriv", params);
     309             : 
     310          18 :   params.set<NonlinearVariableName>("variable") = NS::momentum_x;
     311           9 :   _problem->addKernel(kernel_type, NS::momentum_x + "_time_deriv", params);
     312           9 :   if (_dim >= 2)
     313             :   {
     314          18 :     params.set<NonlinearVariableName>("variable") = NS::momentum_y;
     315          18 :     _problem->addKernel(kernel_type, NS::momentum_y + "_time_deriv", params);
     316             :   }
     317           9 :   if (_dim >= 3)
     318             :   {
     319           0 :     params.set<NonlinearVariableName>("variable") = NS::momentum_z;
     320           0 :     _problem->addKernel(kernel_type, NS::momentum_z + "_time_deriv", params);
     321             :   }
     322             : 
     323          18 :   params.set<NonlinearVariableName>("variable") = NS::total_energy_density;
     324           9 :   _problem->addKernel(kernel_type, NS::total_energy_density + "_time_deriv", params);
     325          18 : }
     326             : 
     327             : void
     328           9 : CNSAction::addNSSUPGMass()
     329             : {
     330           9 :   const std::string kernel_type = "NSSUPGMass";
     331           9 :   InputParameters params = _factory.getValidParams(kernel_type);
     332          18 :   params.set<NonlinearVariableName>("variable") = NS::density;
     333           9 :   setKernelCommonParams(params);
     334             : 
     335             :   // SUPG Kernels also need temperature and specific_total_enthalpy currently.
     336          27 :   params.set<CoupledName>(NS::temperature) = {NS::temperature};
     337          27 :   params.set<CoupledName>(NS::specific_total_enthalpy) = {NS::specific_total_enthalpy};
     338             : 
     339           9 :   _problem->addKernel(kernel_type, "rho_supg", params);
     340          18 : }
     341             : 
     342             : void
     343          18 : CNSAction::addNSSUPGMomentum(unsigned int component)
     344             : {
     345          18 :   const static std::string momentums[3] = {NS::momentum_x, NS::momentum_y, NS::momentum_z};
     346             : 
     347          18 :   const std::string kernel_type = "NSSUPGMomentum";
     348          18 :   InputParameters params = _factory.getValidParams(kernel_type);
     349          36 :   params.set<NonlinearVariableName>("variable") = momentums[component];
     350          18 :   setKernelCommonParams(params);
     351             : 
     352             :   // SUPG Kernels also need temperature and specific_total_enthalpy currently.
     353          54 :   params.set<CoupledName>(NS::temperature) = {NS::temperature};
     354          54 :   params.set<CoupledName>(NS::specific_total_enthalpy) = {NS::specific_total_enthalpy};
     355             : 
     356             :   // Momentum Kernels also need the component.
     357          18 :   params.set<unsigned int>("component") = component;
     358             : 
     359          18 :   _problem->addKernel(kernel_type, momentums[component] + std::string("_supg"), params);
     360          36 : }
     361             : 
     362             : void
     363           9 : CNSAction::addNSSUPGEnergy()
     364             : {
     365           9 :   const std::string kernel_type = "NSSUPGEnergy";
     366           9 :   InputParameters params = _factory.getValidParams(kernel_type);
     367          18 :   params.set<NonlinearVariableName>("variable") = NS::total_energy_density;
     368           9 :   setKernelCommonParams(params);
     369             : 
     370             :   // SUPG Kernels also need temperature and specific_total_enthalpy currently.
     371          27 :   params.set<CoupledName>(NS::temperature) = {NS::temperature};
     372          27 :   params.set<CoupledName>(NS::specific_total_enthalpy) = {NS::specific_total_enthalpy};
     373             : 
     374           9 :   _problem->addKernel(kernel_type, "rhoE_supg", params);
     375          18 : }
     376             : 
     377             : void
     378           9 : CNSAction::addSpecificVolumeComputation()
     379             : {
     380           9 :   const std::string kernel_type = "ParsedAux";
     381             : 
     382           9 :   InputParameters params = _factory.getValidParams(kernel_type);
     383          18 :   params.set<AuxVariableName>("variable") = NS::specific_volume;
     384             : 
     385             :   // arguments
     386          27 :   params.set<CoupledName>("coupled_variables") = {NS::density};
     387             : 
     388             :   // expression
     389          18 :   std::string function = "if(" + NS::density + " = 0, 1e10, 1 / " + NS::density + ")";
     390           9 :   params.set<std::string>("expression") = function;
     391             : 
     392          18 :   _problem->addAuxKernel(kernel_type, "specific_volume_auxkernel", params);
     393          18 : }
     394             : 
     395             : void
     396           9 : CNSAction::addNSInternalEnergyAux()
     397             : {
     398           9 :   const std::string kernel_type = "NSInternalEnergyAux";
     399             : 
     400           9 :   InputParameters params = _factory.getValidParams(kernel_type);
     401          18 :   params.set<AuxVariableName>("variable") = NS::specific_internal_energy;
     402             : 
     403             :   // coupled variables
     404          27 :   params.set<CoupledName>(NS::density) = {NS::density};
     405          27 :   params.set<CoupledName>(NS::total_energy_density) = {NS::total_energy_density};
     406             : 
     407             :   // Couple the appropriate number of velocities
     408           9 :   coupleVelocities(params);
     409             : 
     410           9 :   _problem->addAuxKernel(kernel_type, "specific_internal_energy_auxkernel", params);
     411          18 : }
     412             : 
     413             : void
     414           9 : CNSAction::addNSMachAux()
     415             : {
     416           9 :   const std::string kernel_type = "NSMachAux";
     417             : 
     418           9 :   InputParameters params = _factory.getValidParams(kernel_type);
     419          18 :   params.set<AuxVariableName>("variable") = NS::mach_number;
     420             : 
     421             :   // coupled variables
     422          27 :   params.set<CoupledName>(NS::specific_internal_energy) = {NS::specific_internal_energy};
     423          27 :   params.set<CoupledName>(NS::specific_volume) = {NS::specific_volume};
     424             : 
     425             :   // Couple the appropriate number of velocities
     426           9 :   coupleVelocities(params);
     427             : 
     428           9 :   params.set<UserObjectName>("fluid_properties") = _fp_name;
     429             : 
     430           9 :   _problem->addAuxKernel(kernel_type, "mach_auxkernel", params);
     431          18 : }
     432             : 
     433             : void
     434           9 : CNSAction::addSpecificTotalEnthalpyAux()
     435             : {
     436           9 :   const std::string kernel_type = "NSSpecificTotalEnthalpyAux";
     437             : 
     438           9 :   InputParameters params = _factory.getValidParams(kernel_type);
     439          18 :   params.set<AuxVariableName>("variable") = NS::specific_total_enthalpy;
     440             : 
     441             :   // coupled variables
     442          27 :   params.set<CoupledName>(NS::density) = {NS::density};
     443          27 :   params.set<CoupledName>(NS::total_energy_density) = {NS::total_energy_density};
     444          27 :   params.set<CoupledName>(NS::pressure) = {_pressure_variable_name};
     445             : 
     446           9 :   _problem->addAuxKernel(kernel_type, "specific_total_enthalpy_auxkernel", params);
     447          18 : }
     448             : 
     449             : void
     450          18 : CNSAction::addNSVelocityAux(unsigned int component)
     451             : {
     452          18 :   const std::string kernel_type = "NSVelocityAux";
     453          18 :   const static std::string velocities[3] = {NS::velocity_x, NS::velocity_y, NS::velocity_z};
     454          18 :   const static std::string momentums[3] = {NS::momentum_x, NS::momentum_y, NS::momentum_z};
     455             : 
     456          18 :   InputParameters params = _factory.getValidParams(kernel_type);
     457          36 :   params.set<AuxVariableName>("variable") = velocities[component];
     458             : 
     459             :   // coupled variables
     460          54 :   params.set<CoupledName>(NS::density) = {NS::density};
     461          54 :   params.set<CoupledName>("momentum") = {momentums[component]};
     462          18 :   params.set<UserObjectName>("fluid_properties") = _fp_name;
     463             : 
     464          18 :   _problem->addAuxKernel(kernel_type, velocities[component] + "_auxkernel", params);
     465          36 : }
     466             : 
     467             : void
     468          18 : CNSAction::addPressureOrTemperatureAux(const std::string & kernel_type)
     469             : {
     470          18 :   InputParameters params = _factory.getValidParams(kernel_type);
     471          18 :   std::string var_name = (kernel_type == "PressureAux" ? _pressure_variable_name : NS::temperature);
     472          36 :   params.set<AuxVariableName>("variable") = var_name;
     473             : 
     474             :   // coupled variables
     475          54 :   params.set<CoupledName>("e") = {NS::specific_internal_energy};
     476          54 :   params.set<CoupledName>("v") = {NS::specific_volume};
     477          18 :   params.set<UserObjectName>("fp") = _fp_name;
     478             : 
     479          36 :   _problem->addAuxKernel(kernel_type, var_name + "_auxkernel", params);
     480          18 : }
     481             : 
     482             : void
     483           9 : CNSAction::addNSMassInviscidFlux()
     484             : {
     485           9 :   const std::string kernel_type = "NSMassInviscidFlux";
     486           9 :   InputParameters params = _factory.getValidParams(kernel_type);
     487          18 :   params.set<NonlinearVariableName>("variable") = NS::density;
     488           9 :   setKernelCommonParams(params);
     489           9 :   _problem->addKernel(kernel_type, "rho_if", params);
     490          18 : }
     491             : 
     492             : void
     493          18 : CNSAction::addNSMomentumInviscidFlux(unsigned int component)
     494             : {
     495          18 :   const static std::string momentums[3] = {NS::momentum_x, NS::momentum_y, NS::momentum_z};
     496          18 :   const std::string kernel_type = "NSMomentumInviscidFlux";
     497          18 :   InputParameters params = _factory.getValidParams(kernel_type);
     498          36 :   params.set<NonlinearVariableName>("variable") = momentums[component];
     499          18 :   setKernelCommonParams(params);
     500             : 
     501             :   // Extra stuff needed by momentum Kernels
     502          54 :   params.set<CoupledName>(NS::pressure) = {_pressure_variable_name};
     503          18 :   params.set<unsigned int>("component") = component;
     504             : 
     505             :   // Add the Kernel
     506          18 :   _problem->addKernel(kernel_type, momentums[component] + std::string("if"), params);
     507          36 : }
     508             : 
     509             : void
     510           9 : CNSAction::addNSEnergyInviscidFlux()
     511             : {
     512           9 :   const std::string kernel_type = "NSEnergyInviscidFlux";
     513           9 :   InputParameters params = _factory.getValidParams(kernel_type);
     514          18 :   params.set<NonlinearVariableName>("variable") = NS::total_energy_density;
     515           9 :   setKernelCommonParams(params);
     516             : 
     517             :   // Extra stuff needed by energy equation
     518          27 :   params.set<CoupledName>(NS::specific_total_enthalpy) = {NS::specific_total_enthalpy};
     519             : 
     520             :   // Add the Kernel
     521           9 :   _problem->addKernel(kernel_type, "rhoE_if", params);
     522          18 : }
     523             : 
     524             : void
     525           9 : CNSAction::addNSMassWeakStagnationBC()
     526             : {
     527           9 :   const std::string kernel_type = "NSMassWeakStagnationBC";
     528           9 :   InputParameters params = _factory.getValidParams(kernel_type);
     529          18 :   params.set<NonlinearVariableName>("variable") = NS::density;
     530           9 :   setBCCommonParams(params);
     531             : 
     532          18 :   for (unsigned int i = 0; i < _stagnation_boundary.size(); ++i)
     533             :   {
     534           9 :     setStagnationBCCommonParams(params, i);
     535          18 :     _problem->addBoundaryCondition(
     536          18 :         kernel_type, "weak_stagnation_mass_inflow_" + Moose::stringify(i), params);
     537             :   }
     538          18 : }
     539             : 
     540             : void
     541           9 : CNSAction::addNSEnergyWeakStagnationBC()
     542             : {
     543           9 :   const std::string kernel_type = "NSEnergyWeakStagnationBC";
     544           9 :   InputParameters params = _factory.getValidParams(kernel_type);
     545          18 :   params.set<NonlinearVariableName>("variable") = NS::total_energy_density;
     546           9 :   setBCCommonParams(params);
     547          18 :   for (unsigned int i = 0; i < _stagnation_boundary.size(); ++i)
     548             :   {
     549           9 :     setStagnationBCCommonParams(params, i);
     550          18 :     _problem->addBoundaryCondition(
     551          18 :         kernel_type, "weak_stagnation_energy_inflow_" + Moose::stringify(i), params);
     552             :   }
     553          18 : }
     554             : 
     555             : void
     556          18 : CNSAction::addNSMomentumWeakStagnationBC(unsigned int component)
     557             : {
     558          18 :   const static std::string momentums[3] = {NS::momentum_x, NS::momentum_y, NS::momentum_z};
     559             : 
     560             :   // Convective part
     561             :   {
     562          18 :     const std::string kernel_type = "NSMomentumConvectiveWeakStagnationBC";
     563          18 :     InputParameters params = _factory.getValidParams(kernel_type);
     564          36 :     params.set<NonlinearVariableName>("variable") = momentums[component];
     565          18 :     setBCCommonParams(params);
     566             :     // Momentum BCs also need the component.
     567          18 :     params.set<unsigned int>("component") = component;
     568          36 :     for (unsigned int i = 0; i < _stagnation_boundary.size(); ++i)
     569             :     {
     570          18 :       setStagnationBCCommonParams(params, i);
     571          36 :       _problem->addBoundaryCondition(kernel_type,
     572          36 :                                      std::string("weak_stagnation_") + momentums[component] +
     573          54 :                                          std::string("_convective_inflow_") + Moose::stringify(i),
     574             :                                      params);
     575             :     }
     576          18 :   }
     577             : 
     578             :   // Pressure part
     579             :   {
     580          18 :     const std::string kernel_type = "NSMomentumPressureWeakStagnationBC";
     581          18 :     InputParameters params = _factory.getValidParams(kernel_type);
     582          36 :     params.set<NonlinearVariableName>("variable") = momentums[component];
     583          18 :     setBCCommonParams(params);
     584             :     // Momentum BCs also need the component.
     585          18 :     params.set<unsigned int>("component") = component;
     586             : 
     587          36 :     for (unsigned int i = 0; i < _stagnation_boundary.size(); ++i)
     588             :     {
     589          18 :       setStagnationBCCommonParams(params, i);
     590             : 
     591          36 :       _problem->addBoundaryCondition(kernel_type,
     592          36 :                                      std::string("weak_stagnation_") + momentums[component] +
     593          54 :                                          std::string("_pressure_inflow_") + Moose::stringify(i),
     594             :                                      params);
     595             :     }
     596          18 :   }
     597          18 : }
     598             : 
     599             : void
     600          18 : CNSAction::addNoPenetrationBC(unsigned int component)
     601             : {
     602          18 :   const static std::string momentums[3] = {NS::momentum_x, NS::momentum_y, NS::momentum_z};
     603          18 :   const std::string kernel_type = "NSPressureNeumannBC";
     604          18 :   InputParameters params = _factory.getValidParams(kernel_type);
     605          36 :   params.set<NonlinearVariableName>("variable") = momentums[component];
     606          18 :   setBCCommonParams(params);
     607             : 
     608             :   // These BCs also need the component and couping to the pressure.
     609          18 :   params.set<unsigned int>("component") = component;
     610          54 :   params.set<CoupledName>(NS::pressure) = {_pressure_variable_name};
     611             : 
     612          18 :   params.set<std::vector<BoundaryName>>("boundary") = _no_penetration_boundary;
     613          36 :   _problem->addBoundaryCondition(
     614          18 :       kernel_type, momentums[component] + std::string("_no_penetration"), params);
     615          36 : }
     616             : 
     617             : void
     618           9 : CNSAction::addNSMassUnspecifiedNormalFlowBC()
     619             : {
     620           9 :   const std::string kernel_type = "NSMassUnspecifiedNormalFlowBC";
     621           9 :   InputParameters params = _factory.getValidParams(kernel_type);
     622          18 :   params.set<NonlinearVariableName>("variable") = NS::density;
     623           9 :   setBCCommonParams(params);
     624          18 :   for (unsigned int i = 0; i < _static_pressure_boundary.size(); ++i)
     625             :   {
     626          27 :     params.set<std::vector<BoundaryName>>("boundary") = {_static_pressure_boundary[i]};
     627           9 :     params.set<Real>("specified_pressure") = _static_pressure[i];
     628          18 :     _problem->addBoundaryCondition(kernel_type, "mass_outflow_" + Moose::stringify(i), params);
     629             :   }
     630          18 : }
     631             : 
     632             : void
     633          18 : CNSAction::addNSMomentumInviscidSpecifiedPressureBC(unsigned int component)
     634             : {
     635          18 :   const static std::string momentums[3] = {NS::momentum_x, NS::momentum_y, NS::momentum_z};
     636          18 :   const std::string kernel_type = "NSMomentumInviscidSpecifiedPressureBC";
     637          18 :   InputParameters params = _factory.getValidParams(kernel_type);
     638          36 :   params.set<NonlinearVariableName>("variable") = momentums[component];
     639          18 :   setBCCommonParams(params);
     640             : 
     641             :   // These BCs also need the component.
     642          18 :   params.set<unsigned int>("component") = component;
     643             : 
     644          36 :   for (unsigned int i = 0; i < _static_pressure_boundary.size(); ++i)
     645             :   {
     646          54 :     params.set<std::vector<BoundaryName>>("boundary") = {_static_pressure_boundary[i]};
     647          18 :     params.set<Real>("specified_pressure") = _static_pressure[i];
     648          36 :     _problem->addBoundaryCondition(
     649             :         kernel_type,
     650          36 :         momentums[component] + std::string("_specified_pressure_outflow_") + Moose::stringify(i),
     651             :         params);
     652             :   }
     653          36 : }
     654             : 
     655             : void
     656           9 : CNSAction::addNSEnergyInviscidSpecifiedPressureBC()
     657             : {
     658           9 :   const std::string kernel_type = "NSEnergyInviscidSpecifiedPressureBC";
     659           9 :   InputParameters params = _factory.getValidParams(kernel_type);
     660          18 :   params.set<NonlinearVariableName>("variable") = NS::total_energy_density;
     661           9 :   setBCCommonParams(params);
     662             :   // This BC also requires the current value of the temperature.
     663          27 :   params.set<CoupledName>(NS::temperature) = {NS::temperature};
     664          18 :   for (unsigned int i = 0; i < _static_pressure_boundary.size(); ++i)
     665             :   {
     666          27 :     params.set<std::vector<BoundaryName>>("boundary") = {_static_pressure_boundary[i]};
     667           9 :     params.set<Real>("specified_pressure") = _static_pressure[i];
     668          18 :     _problem->addBoundaryCondition(
     669          18 :         kernel_type, "rhoE_specified_pressure_outflow_" + Moose::stringify(i), params);
     670             :   }
     671          18 : }
     672             : 
     673             : void
     674          72 : CNSAction::setKernelCommonParams(InputParameters & params)
     675             : {
     676         144 :   params.set<std::vector<SubdomainName>>("block") = _blocks;
     677             : 
     678             :   // coupled variables
     679         216 :   params.set<CoupledName>(NS::density) = {NS::density};
     680         216 :   params.set<CoupledName>(NS::total_energy_density) = {NS::total_energy_density};
     681             : 
     682             :   // Couple the appropriate number of velocities
     683          72 :   coupleVelocities(params);
     684          72 :   coupleMomentums(params);
     685             : 
     686             :   // FluidProperties object
     687          72 :   params.set<UserObjectName>("fluid_properties") = _fp_name;
     688          72 : }
     689             : 
     690             : void
     691         108 : CNSAction::setBCCommonParams(InputParameters & params)
     692             : {
     693             :   // coupled variables
     694         324 :   params.set<CoupledName>(NS::density) = {NS::density};
     695         324 :   params.set<CoupledName>(NS::total_energy_density) = {NS::total_energy_density};
     696             : 
     697             :   // Couple the appropriate number of velocities
     698         108 :   coupleVelocities(params);
     699         108 :   coupleMomentums(params);
     700             : 
     701             :   // FluidProperties object
     702         108 :   params.set<UserObjectName>("fluid_properties") = _fp_name;
     703         108 : }
     704             : 
     705             : void
     706          54 : CNSAction::setStagnationBCCommonParams(InputParameters & params, unsigned int i)
     707             : {
     708         162 :   params.set<std::vector<BoundaryName>>("boundary") = {_stagnation_boundary[i]};
     709          54 :   params.set<Real>("stagnation_pressure") = _stagnation_pressure[i];
     710          54 :   params.set<Real>("stagnation_temperature") = _stagnation_temperature[i];
     711          54 :   params.set<Real>("sx") = _stagnation_direction[_dim * i];
     712          54 :   if (_dim == 1)
     713           0 :     params.set<Real>("sy") = 0;
     714          54 :   if (_dim >= 2)
     715          54 :     params.set<Real>("sy") = _stagnation_direction[_dim * i + 1];
     716          54 :   if (_dim >= 3)
     717           0 :     params.set<Real>("sz") = _stagnation_direction[_dim * i + 2];
     718          54 : }
     719             : 
     720             : void
     721         198 : CNSAction::coupleVelocities(InputParameters & params)
     722             : {
     723         594 :   params.set<CoupledName>(NS::velocity_x) = {NS::velocity_x};
     724             : 
     725         198 :   if (_dim >= 2)
     726         594 :     params.set<CoupledName>(NS::velocity_y) = {NS::velocity_y};
     727             : 
     728         198 :   if (_dim >= 3)
     729           0 :     params.set<CoupledName>(NS::velocity_z) = {NS::velocity_z};
     730         198 : }
     731             : 
     732             : void
     733         180 : CNSAction::coupleMomentums(InputParameters & params)
     734             : {
     735         540 :   params.set<CoupledName>(NS::momentum_x) = {NS::momentum_x};
     736             : 
     737         180 :   if (_dim >= 2)
     738         540 :     params.set<CoupledName>(NS::momentum_y) = {NS::momentum_y};
     739             : 
     740         180 :   if (_dim >= 3)
     741           0 :     params.set<CoupledName>(NS::momentum_z) = {NS::momentum_z};
     742         180 : }

Generated by: LCOV version 1.14