From 7ddb3b4e0dfa2c0bc1d53de5eeaf0eeb7ad1ed1c Mon Sep 17 00:00:00 2001 From: David Sagan Date: Wed, 17 Apr 2024 22:56:55 -0400 Subject: [PATCH 1/3] Cleaned up CSR/space charge tracking code selection. --- .../tao_examples/csr_beam_tracking/CSR.tao | 2 +- bmad/multiparticle/beam_mod.f90 | 39 ++++---- changelog.md | 99 ++++++++++++------- tao/code/tao_set_mod.f90 | 2 +- tao/version/tao_version_mod.f90 | 2 +- 5 files changed, 86 insertions(+), 58 deletions(-) diff --git a/bmad-doc/tao_examples/csr_beam_tracking/CSR.tao b/bmad-doc/tao_examples/csr_beam_tracking/CSR.tao index 128a2e2730..56da4caece 100644 --- a/bmad-doc/tao_examples/csr_beam_tracking/CSR.tao +++ b/bmad-doc/tao_examples/csr_beam_tracking/CSR.tao @@ -14,7 +14,7 @@ set space_charge_com ds_track_step = 0.01 set space_charge_com n_bin = 40 set space_charge_com particle_bin_span = 2 set space_charge_com lsc_sigma_cutoff = 0.1 ! Cutoff for the lsc calc. If a bin sigma is < cutoff * sigma_ave then ignore. -set space_charge_com write_csr_wake = T +set space_charge_com diagnostic_output_file = "wake.dat" set bmad_com csr_and_space_charge_on = T diff --git a/bmad/multiparticle/beam_mod.f90 b/bmad/multiparticle/beam_mod.f90 index d721ad9300..6947b8decb 100644 --- a/bmad/multiparticle/beam_mod.f90 +++ b/bmad/multiparticle/beam_mod.f90 @@ -212,7 +212,7 @@ subroutine track1_bunch (bunch, ele, err, centroid, direction, bunch_track) integer, optional :: direction integer i, j, n, im, ix_pass, ixs, ix, n_links -logical csr_sc_on, err, finished, track1_bunch_space_charge_called +logical csr_sc_on, err, finished, sc_fft_on, time_rk_tracking, track1_bunch_space_charge_called character(*), parameter :: r_name = 'track1_bunch' @@ -235,15 +235,18 @@ subroutine track1_bunch (bunch, ele, err, centroid, direction, bunch_track) ! Tracking track1_bunch_space_charge_called = .false. +csr_sc_on = (bmad_com%csr_and_space_charge_on .and. (ele%csr_method /= off$ .or. ele%space_charge_method /= off$)) +sc_fft_on = (ele%space_charge_method == cathode_fft_3d$ .or. ele%space_charge_method == fft_3d$) +time_rk_tracking = (ele%tracking_method == time_runge_kutta$ .or. ele%tracking_method == fixed_step_time_runge_kutta$) + +if (csr_sc_on .and. ele%space_charge_method == cathode_fft_3d$ .and. ele%csr_method /= off$) then + call out_io (s_error$, r_name, 'WITH SPACE_CHARGE_METHOD SET TO CATHODE_FFT_3D, CSR EFFECTS CANNOT BE HANDLED SO', & + 'CSR_METHOD NEEDS TO BE SET TO OFF. FOR LATTICE ELEMENT: ' // ele%name, & + 'ALL PARTICLES OF THE BUNCH WILL BE MARKED AS LOST.') + goto 9000 ! Mark all particles as lost and return +endif -if (ele%space_charge_method == cathode_fft_3d$) then - if (ele%csr_method /= off$) then - call out_io (s_error$, r_name, 'WITH SPACE_CHARGE_METHOD SET TO CATHODE_FFT_3D, CSR EFFECTS CANNOT BE HANDLED SO', & - 'CSR_METHOD NEEDS TO BE SET TO OFF. FOR LATTICE ELEMENT: ' // ele%name, & - 'ALL PARTICLES OF THE BUNCH WILL BE MARKED AS LOST.') - goto 9000 ! Mark all particles as lost and return - endif - +if (csr_sc_on .and. ele%csr_method == off$ .and. sc_fft_on) then if (ele%tracking_method /= time_runge_kutta$ .and. ele%tracking_method /= fixed_step_time_runge_kutta$) then call out_io (s_error$, r_name, 'WITH SPACE_CHARGE_METHOD SET TO CATHODE_FFT_3D, THE TRACKING_METHOD SHOULD BE SET TO', & 'TIME_RUNGE_KUTTA OR FIXED_STEP_TIME_RUNGE_KUTTA. FOR LATTICE ELEMENT: ' // ele%name, & @@ -252,16 +255,18 @@ subroutine track1_bunch (bunch, ele, err, centroid, direction, bunch_track) endif endif -csr_sc_on = (bmad_com%csr_and_space_charge_on .and. (ele%csr_method /= off$ .or. ele%space_charge_method /= off$)) + +if (ele%csr_method /= off$ .and. time_rk_tracking) then + call out_io (s_error$, r_name, 'CSR_METHOD IS NOT OFF FOR LATTICE ELEMENT: ' // ele%name, & + 'THIS IS INCOMPATIBLE WITH TRACKING_METHOD SET TO TIME_RUNGE_KUTTA OR FIXED_STEP_TIME_RUNGE_KUTTA.', & + 'ALL PARTICLES OF THE BUNCH WILL BE MARKED AS LOST.') + goto 9000 ! Mark all particles as lost and return +endif + +! if (csr_sc_on .and. ele%key /= match$) then - if (ele%tracking_method == time_runge_kutta$ .or. ele%tracking_method == fixed_step_time_runge_kutta$) then - if (ele%csr_method /= off$) then - call out_io (s_error$, r_name, 'CSR_METHOD IS NOT OFF FOR LATTICE ELEMENT: ' // ele%name, & - 'THIS IS INCOMPATIBLE WITH TRACKING_METHOD SET TO TIME_RUNGE_KUTTA OR FIXED_STEP_TIME_RUNGE_KUTTA.', & - 'ALL PARTICLES OF THE BUNCH WILL BE MARKED AS LOST.') - goto 9000 ! Mark all particles as lost and return - endif + if (ele%csr_method == off$ .and. sc_fft_on .and. time_rk_tracking) then call track1_bunch_space_charge (bunch, ele, err, bunch_track = bunch_track) track1_bunch_space_charge_called = .true. diff --git a/changelog.md b/changelog.md index 6ff0fe981f..0619c26546 100644 --- a/changelog.md +++ b/changelog.md @@ -11,79 +11,102 @@ Types of entries: - `Security` in case of vulnerabilities. -- 2024/01 Added: extraction line tracking to the long_term_tracking program. -- 2024/01 Added: *INDIVIDUAL* mode to the long_term_tracking program for resonant extraction simulations. +- 2024-04-16 Fixed: `set_ele_attribute` routine will now set err_flag True on error with unknown variable in expression. -- 2024/01 Added: *foil* lattice element for simulating things like charge stripping, emittance smoothing, etc. +- 2024-04-16 Added: New Tao global: `global%beam_dead_cutoff` +- 2024-04-16 Fixed: Bug traced to OMP and multipole caching. Problem is that if auto_bookkeeper is +turned off initially, the cache is not use. Track1_bunch_csr turns it on for speed but +then tracking with OMP gives a race condition when the cache gets initialized during tracking. +- 2024-04-16 Fixed: Ramper bookkeeping when rampers control overlays and groups. +The new bookkeeping is more efficient in terms of computation time. -- 2024-02- +- 2024-04-15 Added: New Tao command: `show rampers`. -- 2024-02- +- 2024-04-06 Changed: Foil element attribute drel_thickness_dx changed to dthickness_dx. -- 2024-02-12 Fixed: Reinstated phase_trombone in closed geometry lattice. +- 2024-03-29 Fixed: Corrected sbend changed attribute bookkeeping for k1 and k2. -- 2024-02-13 Fixed: Phase trombone tune set. +- 2024-03-28 Fixed: m56 calc for standing_wave lcavity. -- 2024-02-16 Fixed: Eigen anal from sigma matrix. +- 2024-03-28 Fixed: Fix setting of lat_sigma_calc_needed logical in Tao. -- 2024-02-18 Fixed: Now long_term_tracking with energy ramping will properly init particles. +- 2024-03-28 Fixed: Tao now checks for call file infinite loop. -- 2024-02-25 Fixed: Now chrom.w_a, etc. datums can be used with open lattice. +- 2024-03-28 Fixed: Fix expression eval when there is an evaluation range in Tao. -- 2024-02-25 Fixed: Spin tracking will not respect element is_on = False setting. +- 2024-03-27 Added: Added `ltt_com%ltt_tracking_happening_now` in long_term_tracking for use in custom code. -- 2024-02-26 Fixed: Correction to `track_a_lcavity` ref time calc. +- 2024-03-27 Added: "Bunch0" combined bunch for averages output in long_term_tracking. -- 2024-03-06 Fixed: Tao now checks for call file infinite loop. +- 2024-03-27 Fixed: Reduced unnecessary output for tune_scan program. -- 2024-03-06 Fixed: Fix radiation calc for taylor element with finite length. +- 2024-03-25 Fixed: Now MPI messages will go through out_io for long_term_tracking. -- 2024-03-06 Fixed: Tao confusion with multiple universes with the same lattice and Rf is to be turned off. +- 2024-03-25 Fixed: Added negative thickness error checking for foil element. -- 2024-03-12 Fixed: long_term_tracking extraction tracking. +- 2024-03-23 Added: `SWAVE` parameter to translation between Bmad and MAD8. -- 2024-03-18 Added: output_only_last_turns and output_combined_bunches parameters to long_term_tracking. +- 2024-03-22 Fixed: Test of particle outside of RF bucket ignoring closed orbit z. + +- 2024-03-21 Added: `ltt%print_info_messages` parameter for long_term_tracking. - 2024-03-20 Fixed: Particle z-calc with beam init and multiple bunches. -- 2024-03-21 Added: `ltt%print_info_messages` parameter for long_term_tracking. +- 2024-03-18 Added: output_only_last_turns and output_combined_bunches parameters to long_term_tracking. -- 2024-03-22 Fixed: Test of particle outside of RF bucket ignoring closed orbit z. +- 2024-03-12 Fixed: long_term_tracking extraction tracking. -- 2024-03-23 Added: `SWAVE` parameter to translation between Bmad and MAD8. +- 2024-03-06 Fixed: Tao confusion with multiple universes with the same lattice and Rf is to be turned off. -- 2024-03-25 Fixed: Added negative thickness error checking for foil element. +- 2024-03-06 Fixed: Fix radiation calc for taylor element with finite length. -- 2024-03-25 Fixed: Now MPI messages will go through out_io for long_term_tracking. +- 2024-03-06 Fixed: Tao now checks for call file infinite loop. -- 2024-03-27 Fixed: Reduced unnecessary output for tune_scan program. +- 2024-02-26 Fixed: Correction to `track_a_lcavity` ref time calc. -- 2024-03-27 Added: "Bunch0" combined bunch for averages output in long_term_tracking. +- 2024-02-25 Fixed: Spin tracking will not respect element is_on = False setting. -- 2024-03-27 Added: Added `ltt_com%ltt_tracking_happening_now` in long_term_tracking for use in custom code. +- 2024-02-25 Fixed: Now chrom.w_a, etc. datums can be used with open lattice. -- 2024-03-28 Fixed: Fix expression eval when there is an evaluation range in Tao. +- 2024-02-18 Fixed: Now long_term_tracking with energy ramping will properly init particles. -- 2024-03-28 Fixed: Tao now checks for call file infinite loop. +- 2024-02-16 Fixed: Eigen anal from sigma matrix. -- 2024-03-28 Fixed: Fix setting of lat_sigma_calc_needed logical in Tao. +- 2024-02-13 Fixed: Phase trombone tune set. -- 2024-03-28 Fixed: m56 calc for standing_wave lcavity. +- 2024-02-12 Fixed: Reinstated phase_trombone in closed geometry lattice. -- 2024-03-29 Fixed: Corrected sbend changed attribute bookkeeping for k1 and k2. +- 2024-02-13 Fixed: Add mode flip warning in Tao. -- 2024-04-06 Changed: Foil element attribute drel_thickness_dx changed to dthickness_dx. +- 2024-02-13 Fixed: Phase trombone tune set. -- 2024-04-15 Added: New Tao command: `show rampers`. +- 2024-02-12 Fixed: Updated tune_scan program to properly insert phase trombone element. -- 2024-04-16 Fixed: Ramper bookkeeping when rampers control overlays and groups. -The new bookkeeping is more efficient in terms of computation time. +- 2024-02-11 Added: `t_center` to `beam_init_struct`. -- 2024-04-16 Fixed: Bug traced to OMP and multipole caching. Problem is that if auto_bookkeeper is -turned off initially, the cache is not use. Track1_bunch_csr turns it on for speed but -then tracking with OMP gives a race condition when the cache gets initialized during tracking. +- 2024-02-10 Added: Basic control_lord (for feedback elements) parsing is done. (#796) -- 2024-04-16 Added: New Tao global: `global%beam_dead_cutoff` +- 2024-02-09 Added: New dispersion derivative. + +- 2024-02-09 Fixed: Fixed aperture_type set for super_slaves. (#792) + +- 2024-02-05 Added: Added energy kick to beambeam tracking. (#766) + +- 2024-01-18 Added: Code for pointing at cartesian_map(N)%term components. + +- 2024-01-17 Fixed: Expression parsing of ...+d+.... + +- 2024-01-15 Fixed: Sliced crab_cavity phase calc. + +- 2024-01-14 Added: *INDIVIDUAL* mode to the long_term_tracking program for resonant extraction simulations. + +- 2024-01-11 Fixed: Linear beambeam spin tracking. + +- 2024-01-11 Fixed: Corrected `ltt_init_tracking` logic for when beam init is needed. + +- 2024-01-11 Fixed: SAD quad to bmad sad_mult translation. + +- 2024-01-11 Added: *foil* lattice element for simulating things like charge stripping, emittance smoothing, etc. diff --git a/tao/code/tao_set_mod.f90 b/tao/code/tao_set_mod.f90 index 8f7c9eb320..037a1e9fc2 100644 --- a/tao/code/tao_set_mod.f90 +++ b/tao/code/tao_set_mod.f90 @@ -660,7 +660,7 @@ subroutine tao_set_space_charge_com_cmd (who, value_str) select case (who) case ('diagnostic_output_file') - space_charge_com%diagnostic_output_file = value_str + space_charge_com%diagnostic_output_file = unquote(value_str) return case ('ds_track_step', 'beam_chamber_height', 'sigma_cutoff') diff --git a/tao/version/tao_version_mod.f90 b/tao/version/tao_version_mod.f90 index 1a87f641b8..e9f0bd7f68 100644 --- a/tao/version/tao_version_mod.f90 +++ b/tao/version/tao_version_mod.f90 @@ -6,5 +6,5 @@ !- module tao_version_mod -character(*), parameter :: tao_version_date = "2024/04/16 11:31:15" +character(*), parameter :: tao_version_date = "2024/04/16 20:45:50" end module From f1d59532e96492d20d7ccb52e4720de9a1de738d Mon Sep 17 00:00:00 2001 From: David Sagan Date: Thu, 2 May 2024 14:56:46 -0400 Subject: [PATCH 2/3] Fix Tao `python space_charge_com` command. --- tao/code/tao_python_cmd.f90 | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/tao/code/tao_python_cmd.f90 b/tao/code/tao_python_cmd.f90 index dbea51deb4..7bf9d83fd9 100644 --- a/tao/code/tao_python_cmd.f90 +++ b/tao/code/tao_python_cmd.f90 @@ -13,9 +13,10 @@ ! ! {type} is the type of the parameter and is one of: ! INT ! Integer number +! INT_ARR ! Integer array. ! REAL ! Real number -! COMPLEX ! Complex number (Re;Im) ! REAL_ARR ! Real array +! COMPLEX ! Complex number (Re;Im) ! LOGIC ! Logical: "T" or "F". ! INUM ! Integer whose allowed values can be obtained using the "python inum" command. ! ENUM ! String whose allowed values can be obtained using the "python enum" command. @@ -6792,8 +6793,8 @@ subroutine tao_python_cmd (input_str) nl=incr(nl); write(li(nl), rmt) 'lsc_sigma_cutoff;REAL;T;', space_charge_com%lsc_sigma_cutoff nl=incr(nl); write(li(nl), rmt) 'particle_sigma_cutoff;REAL;T;', space_charge_com%particle_sigma_cutoff - nl=incr(nl); write(li(nl), imt) 'space_charge_mesh_size;INT;T;', space_charge_com%space_charge_mesh_size - nl=incr(nl); write(li(nl), imt) 'csr3d_mesh_size;INT;T;', space_charge_com%csr3d_mesh_size + nl=incr(nl); write(li(nl), '(a, 3(a, i0))') 'space_charge_mesh_size;INT_ARR;T', (';', space_charge_com%space_charge_mesh_size(j), j = 1, 3) + nl=incr(nl); write(li(nl), '(a, 3(a, i0))') 'csr3d_mesh_size;INT_ARR;T', (';', space_charge_com%csr3d_mesh_size(j), j = 1, 3) nl=incr(nl); write(li(nl), imt) 'n_bin;INT;T;', space_charge_com%n_bin nl=incr(nl); write(li(nl), imt) 'particle_bin_span;INT;T;', space_charge_com%particle_bin_span nl=incr(nl); write(li(nl), imt) 'n_shield_images;INT;T;', space_charge_com%n_shield_images From 49fbba166eaf648739ad94c44c43996ba0549e51 Mon Sep 17 00:00:00 2001 From: David Sagan Date: Mon, 6 May 2024 22:02:42 -0400 Subject: [PATCH 3/3] Fix Tap `cut` command orbit setting --- changelog.md | 2 ++ tao/code/tao_command.f90 | 3 ++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/changelog.md b/changelog.md index 10fe3518c9..f02a5b16ca 100644 --- a/changelog.md +++ b/changelog.md @@ -10,6 +10,8 @@ Types of entries: - `Fixed` for any bug fixes. - `Security` in case of vulnerabilities. +- 2024-05-06 Fixed Tao `cut` command orbit setting. + - 2024-04-24 Removed: srdt_lsq_soln program since it is not supported and Tao has this functionality. - 2024-04-24 Fixed: Foil tracking when there is an offset. diff --git a/tao/code/tao_command.f90 b/tao/code/tao_command.f90 index 395d309e7f..13327f6700 100644 --- a/tao/code/tao_command.f90 +++ b/tao/code/tao_command.f90 @@ -364,7 +364,8 @@ subroutine tao_command (command_line, err_flag, err_is_fatal) case ('-static'); u%model%lat%particle_start = u%model%tao_branch(0)%orbit(0) case ('-zero'); u%model%lat%particle_start%vec = 0 end select - + u%model%tao_branch(0)%orb0 = u%model%lat%particle_start + u%calc%lattice = .true. call tao_lattice_calc (ok)