Finite Volume Solver  prototype
A framework to build finite volume solvers for the AG Klein at the Freie Universität Berlin.
Advection.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_ADVECTION_HPP
22 #define FUB_EQUATIONS_ADVECTION_HPP
23 
24 // #include "fub/Equation.hpp"
25 #include "fub/Direction.hpp"
27 #include "fub/State.hpp"
28 #include "fub/StateArray.hpp"
29 #include "fub/ext/Eigen.hpp"
30 
34 
35 #include <array>
36 
37 namespace fub {
38 template <typename Mass> struct AdvectionVariables { Mass mass; };
39 
40 template <typename... Xs> struct StateTraits<AdvectionVariables<Xs...>> {
41  static constexpr auto names = std::make_tuple("Mass");
42  static constexpr auto pointers_to_member =
43  std::make_tuple(&AdvectionVariables<Xs...>::mass);
44 
45  template <int Rank> using Depths = AdvectionVariables<ScalarDepth>;
46 };
47 
48 /// \ingroup Equations
49 /// This class descibes the 2-dimensional advection equation with constant
50 /// transport velocity.
51 struct Advection2d {
54 
57 
60 
61  /// Constructs an equation object with velocity `v`.
62  Advection2d(const std::array<double, 2>& v) noexcept : velocity{v} {}
63 
64  /// Returns 2, which is the space dimension for this equation.
65  static constexpr int Rank() { return 2; }
66 
67  /// Computes the linear transport flux in the specified direction.
68  ///
69  /// \param[out] flux The conservative state which will store the results.
70  /// \param[in] state The input state.
71  /// \param[in] dir The split direction of this flux.
72  void Flux(Conservative& flux, const Complete& state, Direction dir) const
73  noexcept;
74 
75  /// Computes the linear transport flux in the specified direction (Array
76  /// version).
77  ///
78  /// \param[out] flux The conservative state which will store the results.
79  /// \param[in] state The input state.
80  /// \param[in] dir The split direction of this flux.
81  void Flux(ConservativeArray& flux, const CompleteArray& state,
82  Direction dir) const noexcept;
83 
84  /// This member variable stores the constant transport velocity.
85  std::array<double, 2> velocity;
86 };
87 
88 template <> class ExactRiemannSolver<Advection2d> {
89 public:
90  using Complete = typename Advection2d::Complete;
92 
93  ExactRiemannSolver(const Advection2d& equation) : equation_{equation} {}
94 
95  /// Returns either left or right, depending on the upwind velocity.
96  void SolveRiemannProblem(Complete& state, const Complete& left,
97  const Complete& right, Direction dir);
98 
99  /// Returns either left or right, depending on the upwind velocity.
101  const CompleteArray& right, Direction dir);
102 
103  /// Returns the upwind velocity in the specified direction.
104  std::array<double, 1> ComputeSignals(const Complete&, const Complete&,
105  Direction dir);
106 
107  /// Returns the upwind velocity in the specified direction.
108  std::array<Array1d, 1> ComputeSignals(const CompleteArray&,
109  const CompleteArray&, Direction dir);
110 
111 private:
113 };
114 
115 extern template class FluxMethod<Godunov<Advection2d>>;
116 extern template class FluxMethod<MusclHancock<Advection2d>>;
117 
118 } // namespace fub
119 
120 #endif
std::array< Array1d, 1 > ComputeSignals(const CompleteArray &, const CompleteArray &, Direction dir)
Returns the upwind velocity in the specified direction.
void SolveRiemannProblem(CompleteArray &state, const CompleteArray &left, const CompleteArray &right, Direction dir)
Returns either left or right, depending on the upwind velocity.
ExactRiemannSolver(const Advection2d &equation)
Definition: Advection.hpp:93
std::array< double, 1 > ComputeSignals(const Complete &, const Complete &, Direction dir)
Returns the upwind velocity in the specified direction.
typename Advection2d::CompleteArray CompleteArray
Definition: Advection.hpp:91
typename Advection2d::Complete Complete
Definition: Advection.hpp:90
void SolveRiemannProblem(Complete &state, const Complete &left, const Complete &right, Direction dir)
Returns either left or right, depending on the upwind velocity.
Advection2d equation_
Definition: Advection.hpp:112
Definition: ExactRiemannSolver.hpp:26
This class applies a base flux nethod on a view of states.
Definition: flux_method/FluxMethod.hpp:57
The fub namespace.
Definition: AnyBoundaryCondition.hpp:31
Direction
This is a type safe type to denote a dimensional split direction.
Definition: Direction.hpp:30
This class descibes the 2-dimensional advection equation with constant transport velocity.
Definition: Advection.hpp:51
::fub::CompleteArray< Advection2d > CompleteArray
Definition: Advection.hpp:58
void Flux(ConservativeArray &flux, const CompleteArray &state, Direction dir) const noexcept
Computes the linear transport flux in the specified direction (Array version).
std::array< double, 2 > velocity
This member variable stores the constant transport velocity.
Definition: Advection.hpp:85
AdvectionVariables< ScalarDepth > ConservativeDepths
Definition: Advection.hpp:52
static constexpr int Rank()
Returns 2, which is the space dimension for this equation.
Definition: Advection.hpp:65
Advection2d(const std::array< double, 2 > &v) noexcept
Constructs an equation object with velocity v.
Definition: Advection.hpp:62
void Flux(Conservative &flux, const Complete &state, Direction dir) const noexcept
Computes the linear transport flux in the specified direction.
::fub::Complete< Advection2d > Complete
Definition: Advection.hpp:55
Definition: Advection.hpp:38
Mass mass
Definition: Advection.hpp:38
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: State.hpp:35