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 1148 : NSFunctionInitialCondition::validParams() 24 : { 25 1148 : InputParameters params = InitialCondition::validParams(); 26 1148 : params.addClassDescription("Sets intial values for all variables."); 27 2296 : 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 19516 : 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 16072 : NS::velocity_z}, 45 2296 : " ")); 46 2296 : params.addParam<MooseEnum>( 47 : "variable_type", 48 : variable_types, 49 : "Specifies what this variable is in the Navier Stokes namespace of variables"); 50 2296 : params.addRequiredParam<FunctionName>("initial_pressure", "The initial pressure"); 51 2296 : params.addRequiredParam<FunctionName>("initial_temperature", "The initial temperature"); 52 2296 : params.addRequiredParam<std::vector<FunctionName>>("initial_velocity", "The initial velocity"); 53 2296 : params.addRequiredParam<UserObjectName>("fluid_properties", 54 : "The name of the user object for fluid properties"); 55 : 56 1148 : return params; 57 2296 : } 58 : 59 616 : NSFunctionInitialCondition::NSFunctionInitialCondition(const InputParameters & parameters) 60 : : InitialCondition(parameters), 61 2464 : _variable_type(isParamValid("variable_type") ? getParam<MooseEnum>("variable_type") 62 616 : : MooseEnum(_var.name(), _var.name())), 63 616 : _initial_pressure(getFunction("initial_pressure")), 64 616 : _initial_temperature(getFunction("initial_temperature")), 65 616 : _fp(getUserObject<IdealGasFluidProperties>("fluid_properties")), 66 1848 : _pressure_variable_name(getParam<std::string>("pressure_variable_name")) 67 : { 68 2464 : for (const auto i : make_range(Moose::dim)) 69 1848 : _initial_velocity.push_back( 70 5544 : &getFunctionByName(getParam<std::vector<FunctionName>>("initial_velocity")[i])); 71 616 : } 72 : 73 : Real 74 5670 : NSFunctionInitialCondition::value(const Point & p) 75 : { 76 5670 : const Real initial_pressure = _initial_pressure.value(_t, p); 77 5670 : const Real initial_temperature = _initial_temperature.value(_t, p); 78 5670 : const RealVectorValue initial_velocity = {_initial_velocity[0]->value(_t, p), 79 5670 : _initial_velocity[1]->value(_t, p), 80 5670 : _initial_velocity[2]->value(_t, p)}; 81 : 82 5670 : 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 5670 : const Real e_initial = _fp.cv() * initial_temperature; 86 5670 : const Real et_initial = e_initial + 0.5 * initial_velocity.norm_sq(); 87 5670 : const Real v_initial = 1. / rho_initial; 88 : 89 5670 : if (_variable_type == NS::specific_total_enthalpy) 90 405 : return et_initial + initial_pressure / rho_initial; 91 : 92 5265 : if (_variable_type == NS::specific_internal_energy) 93 : return e_initial; 94 : 95 4860 : if (_variable_type == NS::mach_number) 96 405 : return initial_velocity.norm() / _fp.c_from_v_e(v_initial, e_initial); 97 : 98 4455 : if (_variable_type == NS::pressure || _variable_type == _pressure_variable_name) 99 : return initial_pressure; 100 : 101 4050 : if (_variable_type == NS::density) 102 : return rho_initial; 103 : 104 3645 : if (_variable_type == NS::momentum_x) 105 405 : return rho_initial * initial_velocity(0); 106 : 107 3240 : if (_variable_type == NS::momentum_y) 108 405 : return rho_initial * initial_velocity(1); 109 : 110 2835 : if (_variable_type == NS::momentum_z) 111 405 : return rho_initial * initial_velocity(2); 112 : 113 2430 : if (_variable_type == NS::total_energy_density) 114 405 : return rho_initial * et_initial; 115 : 116 2025 : if (_variable_type == NS::specific_volume) 117 : return v_initial; 118 : 119 1620 : if (_variable_type == NS::temperature) 120 : return initial_temperature; 121 : 122 1215 : if (_variable_type == NS::velocity_x) 123 : return initial_velocity(0); 124 : 125 810 : if (_variable_type == NS::velocity_y) 126 : return initial_velocity(1); 127 : 128 405 : 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 : }