Skip to content

Commit

Permalink
Add [x*uy], [y*ux], [ux/uz], [uy/uz] to beam in-situ diagnostics (#1058)
Browse files Browse the repository at this point in the history
* clean up insitu diagnostic

* use amrex::constexpr_for

* add comments

* add xuy yux uxuz uyuz to beam insitu

* add jz_beam to field insitu
  • Loading branch information
AlexanderSinn authored Feb 13, 2024
1 parent a94f580 commit 2837d31
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 14 deletions.
4 changes: 2 additions & 2 deletions docs/source/run/parameters.rst
Original file line number Diff line number Diff line change
Expand Up @@ -924,7 +924,7 @@ In-situ diagnostics compute slice quantities (1 number per quantity per longitud
For particle beams, they can be used to calculate the main characterizing beam parameters (width, energy spread, emittance, etc.), from which most common beam parameters (e.g. slice and projected emittance, etc.) can be computed. Additionally, the plasma particle properties (e.g, the temperature) can be calculated.

For particle beams, the following quantities are calculated per slice and stored:
``sum(w), [x], [x^2], [y], [y^2], [z], [z^2], [ux], [ux^2], [uy], [uy^2], [uz], [uz^2], [x*ux], [y*uy], [z*uz], [ga], [ga^2], np``.
``sum(w), [x], [x^2], [y], [y^2], [z], [z^2], [ux], [ux^2], [uy], [uy^2], [uz], [uz^2], [x*ux], [y*uy], [z*uz], [x*uy], [y*ux], [ux/uz], [uy/uz], [ga], [ga^2], np``.
For plasma particles, the following quantities are calculated per slice and stored:
``sum(w), [x], [x^2], [y], [y^2], [ux], [ux^2], [uy], [uy^2], [uz], [uz^2], [ga], [ga^2], np``.
Thereby, "[]" stands for averaging over all particles in the current slice,
Expand All @@ -933,7 +933,7 @@ Averages and totals over all slices are also provided for convenience under the
respective ``average`` and ``total`` subcategories.

For the field in-situ diagnostics, the following quantities are calculated per slice and stored:
``[Ex^2], [Ey^2], [Ez^2], [Bx^2], [By^2], [Bz^2], [ExmBy^2], [EypBx^2], [Ez*jz_beam]``.
``[Ex^2], [Ey^2], [Ez^2], [Bx^2], [By^2], [Bz^2], [ExmBy^2], [EypBx^2], [jz_beam], [Ez*jz_beam]``.
Thereby, "[]" stands for averaging over all cells in the current slice.
These quantities can be used to calculate the energy stored in the fields.

Expand Down
2 changes: 1 addition & 1 deletion src/fields/Fields.H
Original file line number Diff line number Diff line change
Expand Up @@ -522,7 +522,7 @@ private:
/** If any plasma species has a neutralizing background */
bool m_any_neutral_background = false;
/** Number of real field properties for in-situ per-slice reduced diagnostics. */
static constexpr int m_insitu_nrp = 9;
static constexpr int m_insitu_nrp = 10;
/** How often the insitu field diagnostics should be computed and written
* Default is 0, meaning no output */
int m_insitu_period {0};
Expand Down
9 changes: 6 additions & 3 deletions src/fields/Fields.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1302,7 +1302,8 @@ Fields::InSituComputeDiags (int step, amrex::Real time, int islice, const amrex:
pow<2>(arr(i,j,Bz)), // 5 [Bz^2]
pow<2>(arr(i,j,ExmBy)), // 6 [ExmBy^2]
pow<2>(arr(i,j,EypBx)), // 7 [EypBx^2]
arr(i,j,Ez)*arr(i,j,jz_beam) // 8 [Ez*jz_beam]
arr(i,j,jz_beam), // 8 [jz_beam]
arr(i,j,Ez)*arr(i,j,jz_beam) // 9 [Ez*jz_beam]
};
});
}
Expand Down Expand Up @@ -1359,7 +1360,8 @@ Fields::InSituWriteToFile (int step, amrex::Real time, const amrex::Geometry& ge
{"[Bz^2]" , &m_insitu_rdata[5*nslices], nslices},
{"[ExmBy^2]", &m_insitu_rdata[6*nslices], nslices},
{"[EypBx^2]", &m_insitu_rdata[7*nslices], nslices},
{"[Ez*jz_beam]", &m_insitu_rdata[8*nslices], nslices},
{"[jz_beam]", &m_insitu_rdata[8*nslices], nslices},
{"[Ez*jz_beam]", &m_insitu_rdata[9*nslices], nslices},
{"integrated", {
{"[Ex^2]" , &m_insitu_sum_rdata[0]},
{"[Ey^2]" , &m_insitu_sum_rdata[1]},
Expand All @@ -1369,7 +1371,8 @@ Fields::InSituWriteToFile (int step, amrex::Real time, const amrex::Geometry& ge
{"[Bz^2]" , &m_insitu_sum_rdata[5]},
{"[ExmBy^2]", &m_insitu_sum_rdata[6]},
{"[EypBx^2]", &m_insitu_sum_rdata[7]},
{"[Ez*jz_beam]", &m_insitu_sum_rdata[8]}
{"[jz_beam]", &m_insitu_sum_rdata[8]},
{"[Ez*jz_beam]", &m_insitu_sum_rdata[9]}
}}
};

Expand Down
2 changes: 1 addition & 1 deletion src/particles/beam/BeamParticleContainer.H
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ private:

int m_nslices; /**< number of z slices of the domain */
/** Number of real beam properties for in-situ per-slice reduced diagnostics. */
static constexpr int m_insitu_nrp = 18;
static constexpr int m_insitu_nrp = 22;
/** Number of int beam properties for in-situ per-slice reduced diagnostics. */
static constexpr int m_insitu_nip = 1;
/** Per-slice real beam properties */
Expand Down
28 changes: 21 additions & 7 deletions src/particles/beam/BeamParticleContainer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -470,6 +470,8 @@ BeamParticleContainer::InSituComputeDiags (int islice)
const amrex::Real uz = ptd.rdata(BeamIdx::uz)[ip] * clight_inv;
const amrex::Real w = ptd.rdata(BeamIdx::w)[ip];

const amrex::Real uz_inv = uz == 0._rt ? 0._rt : 1._rt / uz;

if (ptd.id(ip) < 0 || x*x + y*y > insitu_radius_sq) {
return amrex::IdentityTuple(ReduceTuple{}, reduce_op);
}
Expand All @@ -491,9 +493,13 @@ BeamParticleContainer::InSituComputeDiags (int islice)
w*x*ux, // 13 [x*ux]
w*y*uy, // 14 [y*uy]
w*z*uz, // 15 [z*uz]
w*gamma, // 16 [ga]
w*gamma*gamma, // 17 [ga^2]
1 // 18 Np
w*x*uy, // 16 [x*uy]
w*y*ux, // 17 [y*ux]
w*ux*uz_inv, // 18 [ux/uz]
w*uy*uz_inv, // 19 [uy/uz]
w*gamma, // 20 [ga]
w*gamma*gamma, // 21 [ga^2]
1 // 22 Np
};
});

