Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wrapper for writing single level plotfile #153

Merged
merged 1 commit into from
Jul 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/Base/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ foreach(D IN LISTS AMReX_SPACEDIM)
ParallelDescriptor.cpp
ParmParse.cpp
Periodicity.cpp
PlotFileUtil.cpp
PODVector.cpp
Utility.cpp
Vector.cpp
Expand Down
33 changes: 33 additions & 0 deletions src/Base/PlotFileUtil.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/* Copyright 2021-2022 The AMReX Community
*
* License: BSD-3-Clause-LBNL
*/
#include "pyAMReX.H"

#include <AMReX_PlotFileUtil.H>
#include <AMReX_Vector.H>
#include <AMReX_Print.H>

#include <sstream>
#include <string>

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<std::string>()
);
}
14 changes: 12 additions & 2 deletions src/Base/Vector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ void make_Vector(py::module &m, std::string typestr)
using Vector_type = Vector<T, Allocator>;
auto const v_name = std::string("Vector_").append(typestr);

py::class_<Vector_type>(m, v_name.c_str())
auto py_vect = py::bind_vector<Vector_type>(m, v_name.c_str());
py_vect
.def("__repr__",
[typestr](Vector_type const & v) {
std::stringstream s, rs;
Expand All @@ -61,9 +62,14 @@ void make_Vector(py::module &m, std::string typestr)
}
)
.def(py::init<>())
.def(py::init<Vector_type const &>())

.def("size", &Vector_type::size)
;

if constexpr(!std::is_same_v<T, std::string>)
{
py_vect
.def_property_readonly("__array_interface__", [](Vector_type const & vector) {
return array_interface(vector);
})
Expand All @@ -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]; })
Expand All @@ -106,4 +114,6 @@ void init_Vector(py::module& m)
make_Vector<int> (m, "int");
if constexpr(!std::is_same_v<int, Long>)
make_Vector<Long> (m, "Long");

make_Vector<std::string> (m, "string");
}
3 changes: 3 additions & 0 deletions src/pyAMReX.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 &);
Expand Down Expand Up @@ -77,6 +78,7 @@ PYBIND11_MODULE(amrex_3d_pybind, m) {
ParticleTile
ParticleContainer
Periodicity
PlotFileUtil
PODVector
StructOfArrays
Utility
Expand Down Expand Up @@ -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
Expand Down
Loading