From e8d3fda2c991348a19b3a0e33dde4869c57630a9 Mon Sep 17 00:00:00 2001 From: Dave Grote Date: Tue, 10 Jan 2017 10:59:08 -0800 Subject: Cleaned up python importing of warpx --- Python/pywarpx/WarpX.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'Python/pywarpx/WarpX.py') diff --git a/Python/pywarpx/WarpX.py b/Python/pywarpx/WarpX.py index a1c85e618..16a7db506 100644 --- a/Python/pywarpx/WarpX.py +++ b/Python/pywarpx/WarpX.py @@ -1,18 +1,18 @@ from .Bucket import Bucket -from . import _warpxC +from . import warpxC class WarpX(Bucket): def init(self): - _warpxC.warpx_init() + warpxC.warpx_init() def evolve(self, nsteps=None): if nsteps is None: - _warpxC.warpx_evolve() + warpxC.warpx_evolve() else: - _warpxC.warpx_evolve(nsteps) + warpxC.warpx_evolve(nsteps) def finalize(self): - _warpxC.warpx_finalize() + warpxC.warpx_finalize() warpx = WarpX('warpx') -- cgit v1.2.3 From 4b979e2794f00dd09bf3523f4a4acd2cb73488fc Mon Sep 17 00:00:00 2001 From: Andrew Myers Date: Wed, 25 Jan 2017 17:53:42 -0800 Subject: Modify the plasma_acceleration.py script to perform the moving window particle injection from Python. --- Python/pywarpx/WarpX.py | 6 ++ Source/WarpXWrappers.cpp | 14 ++++ Source/WarpXWrappers.h | 4 ++ tests/plasma_acceleration/plasma_acceleration.py | 85 ++++++++++++++++++++++-- 4 files changed, 103 insertions(+), 6 deletions(-) (limited to 'Python/pywarpx/WarpX.py') diff --git a/Python/pywarpx/WarpX.py b/Python/pywarpx/WarpX.py index 16a7db506..8b9ecefe5 100644 --- a/Python/pywarpx/WarpX.py +++ b/Python/pywarpx/WarpX.py @@ -15,4 +15,10 @@ class WarpX(Bucket): def finalize(self): warpxC.warpx_finalize() + def getProbLo(self, direction): + return warpxC.warpx_getProbLo(direction) + + def getProbHi(self, direction): + return warpxC.warpx_getProbHi(direction) + warpx = WarpX('warpx') diff --git a/Source/WarpXWrappers.cpp b/Source/WarpXWrappers.cpp index 09c7abaf4..fe8ad4d4c 100644 --- a/Source/WarpXWrappers.cpp +++ b/Source/WarpXWrappers.cpp @@ -45,5 +45,19 @@ extern "C" auto & myspc = mypc.GetParticleContainer(speciesnumber); myspc.AddNParticles(lenx, x, y, z, vx, vy, vz, nattr, attr, uniqueparticles); } + + double warpx_getProbLo(int dir) + { + WarpX& warpx = WarpX::GetInstance(); + const Geometry& geom = warpx.Geom(0); + return geom.ProbLo(dir); + } + + double warpx_getProbHi(int dir) + { + WarpX& warpx = WarpX::GetInstance(); + const Geometry& geom = warpx.Geom(0); + return geom.ProbHi(dir); + } } diff --git a/Source/WarpXWrappers.h b/Source/WarpXWrappers.h index 3a080942e..a2c8dfe12 100644 --- a/Source/WarpXWrappers.h +++ b/Source/WarpXWrappers.h @@ -20,6 +20,10 @@ extern "C" { void warpx_evolve (int numsteps); // -1 means the inputs parameter will be used. void 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); #ifdef __cplusplus } diff --git a/tests/plasma_acceleration/plasma_acceleration.py b/tests/plasma_acceleration/plasma_acceleration.py index cb741dd69..e82daf1ae 100644 --- a/tests/plasma_acceleration/plasma_acceleration.py +++ b/tests/plasma_acceleration/plasma_acceleration.py @@ -116,9 +116,69 @@ def set_initial_conditions(ncells, domain_min, domain_max): comm.Barrier() + +def inject_plasma(num_shift, direction): + ''' + + This injects fresh plasma into the domain after the moving window has been upated. + + ''' + + comm.Barrier() + + num_ppc = 4 + density = 1.e22 + weight = density * dx[0]*dx[1]*dx[2] / num_ppc + + shift_box = np.array(ncells) + shift_box[direction] = abs(num_shift) + + Z, Y, X, P = np.mgrid[0:shift_box[2], 0:shift_box[1], 0:shift_box[0], 0:num_ppc] + X = X.flatten() + Y = Y.flatten() + Z = Z.flatten() + P = P.flatten() + particle_shift = (0.5 + P) / num_ppc + + pos = [[],[],[]] + + if (num_shift > 0): + pos[0] = (X + particle_shift)*dx[0] + domain_min[0] + pos[1] = (Y + particle_shift)*dx[1] + domain_min[1] + pos[2] = (Z + particle_shift)*dx[2] + domain_min[2] + pos[direction] -= domain_min[direction] + pos[direction] += domain_max[direction] + + if (num_shift < 0): + pos[0] = (X + particle_shift)*dx[0] + domain_min[0] + pos[1] = (Y + particle_shift)*dx[1] + domain_min[1] + pos[2] = (Z + particle_shift)*dx[2] + domain_min[2] + pos[direction] += num_shift*dx[direction] + + xp = pos[0] + yp = pos[1] + zp = pos[2] + + uxp = np.zeros_like(xp) + uyp = np.zeros_like(xp) + uzp = np.zeros_like(xp) + + Np = xp.shape[0] + wp = np.full((Np, 1), weight) + + lo, hi = get_parallel_indices(Np, comm.rank, comm.size) + + warpxC.addNParticles(1, xp[lo:hi], yp[lo:hi], zp[lo:hi], + uxp[lo:hi], uyp[lo:hi], uzp[lo:hi], + wp[lo:hi], 1) + + comm.Barrier() + + ncells = np.array([64, 64, 64]) domain_min = np.array([-200e-6, -200e-6, -200e-6]) domain_max = np.array([ 200e-6, 200e-6, 200e-6]) +dx = (domain_max - domain_min) / ncells # Maximum number of time steps max_step = 60 @@ -156,11 +216,11 @@ warpx.do_moving_window = 1 warpx.moving_window_dir = 2 warpx.moving_window_v = 1.0 # in units of the speed of light -warpx.do_plasma_injection = 1 -warpx.num_injected_species = 1 -warpx.injected_plasma_species = 1 -warpx.injected_plasma_density = 1e22 -warpx.injected_plasma_ppc = 4 +warpx.do_plasma_injection = 0 +#warpx.num_injected_species = 1 +#warpx.injected_plasma_species = 1 +#warpx.injected_plasma_density = 1e22 +#warpx.injected_plasma_ppc = 4 # --- Initialize the simulation boxlib = BoxLib() @@ -169,9 +229,22 @@ warpx.init() set_initial_conditions(ncells, domain_min, domain_max) -for i in range(max_step + 1): +old_x = warpx.getProbLo(warpx.moving_window_dir) +new_x = old_x +for i in range(1, max_step + 1): + + # check whether the moving window has updated + num_shift = int( 0.5 + (new_x - old_x) / dx[warpx.moving_window_dir]) + if (num_shift != 0): + inject_plasma(num_shift, warpx.moving_window_dir) + domain_min[warpx.moving_window_dir] += num_shift*dx[warpx.moving_window_dir] + domain_max[warpx.moving_window_dir] += num_shift*dx[warpx.moving_window_dir] + warpx.evolve(i) + old_x = new_x + new_x = warpx.getProbLo(warpx.moving_window_dir) + warpx.finalize() boxlib.finalize() -- cgit v1.2.3