Coverage for planit/eos/aneostable.py: 95%

116 statements  

« prev     ^ index     » next       coverage.py v7.17.2, created at 2026-11-11 15:42 +0000

1""" 

2 planit ANEOS/SESAME table wrapper functions 

3""" 

4 

5from ..main import * 

6from .eos_table import * 

7from .eostab_extension import * 

8from .get_eos_data import get_eosdata_path 

9import numpy as npy 

10from pathlib import Path 

11 

12 

13REQUIRED_SESAME_FILES = ( 

14 'NEW-SESAME-STD.TXT', 

15 'NEW-SESAME-STD-NOTENSION.TXT', 

16 'NEW-SESAME-EXT.TXT', 

17) 

18"""Files required for a custom planit SESAME EOS table.""" 

19 

20USER_WOMA_IDS = frozenset(range(900, 905)) 

21"""WoMa IDs reserved by planit for custom EOS tables.""" 

22 

23 

24def _validate_user_sesame_request(eos, eosdir, womaID): 

25 """Validate a custom SESAME request and return its table directory. 

26 

27 The public custom-EOS interface is :func:`planit.eos.select`; this helper 

28 also keeps direct ``loadANEOSEOS(..., user=True)`` calls from failing later 

29 with an obscure file or local-variable error. 

30 """ 

31 if not isinstance(eos, str) or not eos.strip(): 

32 raise ValueError('Custom EOS eosname must be a non-empty string.') 

33 

34 if (isinstance(womaID, bool) or not isinstance(womaID, int) 

35 or womaID not in USER_WOMA_IDS): 

36 raise ValueError( 

37 'Custom EOS womaID must be one of 900, 901, 902, 903, or 904.' 

38 ) 

39 

40 if eosdir is None: 

41 raise ValueError('Custom EOS eosdir must name a directory containing SESAME files.') 

42 if isinstance(eosdir, str) and not eosdir.strip(): 

43 raise ValueError('Custom EOS eosdir must not be empty.') 

44 

45 try: 

46 table_dir = Path(eosdir).expanduser() 

47 except TypeError as exc: 

48 raise ValueError('Custom EOS eosdir must be a path-like value.') from exc 

49 

50 if not table_dir.exists(): 

51 raise FileNotFoundError( 

52 f'Custom EOS directory does not exist: {table_dir}' 

53 ) 

54 if not table_dir.is_dir(): 

55 raise NotADirectoryError( 

56 f'Custom EOS path is not a directory: {table_dir}' 

57 ) 

58 

59 missing_files = [ 

60 filename for filename in REQUIRED_SESAME_FILES 

61 if not (table_dir / filename).is_file() 

62 ] 

63 if missing_files: 

64 raise FileNotFoundError( 

65 f'Custom EOS directory {table_dir} is missing required file(s): ' 

66 + ', '.join(missing_files) 

67 ) 

68 

69 return table_dir 

70 

71 

72def loadANEOSEOS(eos='Iron-ANEOS-SLVTv0.2G1', eostype='ANEOS', debug=False, 

73 eosdir=None, user=False, womaID=None): 

74 """ 

75 Load a bundled ANEOS/SESAME table or a validated custom SESAME table. 

76 

77 Custom tables are normally loaded through ``planit.eos.select``. Direct 

78 callers must use ``user=True``, ``eostype='SESAME'``, a directory that 

79 contains :data:`REQUIRED_SESAME_FILES`, and a ``womaID`` from 900 to 904. 

80 ``womaID`` is optional for bundled EOS models and is ignored for them. 

81 

82 Returns: EOStable 

83 """ 

84 

85 NewEOS = EOStable() # make new empty EOS object 

86 

87 if user: 

88 if eostype != 'SESAME': 

89 raise ValueError("Custom EOS tables require eostype='SESAME'.") 

90 eosdir = _validate_user_sesame_request(eos, eosdir, womaID) 

91 

92 elif eos == 'Iron-ANEOS-SLVTv0.2G1': 

