planit 1.0.0__tar.gz → 1.2.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 (42) hide show
  1. {planit-1.0.0 → planit-1.2.2}/PKG-INFO +50 -4
  2. {planit-1.0.0 → planit-1.2.2}/README.md +47 -3
  3. {planit-1.0.0 → planit-1.2.2}/planit/__init__.py +2 -0
  4. {planit-1.0.0 → planit-1.2.2}/planit/eos/aneostable.py +84 -10
  5. {planit-1.0.0 → planit-1.2.2}/planit/eos/aquatable.py +3 -1
  6. {planit-1.0.0 → planit-1.2.2}/planit/eos/eosfuncs.py +102 -33
  7. {planit-1.0.0 → planit-1.2.2}/planit/eos/eostab_extension.py +4 -2
  8. {planit-1.0.0 → planit-1.2.2}/planit/eos/rhoUtable.py +1 -0
  9. planit-1.2.2/planit/globaldefs.py +11 -0
  10. planit-1.2.2/planit/impacttools.py +459 -0
  11. {planit-1.0.0 → planit-1.2.2}/planit/main.py +7 -10
  12. {planit-1.0.0 → planit-1.2.2}/planit/makeplanet.py +15 -10
  13. planit-1.2.2/planit/plotting.py +298 -0
  14. planit-1.2.2/planit/snaptools/__init__.py +2 -0
  15. planit-1.2.2/planit/snaptools/io.py +786 -0
  16. planit-1.2.2/planit/snaptools/snaptools.py +555 -0
  17. {planit-1.0.0 → planit-1.2.2}/planit/utils.py +29 -8
  18. {planit-1.0.0 → planit-1.2.2}/planit.egg-info/PKG-INFO +50 -4
  19. {planit-1.0.0 → planit-1.2.2}/planit.egg-info/SOURCES.txt +8 -1
  20. {planit-1.0.0 → planit-1.2.2}/planit.egg-info/requires.txt +1 -0
  21. planit-1.2.2/pyproject.toml +37 -0
  22. planit-1.2.2/tests/test_eos.py +195 -0
  23. planit-1.2.2/tests/test_imp.py +38 -0
  24. planit-1.2.2/tests/test_io.py +102 -0
  25. planit-1.2.2/tests/test_make.py +74 -0
  26. planit-1.2.2/tests/test_plot.py +72 -0
  27. planit-1.2.2/tests/test_snap.py +122 -0
  28. planit-1.2.2/tests/test_utils.py +65 -0
  29. planit-1.0.0/planit/impacttools.py +0 -566
  30. planit-1.0.0/planit/snaptools.py +0 -929
  31. planit-1.0.0/pyproject.toml +0 -13
  32. planit-1.0.0/tests/test_eos.py +0 -43
  33. planit-1.0.0/tests/test_make.py +0 -24
  34. planit-1.0.0/tests/test_snap.py +0 -14
  35. planit-1.0.0/tests/test_utils.py +0 -33
  36. {planit-1.0.0 → planit-1.2.2}/LICENSE +0 -0
  37. {planit-1.0.0 → planit-1.2.2}/planit/eos/__init__.py +0 -0
  38. {planit-1.0.0 → planit-1.2.2}/planit/eos/eos_table.py +0 -0
  39. {planit-1.0.0 → planit-1.2.2}/planit/eos/tabinterp.py +0 -0
  40. {planit-1.0.0 → planit-1.2.2}/planit.egg-info/dependency_links.txt +0 -0
  41. {planit-1.0.0 → planit-1.2.2}/planit.egg-info/top_level.txt +0 -0
  42. {planit-1.0.0 → planit-1.2.2}/setup.cfg +0 -0
@@ -1,10 +1,11 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: planit
3
- Version: 1.0.0
3
+ Version: 1.2.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
7
7
  Project-URL: Homepage, https://github.com/PhilJCarter/planit
8
+ Requires-Python: >=3.10
8
9
  Description-Content-Type: text/markdown
9
10
  License-File: LICENSE
10
11
  Requires-Dist: numpy
@@ -14,11 +15,15 @@ Requires-Dist: numba
14
15
  Requires-Dist: h5py
15
16
  Requires-Dist: seagen
16
17
  Requires-Dist: cmasher
18
+ Requires-Dist: IPython
17
19
  Dynamic: license-file
18
20
 
19
21
  # planit
