ryujin 2.1.1 revision ef0fcd4010d109b860652ece4a7b8963fb7d46b1
initial_state_geotiff.h
Go to the documentation of this file.
1//
2// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
3// Copyright (C) 2024 - 2024 by the ryujin authors
4//
5
6#pragma once
7
8#include <compile_time_options.h>
9
10#include <geotiff_reader.h>
12#include <lazy.h>
13
14#include <deal.II/base/function_parser.h>
15
16namespace ryujin
17{
18 namespace ShallowWaterInitialStates
19 {
27 template <typename Description, int dim, typename Number>
28 class GeoTIFF : public InitialState<Description, dim, Number>
29 {
30 public:
32 using View =
33 typename Description::template HyperbolicSystemView<dim, Number>;
34 using state_type = typename View::state_type;
35
36
37 GeoTIFF(const HyperbolicSystem &hyperbolic_system,
38 const std::string subsection)
39 : InitialState<Description, dim, Number>("geotiff", subsection)
40 , hyperbolic_system_(hyperbolic_system)
41 , geotiff_reader_(subsection + "/geotiff")
42 {
43 height_expression_ = "1.4";
44 this->add_parameter(
45 "water height expression",
46 height_expression_,
47 "A function expression describing the initial total water height");
48
49 velocity_expression_ = "0.0";
50 this->add_parameter(
51 "velocity expression",
52 velocity_expression_,
53 "A function expression describing the initial velocity");
54
55 const auto set_up = [this] {
56 using FP = dealii::FunctionParser<dim>;
57 /*
58 * This variant of the constructor initializes the function
59 * parser with support for a time-dependent description involving
60 * a variable »t«:
61 */
62 height_function_ = std::make_unique<FP>(height_expression_);
63 velocity_function_ = std::make_unique<FP>(velocity_expression_);
64 };
65
66 set_up();
67 this->parse_parameters_call_back.connect(set_up);
68 }
69
70 state_type compute(const dealii::Point<dim> &point, Number t) final
71 {
72 const auto z = geotiff_reader_.compute_height(point);
73
74 dealii::Tensor<1, 2, Number> primitive;
75
76 height_function_->set_time(t);
77 primitive[0] = std::max(0., height_function_->value(point) - z);
78
79 velocity_function_->set_time(t);
80 primitive[1] = velocity_function_->value(point);
81
82 const auto view = hyperbolic_system_.template view<dim, Number>();
83 return view.from_initial_state(primitive);
84 }
85
86 auto initial_precomputations(const dealii::Point<dim> &point) ->
88 initial_precomputed_type final
89 {
90 /* Compute bathymetry: */
91 return {static_cast<Number>(geotiff_reader_.compute_height(point))};
92 }
93
94 private:
95 const HyperbolicSystem &hyperbolic_system_;
96 mutable GeoTIFFReader<dim> geotiff_reader_;
97
98 /* Runtime parameters: */
99
100 std::string height_expression_;
101 std::string velocity_expression_;
102
103 /* Fields for muparser support for water height and velocity: */
104
105 std::unique_ptr<dealii::FunctionParser<dim>> height_function_;
106 std::unique_ptr<dealii::FunctionParser<dim>> velocity_function_;
107 };
108 } // namespace ShallowWaterInitialStates
109} // namespace ryujin
typename Description::HyperbolicSystem HyperbolicSystem
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
GeoTIFF(const HyperbolicSystem &hyperbolic_system, const std::string subsection)
typename Description::template HyperbolicSystemView< dim, Number > View
Euler::HyperbolicSystem HyperbolicSystem
Definition: description.h:34