(self, gas, spc_ix, mode=None, const_t=True, rtol_deltac=1e-6,
atol_deltac=1e-20, ddX=True)
| 491 | assert drate[spc_ix] == approx(drate_num[spc_ix], rel=self.rtol) |
| 492 | |
| 493 | def rate_ddX(self, gas, spc_ix, mode=None, const_t=True, rtol_deltac=1e-6, |
| 494 | atol_deltac=1e-20, ddX=True): |
| 495 | # numerical derivative for production rates with respect to mole fractions |
| 496 | def calc(mode): |
| 497 | if mode == "creation": |
| 498 | return gas.creation_rates |
| 499 | if mode == "destruction": |
| 500 | return gas.destruction_rates |
| 501 | if mode == "net": |
| 502 | return gas.net_production_rates |
| 503 | |
| 504 | tpx = gas.TPX |
| 505 | |
| 506 | rate0 = calc(mode) |
| 507 | conc = gas.concentrations |
| 508 | ctot0 = conc.sum() |
| 509 | |
| 510 | # perturb concentration |
| 511 | dconc = conc[spc_ix] * rtol_deltac + atol_deltac |
| 512 | conc[spc_ix] += dconc |
| 513 | ctot1 = conc.sum() |
| 514 | if const_t: |
| 515 | # adjust pressure to compensate for concentration change |
| 516 | pnew = gas.P * ctot1 / ctot0 |
| 517 | gas.TPX = gas.T, pnew, conc / ctot1 |
| 518 | else: |
| 519 | # adjust temperature to compensate for concentration change |
| 520 | tnew = gas.T * ctot1 / ctot0 |
| 521 | gas.TPX = tnew, gas.P, conc / ctot1 |
| 522 | drate = (calc(mode) - rate0) / dconc |
| 523 | |
| 524 | gas.TPX = tpx # reset state |
| 525 | # cantera calculates kinetics derivatives with respect to mole fractions |
| 526 | # and concentrations, when ddX flag is true it will return the numerical |
| 527 | # derivatives in the form of mole fractions but otherwise return concentrations |
| 528 | if ddX: |
| 529 | return drate * gas.density_mole |
| 530 | else: |
| 531 | return drate |
| 532 | |
| 533 | def test_creation_ddX(self, gas, rix, pix): |
| 534 | # check derivatives of creation rates with respect to mole fractions |
no test coverage detected