planit 0.8.2__tar.gz → 1.0.2__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (39) hide show
  1. {planit-0.8.2 → planit-1.0.2}/PKG-INFO +52 -6
  2. {planit-0.8.2 → planit-1.0.2}/README.md +50 -5
  3. {planit-0.8.2 → planit-1.0.2}/planit/__init__.py +2 -1
  4. planit-1.0.2/planit/eos/aneostable.py +216 -0
  5. {planit-0.8.2 → planit-1.0.2}/planit/eos/aquatable.py +2 -4
  6. planit-0.8.2/planit/eos/eosfuncs (1).py → planit-1.0.2/planit/eos/eosfuncs.py +99 -49
  7. planit-1.0.2/planit/eos/eostab_extension.py +329 -0
  8. planit-1.0.2/planit/eos/rhoUtable.py +30 -0
  9. {planit-0.8.2 → planit-1.0.2}/planit/eos/tabinterp.py +16 -12
  10. planit-1.0.2/planit/globaldefs.py +11 -0
  11. {planit-0.8.2 → planit-1.0.2}/planit/impacttools.py +90 -64
  12. {planit-0.8.2 → planit-1.0.2}/planit/main.py +4 -8
  13. planit-0.8.2/planit/makeplanet (1).py → planit-1.0.2/planit/makeplanet.py +204 -49
  14. planit-0.8.2/planit/snaptools (1).py → planit-1.0.2/planit/snaptools.py +56 -40
  15. planit-1.0.2/planit/utils.py +138 -0
  16. {planit-0.8.2 → planit-1.0.2}/planit.egg-info/PKG-INFO +52 -6
  17. {planit-0.8.2 → planit-1.0.2}/planit.egg-info/SOURCES.txt +2 -4
  18. {planit-0.8.2 → planit-1.0.2}/planit.egg-info/requires.txt +1 -0
  19. {planit-0.8.2 → planit-1.0.2}/pyproject.toml +3 -3
  20. planit-1.0.2/tests/test_eos.py +168 -0
  21. planit-1.0.2/tests/test_make.py +24 -0
  22. planit-1.0.2/tests/test_snap.py +14 -0
  23. {planit-0.8.2 → planit-1.0.2}/tests/test_utils.py +11 -6
  24. planit-0.8.2/planit/eos/aneostable.py +0 -154
  25. planit-0.8.2/planit/eos/eosfuncs.py +0 -277
  26. planit-0.8.2/planit/eos/eostab_extension.py +0 -60
  27. planit-0.8.2/planit/eos/rhoUtable.py +0 -45
  28. planit-0.8.2/planit/impacttools (1).py +0 -546
  29. planit-0.8.2/planit/makeplanet.py +0 -1010
  30. planit-0.8.2/planit/snaptools.py +0 -917
  31. planit-0.8.2/planit/utils.py +0 -125
  32. planit-0.8.2/tests/test_eos.py +0 -30
  33. planit-0.8.2/tests/test_snap.py +0 -7
  34. {planit-0.8.2 → planit-1.0.2}/LICENSE +0 -0
  35. {planit-0.8.2 → planit-1.0.2}/planit/eos/__init__.py +0 -0
  36. {planit-0.8.2 → planit-1.0.2}/planit/eos/eos_table.py +0 -0
  37. {planit-0.8.2 → planit-1.0.2}/planit.egg-info/dependency_links.txt +0 -0
  38. {planit-0.8.2 → planit-1.0.2}/planit.egg-info/top_level.txt +0 -0
  39. {planit-0.8.2 → planit-1.0.2}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: planit
3
- Version: 0.8.2
3
+ Version: 1.0.2
4
4
  Summary: The PLANetary Impact Toolkit provides tools for accessing, manipulating, and analysing smoothed particle hydrodynamcis (SPH) impact simulation data, and creating planets for SPH impact simulations.
5
5
  Author-email: Philip Carter <p.carter@bristol.ac.uk>
6
6
  License-Expression: GPL-3.0-or-later
@@ -13,6 +13,7 @@ Requires-Dist: matplotlib
13
13
  Requires-Dist: numba
14
14
  Requires-Dist: h5py
15
15
  Requires-Dist: seagen
16
+ Requires-Dist: cmasher
16
17
  Dynamic: license-file
17
18
 
18
19
  # planit
@@ -39,8 +40,11 @@ an impact simulation.\
39
40
  `eos` provides classes and functions for accessing and using equations of state.\
40
41
  `utils` provides additional utility functions for analysis.
