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

Commit

Permalink
Cleanup and fixing segfaults
Browse files Browse the repository at this point in the history
  • Loading branch information
daminton committed Dec 18, 2022
1 parent a009b55 commit 199b288
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 5 deletions.
2 changes: 2 additions & 0 deletions src/collision/collision_regime.f90
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ module subroutine collision_regime_impactors(self, system, param)
x1_si(:), x2_si(:), v1_si(:), v2_si(:), density_si(jtarg), density_si(jproj), &
min_mfrag_si, impactors%regime, mlr, mslr, impactors%Qloss)

if (allocated(impactors%mass_dist)) deallocate(impactors%mass_dist)
allocate(impactors%mass_dist(3))
impactors%mass_dist(1) = min(max(mlr, 0.0_DP), mtot)
impactors%mass_dist(2) = min(max(mslr, 0.0_DP), mtot)
impactors%mass_dist(3) = min(max(mtot - mlr - mslr, 0.0_DP), mtot)
Expand Down
4 changes: 2 additions & 2 deletions src/collision/collision_util.f90
Original file line number Diff line number Diff line change
Expand Up @@ -413,8 +413,8 @@ module subroutine collision_util_reset_system(self, param)
self%pe(:) = 0.0_DP
self%Etot(:) = 0.0_DP

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

return
end subroutine collision_util_reset_system
Expand Down
9 changes: 6 additions & 3 deletions src/fraggle/fraggle_set.f90
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ module subroutine fraggle_set_mass_dist(self, param)
integer(I4B) :: i, jproj, jtarg, nfrag, istart
real(DP), dimension(2) :: volume
real(DP), dimension(NDIM) :: Ip_avg
real(DP) :: mfrag, mremaining, min_mfrag
real(DP) :: mfrag, mremaining, min_mfrag, mtot
real(DP), parameter :: BETA = 2.85_DP
integer(I4B), parameter :: NFRAGMAX = 100 !! Maximum number of fragments that can be generated
integer(I4B), parameter :: NFRAGMIN = 7 !! Minimum number of fragments that can be generated (set by the fraggle_generate algorithm for constraining momentum and energy)
Expand All @@ -66,7 +66,9 @@ module subroutine fraggle_set_mass_dist(self, param)
class is (fraggle_fragments)
! Get mass weighted mean of Ip and density
volume(1:2) = 4._DP / 3._DP * PI * impactors%radius(1:2)**3
Ip_avg(:) = (impactors%mass(1) * impactors%Ip(:,1) + impactors%mass(2) * impactors%Ip(:,2)) / fragments%mtot
mtot = sum(impactors%mass(:))
Ip_avg(:) = (impactors%mass(1) * impactors%Ip(:,1) + impactors%mass(2) * impactors%Ip(:,2)) / mtot

if (impactors%mass(1) > impactors%mass(2)) then
jtarg = 1
jproj = 2
Expand All @@ -88,7 +90,7 @@ module subroutine fraggle_set_mass_dist(self, param)
! The number of fragments we generate is bracked by the minimum required by fraggle_generate (7) and the
! maximum set by the NFRAG_SIZE_MULTIPLIER which limits the total number of fragments to prevent the nbody
! code from getting an overwhelmingly large number of fragments
nfrag = ceiling(NFRAG_SIZE_MULTIPLIER * log(fragments%mtot / min_mfrag))
nfrag = ceiling(NFRAG_SIZE_MULTIPLIER * log(mtot / min_mfrag))
nfrag = max(min(nfrag, NFRAGMAX), NFRAGMIN)
class default
min_mfrag = 0.0_DP
Expand Down Expand Up @@ -116,6 +118,7 @@ module subroutine fraggle_set_mass_dist(self, param)
case default
write(*,*) "fraggle_set_mass_dist_fragments error: Unrecognized regime code",impactors%regime
end select
fragments%mtot = mtot

! 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)
Expand Down
1 change: 1 addition & 0 deletions src/fraggle/fraggle_setup.f90
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ module subroutine fraggle_setup_fragments(self, n, param)
call collision_setup_fragments(self, n, param)
if (n < 0) return

if (allocated(self%rotmag)) deallocate(self%rotmag)
if (allocated(self%v_r_mag)) deallocate(self%v_r_mag)
if (allocated(self%v_t_mag)) deallocate(self%v_t_mag)
if (allocated(self%v_n_mag)) deallocate(self%v_t_mag)
Expand Down

0 comments on commit 199b288

Please sign in to comment.