ryujin 2.1.1 revision ee5cbcbf2346c1299c942d0e1f13b46449973c18
Loading...
Searching...
No Matches
initial_state_function.h
Go to the documentation of this file.
1//
2// SPDX-License-Identifier: Apache-2.0
3// [LANL Copyright Statement]
4// Copyright (C) 2023 - 2025 by the ryujin authors
5// Copyright (C) 2023 - 2024 by Triad National Security, LLC
6//
7
8#pragma once
9
10#include <compile_time_options.h>
11
13
14#include <deal.II/base/function_parser.h>
15
16namespace ryujin
17{
18 namespace ShallowWaterInitialStates
19 {
26 template <typename Description, int dim, typename Number>
27 class Function : public InitialState<Description, dim, Number>
28 {
29 public:
31 using View = typename HyperbolicSystem::template View<dim, Number>;
32 using state_type = typename View::state_type;
33
34 Function(const HyperbolicSystem &hyperbolic_system,
35 const std::string subsection)
36 : InitialState<Description, dim, Number>("function", subsection)
37 , hyperbolic_system_(hyperbolic_system)
38 {
39
40 depth_expression_ = "1.4";
41 this->add_parameter(
42 "water elevation expression",
43 depth_expression_,
44 "A function expression describing the water elevation. When "
45 "bathymetry is 0, this reduces to the water depth.");
46
47 bathymetry_expression_ = "0.";
48 this->add_parameter("bathymetry expression",
49 bathymetry_expression_,
50 "A function expression describing the bathymetry");
51
52
53 velocity_x_expression_ = "3.0";
54 this->add_parameter(
55 "velocity x expression",
56 velocity_x_expression_,
57 "A function expression describing the x-component of the velocity");
58
59 if constexpr (dim > 1) {
60 velocity_y_expression_ = "0.0";
61 this->add_parameter("velocity y expression",
62 velocity_y_expression_,
63 "A function expression describing the "
64 "y-component of the velocity");
65 }
66
67 /*
68 * Set up the muparser object with the final flux description from
69 * the parameter file:
70 */
71 const auto set_up_muparser = [this] {
72 using FP = dealii::FunctionParser<dim>;
73 /*
74 * This variant of the constructor initializes the function
75 * parser with support for a time-dependent description involving
76 * a variable »t«:
77 */
78 depth_function_ = std::make_unique<FP>(depth_expression_);
79 velocity_x_function_ = std::make_unique<FP>(velocity_x_expression_);
80 if constexpr (dim > 1)
81 velocity_y_function_ = std::make_unique<FP>(velocity_y_expression_);
82 bathymetry_function_ = std::make_unique<FP>(bathymetry_expression_);
83 };
84
85 set_up_muparser();
86 this->parse_parameters_call_back.connect(set_up_muparser);
87 }
88
89 state_type compute(const dealii::Point<dim> &point, Number t) final
90 {
91 const auto view = hyperbolic_system_.template view<dim, Number>();
92 state_type full_primitive;
93
94 /* Compute bathymetry */
95 const Number z = compute_bathymetry(point);
96
97 depth_function_->set_time(t);
98 full_primitive[0] =
99 std::max(Number(depth_function_->value(point)) - z, Number(0.));
100
101 velocity_x_function_->set_time(t);
102 full_primitive[1] = velocity_x_function_->value(point);
103
104 if constexpr (dim > 1) {
105 velocity_y_function_->set_time(t);
106 full_primitive[2] = velocity_y_function_->value(point);
107 }
108
109 return view.from_primitive_state(full_primitive);
110 }
111
112 auto initial_precomputations(const dealii::Point<dim> &point) ->
114 initial_precomputed_type final
115 {
116 /* Compute bathymetry: */
117 return {compute_bathymetry(point)};
118 }
119
120 private:
121 const HyperbolicSystem &hyperbolic_system_;
122
123 std::string depth_expression_;
124 std::string velocity_x_expression_;
125 std::string velocity_y_expression_;
126 std::string bathymetry_expression_;
127
128 std::unique_ptr<dealii::FunctionParser<dim>> depth_function_;
129 std::unique_ptr<dealii::FunctionParser<dim>> velocity_x_function_;
130 std::unique_ptr<dealii::FunctionParser<dim>> velocity_y_function_;
131 std::unique_ptr<dealii::FunctionParser<dim>> bathymetry_function_;
132
133 DEAL_II_ALWAYS_INLINE inline Number
134 compute_bathymetry(const dealii::Point<dim> &point) const
135 {
136 bathymetry_function_->set_time(0.);
137 return bathymetry_function_->value(point);
138 }
139 };
140 } // namespace ShallowWaterInitialStates
141} // namespace ryujin
typename HyperbolicSystem::template View< dim, Number > View
auto initial_precomputations(const dealii::Point< dim > &point) -> typename InitialState< Description, dim, Number >::initial_precomputed_type final
state_type compute(const dealii::Point< dim > &point, Number t) final
typename Description::HyperbolicSystem HyperbolicSystem
Function(const HyperbolicSystem &hyperbolic_system, const std::string subsection)
Euler::HyperbolicSystem HyperbolicSystem
Definition description.h:34