41
42
 
43
+ > [!NOTE]
44
+ > Currently only two-layer planets with a forsterite mantle are *fully* supported.
45
+
42
46
  ## Installation
43
- <!-- **planit** is available in PyPI and can be installed with `pip install planit`.-->
47
+ **planit** is available in PyPI and can be installed with `pip install planit`.
44
48
 
45
49
  ## Equations of State (EoS)
46
50
 
@@ -54,7 +58,52 @@ an impact simulation.\
54
58
 
55
59
  They can be accessed using the names given above (as well as some variations) or using the
56
60
  corresponding SWIFT/WoMa ID number.\
57
- User supplied tables in standard SESAME format can also be used.
61
+ User supplied SESAME tables can also be loaded into one of five custom slots.
62
+
63
+ ### Custom SESAME EoS tables
64
+
65
+ **planit** supports custom tables in the same SESAME-style layout used by its bundled ANEOS
66
+ and 5-phase-water tables. A table directory must contain all of these files:
67
+
68
+ - `NEW-SESAME-STD.TXT`
69
+ - `NEW-SESAME-STD-NOTENSION.TXT`
70
+ - `NEW-SESAME-EXT.TXT`
71
+
72
+ Use `User0` through `User4` to choose the corresponding reserved SWIFT/WoMa ID:
73
+ `User0` = 900, `User1` = 901, `User2` = 902, `User3` = 903, and `User4` = 904.
74
+ The IDs can also be passed to `select()` in place of the slot names.
75
+
76
+ ```python
77
+ from planit import eos
78
+
79
+ table = eos.select(
80
+ "User0",
81
+ eosname="MyMaterial",
82
+ eosdir="/path/to/my-sesame-table", # trailing slash is optional
83
+ )
84
+
85
+ print(table.MODELNAME) # MyMaterial
86
+ print(table.womaID) # 900
87
+
88
+ # Use the loaded table in the usual way.
89
+ eos_passer = table.make_passer_class()
90
+ internal_energy = eos.tabinterp.from_rhoT("U", 1.0, 300.0, eos_passer)
91
+ ```
92
+
93
+ The first load for a slot requires both `eosname` and `eosdir`. Subsequent
94
+ `eos.select("User0")` calls return that slot's cached table. Passing both arguments
95
+ again deliberately replaces the slot, but only after the new table has loaded
96
+ successfully; a failed replacement raises an error and leaves the previous cached table
97
+ available. Passing just one argument, or reading a slot that was never loaded, raises a
98
+ clear `ValueError` instead of returning an uninitialised table.
99
+
100
+ The loader validates the directory and file names, but it does not validate the physical
101
+ quality or full internal consistency of a table. `NEW-SESAME-EXT.TXT` is required, so a
102
+ minimal standard SESAME 201/301 file alone is not sufficient. Custom tables are cached
103
+ only in the current Python process, and there are only five simultaneous custom slots.
104
+
105
+ >[!WARNING]
106
+ > HM80 EoS support is not fully tested yet!
58
107
 
59
108
  > [!NOTE]
60
109
  > `ANEOSPyrolite` has been assigned the SWIFT/WoMa ID 403 in planit but does not currently have an
@@ -70,6 +119,3 @@ requested mass and component mass fractions are matched (within tolerance). The
70
119
  behaviour prevents the unphyiscal scenario of a core cooler than the mantle at the
71
120
  core-mantle boundary.
72
121
 
73
- > [!NOTE]
74
- > `makeplanet` currently only supports 2-layer planets
75
-
@@ -22,8 +22,11 @@ an impact simulation.\
22
22
  `eos` provides classes and functions for accessing and using equations of state.\
23
23
  `utils` provides additional utility functions for analysis.
24
24
 
25
+ > [!NOTE]
26
+ > Currently only two-layer planets with a forsterite mantle are *fully* supported.
27
+
25
28
  ## Installation
26
- <!-- **planit** is available in PyPI and can be installed with `pip install planit`.-->
29
+ **planit** is available in PyPI and can be installed with `pip install planit`.
27
30
 
28
31
  ## Equations of State (EoS)
29
32
 
@@ -37,7 +40,52 @@ an impact simulation.\
37
40
 
38
41
  They can be accessed using the names given above (as well as some variations) or using the
39
42
  corresponding SWIFT/WoMa ID number.\
