/* Copyright 2021-2022 The WarpX Community * * Authors: Axel Huebl * License: BSD-3-Clause-LBNL */ #include "pyWarpX.H" #include // see WarpX.cpp - full includes for _fwd.H headers #include #include #include #include #include #include #include #ifdef WARPX_USE_PSATD # include # ifdef WARPX_DIM_RZ # include # include # else # include # endif // RZ ifdef #endif // use PSATD ifdef #include #include #include #include #include #include #include #include #include #include #include #include #include #if defined(AMREX_DEBUG) || defined(DEBUG) # include #endif #include //using namespace warpx; namespace warpx { struct Config {}; } void init_WarpX (py::module& m) { // Expose the WarpX instance m.def("get_instance", [] () { return &WarpX::GetInstance(); }, "Return a reference to the WarpX object."); m.def("finalize", &WarpX::Finalize, "Close out the WarpX related data"); py::class_ warpx(m, "WarpX"); warpx // WarpX is a Singleton Class with a private constructor // https://github.com/ECP-WarpX/WarpX/pull/4104 // https://pybind11.readthedocs.io/en/stable/advanced/classes.html?highlight=singleton#custom-constructors .def(py::init([]() { return &WarpX::GetInstance(); })) .def_static("get_instance", [] () { return &WarpX::GetInstance(); }, "Return a reference to the WarpX object." ) .def_static("finalize", &WarpX::Finalize, "Close out the WarpX related data" ) .def("initialize_data", &WarpX::InitData, "Initializes the WarpX simulation" ) .def("evolve", &WarpX::Evolve, "Evolve the simulation the specified number of steps" ) // from AmrCore->AmrMesh .def("Geom", //[](WarpX const & wx, int const lev) { return wx.Geom(lev); }, py::overload_cast< int >(&WarpX::Geom, py::const_), py::arg("lev") ) .def("DistributionMap", [](WarpX const & wx, int const lev) { return wx.DistributionMap(lev); }, //py::overload_cast< int >(&WarpX::DistributionMap, py::const_), py::arg("lev") ) .def("boxArray", [](WarpX const & wx, int const lev) { return wx.boxArray(lev); }, //py::overload_cast< int >(&WarpX::boxArray, py::const_), py::arg("lev") ) .def("multifab", [](WarpX const & wx, std::string const multifab_name) { if (wx.multifab_map.count(multifab_name) > 0) { return wx.multifab_map.at(multifab_name); } else { throw std::runtime_error("The MultiFab '" + multifab_name + "' is unknown or is not allocated!"); } }, py::arg("multifab_name"), py::return_value_policy::reference_internal, "Return MultiFabs by name, e.g., 'Efield_aux[x][l=0]', 'Efield_cp[x][l=0]', ..." ) .def("multi_particle_container", [](WarpX& wx){ return &wx.GetPartContainer(); }, py::return_value_policy::reference_internal ) .def("get_particle_boundary_buffer", [](WarpX& wx){ return &wx.GetParticleBoundaryBuffer(); }, py::return_value_policy::reference_internal ) // Expose functions used to sync the charge density multifab // accross tiles and apply appropriate boundary conditions .def("sync_rho", [](WarpX& wx){ wx.SyncRho(); } ) #ifdef WARPX_DIM_RZ .def("apply_inverse_volume_scaling_to_charge_density", [](WarpX& wx, amrex::MultiFab* rho, int const lev) { wx.ApplyInverseVolumeScalingToChargeDensity(rho, lev); }, py::arg("rho"), py::arg("lev") ) #endif // Expose functions to get the current simulation step and time .def("getistep", [](WarpX const & wx, int lev){ return wx.getistep(lev); }, py::arg("lev") ) .def("gett_new", [](WarpX const & wx, int lev){ return wx.gett_new(lev); }, py::arg("lev") ) .def("set_potential_on_eb", [](WarpX& wx, std::string potential) { wx.m_poisson_boundary_handler.setPotentialEB(potential); }, py::arg("potential") ) ; py::class_(m, "Config") // .def_property_readonly_static( // "warpx_version", // [](py::object) { return Version(); }, // "WarpX version") .def_property_readonly_static( "have_mpi", [](py::object){ #ifdef AMREX_USE_MPI return true; #else return false; #endif }) .def_property_readonly_static( "have_gpu", [](py::object){ #ifdef AMREX_USE_GPU return true; #else return false; #endif }) .def_property_readonly_static( "have_omp", [](py::object){ #ifdef AMREX_USE_OMP return true; #else return false; #endif }) .def_property_readonly_static( "gpu_backend", [](py::object){ #ifdef AMREX_USE_CUDA return "CUDA"; #elif defined(AMREX_USE_HIP) return "HIP"; #elif defined(AMREX_USE_DPCPP) return "SYCL"; #else return py::none(); #endif }) ; }