Skip to content

Commit

Permalink
Parm parse getter query for selected types (int, bool, Real) (#158)
Browse files Browse the repository at this point in the history
* adding wrappers for parmparse get and query for selected types with tests

Co-authored-by: Edoardo Zoni <ezoni@lbl.gov>
Co-authored-by: Axel Huebl <axelhuebl@lbl.gov>

* initialize-finalize called once for all tests

Co-authored-by: Axel Huebl <axel.huebl@plasma.ninja>

* add dir for input file

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Cleaning

* Cleaning

* Fix typo

---------

Co-authored-by: Edoardo Zoni <ezoni@lbl.gov>
Co-authored-by: Axel Huebl <axelhuebl@lbl.gov>
Co-authored-by: Axel Huebl <axel.huebl@plasma.ninja>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
  • Loading branch information
5 people authored Jul 22, 2023
1 parent b63a9e6 commit 494ad40
Show file tree
Hide file tree
Showing 3 changed files with 57 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
18 changes: 18 additions & 0 deletions tests/test_parmparse.py
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 494ad40

Please sign in to comment.