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