Skip to content

Commit 557eb5c

Browse files
authored
Start: ParmParse (#72)
Start implementing `amrex::ParmParse`. Begins with param adder functionality.
1 parent e66ebde commit 557eb5c

File tree

3 files changed

+67
-2
lines changed

3 files changed

+67
-2
lines changed

src/Base/CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ target_sources(pyAMReX
1313
RealVect.cpp
1414
MultiFab.cpp
1515
ParallelDescriptor.cpp
16+
ParmParse.cpp
1617
Periodicity.cpp
1718
PODVector.cpp
1819
Vector.cpp

src/Base/ParmParse.cpp

+61
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
/* Copyright 2021-2022 The AMReX Community
2+
*
3+
* Authors: Axel Huebl
4+
* License: BSD-3-Clause-LBNL
5+
*/
6+
#include <pybind11/pybind11.h>
7+
#include <pybind11/operators.h>
8+
#include <pybind11/stl.h>
9+
10+
#include <AMReX_Config.H>
11+
#include <AMReX_Box.H>
12+
#include <AMReX_IntVect.H>
13+
#include <AMReX_ParmParse.H>
14+
15+
#include <string>
16+
#include <vector>
17+
18+
namespace py = pybind11;
19+
using namespace amrex;
20+
21+
22+
void init_ParmParse(py::module &m) {
23+
py::class_<ParmParse>(m, "ParmParse")
24+
.def("__repr__",
25+
[](ParmParse const &) {
26+
// todo: make ParmParse::getPrefix() public?
27+
return "<amrex.ParmParse>";
28+
}
29+
)
30+
.def(py::init<std::string const &>(),
31+
py::arg("prefix") = std::string()
32+
)
33+
34+
.def("remove", &ParmParse::remove)
35+
36+
.def("addfile", &ParmParse::addfile)
37+
38+
.def("add", py::overload_cast<char const*, bool const>(&ParmParse::add))
39+
.def("add", py::overload_cast<char const*, int const>(&ParmParse::add))
40+
.def("add", py::overload_cast<char const*, long const>(&ParmParse::add))
41+
.def("add", py::overload_cast<char const*, long long const>(&ParmParse::add))
42+
.def("add", py::overload_cast<char const*, float const>(&ParmParse::add))
43+
.def("add", py::overload_cast<char const*, double const>(&ParmParse::add))
44+
.def("add", py::overload_cast<char const*, std::string const &>(&ParmParse::add))
45+
.def("add", py::overload_cast<char const*, amrex::IntVect const &>(&ParmParse::add))
46+
.def("add", py::overload_cast<char const*, amrex::Box const &>(&ParmParse::add))
47+
48+
.def("addarr", py::overload_cast<char const*, std::vector<int> const &>(&ParmParse::addarr))
49+
.def("addarr", py::overload_cast<char const*, std::vector<long> const &>(&ParmParse::addarr))
50+
.def("addarr", py::overload_cast<char const*, std::vector<long long> const &>(&ParmParse::addarr))
51+
.def("addarr", py::overload_cast<char const*, std::vector<float> const &>(&ParmParse::addarr))
52+
.def("addarr", py::overload_cast<char const*, std::vector<double> const &>(&ParmParse::addarr))
53+
.def("addarr", py::overload_cast<char const*, std::vector<std::string> const &>(&ParmParse::addarr))
54+
.def("addarr", py::overload_cast<char const*, std::vector<amrex::IntVect> const &>(&ParmParse::addarr))
55+
.def("addarr", py::overload_cast<char const*, std::vector<amrex::Box> const &>(&ParmParse::addarr))
56+
57+
// TODO: getters and queries
58+
59+
// TODO: dumpTable, hasUnusedInputs, getUnusedInputs, getEntries
60+
;
61+
}

src/pyAMReX.cpp

+5-2
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ void init_RealVect(py::module &);
3030
void init_AmrMesh(py::module &);
3131
void init_MultiFab(py::module &);
3232
void init_ParallelDescriptor(py::module &);
33+
void init_ParmParse(py::module &);
3334
void init_Particle(py::module &);
3435
void init_StructOfArrays(py::module &);
3536
void init_ArrayOfStructs(py::module &);
@@ -51,6 +52,7 @@ PYBIND11_MODULE(amrex_pybind, m) {
5152
:toctree: _generate
5253
AmrInfo
5354
AmrMesh
55+
ArrayOfStructs
5456
Box
5557
RealBox
5658
BoxArray
@@ -60,12 +62,12 @@ PYBIND11_MODULE(amrex_pybind, m) {
6062
MultiFab
6163
ParallelDescriptor
6264
Particle
63-
StructOfArrays
64-
ArrayOfStructs
65+
ParmParse
6566
ParticleTile
6667
ParticleContainer
6768
Periodicity
6869
PODVector
70+
StructOfArrays
6971
Vector
7072
)pbdoc";
7173

@@ -78,6 +80,7 @@ PYBIND11_MODULE(amrex_pybind, m) {
7880
init_Array4(m);
7981
init_Box(m);
8082
init_BoxArray(m);
83+
init_ParmParse(m);
8184
init_MultiFab(m);
8285
init_DistributionMapping(m);
8386
init_RealBox(m);

0 commit comments

Comments
 (0)