Finite Volume Solver  prototype
A framework to build finite volume solvers for the AG Klein at the Freie Universität Berlin.
CounterOutput.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_OUTPUT_COUNTER_OUTPUT_HPP
22 #define FUB_OUTPUT_COUNTER_OUTPUT_HPP
23 
24 #include "fub/counter/CounterRegistry.hpp"
27 
28 #include <chrono>
29 #include <memory>
30 
31 namespace fub {
32 
33 template <typename Grid, typename PrintDuration = std::chrono::nanoseconds>
35 public:
37  std::chrono::steady_clock::time_point ref)
38  : OutputAtFrequencyOrInterval<Grid>(po), reference_{ref} {}
39 
41  : OutputAtFrequencyOrInterval<Grid>(po),
42  reference_{std::chrono::steady_clock::now()} {}
43 
44  CounterOutput(std::chrono::steady_clock::time_point reference,
45  std::vector<std::ptrdiff_t> frequencies,
46  std::vector<Duration> intervals)
47  : OutputAtFrequencyOrInterval<Grid>(std::move(frequencies),
48  std::move(intervals)),
49  reference_(reference) {}
50 
51  void operator()(const Grid& grid) override {
52  std::chrono::steady_clock::time_point now =
53  std::chrono::steady_clock::now();
54  auto diff =
55  std::chrono::duration_cast<std::chrono::nanoseconds>(now - reference_);
56  std::vector<CounterResult> statistics =
57  grid.GetPatchHierarchy().GetCounterRegistry()->gather_statistics();
58  if (statistics.size()) {
59  print_statistics<PrintDuration>(statistics, diff.count());
60  }
61  }
62 
63 private:
64  std::chrono::steady_clock::time_point reference_;
65 };
66 
67 } // namespace fub
68 
69 #endif
Definition: CounterOutput.hpp:34
CounterOutput(const ProgramOptions &po, std::chrono::steady_clock::time_point ref)
Definition: CounterOutput.hpp:36
void operator()(const Grid &grid) override
Invoke the actual output logic.
Definition: CounterOutput.hpp:51
CounterOutput(const ProgramOptions &po)
Definition: CounterOutput.hpp:40
CounterOutput(std::chrono::steady_clock::time_point reference, std::vector< std::ptrdiff_t > frequencies, std::vector< Duration > intervals)
Definition: CounterOutput.hpp:44
std::chrono::steady_clock::time_point reference_
Definition: CounterOutput.hpp:64
Definition: OutputAtFrequencyOrInterval.hpp:32
The fub namespace.
Definition: AnyBoundaryCondition.hpp:31
std::map< std::string, pybind11::object > ProgramOptions
Definition: ProgramOptions.hpp:40