Skip to content
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

Addition of Jacobian Preconditioning Functionality to Cantera. #47

Open
anthony-walker opened this issue Apr 14, 2020 · 16 comments
Open
Labels
work-in-progress An enhancement that someone is currently working on

Comments

@anthony-walker
Copy link

Abstract

We are working on implementing a Jacobian preconditioning method to accelerate chemical kinetics for large mechanisms in Cantera. The specific technique is referred to as adaptive preconditioning by those who developed it at LANL (see references below). This method has been shown to provide speed up for kinetic models with more than roughly 100 species. It specifically preconditions with a reduced model that neglects third-body efficiencies and pressure dependence in reactions, and reduces the number of iterations necessary to obtain the Jacobian matrix used in implicit integration.

Motivation

Using kinetic models with a large number of species is computationally expensive. The goal of this implementation is to make simulations requiring larger and more complicated mechanisms more feasible. This could accelerate autoignition simulations for large models by one or two orders of magnitude. In addition, another application of interest is applying this to modeling atmospheric chemistry. Models for volatile organic carbons (VOC) and second organic aerosols (SOA) in the atmosphere can involve thousands of species, but current atmospheric simulations only use a few hundred species due to computational expense. This change will impact anyone interested in resolving large detailed kinetic models for any application. It is a good solution because it has shown potential to provide substantial speedup over traditional methods.

Description

A detailed description of the work being done. This may include examples of how the new feature will be used, intended use cases, and pseudo-code illustrating its use.
Jacobian preconditioning is a method used to accelerate solutions to systems of ODEs that require inversion of the Jacobian matrix. It works by applying an educated guess to the Jacobian prior to it being inverted which reduces the number of iterations necessary to invert the matrix. LANL’s method uses a reduced mechanism to precondition the Jacobian and leverage matrix sparsity. Their study showed promising results we intend to implement more generally for more cases.

References

McNenly, M. J., Whitesides, R. A., & Flowers, D. L. (2015). Faster solvers for large kinetic mechanisms using adaptive preconditioners. Proceedings of the Combustion Institute, 35(1), 581-587.

Github Fork

@anthony-walker anthony-walker added the feature-request New feature request label Apr 14, 2020
@kyleniemeyer
Copy link
Member

Another relevant link: the LLNL zero-rk software repo

@ischoegl
Copy link
Member

ischoegl commented Apr 20, 2020

This is a functionality that is really needed, so I am happy that this is being worked on. I ran a brief benchmark of Cantera vs Zero-RK for ignition delay times using relatively large mechanisms some time ago. These are the results on a low-end Xeon (no GPU):

                 nSpc   nRxn(CK)   nRxn(ct)   Cantera   Cantera(MKL)   Zero-RK
iso-octane:       874       3796       ~6k     28.4 s        20.69 s    2.62 s
n-hexadecane:    2115       8157      ~16k    173.9 s        80.77 s    4.31 s

In a nutshell, single threaded speedup of Zero-RK vs. Cantera is 10x to 40x, and MKL scales very poorly (8 threads). Bringing the same speed-up to Cantera (with its inherent flexibility) would be terrific.

@bryanwweber
Copy link
Member

Thanks @ischoegl Can you provide the script and/or conditions that you used for that benchmark?

@ischoegl
Copy link
Member

ischoegl commented Apr 20, 2020

@bryanwweber ... this was a while ago, and done on my office machine. Going through my command history, Zero-RK results are directly taken from shipped examples, i.e.

$ constVolumeWSR.x iso_octane_test.inp 
$ constVolumeWSR.x n_hexadecane_test.inp 

For cantera comparisons, I simply converted the Chemkin input to yaml (via ck2yaml), and ran constant pressure autoignition cases for the same initial conditions; only the simulation was timed. I.e. minor caveat: the Cantera test I ran is constant pressure, while Zero-RK is constant volume, which I believe should be inconsequential. I kept all other settings/tolerances at comparable levels.

