Skip to content
This repository was archived by the owner on Aug 28, 2024. It is now read-only.

Commit

Permalink
Added back user control over enounter check algorithm
Browse files Browse the repository at this point in the history
  • Loading branch information
daminton committed Mar 8, 2023
1 parent f1eab7c commit 2ed8bc0
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 63 deletions.
3 changes: 0 additions & 3 deletions src/base/base_module.f90
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,8 @@ module base

! The following are used internally, and are not set by the user, but instead are determined by the input value of INTERACTION_LOOPS
logical :: lflatten_interactions = .false. !! Use the flattened upper triangular matrix for pl-pl interaction loops
logical :: ladaptive_interactions = .false. !! Adaptive interaction loop is turned on (choose between TRIANGULAR and FLAT based on periodic timing tests)
logical :: lencounter_sas_plpl = .false. !! Use the Sort and Sweep algorithm to prune the encounter list before checking for close encounters
logical :: lencounter_sas_pltp = .false. !! Use the Sort and Sweep algorithm to prune the encounter list before checking for close encounters
logical :: ladaptive_encounters_plpl = .false. !! Adaptive encounter checking is turned on (choose between TRIANGULAR or SORTSWEEP based on periodic timing tests)
logical :: ladaptive_encounters_pltp = .false. !! Adaptive encounter checking is turned on (choose between TRIANGULAR or SORTSWEEP based on periodic timing tests)

