ryujin 2.1.1 revision b84172edef78c6084044948db33243ec1fe983ae
initial_state_ramp_up.h
Go to the documentation of this file.
1//
2// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
3// Copyright (C) 2022 - 2024 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 {
24 template <typename Description, int dim, typename Number>
25 class RampUp : public InitialState<Description, dim, Number>
26 {
27 public:
29 using View =
30 typename Description::template HyperbolicSystemView<dim, Number>;
31 using state_type = typename View::state_type;
32
33 RampUp(const HyperbolicSystem &hyperbolic_system,
34 const std::string subsection)
35 : InitialState<Description, dim, Number>("ramp up", subsection)
36 , hyperbolic_system_(hyperbolic_system)
37 {
38 primitive_initial_[0] = 1.4;
39 primitive_initial_[1] = 0.0;
40 primitive_initial_[2] = 1.;
41 this->add_parameter("primitive state initial",
42 primitive_initial_,
43 "Initial 1d primitive state (rho, u, p)");
44
45 primitive_final_[0] = 1.4;
46 primitive_final_[1] = 3.0;
47 primitive_final_[2] = 1.;
48 this->add_parameter("primitive state final",
49 primitive_final_,
50 "Final 1d primitive state (rho, u, p)");
51
52 t_initial_ = 0.;
53 this->add_parameter("time initial",
54 t_initial_,
55 "Time until which initial state is prescribed");
56
57 t_final_ = 1.;
58 this->add_parameter("time final",
59 t_final_,
60 "Time from which on the final state is attained)");
61
62 const auto convert_states = [&]() {
63 const auto view = hyperbolic_system_.template view<dim, Number>();
64 state_initial_ = view.from_initial_state(primitive_initial_);
65 state_final_ = view.from_initial_state(primitive_final_);
66 };
67 this->parse_parameters_call_back.connect(convert_states);
68 convert_states();
69 }
70
71 auto compute(const dealii::Point<dim> & /*point*/, Number t)
72 -> state_type final
73 {
74 state_type result;
75
76 if (t <= t_initial_) {
77 result = state_initial_;
78 } else if (t >= t_final_) {
79 result = state_final_;
80 } else {
81 const Number factor =
82 std::cos(0.5 * M_PI * (t - t_initial_) / (t_final_ - t_initial_));
83
84 const Number alpha = factor * factor;
85 const Number beta = Number(1.) - alpha;
86 result = alpha * state_initial_ + beta * state_final_;
87 }
88
89 return result;
90 }
91
92 private:
93 const HyperbolicSystem &hyperbolic_system_;
94
95 dealii::Tensor<1, 3, Number> primitive_initial_;
96 dealii::Tensor<1, 3, Number> primitive_final_;
97 Number t_initial_;
98 Number t_final_;
99
100 state_type state_initial_;
101 state_type state_final_;
102 };
103 } // namespace EulerInitialStates
104} // namespace ryujin
RampUp(const HyperbolicSystem &hyperbolic_system, const std::string subsection)
typename Description::template HyperbolicSystemView< dim, Number > View
typename Description::HyperbolicSystem HyperbolicSystem
typename View::state_type state_type
auto compute(const dealii::Point< dim > &, Number t) -> state_type final
Euler::HyperbolicSystem HyperbolicSystem
Definition: description.h:34