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

Law et al. 2021 stratified equation of state #268

Merged
merged 2 commits into from
Mar 14, 2022
Merged
Show file tree
Hide file tree
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
132 changes: 113 additions & 19 deletions src/main/eos.F90
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,11 @@ module eos
implicit none
integer, parameter, public :: maxeos = 20
real, public :: polyk, polyk2, gamma
real, public :: qfacdisc
real, public :: qfacdisc = 0.75, qfacdisc2 = 0.75
logical, parameter, public :: use_entropy = .false.
logical, public :: extract_eos_from_hdr = .false.
integer, public :: isink = 0
integer, public :: isink = 0.

data qfacdisc /0.75/

public :: equationofstate,setpolyk,eosinfo,utherm,en_from_utherm,get_mean_molecular_weight
public :: get_spsound,get_temperature,get_temperature_from_ponrho,eos_is_non_ideal,eos_outputs_mu
Expand All @@ -58,6 +57,7 @@ module eos
public :: calc_rec_ene,calc_temp_and_ene,entropy,get_rho_from_p_s
public :: init_eos,finish_eos,write_options_eos,read_options_eos
public :: print_eos_to_file
public :: write_headeropts_eos, read_headeropts_eos

private

Expand All @@ -81,6 +81,14 @@ module eos
ierr_units_not_set = 3, &
ierr_isink_not_set = 4

!
! 2D temperature structure fit parameters for HD 163296
!
real, public :: z0 = 1.
real, public :: alpha_z = 3.01
real, public :: beta_z = 0.42


contains

