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

Commit

Permalink
Improved scaling and unit consistency
Browse files Browse the repository at this point in the history
  • Loading branch information
daminton committed Aug 7, 2021
1 parent a72bdc5 commit e880213
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 6 deletions.
18 changes: 16 additions & 2 deletions src/fragmentation/fragmentation.f90
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ subroutine set_scale_factors()
! Set scale factors
Escale = 0.5_DP * (mass(1) * dot_product(v(:,1), v(:,1)) + mass(2) * dot_product(v(:,2), v(:,2)))
rscale = sum(radius(:))
mscale = sqrt(Escale * rscale) / param%GU
mscale = sqrt(Escale * rscale / param%GU)
vscale = sqrt(Escale / mscale)
tscale = rscale / vscale
Lscale = mscale * rscale * vscale
Expand Down Expand Up @@ -341,11 +341,25 @@ subroutine calculate_system_energy(linclude_fragments)
ltmp(1:npl) = .true.
call tmpsys%pl%setup(npl_new, param)
call tmpsys%pl%fill(pl, ltmp)
tmpsys%pl%mass(1:npl) = tmpsys%pl%mass(1:npl) / mscale
tmpsys%pl%Gmass(1:npl) = tmpsys%pl%Gmass(1:npl) * tscale**2 / rscale**3
tmpsys%cb%mass = tmpsys%cb%mass / mscale
tmpsys%cb%Gmass = tmpsys%cb%Gmass * tscale**2 / rscale**3
tmpsys%cb%radius = tmpsys%cb%radius / rscale
tmpsys%pl%radius(1:npl) = tmpsys%pl%radius(1:npl) / rscale
tmpsys%pl%xh(:,1:npl) = tmpsys%pl%xh(:,1:npl) / rscale
tmpsys%pl%vh(:,1:npl) = tmpsys%pl%vh(:,1:npl) / vscale
tmpsys%pl%xb(:,1:npl) = tmpsys%pl%xb(:,1:npl) / rscale
tmpsys%pl%vb(:,1:npl) = tmpsys%pl%vb(:,1:npl) / vscale
tmpsys%pl%rot(:,1:npl) = tmpsys%pl%rot(:,1:npl) * tscale
tmpsys%cb%xb(:) = tmpsys%cb%xb(:) / rscale
tmpsys%cb%vb(:) = tmpsys%cb%vb(:) / vscale


if (linclude_fragments) then ! Append the fragments if they are included
! Energy calculation requires the fragments to be in the system barcyentric frame, s
tmpsys%pl%mass(npl+1:npl_new) = m_frag(1:nfrag)
tmpsys%pl%Gmass(npl+1:npl_new) = param%GU * m_frag(1:nfrag)
tmpsys%pl%Gmass(npl+1:npl_new) = m_frag(1:nfrag) * param%GU * rscale**3 * mscale / tscale**2
tmpsys%pl%radius(npl+1:npl_new) = rad_frag(1:nfrag)
tmpsys%pl%xb(:,npl+1:npl_new) = xb_frag(:,1:nfrag)
tmpsys%pl%vb(:,npl+1:npl_new) = vb_frag(:,1:nfrag)
Expand Down
8 changes: 4 additions & 4 deletions src/util/util_get_energy_momentum.f90
Original file line number Diff line number Diff line change
Expand Up @@ -76,14 +76,14 @@ module subroutine util_get_energy_momentum_system(self, param)
!$omp simd
do i = 1, npl
associate(px => pl%xh(1,i), py => pl%xh(2,i), pz => pl%xh(3,i))
pecb(i) = -param%GU * cb%mass * pl%mass(i) / sqrt(px**2 + py**2 + pz**2)
pecb(i) = -cb%Gmass * pl%mass(i) / sqrt(px**2 + py**2 + pz**2)
end associate
end do

! Do the potential energy between pairs of massive bodies
do k = 1, pl%nplpl
associate(ik => pl%k_plpl(1, k), jk => pl%k_plpl(2, k))
pepl(k) = -param%GU * pl%mass(ik) * pl%mass(jk) / norm2(pl%xh(:, jk) - pl%xh(:, ik))
pepl(k) = -pl%Gmass(ik) * pl%mass(jk) / norm2(pl%xh(:, jk) - pl%xh(:, ik))
lstatpl(k) = (lstatus(ik) .and. lstatus(jk))
end associate
end do
Expand All @@ -99,8 +99,8 @@ module subroutine util_get_energy_momentum_system(self, param)
do i = 1, npl
irh(i) = 1.0_DP / norm2(pl%xh(:,i))
end do
call obl_pot(npl, cb%mass, pl%mass, cb%j2rp2, cb%j4rp4, pl%xh, irh, oblpot)
system%pe = system%pe + param%GU * oblpot
call obl_pot(npl, cb%Gmass, pl%mass, cb%j2rp2, cb%j4rp4, pl%xh, irh, oblpot)
system%pe = system%pe + oblpot
end if

system%Lorbit(1) = sum(Lplorbitx(1:npl), lstatus(1:npl))
Expand Down

0 comments on commit e880213

Please sign in to comment.