Coverage for planit/eos/eos_table.py: 81%
552 statements
« prev ^ index » next coverage.py v7.17.2, created at 2026-11-11 15:42 +0000
« prev ^ index » next coverage.py v7.17.2, created at 2026-11-11 15:42 +0000
1"""
2Classes and functions for accessing and manipulating tabulated EOS data.
4Sarah T. Stewart (sts@sarahstewart.net)
6"""
7##############################################################
8# IMPORT PYTHON MODULES
9import numpy as np
10#
11# GLOBAL VARIABLE
12__version__ = 'v1.1.5b' # 7/1/2023 added temperatures to MGR and TIL-iSALE EOS;
13# fixed logic for iSALE Tillotson; problems with SESAME interpolation near zero pressure and tension
14#__version__ = 'v1.1.4' # 6/24/2023 added load STD NOTENSION table
15#__version__ = 'v1.1.3' # 2/15/2023 added write SESAME EXT table function
16#__version__ = 'v1.1.1' # 2/11/2023 minor print statement removals
17#__version__ = 'v1.1' # 2/6/2023 STS adding ideal gas compatibility
18#__version__ = 'v1.0.1' # 2/27/2022 STS Added to classes for plotting data against the ANEOS model
19#__version__ = 'v1.0' # 09/2019 STS original module created for ANEOS-Forsterite-2019
20#
21##############################################################
22#
23# calculate the structure for one planet
24# make a class to hold the PREM data
25class isentrope_class:
26 """Class to isentrope data extracted from EOS table.""" # this is a documentation string for this class
27 def __init__(self): # self is the default name of the object for internal referencing of the variables in the class
28 """A function to initialize the class object.""" # this is a documentation string for this function
29 self.ND = 0 # number of radius points
30 self.density = []
31 self.pressure = []
32 self.temperature = []
33 self.soundspeed = []
34 self.energy = []
35 self.partvel = []
36 self.region = [] # Tillotson region flag
37 # not going to use all the variables in the file
38 self.units = '' # I like to keep a text note in a structure about the units
39 self.label = ''
40#
41# make a class to hold a curve (e.g., isentrope) through EOS surface
42class EOScurve:
43 """Class EOS curve.""" # this is a documentation string for this class
44 def __init__(self): # self is the default name of the object for internal referencing of the variables in the class
45 """A function to initialize the class object.""" # this is a documentation string for this function
46 self.rho = []
47 self.P = []
48 self.P_err = []
49 self.T = []
50 self.cs = []
51 self.gamma = []
52 self.U = []
53 self.U_err = []
54 self.up = []
55 self.us = []
56 # not going to use all the variables in the file
57 self.units = '' # I like to keep a text note in a structure about the units
58 self.label = ''
59#
60class EOShugoniot:
61 """Class for Hugoniot array from extEOStable."""
62 def __init__(self):
63 self.NH = 0
64 self.rho0 = 0.
65 self.rho0_err = 0.
66 self.T0 = 0.
67 self.rho = np.zeros(self.NH)
68 self.rho_err = np.zeros(self.NH)
69 self.T = np.zeros(self.NH)
70 self.T_err = np.zeros(self.NH)
71 self.P = np.zeros(self.NH)
72 self.P_err = np.zeros(self.NH)
73 self.U = np.zeros(self.NH)
74 self.S = np.zeros(self.NH)
75 self.S_err = np.zeros(self.NH)
76 self.up = np.zeros(self.NH)
77 self.up_err = np.zeros(self.NH)
78 self.us = np.zeros(self.NH)
79 self.us_err = np.zeros(self.NH)
80 self.cs = np.zeros(self.NH)
81 self.ref = np.zeros(self.NH) # reflectivity
82 self.ref_err = np.zeros(self.NH) # reflectivity
83 self.gamma = np.zeros(self.NH)
84 self.gamma_err = np.zeros(self.NH)
85 self.units = ''
86 self.label = ''
87#
88class EOSvaporcurve:
89 """Class for vapor curve from ANEOS."""
90 def __init__(self):
91 self.NT = 0
92 self.NV = 0
93 self.T = np.zeros(self.NT)
94 self.rl = np.zeros(self.NT)
95 self.rv = np.zeros(self.NT)
96 self.Pl = np.zeros(self.NT)
97 self.Pv = np.zeros(self.NT)
98 self.Ul = np.zeros(self.NT)
99 self.Uv = np.zeros(self.NT)
100 self.Sl = np.zeros(self.NT)
101 self.Sv = np.zeros(self.NT)
102 self.Gl = np.zeros(self.NT)
103 self.Gv = np.zeros(self.NT)
104 self.units = ''
105#
106class EOSmeltcurve:
107 """Class for melt curve from ANEOS."""
108 def __init__(self):
109 self.NT = 0
110 self.NV = 0
111 self.T = np.zeros(self.NT)
112 self.Tl = np.zeros(self.NT)
113 self.Ts = np.zeros(self.NT)
114 self.rl = np.zeros(self.NT)
115 self.rs = np.zeros(self.NT)
116 self.Pl = np.zeros(self.NT)
117 self.Ps = np.zeros(self.NT)
118 self.Ul = np.zeros(self.NT)
119 self.Us = np.zeros(self.NT)
120 self.Sl = np.zeros(self.NT)
121 self.Ss = np.zeros(self.NT)
122 self.units = ''
123#
124class EOS1barcurve:
125 """Class for 1bar curve from the EOS."""
126 def __init__(self):
127 self.NT = 0
128 self.S = np.zeros(self.NT)
129 self.T = np.zeros(self.NT)
130 self.rho = np.zeros(self.NT)
131 self.Tvap = 0.
132 self.Tmelt = 0.
133 self.Sim = 0.
134 self.Scm = 0.
135 self.Siv = 0.
136 self.Scv = 0.
137 self.rhoiv = 0.
138 self.rhocv = 0.
139 self.rhocm = 0.
140 self.rhoim = 0.
141 self.units = ''
142 self.label = ''
143#
144class EOSpoint:
145 """Class for a state on the EOS."""
146 def __init__(self):
147 self.P = 0
148 self.P_err = 0
149 self.S = 0
150 self.S_err = 0
151 self.T = 0
152 self.T_err = 0
153 self.rho = 0
154 self.rho_err = 0
155 self.U = 0
156 self.U_err = 0
157 self.units = ''
158 self.label = ''
159 def __str__(self):
160 """ Print the values in the EOS point """
161 return '\nClass EOSpoint: \n' + \
162 f' eos_table module version {__version__} \n' + \
163 f' P, rho, T: {self.P} {self.rho} {self.T} \n' + \
164 f' U, S: {self.U} {self.S} \n'
166#
167class EOScriticalpoint:
168 """Class for critical point state from the EOS."""
169 def __init__(self):
170 self.P = 0
171 self.S = 0
172 self.T = 0
173 self.rho = 0
174 self.U = 0
175 self.units = ''
176 self.label = ''
177#
178class EOStriplepoint:
179 """Class for triple point state from the EOS."""
180 def __init__(self):
181 self.P = 0
182 self.T = 0
183 self.Sim = 0.
184 self.Scm = 0.
185 self.Siv = 0.
186 self.Scv = 0.
187 self.rhol = 0.
188 self.units = ''
189 self.label = ''
190#
191class EOSaneoshugoniot:
192 """Class for Hugoniot calculated in ANEOS."""
193 def __init__(self):
194 self.ND = 0
195 self.NV = 0
196 #self.all = np.zeros((self.ND,self.NV))
197 self.rho = 0
198 self.T = 0
199 self.P = 0
200 self.U = 0
201 self.S = 0
202 self.us = 0
203 self.up = 0
204 self.units = ''
205#
206class extEOStable:
207 """Class for accessing EXTENDED SESAME-STYLE EOS tables output from ANEOS"""
208 # ANEOS KPA FLAG
209 # TABLE ANEOS
210 # KPAQQ=STATE INDICATOR =1, 1p =1, 1p (eos without melt)
211 # =2, 2p lv =2, 2p liquid/solid plus vapor
212 # =4, 1p solid (eos with melt)
213 # =5, 2p melt (eos with melt)
214 # =6, 1p liquid (eos with melt)
215 # =-1 bad value of temperature
216 # =-2 bad value of density
217 # =-3 bad value of material number
218 #
219 def __init__(self):
220 self.ND = 0 # integer; number of density points in grid
221 self.NT = 0 # integer; number of temperature points in grid
222 self.rho = np.zeros(self.ND) # g/cm3, density values
223 self.T = np.zeros(self.NT) # K, temperature values
224 self.P = np.zeros(self.ND*self.NT) # GPA, pressure(T,rho)
225 self.U = np.zeros(self.ND*self.NT) # MJ/kg, sp. internal energy(T,rho)
226 self.A = np.zeros(self.ND*self.NT) # MJ/kg, Helmholtz free energy(T,rho)
227 self.S = np.zeros(self.ND*self.NT) # MJ/K/kg, sp. entropy(T,rho)
228 self.cs = np.zeros(self.ND*self.NT) # cm/s, sound speed(T,rho)
229 self.cv = np.zeros(self.ND*self.NT) # MJ/K/kg, sp. heat capacity(T,rho)
230 self.KPA = np.zeros(self.ND*self.NT) # integer, ANEOS KPA flag(T,rho)
231 self.MDQ = np.zeros(self.ND*self.NT) # integer, Model Development Quality Flag(T,rho)
232 self.units = ''
233 self.hug = EOShugoniot()
234 self.hugo = EOShugoniot()
235 self.vc = EOSvaporcurve()
236 self.mc = EOSmeltcurve()
237 self.cp = EOScriticalpoint()
238 self.tp = EOStriplepoint()
239 self.onebar = EOS1barcurve()
240 self.anhug = EOSaneoshugoniot()
241 # these are variables needed for the sesame header
242 self.MATID = 0.
243 self.DATE = 0.
244 self.VERSION = 0.
245 self.FMN = 0.
246 self.FMW = 0.
247 self.R0REF = 0.
248 self.K0REF = 0.
249 self.T0REF = 0.
250 self.P0REF = 0.
251 self.CS0REF = 0.
252 # variables needed for the ANEOS gamma function
253 self.gamma0 = 0.
254 self.theta0 = 0.
255 self.C24 = 0.
256 self.C60 = 0.
257 self.C61 = 0.
258 self.beta = 0.
259 # model name/version string
260 self.MODELNAME = ''
262 def loadstdsesame(self, fname, unitstxt=None):
263 """Function for loading STD SESAME-STYLE EOS table output from ANEOS"""
264 data = ([])
265 if unitstxt is None:
266 self.units = 'Units: rho g/cm3, T K, P GPa, U MJ/kg, A MJ/kg, S MJ/K/kg, cs cm/s, cv MJ/K/kg, KPA flag. 2D arrays are (NT,ND).'
267 else:
268 self.units = unitstxt
269 sesamefile = open(fname,"r")
270 sesamedata=sesamefile.readlines()
271 sesamefile.close()
272 nskip = 6 # skip standard header to get to the content of the 301 table
273 # num.density, num. temps
274 tmp = sesamedata[nskip][0:16]
275 dlen = float(tmp)
276 tmp = sesamedata[nskip][16:32]
277 tlen = float(tmp)
278 if (np.mod((dlen*tlen*3.0+dlen+tlen+2.0),5.0) == 0):
279 neos = int((dlen*tlen*3.0+dlen+tlen+2.0)/5.0)
280 else:
281 neos = int((dlen*tlen*3.0+dlen+tlen+2.0)/5.0) +1
282 #print(dlen,tlen,neos,len(sesamedata))
283 data = np.zeros((neos,5),dtype=float)
284 for j in range(nskip,neos+nskip):
285 tmp3 = sesamedata[j]
286 tmp4 = list(tmp3.split())
287 if len(tmp4) < 5:
288 lentmp4 = len(tmp4)
289 data[j-nskip,0:lentmp4] = np.asarray(tmp4[0:lentmp4])
290 else:
291 data[j-nskip,:] = np.asarray(tmp4)
292 #print(j,eosarr[j,:])
293 #print(data.shape)
294 data=np.resize(data,(neos*5))
295 #print(data.shape)
296 self.ND = data[0].astype(int) # now fill the extEOStable class
297 self.NT = data[1].astype(int)
298 self.rho = data[2:2+self.ND]
299 self.T = data[2+self.ND : 2+self.ND+self.NT]
300 self.P = data[2+self.ND+self.NT : 2+self.ND+self.NT+self.ND*self.NT
301 ].reshape(self.NT,self.ND)
302 self.U = data[2+self.ND+self.NT+self.ND*self.NT
303 : 2+self.ND+self.NT+2*self.ND*self.NT
304 ].reshape(self.NT,self.ND)
305 self.A = data[2+self.ND+self.NT+2*self.ND*self.NT
306 : 2+self.ND+self.NT+3*self.ND*self.NT
307 ].reshape(self.NT,self.ND)
308 #self.S = data[2+self.ND+self.NT+3*self.ND*self.NT
309 # : 2+self.ND+self.NT+4*self.ND*self.NT
310 # ].reshape(self.NT,self.ND)
311 #self.cs = data[2+self.ND+self.NT+4*self.ND*self.NT
312 # : 2+self.ND+self.NT+5*self.ND*self.NT
313 # ].reshape(self.NT,self.ND)
314 #self.cv = data[2+self.ND+self.NT+5*self.ND*self.NT
315 # : 2+self.ND+self.NT+6*self.ND*self.NT
316 # ].reshape(self.NT,self.ND)
317 #self.KPA = data[2+self.ND+self.NT+6*self.ND*self.NT
318 # : 2+self.ND+self.NT+7*self.ND*self.NT
319 # ].reshape(self.NT,self.ND)
320#
321 def loadextsesame(self, fname, unitstxt=None):
322 """Function for loading EXTENDED SESAME-STYLE EOS table output from ANEOS"""
323 data = ([])
324 if unitstxt is None:
325 self.units = 'Units: rho g/cm3, T K, P GPa, U MJ/kg, A MJ/kg, S MJ/K/kg, cs cm/s, cv MJ/K/kg, KPA flag. 2D arrays are (NT,ND).'
326 else:
327 self.units = unitstxt
328 sesamefile = open(fname,"r")
329 sesamedata=sesamefile.readlines()
330 sesamefile.close()
331 nskip = 6 # skip standard header to get to the content of the 301 table
332 # num.density, num. temps
333 tmp = sesamedata[nskip][0:16]
334 dlen = float(tmp)
335 tmp = sesamedata[nskip][16:32]
336 tlen = float(tmp)
337 if (np.mod((dlen*tlen*4.0+dlen+tlen+2.0),5.0) == 0):
338 neos = int((dlen*tlen*4.0+dlen+tlen+2.0)/5.0)
339 else:
340 neos = int((dlen*tlen*4.0+dlen+tlen+2.0)/5.0) +1
341 #print(dlen,tlen,neos,len(sesamedata))
342 data = np.zeros((neos,5),dtype=float)
343 for j in range(nskip,neos+nskip):
344 tmp3 = sesamedata[j]
345 tmp4 = list(tmp3.split())
346 if len(tmp4) < 5:
347 lentmp4 = len(tmp4)
348 data[j-nskip,0:lentmp4] = np.asarray(tmp4[0:lentmp4])
349 else:
350 data[j-nskip,:] = np.asarray(tmp4)
351 #print(j,eosarr[j,:])
352 #print(data.shape)
353 data=np.resize(data,(neos*5))
354 #print(data.shape)
355 self.ND = data[0].astype(int) # now fill the extEOStable class
356 self.NT = data[1].astype(int)
357 self.rho = data[2:2+self.ND]
358 self.T = data[2+self.ND : 2+self.ND+self.NT]
359 #self.P = data[2+self.ND+self.NT : 2+self.ND+self.NT+self.ND*self.NT
360 # ].reshape(self.NT,self.ND)
361 #self.U = data[2+self.ND+self.NT+self.ND*self.NT
362 # : 2+self.ND+self.NT+2*self.ND*self.NT
363 # ].reshape(self.NT,self.ND)
364 #self.A = data[2+self.ND+self.NT+2*self.ND*self.NT
365 # : 2+self.ND+self.NT+3*self.ND*self.NT
366 # ].reshape(self.NT,self.ND)
367 self.S = data[2+self.ND+self.NT+0*self.ND*self.NT
368 : 2+self.ND+self.NT+1*self.ND*self.NT
369 ].reshape(self.NT,self.ND)
370 self.cs = data[2+self.ND+self.NT+1*self.ND*self.NT
371 : 2+self.ND+self.NT+2*self.ND*self.NT
372 ].reshape(self.NT,self.ND)
373 self.cv = data[2+self.ND+self.NT+2*self.ND*self.NT
374 : 2+self.ND+self.NT+3*self.ND*self.NT
375 ].reshape(self.NT,self.ND)
376 self.KPA = data[2+self.ND+self.NT+3*self.ND*self.NT
377 : 2+self.ND+self.NT+4*self.ND*self.NT
378 ].reshape(self.NT,self.ND)
379#
380 def view(self, q='P', Tlow=None, Thigh=None, rholow=None, rhohigh=None):
381 """Function for printing values from EXTENDED SESAME-STYLE EOS table."""
382 if Tlow is None:
383 Tlow = self.T.min()
384 if Thigh is None:
385 Thigh = self.T.max()
386 if rholow is None:
387 rholow = self.rho.min()
388 if rhohigh is None:
389 rhohigh = self.rho.max()
390 print(self.units)
391 if q == 'P':
392 print('T:', self.T[np.logical_and(self.T >= Tlow,self.T <= Thigh)])
393 print('rho:', self.rho[np.logical_and(self.rho >= rholow,
394 self.rho <= rhohigh)
395 ])
396 print('P:', (self.P[np.logical_and(self.T >= Tlow,
397 self.T<=Thigh)
398 ])[:, np.logical_and(self.rho >= rholow,
399 self.rho <= rhohigh)
400 ])
401 if q == 'U':
402 print('T:', self.T[np.logical_and(self.T >= Tlow,self.T <= Thigh)])
403 print('rho:', self.rho[np.logical_and(self.rho >= rholow,
404 self.rho <= rhohigh)
405 ])
406 print('U:', (self.U[np.logical_and(self.T >= Tlow,
407 self.T <= Thigh)
408 ])[:, np.logical_and(self.rho >= rholow,
409 self.rho <= rhohigh)
410 ])
411 if q == 'A':
412 print('T:', self.T[np.logical_and(self.T >= Tlow,self.T <= Thigh)])
413 print('rho:', self.rho[np.logical_and(self.rho >= rholow,
414 self.rho <= rhohigh)
415 ])
416 print('A:', (self.A[np.logical_and(self.T >= Tlow,
417 self.T <= Thigh)
418 ])[:, np.logical_and(self.rho >= rholow,
419 self.rho <= rhohigh)
420 ])
421 if q == 'S':
422 print('T:', self.T[np.logical_and(self.T >= Tlow,self.T <= Thigh)])
423 print('rho:', self.rho[np.logical_and(self.rho
424 >= rholow,self.rho<=rhohigh)
425 ])
426 print('S:', (self.S[np.logical_and(self.T >= Tlow,self.T <= Thigh)
427 ])[:, np.logical_and(self.rho >= rholow,
428 self.rho <= rhohigh)
429 ])
430 if q == 'cs':
431 print('T:', self.T[np.logical_and(self.T >= Tlow,self.T <= Thigh)])
432 print('rho:', self.rho[np.logical_and(self.rho >= rholow,
433 self.rho<=rhohigh)])
434 print('cs:', (self.cs[np.logical_and(self.T >= Tlow,
435 self.T <= Thigh)
436 ])[:, np.logical_and(self.rho >= rholow,
437 self.rho <= rhohigh)
438 ])
439 if q == 'cv':
440 print('T:', self.T[np.logical_and(self.T >= Tlow,self.T <= Thigh)])
441 print('rho:', self.rho[np.logical_and(self.rho >= rholow,
442 self.rho<=rhohigh)])
443 print('cv:', (self.cv[np.logical_and(self.T >= Tlow,
444 self.T <= Thigh)
445 ])[:, np.logical_and(self.rho >= rholow,
446 self.rho <= rhohigh)
447 ])
448 if q == 'KPA':
449 print('T:', self.T[np.logical_and(self.T >= Tlow,self.T <= Thigh)])
450 print('rho:', self.rho[np.logical_and(self.rho >= rholow,
451 self.rho<=rhohigh)])
452 print('KPA:', (self.KPA[np.logical_and(self.T >= Tlow,
453 self.T <= Thigh)
454 ])[:, np.logical_and(self.rho >= rholow,
455 self.rho <= rhohigh)
456 ])
458 def calchugoniot(self, r0=None, t0=None, pmax=None, writefilename=None):
459 """Function for calculating a Hugoniot from EXTENDED SESAME-STYLE EOS table."""
460 if r0 is None:
461 return 'Must provide r0 and t0.'
462 if t0 is None:
463 return 'Must provide r0 and t0.'
464 if pmax is None:
465 pmax=1.E4 # GPa
466 self.hug.rho = []
467 self.hug.P = []
468 self.hug.T = []
469 self.hug.U = []
470 self.hug.S = []
471 self.hug.up = []
472 self.hug.us = []
473 self.hug.cs = []
475 it0 = int(np.round(np.interp(t0,self.T,np.arange(self.NT)))) # uses nearest value if t0 not in array
476 ir0 = int(np.round(np.interp(r0,self.rho,np.arange(self.ND)))) # uses nearest value if r0 not in the array
477 p0 = self.P[it0,ir0] # GPa
478 #print(self.P[it0,ir0])
479 e0 = self.U[it0,ir0]#np.interp(p0,self.P[it0,:],self.U[it0,:])
480 s0 = self.S[it0,ir0]#np.interp(p0,self.P[it0,:],self.S[it0,:])
481 up0 = 0. # no initial particle velocity
482 us0 = self.cs[it0,ir0]/1.e5 # cm/s->km/s use sound velocity for initial
483 cs0 = self.cs[it0,ir0]/1.e5 # cm/s->km/s use sound velocity for initial
484 #print(ir0,it0,r0,t0,p0,e0,up0,us0)
485 self.hug.rho = np.append(self.hug.rho, self.rho[ir0])
486 self.hug.P = np.append(self.hug.P, p0)
487 self.hug.T = np.append(self.hug.T, self.T[it0])
488 self.hug.U = np.append(self.hug.U, e0)
489 self.hug.S = np.append(self.hug.S, s0)
490 self.hug.up = np.append(self.hug.up, up0)
491 self.hug.us = np.append(self.hug.us, us0)
492 self.hug.cs = np.append(self.hug.cs, cs0)
494 #for iir in range(ir0+1,self.ND):
495 iir=ir0+1
496 pnew=p0
497 while pnew<pmax:
498 ediff =0.5*(self.P[it0::,iir]+p0)*(1./r0-1./self.rho[iir])+e0 -(self.U[it0::,iir]) # MJ/kg
499 # np.interp wants x values increasing
500 pnew = np.interp(0.,np.flip(ediff),np.flip(self.P[it0::,iir]))
501 tnew = np.interp(0.,np.flip(ediff),np.flip(self.T[it0::]))
502 enew = np.interp(0.,np.flip(ediff),np.flip(self.U[it0::,iir]))
503 snew = np.interp(0.,np.flip(ediff),np.flip(self.S[it0::,iir]))
504 upnew = np.sqrt((pnew-p0)*(1./r0-1./self.rho[iir]))
505 usnew = (1./r0)*np.sqrt((pnew-p0)/(1./r0-1./self.rho[iir]))
506 csnew = np.interp(0.,np.flip(ediff),np.flip(self.cs[it0::,iir]))/1.E5 # km/s
507 #print(self.rho[iir],tnew,pnew,enew,upnew,usnew)
508 self.hug.rho = np.append(self.hug.rho, self.rho[iir])
509 self.hug.P = np.append(self.hug.P, pnew)
510 self.hug.T = np.append(self.hug.T, tnew)
511 self.hug.U = np.append(self.hug.U, enew)
512 self.hug.S = np.append(self.hug.S, snew)
513 self.hug.up = np.append(self.hug.up, upnew)
514 self.hug.us = np.append(self.hug.us, usnew)
515 self.hug.cs = np.append(self.hug.cs, csnew) # km/s
516 iir += 1
517 self.hug.NH=len(self.hug.P)
518 self.hug.units='units: T K, rho g/cm3, P GPa, U MJ/kg, S MJ/K/kg, Up km/s, Us km/s, cs km/s'
520 if writefilename:
521 print('Writing Hugoniot to file: ',writefilename)
522 hugoniotfile = open(writefilename,"w")
523 hugoniotfile.writelines(' Hugoniot \n')
524 hugoniotfile.writelines(' Temperature, Density, Pressure, Int. Energy, Sp. Entropy, Part. Vel., Shock Vel. \n')
525 hugoniotfile.writelines(' K, g/cm3, GPa, MJ/kg, MJ/K/kg, km/s, km/s\n')
526 for iih in range(0,self.hug.NH):
527 hugoniotfile.write("%14.6e, %14.6e, %14.6e, %14.6e, %14.6e, %14.6e, %14.6e\n" % (
528 self.hug.T[iih],self.hug.rho[iih],self.hug.P[iih],self.hug.U[iih],self.hug.S[iih],self.hug.up[iih],self.hug.us[iih]))
529 hugoniotfile.close()
531 def calcOffEOSHugoniot(self, r0=None, t0=None, p0=None, e0=None, r1=None, pmax=None, writefilename=None):
532 """Function for calculating a Hugoniot from EXTENDED SESAME-STYLE EOS table."""
533 if r0 is None:
534 return 'Must provide r0, t0, p0, e0.'
535 if t0 is None:
536 return 'Must provide r0, t0, p0, e0.'
537 if p0 is None:
538 return 'Must provide r0, t0, p0, e0.'
539 if e0 is None:
540 return 'Must provide r0, t0, p0, e0.'
541 if pmax is None:
542 pmax=1.E4 # GPa
543 self.hugo.rho = []
544 self.hugo.P = []
545 self.hugo.T = []
546 self.hugo.U = []
547 self.hugo.S = []
548 self.hugo.up = []
549 self.hugo.us = []
550 self.hugo.cs = []
551 print('r1=',r1)
552 it0 = int(np.round(np.interp(t0,self.T,np.arange(self.NT)))) # uses nearest value if t0 not in array
553 ir0 = int(np.round(np.interp(r1,self.rho,np.arange(self.ND)))) # start with full density
554 s0 = 0. # don't need it to get going
555 up0 = 0. # no initial particle velocity
556 us0 = self.cs[it0,ir0]/1.e5 # cm/s->km/s use sound velocity for initial
557 cs0 = self.cs[it0,ir0]/1.e5 # cm/s->km/s use sound velocity for initial
558 print(ir0,it0,r0,t0,p0,e0,up0,us0)
559 self.hugo.rho = np.append(self.hugo.rho, r0)
560 self.hugo.P = np.append(self.hugo.P, p0)
561 self.hugo.T = np.append(self.hugo.T, t0)
562 self.hugo.U = np.append(self.hugo.U, e0)
563 self.hugo.S = np.append(self.hugo.S, s0)
564 self.hugo.up = np.append(self.hugo.up, up0)
565 self.hugo.us = np.append(self.hugo.us, us0)
566 self.hugo.cs = np.append(self.hugo.cs, cs0)
568 #for iir in range(ir0+1,self.ND):
569 iir=ir0+1
570 pnew=p0
571 count=0
572 while pnew<pmax:
573 ediff =0.5*(self.P[it0::,iir]+p0)*(1./r0-1./self.rho[iir])+e0 -(self.U[it0::,iir]) # MJ/kg
574 # np.interp wants x values increasing
575 pnew = np.interp(0.,np.flip(ediff),np.flip(self.P[it0::,iir]))
576 tnew = np.interp(0.,np.flip(ediff),np.flip(self.T[it0::]))
577 enew = np.interp(0.,np.flip(ediff),np.flip(self.U[it0::,iir]))
578 snew = np.interp(0.,np.flip(ediff),np.flip(self.S[it0::,iir]))
579 upnew = np.sqrt((pnew-p0)*(1./r0-1./self.rho[iir]))
580 usnew = (1./r0)*np.sqrt((pnew-p0)/(1./r0-1./self.rho[iir]))
581 csnew = np.interp(0.,np.flip(ediff),np.flip(self.cs[it0::,iir]))/1.E5 # km/s
582 #print(self.rho[iir],tnew,pnew,enew,upnew,usnew)
583 self.hugo.rho = np.append(self.hugo.rho, self.rho[iir])
584 self.hugo.P = np.append(self.hugo.P, pnew)
585 self.hugo.T = np.append(self.hugo.T, tnew)
586 self.hugo.U = np.append(self.hugo.U, enew)
587 self.hugo.S = np.append(self.hugo.S, snew)
588 self.hugo.up = np.append(self.hugo.up, upnew)
589 self.hugo.us = np.append(self.hugo.us, usnew)
590 self.hugo.cs = np.append(self.hugo.cs, csnew) # km/s
591 count=count+1
592 iir += 1
593 self.hugo.NH=len(self.hug.P)
594 self.hugo.units='units: T K, rho g/cm3, P GPa, U MJ/kg, S MJ/K/kg, Up km/s, Us km/s, cs km/s'
596 if writefilename:
597 print('Writing Hugoniot to file: ',writefilename)
598 hugoniotfile = open(writefilename,"w")
599 hugoniotfile.writelines(' Hugoniot \n')
600 hugoniotfile.writelines(' Temperature, Density, Pressure, Int. Energy, Sp. Entropy, Part. Vel., Shock Vel. \n')
601 hugoniotfile.writelines(' K, g/cm3, GPa, MJ/kg, MJ/K/kg, km/s, km/s\n')
602 for iih in range(0,count):
603 hugoniotfile.write("%14.6e, %14.6e, %14.6e, %14.6e, %14.6e, %14.6e, %14.6e\n" % (
604 self.hugo.T[iih],self.hugo.rho[iih],self.hugo.P[iih],self.hugo.U[iih],self.hugo.S[iih],self.hugo.up[iih],self.hugo.us[iih]))
605 hugoniotfile.close()
606 ###########################################################################################
607 # Functions added to be helpful for integration with the KO hydrocode
608 #
609 #
610 def querypt(self,rho,t):
611 """Return EOS state for input (rho,t)"""
612 print('in query pt')
613 pt = EOSpoint()
614 # linearly interpolate the table for return the rho,t point values
615 rindex = np.where(self.rho >= rho)[0][0]
616 tindex = np.where(self.T >= t)[0][0]
617 P11 = self.P[tindex-1,rindex-1]
618 P21 = self.P[tindex,rindex-1]
619 P12 = self.P[tindex-1,rindex]
620 P22 = self.P[tindex,rindex]
621 U11 = self.U[tindex-1,rindex-1]
622 U21 = self.U[tindex,rindex-1]
623 U12 = self.U[tindex-1,rindex]
624 U22 = self.U[tindex,rindex]
625 r1 = np.log10(self.rho[rindex-1]) # try linearly interpreting on the log of the index
626 r2 = np.log10(self.rho[rindex])
627 t1 = np.log10(self.T[tindex-1])
628 t2 = np.log10(self.T[tindex])
629 logr = np.log10(rho)
630 logt = np.log10(t)
631 u1 = np.log10(U11) * (r2-logr)/(r2-r1) + np.log10(U12) * (logr-r1)/(r2-r1)
632 u2 = np.log10(U21) * (r2-logr)/(r2-r1) + np.log10(U22) * (logr-r1)/(r2-r1)
633 p1 = np.log10(P11) * (r2-logr)/(r2-r1) + np.log10(P12) * (logr-r1)/(r2-r1)
634 p2 = np.log10(P21) * (r2-logr)/(r2-r1) + np.log10(P22) * (logr-r1)/(r2-r1)
635 logp = p1 * (t2-logt)/(t2-t1) + p2 * (logt-t1)/(t2-t1)
636 pnew = np.power(10.,logp)
637 logu = u1 * (t2-logt)/(t2-t1) + u2 * (logt-t1)/(t2-t1)
638 unew = np.power(10.,logu)
639 pt.T = t
640 pt.rho = rho
641 pt.P = pnew
642 pt.U = unew
643 return pt
644 def queryptlin(self,rho,t):
645 """Return EOS state for input (rho,t); linear EOS"""
646 print('in query pt')
647 pt = EOSpoint()
648 # linearly interpolate the table for return the rho,t point values
649 rindex = np.where(self.rho >= rho)[0][0]
650 tindex = np.where(self.T >= t)[0][0]
651 P11 = self.P[tindex-1,rindex-1]
652 P21 = self.P[tindex,rindex-1]
653 P12 = self.P[tindex-1,rindex]
654 P22 = self.P[tindex,rindex]
655 U11 = self.U[tindex-1,rindex-1]
656 U21 = self.U[tindex,rindex-1]
657 U12 = self.U[tindex-1,rindex]
658 U22 = self.U[tindex,rindex]
659 r1 = self.rho[rindex-1]
660 r2 = self.rho[rindex]
661 t1 = self.T[tindex-1]
662 t2 = self.T[tindex]
663 u1 = U11 * (r2-rho)/(r2-r1) + U12 * (rho-r1)/(r2-r1)
664 u2 = U21 * (r2-rho)/(r2-r1) + U22 * (rho-r1)/(r2-r1)
665 p1 = P11 * (r2-rho)/(r2-r1) + P12 * (rho-r1)/(r2-r1)
666 p2 = P21 * (r2-rho)/(r2-r1) + P22 * (rho-r1)/(r2-r1)
667 pnew = p1 * (t2-t)/(t2-t1) + p2 * (t-t1)/(t2-t1)
668 unew = u1 * (t2-t)/(t2-t1) + u2 * (t-t1)/(t2-t1)
669 pt.T = t
670 pt.rho = rho
671 pt.P = pnew
672 pt.U = unew
673 return pt
674 #
675 ###########################################################################################
676 #
677 def writestdsesame(self, writestdsesfname=None):
678 """Write standard Header-201-301 SESAME EOS TABULAR EOS FILE"""
679 # write a standard SESAME ascii file
680 # WRITE STANDARD Header-201-301 SESAME FILE
681 # WRITE SESAME 301 TABLE CONTAINS P, E, HFE
682 #sesfile = open("NEW-SESAME-STD-NOTENSION.EOSTXT","w")
683 if writestdsesfname is None:
684 print('Please provide a file name.')
685 exit(0)
686 sesfile = open(writestdsesfname,"w")
687 # WRITE SESAME HEADER INFORMATION: EOS matid number, number of words in section
688 # could input matid, date, version with the grid
689 # these parameters are set in the cell above that sets up the grid for ANEOS
690 # THEY SHOULD MATCH.......
691 # These variables are needed for the standard table output
692 NWDS=9
693 SESNTABLES=2.0
694 TABLE1 = 201.0
695 TABLE2 = 301.0
696 # 5 entries in 201 table
697 SESNWDS1=5.0
698 # Number of entries in STANDARD 301 table: 3 variables at each T,rho point
699 SESNWDS2=2.+self.ND+self.NT+self.ND*self.NT*3.
700 # HEADER SECTION
701 #sesfile.write("%14.6e, %14.6e, %14.6e, %14.6e, %14.6e, %14.6e, %14.6e\n" % (antarr[iit],rnew,pnew,enew,snew,upnew,usnew))
702 sesfile.write(" INDEX MATID ={:7d} NWDS = {:8d}\n".format(int(self.MATID), int(NWDS)))
703 sesfile.write("{:16.8e}{:16.8e}{:16.8e}{:16.8e}{:16.8e}\n".format(self.MATID, self.DATE, self.DATE, self.VERSION, SESNTABLES))
704 sesfile.write("{:16.8e}{:16.8e}{:16.8e}{:16.8e}\n".format(TABLE1, TABLE2, SESNWDS1, SESNWDS2))
705 # 201 SECTION
706 sesfile.write(" RECORD TYPE ={:5d} NWDS = {:8d}\n".format(int(TABLE1),int(SESNWDS1)))
707 sesfile.write("{:16.8e}{:16.8e}{:16.8e}{:16.8e}{:16.8e}\n".format(self.FMN, self.FMW, self.R0REF, self.K0REF, self.T0REF))
708 sesfile.write(" RECORD TYPE ={:5d} NWDS = {:8d}\n".format(int(TABLE2),int(SESNWDS2)))
709 sesfile.write("{:16.8e}{:16.8e}".format(self.ND, self.NT))
710 STYLE=2
711 # density array g/cm3
712 for k in range(0, int(self.ND)):
713 sesfile.write("{:16.8e}".format(self.rho[k]))
714 STYLE=STYLE+1
715 if (np.mod(STYLE,5) == 0):
716 sesfile.write("\n")
717 # temperature array K
718 for j in range(0, int(self.NT)):
719 sesfile.write("{:16.8e}".format(self.T[j]))
720 STYLE=STYLE+1
721 if (np.mod(STYLE,5) == 0):
722 sesfile.write("\n")
723 # pressure array GPa P[tempindex,dindex]
724 for j in range(0,int(self.NT)):
725 for k in range(0,int(self.ND)):
726 sesfile.write("{:16.8e}".format(self.P[j,k]))
727 STYLE=STYLE+1
728 if (np.mod(STYLE,5) == 0):
729 sesfile.write("\n")
730 # specific internal energy array MJ/kg U[tempindex,dindex]
731 for j in range(0,int(self.NT)):
732 for k in range(0,int(self.ND)):
733 sesfile.write("{:16.8e}".format(self.U[j,k]))
734 STYLE=STYLE+1
735 if (np.mod(STYLE,5) == 0):
736 sesfile.write("\n")
737 # Helmholtz free energy array in MJ/kg A[tempindex,dindex]
738 for j in range(0,int(self.NT)):
739 for k in range(0,int(self.ND)):
740 sesfile.write("{:16.8e}".format(self.A[j,k]))
741 STYLE=STYLE+1
742 if (np.mod(STYLE,5) == 0):
743 sesfile.write("\n")
744 # close the SESAME TABLE FILE
745 sesfile.close()
746 print('Done writing the STD SESAME 301 table to local directory: ',writestdsesfname)
748 def writeextsesame(self, writeextsesfname=None):
749 """Write standard Header-201-301 SESAME EOS TABULAR EOS FILE"""
750 # WRITE STANDARD Header-201-301 SESAME FILE
751 if writeextsesfname is None:
752 print('Please provide a file name.')
753 exit(0)
754 sesfile = open(writeextsesfname,"w")
755 # WRITE SESAME HEADER INFORMATION: EOS matid number, number of words in section
756 # could input matid, date, version with the grid
757 # these parameters are set in the cell above that sets up the grid for ANEOS
758 # THEY SHOULD MATCH.......
759 # These variables are needed for the standard table output
760 NWDS=9
761 SESNTABLES=2.0
762 TABLE1 = 201.0
763 TABLE2 = 301.0
764 # 5 entries in 201 table
765 SESNWDS1=5.0
766 # Number of entries in STANDARD 301 table: 3 variables at each T,rho point
767 SESNWDS2=2.+self.ND+self.NT+self.ND*self.NT*3.
768 # HEADER SECTION
769 #sesfile.write("%14.6e, %14.6e, %14.6e, %14.6e, %14.6e, %14.6e, %14.6e\n" % (antarr[iit],rnew,pnew,enew,snew,upnew,usnew))
770 sesfile.write(" INDEX MATID ={:7d} NWDS = {:8d}\n".format(int(self.MATID), int(NWDS)))
771 sesfile.write("{:16.8e}{:16.8e}{:16.8e}{:16.8e}{:16.8e}\n".format(self.MATID, self.DATE, self.DATE, self.VERSION, SESNTABLES))
772 sesfile.write("{:16.8e}{:16.8e}{:16.8e}{:16.8e}\n".format(TABLE1, TABLE2, SESNWDS1, SESNWDS2))
773 # 201 SECTION
774 sesfile.write(" RECORD TYPE ={:5d} NWDS = {:8d}\n".format(int(TABLE1),int(SESNWDS1)))
775 sesfile.write("{:16.8e}{:16.8e}{:16.8e}{:16.8e}{:16.8e}\n".format(self.FMN, self.FMW, self.R0REF, self.K0REF, self.T0REF))
776 sesfile.write(" RECORD TYPE ={:5d} NWDS = {:8d}\n".format(int(TABLE2),int(SESNWDS2)))
777 sesfile.write("{:16.8e}{:16.8e}".format(self.ND, self.NT))
778 STYLE=2
779#NEW-SESAME-EXT.TXT: SESAME-style table with extra variables from ANEOS. Contains the standard 201 table and non-standard 301-extra-variables EOS table. The 301 table has: density grid values, temperature grid values, sp. entropy(T,rho), sound speed(T,rho), sp. heat capacity(T,rho), KPA flag(T,rho). 2-D arrays list all densities, looping over each temperature. 301 table units: g/cm$^3$, K, MJ/K/kg, cm/s, MJ/K/kg, integer flag, integer flag. The KPA flag is an ANEOS output with phase information. <br>
781 # density array g/cm3
782 for k in range(0, int(self.ND)):
783 sesfile.write("{:16.8e}".format(self.rho[k]))
784 STYLE=STYLE+1
785 if (np.mod(STYLE,5) == 0):
786 sesfile.write("\n")
787 # temperature array K
788 for j in range(0, int(self.NT)):
789 sesfile.write("{:16.8e}".format(self.T[j]))
790 STYLE=STYLE+1
791 if (np.mod(STYLE,5) == 0):
792 sesfile.write("\n")
793 # specific entropy array MJ/K/kg S[tempindex,dindex]
794 for j in range(0,int(self.NT)):
795 for k in range(0,int(self.ND)):
796 sesfile.write("{:16.8e}".format(self.S[j,k]))
797 STYLE=STYLE+1
798 if (np.mod(STYLE,5) == 0):
799 sesfile.write("\n")
800 # sound speed array cm/s cs[tempindex,dindex]
801 for j in range(0,int(self.NT)):
802 for k in range(0,int(self.ND)):
803 sesfile.write("{:16.8e}".format(self.cs[j,k]))
804 STYLE=STYLE+1
805 if (np.mod(STYLE,5) == 0):
806 sesfile.write("\n")
807 # sp. heat capacity array in MJ/K/kg cv[tempindex,dindex]
808 for j in range(0,int(self.NT)):
809 for k in range(0,int(self.ND)):
810 sesfile.write("{:16.8e}".format(self.cv[j,k]))
811 STYLE=STYLE+1
812 if (np.mod(STYLE,5) == 0):
813 sesfile.write("\n")
814 # phase flag [integer] KPA[tempindex,dindex]
815 for j in range(0,int(self.NT)):
816 for k in range(0,int(self.ND)):
817 sesfile.write("{:16.8e}".format(self.KPA[j,k]))
818 STYLE=STYLE+1
819 if (np.mod(STYLE,5) == 0):
820 sesfile.write("\n")
821 # close the SESAME TABLE FILE
822 sesfile.close()
823 print('Done writing the EXT SESAME 301 table to local directory: ',writeextsesfname)
825 def writegadgetinitsesame(self, writegadgetinitsesfname=None):
826 """Write standard Header-201-301 SESAME EOS TABULAR EOS FILE"""
827 # write a standard SESAME ascii file
828 # WRITE GADGET INIT Header-201-301 SESAME FILE
829 # WRITE SESAME 301 TABLE CONTAINS P, E, S
830 #sesfile = open("NEW-SESAME-GADGETINIT-NOTENSION.EOSTXT","w")
831 if writegadgetinitsesfname is None:
832 print('Please provide a file name.')
833 exit(0)
834 sesfile = open(writegadgetinitsesfname,"w")
835 # WRITE SESAME HEADER INFORMATION: EOS matid number, number of words in section
836 # could input matid, date, version with the grid
837 # these parameters are set in the cell above that sets up the grid for ANEOS
838 # THEY SHOULD MATCH.......
839 # These variables are needed for the standard table output
840 NWDS=9
841 SESNTABLES=2.0
842 TABLE1 = 201.0
843 TABLE2 = 301.0
844 # 5 entries in 201 table
845 SESNWDS1=5.0
846 # Number of entries in STANDARD 301 table: 3 variables at each T,rho point
847 SESNWDS2=2.+self.ND+self.NT+self.ND*self.NT*3.
848 # HEADER SECTION
849 #sesfile.write("%14.6e, %14.6e, %14.6e, %14.6e, %14.6e, %14.6e, %14.6e\n" % (antarr[iit],rnew,pnew,enew,snew,upnew,usnew))
850 sesfile.write(" INDEX MATID ={:7d} NWDS = {:8d}\n".format(int(self.MATID), int(NWDS)))
851 sesfile.write("{:16.8e}{:16.8e}{:16.8e}{:16.8e}{:16.8e}\n".format(self.MATID, self.DATE, self.DATE, self.VERSION, SESNTABLES))
852 sesfile.write("{:16.8e}{:16.8e}{:16.8e}{:16.8e}\n".format(TABLE1, TABLE2, SESNWDS1, SESNWDS2))
853 # 201 SECTION
854 sesfile.write(" RECORD TYPE ={:5d} NWDS = {:8d}\n".format(int(TABLE1),int(SESNWDS1)))
855 sesfile.write("{:16.8e}{:16.8e}{:16.8e}{:16.8e}{:16.8e}\n".format(self.FMN, self.FMW, self.R0REF, self.K0REF, self.T0REF))
856 sesfile.write(" RECORD TYPE ={:5d} NWDS = {:8d}\n".format(int(TABLE2),int(SESNWDS2)))
857 sesfile.write("{:16.8e}{:16.8e}".format(self.ND, self.NT))
858 STYLE=2
859 # density array g/cm3
860 for k in range(0, int(self.ND)):
861 sesfile.write("{:16.8e}".format(self.rho[k]))
862 STYLE=STYLE+1
863 if (np.mod(STYLE,5) == 0):
864 sesfile.write("\n")
865 # temperature array K
866 for j in range(0, int(self.NT)):
867 sesfile.write("{:16.8e}".format(self.T[j]))
868 STYLE=STYLE+1
869 if (np.mod(STYLE,5) == 0):
870 sesfile.write("\n")
871 # pressure array GPa P[tempindex,dindex]
872 for j in range(0,int(self.NT)):
873 for k in range(0,int(self.ND)):
874 sesfile.write("{:16.8e}".format(self.P[j,k]))
875 STYLE=STYLE+1
876 if (np.mod(STYLE,5) == 0):
877 sesfile.write("\n")
878 # specific internal energy array MJ/kg U[tempindex,dindex]
879 for j in range(0,int(self.NT)):
880 for k in range(0,int(self.ND)):
881 sesfile.write("{:16.8e}".format(self.U[j,k]))
882 STYLE=STYLE+1
883 if (np.mod(STYLE,5) == 0):
884 sesfile.write("\n")
885 # specific entropy array in MJ/kg/K S[tempindex,dindex]
886 for j in range(0,int(self.NT)):
887 for k in range(0,int(self.ND)):
888 sesfile.write("{:16.8e}".format(self.S[j,k]))
889 STYLE=STYLE+1
890 if (np.mod(STYLE,5) == 0):
891 sesfile.write("\n")
892 # close the SESAME TABLE FILE
893 sesfile.close()
894 print('Done writing the GADGET INIT SESAME 301 notension table to local directory: ',writegadgetinitsesfname)
896 def writemdqsesame(self, writemdqsesfname=None):
897 """Function to write a sesame 301-style ascii file with the MDQ variable"""
898 if writemdqsesfname is None:
899 print('Please provide a file name.')
900 exit(0)
901 sesfile = open(writemdqsesfname,"w")
902 sesfile.write("{:16.8e}{:16.8e}".format(self.ND, self.NT))
903 STYLE=2
904 # density array g/cm3
905 for k in range(0, int(self.ND)):
906 sesfile.write("{:16.8e}".format(self.rho[k]))
907 STYLE=STYLE+1
908 if (np.mod(STYLE,5) == 0):
909 sesfile.write("\n")
910 # temperature array K
911 for j in range(0, int(self.NT)):
912 sesfile.write("{:16.8e}".format(self.T[j]))
913 STYLE=STYLE+1
914 if (np.mod(STYLE,5) == 0):
915 sesfile.write("\n")
916 # MDQ Flag[tempindex,dindex]
917 for j in range(0,int(self.NT)):
918 for k in range(0,int(self.ND)):
919 sesfile.write("{:16.8e}".format(self.MDQ[j,k]))
920 STYLE=STYLE+1
921 if (np.mod(STYLE,5) == 0):
922 sesfile.write("\n")
923 # close the SESAME TABLE FILE
924 sesfile.close()
925 print('Done writing the MDQ Flag as a 301-style table to local directory: ',writemdqsesfname)
927 def loadaneos(self, aneosinfname=None, aneosoutfname=None, silent=False):
928 """Function for reading in ANEOS INPUT and OUTPUT FILE DATA into EOS structure."""
929 if aneosinfname is None:
930 return 'Must provide input file name.'
931 if aneosoutfname is None:
932 return 'Must provide output file name.'
933 # function to gather data from ANEOS input and output files
934 # SESAME FILE HEADER INFORMATION MUST BE LOADED INTO THE EOS STRUCTURE BEFORE CALLING THIS FUNCTION
935 #
936 # READ IN ANEOS INPUT FILE
937 aneosinputfile = open(aneosinfname,"r")
938 testin=aneosinputfile.readlines() # read in the whole ascii file at once because this is fatser
939 aneosinputfile.close()
940 # gather EOS information from the ANEOS.OUTPUT file
941 aneosoutputfile = open(aneosoutfname,"r")
942 testout=aneosoutputfile.readlines() # read everything in at once because this is faster
943 aneosoutputfile.close()
944 if silent == False:
945 print('Done loading ANEOS files.')
947 # THIS CODE PARSES THE ANEOS.OUTPUT FILE INTO ARRAYS FOR USE IN PLOTTING/USING THE EOS
948 if silent == False:
949 print('ANEOS WAS CALLED WITH THE FOLLOWING INPUT, LOADED FROM FILE ',aneosinfname)
950 # Gather parameters for the gamma function while printing the ANEOS INPUT FILE
951 aneoscount=1
952 for i in np.arange(len(testin)):
953 if testin[i].find('ANEOS') == 0:
954 if aneoscount<9:
955 if silent == False:
956 print(' '+testin[i-3],testin[i-2],testin[i-1],testin[i])
957 aneoscount=aneoscount+1
958 else:
959 if silent == False:
960 print(' '+testin[i])
961 if testin[i].find('ANEOS2') == 0:
962 tmp=testin[i]
963 nelem=int(tmp[10:20])
964 #print('nelem=',nelem)
965 rho0=float(tmp[30:40])
966 #print('rho0=',rho0)
967 gamma0=float(tmp[70:80])
968 #print('gamma0=',gamma0)
969 theta0=float(tmp[80:90])
970 if testin[i].find('ANEOS3') == 0:
971 tmp=testin[i]
972 C24=float(tmp[20:30])/3.
973 #print('C24=',C24)
974 if testin[i].find('ANEOS5') == 0:
975 tmp=testin[i]
976 C60=float(tmp[60:70])
977 C61=float(tmp[70:80])
978 #print('C60=',C60)
979 if testin[i].find('ANEOS7') == 0:
980 tmp=testin[i]
981 betagamma=float(tmp[70:80])
983 # some checks
984 if rho0 != self.R0REF:
985 #print('WARNING: rho0 does not match. ')
986 #assert(False) # just a way to stop the notebook
987 print('WARNING: rho0 does not match. STOPPING THIS NOTEBOOK.')
988 assert(False) # just a way to stop the notebook
990 # GUESS A BIG ARRAY SIZE FOR THE PHASE BOUNDARIES AND HUGONIOT IN ANEOS.OUTPUT
991 # the melt curve, vapor curve and Hugoniot curves are not fixed length outputs
992 nleninit=300
993 meltcurve = 0
995 if silent == False:
996 print('READING DATA FROM ANEOS OUTPUT FILE ',aneosoutfname)
998 # Read in data from the ANEOS.OUTPUT FILE
999 imc = -1 # flag for no melt curve in the model
1000 for i in np.arange(len(testout)):
1001 if testout[i].find(' Data for ANEOS number') == 0:
1002 tmp = testout[i+2][0:50]
1003 eosname = tmp.strip()
1004 if testout[i] == ' TWO-PHASE BOUNDARIES\n':
1005 nvc = nleninit
1006 ivc = i
1007 vcarrtmp = np.zeros((nvc,12),dtype=float)
1008 flag=0
1009 j=0
1010 while flag == 0:
1011 if testout[j+i+4].find(' anphas') == 0:
1012 print(testout[j+i+4])
1013 vcarrtmp[j,:]=vcarrtmp[j-1,:]
1014 j=j+1
1015 else:
1016 tmp=str.replace(testout[j+i+4],'D','E')
1017 tmp3 = tmp[0:157]
1018 tmp4 = list(tmp3.split())
1019 if (len(tmp4) >0) and (float(tmp4[3]) > 0) and (float(tmp4[4]) > 0): # stop if the pressures become negative on the vapor curve
1020 tmp5 = np.asarray(tmp4)
1021 vcarrtmp[j,:] = tmp5[:]
1022 j=j+1
1023 else:
1024 flag=1
1025 vcarr = np.zeros((j,12),dtype=float)
1026 vcarr[:,:] = vcarrtmp[0:j,:]
1027 if testout[i] == ' LIQUID/SOLID PHASE CURVE\n':
1028 nmc = nleninit
1029 imc = i
1030 meltcurve=1
1031 mcarrtmp = np.zeros((nmc,11),dtype=float)
1032 flag=0
1033 j=0
1034 while flag == 0:
1035 tmp = str.replace(testout[j+i+5],'D','E')
1036 tmp3 = tmp[0:132]
1037 tmp4 = list(tmp3.split())
1038 if len(tmp4) > 0:
1039 tmp5 = np.asarray(tmp4)
1040 mcarrtmp[j,:] = tmp5[:]
1041 j=j+1
1042 else:
1043 flag=1
1044 mcarr = np.zeros((j,11),dtype=float)
1045 mcarr[:,:] = mcarrtmp[0:j,:]
1046 if testout[i] == ' HUGONIOT\n':
1047 nhc = nleninit
1048 ihc = i
1049 hcarrtmp = np.zeros((nhc,9),dtype=float)
1050 flag=0
1051 j=0
1052 while flag == 0:
1053# while j<22:
1054 tmp=str.replace(testout[j+i+5],'D','E')
1055 #print(j,i,5,tmp)
1056 tmp3 = tmp[0:109]
1057 tmp4 = list(tmp3.split())
1058 if len(tmp4) > 0:
1059 tmp4[3]='0.0' # this column often gives problems with exponential notation so don't read it
1060 tmp5 = np.asarray(tmp4)
1061 hcarrtmp[j,:] = tmp5[:]
1062 j=j+1
1063 else:
1064 flag=1
1065 hcarr = np.zeros((j,9),dtype=float)
1066 hcarr[:,:] = hcarrtmp[0:j,:]
1068 # UPDATE THE MAIN EOS STRUCTURE WITH GATHERED INFORMATION
1069 # Add variables needed to calculate the ANEOS gamma function
1070 self.gamma0 = gamma0
1071 self.theta0 = theta0
1072 self.C24 = C24
1073 self.C60 = C60
1074 self.C61 = C61
1075 self.beta = betagamma
1076 #
1077 # ANEOS.OUTPUT UNITS ARE NOT THE SAME AS THE SESAME TABLE!
1078 # add the vapor curve to this EOS object extracted from the ANEOS.OUTPUT
1079 # TWO-PHASE BOUNDARIES
1080 # T RHOLIQ RHOVAP PLIQ PVAP ELIQ EVAP SLIQ SVAP GLIQ GVAP PSILIQ PSIVAP NTY
1081 # K kg/m**3 kg/m**3 GPa GPa J/kg J/kg J/kg-K J/kg-K J/kg J/kg
1082 tmp = vcarr.shape
1083 #put vapor curve information in nicely named structure
1084 self.vc.NT = tmp[0]
1085 self.vc.T = vcarr[:,0] # K
1086 self.vc.rl = vcarr[:,1]/1.E3 # g/cm3
1087 self.vc.rv = vcarr[:,2]/1.E3 # g/cm3
1088 self.vc.Pl = vcarr[:,3] # GPa
1089 self.vc.Pv = vcarr[:,4] # GPa
1090 self.vc.Ul = vcarr[:,5]/1.E6 # MJ/kg
1091 self.vc.Uv = vcarr[:,6]/1.E6 # MJ/kg
1092 self.vc.Sl = vcarr[:,7]/1.E6 # MJ/K/kg
1093 self.vc.Sv = vcarr[:,8]/1.E6 # MJ/K/kg
1094 self.vc.Gl = vcarr[:,9]/1.E6 # MJ/kg
1095 self.vc.Gv = vcarr[:,10]/1.E6 # MJ/kg
1096 self.vc.units = 'T K, rho g/cm3, P GPa, U MJ/kg, S MJ/K/kg, G MJ/kg'
1097 # np.interp wants increasing x values
1098 self.onebar.Tvap = np.interp(1.E-4,np.flipud(self.vc.Pl),np.flipud(self.vc.T)) # extract boiling point temperature at 1 bar, K
1099 self.onebar.Siv = np.interp(1.E-4,np.flipud(self.vc.Pl),np.flipud(self.vc.Sl)) # extract liquid sp. entropy at 1 bar, MJ/K/kg
1100 self.onebar.Scv = np.interp(1.E-4,np.flipud(self.vc.Pl),np.flipud(self.vc.Sv)) # extract vapor sp. entropy at 1 bar, MJ/K/kg
1101 self.onebar.rhoiv = np.interp(1.E-4,np.flipud(self.vc.Pl),np.flipud(self.vc.rl)) # extract liquid density at 1 bar, g/cm3
1102 self.onebar.rhocv = np.interp(1.E-4,np.flipud(self.vc.Pl),np.flipud(self.vc.rv)) # extract vapor density at 1 bar, g/cm3
1103 #
1104 # add the ANEOS Hugoniot to this EOS object extracted from the ANEOS.OUTPUT
1105 # RHO T P PC E S V U RHO/RHOO #IT STATE
1106 # kg/m**3 K GPa GPa J/kg J/kg-K km/sec km/sec
1107 #self.anhug.all = hcarr # 2D array of Hugoniot variables
1108 tmp = hcarr.shape
1109 self.anhug.ND = tmp[0] # number of density points on the Hugoniot
1110 self.anhug.rho = hcarr[:,0]/1.E3 # g/cm3
1111 self.anhug.T = hcarr[:,1] # K
1112 self.anhug.P = hcarr[:,2] # GPa
1113 self.anhug.U = hcarr[:,4]/1.E6 # MJ/kg
1114 self.anhug.S = hcarr[:,5]/1.E6 # MJ/K/kg
1115 self.anhug.us = hcarr[:,6] # km/s
1116 self.anhug.up = hcarr[:,7] # km/s
1117 self.anhug.units = 'vars: rho g/cm3, T K, P GPa, U MJ/kg, S MJ/K/kg, Us km/s, Up km/s'
1118 #
1119 # Add melt curve to EOS objects if available
1120 # LIQUID/SOLID PHASE CURVE
1121 # T RLIQ RSOLID PLIQ PSOLID ELIQ ESOLID SLIQ SOLID GLIQ GSOLID #ITER
1122 # K kg/m**3 kg/m**3 GPa GPa J/kg J/kg J/kg-K J/kg-K J/kg J/kg
1123 if meltcurve == 1:
1124 # put the melt curve information in nicely named structure
1125 tmp=mcarr.shape
1126 self.mc.NT = tmp[0]
1127 self.mc.T = mcarr[:,0] # K
1128 self.mc.rl = mcarr[:,1]/1.E3 # g/cm3
1129 self.mc.rs = mcarr[:,2]/1.E3 # g/cm3
1130 self.mc.Pl = mcarr[:,3] # GPa
1131 self.mc.Ps = mcarr[:,4] # GPa
1132 self.mc.Ul = mcarr[:,5]/1.E6 # MJ/kg
1133 self.mc.Us = mcarr[:,6]/1.E6 # MJ/kg
1134 self.mc.Sl = mcarr[:,7]/1.E6 # MJ/K/kg
1135 self.mc.Ss = mcarr[:,8]/1.E6 # MJ/K/kg
1136 self.mc.units = 'T K, rho g/cm3, P GPa, U MJ/kg, S MJ/K/kg'
1137 # NOTE THAT TRIPLE POINT AND VAPOR CURVE SOLUTIONS DO NOT ALWAYS MATCH PERFECTLY AT THE TRIPLE POINT
1138 tmp = np.where(mcarr[:,3] > 0.)[0] # find the triple point first entry with positive pressure
1139 self.tp.T = mcarr[tmp[0],0] # K
1140 self.tp.P = np.interp(self.tp.T,np.flipud(self.vc.T),np.flipud(self.vc.Pv)) # this has trouble for forsterite; use the vapor size of the VC mcarr[:,3] # GPa
1141 self.tp.Sim = mcarr[tmp[0],8]/1.E6 # extract solid sp. entropy at tp, MJ/K/kg
1142 self.tp.Scm = mcarr[tmp[0],7]/1.E6 # extract liquid sp. entropy at tp, MJ/K/kg
1143 # np.interp wants x values increasing
1144 self.tp.Siv = np.interp(self.tp.T,np.flipud(self.vc.T),np.flipud(self.vc.Sl)) # extract liquid sp. entropy at tp, MJ/K/kg
1145 self.tp.Scv = np.interp(self.tp.T,np.flipud(self.vc.T),np.flipud(self.vc.Sv)) # extract vapor sp. entropy at tp, MJ/K/kg
1146 self.tp.rhol = mcarr[tmp[0],1]/1.E3 # extract liquid density at tp, g/cm3
1147 self.tp.rhos = mcarr[tmp[0],2]/1.E3 # extract solid density at tp, g/cm3
1148 self.tp.rhov = np.interp(self.tp.T,np.flipud(self.vc.T),np.flipud(self.vc.rv)) # extract vapor density at tp, g/cm3
1149 self.tp.units = 'T K, P GPa, S MJ/K/kg, rho g/cm3'
1150 # Extract melting point
1151 self.onebar.Tmelt = np.interp(1.E-4,self.mc.Pl,self.mc.T) # extract melting point temperature at 1 bar, K
1152 self.onebar.Sim = np.interp(1.E-4,self.mc.Pl,self.mc.Ss) # extract liquid sp. entropy at 1 bar BP, MJ/K/kg
1153 self.onebar.Scm = np.interp(1.E-4,self.mc.Pl,self.mc.Sl) # extract vapor sp. entropy at 1 bar BP, MJ/K/kg
1154 self.onebar.rhoim = np.interp(1.E-4,self.mc.Pl[3::],self.mc.rs[3::]) # extract solid density at 1 bar MP, MJ/K/kg
1155 self.onebar.rhocm = np.interp(1.E-4,self.mc.Pl[3::],self.mc.rl[3::]) # extract liquid density at 1 bar MP, MJ/K/kg
1156 # put the data for the critical point in the EOS structure for easy access
1157 self.cp.T = vcarr[0,0] # K
1158 self.cp.rho = vcarr[0,1]/1.E3 # g/cm3
1159 self.cp.P = vcarr[0,3] # GPa
1160 self.cp.U = vcarr[0,5]/1.E6 # MJ/kg
1161 self.cp.S = vcarr[0,7]/1.E6 # MJ/K/kg
1162 self.cp.units = 'T K, rho g/cm3, P GPa, U MJ/kg, S MJ/K/kg'
1163 #------------------------------------------------------------------
1165 def loadaneosidg(self, aneosinfname=None, aneosoutfname=None, silent=False):
1166 """Function for reading in IDEAL GAS MODEL
1167 ANEOS INPUT and OUTPUT FILE DATA into EOS structure."""
1168 if aneosinfname is None:
1169 return 'Must provide input file name.'
1170 if aneosoutfname is None:
1171 return 'Must provide output file name.'
1172 # function to gather data from ANEOS input and output files
1173 # SESAME FILE HEADER INFORMATION MUST BE LOADED INTO THE EOS STRUCTURE BEFORE CALLING THIS FUNCTION
1174 #
1175 # READ IN ANEOS INPUT FILE
1176 aneosinputfile = open(aneosinfname,"r")
1177 testin=aneosinputfile.readlines() # read in the whole ascii file at once because this is fatser
1178 aneosinputfile.close()
1179 # gather EOS information from the ANEOS.OUTPUT file
1180 aneosoutputfile = open(aneosoutfname,"r")
1181 testout=aneosoutputfile.readlines() # read everything in at once because this is faster
1182 aneosoutputfile.close()
1183 if silent == False:
1184 print('Done loading ANEOS files.')
1186 # THIS CODE PARSES THE ANEOS.OUTPUT FILE INTO ARRAYS FOR USE IN PLOTTING/USING THE EOS
1187 if silent == False:
1188 print('ANEOS WAS CALLED WITH THE FOLLOWING INPUT, LOADED FROM FILE ',aneosinfname)
1189 # Gather parameters for the gamma function while printing the ANEOS INPUT FILE
1190 aneoscount=1
1191 for i in np.arange(len(testin)):
1192 if testin[i].find('ANEOS') == 0:
1193 if aneoscount<9:
1194 if silent == False:
1195 print(' '+testin[i-3],testin[i-2],testin[i-1],testin[i])
1196 aneoscount=aneoscount+1
1197 else:
1198 if silent == False:
1199 print(' '+testin[i])
1200 if testin[i].find('ANEOS2') == 0:
1201 tmp=testin[i]
1202 nelem=int(tmp[10:20])
1203 #print('nelem=',nelem)
1204 eostype=int(tmp[20:30])
1205 #print('eostype=',eostype)
1206 rho0=float(tmp[30:40])
1207 #print('rho0=',rho0)
1208 gamma0=float(tmp[70:80])+1 # input was cp/cv-1
1209 #print('gamma0=',gamma0)
1211 # some checks
1212 if rho0 != self.R0REF:
1213 print('WARNING: rho0 does not match. ')
1214 #assert(False) # just a way to stop the notebook
1215 #print('WARNING: rho0 does not match. STOPPING THIS NOTEBOOK.')
1216 #assert(False) # just a way to stop the notebook
1218 # GUESS A BIG ARRAY SIZE FOR THE PHASE BOUNDARIES AND HUGONIOT IN ANEOS.OUTPUT
1219 # the melt curve, vapor curve and Hugoniot curves are not fixed length outputs
1220 nleninit=300
1221 meltcurve = 0
1223 if silent == False:
1224 print('READING DATA FROM ANEOS OUTPUT FILE ',aneosoutfname)
1226 # Read in data from the ANEOS.OUTPUT FILE
1227 imc = -1 # flag for no melt curve in the model
1228 for i in np.arange(len(testout)):
1229 if testout[i].find(' Data for ANEOS number') == 0:
1230 tmp = testout[i+2][0:50]
1231 eosname = tmp.strip()
1232 if testout[i] == ' HUGONIOT\n':
1233 nhc = nleninit
1234 ihc = i
1235 hcarrtmp = np.zeros((nhc,9),dtype=float)
1236 flag=0
1237 j=0
1238# while flag == 0:
1239 while j<22:
1240 tmp=str.replace(testout[j+i+5],'D','E')
1241 #print(j,i,5,tmp)
1242 tmp3 = tmp[0:109]
1243 tmp4 = list(tmp3.split())
1244 if len(tmp4) > 0:
1245 tmp4[3]='0.0' # this column often gives problems with exponential notation so don't read it
1246 tmp5 = np.asarray(tmp4)
1247 hcarrtmp[j,:] = tmp5[:]
1248 j=j+1
1249 else:
1250 flag=1
1251 hcarr = np.zeros((j,9),dtype=float)
1252 hcarr[:,:] = hcarrtmp[0:j,:]
1254 # UPDATE THE MAIN EOS STRUCTURE WITH GATHERED INFORMATION
1255 # Add variables needed to calculate the ANEOS gamma function
1256 self.gamma0 = gamma0
1257 #self.theta0 = theta0
1258 #self.C24 = C24
1259 #self.C60 = C60
1260 #self.C61 = C61
1261 #self.beta = betagamma
1262 #
1263 # add the ANEOS Hugoniot to this EOS object extracted from the ANEOS.OUTPUT
1264 # RHO T P PC E S V U RHO/RHOO #IT STATE
1265 # kg/m**3 K GPa GPa J/kg J/kg-K km/sec km/sec
1266 #self.anhug.all = hcarr # 2D array of Hugoniot variables
1267 tmp = hcarr.shape
1268 self.anhug.ND = tmp[0] # number of density points on the Hugoniot
1269 self.anhug.rho = hcarr[:,0]/1.E3 # g/cm3
1270 self.anhug.T = hcarr[:,1] # K
1271 self.anhug.P = hcarr[:,2] # GPa
1272 self.anhug.U = hcarr[:,4]/1.E6 # MJ/kg
1273 self.anhug.S = hcarr[:,5]/1.E6 # MJ/K/kg
1274 self.anhug.us = hcarr[:,6] # km/s
1275 self.anhug.up = hcarr[:,7] # km/s
1276 self.anhug.units = 'vars: rho g/cm3, T K, P GPa, U MJ/kg, S MJ/K/kg, Us km/s, Up km/s'
1277 #
1278 #------------------------------------------------------------------
1280###########################################################################################
1281########## GADGET STYLE TABLES
1282###########################################################################################
1283class extGADtable:
1284 """Class for v2019 GADGET EOS tables using SESAME UNITS"""
1285 def __init__(self):
1286 """Function to initialize GADGET TABULAR EOS structure"""
1287 self.ND = 0 # integer; number of density points in grid
1288 self.NS = 0 # integer; number of sp. entropy points in grid
1289 self.rho = np.zeros(self.ND) # g/cm3, density values
1290 self.S = np.zeros(self.NS) # MJ/K/kg, sp. entropy values
1291 self.P = np.zeros(self.ND*self.NS) # GPA, pressure(S,rho)
1292 self.T = np.zeros(self.ND*self.NS) # K, temperature(S,rho)
1293 self.U = np.zeros(self.ND*self.NS) # MJ/kg, sp. internal energy(S,rho)
1294 self.A = np.zeros(self.ND*self.NS) # MJ/kg, Helmholtz free energy(S,rho)
1295 self.cs = np.zeros(self.ND*self.NS) # cm/s, sound speed(S,rho)
1296 self.cv = np.zeros(self.ND*self.NS) # MJ/K/kg, sp. heat capacity(S,rho)
1297 self.KPA = np.zeros(self.ND*self.NS) # integer, ANEOS KPA flag(S,rho)
1298 self.MDQ = np.zeros(self.ND*self.NS) # integer, Model Development Quality Flag(S,rho)
1299 self.units = 'Units: g/cm3, MJ/K/kg, GPa, K, MJ/kg, MJ/kg, cm/s, MJ/K/kg, KPA flag. 2D arrays are (NS,ND).'
1300 self.MODELNAME = ''
1301 #
1302 def view(self, q='P', Slow=None, Shigh=None, rholow=None, rhohigh=None):
1303 """Function to print variables from GADGET EOS table"""
1304 if Slow is None:
1305 Slow = self.S.min()
1306 if Shigh is None:
1307 Shigh = self.S.max()
1308 if rholow is None:
1309 rholow = self.rho.min()
1310 if rhohigh is None:
1311 rhohigh = self.rho.max()
1312 if q == 'P':
1313 print('S:', self.S[np.logical_and(self.S >= Slow,self.S <= Shigh)])
1314 print('rho:', self.rho[np.logical_and(self.rho >= rholow,
1315 self.rho <= rhohigh)
1316 ])
1317 print('P:', (self.P[np.logical_and(self.S >= Slow,
1318 self.S<=Shigh)
1319 ])[:, np.logical_and(self.rho >= rholow,
1320 self.rho <= rhohigh)
1321 ])
1322 if q == 'U':
1323 print('S:', self.S[np.logical_and(self.S >= Slow,self.S <= Shigh)])
1324 print('rho:', self.rho[np.logical_and(self.rho >= rholow,
1325 self.rho <= rhohigh)
1326 ])
1327 print('U:', (self.U[np.logical_and(self.S >= Slow,
1328 self.S <= Shigh)
1329 ])[:, np.logical_and(self.rho >= rholow,
1330 self.rho <= rhohigh)
1331 ])
1332 if q == 'A':
1333 print('S:', self.S[np.logical_and(self.S >= Slow,self.S <= Shigh)])
1334 print('rho:', self.rho[np.logical_and(self.rho >= rholow,
1335 self.rho <= rhohigh)
1336 ])
1337 print('A:', (self.A[np.logical_and(self.S >= Slow,
1338 self.S <= Shigh)
1339 ])[:, np.logical_and(self.rho >= rholow,
1340 self.rho <= rhohigh)
1341 ])
1342 if q == 'T':
1343 print('S:', self.S[np.logical_and(self.S >= Slow,self.S <= Shigh)])
1344 print('rho:', self.rho[np.logical_and(self.rho
1345 >= rholow,self.rho<=rhohigh)
1346 ])
1347 print('T:', (self.T[np.logical_and(self.S >= Slow,self.S <= Shigh)
1348 ])[:, np.logical_and(self.rho >= rholow,
1349 self.rho <= rhohigh)
1350 ])
1351 if q == 'cs':
1352 print('S:', self.S[np.logical_and(self.S >= Slow,self.S <= Shigh)])
1353 print('rho:', self.rho[np.logical_and(self.rho >= rholow,
1354 self.rho<=rhohigh)])
1355 print('cs:', (self.cs[np.logical_and(self.S >= Slow,
1356 self.S <= Shigh)
1357 ])[:, np.logical_and(self.rho >= rholow,
1358 self.rho <= rhohigh)
1359 ])
1360 if q == 'cv':
1361 print('S:', self.S[np.logical_and(self.S >= Slow,self.S <= Shigh)])
1362 print('rho:', self.rho[np.logical_and(self.rho >= rholow,
1363 self.rho<=rhohigh)])
1364 print('cv:', (self.cv[np.logical_and(self.S >= Slow,
1365 self.S <= Shigh)
1366 ])[:, np.logical_and(self.rho >= rholow,
1367 self.rho <= rhohigh)
1368 ])
1369 if q == 'KPA':
1370 print('S:', self.S[np.logical_and(self.S >= Slow,self.S <= Shigh)])
1371 print('rho:', self.rho[np.logical_and(self.rho >= rholow,
1372 self.rho<=rhohigh)])
1373 print('KPA:', (self.KPA[np.logical_and(self.S >= Slow,
1374 self.S <= Shigh)
1375 ])[:, np.logical_and(self.rho >= rholow,
1376 self.rho <= rhohigh)
1377 ])
1378 #
1379 def writestdgadget(self, writestdgadgetfname=None):
1380 """Function to write an standard gadget2 EOS ascii file in 301 format"""
1381 #sesfile = open("NEW-GADGET-STD-NOTENSION.TXT","w")
1382 if writestdgadgetfname is None:
1383 print('Please provide a file name.')
1384 exit(0)
1385 sesfile = open(writestdgadgetfname,"w")
1386 sesfile.write("{:16.8e}{:16.8e}".format(self.ND, self.NS))
1387 STYLE=2
1388 # density array g/cm3
1389 for k in range(0, int(self.ND)):
1390 sesfile.write("{:16.8e}".format(self.rho[k]))
1391 STYLE=STYLE+1
1392 if (np.mod(STYLE,5) == 0):
1393 sesfile.write("\n")
1394 # sp. entropy array MJ/K/kg -> erg/K/g
1395 for j in range(0, int(self.NS)):
1396 sesfile.write("{:16.8e}".format(self.S[j]*1.E10))
1397 STYLE=STYLE+1
1398 if (np.mod(STYLE,5) == 0):
1399 sesfile.write("\n")
1400 # pressure array GPa -> dynes/cm2 P[sindex,dindex]
1401 for j in range(0,int(self.NS)):
1402 for k in range(0,int(self.ND)):
1403 sesfile.write("{:16.8e}".format(self.P[j,k]*1.E10))
1404 STYLE=STYLE+1
1405 if (np.mod(STYLE,5) == 0):
1406 sesfile.write("\n")
1407 # temperature array K T[sindex,dindex]
1408 for j in range(0,int(self.NS)):
1409 for k in range(0,int(self.ND)):
1410 sesfile.write("{:16.8e}".format(self.T[j,k]))
1411 STYLE=STYLE+1
1412 if (np.mod(STYLE,5) == 0):
1413 sesfile.write("\n")
1414 # specific internal energy array MJ/kg -> erg/g U[sindex,dindex]
1415 for j in range(0,int(self.NS)):
1416 for k in range(0,int(self.ND)):
1417 sesfile.write("{:16.8e}".format(self.U[j,k]*1.E10))
1418 STYLE=STYLE+1
1419 if (np.mod(STYLE,5) == 0):
1420 sesfile.write("\n")
1421 # sound speed array cm/s cs[sindex,dindex]
1422 for j in range(0,int(self.NS)):
1423 for k in range(0,int(self.ND)):
1424 sesfile.write("{:16.8e}".format(self.cs[j,k]))
1425 STYLE=STYLE+1
1426 if (np.mod(STYLE,5) == 0):
1427 sesfile.write("\n")
1428 # close the STD GADGET TABLE FILE
1429 sesfile.close()
1430 print('Done writing the STD GADGET TABLE FILE with notension to local directory: ',writestdgadgetfname)
1431 #
1432 def writeextgadget(self, writeextgadgetfname=None):
1433 """Function to write an extended gadget2 EOS ascii file in 301 format"""
1434 #sesfile = open("NEW-GADGET-EXT-NOTENSION.TXT","w")
1435 if writeextgadgetfname is None:
1436 print('Please provide a file name.')
1437 exit(0)
1438 sesfile = open(writeextgadgetfname,"w")
1439 sesfile.write("{:16.8e}{:16.8e}".format(self.ND, self.NS))
1440 STYLE=2
1441 # density array g/cm3
1442 for k in range(0, int(self.ND)):
1443 sesfile.write("{:16.8e}".format(self.rho[k]))
1444 STYLE=STYLE+1
1445 if (np.mod(STYLE,5) == 0):
1446 sesfile.write("\n")
1447 # sp. entropy array MJ/K/kg -> erg/K/g
1448 for j in range(0, int(self.NS)):
1449 sesfile.write("{:16.8e}".format(self.S[j]*1.E10))
1450 STYLE=STYLE+1
1451 if (np.mod(STYLE,5) == 0):
1452 sesfile.write("\n")
1453 # Helmholtz free energy array in MJ/kg -> ergs/g A[tempindex,dindex]
1454 for j in range(0,int(self.NS)):
1455 for k in range(0,int(self.ND)):
1456 sesfile.write("{:16.8e}".format(self.A[j,k]*1.E10))
1457 STYLE=STYLE+1
1458 if (np.mod(STYLE,5) == 0):
1459 sesfile.write("\n")
1460 # sp. heat capacity array MJ/K/kg -> erg/K/g cv[sindex,dindex]
1461 for j in range(0,int(self.NS)):
1462 for k in range(0,int(self.ND)):
1463 sesfile.write("{:16.8e}".format(self.cv[j,k]*1.E10))
1464 STYLE=STYLE+1
1465 if (np.mod(STYLE,5) == 0):
1466 sesfile.write("\n")
1467 # KPA array flag k[sindex,dindex]
1468 for j in range(0,int(self.NS)):
1469 for k in range(0,int(self.ND)):
1470 sesfile.write("{:16.8e}".format(self.KPA[j,k]))
1471 STYLE=STYLE+1
1472 if (np.mod(STYLE,5) == 0):
1473 sesfile.write("\n")
1474 # MDQ array flag MDQ[sindex,dindex]
1475 for j in range(0,int(self.NS)):
1476 for k in range(0,int(self.ND)):
1477 sesfile.write("{:16.8e}".format(self.MDQ[j,k]))
1478 STYLE=STYLE+1
1479 if (np.mod(STYLE,5) == 0):
1480 sesfile.write("\n")
1481 # close the EXTENDED GADGET TABLE FILE
1482 sesfile.close()
1483 print('Done writing the EXTENDED GADGET TABLE FILE with notension to local directory: ',writeextgadgetfname)
1484 #
1486###########################################################################################
1487########## TILLOTSON TABLE CLASS
1488###########################################################################################
1489class TillotsonClass:
1490 """Class for tabulated Tillotson EOS tables using SESAME UNITS"""
1491 def __init__(self):
1492 """Function to initialize Tillotson TABULAR EOS structure"""
1493 # variables stored in SESAME units
1494 self.rho0 = 0. # reference density g/m3
1495 self.E0 = 0. # E0 constant MJ/kg
1496 self.EIV = 0. # specific internal energy of incipient vaporization MJ/kg
1497 self.ECV = 0. # specific internal energy of complete vaporization MJ/kg
1498 self.AA = 0. # Bulk modulus K0 GPa
1499 self.BB = 0. # B constant GPa
1500 self.a = 0. # a constant [-]
1501 self.b = 0. # b constant [-]
1502 self.alpha = 0. # alpha constant [-]
1503 self.beta = 0. # beta constant [-] a+b=Gruneisen gamma at rho0
1504 self.cv = 0. # constant specific heat capacity MJ/K/kg
1505 self.t0 = 298. # K
1506 self.params = [] # for passing the parameter list to subroutines
1507 self.ND = 0 # integer; number of density points in grid
1508 self.NU = 0 # integer; number of sp. internal energy points in grid
1509 self.rho = np.zeros(self.ND) # g/cm3, density values
1510 self.U = np.zeros(self.NU) # MJ/kg, sp. internal energy values
1511 self.P = np.zeros(self.ND*self.NU) # GPA, pressure(U,rho)
1512 self.cs = np.zeros(self.ND*self.NU) # km/s, sound speed(U,rho)
1513 self.region= np.zeros(self.ND*self.NU) # region flag: 1-condensed, 2-interpolated, 3-expanded
1514 self.T = np.zeros(self.ND*self.NU) # K temperature
1515 self.units = 'Units: g/cm3, MJ/kg, GPa, cm/s, K. 2D arrays are (NU,ND).'
1516 self.MODELNAME = ''
1517 self.hug = EOShugoniot()
1518 self.ecold = EOScurve() # energy as a function of density (rho>rho0) with initial condition of E=0 at rho0
1519 def assignparams(self,tilleos):
1520 # index numbers for material parameters in the tilleos array
1521 r0 = 0
1522 E0 = 1
1523 EIV = 2
1524 ECV=3
1525 AA=4
1526 BB=5
1527 a=6
1528 b=7
1529 alpha=8
1530 beta=9
1531 cv=10
1532 self.params = tilleos # in MKS
1533 self.rho0 = tilleos[r0]/1.e3 # reference density g/m3
1534 self.E0 = tilleos[E0]/1.e6 # E0 constant MJ/kg
1535 self.EIV = tilleos[EIV]/1.e6 # specific internal energy of incipient vaporization MJ/kg
1536 self.ECV = tilleos[ECV]/1.e6 # specific internal energy of complete vaporization MJ/kg
1537 self.AA = tilleos[AA]/1.e9 # Bulk modulus K0 GPa
1538 self.BB = tilleos[BB]/1.e9 # B constant GPa
1539 self.a = tilleos[a] # a constant [-]
1540 self.b = tilleos[b] # b constant [-]
1541 self.alpha = tilleos[alpha] # alpha constant [-]
1542 self.beta = tilleos[beta] # beta constant [-] a+b=Gruneisen gamma at rho0
1543 self.cv = tilleos[cv]/1.e6 # constant specific heat capacity MJ/K/kg
1544 def calcecold(self):
1545 """ Calculate the internal energy of the cold curve. Passed to Tillotson EOS function with params for temperature. """
1546 # start by compressing a factor of 3 with 1000 steps
1547 # Use params in mks units
1548 nsteps = 100
1549 self.ecold.rho = np.arange(nsteps)/nsteps*(2.*self.params[0])+self.params[0] # rho is rho0 to 3*rho0
1550 self.ecold.U = np.zeros(nsteps) # initial energy is zero by definition
1551 self.ecold.P = np.zeros(nsteps) # initial pressure is zero by definition
1552 self.ecold.T = np.zeros(nsteps)+self.t0 # initial temperature is T0 by definition
1553 h = self.ecold.rho[1]-self.ecold.rho[0]
1554 x0 = self.ecold.rho[0]
1555 y = 0.0
1556 for i in range(1, nsteps):
1557 #"Apply Runge Kutta Formulas to find next value of y"
1558 # Rundage 2015: dE/drho = P(rho,E)/rho^2
1559 # Till_P returns [pout,flag,csout,tout]
1560 k1 = h * Till_P(x0,y,self.params,self.ecold,calctemp=False)[0]/x0/x0
1561 k2 = h * Till_P(x0 + 0.5 * h,y + 0.5 * k1,self.params,self.ecold,calctemp=False)[0]/(x0 + 0.5 * h)/(x0 + 0.5 * h)
1562 k3 = h * Till_P(x0 + 0.5 * h,y + 0.5 * k2,self.params,self.ecold,calctemp=False)[0]/(x0 + 0.5 * h)/(x0 + 0.5 * h)
1563 k4 = h * Till_P(x0 + h,y + k3,self.params,self.ecold,calctemp=False)[0]/(x0+h)/(x0+h)
1564 #k1 = h * dydx(x0, y)
1565 #k2 = h * dydx(x0 + 0.5 * h, y + 0.5 * k1)
1566 #k3 = h * dydx(x0 + 0.5 * h, y + 0.5 * k2)
1567 #k4 = h * dydx(x0 + h, y + k3)
1569 # Update next value of y
1570 y = y + (1.0 / 6.0)*(k1 + 2 * k2 + 2 * k3 + k4)
1572 # Update next value of x
1573 x0 = x0 + h
1575 # update structure arrays
1576 self.ecold.rho[i] = x0
1577 self.ecold.U[i] = y
1578 self.ecold.P[i] = Till_P(x0,y,self.params,self.ecold,calctemp=False)[0]
1579 #print('Tillotson cold curve: ',i,x0,y,Till_P(x0,y,self.params,self.ecold,calctemp=False)[0])
1580 return
1581 def FillTable(self, matparams=None, modelname=None):
1582 """Function to populate table with Tillotson EOS. Assumes ND,NU,rho,and U are filled."""
1583 if matparams is None:
1584 print('Must provide a material parameter list [rho0, E0, EIV, ECV, AA, BB, a, b, alpha, beta, cv].')
1585 exit(0)
1586 # matparams: [rho0, E0, EIV, ECV, AA, BB, a, b, alpha, beta, cv]
1587 # units: [kg/m3, J/kg, J/kg, J/kg, Pa, Pa, [-]x4, J/K/kg]
1588 # print(self.NU,self.ND)
1589 self.cs = np.zeros((self.NU,self.ND))
1590 self.P = np.zeros((self.NU,self.ND))
1591 self.T = np.zeros((self.NU,self.ND))
1592 self.region = np.zeros((self.NU,self.ND))
1593# print('Using the iSALE Tillotson implementation.')
1594 print('Using standard Tillotson implementation (e.g., Hosono et al. 2019, Melosh 1989).')
1595 print('Tillotson parameters: ',matparams)
1596 for ie in range(0,self.NU):
1597 for ir in range(0,self.ND):
1598 flag = 0
1599 eng = self.U[ie]*1.e6 # J/kg
1600 dens = self.rho[ir]*1000. # kg/m3
1601 tmp = Till_P_Hosono(dens,eng,matparams) # returns [P Pa, flag]
1602 self.P[ie,ir] = tmp[0]/1.e9 # Pa to GPa
1603 self.region[ie,ir] = tmp[1] # cold, hot, interpolated regions
1604 self.cs[ie,ir] = Till_SoundSpeed(dens,eng,matparams)/1.E3 # km/s
1606 def FillTable_iSALE(self, matparams=None, modelname=None):
1607 """Function to populate table with Tillotson EOS. Assumes ND,NU,rho,and U are filled."""
1608 if matparams is None:
1609 print('Must provide a material parameter list [rho0, E0, EIV, ECV, AA, BB, a, b, alpha, beta, cv].')
1610 exit(0)
1611 # matparams: [rho0, E0, EIV, ECV, AA, BB, a, b, alpha, beta, cv]
1612 # units: [kg/m3, J/kg, J/kg, J/kg, Pa, Pa, [-]x4, J/K/kg]
1613 # print(self.NU,self.ND)
1614 self.cs = np.zeros((self.NU,self.ND))
1615 self.P = np.zeros((self.NU,self.ND))
1616 self.T = np.zeros((self.NU,self.ND))
1617 self.region = np.zeros((self.NU,self.ND))
1618 print('Using the iSALE Tillotson implementation.')
1619# print('Using standard Tillotson implementation (e.g., Hosono et al. 2019, Melosh 1989).')
1620 print('Tillotson parameters: ',matparams)
1621 # Till_P is expecting mks units
1622 for ie in range(0,self.NU):
1623 for ir in range(0,self.ND):
1624 flag = 0
1625 eng = self.U[ie]*1.e6 # J/kg
1626 dens = self.rho[ir]*1000. # kg/m3
1627 tmp = Till_P(dens,eng,matparams,self.ecold,calctemp=True) # returns [P Pa, flag]
1628 self.P[ie,ir] = tmp[0]/1.e9 # Pa to GPa
1629 self.region[ie,ir] = tmp[1] # cold, hot, interpolated regions
1630 self.cs[ie,ir] = tmp[2]/1.e3 # km/s
1631 self.T[ie,ir] = tmp[3] # K
1633 def FillTable_ea(self, matparams=None, modelname=None):
1634 """Function to populate table with Tillotson EOS. Assumes ND,NU,rho,and U are filled."""
1635 if matparams is None:
1636 print('Must provide a material parameter list [rho0, E0, EIV, ECV, AA, BB, a, b, alpha, beta, cv].')
1637 exit(0)
1638 # matparams: [rho0, E0, EIV, ECV, AA, BB, a, b, alpha, beta, cv]
1639 # units: [kg/m3, J/kg, J/kg, J/kg, Pa, Pa, [-]x4, J/K/kg]
1640 # print(self.NU,self.ND)
1641 self.cs = np.zeros((self.NU,self.ND))
1642 self.P = np.zeros((self.NU,self.ND))
1643 self.T = np.zeros((self.NU,self.ND))
1644 self.region = np.zeros((self.NU,self.ND))
1645 print('Using the iSALE Asphaug implementation.')
1646 print('Tillotson parameters: ',matparams)
1647 for ie in range(0,self.NU):
1648 for ir in range(0,self.ND):
1649 flag = 0
1650 eng = self.U[ie]*1.e6 # J/kg
1651 dens = self.rho[ir]*1000. # kg/m3
1652 tmp = tilleos_ea(dens,eng,matparams) # returns [P Pa, flag]
1653 self.P[ie,ir] = tmp[0]/1.e9 # Pa to GPa
1654 self.region[ie,ir] = tmp[1] # cold, hot, interpolated regions
1655 self.cs[ie,ir] = tmp[2]/1.e3 # km/s
1657 def calchugoniot(self, r00=None, e0=None, pmax=None, writefilename=None):
1658 """Function for calculating a Hugoniot from Tillotson EOS table."""
1659 if r00 is None:
1660 return 'Must provide r00 in g/cm^3 and e0 in MJ/kg.'
1661 if e0 is None:
1662 return 'Must provide r0 in g/cm^3 and e0 in MJ/kg.'
1663 if pmax is None:
1664 pmax=1.E4 # GPa
1665 self.hug.rho = []
1666 self.hug.P = []
1667 self.hug.T = []
1668 self.hug.U = []
1669 self.hug.up = []
1670 self.hug.us = []
1671 self.hug.cs = []
1672 self.hug.region = [] # Tillotson region flag
1674 ie0 = int(np.round(np.interp(e0,self.U,np.arange(self.NU)))) # uses nearest value if e0 not in array
1675 ir0 = int(np.round(np.interp(r00,self.rho,np.arange(self.ND)))) # uses nearest value if r0 not in the array
1676 print('Hug ie0,ir0=',ie0,ir0)
1677 r0 = self.rho[ir0] # g/cm^3
1678 p0 = self.P[ie0,ir0] # GPa
1679 e0 = self.U[ie0] # MJ/kg
1680 t0 = self.t0
1681 up0 = 0. # no initial particle velocity km/s
1682 us0 = self.cs[ie0,ir0] # km/s use sound velocity for initial
1683 cs0 = self.cs[ie0,ir0] # km/s use sound velocity for initial
1684 #print(ir0,ie0,r0,p0,e0,up0,us0)
1685 self.hug.rho = np.append(self.hug.rho, self.rho[ir0])
1686 self.hug.P = np.append(self.hug.P, p0)
1687 self.hug.U = np.append(self.hug.U, e0)
1688 self.hug.up = np.append(self.hug.up, up0)
1689 self.hug.us = np.append(self.hug.us, us0)
1690 self.hug.cs = np.append(self.hug.cs, cs0)
1691 self.hug.T = np.append(self.hug.T, t0)
1692 #iir=ir0+1
1693 #pnew=p0
1694 #while pnew<pmax:
1695 #print(iir,pnew,self.P[ie0::,iir],r0,self.rho[iir],e0,self.U[ie0::])
1696 for iir in range(ir0+1,self.ND):
1697 ediff =0.5*(self.P[ie0::,iir]+p0)*(1./r0-1./self.rho[iir])+e0 -(self.U[ie0::]) # MJ/kg
1698 # np.interp wants x values increasing
1699 pnew = np.interp(0.,np.flip(ediff),np.flip(self.P[ie0::,iir]))
1700 enew = np.interp(0.,np.flip(ediff),np.flip(self.U[ie0::]))
1701 csnew = np.interp(0.,np.flip(ediff),np.flip(self.cs[ie0::,iir]))
1702 tnew = np.interp(0.,np.flip(ediff),np.flip(self.T[ie0::,iir]))
1703 upnew = np.sqrt((pnew-p0)*(1./r0-1./self.rho[iir]))
1704 usnew = (1./r0)*np.sqrt((pnew-p0)/(1./r0-1./self.rho[iir]))
1705 #print(self.rho[iir],pnew,enew,upnew,usnew)
1706 self.hug.rho = np.append(self.hug.rho, self.rho[iir])
1707 self.hug.P = np.append(self.hug.P, pnew)
1708 self.hug.U = np.append(self.hug.U, enew)
1709 self.hug.up = np.append(self.hug.up, upnew)
1710 self.hug.us = np.append(self.hug.us, usnew)
1711 self.hug.cs = np.append(self.hug.cs, csnew)
1712 self.hug.T = np.append(self.hug.T, tnew)
1713 #print(iir,pnew)
1714 #iir += 1
1715 self.hug.NH=len(self.hug.P)
1716 self.hug.units='units: rho g/cm3, P GPa, U MJ/kg, Up km/s, Us km/s, cs km/s'
1717 print('Done calculating Hugoniot with Tillotson EOS table.')
1718 def __str__(self):
1719 """ Print the Tillotson EOS parameters """
1720 return f'\n{self.MODELNAME} Tillotson EOS parameters [SESAME Units]: \n' + \
1721 f' rhoref: {self.rho0} \n' + \
1722 f' a: {self.a} \n' + \
1723 f' b: {self.b} \n' + \
1724 f' AA: {self.AA} \n' + \
1725 f' BB: {self.BB} \n' + \
1726 f' E0: {self.E0} \n' + \
1727 f' alpha: {self.alpha} \n' + \
1728 f' beta: {self.beta} \n' + \
1729 f' Eiv: {self.EIV} \n' + \
1730 f' Ecv: {self.ECV} \n' + \
1731 f' cv: {self.cv} \n' + \
1732 f' params [mks]: {self.params} \n'
1733#
1734#
1735###########################################################################################
1736########## TILLOTSON EOS FUNCTIONS
1737###########################################################################################
1738# TILLOTSON FUNCTIONS AS IMPLEMENTED BY HOSONO
1739# dunite tillotson parameters used by Hosono et al. 2019
1740# these olivine parameters are from Marinova et al. 2011 Icarus
1741# parameters: [rho0, E0, EIV, ECV, AA, BB, a, b, alpha, beta]
1742# units: [kg/m3, J/kg, J/kg, J/kg, Pa, Pa, [-]x4]
1743# dunitetill = [3500.0, 550.0e+6, 4.500e+6, 14.50e+6, 131.00e+9, 49.00e+9, 0.5, 1.4, 5.0, 5.0]
1744# Basalt parameters from iSALE -- from where? Benz?
1745# basalttill = [2650.0, 4.87E8, 4.72E6, 18.2E6, 5.3E10, 5.3E10, 0.6, 0.6, 5., 5.]
1746#
1747def Till_P_co(dens,eng,tilleos):
1748 r0 = 0
1749 E0 = 1
1750 EIV = 2
1751 ECV=3
1752 AA=4
1753 BB=5
1754 a=6
1755 b=7
1756 alpha=8
1757 beta=9
1758 # Hosono implementation - straight up equation
1759 eta = dens/tilleos[r0]
1760 mu = eta - 1.0
1761 pco = (tilleos[a] + tilleos[b] / (eng / tilleos[E0] / eta / eta + 1.0)) * dens * eng + \
1762 tilleos[AA] * mu + tilleos[BB] * mu * mu
1764 return pco
1765#
1766def Till_P_ex(dens,eng,tilleos):
1767 import numpy as np
1768 r0 = 0
1769 E0 = 1
1770 EIV = 2
1771 ECV=3
1772 AA=4
1773 BB=5
1774 a=6
1775 b=7
1776 alpha=8
1777 beta=9
1778 # hosono equation
1779 eta = dens/tilleos[r0]
1780 mu = eta - 1.0
1781 pex = tilleos[a] * dens * eng + \
1782 (tilleos[b] * dens * eng / (eng / tilleos[E0] / eta / eta + 1.0) + \
1783 tilleos[AA] * mu * np.exp(- tilleos[beta] * (1.0 / eta - 1.0))) * \
1784 np.exp(- tilleos[alpha] * (1.0 / eta - 1.0) * (1.0 / eta - 1.0))
1785 return pex
1786#
1787def Till_P_Hosono(dens,eng,tilleos):
1788 flag=0 # flag for the region of the EOS
1789 r0 = 0 # index numbers for variables in the tilleos array
1790 E0 = 1
1791 EIV = 2
1792 ECV=3
1793 AA=4
1794 BB=5
1795 a=6
1796 b=7
1797 alpha=8
1798 beta=9
1800 # Hosono has 2 options
1801 pmin=1.e-7
1803 # option 1
1804 if ( (dens>tilleos[r0]) or (eng < tilleos[EIV]) ):
1805 # condensed region
1806 flag=1
1807 pco = Till_P_co(dens,eng,tilleos)
1808 #if pco < pmin:
1809 # pout = pmin
1810 #else:
1811 # pout = pco
1812 # allow tension
1813 pout = pco
1814 return [pout,flag]
1815 else:
1816 if ( (dens < tilleos[r0]) and (eng >= tilleos[ECV]) ):
1817 # expanded region
1818 flag=3
1819 pex = Till_P_ex(dens,eng,tilleos)
1820 #if pex < pmin:
1821 # pout = pmin
1822 #else:
1823 # pout = pex
1824 pout=pex
1825 return [pout,flag]
1826 else:
1827 # interpolated region
1828 flag=2
1829 Pex = Till_P_ex(dens,eng,tilleos)
1830 Pco = Till_P_co(dens,eng,tilleos)
1831 # nobody seem to do this step
1832 #if Pco < pmin:
1833 # Pco = pmin
1834 Pint = ((eng-tilleos[EIV])*Pex+(tilleos[ECV]-eng)*Pco)/(tilleos[ECV]-tilleos[EIV])
1835 #if Pint < pmin:
1836 # pout = pmin
1837 #else:
1838 # pout = Pint
1839 pout=Pint
1840 return [pout,flag]
1841 '''
1842 # option 2
1843 if ( (dens>=tilleos[r0]) or (eng < tilleos[EIV]) ):
1844 # condensed region
1845 flag=1
1846 pout = Till_P_co(dens,eng,tilleos)
1847 if (dens <= 0.9*tilleos[r0]):
1848 pout = 1.e-16
1849 return [pout,flag]
1850 else:
1851 if ( (dens < tilleos[r0]) and (eng > tilleos[ECV]) ):
1852 # expanded region
1853 flag=3
1854 pout = Till_P_ex(dens,eng,tilleos)
1855 else:
1856 # interpolated region
1857 flag=2
1858 Pex = Till_P_ex(dens,eng,tilleos)
1859 Pco = Till_P_co(dens,eng,tilleos)
1860 pout = ((eng-tilleos[EIV])*Pex+(tilleos[ECV]-eng)*Pco)/(tilleos[ECV]-tilleos[EIV])
1861 if (pout < pmin):
1862 pout = pmin
1863 return [pout,flag]
1864 '''
1865 # END HOSONO TILLOTSON FUNCTION
1866def Till_dPdrho(dens,eng,tilleos):
1867 drho=0.0001
1868 a = Till_P_Hosono(dens+drho,eng,tilleos)
1869 b = Till_P_Hosono(dens-drho,eng,tilleos)
1870 return (a[0] - b[0])/(2.*drho)
1872def Till_dPdu(dens,eng,tilleos):
1873 ddu=0.0001
1874 a=Till_P_Hosono(dens,eng+ddu,tilleos)
1875 b=Till_P_Hosono(dens,eng-ddu,tilleos)
1876 return (a[0] - b[0])/(2.*ddu)
1878def Till_SoundSpeed(dens,eng,tilleos):
1879 #if dens<= 100.:
1880 # cs = 1.e-8 # m/s
1881 #else:
1882 ptil = Till_P_Hosono(dens,eng,tilleos)[0]
1883 cs2 = ptil/(dens*dens)*Till_dPdu(dens,eng,tilleos) + Till_dPdrho(dens,eng,tilleos)
1884 if cs2 < 0.:
1885 cs2 = np.abs(ptil/dens) # better to use ideal gas approx
1886 cs = np.sqrt(cs2)
1887 return cs
1888# END HOSONO FUNCTIONS
1889# ------------------------------
1890# iSALE Dellon implementation of Tillotson --> now substantially modified
1891# added cold curve and temperature calcs 2023-06-30 STS
1892# region logic fixed and temp variables removed sts 7/3/2023
1894def Till_P(rin,ein,tilleos,ecold,calctemp=True):
1895 """ tilleos is the params list for the material
1896 ecold is an EOScurve object with the cold curve at t0
1897 returns [pout,flag,csout,tout]
1898 """
1899 # output variables
1900 flag = 0 # flag for the region of the EOS
1901 pout = 0.
1902 csout = 0.
1903 tout = 0.
1904 #
1905 # iSALE implementation of Tillotson
1906 # index numbers for material parameters in the tilleos array
1907 # should all be in code units/self-consistent units
1908 r0 = 0
1909 E0 = 1
1910 EIV = 2
1911 ECV = 3
1912 AA = 4
1913 BB = 5
1914 a = 6
1915 b = 7
1916 alpha = 8
1917 beta = 9
1918 cv = 10 # cv is converted to code units eu/K/(original volume cm3)
1919 #
1920 # if density is zero or negative return 0 pressure
1921 if (rin <= 0.):
1922 pout = 0.
1923 csout = 0.
1924 tout = 0.
1925 flag = -1
1926 return [pout,flag,csout,tout]
1927 #
1928 # define intermediate variables
1929 eta = rin/tilleos[r0]
1930 mu = eta - 1.0
1931 imu = tilleos[r0]/rin - 1.0
1932 #temp = tilleos[E0] * np.power(eta,2.)
1933 erel = ein/(tilleos[E0] * np.power(eta,2.))
1934 #if (temp > 0.):
1935 # erel = ein/temp
1936 #else:
1937 # # avoids divide by zero
1938 # erel = 0.
1939 ierel = 1./(erel + 1.)
1940 grun = tilleos[a] + tilleos[b]*ierel
1941 gterm = tilleos[a] * rin * ein
1942 eterm = tilleos[b] * rin * ein * ierel
1943 #
1944 # initialize hot and cold terms to the pressure
1945 ph = 0.
1946 pc = 0.
1947 #
1948 #if ( (eta < 1.) & (ein >= tilleos[ECV]) ):
1949 # calculate ph for expanded region above ECV
1950 #flag = 3
1951 #tmp = tilleos[alpha]*np.power(imu,2.)
1952 exp_a = np.exp(-tilleos[alpha]*np.power(imu,2.))
1953 #if (tmp < 100.): # why 100? need to make some plots on this limit
1954 # exp_a = np.exp(-tmp)
1955 #else:
1956 # exp_a = 0.
1957 #tmp = tilleos[beta]*imu
1958 exp_b = np.exp(-tilleos[beta]*imu)
1959 #if (tmp < 100.): # check this limit
1960 # exp_b = np.exp(-tmp)
1961 #else:
1962 # exp_b = 0.
1963 # compute "hot pressure"
1964 ph = gterm + (eterm + tilleos[AA]*mu*exp_b)*exp_a
1965 #
1966 # compute sound speed from derivatives
1967 dpre2 = tilleos[b]*ein*ierel*(1.+2.*(tilleos[alpha]*imu/eta + erel*ierel))*exp_a
1968 dpre3 = (tilleos[AA]/rin)*(1.+(mu/np.power(eta,2.))*(tilleos[beta]+2.*tilleos[alpha]*imu))*exp_a*exp_b
1969 dpreh = tilleos[a]*ein+dpre2+dpre3
1970 dperh = rin*(tilleos[a]+tilleos[b]*ierel*(1.-erel*ierel)*exp_a)
1971 c_dperh = (ph/np.power(rin,2.))*dperh
1972 cs2_h = dpreh + c_dperh
1973 cs2 = cs2_h
1975 #if ( (eta >= 1.) or (ein < tilleos[EIV]) ):
1976 # compressed region or expanded below energy of complete vaporization
1977 # should update this flag and calculate rho_IV for proper use of the low energy expansion
1978 if (eta >= 1.):
1979 #flag=1
1980 # low energy compression
1981 b_temp = tilleos[BB] # in compression without cubic
1982 else:
1983 #flag=4
1984 # low energy expansion
1985 # different versions are implemented
1986 # Brundage 2013 uses zero
1987 # iSALE Dellen uses AA or suggests BB if BB<AA
1988 # obviously needs some comparisons to data to know what to do here
1989 # b_temp = tilleos[AA] # in expansion
1990 b_temp = 0.0 # using Brundage option for simplicity at this point
1991 #pcold = (tilleos[AA] * mu) + (b_temp * np.power(mu,2.))
1992 pcold = (tilleos[AA] * mu) + (tilleos[BB] * np.power(mu,2.))
1993 pc = gterm + eterm + pcold
1994 # allow tension for pyKO
1995 #if (pc < 0.):
1996 # pc=1.e-10
1997 #
1998 # compute sound speed from derivatives
1999 dprec = (tilleos[AA]+2.*b_temp*mu)/tilleos[r0] + ein*(grun+2.*tilleos[b]*erel*ierel*ierel)
2000 dperc = rin * (grun-tilleos[b]*erel*ierel*ierel)
2001 c_dperc = (pc/(np.power(rin,2.)))*dperc
2002 cs2_c = dprec + c_dperc
2003 cs2 = cs2_c
2005 if calctemp:
2006 # Estimate the temperature for rho>rho0
2007 # extract the cold curve energy for the current density
2008 # ecold needs to be in same units as this function to work
2009 ecold_rin = np.interp(rin,ecold.rho,ecold.U)
2010 tout=ecold.T[0]+(ein-ecold_rin)/tilleos[cv]
2011 #print(rin,ein,ecold_rin,tilleos[cv],tout)
2013 # Figure out the right region
2014 if ( (eta < 1.) & (ein >= tilleos[ECV]) ):
2015 # expanded region above ECV
2016 flag = 3
2017 cs2 = cs2_h
2018 pout = ph
2019 if ( (eta >= 1.) or (ein < tilleos[EIV]) ):
2020 cs2 = cs2_c
2021 pout = pc
2022 if (eta >= 1.):
2023 flag=1
2024 else:
2025 flag=4
2026 #
2027 if (ein > tilleos[EIV]) & (ein < tilleos[ECV]) & (eta < 1.):
2028 # interpolated region
2029 flag=2
2030 pout = ((ein-tilleos[EIV])*ph+(tilleos[ECV]-ein)*pc)/(tilleos[ECV]-tilleos[EIV])
2031 # transition sound speed
2032 dprem = ((ein-tilleos[EIV])*dpreh + (tilleos[ECV]-ein)*dprec) / (tilleos[ECV]-tilleos[EIV])
2033 dperm = ((ein-tilleos[EIV])*dperh + (tilleos[ECV]-ein)*dperc+ph-pc) / (tilleos[ECV]-tilleos[EIV])
2034 cs2_m = dprem+(pout/np.power(rin,2.))*dperm
2035 cs2 = cs2_m
2036 #
2037 # limiting after tillotson EOS
2038 # allow negative pressures for pyKO
2039 #if (pout <= 1.e-10):
2040 # pout = 1.e-10 # pmin
2041 # cs2 = tilleos[AA]/tilleos[r0]
2042 #
2043 if cs2>0:
2044 csout = np.sqrt(cs2)
2045 else:
2046 #csout = np.sqrt(tilleos[AA]/tilleos[r0])
2047 # use ideal gas approximation when low density limit?
2048 csout = np.sqrt(np.abs(pout/rin))
2049 return [pout,flag,csout,tout]
2050 # END OF TILLOTSON EOS ISALE IMPLEMENTATION FUNCTIONS
2051##------------------------------
2052## Erik Asphaug Tillotson Routine converted from tilleos.f 7/3/2023
2053## Did not have temperature implemented
2054## Using this to cross-check the sound speed derivates with iSALE version
2055def tilleos_ea(rin,ein,tilleos):
2056 # tilleos is the params list for the material
2057 # returns [pout,flag,csout]
2058 # initialize output variables as zeros
2059 # Tillotson region flag: 1-condensed, 2-interpolated, 3-expanded, 4-low energy expansion
2060 flag = 0 # flag for the region of the EOS
2061 pout = 0. # P(rin,ein)
2062 csout = 0. # cs(rin,ein)
2064 # Index numbers for tilleos array; cv=10 not used here
2065 r0 = 0 # index numbers for material parameters in the tilleos array
2066 E0 = 1
2067 EIV = 2
2068 ECV = 3
2069 AA = 4
2070 BB = 5
2071 a = 6
2072 b = 7
2073 alpha = 8
2074 beta = 9
2076 # assign Tillotson parameters into Asphaug variable names
2077 rozn = tilleos[r0] # rozero[imat]
2078 ezn = tilleos[E0] # uzero[imat]
2079 capan = tilleos[AA] # capa[imat]
2080 esn = tilleos[EIV] # es[imat]
2081 espn = tilleos[ECV] # esp[imat]
2082 difesn = espn-esn
2083 capbn = tilleos[BB] # capb[imat]
2084 smallaj = tilleos[a] # smalla[imat]
2085 smallbj = tilleos[b] # smallb[imat]
2086 alphaj = tilleos[alpha] # alpha[imat]
2087 betaj = tilleos[beta] # beta[imat]
2089 ui = ein
2090 rhoi = rin
2091 rhoi2 = rin*rin
2092 eta = rhoi/rozn
2093 xmu = eta - 1.
2094 rap = rozn/rhoi
2096 # condensed phase, compute pressure and sound speed
2097 p1 = smallbj/(ui/(ezn*eta*eta) + 1.)
2098 pressc = (smallaj + p1) * ui * rhoi + capan * xmu + capbn * xmu * xmu
2100 p1 = ui/(ezn*eta*eta) + 1.
2101 c2 = p1*p1
2102 c3 = p1 - 1.
2103 c4 = smallbj * ui * (3. * c3 + 1.) / c2
2104 dpdi = smallaj * rhoi + smallbj * rhoi / c2
2105 dpdrho = smallaj * ui + capan / rozn + 2. * capbn * xmu / rozn + c4
2106 cvelc = dpdrho + dpdi * pressc / rhoi2
2108 # expanded phase, compute pressure and sound speed
2109 # for now, keep original Asphaug lower value limits
2110 p1 = ui/ezn/eta**2 + 1.
2111 p2 = smallaj * ui * rhoi
2112 p3 = smallbj * ui * rhoi / p1
2113 p4 = capan * xmu
2114 vow = 1. / eta
2115 p6 = betaj * (vow - 1.)
2116 # changed value limit from 70 to 100 to match iSALE cross check
2117 p6 = min(p6, 100.)
2118 p6 = np.exp(-p6)
2119 p7 = alphaj * (vow - 1.) ** 2
2120 p7 = min(p7, 100.)
2121 p7 = np.exp(-p7)
2122 pressv = p2 + (p3 + p4 * p6) * p7
2124 c1 = smallaj * ui
2125 c2 = p1 ** 2
2126 c3 = p1 - 1.
2127 c4 = smallbj * ui * (3. * c3 + 1.) / c2
2128 c5 = p6 * p7 * capan
2129 c6 = 2. * alphaj * (vow - 1.)
2130 dpdrho = c1 + p7 * c4 + p7 * p3 * rozn * c6 / rhoi2 + c5 * (1. / rozn + xmu * rozn / rhoi2 * (c6 + betaj))
2131 dpdi = smallaj * rhoi + p7 / c2 * smallbj * rhoi
2132 cvelv = dpdrho + dpdi * pressv / rhoi2
2133 if cvelv < 0.:
2134 cvelv = 0.
2136 # pick up the right state
2137 # default is condensed region
2138 flag = 1
2139 pri = pressc
2140 vsoundi = cvelc
2141 if rap >= 1. and ui >= espn:
2142 # expanded region
2143 flag = 3
2144 pri = pressv
2145 vsoundi = cvelv
2146 if rap >= 1. and ui > esn and ui < espn:
2147 # interpolated region
2148 flag = 2
2149 pri = (pressv * (ui - esn) + pressc * (espn - ui)) / difesn
2150 vsoundi = (cvelv * (ui - esn) + cvelc * (espn - ui)) / difesn
2152 # do not limit the sound speed for now; cross checking with iSALE
2153 #cmin = .25 * capan / rozn
2154 #vsoundi = max(cmin, vsoundi)
2156 pout = pri
2157 if vsoundi < 0.:
2158 vsoundi = np.abs(pout/rin)
2159 csout = np.sqrt(vsoundi)
2160 return [pout,flag,csout]
2161#################
2162####################################################################################
2163### END eostable.py FILE ###
2164####################################################################################