Skip to content

Commit

Permalink
Add wrapper for VisMF (#388)
Browse files Browse the repository at this point in the history
I need to read in a MultiFab so added this.

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
  • Loading branch information
dpgrote and pre-commit-ci[bot] authored Nov 1, 2024
1 parent 2ed3ba2 commit 6c2dc4f
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 0 deletions.
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

0 comments on commit 6c2dc4f

Please sign in to comment.