oilprops 0.1.0__py3-none-any.whl

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.
oilprops/__init__.py ADDED
@@ -0,0 +1,146 @@
1
+ """OilProps: Universal thermophysical, transport, caloric, and PVT library for petroleum oils."""
2
+
3
+ from __future__ import annotations
4
+
5
+ from oilprops.presets import (
6
+ BUILTIN_PRESETS,
7
+ PRESET_ALIASES,
8
+ OilGradeSpec,
9
+ create_custom_oil,
10
+ estimate_barus_alpha,
11
+ estimate_bulk_modulus_15,
12
+ estimate_thermal_conductivity_15,
13
+ estimate_thermal_expansion_beta,
14
+ from_api_gravity,
15
+ get_preset,
16
+ list_presets,
17
+ )
18
+ from oilprops.properties import (
19
+ AstmD341Coeffs,
20
+ OilState,
21
+ ViscosityChartRow,
22
+ blend_oils,
23
+ eval_astm_d341,
24
+ fit_astm_d341,
25
+ generate_viscosity_temp_table,
26
+ get_acoustic_speed,
27
+ get_api_gravity,
28
+ get_bulk_modulus,
29
+ get_compressibility,
30
+ get_density,
31
+ get_dynamic_viscosity,
32
+ get_enthalpy,
33
+ get_kinematic_viscosity,
34
+ get_oil_properties,
35
+ get_oil_properties_from_enthalpy,
36
+ get_prandtl_number,
37
+ get_specific_gravity,
38
+ get_specific_heat,
39
+ get_temperature_from_enthalpy,
40
+ get_thermal_conductivity,
41
+ get_vapor_pressure,
42
+ solve_temp_for_viscosity,
43
+ )
44
+ from oilprops.thermo_adapter import (
45
+ PseudocomponentSpec,
46
+ characterize_pseudocomponent,
47
+ evaluate_hydrocarbon,
48
+ evaluate_mixture,
49
+ evaluate_pseudocomponent,
50
+ pseudocomponent_to_oil_spec,
51
+ )
52
+ from oilprops.units import (
53
+ ATM_BAR,
54
+ ATM_PA,
55
+ WATER_REF_60F_KG_M3,
56
+ api_to_sg,
57
+ bar_to_pa,
58
+ bar_to_psi,
59
+ c_to_f,
60
+ c_to_k,
61
+ cp_to_pas,
62
+ cst_to_m2s,
63
+ cst_to_sus,
64
+ f_to_c,
65
+ k_to_c,
66
+ m2s_to_cst,
67
+ pa_to_bar,
68
+ pas_to_cp,
69
+ psi_to_bar,
70
+ sg_to_api,
71
+ sus_to_cst,
72
+ )
73
+
74
+ try:
75
+ from oilprops._version import __version__
76
+ except ImportError: # pragma: no cover
77
+ try:
78
+ from importlib.metadata import version as _pkg_version
79
+
80
+ __version__ = _pkg_version("oilprops")
81
+ except Exception:
82
+ __version__ = "0.0.0.dev0"
83
+
84
+ __all__ = [
85
+ "__version__",
86
+ "ATM_BAR",
87
+ "ATM_PA",
88
+ "WATER_REF_60F_KG_M3",
89
+ "BUILTIN_PRESETS",
90
+ "PRESET_ALIASES",
91
+ "OilGradeSpec",
92
+ "AstmD341Coeffs",
93
+ "ViscosityChartRow",
94
+ "OilState",
95
+ "PseudocomponentSpec",
96
+ "list_presets",
97
+ "get_preset",
98
+ "create_custom_oil",
99
+ "from_api_gravity",
100
+ "estimate_thermal_expansion_beta",
101
+ "estimate_barus_alpha",
102
+ "estimate_bulk_modulus_15",
103
+ "estimate_thermal_conductivity_15",
104
+ "fit_astm_d341",
105
+ "eval_astm_d341",
106
+ "solve_temp_for_viscosity",
107
+ "generate_viscosity_temp_table",
108
+ "blend_oils",
109
+ "get_density",
110
+ "get_specific_gravity",
111
+ "get_api_gravity",
112
+ "get_kinematic_viscosity",
113
+ "get_dynamic_viscosity",
114
+ "get_vapor_pressure",
115
+ "get_bulk_modulus",
116
+ "get_compressibility",
117
+ "get_acoustic_speed",
118
+ "get_specific_heat",
119
+ "get_enthalpy",
120
+ "get_temperature_from_enthalpy",
121
+ "get_thermal_conductivity",
122
+ "get_prandtl_number",
123
+ "get_oil_properties",
124
+ "get_oil_properties_from_enthalpy",
125
+ "characterize_pseudocomponent",
126
+ "evaluate_hydrocarbon",
127
+ "evaluate_mixture",
128
+ "evaluate_pseudocomponent",
129
+ "pseudocomponent_to_oil_spec",
130
+ "c_to_k",
131
+ "k_to_c",
132
+ "f_to_c",
133
+ "c_to_f",
134
+ "bar_to_pa",
135
+ "pa_to_bar",
136
+ "psi_to_bar",
137
+ "bar_to_psi",
138
+ "sg_to_api",
139
+ "api_to_sg",
140
+ "cst_to_m2s",
141
+ "m2s_to_cst",
142
+ "cp_to_pas",
143
+ "pas_to_cp",
144
+ "cst_to_sus",
145
+ "sus_to_cst",
146
+ ]
oilprops/_version.py ADDED
@@ -0,0 +1,24 @@
1
+ # file generated by vcs-versioning
2
+ # don't change, don't track in version control
3
+ from __future__ import annotations
4
+
5
+ __all__ = [
6
+ "__version__",
7
+ "__version_tuple__",
8
+ "version",
9
+ "version_tuple",
10
+ "__commit_id__",
11
+ "commit_id",
12
+ ]
13
+
14
+ version: str
15
+ __version__: str
16
+ __version_tuple__: tuple[int | str, ...]
17
+ version_tuple: tuple[int | str, ...]
18
+ commit_id: str | None
19
+ __commit_id__: str | None
20
+
21
+ __version__ = version = '0.1.0'
22
+ __version_tuple__ = version_tuple = (0, 1, 0)
23
+
24
+ __commit_id__ = commit_id = None
oilprops/presets.py ADDED
@@ -0,0 +1,409 @@
1
+ """Built-in industrial petroleum oil presets and custom grade builders."""
2
+
3
+ from __future__ import annotations
4
+
5
+ from dataclasses import dataclass
6
+ import math
7
+ import re
8
+
9
+ from oilprops.units import (
10
+ TEMP_60F_C,
11
+ WATER_REF_60F_KG_M3,
12
+ api_to_sg,
13
+ validate_finite,
14
+ validate_non_negative,
15
+ validate_positive,
16
+ validate_temperature_c,
17
+ )
18
+
19
+
20
+ def _normalize_key(raw: str) -> str:
21
+ """Normalize a preset name or alias into lowercase snake_case."""
22
+ cleaned = re.sub(r"[^a-z0-9]+", "_", str(raw).strip().lower())
23
+ return cleaned.strip("_")
24
+
25
+
26
+ def estimate_thermal_expansion_beta(rho_15_kg_m3: float) -> float:
27
+ """
28
+ Estimate ISO 91-1 / API MPMS 11.1 thermal expansion coefficient beta [1/K]
29
+ from reference density at 15 °C [kg/m³] using the generalized fuel/crude correlation.
30
+ """
31
+ rho = validate_positive(rho_15_kg_m3, "rho_15_kg_m3")
32
+ return (186.9696 + 0.48618 * rho) / (rho * rho)
33
+
34
+
35
+ def estimate_barus_alpha(visc_50_cst: float, rho_15_kg_m3: float) -> float:
36
+ """
37
+ Estimate Barus pressure-viscosity coefficient alpha [Pa⁻¹] for petroleum oils.
38
+ Typical mineral/fuel oils range from ~1.1e-8 Pa⁻¹ (light distillates)
39
+ to ~2.5e-8 Pa⁻¹ (heavy residual oils).
40
+ """
41
+ nu = validate_positive(visc_50_cst, "visc_50_cst")
42
+ rho = validate_positive(rho_15_kg_m3, "rho_15_kg_m3")
43
+ # Wu / So-Klaus-style empirical approximation bounded to realistic mineral-oil band
44
+ est = (1.0 + 0.16 * math.log10(max(nu, 1.0)) + 0.0005 * max(rho - 800.0, 0.0)) * 1.15e-8
45
+ return max(1.0e-8, min(est, 3.2e-8))
46
+
47
+
48
+ def estimate_bulk_modulus_15(rho_15_kg_m3: float) -> float:
49
+ """
50
+ Estimate reference isothermal bulk modulus K_15 [Pa] at 15 °C from density [kg/m³].
51
+ Light distillates are ~1.30–1.45 GPa; heavy residual oils are ~1.70–1.85 GPa.
52
+ """
53
+ rho = validate_positive(rho_15_kg_m3, "rho_15_kg_m3")
54
+ k_gpa = 1.35 + 0.0028 * (rho - 820.0)
55
+ return max(0.8e9, min(k_gpa * 1e9, 2.5e9))
56
+
57
+
58
+ def estimate_thermal_conductivity_15(rho_15_kg_m3: float) -> float:
59
+ """Estimate liquid thermal conductivity at 15 °C [W/(m·K)] via Cragoe correlation."""
60
+ sg_15 = validate_positive(rho_15_kg_m3, "rho_15_kg_m3") / WATER_REF_60F_KG_M3
61
+ return 0.1172 / sg_15
62
+
63
+
64
+ def _estimate_antoine_from_density(rho_15_kg_m3: float) -> tuple[float, float, float]:
65
+ """
66
+ Provide conservative Antoine parameters log10(Pv [Pa]) = A - B / (T_K + C)
67
+ scaled monotonically with fuel density (lighter distillates are more volatile).
68
+ """
69
+ rho = validate_positive(rho_15_kg_m3, "rho_15_kg_m3")
70
+ # Linearly interpolate between light distillate (~800 kg/m³) and heavy residual (~970 kg/m³)
71
+ frac = max(0.0, min((rho - 800.0) / 170.0, 1.0))
72
+ a = 8.60 - 0.40 * frac
73
+ b = 1430.0 + 620.0 * frac
74
+ c = -45.0
75
+ return a, b, c
76
+
77
+
78
+ @dataclass(frozen=True)
79
+ class OilGradeSpec:
80
+ """Immutable specification of a petroleum oil grade."""
81
+
82
+ key: str
83
+ name: str
84
+ rho_15_kg_m3: float
85
+ thermal_expansion_beta: float
86
+ cp_15_kj_kgk: float
87
+ visc_t1_c: float
88
+ visc_1_cst: float
89
+ visc_t2_c: float
90
+ visc_2_cst: float
91
+ barus_alpha_pa_inv: float = 1.8e-8
92
+ bulk_modulus_15_pa: float = 1.5e9
93
+ bulk_modulus_temp_decay: float = 0.0045
94
+ bulk_modulus_pressure_slope: float = 5.5
95
+ antoine_a: float = 8.35
96
+ antoine_b: float = 1650.0
97
+ antoine_c: float = -45.0
98
+ cp_temp_slope: float = 0.001
99
+ thermal_conductivity_15_w_mk: float = 0.130
100
+ thermal_conductivity_temp_slope: float = -0.00054
101
+
102
+ def __post_init__(self) -> None:
103
+ if not str(self.key).strip():
104
+ raise ValueError("key must be a non-empty string")
105
+ if not str(self.name).strip():
106
+ raise ValueError("name must be a non-empty string")
107
+
108
+ validate_positive(self.rho_15_kg_m3, "rho_15_kg_m3")
109
+ validate_positive(self.thermal_expansion_beta, "thermal_expansion_beta")
110
+ validate_positive(self.cp_15_kj_kgk, "cp_15_kj_kgk")
111
+ validate_finite(self.cp_temp_slope, "cp_temp_slope")
112
+
113
+ t1 = validate_temperature_c(self.visc_t1_c, "visc_t1_c")
114
+ t2 = validate_temperature_c(self.visc_t2_c, "visc_t2_c")
115
+ if abs(t1 - t2) < 1e-6:
116
+ raise ValueError("visc_t1_c and visc_t2_c must be distinct temperatures")
117
+
118
+ nu1 = validate_positive(self.visc_1_cst, "visc_1_cst")
119
+ nu2 = validate_positive(self.visc_2_cst, "visc_2_cst")
120
+ if nu1 + 0.7 <= 1.0 or nu2 + 0.7 <= 1.0:
121
+ raise ValueError(
122
+ "ASTM D341 Walther equation requires kinematic viscosities > 0.30 cSt"
123
+ )
124
+
125
+ validate_non_negative(self.barus_alpha_pa_inv, "barus_alpha_pa_inv")
126
+ validate_positive(self.bulk_modulus_15_pa, "bulk_modulus_15_pa")
127
+ validate_non_negative(self.bulk_modulus_temp_decay, "bulk_modulus_temp_decay")
128
+ validate_non_negative(
129
+ self.bulk_modulus_pressure_slope, "bulk_modulus_pressure_slope"
130
+ )
131
+ validate_finite(self.antoine_a, "antoine_a")
132
+ validate_positive(self.antoine_b, "antoine_b")
133
+ validate_finite(self.antoine_c, "antoine_c")
134
+ validate_positive(
135
+ self.thermal_conductivity_15_w_mk, "thermal_conductivity_15_w_mk"
136
+ )
137
+ validate_finite(
138
+ self.thermal_conductivity_temp_slope, "thermal_conductivity_temp_slope"
139
+ )
140
+
141
+
142
+ BUILTIN_PRESETS: dict[str, OilGradeSpec] = {
143
+ "hfo": OilGradeSpec(
144
+ key="hfo",
145
+ name="Heavy Fuel Oil (HFO 380 / Bunker C)",
146
+ rho_15_kg_m3=965.0,
147
+ thermal_expansion_beta=0.00067,
148
+ cp_15_kj_kgk=1.95,
149
+ visc_t1_c=50.0,
150
+ visc_1_cst=380.0,
151
+ visc_t2_c=100.0,
152
+ visc_2_cst=25.0,
153
+ barus_alpha_pa_inv=2.2e-8,
154
+ bulk_modulus_15_pa=1.75e9,
155
+ bulk_modulus_temp_decay=0.0045,
156
+ bulk_modulus_pressure_slope=5.6,
157
+ antoine_a=8.20,
158
+ antoine_b=2050.0,
159
+ antoine_c=-45.0,
160
+ thermal_conductivity_15_w_mk=estimate_thermal_conductivity_15(965.0),
161
+ ),
162
+ "hfo_180": OilGradeSpec(
163
+ key="hfo_180",
164
+ name="Heavy Fuel Oil (HFO 180 / RMF 180)",
165
+ rho_15_kg_m3=955.0,
166
+ thermal_expansion_beta=0.00068,
167
+ cp_15_kj_kgk=1.97,
168
+ visc_t1_c=50.0,
169
+ visc_1_cst=180.0,
170
+ visc_t2_c=100.0,
171
+ visc_2_cst=17.5,
172
+ barus_alpha_pa_inv=2.0e-8,
173
+ bulk_modulus_15_pa=1.72e9,
174
+ bulk_modulus_temp_decay=0.0045,
175
+ bulk_modulus_pressure_slope=5.5,
176
+ antoine_a=8.24,
177
+ antoine_b=1980.0,
178
+ antoine_c=-45.0,
179
+ thermal_conductivity_15_w_mk=estimate_thermal_conductivity_15(955.0),
180
+ ),
181
+ "ldo": OilGradeSpec(
182
+ key="ldo",
183
+ name="Light Diesel Oil (LDO)",
184
+ rho_15_kg_m3=850.0,
185
+ thermal_expansion_beta=0.00072,
186
+ cp_15_kj_kgk=2.05,
187
+ visc_t1_c=40.0,
188
+ visc_1_cst=5.5,
189
+ visc_t2_c=100.0,
190
+ visc_2_cst=1.8,
191
+ barus_alpha_pa_inv=1.5e-8,
192
+ bulk_modulus_15_pa=1.45e9,
193
+ bulk_modulus_temp_decay=0.0048,
194
+ bulk_modulus_pressure_slope=5.4,
195
+ antoine_a=8.35,
196
+ antoine_b=1650.0,
197
+ antoine_c=-45.0,
198
+ thermal_conductivity_15_w_mk=estimate_thermal_conductivity_15(850.0),
199
+ ),
200
+ "diesel": OilGradeSpec(
201
+ key="diesel",
202
+ name="Diesel / Gasoil (No. 2)",
203
+ rho_15_kg_m3=830.0,
204
+ thermal_expansion_beta=0.00075,
205
+ cp_15_kj_kgk=2.08,
206
+ visc_t1_c=40.0,
207
+ visc_1_cst=3.0,
208
+ visc_t2_c=100.0,
209
+ visc_2_cst=1.2,
210
+ barus_alpha_pa_inv=1.3e-8,
211
+ bulk_modulus_15_pa=1.38e9,
212
+ bulk_modulus_temp_decay=0.0050,
213
+ bulk_modulus_pressure_slope=5.3,
214
+ antoine_a=8.45,
215
+ antoine_b=1560.0,
216
+ antoine_c=-45.0,
217
+ thermal_conductivity_15_w_mk=estimate_thermal_conductivity_15(830.0),
218
+ ),
219
+ "kerosene": OilGradeSpec(
220
+ key="kerosene",
221
+ name="Kerosene / Jet A-1",
222
+ rho_15_kg_m3=800.0,
223
+ thermal_expansion_beta=0.00085,
224
+ cp_15_kj_kgk=2.01,
225
+ visc_t1_c=40.0,
226
+ visc_1_cst=1.4,
227
+ visc_t2_c=100.0,
228
+ visc_2_cst=0.7,
229
+ barus_alpha_pa_inv=1.15e-8,
230
+ bulk_modulus_15_pa=1.30e9,
231
+ bulk_modulus_temp_decay=0.0052,
232
+ bulk_modulus_pressure_slope=5.2,
233
+ antoine_a=8.60,
234
+ antoine_b=1430.0,
235
+ antoine_c=-45.0,
236
+ thermal_conductivity_15_w_mk=estimate_thermal_conductivity_15(800.0),
237
+ ),
238
+ }
239
+
240
+ PRESET_ALIASES: dict[str, str] = {
241
+ "hfo": "hfo",
242
+ "hfo_380": "hfo",
243
+ "hfo380": "hfo",
244
+ "rmg380": "hfo",
245
+ "bunker_c": "hfo",
246
+ "bunkerc": "hfo",
247
+ "heavy_fuel_oil": "hfo",
248
+ "heavy_fuel_oil_hfo_bunker_c": "hfo",
249
+ "heavy_fuel_oil_hfo_380_bunker_c": "hfo",
250
+ "hfo_180": "hfo_180",
251
+ "hfo180": "hfo_180",
252
+ "rmf180": "hfo_180",
253
+ "heavy_fuel_oil_hfo_180_rmf_180": "hfo_180",
254
+ "ldo": "ldo",
255
+ "light_diesel": "ldo",
256
+ "light_diesel_oil": "ldo",
257
+ "light_diesel_oil_ldo": "ldo",
258
+ "diesel": "diesel",
259
+ "diesel_no2": "diesel",
260
+ "diesel_no_2": "diesel",
261
+ "diesel_gasoil": "diesel",
262
+ "diesel_gasoil_no_2": "diesel",
263
+ "gasoil": "diesel",
264
+ "no2": "diesel",
265
+ "mgo": "diesel",
266
+ "kerosene": "kerosene",
267
+ "jet_a1": "kerosene",
268
+ "jet_a_1": "kerosene",
269
+ "jeta1": "kerosene",
270
+ "jet_a": "kerosene",
271
+ "kerosene_jet_a_1": "kerosene",
272
+ }
273
+
274
+
275
+ def list_presets() -> tuple[str, ...]:
276
+ """Return canonical keys of all built-in petroleum oil presets."""
277
+ return tuple(BUILTIN_PRESETS.keys())
278
+
279
+
280
+ def get_preset(oil: str | OilGradeSpec) -> OilGradeSpec:
281
+ """Resolve an OilGradeSpec from a preset key, alias, or OilGradeSpec instance."""
282
+ if isinstance(oil, OilGradeSpec):
283
+ return oil
284
+ if not isinstance(oil, str):
285
+ raise ValueError(f"oil must be a preset name or OilGradeSpec, got {type(oil).__name__}")
286
+
287
+ norm = _normalize_key(oil)
288
+ canonical = PRESET_ALIASES.get(norm)
289
+ if canonical is None:
290
+ available = ", ".join(BUILTIN_PRESETS.keys())
291
+ raise ValueError(f"Unknown oil preset {oil!r}. Available presets: {available}")
292
+ return BUILTIN_PRESETS[canonical]
293
+
294
+
295
+ def create_custom_oil(
296
+ *,
297
+ name: str = "Custom Fuel Oil",
298
+ key: str = "custom",
299
+ rho_15_kg_m3: float,
300
+ visc_t1_c: float,
301
+ visc_1_cst: float,
302
+ visc_t2_c: float,
303
+ visc_2_cst: float,
304
+ cp_15_kj_kgk: float = 2.0,
305
+ thermal_expansion_beta: float | None = None,
306
+ barus_alpha_pa_inv: float | None = None,
307
+ bulk_modulus_15_pa: float | None = None,
308
+ bulk_modulus_temp_decay: float = 0.0046,
309
+ bulk_modulus_pressure_slope: float = 5.5,
310
+ antoine_coeffs: tuple[float, float, float] | None = None,
311
+ cp_temp_slope: float = 0.001,
312
+ thermal_conductivity_15_w_mk: float | None = None,
313
+ thermal_conductivity_temp_slope: float = -0.00054,
314
+ ) -> OilGradeSpec:
315
+ """
316
+ Create a custom OilGradeSpec from measured lab data, auto-estimating omitted
317
+ secondary constants using API MPMS / Cragoe / empirical correlations.
318
+ """
319
+ rho_15 = validate_positive(rho_15_kg_m3, "rho_15_kg_m3")
320
+ beta = (
321
+ estimate_thermal_expansion_beta(rho_15)
322
+ if thermal_expansion_beta is None
323
+ else validate_positive(thermal_expansion_beta, "thermal_expansion_beta")
324
+ )
325
+ alpha = (
326
+ estimate_barus_alpha(max(visc_1_cst, visc_2_cst), rho_15)
327
+ if barus_alpha_pa_inv is None
328
+ else validate_non_negative(barus_alpha_pa_inv, "barus_alpha_pa_inv")
329
+ )
330
+ k15 = (
331
+ estimate_bulk_modulus_15(rho_15)
332
+ if bulk_modulus_15_pa is None
333
+ else validate_positive(bulk_modulus_15_pa, "bulk_modulus_15_pa")
334
+ )
335
+ if antoine_coeffs is None:
336
+ ant_a, ant_b, ant_c = _estimate_antoine_from_density(rho_15)
337
+ else:
338
+ ant_a, ant_b, ant_c = antoine_coeffs
339
+
340
+ cond15 = (
341
+ estimate_thermal_conductivity_15(rho_15)
342
+ if thermal_conductivity_15_w_mk is None
343
+ else validate_positive(
344
+ thermal_conductivity_15_w_mk, "thermal_conductivity_15_w_mk"
345
+ )
346
+ )
347
+
348
+ return OilGradeSpec(
349
+ key=key,
350
+ name=name,
351
+ rho_15_kg_m3=rho_15,
352
+ thermal_expansion_beta=beta,
353
+ cp_15_kj_kgk=cp_15_kj_kgk,
354
+ cp_temp_slope=cp_temp_slope,
355
+ visc_t1_c=visc_t1_c,
356
+ visc_1_cst=visc_1_cst,
357
+ visc_t2_c=visc_t2_c,
358
+ visc_2_cst=visc_2_cst,
359
+ barus_alpha_pa_inv=alpha,
360
+ bulk_modulus_15_pa=k15,
361
+ bulk_modulus_temp_decay=bulk_modulus_temp_decay,
362
+ bulk_modulus_pressure_slope=bulk_modulus_pressure_slope,
363
+ antoine_a=ant_a,
364
+ antoine_b=ant_b,
365
+ antoine_c=ant_c,
366
+ thermal_conductivity_15_w_mk=cond15,
367
+ thermal_conductivity_temp_slope=thermal_conductivity_temp_slope,
368
+ )
369
+
370
+
371
+ def from_api_gravity(
372
+ *,
373
+ api_gravity: float,
374
+ visc_t1_c: float,
375
+ visc_1_cst: float,
376
+ visc_t2_c: float,
377
+ visc_2_cst: float,
378
+ name: str = "Custom API Oil",
379
+ key: str = "custom_api",
380
+ cp_15_kj_kgk: float = 2.0,
381
+ thermal_expansion_beta: float | None = None,
382
+ **kwargs: object,
383
+ ) -> OilGradeSpec:
384
+ """
385
+ Create a custom OilGradeSpec from API gravity [°API] and two kinematic viscosity points.
386
+ Converts SG(60/60 °F) to rho_15 consistently with ISO 91-1 thermal expansion.
387
+ """
388
+ sg_60 = api_to_sg(api_gravity)
389
+ rho_60 = sg_60 * WATER_REF_60F_KG_M3
390
+ beta = (
391
+ estimate_thermal_expansion_beta(rho_60)
392
+ if thermal_expansion_beta is None
393
+ else validate_positive(thermal_expansion_beta, "thermal_expansion_beta")
394
+ )
395
+ # Adjust from 60 °F (15.5556 °C) back to 15.0 °C so get_api_gravity() round-trips exactly
396
+ rho_15 = rho_60 * (1.0 + beta * (TEMP_60F_C - 15.0))
397
+
398
+ return create_custom_oil(
399
+ name=name,
400
+ key=key,
401
+ rho_15_kg_m3=rho_15,
402
+ visc_t1_c=visc_t1_c,
403
+ visc_1_cst=visc_1_cst,
404
+ visc_t2_c=visc_t2_c,
405
+ visc_2_cst=visc_2_cst,
406
+ cp_15_kj_kgk=cp_15_kj_kgk,
407
+ thermal_expansion_beta=beta,
408
+ **kwargs, # type: ignore[arg-type]
409
+ )