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

Commit

Permalink
More cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
daminton committed Dec 21, 2022
1 parent cc37144 commit a26e615
Show file tree
Hide file tree
Showing 30 changed files with 1,048 additions and 1,120 deletions.
2 changes: 1 addition & 1 deletion src/collision/collision_io.f90
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ module subroutine collision_io_initialize_output(self, param)

667 continue
write(*,*) "Error creating fragmentation output file. " // trim(adjustl(errmsg))
call util_exit(FAILURE)
call swiftest_util_exit(FAILURE)
end subroutine collision_io_initialize_output


Expand Down
2 changes: 1 addition & 1 deletion src/collision/collision_resolve.f90
Original file line number Diff line number Diff line change
Expand Up @@ -635,7 +635,7 @@ subroutine collision_resolve_list(plpl_collision , system, param, t)
plpl_collision%status(i) = collision_resolve_merge(system, param, t)
case default
write(*,*) "Error in swiftest_collision, unrecognized collision regime"
call util_exit(FAILURE)
call swiftest_util_exit(FAILURE)
end select
call collision_history%take_snapshot(param,system, t, "after")
call impactors%reset()
Expand Down
5 changes: 3 additions & 2 deletions src/collision/collision_util.f90
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ module subroutine collision_util_get_energy_momentum(self, system, param, lbefo
if (.not.allocated(tmpsys)) then
write(*,*) "Error in collision_util_get_energy_momentum. " // &
" This must be called with lbefore=.true. at least once before calling it with lbefore=.false."
call util_exit(FAILURE)
call swiftest_util_exit(FAILURE)
end if
select type(tmpsys)
class is (swiftest_nbody_system)
Expand Down Expand Up @@ -345,7 +345,7 @@ module subroutine collision_util_index_map(self)
call self%get_index_values(idvals, tvals)

! Consolidate ids to only unique values
call util_unique(idvals,self%idvals,self%idmap)
call swiftest_util_unique(idvals,self%idvals,self%idmap)
self%nid = size(self%idvals)

! Don't consolidate time values (multiple collisions can happen in a single time step)
Expand Down Expand Up @@ -502,6 +502,7 @@ module subroutine collision_util_set_coordinate_system(self)
return
end subroutine collision_util_set_coordinate_system


subroutine collision_util_save_snapshot(collision_history, snapshot)
!! author: David A. Minton
!!
Expand Down
30 changes: 15 additions & 15 deletions src/encounter/encounter_check.f90
Original file line number Diff line number Diff line change
Expand Up @@ -168,10 +168,10 @@ module subroutine encounter_check_all_plplm(param, nplm, nplt, xplm, vplm, xplt,
call move_alloc(ltmp, lvdotr)
nenc = nenc + plmplt_nenc

call util_sort(index1, ind)
call util_sort_rearrange(index1, ind, nenc)
call util_sort_rearrange(index2, ind, nenc)
call util_sort_rearrange(lvdotr, ind, nenc)
call swiftest_util_sort(index1, ind)
call swiftest_util_sort_rearrange(index1, ind, nenc)
call swiftest_util_sort_rearrange(index2, ind, nenc)
call swiftest_util_sort_rearrange(lvdotr, ind, nenc)

end if

Expand Down Expand Up @@ -565,7 +565,7 @@ subroutine encounter_check_all_triangular_plpl(npl, x, v, renc, dt, nenc, index1
integer(I4B), dimension(:), allocatable, save :: ind_arr
type(collision_list_plpl), dimension(npl) :: lenc

call util_index_array(ind_arr, npl)
call swiftest_util_index_array(ind_arr, npl)

!$omp parallel do default(private) schedule(static)&
!$omp shared(x, v, renc, lenc, ind_arr) &
Expand Down Expand Up @@ -612,7 +612,7 @@ subroutine encounter_check_all_triangular_plplm(nplm, nplt, xplm, vplm, xplt, vp
integer(I4B), dimension(:), allocatable, save :: ind_arr
type(collision_list_plpl), dimension(nplm) :: lenc

call util_index_array(ind_arr, nplt)
call swiftest_util_index_array(ind_arr, nplt)

!$omp parallel do default(private) schedule(dynamic)&
!$omp shared(xplm, vplm, xplt, vplt, rencm, renct, lenc, ind_arr) &
Expand Down Expand Up @@ -659,7 +659,7 @@ subroutine encounter_check_all_triangular_pltp(npl, ntp, xpl, vpl, xtp, vtp, ren
type(collision_list_pltp), dimension(npl) :: lenc
real(DP), dimension(ntp) :: renct

call util_index_array(ind_arr, ntp)
call swiftest_util_index_array(ind_arr, ntp)
renct(:) = 0.0_DP

!$omp parallel do default(private) schedule(dynamic)&
Expand Down Expand Up @@ -807,10 +807,10 @@ subroutine encounter_check_remove_duplicates(n, nenc, index1, index2, lvdotr)
return
end if

call util_sort(index1, ind)
call util_sort_rearrange(index1, ind, nenc)
call util_sort_rearrange(index2, ind, nenc)
call util_sort_rearrange(lvdotr, ind, nenc)
call swiftest_util_sort(index1, ind)
call swiftest_util_sort_rearrange(index1, ind, nenc)
call swiftest_util_sort_rearrange(index2, ind, nenc)
call swiftest_util_sort_rearrange(lvdotr, ind, nenc)

! Get the bounds on the bodies in the first index
ibeg(:) = n
Expand All @@ -836,7 +836,7 @@ subroutine encounter_check_remove_duplicates(n, nenc, index1, index2, lvdotr)
khi = iend(i)
nenci = khi - klo + 1_I8B
if (allocated(ind)) deallocate(ind)
call util_sort(index2(klo:khi), ind)
call swiftest_util_sort(index2(klo:khi), ind)
index2(klo:khi) = itmp(klo - 1_I8B + ind(:))
do j = klo + 1_I8B, khi
if (index2(j) == index2(j - 1_I8B)) lencounter(j) = .false.
Expand Down Expand Up @@ -876,7 +876,7 @@ pure module subroutine encounter_check_sort_aabb_1D(self, n, extent_arr)
! Internals
integer(I8B) :: i, k

call util_sort(extent_arr, self%ind)
call swiftest_util_sort(extent_arr, self%ind)

do concurrent(k = 1_I8B:2_I8B * n)
i = self%ind(k)
Expand Down Expand Up @@ -923,7 +923,7 @@ module subroutine encounter_check_sweep_aabb_double_list(self, n1, n2, r1, v1, r
real(DP), dimension(2*(n1+n2)) :: xind, yind, zind, vxind, vyind, vzind, rencind

ntot = n1 + n2
call util_index_array(ind_arr, ntot)
call swiftest_util_index_array(ind_arr, ntot)

do concurrent(dim = 1:SWEEPDIM)
loverlap_by_dimension(dim,:) = (self%aabb(dim)%ibeg(:) + 1_I8B) < (self%aabb(dim)%iend(:) - 1_I8B)
Expand Down Expand Up @@ -1035,7 +1035,7 @@ module subroutine encounter_check_sweep_aabb_single_list(self, n, x, v, renc, dt
integer(I4B), dimension(:), allocatable, save :: ind_arr
integer(I8B) :: ibeg, iend

call util_index_array(ind_arr, n)
call swiftest_util_index_array(ind_arr, n)
dim = 1

! Sweep the intervals for each of the massive bodies along one dimension
Expand Down
2 changes: 1 addition & 1 deletion src/encounter/encounter_io.f90
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ module subroutine encounter_io_initialize_output(self, param)

667 continue
write(*,*) "Error creating encounter output file. " // trim(adjustl(errmsg))
call util_exit(FAILURE)
call swiftest_util_exit(FAILURE)
end subroutine encounter_io_initialize_output


Expand Down
2 changes: 2 additions & 0 deletions src/encounter/encounter_setup.f90
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ module subroutine encounter_setup_list(self, n)
allocate(self%r2(NDIM,n))
allocate(self%v1(NDIM,n))
allocate(self%v2(NDIM,n))
allocate(self%level(n))

self%tcollision(:) = 0.0_DP
self%lvdotr(:) = .false.
Expand All @@ -97,6 +98,7 @@ module subroutine encounter_setup_list(self, n)
self%r2(:,:) = 0.0_DP
self%v1(:,:) = 0.0_DP
self%v2(:,:) = 0.0_DP
self%level(:) = 0

return
end subroutine encounter_setup_list
Expand Down
60 changes: 34 additions & 26 deletions src/encounter/encounter_util.f90
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,19 @@ module subroutine encounter_util_append_list(self, source, lsource_mask)

nold = self%nenc
nsrc = source%nenc
call util_append(self%lvdotr, source%lvdotr, nold, nsrc, lsource_mask)
call util_append(self%lclosest, source%lclosest, nold, nsrc, lsource_mask)
call util_append(self%status, source%status, nold, nsrc, lsource_mask)
call util_append(self%index1, source%index1, nold, nsrc, lsource_mask)
call util_append(self%index2, source%index2, nold, nsrc, lsource_mask)
call util_append(self%id1, source%id1, nold, nsrc, lsource_mask)
call util_append(self%id2, source%id2, nold, nsrc, lsource_mask)
call util_append(self%r1, source%r1, nold, nsrc, lsource_mask)
call util_append(self%r2, source%r2, nold, nsrc, lsource_mask)
call util_append(self%v1, source%v1, nold, nsrc, lsource_mask)
call util_append(self%v2, source%v2, nold, nsrc, lsource_mask)
call swiftest_util_append(self%tcollision, source%tcollision, nold, nsrc, lsource_mask)
call swiftest_util_append(self%lclosest, source%lclosest, nold, nsrc, lsource_mask)
call swiftest_util_append(self%lvdotr, source%lvdotr, nold, nsrc, lsource_mask)
call swiftest_util_append(self%status, source%status, nold, nsrc, lsource_mask)
call swiftest_util_append(self%index1, source%index1, nold, nsrc, lsource_mask)
call swiftest_util_append(self%index2, source%index2, nold, nsrc, lsource_mask)
call swiftest_util_append(self%id1, source%id1, nold, nsrc, lsource_mask)
call swiftest_util_append(self%id2, source%id2, nold, nsrc, lsource_mask)
call swiftest_util_append(self%r1, source%r1, nold, nsrc, lsource_mask)
call swiftest_util_append(self%r2, source%r2, nold, nsrc, lsource_mask)
call swiftest_util_append(self%v1, source%v1, nold, nsrc, lsource_mask)
call swiftest_util_append(self%v2, source%v2, nold, nsrc, lsource_mask)
call swiftest_util_append(self%level, source%level, nold, nsrc, lsource_mask)
self%nenc = nold + count(lsource_mask(1:nsrc))

return
Expand All @@ -55,8 +57,10 @@ module subroutine encounter_util_copy_list(self, source)
associate(n => source%nenc)
self%nenc = n
self%t = source%t
self%lvdotr(1:n) = source%lvdotr(1:n)
self%lcollision = source%lcollision
self%tcollision(1:n) = source%tcollision(1:n)
self%lclosest(1:n) = source%lclosest(1:n)
self%lvdotr(1:n) = source%lvdotr(1:n)
self%status(1:n) = source%status(1:n)
self%index1(1:n) = source%index1(1:n)
self%index2(1:n) = source%index2(1:n)
Expand All @@ -66,6 +70,7 @@ module subroutine encounter_util_copy_list(self, source)
self%r2(:,1:n) = source%r2(:,1:n)
self%v1(:,1:n) = source%v1(:,1:n)
self%v2(:,1:n) = source%v2(:,1:n)
self%level(1:n) = source%level(1:n)
end associate

return
Expand Down Expand Up @@ -97,8 +102,8 @@ module subroutine encounter_util_dealloc_list(self)
class(encounter_list), intent(inout) :: self

if (allocated(self%tcollision)) deallocate(self%tcollision)
if (allocated(self%lvdotr)) deallocate(self%lvdotr)
if (allocated(self%lclosest)) deallocate(self%lclosest)
if (allocated(self%lvdotr)) deallocate(self%lvdotr)
if (allocated(self%status)) deallocate(self%status)
if (allocated(self%index1)) deallocate(self%index1)
if (allocated(self%index2)) deallocate(self%index2)
Expand All @@ -108,6 +113,7 @@ module subroutine encounter_util_dealloc_list(self)
if (allocated(self%r2)) deallocate(self%r2)
if (allocated(self%v1)) deallocate(self%v1)
if (allocated(self%v2)) deallocate(self%v2)
if (allocated(self%level)) deallocate(self%level)

return
end subroutine encounter_util_dealloc_list
Expand Down Expand Up @@ -276,11 +282,11 @@ module subroutine encounter_util_index_map(self)
call encounter_util_get_vals_storage(self, idvals, tvals)

! Consolidate ids to only unique values
call util_unique(idvals,self%idvals,self%idmap)
call swiftest_util_unique(idvals,self%idvals,self%idmap)
self%nid = size(self%idvals)

! Consolidate time values to only unique values
call util_unique(tvals,self%tvals,self%tmap)
call swiftest_util_unique(tvals,self%tvals,self%tmap)
self%nt = size(self%tvals)

return
Expand Down Expand Up @@ -339,17 +345,19 @@ module subroutine encounter_util_spill_list(self, discards, lspill_list, ldestru
integer(I8B) :: nenc_old

associate(keeps => self)
call util_spill(keeps%lvdotr, discards%lvdotr, lspill_list, ldestructive)
call util_spill(keeps%lclosest, discards%lclosest, lspill_list, ldestructive)
call util_spill(keeps%status, discards%status, lspill_list, ldestructive)
call util_spill(keeps%index1, discards%index1, lspill_list, ldestructive)
call util_spill(keeps%index2, discards%index2, lspill_list, ldestructive)
call util_spill(keeps%id1, discards%id1, lspill_list, ldestructive)
call util_spill(keeps%id2, discards%id2, lspill_list, ldestructive)
call util_spill(keeps%r1, discards%r1, lspill_list, ldestructive)
call util_spill(keeps%r2, discards%r2, lspill_list, ldestructive)
call util_spill(keeps%v1, discards%v1, lspill_list, ldestructive)
call util_spill(keeps%v2, discards%v2, lspill_list, ldestructive)
call swiftest_util_spill(keeps%tcollision, discards%tcollision, lspill_list, ldestructive)
call swiftest_util_spill(keeps%lvdotr, discards%lvdotr, lspill_list, ldestructive)
call swiftest_util_spill(keeps%lclosest, discards%lclosest, lspill_list, ldestructive)
call swiftest_util_spill(keeps%status, discards%status, lspill_list, ldestructive)
call swiftest_util_spill(keeps%index1, discards%index1, lspill_list, ldestructive)
call swiftest_util_spill(keeps%index2, discards%index2, lspill_list, ldestructive)
call swiftest_util_spill(keeps%id1, discards%id1, lspill_list, ldestructive)
call swiftest_util_spill(keeps%id2, discards%id2, lspill_list, ldestructive)
call swiftest_util_spill(keeps%r1, discards%r1, lspill_list, ldestructive)
call swiftest_util_spill(keeps%r2, discards%r2, lspill_list, ldestructive)
call swiftest_util_spill(keeps%v1, discards%v1, lspill_list, ldestructive)
call swiftest_util_spill(keeps%v2, discards%v2, lspill_list, ldestructive)
call swiftest_util_spill(keeps%level, discards%level, lspill_list, ldestructive)

nenc_old = keeps%nenc

Expand Down
9 changes: 5 additions & 4 deletions src/fraggle/fraggle_generate.f90
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,7 @@ subroutine fraggle_generate_tan_vel(collision_system, lfailure)

tol = TOL_INIT
do while(tol < TOL_MIN)
call util_minimize_bfgs(objective_function, nfrag-6, v_t_initial(7:nfrag), tol, MAXLOOP, lfailure, v_t_output)
call swiftest_util_minimize_bfgs(objective_function, nfrag-6, v_t_initial(7:nfrag), tol, MAXLOOP, lfailure, v_t_output)
fragments%v_t_mag(7:nfrag) = v_t_output(:)
! Now that the KE-minimized values of the i>6 fragments are found, calculate the momentum-conserving solution for tangential velociteis
v_t_initial(7:nfrag) = fragments%v_t_mag(7:nfrag)
Expand Down Expand Up @@ -495,7 +495,7 @@ function solve_fragment_tan_vel(lfailure, v_t_mag_input) result(v_t_mag_output)
b(1:3) = -L_lin_others(:)
b(4:6) = fragments%L_budget(:) - fragments%Lspin(:) - L_orb_others(:)
allocate(v_t_mag_output(nfrag))
v_t_mag_output(1:6) = util_solve_linear_system(A, b, 6, lfailure)
v_t_mag_output(1:6) = swiftest_util_solve_linear_system(A, b, 6, lfailure)
if (present(v_t_mag_input)) v_t_mag_output(7:nfrag) = v_t_mag_input(:)
end associate
end select
Expand Down Expand Up @@ -559,7 +559,7 @@ subroutine fraggle_generate_rad_vel(collision_system, lfailure)
integer(I4B), parameter :: MAXLOOP = 100
real(DP) :: ke_radial, tol
integer(I4B) :: i
real(DP), dimension(:), allocatable :: v_r_initial
real(DP), dimension(:), allocatable :: v_r_initial, v_r_output
real(DP), dimension(collision_system%fragments%nbody) :: vnoise
type(lambda_obj) :: objective_function
character(len=STRMAX) :: message
Expand All @@ -584,7 +584,8 @@ subroutine fraggle_generate_rad_vel(collision_system, lfailure)
objective_function = lambda_obj(radial_objective_function)
tol = TOL_INIT
do while(tol < TOL_MIN)
call util_minimize_bfgs(objective_function, nfrag, v_r_initial, tol, MAXLOOP, lfailure, fragments%v_r_mag)
call swiftest_util_minimize_bfgs(objective_function, nfrag, v_r_initial, tol, MAXLOOP, lfailure, v_r_output)
fragments%v_r_mag(1:nfrag) = v_r_output(1:nfrag)
if (.not.lfailure) exit
tol = tol * 2 ! Keep increasing the tolerance until we converge on a solution
v_r_initial(:) = fragments%v_r_mag(:)
Expand Down
2 changes: 1 addition & 1 deletion src/main/swiftest_driver.f90
Original file line number Diff line number Diff line change
Expand Up @@ -170,5 +170,5 @@ program swiftest_driver
end associate
end associate

call util_exit(SUCCESS)
call swiftest_util_exit(SUCCESS)
end program swiftest_driver
2 changes: 1 addition & 1 deletion src/modules/base.f90
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,7 @@ subroutine netcdf_check(status, call_identifier)
if(status /= nf90_noerr) then
if (present(call_identifier)) write(*,*) "NetCDF error in ",trim(call_identifier)
write(*,*) trim(nf90_strerror(status))
call util_exit(FAILURE)
call swiftest_util_exit(FAILURE)
end if

return
Expand Down
1 change: 1 addition & 0 deletions src/modules/collision.f90
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
!! You should have received a copy of the GNU General Public License along with Swiftest.
!! If not, see: https://www.gnu.org/licenses.


module collision
!! author: The Purdue Swiftest Team - David A. Minton, Carlisle A. Wishard, Jennifer L.L. Pouplin, and Jacob R. Elliott
!!
Expand Down
3 changes: 2 additions & 1 deletion src/modules/encounter.f90
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ module encounter
integer(I8B) :: nenc = 0 !! Total number of encounters
real(DP) :: t !! Time of encounter
logical :: lcollision !! Indicates if the encounter resulted in at least one collision
real(DP), dimension(:), allocatable :: tcollision!! Time of collision
real(DP), dimension(:), allocatable :: tcollision !! Time of collision
logical, dimension(:), allocatable :: lclosest !! indicates that thie pair of bodies is in currently at its closest approach point
logical, dimension(:), allocatable :: lvdotr !! relative vdotr flag
integer(I4B), dimension(:), allocatable :: status !! status of the interaction
Expand All @@ -34,6 +34,7 @@ module encounter
real(DP), dimension(:,:), allocatable :: r2 !! the position of body 2 in the encounter
real(DP), dimension(:,:), allocatable :: v1 !! the velocity of body 1 in the encounter
real(DP), dimension(:,:), allocatable :: v2 !! the velocity of body 2 in the encounter
integer(I4B), dimension(:), allocatable :: level !! Recursion level (used in SyMBA)
contains
procedure :: setup => encounter_setup_list !! A constructor that sets the number of encounters and allocates and initializes all arrays
procedure :: append => encounter_util_append_list !! Appends elements from one structure to another
Expand Down
Loading

0 comments on commit a26e615

Please sign in to comment.