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 874 : PNSInitialCondition::validParams() 24 : { 25 874 : InputParameters params = InitialCondition::validParams(); 26 874 : params.addClassDescription( 27 : "PNSInitialCondition sets intial constant values for any porous flow variable."); 28 : 29 : MooseEnum variable_types( 30 22724 : 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 20102 : NS::superficial_total_enthalpy_density}, 53 1748 : " ")); 54 1748 : params.addParam<MooseEnum>( 55 : "variable_type", 56 : variable_types, 57 : "Specifies what this variable is in the Navier Stokes namespace of variables"); 58 1748 : params.addRequiredParam<Real>("initial_pressure", 59 : "The initial pressure, assumed constant everywhere"); 60 1748 : params.addRequiredParam<Real>("initial_temperature", 61 : "The initial temperature, assumed constant everywhere"); 62 1748 : params.addParam<RealVectorValue>( 63 : "initial_interstitial_velocity", 64 : "The initial interstitial velocity, assumed constant everywhere"); 65 1748 : params.addParam<RealVectorValue>("initial_superficial_velocity", 66 : "The initial superficial velocity, assumed constant everywhere"); 67 1748 : params.addCoupledVar("porosity", "Porosity variable (defaults to porosity material property)."); 68 1748 : params.addRequiredParam<UserObjectName>("fluid_properties", 69 : "The name of the user object for fluid properties"); 70 : 71 874 : return params; 72 1748 : } 73 : 74 460 : PNSInitialCondition::PNSInitialCondition(const InputParameters & parameters) 75 : : InitialCondition(parameters), 76 1380 : _variable_type(isParamValid("variable_type") ? getParam<MooseEnum>("variable_type") 77 230 : : MooseEnum(_var.name(), _var.name())), 78 920 : _initial_pressure(getParam<Real>("initial_pressure")), 79 920 : _initial_temperature(getParam<Real>("initial_temperature")), 80 920 : _superficial_velocities_set(isParamValid("initial_superficial_velocity") ? true : false), 81 920 : _eps(isCoupled("porosity") ? coupledValue("porosity") 82 0 : : getMaterialProperty<Real>(NS::porosity).get()), 83 920 : _fp(getUserObject<IdealGasFluidProperties>("fluid_properties")) 84 : { 85 920 : if (isParamValid("initial_superficial_velocity")) 86 920 : _initial_superficial_velocity = getParam<RealVectorValue>("initial_superficial_velocity"); 87 920 : if (isParamValid("initial_interstitial_velocity")) 88 0 : _initial_interstitial_velocity = getParam<RealVectorValue>("initial_interstitial_velocity"); 89 1840 : if (isParamValid("initial_superficial_velocity") && isParamValid("initial_interstitial_velocity")) 90 0 : paramError("Either superficial or interstitial velocities may be specified."); 91 460 : } 92 : 93 : Real 94 11040 : PNSInitialCondition::value(const Point & /*p*/) 95 : { 96 : // Compute velocities 97 11040 : if (_superficial_velocities_set) 98 11040 : _initial_interstitial_velocity = _initial_superficial_velocity / _eps[_qp]; 99 : else 100 0 : _initial_superficial_velocity = _initial_interstitial_velocity * _eps[_qp]; 101 : 102 11040 : 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 11040 : const Real e_initial = _fp.cv() * _initial_temperature; 106 11040 : const Real et_initial = e_initial + 0.5 * _initial_interstitial_velocity.norm_sq(); 107 11040 : const Real v_initial = 1. / rho_initial; 108 : 109 11040 : if (_variable_type == NS::specific_total_enthalpy) 110 480 : return et_initial + _initial_pressure / rho_initial; 111 : 112 10560 : if (_variable_type == NS::superficial_total_enthalpy_density) 113 480 : return (et_initial + _initial_pressure / rho_initial) * _eps[_qp]; 114 : 115 10080 : if (_variable_type == NS::specific_internal_energy) 116 : return e_initial; 117 : 118 9600 : if (_variable_type == NS::mach_number) 119 480 : return _initial_superficial_velocity.norm() / _fp.c_from_v_e(v_initial, e_initial); 120 : 121 9120 : if (_variable_type == NS::pressure) 122 480 : return _initial_pressure; 123 : 124 8640 : if (_variable_type == NS::density) 125 : return rho_initial; 126 : 127 8160 : if (_variable_type == NS::superficial_density) 128 480 : return rho_initial * _eps[_qp]; 129 : 130 7680 : if (_variable_type == NS::superficial_momentum_x) 131 480 : return rho_initial * _initial_superficial_velocity(0); 132 : 133 7200 : if (_variable_type == NS::superficial_momentum_y) 134 480 : return rho_initial * _initial_superficial_velocity(1); 135 : 136 6720 : if (_variable_type == NS::superficial_momentum_z) 137 480 : return rho_initial * _initial_superficial_velocity(2); 138 : 139 6240 : if (_variable_type == NS::momentum_x) 140 480 : return rho_initial * _initial_interstitial_velocity(0); 141 : 142 5760 : if (_variable_type == NS::momentum_y) 143 480 : return rho_initial * _initial_interstitial_velocity(1); 144 : 145 5280 : if (_variable_type == NS::momentum_z) 146 480 : return rho_initial * _initial_interstitial_velocity(2); 147 : 148 4800 : if (_variable_type == NS::total_energy_density) 149 480 : return rho_initial * et_initial; 150 : 151 4320 : if (_variable_type == NS::superficial_total_energy_density) 152 480 : return rho_initial * et_initial * _eps[_qp]; 153 : 154 3840 : if (_variable_type == NS::specific_volume) 155 : return v_initial; 156 : 157 3360 : if (_variable_type == NS::temperature) 158 : return _initial_temperature; 159 : 160 2880 : if (_variable_type == NS::superficial_velocity_x) 161 480 : return _initial_superficial_velocity(0); 162 : 163 2400 : if (_variable_type == NS::superficial_velocity_y) 164 480 : return _initial_superficial_velocity(1); 165 : 166 1920 : if (_variable_type == NS::superficial_velocity_z) 167 480 : return _initial_superficial_velocity(2); 168 : 169 1440 : if (_variable_type == NS::velocity_x) 170 : return _initial_interstitial_velocity(0); 171 : 172 960 : if (_variable_type == NS::velocity_y) 173 : return _initial_interstitial_velocity(1); 174 : 175 480 : 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 : }