diff --git a/src/Base/ParmParse.cpp b/src/Base/ParmParse.cpp index c906d83e..3ca9f9f5 100644 --- a/src/Base/ParmParse.cpp +++ b/src/Base/ParmParse.cpp @@ -30,7 +30,7 @@ void init_ParmParse(py::module &m) .def("remove", &ParmParse::remove) - .def("addfile", &ParmParse::addfile) + .def_static("addfile", &ParmParse::addfile) .def("add", py::overload_cast(&ParmParse::add)) .def("add", py::overload_cast(&ParmParse::add)) @@ -52,6 +52,41 @@ void init_ParmParse(py::module &m) .def("addarr", py::overload_cast const &>(&ParmParse::addarr)) // TODO: getters and queries + .def("get_bool", + [](ParmParse &pp, std::string name, int ival) { + bool ref; + pp.get(name.c_str(), ref, ival); + return ref; + }, + "parses input values", py::arg("name"), py::arg("ival")=0 + ) + + .def("get_int", + [](ParmParse &pp, std::string name, int ival) { + int ref; + pp.get(name.c_str(), ref, ival); + return ref; + }, + "parses input values", py::arg("name"), py::arg("ival")=0 + ) + + .def("get_real", + [](ParmParse &pp, std::string name, int ival) { + amrex::Real ref; + pp.get(name.c_str(), ref, ival); + return ref; + }, + "parses input values", py::arg("name"), py::arg("ival")=0 + ) + + .def("query_int", + [](ParmParse &pp, std::string name, int ival) { + int ref; + bool exist = pp.query(name.c_str(), ref, ival); + return std::make_tuple(exist,ref); + }, + "queries input values", py::arg("name"), py::arg("ival")=0 + ) // TODO: dumpTable, hasUnusedInputs, getUnusedInputs, getEntries ; diff --git a/tests/parmparse_inputs b/tests/parmparse_inputs new file mode 100644 index 00000000..b6a22a87 --- /dev/null +++ b/tests/parmparse_inputs @@ -0,0 +1,3 @@ +param.dt = 1.e-5 +param.ncell = 100 +param.do_pml = 1 diff --git a/tests/test_parmparse.py b/tests/test_parmparse.py new file mode 100644 index 00000000..2871d2fd --- /dev/null +++ b/tests/test_parmparse.py @@ -0,0 +1,18 @@ +# -*- coding: utf-8 -*- +import os + +import amrex.space3d as amr + + +def test_parmparse(): + pp = amr.ParmParse("") + dir_name = os.path.dirname(__file__) + pp.addfile(os.path.join(dir_name, "parmparse_inputs")) + pp_param = amr.ParmParse("param") + _, ncell = pp_param.query_int("ncell") + dt = pp_param.get_real("dt") + dopml = pp_param.get_bool("do_pml") + + assert dopml == True + assert dt == 1.0e-5 + assert ncell == 100