ryujin 2.1.1 revision ee5cbcbf2346c1299c942d0e1f13b46449973c18
Loading...
Searching...
No Matches
initial_state_rarefaction.h
Go to the documentation of this file.
1//
2// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
3// Copyright (C) 2023 - 2025 by the ryujin authors
4//
5
6#pragma once
7
8#include <compile_time_options.h>
9
11
12namespace ryujin
13{
14 namespace EulerInitialStates
15 {
28 template <typename Description, int dim, typename Number>
29 class Rarefaction : public InitialState<Description, dim, Number>
30 {
31 public:
33 using View = typename HyperbolicSystem::template View<dim, Number>;
34 using state_type = typename View::state_type;
35
36 using state_type_1d = std::array<Number, 4>;
37
38 Rarefaction(const HyperbolicSystem &hyperbolic_system,
39 const std::string subsection)
40 : InitialState<Description, dim, Number>("rarefaction", subsection)
41 , hyperbolic_system_(hyperbolic_system)
42 {
43 gamma_ = 1.4;
44 if constexpr (!View::have_gamma) {
45 this->add_parameter("gamma", gamma_, "The ratio of specific heats");
46 }
47
48 /*
49 * Compute the speed of sound:
50 */
51 const auto speed_of_sound = [&](const Number rho, const Number p) {
52 return std::sqrt(gamma_ * p / rho);
53 };
54
55 /*
56 * Compute the rarefaction right side:
57 */
58 const auto rarefaction_right_state = [this, speed_of_sound](
59 const auto primitive_left,
60 const Number rho_right) {
61 const auto &[rho_left, u_left, p_left, c_left] = primitive_left;
62 state_type_1d primitive_right{{rho_right, 0., 0.}};
63
64 /* Isentropic condition: pR = (rhoR/rhoL)^{gamma} * pL */
65 primitive_right[2] = std::pow(rho_right / rho_left, gamma_) * p_left;
66
67 const auto c_right = speed_of_sound(rho_right, primitive_right[2]);
68 primitive_right[3] = c_right;
69
70 /* 1-Riemann invariant: uR + 2 cR/(gamma -1) = uL + 2 cL/(gamma -1) */
71 primitive_right[1] =
72 u_left + 2.0 * (c_left - c_right) / (gamma_ - 1.0);
73
74 return primitive_right;
75 };
76
77 const auto compute_constants =
78 [this, speed_of_sound, rarefaction_right_state]() {
79 const auto view = hyperbolic_system_.template view<dim, Number>();
80 if constexpr (View::have_gamma) {
81 gamma_ = view.gamma();
82 }
83
84 /*
85 * Initial left and right states (rho, u, p, c):
86 */
87
88 const Number rho_left = 3.0;
89 const Number p_left = 1.0;
90 const Number c_left = speed_of_sound(rho_left, p_left);
91 const Number u_left = c_left; /* verify */
92 const Number rho_right = 0.5;
93
94 primitive_left_ = {rho_left, c_left, p_left, c_left};
95 primitive_right_ =
96 rarefaction_right_state(primitive_left_, rho_right);
97
98 /*
99 * Populate constants:
100 */
101
102 k1 = 2.0 / (gamma_ + 1.0);
103 k2 = ((gamma_ - 1.0) / ((gamma_ + 1.0) * c_left));
104 density_exponent = 2.0 / (gamma_ - 1.0);
105 k3 = c_left + ((gamma_ - 1.0) / 2.0) * u_left;
106 pressure_exponent = 2.0 * gamma_ / (gamma_ - 1.0);
107 };
108
109 this->parse_parameters_call_back.connect(compute_constants);
110 compute_constants();
111 } /* Constructor */
112
113 state_type compute(const dealii::Point<dim> &point, Number delta_t) final
114 {
115 /*
116 * Compute rarefaction solution:
117 */
118
119 const auto &[rho_left, u_left, p_left, c_left] = primitive_left_;
120 const auto &[rho_right, u_right, p_right, c_right] = primitive_right_;
121
122 const double x = point[0];
123 const auto t_0 = 0.2 / (u_right - u_left);
124 const auto t = t_0 + delta_t;
125
126 state_type_1d primitive;
127
128 if (x <= t * (u_left - c_left)) {
129 primitive = primitive_left_;
130
131 } else if (x <= t * (u_right - c_right)) {
132
133 /* Self-similar variable: */
134 const double chi = x / t;
135
136 primitive[0] =
137 rho_left * std::pow(k1 + k2 * (u_left - chi), density_exponent);
138 primitive[1] = k1 * (k3 + chi);
139 primitive[2] =
140 p_left * std::pow(k1 + k2 * (u_left - chi), pressure_exponent);
141
142 } else {
143 primitive = primitive_right_;
144 }
145
146 state_type conserved_state;
147 {
148 const auto &[rho, u, p, c] = primitive;
149 conserved_state[0] = rho;
150 conserved_state[1] = rho * u;
151 if constexpr (View::have_energy_equation)
152 conserved_state[dim + 1] =
153 p / Number(gamma_ - 1.) + Number(0.5) * rho * u * u;
154 }
155 return conserved_state;
156 }
157
158 private:
159 const HyperbolicSystem &hyperbolic_system_;
160 Number gamma_;
161
162 state_type_1d primitive_left_;
163 state_type_1d primitive_right_;
164 Number k1;
165 Number k2;
166 Number density_exponent;
167 Number k3;
168 Number pressure_exponent;
169 };
170 } // namespace EulerInitialStates
171} // namespace ryujin
Rarefaction(const HyperbolicSystem &hyperbolic_system, const std::string subsection)
typename HyperbolicSystem::template View< dim, Number > View
state_type compute(const dealii::Point< dim > &point, Number delta_t) final
typename Description::HyperbolicSystem HyperbolicSystem
Euler::HyperbolicSystem HyperbolicSystem
Definition description.h:34