|
| 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 | +} |
0 commit comments