Expand Down Expand Up @@ -569,8 +575,12 @@ BeamParticleContainer::InSituWriteToFile (int step, amrex::Real time, const amre
{"[x*ux]" , &m_insitu_rdata[13*nslices], nslices},
{"[y*uy]" , &m_insitu_rdata[14*nslices], nslices},
{"[z*uz]" , &m_insitu_rdata[15*nslices], nslices},
{"[ga]" , &m_insitu_rdata[16*nslices], nslices},
{"[ga^2]" , &m_insitu_rdata[17*nslices], nslices},
{"[x*uy]" , &m_insitu_rdata[16*nslices], nslices},
{"[y*ux]" , &m_insitu_rdata[17*nslices], nslices},
{"[ux/uz]" , &m_insitu_rdata[18*nslices], nslices},
{"[uy/uz]" , &m_insitu_rdata[19*nslices], nslices},
{"[ga]" , &m_insitu_rdata[20*nslices], nslices},
{"[ga^2]" , &m_insitu_rdata[21*nslices], nslices},
{"sum(w)" , &m_insitu_rdata[0], nslices},
{"Np" , &m_insitu_idata[0], nslices},
{"average" , {
Expand All @@ -589,8 +599,12 @@ BeamParticleContainer::InSituWriteToFile (int step, amrex::Real time, const amre
{"[x*ux]", &(m_insitu_sum_rdata[13] /= sum_w0)},
{"[y*uy]", &(m_insitu_sum_rdata[14] /= sum_w0)},
{"[z*uz]", &(m_insitu_sum_rdata[15] /= sum_w0)},
{"[ga]" , &(m_insitu_sum_rdata[16] /= sum_w0)},
{"[ga^2]", &(m_insitu_sum_rdata[17] /= sum_w0)}
{"[x*uy]", &(m_insitu_sum_rdata[16] /= sum_w0)},
{"[y*ux]", &(m_insitu_sum_rdata[17] /= sum_w0)},
{"[ux/uz]",&(m_insitu_sum_rdata[18] /= sum_w0)},
{"[uy/uz]",&(m_insitu_sum_rdata[19] /= sum_w0)},
{"[ga]" , &(m_insitu_sum_rdata[20] /= sum_w0)},
{"[ga^2]", &(m_insitu_sum_rdata[21] /= sum_w0)}
}},
{"total" , {
{"sum(w)", &m_insitu_sum_rdata[0]},
Expand Down

0 comments on commit 2837d31

Please sign in to comment.