Finite Volume Solver  prototype
A framework to build finite volume solvers for the AG Klein at the Freie Universität Berlin.
IndexSpace.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_AMREX_CUTCELL_INDEX_SPACE_HPP
22 #define FUB_AMREX_CUTCELL_INDEX_SPACE_HPP
23 
24 #include <AMReX.H>
25 
26 #ifdef AMREX_USE_EB
29 
30 #include <AMReX_EB2.H>
31 
32 #include <vector>
33 
34 namespace fub {
35 namespace amrex {
36 namespace cutcell {
37 
38 constexpr std::ptrdiff_t ipow(int base, int exponent) {
39  std::ptrdiff_t prod{1};
40  while (exponent > 0) {
41  prod *= base;
42  exponent -= 1;
43  }
44  return prod;
45 }
46 
47 template <typename GShop>
48 std::vector<const ::amrex::EB2::IndexSpace*>
49 MakeIndexSpaces(GShop&& shop, const ::amrex::Geometry& coarse_geom, int n_level,
50  int ngrow = 4) {
51  FUB_ASSERT(n_level > 0);
52  std::vector<const ::amrex::EB2::IndexSpace*> index_spaces(
53  static_cast<std::size_t>(n_level));
54  ::amrex::Geometry geom = coarse_geom;
55  ::amrex::EB2::Build(shop, geom, 0, 0, ngrow);
56  index_spaces[0] = &::amrex::EB2::IndexSpace::top();
57  for (int level = 1; level < n_level; ++level) {
58  geom.refine({AMREX_D_DECL(2, 2, 2)});
59  ::amrex::EB2::Build(shop, geom, 1, 2, ngrow);
60  index_spaces[static_cast<std::size_t>(level)] =
61  &::amrex::EB2::IndexSpace::top();
62  }
63  return index_spaces;
64 }
65 
66 template <typename GShop>
67 std::vector<const ::amrex::EB2::IndexSpace*>
68 MakeIndexSpaces(GShop&& shop, const CartesianGridGeometry& grid_geometry,
69  const fub::amrex::PatchHierarchyOptions& hierarchy_options) {
70  return MakeIndexSpaces(shop, GetCoarseGeometry(grid_geometry),
71  hierarchy_options.max_number_of_levels);
72 }
73 
74 } // namespace cutcell
75 } // namespace amrex
76 } // namespace fub
77 #endif
78 
79 #endif
#define FUB_ASSERT(x)
Definition: assert.hpp:39
::amrex::Geometry GetCoarseGeometry(const CartesianGridGeometry &grid_geometry)
The fub namespace.
Definition: AnyBoundaryCondition.hpp:31
constexpr std::ptrdiff_t ipow(int base, int exponent)
Definition: algorithm.hpp:39
Definition: AMReX/PatchHierarchy.hpp:54
int max_number_of_levels
Definition: AMReX/PatchHierarchy.hpp:60