Skip to content

Commit

Permalink
adding wrappers for parmparse get and query for selected types with t…
Browse files Browse the repository at this point in the history
…ests

Co-authored-by: Edoardo Zoni <ezoni@lbl.gov>
Co-authored-by: Axel Huebl <axelhuebl@lbl.gov>
  • Loading branch information
3 people committed Jul 21, 2023
1 parent 1992c18 commit 39f7f33
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 1 deletion.
37 changes: 36 additions & 1 deletion src/Base/ParmParse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<char const*, bool const>(&ParmParse::add))
.def("add", py::overload_cast<char const*, int const>(&ParmParse::add))
Expand All @@ -52,6 +52,41 @@ void init_ParmParse(py::module &m)
.def("addarr", py::overload_cast<char const*, std::vector<amrex::Box> 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
;
Expand Down
3 changes: 3 additions & 0 deletions tests/parmparse_inputs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
param.dt = 1.e-5
param.ncell = 100
param.do_pml = 1
21 changes: 21 additions & 0 deletions tests/test_parmparse.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# -*- coding: utf-8 -*-

import amrex.space3d as amr


def test_parmparse():
dopml = False
ncell = 10
dt = 0.0
# Since ParmParse is done in IO Processors, we need amr.initialize first
amr.initialize([])
pp = amr.ParmParse("")
pp.addfile("./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
amr.finalize()

0 comments on commit 39f7f33

Please sign in to comment.