Finite Volume Solver  prototype
A framework to build finite volume solvers for the AG Klein at the Freie Universität Berlin.
MultiBlockPlotfileOutput.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_MULTI_BLOCK_PLOT_FILE_OUTPUT_HPP
22 #define FUB_AMREX_MULTI_BLOCK_PLOT_FILE_OUTPUT_HPP
23 
28 
29 #include <string>
30 
31 namespace fub::amrex {
32 
34  : public OutputAtFrequencyOrInterval<MultiBlockGriddingAlgorithm> {
35 public:
36  MultiBlockPlotfileOutput(const std::map<std::string, pybind11::object>& vm);
37 
38  void operator()(const MultiBlockGriddingAlgorithm& grid) override;
39 
40 private:
41  std::string parent_path_;
42 };
43 
44 template <typename TubeEquation, typename PlenumEquation>
46  : public OutputAtFrequencyOrInterval<MultiBlockGriddingAlgorithm2> {
47 public:
48  MultiBlockPlotfileOutput2(const std::map<std::string, pybind11::object>& vm, const TubeEquation& tube_equation, const PlenumEquation& plenum_equation);
49 
50  void operator()(const MultiBlockGriddingAlgorithm2& grid) override;
51 
52 private:
53  TubeEquation tube_equation_;
54  PlenumEquation plenum_equation_;
55  std::string parent_path_;
56 };
57 
58 template <typename TubeEquation, typename PlenumEquation>
60  const std::map<std::string, pybind11::object>& vm, const TubeEquation& tube_equation, const PlenumEquation& plenum_equation)
61  : OutputAtFrequencyOrInterval<MultiBlockGriddingAlgorithm2>(vm), tube_equation_(tube_equation), plenum_equation_(plenum_equation) {
62  parent_path_ = GetOptionOr(vm, "directory", std::string("."));
63 }
64 
65 template <typename TubeEquation, typename PlenumEquation>
68  boost::log::sources::severity_logger<boost::log::trivial::severity_level> log(
69  boost::log::keywords::severity = boost::log::trivial::info);
70  BOOST_LOG_SCOPED_LOGGER_TAG(log, "Channel", "Plotfile");
71  BOOST_LOG_SCOPED_LOGGER_TAG(log, "Time", grid.GetTimePoint().count());
72  for (int i = 0; i < grid.GetPlena().size(); ++i) {
73  std::string name =
74  fmt::format("{}/Plenum{}/plt{:09}", parent_path_, i, grid.GetCycles());
75  BOOST_LOG(log) << fmt::format("Write Plotfile output to '{}'.", name);
76  cutcell::WritePlotFile(name, grid.GetPlena()[i]->GetPatchHierarchy(),
77  plenum_equation_);
78  }
79  for (int i = 0; i < grid.GetTubes().size(); ++i) {
80  std::string name =
81  fmt::format("{}/Tube{}/plt{:09}", parent_path_, i, grid.GetCycles());
82  BOOST_LOG(log) << fmt::format("Write Plotfile output to '{}'.", name);
83  WritePlotFile(name, grid.GetTubes()[i]->GetPatchHierarchy(), tube_equation_);
84  }
85 }
86 
87 
88 } // namespace fub::amrex
89 
90 #endif
Definition: OutputAtFrequencyOrInterval.hpp:32
Definition: MultiBlockGriddingAlgorithm2.hpp:37
span< const std::shared_ptr< cutcell::GriddingAlgorithm > > GetPlena() const noexcept
Duration GetTimePoint() const noexcept
Definition: MultiBlockGriddingAlgorithm2.hpp:58
span< const std::shared_ptr< GriddingAlgorithm > > GetTubes() const noexcept
std::ptrdiff_t GetCycles() const noexcept
Definition: MultiBlockGriddingAlgorithm2.hpp:56
Definition: MultiBlockGriddingAlgorithm.hpp:39
Definition: MultiBlockPlotfileOutput.hpp:46
TubeEquation tube_equation_
Definition: MultiBlockPlotfileOutput.hpp:53
MultiBlockPlotfileOutput2(const std::map< std::string, pybind11::object > &vm, const TubeEquation &tube_equation, const PlenumEquation &plenum_equation)
Definition: MultiBlockPlotfileOutput.hpp:59
void operator()(const MultiBlockGriddingAlgorithm2 &grid) override
Definition: MultiBlockPlotfileOutput.hpp:67
PlenumEquation plenum_equation_
Definition: MultiBlockPlotfileOutput.hpp:54
std::string parent_path_
Definition: MultiBlockPlotfileOutput.hpp:55
Definition: MultiBlockPlotfileOutput.hpp:34
MultiBlockPlotfileOutput(const std::map< std::string, pybind11::object > &vm)
void operator()(const MultiBlockGriddingAlgorithm &grid) override
std::string parent_path_
Definition: MultiBlockPlotfileOutput.hpp:41
void WritePlotFile(const std::string &plotfilename, const PatchHierarchy &hier, const Equation &equation)
Definition: AMReX/cutcell/PatchHierarchy.hpp:237
The amrex namespace.
Definition: AverageState.hpp:33
void WritePlotFile(const std::string plotfilename, const fub::amrex::PatchHierarchy &hier, const Equation &equation)
Definition: AMReX/PatchHierarchy.hpp:267
T GetOptionOr(const ProgramOptions &map, const std::string &name, const T &value)
Definition: ProgramOptions.hpp:48