diff --git a/src/Base/CMakeLists.txt b/src/Base/CMakeLists.txt index a44cda81..ada9fb5f 100644 --- a/src/Base/CMakeLists.txt +++ b/src/Base/CMakeLists.txt @@ -20,6 +20,7 @@ foreach(D IN LISTS AMReX_SPACEDIM) ParallelDescriptor.cpp ParmParse.cpp Periodicity.cpp + PlotFileUtil.cpp PODVector.cpp Utility.cpp Vector.cpp diff --git a/src/Base/PlotFileUtil.cpp b/src/Base/PlotFileUtil.cpp new file mode 100644 index 00000000..90c930f8 --- /dev/null +++ b/src/Base/PlotFileUtil.cpp @@ -0,0 +1,33 @@ +/* Copyright 2021-2022 The AMReX Community + * + * License: BSD-3-Clause-LBNL + */ +#include "pyAMReX.H" + +#include +#include +#include + +#include +#include + +namespace py = pybind11; +using namespace amrex; + +void init_PlotFileUtil(py::module& m) +{ + m.def("write_single_level_plotfile", + &amrex::WriteSingleLevelPlotfile, + "Writes single level plotfile", + py::arg("plotfilename"), + py::arg("mf"), + py::arg("varnames"), + py::arg("geom"), + py::arg("time"), + py::arg("level_step"), + py::arg("versionName")="HyperCLaw-V1.1", + py::arg("levelPrefix")="Level_", + py::arg("mfPrefix")="Cell", + py::arg("extra_dirs")=Vector() + ); +} diff --git a/src/Base/Vector.cpp b/src/Base/Vector.cpp index 0ce350a4..9ceeb718 100644 --- a/src/Base/Vector.cpp +++ b/src/Base/Vector.cpp @@ -45,7 +45,8 @@ void make_Vector(py::module &m, std::string typestr) using Vector_type = Vector; auto const v_name = std::string("Vector_").append(typestr); - py::class_(m, v_name.c_str()) + auto py_vect = py::bind_vector(m, v_name.c_str()); + py_vect .def("__repr__", [typestr](Vector_type const & v) { std::stringstream s, rs; @@ -61,9 +62,14 @@ void make_Vector(py::module &m, std::string typestr) } ) .def(py::init<>()) + .def(py::init()) .def("size", &Vector_type::size) + ; + if constexpr(!std::is_same_v) + { + py_vect .def_property_readonly("__array_interface__", [](Vector_type const & vector) { return array_interface(vector); }) @@ -87,8 +93,10 @@ void make_Vector(py::module &m, std::string typestr) d["version"] = 3; return d; - }) + }); + } + py_vect // setter & getter .def("__setitem__", [](Vector_type & vector, int const idx, T const value){ vector[idx] = value; }) .def("__getitem__", [](Vector_type & v, int const idx){ return v[idx]; }) @@ -106,4 +114,6 @@ void init_Vector(py::module& m) make_Vector (m, "int"); if constexpr(!std::is_same_v) make_Vector (m, "Long"); + + make_Vector (m, "string"); } diff --git a/src/pyAMReX.cpp b/src/pyAMReX.cpp index a5e67307..4de4333a 100644 --- a/src/pyAMReX.cpp +++ b/src/pyAMReX.cpp @@ -37,6 +37,7 @@ void init_ArrayOfStructs(py::module &); void init_ParticleTile(py::module &); void init_ParticleContainer(py::module &); void init_Periodicity(py::module &); +void init_PlotFileUtil(py::module &); void init_PODVector(py::module &); void init_Utility(py::module &); void init_Vector(py::module &); @@ -77,6 +78,7 @@ PYBIND11_MODULE(amrex_3d_pybind, m) { ParticleTile ParticleContainer Periodicity + PlotFileUtil PODVector StructOfArrays Utility @@ -113,6 +115,7 @@ PYBIND11_MODULE(amrex_3d_pybind, m) { init_AmrMesh(m); // Wrappers around standalone functions + init_PlotFileUtil(m); init_Utility(m); // API runtime version