Skip to content

Commit 069fea5

Browse files
committed
Update calculation
1 parent 12b6636 commit 069fea5

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

examples/multi_stage/analysis_script.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,13 @@
99
def get_emittance(ts, t):
1010
"""Calculate the beam emittance at the given time step."""
1111
w, x, ux = ts.get_particle(["w", "x", "ux"], t=t)
12-
x2 = np.average(x**2, weights=w)
13-
xu = np.average(x * ux, weights=w)
14-
return np.sqrt(x2 * np.average((ux - xu / x2 * x) ** 2, weights=w))
15-
12+
if len(w) <= 2:
13+
return 0
14+
else:
15+
x2 = np.average(x**2, weights=w)
16+
u2 = np.average(ux**2, weights=w)
17+
xu = np.average(x * ux, weights=w)
18+
return np.sqrt(x2 * u2 - xu**2)
1619

1720
def analyze_simulation(simulation_directory, output_params):
1821
"""Analyze the output of the WarpX simulation.

0 commit comments

Comments
 (0)