Regardless, the speedup of Jacobian preconditioning has been documented by the original authors at LLNL (e.g. zork.pdf Fig. 2), i.e. computational effort scales roughly proportional to number of species, with conventional techniques scaling with number of species squared. Again, pretty happy that this may be coming to Cantera eventually!

@bryanwweber
Copy link
Member

which I believe should be inconsequential

As long as the end time is the same, and not based on an ignition condition, I would tend to agree 😄

Hopefully @awa1k3r and @kyleniemeyer can produce some similar benchmarks for comparison purposes!

@kyleniemeyer
Copy link
Member

kyleniemeyer commented Apr 20, 2020

One thing we have noticed: the LLNL approach (Zero-RK) only works for constant volume simulations; the approximations they have done will not work for constant pressure reactors. The approach we are working on will apply in either case.

@ischoegl
Copy link
Member

ischoegl commented Apr 20, 2020

Thanks, @kyleniemeyer. I haven't looked at the details, but what's currently available certainly has those limitations. From what I'm aware of, the status of the code uploaded to Github is circa 2017, and some of those limitations may have been relaxed since. I believe there is an updated release planned, but am not privy to exact details. Regardless, the important thing is that you are already working on this, so this is great ...

@kyleniemeyer
Copy link
Member

@ischoegl well, hopefully we are able to show some novel strategies soon/first 😄

I'm actually going off the paper/theory more than the code—the problem with their approach is that it actually relies on constant-volume combustion. With constant pressure, you fundamentally cannot avoid a dense Jacobian when using a state vector with mass fractions, due to the changing density that is affected by all species.

Instead, we are looking at changing the state vector to include pressure/volume and then number of moles. This would make it possible to get a sparse Jacobian regardless of whether you are simulating constant pressure or constant volume (or whatever).

@ischoegl
Copy link
Member

@kyleniemeyer ... makes sense - as mentioned, I'm not sure what exactly they've been up to since.

@jiweiqi
Copy link

jiweiqi commented May 1, 2020

@kyleniemeyer Just for curious, if we adopt auto-differentiation to evaluate the Jacobian matrix, for example, using deep learning framework to get the Jacobian. how much the 0D calculation will be accelerated?

@kyleniemeyer
Copy link
Member

@jiweiqi Good question! Our work with analytical Jacobians actually hasn't focused on cost reduction for implicit integration, but others have shown improvements from factor of 2-5 up to an order of magnitude for larger models (e.g., https://doi.org/10.1021/ef300747n)

@ischoegl
Copy link
Member

FWIW, Zero-RK Version 2.0 was just released, which includes a range of 0D and 1D solvers.

@anthony-walker
Copy link
Author

@ischoegl I will have to check it out. We're hoping to release our first version soon!

@ischoegl
Copy link
Member

ischoegl commented Aug 11, 2020

@anthony-walker ... that’s great to hear! I hope that it will become part of core Cantera soon, as this is where the functionality is greatly needed.

@anthony-walker
Copy link
Author

anthony-walker commented Jul 20, 2022

Cantera/cantera#1010 has added the core functionality of preconditioners to Cantera. There is still further improvements possible.

This includes:

  • Improving robustness
  • More rigorous testing for the preconditioner and mole reactors
  • Including surface chemistry
  • Extending to non-ideal gas reactors
  • More practical usage examples
  • Development of additional threshold guidelines for documentation

Additionally, further work could be used in considering if the finite difference temperature derivatives are helpful over the analytical derivatives.

@ischoegl @speth do you have additonal requests for this work? Otherwise, I believe this addresses the requested update from Cantera/cantera#1010 .

@speth
Copy link
Member

speth commented Jul 20, 2022

One other item I'd add to your list:

@speth speth added work-in-progress An enhancement that someone is currently working on and removed feature-request New feature request labels Aug 6, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
work-in-progress An enhancement that someone is currently working on
Projects
None yet
Development

No branches or pull requests

6 participants