diff options
author | 2021-12-22 15:32:36 -0800 | |
---|---|---|
committer | 2021-12-22 23:32:36 +0000 | |
commit | d411310e45a370cfde872b25baa7a9f20bcf4966 (patch) | |
tree | cbb12f8fc9ba701a9d2a08701aaf46a99ea9ba31 /Examples/Modules | |
parent | f73b3cd49c430c59b6750d5e65dfd19dcf44c752 (diff) | |
download | WarpX-d411310e45a370cfde872b25baa7a9f20bcf4966.tar.gz WarpX-d411310e45a370cfde872b25baa7a9f20bcf4966.tar.zst WarpX-d411310e45a370cfde872b25baa7a9f20bcf4966.zip |
Change _libwarpx.py functions to LibWarpX class methods (#2696)
* Initial attempt at moving function into LibWarpX
* Bugfix - undefined structs in get_particle_theta
This is untested, identified by IDE/visual inspection only
* Unify newlines
* Delete libwarpx.clight (duplicated picmi.py)
See picmi.constants.c
* Change function descriptive comment to docstring
Also remove extra newline in __init__ beginning.
* Replace pywarpx/_libwarpx calls appropriately
* Fix atexit register of finalize function
* Reorder WarpX.py imports for pre-commit
* Use picmi.Simulation.extension = libwarpx alias
This will hopefully preempt user script changes if we restructure things
to allow multiple WarpX runs to be done within a single Python script.
* Fix libwarpx ref in WarpX.getProbLo/getProbHi
* Update get_particle_boundary_buffer doc reference
Diffstat (limited to 'Examples/Modules')
3 files changed, 21 insertions, 24 deletions
diff --git a/Examples/Modules/ParticleBoundaryProcess/PICMI_inputs_reflection.py b/Examples/Modules/ParticleBoundaryProcess/PICMI_inputs_reflection.py index c9903ad22..d7d023ef6 100755 --- a/Examples/Modules/ParticleBoundaryProcess/PICMI_inputs_reflection.py +++ b/Examples/Modules/ParticleBoundaryProcess/PICMI_inputs_reflection.py @@ -2,7 +2,6 @@ # # --- Input file to test particle reflection off an absorbing boundary -import pywarpx from pywarpx import picmi constants = picmi.constants @@ -115,20 +114,20 @@ sim.step(max_steps) # buffer functions as intended ################################################ -n = pywarpx.get_particle_boundary_buffer_size("electrons", 'z_hi') +n = sim.extension.get_particle_boundary_buffer_size("electrons", 'z_hi') print("Number of electrons in upper buffer:", n) assert n == 63 -n = pywarpx.get_particle_boundary_buffer_size("electrons", 'z_lo') +n = sim.extension.get_particle_boundary_buffer_size("electrons", 'z_lo') print("Number of electrons in lower buffer:", n) assert n == 67 -scraped_steps = pywarpx.get_particle_boundary_buffer("electrons", 'z_hi', 'step_scraped', 0) +scraped_steps = sim.extension.get_particle_boundary_buffer("electrons", 'z_hi', 'step_scraped', 0) for arr in scraped_steps: # print(arr) assert all(arr == 4) -scraped_steps = pywarpx.get_particle_boundary_buffer("electrons", 'z_lo', 'step_scraped', 0) +scraped_steps = sim.extension.get_particle_boundary_buffer("electrons", 'z_lo', 'step_scraped', 0) for arr in scraped_steps: # print(arr) assert all(arr == 8) diff --git a/Examples/Modules/ParticleBoundaryScrape/PICMI_inputs_scrape.py b/Examples/Modules/ParticleBoundaryScrape/PICMI_inputs_scrape.py index 90f526e4b..8009da0cc 100755 --- a/Examples/Modules/ParticleBoundaryScrape/PICMI_inputs_scrape.py +++ b/Examples/Modules/ParticleBoundaryScrape/PICMI_inputs_scrape.py @@ -3,7 +3,6 @@ # --- Input file to test the particle scraper and the Python wrappers # --- to access the buffer of scraped particles. -import pywarpx from pywarpx import picmi ########################## @@ -117,25 +116,25 @@ sim.step(max_steps) from mpi4py import MPI as mpi -my_id = pywarpx.getMyProc() +my_id = sim.extension.getMyProc() -n = pywarpx.get_particle_boundary_buffer_size("electrons", 'eb') +n = sim.extension.get_particle_boundary_buffer_size("electrons", 'eb') print(f"Number of electrons in buffer (proc #{my_id}): {n}") assert n == 612 -scraped_steps = pywarpx.get_particle_boundary_buffer("electrons", 'eb', 'step_scraped', 0) +scraped_steps = sim.extension.get_particle_boundary_buffer("electrons", 'eb', 'step_scraped', 0) for arr in scraped_steps: assert all(arr > 40) -weights = pywarpx.get_particle_boundary_buffer("electrons", 'eb', 'w', 0) +weights = sim.extension.get_particle_boundary_buffer("electrons", 'eb', 'w', 0) n = sum(len(arr) for arr in weights) print(f"Number of electrons in this proc's buffer (proc #{my_id}): {n}") n_sum = mpi.COMM_WORLD.allreduce(n, op=mpi.SUM) assert n_sum == 612 # clear the particle buffer -pywarpx.clearParticleBoundaryBuffer() +sim.extension.clearParticleBoundaryBuffer() # confirm that the buffer was cleared -n = pywarpx.get_particle_boundary_buffer_size("electrons", 'eb') +n = sim.extension.get_particle_boundary_buffer_size("electrons", 'eb') print(f"Number of electrons in buffer (proc #{my_id}): {n}") assert n == 0 diff --git a/Examples/Modules/embedded_boundary_python_API/PICMI_inputs_EB_API.py b/Examples/Modules/embedded_boundary_python_API/PICMI_inputs_EB_API.py index 6dea197d3..4619defe1 100755 --- a/Examples/Modules/embedded_boundary_python_API/PICMI_inputs_EB_API.py +++ b/Examples/Modules/embedded_boundary_python_API/PICMI_inputs_EB_API.py @@ -1,6 +1,5 @@ #!/usr/bin/env python3 import numpy as np -import pywarpx from pywarpx import fields, picmi max_steps = 1 @@ -84,10 +83,10 @@ sim.initialize_inputs() sim.step(1) -print("======== Testing pywarpx.get_mesh_edge_lengths =========") +print("======== Testing sim.extension.get_mesh_edge_lengths =========") -ly_slice_x = np.array(pywarpx.get_mesh_edge_lengths(0,1,include_ghosts=False)[0])[int(nx/2),:,:] -lz_slice_x = np.array(pywarpx.get_mesh_edge_lengths(0,2,include_ghosts=False)[0])[int(nx/2),:,:] +ly_slice_x = np.array(sim.extension.get_mesh_edge_lengths(0,1,include_ghosts=False)[0])[int(nx/2),:,:] +lz_slice_x = np.array(sim.extension.get_mesh_edge_lengths(0,2,include_ghosts=False)[0])[int(nx/2),:,:] n_edge_y_lo = int((ny - 30)/2) n_edge_y_hi = int(ny - (ny - 30)/2) @@ -105,8 +104,8 @@ print("Perimeter of the middle x-slice:", perimeter_slice_x) assert np.isclose(perimeter_slice_x, perimeter_slice_x_true, rtol=1e-05, atol=1e-08) -lx_slice_y = np.array(pywarpx.get_mesh_edge_lengths(0,0,include_ghosts=False)[0])[:,int(ny/2),:] -lz_slice_y = np.array(pywarpx.get_mesh_edge_lengths(0,2,include_ghosts=False)[0])[:,int(ny/2),:] +lx_slice_y = np.array(sim.extension.get_mesh_edge_lengths(0,0,include_ghosts=False)[0])[:,int(ny/2),:] +lz_slice_y = np.array(sim.extension.get_mesh_edge_lengths(0,2,include_ghosts=False)[0])[:,int(ny/2),:] n_edge_x_lo = int((nx - 30)/2) n_edge_x_hi = int(nx - (nx - 30)/2) @@ -125,8 +124,8 @@ print("Perimeter of the middle y-slice:", perimeter_slice_y) assert np.isclose(perimeter_slice_y, perimeter_slice_y_true, rtol=1e-05, atol=1e-08) -lx_slice_z = np.array(pywarpx.get_mesh_edge_lengths(0,0,include_ghosts=False)[0])[:,:,int(nz/2)] -ly_slice_z = np.array(pywarpx.get_mesh_edge_lengths(0,1,include_ghosts=False)[0])[:,:,int(nz/2)] +lx_slice_z = np.array(sim.extension.get_mesh_edge_lengths(0,0,include_ghosts=False)[0])[:,:,int(nz/2)] +ly_slice_z = np.array(sim.extension.get_mesh_edge_lengths(0,1,include_ghosts=False)[0])[:,:,int(nz/2)] n_edge_x_lo = int((nx - 30)/2) n_edge_x_hi = int(nx - (nx - 30)/2) @@ -143,9 +142,9 @@ perimeter_slice_z_true = L_cavity*4 print("Perimeter of the middle z-slice:", perimeter_slice_z) assert np.isclose(perimeter_slice_z, perimeter_slice_z_true, rtol=1e-05, atol=1e-08) -print("======== Testing pywarpx.get_mesh_face_areas =========") +print("======== Testing sim.extension.get_mesh_face_areas =========") -Sx_slice = np.sum(np.array(pywarpx.get_mesh_face_areas(0,0,include_ghosts=False)[0])[int(nx/2),:,:]) +Sx_slice = np.sum(np.array(sim.extension.get_mesh_face_areas(0,0,include_ghosts=False)[0])[int(nx/2),:,:]) dx = (xmax-xmin)/nx Ax = dx*dx Sx_slice_true = L_cavity*L_cavity - 2*Ax @@ -153,7 +152,7 @@ print("Area of the middle x-slice:", Sx_slice) assert np.isclose(Sx_slice, Sx_slice_true, rtol=1e-05, atol=1e-08) -Sy_slice = np.sum(np.array(pywarpx.get_mesh_face_areas(0,1,include_ghosts=False)[0])[:,int(ny/2),:]) +Sy_slice = np.sum(np.array(sim.extension.get_mesh_face_areas(0,1,include_ghosts=False)[0])[:,int(ny/2),:]) dy = (ymax-ymin)/ny Ay = dy*dy Sy_slice_true = L_cavity*L_cavity - 2*Ay @@ -161,7 +160,7 @@ print("Area of the middle y-slice:", Sx_slice) assert np.isclose(Sy_slice, Sy_slice_true, rtol=1e-05, atol=1e-08) -Sz_slice = np.sum(np.array(pywarpx.get_mesh_face_areas(0,2,include_ghosts=False)[0])[:,:,int(nz/2)]) +Sz_slice = np.sum(np.array(sim.extension.get_mesh_face_areas(0,2,include_ghosts=False)[0])[:,:,int(nz/2)]) dz = (zmax-zmin)/nz Az = dz*dz Sz_slice_true = L_cavity*L_cavity - 2*Az |