20
22
 
21
23
  [![Tests](https://github.com/PhilJCarter/planit/actions/workflows/python-test.yml/badge.svg)](https://github.com/PhilJCarter/planit/actions/workflows/python-test.yml)
24
+ [![Coverage](https://PhilJCarter.github.io/planit/coverage.svg)](https://PhilJCarter.github.io/planit/cov_html/index.html)
25
+ [![License: GPL v3](https://img.shields.io/badge/License-GPLv3-blue.svg)](https://github.com/PhilJCarter/planit/tree/main?tab=GPL-3.0-1-ov-file#GPL-3.0-1-ov-file)
26
+
22
27
 
23
28
  The **Plan**etary **I**mpact **T**oolkit provides tools for accessing, manipulating, and
24
29
  analysing smoothed particle hydrodynamcis (SPH) impact simulation data, and creating
@@ -29,7 +34,7 @@ Sarah T. Stewart (sstewa56@asu.edu)
29
34
 
30
35
  ## Overview
31
36
 
32
- **planit** currently supports the SPH codes [Gadget2-planetary](https://github.com/PlanetSim/gadget2-planetary) and [SWIFT](http://www.swiftsim.com/).
37
+ **planit** currently supports the SPH codes [Gadget2-planetary](https://github.com/PlanetSim/gadget2-planetary), [pkdgrav3](https://bitbucket.org/dpotter/pkdgrav3/src/master/), and [SWIFT](http://www.swiftsim.com/).
33
38
 
34
39
  `makeplanet` provides functions for generating adiabatic 1D planet structures and
35
40
  converting these into (unequilibrated) SPH planets.\
@@ -58,7 +63,49 @@ an impact simulation.\
58
63
 
59
64
  They can be accessed using the names given above (as well as some variations) or using the
60
65
  corresponding SWIFT/WoMa ID number.\
61
- User supplied tables in standard SESAME format can also be used.
66
+ User supplied SESAME tables can also be loaded into one of five custom slots.
67
+
68
+ ### Custom SESAME EoS tables
69
+
70
+ **planit** supports custom tables in the same SESAME-style layout used by its bundled ANEOS
71
+ and 5-phase-water tables. A table directory must contain all of these files:
72
+
73
+ - `NEW-SESAME-STD.TXT`
74
+ - `NEW-SESAME-STD-NOTENSION.TXT`
75
+ - `NEW-SESAME-EXT.TXT`
76
+
77
+ Use `User0` through `User4` to choose the corresponding reserved SWIFT/WoMa ID:
78
+ `User0` = 900, `User1` = 901, `User2` = 902, `User3` = 903, and `User4` = 904.
79
+ The IDs can also be passed to `select()` in place of the slot names.
80
+
81
+ ```python
82
+ from planit import eos
83
+
84
+ table = eos.select(
85
+ "User0",
86
+ eosname="MyMaterial",
87
+ eosdir="/path/to/my-sesame-table", # trailing slash is optional
88
+ )
89
+
90
+ print(table.MODELNAME) # MyMaterial
91
+ print(table.womaID) # 900
92
+
93
+ # Use the loaded table in the usual way.
94
+ eos_passer = table.make_passer_class()
95
+ internal_energy = eos.tabinterp.from_rhoT("U", 1.0, 300.0, eos_passer)
96
+ ```
97
+
98
+ The first load for a slot requires both `eosname` and `eosdir`. Subsequent
99
+ `eos.select("User0")` calls return that slot's cached table. Passing both arguments
100
+ again deliberately replaces the slot, but only after the new table has loaded
101
+ successfully; a failed replacement raises an error and leaves the previous cached table
102
+ available. Passing just one argument, or reading a slot that was never loaded, raises a
103
+ clear `ValueError` instead of returning an uninitialised table.
104
+
105
+ The loader validates the directory and file names, but it does not validate the physical
106
+ quality or full internal consistency of a table. `NEW-SESAME-EXT.TXT` is required, so a
107
+ minimal standard SESAME 201/301 file alone is not sufficient. Custom tables are cached
108
+ only in the current Python process, and there are only five simultaneous custom slots.
62
109
 
63
110
  >[!WARNING]
64
111
  > HM80 EoS support is not fully tested yet!
@@ -77,4 +124,3 @@ requested mass and component mass fractions are matched (within tolerance). The
77
124
  behaviour prevents the unphyiscal scenario of a core cooler than the mantle at the
78
125
  core-mantle boundary.
79
126
 
80
-
@@ -1,6 +1,9 @@
1
1
  # planit
2
2
 
3
3
  [![Tests](https://github.com/PhilJCarter/planit/actions/workflows/python-test.yml/badge.svg)](https://github.com/PhilJCarter/planit/actions/workflows/python-test.yml)
4
+ [![Coverage](https://PhilJCarter.github.io/planit/coverage.svg)](https://PhilJCarter.github.io/planit/cov_html/index.html)
5
+ [![License: GPL v3](https://img.shields.io/badge/License-GPLv3-blue.svg)](https://github.com/PhilJCarter/planit/tree/main?tab=GPL-3.0-1-ov-file#GPL-3.0-1-ov-file)
6
+
4
7
 
5
8
  The **Plan**etary **I**mpact **T**oolkit provides tools for accessing, manipulating, and
6
9
  analysing smoothed particle hydrodynamcis (SPH) impact simulation data, and creating
@@ -11,7 +14,7 @@ Sarah T. Stewart (sstewa56@asu.edu)
11
14
 
12
15
  ## Overview
13
16
 
14
- **planit** currently supports the SPH codes [Gadget2-planetary](https://github.com/PlanetSim/gadget2-planetary) and [SWIFT](http://www.swiftsim.com/).
17
+ **planit** currently supports the SPH codes [Gadget2-planetary](https://github.com/PlanetSim/gadget2-planetary), [pkdgrav3](https://bitbucket.org/dpotter/pkdgrav3/src/master/), and [SWIFT](http://www.swiftsim.com/).
15
18
 
16
19
  `makeplanet` provides functions for generating adiabatic 1D planet structures and
17
20
  converting these into (unequilibrated) SPH planets.\
@@ -40,7 +43,49 @@ an impact simulation.\
40
43
 
41
44
  They can be accessed using the names given above (as well as some variations) or using the
42
45
  corresponding SWIFT/WoMa ID number.\
43
- User supplied tables in standard SESAME format can also be used.
46
+ User supplied SESAME tables can also be loaded into one of five custom slots.
47
+
48
+ ### Custom SESAME EoS tables
49
+
50
+ **planit** supports custom tables in the same SESAME-style layout used by its bundled ANEOS
51
+ and 5-phase-water tables. A table directory must contain all of these files:
52
+
53
+ - `NEW-SESAME-STD.TXT`
54
+ - `NEW-SESAME-STD-NOTENSION.TXT`
55
+ - `NEW-SESAME-EXT.TXT`
56
+
57
+ Use `User0` through `User4` to choose the corresponding reserved SWIFT/WoMa ID:
58
+ `User0` = 900, `User1` = 901, `User2` = 902, `User3` = 903, and `User4` = 904.
59
+ The IDs can also be passed to `select()` in place of the slot names.
60
+
61
+ ```python
62
+ from planit import eos
63
+
64
+ table = eos.select(
65
+ "User0",
66
+ eosname="MyMaterial",
67
+ eosdir="/path/to/my-sesame-table", # trailing slash is optional
68
+ )
69
+
70
+ print(table.MODELNAME) # MyMaterial
71
+ print(table.womaID) # 900
72
+
73
+ # Use the loaded table in the usual way.
74
+ eos_passer = table.make_passer_class()
75
+ internal_energy = eos.tabinterp.from_rhoT("U", 1.0, 300.0, eos_passer)
76
+ ```
77
+
78
+ The first load for a slot requires both `eosname` and `eosdir`. Subsequent
79
+ `eos.select("User0")` calls return that slot's cached table. Passing both arguments
80
+ again deliberately replaces the slot, but only after the new table has loaded
81
+ successfully; a failed replacement raises an error and leaves the previous cached table
82
+ available. Passing just one argument, or reading a slot that was never loaded, raises a
83
+ clear `ValueError` instead of returning an uninitialised table.
84
+
85
+ The loader validates the directory and file names, but it does not validate the physical
86
+ quality or full internal consistency of a table. `NEW-SESAME-EXT.TXT` is required, so a
87
+ minimal standard SESAME 201/301 file alone is not sufficient. Custom tables are cached
88
+ only in the current Python process, and there are only five simultaneous custom slots.
44
89
 
45
90
  >[!WARNING]
46
91
  > HM80 EoS support is not fully tested yet!
@@ -59,4 +104,3 @@ requested mass and component mass fractions are matched (within tolerance). The
59
104
  behaviour prevents the unphyiscal scenario of a core cooler than the mantle at the
60
105
  core-mantle boundary.
61
106
 
62
-
@@ -1,4 +1,6 @@
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
@@ -6,18 +6,89 @@ from ..main import *
6
6
  from .eos_table import *
7
7
  from .eostab_extension import *
8
8
  import numpy as npy
9
+ from pathlib import Path
9
10
 
10
11
 
11
- def loadANEOSEOS(eos='Iron-ANEOS-SLVTv0.2G1', eostype='ANEOS', debug=False, eosdir=None, user=False):
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):
12
73
  """
13
- READ IN NEW ANEOS MODEL and fill the extEOStable class object
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.
14
80
 
15
81
  Returns: EOStable
16
82
  """
17
83
 
18
84
  NewEOS = EOStable() # make new empty EOS object
19
85
 
20
- if eos == 'Iron-ANEOS-SLVTv0.2G1':
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':
21
92
  eosdir = eospath + 'aneos-iron-2020-master/'
22
93
  womaID = 401
23
94
  # MODELNAME = 'Iron-ANEOS-SLVTv0.2G1'
@@ -59,16 +130,20 @@ def loadANEOSEOS(eos='Iron-ANEOS-SLVTv0.2G1', eostype='ANEOS', debug=False, eosd
59
130
  NewEOS.T0REF = 298. # K -- *** T0REF is inserted into the temperature array
60
131
  NewEOS.P0REF = 1.E6
61
132
 
62
- elif not user:
133
+ else:
63
134
  raise ValueError('EOS:', eos, 'unknown.')
64
135
 
65
136
  NewEOS.TYPE = eostype
66
137
  NewEOS.womaID = womaID
67
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
+
68
143
  if eostype == 'ANEOS':
69
144
  # READ EOS HEADER INFORMATION
70
145
  # READ IN ANEOS INPUT FILE
71
- aneosinputfile = open(eosdir+'ANEOS.INPUT', "r")
146
+ aneosinputfile = open(eosdir / 'ANEOS.INPUT', "r")
72
147
  an_in = aneosinputfile.readlines() # read in the whole ascii file at once because this is fatser
73
148
  aneosinputfile.close()
74
149
  aneoscount = 1
@@ -94,7 +169,7 @@ def loadANEOSEOS(eos='Iron-ANEOS-SLVTv0.2G1', eostype='ANEOS', debug=False, eosd
94
169
  NewEOS.P0REF = P0REF
95
170
 
96
171
  # READ SESAME HEADER
97
- sesfile = open(eosdir+'NEW-SESAME-STD.TXT', "r")
172
+ sesfile = open(eosdir / 'NEW-SESAME-STD.TXT', "r")
98
173
  sesdata = sesfile.readlines(5000)
99
174
  sesfile.close()
100
175
  for i in range(len(sesdata)):
@@ -109,8 +184,8 @@ def loadANEOSEOS(eos='Iron-ANEOS-SLVTv0.2G1', eostype='ANEOS', debug=False, eosd
109
184
  FMW = float(tmp.split()[1])
110
185
  break
111
186
 
112
- NewEOS.loadextsesame(eosdir+'NEW-SESAME-EXT.TXT') # LOAD THE EXTENDED 301 SESAME FILE GENERATED BY STSM VERSION OF ANEOS
113
- NewEOS.loadstdsesame(eosdir+'NEW-SESAME-STD-NOTENSION.TXT') # LOAD THE STANDARD 301 SESAME FILE GENERATED BY STSM VERSION OF ANEOS
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
114
189
  NewEOS.MODELNAME = eos # string set above in user input
115
190
  NewEOS.MDQ = npy.zeros((NewEOS.NT,NewEOS.ND)) # makes the empty MDQ array
116
191
 
@@ -123,7 +198,7 @@ def loadANEOSEOS(eos='Iron-ANEOS-SLVTv0.2G1', eostype='ANEOS', debug=False, eosd
123
198
 
124
199
  # Load the information from ANEOS.INPUT and ANEOS.OUTPUT
125
200
  if eostype == 'ANEOS':
126
- NewEOS.loadaneos(aneosinfname=eosdir+'ANEOS.INPUT', aneosoutfname=eosdir+'ANEOS.OUTPUT', silent=True)
201
+ NewEOS.loadaneos(aneosinfname=str(eosdir / 'ANEOS.INPUT'), aneosoutfname=str(eosdir / 'ANEOS.OUTPUT'), silent=True)
127
202
  #
128
203
  NewEOS.calchugoniot(r0=NewEOS.R0REF,t0=NewEOS.T0REF)
129
204
  #
@@ -139,4 +214,3 @@ def loadANEOSEOS(eos='Iron-ANEOS-SLVTv0.2G1', eostype='ANEOS', debug=False, eosd
139
214
  NewEOS.onebar.rho[iit] = npy.interp(1.E-4, NewEOS.P[iit,id0], NewEOS.rho[id0])
140
215
 
141
216
  return NewEOS
142
-
@@ -17,9 +17,11 @@ def loadAQUAEOS(eos='Water-AQUA-v1.0', eostype='AQUA', debug = False):
17
17
 
18
18
  if eos == 'Water-AQUA-v1.0':
19
19
  eosdir = eospath + 'aqua-water/'
20
-
20
+ womaID = 304
21
+
21
22
  NewEOS = EOStable() # FIRST make new empty EOS object
22
23
  NewEOS.TYPE = eostype
24
+ NewEOS.womaID = womaID
23
25
  NewEOS.VERSION = 1.0
24
26
 
25
27
  NewEOS.loadaquatable(eosdir+'aqua_eos_rhot_v1_0.dat')
@@ -50,9 +50,9 @@ UserEOS4 = None
50
50
 
51
51
 
52
52
  # Name lists for EoS
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]
53
+ ironnames = ['Iron-ANEOS-SLVTv0.2G1', 'iron', 'ANEOSIron', 'Fe', 'Iron', 401, 63]
54
+ alloynames = ['Fe85Si15-ANEOS-SLVTv0.2G1', 'alloy', 'ANEOSFeSiAlloy', 'FeSi', 'Alloy', 'IronAlloy', 'ironalloy', 402, 64]
55
+ forsteritenames = ['Forsterite-ANEOS-SLVTv1.0G1', 'forsterite', 'ANEOSForsterite', 'Forsterite', 'Fo', 400, 62]
56
56
  pyrolitenames = ['Pyrolite_ANEOS_SLVTv0.2', 'pyrolite', 'Pyrolite', 'ANEOSPyrolite', 403]
57
57
  aquawaternames = ['Water-AQUA-v1.0', 'AQUA', 'AQUAWater', 'aqua', 304]
58
58
  fivephasewaternames = ['5PhaseEOSv8.3', '5PhaseWater', '5phasewater', 'SS08', 'SenftStewartWater', 'SenftStewart08', 303]
@@ -64,12 +64,87 @@ user2names = ['User2', 902]
64
64
  user3names = ['User3', 903]
65
65
  user4names = ['User4',904]
66
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
+
67
122
 
68
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``.
69
138
  """
70
- Return EoS table object specified by name,
71
- loading it first if not already loaded
72
- """
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
+
73
148
  if name in ironnames:
74
149
  global ANEOSIron
75
150
  if not ANEOSIron:
@@ -105,34 +180,8 @@ def select(name, eosname=None, eosdir=None):
105
180
  if not HM80HHe:
106
181
  HM80HHe = loadEOS(eos='HM80-HHe-v2.0', eostype='HM80')
107
182
  return HM80HHe
108
- elif name in user0names:
109
- global UserEOS0
110
- if (not UserEOS0) or (eosdir and eosname):
111
- UserEOS0 = loadANEOSEOS(eos=eosname, eostype='SESAME', eosdir=eosdir, user=True)
112
- return UserEOS0
113
- elif name in user1names:
114
- global UserEOS1
115
- if (not UserEOS1) or (eosdir and eosname):
116
- UserEOS1 = loadANEOSEOS(eos=eosname, eostype='SESAME', eosdir=eosdir, user=True)
117
- return UserEOS1
118
- elif name in user2names:
119
- global UserEOS2
120
- if (not UserEOS2) or (eosdir and eosname):
121
- UserEOS2 = loadANEOSEOS(eos=eosname, eostype='SESAME', eosdir=eosdir, user=True)
122
- return UserEOS2
123
- elif name in user3names:
124
- global UserEOS3
125
- if (not UserEOS3) or (eosdir and eosname):
126
- UserEOS3 = loadANEOSEOS(eos=eosname, eostype='SESAME', eosdir=eosdir, user=True)
127
- return UserEOS3
128
- elif name in user4names:
129
- global UserEOS4
130
- if (not UserEOS4) or (eosdir and eosname):
131
- UserEOS4 = loadANEOSEOS(eos=eosname, eostype='SESAME', eosdir=eosdir, user=True)
132
- return UserEOS4
133
183
  else:
134
184
  raise ValueError('Unknown EOS:', name)
135
- #return None
136
185
 
137
186
 
138
187
  class isentrope_class(eos_isentrope_class):
@@ -204,6 +253,26 @@ uconversion_U_inv = 1./uconversion_U
204
253
  uconversion_S_inv = 1./uconversion_S
205
254
 
206
255
 
256
+ def pkdgrav3towoma(pkdmats):
257
+ """Translate pkdgrav3/EOSLib material numbers to swift/woma IDs"""
258
+ swiftmats = pkdmats.copy()
259
+ swiftmats[pkdmats==63] = 401 # iron
260
+ swiftmats[pkdmats==62] = 400 # forsterite
261
+ swiftmats[pkdmats==64] = 402 # FeSi alloy
262
+
263
+ return swiftmats
264
+
265
+
266
+ def womatopkdgrav3(swiftmats):
267
+ """Translate swift/woma IDs to pkdgrav3/EOSLib material numbers"""
268
+ pkdmats = swiftmats.copy()
269
+ pkdmats[swiftmats==401] = 63 # iron
270
+ pkdmats[swiftmats==400] = 62 # forsterite
271
+ pkdmats[swiftmats==402] = 64 # FeSi alloy
272
+
273
+ return pkdmats
274
+
275
+
207
276
  def calcprop(Qlab,Xlab,Ylab,X,Y,mats):
208
277
  """Calculate thermodynamic property
209
278
 
@@ -273,7 +342,7 @@ def _calc_prop(Qlab,Xlab,Ylab,X,Y,EOSlist):
273
342
  Q = npy.zeros(len(X))
274
343
  for i in numba.prange(len(X)):
275
344
 
276
- if EOSlist[i].TYPE in ['ANEOS','SESAME','AQUA']:
345
+ if EOSlist[i].TYPE in ['ANEOS', 'SESAME', 'AQUA']:
277
346
  if Ylab == 'S':
278
347
  Q[i] = tabinterp.from_rhoS(Qlab, X[i], Y[i], EOSlist[i])
279
348
  elif Ylab == 'U':
@@ -79,10 +79,12 @@ class EOStable(extEOStable):
79
79
  passer.T = self.T
80
80
  passer.P = self.P
81
81
  passer.U = self.U
82
- passer.A = self.A
82
+ if len(self.A) > 0:
83
+ passer.A = self.A
83
84
  passer.S = self.S
84
85
  passer.cs = self.cs
85
- passer.cv = self.cv
86
+ if len(self.cv) > 0:
87
+ passer.cv = self.cv
86
88
  # passer.KPA = self.KPA
87
89
  # passer.MDQ = self.MDQ
88
90
  passer.TYPE = self.TYPE
@@ -19,6 +19,7 @@ def loadrhoUEOS(eos='HM80-HHe-v2.0', eostype='HM80', debug = False):
19
19
 
20
20
  if eos == 'HM80-HHe-v2.0':
21
21
  eosdir = eospath + 'HM80_HHe/'
22
+ NewEOS.womaID = 200
22
23
  NewEOS.VERSION = 2.0
23
24
  NewEOS.loadrhoUtable(eosdir+'HM80_HHe_extended.txt')
24
25
 
@@ -0,0 +1,11 @@
1
+ import os
2
+
3
+ G = 6.6743E-8 # Gravitational constant cgs cm3/g/s2
4
+ Mearth = 5.972E27 # Earth's mass g
5
+ Rearth = 6.371e8 # Earth's radius in cm
6
+
7
+ GADGET_EOS_OFFSET = IDOFF = 200000000 # material id offset
8
+ PROJ_ID_OFFSET = BODYOFF = 100000000 # body id offset
9
+
10
+ eospath = os.path.dirname(__file__) + '/eos/data/'
11
+ datadir = os.path.dirname(__file__) + '/data/'