Finite Volume Solver  prototype
A framework to build finite volume solvers for the AG Klein at the Freie Universität Berlin.
AsOutput.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_INVOKE_FUNCTIONS_HPP
22 #define FUB_OUTPUT_INVOKE_FUNCTIONS_HPP
23 
27 
28 namespace fub {
29 
30 template <typename Grid, typename Fn>
31 class AsOutput : public OutputAtFrequencyOrInterval<Grid> {
32 public:
33  AsOutput(std::vector<std::ptrdiff_t> frequencies,
34  std::vector<Duration> intervals, Fn fn)
35  : OutputAtFrequencyOrInterval<Grid>(std::move(frequencies),
36  std::move(intervals)),
37  fn_(std::move(fn)) {}
38 
39  AsOutput(const std::map<std::string, pybind11::object>& vm, Fn fn)
40  : OutputAtFrequencyOrInterval<Grid>(vm), fn_(std::move(fn)) {}
41 
42  void operator()(const Grid& grid) override { std::invoke(fn_, grid); }
43 
44 private:
45  Fn fn_;
46 };
47 
48 template <typename Grid, typename Fn>
49 std::unique_ptr<AsOutput<Grid, Fn>>
50 MakeOutput(std::vector<std::ptrdiff_t> frequencies,
51  std::vector<Duration> intervals, Fn fn) {
52  return std::make_unique<AsOutput<Grid, Fn>>(
53  std::move(frequencies), std::move(intervals), std::move(fn));
54 }
55 
56 template <typename Grid>
57 class AnyOutput : public OutputAtFrequencyOrInterval<Grid> {
58 public:
59  AnyOutput(std::vector<std::ptrdiff_t> frequencies,
60  std::vector<Duration> intervals,
61  std::function<void(const Grid&)> fn)
62  : OutputAtFrequencyOrInterval<Grid>(std::move(frequencies),
63  std::move(intervals)),
64  fn_(std::move(fn)) {}
65 
66  AnyOutput(const std::map<std::string, pybind11::object>& vm,
67  std::function<void(const Grid&)> fn)
68  : OutputAtFrequencyOrInterval<Grid>(vm), fn_(std::move(fn)) {}
69 
70  void operator()(const Grid& grid) override { fn_(grid); }
71 
72 private:
73  std::function<void(const Grid&)> fn_;
74 };
75 } // namespace fub
76 
77 #endif
Definition: AsOutput.hpp:57
void operator()(const Grid &grid) override
Invoke the actual output logic.
Definition: AsOutput.hpp:70
std::function< void(const Grid &)> fn_
Definition: AsOutput.hpp:73
AnyOutput(const std::map< std::string, pybind11::object > &vm, std::function< void(const Grid &)> fn)
Definition: AsOutput.hpp:66
AnyOutput(std::vector< std::ptrdiff_t > frequencies, std::vector< Duration > intervals, std::function< void(const Grid &)> fn)
Definition: AsOutput.hpp:59
Definition: AsOutput.hpp:31
void operator()(const Grid &grid) override
Invoke the actual output logic.
Definition: AsOutput.hpp:42
Fn fn_
Definition: AsOutput.hpp:45
AsOutput(std::vector< std::ptrdiff_t > frequencies, std::vector< Duration > intervals, Fn fn)
Definition: AsOutput.hpp:33
AsOutput(const std::map< std::string, pybind11::object > &vm, Fn fn)
Definition: AsOutput.hpp:39
Definition: OutputAtFrequencyOrInterval.hpp:32
The fub namespace.
Definition: AnyBoundaryCondition.hpp:31
std::unique_ptr< AsOutput< Grid, Fn > > MakeOutput(std::vector< std::ptrdiff_t > frequencies, std::vector< Duration > intervals, Fn fn)
Definition: AsOutput.hpp:50