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

Commit

Permalink
Streamlined pseudovelocity conversion now that the methods are attach…
Browse files Browse the repository at this point in the history
…ed to the swiftest_body class
  • Loading branch information
daminton committed Jul 12, 2021
1 parent 0f65016 commit af307f7
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 59 deletions.
25 changes: 7 additions & 18 deletions examples/whm_gr_test/swiftest_relativity.ipynb

Large diffs are not rendered by default.

28 changes: 6 additions & 22 deletions src/io/io.f90
Original file line number Diff line number Diff line change
Expand Up @@ -975,12 +975,8 @@ module subroutine io_write_discard(self, param)
call util_exit(FAILURE)
end select
lfirst = .false.
if (param%lgr) then
select type(discards)
class is (whm_tp)
call discards%pv2vh(param)
end select
end if
if (param%lgr) call discards%pv2v(param)

write(LUN, HDRFMT) t, nsp, param%lbig_discard
do i = 1, nsp
write(LUN, NAMEFMT) sub, dname(i), dstatus(i)
Expand All @@ -993,11 +989,8 @@ module subroutine io_write_discard(self, param)

if (param%lgr) then
allocate(pltemp, source = pl)
select type(pltemp)
class is (whm_pl)
call pltemp%pv2vh(param)
allocate(vh, source = pltemp%vh)
end select
call pltemp%pv2v(param)
allocate(vh, source = pltemp%vh)
deallocate(pltemp)
else
allocate(vh, source = pl%vh)
Expand All @@ -1007,7 +1000,6 @@ module subroutine io_write_discard(self, param)
do i = 1, npl
write(LUN, PLNAMEFMT) name(i), GMpl(i), Rpl(i)
write(LUN, VECFMT) xh(1, i), xh(2, i), xh(3, i)

write(LUN, VECFMT) vh(1, i), vh(2, i), vh(3, i)
end do
deallocate(vh)
Expand Down Expand Up @@ -1189,16 +1181,8 @@ module subroutine io_write_frame_system(self, iu, param)
call io_write_hdr(iu, param%t, pl%nbody, tp%nbody, param%out_form, param%out_type)

if (param%lgr) then
associate(vh => pl%vh, vht => tp%vh)
select type(pl)
class is (whm_pl)
call pl%pv2vh(param)
end select
select type(tp)
class is (whm_tp)
call tp%pv2vh(param)
end select
end associate
call pl%pv2v(param)
call tp%pv2v(param)
end if

if (param%out_form == EL) then ! Do an orbital element conversion prior to writing out the frame, as we have access to the central body here
Expand Down
4 changes: 2 additions & 2 deletions src/modules/swiftest_classes.f90
Original file line number Diff line number Diff line change
Expand Up @@ -159,8 +159,8 @@ module swiftest_classes
procedure(abstract_step_body), public, deferred :: step
procedure(abstract_accel), public, deferred :: accel
! These are concrete because the implementation is the same for all types of particles
procedure, public :: vh2pv => gr_vh2pv_body !! Converts from heliocentric velocity to psudeovelocity for GR calculations
procedure, public :: pv2vh => gr_pv2vh_body !! Converts from psudeovelocity to heliocentric velocity for GR calculations
procedure, public :: v2pv => gr_vh2pv_body !! Converts from velocity to psudeovelocity for GR calculations using symplectic integrators
procedure, public :: pv2v => gr_pv2vh_body !! Converts from psudeovelocity to velocity for GR calculations using symplectic integrators
procedure, public :: initialize => io_read_body_in !! Read in body initial conditions from a file
procedure, public :: read_frame => io_read_frame_body !! I/O routine for writing out a single frame of time-series data for the central body
procedure, public :: write_frame => io_write_frame_body !! I/O routine for writing out a single frame of time-series data for the central body
Expand Down
4 changes: 2 additions & 2 deletions src/modules/whm_classes.f90
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ end subroutine whm_gr_getacch_tp
module pure subroutine whm_gr_p4_pl(self, param, dt)
use swiftest_classes, only : swiftest_parameters
implicit none
class(whm_pl), intent(inout) :: self !! Swiftest particle object
class(whm_pl), intent(inout) :: self !! WHM massive body object
class(swiftest_parameters), intent(in) :: param !! Current run configuration parameters of on parameters
real(DP), intent(in) :: dt !! Step size
end subroutine whm_gr_p4_pl
Expand All @@ -178,7 +178,7 @@ end subroutine whm_gr_p4_tp
!> Reads WHM massive body object in from file
module subroutine whm_setup_pl(self,n)
implicit none
class(whm_pl), intent(inout) :: self !! Swiftest test particle object
class(whm_pl), intent(inout) :: self !! WHM massive body objectobject
integer(I4B), intent(in) :: n !! Number of test particles to allocate
end subroutine whm_setup_pl

Expand Down
22 changes: 8 additions & 14 deletions src/whm/whm_setup.f90
Original file line number Diff line number Diff line change
Expand Up @@ -58,15 +58,14 @@ module subroutine whm_util_set_mu_eta_pl(self, cb)
! Internals
integer(I4B) :: i

associate(pl => self, npl => self%nbody, GMpl => self%Gmass, muj => self%muj, &
eta => self%eta, GMcb => cb%Gmass)
associate(pl => self, npl => self%nbody)
if (npl == 0) return
call util_set_mu_pl(pl, cb)
eta(1) = GMcb + GMpl(1)
muj(1) = eta(1)
pl%eta(1) = cb%Gmass + pl%Gmass(1)
pl%muj(1) = pl%eta(1)
do i = 2, npl
eta(i) = eta(i - 1) + GMpl(i)
muj(i) = GMcb * eta(i) / eta(i - 1)
pl%eta(i) = pl%eta(i - 1) + pl%Gmass(i)
pl%muj(i) = cb%Gmass * pl%eta(i) / pl%eta(i - 1)
end do
end associate

Expand All @@ -81,20 +80,15 @@ module subroutine whm_setup_system(self, param)
! Arguments
class(whm_nbody_system), intent(inout) :: self !! Swiftest system object
class(swiftest_parameters), intent(inout) :: param !! Current run configuration parameters of on parameters

call io_read_initialize_system(self, param)
! Make sure that the discard list gets allocated initially
call self%tp_discards%setup(self%tp%nbody)
call self%pl%set_mu(self%cb)
call self%tp%set_mu(self%cb)
if (param%lgr) then
select type(pl => self%pl)
class is (whm_pl)
call pl%vh2pv(param)
end select
select type(tp => self%tp)
class is (whm_tp)
call tp%vh2pv(param)
end select
call self%pl%v2pv(param)
call self%tp%v2pv(param)
end if

end subroutine whm_setup_system
Expand Down
2 changes: 1 addition & 1 deletion src/whm/whm_step.f90
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ module subroutine whm_step_system(self, param, t, dt)
real(DP), intent(in) :: t !! Current simulation time
real(DP), intent(in) :: dt !! Current stepsize

associate(system => self, cb => self%cb, pl => self%pl, tp => self%tp, ntp => self%tp%nbody)
associate(system => self, cb => self%cb, pl => self%pl, tp => self%tp)
call pl%set_rhill(cb)
call pl%step(system, param, t, dt)
call tp%step(system, param, t, dt)
Expand Down

0 comments on commit af307f7

Please sign in to comment.