40
- User supplied tables in standard SESAME format can also be used.
43
+ User supplied SESAME tables can also be loaded into one of five custom slots.
44
+
45
+ ### Custom SESAME EoS tables
46
+
47
+ **planit** supports custom tables in the same SESAME-style layout used by its bundled ANEOS
48
+ and 5-phase-water tables. A table directory must contain all of these files:
49
+
50
+ - `NEW-SESAME-STD.TXT`
51
+ - `NEW-SESAME-STD-NOTENSION.TXT`
52
+ - `NEW-SESAME-EXT.TXT`
53
+
54
+ Use `User0` through `User4` to choose the corresponding reserved SWIFT/WoMa ID:
55
+ `User0` = 900, `User1` = 901, `User2` = 902, `User3` = 903, and `User4` = 904.
56
+ The IDs can also be passed to `select()` in place of the slot names.
57
+
58
+ ```python
59
+ from planit import eos
60
+
61
+ table = eos.select(
62
+ "User0",
63
+ eosname="MyMaterial",
64
+ eosdir="/path/to/my-sesame-table", # trailing slash is optional
65
+ )
66
+
67
+ print(table.MODELNAME) # MyMaterial
68
+ print(table.womaID) # 900
69
+
70
+ # Use the loaded table in the usual way.
71
+ eos_passer = table.make_passer_class()
72
+ internal_energy = eos.tabinterp.from_rhoT("U", 1.0, 300.0, eos_passer)
73
+ ```
74
+
75
+ The first load for a slot requires both `eosname` and `eosdir`. Subsequent
76
+ `eos.select("User0")` calls return that slot's cached table. Passing both arguments
77
+ again deliberately replaces the slot, but only after the new table has loaded
78
+ successfully; a failed replacement raises an error and leaves the previous cached table
79
+ available. Passing just one argument, or reading a slot that was never loaded, raises a
80
+ clear `ValueError` instead of returning an uninitialised table.
81
+
82
+ The loader validates the directory and file names, but it does not validate the physical
83
+ quality or full internal consistency of a table. `NEW-SESAME-EXT.TXT` is required, so a
84
+ minimal standard SESAME 201/301 file alone is not sufficient. Custom tables are cached
85
+ only in the current Python process, and there are only five simultaneous custom slots.
86
+
87
+ >[!WARNING]
88
+ > HM80 EoS support is not fully tested yet!
41
89
 
42
90
  > [!NOTE]
43
91
  > `ANEOSPyrolite` has been assigned the SWIFT/WoMa ID 403 in planit but does not currently have an
@@ -53,6 +101,3 @@ requested mass and component mass fractions are matched (within tolerance). The
53
101
  behaviour prevents the unphyiscal scenario of a core cooler than the mantle at the
54
102
  core-mantle boundary.
55
103
 
56
- > [!NOTE]
57
- > `makeplanet` currently only supports 2-layer planets
58
-
@@ -1,7 +1,8 @@
1
+ from .globaldefs import *
1
2
  from .main import *
3
+ from . import utils
2
4
  from . import eos
3
5
  from .impacttools import Impact, multiplotseq
4
6
  from .makeplanet import planet_profile
5
7
  from .eos import loadEOS, isentrope_class
6
8
  from .snaptools import SnapHeader, Snapshot
