From eb07f18b380cb6b7205c05e7828f00a0fa2b8161 Mon Sep 17 00:00:00 2001 From: MaxThevenet Date: Tue, 12 Feb 2019 10:42:13 -0800 Subject: re-order tree structure of source code --- Source/Python/WarpX_py.H | 23 +++++++++++++++++++++++ Source/Python/WarpX_py.cpp | 19 +++++++++++++++++++ 2 files changed, 42 insertions(+) create mode 100644 Source/Python/WarpX_py.H create mode 100644 Source/Python/WarpX_py.cpp (limited to 'Source/Python') diff --git a/Source/Python/WarpX_py.H b/Source/Python/WarpX_py.H new file mode 100644 index 000000000..d8cf22155 --- /dev/null +++ b/Source/Python/WarpX_py.H @@ -0,0 +1,23 @@ +#ifndef WARPX_PY_H_ +#define WARPX_PY_H_ + +#include + +extern "C" { + + extern WARPX_CALLBACK_PY_FUNC_0 warpx_py_afterinit; + extern WARPX_CALLBACK_PY_FUNC_0 warpx_py_beforeEsolve; + extern WARPX_CALLBACK_PY_FUNC_0 warpx_py_afterEsolve; + extern WARPX_CALLBACK_PY_FUNC_0 warpx_py_beforedeposition; + extern WARPX_CALLBACK_PY_FUNC_0 warpx_py_afterdeposition; + extern WARPX_CALLBACK_PY_FUNC_0 warpx_py_particlescraper; + extern WARPX_CALLBACK_PY_FUNC_0 warpx_py_particleloader; + extern WARPX_CALLBACK_PY_FUNC_0 warpx_py_beforestep; + extern WARPX_CALLBACK_PY_FUNC_0 warpx_py_afterstep; + extern WARPX_CALLBACK_PY_FUNC_0 warpx_py_afterrestart; + extern WARPX_CALLBACK_PY_FUNC_0 warpx_py_particleinjection; + extern WARPX_CALLBACK_PY_FUNC_0 warpx_py_appliedfields; + +} + +#endif diff --git a/Source/Python/WarpX_py.cpp b/Source/Python/WarpX_py.cpp new file mode 100644 index 000000000..276d637d7 --- /dev/null +++ b/Source/Python/WarpX_py.cpp @@ -0,0 +1,19 @@ +#include + +extern "C" { + + WARPX_CALLBACK_PY_FUNC_0 warpx_py_afterinit = nullptr; + WARPX_CALLBACK_PY_FUNC_0 warpx_py_beforeEsolve = nullptr; + WARPX_CALLBACK_PY_FUNC_0 warpx_py_afterEsolve = nullptr; + WARPX_CALLBACK_PY_FUNC_0 warpx_py_beforedeposition = nullptr; + WARPX_CALLBACK_PY_FUNC_0 warpx_py_afterdeposition = nullptr; + WARPX_CALLBACK_PY_FUNC_0 warpx_py_particlescraper = nullptr; + WARPX_CALLBACK_PY_FUNC_0 warpx_py_particleloader = nullptr; + WARPX_CALLBACK_PY_FUNC_0 warpx_py_beforestep = nullptr; + WARPX_CALLBACK_PY_FUNC_0 warpx_py_afterstep = nullptr; + WARPX_CALLBACK_PY_FUNC_0 warpx_py_afterrestart = nullptr; + WARPX_CALLBACK_PY_FUNC_0 warpx_py_particleinjection = nullptr; + WARPX_CALLBACK_PY_FUNC_0 warpx_py_appliedfields = nullptr; + +} + -- cgit v1.2.3 From 1e86168dc188d74f1e33d3725ccbdfdedb31258e Mon Sep 17 00:00:00 2001 From: MaxThevenet Date: Tue, 19 Feb 2019 14:06:01 -0800 Subject: update make file(s) so that code compiles --- Source/BoundaryConditions/Make.package | 9 +++++++ Source/Diagnostics/Make.package | 8 +++++++ Source/Electrostatic/Make.package | 7 ++++++ Source/FieldSolver/Make.package | 7 ++++++ Source/Filter/Make.package | 4 ++++ Source/FortranInterface/Make.package | 6 +++++ Source/Initialization/Make.package | 10 ++++++++ Source/Laser/Make.package | 6 +++++ Source/Make.WarpX | 12 ++++++++++ Source/Make.package | 43 +++------------------------------- Source/Parallelization/Make.package | 5 ++++ Source/Particles/Make.package | 11 +++++++++ Source/Python/Make.package | 10 ++++++++ Source/Utils/Make.package | 11 +++++++++ 14 files changed, 109 insertions(+), 40 deletions(-) create mode 100644 Source/BoundaryConditions/Make.package create mode 100644 Source/Diagnostics/Make.package create mode 100644 Source/Electrostatic/Make.package create mode 100644 Source/FieldSolver/Make.package create mode 100644 Source/Filter/Make.package create mode 100644 Source/FortranInterface/Make.package create mode 100644 Source/Initialization/Make.package create mode 100644 Source/Laser/Make.package create mode 100644 Source/Parallelization/Make.package create mode 100644 Source/Particles/Make.package create mode 100644 Source/Python/Make.package create mode 100644 Source/Utils/Make.package (limited to 'Source/Python') diff --git a/Source/BoundaryConditions/Make.package b/Source/BoundaryConditions/Make.package new file mode 100644 index 000000000..931b48147 --- /dev/null +++ b/Source/BoundaryConditions/Make.package @@ -0,0 +1,9 @@ +CEXE_sources += WarpXPML.cpp +CEXE_headers += WarpXPML.H +F90EXE_sources += WarpX_pml.F90 +ifeq ($(USE_OPENBC_POISSON),TRUE) + F90EXE_sources += openbc_f.F90 +endif + +INCLUDE_LOCATIONS += $(WARPX_HOME)/Source/BoundaryConditions +VPATH_LOCATIONS += $(WARPX_HOME)/Source/BoundaryConditions diff --git a/Source/Diagnostics/Make.package b/Source/Diagnostics/Make.package new file mode 100644 index 000000000..ac5f033f5 --- /dev/null +++ b/Source/Diagnostics/Make.package @@ -0,0 +1,8 @@ +CEXE_sources += WarpXIO.cpp +CEXE_sources += WarpXBoostedFrameDiagnostic.cpp +CEXE_sources += ParticleIO.cpp +CEXE_headers += WarpXBoostedFrameDiagnostic.H +F90EXE_sources += WarpX_boosted_frame.F90 + +INCLUDE_LOCATIONS += $(WARPX_HOME)/Source/Diagnostics +VPATH_LOCATIONS += $(WARPX_HOME)/Source/Diagnostics diff --git a/Source/Electrostatic/Make.package b/Source/Electrostatic/Make.package new file mode 100644 index 000000000..5640c3940 --- /dev/null +++ b/Source/Electrostatic/Make.package @@ -0,0 +1,7 @@ +F90EXE_sources += WarpX_electrostatic.F90 +ifeq ($(DO_ELECTROSTATIC),TRUE) + CEXE_sources += WarpXElectrostatic.cpp +endif + +INCLUDE_LOCATIONS += $(WARPX_HOME)/Source/Electrostatic +VPATH_LOCATIONS += $(WARPX_HOME)/Source/Electrostatic diff --git a/Source/FieldSolver/Make.package b/Source/FieldSolver/Make.package new file mode 100644 index 000000000..7cfe3136b --- /dev/null +++ b/Source/FieldSolver/Make.package @@ -0,0 +1,7 @@ +ifeq ($(USE_PSATD),TRUE) + CEXE_sources += WarpXFFT.cpp + F90EXE_sources += WarpX_fft.F90 +endif + +INCLUDE_LOCATIONS += $(WARPX_HOME)/Source/FieldSolver +VPATH_LOCATIONS += $(WARPX_HOME)/Source/FieldSolver diff --git a/Source/Filter/Make.package b/Source/Filter/Make.package new file mode 100644 index 000000000..404e8daa4 --- /dev/null +++ b/Source/Filter/Make.package @@ -0,0 +1,4 @@ +F90EXE_sources += WarpX_filter.F90 + +INCLUDE_LOCATIONS += $(WARPX_HOME)/Source/Filter +VPATH_LOCATIONS += $(WARPX_HOME)/Source/Filter diff --git a/Source/FortranInterface/Make.package b/Source/FortranInterface/Make.package new file mode 100644 index 000000000..fe0c2ba3d --- /dev/null +++ b/Source/FortranInterface/Make.package @@ -0,0 +1,6 @@ +CEXE_headers += WarpX_f.H +F90EXE_sources += WarpX_f.F90 +F90EXE_sources += WarpX_picsar.F90 + +INCLUDE_LOCATIONS += $(WARPX_HOME)/Source/FortranInterface +VPATH_LOCATIONS += $(WARPX_HOME)/Source/FortranInterface diff --git a/Source/Initialization/Make.package b/Source/Initialization/Make.package new file mode 100644 index 000000000..32f2932a0 --- /dev/null +++ b/Source/Initialization/Make.package @@ -0,0 +1,10 @@ +CEXE_sources += CustomDensityProb.cpp +CEXE_sources += WarpXInitData.cpp +CEXE_sources += CustomMomentumProb.cpp +CEXE_sources += PlasmaInjector.cpp +CEXE_sources += WarpXProb.cpp +CEXE_headers += PlasmaInjector.H +F90EXE_sources += WarpX_parser.F90 + +INCLUDE_LOCATIONS += $(WARPX_HOME)/Source/Initialization +VPATH_LOCATIONS += $(WARPX_HOME)/Source/Initialization diff --git a/Source/Laser/Make.package b/Source/Laser/Make.package new file mode 100644 index 000000000..96e1e8350 --- /dev/null +++ b/Source/Laser/Make.package @@ -0,0 +1,6 @@ +CEXE_sources += LaserParticleContainer.cpp +CEXE_headers += LaserParticleContainer.H +F90EXE_sources += WarpX_laser.F90 + +INCLUDE_LOCATIONS += $(WARPX_HOME)/Source/Laser +VPATH_LOCATIONS += $(WARPX_HOME)/Source/Laser diff --git a/Source/Make.WarpX b/Source/Make.WarpX index e5da17e93..320cd251d 100644 --- a/Source/Make.WarpX +++ b/Source/Make.WarpX @@ -32,6 +32,18 @@ endif -include Make.package include $(WARPX_HOME)/Source/Make.package +include $(WARPX_HOME)/Source/BoundaryConditions/Make.package +include $(WARPX_HOME)/Source/Diagnostics/Make.package +include $(WARPX_HOME)/Source/Electrostatic/Make.package +include $(WARPX_HOME)/Source/FieldSolver/Make.package +include $(WARPX_HOME)/Source/Filter/Make.package +include $(WARPX_HOME)/Source/FortranInterface/Make.package +include $(WARPX_HOME)/Source/Initialization/Make.package +include $(WARPX_HOME)/Source/Laser/Make.package +include $(WARPX_HOME)/Source/Parallelization/Make.package +include $(WARPX_HOME)/Source/Particles/Make.package +include $(WARPX_HOME)/Source/Python/Make.package +include $(WARPX_HOME)/Source/Utils/Make.package include $(AMREX_HOME)/Src/Base/Make.package include $(AMREX_HOME)/Src/Particle/Make.package diff --git a/Source/Make.package b/Source/Make.package index f55e12297..d6fdf3094 100644 --- a/Source/Make.package +++ b/Source/Make.package @@ -1,46 +1,9 @@ ifneq ($(USE_PYTHON_MAIN),TRUE) CEXE_sources += main.cpp -else - CEXE_sources += WarpXWrappers.cpp - CEXE_headers += WarpXWrappers.h endif -CEXE_sources += WarpX_py.cpp - -CEXE_sources += WarpX.cpp WarpXInitData.cpp WarpXEvolve.cpp WarpXIO.cpp WarpXProb.cpp WarpXRegrid.cpp -CEXE_sources += WarpXTagging.cpp WarpXComm.cpp WarpXMove.cpp WarpXBoostedFrameDiagnostic.cpp - -CEXE_sources += ParticleIO.cpp -CEXE_sources += ParticleContainer.cpp WarpXParticleContainer.cpp PhysicalParticleContainer.cpp LaserParticleContainer.cpp RigidInjectedParticleContainer.cpp - -CEXE_headers += WarpX_py.H - -CEXE_headers += WarpX.H WarpX_f.H WarpXConst.H WarpXBoostedFrameDiagnostic.H -CEXE_sources += WarpXConst.cpp - -CEXE_headers += ParticleContainer.H WarpXParticleContainer.H PhysicalParticleContainer.H LaserParticleContainer.H RigidInjectedParticleContainer.H - -CEXE_headers += PlasmaInjector.H -CEXE_sources += PlasmaInjector.cpp CustomDensityProb.cpp CustomMomentumProb.cpp - -CEXE_sources += WarpXPML.cpp WarpXUtil.cpp -CEXE_headers += WarpXPML.H WarpXUtil.H - -F90EXE_sources += WarpX_f.F90 WarpX_picsar.F90 WarpX_laser.F90 WarpX_pml.F90 WarpX_electrostatic.F90 -F90EXE_sources += WarpX_boosted_frame.F90 WarpX_filter.F90 WarpX_parser.F90 - -ifeq ($(USE_OPENBC_POISSON),TRUE) - F90EXE_sources += openbc_f.F90 -endif - -ifeq ($(USE_PSATD),TRUE) - CEXE_sources += WarpXFFT.cpp - F90EXE_sources += WarpX_fft.F90 -endif - -ifeq ($(DO_ELECTROSTATIC),TRUE) - CEXE_sources += WarpXElectrostatic.cpp -endif +CEXE_sources += WarpXEvolve.cpp WarpX.cpp +CEXE_headers += WarpX.H INCLUDE_LOCATIONS += $(WARPX_HOME)/Source -VPATH_LOCATIONS += $(WARPX_HOME)/Source +VPATH_LOCATIONS += $(WARPX_HOME)/Source \ No newline at end of file diff --git a/Source/Parallelization/Make.package b/Source/Parallelization/Make.package new file mode 100644 index 000000000..cbb1b5234 --- /dev/null +++ b/Source/Parallelization/Make.package @@ -0,0 +1,5 @@ +CEXE_sources += WarpXComm.cpp +CEXE_sources += WarpXRegrid.cpp + +INCLUDE_LOCATIONS += $(WARPX_HOME)/Source/Parallelization +VPATH_LOCATIONS += $(WARPX_HOME)/Source/Parallelization diff --git a/Source/Particles/Make.package b/Source/Particles/Make.package new file mode 100644 index 000000000..e7a7039d5 --- /dev/null +++ b/Source/Particles/Make.package @@ -0,0 +1,11 @@ +CEXE_sources += PhysicalParticleContainer.cpp +CEXE_sources += ParticleContainer.cpp +CEXE_sources += WarpXParticleContainer.cpp +CEXE_sources += RigidInjectedParticleContainer.cpp +CEXE_headers += ParticleContainer.H +CEXE_headers += WarpXParticleContainer.H +CEXE_headers += RigidInjectedParticleContainer.H +CEXE_headers += PhysicalParticleContainer.H + +INCLUDE_LOCATIONS += $(WARPX_HOME)/Source/Particles +VPATH_LOCATIONS += $(WARPX_HOME)/Source/Particles diff --git a/Source/Python/Make.package b/Source/Python/Make.package new file mode 100644 index 000000000..c79049f02 --- /dev/null +++ b/Source/Python/Make.package @@ -0,0 +1,10 @@ +ifeq ($(USE_PYTHON_MAIN),TRUE) + CEXE_sources += WarpXWrappers.cpp + CEXE_headers += WarpXWrappers.h +endif + +CEXE_sources += WarpX_py.cpp +CEXE_headers += WarpX_py.H + +INCLUDE_LOCATIONS += $(WARPX_HOME)/Source/Python +VPATH_LOCATIONS += $(WARPX_HOME)/Source/Python diff --git a/Source/Utils/Make.package b/Source/Utils/Make.package new file mode 100644 index 000000000..81ef76e51 --- /dev/null +++ b/Source/Utils/Make.package @@ -0,0 +1,11 @@ +CEXE_sources += WarpXMove.cpp +CEXE_sources += WarpXWrappers.cpp +CEXE_sources += WarpXConst.cpp +CEXE_sources += WarpXTagging.cpp +CEXE_sources += WarpXUtil.cpp +CEXE_headers += WarpXConst.H +CEXE_headers += WarpXUtil.H +CEXE_headers += WarpXWrappers.h + +INCLUDE_LOCATIONS += $(WARPX_HOME)/Source/Utils +VPATH_LOCATIONS += $(WARPX_HOME)/Source/Utils -- cgit v1.2.3 From 8282a703e7ab08d1f3f5cf197aa242fabf717c57 Mon Sep 17 00:00:00 2001 From: MaxThevenet Date: Fri, 1 Mar 2019 10:25:55 -0800 Subject: move warpxwrappers. rename ParticleContainer files to MultiParticleContainer files --- Source/Diagnostics/BoostedFrameDiagnostic.H | 2 +- Source/Diagnostics/ParticleIO.cpp | 2 +- Source/Laser/LaserParticleContainer.cpp | 2 +- Source/Particles/Make.package | 4 +- Source/Particles/MultiParticleContainer.H | 209 ++++++++++++ Source/Particles/MultiParticleContainer.cpp | 389 +++++++++++++++++++++ Source/Particles/ParticleContainer.H | 209 ------------ Source/Particles/ParticleContainer.cpp | 389 --------------------- Source/Particles/PhysicalParticleContainer.cpp | 2 +- Source/Particles/WarpXParticleContainer.cpp | 2 +- Source/Python/Make.package | 3 +- Source/Python/WarpXWrappers.cpp | 446 +++++++++++++++++++++++++ Source/Python/WarpXWrappers.h | 120 +++++++ Source/Utils/Make.package | 2 - Source/Utils/WarpXConst.cpp | 2 +- Source/Utils/WarpXWrappers.cpp | 446 ------------------------- Source/Utils/WarpXWrappers.h | 120 ------- 17 files changed, 1174 insertions(+), 1175 deletions(-) create mode 100644 Source/Particles/MultiParticleContainer.H create mode 100644 Source/Particles/MultiParticleContainer.cpp delete mode 100644 Source/Particles/ParticleContainer.H delete mode 100644 Source/Particles/ParticleContainer.cpp create mode 100644 Source/Python/WarpXWrappers.cpp create mode 100644 Source/Python/WarpXWrappers.h delete mode 100644 Source/Utils/WarpXWrappers.cpp delete mode 100644 Source/Utils/WarpXWrappers.h (limited to 'Source/Python') diff --git a/Source/Diagnostics/BoostedFrameDiagnostic.H b/Source/Diagnostics/BoostedFrameDiagnostic.H index 452062137..17f2b161c 100644 --- a/Source/Diagnostics/BoostedFrameDiagnostic.H +++ b/Source/Diagnostics/BoostedFrameDiagnostic.H @@ -7,7 +7,7 @@ #include #include -#include "ParticleContainer.H" +#include "MultiParticleContainer.H" #include "WarpXConst.H" /// diff --git a/Source/Diagnostics/ParticleIO.cpp b/Source/Diagnostics/ParticleIO.cpp index ced2d6b9a..be9809bac 100644 --- a/Source/Diagnostics/ParticleIO.cpp +++ b/Source/Diagnostics/ParticleIO.cpp @@ -1,5 +1,5 @@ -#include +#include #include using namespace amrex; diff --git a/Source/Laser/LaserParticleContainer.cpp b/Source/Laser/LaserParticleContainer.cpp index d5665e053..08d0ae861 100644 --- a/Source/Laser/LaserParticleContainer.cpp +++ b/Source/Laser/LaserParticleContainer.cpp @@ -7,7 +7,7 @@ #include #include #include -#include +#include using namespace amrex; diff --git a/Source/Particles/Make.package b/Source/Particles/Make.package index 93f7ca515..acbfe3390 100644 --- a/Source/Particles/Make.package +++ b/Source/Particles/Make.package @@ -2,10 +2,10 @@ F90EXE_sources += deposit_cic.F90 F90EXE_sources += interpolate_cic.F90 F90EXE_sources += push_particles_ES.F90 CEXE_sources += PhysicalParticleContainer.cpp -CEXE_sources += ParticleContainer.cpp +CEXE_sources += MultiParticleContainer.cpp CEXE_sources += WarpXParticleContainer.cpp CEXE_sources += RigidInjectedParticleContainer.cpp -CEXE_headers += ParticleContainer.H +CEXE_headers += MultiParticleContainer.H CEXE_headers += WarpXParticleContainer.H CEXE_headers += RigidInjectedParticleContainer.H CEXE_headers += PhysicalParticleContainer.H diff --git a/Source/Particles/MultiParticleContainer.H b/Source/Particles/MultiParticleContainer.H new file mode 100644 index 000000000..b21247ff6 --- /dev/null +++ b/Source/Particles/MultiParticleContainer.H @@ -0,0 +1,209 @@ + +#ifndef WARPX_ParticleContainer_H_ +#define WARPX_ParticleContainer_H_ + +#include +#include +#include + +#include + +#include +#include +#include +#include + +// +// MultiParticleContainer holds multiple (nspecies or npsecies+1 when +// using laser) WarpXParticleContainer. WarpXParticleContainer is +// derived from amrex::ParticleContainer, and it is +// polymorphic. PhysicalParticleContainer and LaserParticleContainer are +// concrete class dervied from WarpXParticlContainer. +// + +class MultiParticleContainer +{ + +public: + + MultiParticleContainer (amrex::AmrCore* amr_core); + + ~MultiParticleContainer() {} + + WarpXParticleContainer& GetParticleContainer (int ispecies) { + return *allcontainers[ispecies]; + } + + std::array meanParticleVelocity(int ispecies) { + return allcontainers[ispecies]->meanParticleVelocity(); + } + + void AllocData (); + + void InitData (); + +#ifdef WARPX_DO_ELECTROSTATIC + /// + /// Performs the field gather operation using the input field E, for all the species + /// in the MultiParticleContainer. This is the electrostatic version of the field gather. + /// + void FieldGatherES (const amrex::Vector, 3> >& E, + const amrex::Vector > > >& masks); + + /// + /// This evolves all the particles by one PIC time step, including charge deposition, the + /// field solve, and pushing the particles, for all the species in the MultiParticleContainer. + /// This is the electrostatic version. + /// + void EvolveES (const amrex::Vector, 3> >& E, + amrex::Vector >& rho, + amrex::Real t, amrex::Real dt); + + /// + /// This pushes the particle positions by one half time step for all the species in the + /// MultiParticleContainer. It is used to desynchronize the particles after initializaton + /// or when restarting from a checkpoint. This is the electrostatic version. + /// + void PushXES (amrex::Real dt); + + /// + /// This deposits the particle charge onto rho, accumulating the value for all the species + /// in the MultiParticleContainer. rho is assumed to contain node-centered multifabs. + /// This version is hard-coded for CIC deposition. + /// + void DepositCharge(amrex::Vector >& rho, bool local = false); + + /// + /// This returns the total particle charge for all the species in this MultiParticleContainer. + /// This is needed to subtract the offset for periodic boundary conditions. + /// + amrex::Real sumParticleCharge(bool local = false); +#endif // WARPX_DO_ELECTROSTATIC + + /// + /// Performs the field gather operation using the input fields E and B, for all the species + /// in the MultiParticleContainer. This is the electromagnetic version of the field gather. + /// + void FieldGather (int lev, + const amrex::MultiFab& Ex, const amrex::MultiFab& Ey, const amrex::MultiFab& Ez, + const amrex::MultiFab& Bx, const amrex::MultiFab& By, const amrex::MultiFab& Bz); + + /// + /// This evolves all the particles by one PIC time step, including current deposition, the + /// field solve, and pushing the particles, for all the species in the MultiParticleContainer. + /// This is the electromagnetic version. + /// + void Evolve (int lev, + const amrex::MultiFab& Ex, const amrex::MultiFab& Ey, const amrex::MultiFab& Ez, + const amrex::MultiFab& Bx, const amrex::MultiFab& By, const amrex::MultiFab& Bz, + amrex::MultiFab& jx, amrex::MultiFab& jy, amrex::MultiFab& jz, + amrex::MultiFab* cjx, amrex::MultiFab* cjy, amrex::MultiFab* cjz, + amrex::MultiFab* rho, amrex::MultiFab* crho, + const amrex::MultiFab* cEx, const amrex::MultiFab* cEy, const amrex::MultiFab* cEz, + const amrex::MultiFab* cBx, const amrex::MultiFab* cBy, const amrex::MultiFab* cBz, + amrex::Real t, amrex::Real dt); + + /// + /// This pushes the particle positions by one half time step for all the species in the + /// MultiParticleContainer. It is used to desynchronize the particles after initializaton + /// or when restarting from a checkpoint. This is the electromagnetic version. + /// + void PushX (amrex::Real dt); + + /// + /// This pushes the particle momenta by dt for all the species in the + /// MultiParticleContainer. It is used to desynchronize the particles after initializaton + /// or when restarting from a checkpoint. It is also used to synchronize particles at the + /// the end of the run. This is the electromagnetic version. + /// + void PushP (int lev, amrex::Real dt, + const amrex::MultiFab& Ex, const amrex::MultiFab& Ey, const amrex::MultiFab& Ez, + const amrex::MultiFab& Bx, const amrex::MultiFab& By, const amrex::MultiFab& Bz); + + /// + /// This deposits the particle charge onto a node-centered MultiFab and returns a unique ptr + /// to it. The charge density is accumulated over all the particles in the MultiParticleContainer + /// This version uses PICSAR routines to perform the deposition. + /// + std::unique_ptr GetChargeDensity(int lev, bool local = false); + + void Checkpoint (const std::string& dir, + bool is_checkpoint, + const amrex::Vector& varnames = amrex::Vector()) const; + + void Restart (const std::string& dir); + + void PostRestart (); + + void ReadHeader (std::istream& is); + + void WriteHeader (std::ostream& os) const; + + void SortParticlesByCell (); + + void Redistribute (); + + void RedistributeLocal (const int num_ghost); + + amrex::Vector NumberOfParticlesInGrid(int lev) const; + + void Increment (amrex::MultiFab& mf, int lev); + + void SetParticleBoxArray (int lev, amrex::BoxArray& new_ba); + void SetParticleDistributionMap (int lev, amrex::DistributionMapping& new_dm); + + int nSpecies() const {return nspecies;} + + int nSpeciesDepositOnMainGrid () const { + int r = 0; + for (int i : deposit_on_main_grid) { + if (i) ++r; + } + return r; + } + + void GetLabFrameData(const std::string& snapshot_name, + const int i_lab, const int direction, + const amrex::Real z_old, const amrex::Real z_new, + const amrex::Real t_boost, const amrex::Real t_lab, const amrex::Real dt, + amrex::Vector& parts) const; + + // + // Parameters for the Cherenkov corrector in the FDTD solver. + // Both stencils are calculated ar runtime. + // + // Number of coefficients for the stencil of the NCI corrector. + // The stencil is applied in the z direction only. + static constexpr int nstencilz_fdtd_nci_corr=5; + + amrex::Vector > fdtd_nci_stencilz_ex; + amrex::Vector > fdtd_nci_stencilz_by; + + std::vector GetSpeciesNames() const { return species_names; } + + PhysicalParticleContainer& GetPCtmp () { return *pc_tmp; } + +protected: + + // Particle container types + enum struct PCTypes {Physical, RigidInjected}; + + std::vector species_names; + + std::vector deposit_on_main_grid; + + std::vector species_types; + +private: + + // physical particles (+ laser) + amrex::Vector > allcontainers; + // Temporary particle container, used e.g. for particle splitting. + std::unique_ptr pc_tmp; + + void ReadParameters (); + + // runtime parameters + int nspecies = 1; // physical particles only. If WarpX::use_laser, nspecies+1 == allcontainers.size(). +}; +#endif /*WARPX_ParticleContainer_H_*/ diff --git a/Source/Particles/MultiParticleContainer.cpp b/Source/Particles/MultiParticleContainer.cpp new file mode 100644 index 000000000..1b644b543 --- /dev/null +++ b/Source/Particles/MultiParticleContainer.cpp @@ -0,0 +1,389 @@ +#include +#include +#include + +#include +#include +#include + +using namespace amrex; + +constexpr int MultiParticleContainer::nstencilz_fdtd_nci_corr; + +MultiParticleContainer::MultiParticleContainer (AmrCore* amr_core) +{ + ReadParameters(); + + int n = WarpX::use_laser ? nspecies+1 : nspecies; + allcontainers.resize(n); + for (int i = 0; i < nspecies; ++i) { + if (species_types[i] == PCTypes::Physical) { + allcontainers[i].reset(new PhysicalParticleContainer(amr_core, i, species_names[i])); + } + else if (species_types[i] == PCTypes::RigidInjected) { + allcontainers[i].reset(new RigidInjectedParticleContainer(amr_core, i, species_names[i])); + } + allcontainers[i]->deposit_on_main_grid = deposit_on_main_grid[i]; + } + if (WarpX::use_laser) { + allcontainers[n-1].reset(new LaserParticleContainer(amr_core,n-1)); + } + pc_tmp.reset(new PhysicalParticleContainer(amr_core)); +} + +void +MultiParticleContainer::ReadParameters () +{ + static bool initialized = false; + if (!initialized) + { + ParmParse pp("particles"); + + pp.query("nspecies", nspecies); + BL_ASSERT(nspecies >= 0); + + if (nspecies > 0) { + pp.getarr("species_names", species_names); + BL_ASSERT(species_names.size() == nspecies); + + deposit_on_main_grid.resize(nspecies, 0); + std::vector tmp; + pp.queryarr("deposit_on_main_grid", tmp); + for (auto const& name : tmp) { + auto it = std::find(species_names.begin(), species_names.end(), name); + AMREX_ALWAYS_ASSERT_WITH_MESSAGE(it != species_names.end(), "ERROR: species in particles.deposit_on_main_grid must be part of particles.species_names"); + int i = std::distance(species_names.begin(), it); + deposit_on_main_grid[i] = 1; + } + + species_types.resize(nspecies, PCTypes::Physical); + + std::vector rigid_injected_species; + pp.queryarr("rigid_injected_species", rigid_injected_species); + + if (!rigid_injected_species.empty()) { + for (auto const& name : rigid_injected_species) { + auto it = std::find(species_names.begin(), species_names.end(), name); + AMREX_ALWAYS_ASSERT_WITH_MESSAGE(it != species_names.end(), "ERROR: species in particles.rigid_injected_species must be part of particles.species_names"); + int i = std::distance(species_names.begin(), it); + species_types[i] = PCTypes::RigidInjected; + } + } + } + pp.query("use_fdtd_nci_corr", WarpX::use_fdtd_nci_corr); + pp.query("l_lower_order_in_v", WarpX::l_lower_order_in_v); + initialized = true; + } +} + +void +MultiParticleContainer::AllocData () +{ + for (auto& pc : allcontainers) { + pc->AllocData(); + } + pc_tmp->AllocData(); +} + +void +MultiParticleContainer::InitData () +{ + for (auto& pc : allcontainers) { + pc->InitData(); + } + pc_tmp->InitData(); +} + + +#ifdef WARPX_DO_ELECTROSTATIC +void +MultiParticleContainer::FieldGatherES (const Vector, 3> >& E, + const amrex::Vector > > >& masks) +{ + for (auto& pc : allcontainers) { + pc->FieldGatherES(E, masks); + } +} + +void +MultiParticleContainer::EvolveES (const Vector, 3> >& E, + Vector >& rho, + Real t, Real dt) +{ + + int nlevs = rho.size(); + int ng = rho[0]->nGrow(); + + for (unsigned i = 0; i < nlevs; i++) { + rho[i]->setVal(0.0, ng); + } + + for (auto& pc : allcontainers) { + pc->EvolveES(E, rho, t, dt); + } + + for (unsigned i = 0; i < nlevs; i++) { + const Geometry& gm = allcontainers[0]->Geom(i); + rho[i]->SumBoundary(gm.periodicity()); + } +} + +void +MultiParticleContainer::Evolve (int lev, + const MultiFab& Ex, const MultiFab& Ey, const MultiFab& Ez, + const MultiFab& Bx, const MultiFab& By, const MultiFab& Bz, + MultiFab& jx, MultiFab& jy, MultiFab& jz, + MultiFab* cjx, MultiFab* cjy, MultiFab* cjz, + MultiFab* rho, + const MultiFab* cEx, const MultiFab* cEy, const MultiFab* cEz, + const MultiFab* cBx, const MultiFab* cBy, const MultiFab* cBz, + Real t, Real dt) +{ + jx.setVal(0.0); + jy.setVal(0.0); + jz.setVal(0.0); + if (cjx) cjx->setVal(0.0); + if (cjy) cjy->setVal(0.0); + if (cjz) cjz->setVal(0.0); + if (rho) rho->setVal(0.0); + for (auto& pc : allcontainers) { + pc->Evolve(lev, Ex, Ey, Ez, Bx, By, Bz, jx, jy, jz, cjx, cjy, cjz, + rho, cEx, cEy, cEz, cBx, cBy, cBz, t, dt); + } +} + +void +MultiParticleContainer::PushXES (Real dt) +{ + for (auto& pc : allcontainers) { + pc->PushXES(dt); + } +} + +void +MultiParticleContainer:: +DepositCharge (Vector >& rho, bool local) +{ + int nlevs = rho.size(); + int ng = rho[0]->nGrow(); + + for (unsigned i = 0; i < nlevs; i++) { + rho[i]->setVal(0.0, ng); + } + + for (unsigned i = 0, n = allcontainers.size(); i < n; ++i) { + allcontainers[i]->DepositCharge(rho, true); + } + + if (!local) { + for (unsigned i = 0; i < nlevs; i++) { + const Geometry& gm = allcontainers[0]->Geom(i); + rho[i]->SumBoundary(gm.periodicity()); + } + } +} + +amrex::Real +MultiParticleContainer::sumParticleCharge (bool local) +{ + amrex::Real total_charge = allcontainers[0]->sumParticleCharge(local); + for (unsigned i = 1, n = allcontainers.size(); i < n; ++i) { + total_charge += allcontainers[i]->sumParticleCharge(local); + } + return total_charge; +} + +#endif // WARPX_DO_ELECTROSTATIC + +void +MultiParticleContainer::FieldGather (int lev, + const MultiFab& Ex, const MultiFab& Ey, const MultiFab& Ez, + const MultiFab& Bx, const MultiFab& By, const MultiFab& Bz) +{ + for (auto& pc : allcontainers) { + pc->FieldGather(lev, Ex, Ey, Ez, Bx, By, Bz); + } +} + +void +MultiParticleContainer::Evolve (int lev, + const MultiFab& Ex, const MultiFab& Ey, const MultiFab& Ez, + const MultiFab& Bx, const MultiFab& By, const MultiFab& Bz, + MultiFab& jx, MultiFab& jy, MultiFab& jz, + MultiFab* cjx, MultiFab* cjy, MultiFab* cjz, + MultiFab* rho, MultiFab* crho, + const MultiFab* cEx, const MultiFab* cEy, const MultiFab* cEz, + const MultiFab* cBx, const MultiFab* cBy, const MultiFab* cBz, + Real t, Real dt) +{ + jx.setVal(0.0); + jy.setVal(0.0); + jz.setVal(0.0); + if (cjx) cjx->setVal(0.0); + if (cjy) cjy->setVal(0.0); + if (cjz) cjz->setVal(0.0); + if (rho) rho->setVal(0.0); + if (crho) crho->setVal(0.0); + for (auto& pc : allcontainers) { + pc->Evolve(lev, Ex, Ey, Ez, Bx, By, Bz, jx, jy, jz, cjx, cjy, cjz, + rho, crho, cEx, cEy, cEz, cBx, cBy, cBz, t, dt); + } +} + +void +MultiParticleContainer::PushX (Real dt) +{ + for (auto& pc : allcontainers) { + pc->PushX(dt); + } +} + +void +MultiParticleContainer::PushP (int lev, Real dt, + const MultiFab& Ex, const MultiFab& Ey, const MultiFab& Ez, + const MultiFab& Bx, const MultiFab& By, const MultiFab& Bz) +{ + for (auto& pc : allcontainers) { + pc->PushP(lev, dt, Ex, Ey, Ez, Bx, By, Bz); + } +} + +std::unique_ptr +MultiParticleContainer::GetChargeDensity (int lev, bool local) +{ + std::unique_ptr rho = allcontainers[0]->GetChargeDensity(lev, true); + for (unsigned i = 1, n = allcontainers.size(); i < n; ++i) { + std::unique_ptr rhoi = allcontainers[i]->GetChargeDensity(lev, true); + MultiFab::Add(*rho, *rhoi, 0, 0, 1, rho->nGrow()); + } + if (!local) { + const Geometry& gm = allcontainers[0]->Geom(lev); + rho->SumBoundary(gm.periodicity()); + } + return rho; +} + +void +MultiParticleContainer::SortParticlesByCell () +{ + for (auto& pc : allcontainers) { + pc->SortParticlesByCell(); + } +} + +void +MultiParticleContainer::Redistribute () +{ + for (auto& pc : allcontainers) { + pc->Redistribute(); + } +} + +void +MultiParticleContainer::RedistributeLocal (const int num_ghost) +{ + for (auto& pc : allcontainers) { + pc->Redistribute(0, 0, 0, num_ghost); + } +} + +Vector +MultiParticleContainer::NumberOfParticlesInGrid(int lev) const +{ + const bool only_valid=true, only_local=true; + Vector r = allcontainers[0]->NumberOfParticlesInGrid(lev,only_valid,only_local); + for (unsigned i = 1, n = allcontainers.size(); i < n; ++i) { + const auto& ri = allcontainers[i]->NumberOfParticlesInGrid(lev,only_valid,only_local); + for (unsigned j=0, m=ri.size(); jIncrement(mf,lev); + } +} + +void +MultiParticleContainer::SetParticleBoxArray (int lev, BoxArray& new_ba) +{ + for (auto& pc : allcontainers) { + pc->SetParticleBoxArray(lev,new_ba); + } +} + +void +MultiParticleContainer::SetParticleDistributionMap (int lev, DistributionMapping& new_dm) +{ + for (auto& pc : allcontainers) { + pc->SetParticleDistributionMap(lev,new_dm); + } +} + +void +MultiParticleContainer::PostRestart () +{ + for (auto& pc : allcontainers) { + pc->PostRestart(); + } + pc_tmp->PostRestart(); +} + +void +MultiParticleContainer +::GetLabFrameData(const std::string& snapshot_name, + const int i_lab, const int direction, + const Real z_old, const Real z_new, + const Real t_boost, const Real t_lab, const Real dt, + Vector& parts) const +{ + + BL_PROFILE("MultiParticleContainer::GetLabFrameData"); + + for (int i = 0; i < nspecies; ++i) + { + WarpXParticleContainer* pc = allcontainers[i].get(); + WarpXParticleContainer::DiagnosticParticles diagnostic_particles; + pc->GetParticleSlice(direction, z_old, z_new, t_boost, t_lab, dt, diagnostic_particles); + + for (int lev = 0; lev <= pc->finestLevel(); ++lev) + { + for (auto it = diagnostic_particles[lev].begin(); it != diagnostic_particles[lev].end(); ++it) + { + parts[i].GetRealData(DiagIdx::w).insert( parts[i].GetRealData(DiagIdx::w ).end(), + it->second.GetRealData(DiagIdx::w ).begin(), + it->second.GetRealData(DiagIdx::w ).end()); + + parts[i].GetRealData(DiagIdx::x).insert( parts[i].GetRealData(DiagIdx::x ).end(), + it->second.GetRealData(DiagIdx::x ).begin(), + it->second.GetRealData(DiagIdx::x ).end()); + + parts[i].GetRealData(DiagIdx::y).insert( parts[i].GetRealData(DiagIdx::y ).end(), + it->second.GetRealData(DiagIdx::y ).begin(), + it->second.GetRealData(DiagIdx::y ).end()); + + parts[i].GetRealData(DiagIdx::z).insert( parts[i].GetRealData(DiagIdx::z ).end(), + it->second.GetRealData(DiagIdx::z ).begin(), + it->second.GetRealData(DiagIdx::z ).end()); + + parts[i].GetRealData(DiagIdx::ux).insert( parts[i].GetRealData(DiagIdx::ux).end(), + it->second.GetRealData(DiagIdx::ux).begin(), + it->second.GetRealData(DiagIdx::ux).end()); + + parts[i].GetRealData(DiagIdx::uy).insert( parts[i].GetRealData(DiagIdx::uy).end(), + it->second.GetRealData(DiagIdx::uy).begin(), + it->second.GetRealData(DiagIdx::uy).end()); + + parts[i].GetRealData(DiagIdx::uz).insert( parts[i].GetRealData(DiagIdx::uz).end(), + it->second.GetRealData(DiagIdx::uz).begin(), + it->second.GetRealData(DiagIdx::uz).end()); + } + } + } +} diff --git a/Source/Particles/ParticleContainer.H b/Source/Particles/ParticleContainer.H deleted file mode 100644 index b21247ff6..000000000 --- a/Source/Particles/ParticleContainer.H +++ /dev/null @@ -1,209 +0,0 @@ - -#ifndef WARPX_ParticleContainer_H_ -#define WARPX_ParticleContainer_H_ - -#include -#include -#include - -#include - -#include -#include -#include -#include - -// -// MultiParticleContainer holds multiple (nspecies or npsecies+1 when -// using laser) WarpXParticleContainer. WarpXParticleContainer is -// derived from amrex::ParticleContainer, and it is -// polymorphic. PhysicalParticleContainer and LaserParticleContainer are -// concrete class dervied from WarpXParticlContainer. -// - -class MultiParticleContainer -{ - -public: - - MultiParticleContainer (amrex::AmrCore* amr_core); - - ~MultiParticleContainer() {} - - WarpXParticleContainer& GetParticleContainer (int ispecies) { - return *allcontainers[ispecies]; - } - - std::array meanParticleVelocity(int ispecies) { - return allcontainers[ispecies]->meanParticleVelocity(); - } - - void AllocData (); - - void InitData (); - -#ifdef WARPX_DO_ELECTROSTATIC - /// - /// Performs the field gather operation using the input field E, for all the species - /// in the MultiParticleContainer. This is the electrostatic version of the field gather. - /// - void FieldGatherES (const amrex::Vector, 3> >& E, - const amrex::Vector > > >& masks); - - /// - /// This evolves all the particles by one PIC time step, including charge deposition, the - /// field solve, and pushing the particles, for all the species in the MultiParticleContainer. - /// This is the electrostatic version. - /// - void EvolveES (const amrex::Vector, 3> >& E, - amrex::Vector >& rho, - amrex::Real t, amrex::Real dt); - - /// - /// This pushes the particle positions by one half time step for all the species in the - /// MultiParticleContainer. It is used to desynchronize the particles after initializaton - /// or when restarting from a checkpoint. This is the electrostatic version. - /// - void PushXES (amrex::Real dt); - - /// - /// This deposits the particle charge onto rho, accumulating the value for all the species - /// in the MultiParticleContainer. rho is assumed to contain node-centered multifabs. - /// This version is hard-coded for CIC deposition. - /// - void DepositCharge(amrex::Vector >& rho, bool local = false); - - /// - /// This returns the total particle charge for all the species in this MultiParticleContainer. - /// This is needed to subtract the offset for periodic boundary conditions. - /// - amrex::Real sumParticleCharge(bool local = false); -#endif // WARPX_DO_ELECTROSTATIC - - /// - /// Performs the field gather operation using the input fields E and B, for all the species - /// in the MultiParticleContainer. This is the electromagnetic version of the field gather. - /// - void FieldGather (int lev, - const amrex::MultiFab& Ex, const amrex::MultiFab& Ey, const amrex::MultiFab& Ez, - const amrex::MultiFab& Bx, const amrex::MultiFab& By, const amrex::MultiFab& Bz); - - /// - /// This evolves all the particles by one PIC time step, including current deposition, the - /// field solve, and pushing the particles, for all the species in the MultiParticleContainer. - /// This is the electromagnetic version. - /// - void Evolve (int lev, - const amrex::MultiFab& Ex, const amrex::MultiFab& Ey, const amrex::MultiFab& Ez, - const amrex::MultiFab& Bx, const amrex::MultiFab& By, const amrex::MultiFab& Bz, - amrex::MultiFab& jx, amrex::MultiFab& jy, amrex::MultiFab& jz, - amrex::MultiFab* cjx, amrex::MultiFab* cjy, amrex::MultiFab* cjz, - amrex::MultiFab* rho, amrex::MultiFab* crho, - const amrex::MultiFab* cEx, const amrex::MultiFab* cEy, const amrex::MultiFab* cEz, - const amrex::MultiFab* cBx, const amrex::MultiFab* cBy, const amrex::MultiFab* cBz, - amrex::Real t, amrex::Real dt); - - /// - /// This pushes the particle positions by one half time step for all the species in the - /// MultiParticleContainer. It is used to desynchronize the particles after initializaton - /// or when restarting from a checkpoint. This is the electromagnetic version. - /// - void PushX (amrex::Real dt); - - /// - /// This pushes the particle momenta by dt for all the species in the - /// MultiParticleContainer. It is used to desynchronize the particles after initializaton - /// or when restarting from a checkpoint. It is also used to synchronize particles at the - /// the end of the run. This is the electromagnetic version. - /// - void PushP (int lev, amrex::Real dt, - const amrex::MultiFab& Ex, const amrex::MultiFab& Ey, const amrex::MultiFab& Ez, - const amrex::MultiFab& Bx, const amrex::MultiFab& By, const amrex::MultiFab& Bz); - - /// - /// This deposits the particle charge onto a node-centered MultiFab and returns a unique ptr - /// to it. The charge density is accumulated over all the particles in the MultiParticleContainer - /// This version uses PICSAR routines to perform the deposition. - /// - std::unique_ptr GetChargeDensity(int lev, bool local = false); - - void Checkpoint (const std::string& dir, - bool is_checkpoint, - const amrex::Vector& varnames = amrex::Vector()) const; - - void Restart (const std::string& dir); - - void PostRestart (); - - void ReadHeader (std::istream& is); - - void WriteHeader (std::ostream& os) const; - - void SortParticlesByCell (); - - void Redistribute (); - - void RedistributeLocal (const int num_ghost); - - amrex::Vector NumberOfParticlesInGrid(int lev) const; - - void Increment (amrex::MultiFab& mf, int lev); - - void SetParticleBoxArray (int lev, amrex::BoxArray& new_ba); - void SetParticleDistributionMap (int lev, amrex::DistributionMapping& new_dm); - - int nSpecies() const {return nspecies;} - - int nSpeciesDepositOnMainGrid () const { - int r = 0; - for (int i : deposit_on_main_grid) { - if (i) ++r; - } - return r; - } - - void GetLabFrameData(const std::string& snapshot_name, - const int i_lab, const int direction, - const amrex::Real z_old, const amrex::Real z_new, - const amrex::Real t_boost, const amrex::Real t_lab, const amrex::Real dt, - amrex::Vector& parts) const; - - // - // Parameters for the Cherenkov corrector in the FDTD solver. - // Both stencils are calculated ar runtime. - // - // Number of coefficients for the stencil of the NCI corrector. - // The stencil is applied in the z direction only. - static constexpr int nstencilz_fdtd_nci_corr=5; - - amrex::Vector > fdtd_nci_stencilz_ex; - amrex::Vector > fdtd_nci_stencilz_by; - - std::vector GetSpeciesNames() const { return species_names; } - - PhysicalParticleContainer& GetPCtmp () { return *pc_tmp; } - -protected: - - // Particle container types - enum struct PCTypes {Physical, RigidInjected}; - - std::vector species_names; - - std::vector deposit_on_main_grid; - - std::vector species_types; - -private: - - // physical particles (+ laser) - amrex::Vector > allcontainers; - // Temporary particle container, used e.g. for particle splitting. - std::unique_ptr pc_tmp; - - void ReadParameters (); - - // runtime parameters - int nspecies = 1; // physical particles only. If WarpX::use_laser, nspecies+1 == allcontainers.size(). -}; -#endif /*WARPX_ParticleContainer_H_*/ diff --git a/Source/Particles/ParticleContainer.cpp b/Source/Particles/ParticleContainer.cpp deleted file mode 100644 index 8a46dd835..000000000 --- a/Source/Particles/ParticleContainer.cpp +++ /dev/null @@ -1,389 +0,0 @@ -#include -#include -#include - -#include -#include -#include - -using namespace amrex; - -constexpr int MultiParticleContainer::nstencilz_fdtd_nci_corr; - -MultiParticleContainer::MultiParticleContainer (AmrCore* amr_core) -{ - ReadParameters(); - - int n = WarpX::use_laser ? nspecies+1 : nspecies; - allcontainers.resize(n); - for (int i = 0; i < nspecies; ++i) { - if (species_types[i] == PCTypes::Physical) { - allcontainers[i].reset(new PhysicalParticleContainer(amr_core, i, species_names[i])); - } - else if (species_types[i] == PCTypes::RigidInjected) { - allcontainers[i].reset(new RigidInjectedParticleContainer(amr_core, i, species_names[i])); - } - allcontainers[i]->deposit_on_main_grid = deposit_on_main_grid[i]; - } - if (WarpX::use_laser) { - allcontainers[n-1].reset(new LaserParticleContainer(amr_core,n-1)); - } - pc_tmp.reset(new PhysicalParticleContainer(amr_core)); -} - -void -MultiParticleContainer::ReadParameters () -{ - static bool initialized = false; - if (!initialized) - { - ParmParse pp("particles"); - - pp.query("nspecies", nspecies); - BL_ASSERT(nspecies >= 0); - - if (nspecies > 0) { - pp.getarr("species_names", species_names); - BL_ASSERT(species_names.size() == nspecies); - - deposit_on_main_grid.resize(nspecies, 0); - std::vector tmp; - pp.queryarr("deposit_on_main_grid", tmp); - for (auto const& name : tmp) { - auto it = std::find(species_names.begin(), species_names.end(), name); - AMREX_ALWAYS_ASSERT_WITH_MESSAGE(it != species_names.end(), "ERROR: species in particles.deposit_on_main_grid must be part of particles.species_names"); - int i = std::distance(species_names.begin(), it); - deposit_on_main_grid[i] = 1; - } - - species_types.resize(nspecies, PCTypes::Physical); - - std::vector rigid_injected_species; - pp.queryarr("rigid_injected_species", rigid_injected_species); - - if (!rigid_injected_species.empty()) { - for (auto const& name : rigid_injected_species) { - auto it = std::find(species_names.begin(), species_names.end(), name); - AMREX_ALWAYS_ASSERT_WITH_MESSAGE(it != species_names.end(), "ERROR: species in particles.rigid_injected_species must be part of particles.species_names"); - int i = std::distance(species_names.begin(), it); - species_types[i] = PCTypes::RigidInjected; - } - } - } - pp.query("use_fdtd_nci_corr", WarpX::use_fdtd_nci_corr); - pp.query("l_lower_order_in_v", WarpX::l_lower_order_in_v); - initialized = true; - } -} - -void -MultiParticleContainer::AllocData () -{ - for (auto& pc : allcontainers) { - pc->AllocData(); - } - pc_tmp->AllocData(); -} - -void -MultiParticleContainer::InitData () -{ - for (auto& pc : allcontainers) { - pc->InitData(); - } - pc_tmp->InitData(); -} - - -#ifdef WARPX_DO_ELECTROSTATIC -void -MultiParticleContainer::FieldGatherES (const Vector, 3> >& E, - const amrex::Vector > > >& masks) -{ - for (auto& pc : allcontainers) { - pc->FieldGatherES(E, masks); - } -} - -void -MultiParticleContainer::EvolveES (const Vector, 3> >& E, - Vector >& rho, - Real t, Real dt) -{ - - int nlevs = rho.size(); - int ng = rho[0]->nGrow(); - - for (unsigned i = 0; i < nlevs; i++) { - rho[i]->setVal(0.0, ng); - } - - for (auto& pc : allcontainers) { - pc->EvolveES(E, rho, t, dt); - } - - for (unsigned i = 0; i < nlevs; i++) { - const Geometry& gm = allcontainers[0]->Geom(i); - rho[i]->SumBoundary(gm.periodicity()); - } -} - -void -MultiParticleContainer::Evolve (int lev, - const MultiFab& Ex, const MultiFab& Ey, const MultiFab& Ez, - const MultiFab& Bx, const MultiFab& By, const MultiFab& Bz, - MultiFab& jx, MultiFab& jy, MultiFab& jz, - MultiFab* cjx, MultiFab* cjy, MultiFab* cjz, - MultiFab* rho, - const MultiFab* cEx, const MultiFab* cEy, const MultiFab* cEz, - const MultiFab* cBx, const MultiFab* cBy, const MultiFab* cBz, - Real t, Real dt) -{ - jx.setVal(0.0); - jy.setVal(0.0); - jz.setVal(0.0); - if (cjx) cjx->setVal(0.0); - if (cjy) cjy->setVal(0.0); - if (cjz) cjz->setVal(0.0); - if (rho) rho->setVal(0.0); - for (auto& pc : allcontainers) { - pc->Evolve(lev, Ex, Ey, Ez, Bx, By, Bz, jx, jy, jz, cjx, cjy, cjz, - rho, cEx, cEy, cEz, cBx, cBy, cBz, t, dt); - } -} - -void -MultiParticleContainer::PushXES (Real dt) -{ - for (auto& pc : allcontainers) { - pc->PushXES(dt); - } -} - -void -MultiParticleContainer:: -DepositCharge (Vector >& rho, bool local) -{ - int nlevs = rho.size(); - int ng = rho[0]->nGrow(); - - for (unsigned i = 0; i < nlevs; i++) { - rho[i]->setVal(0.0, ng); - } - - for (unsigned i = 0, n = allcontainers.size(); i < n; ++i) { - allcontainers[i]->DepositCharge(rho, true); - } - - if (!local) { - for (unsigned i = 0; i < nlevs; i++) { - const Geometry& gm = allcontainers[0]->Geom(i); - rho[i]->SumBoundary(gm.periodicity()); - } - } -} - -amrex::Real -MultiParticleContainer::sumParticleCharge (bool local) -{ - amrex::Real total_charge = allcontainers[0]->sumParticleCharge(local); - for (unsigned i = 1, n = allcontainers.size(); i < n; ++i) { - total_charge += allcontainers[i]->sumParticleCharge(local); - } - return total_charge; -} - -#endif // WARPX_DO_ELECTROSTATIC - -void -MultiParticleContainer::FieldGather (int lev, - const MultiFab& Ex, const MultiFab& Ey, const MultiFab& Ez, - const MultiFab& Bx, const MultiFab& By, const MultiFab& Bz) -{ - for (auto& pc : allcontainers) { - pc->FieldGather(lev, Ex, Ey, Ez, Bx, By, Bz); - } -} - -void -MultiParticleContainer::Evolve (int lev, - const MultiFab& Ex, const MultiFab& Ey, const MultiFab& Ez, - const MultiFab& Bx, const MultiFab& By, const MultiFab& Bz, - MultiFab& jx, MultiFab& jy, MultiFab& jz, - MultiFab* cjx, MultiFab* cjy, MultiFab* cjz, - MultiFab* rho, MultiFab* crho, - const MultiFab* cEx, const MultiFab* cEy, const MultiFab* cEz, - const MultiFab* cBx, const MultiFab* cBy, const MultiFab* cBz, - Real t, Real dt) -{ - jx.setVal(0.0); - jy.setVal(0.0); - jz.setVal(0.0); - if (cjx) cjx->setVal(0.0); - if (cjy) cjy->setVal(0.0); - if (cjz) cjz->setVal(0.0); - if (rho) rho->setVal(0.0); - if (crho) crho->setVal(0.0); - for (auto& pc : allcontainers) { - pc->Evolve(lev, Ex, Ey, Ez, Bx, By, Bz, jx, jy, jz, cjx, cjy, cjz, - rho, crho, cEx, cEy, cEz, cBx, cBy, cBz, t, dt); - } -} - -void -MultiParticleContainer::PushX (Real dt) -{ - for (auto& pc : allcontainers) { - pc->PushX(dt); - } -} - -void -MultiParticleContainer::PushP (int lev, Real dt, - const MultiFab& Ex, const MultiFab& Ey, const MultiFab& Ez, - const MultiFab& Bx, const MultiFab& By, const MultiFab& Bz) -{ - for (auto& pc : allcontainers) { - pc->PushP(lev, dt, Ex, Ey, Ez, Bx, By, Bz); - } -} - -std::unique_ptr -MultiParticleContainer::GetChargeDensity (int lev, bool local) -{ - std::unique_ptr rho = allcontainers[0]->GetChargeDensity(lev, true); - for (unsigned i = 1, n = allcontainers.size(); i < n; ++i) { - std::unique_ptr rhoi = allcontainers[i]->GetChargeDensity(lev, true); - MultiFab::Add(*rho, *rhoi, 0, 0, 1, rho->nGrow()); - } - if (!local) { - const Geometry& gm = allcontainers[0]->Geom(lev); - rho->SumBoundary(gm.periodicity()); - } - return rho; -} - -void -MultiParticleContainer::SortParticlesByCell () -{ - for (auto& pc : allcontainers) { - pc->SortParticlesByCell(); - } -} - -void -MultiParticleContainer::Redistribute () -{ - for (auto& pc : allcontainers) { - pc->Redistribute(); - } -} - -void -MultiParticleContainer::RedistributeLocal (const int num_ghost) -{ - for (auto& pc : allcontainers) { - pc->Redistribute(0, 0, 0, num_ghost); - } -} - -Vector -MultiParticleContainer::NumberOfParticlesInGrid(int lev) const -{ - const bool only_valid=true, only_local=true; - Vector r = allcontainers[0]->NumberOfParticlesInGrid(lev,only_valid,only_local); - for (unsigned i = 1, n = allcontainers.size(); i < n; ++i) { - const auto& ri = allcontainers[i]->NumberOfParticlesInGrid(lev,only_valid,only_local); - for (unsigned j=0, m=ri.size(); jIncrement(mf,lev); - } -} - -void -MultiParticleContainer::SetParticleBoxArray (int lev, BoxArray& new_ba) -{ - for (auto& pc : allcontainers) { - pc->SetParticleBoxArray(lev,new_ba); - } -} - -void -MultiParticleContainer::SetParticleDistributionMap (int lev, DistributionMapping& new_dm) -{ - for (auto& pc : allcontainers) { - pc->SetParticleDistributionMap(lev,new_dm); - } -} - -void -MultiParticleContainer::PostRestart () -{ - for (auto& pc : allcontainers) { - pc->PostRestart(); - } - pc_tmp->PostRestart(); -} - -void -MultiParticleContainer -::GetLabFrameData(const std::string& snapshot_name, - const int i_lab, const int direction, - const Real z_old, const Real z_new, - const Real t_boost, const Real t_lab, const Real dt, - Vector& parts) const -{ - - BL_PROFILE("MultiParticleContainer::GetLabFrameData"); - - for (int i = 0; i < nspecies; ++i) - { - WarpXParticleContainer* pc = allcontainers[i].get(); - WarpXParticleContainer::DiagnosticParticles diagnostic_particles; - pc->GetParticleSlice(direction, z_old, z_new, t_boost, t_lab, dt, diagnostic_particles); - - for (int lev = 0; lev <= pc->finestLevel(); ++lev) - { - for (auto it = diagnostic_particles[lev].begin(); it != diagnostic_particles[lev].end(); ++it) - { - parts[i].GetRealData(DiagIdx::w).insert( parts[i].GetRealData(DiagIdx::w ).end(), - it->second.GetRealData(DiagIdx::w ).begin(), - it->second.GetRealData(DiagIdx::w ).end()); - - parts[i].GetRealData(DiagIdx::x).insert( parts[i].GetRealData(DiagIdx::x ).end(), - it->second.GetRealData(DiagIdx::x ).begin(), - it->second.GetRealData(DiagIdx::x ).end()); - - parts[i].GetRealData(DiagIdx::y).insert( parts[i].GetRealData(DiagIdx::y ).end(), - it->second.GetRealData(DiagIdx::y ).begin(), - it->second.GetRealData(DiagIdx::y ).end()); - - parts[i].GetRealData(DiagIdx::z).insert( parts[i].GetRealData(DiagIdx::z ).end(), - it->second.GetRealData(DiagIdx::z ).begin(), - it->second.GetRealData(DiagIdx::z ).end()); - - parts[i].GetRealData(DiagIdx::ux).insert( parts[i].GetRealData(DiagIdx::ux).end(), - it->second.GetRealData(DiagIdx::ux).begin(), - it->second.GetRealData(DiagIdx::ux).end()); - - parts[i].GetRealData(DiagIdx::uy).insert( parts[i].GetRealData(DiagIdx::uy).end(), - it->second.GetRealData(DiagIdx::uy).begin(), - it->second.GetRealData(DiagIdx::uy).end()); - - parts[i].GetRealData(DiagIdx::uz).insert( parts[i].GetRealData(DiagIdx::uz).end(), - it->second.GetRealData(DiagIdx::uz).begin(), - it->second.GetRealData(DiagIdx::uz).end()); - } - } - } -} diff --git a/Source/Particles/PhysicalParticleContainer.cpp b/Source/Particles/PhysicalParticleContainer.cpp index 9cfd30862..afc1412d5 100644 --- a/Source/Particles/PhysicalParticleContainer.cpp +++ b/Source/Particles/PhysicalParticleContainer.cpp @@ -1,7 +1,7 @@ #include #include -#include +#include #include #include #include diff --git a/Source/Particles/WarpXParticleContainer.cpp b/Source/Particles/WarpXParticleContainer.cpp index ca7d18d19..ad80f7c4f 100644 --- a/Source/Particles/WarpXParticleContainer.cpp +++ b/Source/Particles/WarpXParticleContainer.cpp @@ -1,7 +1,7 @@ #include -#include +#include #include #include #include diff --git a/Source/Python/Make.package b/Source/Python/Make.package index c79049f02..71bd4ebe8 100644 --- a/Source/Python/Make.package +++ b/Source/Python/Make.package @@ -2,8 +2,9 @@ ifeq ($(USE_PYTHON_MAIN),TRUE) CEXE_sources += WarpXWrappers.cpp CEXE_headers += WarpXWrappers.h endif - +CEXE_sources += WarpXWrappers.cpp CEXE_sources += WarpX_py.cpp +CEXE_headers += WarpXWrappers.h CEXE_headers += WarpX_py.H INCLUDE_LOCATIONS += $(WARPX_HOME)/Source/Python diff --git a/Source/Python/WarpXWrappers.cpp b/Source/Python/WarpXWrappers.cpp new file mode 100644 index 000000000..6ee06a7d5 --- /dev/null +++ b/Source/Python/WarpXWrappers.cpp @@ -0,0 +1,446 @@ + +#include +#include + +#include +#include +#include +#include + +namespace +{ + double** getMultiFabPointers(const amrex::MultiFab& mf, int *num_boxes, int *ngrow, int **shapes) + { + *ngrow = mf.nGrow(); + *num_boxes = mf.local_size(); + *shapes = (int*) malloc(AMREX_SPACEDIM * (*num_boxes) * sizeof(int)); + double** data = (double**) malloc((*num_boxes) * sizeof(double*)); + + int i = 0; +#ifdef _OPENMP +#pragma omp parallel +#endif + for ( amrex::MFIter mfi(mf, false); mfi.isValid(); ++mfi, ++i ) { + data[i] = (double*) mf[mfi].dataPtr(); + for (int j = 0; j < AMREX_SPACEDIM; ++j) { + (*shapes)[AMREX_SPACEDIM*i+j] = mf[mfi].box().length(j); + } + } + return data; + } + int* getMultiFabLoVects(const amrex::MultiFab& mf, int *num_boxes, int *ngrow) + { + *ngrow = mf.nGrow(); + *num_boxes = mf.local_size(); + int *loVects = (int*) malloc((*num_boxes)*AMREX_SPACEDIM * sizeof(int)); + + int i = 0; + for ( amrex::MFIter mfi(mf, false); mfi.isValid(); ++mfi, ++i ) { + const int* loVect = mf[mfi].loVect(); + for (int j = 0; j < AMREX_SPACEDIM; ++j) { + loVects[AMREX_SPACEDIM*i+j] = loVect[j]; + } + } + return loVects; + } +} + +extern "C" +{ + + int warpx_nSpecies() + { + auto & mypc = WarpX::GetInstance().GetPartContainer(); + return mypc.nSpecies(); + } + + bool warpx_use_fdtd_nci_corr() + { + return WarpX::use_fdtd_nci_corr; + } + + int warpx_l_lower_order_in_v() + { + return WarpX::l_lower_order_in_v; + } + + int warpx_nComps() + { + return PIdx::nattribs; + } + + int warpx_SpaceDim() + { + return AMREX_SPACEDIM; + } + + void amrex_init (int argc, char* argv[]) + { + amrex::Initialize(argc,argv); + } + +#ifdef BL_USE_MPI + void amrex_init_with_inited_mpi (int argc, char* argv[], MPI_Comm mpicomm) + { + amrex::Initialize(argc,argv,true,mpicomm); + } +#endif + + void amrex_finalize (int finalize_mpi) + { + amrex::Finalize(finalize_mpi); + } + + void warpx_init () + { + WarpX& warpx = WarpX::GetInstance(); + warpx.InitData(); + if (warpx_py_afterinit) warpx_py_afterinit(); + if (warpx_py_particleloader) warpx_py_particleloader(); + } + + void warpx_finalize () + { + WarpX::ResetInstance(); + } + + void warpx_set_callback_py_afterinit (WARPX_CALLBACK_PY_FUNC_0 callback) + { + warpx_py_afterinit = callback; + } + void warpx_set_callback_py_beforeEsolve (WARPX_CALLBACK_PY_FUNC_0 callback) + { + warpx_py_beforeEsolve = callback; + } + void warpx_set_callback_py_afterEsolve (WARPX_CALLBACK_PY_FUNC_0 callback) + { + warpx_py_afterEsolve = callback; + } + void warpx_set_callback_py_beforedeposition (WARPX_CALLBACK_PY_FUNC_0 callback) + { + warpx_py_beforedeposition = callback; + } + void warpx_set_callback_py_afterdeposition (WARPX_CALLBACK_PY_FUNC_0 callback) + { + warpx_py_afterdeposition = callback; + } + void warpx_set_callback_py_particlescraper (WARPX_CALLBACK_PY_FUNC_0 callback) + { + warpx_py_particlescraper = callback; + } + void warpx_set_callback_py_particleloader (WARPX_CALLBACK_PY_FUNC_0 callback) + { + warpx_py_particleloader = callback; + } + void warpx_set_callback_py_beforestep (WARPX_CALLBACK_PY_FUNC_0 callback) + { + warpx_py_beforestep = callback; + } + void warpx_set_callback_py_afterstep (WARPX_CALLBACK_PY_FUNC_0 callback) + { + warpx_py_afterstep = callback; + } + void warpx_set_callback_py_afterrestart (WARPX_CALLBACK_PY_FUNC_0 callback) + { + warpx_py_afterrestart = callback; + } + void warpx_set_callback_py_particleinjection (WARPX_CALLBACK_PY_FUNC_0 callback) + { + warpx_py_particleinjection = callback; + } + void warpx_set_callback_py_appliedfields (WARPX_CALLBACK_PY_FUNC_0 callback) + { + warpx_py_appliedfields = callback; + } + + void warpx_evolve (int numsteps) + { + WarpX& warpx = WarpX::GetInstance(); + warpx.Evolve(numsteps); + } + + void warpx_addNParticles(int speciesnumber, int lenx, + double* x, double* y, double* z, + double* vx, double* vy, double* vz, + int nattr, double* attr, int uniqueparticles) + { + auto & mypc = WarpX::GetInstance().GetPartContainer(); + auto & myspc = mypc.GetParticleContainer(speciesnumber); + const int lev = 0; + myspc.AddNParticles(lev, lenx, x, y, z, vx, vy, vz, nattr, attr, uniqueparticles); + } + + double warpx_getProbLo(int dir) + { + WarpX& warpx = WarpX::GetInstance(); + const amrex::Geometry& geom = warpx.Geom(0); + return geom.ProbLo(dir); + } + + double warpx_getProbHi(int dir) + { + WarpX& warpx = WarpX::GetInstance(); + const amrex::Geometry& geom = warpx.Geom(0); + return geom.ProbHi(dir); + } + + long warpx_getNumParticles(int speciesnumber) { + auto & mypc = WarpX::GetInstance().GetPartContainer(); + auto & myspc = mypc.GetParticleContainer(speciesnumber); + return myspc.TotalNumberOfParticles(); + } + + double** warpx_getEfield(int lev, int direction, + int *return_size, int *ngrow, int **shapes) { + auto & mf = WarpX::GetInstance().getEfield(lev, direction); + return getMultiFabPointers(mf, return_size, ngrow, shapes); + } + + int* warpx_getEfieldLoVects(int lev, int direction, + int *return_size, int *ngrow) { + auto & mf = WarpX::GetInstance().getEfield(lev, direction); + return getMultiFabLoVects(mf, return_size, ngrow); + } + + double** warpx_getEfieldCP(int lev, int direction, + int *return_size, int *ngrow, int **shapes) { + auto & mf = WarpX::GetInstance().getEfield_cp(lev, direction); + return getMultiFabPointers(mf, return_size, ngrow, shapes); + } + + int* warpx_getEfieldCPLoVects(int lev, int direction, + int *return_size, int *ngrow) { + auto & mf = WarpX::GetInstance().getEfield_cp(lev, direction); + return getMultiFabLoVects(mf, return_size, ngrow); + } + + double** warpx_getEfieldFP(int lev, int direction, + int *return_size, int *ngrow, int **shapes) { + auto & mf = WarpX::GetInstance().getEfield_fp(lev, direction); + return getMultiFabPointers(mf, return_size, ngrow, shapes); + } + + int* warpx_getEfieldFPLoVects(int lev, int direction, + int *return_size, int *ngrow) { + auto & mf = WarpX::GetInstance().getEfield_fp(lev, direction); + return getMultiFabLoVects(mf, return_size, ngrow); + } + + double** warpx_getBfield(int lev, int direction, + int *return_size, int *ngrow, int **shapes) { + auto & mf = WarpX::GetInstance().getBfield(lev, direction); + return getMultiFabPointers(mf, return_size, ngrow, shapes); + } + + int* warpx_getBfieldLoVects(int lev, int direction, + int *return_size, int *ngrow) { + auto & mf = WarpX::GetInstance().getBfield(lev, direction); + return getMultiFabLoVects(mf, return_size, ngrow); + } + + double** warpx_getBfieldCP(int lev, int direction, + int *return_size, int *ngrow, int **shapes) { + auto & mf = WarpX::GetInstance().getBfield_cp(lev, direction); + return getMultiFabPointers(mf, return_size, ngrow, shapes); + } + + int* warpx_getBfieldCPLoVects(int lev, int direction, + int *return_size, int *ngrow) { + auto & mf = WarpX::GetInstance().getBfield_cp(lev, direction); + return getMultiFabLoVects(mf, return_size, ngrow); + } + + double** warpx_getBfieldFP(int lev, int direction, + int *return_size, int *ngrow, int **shapes) { + auto & mf = WarpX::GetInstance().getBfield_fp(lev, direction); + return getMultiFabPointers(mf, return_size, ngrow, shapes); + } + + int* warpx_getBfieldFPLoVects(int lev, int direction, + int *return_size, int *ngrow) { + auto & mf = WarpX::GetInstance().getBfield_fp(lev, direction); + return getMultiFabLoVects(mf, return_size, ngrow); + } + + double** warpx_getCurrentDensity(int lev, int direction, + int *return_size, int *ngrow, int **shapes) { + auto & mf = WarpX::GetInstance().getcurrent(lev, direction); + return getMultiFabPointers(mf, return_size, ngrow, shapes); + } + + int* warpx_getCurrentDensityLoVects(int lev, int direction, + int *return_size, int *ngrow) { + auto & mf = WarpX::GetInstance().getcurrent(lev, direction); + return getMultiFabLoVects(mf, return_size, ngrow); + } + + double** warpx_getCurrentDensityCP(int lev, int direction, + int *return_size, int *ngrow, int **shapes) { + auto & mf = WarpX::GetInstance().getcurrent_cp(lev, direction); + return getMultiFabPointers(mf, return_size, ngrow, shapes); + } + + int* warpx_getCurrentDensityCPLoVects(int lev, int direction, + int *return_size, int *ngrow) { + auto & mf = WarpX::GetInstance().getcurrent_cp(lev, direction); + return getMultiFabLoVects(mf, return_size, ngrow); + } + + double** warpx_getCurrentDensityFP(int lev, int direction, + int *return_size, int *ngrow, int **shapes) { + auto & mf = WarpX::GetInstance().getcurrent_fp(lev, direction); + return getMultiFabPointers(mf, return_size, ngrow, shapes); + } + + int* warpx_getCurrentDensityFPLoVects(int lev, int direction, + int *return_size, int *ngrow) { + auto & mf = WarpX::GetInstance().getcurrent_fp(lev, direction); + return getMultiFabLoVects(mf, return_size, ngrow); + } + + double** warpx_getParticleStructs(int speciesnumber, + int* num_tiles, int** particles_per_tile) { + auto & mypc = WarpX::GetInstance().GetPartContainer(); + auto & myspc = mypc.GetParticleContainer(speciesnumber); + + const int level = 0; + + int i = 0; + for (WarpXParIter pti(myspc, level); pti.isValid(); ++pti, ++i) {} + + // *num_tiles = myspc.numLocalTilesAtLevel(level); + *num_tiles = i; + *particles_per_tile = (int*) malloc(*num_tiles*sizeof(int)); + + double** data = (double**) malloc(*num_tiles*sizeof(typename WarpXParticleContainer::ParticleType*)); + i = 0; + for (WarpXParIter pti(myspc, level); pti.isValid(); ++pti, ++i) { + auto& aos = pti.GetArrayOfStructs(); + data[i] = (double*) aos.data(); + (*particles_per_tile)[i] = pti.numParticles(); + } + return data; + } + + double** warpx_getParticleArrays(int speciesnumber, int comp, + int* num_tiles, int** particles_per_tile) { + auto & mypc = WarpX::GetInstance().GetPartContainer(); + auto & myspc = mypc.GetParticleContainer(speciesnumber); + + const int level = 0; + + int i = 0; + for (WarpXParIter pti(myspc, level); pti.isValid(); ++pti, ++i) {} + + // *num_tiles = myspc.numLocalTilesAtLevel(level); + *num_tiles = i; + *particles_per_tile = (int*) malloc(*num_tiles*sizeof(int)); + + double** data = (double**) malloc(*num_tiles*sizeof(double*)); + i = 0; + for (WarpXParIter pti(myspc, level); pti.isValid(); ++pti, ++i) { + auto& soa = pti.GetStructOfArrays(); + data[i] = (double*) soa.GetRealData(comp).dataPtr(); + (*particles_per_tile)[i] = pti.numParticles(); + } + return data; + } + + void warpx_ComputeDt () { + WarpX& warpx = WarpX::GetInstance(); + warpx.ComputeDt (); + } + void warpx_MoveWindow () { + WarpX& warpx = WarpX::GetInstance(); + warpx.MoveWindow (true); + } + + void warpx_EvolveE (double dt) { + WarpX& warpx = WarpX::GetInstance(); + warpx.EvolveE (dt); + } + void warpx_EvolveB (double dt) { + WarpX& warpx = WarpX::GetInstance(); + warpx.EvolveB (dt); + } + void warpx_FillBoundaryE () { + WarpX& warpx = WarpX::GetInstance(); + warpx.FillBoundaryE (); + } + void warpx_FillBoundaryB () { + WarpX& warpx = WarpX::GetInstance(); + warpx.FillBoundaryB (); + } + void warpx_SyncCurrent () { + WarpX& warpx = WarpX::GetInstance(); + warpx.SyncCurrent (); + } + void warpx_UpdateAuxilaryData () { + WarpX& warpx = WarpX::GetInstance(); + warpx.UpdateAuxilaryData (); + } + void warpx_PushParticlesandDepose (double cur_time) { + WarpX& warpx = WarpX::GetInstance(); + warpx.PushParticlesandDepose (cur_time); + } + + int warpx_getistep (int lev) { + WarpX& warpx = WarpX::GetInstance(); + return warpx.getistep (lev); + } + void warpx_setistep (int lev, int ii) { + WarpX& warpx = WarpX::GetInstance(); + warpx.setistep (lev, ii); + } + double warpx_gett_new (int lev) { + WarpX& warpx = WarpX::GetInstance(); + return warpx.gett_new (lev); + } + void warpx_sett_new (int lev, double time) { + WarpX& warpx = WarpX::GetInstance(); + warpx.sett_new (lev, time); + } + double warpx_getdt (int lev) { + WarpX& warpx = WarpX::GetInstance(); + return warpx.getdt (lev); + } + + int warpx_maxStep () { + WarpX& warpx = WarpX::GetInstance(); + return warpx.maxStep (); + } + double warpx_stopTime () { + WarpX& warpx = WarpX::GetInstance(); + return warpx.stopTime (); + } + + int warpx_checkInt () { + WarpX& warpx = WarpX::GetInstance(); + return warpx.checkInt (); + } + int warpx_plotInt () { + WarpX& warpx = WarpX::GetInstance(); + return warpx.plotInt (); + } + + void warpx_WriteCheckPointFile () { + WarpX& warpx = WarpX::GetInstance(); + warpx.WriteCheckPointFile (); + } + void warpx_WritePlotFile () { + WarpX& warpx = WarpX::GetInstance(); + warpx.WritePlotFile (); + } + + int warpx_finestLevel () { + WarpX& warpx = WarpX::GetInstance(); + return warpx.finestLevel (); + } + + void mypc_Redistribute () { + auto & mypc = WarpX::GetInstance().GetPartContainer(); + mypc.Redistribute(); + } + +} + diff --git a/Source/Python/WarpXWrappers.h b/Source/Python/WarpXWrappers.h new file mode 100644 index 000000000..07d6f80f7 --- /dev/null +++ b/Source/Python/WarpXWrappers.h @@ -0,0 +1,120 @@ +#ifndef WARPX_WRAPPERS_H_ +#define WARPX_WRAPPERS_H_ + +#ifdef BL_USE_MPI +#include +#endif + +#ifdef __cplusplus +extern "C" { +#endif + + int warpx_nSpecies(); + + bool warpx_use_fdtd_nci_corr(); + + int warpx_l_lower_order_in_v(); + + int warpx_nComps(); + + int warpx_SpaceDim(); + + void amrex_init (int argc, char* argv[]); + +#ifdef BL_USE_MPI + void amrex_init_with_inited_mpi (int argc, char* argv[], MPI_Comm mpicomm); +#endif + + void amrex_finalize (int finalize_mpi); + + void warpx_init (); + + void warpx_finalize (); + + typedef void(*WARPX_CALLBACK_PY_FUNC_0)(); + + void warpx_set_callback_py_afterinit (WARPX_CALLBACK_PY_FUNC_0); + void warpx_set_callback_py_beforeEsolve (WARPX_CALLBACK_PY_FUNC_0); + void warpx_set_callback_py_afterEsolve (WARPX_CALLBACK_PY_FUNC_0); + void warpx_set_callback_py_beforedeposition (WARPX_CALLBACK_PY_FUNC_0); + void warpx_set_callback_py_afterdeposition (WARPX_CALLBACK_PY_FUNC_0); + void warpx_set_callback_py_particlescraper (WARPX_CALLBACK_PY_FUNC_0); + void warpx_set_callback_py_particleloader (WARPX_CALLBACK_PY_FUNC_0); + void warpx_set_callback_py_beforestep (WARPX_CALLBACK_PY_FUNC_0); + void warpx_set_callback_py_afterstep (WARPX_CALLBACK_PY_FUNC_0); + void warpx_set_callback_py_afterrestart (WARPX_CALLBACK_PY_FUNC_0); + void warpx_set_callback_py_particleinjection (WARPX_CALLBACK_PY_FUNC_0); + void warpx_set_callback_py_appliedfields (WARPX_CALLBACK_PY_FUNC_0); + + void warpx_evolve (int numsteps); // -1 means the inputs parameter will be used. + + void warpx_addNParticles(int speciesnumber, int lenx, + double* x, double* y, double* z, + double* vx, double* vy, double* vz, + int nattr, double* attr, int uniqueparticles); + + double warpx_getProbLo(int dir); + + double warpx_getProbHi(int dir); + + long warpx_getNumParticles(int speciesnumber); + + double** warpx_getEfield(int lev, int direction, + int *return_size, int* ngrow, int **shapes); + + int* warpx_getEfieldLoVects(int lev, int direction, + int *return_size, int* ngrow); + + double** warpx_getBfield(int lev, int direction, + int *return_size, int* ngrow, int **shapes); + + int* warpx_getBfieldLoVects(int lev, int direction, + int *return_size, int* ngrow); + + double** warpx_getCurrentDensity(int lev, int direction, + int *return_size, int* ngrow, int **shapes); + + int* warpx_getCurrentDensityLoVects(int lev, int direction, + int *return_size, int* ngrow); + + double** warpx_getParticleStructs(int speciesnumber, + int* num_tiles, int** particles_per_tile); + + double** warpx_getParticleArrays(int speciesnumber, int comp, + int* num_tiles, int** particles_per_tile); + + void warpx_ComputeDt (); + void warpx_MoveWindow (); + + void warpx_EvolveE (double dt); + void warpx_EvolveB (double dt); + void warpx_FillBoundaryE (); + void warpx_FillBoundaryB (); + void warpx_SyncCurrent (); + void warpx_UpdateAuxilaryData (); + void warpx_PushParticlesandDepose (double cur_time); + + int warpx_getistep (int lev); + void warpx_setistep (int lev, int ii); + double warpx_gett_new (int lev); + void warpx_sett_new (int lev, double time); + double warpx_getdt (int lev); + + int warpx_maxStep (); + double warpx_stopTime (); + + int warpx_checkInt (); + int warpx_plotInt (); + + void warpx_WriteCheckPointFile (); + void warpx_WritePlotFile (); + + int warpx_finestLevel (); + + void mypc_Redistribute (); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/Source/Utils/Make.package b/Source/Utils/Make.package index 5e4233a29..8cd124ea3 100644 --- a/Source/Utils/Make.package +++ b/Source/Utils/Make.package @@ -1,12 +1,10 @@ F90EXE_sources += utils_ES.F90 CEXE_sources += WarpXMovingWindow.cpp -CEXE_sources += WarpXWrappers.cpp CEXE_sources += WarpXConst.cpp CEXE_sources += WarpXTagging.cpp CEXE_sources += WarpXUtil.cpp CEXE_headers += WarpXConst.H CEXE_headers += WarpXUtil.H -CEXE_headers += WarpXWrappers.h INCLUDE_LOCATIONS += $(WARPX_HOME)/Source/Utils VPATH_LOCATIONS += $(WARPX_HOME)/Source/Utils diff --git a/Source/Utils/WarpXConst.cpp b/Source/Utils/WarpXConst.cpp index 4ca729872..bd3ebc3ef 100644 --- a/Source/Utils/WarpXConst.cpp +++ b/Source/Utils/WarpXConst.cpp @@ -8,7 +8,7 @@ #include #include #include -#include +#include std::string UserConstants::replaceStringValue(std::string math_expr){ std::string pattern, value_str; diff --git a/Source/Utils/WarpXWrappers.cpp b/Source/Utils/WarpXWrappers.cpp deleted file mode 100644 index 6ee06a7d5..000000000 --- a/Source/Utils/WarpXWrappers.cpp +++ /dev/null @@ -1,446 +0,0 @@ - -#include -#include - -#include -#include -#include -#include - -namespace -{ - double** getMultiFabPointers(const amrex::MultiFab& mf, int *num_boxes, int *ngrow, int **shapes) - { - *ngrow = mf.nGrow(); - *num_boxes = mf.local_size(); - *shapes = (int*) malloc(AMREX_SPACEDIM * (*num_boxes) * sizeof(int)); - double** data = (double**) malloc((*num_boxes) * sizeof(double*)); - - int i = 0; -#ifdef _OPENMP -#pragma omp parallel -#endif - for ( amrex::MFIter mfi(mf, false); mfi.isValid(); ++mfi, ++i ) { - data[i] = (double*) mf[mfi].dataPtr(); - for (int j = 0; j < AMREX_SPACEDIM; ++j) { - (*shapes)[AMREX_SPACEDIM*i+j] = mf[mfi].box().length(j); - } - } - return data; - } - int* getMultiFabLoVects(const amrex::MultiFab& mf, int *num_boxes, int *ngrow) - { - *ngrow = mf.nGrow(); - *num_boxes = mf.local_size(); - int *loVects = (int*) malloc((*num_boxes)*AMREX_SPACEDIM * sizeof(int)); - - int i = 0; - for ( amrex::MFIter mfi(mf, false); mfi.isValid(); ++mfi, ++i ) { - const int* loVect = mf[mfi].loVect(); - for (int j = 0; j < AMREX_SPACEDIM; ++j) { - loVects[AMREX_SPACEDIM*i+j] = loVect[j]; - } - } - return loVects; - } -} - -extern "C" -{ - - int warpx_nSpecies() - { - auto & mypc = WarpX::GetInstance().GetPartContainer(); - return mypc.nSpecies(); - } - - bool warpx_use_fdtd_nci_corr() - { - return WarpX::use_fdtd_nci_corr; - } - - int warpx_l_lower_order_in_v() - { - return WarpX::l_lower_order_in_v; - } - - int warpx_nComps() - { - return PIdx::nattribs; - } - - int warpx_SpaceDim() - { - return AMREX_SPACEDIM; - } - - void amrex_init (int argc, char* argv[]) - { - amrex::Initialize(argc,argv); - } - -#ifdef BL_USE_MPI - void amrex_init_with_inited_mpi (int argc, char* argv[], MPI_Comm mpicomm) - { - amrex::Initialize(argc,argv,true,mpicomm); - } -#endif - - void amrex_finalize (int finalize_mpi) - { - amrex::Finalize(finalize_mpi); - } - - void warpx_init () - { - WarpX& warpx = WarpX::GetInstance(); - warpx.InitData(); - if (warpx_py_afterinit) warpx_py_afterinit(); - if (warpx_py_particleloader) warpx_py_particleloader(); - } - - void warpx_finalize () - { - WarpX::ResetInstance(); - } - - void warpx_set_callback_py_afterinit (WARPX_CALLBACK_PY_FUNC_0 callback) - { - warpx_py_afterinit = callback; - } - void warpx_set_callback_py_beforeEsolve (WARPX_CALLBACK_PY_FUNC_0 callback) - { - warpx_py_beforeEsolve = callback; - } - void warpx_set_callback_py_afterEsolve (WARPX_CALLBACK_PY_FUNC_0 callback) - { - warpx_py_afterEsolve = callback; - } - void warpx_set_callback_py_beforedeposition (WARPX_CALLBACK_PY_FUNC_0 callback) - { - warpx_py_beforedeposition = callback; - } - void warpx_set_callback_py_afterdeposition (WARPX_CALLBACK_PY_FUNC_0 callback) - { - warpx_py_afterdeposition = callback; - } - void warpx_set_callback_py_particlescraper (WARPX_CALLBACK_PY_FUNC_0 callback) - { - warpx_py_particlescraper = callback; - } - void warpx_set_callback_py_particleloader (WARPX_CALLBACK_PY_FUNC_0 callback) - { - warpx_py_particleloader = callback; - } - void warpx_set_callback_py_beforestep (WARPX_CALLBACK_PY_FUNC_0 callback) - { - warpx_py_beforestep = callback; - } - void warpx_set_callback_py_afterstep (WARPX_CALLBACK_PY_FUNC_0 callback) - { - warpx_py_afterstep = callback; - } - void warpx_set_callback_py_afterrestart (WARPX_CALLBACK_PY_FUNC_0 callback) - { - warpx_py_afterrestart = callback; - } - void warpx_set_callback_py_particleinjection (WARPX_CALLBACK_PY_FUNC_0 callback) - { - warpx_py_particleinjection = callback; - } - void warpx_set_callback_py_appliedfields (WARPX_CALLBACK_PY_FUNC_0 callback) - { - warpx_py_appliedfields = callback; - } - - void warpx_evolve (int numsteps) - { - WarpX& warpx = WarpX::GetInstance(); - warpx.Evolve(numsteps); - } - - void warpx_addNParticles(int speciesnumber, int lenx, - double* x, double* y, double* z, - double* vx, double* vy, double* vz, - int nattr, double* attr, int uniqueparticles) - { - auto & mypc = WarpX::GetInstance().GetPartContainer(); - auto & myspc = mypc.GetParticleContainer(speciesnumber); - const int lev = 0; - myspc.AddNParticles(lev, lenx, x, y, z, vx, vy, vz, nattr, attr, uniqueparticles); - } - - double warpx_getProbLo(int dir) - { - WarpX& warpx = WarpX::GetInstance(); - const amrex::Geometry& geom = warpx.Geom(0); - return geom.ProbLo(dir); - } - - double warpx_getProbHi(int dir) - { - WarpX& warpx = WarpX::GetInstance(); - const amrex::Geometry& geom = warpx.Geom(0); - return geom.ProbHi(dir); - } - - long warpx_getNumParticles(int speciesnumber) { - auto & mypc = WarpX::GetInstance().GetPartContainer(); - auto & myspc = mypc.GetParticleContainer(speciesnumber); - return myspc.TotalNumberOfParticles(); - } - - double** warpx_getEfield(int lev, int direction, - int *return_size, int *ngrow, int **shapes) { - auto & mf = WarpX::GetInstance().getEfield(lev, direction); - return getMultiFabPointers(mf, return_size, ngrow, shapes); - } - - int* warpx_getEfieldLoVects(int lev, int direction, - int *return_size, int *ngrow) { - auto & mf = WarpX::GetInstance().getEfield(lev, direction); - return getMultiFabLoVects(mf, return_size, ngrow); - } - - double** warpx_getEfieldCP(int lev, int direction, - int *return_size, int *ngrow, int **shapes) { - auto & mf = WarpX::GetInstance().getEfield_cp(lev, direction); - return getMultiFabPointers(mf, return_size, ngrow, shapes); - } - - int* warpx_getEfieldCPLoVects(int lev, int direction, - int *return_size, int *ngrow) { - auto & mf = WarpX::GetInstance().getEfield_cp(lev, direction); - return getMultiFabLoVects(mf, return_size, ngrow); - } - - double** warpx_getEfieldFP(int lev, int direction, - int *return_size, int *ngrow, int **shapes) { - auto & mf = WarpX::GetInstance().getEfield_fp(lev, direction); - return getMultiFabPointers(mf, return_size, ngrow, shapes); - } - - int* warpx_getEfieldFPLoVects(int lev, int direction, - int *return_size, int *ngrow) { - auto & mf = WarpX::GetInstance().getEfield_fp(lev, direction); - return getMultiFabLoVects(mf, return_size, ngrow); - } - - double** warpx_getBfield(int lev, int direction, - int *return_size, int *ngrow, int **shapes) { - auto & mf = WarpX::GetInstance().getBfield(lev, direction); - return getMultiFabPointers(mf, return_size, ngrow, shapes); - } - - int* warpx_getBfieldLoVects(int lev, int direction, - int *return_size, int *ngrow) { - auto & mf = WarpX::GetInstance().getBfield(lev, direction); - return getMultiFabLoVects(mf, return_size, ngrow); - } - - double** warpx_getBfieldCP(int lev, int direction, - int *return_size, int *ngrow, int **shapes) { - auto & mf = WarpX::GetInstance().getBfield_cp(lev, direction); - return getMultiFabPointers(mf, return_size, ngrow, shapes); - } - - int* warpx_getBfieldCPLoVects(int lev, int direction, - int *return_size, int *ngrow) { - auto & mf = WarpX::GetInstance().getBfield_cp(lev, direction); - return getMultiFabLoVects(mf, return_size, ngrow); - } - - double** warpx_getBfieldFP(int lev, int direction, - int *return_size, int *ngrow, int **shapes) { - auto & mf = WarpX::GetInstance().getBfield_fp(lev, direction); - return getMultiFabPointers(mf, return_size, ngrow, shapes); - } - - int* warpx_getBfieldFPLoVects(int lev, int direction, - int *return_size, int *ngrow) { - auto & mf = WarpX::GetInstance().getBfield_fp(lev, direction); - return getMultiFabLoVects(mf, return_size, ngrow); - } - - double** warpx_getCurrentDensity(int lev, int direction, - int *return_size, int *ngrow, int **shapes) { - auto & mf = WarpX::GetInstance().getcurrent(lev, direction); - return getMultiFabPointers(mf, return_size, ngrow, shapes); - } - - int* warpx_getCurrentDensityLoVects(int lev, int direction, - int *return_size, int *ngrow) { - auto & mf = WarpX::GetInstance().getcurrent(lev, direction); - return getMultiFabLoVects(mf, return_size, ngrow); - } - - double** warpx_getCurrentDensityCP(int lev, int direction, - int *return_size, int *ngrow, int **shapes) { - auto & mf = WarpX::GetInstance().getcurrent_cp(lev, direction); - return getMultiFabPointers(mf, return_size, ngrow, shapes); - } - - int* warpx_getCurrentDensityCPLoVects(int lev, int direction, - int *return_size, int *ngrow) { - auto & mf = WarpX::GetInstance().getcurrent_cp(lev, direction); - return getMultiFabLoVects(mf, return_size, ngrow); - } - - double** warpx_getCurrentDensityFP(int lev, int direction, - int *return_size, int *ngrow, int **shapes) { - auto & mf = WarpX::GetInstance().getcurrent_fp(lev, direction); - return getMultiFabPointers(mf, return_size, ngrow, shapes); - } - - int* warpx_getCurrentDensityFPLoVects(int lev, int direction, - int *return_size, int *ngrow) { - auto & mf = WarpX::GetInstance().getcurrent_fp(lev, direction); - return getMultiFabLoVects(mf, return_size, ngrow); - } - - double** warpx_getParticleStructs(int speciesnumber, - int* num_tiles, int** particles_per_tile) { - auto & mypc = WarpX::GetInstance().GetPartContainer(); - auto & myspc = mypc.GetParticleContainer(speciesnumber); - - const int level = 0; - - int i = 0; - for (WarpXParIter pti(myspc, level); pti.isValid(); ++pti, ++i) {} - - // *num_tiles = myspc.numLocalTilesAtLevel(level); - *num_tiles = i; - *particles_per_tile = (int*) malloc(*num_tiles*sizeof(int)); - - double** data = (double**) malloc(*num_tiles*sizeof(typename WarpXParticleContainer::ParticleType*)); - i = 0; - for (WarpXParIter pti(myspc, level); pti.isValid(); ++pti, ++i) { - auto& aos = pti.GetArrayOfStructs(); - data[i] = (double*) aos.data(); - (*particles_per_tile)[i] = pti.numParticles(); - } - return data; - } - - double** warpx_getParticleArrays(int speciesnumber, int comp, - int* num_tiles, int** particles_per_tile) { - auto & mypc = WarpX::GetInstance().GetPartContainer(); - auto & myspc = mypc.GetParticleContainer(speciesnumber); - - const int level = 0; - - int i = 0; - for (WarpXParIter pti(myspc, level); pti.isValid(); ++pti, ++i) {} - - // *num_tiles = myspc.numLocalTilesAtLevel(level); - *num_tiles = i; - *particles_per_tile = (int*) malloc(*num_tiles*sizeof(int)); - - double** data = (double**) malloc(*num_tiles*sizeof(double*)); - i = 0; - for (WarpXParIter pti(myspc, level); pti.isValid(); ++pti, ++i) { - auto& soa = pti.GetStructOfArrays(); - data[i] = (double*) soa.GetRealData(comp).dataPtr(); - (*particles_per_tile)[i] = pti.numParticles(); - } - return data; - } - - void warpx_ComputeDt () { - WarpX& warpx = WarpX::GetInstance(); - warpx.ComputeDt (); - } - void warpx_MoveWindow () { - WarpX& warpx = WarpX::GetInstance(); - warpx.MoveWindow (true); - } - - void warpx_EvolveE (double dt) { - WarpX& warpx = WarpX::GetInstance(); - warpx.EvolveE (dt); - } - void warpx_EvolveB (double dt) { - WarpX& warpx = WarpX::GetInstance(); - warpx.EvolveB (dt); - } - void warpx_FillBoundaryE () { - WarpX& warpx = WarpX::GetInstance(); - warpx.FillBoundaryE (); - } - void warpx_FillBoundaryB () { - WarpX& warpx = WarpX::GetInstance(); - warpx.FillBoundaryB (); - } - void warpx_SyncCurrent () { - WarpX& warpx = WarpX::GetInstance(); - warpx.SyncCurrent (); - } - void warpx_UpdateAuxilaryData () { - WarpX& warpx = WarpX::GetInstance(); - warpx.UpdateAuxilaryData (); - } - void warpx_PushParticlesandDepose (double cur_time) { - WarpX& warpx = WarpX::GetInstance(); - warpx.PushParticlesandDepose (cur_time); - } - - int warpx_getistep (int lev) { - WarpX& warpx = WarpX::GetInstance(); - return warpx.getistep (lev); - } - void warpx_setistep (int lev, int ii) { - WarpX& warpx = WarpX::GetInstance(); - warpx.setistep (lev, ii); - } - double warpx_gett_new (int lev) { - WarpX& warpx = WarpX::GetInstance(); - return warpx.gett_new (lev); - } - void warpx_sett_new (int lev, double time) { - WarpX& warpx = WarpX::GetInstance(); - warpx.sett_new (lev, time); - } - double warpx_getdt (int lev) { - WarpX& warpx = WarpX::GetInstance(); - return warpx.getdt (lev); - } - - int warpx_maxStep () { - WarpX& warpx = WarpX::GetInstance(); - return warpx.maxStep (); - } - double warpx_stopTime () { - WarpX& warpx = WarpX::GetInstance(); - return warpx.stopTime (); - } - - int warpx_checkInt () { - WarpX& warpx = WarpX::GetInstance(); - return warpx.checkInt (); - } - int warpx_plotInt () { - WarpX& warpx = WarpX::GetInstance(); - return warpx.plotInt (); - } - - void warpx_WriteCheckPointFile () { - WarpX& warpx = WarpX::GetInstance(); - warpx.WriteCheckPointFile (); - } - void warpx_WritePlotFile () { - WarpX& warpx = WarpX::GetInstance(); - warpx.WritePlotFile (); - } - - int warpx_finestLevel () { - WarpX& warpx = WarpX::GetInstance(); - return warpx.finestLevel (); - } - - void mypc_Redistribute () { - auto & mypc = WarpX::GetInstance().GetPartContainer(); - mypc.Redistribute(); - } - -} - diff --git a/Source/Utils/WarpXWrappers.h b/Source/Utils/WarpXWrappers.h deleted file mode 100644 index 07d6f80f7..000000000 --- a/Source/Utils/WarpXWrappers.h +++ /dev/null @@ -1,120 +0,0 @@ -#ifndef WARPX_WRAPPERS_H_ -#define WARPX_WRAPPERS_H_ - -#ifdef BL_USE_MPI -#include -#endif - -#ifdef __cplusplus -extern "C" { -#endif - - int warpx_nSpecies(); - - bool warpx_use_fdtd_nci_corr(); - - int warpx_l_lower_order_in_v(); - - int warpx_nComps(); - - int warpx_SpaceDim(); - - void amrex_init (int argc, char* argv[]); - -#ifdef BL_USE_MPI - void amrex_init_with_inited_mpi (int argc, char* argv[], MPI_Comm mpicomm); -#endif - - void amrex_finalize (int finalize_mpi); - - void warpx_init (); - - void warpx_finalize (); - - typedef void(*WARPX_CALLBACK_PY_FUNC_0)(); - - void warpx_set_callback_py_afterinit (WARPX_CALLBACK_PY_FUNC_0); - void warpx_set_callback_py_beforeEsolve (WARPX_CALLBACK_PY_FUNC_0); - void warpx_set_callback_py_afterEsolve (WARPX_CALLBACK_PY_FUNC_0); - void warpx_set_callback_py_beforedeposition (WARPX_CALLBACK_PY_FUNC_0); - void warpx_set_callback_py_afterdeposition (WARPX_CALLBACK_PY_FUNC_0); - void warpx_set_callback_py_particlescraper (WARPX_CALLBACK_PY_FUNC_0); - void warpx_set_callback_py_particleloader (WARPX_CALLBACK_PY_FUNC_0); - void warpx_set_callback_py_beforestep (WARPX_CALLBACK_PY_FUNC_0); - void warpx_set_callback_py_afterstep (WARPX_CALLBACK_PY_FUNC_0); - void warpx_set_callback_py_afterrestart (WARPX_CALLBACK_PY_FUNC_0); - void warpx_set_callback_py_particleinjection (WARPX_CALLBACK_PY_FUNC_0); - void warpx_set_callback_py_appliedfields (WARPX_CALLBACK_PY_FUNC_0); - - void warpx_evolve (int numsteps); // -1 means the inputs parameter will be used. - - void warpx_addNParticles(int speciesnumber, int lenx, - double* x, double* y, double* z, - double* vx, double* vy, double* vz, - int nattr, double* attr, int uniqueparticles); - - double warpx_getProbLo(int dir); - - double warpx_getProbHi(int dir); - - long warpx_getNumParticles(int speciesnumber); - - double** warpx_getEfield(int lev, int direction, - int *return_size, int* ngrow, int **shapes); - - int* warpx_getEfieldLoVects(int lev, int direction, - int *return_size, int* ngrow); - - double** warpx_getBfield(int lev, int direction, - int *return_size, int* ngrow, int **shapes); - - int* warpx_getBfieldLoVects(int lev, int direction, - int *return_size, int* ngrow); - - double** warpx_getCurrentDensity(int lev, int direction, - int *return_size, int* ngrow, int **shapes); - - int* warpx_getCurrentDensityLoVects(int lev, int direction, - int *return_size, int* ngrow); - - double** warpx_getParticleStructs(int speciesnumber, - int* num_tiles, int** particles_per_tile); - - double** warpx_getParticleArrays(int speciesnumber, int comp, - int* num_tiles, int** particles_per_tile); - - void warpx_ComputeDt (); - void warpx_MoveWindow (); - - void warpx_EvolveE (double dt); - void warpx_EvolveB (double dt); - void warpx_FillBoundaryE (); - void warpx_FillBoundaryB (); - void warpx_SyncCurrent (); - void warpx_UpdateAuxilaryData (); - void warpx_PushParticlesandDepose (double cur_time); - - int warpx_getistep (int lev); - void warpx_setistep (int lev, int ii); - double warpx_gett_new (int lev); - void warpx_sett_new (int lev, double time); - double warpx_getdt (int lev); - - int warpx_maxStep (); - double warpx_stopTime (); - - int warpx_checkInt (); - int warpx_plotInt (); - - void warpx_WriteCheckPointFile (); - void warpx_WritePlotFile (); - - int warpx_finestLevel (); - - void mypc_Redistribute (); - -#ifdef __cplusplus -} -#endif - -#endif -- cgit v1.2.3