diff options
Diffstat (limited to 'Source/Python/WarpX.cpp')
-rw-r--r-- | Source/Python/WarpX.cpp | 201 |
1 files changed, 201 insertions, 0 deletions
diff --git a/Source/Python/WarpX.cpp b/Source/Python/WarpX.cpp new file mode 100644 index 000000000..9ef5281b3 --- /dev/null +++ b/Source/Python/WarpX.cpp @@ -0,0 +1,201 @@ +/* Copyright 2021-2022 The WarpX Community + * + * Authors: Axel Huebl + * License: BSD-3-Clause-LBNL + */ +#include "pyWarpX.H" + +#include <WarpX.H> +// see WarpX.cpp - full includes for _fwd.H headers +#include <BoundaryConditions/PML.H> +#include <Diagnostics/MultiDiagnostics.H> +#include <Diagnostics/ReducedDiags/MultiReducedDiags.H> +#include <EmbeddedBoundary/WarpXFaceInfoBox.H> +#include <FieldSolver/FiniteDifferenceSolver/FiniteDifferenceSolver.H> +#include <FieldSolver/FiniteDifferenceSolver/MacroscopicProperties/MacroscopicProperties.H> +#include <FieldSolver/FiniteDifferenceSolver/HybridPICModel/HybridPICModel.H> +#ifdef WARPX_USE_PSATD +# include <FieldSolver/SpectralSolver/SpectralKSpace.H> +# ifdef WARPX_DIM_RZ +# include <FieldSolver/SpectralSolver/SpectralSolverRZ.H> +# include <BoundaryConditions/PML_RZ.H> +# else +# include <FieldSolver/SpectralSolver/SpectralSolver.H> +# endif // RZ ifdef +#endif // use PSATD ifdef +#include <FieldSolver/WarpX_FDTD.H> +#include <Filter/NCIGodfreyFilter.H> +#include <Particles/MultiParticleContainer.H> +#include <Particles/ParticleBoundaryBuffer.H> +#include <AcceleratorLattice/AcceleratorLattice.H> +#include <Utils/TextMsg.H> +#include <Utils/WarpXAlgorithmSelection.H> +#include <Utils/WarpXConst.H> +#include <Utils/WarpXProfilerWrapper.H> +#include <Utils/WarpXUtil.H> + +#include <AMReX.H> +#include <AMReX_ParmParse.H> +#include <AMReX_ParallelDescriptor.H> + +#if defined(AMREX_DEBUG) || defined(DEBUG) +# include <cstdio> +#endif +#include <string> + + +//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> 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_<warpx::Config>(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 + }) + ; +} |