diff --git a/src/collision/collision_util.f90 b/src/collision/collision_util.f90 index 3a1aea3fa..b6c776fbe 100644 --- a/src/collision/collision_util.f90 +++ b/src/collision/collision_util.f90 @@ -11,6 +11,52 @@ use swiftest contains + module subroutine collison_util_add_fragments_to_system(self, system, param) + !! Author: David A. Minton + !! + !! Adds fragments to the temporary system pl object + implicit none + ! Arguments + class(collision_system), intent(in) :: self !! Collision system system object + class(swiftest_nbody_system), intent(inout) :: system !! Swiftest nbody system object + class(swiftest_parameters), intent(in) :: param !! Current swiftest run configuration parameters + ! Internals + integer(I4B) :: i, npl_before, npl_after + logical, dimension(:), allocatable :: lexclude + + associate(fragments => self%fragments, impactors => self%impactors, nfrag => self%fragments%nbody, pl => system%pl, cb => system%cb) + npl_after = pl%nbody + npl_before = npl_after - nfrag + allocate(lexclude(npl_after)) + + pl%status(npl_before+1:npl_after) = ACTIVE + pl%mass(npl_before+1:npl_after) = fragments%mass(1:nfrag) + pl%Gmass(npl_before+1:npl_after) = fragments%mass(1:nfrag) * param%GU + pl%radius(npl_before+1:npl_after) = fragments%radius(1:nfrag) + do concurrent (i = 1:nfrag) + pl%rb(:,npl_before+i) = fragments%rb(:,i) + pl%vb(:,npl_before+i) = fragments%vb(:,i) + pl%rh(:,npl_before+i) = fragments%rb(:,i) - cb%rb(:) + pl%vh(:,npl_before+i) = fragments%vb(:,i) - cb%vb(:) + end do + if (param%lrotation) then + pl%Ip(:,npl_before+1:npl_after) = fragments%Ip(:,1:nfrag) + pl%rot(:,npl_before+1:npl_after) = fragments%rot(:,1:nfrag) + end if + ! This will remove the impactors from the system since we've replaced them with fragments + lexclude(1:npl_after) = .false. + lexclude(impactors%idx(1:impactors%ncoll)) = .true. + where(lexclude(1:npl_after)) + pl%status(1:npl_after) = INACTIVE + elsewhere + pl%status(1:npl_after) = ACTIVE + endwhere + + end associate + + return + end subroutine collison_util_add_fragments_to_system + module subroutine collision_util_dealloc_fragments(self) !! author: David A. Minton !! @@ -179,7 +225,7 @@ module subroutine collision_util_get_energy_momentum(self, system, param, lbefo call util_exit(FAILURE) end if ! Build the exluded body logical mask for the *after* case: Only the new bodies are used to compute energy and momentum - call encounter_util_add_fragments_to_system(fragments, impactors, tmpsys, tmpparam) + call self%add_fragments(tmpsys, tmpparam) tmpsys%pl%status(impactors%idx(1:impactors%ncoll)) = INACTIVE tmpsys%pl%status(npl_before+1:npl_after) = ACTIVE end if diff --git a/src/fraggle/fraggle_util.f90 b/src/fraggle/fraggle_util.f90 index ae9cb8854..6da202ad6 100644 --- a/src/fraggle/fraggle_util.f90 +++ b/src/fraggle/fraggle_util.f90 @@ -11,52 +11,6 @@ use swiftest contains - module subroutine fraggle_util_add_fragments_to_system(fragments, impactors, system, param) - !! Author: David A. Minton - !! - !! Adds fragments to the temporary system pl object - implicit none - ! Arguments - class(fraggle_fragments), intent(in) :: fragments !! Fraggle fragment system object - class(collision_impactors), intent(in) :: impactors !! Fraggle collider system object - class(swiftest_nbody_system), intent(inout) :: system !! Swiftest nbody system object - class(swiftest_parameters), intent(in) :: param !! Current swiftest run configuration parameters - ! Internals - integer(I4B) :: i, npl_before, npl_after - logical, dimension(:), allocatable :: lexclude - - associate(nfrag => fragments%nbody, pl => system%pl, cb => system%cb) - npl_after = pl%nbody - npl_before = npl_after - nfrag - allocate(lexclude(npl_after)) - - pl%status(npl_before+1:npl_after) = ACTIVE - pl%mass(npl_before+1:npl_after) = fragments%mass(1:nfrag) - pl%Gmass(npl_before+1:npl_after) = fragments%mass(1:nfrag) * param%GU - pl%radius(npl_before+1:npl_after) = fragments%radius(1:nfrag) - do concurrent (i = 1:nfrag) - pl%rb(:,npl_before+i) = fragments%rb(:,i) - pl%vb(:,npl_before+i) = fragments%vb(:,i) - pl%rh(:,npl_before+i) = fragments%rb(:,i) - cb%rb(:) - pl%vh(:,npl_before+i) = fragments%vb(:,i) - cb%vb(:) - end do - if (param%lrotation) then - pl%Ip(:,npl_before+1:npl_after) = fragments%Ip(:,1:nfrag) - pl%rot(:,npl_before+1:npl_after) = fragments%rot(:,1:nfrag) - end if - ! This will remove the impactors from the system since we've replaced them with fragments - lexclude(1:npl_after) = .false. - lexclude(impactors%idx(1:impactors%ncoll)) = .true. - where(lexclude(1:npl_after)) - pl%status(1:npl_after) = INACTIVE - elsewhere - pl%status(1:npl_after) = ACTIVE - endwhere - - end associate - - return - end subroutine fraggle_util_add_fragments_to_system module subroutine fraggle_util_get_angular_momentum(self) diff --git a/src/modules/collision_classes.f90 b/src/modules/collision_classes.f90 index 635a3fb33..ac80477f1 100644 --- a/src/modules/collision_classes.f90 +++ b/src/modules/collision_classes.f90 @@ -56,7 +56,6 @@ module collision_classes contains procedure :: get_regime => collision_regime_impactors !! Determine which fragmentation regime the set of impactors will be - procedure :: set_coordinate_system => collision_set_coordinate_impactors !! Defines the collisional coordinate system, including the unit vectors of both the system and individual fragments. procedure :: setup => collision_setup_impactors !! Allocates arrays for n fragments in a fragment system. Passing n = 0 deallocates all arrays. procedure :: reset => collision_util_reset_impactors !! Resets the collider object variables to 0 and deallocates the index and mass distributions final :: collision_util_final_impactors !! Finalizer will deallocate all allocatables @@ -102,13 +101,14 @@ module collision_classes real(DP), dimension(2) :: pe !! Before/after potential energy real(DP), dimension(2) :: Etot !! Before/after total system energy contains - procedure :: generate_fragments => abstract_generate_fragments !! Generates a system of fragments - procedure :: set_mass_dist => abstract_set_mass_dist !! Sets the distribution of mass among the fragments depending on the regime type - procedure :: setup => collision_setup_system !! Initializer for the encounter collision system. Allocates the collider and fragments classes and the before/after snapshots - procedure :: get_energy_and_momentum => collision_util_get_energy_momentum !! Calculates total system energy in either the pre-collision outcome state (lbefore = .true.) or the post-collision outcome state (lbefore = .false.) - procedure :: reset => collision_util_reset_system !! Deallocates all allocatables - procedure :: set_coordinate_system => collision_util_set_coordinate_system !! Sets the coordinate system of the collisional system - final :: collision_util_final_system !! Finalizer will deallocate all allocatables + procedure :: generate_fragments => abstract_generate_fragments !! Generates a system of fragments + procedure :: set_mass_dist => abstract_set_mass_dist !! Sets the distribution of mass among the fragments depending on the regime type + procedure :: setup => collision_setup_system !! Initializer for the encounter collision system. Allocates the collider and fragments classes and the before/after snapshots + procedure :: add_fragments => collison_util_add_fragments_to_system !! Add fragments to system + procedure :: get_energy_and_momentum => collision_util_get_energy_momentum !! Calculates total system energy in either the pre-collision outcome state (lbefore = .true.) or the post-collision outcome state (lbefore = .false.) + procedure :: reset => collision_util_reset_system !! Deallocates all allocatables + procedure :: set_coordinate_system => collision_util_set_coordinate_system !! Sets the coordinate system of the collisional system + final :: collision_util_final_system !! Finalizer will deallocate all allocatables end type collision_system abstract interface @@ -227,11 +227,6 @@ module subroutine collision_regime_impactors(self, system, param) class(swiftest_parameters), intent(in) :: param !! Current Swiftest run configuration parameters end subroutine collision_regime_impactors - module subroutine collision_set_coordinate_impactors(self) - implicit none - class(collision_impactors), intent(inout) :: self !! Collider system object - end subroutine collision_set_coordinate_impactors - module subroutine collision_util_set_coordinate_system(self) implicit none class(collision_system), intent(inout) :: self !! Collisional system @@ -258,6 +253,13 @@ module subroutine collision_setup_system(self, param) class(swiftest_parameters), intent(inout) :: param !! Current run configuration parameters end subroutine collision_setup_system + module subroutine collison_util_add_fragments_to_system(self, system, param) + implicit none + class(collision_system), intent(in) :: self !! Collision system system object + class(swiftest_nbody_system), intent(inout) :: system !! Swiftest nbody system object + class(swiftest_parameters), intent(in) :: param !! Current swiftest run configuration parameters + end subroutine collison_util_add_fragments_to_system + module subroutine collision_util_dealloc_fragments(self) implicit none class(collision_fragments), intent(inout) :: self diff --git a/src/modules/fraggle_classes.f90 b/src/modules/fraggle_classes.f90 index eff70b1f8..cdecf1205 100644 --- a/src/modules/fraggle_classes.f90 +++ b/src/modules/fraggle_classes.f90 @@ -113,15 +113,6 @@ module subroutine fraggle_setup_reset_fragments(self) class(fraggle_fragments), intent(inout) :: self end subroutine fraggle_setup_reset_fragments - module subroutine fraggle_util_add_fragments_to_system(fragments, impactors, system, param) - use swiftest_classes, only : swiftest_nbody_system, swiftest_parameters - implicit none - class(fraggle_fragments), intent(in) :: fragments !! Fraggle fragment system object - class(collision_impactors), intent(in) :: impactors !! Fraggle collider system object - class(swiftest_nbody_system), intent(inout) :: system !! Swiftest nbody system object - class(swiftest_parameters), intent(in) :: param !! Current swiftest run configuration parameters - end subroutine fraggle_util_add_fragments_to_system - module subroutine fraggle_util_get_angular_momentum(self) implicit none class(fraggle_fragments), intent(inout) :: self !! Fraggle fragment system object