diff options
Diffstat (limited to 'Source')
| -rw-r--r-- | Source/WarpXElectrostatic.cpp | 18 | ||||
| -rw-r--r-- | Source/WarpXEvolve.cpp | 25 | ||||
| -rw-r--r-- | Source/WarpXWrappers.cpp | 72 | ||||
| -rw-r--r-- | Source/WarpXWrappers.h | 18 | ||||
| -rw-r--r-- | Source/WarpX_py.H | 15 | ||||
| -rw-r--r-- | Source/WarpX_py.cpp | 15 |
6 files changed, 147 insertions, 16 deletions
diff --git a/Source/WarpXElectrostatic.cpp b/Source/WarpXElectrostatic.cpp index 277dc2887..c4e37ce1a 100644 --- a/Source/WarpXElectrostatic.cpp +++ b/Source/WarpXElectrostatic.cpp @@ -63,6 +63,9 @@ WarpX::EvolveES (int numsteps) { // Start loop on time steps amrex::Print() << "\nSTEP " << step+1 << " starts ...\n"; +#ifdef WARPX_USE_PY + if (warpx_py_beforestep) warpx_py_beforestep(); +#endif // At initialization, particles have p^{n-1/2} and x^{n-1/2}. // Beyond one step, particles have p^{n-1/2} and x^{n}. @@ -86,10 +89,22 @@ WarpX::EvolveES (int numsteps) { // Evolve particles to p^{n+1/2} and x^{n+1} mypc->EvolveES(eFieldNodal, rhoNodal, cur_time, dt[lev]); +#ifdef WARPX_USE_PY + if (warpx_py_particleinjection) warpx_py_particleinjection(); + if (warpx_py_particlescraper) warpx_py_particlescraper(); + if (warpx_py_beforedeposition) warpx_py_beforedeposition(); +#endif mypc->DepositCharge(rhoNodal); +#ifdef WARPX_USE_PY + if (warpx_py_afterdeposition) warpx_py_afterdeposition(); + if (warpx_py_beforeEsolve) warpx_py_beforeEsolve(); +#endif computePhi(rhoNodal, phiNodal); computeE(eFieldNodal, phiNodal); +#ifdef WARPX_USE_PY + if (warpx_py_afterEsolve) warpx_py_afterEsolve(); +#endif if (cur_time + dt[0] >= stop_time - 1.e-3*dt[0] || step == numsteps_max-1) { // on last step, push by only 0.5*dt to synchronize all at n+1/2 @@ -135,6 +150,9 @@ WarpX::EvolveES (int numsteps) { break; } +#ifdef WARPX_USE_PY + if (warpx_py_afterstep) warpx_py_afterstep(); +#endif // End loop on time steps } diff --git a/Source/WarpXEvolve.cpp b/Source/WarpXEvolve.cpp index a92f033b5..b42a781d1 100644 --- a/Source/WarpXEvolve.cpp +++ b/Source/WarpXEvolve.cpp @@ -5,7 +5,9 @@ #include <WarpX.H> #include <WarpXConst.H> #include <WarpX_f.H> +#ifdef WARPX_USE_PY #include <WarpX_py.H> +#endif using namespace amrex; @@ -45,12 +47,12 @@ WarpX::EvolveEM (int numsteps) Real walltime, walltime_start = ParallelDescriptor::second(); for (int step = istep[0]; step < numsteps_max && cur_time < stop_time; ++step) { - if (warpx_py_print_step) { - warpx_py_print_step(step); - } // Start loop on time steps amrex::Print() << "\nSTEP " << step+1 << " starts ...\n"; +#ifdef WARPX_USE_PY + if (warpx_py_beforestep) warpx_py_beforestep(); +#endif if (costs[0] != nullptr) { @@ -97,7 +99,15 @@ WarpX::EvolveEM (int numsteps) // from p^{n-1/2} to p^{n+1/2} // Deposit current j^{n+1/2} // Deposit charge density rho^{n} +#ifdef WARPX_USE_PY + if (warpx_py_particleinjection) warpx_py_particleinjection(); + if (warpx_py_particlescraper) warpx_py_particlescraper(); + if (warpx_py_beforedeposition) warpx_py_beforedeposition(); +#endif PushParticlesandDepose(cur_time); +#ifdef WARPX_USE_PY + if (warpx_py_afterdeposition) warpx_py_afterdeposition(); +#endif SyncCurrent(); @@ -122,6 +132,9 @@ WarpX::EvolveEM (int numsteps) FillBoundaryB(); #endif +#ifdef WARPX_USE_PY + if (warpx_py_beforeEsolve) warpx_py_beforeEsolve(); +#endif if (cur_time + dt[0] >= stop_time - 1.e-3*dt[0] || step == numsteps_max-1) { // At the end of last step, push p by 0.5*dt to synchronize UpdateAuxilaryData(); @@ -132,6 +145,9 @@ WarpX::EvolveEM (int numsteps) } is_synchronized = true; } +#ifdef WARPX_USE_PY + if (warpx_py_afterEsolve) warpx_py_afterEsolve(); +#endif for (int lev = 0; lev <= max_level; ++lev) { ++istep[lev]; @@ -196,6 +212,9 @@ WarpX::EvolveEM (int numsteps) break; } +#ifdef WARPX_USE_PY + if (warpx_py_afterstep) warpx_py_afterstep(); +#endif // End loop on time steps } diff --git a/Source/WarpXWrappers.cpp b/Source/WarpXWrappers.cpp index e65c5cae6..87faac93b 100644 --- a/Source/WarpXWrappers.cpp +++ b/Source/WarpXWrappers.cpp @@ -97,6 +97,8 @@ extern "C" { WarpX& warpx = WarpX::GetInstance(); warpx.InitData(); + if (warpx_py_afterinit) warpx_py_afterinit(); + if (warpx_py_particleloader) warpx_py_particleloader(); } void warpx_finalize () @@ -104,9 +106,53 @@ extern "C" WarpX::ResetInstance(); } - void warpx_set_callback_py_funcs (WARPX_CALLBACK_PY_FUNC_1 print_step) + void warpx_set_callback_py_afterinit (WARPX_CALLBACK_PY_FUNC_0 callback) { - warpx_py_print_step = print_step; + 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) @@ -260,11 +306,16 @@ extern "C" auto & myspc = mypc.GetParticleContainer(speciesnumber); const int level = 0; - *num_tiles = myspc.numLocalTilesAtLevel(level); + + 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*)); - int i = 0; + i = 0; for (WarpXParIter pti(myspc, level); pti.isValid(); ++pti, ++i) { auto& aos = pti.GetArrayOfStructs(); data[i] = (double*) aos.data(); @@ -279,11 +330,16 @@ extern "C" auto & myspc = mypc.GetParticleContainer(speciesnumber); const int level = 0; - *num_tiles = myspc.numLocalTilesAtLevel(level); + + 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*)); - int i = 0; + i = 0; for (WarpXParIter pti(myspc, level); pti.isValid(); ++pti, ++i) { auto& soa = pti.GetStructOfArrays(); data[i] = (double*) soa.GetRealData(comp).dataPtr(); diff --git a/Source/WarpXWrappers.h b/Source/WarpXWrappers.h index 7862b0fc3..07a573cc8 100644 --- a/Source/WarpXWrappers.h +++ b/Source/WarpXWrappers.h @@ -31,9 +31,21 @@ extern "C" { void warpx_finalize (); - typedef void(*WARPX_CALLBACK_PY_FUNC_1)(int); - void warpx_set_callback_py_funcs (WARPX_CALLBACK_PY_FUNC_1); - + 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, diff --git a/Source/WarpX_py.H b/Source/WarpX_py.H index 75977acf2..d8cf22155 100644 --- a/Source/WarpX_py.H +++ b/Source/WarpX_py.H @@ -4,7 +4,20 @@ #include <WarpXWrappers.h> extern "C" { - extern WARPX_CALLBACK_PY_FUNC_1 warpx_py_print_step; + + 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/WarpX_py.cpp b/Source/WarpX_py.cpp index 8f7b36e45..276d637d7 100644 --- a/Source/WarpX_py.cpp +++ b/Source/WarpX_py.cpp @@ -1,6 +1,19 @@ #include <WarpX_py.H> extern "C" { - WARPX_CALLBACK_PY_FUNC_1 warpx_py_print_step = nullptr; + + 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; + } |
