LCOV - code coverage report
Current view: top level - src/ics - NSInitialCondition.C (source / functions) Hit Total Coverage
Test: idaholab/moose navier_stokes: 9fc4b0 Lines: 49 50 98.0 %
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 "NSInitialCondition.h"
      13             : 
      14             : // FluidProperties includes
      15             : #include "IdealGasFluidProperties.h"
      16             : 
      17             : // MOOSE includes
      18             : #include "MooseVariable.h"
      19             : 
      20             : registerMooseObject("NavierStokesApp", NSInitialCondition);
      21             : 
      22             : InputParameters
      23        1640 : NSInitialCondition::validParams()
      24             : {
      25        1640 :   InputParameters params = InitialCondition::validParams();
      26        1640 :   params.addClassDescription("NSInitialCondition sets intial constant values for all variables.");
      27        3280 :   params.addDeprecatedParam<std::string>("pressure_variable_name",
      28             :                                          NS::pressure,
      29             :                                          "The name of the pressure variable",
      30             :                                          "pressure_variable_name is deprecated, use variable_type");
      31       27880 :   MooseEnum variable_types(MooseUtils::join(std::vector<std::string>{NS::specific_total_enthalpy,
      32             :                                                                      NS::specific_internal_energy,
      33             :                                                                      NS::mach_number,
      34             :                                                                      NS::pressure,
      35             :                                                                      NS::density,
      36             :                                                                      NS::momentum_x,
      37             :                                                                      NS::momentum_y,
      38             :                                                                      NS::momentum_z,
      39             :                                                                      NS::total_energy_density,
      40             :                                                                      NS::specific_volume,
      41             :                                                                      NS::temperature,
      42             :                                                                      NS::velocity_x,
      43             :                                                                      NS::velocity_y,
      44       22960 :                                                                      NS::velocity_z},
      45        3280 :                                             " "));
      46        3280 :   params.addParam<MooseEnum>(
      47             :       "variable_type",
      48             :       variable_types,
      49             :       "Specifies what this variable is in the Navier Stokes namespace of variables");
      50        3280 :   params.addRequiredParam<Real>("initial_pressure",
      51             :                                 "The initial pressure, assumed constant everywhere");
      52        3280 :   params.addRequiredParam<Real>("initial_temperature",
      53             :                                 "The initial temperature, assumed constant everywhere");
      54        3280 :   params.addRequiredParam<RealVectorValue>("initial_velocity",
      55             :                                            "The initial velocity, assumed constant everywhere");
      56        3280 :   params.addRequiredParam<UserObjectName>("fluid_properties",
      57             :                                           "The name of the user object for fluid properties");
      58             : 
      59        1640 :   return params;
      60        3280 : }
      61             : 
      62         880 : NSInitialCondition::NSInitialCondition(const InputParameters & parameters)
      63             :   : InitialCondition(parameters),
      64        3740 :     _variable_type(isParamValid("variable_type") ? getParam<MooseEnum>("variable_type")
      65        1100 :                                                  : MooseEnum(_var.name(), _var.name())),
      66        1760 :     _initial_pressure(getParam<Real>("initial_pressure")),
      67        1760 :     _initial_temperature(getParam<Real>("initial_temperature")),
      68        1760 :     _initial_velocity(getParam<RealVectorValue>("initial_velocity")),
      69         880 :     _fp(getUserObject<IdealGasFluidProperties>("fluid_properties")),
      70        2640 :     _pressure_variable_name(getParam<std::string>("pressure_variable_name"))
      71             : {
      72         880 : }
      73             : 
      74             : Real
      75       93024 : NSInitialCondition::value(const Point & /*p*/)
      76             : {
      77       93024 :   const Real rho_initial = _fp.rho_from_p_T(_initial_pressure, _initial_temperature);
      78             : 
      79             :   // TODO: The internal energy could be computed by the IdealGasFluidProperties.
      80       93024 :   const Real e_initial = _fp.cv() * _initial_temperature;
      81       93024 :   const Real et_initial = e_initial + 0.5 * _initial_velocity.norm_sq();
      82       93024 :   const Real v_initial = 1. / rho_initial;
      83             : 
      84       93024 :   if (_variable_type == NS::specific_total_enthalpy)
      85        7632 :     return et_initial + _initial_pressure / rho_initial;
      86             : 
      87       85392 :   if (_variable_type == NS::specific_internal_energy)
      88             :     return e_initial;
      89             : 
      90       77760 :   if (_variable_type == NS::mach_number)
      91        7632 :     return _initial_velocity.norm() / _fp.c_from_v_e(v_initial, e_initial);
      92             : 
      93       70128 :   if (_variable_type == NS::pressure || _variable_type == _pressure_variable_name)
      94        7632 :     return _initial_pressure;
      95             : 
      96       62496 :   if (_variable_type == NS::density)
      97             :     return rho_initial;
      98             : 
      99       54864 :   if (_variable_type == NS::momentum_x)
     100        7632 :     return rho_initial * _initial_velocity(0);
     101             : 
     102       47232 :   if (_variable_type == NS::momentum_y)
     103        7632 :     return rho_initial * _initial_velocity(1);
     104             : 
     105       39600 :   if (_variable_type == NS::momentum_z)
     106         720 :     return rho_initial * _initial_velocity(2);
     107             : 
     108       38880 :   if (_variable_type == NS::total_energy_density)
     109        7632 :     return rho_initial * et_initial;
     110             : 
     111       31248 :   if (_variable_type == NS::specific_volume)
     112             :     return v_initial;
     113             : 
     114       23616 :   if (_variable_type == NS::temperature)
     115             :     return _initial_temperature;
     116             : 
     117       15984 :   if (_variable_type == NS::velocity_x)
     118             :     return _initial_velocity(0);
     119             : 
     120        8352 :   if (_variable_type == NS::velocity_y)
     121             :     return _initial_velocity(1);
     122             : 
     123         720 :   if (_variable_type == NS::velocity_z)
     124             :     return _initial_velocity(2);
     125             : 
     126             :   // If we got here, then the variable name was not one of the ones we know about.
     127           0 :   mooseError("Unrecognized variable: ", _variable_type);
     128             :   return 0.;
     129             : }

Generated by: LCOV version 1.14