Skip to content

Commit

Permalink
Remove additional string for Twiss input (#698)
Browse files Browse the repository at this point in the history
Improve maintainability by removing additional string "from_cs" that allows
for beam initialization from Twiss parameters.
  • Loading branch information
n01r authored Sep 8, 2024
1 parent e784039 commit b43b397
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 16 deletions.
18 changes: 9 additions & 9 deletions docs/source/usage/parameters.rst
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ Initial Beam Distributions
* ``beam.muypy`` (``float``, dimensionless, default: ``0``) correlation Y-Py
* ``beam.mutpt`` (``float``, dimensionless, default: ``0``) correlation T-Pt

* Courant-Snyder / Twiss parameters.
To enable input via CS / Twiss parameters, add the suffix ``_from_cs`` or ``from_twiss`` to the name of the distribution.
* Courant-Snyder (Twiss) parameters.
To enable input via Courant-Snyder (Twiss) parameters, add the suffix ``from_twiss`` to the name of the distribution.
Use the following parameters to characterize it:

* ``beam.alphaX`` (``float``, dimensionless, default: ``0``) CS / Twiss :math:`\alpha` for X
Expand All @@ -59,21 +59,21 @@ Initial Beam Distributions

The following distributions are available:

* ``waterbag`` or ``waterbag_from_cs``/``waterbag_from_twiss`` for initial Waterbag distribution.
* ``waterbag`` or ``waterbag_from_twiss`` for initial Waterbag distribution.

* ``kurth6d`` or ``kurth6d_from_cs``/``kurth6d_from_twiss`` for initial 6D Kurth distribution.
* ``kurth6d`` or ``kurth6d_from_twiss`` for initial 6D Kurth distribution.

* ``gaussian`` or ``gaussian_from_cs``/``gaussian_from_twiss`` for initial 6D Gaussian (normal) distribution.
* ``gaussian`` or ``gaussian_from_twiss`` for initial 6D Gaussian (normal) distribution.

* ``kvdist`` or ``kvdist_from_cs``/``kvdist_from_twiss`` for initial K-V distribution in the transverse plane.
* ``kvdist`` or ``kvdist_from_twiss`` for initial K-V distribution in the transverse plane.
The distribution is uniform in t and Gaussian in pt.

* ``kurth4d`` or ``kurth4d_from_cs``/``kurth4d_from_twiss`` for initial 4D Kurth distribution in the transverse plane.
* ``kurth4d`` or ``kurth4d_from_twiss`` for initial 4D Kurth distribution in the transverse plane.
The distribution is uniform in t and Gaussian in pt.

* ``semigaussian`` or ``semigaussian_from_cs``/``semigaussian_from_twiss`` for initial Semi-Gaussian distribution. The distribution is uniform within a cylinder in (x,y,z) and Gaussian in momenta (px,py,pt).
* ``semigaussian`` or ``semigaussian_from_twiss`` for initial Semi-Gaussian distribution. The distribution is uniform within a cylinder in (x,y,z) and Gaussian in momenta (px,py,pt).

* ``triangle`` or ``triangle_from_cs``/``triangle_from_twiss`` a triangle distribution for laser-plasma acceleration related applications.
* ``triangle`` or ``triangle_from_twiss`` a triangle distribution for laser-plasma acceleration related applications.
A ramped, triangular current profile with a Gaussian energy spread (possibly correlated).
The transverse distribution is a 4D waterbag.

Expand Down
2 changes: 1 addition & 1 deletion examples/fodo/input_fodo_twiss.in
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ beam.units = static
beam.kin_energy = 2.0e3
beam.charge = 1.0e-9
beam.particle = electron
beam.distribution = waterbag_from_cs
beam.distribution = waterbag_from_twiss
beam.alphaX = -1.5905003499999992
beam.alphaY = 1.5905003499999992
beam.alphaT = 0.0
Expand Down
7 changes: 1 addition & 6 deletions src/initialization/InitDistribution.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -266,19 +266,14 @@ namespace impactx
pp_dist.get("distribution", distribution_type);

std::string base_dist_type = distribution_type;
// Position of the underscore for splitting off the suffix in case the distribution name either ends in "_from_twiss" or "_from_cs"
// Position of the underscore for splitting off the suffix in case the distribution name either ends in "_from_twiss"
std::size_t str_pos_from_twiss = distribution_type.rfind("_from_twiss");
std::size_t str_pos_from_cs = distribution_type.rfind("_from_cs");
bool initialize_from_twiss = false;

if (str_pos_from_twiss != std::string::npos) { // "_from_twiss" is found
// Calculate suffix and base type, consider length of "_from_twiss" = 12
base_dist_type = distribution_type.substr(0, str_pos_from_twiss);
initialize_from_twiss = true;
} else if (str_pos_from_cs != std::string::npos) { // "_from_cs" is found
// Calculate suffix and base type, consider length of "_from_cs" = 8
base_dist_type = distribution_type.substr(0, str_pos_from_cs);
initialize_from_twiss = true;
}

/* After separating a potential suffix from its base type, check if the base distribution type is in the set of
Expand Down

0 comments on commit b43b397

Please sign in to comment.