-
-
Notifications
You must be signed in to change notification settings - Fork 359
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Sparse Jacobians for GasKinetics #1089
Conversation
Codecov Report
@@ Coverage Diff @@
## main #1089 +/- ##
==========================================
+ Coverage 65.15% 65.35% +0.19%
==========================================
Files 315 315
Lines 45389 45995 +606
Branches 19279 19531 +252
==========================================
+ Hits 29574 30060 +486
- Misses 13347 13443 +96
- Partials 2468 2492 +24
Continue to review full report at Codecov.
|
999158e
to
57c7e23
Compare
8814012
to
c0114bb
Compare
ff9ea65
to
27c99c4
Compare
This comment has been minimized.
This comment has been minimized.
376faa5
to
f2d5fdc
Compare
Adding a sample for speed tests (
|
44d7128
to
feae7a8
Compare
I believe this is ready for review / testing. |
5efb7e5
to
d362122
Compare
a7a7435
to
ac1a9ab
Compare
Adding a minor update to the Jacobian benchmark sample to illustrate the impact of number of species on performance. Here are some results for doubling the number of species ('nDodecane_Reitz.yaml`):
Nothing else changed (I'm aware of some pending review comments). |
@anthony-walker ... thanks for your thoughts!
Yes and no. For the C++API, the main placeholders are in void getJacobianSettings(AnyMap& settings);
void setJacobianSettings(AnyMap& settings); which presumably should govern how derivatives are calculated (various assumptions for relative perturbations and treatment of 3rd-bodies).
That makes sense. For derivatives with respect to scalars, this is straight forward: void getNetProductionRates(doublereal* wdot); // existing
void getNetProductionRates_ddT(double* dwdot); // in analogy ...
void getNetProductionRates_ddP(double* dwdot);
void getNetProductionRates_ddC(double* dwdot); But for the derivative with respect to mole fractions ( |
I had been thinking about the need for an offset argument as well, so that may be a key part of the interface expansion. What I'm less sure about is whether it's generally useful to just update an existing |
Are these methods to apply a custom mapping to the a sparse representation of the derivatives? If so do you have methods to form the sparse mapping? I use the current
I am also using derivatives with respect to moles in #1010, is that a possibility here? |
@anthony-walker ... the jacobian settings are mainly to pass some assumptions to C++, e.g. from Python
... total or individual? Here, |
0c7f1a0
to
de3150d
Compare
@ischoegl Ah, I would most likely use the C++ interface. I will need a way to remap the output which I believe I discussed a bit in #1010. I can work on that when I start merging the two of them.
My approximate Jacobian based preconditioner is built from derivatives with respect to moles of individual species.
|
@speth / @anthony-walker ... thanks for your comments thus far. Based on what was said, I believe I will proceed as follows:
but leave |
It is equivalent, and uses an
I don't think that this is mutually exclusive: this PR should be using the same mapping as we discussed a while back; it's just that entries are shifted by an offset within the sparse element storage vector.
All it takes is to multiply Note: As mentioned somewhere above (in the collapsed portion) ... the derivatives here do not incorporate constraints posed by the EoS, which may be another difference. |
Also, add missing 'final' to Blowers-Masel rate
de3150d
to
4ec8cdc
Compare
In addition, reduce size reserved for derivative coefficients
4ec8cdc
to
5f49d1b
Compare
@speth ... thanks for responding to my queries quickly! At this point, I believe everything that was pointed out is addressed; let me know if there's anything else. Otherwise, this is ready for another round of reviews from my end. |
PS: While I'd suggest to leave tweaks of the internal C++
One alternative would be to pass a fully created PPS: The best approach here may be to leave the current C++ getters that return |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the updates, @ischoegl. Looks like you also found my one last request for update (regarding ReactionData::restore
) that GitHub was trying to hide.
@speth ... thanks for your prompt (and thorough!) review! Beyond: @anthony-walker I'd be happy to assist with blending this with #1010. Let me know ... |
Changes proposed in this pull request
GasKinetics
gas.jacobian_settings
(Python API)ct.use_sparse()
(requires Scipy)The proposed enhancement is fully functional for Jacobians at constant pressure; some caveats remain:As the transition from old to new… addressedReactionRate
is not complete (Falloff
reactions remain to be ported), some band-aid implementations were necessary, which mostly affect temperature derivatives and a missing derivative term related to reaction rates depending on third-body concentrations.While the calculation of individual terms is optimized for speed, the addition of multiple sparse Jacobian terms is slow. A solution would involve the creation of internal buffers. As Jacobians are expected to be used elsewhere, I am leaving this up for discussion.Derivatives with respect to pressure - while relatively straightforward - are currently not implemented.… addressedWhile I am leaving the PR in draft status,- (edit: work is no longer draft) - I am explicitly welcoming feedback at this moment (@speth, @kyleniemeyer, @bryanwweber , @anthony-walker, @DavidAkinpelu, among others). It may make sense to discuss some more generic issues in Cantera/enhancements#100.If applicable, fill in the issue number this pull request is fixing
Closes #Cantera/enhancements#19
Supersedes #1081; incorporates changes proposed in #1088.
If applicable, provide an example illustrating new features this pull request is introducing
While calculations are handled by
<Eigen/Sparse>
internally, results are exposed to the Python API as:In order to avoid a lengthy interface, derivative evaluation depends on 'settings'.
All derivatives are checked against numerical implementations in unit tests.
Checklist
scons build
&scons test
) and unit tests address code coverageAdditional items: