-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Test the charge deposition logic & scaling of values.
- Loading branch information
Showing
5 changed files
with
92 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
# -*- coding: utf-8 -*- | ||
|
||
import amrex | ||
from impactx import ImpactX | ||
import matplotlib.pyplot as plt | ||
import numpy as np | ||
|
||
|
||
def test_charge_deposition(): | ||
""" | ||
Deposit charge and access/plot it | ||
""" | ||
impactX = ImpactX() | ||
|
||
impactX.load_inputs_file("examples/fodo/input_fodo.in") | ||
|
||
impactX.init_grids() | ||
impactX.init_beam_distribution_from_inputs() | ||
impactX.init_lattice_elements_from_inputs() | ||
|
||
impactX.evolve() | ||
|
||
f = plt.figure() | ||
ax = f.gca() | ||
lev = 0 | ||
rho = impactX.rho(lev) | ||
print(f"rho={rho}") | ||
print(f"rho.sum={rho.sum(0)}") | ||
|
||
gm = impactX.Geom(lev) | ||
print(f"gm={gm}") | ||
|
||
for mfi in rho: | ||
bx = mfi.validbox() | ||
#rbx = amrex.RealBox(bx, gm.CellSize(), gm.ProbLo()) | ||
print(f"bx={bx}") | ||
#print(f"rbx={rbx}") | ||
|
||
arr = rho.array(mfi) | ||
arr_np = np.array(arr, copy=False) | ||
|
||
half_z = arr_np.shape[1] // 2 | ||
im = ax.imshow( | ||
arr_np[0, half_z, ...] | ||
#extent=rbx | ||
) | ||
f.colorbar(im) | ||
plt.show() | ||
|
||
|
||
if __name__ == '__main__': | ||
amrex.initialize([ | ||
# print AMReX status messages | ||
"amrex.verbose=2", | ||
# throw exceptions and create core dumps instead of | ||
# AMReX backtrace files: allows to attach to | ||
# debuggers | ||
"amrex.throw_exception=1", | ||
"amrex.signal_handling=0", | ||
# abort GPU runs if out-of-memory instead of swapping to host RAM | ||
"amrex.abort_on_out_of_gpu_memory=1" | ||
]) | ||
|
||
test_charge_deposition() | ||
|
||
amrex.finalize() |