Finite Volume Solver  prototype
A framework to build finite volume solvers for the AG Klein at the Freie Universität Berlin.
boundary_condition/TransmissiveBoundary.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_BOUNDARY_CONDITION_TRANSMISSIVE_BOUNDARY_HPP
22 #define FUB_BOUNDARY_CONDITION_TRANSMISSIVE_BOUNDARY_HPP
23 
27 #include "fub/Equation.hpp"
28 #include "fub/State.hpp"
29 
30 namespace fub {
31 
32 template <typename Eq> struct TransmissiveBoundary {
33  using Equation = Eq;
36 
37  static constexpr int Rank = Equation::Rank();
38  static constexpr std::size_t sRank = static_cast<std::size_t>(Rank);
39 
40  explicit TransmissiveBoundary(const Equation& eq) : equation_{eq} {}
41  explicit TransmissiveBoundary(const Equation& eq, const Complete& fallback)
42  : equation_{eq}, fallback_state_{fallback} {}
43 
45  const fub::amrex::PatchHierarchy&, fub::amrex::PatchHandle,
46  fub::Location location, int fill_width, fub::Duration) {
47  fub::BasicView<Complete> complete =
48  fub::amrex::MakeView<fub::BasicView<Complete>>(data, equation_);
49  fub::IndexBox<Rank> box = Box<0>(complete);
50  FUB_ASSERT(location.side == 0 || location.side == 1);
51  std::array<std::ptrdiff_t, sRank> lower = box.lower;
52  std::array<std::ptrdiff_t, sRank> upper = box.upper;
53  if (location.side == 0) {
54  upper[location.direction] = lower[location.direction] + fill_width;
55  const fub::IndexBox<Rank> fill_box{lower, upper};
56  fub::ForEachIndex(fill_box, [&](auto... is) {
57  const std::array<std::ptrdiff_t, sRank> dest_index{is...};
58  std::array<std::ptrdiff_t, sRank> source_index = dest_index;
59  source_index[location.direction] = upper[location.direction];
60  Load(state_, AsConst(complete), source_index);
61  Store(complete, state_, dest_index);
62  });
63  } else {
64  lower[location.direction] = upper[location.direction] - fill_width;
65  const fub::IndexBox<Rank> fill_box{lower, upper};
66  fub::ForEachIndex(fill_box, [&](auto... is) {
67  const std::array<std::ptrdiff_t, sRank> dest_index{is...};
68  std::array<std::ptrdiff_t, sRank> source_index = dest_index;
69  source_index[location.direction] =
70  upper[location.direction] - fill_width - 1;
71  Load(state_, AsConst(complete), source_index);
72  Store(complete, state_, dest_index);
73  });
74  }
75  }
76 
79  fub::amrex::PatchHandle, fub::Location location,
80  int fill_width, fub::Duration) {
81  fub::BasicView<Complete> complete =
82  fub::amrex::MakeView<fub::BasicView<Complete>>(data, equation_);
83  fub::IndexBox<Rank> box = Box<0>(complete);
84  FUB_ASSERT(location.side == 0 || location.side == 1);
85  std::array<std::ptrdiff_t, sRank> lower = box.lower;
86  std::array<std::ptrdiff_t, sRank> upper = box.upper;
87  if (location.side == 0) {
88  upper[location.direction] = lower[location.direction] + fill_width;
89  const fub::IndexBox<Rank> fill_box{lower, upper};
90  fub::ForEachIndex(fill_box, [&](auto... is) {
91  const std::array<std::ptrdiff_t, sRank> dest_index{is...};
92  std::array<std::ptrdiff_t, sRank> source_index = dest_index;
93  source_index[location.direction] = upper[location.direction];
94  Load(state_, AsConst(complete), source_index);
95  if (!AnyNaN(state_)) {
96  Store(complete, state_, dest_index);
97  } else {
98  Store(complete, fallback_state_, dest_index);
99  }
100  });
101  } else {
102  lower[location.direction] = upper[location.direction] - fill_width;
103  const fub::IndexBox<Rank> fill_box{lower, upper};
104  fub::ForEachIndex(fill_box, [&](auto... is) {
105  const std::array<std::ptrdiff_t, sRank> dest_index{is...};
106  std::array<std::ptrdiff_t, sRank> source_index = dest_index;
107  source_index[location.direction] =
108  upper[location.direction] - fill_width - 1;
109  Load(state_, AsConst(complete), source_index);
110  if (!AnyNaN(state_)) {
111  Store(complete, state_, dest_index);
112  } else {
113  Store(complete, fallback_state_, dest_index);
114  }
115  });
116  }
117  }
118 
122 };
123 
124 } // namespace fub
125 
126 #endif
#define FUB_ASSERT(x)
Definition: assert.hpp:39
The PatchHierarchy holds simulation data on multiple refinement levels.
Definition: AMReX/PatchHierarchy.hpp:156
Definition: AMReX/cutcell/PatchHierarchy.hpp:139
Function ForEachIndex(const layout_left::mapping< Extents > &mapping, Function function)
Iterate through the multi-dimensional index space descibed by mapping and invoke function for each su...
Definition: ForEach.hpp:74
The fub namespace.
Definition: AnyBoundaryCondition.hpp:31
std::chrono::duration< double > Duration
Definition: Duration.hpp:31
bool AnyNaN(const Complete< Equation > &state)
Definition: State.hpp:719
void Load(State &state, const BasicView< const State, Layout, Rank > &view, const std::array< std::ptrdiff_t, State::Equation::Rank()> &index)
Definition: State.hpp:640
void Store(const BasicView< Conservative< Eq >, Layout, Eq::Rank()> &view, const Conservative< Eq > &state, const std::array< std::ptrdiff_t, Eq::Rank()> &index)
Definition: State.hpp:663
BasicView< const State, Layout, Rank > AsConst(const BasicView< State, Layout, Rank > &v)
Definition: State.hpp:431
Definition: State.hpp:403
Definition: PatchDataView.hpp:56
Definition: Direction.hpp:36
int side
Definition: Direction.hpp:38
std::size_t direction
Definition: Direction.hpp:37
Definition: PatchDataView.hpp:201
Definition: boundary_condition/TransmissiveBoundary.hpp:32
Complete fallback_state_
Definition: boundary_condition/TransmissiveBoundary.hpp:121
Complete state_
Definition: boundary_condition/TransmissiveBoundary.hpp:120
TransmissiveBoundary(const Equation &eq)
Definition: boundary_condition/TransmissiveBoundary.hpp:40
static constexpr std::size_t sRank
Definition: boundary_condition/TransmissiveBoundary.hpp:38
void operator()(const fub::PatchDataView< double, AMREX_SPACEDIM+1 > &data, const fub::amrex::cutcell::PatchHierarchy &, fub::amrex::PatchHandle, fub::Location location, int fill_width, fub::Duration)
Definition: boundary_condition/TransmissiveBoundary.hpp:77
TransmissiveBoundary(const Equation &eq, const Complete &fallback)
Definition: boundary_condition/TransmissiveBoundary.hpp:41
Equation equation_
Definition: boundary_condition/TransmissiveBoundary.hpp:119
Eq Equation
Definition: boundary_condition/TransmissiveBoundary.hpp:33
static constexpr int Rank
Definition: boundary_condition/TransmissiveBoundary.hpp:37
void operator()(const fub::PatchDataView< double, AMREX_SPACEDIM+1 > &data, const fub::amrex::PatchHierarchy &, fub::amrex::PatchHandle, fub::Location location, int fill_width, fub::Duration)
Definition: boundary_condition/TransmissiveBoundary.hpp:44