7
-
@@ -0,0 +1,216 @@
1
+ """
2
+ planit ANEOS/SESAME table wrapper functions
3
+ """
4
+
5
+ from ..main import *
6
+ from .eos_table import *
7
+ from .eostab_extension import *
8
+ import numpy as npy
9
+ from pathlib import Path
10
+
11
+
12
+ REQUIRED_SESAME_FILES = (
13
+ 'NEW-SESAME-STD.TXT',
14
+ 'NEW-SESAME-STD-NOTENSION.TXT',
15
+ 'NEW-SESAME-EXT.TXT',
16
+ )
17
+ """Files required for a custom planit SESAME EOS table."""
18
+
19
+ USER_WOMA_IDS = frozenset(range(900, 905))
20
+ """WoMa IDs reserved by planit for custom EOS tables."""
21
+
22
+
23
+ def _validate_user_sesame_request(eos, eosdir, womaID):
24
+ """Validate a custom SESAME request and return its table directory.
25
+
26
+ The public custom-EOS interface is :func:`planit.eos.select`; this helper
27
+ also keeps direct ``loadANEOSEOS(..., user=True)`` calls from failing later
28
+ with an obscure file or local-variable error.
29
+ """
30
+ if not isinstance(eos, str) or not eos.strip():
31
+ raise ValueError('Custom EOS eosname must be a non-empty string.')
32
+
33
+ if (isinstance(womaID, bool) or not isinstance(womaID, int)
34
+ or womaID not in USER_WOMA_IDS):
35
+ raise ValueError(
36
+ 'Custom EOS womaID must be one of 900, 901, 902, 903, or 904.'
37
+ )
38
+
39
+ if eosdir is None:
40
+ raise ValueError('Custom EOS eosdir must name a directory containing SESAME files.')
41
+ if isinstance(eosdir, str) and not eosdir.strip():
42
+ raise ValueError('Custom EOS eosdir must not be empty.')
43
+
44
+ try:
45
+ table_dir = Path(eosdir).expanduser()
46
+ except TypeError as exc:
47
+ raise ValueError('Custom EOS eosdir must be a path-like value.') from exc
48
+
49
+ if not table_dir.exists():
50
+ raise FileNotFoundError(
51
+ f'Custom EOS directory does not exist: {table_dir}'
52
+ )
53
+ if not table_dir.is_dir():
54
+ raise NotADirectoryError(
55
+ f'Custom EOS path is not a directory: {table_dir}'
56
+ )
57
+
58
+ missing_files = [
59
+ filename for filename in REQUIRED_SESAME_FILES
60
+ if not (table_dir / filename).is_file()
61
+ ]
62
+ if missing_files:
63
+ raise FileNotFoundError(
64
+ f'Custom EOS directory {table_dir} is missing required file(s): '
65
+ + ', '.join(missing_files)
66
+ )
67
+
68
+ return table_dir
69
+
70
+
71
+ def loadANEOSEOS(eos='Iron-ANEOS-SLVTv0.2G1', eostype='ANEOS', debug=False,
72
+ eosdir=None, user=False, womaID=None):
73
+ """
74
+ Load a bundled ANEOS/SESAME table or a validated custom SESAME table.
75
+
76
+ Custom tables are normally loaded through ``planit.eos.select``. Direct
77
+ callers must use ``user=True``, ``eostype='SESAME'``, a directory that
78
+ contains :data:`REQUIRED_SESAME_FILES`, and a ``womaID`` from 900 to 904.
79
+ ``womaID`` is optional for bundled EOS models and is ignored for them.
80
+
81
+ Returns: EOStable
82
+ """
83
+
84
+ NewEOS = EOStable() # make new empty EOS object
85
+
86
+ if user:
87
+ if eostype != 'SESAME':
88
+ raise ValueError("Custom EOS tables require eostype='SESAME'.")
89
+ eosdir = _validate_user_sesame_request(eos, eosdir, womaID)
90
+
91
+ elif eos == 'Iron-ANEOS-SLVTv0.2G1':
92
+ eosdir = eospath + 'aneos-iron-2020-master/'
93
+ womaID = 401
94
+ # MODELNAME = 'Iron-ANEOS-SLVTv0.2G1'
95
+ # MATID = 1.0 # MATID number
96
+ # DATE = 191105. # Date as a single 6-digit number YYMMDD
97
+ # VERSION = 0.2 # ANEOS Parameters Version number
98
+
99
+ elif eos == 'Fe85Si15-ANEOS-SLVTv0.2G1':
100
+ eosdir = eospath + 'aneos-Fe85Si15-2020-master/'
101
+ womaID = 402
102
+ # MODELNAME = 'Fe85Si15-ANEOS-SLVTv0.2G1'
103
+ # MATID = 1.0 # MATID number
104
+ # DATE = 191105. # Date as a single 6-digit number YYMMDD
105
+ # VERSION = 0.2 # ANEOS Parameters Version number
106
+
107
+ elif eos == 'Forsterite-ANEOS-SLVTv1.0G1':
108
+ eosdir = eospath + 'aneos-forsterite-2019-master/'
109
+ womaID = 400
110
+ # MODELNAME = 'Forsterite-ANEOS-SLVTv1.0G1'
111
+ # MATID = 1.0 # MATID number
112
+ # DATE = 190802. # Date as a single 6-digit number YYMMDD
113
+ # VERSION = 0.1 # ANEOS Parameters Version number
114
+
115
+ elif eos == 'Pyrolite_ANEOS_SLVTv0.2':
116
+ eosdir = eospath + 'aneos-pyrolite-2022/'
117
+ womaID = 403
118
+ # MODELNAME = 'Pyrolite_ANEOS_SLVTv0.2'
119
+ # MATID = 1.0 # MATID number
120
+ # DATE = 210627. # Date as a single 6-digit number YYMMDD
121
+ # VERSION = 0.1 # ANEOS Parameters Version number
122
+
123
+ elif eos == '5PhaseEOSv8.3':
124
+ eosdir = eospath + '5-phase-water/'
125
+ womaID = 303
126
+ # MODELNAME='5PhaseEOSv8.3'
127
+ # The following define the default initial state for material in the 201 table
128
+ NewEOS.R0REF = 1.0 # g/cm3 *** R0REF is inserted into the density array
129
+ NewEOS.K0REF = 2E10 # dynes/cm2
130
+ NewEOS.T0REF = 298. # K -- *** T0REF is inserted into the temperature array
131
+ NewEOS.P0REF = 1.E6
132
+
133
+ else:
134
+ raise ValueError('EOS:', eos, 'unknown.')
135
+
136
+ NewEOS.TYPE = eostype
137
+ NewEOS.womaID = womaID
138
+
139
+ # pathlib joins work with both bundled paths and user paths, so callers do
140
+ # not have to supply a trailing path separator for a custom EOS directory.
141
+ eosdir = Path(eosdir)
142
+
143
+ if eostype == 'ANEOS':
144
+ # READ EOS HEADER INFORMATION
145
+ # READ IN ANEOS INPUT FILE
146
+ aneosinputfile = open(eosdir / 'ANEOS.INPUT', "r")
147
+ an_in = aneosinputfile.readlines() # read in the whole ascii file at once because this is fatser
148
+ aneosinputfile.close()
149
+ aneoscount = 1
150
+ for i in npy.arange(len(an_in)):
151
+ if an_in[i].find('ANEOS') == 0:
152
+ if aneoscount < 9:
153
+ if debug:
154
+ print(' '+an_in[i-3], an_in[i-2], an_in[i-1], an_in[i])
155
+ aneoscount = aneoscount+1
156
+ else:
157
+ if debug:
158
+ print(' '+an_in[i])
159
+ if an_in[i].find('ANEOS2') == 0:
160
+ tmp = an_in[i]
161
+ R0REF = float(tmp[30:40])
162
+ T0REF = float(tmp[40:50])
163
+ P0REF = float(tmp[50:60])
164
+ K0REF = float(tmp[60:70])
165
+ break
166
+ NewEOS.R0REF = R0REF
167
+ NewEOS.K0REF = K0REF
168
+ NewEOS.T0REF = T0REF
169
+ NewEOS.P0REF = P0REF
170
+
171
+ # READ SESAME HEADER
172
+ sesfile = open(eosdir / 'NEW-SESAME-STD.TXT', "r")
173
+ sesdata = sesfile.readlines(5000)
174
+ sesfile.close()
175
+ for i in range(len(sesdata)):
176
+ if sesdata[i].find(' INDEX') == 0:
177
+ tmp = sesdata[i+1]
178
+ MATID = float(tmp.split()[0])
179
+ DATE = float(tmp.split()[1])
180
+ VERSION = float(tmp.split()[3])
181
+ if sesdata[i].find(' RECORD TYPE = 201') == 0:
182
+ tmp = sesdata[i+1]
183
+ FMN = float(tmp.split()[0])
184
+ FMW = float(tmp.split()[1])
185
+ break
186
+
187
+ NewEOS.loadextsesame(str(eosdir / 'NEW-SESAME-EXT.TXT')) # LOAD THE EXTENDED 301 SESAME FILE GENERATED BY STSM VERSION OF ANEOS
188
+ NewEOS.loadstdsesame(str(eosdir / 'NEW-SESAME-STD-NOTENSION.TXT')) # LOAD THE STANDARD 301 SESAME FILE GENERATED BY STSM VERSION OF ANEOS
189
+ NewEOS.MODELNAME = eos # string set above in user input
190
+ NewEOS.MDQ = npy.zeros((NewEOS.NT,NewEOS.ND)) # makes the empty MDQ array
191
+
192
+ # Add the header info to the table. This could be done during the loading.
193
+ NewEOS.MATID = MATID
194
+ NewEOS.DATE = DATE
195
+ NewEOS.VERSION = VERSION
196
+ NewEOS.FMN = FMN
197
+ NewEOS.FMW = FMW
198
+
199
+ # Load the information from ANEOS.INPUT and ANEOS.OUTPUT
200
+ if eostype == 'ANEOS':
201
+ NewEOS.loadaneos(aneosinfname=str(eosdir / 'ANEOS.INPUT'), aneosoutfname=str(eosdir / 'ANEOS.OUTPUT'), silent=True)
202
+ #
203
+ NewEOS.calchugoniot(r0=NewEOS.R0REF,t0=NewEOS.T0REF)
204
+ #
205
+ # calculate the 1-bar profile; loop over temp
206
+ NewEOS.onebar.T = npy.zeros(NewEOS.NT)
207
+ NewEOS.onebar.S = npy.zeros(NewEOS.NT)
208
+ NewEOS.onebar.rho = npy.zeros(NewEOS.NT)
209
+ #it0 = npy.where(NewEOS.T >= NewEOS.T0REF)[0]
210
+ id0 = npy.arange(NewEOS.ND)#npy.where(NewEOS.rho >= 0.8*NewEOS.R0REF)[0]
211
+ for iit in range(0,NewEOS.NT):
212
+ NewEOS.onebar.T[iit] = NewEOS.T[iit]
213
+ NewEOS.onebar.S[iit] = npy.interp(1.E-4, NewEOS.P[iit,id0], NewEOS.S[iit,id0])
214
+ NewEOS.onebar.rho[iit] = npy.interp(1.E-4, NewEOS.P[iit,id0], NewEOS.rho[id0])
215
+
216
+ return NewEOS
@@ -18,19 +18,17 @@ def loadAQUAEOS(eos='Water-AQUA-v1.0', eostype='AQUA', debug = False):
18
18
  if eos == 'Water-AQUA-v1.0':
