Finite Volume Solver  prototype
A framework to build finite volume solvers for the AG Klein at the Freie Universität Berlin.
ProgramOptions.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 /// \file This file declares a function to parse program options from a python
22 /// script file.
23 
24 #ifndef FUB_EXT_PROGRAM_OPTIONS_HPP
25 #define FUB_EXT_PROGRAM_OPTIONS_HPP
26 
27 #include "fub/Direction.hpp"
28 
29 #include <map>
30 #include <optional>
31 #include <string>
32 
33 #include <boost/filesystem.hpp>
34 #include <mpi.h>
35 #include <pybind11/embed.h>
36 #include <pybind11/stl.h>
37 
38 namespace fub {
39 
40 using ProgramOptions = std::map<std::string, pybind11::object>;
41 
42 ProgramOptions ParsePythonScript(const boost::filesystem::path& path,
43  MPI_Comm comm);
44 
45 ProgramOptions ToMap(const pybind11::dict& dict);
46 
47 template <typename T>
48 T GetOptionOr(const ProgramOptions& map, const std::string& name,
49  const T& value) {
50  auto iter = map.find(name);
51  if (iter != map.end()) {
52  return iter->second.cast<T>();
53  }
54  return value;
55 }
56 
57 template <>
58 Direction GetOptionOr(const ProgramOptions& map, const std::string& name,
59  const Direction& value);
60 
62  const std::string& name);
63 
64 std::optional<ProgramOptions> ParseCommandLine(int argc, char** argv);
65 
66 } // namespace fub
67 
68 #endif
The fub namespace.
Definition: AnyBoundaryCondition.hpp:31
std::optional< ProgramOptions > ParseCommandLine(int argc, char **argv)
Direction
This is a type safe type to denote a dimensional split direction.
Definition: Direction.hpp:30
ProgramOptions GetOptions(const ProgramOptions &options, const std::string &name)
T GetOptionOr(const ProgramOptions &map, const std::string &name, const T &value)
Definition: ProgramOptions.hpp:48
ProgramOptions ToMap(const pybind11::dict &dict)
ProgramOptions ParsePythonScript(const boost::filesystem::path &path, MPI_Comm comm)
std::map< std::string, pybind11::object > ProgramOptions
Definition: ProgramOptions.hpp:40