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

Commit

Permalink
More cleanup. It compiles again!
Browse files Browse the repository at this point in the history
  • Loading branch information
daminton committed Dec 17, 2022
1 parent f903e34 commit da12dc9
Show file tree
Hide file tree
Showing 10 changed files with 116 additions and 80 deletions.
2 changes: 1 addition & 1 deletion src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ SET(FAST_MATH_FILES
${SRC}/modules/whm_classes.f90
${SRC}/modules/swiftest.f90
${SRC}/collision/collision_io.f90
${SRC}/collision/collision_regime.f90
${SRC}/collision/collision_setup.f90
${SRC}/collision/collision_util.f90
${SRC}/discard/discard.f90
Expand All @@ -37,7 +38,6 @@ SET(FAST_MATH_FILES
${SRC}/encounter/encounter_io.f90
${SRC}/fraggle/fraggle_generate.f90
${SRC}/fraggle/fraggle_io.f90
${SRC}/fraggle/fraggle_regime.f90
${SRC}/fraggle/fraggle_set.f90
${SRC}/fraggle/fraggle_setup.f90
${SRC}/fraggle/fraggle_util.f90
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,19 @@
!! You should have received a copy of the GNU General Public License along with Swiftest.
!! If not, see: https://www.gnu.org/licenses.

submodule(fraggle_classes) s_encounter_regime
submodule(collision_classes) s_collision_regime
use swiftest

contains

module subroutine encounter_regime_impactors(self, fragments, system, param)
module subroutine collision_regime_impactors(self, system, param)
!! Author: Jennifer L.L. Pouplin, Carlisle A. Wishard, and David A. Minton
!!
!! Determine which fragmentation regime the set of impactors will be. This subroutine is a wrapper for the non-polymorphic raggle_regime_collresolve subroutine.
!! It converts to SI units prior to calling
implicit none
! Arguments
class(collision_impactors), intent(inout) :: self !! Fraggle impactors object
class(fraggle_fragments), intent(inout) :: fragments !! Fraggle fragment system object
class(collision_impactors), intent(inout) :: self !! Collision system impactors object
class(swiftest_nbody_system), intent(in) :: system !! Swiftest nbody system object
class(swiftest_parameters), intent(in) :: param !! Current Swiftest run configuration parameters
! Internals
Expand Down Expand Up @@ -58,7 +57,7 @@ module subroutine encounter_regime_impactors(self, fragments, system, param)
dentot = sum(mass_si(:) * density_si(:)) / mtot

!! Use the positions and velocities of the parents from indside the step (at collision) to calculate the collisional regime
call encounter_regime_collresolve(Mcb_si, mass_si(jtarg), mass_si(jproj), radius_si(jtarg), radius_si(jproj), &
call collision_regime_collresolve(Mcb_si, mass_si(jtarg), mass_si(jproj), radius_si(jtarg), radius_si(jproj), &
x1_si(:), x2_si(:), v1_si(:), v2_si(:), density_si(jtarg), density_si(jproj), &
min_mfrag_si, impactors%regime, mlr, mslr, impactors%Qloss)

Expand All @@ -67,9 +66,9 @@ module subroutine encounter_regime_impactors(self, fragments, system, param)
impactors%mass_dist(3) = min(max(mtot - mlr - mslr, 0.0_DP), mtot)

! Find the center of mass of the collisional system
fragments%mtot = sum(impactors%mass(:))
impactors%rbcom(:) = (impactors%mass(1) * impactors%rb(:,1) + impactors%mass(2) * impactors%rb(:,2)) / fragments%mtot
impactors%vbcom(:) = (impactors%mass(1) * impactors%vb(:,1) + impactors%mass(2) * impactors%vb(:,2)) / fragments%mtot
mtot = sum(impactors%mass(:))
impactors%rbcom(:) = (impactors%mass(1) * impactors%rb(:,1) + impactors%mass(2) * impactors%rb(:,2)) / mtot
impactors%vbcom(:) = (impactors%mass(1) * impactors%vb(:,1) + impactors%mass(2) * impactors%vb(:,2)) / mtot

! Find the point of impact between the two bodies
runit(:) = impactors%rb(:,2) - impactors%rb(:,1)
Expand All @@ -80,14 +79,14 @@ module subroutine encounter_regime_impactors(self, fragments, system, param)
impactors%mass_dist(:) = (impactors%mass_dist(:) / param%MU2KG)
impactors%Qloss = impactors%Qloss * (param%TU2S / param%DU2M)**2 / param%MU2KG

call fraggle_io_log_regime(impactors, fragments)
!call fraggle_io_log_regime(impactors, fragments)
end associate

return
end subroutine encounter_regime_impactors
end subroutine collision_regime_impactors


subroutine encounter_regime_collresolve(Mcb, m1, m2, rad1, rad2, rh1, rh2, vb1, vb2, den1, den2, min_mfrag, &
subroutine collision_regime_collresolve(Mcb, m1, m2, rad1, rad2, rh1, rh2, vb1, vb2, den1, den2, min_mfrag, &
regime, Mlr, Mslr, Qloss)
!! Author: Jennifer L.L. Pouplin, Carlisle A. Wishard, and David A. Minton
!!
Expand Down Expand Up @@ -379,6 +378,6 @@ function calc_c_star(Rc1) result(c_star)
return
end function calc_c_star

end subroutine encounter_regime_collresolve
end subroutine collision_regime_collresolve

end submodule s_encounter_regime
end submodule s_collision_regime
12 changes: 8 additions & 4 deletions src/collision/collision_setup.f90
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,25 @@
use swiftest
contains

module subroutine collision_setup_system(self, system, param)
module subroutine collision_setup_system(self, param)
!! author: David A. Minton
!!
!! Initializer for the encounter collision system. Allocates the collider and fragments classes and the before/after snapshots
implicit none
! Arguments
class(collision_system), intent(inout) :: self !! Encounter collision system object
class(swiftest_nbody_system), intent(inout) :: system !! Swiftest nbody system object
class(swiftest_parameters), intent(inout) :: param !! Current run configuration parameters
class(collision_system), intent(inout) :: self !! Encounter collision system object
class(swiftest_parameters), intent(inout) :: param !! Current run configuration parameters
! Internals

! TODO: Check parameter file for fragmentation model in SyMBA
allocate(collision_impactors :: self%impactors)
allocate(fraggle_fragments :: self%fragments)


return
end subroutine collision_setup_system


module subroutine collision_setup_fragments(self, n, param)
!! author: David A. Minton
!!
Expand Down
19 changes: 11 additions & 8 deletions src/collision/collision_util.f90
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,12 @@ module subroutine collision_util_final_system(self)
implicit none
! Arguments
type(collision_system), intent(inout) :: self !! Collision system object
! Internals
type(swiftest_parameters) :: tmp_param

call self%reset()
call self%reset(tmp_param)
if (allocated(self%impactors)) deallocate(self%impactors)
if (allocated(self%fragments)) deallocate(self%fragments)

return
end subroutine collision_util_final_system
Expand Down Expand Up @@ -298,17 +302,15 @@ module subroutine collision_util_reset_impactors(self)
return
end subroutine collision_util_reset_impactors


module subroutine collision_util_reset_system(self)
module subroutine collision_util_reset_system(self, param)
!! author: David A. Minton
!!
!! Resets the collider system and deallocates all allocatables
implicit none
! Arguments
class(collision_system), intent(inout) :: self
class(collision_system), intent(inout) :: self !! Collision system object
class(swiftest_parameters), intent(in) :: param !! Current run configuration parameters

if (allocated(self%impactors)) deallocate(self%impactors)
if (allocated(self%fragments)) deallocate(self%fragments)
if (allocated(self%before)) deallocate(self%before)
if (allocated(self%after)) deallocate(self%after)

Expand All @@ -320,12 +322,13 @@ module subroutine collision_util_reset_system(self)
self%pe(:) = 0.0_DP
self%Etot(:) = 0.0_DP

call self%impactors%reset()
call self%fragments%setup(0, param)

return
end subroutine collision_util_reset_system




module subroutine collision_util_set_coordinate_system(self)
!! author: David A. Minton
!!
Expand Down
4 changes: 2 additions & 2 deletions src/fraggle/fraggle_set.f90
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ module subroutine fraggle_set_mass_dist(self, param)

select case(impactors%regime)
case(COLLRESOLVE_REGIME_DISRUPTION, COLLRESOLVE_REGIME_SUPERCATASTROPHIC, COLLRESOLVE_REGIME_HIT_AND_RUN)
! The first two bins of the mass_dist are the largest and second-largest fragments that came out of encounter_regime.
! The first two bins of the mass_dist are the largest and second-largest fragments that came out of collision_regime.
! The remainder from the third bin will be distributed among nfrag-2 bodies. The following code will determine nfrag based on
! the limits bracketed above and the model size distribution of fragments.
! Check to see if our size distribution would give us a smaller number of fragments than the maximum number
Expand Down Expand Up @@ -117,7 +117,7 @@ module subroutine fraggle_set_mass_dist(self, param)
write(*,*) "fraggle_set_mass_dist_fragments error: Unrecognized regime code",impactors%regime
end select

! Make the first two bins the same as the Mlr and Mslr values that came from encounter_regime
! Make the first two bins the same as the Mlr and Mslr values that came from collision_regime
fragments%mass(1) = impactors%mass_dist(iMlr)
fragments%mass(2) = impactors%mass_dist(iMslr)

Expand Down
6 changes: 5 additions & 1 deletion src/fraggle/fraggle_util.f90
Original file line number Diff line number Diff line change
Expand Up @@ -185,8 +185,12 @@ module subroutine fraggle_util_final_system(self)
implicit none
! Arguments
type(fraggle_system), intent(inout) :: self !! Collision impactors storage object
! Internals
type(swiftest_parameters) :: tmp_param

call self%reset()
call self%reset(tmp_param)
if (allocated(self%impactors)) deallocate(self%impactors)
if (allocated(self%fragments)) deallocate(self%fragments)

return
end subroutine fraggle_util_final_system
Expand Down
49 changes: 34 additions & 15 deletions src/modules/collision_classes.f90
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ module collision_classes
real(DP), dimension(NDIM) :: rbimp !! Impact point position vector of the collider system in system barycentric coordinates

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
Expand Down Expand Up @@ -102,14 +103,33 @@ module collision_classes
real(DP), dimension(2) :: pe !! Before/after potential energy
real(DP), dimension(2) :: Etot !! Before/after total system energy
contains
procedure :: regime => collision_regime_system !! Determine which fragmentation regime the set of impactors will be
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
end type collision_system

abstract interface
subroutine abstract_generate_fragments(self, system, param, lfailure)
import collision_system, swiftest_nbody_system, swiftest_parameters
implicit none
class(collision_system), intent(inout) :: self !! Fraggle fragment system object
class(swiftest_nbody_system), intent(inout) :: system !! Swiftest nbody system object
class(swiftest_parameters), intent(inout) :: param !! Current run configuration parameters
logical, intent(out) :: lfailure !! Answers the question: Should this have been a merger instead?
end subroutine abstract_generate_fragments

subroutine abstract_set_mass_dist(self, param)
import collision_system, swiftest_parameters
implicit none
class(collision_system), intent(inout) :: self !! Collision system object
class(swiftest_parameters), intent(in) :: param !! Current Swiftest run configuration parameters
end subroutine abstract_set_mass_dist
end interface

!! NetCDF dimension and variable names for the enounter save object
type, extends(encounter_io_parameters) :: collision_io_parameters
integer(I4B) :: stage_dimid !! ID for the stage dimension
Expand Down Expand Up @@ -201,12 +221,12 @@ module subroutine collision_util_placeholder_step(self, system, param, t, dt)
real(DP), intent(in) :: dt !! Stepsiz
end subroutine collision_util_placeholder_step

module subroutine collision_regime_system(self, system, param)
module subroutine collision_regime_impactors(self, system, param)
implicit none
class(collision_system), intent(inout) :: self !! Collision system object
class(swiftest_nbody_system), intent(in) :: system !! Swiftest nbody system object
class(swiftest_parameters), intent(in) :: param !! Current Swiftest run configuration parameters
end subroutine collision_regime_system
class(collision_impactors), intent(inout) :: self !! Collision system impactors object
class(swiftest_nbody_system), intent(in) :: system !! Swiftest nbody system object
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
Expand All @@ -223,7 +243,6 @@ module subroutine collision_util_set_coordinate_system(self)
class(collision_system), intent(inout) :: self !! Collisional system
end subroutine collision_util_set_coordinate_system


module subroutine collision_setup_fragments(self, n, param)
implicit none
class(collision_fragments), intent(inout) :: self !! Fragment system object
Expand All @@ -238,12 +257,11 @@ module subroutine collision_setup_impactors(self, system, param)
class(swiftest_parameters), intent(in) :: param !! Current swiftest run configuration parameters
end subroutine collision_setup_impactors

module subroutine collision_setup_system(self, system, param)
use swiftest_classes, only : swiftest_nbody_system, swiftest_parameters
module subroutine collision_setup_system(self, param)
use swiftest_classes, only : swiftest_parameters
implicit none
class(collision_system), intent(inout) :: self !! Encounter collision system object
class(swiftest_nbody_system), intent(inout) :: system !! Swiftest nbody system object
class(swiftest_parameters), intent(inout) :: param !! Current run configuration parameters
class(collision_system), intent(inout) :: self !! Collision system object
class(swiftest_parameters), intent(inout) :: param !! Current run configuration parameters
end subroutine collision_setup_system

module subroutine collision_util_dealloc_fragments(self)
Expand Down Expand Up @@ -293,12 +311,13 @@ end subroutine collision_util_index_map

module subroutine collision_util_reset_impactors(self)
implicit none
class(collision_impactors), intent(inout) :: self
class(collision_impactors), intent(inout) :: self !! Collision system object
end subroutine collision_util_reset_impactors

module subroutine collision_util_reset_system(self)
module subroutine collision_util_reset_system(self, param)
implicit none
class(collision_system), intent(inout) :: self
class(collision_system), intent(inout) :: self !! Collision system object
class(swiftest_parameters), intent(in) :: param !! Current run configuration parameters
end subroutine collision_util_reset_system

module subroutine collision_util_snapshot(self, param, system, t, arg)
Expand Down
5 changes: 2 additions & 3 deletions src/modules/symba_classes.f90
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ module symba_classes
use helio_classes, only : helio_cb, helio_pl, helio_tp, helio_nbody_system
use fraggle_classes, only : collision_impactors, fraggle_fragments
use encounter_classes, only : encounter_list, encounter_storage
use collision_classes, only : collision_storage
use collision_classes, only : collision_storage, collision_system
implicit none
public

Expand Down Expand Up @@ -190,8 +190,7 @@ module symba_classes
class(symba_plplenc), allocatable :: plplenc_list !! List of massive body-massive body encounters in a single step
class(symba_plplenc), allocatable :: plplcollision_list !! List of massive body-massive body collisions in a single step
integer(I4B) :: irec !! System recursion level
class(collision_impactors), allocatable :: impactors !! Fraggle impactors object
class(fraggle_fragments), allocatable :: fragments !! Fraggle fragmentation system object
class(collision_system), allocatable :: collision_system !! Collision system object
contains
procedure :: write_discard => symba_io_write_discard !! Write out information about discarded and merged planets and test particles in SyMBA
procedure :: initialize => symba_setup_initialize_system !! Performs SyMBA-specific initilization steps
Expand Down
11 changes: 11 additions & 0 deletions src/setup/setup.f90
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,15 @@ module subroutine setup_construct_system(system, param)

select type(param)
class is (symba_parameters)

if (param%lfragmentation) then
allocate(fraggle_system :: system%collision_system)
call system%collision_system%setup(param)

allocate(symba_nbody_system :: system%collision_system%before)
allocate(symba_nbody_system :: system%collision_system%after)
end if

if (param%lenc_save_trajectory .or. param%lenc_save_closest) then
allocate(encounter_storage :: param%encounter_history)
associate (encounter_history => param%encounter_history)
Expand All @@ -98,6 +107,8 @@ module subroutine setup_construct_system(system, param)
end associate
end select



end select
case (RINGMOONS)
write(*,*) 'RINGMOONS-SyMBA integrator not yet enabled'
Expand Down
Loading

0 comments on commit da12dc9

Please sign in to comment.