diff --git a/language_bindings/python/bind_py_fftengine.cc b/language_bindings/python/bind_py_fftengine.cc index fa29e07..d1bc1ad 100644 --- a/language_bindings/python/bind_py_fftengine.cc +++ b/language_bindings/python/bind_py_fftengine.cc @@ -1,105 +1,110 @@ /** * @file bind_py_fftengine.cc * * @author Till Junge * * @date 17 Jan 2018 * * @brief Python bindings for the FFT engines * * Copyright © 2018 Till Junge * * µSpectre is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as * published by the Free Software Foundation, either version 3, or (at * your option) any later version. * * µSpectre is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details. * * You should have received a copy of the GNU General Public License * along with GNU Emacs; see the file COPYING. If not, write to the * Free Software Foundation, Inc., 59 Temple Place - Suite 330, * Boston, MA 02111-1307, USA. */ #include "fft/fftw_engine.hh" #ifdef WITH_FFTWMPI #include "fft/fftwmpi_engine.hh" #endif #ifdef WITH_PFFT #include "fft/pfft_engine.hh" #endif #include "bind_py_declarations.hh" #include #include #include using namespace muSpectre; namespace py=pybind11; using namespace pybind11::literals; template void add_engine_helper(py::module & mod, std::string name) { using Ccoord = Ccoord_t; using ArrayXXc = Eigen::Array; py::class_(mod, name.c_str()) #ifdef WITH_MPI .def(py::init([](Ccoord res, size_t comm) { return new Engine(res, std::move(Communicator(MPI_Comm(comm)))); }), "resolutions"_a, "communicator"_a=size_t(MPI_COMM_SELF)) #else .def(py::init()) #endif .def("fft", [](Engine & eng, py::EigenDRef v) { using Coll_t = typename Engine::GFieldCollection_t; using Field_t = typename Engine::Field_t; Coll_t coll{}; coll.initialise(eng.get_subdomain_resolutions(), eng.get_subdomain_locations()); Field_t & temp{make_field("temp_field", coll)}; temp.eigen() = v; return ArrayXXc{eng.fft(temp).eigen()}; }, "array"_a) .def("ifft", [](Engine & eng, py::EigenDRef v) { using Coll_t = typename Engine::GFieldCollection_t; using Field_t = typename Engine::Field_t; Coll_t coll{}; coll.initialise(eng.get_subdomain_resolutions(), eng.get_subdomain_locations()); Field_t & temp{make_field("temp_field", coll)}; eng.get_work_space().eigen() = v; eng.ifft(temp); return Eigen::ArrayXXd{temp.eigen()}; }, "array"_a) .def("initialise", &Engine::initialise, "flags"_a=FFT_PlanFlags::estimate) - .def("normalisation", &Engine::normalisation); + .def("normalisation", &Engine::normalisation) + .def("get_subdomain_resolutions", &Engine::get_subdomain_resolutions) + .def("get_subdomain_locations", &Engine::get_subdomain_locations) + .def("get_fourier_resolutions", &Engine::get_fourier_resolutions) + .def("get_fourier_locations", &Engine::get_fourier_locations) + .def("get_domain_resolutions", &Engine::get_domain_resolutions); } void add_fft_engines(py::module & mod) { auto fft{mod.def_submodule("fft")}; fft.doc() = "bindings for µSpectre's fft engines"; add_engine_helper< twoD, FFTWEngine< twoD, twoD>>(fft, "FFTW_2d"); add_engine_helper>(fft, "FFTW_3d"); #ifdef WITH_FFTWMPI add_engine_helper< twoD, FFTWMPIEngine< twoD, twoD>>(fft, "FFTWMPI_2d"); add_engine_helper>(fft, "FFTWMPI_3d"); #endif #ifdef WITH_PFFT add_engine_helper< twoD, PFFTEngine< twoD, twoD>>(fft, "PFFT_2d"); add_engine_helper>(fft, "PFFT_3d"); #endif add_projections(fft); }