19
19
  eosdir = eospath + 'aqua-water/'
20
20
 
21
-
22
21
  NewEOS = EOStable() # FIRST make new empty EOS object
23
22
  NewEOS.TYPE = eostype
24
23
  NewEOS.VERSION = 1.0
25
24
 
26
25
  NewEOS.loadaquatable(eosdir+'aqua_eos_rhot_v1_0.dat')
27
26
 
28
- NewEOS.MODELNAME = eos # string set above in user input
29
- NewEOS.MDQ = npy.zeros((NewEOS.NT,NewEOS.ND)) # makes the empty MDQ array
27
+ NewEOS.MODELNAME = eos
28
+ # NewEOS.MDQ = npy.zeros((NewEOS.NT,NewEOS.ND)) # makes the empty MDQ array
30
29
 
31
30
 
32
31
  # NewEOS.calchugoniot(r0=NewEOS.R0REF,t0=NewEOS.T0REF)
33
- #
34
32
  # calculate the 1-bar profile; loop over temp
35
33
  # NewEOS.onebar.T = npy.zeros(NewEOS.NT)
36
34
  # NewEOS.onebar.S = npy.zeros(NewEOS.NT)
@@ -15,6 +15,7 @@ import numpy as npy
15
15
  import numba
16
16
  from scipy import interpolate
