Debian Codegraph @

python/src/log.cpp

raw
1 // Copyright (C) 2017 Chris Richardson and Garth N. Wells
2 //
3 // This file is part of DOLFIN.
4 //
5 // DOLFIN is free software: you can redistribute it and/or modify
6 // it under the terms of the GNU Lesser General Public License as published by
7 // the Free Software Foundation, either version 3 of the License, or
8 // (at your option) any later version.
9 //
10 // DOLFIN is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU Lesser General Public License for more details.
14 //
15 // You should have received a copy of the GNU Lesser General Public License
16 // along with DOLFIN. If not, see <http://www.gnu.org/licenses/>.
17
18 #include <memory>
19 #include <string>
20 #include <pybind11/pybind11.h>
21 #include <pybind11/stl.h>
22
23 #include <dolfin/common/Variable.h>
24 #include <dolfin/log/log.h>
25 #include <dolfin/log/Table.h>
26 #include <dolfin/log/Progress.h>
27 #include <dolfin/mesh/Mesh.h>
28 #include <dolfin/multistage/MultiStageScheme.h>
29 #include "casters.h"
30
31 namespace py = pybind11;
32
33 namespace dolfin_wrappers
34 {
35 void log(py::module& m)
36 {
37
38 // dolfin::LogLevel enums
39 py::enum_<dolfin::LogLevel>(m, "LogLevel", py::arithmetic())
40 .value("DEBUG", dolfin::LogLevel::DBG)
41 .value("TRACE", dolfin::LogLevel::TRACE)
42 .value("PROGRESS", dolfin::LogLevel::PROGRESS)
43 .value("INFO", dolfin::LogLevel::INFO)
44 .value("WARNING", dolfin::LogLevel::WARNING)
45 .value("ERROR", dolfin::LogLevel::ERROR)
46 .value("CRITICAL", dolfin::LogLevel::CRITICAL);
47
48 // dolfin::Table
49 py::class_<dolfin::Table, std::shared_ptr<dolfin::Table>, dolfin::Variable>(m, "Table")
50 .def(py::init<std::string>())
51 .def("str", &dolfin::Table::str);
52
53 // dolfin/log free functions
54 m.def("info", [](const dolfin::Variable& v){ dolfin::info(v); });
55 m.def("info", [](const dolfin::Variable& v, bool verbose){ dolfin::info(v, verbose); });
56 m.def("info", [](std::string s){ dolfin::info(s); });
57 m.def("info", [](const dolfin::Parameters& p, bool verbose){ dolfin::info(p, verbose); });
58 m.def("info", [](const dolfin::Mesh& mesh, bool verbose){ dolfin::info(mesh, verbose); },
59 py::arg("mesh"), py::arg("verbose")=false);
60 m.def("info", [](const dolfin::MultiStageScheme& mms, bool verbose){ dolfin::info(mms, verbose); },
61 py::arg("scheme"), py::arg("verbose")=false);
62 m.def("set_log_level", &dolfin::set_log_level);
63 m.def("set_log_active", &dolfin::set_log_active);
64 m.def("get_log_level", &dolfin::get_log_level);
65 m.def("log", [](dolfin::LogLevel level, std::string s){ dolfin::log(level, s); });
66 m.def("begin", [](unsigned int debug_level, std::string msg){ dolfin::begin(debug_level, msg);});
67 m.def("begin", [](std::string msg){ dolfin::begin(msg);});
68 m.def("error", [](std::string msg){ dolfin::error(msg);});
69 m.def("warning", [](std::string msg){ dolfin::warning(msg);});
70 m.def("end", &dolfin::end);
71
72 // dolfin::Progress
73 py::class_<dolfin::Progress, std::shared_ptr<dolfin::Progress>>
74 (m, "Progress", py::dynamic_attr(), "DOLFIN Progress object")
75 .def(py::init<std::string>())
76 .def(py::init<std::string, unsigned int>())
77 .def("_assign", (void (dolfin::Progress::*)(double))
78 &dolfin::Progress::operator=)
79 .def("_increment", &dolfin::Progress::operator++);
80 }
81 }