Cantera / enhancements

Repository for proposed and ongoing enhancements to Cantera
11 stars 5 forks source link

Addition of Jacobian Preconditioning Functionality to Cantera. #47

Open anthony-walker opened 4 years ago

anthony-walker commented 4 years ago

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

kyleniemeyer commented 4 years ago

Another relevant link: the LLNL zero-rk software repo

ischoegl commented 4 years ago

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 commented 4 years ago

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

ischoegl commented 4 years ago

@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 commented 4 years ago

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 commented 4 years ago

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 commented 4 years ago

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 commented 4 years ago

@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 commented 4 years ago

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

jiweiqi commented 4 years ago

@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 commented 4 years ago

@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 commented 4 years ago

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

anthony-walker commented 4 years ago

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

ischoegl commented 4 years ago

@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 commented 2 years ago

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

This includes:

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 commented 2 years ago

One other item I'd add to your list: