https://mooseframework.inl.gov
NSFunctionInitialCondition.C
Go to the documentation of this file.
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"
13 
14 // FluidProperties includes
16 
17 // MOOSE includes
18 #include "MooseVariable.h"
19 
21 
24 {
26  params.addClassDescription("Sets intial values for all variables.");
27  params.addDeprecatedParam<std::string>("pressure_variable_name",
29  "The name of the pressure variable",
30  "pressure_variable_name is deprecated, use variable_type");
31  MooseEnum variable_types(MooseUtils::join(std::vector<std::string>{NS::specific_total_enthalpy,
45  " "));
46  params.addParam<MooseEnum>(
47  "variable_type",
48  variable_types,
49  "Specifies what this variable is in the Navier Stokes namespace of variables");
50  params.addRequiredParam<FunctionName>("initial_pressure", "The initial pressure");
51  params.addRequiredParam<FunctionName>("initial_temperature", "The initial temperature");
52  params.addRequiredParam<std::vector<FunctionName>>("initial_velocity", "The initial velocity");
53  params.addRequiredParam<UserObjectName>("fluid_properties",
54  "The name of the user object for fluid properties");
55 
56  return params;
57 }
58 
60  : InitialCondition(parameters),
61  _variable_type(isParamValid("variable_type") ? getParam<MooseEnum>("variable_type")
62  : MooseEnum(_var.name(), _var.name())),
63  _initial_pressure(getFunction("initial_pressure")),
64  _initial_temperature(getFunction("initial_temperature")),
65  _fp(getUserObject<IdealGasFluidProperties>("fluid_properties")),
66  _pressure_variable_name(getParam<std::string>("pressure_variable_name"))
67 {
68  for (const auto i : make_range(Moose::dim))
69  _initial_velocity.push_back(
70  &getFunctionByName(getParam<std::vector<FunctionName>>("initial_velocity")[i]));
71 }
72 
73 Real
75 {
76  const Real initial_pressure = _initial_pressure.value(_t, p);
77  const Real initial_temperature = _initial_temperature.value(_t, p);
78  const RealVectorValue initial_velocity = {_initial_velocity[0]->value(_t, p),
79  _initial_velocity[1]->value(_t, p),
80  _initial_velocity[2]->value(_t, p)};
81 
82  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  const Real e_initial = _fp.cv() * initial_temperature;
86  const Real et_initial = e_initial + 0.5 * initial_velocity.norm_sq();
87  const Real v_initial = 1. / rho_initial;
88 
90  return et_initial + initial_pressure / rho_initial;
91 
93  return e_initial;
94 
96  return initial_velocity.norm() / _fp.c_from_v_e(v_initial, e_initial);
97 
99  return initial_pressure;
100 
102  return rho_initial;
103 
105  return rho_initial * initial_velocity(0);
106 
108  return rho_initial * initial_velocity(1);
109 
111  return rho_initial * initial_velocity(2);
112 
114  return rho_initial * et_initial;
115 
117  return v_initial;
118 
120  return initial_temperature;
121 
123  return initial_velocity(0);
124 
126  return initial_velocity(1);
127 
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  mooseError("Unrecognized variable: ", _variable_type);
133  return 0.;
134 }
static const std::string total_energy_density
Definition: NS.h:65
static const std::string momentum_x
Definition: NS.h:35
std::string join(Iterator begin, Iterator end, const std::string &delimiter)
const std::string _variable_type
Used to map the variable to one of the expected types.
auto norm() const -> decltype(std::norm(Real()))
void addDeprecatedParam(const std::string &name, const T &value, const std::string &doc_string, const std::string &deprecation_message)
std::vector< const Function * > _initial_velocity
Initial constant value of the velocity.
void addParam(const std::string &name, const std::initializer_list< typename T::value_type > &value, const std::string &doc_string)
virtual Real rho_from_p_T(Real p, Real T) const override
static const std::string mach_number
Definition: NS.h:80
static const std::string velocity_z
Definition: NS.h:48
static const std::string density
Definition: NS.h:33
static constexpr std::size_t dim
static InputParameters validParams()
const std::string _pressure_variable_name
pressure variable name
static const std::string velocity_x
Definition: NS.h:46
static const std::string temperature
Definition: NS.h:59
static const std::string specific_internal_energy
Definition: NS.h:62
const Function & _initial_temperature
Initial constant value of the fluid temperature.
NSFunctionInitialCondition(const InputParameters &parameters)
void addRequiredParam(const std::string &name, const std::string &doc_string)
virtual Real value(const Point &p)
The value of the variable at a point.
registerMooseObject("NavierStokesApp", NSFunctionInitialCondition)
auto norm_sq() const -> decltype(std::norm(Real()))
const std::string name
Definition: Setup.h:20
static const std::string specific_volume
Definition: NS.h:81
const T & getParam(const std::string &name) const
static const std::string velocity_y
Definition: NS.h:47
const IdealGasFluidProperties & _fp
Fluid properties.
static InputParameters validParams()
static const std::string momentum_y
Definition: NS.h:36
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
const Function & getFunctionByName(const FunctionName &name) const
static const std::string specific_total_enthalpy
Definition: NS.h:69
static const std::string pressure
Definition: NS.h:56
IntRange< T > make_range(T beg, T end)
void mooseError(Args &&... args) const
virtual Real c_from_v_e(Real v, Real e) const override
void addClassDescription(const std::string &doc_string)
static const std::string momentum_z
Definition: NS.h:37
Ideal gas fluid properties Default parameters are for air at atmospheric pressure and temperature...
virtual Real value(Real t, const Point &p) const
NSFunctionInitialCondition sets intial constant values for all variables given the: ...
const Function & _initial_pressure
Initial constant value of the pressure.