Finite Volume Solver  prototype
A framework to build finite volume solvers for the AG Klein at the Freie Universität Berlin.
ShallowWater.hpp
Go to the documentation of this file.
1 // Copyright (c) 2019 Maikel Nadolski
2 //
3 // Permission is hereby granted, free of charge, to any person obtaining a copy
4 // of this software and associated documentation files (the "Software"), to deal
5 // in the Software without restriction, including without limitation the rights
6 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7 // copies of the Software, and to permit persons to whom the Software is
8 // furnished to do so, subject to the following conditions:
9 //
10 // The above copyright notice and this permission notice shall be included in
11 // all copies or substantial portions of the Software.
12 //
13 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19 // SOFTWARE.
20 
21 #ifndef FUB_EQUATIONS_SHALLOW_WATER_HPP
22 #define FUB_EQUATIONS_SHALLOW_WATER_HPP
23 
24 #include "fub/Equation.hpp"
26 #include "fub/State.hpp"
27 #include "fub/ext/Eigen.hpp"
28 
33 
34 #include <array>
35 
36 namespace fub {
37 template <typename Heigth, typename Momentum> struct ShallowWaterVariables {
38  Heigth height;
40 };
41 
42 template <typename... Xs> struct StateTraits<ShallowWaterVariables<Xs...>> {
43  static constexpr auto names = std::make_tuple("Height", "Momentum");
44 
45  static constexpr auto pointers_to_member =
46  std::make_tuple(&ShallowWaterVariables<Xs...>::height,
48 
50 };
51 
52 struct ShallowWater {
55 
58 
61 
62  static constexpr int Rank() noexcept { return 2; }
63 
64  void Flux(Conservative& flux, const Complete& state, Direction dir) const
65  noexcept;
66 
67  void Flux(ConservativeArray& flux, const CompleteArray& state,
68  Direction dir) const noexcept;
69 
70  double gravity_{10.0};
71 };
72 
73 template <> class ExactRiemannSolver<ShallowWater> {
74 public:
75  using Complete = typename ShallowWater::Complete;
77 
78  ExactRiemannSolver(const ShallowWater& equation) : equation_{equation} {}
79 
80  /// Returns either left or right, depending on the upwind velocity.
81  void SolveRiemannProblem(Complete& state, const Complete& left,
82  const Complete& right, Direction dir);
83 
84  /// Returns either left or right, depending on the upwind velocity.
86  const CompleteArray& right, Direction dir);
87 
88  /// Returns the upwind velocity in the specified direction.
89  std::array<double, 2> ComputeSignals(const Complete&, const Complete&,
90  Direction dir);
91 
92  /// Returns the upwind velocity in the specified direction.
93  std::array<Array1d, 2> ComputeSignals(const CompleteArray&,
94  const CompleteArray&, Direction dir);
95 
96  Complete ComputeMiddleState(const Complete& left, const Complete& right,
97  Direction dir);
98 
99 private:
101 };
102 
106 
107  std::array<double, 2> operator()(const ShallowWater& equation,
108  const Complete& left, const Complete& right,
109  Direction dir);
110 
111  std::array<Array1d, 2> operator()(const ShallowWater& equation,
112  const CompleteArray& left,
113  const CompleteArray& right, Direction dir);
114 };
115 
116 extern template class FluxMethod<
118 
119 extern template class FluxMethod<Godunov<ShallowWater>>;
120 
121 extern template class FluxMethod<MusclHancock<ShallowWater>>;
122 
123 extern template class FluxMethod<MusclHancock<
125 
126 } // namespace fub
127 
128 #endif
void SolveRiemannProblem(Complete &state, const Complete &left, const Complete &right, Direction dir)
Returns either left or right, depending on the upwind velocity.
std::array< Array1d, 2 > ComputeSignals(const CompleteArray &, const CompleteArray &, Direction dir)
Returns the upwind velocity in the specified direction.
ExactRiemannSolver(const ShallowWater &equation)
Definition: ShallowWater.hpp:78
ShallowWater equation_
Definition: ShallowWater.hpp:100
typename ShallowWater::CompleteArray CompleteArray
Definition: ShallowWater.hpp:76
void SolveRiemannProblem(CompleteArray &state, const CompleteArray &left, const CompleteArray &right, Direction dir)
Returns either left or right, depending on the upwind velocity.
Complete ComputeMiddleState(const Complete &left, const Complete &right, Direction dir)
typename ShallowWater::Complete Complete
Definition: ShallowWater.hpp:75
std::array< double, 2 > ComputeSignals(const Complete &, const Complete &, Direction dir)
Returns the upwind velocity in the specified direction.
Definition: ExactRiemannSolver.hpp:26
This class applies a base flux nethod on a view of states.
Definition: flux_method/FluxMethod.hpp:57
Definition: HllMethod.hpp:139
constexpr struct fub::euler::MomentumFn Momentum
The fub namespace.
Definition: AnyBoundaryCondition.hpp:31
Direction
This is a type safe type to denote a dimensional split direction.
Definition: Direction.hpp:30
Definition: StateArray.hpp:178
This type has a constructor which takes an equation and might allocate any dynamically sized member v...
Definition: State.hpp:335
Definition: StateArray.hpp:135
This type has a constructor which takes an equation and might allocate any dynamically sized member v...
Definition: State.hpp:251
Definition: HllMethod.hpp:150
Definition: flux_method/MusclHancockMethod.hpp:193
Definition: ShallowWater.hpp:103
std::array< double, 2 > operator()(const ShallowWater &equation, const Complete &left, const Complete &right, Direction dir)
std::array< Array1d, 2 > operator()(const ShallowWater &equation, const CompleteArray &left, const CompleteArray &right, Direction dir)
Definition: ShallowWater.hpp:37
Heigth height
Definition: ShallowWater.hpp:38
Momentum momentum
Definition: ShallowWater.hpp:39
Definition: ShallowWater.hpp:52
ShallowWaterVariables< ScalarDepth, VectorDepth< 2 > > ConservativeDepths
Definition: ShallowWater.hpp:53
void Flux(Conservative &flux, const Complete &state, Direction dir) const noexcept
::fub::CompleteArray< ShallowWater > CompleteArray
Definition: ShallowWater.hpp:60
void Flux(ConservativeArray &flux, const CompleteArray &state, Direction dir) const noexcept
::fub::Complete< ShallowWater > Complete
Definition: ShallowWater.hpp:57
static constexpr int Rank() noexcept
Definition: ShallowWater.hpp:62
double gravity_
Definition: ShallowWater.hpp:70
Definition: State.hpp:35