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 17, 2022
1 parent 33282c6 commit ae189eb
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 69 deletions.
48 changes: 47 additions & 1 deletion src/collision/collision_util.f90
Original file line number Diff line number Diff line change
Expand Up @@ -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
!!
Expand Down Expand Up @@ -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
Expand Down
46 changes: 0 additions & 46 deletions src/fraggle/fraggle_util.f90
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
28 changes: 15 additions & 13 deletions src/modules/collision_classes.f90
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
9 changes: 0 additions & 9 deletions src/modules/fraggle_classes.f90
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit ae189eb

Please sign in to comment.