Finite Volume Solver  prototype
A framework to build finite volume solvers for the AG Klein at the Freie Universität Berlin.
cutcell/output/WritePlotfiles.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_CUTCELL_PLOT_FILES_HPP
22 #define FUB_AMREX_CUTCELL_PLOT_FILES_HPP
23 
27 
28 #include <boost/log/common.hpp>
29 #include <boost/log/sources/severity_logger.hpp>
30 #include <boost/log/trivial.hpp>
31 
32 namespace fub::amrex::cutcell {
33 
34 template <typename Equation>
35 class PlotfileOutput : public OutputAtFrequencyOrInterval<GriddingAlgorithm> {
36 public:
37  PlotfileOutput(const ProgramOptions& options, const Equation& equation)
38  : OutputAtFrequencyOrInterval(options), equation_(equation) {
39  parent_path_ = fub::GetOptionOr(options, "directory", parent_path_);
40  }
41 
42  PlotfileOutput(const Equation& equation, const std::string& path)
43  : OutputAtFrequencyOrInterval(), equation_(equation), parent_path_(path) {
44  }
45 
46  PlotfileOutput(std::vector<std::ptrdiff_t> freqs,
47  std::vector<Duration> intervals, const Equation& equation,
48  const std::string& path)
49  : OutputAtFrequencyOrInterval(std::move(freqs), std::move(intervals)),
50  equation_(equation), parent_path_(path) {}
51 
52  void operator()(const GriddingAlgorithm& grid) override {
53  boost::log::sources::severity_logger<boost::log::trivial::severity_level>
54  log(boost::log::keywords::severity = boost::log::trivial::info);
55  BOOST_LOG_SCOPED_LOGGER_TAG(log, "Channel", "Plotfile");
56  BOOST_LOG_SCOPED_LOGGER_TAG(log, "Time", grid.GetTimePoint().count());
57  std::string name =
58  fmt::format("{}/plt{:09}", parent_path_, grid.GetCycles());
59  BOOST_LOG(log) << fmt::format("Write Plotfile output to '{}'.", name);
61  }
62 
63 private:
65  std::string parent_path_;
66 };
67 
68 } // namespace fub::amrex::cutcell
69 
70 #endif
Definition: OutputAtFrequencyOrInterval.hpp:32
This class modifies and initializes a cutcell::PatchLevel in a cutcell::PatchHierarchy.
Definition: AMReX/cutcell/GriddingAlgorithm.hpp:56
Duration GetTimePoint() const noexcept
Returns the current time point on the coarsest refinement level.
Definition: AMReX/cutcell/GriddingAlgorithm.hpp:126
const PatchHierarchy & GetPatchHierarchy() const noexcept
std::ptrdiff_t GetCycles() const noexcept
Returns the number of time steps taken on the coarsest refinement level.
Definition: AMReX/cutcell/GriddingAlgorithm.hpp:121
Definition: cutcell/output/WritePlotfiles.hpp:35
PlotfileOutput(const ProgramOptions &options, const Equation &equation)
Definition: cutcell/output/WritePlotfiles.hpp:37
PlotfileOutput(std::vector< std::ptrdiff_t > freqs, std::vector< Duration > intervals, const Equation &equation, const std::string &path)
Definition: cutcell/output/WritePlotfiles.hpp:46
PlotfileOutput(const Equation &equation, const std::string &path)
Definition: cutcell/output/WritePlotfiles.hpp:42
void operator()(const GriddingAlgorithm &grid) override
Definition: cutcell/output/WritePlotfiles.hpp:52
std::string parent_path_
Definition: cutcell/output/WritePlotfiles.hpp:65
Equation equation_
Definition: cutcell/output/WritePlotfiles.hpp:64
Definition: FillCutCellData.hpp:30
void WritePlotFile(const std::string &plotfilename, const PatchHierarchy &hier, const Equation &equation)
Definition: AMReX/cutcell/PatchHierarchy.hpp:237
std::decay_t< decltype(std::declval< T >().GetEquation())> Equation
A template typedef to detect the member function.
Definition: Meta.hpp:59
T GetOptionOr(const ProgramOptions &map, const std::string &name, const T &value)
Definition: ProgramOptions.hpp:48
std::map< std::string, pybind11::object > ProgramOptions
Definition: ProgramOptions.hpp:40