diff options
Diffstat (limited to 'Source')
-rw-r--r-- | Source/WarpXEvolve.cpp | 19 | ||||
-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 |
5 files changed, 123 insertions, 16 deletions
diff --git a/Source/WarpXEvolve.cpp b/Source/WarpXEvolve.cpp index c21e122c2..cda70dd53 100644 --- a/Source/WarpXEvolve.cpp +++ b/Source/WarpXEvolve.cpp @@ -62,6 +62,7 @@ WarpX::EvolveES(int numsteps) { // Start loop on time steps amrex::Print() << "\nSTEP " << step+1 << " starts ...\n"; + if (warpx_py_beforestep) warpx_py_beforestep(); // 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}. @@ -85,10 +86,16 @@ WarpX::EvolveES(int numsteps) { // Evolve particles to p^{n+1/2} and x^{n+1} mypc->EvolveES(eFieldNodal, rhoNodal, cur_time, dt[lev]); + if (warpx_py_particleinjection) warpx_py_particleinjection(); + if (warpx_py_particlescraper) warpx_py_particlescraper(); + if (warpx_py_beforedeposition) warpx_py_beforedeposition(); mypc->DepositCharge(rhoNodal); + if (warpx_py_afterdeposition) warpx_py_afterdeposition(); + if (warpx_py_beforeEsolve) warpx_py_beforeEsolve(); computePhi(rhoNodal, phiNodal); computeE(eFieldNodal, phiNodal); + if (warpx_py_afterEsolve) warpx_py_afterEsolve(); 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 @@ -134,6 +141,7 @@ WarpX::EvolveES(int numsteps) { break; } + if (warpx_py_afterstep) warpx_py_afterstep(); // End loop on time steps } @@ -165,12 +173,10 @@ WarpX::EvolveEM (int numsteps) bool max_time_reached = false; 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"; + if (warpx_py_beforestep) warpx_py_beforestep(); if (costs[0] != nullptr) { @@ -212,7 +218,11 @@ WarpX::EvolveEM (int numsteps) // Push particle from x^{n} to x{n+1} // Deposit current j^{n+1/2} // Deposit charge density rho^{n} + if (warpx_py_particleinjection) warpx_py_particleinjection(); + if (warpx_py_particlescraper) warpx_py_particlescraper(); + if (warpx_py_beforedeposition) warpx_py_beforedeposition(); PushParticlesandDepose(cur_time); + if (warpx_py_afterdeposition) warpx_py_afterdeposition(); EvolveB(0.5*dt[0], DtType::SecondHalf); // We now B^{n+1/2} @@ -225,6 +235,7 @@ WarpX::EvolveEM (int numsteps) // Fill B's ghost cells because of the next step of evolving E. FillBoundaryB(); + if (warpx_py_beforeEsolve) warpx_py_beforeEsolve(); 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 EvolveE(0.5*dt[0], DtType::FirstHalf); // We now have E^{n+1/2} @@ -234,6 +245,7 @@ WarpX::EvolveEM (int numsteps) } else { EvolveE(dt[0], DtType::Full); // We now have E^{n+1} } + if (warpx_py_afterEsolve) warpx_py_afterEsolve(); for (int lev = 0; lev <= max_level; ++lev) { ++istep[lev]; @@ -294,6 +306,7 @@ WarpX::EvolveEM (int numsteps) break; } + if (warpx_py_afterstep) warpx_py_afterstep(); // End loop on time steps } diff --git a/Source/WarpXWrappers.cpp b/Source/WarpXWrappers.cpp index bc6300bb3..d106cfca7 100644 --- a/Source/WarpXWrappers.cpp +++ b/Source/WarpXWrappers.cpp @@ -85,6 +85,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 () @@ -92,9 +94,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) @@ -248,11 +294,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(); @@ -267,11 +318,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 8795b17f9..8079e847e 100644 --- a/Source/WarpXWrappers.h +++ b/Source/WarpXWrappers.h @@ -27,9 +27,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; + } |