From 12f3f53c0b499f2020e749d5cfae069ee612399d Mon Sep 17 00:00:00 2001 From: David A Minton Date: Wed, 21 Dec 2022 23:19:35 -0500 Subject: [PATCH] cleanup --- src/CMakeLists.txt | 2 +- src/collision/collision_check.f90 | 2 +- src/collision/collision_resolve.f90 | 14 +-- src/fraggle/fraggle_module.f90 | 22 ++-- src/fraggle/fraggle_resolve.f90 | 165 +++++++++++++--------------- 5 files changed, 95 insertions(+), 110 deletions(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 4f7c53667..7d3eded2a 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -40,8 +40,8 @@ SET(FAST_MATH_FILES ${SRC}/symba/symba_module.f90 ${SRC}/fraggle/fraggle_module.f90 ${SRC}/collision/collision_check.f90 + ${SRC}/collision/collision_generate.f90 ${SRC}/collision/collision_io.f90 - ${SRC}/collision/collision_model.f90 ${SRC}/collision/collision_regime.f90 ${SRC}/collision/collision_resolve.f90 ${SRC}/collision/collision_setup.f90 diff --git a/src/collision/collision_check.f90 b/src/collision/collision_check.f90 index 2fda012bd..7dd35a658 100644 --- a/src/collision/collision_check.f90 +++ b/src/collision/collision_check.f90 @@ -246,7 +246,7 @@ module subroutine collision_check_pltp(self, system, param, t, dt, irec, lany_co write(message, *) "Particle " // trim(adjustl(tp%info(j)%name)) // " (" // trim(adjustl(idstrj)) // ")" & // " collided with massive body " // trim(adjustl(pl%info(i)%name)) // " (" // trim(adjustl(idstri)) // ")" & // " at t = " // trim(adjustl(timestr)) - call swiftest_io_log_one_message(FRAGGLE_LOG_OUT, message) + !call swiftest_io_log_one_message(FRAGGLE_LOG_OUT, message) end if end do diff --git a/src/collision/collision_resolve.f90 b/src/collision/collision_resolve.f90 index 51789cc10..aee398839 100644 --- a/src/collision/collision_resolve.f90 +++ b/src/collision/collision_resolve.f90 @@ -669,13 +669,13 @@ module subroutine collision_resolve_plpl(self, system, param, t, dt, irec) do write(timestr,*) t - call swiftest_io_log_one_message(FRAGGLE_LOG_OUT, "") - call swiftest_io_log_one_message(FRAGGLE_LOG_OUT, "***********************************************************" // & - "***********************************************************") - call swiftest_io_log_one_message(FRAGGLE_LOG_OUT, "Collision between massive bodies detected at time t = " // & - trim(adjustl(timestr))) - call swiftest_io_log_one_message(FRAGGLE_LOG_OUT, "***********************************************************" // & - "***********************************************************") + ! call swiftest_io_log_one_message(FRAGGLE_LOG_OUT, "") + ! call swiftest_io_log_one_message(FRAGGLE_LOG_OUT, "***********************************************************" // & + ! "***********************************************************") + ! call swiftest_io_log_one_message(FRAGGLE_LOG_OUT, "Collision between massive bodies detected at time t = " // & + ! trim(adjustl(timestr))) + ! call swiftest_io_log_one_message(FRAGGLE_LOG_OUT, "***********************************************************" // & + ! "***********************************************************") allocate(tmp_param, source=param) call collision_resolve_list(plpl_collision, system, param, t) diff --git a/src/fraggle/fraggle_module.f90 b/src/fraggle/fraggle_module.f90 index da9dcaf6d..7960a8d44 100644 --- a/src/fraggle/fraggle_module.f90 +++ b/src/fraggle/fraggle_module.f90 @@ -99,20 +99,22 @@ module subroutine fraggle_set_natural_scale_factors(self) class(fraggle_system), intent(inout) :: self !! Fraggle collision system object end subroutine fraggle_set_natural_scale_factors - module function fraggle_resolve_disruption(system, param, t) result(status) + module function fraggle_resolve_disruption(collision_system, nbody_system, param, t) result(status) implicit none - class(swiftest_nbody_system), intent(inout) :: system !! SyMBA nbody system object - class(swiftest_parameters), intent(inout) :: param !! Current run configuration parameters with SyMBA additions - real(DP), intent(in) :: t !! Time of collision - integer(I4B) :: status !! Status flag assigned to this outcome + class(fraggle_system), intent(inout) :: collision_system !! Fraggle collision system object + class(swiftest_nbody_system), intent(inout) :: nbody_system !! Swiftest nbody system object + class(swiftest_parameters), intent(inout) :: param !! Current run configuration parameters with SyMBA additions + real(DP), intent(in) :: t !! Time of collision + integer(I4B) :: status !! Status flag assigned to this outcome end function fraggle_resolve_disruption - module function fraggle_resolve_hitandrun(system, param, t) result(status) + module function fraggle_resolve_hitandrun(collision_system, nbody_system, param, t) result(status) implicit none - class(swiftest_nbody_system), intent(inout) :: system !! SyMBA nbody system object - class(swiftest_parameters), intent(inout) :: param !! Current run configuration parameters with SyMBA additions - real(DP), intent(in) :: t !! Time of collision - integer(I4B) :: status !! Status flag assigned to this outcome + class(fraggle_system), intent(inout) :: collision_system !! Fraggle collision system object + class(swiftest_nbody_system), intent(inout) :: nbody_system !! Swiftest nbody system object + class(swiftest_parameters), intent(inout) :: param !! Current run configuration parameters with SyMBA additions + real(DP), intent(in) :: t !! Time of collision + integer(I4B) :: status !! Status flag assigned to this outcome end function fraggle_resolve_hitandrun module subroutine fraggle_set_original_scale_factors(self) diff --git a/src/fraggle/fraggle_resolve.f90 b/src/fraggle/fraggle_resolve.f90 index 0bf3017a6..41f80aa72 100644 --- a/src/fraggle/fraggle_resolve.f90 +++ b/src/fraggle/fraggle_resolve.f90 @@ -12,16 +12,17 @@ use symba contains - module function fraggle_resolve_disruption(system, param, t) result(status) + module function fraggle_resolve_disruption(collision_system, nbody_system, param, t) result(status) !! author: Jennifer L.L. Pouplin, Carlisle A. Wishard, and David A. Minton !! !! Create the fragments resulting from a non-catastrophic disruption collision !! implicit none ! Arguments - class(swiftest_nbody_system), intent(inout) :: system !! SyMBA nbody system object - class(swiftest_parameters), intent(inout) :: param !! Current run configuration parameters with SyMBA additions - real(DP), intent(in) :: t !! Time of collision + class(fraggle_system), intent(inout) :: collision_system + class(swiftest_nbody_system), intent(inout) :: nbody_system !! Swiftest nbody system object + class(swiftest_parameters), intent(inout) :: param !! Current run configuration parameters with SyMBA additions + real(DP), intent(in) :: t !! Time of collision ! Result integer(I4B) :: status !! Status flag assigned to this outcome ! Internals @@ -30,105 +31,92 @@ module function fraggle_resolve_disruption(system, param, t) result(status) character(len=STRMAX) :: message real(DP) :: dpe - select type(system) - class is (swiftest_nbody_system) - select type(param) - class is (swiftest_parameters) - select type(before => system%collision_system%before) - class is (swiftest_nbody_system) - select type(after => system%collision_system%after) - class is (swiftest_nbody_system) - - associate(collision_system => system%collision_system, impactors => system%collision_system%impactors, fragments => system%collision_system%fragments) + associate(impactors => collision_system%impactors, fragments => collision_system%fragments, pl => nbody_system%pl) + select case(impactors%regime) + case(COLLRESOLVE_REGIME_DISRUPTION) + message = "Disruption between" + case(COLLRESOLVE_REGIME_SUPERCATASTROPHIC) + message = "Supercatastrophic disruption between" + end select + call collision_resolve_collider_message(nbody_system%pl, impactors%id, message) + call swiftest_io_log_one_message(FRAGGLE_LOG_OUT, message) + + ! Collisional fragments will be uniformly distributed around the pre-impact barycenter + call collision_system%set_mass_dist(param) + + ! Generate the position and velocity distributions of the fragments + call fraggle_generate_fragments(collision_system, nbody_system, param, lfailure) + + dpe = collision_system%pe(2) - collision_system%pe(1) + nbody_system%Ecollisions = nbody_system%Ecollisions - dpe + nbody_system%Euntracked = nbody_system%Euntracked + dpe + + if (lfailure) then + call swiftest_io_log_one_message(FRAGGLE_LOG_OUT, "No fragment solution found, so treat as a pure hit-and-run") + status = ACTIVE + nfrag = 0 + pl%status(impactors%id(:)) = status + pl%ldiscard(impactors%id(:)) = .false. + pl%lcollision(impactors%id(:)) = .false. + select type(before => collision_system%before) + class is (swiftest_nbody_system) + select type(after => collision_system%after) + class is (swiftest_nbody_system) + allocate(after%pl, source=before%pl) ! Be sure to save the pl so that snapshots still work + end select + end select + else + ! Populate the list of new bodies + nfrag = fragments%nbody + write(message, *) nfrag + call swiftest_io_log_one_message(FRAGGLE_LOG_OUT, "Generating " // trim(adjustl(message)) // " fragments") select case(impactors%regime) case(COLLRESOLVE_REGIME_DISRUPTION) - message = "Disruption between" + status = DISRUPTED + ibiggest = impactors%id(maxloc(pl%Gmass(impactors%id(:)), dim=1)) + fragments%id(1) = pl%id(ibiggest) + fragments%id(2:nfrag) = [(i, i = param%maxid + 1, param%maxid + nfrag - 1)] + param%maxid = fragments%id(nfrag) case(COLLRESOLVE_REGIME_SUPERCATASTROPHIC) - message = "Supercatastrophic disruption between" + status = SUPERCATASTROPHIC + fragments%id(1:nfrag) = [(i, i = param%maxid + 1, param%maxid + nfrag)] + param%maxid = fragments%id(nfrag) end select - call collision_resolve_collider_message(system%pl, impactors%id, message) - call swiftest_io_log_one_message(FRAGGLE_LOG_OUT, message) - ! Collisional fragments will be uniformly distributed around the pre-impact barycenter - call collision_system%set_mass_dist(param) - - ! Generate the position and velocity distributions of the fragments - call fraggle_generate_fragments(collision_system, nbody_system, param, lfailure) - - dpe = collision_system%pe(2) - collision_system%pe(1) - system%Ecollisions = system%Ecollisions - dpe - system%Euntracked = system%Euntracked + dpe - - if (lfailure) then - call swiftest_io_log_one_message(FRAGGLE_LOG_OUT, "No fragment solution found, so treat as a pure hit-and-run") - status = ACTIVE - nfrag = 0 - select type(pl => system%pl) - class is (swiftest_pl) - pl%status(impactors%id(:)) = status - pl%ldiscard(impactors%id(:)) = .false. - pl%lcollision(impactors%id(:)) = .false. - end select - allocate(after%pl, source=before%pl) ! Be sure to save the pl so that snapshots still work - else - ! Populate the list of new bodies - nfrag = fragments%nbody - write(message, *) nfrag - call swiftest_io_log_one_message(FRAGGLE_LOG_OUT, "Generating " // trim(adjustl(message)) // " fragments") - select case(impactors%regime) - case(COLLRESOLVE_REGIME_DISRUPTION) - status = DISRUPTED - ibiggest = impactors%id(maxloc(system%pl%Gmass(impactors%id(:)), dim=1)) - fragments%id(1) = system%pl%id(ibiggest) - fragments%id(2:nfrag) = [(i, i = param%maxid + 1, param%maxid + nfrag - 1)] - param%maxid = fragments%id(nfrag) - case(COLLRESOLVE_REGIME_SUPERCATASTROPHIC) - status = SUPERCATASTROPHIC - fragments%id(1:nfrag) = [(i, i = param%maxid + 1, param%maxid + nfrag)] - param%maxid = fragments%id(nfrag) - end select - - call collision_resolve_mergeaddsub(system, param, t, status) - end if - end associate - end select - end select - end select - end select + call collision_resolve_mergeaddsub(nbody_system, param, t, status) + end if + end associate return end function fraggle_resolve_disruption - module function fraggle_resolve_hitandrun(system, param, t) result(status) + module function fraggle_resolve_hitandrun(collision_system, nbody_system, param, t) result(status) !! author: Jennifer L.L. Pouplin, Carlisle A. Wishard, and David A. Minton !! !! Create the fragments resulting from a non-catastrophic hit-and-run collision !! implicit none ! Arguments - class(swiftest_nbody_system), intent(inout) :: system !! SyMBA nbody system object - class(swiftest_parameters), intent(inout) :: param !! Current run configuration parameters with SyMBA additions - real(DP), intent(in) :: t !! Time of collision + class(fraggle_system), intent(inout) :: collision_system !! Fraggle collision system object + class(swiftest_nbody_system), intent(inout) :: nbody_system !! Swiftest nbody system object + class(swiftest_parameters), intent(inout) :: param !! Current run configuration parameters with SyMBA additions + real(DP), intent(in) :: t !! Time of collision ! Result - integer(I4B) :: status !! Status flag assigned to this outcom + integer(I4B) :: status !! Status flag assigned to this outcome ! Internals integer(I4B) :: i, ibiggest, nfrag, jtarg, jproj logical :: lpure character(len=STRMAX) :: message real(DP) :: dpe - select type(system) + select type(before => collision_system%before) class is (swiftest_nbody_system) - select type(param) - class is (swiftest_parameters) - select type(before => system%collision_system%before) + select type(after => collision_system%after) class is (swiftest_nbody_system) - select type(after => system%collision_system%after) - class is (swiftest_nbody_system) - associate(collision_system => system%collision_system, impactors => system%collision_system%impactors, fragments => system%collision_system%fragments) + associate(impactors => collision_system%impactors, fragments => collision_system%fragments, pl => nbody_system%pl) message = "Hit and run between" - call collision_resolve_collider_message(system%pl, impactors%id, message) + call collision_resolve_collider_message(nbody_system%pl, impactors%id, message) call swiftest_io_log_one_message(FRAGGLE_LOG_OUT, trim(adjustl(message))) if (impactors%mass(1) > impactors%mass(2)) then @@ -148,11 +136,11 @@ module function fraggle_resolve_hitandrun(system, param, t) result(status) call collision_system%set_mass_dist(param) ! Generate the position and velocity distributions of the fragments - call collision_system%generate(system, param, lpure) + call fraggle_generate_fragments(collision_system, nbody_system, param, lpure) dpe = collision_system%pe(2) - collision_system%pe(1) - system%Ecollisions = system%Ecollisions - dpe - system%Euntracked = system%Euntracked + dpe + nbody_system%Ecollisions = nbody_system%Ecollisions - dpe + nbody_system%Euntracked = nbody_system%Euntracked + dpe if (lpure) then call swiftest_io_log_one_message(FRAGGLE_LOG_OUT, "Should have been a pure hit and run instead") @@ -165,26 +153,21 @@ module function fraggle_resolve_hitandrun(system, param, t) result(status) end if if (lpure) then ! Reset these bodies back to being active so that nothing further is done to them status = HIT_AND_RUN_PURE - select type(pl => system%pl) - class is (symba_pl) - pl%status(impactors%id(:)) = ACTIVE - pl%ldiscard(impactors%id(:)) = .false. - pl%lcollision(impactors%id(:)) = .false. - end select + pl%status(impactors%id(:)) = ACTIVE + pl%ldiscard(impactors%id(:)) = .false. + pl%lcollision(impactors%id(:)) = .false. allocate(after%pl, source=before%pl) ! Be sure to save the pl so that snapshots still work else - ibiggest = impactors%id(maxloc(system%pl%Gmass(impactors%id(:)), dim=1)) - fragments%id(1) = system%pl%id(ibiggest) + ibiggest = impactors%id(maxloc(pl%Gmass(impactors%id(:)), dim=1)) + fragments%id(1) = pl%id(ibiggest) fragments%id(2:nfrag) = [(i, i = param%maxid + 1, param%maxid + nfrag - 1)] param%maxid = fragments%id(nfrag) status = HIT_AND_RUN_DISRUPT - call collision_resolve_mergeaddsub(system, param, t, status) + call collision_resolve_mergeaddsub(nbody_system, param, t, status) end if end associate end select end select - end select - end select return