LCOV - code coverage report
Current view: top level - src/ics - PNSInitialCondition.C (source / functions) Hit Total Coverage
Test: idaholab/moose navier_stokes: 9fc4b0 Lines: 74 79 93.7 %
Date: 2025-08-14 10:14:56 Functions: 3 3 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 "NS.h"
      12             : #include "PNSInitialCondition.h"
      13             : 
      14             : // FluidProperties includes
      15             : #include "IdealGasFluidProperties.h"
      16             : 
      17             : // MOOSE includes
      18             : #include "MooseVariable.h"
      19             : 
      20             : registerMooseObject("NavierStokesApp", PNSInitialCondition);
      21             : 
      22             : InputParameters
      23        1886 : PNSInitialCondition::validParams()
      24             : {
      25        1886 :   InputParameters params = InitialCondition::validParams();
      26        1886 :   params.addClassDescription(
      27             :       "PNSInitialCondition sets intial constant values for any porous flow variable.");
      28             : 
      29             :   MooseEnum variable_types(
      30       49036 :       MooseUtils::join(std::vector<std::string>{NS::specific_total_enthalpy,
      31             :                                                 NS::specific_internal_energy,
      32             :                                                 NS::mach_number,
      33             :                                                 NS::pressure,
      34             :                                                 NS::density,
      35             :                                                 NS::momentum_x,
      36             :                                                 NS::momentum_y,
      37             :                                                 NS::momentum_z,
      38             :                                                 NS::total_energy_density,
      39             :                                                 NS::specific_volume,
      40             :                                                 NS::temperature,
      41             :                                                 NS::velocity_x,
      42             :                                                 NS::velocity_y,
      43             :                                                 NS::velocity_z,
      44             :                                                 NS::superficial_velocity_x,
      45             :                                                 NS::superficial_velocity_y,
      46             :                                                 NS::superficial_velocity_z,
      47             :                                                 NS::superficial_density,
      48             :                                                 NS::superficial_momentum_x,
      49             :                                                 NS::superficial_momentum_y,
      50             :                                                 NS::superficial_momentum_z,
      51             :                                                 NS::superficial_total_energy_density,
      52       43378 :                                                 NS::superficial_total_enthalpy_density},
      53        3772 :                        " "));
      54        3772 :   params.addParam<MooseEnum>(
      55             :       "variable_type",
      56             :       variable_types,
      57             :       "Specifies what this variable is in the Navier Stokes namespace of variables");
      58        3772 :   params.addRequiredParam<Real>("initial_pressure",
      59             :                                 "The initial pressure, assumed constant everywhere");
      60        3772 :   params.addRequiredParam<Real>("initial_temperature",
      61             :                                 "The initial temperature, assumed constant everywhere");
      62        3772 :   params.addParam<RealVectorValue>(
      63             :       "initial_interstitial_velocity",
      64             :       "The initial interstitial velocity, assumed constant everywhere");
      65        3772 :   params.addParam<RealVectorValue>("initial_superficial_velocity",
      66             :                                    "The initial superficial velocity, assumed constant everywhere");
      67        3772 :   params.addCoupledVar("porosity", "Porosity variable (defaults to porosity material property).");
      68        3772 :   params.addRequiredParam<UserObjectName>("fluid_properties",
      69             :                                           "The name of the user object for fluid properties");
      70             : 
      71        1886 :   return params;
      72        3772 : }
      73             : 
      74        1012 : PNSInitialCondition::PNSInitialCondition(const InputParameters & parameters)
      75             :   : InitialCondition(parameters),
      76        4048 :     _variable_type(isParamValid("variable_type") ? getParam<MooseEnum>("variable_type")
      77        1012 :                                                  : MooseEnum(_var.name(), _var.name())),
      78        2024 :     _initial_pressure(getParam<Real>("initial_pressure")),
      79        2024 :     _initial_temperature(getParam<Real>("initial_temperature")),
      80        2024 :     _superficial_velocities_set(isParamValid("initial_superficial_velocity") ? true : false),
      81        2024 :     _eps(isCoupled("porosity") ? coupledValue("porosity")
      82           0 :                                : getMaterialProperty<Real>(NS::porosity).get()),
      83        2024 :     _fp(getUserObject<IdealGasFluidProperties>("fluid_properties"))
      84             : {
      85        2024 :   if (isParamValid("initial_superficial_velocity"))
      86        2024 :     _initial_superficial_velocity = getParam<RealVectorValue>("initial_superficial_velocity");
      87        2024 :   if (isParamValid("initial_interstitial_velocity"))
      88           0 :     _initial_interstitial_velocity = getParam<RealVectorValue>("initial_interstitial_velocity");
      89        4048 :   if (isParamValid("initial_superficial_velocity") && isParamValid("initial_interstitial_velocity"))
      90           0 :     paramError("Either superficial or interstitial velocities may be specified.");
      91        1012 : }
      92             : 
      93             : Real
      94       16560 : PNSInitialCondition::value(const Point & /*p*/)
      95             : {
      96             :   // Compute velocities
      97       16560 :   if (_superficial_velocities_set)
      98       16560 :     _initial_interstitial_velocity = _initial_superficial_velocity / _eps[_qp];
      99             :   else
     100           0 :     _initial_superficial_velocity = _initial_interstitial_velocity * _eps[_qp];
     101             : 
     102       16560 :   const Real rho_initial = _fp.rho_from_p_T(_initial_pressure, _initial_temperature);
     103             : 
     104             :   // TODO: The internal energy could be computed by the IdealGasFluidProperties.
     105       16560 :   const Real e_initial = _fp.cv() * _initial_temperature;
     106       16560 :   const Real et_initial = e_initial + 0.5 * _initial_interstitial_velocity.norm_sq();
     107       16560 :   const Real v_initial = 1. / rho_initial;
     108             : 
     109       16560 :   if (_variable_type == NS::specific_total_enthalpy)
     110         720 :     return et_initial + _initial_pressure / rho_initial;
     111             : 
     112       15840 :   if (_variable_type == NS::superficial_total_enthalpy_density)
     113         720 :     return (et_initial + _initial_pressure / rho_initial) * _eps[_qp];
     114             : 
     115       15120 :   if (_variable_type == NS::specific_internal_energy)
     116             :     return e_initial;
     117             : 
     118       14400 :   if (_variable_type == NS::mach_number)
     119         720 :     return _initial_superficial_velocity.norm() / _fp.c_from_v_e(v_initial, e_initial);
     120             : 
     121       13680 :   if (_variable_type == NS::pressure)
     122         720 :     return _initial_pressure;
     123             : 
     124       12960 :   if (_variable_type == NS::density)
     125             :     return rho_initial;
     126             : 
     127       12240 :   if (_variable_type == NS::superficial_density)
     128         720 :     return rho_initial * _eps[_qp];
     129             : 
     130       11520 :   if (_variable_type == NS::superficial_momentum_x)
     131         720 :     return rho_initial * _initial_superficial_velocity(0);
     132             : 
     133       10800 :   if (_variable_type == NS::superficial_momentum_y)
     134         720 :     return rho_initial * _initial_superficial_velocity(1);
     135             : 
     136       10080 :   if (_variable_type == NS::superficial_momentum_z)
     137         720 :     return rho_initial * _initial_superficial_velocity(2);
     138             : 
     139        9360 :   if (_variable_type == NS::momentum_x)
     140         720 :     return rho_initial * _initial_interstitial_velocity(0);
     141             : 
     142        8640 :   if (_variable_type == NS::momentum_y)
     143         720 :     return rho_initial * _initial_interstitial_velocity(1);
     144             : 
     145        7920 :   if (_variable_type == NS::momentum_z)
     146         720 :     return rho_initial * _initial_interstitial_velocity(2);
     147             : 
     148        7200 :   if (_variable_type == NS::total_energy_density)
     149         720 :     return rho_initial * et_initial;
     150             : 
     151        6480 :   if (_variable_type == NS::superficial_total_energy_density)
     152         720 :     return rho_initial * et_initial * _eps[_qp];
     153             : 
     154        5760 :   if (_variable_type == NS::specific_volume)
     155             :     return v_initial;
     156             : 
     157        5040 :   if (_variable_type == NS::temperature)
     158             :     return _initial_temperature;
     159             : 
     160        4320 :   if (_variable_type == NS::superficial_velocity_x)
     161         720 :     return _initial_superficial_velocity(0);
     162             : 
     163        3600 :   if (_variable_type == NS::superficial_velocity_y)
     164         720 :     return _initial_superficial_velocity(1);
     165             : 
     166        2880 :   if (_variable_type == NS::superficial_velocity_z)
     167         720 :     return _initial_superficial_velocity(2);
     168             : 
     169        2160 :   if (_variable_type == NS::velocity_x)
     170             :     return _initial_interstitial_velocity(0);
     171             : 
     172        1440 :   if (_variable_type == NS::velocity_y)
     173             :     return _initial_interstitial_velocity(1);
     174             : 
     175         720 :   if (_variable_type == NS::velocity_z)
     176             :     return _initial_interstitial_velocity(2);
     177             : 
     178             :   // If we got here, then the variable name was not one of the ones we know about.
     179           0 :   mooseError("Unrecognized variable: ", _variable_type);
     180             :   return 0.;
     181             : }

Generated by: LCOV version 1.14