! Logical flags to turn on or off various features of the code
logical :: lrhill_present = .false. !! Hill radii are given as an input rather than calculated by the code (can be used to inflate close encounter regions manually)
Expand Down
35 changes: 17 additions & 18 deletions src/encounter/encounter_check.f90
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,12 @@ module subroutine encounter_check_all_plpl(param, npl, r, v, renc, dt, nenc, ind
integer(I4B), dimension(:), allocatable, intent(out) :: index1 !! List of indices for body 1 in each encounter
integer(I4B), dimension(:), allocatable, intent(out) :: index2 !! List of indices for body 2 in each encounter
logical, dimension(:), allocatable, intent(out) :: lvdotr !! Logical flag indicating the sign of v .dot. x
! Internals
!type(interaction_timer), save :: itimer
logical, save :: lfirst = .true.
logical, save :: skipit = .false. ! This will be used to ensure that the sort & sweep subroutine gets called at least once before timing it so that the extent array is nearly sorted when it is timed
integer(I8B) :: nplpl = 0_I8B


!call encounter_check_all_triangular_plpl(npl, r, v, renc, dt, nenc, index1, index2, lvdotr)
call encounter_check_all_sort_and_sweep_plpl(npl, r, v, renc, dt, nenc, index1, index2, lvdotr)
if (param%lencounter_sas_plpl) then
call encounter_check_all_sort_and_sweep_plpl(npl, r, v, renc, dt, nenc, index1, index2, lvdotr)
else
call encounter_check_all_triangular_plpl(npl, r, v, renc, dt, nenc, index1, index2, lvdotr)
end if

return
end subroutine encounter_check_all_plpl
Expand Down Expand Up @@ -80,13 +77,16 @@ module subroutine encounter_check_all_plplm(param, nplm, nplt, rplm, vplm, rplt,

allocate(tmp_param, source=param)

! Turn off adaptive encounter checks for the pl-pl group
tmp_param%ladaptive_encounters_plpl = .false.

! Start with the pl-pl group
call encounter_check_all_plpl(tmp_param, nplm, rplm, vplm, rencm, dt, nenc, index1, index2, lvdotr)

call encounter_check_all_triangular_plplm(nplm, nplt, rplm, vplm, rplt, vplt, rencm, renct, dt, plmplt_nenc, plmplt_index1, plmplt_index2, plmplt_lvdotr)
if (param%lencounter_sas_plpl) then
call encounter_check_all_sort_and_sweep_plplm(nplm, nplt, rplm, vplm, rplt, vplt, rencm, renct, dt, &
plmplt_nenc, plmplt_index1, plmplt_index2, plmplt_lvdotr)
else
call encounter_check_all_triangular_plplm(nplm, nplt, rplm, vplm, rplt, vplt, rencm, renct, dt, &
plmplt_nenc, plmplt_index1, plmplt_index2, plmplt_lvdotr)
end if

if (plmplt_nenc > 0) then ! Consolidate the two lists
allocate(itmp(nenc+plmplt_nenc))
Expand Down Expand Up @@ -134,13 +134,12 @@ module subroutine encounter_check_all_pltp(param, npl, ntp, rpl, vpl, rtp, vtp,
integer(I4B), dimension(:), allocatable, intent(out) :: index1 !! List of indices for body 1 in each encounter
integer(I4B), dimension(:), allocatable, intent(out) :: index2 !! List of indices for body 2 in each encounter
logical, dimension(:), allocatable, intent(out) :: lvdotr !! Logical flag indicating the sign of v .dot. x
! Internals
! type(interaction_timer), save :: itimer
logical, save :: lfirst = .true.
logical, save :: lsecond = .false.
integer(I8B) :: npltp = 0_I8B

call encounter_check_all_triangular_pltp(npl, ntp, rpl, vpl, rtp, vtp, renc, dt, nenc, index1, index2, lvdotr)
if (param%lencounter_sas_pltp) then
call encounter_check_all_sort_and_sweep_pltp(npl, ntp, rpl, vpl, rtp, vtp, renc, dt, nenc, index1, index2, lvdotr)
else
call encounter_check_all_triangular_pltp(npl, ntp, rpl, vpl, rtp, vtp, renc, dt, nenc, index1, index2, lvdotr)
end if

return
end subroutine encounter_check_all_pltp
Expand Down
54 changes: 12 additions & 42 deletions src/swiftest/swiftest_io.f90
Original file line number Diff line number Diff line change
Expand Up @@ -2270,72 +2270,42 @@ module subroutine swiftest_io_param_reader(self, unit, iotype, v_list, iostat, i
end if

select case(trim(adjustl(param%interaction_loops)))
case("ADAPTIVE")
param%ladaptive_interactions = .true.
param%lflatten_interactions = .true.
call swiftest_io_log_start(param, INTERACTION_TIMER_LOG_OUT, "Interaction loop timer logfile")
call swiftest_io_log_one_message(INTERACTION_TIMER_LOG_OUT, "Diagnostic values: loop style, time count, nplpl, metric")
case("TRIANGULAR")
param%ladaptive_interactions = .false.
param%lflatten_interactions = .false.
case("FLAT")
param%ladaptive_interactions = .false.
param%lflatten_interactions = .true.
case default
write(*,*) "Unknown value for parameter INTERACTION_LOOPS: -> ",trim(adjustl(param%interaction_loops))
write(*,*) "Must be one of the following: TRIANGULAR, FLAT, or ADAPTIVE"
write(*,*) "Using default value of ADAPTIVE"
param%interaction_loops = "ADAPTIVE"
param%ladaptive_interactions = .true.
param%lflatten_interactions = .true.
call swiftest_io_log_start(param, INTERACTION_TIMER_LOG_OUT, "Interaction loop timer logfile")
call swiftest_io_log_one_message(INTERACTION_TIMER_LOG_OUT, "Diagnostic values: loop style, time count, nplpl, metric")
write(*,*) "Must be one of the following: TRIANGULAR or FLAT"
write(*,*) "Using default value of TRIANGULAR"
param%interaction_loops = "TRIANGULAR"
param%lflatten_interactions = .false.
end select

select case(trim(adjustl(param%encounter_check_plpl)))
case("ADAPTIVE")
param%ladaptive_encounters_plpl = .true.
param%lencounter_sas_plpl = .true.
call swiftest_io_log_start(param, ENCOUNTER_PLPL_TIMER_LOG_OUT, "Encounter check loop timer logfile")
call swiftest_io_log_one_message(ENCOUNTER_PLPL_TIMER_LOG_OUT, "Diagnostic values: loop style, time count, nplpl, metric")
case("TRIANGULAR")
param%ladaptive_encounters_plpl = .false.
param%lencounter_sas_plpl = .false.
case("SORTSWEEP")
param%ladaptive_encounters_plpl = .false.
param%lencounter_sas_plpl = .true.
case default
write(*,*) "Unknown value for parameter ENCOUNTER_CHECK_PLPL: -> ",trim(adjustl(param%encounter_check_plpl))
write(*,*) "Must be one of the following: TRIANGULAR, SORTSWEEP, or ADAPTIVE"
write(*,*) "Using default value of ADAPTIVE"
param%encounter_check_plpl = "ADAPTIVE"
param%ladaptive_encounters_plpl = .true.
param%lencounter_sas_plpl = .true.
call swiftest_io_log_start(param, ENCOUNTER_PLPL_TIMER_LOG_OUT, "Encounter check loop timer logfile")
call swiftest_io_log_one_message(ENCOUNTER_PLPL_TIMER_LOG_OUT, "Diagnostic values: loop style, time count, nplpl, metric")
write(*,*) "Must be one of the following: TRIANGULAR or SORTSWEEP"
write(*,*) "Using default value of TRIANGULAR"
param%encounter_check_plpl = "TRIANGULAR"
param%lencounter_sas_plpl = .false.
end select

select case(trim(adjustl(param%encounter_check_pltp)))
case("ADAPTIVE")
param%ladaptive_encounters_pltp = .true.
param%lencounter_sas_pltp = .true.
call swiftest_io_log_start(param, ENCOUNTER_PLTP_TIMER_LOG_OUT, "Encounter check loop timer logfile")
call swiftest_io_log_one_message(ENCOUNTER_PLTP_TIMER_LOG_OUT, "Diagnostic values: loop style, time count, npltp, metric")
case("TRIANGULAR")
param%ladaptive_encounters_pltp = .false.
param%lencounter_sas_pltp = .false.
case("SORTSWEEP")
param%ladaptive_encounters_pltp = .false.
param%lencounter_sas_pltp = .true.
case default
write(*,*) "Unknown value for parameter ENCOUNTER_CHECK_PLTP: -> ",trim(adjustl(param%encounter_check_pltp))
write(*,*) "Must be one of the following: TRIANGULAR, SORTSWEEP, or ADAPTIVE"
write(*,*) "Using default value of ADAPTIVE"
param%encounter_check_pltp = "ADAPTIVE"
param%ladaptive_encounters_pltp = .true.
param%lencounter_sas_pltp = .true.
call swiftest_io_log_start(param, ENCOUNTER_PLTP_TIMER_LOG_OUT, "Encounter check loop timer logfile")
call swiftest_io_log_one_message(ENCOUNTER_PLTP_TIMER_LOG_OUT, "Diagnostic values: loop style, time count, npltp, metric")
write(*,*) "Must be one of the following: TRIANGULAR or SORTSWEEP"
write(*,*) "Using default value of TRIANGULAR"
param%encounter_check_pltp = "TRIANGULAR"
param%lencounter_sas_pltp = .false.
end select

iostat = 0
Expand Down

0 comments on commit 2ed8bc0

Please sign in to comment.