17
17
 
18
+
18
19
  def loadEOS(eos='Iron-ANEOS-SLVTv0.2G1', eostype='ANEOS'):
19
20
  """
20
21
  Wrapper function for loading EoS
@@ -35,11 +36,11 @@ def loadEOS(eos='Iron-ANEOS-SLVTv0.2G1', eostype='ANEOS'):
35
36
  ANEOSIron = None
36
37
  ANEOSFeSiAlloy = None
37
38
  ANEOSForsterite = None
38
- ANEOSPyrolite = None
39
+ ANEOSPyrolite = None
39
40
 
40
- FivePhaseWater = None
41
+ FivePhaseWater = None
41
42
  AQUAWater = None
42
- HM80HHe = None
43
+ HM80HHe = None
43
44
 
44
45
  UserEOS0 = None
45
46
  UserEOS1 = None
@@ -47,27 +48,103 @@ UserEOS2 = None
47
48
  UserEOS3 = None
48
49
  UserEOS4 = None
49
50
 
51
+
50
52
  # Name lists for EoS
51
- ironnames = ['iron','ANEOSIron','Fe','Iron',401]
52
- alloynames = ['alloy','ANEOSFeSiAlloy','FeSi','Alloy','IronAlloy','ironalloy',402]
53
- forsteritenames = ['forsterite','ANEOSForsterite','Forsterite','Fo',400]
54
- pyrolitenames = ['pyrolite','Pyrolite','ANEOSPyrolite',403]
55
- aquawaternames = ['AQUA','AQUAWater','aqua',304]
56
- fivephasewaternames = ['5PhaseWater','5phasewater','SS08','SenftStewartWater','SenftStewart08',303]
57
- hm80HHenames = ['HM80_HHe','HM80HHe',200]
58
-
59
- user0names = ['User0',900]
60
- user1names = ['User1',901]
61
- user2names = ['User2',902]
62
- user3names = ['User3',903]
53
+ ironnames = ['Iron-ANEOS-SLVTv0.2G1', 'iron', 'ANEOSIron', 'Fe', 'Iron', 401]
54
+ alloynames = ['Fe85Si15-ANEOS-SLVTv0.2G1', 'alloy', 'ANEOSFeSiAlloy', 'FeSi', 'Alloy', 'IronAlloy', 'ironalloy', 402]
55
+ forsteritenames = ['Forsterite-ANEOS-SLVTv1.0G1', 'forsterite', 'ANEOSForsterite', 'Forsterite', 'Fo', 400]
56
+ pyrolitenames = ['Pyrolite_ANEOS_SLVTv0.2', 'pyrolite', 'Pyrolite', 'ANEOSPyrolite', 403]
57
+ aquawaternames = ['Water-AQUA-v1.0', 'AQUA', 'AQUAWater', 'aqua', 304]
58
+ fivephasewaternames = ['5PhaseEOSv8.3', '5PhaseWater', '5phasewater', 'SS08', 'SenftStewartWater', 'SenftStewart08', 303]
59
+ hm80HHenames = ['HM80-HHe-v2.0', 'HM80_HHe', 'HM80HHe', 200]
60
+
61
+ user0names = ['User0', 900]
62
+ user1names = ['User1', 901]
63
+ user2names = ['User2', 902]
64
+ user3names = ['User3', 903]
63
65
  user4names = ['User4',904]
64
66
 
67
+ USER_EOS_SLOTS = {
68
+ 'User0': 900,
69
+ 'User1': 901,
70
+ 'User2': 902,
71
+ 'User3': 903,
72
+ 'User4': 904,
73
+ }
74
+ """Custom EOS slot names and their reserved SWIFT/WoMa material IDs."""
75
+
76
+ _USER_EOS_CACHE_NAMES = {
77
+ slot: f'UserEOS{index}'
78
+ for index, slot in enumerate(USER_EOS_SLOTS)
79
+ }
80
+
81
+
82
+ def _user_slot_name(name):
83
+ """Return the canonical user-slot name for a name or WoMa ID."""
84
+ for slot, womaID in USER_EOS_SLOTS.items():
85
+ if name == slot or name == womaID:
86
+ return slot
87
+ return None
88
+
89
+
90
+ def _select_user_eos(slot, eosname=None, eosdir=None):
91
+ """Load or return a custom EOS slot without hiding invalid requests."""
92
+ cache_name = _USER_EOS_CACHE_NAMES[slot]
93
+ cached_eos = globals()[cache_name]
94
+ has_eosname = eosname is not None
95
+ has_eosdir = eosdir is not None
96
+
97
+ if has_eosname != has_eosdir:
98
+ raise ValueError(
99
+ f'Custom EOS {slot} requires both eosname and eosdir; '
100
+ 'provide neither only to retrieve an already loaded table.'
101
+ )
102
+
103
+ if not has_eosname:
104
+ if cached_eos is None:
105
+ raise ValueError(
106
+ f'Custom EOS {slot} is not loaded. Provide both eosname and eosdir.'
107
+ )
108
+ return cached_eos
109
+
110
+ # Assign only after the loader succeeds, so a malformed replacement cannot
111
+ # leave a slot uninitialised or make select() silently return stale data.
112
+ new_eos = loadANEOSEOS(
113
+ eos=eosname,
114
+ eostype='SESAME',
115
+ eosdir=eosdir,
116
+ user=True,
117
+ womaID=USER_EOS_SLOTS[slot],
118
+ )
119
+ globals()[cache_name] = new_eos
120
+ return new_eos
121
+
65
122
 
66
123
  def select(name, eosname=None, eosdir=None):
124
+ """Return an EOS table, loading it if necessary.
125
+
126
+ Bundled EOS tables can be selected by their established names or material
127
+ IDs. Custom SESAME tables use one of the five ``User0``--``User4`` slots
128
+ (or their IDs 900--904) and must be loaded with both ``eosname`` and
129
+ ``eosdir``::
130
+
131
+ table = select('User0', eosname='MyMaterial', eosdir='/path/to/table')
132
+
133
+ ``eosdir`` may be a string or path-like object and does not need a trailing
134
+ slash. Repeating this call with both arguments replaces that slot after a
135
+ successful load. Calling ``select('User0')`` later returns the cached
136
+ table; calling it before a successful load, or supplying only one of the
137
+ two arguments, raises ``ValueError``.
67
138
  """
68
- Return EoS table object specified by name,
69
- loading it first if not already loaded
70
- """
139
+ user_slot = _user_slot_name(name)
140
+ if user_slot is not None:
141
+ return _select_user_eos(user_slot, eosname=eosname, eosdir=eosdir)
142
+ if isinstance(name, str) and name.startswith('User'):
143
+ raise ValueError(
144
+ f'Unknown user EOS slot {name!r}. Supported slots are User0 through User4 '
145
+ '(WoMa IDs 900 through 904).'
146
+ )
147
+
71
148
  if name in ironnames:
