Skip to content

Commit d357c42

Browse files
committed
Update Reduce Beam Diagnostics
Remove ref particle quantities. Update examples and docs. Add beta and gamma consistently to ref particle output.
1 parent ca88505 commit d357c42

File tree

5 files changed

+24
-20
lines changed

5 files changed

+24
-20
lines changed

docs/source/dataanalysis/dataanalysis.rst

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ Reference particle:
2727

2828
* ``beta_ref`` reference particle normalized velocity :math:`\beta = v/c`
2929
* ``gamma_ref`` reference particle Lorentz factor :math:`\gamma = 1/\sqrt{1-\beta^2}`
30+
* ``beta_gamma_ref`` reference particle momentum normalized to rest mass :math:`\beta\gamma = p/(mc)`
3031
* ``s_ref`` integrated orbit path length, in meters
3132
* ``x_ref`` horizontal position x, in meters
3233
* ``y_ref`` vertical position y, in meters
@@ -36,8 +37,10 @@ Reference particle:
3637
* ``py_ref`` momentum in y, normalized to mass*c, :math:`p_y = \gamma \beta_y`
3738
* ``pz_ref`` momentum in z, normalized to mass*c, :math:`p_z = \gamma \beta_z`
3839
* ``pt_ref`` energy, normalized by rest energy, :math:`p_t = -\gamma`
39-
* ``mass`` reference rest mass, in kg
40-
* ``charge`` reference charge, in C
40+
* ``mass_ref`` reference rest mass, in kg
41+
* ``charge_ref`` reference charge, in C
42+
43+
Bunch properties: all properties listed in :ref:`Reduced Beam Characteristics <dataanalysis-beam-characteristics>`.
4144

4245
Example to print the integrated orbit path length ``s`` at each beam monitor position:
4346

@@ -66,8 +69,6 @@ The code writes out the values in an ASCII file prefixed ``reduced_beam_characte
6669

6770
* ``step``
6871
Iteration within the simulation
69-
* ``s``, ``ref_beta_gamma``
70-
Reference particle coordinate ``s`` (unit: meter) and relativistic momentum normalized by the particle mass and the speed of light (unit: dimensionless)
7172
* ``x_mean/min/max``, ``y_mean/min/max``, ``t_mean/min/max``
7273
Average / minimum / maximum beam particle position in the dimensions of ``x``, ``y`` (transverse coordinates, unit: meter), and ``t`` (normalized time difference :math:`ct`, unit: meter)
7374
* ``sig_x``, ``sig_y``, ``sig_t``

examples/pytorch_surrogate_model/visualize_ml_surrogate_15_stage.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -291,14 +291,15 @@ def plot_beam_df(
291291
)
292292
args = parser.parse_args()
293293