!----------------------------------------------------------------
Expand All @@ -107,11 +115,12 @@ subroutine equationofstate(eos_type,ponrhoi,spsoundi,rhoi,xi,yi,zi,eni,tempi,gam
real, intent(inout), optional :: eni
real, intent(inout), optional :: tempi,mu_local
real, intent(in) , optional :: gamma_local,Xlocal,Zlocal
real :: r,omega,bigH,polyk_new,r1,r2
real :: r1,r2
real :: gammai,temperaturei,mui,imui,X_i,Z_i
real :: cgsrhoi,cgseni,cgspresi,presi,gam1,cgsspsoundi
integer :: ierr
real :: uthermconst
real :: zq,cs2atm,cs2mid,cs2
#ifdef GR
real :: enthi,pondensi
! Check to see if adiabatic equation of state is being used.
Expand Down Expand Up @@ -208,21 +217,15 @@ subroutine equationofstate(eos_type,ponrhoi,spsoundi,rhoi,xi,yi,zi,eni,tempi,gam
case(7)
!
!-- z-dependent locally isothermal eos
!
r = sqrt(xi**2 + yi**2 + zi**2)
omega = r**(-1.5)
bigH = (sqrt(polyk)*r**(-qfacdisc))/omega

if (abs(zi) <= bigH) then
polyk_new = polyk
elseif (abs(zi) <= 2.0*bigH) then
polyk_new = polyk*(1.0+99.0*(abs(zi)-bigH))
else
polyk_new = 100.0*polyk
endif

ponrhoi = polyk_new*(xi**2 + yi**2 + zi**2)**(-qfacdisc)
spsoundi = sqrt(ponrhoi)
r2 = xi**2 + yi**2
cs2mid = polyk * r2**(-qfacdisc)
cs2atm = polyk2 * r2**(-qfacdisc2)
zq = z0 * r2**(0.5*beta_z)

! modified equation 6 from Law et al. (2021)
cs2 = (cs2mid**4 + 0.5*(1 + tanh((zi - alpha_z*zq)/zq))*cs2atm**4)**(1./4.)
ponrhoi = cs2
spsoundi = sqrt(cs2)
if (present(tempi)) tempi = temperature_coef*mui*ponrhoi

case(8)
Expand Down Expand Up @@ -1130,4 +1133,95 @@ real function get_mean_molecular_weight(XX,ZZ) result(mu)

end function get_mean_molecular_weight

!-----------------------------------------------------------------------
!+
! write relevant options to the header of the dump file
!+
!-----------------------------------------------------------------------
subroutine write_headeropts_eos(ieos,hdr,ierr)
use dump_utils, only:dump_h,add_to_rheader,add_to_iheader
integer, intent(in) :: ieos
type(dump_h), intent(inout) :: hdr
integer, intent(out) :: ierr

call add_to_iheader(isink,'isink',hdr,ierr)
call add_to_rheader(gamma,'gamma',hdr,ierr)
call add_to_rheader(1.5*polyk,'RK2',hdr,ierr)
call add_to_rheader(polyk2,'polyk2',hdr,ierr)
call add_to_rheader(qfacdisc,'qfacdisc',hdr,ierr)
call add_to_rheader(qfacdisc2,'qfacdisc2',hdr,ierr)

if (ieos==7) then
call add_to_rheader(alpha_z,'alpha_z',hdr,ierr)
call add_to_rheader(beta_z,'beta_z',hdr,ierr)
call add_to_rheader(z0,'z0',hdr,ierr)

endif

end subroutine write_headeropts_eos

!-----------------------------------------------------------------------
!+
! read relevant options from the header of the dump file
!+
!-----------------------------------------------------------------------
subroutine read_headeropts_eos(ieos,hdr,ierr)
use dump_utils, only:dump_h, extract
use io, only:iprint,id,master
use dim, only:use_krome,maxvxyzu
integer, intent(in) :: ieos
type(dump_h), intent(in) :: hdr
integer, intent(out) :: ierr
real :: RK2


call extract('gamma',gamma,hdr,ierr)
call extract('RK2',rk2,hdr,ierr)
polyk = 2./3.*rk2
if (id==master) then
if (maxvxyzu >= 4) then
if (use_krome) then
write(iprint,*) 'KROME eos: initial gamma = 1.666667'
else
write(iprint,*) 'adiabatic eos: gamma = ',gamma
endif
else
write(iprint,*) 'setting isothermal sound speed^2 (polyk) = ',polyk,' gamma = ',gamma
if (polyk <= tiny(polyk)) write(iprint,*) 'WARNING! sound speed zero in dump!, polyk = ',polyk
endif
endif
call extract('polyk2',polyk2,hdr,ierr)
call extract('qfacdisc',qfacdisc,hdr,ierr)
call extract('qfacdisc2',qfacdisc2,hdr,ierr)
call extract('isink',isink,hdr,ierr)

if (abs(gamma-1.) > tiny(gamma) .and. maxvxyzu < 4) then
write(*,*) 'WARNING! compiled for isothermal equation of state but gamma /= 1, gamma=',gamma
endif

ierr = 0
if (ieos==3 .or. ieos==6 .or. ieos==7) then
if (qfacdisc <= tiny(qfacdisc)) then
write(iprint,*) 'ERROR: qfacdisc <= 0'
ierr = 2
else
write(iprint,*) 'qfacdisc = ',qfacdisc
endif
endif

if (ieos==7) then
call extract('alpha_z',alpha_z,hdr,ierr)
call extract('beta_z', beta_z, hdr,ierr)
call extract('z0',z0,hdr,ierr)
if (qfacdisc2 <= tiny(qfacdisc2)) then
write(iprint,*) 'ERROR: qfacdisc2 <= 0'
ierr = 2
else
write(iprint,*) 'qfacdisc2 = ',qfacdisc2
endif
endif

end subroutine read_headeropts_eos


end module eos
2 changes: 1 addition & 1 deletion src/main/options.f90
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ subroutine set_default_options
ipdv_heating = 1
iresistive_heating = 1
icooling = 0
polyk2 = 0 ! only used for ieos=8
polyk2 = 0. ! only used for ieos=8

! artificial viscosity
if (maxalpha>0 .and. maxalpha==maxp) then
Expand Down
47 changes: 9 additions & 38 deletions src/main/readwrite_dumps_fortran.F90
Original file line number Diff line number Diff line change
Expand Up @@ -1488,7 +1488,7 @@ end subroutine unfill_header
!+
!-------------------------------------------------------------------
subroutine fill_header(sphNGdump,t,nparttot,npartoftypetot,nblocks,nptmass,hdr,ierr)
use eos, only:polyk,gamma,polyk2,qfacdisc,isink
use eos, only:write_headeropts_eos,polyk2
use options, only:tolh,alpha,alphau,alphaB,iexternalforce,ieos
use part, only:massoftype,hfact,Bextx,Bexty,Bextz,ndustsmall,ndustlarge,&
idust,grainsize,graindens,ndusttypes
Expand All @@ -1515,7 +1515,6 @@ subroutine fill_header(sphNGdump,t,nparttot,npartoftypetot,nblocks,nptmass,hdr,i
call add_to_iheader(maxtypes,'ntypes',hdr,ierr)
call add_to_iheader(int(npartoftypetot(1:maxtypes)),'npartoftype',hdr,ierr)
call add_to_iheader(nblocks,'nblocks',hdr,ierr)
call add_to_iheader(isink,'isink',hdr,ierr)
call add_to_iheader(nptmass,'nptmass',hdr,ierr)
call add_to_iheader(ndustlarge,'ndustlarge',hdr,ierr)
call add_to_iheader(ndustsmall,'ndustsmall',hdr,ierr)
Expand All @@ -1532,6 +1531,7 @@ subroutine fill_header(sphNGdump,t,nparttot,npartoftypetot,nblocks,nptmass,hdr,i
! int*4
call add_to_header(iexternalforce,'iexternalforce',hdr,ierr)
call add_to_header(ieos,'ieos',hdr,ierr)
call write_headeropts_eos(ieos,hdr,ierr)

! default real variables
call add_to_rheader(t,'time',hdr,ierr)
Expand All @@ -1541,9 +1541,7 @@ subroutine fill_header(sphNGdump,t,nparttot,npartoftypetot,nblocks,nptmass,hdr,i
else
call add_to_rheader(dtmax, 'dtmax0',hdr,ierr)
endif
call add_to_rheader(gamma,'gamma',hdr,ierr)
call add_to_rheader(rhozero,'rhozero',hdr,ierr)
call add_to_rheader(1.5*polyk,'RK2',hdr,ierr)
if (sphNGdump) then ! number = 23
call add_to_rheader(0.,'escaptot',hdr,ierr)
call add_to_rheader(0.,'tkin',hdr,ierr)
Expand Down Expand Up @@ -1571,8 +1569,6 @@ subroutine fill_header(sphNGdump,t,nparttot,npartoftypetot,nblocks,nptmass,hdr,i
call add_to_rheader(alpha,'alpha',hdr,ierr)
call add_to_rheader(alphau,'alphau',hdr,ierr)
call add_to_rheader(alphaB,'alphaB',hdr,ierr)
call add_to_rheader(polyk2,'polyk2',hdr,ierr)
call add_to_rheader(qfacdisc,'qfacdisc',hdr,ierr)
call add_to_rheader(massoftype,'massoftype',hdr,ierr) ! array
call add_to_rheader(Bextx,'Bextx',hdr,ierr)
call add_to_rheader(Bexty,'Bexty',hdr,ierr)
Expand Down Expand Up @@ -1622,7 +1618,7 @@ subroutine unfill_rheader(hdr,phantomdump,ntypesinfile,nptmass,&
tfile,hfactfile,alphafile,iprint,ierr)
use io, only:id,master
use dim, only:maxvxyzu,use_dust,use_dustgrowth,use_krome
use eos, only:polyk,gamma,polyk2,qfacdisc,extract_eos_from_hdr
use eos, only:extract_eos_from_hdr, read_headeropts_eos
use options, only:ieos,iexternalforce
use part, only:massoftype,Bextx,Bexty,Bextz,mhd,periodic,&
maxtypes,grainsize,graindens,ndusttypes
Expand All @@ -1642,7 +1638,7 @@ subroutine unfill_rheader(hdr,phantomdump,ntypesinfile,nptmass,&

integer, parameter :: lu = 173
integer :: ierrs(10),iextern_in_file
real :: rk2,xmini,xmaxi,ymini,ymaxi,zmini,zmaxi,dtmaxi
real :: xmini,xmaxi,ymini,ymaxi,zmini,zmaxi,dtmaxi
real :: alphaufile,alphaBfile,C_courfile,C_forcefile,tolhfile
logical :: iexist

Expand All @@ -1651,23 +1647,7 @@ subroutine unfill_rheader(hdr,phantomdump,ntypesinfile,nptmass,&
if (ierr/=0) call extract('gt',tfile,hdr,ierr) ! this is sphNG's label for time
call extract('dtmax',dtmaxi,hdr,ierr)
call extract('dtmax0',dtmax0,hdr,ierr)
call extract('gamma',gamma,hdr,ierr)
call extract('rhozero',rhozero,hdr,ierr)
call extract('RK2',rk2,hdr,ierr)
polyk = 2./3.*rk2
if (id==master) then
if (maxvxyzu >= 4) then
if (use_krome) then
write(iprint,*) 'KROME eos: initial gamma = 1.666667'
else
write(iprint,*) 'adiabatic eos: gamma = ',gamma
endif
else
write(iprint,*) 'setting isothermal sound speed^2 (polyk) = ',polyk,' gamma = ',gamma
if (polyk <= tiny(polyk)) write(iprint,*) 'WARNING! sound speed zero in dump!, polyk = ',polyk
endif
endif

Bextx = 0.
Bexty = 0.
Bextz = 0.
Expand All @@ -1685,17 +1665,9 @@ subroutine unfill_rheader(hdr,phantomdump,ntypesinfile,nptmass,&
if (mhd) then
call extract('alphaB',alphaBfile,hdr,ierr)
endif
call extract('polyk2',polyk2,hdr,ierr)
call extract('qfacdisc',qfacdisc,hdr,ierr)

if (extract_eos_from_hdr) call extract('ieos',ieos,hdr,ierr)
if (ieos==3) then
if (qfacdisc <= tiny(qfacdisc)) then
write(iprint,*) 'ERROR: qfacdisc <= 0'
ierr = 2
else
if (id==master) write(iprint,*) 'qfacdisc = ',qfacdisc
endif
endif

call extract('massoftype',massoftype(1:ntypesinfile),hdr,ierr)
if (ierr /= 0) then
write(*,*) '*** ERROR reading massoftype from dump header ***'
Expand All @@ -1712,10 +1684,11 @@ subroutine unfill_rheader(hdr,phantomdump,ntypesinfile,nptmass,&
endif
else
massoftype(1) = 0.
polyk2 = 0.
hfactfile = 0.
endif

call read_headeropts_eos(ieos,hdr,ierr)

if (periodic) then
call extract('xmin',xmini,hdr,ierrs(1))
call extract('xmax',xmaxi,hdr,ierrs(2))
Expand Down Expand Up @@ -1768,9 +1741,7 @@ subroutine unfill_rheader(hdr,phantomdump,ntypesinfile,nptmass,&
write(*,*) 'ERROR reading values to verify conservation laws. Resetting initial values.'
get_conserv = 1.0
endif
if (abs(gamma-1.) > tiny(gamma) .and. maxvxyzu < 4) then
write(*,*) 'WARNING! compiled for isothermal equation of state but gamma /= 1, gamma=',gamma
endif


!--pull grain size and density arrays if they are in the header
!-- i.e. if dustgrowth is not ON
Expand Down
14 changes: 13 additions & 1 deletion src/main/units.f90
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ module units
real(kind=8), public :: unit_ergg, unit_energ, unit_opacity

public :: set_units, set_units_extra, print_units
public :: get_G_code, get_c_code, get_radconst_code
public :: get_G_code, get_c_code, get_radconst_code, get_kbmh_code
public :: c_is_unity, G_is_unity, in_geometric_units

contains
Expand Down Expand Up @@ -304,6 +304,18 @@ real(kind=8) function get_radconst_code() result(radconst_code)
radconst_code = radconst/unit_energ*udist**3
end function get_radconst_code

!---------------------------------------------------------------------------
!+
! speed of light in code units
!+
!---------------------------------------------------------------------------
real(kind=8) function get_kbmh_code() result(kbmh_code)
use physcon, only:kb_on_mh

kbmh_code = kb_on_mh/unit_velocity**2

end function get_kbmh_code

!---------------------------------------------------------------------------
!+
! whether or not the Gravitational constant is unity in code units
Expand Down
4 changes: 2 additions & 2 deletions src/setup/set_disc.F90
Original file line number Diff line number Diff line change
Expand Up @@ -939,9 +939,9 @@ subroutine write_discinfo(iunit,R_in,R_out,R_ref,Q,npart,sigmaprofile, &
!--print some of these diagnostics in more useful form
if (itype == igas) then
if (T_ref < 1.0d3) then
write(iunit,"(a,f5.1,a,f5.1,a,f4.1,a,/)") '# Temperature profile = ',T_ref,'K (R/',R_ref,')^(',-2.*q_index,')'
write(iunit,"(a,f5.1,a,f5.1,a,f5.2,a,/)") '# Temperature profile = ',T_ref,'K (R/',R_ref,')^(',-2.*q_index,')'
else
write(iunit,"(a,es9.2,a,f5.1,a,f4.1,a,/)") '# Temperature profile = ',T_ref,'K (R/',R_ref,')^(',-2.*q_index,')'
write(iunit,"(a,es9.2,a,f5.1,a,f5.2,a,/)") '# Temperature profile = ',T_ref,'K (R/',R_ref,')^(',-2.*q_index,')'
endif
endif
if (sigmaprofile==0) then
Expand Down
Loading