Skip to content

Commit

Permalink
Minor output fix for long_term_tracking.
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidSagan committed Oct 12, 2024
1 parent 2014136 commit 3d395e1
Showing 1 changed file with 17 additions and 14 deletions.
31 changes: 17 additions & 14 deletions bsim/modules/lt_tracking_mod.f90
Original file line number Diff line number Diff line change
Expand Up @@ -1365,7 +1365,7 @@ subroutine ltt_run_single_mode (lttp, ltt_com, orb_in, beam, ix_bunch, ix_partic
iu_part = lunget()
if (lttp%phase_space_output_file == '') lttp%phase_space_output_file = 'single.dat'
open(iu_part, file = lttp%phase_space_output_file, recl = 300)
call ltt_write_params_header(lttp, ltt_com, iu_part, 1)
call ltt_write_params_header(lttp, ltt_com, iu_part)
write (iu_part, '(2a)') '## Turn ix_ele | x px y py z pz', &
' pc p0c time | spin_x spin_y spin_z | Element'
write (iu_part, ltt_com%ps_fmt) lttp%ix_turn_start, ele_start%ix_ele, orbit%vec, (1.0_rp+orbit%vec(6))*orbit%p0c, &
Expand Down Expand Up @@ -1664,7 +1664,7 @@ subroutine ltt_run_beam_mode (lttp, ltt_com, ix_start_turn, ix_end_turn, beam)

n_live = sum(beam%bunch%n_live)
if (n_live_old - n_live >= n_print_dead_loss) then
print '(2a, i0, a, i0)', trim(prefix_str), ' Cumulative number dead at end of turn ', i_turn, ': ', n_part_tot - n_live
print '(2a, i0, a, i0)', trim(prefix_str), ' Cumulative number dead at turn ', i_turn+1, ': ', n_part_tot - n_live
n_live_old = n_live
endif

Expand All @@ -1681,7 +1681,7 @@ subroutine ltt_run_beam_mode (lttp, ltt_com, ix_start_turn, ix_end_turn, beam)
call run_timer('ABS', time_now)
if (time_now-time1 > lttp%timer_print_dtime .and. .not. ltt_com%using_mpi) then
call out_io (s_blank$, r_name, trim(prefix_str) // ' Ellapsed time (min): ' // &
real_str((time_now-time0)/60, 10, 2) // ', At end of turn: ' // int_str(i_turn))
real_str((time_now-time0)/60, 10, 2) // ', At turn: ' // int_str(i_turn+1))
time1 = time_now
endif

Expand Down Expand Up @@ -1976,9 +1976,9 @@ subroutine write_this_data (lttp, ltt_com, who, base_name, bunch, i_turn, ix_bun
open(iu, file = file_name, recl = 300, access = 'append')
else
open(iu, file = file_name, recl = 300)
call ltt_write_params_header(lttp, ltt_com, iu, ltt_com%n_particle, size(beam%bunch))
call ltt_write_params_header(lttp, ltt_com, iu, ltt_com%n_particle, count(bunch%particle%state == alive$), bunch%ix_bunch)
if (who == 'phase_space') then
write (iu, '(a)') '## Ix Turn | x px y py z pz pc p0c time | spin_x spin_y spin_z State'
write (iu, '(a)') '## Ix Turn | x px y py z pz pc p0c time | spin_x spin_y spin_z State'
else
write (iu, '(a)') '## Ix Turn | Ja Angle_a Jb Angle_b Jc Angle_c | spin_x spin_y spin_z State'
endif
Expand Down Expand Up @@ -2020,12 +2020,12 @@ subroutine write_this_data (lttp, ltt_com, who, base_name, bunch, i_turn, ix_bun
ix = ip + ltt_com%mpi_ix0_particle
if (lttp%only_live_particles_out .and. p%state /= alive$) cycle
if (who == 'phase_space') then
write (iu, '(i9, i9, 8es16.8, 3x, 3f10.6, 4x, a)') ix, i_turn, p%vec, (1.0_rp+p%vec(6))*p%p0c, p%p0c, p%spin, trim(coord_state_name(p%state))
write (iu, '(i9, i9, 9es16.8, 3x, 3f13.9, 4x, a)') ix, i_turn, p%vec, (1.0_rp+p%vec(6))*p%p0c, p%p0c, p%t, p%spin, trim(coord_state_name(p%state))
else
jvec = matmul(n_inv_mat, p%vec-b_params%centroid%vec)
jamp = 0.5_rp * [jvec(1)**2 + jvec(2)**2, jvec(3)**2 + jvec(4)**2, jvec(5)**2 + jvec(6)**2]
jphase = [atan2(jvec(2), jvec(1)), atan2(jvec(4), jvec(3)), atan2(jvec(6), jvec(5))]
write (iu, '(i9, i9, 6es16.8, 3x, 3f10.6, 4x, a)') ix, i_turn, jamp(1), jphase(1), jamp(2), jphase(2), jamp(3), jphase(3), p%spin, trim(coord_state_name(p%state))
write (iu, '(i9, i9, 6es16.8, 3x, 3f13.9, 4x, a)') ix, i_turn, jamp(1), jphase(1), jamp(2), jphase(2), jamp(3), jphase(3), p%spin, trim(coord_state_name(p%state))
endif
enddo

Expand Down Expand Up @@ -2126,7 +2126,7 @@ subroutine ltt_write_custom (lttp, ltt_com, i_turn, orbit, beam)

if (i_turn == 0 .or. lttp%averages_output_every_n_turns == -1) then
open(iu, file = lttp%custom_output_file, recl = 2000)
call ltt_write_params_header(lttp, ltt_com, iu, n_particle, n_bunch)
call ltt_write_params_header(lttp, ltt_com, iu)
line = '#'
do i = 1, size(lttp%column)
col => lttp%column(i)
Expand Down Expand Up @@ -2303,21 +2303,24 @@ end subroutine ltt_write_beam_file
!-------------------------------------------------------------------------------------------
!-------------------------------------------------------------------------------------------

subroutine ltt_write_params_header(lttp, ltt_com, iu, n_particle, n_bunch)
subroutine ltt_write_params_header(lttp, ltt_com, iu, n_particle, n_alive, ix_bunch)

type (ltt_params_struct) lttp
type (ltt_com_struct), target :: ltt_com

integer, optional :: n_bunch
integer iu, n_particle
integer, optional :: n_particle, n_alive, ix_bunch
integer iu

!

write (iu, '(3a)') '# lattice = ', quote(lttp%lat_file)
write (iu, '(3a)') '# simulation_mode = ', quote(lttp%simulation_mode)
write (iu, '(a, i8)') '# n_bunch = ', integer_option(1, n_bunch)
write (iu, '(a, i8)') '# n_particle = ', n_particle
write (iu, '(a, i8)') '# n_turns = ', lttp%n_turns
if (present(n_particle)) then
write (iu, '(a, i8)') '# ix_bunch = ', ix_bunch
write (iu, '(a, i8)') '# n_turns = ', lttp%n_turns
write (iu, '(a, i8)') '# n_particle = ', n_particle
write (iu, '(a, i8)') '# n_alive = ', n_alive
endif
write (iu, '(a, l1)') '# ramping_on = ', lttp%ramping_on
write (iu, '(a, l1)') '# ramp_update_each_particle = ', lttp%ramp_update_each_particle
write (iu, '(a, l1)') '# ramp_particle_energy_without_rf = ', lttp%ramp_particle_energy_without_rf
Expand Down

0 comments on commit 3d395e1

Please sign in to comment.