93 eosdir = eospath + 'aneos-iron-2020-master/' 

94 womaID = 401 

95 # MODELNAME = 'Iron-ANEOS-SLVTv0.2G1' 

96 # MATID = 1.0 # MATID number 

97 # DATE = 191105. # Date as a single 6-digit number YYMMDD 

98 # VERSION = 0.2 # ANEOS Parameters Version number 

99 

100 elif eos == 'Fe85Si15-ANEOS-SLVTv0.2G1': 

101 #eosdir = eospath + 'aneos-Fe85Si15-2020-master/' 

102 eosdir = get_eosdata_path("aneos-Fe85Si15-2020-master") 

103 womaID = 402 

104 # MODELNAME = 'Fe85Si15-ANEOS-SLVTv0.2G1' 

105 # MATID = 1.0 # MATID number 

106 # DATE = 191105. # Date as a single 6-digit number YYMMDD 

107 # VERSION = 0.2 # ANEOS Parameters Version number 

108 

109 elif eos == 'Forsterite-ANEOS-SLVTv1.0G1': 

110 eosdir = eospath + 'aneos-forsterite-2019-master/' 

111 womaID = 400 

112 # MODELNAME = 'Forsterite-ANEOS-SLVTv1.0G1' 

113 # MATID = 1.0 # MATID number 

114 # DATE = 190802. # Date as a single 6-digit number YYMMDD 

115 # VERSION = 0.1 # ANEOS Parameters Version number 

116 

117 elif eos == 'Pyrolite_ANEOS_SLVTv0.2': 

118 #eosdir = eospath + 'aneos-pyrolite-2022/' 

119 eosdir = get_eosdata_path("aneos-pyrolite-2022") 

120 womaID = 403 

121 # MODELNAME = 'Pyrolite_ANEOS_SLVTv0.2' 

122 # MATID = 1.0 # MATID number 

123 # DATE = 210627. # Date as a single 6-digit number YYMMDD 

124 # VERSION = 0.1 # ANEOS Parameters Version number 

125 

126 elif eos == 'Water-ANEOS-SLVTv0.3G1': 

127 #eosdir = eospath + 'aneos-pyrolite-2022/' 

128 eosdir = get_eosdata_path("aneos-water") 

129 womaID = 404 

130 # MODELNAME = 'Water-ANEOS-SLVTv0.3G1' 

131 # MATID = 1.0 # MATID number 

132 # DATE = 221017. # Date as a single 6-digit number YYMMDD 

133 # VERSION = 0.3 # ANEOS Parameters Version number 

134 

135 elif eos == '5PhaseEOSv8.3': 

136 #eosdir = eospath + '5-phase-water/' 

137 eosdir = get_eosdata_path("5-phase-water") 

138 womaID = 303 

139 # MODELNAME='5PhaseEOSv8.3' 

140 # The following define the default initial state for material in the 201 table 

141 NewEOS.R0REF = 1.0 # g/cm3 *** R0REF is inserted into the density array 

142 NewEOS.K0REF = 2E10 # dynes/cm2 

143 NewEOS.T0REF = 298. # K -- *** T0REF is inserted into the temperature array 

144 NewEOS.P0REF = 1.E6 

145 

146 else: 

147 raise ValueError('EOS:', eos, 'unknown.') 

148 

149 NewEOS.TYPE = eostype 

150 NewEOS.womaID = womaID 

151 

152 # pathlib joins work with both bundled paths and user paths, so callers do 

153 # not have to supply a trailing path separator for a custom EOS directory. 

154 eosdir = Path(eosdir) 

155 

156 if eostype == 'ANEOS': 

157 # READ EOS HEADER INFORMATION 

158 # READ IN ANEOS INPUT FILE 

159 with open(eosdir / 'ANEOS.INPUT', "r") as aneosinputfile: 

160 an_in = aneosinputfile.readlines() # read in the whole ascii file at once because this is fatser 

161 aneoscount = 1 

162 for i in npy.arange(len(an_in)): 