294+
impactx_surrogate_ref_particle = read_time_series("diags/ref_particle.*")
294295
impactx_surrogate_reduced_diags = read_time_series(
295296
"diags/reduced_beam_characteristics.*"
296297
)
297-
ref_gamma = np.sqrt(1 + impactx_surrogate_reduced_diags["ref_beta_gamma"] ** 2)
298+
ref_gamma = np.sqrt(1 + impactx_surrogate_ref_particle["ref_beta_gamma"] ** 2)
298299
beam_gamma = (
299300
ref_gamma
300301
- impactx_surrogate_reduced_diags["pt_mean"]
301-
* impactx_surrogate_reduced_diags["ref_beta_gamma"]
302+
* impactx_surrogate_ref_particle["ref_beta_gamma"]
302303
)
303304
beam_u = np.sqrt(beam_gamma**2 - 1)
304305
emit_x = impactx_surrogate_reduced_diags["emittance_x"]
@@ -315,13 +316,13 @@ def plot_beam_df(
315316
ax = axT[0][0]
316317
scale = 1e6
317318
ax.plot(
318-
impactx_surrogate_reduced_diags["s"][ix_slice],
319+
impactx_surrogate_ref_particle["s"][ix_slice],
319320
emit_nx[ix_slice] * scale,
320321
"bo",
321322
label="x",
322323
)
323324
ax.plot(
324-
impactx_surrogate_reduced_diags["s"][ix_slice],
325+
impactx_surrogate_ref_particle["s"][ix_slice],
325326
emit_ny[ix_slice] * scale,
326327
"r",
327328
marker=ymarker,
@@ -335,7 +336,7 @@ def plot_beam_df(
335336
ax = axT[0][1]
336337
scale = m_e * c**2 / e * 1e-9
337338
ax.plot(
338-
impactx_surrogate_reduced_diags["s"][ix_slice],
339+
impactx_surrogate_ref_particle["s"][ix_slice],
339340
beam_gamma[ix_slice] * scale,
340341
"go",
341342
)
@@ -346,13 +347,13 @@ def plot_beam_df(
346347
ax = axT[1][0]
347348
scale = 1e6
348349
ax.plot(
349-
impactx_surrogate_reduced_diags["s"][ix_slice],
350+
impactx_surrogate_ref_particle["s"][ix_slice],
350351
impactx_surrogate_reduced_diags["sig_x"][ix_slice] * scale,
351352
"bo",
352353
label="x",
353354
)
354355
ax.plot(
355-
impactx_surrogate_reduced_diags["s"][ix_slice],
356+
impactx_surrogate_ref_particle["s"][ix_slice],
356357
impactx_surrogate_reduced_diags["sig_y"][ix_slice] * scale,
357358
"r",
358359
marker=ymarker,
@@ -367,13 +368,13 @@ def plot_beam_df(
367368
ax = axT[1][1]
368369
scale = 1e3
369370
ax.semilogy(
370-
impactx_surrogate_reduced_diags["s"][ix_slice],
371+
impactx_surrogate_ref_particle["s"][ix_slice],
371372
impactx_surrogate_reduced_diags["sig_px"][ix_slice] * scale,
372373
"bo",
373374
label="x",
374375
)
375376
ax.semilogy(
376-
impactx_surrogate_reduced_diags["s"][ix_slice],
377+
impactx_surrogate_ref_particle["s"][ix_slice],
377378
impactx_surrogate_reduced_diags["sig_py"][ix_slice] * scale,
378379
"r",
379380
marker=ymarker,
@@ -397,7 +398,6 @@ def plot_beam_df(
397398
"diags/openPMD/monitor.bp", io.Access.read_only
398399
)
399400
impactx_surrogate_steps = list(beam_impactx_surrogate_series.iterations)
400-
impactx_surrogate_ref_particle = read_time_series("diags/ref_particle.*")
401401

402402
millimeter = 1.0e3
403403
micron = 1.0e6

src/particles/diagnostics/DiagnosticOutput.cpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,9 @@ namespace impactx::diagnostics
4141
// write file header per MPI RANK
4242
if (!append) {
4343
if (otype == OutputType::PrintRefParticle) {
44-
file_handler << "step s x y z t px py pz pt\n";
44+
file_handler << "step s beta gamma beta_gamma x y z t px py pz pt\n";
4545
} else if (otype == OutputType::PrintReducedBeamCharacteristics) {
46-
file_handler << "step" << " " << "s" << " " << "ref_beta_gamma" << " "
46+
file_handler << "step" << " "
4747
<< "x_mean" << " " << "x_min" << " " << "x_max" << " "
4848
<< "y_mean" << " " << "y_min" << " " << "y_max" << " "
4949
<< "t_mean" << " " << "t_min" << " " << "t_max" << " "
@@ -65,6 +65,9 @@ namespace impactx::diagnostics
6565
RefPart const ref_part = pc.GetRefParticle();
6666

6767
amrex::ParticleReal const s = ref_part.s;
68+
amrex::ParticleReal const beta = ref_part.beta();
69+
amrex::ParticleReal const gamma = ref_part.gamma();
70+
amrex::ParticleReal const beta_gamma = ref_part.beta_gamma();
6871
amrex::ParticleReal const x = ref_part.x;
6972
amrex::ParticleReal const y = ref_part.y;
7073
amrex::ParticleReal const z = ref_part.z;
@@ -77,14 +80,15 @@ namespace impactx::diagnostics
7780
// write particle data to file
7881
file_handler
7982
<< step << " " << s << " "
83+
<< beta << " " << gamma << " " << beta_gamma << " "
8084
<< x << " " << y << " " << z << " " << t << " "
8185
<< px << " " << py << " " << pz << " " << pt << "\n";
8286
} // if( otype == OutputType::PrintRefParticle)
8387
else if (otype == OutputType::PrintReducedBeamCharacteristics) {
8488
std::unordered_map<std::string, amrex::ParticleReal> const rbc =
8589
diagnostics::reduced_beam_characteristics(pc);
8690

87-
file_handler << step << " " << rbc.at("s") << " " << rbc.at("ref_beta_gamma") << " "
91+
file_handler << step << " "
8892
<< rbc.at("x_mean") << " " << rbc.at("x_min") << " " << rbc.at("x_max") << " "
8993
<< rbc.at("y_mean") << " " << rbc.at("y_min") << " " << rbc.at("y_max") << " "
9094
<< rbc.at("t_mean") << " " << rbc.at("t_min") << " " << rbc.at("t_max") << " "

src/particles/diagnostics/ReducedBeamCharacteristics.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -259,8 +259,6 @@ namespace impactx::diagnostics
259259
amrex::ParticleReal const alpha_t = - tpt / emittance_t;
260260

261261
std::unordered_map<std::string, amrex::ParticleReal> data;
262-
data["s"] = ref_part.s; // TODO: remove when the output gets rerouted to openPMD
263-
data["ref_beta_gamma"] = ref_part.beta_gamma(); // TODO: remove when the output gets rerouted to openPMD
264262
data["x_mean"] = x_mean;
265263
data["x_min"] = x_min;
266264
data["x_max"] = x_max;
@@ -294,7 +292,7 @@ namespace impactx::diagnostics
294292
data["beta_x"] = beta_x;
295293
data["beta_y"] = beta_y;
296294
data["beta_t"] = beta_t;
297-
data["charge_C"] = charge; // TODO: remove when the output gets rerouted to openPMD
295+
data["charge_C"] = charge;
298296

299297
return data;
300298
}

src/particles/elements/diagnostics/openPMD.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,7 @@ namespace detail
257257
// reference particle information
258258
beam.setAttribute( "beta_ref", ref_part.beta() );
259259
beam.setAttribute( "gamma_ref", ref_part.gamma() );
260+
beam.setAttribute( "beta_gamma_ref", ref_part.beta_gamma() );
260261
beam.setAttribute( "s_ref", ref_part.s );
261262
beam.setAttribute( "x_ref", ref_part.x );
262263
beam.setAttribute( "y_ref", ref_part.y );

0 commit comments

Comments
 (0)