Finite Volume Solver  prototype
A framework to build finite volume solvers for the AG Klein at the Freie Universität Berlin.
AMReX/GriddingAlgorithm.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_GRIDDING_ALGORITHM_HPP
22 #define FUB_AMREX_GRIDDING_ALGORITHM_HPP
23 
26 
28 #include "fub/AnyInitialData.hpp"
29 #include "fub/AnyTaggingMethod.hpp"
30 
31 #include <AMReX_AmrCore.H>
32 #include <AMReX_MultiFabUtil.H>
33 
34 #include <memory>
35 
36 namespace fub {
37 namespace amrex {
38 
39 /// \defgroup GriddingAlgorithm Gridding Algorithms
40 /// This modules summarizes all gridding algorithms.
41 
42 class GriddingAlgorithm;
43 } // namespace amrex
44 
45 template <> struct GridTraits<amrex::GriddingAlgorithm> {
47  using TagDataHandle = ::amrex::TagBoxArray&;
48  using DataReference = ::amrex::MultiFab&;
49 };
50 
51 namespace amrex {
55 
56 /// \ingroup GriddingAlgorithm
57 ///
58 /// \brief This class modifies and initializes a PatchLevel in a
59 /// PatchHierarchy.
60 class GriddingAlgorithm : private ::amrex::AmrCore {
61 public:
62  /// @{
63  /// \name Constructors
64 
65  /// \brief Constructs an empty and invalid GriddingAlgorithm
67 
68  /// \brief Constructs a gridding algorithm and defines all customization
69  /// points
70  ///
71  /// \param hier The base PatchHierarchy that will be modified. It also
72  /// contains options that influence the box generation step.
73  ///
74  /// \param initial_data An InitialCondition policy object
75  ///
76  /// \param tagging A tagging routine masks cells that need further refinement.
77  ///
78  /// \param boundary The boundary condition fills the ghost layer for physical
79  /// domain boundary.
80  ///
81  /// \throw Throws `std::bad_alloc` if a memory allocation fails.
83  AnyTaggingMethod tagging,
85 
86  /// \brief The copy constructor makes a deep copy of the all data for each MPI
87  /// rank.
89 
90  /// \brief The copy assignment makes a deep copy of the all data for each MPI
91  /// rank.
93 
94  /// \brief The move constructor moves a gridding algorithm without allocating
95  /// any memory.
96  GriddingAlgorithm(GriddingAlgorithm&& other) noexcept = default;
97 
98  /// \brief The move assignment moves a gridding algorithm without allocating
99  /// any memory.
100  GriddingAlgorithm& operator=(GriddingAlgorithm&& other) noexcept = default;
101 
102  ~GriddingAlgorithm() noexcept override = default;
103  /// @}
104 
105  /// @{
106  /// \name Accessors
107 
109  const PatchHierarchy& GetPatchHierarchy() const noexcept {
110  return hierarchy_;
111  }
112 
113  [[nodiscard]] const AnyBoundaryCondition& GetBoundaryCondition() const
114  noexcept;
115 
116  [[nodiscard]] AnyBoundaryCondition& GetBoundaryCondition() noexcept;
117 
118  [[nodiscard]] const AnyInitialData& GetInitialCondition() const noexcept;
119 
120  [[nodiscard]] const AnyTaggingMethod& GetTagging() const noexcept;
121  /// @}
122 
123  /// @{
124  /// \name Observers
125 
126  /// \brief Returns the number of time steps taken on the coarsest refinement
127  /// level.
128  [[nodiscard]] std::ptrdiff_t GetCycles() const noexcept {
129  return hierarchy_.GetCycles();
130  }
131 
132  /// \brief Returns the current time point on the coarsest refinement level.
133  [[nodiscard]] Duration GetTimePoint() const noexcept {
134  return hierarchy_.GetTimePoint();
135  }
136  /// @}
137 
138 
139  /// @{
140  /// \name Modifiers
141 
142  /// \brief Attempt to regrid all finer level than the specified `which_level`.
143  ///
144  /// \return Returns the coarsest level which was regrid. If no level changed
145  /// this function returns the maximum number of levels.
146  int RegridAllFinerlevels(int which_level);
147 
148  /// \brief Initializes the underlying patch hierarchy using the stored initial
149  /// data method.
150  ///
151  /// \note This function might recreate a refinement level if nesting
152  /// conditions are violated upon creating a new refinement level. This implies
153  /// that the initial condition might be called multiple times for one
154  /// refinement level.
155  void InitializeHierarchy(double level_time = 0.0);
156  /// @}
157 
158  /// @{
159  /// \name Actions
160 
161  /// \brief Fill the ghost layer boundary specified of the specifed MultiFab
162  /// `mf`.
163  void FillMultiFabFromLevel(::amrex::MultiFab& mf, int level_number);
164  void FillMultiFabFromLevel(::amrex::MultiFab& mf, int level_number,
166  /// @}
167 
168 private:
169  void ErrorEst(int level, ::amrex::TagBoxArray& tags, double time_point,
170  int /* ngrow */) override;
171 
173  int level, double time_point, const ::amrex::BoxArray& box_array,
174  const ::amrex::DistributionMapping& distribution_mapping) override;
175 
177  int level, double time_point, const ::amrex::BoxArray& box_array,
178  const ::amrex::DistributionMapping& distribution_mapping) override;
179 
181  int level, double time_point, const ::amrex::BoxArray& box_array,
182  const ::amrex::DistributionMapping& distribution_mapping) override;
183 
184  void ClearLevel([[maybe_unused]] int level) override;
185 
190 };
191 
192 } // namespace amrex
193 } // namespace fub
194 
195 #endif
This is a polymorphic value type that wraps any BoundaryCondition object.
Definition: AnyBoundaryCondition.hpp:55
This class is a polymoprhic value type which stores components to initialize a gridding algorithm dur...
Definition: AnyInitialData.hpp:53
This class is a polymorphic value type that stores objects which satisfies the TaggingMethod<Gridding...
Definition: AnyTaggingMethod.hpp:48
This class modifies and initializes a PatchLevel in a PatchHierarchy.
Definition: AMReX/GriddingAlgorithm.hpp:60
AnyBoundaryCondition boundary_condition_
Definition: AMReX/GriddingAlgorithm.hpp:189
GriddingAlgorithm & operator=(const GriddingAlgorithm &other)
The copy assignment makes a deep copy of the all data for each MPI rank.
AnyInitialData initial_data_
Definition: AMReX/GriddingAlgorithm.hpp:187
GriddingAlgorithm(PatchHierarchy hier, AnyInitialData initial_data, AnyTaggingMethod tagging, AnyBoundaryCondition boundary=AnyBoundaryCondition())
Constructs a gridding algorithm and defines all customization points.
const AnyBoundaryCondition & GetBoundaryCondition() const noexcept
Duration GetTimePoint() const noexcept
Returns the current time point on the coarsest refinement level.
Definition: AMReX/GriddingAlgorithm.hpp:133
GriddingAlgorithm()
Constructs an empty and invalid GriddingAlgorithm.
const PatchHierarchy & GetPatchHierarchy() const noexcept
Definition: AMReX/GriddingAlgorithm.hpp:109
AnyTaggingMethod tagging_
Definition: AMReX/GriddingAlgorithm.hpp:188
void MakeNewLevelFromScratch(int level, double time_point, const ::amrex::BoxArray &box_array, const ::amrex::DistributionMapping &distribution_mapping) override
GriddingAlgorithm(const GriddingAlgorithm &other)
The copy constructor makes a deep copy of the all data for each MPI rank.
void FillMultiFabFromLevel(::amrex::MultiFab &mf, int level_number)
Fill the ghost layer boundary specified of the specifed MultiFab mf.
std::ptrdiff_t GetCycles() const noexcept
Returns the number of time steps taken on the coarsest refinement level.
Definition: AMReX/GriddingAlgorithm.hpp:128
~GriddingAlgorithm() noexcept override=default
Constructs an empty and invalid GriddingAlgorithm.
void ErrorEst(int level, ::amrex::TagBoxArray &tags, double time_point, int) override
GriddingAlgorithm(GriddingAlgorithm &&other) noexcept=default
The move constructor moves a gridding algorithm without allocating any memory.
int RegridAllFinerlevels(int which_level)
Attempt to regrid all finer level than the specified which_level.
void FillMultiFabFromLevel(::amrex::MultiFab &mf, int level_number, AnyBoundaryCondition &bc)
Fill the ghost layer boundary specified of the specifed MultiFab mf.
const AnyTaggingMethod & GetTagging() const noexcept
PatchHierarchy & GetPatchHierarchy() noexcept
Definition: AMReX/GriddingAlgorithm.hpp:108
void ClearLevel([[maybe_unused]] int level) override
GriddingAlgorithm & operator=(GriddingAlgorithm &&other) noexcept=default
The move assignment moves a gridding algorithm without allocating any memory.
void MakeNewLevelFromCoarse(int level, double time_point, const ::amrex::BoxArray &box_array, const ::amrex::DistributionMapping &distribution_mapping) override
PatchHierarchy hierarchy_
Definition: AMReX/GriddingAlgorithm.hpp:186
void RemakeLevel(int level, double time_point, const ::amrex::BoxArray &box_array, const ::amrex::DistributionMapping &distribution_mapping) override
void InitializeHierarchy(double level_time=0.0)
Initializes the underlying patch hierarchy using the stored initial data method.
const AnyInitialData & GetInitialCondition() const noexcept
The PatchHierarchy holds simulation data on multiple refinement levels.
Definition: AMReX/PatchHierarchy.hpp:156
std::ptrdiff_t GetCycles(int level=0) const
Duration GetTimePoint(int level=0) const
::fub::AnyBoundaryCondition< GriddingAlgorithm > AnyBoundaryCondition
Definition: AMReX/GriddingAlgorithm.hpp:54
std::decay_t< decltype(*std::declval< T >().GetGriddingAlgorithm())> GriddingAlgorithm
A template typedef to detect the member function.
Definition: Meta.hpp:56
The fub namespace.
Definition: AnyBoundaryCondition.hpp:31
std::chrono::duration< double > Duration
Definition: Duration.hpp:31
::amrex::MultiFab & DataReference
Definition: AMReX/GriddingAlgorithm.hpp:48
::amrex::TagBoxArray & TagDataHandle
Definition: AMReX/GriddingAlgorithm.hpp:47
Definition: Meta.hpp:67
The PatchLevel represents a distributed grid containing plain simulation data without a ghost cell la...
Definition: AMReX/PatchHierarchy.hpp:90