Finite Volume Solver  prototype
A framework to build finite volume solvers for the AG Klein at the Freie Universität Berlin.
MultiBlockGriddingAlgorithm.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_ALGORITHM_HPP
22 #define FUB_AMREX_COUPLED_GRIDDING_ALGORITHM_HPP
23 
25 
28 
30 
31 #include "fub/core/span.hpp"
32 
34 
35 namespace fub {
36 namespace amrex {
37 
38 /// \ingroup GriddingAlgorithm
40 public:
42  FlameMasterReactor reactor,
43  std::vector<std::shared_ptr<GriddingAlgorithm>> tubes,
44  std::vector<std::shared_ptr<cutcell::GriddingAlgorithm>> plena,
45  std::vector<BlockConnection> connectivity);
46 
48  FlameMasterReactor reactor,
49  std::vector<std::shared_ptr<GriddingAlgorithm>> tubes,
50  std::vector<std::shared_ptr<cutcell::GriddingAlgorithm>> plena,
51  std::vector<BlockConnection> connectivity,
52  std::vector<std::shared_ptr<PressureValve>> valves);
53 
57 
59  default;
60 
62  operator=(MultiBlockGriddingAlgorithm&& other) noexcept = default;
63 
64  std::ptrdiff_t GetCycles() const noexcept { return plena_[0]->GetCycles(); }
65 
66  Duration GetTimePoint() const noexcept { return plena_[0]->GetTimePoint(); }
67 
69  noexcept;
70  [[nodiscard]] span<const std::shared_ptr<cutcell::GriddingAlgorithm>>
71  GetPlena() const noexcept;
72 
73  [[nodiscard]] span<const BlockConnection> GetConnectivity() const noexcept;
74  [[nodiscard]] span<MultiBlockBoundary> GetBoundaries(int level = 0) noexcept {
75  return boundaries_[static_cast<std::size_t>(level)];
76  }
77 
78  void RegridAllFinerLevels(int which_level);
79 
80 private:
82  std::vector<std::shared_ptr<GriddingAlgorithm>> tubes_;
83  std::vector<std::shared_ptr<cutcell::GriddingAlgorithm>> plena_;
84  std::vector<BlockConnection> connectivity_;
85  std::vector<std::vector<MultiBlockBoundary>> boundaries_;
86 };
87 
88 } // namespace amrex
89 
90 template <typename PrintDuration>
91 class CounterOutput<amrex::MultiBlockGriddingAlgorithm, PrintDuration>
92  : public OutputAtFrequencyOrInterval<amrex::MultiBlockGriddingAlgorithm> {
93 public:
95  std::chrono::steady_clock::time_point ref)
96  : OutputAtFrequencyOrInterval<amrex::MultiBlockGriddingAlgorithm>(po),
97  reference_{ref} {}
98 
100  : OutputAtFrequencyOrInterval<amrex::MultiBlockGriddingAlgorithm>(po),
101  reference_{std::chrono::steady_clock::now()} {}
102 
103  CounterOutput(std::chrono::steady_clock::time_point reference,
104  std::vector<std::ptrdiff_t> frequencies,
105  std::vector<Duration> intervals)
106  : OutputAtFrequencyOrInterval<amrex::MultiBlockGriddingAlgorithm>(
107  std::move(frequencies), std::move(intervals)),
108  reference_(reference) {}
109 
110  void operator()(const amrex::MultiBlockGriddingAlgorithm& grid) override {
111  std::chrono::steady_clock::time_point now =
112  std::chrono::steady_clock::now();
113  auto diff =
114  std::chrono::duration_cast<std::chrono::nanoseconds>(now - reference_);
115  std::vector<CounterResult> statistics = grid.GetPlena()[0]
116  ->GetPatchHierarchy()
117  .GetCounterRegistry()
118  ->gather_statistics();
119  if (statistics.size()) {
120  print_statistics<PrintDuration>(statistics, diff.count());
121  }
122  }
123 
124 private:
125  std::chrono::steady_clock::time_point reference_;
126 };
127 
128 } // namespace fub
129 
130 #endif // FUB_AMREX_COUPLED_GRIDDING_ALGORITHM_HPP
CounterOutput(const ProgramOptions &po, std::chrono::steady_clock::time_point ref)
Definition: MultiBlockGriddingAlgorithm.hpp:94
std::chrono::steady_clock::time_point reference_
Definition: MultiBlockGriddingAlgorithm.hpp:125
CounterOutput(const ProgramOptions &po)
Definition: MultiBlockGriddingAlgorithm.hpp:99
void operator()(const amrex::MultiBlockGriddingAlgorithm &grid) override
Definition: MultiBlockGriddingAlgorithm.hpp:110
CounterOutput(std::chrono::steady_clock::time_point reference, std::vector< std::ptrdiff_t > frequencies, std::vector< Duration > intervals)
Definition: MultiBlockGriddingAlgorithm.hpp:103
Definition: CounterOutput.hpp:34
std::chrono::steady_clock::time_point reference_
Definition: CounterOutput.hpp:64
A class mimicking the IdealGasMix / Reactor / ReactorNet interface of Cantera, but with FlameMaster c...
Definition: FlameMasterReactor.hpp:159
Definition: OutputAtFrequencyOrInterval.hpp:32
This class modifies and initializes a PatchLevel in a PatchHierarchy.
Definition: AMReX/GriddingAlgorithm.hpp:60
Definition: MultiBlockBoundary.hpp:64
Definition: MultiBlockGriddingAlgorithm.hpp:39
span< const std::shared_ptr< GriddingAlgorithm > > GetTubes() const noexcept
std::ptrdiff_t GetCycles() const noexcept
Definition: MultiBlockGriddingAlgorithm.hpp:64
std::vector< std::vector< MultiBlockBoundary > > boundaries_
Definition: MultiBlockGriddingAlgorithm.hpp:85
std::vector< std::shared_ptr< cutcell::GriddingAlgorithm > > plena_
Definition: MultiBlockGriddingAlgorithm.hpp:83
MultiBlockGriddingAlgorithm & operator=(const MultiBlockGriddingAlgorithm &other)
span< const std::shared_ptr< cutcell::GriddingAlgorithm > > GetPlena() const noexcept
FlameMasterReactor reactor_
Definition: MultiBlockGriddingAlgorithm.hpp:81
span< const BlockConnection > GetConnectivity() const noexcept
void RegridAllFinerLevels(int which_level)
MultiBlockGriddingAlgorithm(FlameMasterReactor reactor, std::vector< std::shared_ptr< GriddingAlgorithm >> tubes, std::vector< std::shared_ptr< cutcell::GriddingAlgorithm >> plena, std::vector< BlockConnection > connectivity, std::vector< std::shared_ptr< PressureValve >> valves)
MultiBlockGriddingAlgorithm(MultiBlockGriddingAlgorithm &&other) noexcept=default
MultiBlockGriddingAlgorithm(FlameMasterReactor reactor, std::vector< std::shared_ptr< GriddingAlgorithm >> tubes, std::vector< std::shared_ptr< cutcell::GriddingAlgorithm >> plena, std::vector< BlockConnection > connectivity)
std::vector< BlockConnection > connectivity_
Definition: MultiBlockGriddingAlgorithm.hpp:84
std::vector< std::shared_ptr< GriddingAlgorithm > > tubes_
Definition: MultiBlockGriddingAlgorithm.hpp:82
MultiBlockGriddingAlgorithm(const MultiBlockGriddingAlgorithm &other)
Duration GetTimePoint() const noexcept
Definition: MultiBlockGriddingAlgorithm.hpp:66
span< MultiBlockBoundary > GetBoundaries(int level=0) noexcept
Definition: MultiBlockGriddingAlgorithm.hpp:74
MultiBlockGriddingAlgorithm & operator=(MultiBlockGriddingAlgorithm &&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