Closed g-bauer closed 1 year ago
Here are some benchmarks for PC-SAFT comparing current main to this PR. Reported are %-changes is execution time.
For new_npt
, liq. and vap. means that liquid or vapor densities were chosen as initial densities, respectively, so no stability analysis is performed. The temperatures and pressures are chosen so that those phases are stable.
For the bubble and dew point benchmarks, the temperature is used as input.
methane | methane + ethane | methane + ethane + propane | |
---|---|---|---|
State::new_npt (liq) |
-9.7020% | -13.284% | -13.934% |
State::new_npt (vap) |
-9.4964% | -14.938% | -14.187% |
PhaseEquilibrium::tp_flash |
-1.7909% | -4.2929% | |
PhaseEquilibrium::bubble_point |
-3.7754% | -4.8505% | |
PhaseEquilibrium::dew_point |
-5.5984% | -9.8986% |
Note that these benchmarks fluctuate quite heavily (around +-1.5%) when ran multiple times. Not sure how to get more stable results.
This PR introduces the new variant
PartialDerivative::Second
and renames the existing variant toPartialDerivative::SecondMixed
.PartialDerivative::Second
can be used to calculate second order derivatives usingDual2
instead ofHyperDual
, which is sufficient for non-mixed derivatives and computationally less expensive.The new
PartialDerivative
looks like soWe can use this variant to calculate non-mixed second order derivatives like so:
The
Cache
, in which partial derivatives are stored, puts results intoPartialDerivative::SecondMixed
so that there are no cache misses when the derivatives are calculated with the (less efficient) variant that usesHyperDual
s.This change benefits the
density_iteration
function in which we currently repeatedly callIn the added benchmarks for different ways to create
State
s, this change shows an ~8-9% improvement (i.e. execution speed) for theState::new_npt
and an ~2-4% improvement forPhaseEquilibrium::tp_flash
although more systems should be added to get a proper idea of the impact.