72
149
  global ANEOSIron
73
150
  if not ANEOSIron:
@@ -76,7 +153,7 @@ def select(name, eosname=None, eosdir=None):
76
153
  elif name in alloynames:
77
154
  global ANEOSFeSiAlloy
78
155
  if not ANEOSFeSiAlloy:
79
- ANEOSFeSiAlloy = loadEOS(eos='Fe85Si15-ANEOS-SLVTv0.2G1', eostype='ANEOS')
156
+ ANEOSFeSiAlloy = loadEOS(eos='Fe85Si15-ANEOS-SLVTv0.2G1', eostype='ANEOS')
80
157
  return ANEOSFeSiAlloy
81
158
  elif name in forsteritenames:
82
159
  global ANEOSForsterite
@@ -103,34 +180,8 @@ def select(name, eosname=None, eosdir=None):
103
180
  if not HM80HHe:
104
181
  HM80HHe = loadEOS(eos='HM80-HHe-v2.0', eostype='HM80')
105
182
  return HM80HHe
106
- elif name in user0names:
107
- global UserEOS0
108
- if (not UserEOS0) or (eosdir and eosname):
109
- UserEOS0 = loadANEOSEOS(eos=eosname, eostype='SESAME', eosdir=eosdir, user=True)
110
- return UserEOS0
111
- elif name in user1names:
112
- global UserEOS1
113
- if (not UserEOS1) or (eosdir and eosname):
114
- UserEOS1 = loadANEOSEOS(eos=eosname, eostype='SESAME', eosdir=eosdir, user=True)
115
- return UserEOS1
116
- elif name in user2names:
117
- global UserEOS2
118
- if (not UserEOS2) or (eosdir and eosname):
119
- UserEOS2 = loadANEOSEOS(eos=eosname, eostype='SESAME', eosdir=eosdir, user=True)
120
- return UserEOS2
121
- elif name in user3names:
122
- global UserEOS3
123
- if (not UserEOS3) or (eosdir and eosname):
124
- UserEOS3 = loadANEOSEOS(eos=eosname, eostype='SESAME', eosdir=eosdir, user=True)
125
- return UserEOS3
126
- elif name in user4names:
127
- global UserEOS4
128
- if (not UserEOS4) or (eosdir and eosname):
129
- UserEOS4 = loadANEOSEOS(eos=eosname, eostype='SESAME', eosdir=eosdir, user=True)
130
- return UserEOS4
131
183
  else:
132
- raise ValueError('Unknown EOS:',name)
133
- #return None
184
+ raise ValueError('Unknown EOS:', name)
134
185
 
135
186
 
136
187
  class isentrope_class(eos_isentrope_class):
@@ -264,9 +315,10 @@ def calcprop(Qlab,Xlab,Ylab,X,Y,mats):
264
315
  Q = _calc_prop(Qlab,Xlab,Ylab,X,Y,EOSlist.tolist())
265
316
  return Q*uconversion_Q
266
317
 
318
+
267
319
  @numba.njit(parallel=True)
268
320
  def _calc_prop(Qlab,Xlab,Ylab,X,Y,EOSlist):
269
- print(Qlab,Xlab,Ylab)
321
+ #print(Qlab,Xlab,Ylab)
270
322
  Q = npy.zeros(len(X))
271
323
  for i in numba.prange(len(X)):
272
324
 
@@ -284,6 +336,4 @@ def _calc_prop(Qlab,Xlab,Ylab,X,Y,EOSlist):
284
336
  Q[i] = npy.nan
285
337
  else:
286
338
  Q[i] = tabinterp.from_rhoU1D(Qlab, X[i], Y[i], EOSlist[i])
287
- else:
288
- raise NotImplementedError('Non-ANEOS EOS not currently supported.')
289
339
  return Q