Finite Volume Solver  prototype
A framework to build finite volume solvers for the AG Klein at the Freie Universität Berlin.
CompressibleAdvection.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_COMPRESSIBLE_ADVECTION_HPP
22 #define FUB_EQUATIONS_COMPRESSIBLE_ADVECTION_HPP
23 
24 #include "fub/State.hpp"
25 #include "fub/StateArray.hpp"
26 
27 #include "fub/CompleteFromCons.hpp"
28 #include "fub/Equation.hpp"
30 #include "fub/ext/Eigen.hpp"
31 
33 
34 #include <array>
35 
36 namespace fub {
37 
38 /// This is a template class for constructing conservative states for the
39 /// perfect gas equations.
40 template <typename Density, typename Momentum, typename PTDensity>
44  PTDensity PTdensity;
45 };
46 
47 template <int VelocityRank>
50  ScalarDepth>;
51 
52 // We "register" the conservative state with our framework.
53 // This enables us to name and iterate over all member variables in a given
54 // conservative state.
55 template <typename... Xs>
57  static constexpr auto names =
58  std::make_tuple("Density", "Momentum", "PTdensity");
59 
60  static constexpr auto pointers_to_member =
64 
65  template <int Rank> using Depths = CompressibleAdvectionConsShape<Rank>;
66 };
67 
68 template <typename Density, typename Momentum, typename PTDensity,
69  typename PTInverse>
71  : CompressibleAdvectionConservative<Density, Momentum, PTDensity> {
72  PTInverse PTinverse;
73 };
74 
75 template <int VelocityRank>
79 
80 // We "register" the complete state with our framework.
81 // This enables us to name and iterate over all member variables in a given
82 // compete state.
83 template <typename... Xs>
85  static constexpr auto names =
86  std::make_tuple("Density", "Momentum", "PTdensity", "PTinverse");
87  static constexpr auto pointers_to_member =
92 
93  template <int VelocityDim>
95 };
96 
97 template <int N, int VelocityDim = N> struct CompressibleAdvection {
100 
103 
104  static constexpr int Rank() noexcept { return N; }
105  static constexpr int VelocityRank() noexcept { return VelocityDim; }
106 
107  void CompleteFromCons(Complete& state, const Conservative& cons) {
108  state.density = cons.density;
109  state.momentum = cons.momentum;
110  state.PTdensity = cons.PTdensity;
111  state.PTinverse = cons.density / cons.PTdensity;
112  }
113 
114 private:
115  /// This specializes the customization point object "fub::Depth" for this
116  /// equation. It is needed to determine the number of components for each
117  /// registered variable and helps to create views on multi dimensional arrays.
118  template <typename State>
119  friend constexpr auto tag_invoke(fub::DepthsFn, const CompressibleAdvection&,
120  Type<State>) noexcept {
121  return typename State::Traits::template Depths<VelocityDim>{};
122  }
123 };
124 
125 /// This is a special FluxMethod class that uses the stored Pv field within the
126 /// CompressibleAdvectionIntegratorContext sa advection velocities.
127 template <int SpaceDimension, int VelocityDimension = SpaceDimension>
129  using Conservative =
130  typename CompressibleAdvection<SpaceDimension,
131  VelocityDimension>::Conservative;
132  using Complete = typename CompressibleAdvection<SpaceDimension,
133  VelocityDimension>::Complete;
134 
135  constexpr static int GetStencilWidth() { return 2; }
136 
138  GetEquation() const noexcept {
139  return {};
140  }
141 
143  Direction dir);
144 
145  static Duration
148  double dx, Direction dir);
149 
150  static Conservative
151  ComputeNumericFluxes(const std::array<Complete, 4>& stencil,
152  const std::array<double, 5> Pvs, Duration dt, double dx,
153  Direction dir);
154 
155  static void ComputeNumericFluxes(amrex::IntegratorContext& context, int level,
156  Duration dt, Direction dir);
157 
158  static void
160  const View<const Complete>& states,
162  Duration dt, double dx, Direction dir);
163 };
164 
165 // We define this class only for dimensions 1 to 3.
166 // The definitions will be found in its source file CompressibleAdvection.cpp
167 // extern template struct CompressibleAdvection<2>;
168 extern template struct CompressibleAdvectionFluxMethod<2>;
169 
170 } // namespace fub
171 
172 #endif
This class is used by the HypebrolicSplitLevelIntegrator and delegates AMR related tasks to the AMReX...
Definition: AMReX/IntegratorContext.hpp:49
constexpr struct fub::euler::MomentumFn Momentum
constexpr struct fub::euler::DensityFn Density
The fub namespace.
Definition: AnyBoundaryCondition.hpp:31
std::chrono::duration< double > Duration
Definition: Duration.hpp:31
Direction
This is a type safe type to denote a dimensional split direction.
Definition: Direction.hpp:30
Definition: State.hpp:403
This type has a constructor which takes an equation and might allocate any dynamically sized member v...
Definition: State.hpp:335
Definition: CompressibleAdvection.hpp:71
PTInverse PTinverse
Definition: CompressibleAdvection.hpp:72
This is a template class for constructing conservative states for the perfect gas equations.
Definition: CompressibleAdvection.hpp:41
Momentum momentum
Definition: CompressibleAdvection.hpp:43
PTDensity PTdensity
Definition: CompressibleAdvection.hpp:44
Density density
Definition: CompressibleAdvection.hpp:42
This is a special FluxMethod class that uses the stored Pv field within the CompressibleAdvectionInte...
Definition: CompressibleAdvection.hpp:128
static Duration ComputeStableDt(const View< const Complete > &states, const StridedDataView< const double, SpaceDimension > Pv, double dx, Direction dir)
static void ComputeNumericFluxes(const View< Conservative > &fluxes, const View< const Complete > &states, const StridedDataView< const double, SpaceDimension > &Pv, Duration dt, double dx, Direction dir)
CompressibleAdvection< SpaceDimension, VelocityDimension > GetEquation() const noexcept
Definition: CompressibleAdvection.hpp:138
typename CompressibleAdvection< SpaceDimension, VelocityDimension >::Complete Complete
Definition: CompressibleAdvection.hpp:133
constexpr static int GetStencilWidth()
Definition: CompressibleAdvection.hpp:135
Duration ComputeStableDt(amrex::IntegratorContext &context, int level, Direction dir)
static void ComputeNumericFluxes(amrex::IntegratorContext &context, int level, Duration dt, Direction dir)
typename CompressibleAdvection< SpaceDimension, VelocityDimension >::Conservative Conservative
Definition: CompressibleAdvection.hpp:131
static Conservative ComputeNumericFluxes(const std::array< Complete, 4 > &stencil, const std::array< double, 5 > Pvs, Duration dt, double dx, Direction dir)
Definition: CompressibleAdvection.hpp:97
static constexpr int VelocityRank() noexcept
Definition: CompressibleAdvection.hpp:105
void CompleteFromCons(Complete &state, const Conservative &cons)
Definition: CompressibleAdvection.hpp:107
constexpr friend auto tag_invoke(fub::DepthsFn, const CompressibleAdvection &, Type< State >) noexcept
This specializes the customization point object "fub::Depth" for this equation.
Definition: CompressibleAdvection.hpp:119
static constexpr int Rank() noexcept
Definition: CompressibleAdvection.hpp:104
This type has a constructor which takes an equation and might allocate any dynamically sized member v...
Definition: State.hpp:251
Definition: State.hpp:166
Definition: PatchDataView.hpp:201
This type is used to tag scalar quantities.
Definition: State.hpp:109
Definition: State.hpp:35
Definition: State.hpp:162