Finite Volume Solver  prototype
A framework to build finite volume solvers for the AG Klein at the Freie Universität Berlin.
boundary_condition/ConstantBoundary.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_BOUNDARY_CONDITION_CONSTANT_BOUNDARY_HPP
22 #define FUB_AMREX_BOUNDARY_CONDITION_CONSTANT_BOUNDARY_HPP
23 
25 
26 #include "fub/AMReX/ForEachFab.hpp"
28 #include "fub/Direction.hpp"
29 #include "fub/ForEach.hpp"
30 
31 #include <AMReX_MultiFab.H>
32 
33 namespace fub::amrex {
34 
35 /// \ingroup BoundaryCondition
36 ///
37 template <typename Equation> struct ConstantBoundary {
39  int side;
42 
43  void FillBoundary(::amrex::MultiFab& mf, const GriddingAlgorithm& grid,
44  int level) {
45  const ::amrex::Geometry& geom = grid.GetPatchHierarchy().GetGeometry(level);
46  FillBoundary(mf, geom);
47  }
48 
49  void FillBoundary(::amrex::MultiFab& mf, const GriddingAlgorithm& gridding,
50  int level, Direction dir) {
51  if (dir == this->dir) {
52  FillBoundary(mf, gridding, level);
53  }
54  }
55 
56  void FillBoundary(::amrex::MultiFab& mf, const ::amrex::Geometry& geom) {
57  int idir = static_cast<int>(dir);
58  if (!geom.isPeriodic(idir)) {
59  const int ngrow = mf.nGrow(idir);
60  ::amrex::Box fully_grown_box = geom.growNonPeriodicDomain(ngrow);
61  ::amrex::Box grown_dir_box = ::amrex::grow(fully_grown_box, idir, -ngrow);
62  ::amrex::BoxList boundaries = ::amrex::complementIn(
63  fully_grown_box, ::amrex::BoxList{grown_dir_box});
64  if (boundaries.isEmpty()) {
65  return;
66  }
67  ForEachFab(fub::execution::openmp, mf, [&](const ::amrex::MFIter& mfi) {
68  ::amrex::FArrayBox& fab = mf[mfi];
69  for (const ::amrex::Box& boundary : boundaries) {
70  ::amrex::Box shifted =
71  ::amrex::shift(boundary, idir, GetSign(side) * ngrow);
72  if (!geom.Domain().intersects(shifted)) {
73  continue;
74  }
75  ::amrex::Box box_to_fill = mfi.growntilebox() & boundary;
76  if (!box_to_fill.isEmpty()) {
77  auto states =
78  MakeView<Complete<Equation>>(fab, equation, box_to_fill);
79  ForEachIndex(Box<0>(states),
80  [&](auto... is) { Store(states, state, {is...}); });
81  }
82  }
83  });
84  }
85  }
86 };
87 
88 } // namespace fub::amrex
89 
90 #endif
This class modifies and initializes a PatchLevel in a PatchHierarchy.
Definition: AMReX/GriddingAlgorithm.hpp:60
PatchHierarchy & GetPatchHierarchy() noexcept
Definition: AMReX/GriddingAlgorithm.hpp:108
const ::amrex::Geometry & GetGeometry(int level) const
Returns a Geometry object for a specified level.
void ForEachFab(Tag, const ::amrex::FabArrayBase &fabarray, F function)
Iterate through all local FArrayBox objects in a MultiFab.
Definition: ForEachFab.hpp:34
The amrex namespace.
Definition: AverageState.hpp:33
void ForEachIndex(const ::amrex::Box &box, F function)
Definition: ForEachIndex.hpp:29
constexpr OpenMpTag openmp
Definition: Execution.hpp:37
std::decay_t< decltype(std::declval< T >().GetEquation())> Equation
A template typedef to detect the member function.
Definition: Meta.hpp:59
int GetSign(int side)
Definition: AnyBoundaryCondition.hpp:104
Direction
This is a type safe type to denote a dimensional split direction.
Definition: Direction.hpp:30
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
IndexBox< Rank > Box(const BasicView< State, Layout, Rank > &view)
Definition: State.hpp:486
Definition: boundary_condition/ConstantBoundary.hpp:37
Equation equation
Definition: boundary_condition/ConstantBoundary.hpp:40
Complete< Equation > state
Definition: boundary_condition/ConstantBoundary.hpp:41
int side
Definition: boundary_condition/ConstantBoundary.hpp:39
void FillBoundary(::amrex::MultiFab &mf, const GriddingAlgorithm &grid, int level)
Definition: boundary_condition/ConstantBoundary.hpp:43
void FillBoundary(::amrex::MultiFab &mf, const ::amrex::Geometry &geom)
Definition: boundary_condition/ConstantBoundary.hpp:56
void FillBoundary(::amrex::MultiFab &mf, const GriddingAlgorithm &gridding, int level, Direction dir)
Definition: boundary_condition/ConstantBoundary.hpp:49
Direction dir
Definition: boundary_condition/ConstantBoundary.hpp:38