-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy patheos.f90
162 lines (150 loc) · 5.22 KB
/
eos.f90
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
!------------------------------------------------------------------------------!
! NDSPMHD: A Smoothed Particle (Magneto)Hydrodynamics code for (astrophysical) !
! fluid dynamics simulations in 1, 2 and 3 spatial dimensions. !
! !
! (c) 2002-2015 Daniel Price !
! !
! http://users.monash.edu.au/~dprice/ndspmhd !
! daniel.price@monash.edu -or- dprice@cantab.net (forwards to current address) !
! !
! NDSPMHD comes with ABSOLUTELY NO WARRANTY. !
! This is free software; and you are welcome to redistribute !
! it under the terms of the GNU General Public License !
! (see LICENSE file for details) and the provision that !
! this notice remains intact. If you modify this file, please !
! note section 2a) of the GPLv2 states that: !
! !
! a) You must cause the modified files to carry prominent notices !
! stating that you changed the files and the date of any change. !
! !
! ChangeLog: !
!------------------------------------------------------------------------------!
!!-----------------------------------------------------------------
!! this subroutine returns the prsure and sound speed
!! from rho and/or u_therm via the equation of state
!!
!! size of array is specified on input, so can send in either whole
!! arrays or individual elements (just be consistent!)
!!-----------------------------------------------------------------
!-------------------------------------------------------------------
! equation of state related quantities
!-------------------------------------------------------------------
module eos
implicit none
real :: gamma, polyk
contains
subroutine equation_of_state(pr,vsound,uu,rho,gammai)
use options, only:iener
use loguns
use part, only:itype,itypegas,itypegas1,itypegas2,itypebnd
!
!--define local variables
!
implicit none
integer :: i,isize
real, intent(in), dimension(:) :: rho
real, intent(out), dimension(size(rho)) :: pr
real, intent(inout), dimension(size(rho)) :: uu,vsound
real, intent(in), dimension(size(rho)), optional :: gammai
real :: gamma1
isize = size(rho)
gamma1 = gamma - 1.
!
!--exit gracefully if rho is negative
!
if (any(rho.lt.0.)) then
write(iprint,*) 'eos: rho -ve, exiting'
do i=1,isize
if (rho(i).lt.0.) write(iprint,*) i,rho(i),uu(i)
enddo
!call quit
elseif ((iener.ne.0).and.any(uu.lt.0.)) then
write(iprint,*) 'eos: u_therm -ve, exiting',isize
do i=1,isize
if (uu(i).lt.0.) write(iprint,*) i,rho(i),uu(i)
enddo
stop
!call quit
endif
if (iener.eq.0) then ! polytropic (isothermal when gamma=1)
where (rho > 0. .AND. itype(1:isize).EQ.itypegas)
pr = polyk*rho**gamma
vsound = sqrt(gamma*pr/rho)
elsewhere (itype(1:isize).eq.itypegas1)
pr = polyk*(rho - 1.)
elsewhere (itype(1:isize).eq.itypegas2)
pr = polyk*(rho - 1.) !4.*polyk*((rho/0.5) - 1.)
elsewhere(itype(1:isize).ne.itypebnd)
pr = 0.
end where
if (abs(gamma1).gt.1.e-3) then
where (rho > 0.)
uu = pr/(gamma1*rho)
end where
endif
else ! adiabatic
if (present(gammai)) then
where (rho > 0.)
pr = (gammai-1)*uu*rho
vsound = sqrt(gammai*pr/rho)
end where
else
where (rho > 0.)
pr = gamma1*uu*rho
vsound = sqrt(gamma*pr/rho)
end where
endif
endif
return
end subroutine equation_of_state
subroutine equation_of_state1(pr,vsound,uu,rho,gammai)
use options, only:iener
use loguns
!
!--define local variables
!
implicit none
integer :: isize
real, intent(in) :: rho
real, intent(out) :: pr
real, intent(inout) :: uu,vsound
real, intent(in), optional :: gammai
real :: gamma1
gamma1 = gamma - 1.
!
!--exit gracefully if rho is negative
!
if (rho.lt.0.) then
write(iprint,*) 'eos1: rho -ve, exiting'
!call quit
elseif ((iener.ne.0).and.uu.lt.0.) then
write(iprint,*) 'eos1: u_therm -ve, exiting',isize
!call quit
endif
if (iener.eq.0) then ! polytropic (isothermal when gamma=1)
if (rho > 0.) then
pr = polyk*rho**gamma
vsound = sqrt(gamma*pr/rho)
endif
if (abs(gamma1).gt.1.e-3) then
if (rho > 0.) then
uu = pr/(gamma1*rho)
endif
endif
else ! adiabatic
if (present(gammai)) then
if (rho > 0.) then
pr = (gammai-1.)*uu*rho
vsound = sqrt(gammai*pr/rho)
endif
else
if (rho > 0.) then
pr = gamma1*uu*rho
vsound = sqrt(gamma*pr/rho)
endif
endif
!print *,'here ',uu,rho
endif
return
end subroutine equation_of_state1
end module eos