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

Add wrapper for VisMF #388

Merged
merged 5 commits into from
Nov 1, 2024
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 @@ -33,6 +33,7 @@ foreach(D IN LISTS AMReX_SPACEDIM)
Utility.cpp
Vector.cpp
Version.cpp
VisMF.cpp
)

if (AMReX_MPI)
Expand Down
46 changes: 46 additions & 0 deletions src/Base/VisMF.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/* Copyright 2024 The AMReX Community
*
* Authors: David Grote
* License: BSD-3-Clause-LBNL
*/
#include "pyAMReX.H"

#include <AMReX_VisMF.H>
#include <AMReX_MultiFab.H>

void init_VisMF(py::module &m)
{
py::class_< amrex::VisMF > py_VisMF(m, "VisMF");

py_VisMF
.def_static("Write",
[](const amrex::FabArray<amrex::FArrayBox> &mf, const std::string& name) {
return amrex::VisMF::Write(mf, name);
},
py::arg("mf"), py::arg("name"),
"Writes a Multifab to the specified file")
.def_static("Read",
[](const std::string &name) {
amrex::MultiFab mf;
if (amrex::VisMF::Exist(name)) {
amrex::VisMF::Read(mf, name);
} else {
throw std::runtime_error("MultiFab file " + name + " couldn't be found!");
}
return mf;
},
py::return_value_policy::move,
py::arg("name"),
"Reads a MultiFab from the specified file")
.def_static("Read",
[](const std::string &name, amrex::MultiFab &mf) {
if (amrex::VisMF::Exist(name)) {
amrex::VisMF::Read(mf, name);
} else {
throw std::runtime_error("MultiFab file " + name + " couldn't be found!");
}
},
py::arg("name"), py::arg("mf"),
"Reads a MultiFab from the specified file into the given MultiFab. The BoxArray on the disk must match the BoxArray * in mf")
;
}
3 changes: 3 additions & 0 deletions src/pyAMReX.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ void init_PODVector(py::module &);
void init_Utility(py::module &);
void init_Vector(py::module &);
void init_Version(py::module &);
void init_VisMF(py::module &);
#ifdef AMREX_USE_MPI
void init_MPMD(py::module &);
#endif
Expand Down Expand Up @@ -82,6 +83,7 @@ PYBIND11_MODULE(amrex_3d_pybind, m) {
StructOfArrays
Utility
Vector
VisMF
)pbdoc";

// note: order from parent to child classes and argument usage
Expand Down Expand Up @@ -117,6 +119,7 @@ PYBIND11_MODULE(amrex_3d_pybind, m) {
init_PlotFileUtil(m);
init_Utility(m);
init_Version(m);
init_VisMF(m);

// authors
m.attr("__author__") =
Expand Down
Loading