LCOV - code coverage report
Current view: top level - src/ics - NSInitialCondition.C (source / functions) Hit Total Coverage
Test: idaholab/moose navier_stokes: #32971 (54bef8) with base c6cf66 Lines: 49 50 98.0 %
Date: 2026-05-29 20:37:52 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         760 : NSInitialCondition::validParams()
      24             : {
      25         760 :   InputParameters params = InitialCondition::validParams();
      26         760 :   params.addClassDescription("NSInitialCondition sets intial constant values for all variables.");
      27        1520 :   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       12920 :   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       10640 :                                                                      NS::velocity_z},
      45        1520 :                                             " "));
      46        1520 :   params.addParam<MooseEnum>(
      47             :       "variable_type",
      48             :       variable_types,
      49             :       "Specifies what this variable is in the Navier Stokes namespace of variables");
      50        1520 :   params.addRequiredParam<Real>("initial_pressure",
      51             :                                 "The initial pressure, assumed constant everywhere");
      52        1520 :   params.addRequiredParam<Real>("initial_temperature",
      53             :                                 "The initial temperature, assumed constant everywhere");
      54        1520 :   params.addRequiredParam<RealVectorValue>("initial_velocity",
      55             :                                            "The initial velocity, assumed constant everywhere");
      56        1520 :   params.addRequiredParam<UserObjectName>("fluid_properties",
      57             :                                           "The name of the user object for fluid properties");
      58             : 
      59         760 :   return params;
      60        1520 : }
      61             : 
      62         400 : NSInitialCondition::NSInitialCondition(const InputParameters & parameters)
      63             :   : InitialCondition(parameters),
      64        1200 :     _variable_type(isParamValid("variable_type") ? getParam<MooseEnum>("variable_type")
      65         250 :                                                  : MooseEnum(_var.name(), _var.name())),
      66         800 :     _initial_pressure(getParam<Real>("initial_pressure")),
      67         800 :     _initial_temperature(getParam<Real>("initial_temperature")),
      68         800 :     _initial_velocity(getParam<RealVectorValue>("initial_velocity")),
      69         400 :     _fp(getUserObject<IdealGasFluidProperties>("fluid_properties")),
      70        1200 :     _pressure_variable_name(getParam<std::string>("pressure_variable_name"))
      71             : {
      72         400 : }
      73             : 
      74             : Real
      75       62016 : NSInitialCondition::value(const Point & /*p*/)
      76             : {
      77       62016 :   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       62016 :   const Real e_initial = _fp.cv() * _initial_temperature;
      81       62016 :   const Real et_initial = e_initial + 0.5 * _initial_velocity.norm_sq();
      82       62016 :   const Real v_initial = 1. / rho_initial;
      83             : 
      84       62016 :   if (_variable_type == NS::specific_total_enthalpy)
      85        5088 :     return et_initial + _initial_pressure / rho_initial;
      86             : 
      87       56928 :   if (_variable_type == NS::specific_internal_energy)
      88             :     return e_initial;
      89             : 
      90       51840 :   if (_variable_type == NS::mach_number)
      91        5088 :     return _initial_velocity.norm() / _fp.c_from_v_e(v_initial, e_initial);
      92             : 
      93       46752 :   if (_variable_type == NS::pressure || _variable_type == _pressure_variable_name)
      94        5088 :     return _initial_pressure;
      95             : 
      96       41664 :   if (_variable_type == NS::density)
      97             :     return rho_initial;
      98             : 
      99       36576 :   if (_variable_type == NS::momentum_x)
     100        5088 :     return rho_initial * _initial_velocity(0);
     101             : 
     102       31488 :   if (_variable_type == NS::momentum_y)
     103        5088 :     return rho_initial * _initial_velocity(1);
     104             : 
     105       26400 :   if (_variable_type == NS::momentum_z)
     106         480 :     return rho_initial * _initial_velocity(2);
     107             : 
     108       25920 :   if (_variable_type == NS::total_energy_density)
     109        5088 :     return rho_initial * et_initial;
     110             : 
     111       20832 :   if (_variable_type == NS::specific_volume)
     112             :     return v_initial;
     113             : 
     114       15744 :   if (_variable_type == NS::temperature)
     115             :     return _initial_temperature;
     116             : 
     117       10656 :   if (_variable_type == NS::velocity_x)
     118             :     return _initial_velocity(0);
     119             : 
     120        5568 :   if (_variable_type == NS::velocity_y)
     121             :     return _initial_velocity(1);
     122             : 
     123         480 :   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