-
Notifications
You must be signed in to change notification settings - Fork 57
Add bunch monitor for longitudinal coordinates #504
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
eccortes95
wants to merge
6
commits into
xsuite:main
Choose a base branch
from
eccortes95:main
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from 1 commit
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
de71397
Add bunch monitor for longitudinal coordinates
63cd51c
Add correct python file. h and py file got mixed
eccortes95 1223e27
Edit the documentation
eccortes95 636a4bd
Fix forgotten renames and test constructor
eltos 6aa635f
Add test for bunch monitor
eltos 83d7555
Merge pull request #1 from eltos/bunch-monitor
eccortes95 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,71 @@ | ||
| // ################################## | ||
| // Bunch Monitor | ||
| // | ||
| // Author: Philipp Niedermayer | ||
| // Date: 2023-08-14 | ||
| // Edit: 2024-06-12 | ||
| // ################################## | ||
|
|
||
|
|
||
| #ifndef XTRACK_BEAM_SIZE_MONITOR_H | ||
| #define XTRACK_BEAM_SIZE_MONITOR_H | ||
|
|
||
| #if !defined( C_LIGHT ) | ||
| #define C_LIGHT ( 299792458.0 ) | ||
| #endif /* !defined( C_LIGHT ) */ | ||
|
|
||
| /*gpufun*/ | ||
| void BeamSizeMonitor_track_local_particle(BeamSizeMonitorData el, LocalParticle* part0){ | ||
|
|
||
| // get parameters | ||
| int64_t const start_at_turn = BeamSizeMonitorData_get_start_at_turn(el); | ||
| int64_t particle_id_start = BeamSizeMonitorData_get_particle_id_start(el); | ||
| int64_t particle_id_stop = particle_id_start + BeamSizeMonitorData_get_num_particles(el); | ||
| // Should we do explicit casting to float (?) | ||
| int64_t const harmonic = BeamSizeMonitorData_get_harmonic(el); | ||
| double const frev = BeamSizeMonitorData_get_frev(el); | ||
|
|
||
| BeamSizeMonitorRecord record = BeamSizeMonitorData_getp_data(el); | ||
|
|
||
| int64_t max_slot = BeamSizeMonitorRecord_len_count(record); | ||
|
|
||
| //start_per_particle_block(part0->part) | ||
|
|
||
| int64_t particle_id = LocalParticle_get_particle_id(part); | ||
| if (particle_id_stop < 0 || (particle_id_start <= particle_id && particle_id < particle_id_stop)){ | ||
|
|
||
| // zeta is the absolute path length deviation from the reference particle: zeta = (s - beta0*c*t) | ||
| // but without limits, i.e. it can exceed the circumference (for coasting beams) | ||
| // as the particle falls behind or overtakes the reference particle | ||
| double const zeta = LocalParticle_get_zeta(part); | ||
| double const at_turn = LocalParticle_get_at_turn(part); | ||
| double const beta0 = LocalParticle_get_beta0(part); | ||
|
|
||
| // compute sample index | ||
| int64_t slot = round( harmonic * ( (at_turn-start_at_turn) - frev * zeta/beta0/C_LIGHT )); | ||
|
|
||
| if (slot >= 0 && slot < max_slot){ | ||
|
|
||
| double delta = LocalParticle_get_delta(part); | ||
|
|
||
| /*gpuglmem*/ double* count = BeamSizeMonitorRecord_getp1_count(record, slot); | ||
| atomicAdd(count, 1); | ||
|
|
||
| /*gpuglmem*/ double * zeta_sum = BeamSizeMonitorRecord_getp1_zeta_sum(record, slot); | ||
| atomicAdd(zeta_sum, zeta); | ||
|
|
||
| /*gpuglmem*/ double * delta_sum = BeamSizeMonitorRecord_getp1_delta_sum(record, slot); | ||
| atomicAdd(delta_sum, delta); | ||
|
|
||
| /*gpuglmem*/ double * zeta2_sum = BeamSizeMonitorRecord_getp1_zeta2_sum(record, slot); | ||
| atomicAdd(zeta2_sum, zeta*zeta); | ||
|
|
||
| /*gpuglmem*/ double * delta2_sum = BeamSizeMonitorRecord_getp1_delta2_sum(record, slot); | ||
| atomicAdd(delta2_sum, delta*delta); | ||
| } | ||
| } | ||
| //end_per_particle_block | ||
| } | ||
|
|
||
| #endif | ||
|
|
||
This file contains hidden or 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,71 @@ | ||
| // ################################## | ||
| // Bunch Monitor | ||
| // | ||
| // Author: Philipp Niedermayer | ||
| // Date: 2023-08-14 | ||
| // Edit: 2024-06-12 | ||
| // ################################## | ||
|
|
||
|
|
||
| #ifndef XTRACK_BEAM_SIZE_MONITOR_H | ||
| #define XTRACK_BEAM_SIZE_MONITOR_H | ||
|
|
||
| #if !defined( C_LIGHT ) | ||
| #define C_LIGHT ( 299792458.0 ) | ||
| #endif /* !defined( C_LIGHT ) */ | ||
|
|
||
| /*gpufun*/ | ||
| void BeamSizeMonitor_track_local_particle(BeamSizeMonitorData el, LocalParticle* part0){ | ||
|
|
||
| // get parameters | ||
| int64_t const start_at_turn = BeamSizeMonitorData_get_start_at_turn(el); | ||
| int64_t particle_id_start = BeamSizeMonitorData_get_particle_id_start(el); | ||
| int64_t particle_id_stop = particle_id_start + BeamSizeMonitorData_get_num_particles(el); | ||
| // Should we do explicit casting to float (?) | ||
| int64_t const harmonic = BeamSizeMonitorData_get_harmonic(el); | ||
| double const frev = BeamSizeMonitorData_get_frev(el); | ||
|
|
||
| BeamSizeMonitorRecord record = BeamSizeMonitorData_getp_data(el); | ||
|
|
||
| int64_t max_slot = BeamSizeMonitorRecord_len_count(record); | ||
|
|
||
| //start_per_particle_block(part0->part) | ||
|
|
||
| int64_t particle_id = LocalParticle_get_particle_id(part); | ||
| if (particle_id_stop < 0 || (particle_id_start <= particle_id && particle_id < particle_id_stop)){ | ||
|
|
||
| // zeta is the absolute path length deviation from the reference particle: zeta = (s - beta0*c*t) | ||
| // but without limits, i.e. it can exceed the circumference (for coasting beams) | ||
| // as the particle falls behind or overtakes the reference particle | ||
| double const zeta = LocalParticle_get_zeta(part); | ||
| double const at_turn = LocalParticle_get_at_turn(part); | ||
| double const beta0 = LocalParticle_get_beta0(part); | ||
|
|
||
| // compute sample index | ||
| int64_t slot = round( harmonic * ( (at_turn-start_at_turn) - frev * zeta/beta0/C_LIGHT )); | ||
|
|
||
| if (slot >= 0 && slot < max_slot){ | ||
|
|
||
| double delta = LocalParticle_get_delta(part); | ||
|
|
||
| /*gpuglmem*/ double* count = BeamSizeMonitorRecord_getp1_count(record, slot); | ||
| atomicAdd(count, 1); | ||
|
|
||
| /*gpuglmem*/ double * zeta_sum = BeamSizeMonitorRecord_getp1_zeta_sum(record, slot); | ||
| atomicAdd(zeta_sum, zeta); | ||
|
|
||
| /*gpuglmem*/ double * delta_sum = BeamSizeMonitorRecord_getp1_delta_sum(record, slot); | ||
| atomicAdd(delta_sum, delta); | ||
|
|
||
| /*gpuglmem*/ double * zeta2_sum = BeamSizeMonitorRecord_getp1_zeta2_sum(record, slot); | ||
| atomicAdd(zeta2_sum, zeta*zeta); | ||
|
|
||
| /*gpuglmem*/ double * delta2_sum = BeamSizeMonitorRecord_getp1_delta2_sum(record, slot); | ||
| atomicAdd(delta2_sum, delta*delta); | ||
| } | ||
| } | ||
| //end_per_particle_block | ||
| } | ||
|
|
||
| #endif | ||
|
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm thinking maybe you could use the circumference
line.get_length()instead to simplify the slot calculation.In principle, the zeta correction is not required if the monitor is only used for bunched beams and h≥1. But I think it's good to keep to properly handle RF gymnastics like de- and re-bunching.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree, maybe it could be useful in the future.