Finite Volume Solver  prototype
A framework to build finite volume solvers for the AG Klein at the Freie Universität Berlin.
MultiBlockGriddingAlgorithm2.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_COUPLED_GRIDDING_ALGORITHM2_HPP
22 #define FUB_AMREX_COUPLED_GRIDDING_ALGORITHM2_HPP
23 
25 
28 
30 
31 #include "fub/core/span.hpp"
32 
33 namespace fub {
34 namespace amrex {
35 
36 /// \ingroup GriddingAlgorithm
38 public:
39  template <typename TubeEquation, typename PlenumEquation>
41  const TubeEquation& tube_equation, const PlenumEquation& plenum_equation,
42  std::vector<std::shared_ptr<GriddingAlgorithm>> tubes,
43  std::vector<std::shared_ptr<cutcell::GriddingAlgorithm>> plena,
44  std::vector<BlockConnection> connectivity);
45 
49 
51  default;
52 
54  operator=(MultiBlockGriddingAlgorithm2&& other) noexcept = default;
55 
56  std::ptrdiff_t GetCycles() const noexcept { return plena_[0]->GetCycles(); }
57 
58  Duration GetTimePoint() const noexcept { return plena_[0]->GetTimePoint(); }
59 
61  GetTubes() const noexcept;
62  [[nodiscard]] span<const std::shared_ptr<cutcell::GriddingAlgorithm>>
63  GetPlena() const noexcept;
64 
65  [[nodiscard]] span<const BlockConnection> GetConnectivity() const noexcept;
66  [[nodiscard]] span<AnyMultiBlockBoundary>
67  GetBoundaries(int level = 0) noexcept {
68  return boundaries_[static_cast<std::size_t>(level)];
69  }
70 
71  void RegridAllFinerLevels(int which_level);
72 
73 private:
74  std::vector<std::shared_ptr<GriddingAlgorithm>> tubes_;
75  std::vector<std::shared_ptr<cutcell::GriddingAlgorithm>> plena_;
76  std::vector<BlockConnection> connectivity_;
77  std::vector<std::vector<AnyMultiBlockBoundary>> boundaries_;
78 };
79 
80 template <typename TubeEquation, typename PlenumEquation>
82  const TubeEquation& tube_equation, const PlenumEquation& plenum_equation,
83  std::vector<std::shared_ptr<GriddingAlgorithm>> tubes,
84  std::vector<std::shared_ptr<cutcell::GriddingAlgorithm>> plena,
85  std::vector<BlockConnection> connectivity)
86  : tubes_{std::move(tubes)}, plena_{std::move(plena)},
87  connectivity_(std::move(connectivity)) {
88  const int nlevel = plena_[0]->GetPatchHierarchy().GetMaxNumberOfLevels();
89  boundaries_.resize(static_cast<std::size_t>(nlevel));
90  int level = 0;
91  for (auto& boundaries : boundaries_) {
92  for (const BlockConnection& conn : connectivity_) {
93  boundaries.emplace_back(
94  MultiBlockBoundary2(tube_equation, plenum_equation), *this, conn,
95  conn.ghost_cell_width, level);
96  }
97  level += 1;
98  }
99 }
100 
101 } // namespace amrex
102 
103 template <typename PrintDuration>
104 class CounterOutput<amrex::MultiBlockGriddingAlgorithm2, PrintDuration>
105  : public OutputAtFrequencyOrInterval<amrex::MultiBlockGriddingAlgorithm2> {
106 public:
108  std::chrono::steady_clock::time_point ref)
109  : OutputAtFrequencyOrInterval<amrex::MultiBlockGriddingAlgorithm2>(po),
110  reference_{ref} {}
111 
113  : OutputAtFrequencyOrInterval<amrex::MultiBlockGriddingAlgorithm2>(po),
114  reference_{std::chrono::steady_clock::now()} {}
115 
116  CounterOutput(std::chrono::steady_clock::time_point reference,
117  std::vector<std::ptrdiff_t> frequencies,
118  std::vector<Duration> intervals)
119  : OutputAtFrequencyOrInterval<amrex::MultiBlockGriddingAlgorithm2>(
120  std::move(frequencies), std::move(intervals)),
121  reference_(reference) {}
122 
123  void operator()(const amrex::MultiBlockGriddingAlgorithm2& grid) override {
124  std::chrono::steady_clock::time_point now =
125  std::chrono::steady_clock::now();
126  auto diff =
127  std::chrono::duration_cast<std::chrono::nanoseconds>(now - reference_);
128  std::vector<CounterResult> statistics = grid.GetPlena()[0]
129  ->GetPatchHierarchy()
130  .GetCounterRegistry()
131  ->gather_statistics();
132  if (statistics.size()) {
133  print_statistics<PrintDuration>(statistics, diff.count());
134  }
135  }
136 
137 private:
138  std::chrono::steady_clock::time_point reference_;
139 };
140 
141 } // namespace fub
142 
143 #endif // FUB_AMREX_COUPLED_GRIDDING_ALGORITHM_HPP
CounterOutput(const ProgramOptions &po)
Definition: MultiBlockGriddingAlgorithm2.hpp:112
CounterOutput(std::chrono::steady_clock::time_point reference, std::vector< std::ptrdiff_t > frequencies, std::vector< Duration > intervals)
Definition: MultiBlockGriddingAlgorithm2.hpp:116
void operator()(const amrex::MultiBlockGriddingAlgorithm2 &grid) override
Definition: MultiBlockGriddingAlgorithm2.hpp:123
CounterOutput(const ProgramOptions &po, std::chrono::steady_clock::time_point ref)
Definition: MultiBlockGriddingAlgorithm2.hpp:107
std::chrono::steady_clock::time_point reference_
Definition: MultiBlockGriddingAlgorithm2.hpp:138
Definition: CounterOutput.hpp:34
std::chrono::steady_clock::time_point reference_
Definition: CounterOutput.hpp:64
Definition: OutputAtFrequencyOrInterval.hpp:32
Definition: MultiBlockBoundary2.hpp:77
This class modifies and initializes a PatchLevel in a PatchHierarchy.
Definition: AMReX/GriddingAlgorithm.hpp:60
Definition: MultiBlockGriddingAlgorithm2.hpp:37
MultiBlockGriddingAlgorithm2 & operator=(const MultiBlockGriddingAlgorithm2 &other)
span< const std::shared_ptr< cutcell::GriddingAlgorithm > > GetPlena() const noexcept
void RegridAllFinerLevels(int which_level)
span< const BlockConnection > GetConnectivity() const noexcept
Duration GetTimePoint() const noexcept
Definition: MultiBlockGriddingAlgorithm2.hpp:58
std::vector< std::vector< AnyMultiBlockBoundary > > boundaries_
Definition: MultiBlockGriddingAlgorithm2.hpp:77
span< AnyMultiBlockBoundary > GetBoundaries(int level=0) noexcept
Definition: MultiBlockGriddingAlgorithm2.hpp:67
span< const std::shared_ptr< GriddingAlgorithm > > GetTubes() const noexcept
MultiBlockGriddingAlgorithm2(MultiBlockGriddingAlgorithm2 &&other) noexcept=default
std::vector< std::shared_ptr< GriddingAlgorithm > > tubes_
Definition: MultiBlockGriddingAlgorithm2.hpp:74
std::vector< BlockConnection > connectivity_
Definition: MultiBlockGriddingAlgorithm2.hpp:76
MultiBlockGriddingAlgorithm2(const TubeEquation &tube_equation, const PlenumEquation &plenum_equation, std::vector< std::shared_ptr< GriddingAlgorithm >> tubes, std::vector< std::shared_ptr< cutcell::GriddingAlgorithm >> plena, std::vector< BlockConnection > connectivity)
Definition: MultiBlockGriddingAlgorithm2.hpp:81
std::vector< std::shared_ptr< cutcell::GriddingAlgorithm > > plena_
Definition: MultiBlockGriddingAlgorithm2.hpp:75
std::ptrdiff_t GetCycles() const noexcept
Definition: MultiBlockGriddingAlgorithm2.hpp:56
MultiBlockGriddingAlgorithm2(const MultiBlockGriddingAlgorithm2 &other)
MultiBlockGriddingAlgorithm2 & operator=(MultiBlockGriddingAlgorithm2 &&other) noexcept=default
A span is a view over a contiguous sequence of objects, the storage of which is owned by some other o...
Definition: span.hpp:81
The fub namespace.
Definition: AnyBoundaryCondition.hpp:31
std::chrono::duration< double > Duration
Definition: Duration.hpp:31
std::map< std::string, pybind11::object > ProgramOptions
Definition: ProgramOptions.hpp:40
Definition: MultiBlockBoundary.hpp:54
Definition: MultiBlockBoundary2.hpp:186