|
8 | 8 | different reactor configuration. |
9 | 9 | """ |
10 | 10 |
|
| 11 | +import logging |
11 | 12 | import cantera as ct |
12 | 13 | import numpy as np |
13 | 14 | from abc import abstractmethod |
@@ -331,6 +332,9 @@ def simulate(self): |
331 | 332 | non_inert_mask = np.ones(self.num_ct_species, dtype=bool) |
332 | 333 | non_inert_mask[self.inert_index_list] = False |
333 | 334 |
|
| 335 | + if not np.all(np.isfinite(mass_frac_sa)): |
| 336 | + logging.getLogger(__name__).warning( |
| 337 | + 'NaN/inf detected in mass fraction SA matrix — check for numerical issues') |
334 | 338 | kin_correction = mass_frac_sa[non_inert_mask, :self.num_ct_reactions].sum(axis=0) |
335 | 339 | thermo_correction = mass_frac_sa[non_inert_mask, self.num_ct_reactions:].sum(axis=0) |
336 | 340 |
|
@@ -462,9 +466,17 @@ def get_idt_by_T(self): |
462 | 466 | time, data_list, reaction_sensitivity_data, thermodynamic_sensitivity_data = condition_data |
463 | 467 | T_data = data_list[0] |
464 | 468 |
|
465 | | - dTdt = np.diff(T_data.data) / np.diff(time.data) |
466 | | - idt_dict['idt_index'].append(int(np.argmax(dTdt))) |
467 | | - idt_dict['idt'].append(time.data[idt_dict['idt_index'][i]]) |
| 469 | + dt = np.diff(time.data) |
| 470 | + dt = np.where(dt == 0, np.finfo(float).tiny, dt) |
| 471 | + dTdt = np.diff(T_data.data) / dt |
| 472 | + valid = np.isfinite(dTdt) |
| 473 | + if valid.any(): |
| 474 | + masked = np.where(valid, dTdt, -np.inf) |
| 475 | + idx = int(np.argmax(masked)) |
| 476 | + else: |
| 477 | + idx = 0 |
| 478 | + idt_dict['idt_index'].append(idx) |
| 479 | + idt_dict['idt'].append(time.data[min(idx + 1, len(time.data) - 1)]) |
468 | 480 |
|
469 | 481 | return idt_dict |
470 | 482 |
|
|
0 commit comments