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

Add the option to integrate ptmass with 4th order scheme (FSI) #523

Merged
merged 63 commits into from
Apr 22, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
63 commits
Select commit Hold shift + click to select a range
bf9ef22
add the option to integrate ptmass with 4th order scheme
Yrisch Apr 3, 2024
0049d96
Fix a wrong compiler flag name
Yrisch Apr 3, 2024
c221ac4
Remove ifdef + step_extern in a module
Yrisch Apr 3, 2024
b4210eb
add gradient acceleration kernel in the python script
Yrisch Apr 3, 2024
fc926ff
remove kernel in ptmass and fix bad sign
Yrisch Apr 4, 2024
9a98c69
updated kernels.py to spit out gradient term needed in 4th order inte…
danieljprice Apr 5, 2024
bf0d3c9
merge
danieljprice Apr 5, 2024
d9dc344
add mpi support for FSI (just grav)
Yrisch Apr 8, 2024
998d84a
mpi version of gradf
Yrisch Apr 8, 2024
6e7825c
Merge branch '4thorder_scheme' of github.com:Yrisch/phantom into 4tho…
danieljprice Apr 8, 2024
c7b8de7
step_extern.f90 -> step_extern.F90
Yrisch Apr 8, 2024
539897e
Merge branch '4thorder_scheme' of https://github.com/Yrisch/phantom i…
Yrisch Apr 8, 2024
9899fe2
(kernel) added kernel_cubic with new softening function
danieljprice Apr 8, 2024
7027b4f
Merge branch '4thorder_scheme' of github.com:Yrisch/phantom into 4tho…
danieljprice Apr 8, 2024
dae95a1
(FSI) added kernel modules needed for FSI integrator
danieljprice Apr 8, 2024
1239bfb
fix mpi reduce and step extern name
Yrisch Apr 8, 2024
cad9f57
correct typo in ptmass and remove PEFRL
Yrisch Apr 8, 2024
bcffd85
add option use_fourthorder in ptmass file + new simple setup for testing
Yrisch Apr 9, 2024
531221d
add new extrapolation method for FSI (still in test...)
Yrisch Apr 9, 2024
268d972
Merge branch 'master' into 4thorder_scheme
Yrisch Apr 10, 2024
0c34f8c
Merge branch 'master' into 4thorder_scheme
Yrisch Apr 10, 2024
2912d0a
add an additionnal array for FSI gradient force computation + few twe…
Yrisch Apr 10, 2024
7cd0cfa
beginning of the step extern routine to get a more general pattern
Yrisch Apr 11, 2024
b7498f7
clean up of the parallel closes in step_lf
Yrisch Apr 11, 2024
cbfd995
main refactory of step extern... (still need to merge extrap force an…
Yrisch Apr 12, 2024
a6e079d
refactory finished. still few compilation warnings to clear up.
Yrisch Apr 12, 2024
77b54dd
fix update vdep extf for all int order + ck and dk init + clean up
Yrisch Apr 15, 2024
e6bf68a
Merge branch 'master' into 4thorder_scheme
Yrisch Apr 15, 2024
2182243
fix name prdrag
Yrisch Apr 15, 2024
7b783f4
fix option ck and dk
Yrisch Apr 15, 2024
b08de27
fix compilation errors and warnings
Yrisch Apr 15, 2024
169958e
fix bug gw strain and non moving ptmass
Yrisch Apr 15, 2024
50a43a0
fix spin update not supposed to be in drift
Yrisch Apr 15, 2024
feee68c
(docs) update vscode findent info [skip ci]
danieljprice Apr 15, 2024
870db0c
Merge branch '4thorder_scheme' of github.com:Yrisch/phantom into 4tho…
danieljprice Apr 15, 2024
81d38c3
fix nbody and blob test compilation errors
Yrisch Apr 15, 2024
c1633be
fix fourth order test fails + make FSI default option without vdep fo…
Yrisch Apr 16, 2024
b3d1de1
add precision switching sub
Yrisch Apr 16, 2024
65e1b4f
fptmas and dsdt need to be zeroed if there is only 1 ptmass... dtfacp…
Yrisch Apr 17, 2024
a901f80
rename and fix star cluster setup + fix cooling function for blob setup
Yrisch Apr 17, 2024
3d79a1c
step_extern to substepping and move precision switcher in substepping
Yrisch Apr 17, 2024
29a21c6
comments
Yrisch Apr 18, 2024
1080e58
Merge branch '4thorder_scheme' of github.com:Yrisch/phantom into 4tho…
danieljprice Apr 18, 2024
3a499f4
(github) updated actions/checkout to v4
danieljprice Apr 18, 2024
50748db
fix weird failure
Yrisch Apr 18, 2024
c9cc1eb
Merge branch '4thorder_scheme' of github.com:Yrisch/phantom into 4tho…
danieljprice Apr 18, 2024
01f607f
(test) fix build failure
danieljprice Apr 18, 2024
6e73965
fix wrong dt in cooling/abundances function
Yrisch Apr 18, 2024
e3cbe5e
fix starcluster setup import
Yrisch Apr 18, 2024
33a30a0
(cons2prim,energies) unused variable warnings fixed with OPENMP=no
danieljprice Apr 19, 2024
6cfd0cc
(test_ptmass) added further checks of accreting many particles at onc…
danieljprice Apr 19, 2024
b4151dc
bug fix with previous warning fix
danieljprice Apr 19, 2024
9a7b492
(test_ptmass) revert change to disc mass causing test failures
danieljprice Apr 22, 2024
fb3f550
fix angular momentum non conservation issue...
Yrisch Apr 22, 2024
99c8f03
added missing routine to quintic module
danieljprice Apr 22, 2024
b299eb2
Merge branch '4thorder_scheme' of github.com:Yrisch/phantom into 4tho…
danieljprice Apr 22, 2024
0838eb2
#457 adjust tolerances for test ptmass
Yrisch Apr 22, 2024
8639afa
Merge branch '4thorder_scheme' of https://github.com/Yrisch/phantom i…
Yrisch Apr 22, 2024
c4045eb
fix bad tolerance wihout ind timestep
Yrisch Apr 22, 2024
5d380f6
(test_ptmass) added ptmassfsi to run the FSI integrator only; also fi…
danieljprice Apr 22, 2024
23af2c9
Merge branch '4thorder_scheme' of github.com:Yrisch/phantom into 4tho…
danieljprice Apr 22, 2024
f5242a7
fix tolerances 2
Yrisch Apr 22, 2024
426221a
fix tolerances v3
Yrisch Apr 22, 2024
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
4 changes: 4 additions & 0 deletions build/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,10 @@ ifeq ($(RADIATION), yes)
FPPFLAGS += -DRADIATION
endif

ifeq ($(FOURTHORDER), yes)
FPPFLAGS += -DFOURTHORDER
endif
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same comment as below... no new ifdefs!


ifeq ($(SINK_RADIATION), yes)
FPPFLAGS += -DSINK_RADIATION
endif
Expand Down
7 changes: 7 additions & 0 deletions src/main/config.F90
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,13 @@ module dim
logical, parameter :: do_radiation = .false.
#endif

! Regularisation method and/or higher order integrator
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

see #55, this really should be a runtime parameter, not a compile-time parameter. Suggest to remove the #ifdef here...

#ifdef FOURTHORDER
logical, parameter :: use_fourthorder = .true.
#else
logical, parameter :: use_fourthorder = .false.
#endif

! rhosum
integer, parameter :: maxrhosum = 39 + &
maxdustlarge - 1 + &
Expand Down
243 changes: 243 additions & 0 deletions src/main/ptmass.F90
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ module ptmass
public :: init_ptmass, finish_ptmass
public :: pt_write_sinkev, pt_close_sinkev
public :: get_accel_sink_gas, get_accel_sink_sink
public :: get_gradf_sink_gas, get_gradf_sink_sink
public :: merge_sinks
public :: ptmass_predictor, ptmass_corrector
public :: ptmass_not_obscured
Expand Down Expand Up @@ -110,6 +111,27 @@ module ptmass
private

contains

!----------------------------------------------------------------
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will open an issue on this, we should fix the kernel-generating python script to also produce this routine #523

!+
! Kernel for gradient force calculation, necessary for the FSI
!+
!----------------------------------------------------------------
pure subroutine kernel_grad_soft(q2,q,gsoft)
real, intent(in) :: q2,q
real, intent(out) :: gsoft
real :: q4,q6

if (q<1.) then
gsoft = q*(-15.*q2*q-24.*q2)/10.
else
q4 = q2*q2
q6 = q4*q2
gsoft = (25.*q6-120.*q4*q+150.*q4-10.)/(50.*q2)
endif

end subroutine kernel_grad_soft

!----------------------------------------------------------------
!+
! if (tofrom==.true.) Acceleration from/to gas particles due to sink particles;
Expand Down Expand Up @@ -469,6 +491,227 @@ subroutine get_accel_sink_sink(nptmass,xyzmh_ptmass,fxyz_ptmass,phitot,dtsinksin
enddo

end subroutine get_accel_sink_sink

!----------------------------------------------------------------
!+
! get gradient correction of the force for FSI integrator (sink-gas)
!+
!----------------------------------------------------------------
subroutine get_gradf_sink_gas(nptmass,dt,xi,yi,zi,hi,xyzmh_ptmass,fxi,fyi,fzi, &
pmassi,fxyz_ptmass)
use kernel, only:kernel_softening,radkern
integer, intent(in) :: nptmass
real, intent(in) :: xi,yi,zi,hi,dt
real, intent(inout) :: fxi,fyi,fzi
real, intent(in) :: xyzmh_ptmass(nsinkproperties,nptmass)
real, intent(in) :: pmassi
real, intent(inout) :: fxyz_ptmass(4,nptmass)
real :: gtmpxi,gtmpyi,gtmpzi
real :: dx,dy,dz,rr2,ddr,dr3,g11,g12,g21,g22,pmassj
real :: dfx,dfy,dfz,drdotdf
real :: hsoft,hsoft1,hsoft21,q2i,qi,psoft,fsoft,gsoft,gpref
integer :: j

gtmpxi = 0. ! use temporary summation variable
gtmpyi = 0. ! (better for round-off, plus we need this bit of
gtmpzi = 0.

do j=1,nptmass
dx = xi - xyzmh_ptmass(1,j)
dy = yi - xyzmh_ptmass(2,j)
dz = zi - xyzmh_ptmass(3,j)
dfx = fxi - fxyz_ptmass(1,j)
dfy = fyi - fxyz_ptmass(2,j)
dfz = fzi - fxyz_ptmass(3,j)
pmassj = xyzmh_ptmass(4,j)
hsoft = xyzmh_ptmass(ihsoft,j)
if (hsoft > 0.0) hsoft = max(hsoft,hi)
if (pmassj < 0.0) cycle

rr2 = dx*dx + dy*dy + dz*dz + epsilon(rr2)
drdotdf = dx*dfx + dy*dfy + dz*dfz + epsilon(drdotdf)
ddr = 1./sqrt(rr2)
if (rr2 < (radkern*hsoft)**2) then
!
! if the sink particle is given a softening length, soften the
! force and potential if r < radkern*hsoft
!
hsoft1 = 1.0/hsoft
hsoft21= hsoft1**2
q2i = rr2*hsoft21
qi = sqrt(q2i)
call kernel_softening(q2i,qi,psoft,fsoft)

gpref = ((dt**2)/24.)*hsoft21

! first grad term of gas due to point mass particle
g11 = pmassj*fsoft*ddr

! first grad term of sink from gas
g21 = pmassi*fsoft*ddr

call kernel_grad_soft(q2i,qi,gsoft)

dr3 = ddr*ddr*ddr

! Second grad term of gas due to point mass particle
g12 = pmassj*gsoft*dr3*drdotdf

! Second grad term of sink from gas
g22 = pmassi*gsoft*dr3*drdotdf

gtmpxi = gtmpxi - gpref*(dfx*g11-dx*g12)
gtmpyi = gtmpyi - gpref*(dfy*g11-dy*g12)
gtmpzi = gtmpzi - gpref*(dfz*g11-dz*g12)


else
! no softening on the sink-gas interaction
dr3 = ddr*ddr*ddr

gpref = ((dt**2)/24.)

! first grad term of gas due to point mass particle
g11 = pmassj*dr3

! first grad term of sink from gas
g21 = pmassi*dr3

! first grad term of gas due to point mass particle
g12 = 3*pmassj*dr3*ddr*ddr*drdotdf

! first grad term of sink from gas
g22 = 3*pmassi*dr3*ddr*ddr*drdotdf


gtmpxi = gtmpxi - gpref*(dfx*g11-dx*g12)
gtmpyi = gtmpyi - gpref*(dfy*g11-dy*g12)
gtmpzi = gtmpzi - gpref*(dfz*g11-dz*g12)
endif

! backreaction of gas onto sink
fxyz_ptmass(1,j) = fxyz_ptmass(1,j) + gpref*(dfx*g21 - dx*g22)
fxyz_ptmass(2,j) = fxyz_ptmass(2,j) + gpref*(dfy*g21 - dy*g22)
fxyz_ptmass(3,j) = fxyz_ptmass(3,j) + gpref*(dfz*g21 - dz*g22)
enddo
!
! add temporary sums to existing force on gas particle
!
fxi = fxi + gtmpxi
fyi = fyi + gtmpyi
fzi = fzi + gtmpzi

end subroutine get_gradf_sink_gas

!----------------------------------------------------------------
!+
! get gradient correction of the force for FSI integrator (sink-gas)
!+
!----------------------------------------------------------------
subroutine get_gradf_sink_sink(nptmass,xyzmh_ptmass,fxyz_ptmass,dt)
use kernel, only:kernel_softening,radkern
integer, intent(in) :: nptmass
real, intent(in) :: xyzmh_ptmass(nsinkproperties,nptmass)
real, intent(inout) :: fxyz_ptmass(4,nptmass)
real, intent(in) :: dt
real :: xi,yi,zi,pmassi,pmassj,fxi,fyi,fzi,gxi,gyi,gzi
real :: ddr,dx,dy,dz,dfx,dfy,dfz,drdotdf,rr2,dr3,g1,g2
real :: hsoft1,hsoft21,q2i,qi,psoft,fsoft,gsoft
real :: gpref
integer :: i,j

if (nptmass <= 1) return
if (h_soft_sinksink > 0.) then
hsoft1 = 1.0/h_soft_sinksink
hsoft21= hsoft1**2
else
hsoft1 = 0. ! to avoid compiler warnings
hsoft21 = 0.
endif
!
!--compute N^2 gradf on point mass particles due to each other
!
!$omp parallel do default(none) &
!$omp shared(nptmass,xyzmh_ptmass,fxyz_ptmass) &
!$omp shared(h_soft_sinksink,hsoft21,dt) &
!$omp private(i,xi,yi,zi,pmassi,pmassj) &
!$omp private(dx,dy,dz,dfx,dfy,dfz,drdotdf,rr2,ddr,dr3,g1,g2) &
!$omp private(fxi,fyi,fzi,gxi,gyi,gzi,gpref) &
!$omp private(q2i,qi,psoft,fsoft,gsoft)
do i=1,nptmass
xi = xyzmh_ptmass(1,i)
yi = xyzmh_ptmass(2,i)
zi = xyzmh_ptmass(3,i)
pmassi = xyzmh_ptmass(4,i)
if (pmassi < 0.) cycle
fxi = fxyz_ptmass(1,i)
fyi = fxyz_ptmass(2,i)
fzi = fxyz_ptmass(3,i)
gxi = 0.
gyi = 0.
gzi = 0.
do j=1,nptmass
if (i==j) cycle
dx = xi - xyzmh_ptmass(1,j)
dy = yi - xyzmh_ptmass(2,j)
dz = zi - xyzmh_ptmass(3,j)
dfx = fxi - fxyz_ptmass(1,j)
dfy = fyi - fxyz_ptmass(2,j)
dfz = fzi - fxyz_ptmass(3,j)
pmassj = xyzmh_ptmass(4,j)
if (pmassj < 0.) cycle

rr2 = dx*dx + dy*dy + dz*dz + epsilon(rr2)
drdotdf = dx*dfx + dy*dfy + dz*dfz +epsilon(drdotdf)
ddr = 1./sqrt(rr2)

gpref = pmassj*((dt**2)/24.)

if (rr2 < (radkern*h_soft_sinksink)**2) then
!
! if the sink particle is given a softening length, soften the
! force and potential if r < radkern*h_soft_sinksink
!
q2i = rr2*hsoft21
qi = sqrt(q2i)
call kernel_softening(q2i,qi,psoft,fsoft) ! Note: psoft < 0


! gradf part 1 of sink1 from sink2
g1 = fsoft*hsoft21*ddr

call kernel_grad_soft(q2i,qi,gsoft)

dr3 = ddr*ddr*ddr

! gradf part 2 of sink1 from sink2
g2 = gsoft*hsoft21*dr3*drdotdf
gxi = gxi - gpref*(dfx*g1 - dx*g2)
gyi = gyi - gpref*(dfy*g1 - dy*g2)
gzi = gzi - gpref*(dfz*g1 - dz*g2)

else
! no softening on the sink-sink interaction
dr3 = ddr*ddr*ddr

! gradf part 1 of sink1 from sink2
g1 = dr3
! gradf part 2 of sink1 from sink2
g2 = 3*dr3*ddr*ddr*drdotdf
gxi = gxi - gpref*(dfx*g1 - dx*g2)
gyi = gyi - gpref*(dfy*g1 - dy*g2)
gzi = gzi - gpref*(dfz*g1 - dz*g2)
endif
enddo
!
!--store sink-sink forces (only)
!
fxyz_ptmass(1,i) = fxyz_ptmass(1,i) + gxi
fxyz_ptmass(2,i) = fxyz_ptmass(2,i) + gyi
fxyz_ptmass(3,i) = fxyz_ptmass(3,i) + gzi
enddo
!$omp end parallel do
end subroutine get_gradf_sink_sink
!----------------------------------------------------------------
!+
! Update position of sink particles if they cross the periodic boundary
Expand Down
Loading
Loading