diff --git a/src/collision/collision_util.f90 b/src/collision/collision_util.f90 index b6c776fbe..5e81b7b00 100644 --- a/src/collision/collision_util.f90 +++ b/src/collision/collision_util.f90 @@ -11,7 +11,7 @@ use swiftest contains - module subroutine collison_util_add_fragments_to_system(self, system, param) + module subroutine collision_util_add_fragments_to_system(self, system, param) !! Author: David A. Minton !! !! Adds fragments to the temporary system pl object @@ -55,7 +55,52 @@ module subroutine collison_util_add_fragments_to_system(self, system, param) end associate return - end subroutine collison_util_add_fragments_to_system + end subroutine collision_util_add_fragments_to_system + + + module subroutine collision_util_construct_temporary_system(self, nbody_system, param, tmpsys, tmpparam) + !! Author: David A. Minton + !! + !! Constructs a temporary internal system consisting of active bodies and additional fragments. This internal temporary system is used to calculate system energy with and without fragments + implicit none + ! Arguments + class(collision_system), intent(inout) :: self !! Fraggle collision system object + class(swiftest_nbody_system), intent(in) :: nbody_system !! Original swiftest nbody system object + class(swiftest_parameters), intent(in) :: param !! Current swiftest run configuration parameters + class(swiftest_nbody_system), allocatable, intent(out) :: tmpsys !! Output temporary swiftest nbody system object + class(swiftest_parameters), allocatable, intent(out) :: tmpparam !! Output temporary configuration run parameters + ! Internals + logical, dimension(:), allocatable :: linclude + integer(I4B) :: npl_tot + + associate(fragments => self%fragments, nfrag => self%fragments%nbody, pl => nbody_system%pl, npl => nbody_system%pl%nbody, cb => nbody_system%cb) + ! Set up a new system based on the original + if (allocated(tmpparam)) deallocate(tmpparam) + if (allocated(tmpsys)) deallocate(tmpsys) + allocate(tmpparam, source=param) + call setup_construct_system(tmpsys, tmpparam) + + ! No test particles necessary for energy/momentum calcs + call tmpsys%tp%setup(0, param) + + ! Replace the empty central body object with a copy of the original + deallocate(tmpsys%cb) + allocate(tmpsys%cb, source=cb) + + ! Make space for the fragments + npl_tot = npl + nfrag + call tmpsys%pl%setup(npl_tot, tmpparam) + allocate(linclude(npl_tot)) + + ! Fill up the temporary system with all of the original bodies, leaving the spaces for fragments empty until we add them in later + linclude(1:npl) = .true. + linclude(npl+1:npl_tot) = .false. + call tmpsys%pl%fill(pl, linclude) + + end associate + + return + end subroutine collision_util_construct_temporary_system module subroutine collision_util_dealloc_fragments(self) !! author: David A. Minton @@ -214,7 +259,7 @@ module subroutine collision_util_get_energy_momentum(self, system, param, lbefo npl_after = npl_before + nfrag if (lbefore) then - call encounter_util_construct_temporary_system(fragments, system, param, tmpsys, tmpparam) + call self%construct_temporary_system(system, param, tmpsys, tmpparam) ! Build the exluded body logical mask for the *before* case: Only the original bodies are used to compute energy and momentum tmpsys%pl%status(impactors%idx(1:impactors%ncoll)) = ACTIVE tmpsys%pl%status(npl_before+1:npl_after) = INACTIVE diff --git a/src/fraggle/fraggle_util.f90 b/src/fraggle/fraggle_util.f90 index 6da202ad6..a46ec64a0 100644 --- a/src/fraggle/fraggle_util.f90 +++ b/src/fraggle/fraggle_util.f90 @@ -37,49 +37,20 @@ module subroutine fraggle_util_get_angular_momentum(self) end subroutine fraggle_util_get_angular_momentum - module subroutine fraggle_util_construct_temporary_system(collision_system, nbody_system, param, tmpsys, tmpparam) + module subroutine fraggle_util_construct_temporary_system(self, nbody_system, param, tmpsys, tmpparam) !! Author: David A. Minton !! !! Constructs a temporary internal system consisting of active bodies and additional fragments. This internal temporary system is used to calculate system energy with and without fragments implicit none ! Arguments - class(fraggle_system), intent(inout) :: collision_system !! Fraggle collision system object - class(swiftest_nbody_system), intent(in) :: nbody_system !! Original swiftest nbody system object - class(swiftest_parameters), intent(in) :: param !! Current swiftest run configuration parameters - class(swiftest_nbody_system), allocatable, intent(out) :: tmpsys !! Output temporary swiftest nbody system object - class(swiftest_parameters), allocatable, intent(out) :: tmpparam !! Output temporary configuration run parameters - ! Internals - logical, dimension(:), allocatable :: linclude - integer(I4B) :: npl_tot - - associate(fragments => collision_system%fragments, nfrag => collision_system%fragments%nbody, pl => nbody_system%pl, npl => nbody_system%pl%nbody, cb => nbody_system%cb) - ! Set up a new system based on the original - if (allocated(tmpparam)) deallocate(tmpparam) - if (allocated(tmpsys)) deallocate(tmpsys) - allocate(tmpparam, source=param) - call setup_construct_system(tmpsys, tmpparam) - - ! No test particles necessary for energy/momentum calcs - call tmpsys%tp%setup(0, param) - - ! Replace the empty central body object with a copy of the original - deallocate(tmpsys%cb) - allocate(tmpsys%cb, source=cb) - - ! Make space for the fragments - npl_tot = npl + nfrag - call tmpsys%pl%setup(npl_tot, tmpparam) - allocate(linclude(npl_tot)) - - ! Fill up the temporary system with all of the original bodies, leaving the spaces for fragments empty until we add them in later - linclude(1:npl) = .true. - linclude(npl+1:npl_tot) = .false. - call tmpsys%pl%fill(pl, linclude) - - ! Scale the temporary system to the natural units of the current Fraggle calculation - call tmpsys%rescale(tmpparam, collision_system%mscale, collision_system%dscale, collision_system%tscale) - - end associate + class(fraggle_system), intent(inout) :: self !! Fraggle collision system object + class(swiftest_nbody_system), intent(in) :: nbody_system !! Original swiftest nbody system object + class(swiftest_parameters), intent(in) :: param !! Current swiftest run configuration parameters + class(swiftest_nbody_system), allocatable, intent(out) :: tmpsys !! Output temporary swiftest nbody system object + class(swiftest_parameters), allocatable, intent(out) :: tmpparam !! Output temporary configuration run parameters + + call self%collision_system%construct_temporary_system(nbody_system, param, tmpsys, tmpparam) + call tmpsys%rescale(tmpparam, self%mscale, self%dscale, self%tscale) return end subroutine fraggle_util_construct_temporary_system diff --git a/src/modules/collision_classes.f90 b/src/modules/collision_classes.f90 index ac80477f1..dccda9c88 100644 --- a/src/modules/collision_classes.f90 +++ b/src/modules/collision_classes.f90 @@ -101,14 +101,15 @@ 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 :: 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 + 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 => collision_util_add_fragments_to_system !! Add fragments to system + procedure :: construct_temporary_system => collision_util_construct_temporary_system !! Constructs temporary n-body system in order to compute pre- and post-impact energy and momentum + 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 @@ -253,12 +254,21 @@ 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) + module subroutine collision_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 + end subroutine collision_util_add_fragments_to_system + + module subroutine collision_util_construct_temporary_system(self, nbody_system, param, tmpsys, tmpparam) + implicit none + class(collision_system), intent(inout) :: self !! Fraggle collision system object + class(swiftest_nbody_system), intent(in) :: nbody_system !! Original swiftest nbody system object + class(swiftest_parameters), intent(in) :: param !! Current swiftest run configuration parameters + class(swiftest_nbody_system), allocatable, intent(out) :: tmpsys !! Output temporary swiftest nbody system object + class(swiftest_parameters), allocatable, intent(out) :: tmpparam !! Output temporary configuration run parameters + end subroutine collision_util_construct_temporary_system module subroutine collision_util_dealloc_fragments(self) implicit none diff --git a/src/modules/fraggle_classes.f90 b/src/modules/fraggle_classes.f90 index cdecf1205..de8542f67 100644 --- a/src/modules/fraggle_classes.f90 +++ b/src/modules/fraggle_classes.f90 @@ -56,13 +56,14 @@ module fraggle_classes real(DP) :: Escale = 1.0_DP !! Energy scale factor (a convenience unit that is derived from dscale, tscale, and mscale) real(DP) :: Lscale = 1.0_DP !! Angular momentum scale factor (a convenience unit that is derived from dscale, tscale, and mscale) contains - procedure :: generate_fragments => fraggle_generate_fragments !! Generates a system of fragments in barycentric coordinates that conserves energy and momentum. - procedure :: set_budgets => fraggle_set_budgets !! Sets the energy and momentum budgets of the fragments based on the collider value - procedure :: set_mass_dist => fraggle_set_mass_dist !! Sets the distribution of mass among the fragments depending on the regime type - procedure :: set_natural_scale => fraggle_set_natural_scale_factors !! Scales dimenional quantities to ~O(1) with respect to the collisional system. - procedure :: set_original_scale => fraggle_set_original_scale_factors !! Restores dimenional quantities back to the original system units - final :: fraggle_util_final_system !! Finalizer will deallocate all allocatables - end type fraggle_system + procedure :: generate_fragments => fraggle_generate_fragments !! Generates a system of fragments in barycentric coordinates that conserves energy and momentum. + procedure :: set_budgets => fraggle_set_budgets !! Sets the energy and momentum budgets of the fragments based on the collider value + procedure :: set_mass_dist => fraggle_set_mass_dist !! Sets the distribution of mass among the fragments depending on the regime type + procedure :: set_natural_scale => fraggle_set_natural_scale_factors !! Scales dimenional quantities to ~O(1) with respect to the collisional system. + procedure :: set_original_scale => fraggle_set_original_scale_factors !! Restores dimenional quantities back to the original system units + procedure :: construct_temporary_system => fraggle_util_construct_temporary_system !! Constructs temporary n-body system in order to compute pre- and post-impact energy and momentum + final :: fraggle_util_final_system !! Finalizer will deallocate all allocatables + end type fraggle_system interface @@ -118,14 +119,14 @@ module subroutine fraggle_util_get_angular_momentum(self) class(fraggle_fragments), intent(inout) :: self !! Fraggle fragment system object end subroutine fraggle_util_get_angular_momentum - module subroutine fraggle_util_construct_temporary_system(collision_system, nbody_system, param, tmpsys, tmpparam) + module subroutine fraggle_util_construct_temporary_system(self, nbody_system, param, tmpsys, tmpparam) use swiftest_classes, only : swiftest_nbody_system, swiftest_parameters implicit none - class(fraggle_system), intent(inout) :: collision_system !! Fraggle collision system object - class(swiftest_nbody_system), intent(in) :: nbody_system !! Original swiftest nbody system object - class(swiftest_parameters), intent(in) :: param !! Current swiftest run configuration parameters - class(swiftest_nbody_system), allocatable, intent(out) :: tmpsys !! Output temporary swiftest nbody system object - class(swiftest_parameters), allocatable, intent(out) :: tmpparam !! Output temporary configuration run parameters + class(fraggle_system), intent(inout) :: self !! Fraggle collision system object + class(swiftest_nbody_system), intent(in) :: nbody_system !! Original swiftest nbody system object + class(swiftest_parameters), intent(in) :: param !! Current swiftest run configuration parameters + class(swiftest_nbody_system), allocatable, intent(out) :: tmpsys !! Output temporary swiftest nbody system object + class(swiftest_parameters), allocatable, intent(out) :: tmpparam !! Output temporary configuration run parameters end subroutine fraggle_util_construct_temporary_system module subroutine fraggle_util_dealloc_fragments(self)