Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix sink potential check #234

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 25 additions & 20 deletions src/tests/test_ptmass.f90
Original file line number Diff line number Diff line change
Expand Up @@ -554,13 +554,13 @@ subroutine test_createsink(ntests,npass)
use ptmass, only:ndptmass,ptmass_accrete,update_ptmass,icreate_sinks,&
ptmass_create,finish_ptmass,ipart_rhomax,h_acc
use energies, only:compute_energies,angtot,etot,totmom
use mpiutils, only:bcast_mpi,reduce_in_place_mpi,reduceloc_mpi
use mpiutils, only:bcast_mpi,reduce_in_place_mpi,reduceloc_mpi,reduceall_mpi
use spherical, only:set_sphere
use stretchmap, only:rho_func
integer, intent(inout) :: ntests,npass
integer :: i,itest,itestp,nfailed(3),imin(1)
integer :: id_rhomax,ipart_rhomax_global
real :: psep,totmass,r2min,r2,xcofm(3),t
real :: psep,totmass,r2min,r2,t
real :: etotin,angmomin,totmomin,rhomax,rhomax_test
procedure(rho_func), pointer :: density_func

Expand Down Expand Up @@ -590,39 +590,44 @@ subroutine test_createsink(ntests,npass)
! set up gas particles in a uniform sphere with radius R=0.2
!
psep = 0.05 ! required as a variable since this may change under conditions not requested here
if (itest==2) then
! use random so particle with maximum density is unique
call set_sphere('cubic',id,master,0.,0.2,psep,hfact,npartoftype(igas),xyzh,rhofunc=density_func)
if (id == master) then
if (itest==2) then
! use random so particle with maximum density is unique
call set_sphere('cubic',id,master,0.,0.2,psep,hfact,npartoftype(igas),xyzh,rhofunc=density_func)
else
call set_sphere('cubic',id,master,0.,0.2,psep,hfact,npartoftype(igas),xyzh)
endif
else
call set_sphere('cubic',id,master,0.,0.2,psep,hfact,npartoftype(igas),xyzh)
npartoftype(igas) = 0
endif
totmass = 1.0
massoftype(igas) = totmass/real(npartoftype(igas))
massoftype(igas) = totmass/real(reduceall_mpi('+',npartoftype(igas)))
npart = npartoftype(igas)

if (maxphase==maxp) iphase(1:npart) = isetphase(igas,iactive=.true.)
!
! give inward radial velocities
! set up tree for neighbour finding
! and make sure that gravitational potential energy has been computed
!
tree_accuracy = 0.
icreate_sinks = 1

call get_derivs_global()

!
! calculate itest after calling derivs because particles will
! rebalance across tasks
!
itestp = npart
r2min = huge(r2min)
xcofm(:) = 0.
itestp = npart
do i=1,npart
r2 = dot_product(xyzh(1:3,i),xyzh(1:3,i))
if (r2 < r2min) then
itestp = i
r2min = r2
endif
xcofm = xcofm + xyzh(1:3,i)
enddo

xcofm = massoftype(igas)*xcofm/totmass
if (maxphase==maxp) iphase(1:npart) = isetphase(igas,iactive=.true.)
!
! set up tree for neighbour finding
! and make sure that gravitational potential energy has been computed
!
tree_accuracy = 0.
icreate_sinks = 1
call get_derivs_global()
!
! check that particle being tested is at the maximum density
!
Expand Down