LCOV - code coverage report
Current view: top level - src/ics - NSFunctionInitialCondition.C (source / functions) Hit Total Coverage
Test: idaholab/moose navier_stokes: #32971 (54bef8) with base c6cf66 Lines: 55 56 98.2 %
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 "NSFunctionInitialCondition.h"
      13             : 
      14             : // FluidProperties includes
      15             : #include "IdealGasFluidProperties.h"
      16             : 
      17             : // MOOSE includes
      18             : #include "MooseVariable.h"
      19             : 
      20             : registerMooseObject("NavierStokesApp", NSFunctionInitialCondition);
      21             : 
      22             : InputParameters
      23         532 : NSFunctionInitialCondition::validParams()
      24             : {
      25         532 :   InputParameters params = InitialCondition::validParams();
      26         532 :   params.addClassDescription("Sets intial values for all variables.");
      27        1064 :   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        9044 :   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        7448 :                                                                      NS::velocity_z},
      45        1064 :                                             " "));
      46        1064 :   params.addParam<MooseEnum>(
      47             :       "variable_type",
      48             :       variable_types,
      49             :       "Specifies what this variable is in the Navier Stokes namespace of variables");
      50        1064 :   params.addRequiredParam<FunctionName>("initial_pressure", "The initial pressure");
      51        1064 :   params.addRequiredParam<FunctionName>("initial_temperature", "The initial temperature");
      52        1064 :   params.addRequiredParam<std::vector<FunctionName>>("initial_velocity", "The initial velocity");
      53        1064 :   params.addRequiredParam<UserObjectName>("fluid_properties",
      54             :                                           "The name of the user object for fluid properties");
      55             : 
      56         532 :   return params;
      57        1064 : }
      58             : 
      59         280 : NSFunctionInitialCondition::NSFunctionInitialCondition(const InputParameters & parameters)
      60             :   : InitialCondition(parameters),
      61         840 :     _variable_type(isParamValid("variable_type") ? getParam<MooseEnum>("variable_type")
      62         140 :                                                  : MooseEnum(_var.name(), _var.name())),
      63         280 :     _initial_pressure(getFunction("initial_pressure")),
      64         280 :     _initial_temperature(getFunction("initial_temperature")),
      65         280 :     _fp(getUserObject<IdealGasFluidProperties>("fluid_properties")),
      66         840 :     _pressure_variable_name(getParam<std::string>("pressure_variable_name"))
      67             : {
      68        1120 :   for (const auto i : make_range(Moose::dim))
      69         840 :     _initial_velocity.push_back(
      70        2520 :         &getFunctionByName(getParam<std::vector<FunctionName>>("initial_velocity")[i]));
      71         280 : }
      72             : 
      73             : Real
      74        3780 : NSFunctionInitialCondition::value(const Point & p)
      75             : {
      76        3780 :   const Real initial_pressure = _initial_pressure.value(_t, p);
      77        3780 :   const Real initial_temperature = _initial_temperature.value(_t, p);
      78        3780 :   const RealVectorValue initial_velocity = {_initial_velocity[0]->value(_t, p),
      79        3780 :                                             _initial_velocity[1]->value(_t, p),
      80        3780 :                                             _initial_velocity[2]->value(_t, p)};
      81             : 
      82        3780 :   const Real rho_initial = _fp.rho_from_p_T(initial_pressure, initial_temperature);
      83             : 
      84             :   // TODO: The internal energy could be computed by the IdealGasFluidProperties.
      85        3780 :   const Real e_initial = _fp.cv() * initial_temperature;
      86        3780 :   const Real et_initial = e_initial + 0.5 * initial_velocity.norm_sq();
      87        3780 :   const Real v_initial = 1. / rho_initial;
      88             : 
      89        3780 :   if (_variable_type == NS::specific_total_enthalpy)
      90         270 :     return et_initial + initial_pressure / rho_initial;
      91             : 
      92        3510 :   if (_variable_type == NS::specific_internal_energy)
      93             :     return e_initial;
      94             : 
      95        3240 :   if (_variable_type == NS::mach_number)
      96         270 :     return initial_velocity.norm() / _fp.c_from_v_e(v_initial, e_initial);
      97             : 
      98        2970 :   if (_variable_type == NS::pressure || _variable_type == _pressure_variable_name)
      99             :     return initial_pressure;
     100             : 
     101        2700 :   if (_variable_type == NS::density)
     102             :     return rho_initial;
     103             : 
     104        2430 :   if (_variable_type == NS::momentum_x)
     105         270 :     return rho_initial * initial_velocity(0);
     106             : 
     107        2160 :   if (_variable_type == NS::momentum_y)
     108         270 :     return rho_initial * initial_velocity(1);
     109             : 
     110        1890 :   if (_variable_type == NS::momentum_z)
     111         270 :     return rho_initial * initial_velocity(2);
     112             : 
     113        1620 :   if (_variable_type == NS::total_energy_density)
     114         270 :     return rho_initial * et_initial;
     115             : 
     116        1350 :   if (_variable_type == NS::specific_volume)
     117             :     return v_initial;
     118             : 
     119        1080 :   if (_variable_type == NS::temperature)
     120             :     return initial_temperature;
     121             : 
     122         810 :   if (_variable_type == NS::velocity_x)
     123             :     return initial_velocity(0);
     124             : 
     125         540 :   if (_variable_type == NS::velocity_y)
     126             :     return initial_velocity(1);
     127             : 
     128         270 :   if (_variable_type == NS::velocity_z)
     129             :     return initial_velocity(2);
     130             : 
     131             :   // If we got here, then the variable name was not one of the ones we know about.
     132           0 :   mooseError("Unrecognized variable: ", _variable_type);
     133             :   return 0.;
     134             : }

Generated by: LCOV version 1.14