Skip to content

Commit 6c2dc4f

Browse files
Add wrapper for VisMF (#388)
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>
1 parent 2ed3ba2 commit 6c2dc4f

File tree

3 files changed

+50
-0
lines changed

3 files changed

+50
-0
lines changed

src/Base/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ foreach(D IN LISTS AMReX_SPACEDIM)
3333
Utility.cpp
3434
Vector.cpp
3535
Version.cpp
36+
VisMF.cpp
3637
)
3738

3839
if (AMReX_MPI)

src/Base/VisMF.cpp

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/* Copyright 2024 The AMReX Community
2+
*
3+
* Authors: David Grote
4+
* License: BSD-3-Clause-LBNL
5+
*/
6+
#include "pyAMReX.H"
7+
8+
#include <AMReX_VisMF.H>
9+
#include <AMReX_MultiFab.H>
10+
11+
void init_VisMF(py::module &m)
12+
{
13+
py::class_< amrex::VisMF > py_VisMF(m, "VisMF");
14+
15+
py_VisMF
16+
.def_static("Write",
17+
[](const amrex::FabArray<amrex::FArrayBox> &mf, const std::string& name) {
18+
return amrex::VisMF::Write(mf, name);
19+
},
20+
py::arg("mf"), py::arg("name"),
21+
"Writes a Multifab to the specified file")
22+
.def_static("Read",
23+
[](const std::string &name) {
24+
amrex::MultiFab mf;
25+
if (amrex::VisMF::Exist(name)) {
26+
amrex::VisMF::Read(mf, name);
27+
} else {
28+
throw std::runtime_error("MultiFab file " + name + " couldn't be found!");
29+
}
30+
return mf;
31+
},
32+
py::return_value_policy::move,
33+
py::arg("name"),
34+
"Reads a MultiFab from the specified file")
35+
.def_static("Read",
36+
[](const std::string &name, amrex::MultiFab &mf) {
37+
if (amrex::VisMF::Exist(name)) {
38+
amrex::VisMF::Read(mf, name);
39+
} else {
40+
throw std::runtime_error("MultiFab file " + name + " couldn't be found!");
41+
}
42+
},
43+
py::arg("name"), py::arg("mf"),
44+
"Reads a MultiFab from the specified file into the given MultiFab. The BoxArray on the disk must match the BoxArray * in mf")
45+
;
46+
}

src/pyAMReX.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ void init_PODVector(py::module &);
3838
void init_Utility(py::module &);
3939
void init_Vector(py::module &);
4040
void init_Version(py::module &);
41+
void init_VisMF(py::module &);
4142
#ifdef AMREX_USE_MPI
4243
void init_MPMD(py::module &);
4344
#endif
@@ -82,6 +83,7 @@ PYBIND11_MODULE(amrex_3d_pybind, m) {
8283
StructOfArrays
8384
Utility
8485
Vector
86+
VisMF
8587
)pbdoc";
8688

8789
// note: order from parent to child classes and argument usage
@@ -117,6 +119,7 @@ PYBIND11_MODULE(amrex_3d_pybind, m) {
117119
init_PlotFileUtil(m);
118120
init_Utility(m);
119121
init_Version(m);
122+
init_VisMF(m);
120123

121124
// authors
122125
m.attr("__author__") =

0 commit comments

Comments
 (0)