Add non-mixed second order derivatives to State property evaluation#94
Add non-mixed second order derivatives to State property evaluation#94
State property evaluation#94Conversation
| self.map | ||
| .insert(PartialDerivative::First(derivative), value.v1[0]); | ||
| self.map | ||
| .insert(PartialDerivative::SecondMixed(derivative, derivative), value.v2[0]); |
There was a problem hiding this comment.
I was irritated by the comment in your initial post. Now that it is implemented, it is clear that there is no overlap between the two variants, so using PartialDerivative::Second as key for the HashMap is probably simpler to comprehend.
Using both to avoid additional calculations if someone "incorrectly" uses mixed derivatives is probably unnecessary as the relevant functions are not supposed to be used outside of core and the benchmarks anyways.
There was a problem hiding this comment.
I would not (and do not) use both, but we can use SecondMixed exclusively to cover the case of e.g. PartialDerivative::SecondMixed(DV, DV). I am fine with both options to be honest :)
|
Here are some benchmarks for PC-SAFT comparing current main to this PR. Reported are %-changes is execution time.
Note that these benchmarks fluctuate quite heavily (around +-1.5%) when ran multiple times. Not sure how to get more stable results. |
…ances for given temperature and pressure
This PR introduces the new variant
PartialDerivative::Secondand renames the existing variant toPartialDerivative::SecondMixed.PartialDerivative::Secondcan be used to calculate second order derivatives usingDual2instead ofHyperDual, which is sufficient for non-mixed derivatives and computationally less expensive.The new
PartialDerivativelooks 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::SecondMixedso that there are no cache misses when the derivatives are calculated with the (less efficient) variant that usesHyperDuals.This change benefits the
density_iterationfunction in which we currently repeatedly callIn the added benchmarks for different ways to create
States, this change shows an ~8-9% improvement (i.e. execution speed) for theState::new_nptand an ~2-4% improvement forPhaseEquilibrium::tp_flashalthough more systems should be added to get a proper idea of the impact.