-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhds_regime_example.py
More file actions
464 lines (380 loc) · 13.1 KB
/
Copy pathhds_regime_example.py
File metadata and controls
464 lines (380 loc) · 13.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
"""
HDS internal-diffusion regime screening example.
This module evaluates a deliberately simplified first-order reaction in an
isothermal spherical porous catalyst particle. It calculates the Thiele
modulus, the exact spherical-particle effectiveness factor, the model-implied
Weisz-Prater parameter, and a qualitative engineering screening statement.
Authoritative inputs
--------------------
Illustrative numerical inputs are loaded from:
data/example_parameters.csv
The shared loader validates the CSV structure, units, duplicate definitions,
case labels, and numerical values before the model is evaluated.
Scientific scope
----------------
The model assumes:
* a spherical porous particle;
* a first-order intrinsic rate law;
* an intrinsic rate coefficient expressed on a catalyst-particle-volume basis;
* constant effective diffusivity;
* isothermal operation;
* uniform pore structure;
* no external-film resistance;
* a known concentration at the external particle surface;
* no catalyst deactivation during the evaluated interval.
The numerical values are illustrative. They are not validated design data for
a specific hydrodesulfurization catalyst, feed, reactor, or industrial unit.
Evidence status
---------------
E3 -- executable engineering-screening research prototype.
Reference framework
-------------------
Reaction-Transport Regime Analysis for Desulfurization of Gas and Petroleum
Streams: An Engineering Diagnostic Framework.
"""
from __future__ import annotations
from dataclasses import dataclass
import math
from pathlib import Path
try:
from .example_parameter_loader import (
ParameterStore,
load_default_parameter_store,
)
except ImportError:
from example_parameter_loader import (
ParameterStore,
load_default_parameter_store,
)
SMALL_PHI_THRESHOLD = 1.0e-4
LARGE_PHI_THRESHOLD = 50.0
EXAMPLE_ID = "hds_internal_diffusion"
CASE_ID = "hds_default"
@dataclass(frozen=True, slots=True)
class HDSInternalDiffusionCase:
"""Input parameters for the simplified spherical-particle model.
Parameters
----------
name:
Human-readable case identifier.
particle_radius_m:
Catalyst-particle radius, m.
volumetric_rate_constant_s_inv:
Intrinsic first-order rate coefficient on a compatible catalyst
particle-volume basis, s^-1.
effective_diffusivity_m2_s:
Effective diffusivity of the representative sulfur species in the
porous particle, m^2/s.
"""
name: str
particle_radius_m: float
volumetric_rate_constant_s_inv: float
effective_diffusivity_m2_s: float
def __post_init__(self) -> None:
if not self.name.strip():
raise ValueError("Case name must not be empty.")
_require_finite_positive(
"particle_radius_m",
self.particle_radius_m,
)
_require_finite_nonnegative(
"volumetric_rate_constant_s_inv",
self.volumetric_rate_constant_s_inv,
)
_require_finite_positive(
"effective_diffusivity_m2_s",
self.effective_diffusivity_m2_s,
)
@dataclass(frozen=True, slots=True)
class HDSInternalDiffusionResult:
"""Calculated screening quantities."""
thiele_modulus: float
effectiveness_factor: float
model_implied_weisz_prater: float
internal_utilization_loss_percent: float
screening_statement: str
def _require_finite_positive(name: str, value: float) -> None:
"""Require a finite value strictly greater than zero."""
if not math.isfinite(value) or value <= 0.0:
raise ValueError(
f"{name} must be finite and greater than zero."
)
def _require_finite_nonnegative(name: str, value: float) -> None:
"""Require a finite value greater than or equal to zero."""
if not math.isfinite(value) or value < 0.0:
raise ValueError(
f"{name} must be finite and non-negative."
)
def thiele_modulus(
particle_radius_m: float,
volumetric_rate_constant_s_inv: float,
effective_diffusivity_m2_s: float,
) -> float:
"""Return the first-order Thiele modulus for an isothermal sphere.
The implemented relationship is:
phi = R_p * sqrt(k_v / D_eff)
The coefficient ``k_v`` must be expressed on a volumetric
catalyst-particle basis. A mass-based, external-area-based, or
active-site-based coefficient must first be converted to a compatible
volumetric basis.
"""
_require_finite_positive(
"particle_radius_m",
particle_radius_m,
)
_require_finite_nonnegative(
"volumetric_rate_constant_s_inv",
volumetric_rate_constant_s_inv,
)
_require_finite_positive(
"effective_diffusivity_m2_s",
effective_diffusivity_m2_s,
)
return particle_radius_m * math.sqrt(
volumetric_rate_constant_s_inv
/ effective_diffusivity_m2_s
)
def effectiveness_factor_sphere(phi: float) -> float:
"""Return the effectiveness factor for a first-order spherical particle.
The exact isothermal expression is:
eta = (3 / phi**2) * (phi / tanh(phi) - 1)
A series expansion is used for very small ``phi`` to avoid numerical
cancellation. A large-``phi`` asymptotic expression is used to avoid
unnecessary numerical loss.
"""
_require_finite_nonnegative("phi", phi)
if phi == 0.0:
return 1.0
if phi < SMALL_PHI_THRESHOLD:
phi_squared = phi * phi
eta = (
1.0
- phi_squared / 15.0
+ 2.0 * phi_squared * phi_squared / 315.0
)
elif phi > LARGE_PHI_THRESHOLD:
eta = 3.0 / phi - 3.0 / (phi * phi)
else:
eta = (
3.0
/ (phi * phi)
* (phi / math.tanh(phi) - 1.0)
)
# Floating-point protection for the theoretical interval 0 < eta <= 1.
return min(1.0, max(0.0, eta))
def model_implied_weisz_prater(
phi: float,
eta: float,
) -> float:
"""Return the model-implied Weisz-Prater parameter.
For the present first-order spherical model:
C_WP = eta * phi**2
This is a model-consistency quantity. In an experimental assessment,
the Weisz-Prater parameter should instead be constructed from:
* observed rate on a particle-volume basis;
* sulfur concentration at the external particle surface;
* particle radius;
* independently justified effective diffusivity.
Bulk concentration should not replace surface concentration when
external-film resistance is significant.
"""
_require_finite_nonnegative("phi", phi)
if not math.isfinite(eta) or not 0.0 < eta <= 1.0:
raise ValueError(
"eta must be finite and satisfy 0 < eta <= 1."
)
return eta * phi * phi
def classify_internal_diffusion(
phi: float,
eta: float,
) -> str:
"""Return an illustrative qualitative screening statement.
Classification is based primarily on internal catalyst utilization
represented by the effectiveness factor.
These categories are explicit screening conventions, not universal
design criteria. Project-specific limits should consider uncertainty,
catalyst cost, reactor configuration, pressure drop, and the acceptable
loss of catalyst utilization.
"""
_require_finite_nonnegative("phi", phi)
if not math.isfinite(eta) or not 0.0 < eta <= 1.0:
raise ValueError(
"eta must be finite and satisfy 0 < eta <= 1."
)
if eta >= 0.95:
return (
"Weak internal diffusion influence in this simplified model"
)
if eta >= 0.80:
return (
"Mild reaction-diffusion coupling in this simplified model"
)
if eta >= 0.50:
return (
"Significant reaction-diffusion coupling in this simplified model"
)
return (
"Strong internal diffusion influence likely in this simplified model"
)
def evaluate_case(
case: HDSInternalDiffusionCase,
) -> HDSInternalDiffusionResult:
"""Evaluate one internal-diffusion screening case."""
phi = thiele_modulus(
particle_radius_m=case.particle_radius_m,
volumetric_rate_constant_s_inv=(
case.volumetric_rate_constant_s_inv
),
effective_diffusivity_m2_s=(
case.effective_diffusivity_m2_s
),
)
eta = effectiveness_factor_sphere(phi)
weisz_prater = model_implied_weisz_prater(
phi=phi,
eta=eta,
)
return HDSInternalDiffusionResult(
thiele_modulus=phi,
effectiveness_factor=eta,
model_implied_weisz_prater=weisz_prater,
internal_utilization_loss_percent=(1.0 - eta) * 100.0,
screening_statement=classify_internal_diffusion(
phi=phi,
eta=eta,
),
)
def case_from_parameter_store(
store: ParameterStore,
) -> HDSInternalDiffusionCase:
"""Build the documented HDS case from the validated CSV dataset."""
return HDSInternalDiffusionCase(
name=store.case_label(
EXAMPLE_ID,
CASE_ID,
),
particle_radius_m=store.value(
EXAMPLE_ID,
CASE_ID,
"particle_radius_m",
expected_unit="m",
),
volumetric_rate_constant_s_inv=store.value(
EXAMPLE_ID,
CASE_ID,
"volumetric_rate_constant_s_inv",
expected_unit="s^-1",
),
effective_diffusivity_m2_s=store.value(
EXAMPLE_ID,
CASE_ID,
"effective_diffusivity_m2_s",
expected_unit="m^2/s",
),
)
def default_case(
store: ParameterStore | None = None,
) -> HDSInternalDiffusionCase:
"""Return the authoritative illustrative HDS case.
When no store is supplied, the repository CSV is loaded and validated.
"""
parameter_store = (
store
if store is not None
else load_default_parameter_store()
)
return case_from_parameter_store(parameter_store)
def render_results(
case: HDSInternalDiffusionCase,
result: HDSInternalDiffusionResult,
parameter_source: str | Path | None = None,
) -> str:
"""Return a human-readable screening report."""
lines = [
"HDS INTERNAL-DIFFUSION REGIME SCREENING",
"=" * 64,
f"{'Case':<31}: {case.name}",
]
if parameter_source is not None:
lines.append(
f"{'Authoritative input source':<31}: {parameter_source}"
)
lines.extend(
[
(
f"{'Particle radius':<31}: "
f"{case.particle_radius_m:.3e} m"
),
(
f"{'Volumetric rate coefficient':<31}: "
f"{case.volumetric_rate_constant_s_inv:.3e} s^-1"
),
(
f"{'Effective diffusivity':<31}: "
f"{case.effective_diffusivity_m2_s:.3e} m^2/s"
),
"-" * 64,
(
f"{'Thiele modulus, phi':<31}: "
f"{result.thiele_modulus:.4f}"
),
(
f"{'Effectiveness factor':<31}: "
f"{result.effectiveness_factor:.4f}"
),
(
f"{'Model-implied C_WP':<31}: "
f"{result.model_implied_weisz_prater:.4f}"
),
(
f"{'Internal utilization loss':<31}: "
f"{result.internal_utilization_loss_percent:.2f} %"
),
(
f"{'Screening statement':<31}: "
f"{result.screening_statement}"
),
"",
"Scientific interpretation:",
(
"The effectiveness factor represents internal catalyst "
"utilization only under the stated first-order, isothermal, "
"spherical-particle assumptions."
),
(
"The model does not include external-film resistance, "
"hydrogen transport, competitive adsorption, "
"sulfur-species-dependent kinetics, catalyst deactivation, "
"heat effects, pore-size distributions, or reactor "
"hydrodynamics."
),
"",
"Required validation before engineering use:",
(
"Use traceable kinetic and diffusivity data on compatible "
"bases; test particle-size sensitivity; evaluate external "
"mass transfer independently; characterize sulfur "
"speciation, pore structure, wetting, deactivation, "
"temperature, pressure, and feed composition; and quantify "
"uncertainty."
),
"",
"Evidence status:",
"E3 engineering-screening research prototype.",
]
)
return "\n".join(lines)
def main() -> None:
"""Load, validate, and evaluate the illustrative repository case."""
store = load_default_parameter_store()
case = case_from_parameter_store(store)
result = evaluate_case(case)
print(
render_results(
case=case,
result=result,
parameter_source=store.source_path,
)
)
if __name__ == "__main__":
main()