163 if an_in[i].find('ANEOS') == 0: 

164 if aneoscount < 9: 

165 if debug: 

166 print(' '+an_in[i-3], an_in[i-2], an_in[i-1], an_in[i]) 

167 aneoscount = aneoscount+1 

168 else: 

169 if debug: 

170 print(' '+an_in[i]) 

171 if an_in[i].find('ANEOS2') == 0: 

172 tmp = an_in[i] 

173 R0REF = float(tmp[30:40]) 

174 T0REF = float(tmp[40:50]) 

175 P0REF = float(tmp[50:60]) 

176 K0REF = float(tmp[60:70]) 

177 break 

178 NewEOS.R0REF = R0REF 

179 NewEOS.K0REF = K0REF 

180 NewEOS.T0REF = T0REF 

181 NewEOS.P0REF = P0REF 

182 

183 # READ SESAME HEADER 

184 with open(eosdir / 'NEW-SESAME-STD.TXT', "r") as sesfile: 

185 sesdata = sesfile.readlines(5000) 

186 for i in range(len(sesdata)): 

187 if sesdata[i].find(' INDEX') == 0: 

188 tmp = sesdata[i+1] 

189 MATID = float(tmp.split()[0]) 

190 DATE = float(tmp.split()[1]) 

191 VERSION = float(tmp.split()[3]) 

192 if sesdata[i].find(' RECORD TYPE = 201') == 0: 

193 tmp = sesdata[i+1] 

194 FMN = float(tmp.split()[0]) 

195 FMW = float(tmp.split()[1]) 

196 break 

197 

198 NewEOS.loadextsesame(str(eosdir / 'NEW-SESAME-EXT.TXT')) # LOAD THE EXTENDED 301 SESAME FILE GENERATED BY STSM VERSION OF ANEOS 

199 NewEOS.loadstdsesame(str(eosdir / 'NEW-SESAME-STD-NOTENSION.TXT')) # LOAD THE STANDARD 301 SESAME FILE GENERATED BY STSM VERSION OF ANEOS 

200 NewEOS.MODELNAME = eos # string set above in user input 

201 NewEOS.MDQ = npy.zeros((NewEOS.NT,NewEOS.ND)) # makes the empty MDQ array 

202 

203 # Add the header info to the table. This could be done during the loading.  

204 NewEOS.MATID = MATID 

205 NewEOS.DATE = DATE 

206 NewEOS.VERSION = VERSION 

207 NewEOS.FMN = FMN 

208 NewEOS.FMW = FMW 

209 

210 # Load the information from ANEOS.INPUT and ANEOS.OUTPUT 

211 if eostype == 'ANEOS': 

212 NewEOS.loadaneos(aneosinfname=str(eosdir / 'ANEOS.INPUT'), aneosoutfname=str(eosdir / 'ANEOS.OUTPUT'), silent=True) 

213 # 

214 NewEOS.calchugoniot(r0=NewEOS.R0REF,t0=NewEOS.T0REF) 

215 # 

216 # calculate the 1-bar profile; loop over temp 

217 NewEOS.onebar.T = npy.zeros(NewEOS.NT) 

218 NewEOS.onebar.S = npy.zeros(NewEOS.NT) 

219 NewEOS.onebar.rho = npy.zeros(NewEOS.NT) 

220 #it0 = npy.where(NewEOS.T >= NewEOS.T0REF)[0] 

221 id0 = npy.arange(NewEOS.ND)#npy.where(NewEOS.rho >= 0.8*NewEOS.R0REF)[0] 

222 for iit in range(0,NewEOS.NT): 

223 NewEOS.onebar.T[iit] = NewEOS.T[iit] 

224 NewEOS.onebar.S[iit] = npy.interp(1.E-4, NewEOS.P[iit,id0], NewEOS.S[iit,id0]) 

225 NewEOS.onebar.rho[iit] = npy.interp(1.E-4, NewEOS.P[iit,id0], NewEOS.rho[id0]) 

226 

227 return NewEOS