Closed ghost closed 6 years ago
Hi @chengdi123000, yes, for the Jacobian based on a constant-pressure system, the Jacobian is dense—almost all elements are nonzero. This happens because all species mass fractions contribute to density, which shows up in the time derivative of species mass fraction, and thus all species are "connected" to each other in the Jacobian. You can read a bit more about this in Section 3.3 of our article describing pyJac:
Kyle E. Niemeyer, Nicholas J. Curtis, and Chih-Jen Sung. 2017. “pyJac: analytical Jacobian generator for chemical kinetics.” Computer Physics Communications, 215:188–203. https://doi.org/10.1016/j.cpc.2017.02.004 | Available at https://arxiv.org/abs/1605.03262
We are currently working on v2 of pyJac which will enable a sparse formulation—this is almost ready to share! For updates, please follow this repository, or join the SLACKHA user group here: https://groups.io/g/slackha-users/join (the mailing list is extremely low volume).
You could try counting nonzeros by a threshold. Something like np.sum(np.abs(J) > 1.e-12)
ought to do the trick (I haven't tested that).
I should also point out that we currently formulate the exact Jacobian; it may be possible to increase the sparsity of the current constant-pressure formulation by introducing some approximations, but we haven't done this yet.
I once played around and tested to increase sparsity of the Jacobian by easily applying different threshold levels after which the element is forced to zero. I used gri3 and jacobian was created with the Cp assumption in pyjac. I noticed that the ODE solver was able to solve the problem but it took quite a bit more internal steps, making the overall cpu-time higher than with a dense and accurate jacobian. For the sparse tests I applied sparse linear algebra (KLU package). The greater number of integration steps + medium sparsity levels were not enough to make any speedup.
So lessons learned: zeroing jacobian elements by thresholding may not be a good idea for a priori dense jacobian. At least I'm doubting it's generality. Story could be different with larger mechanisms...
Great to hear that pyjac V2 is soon ready.
Cheers, HK
@kyleniemeyer Thank you very much for your reply!
@michael-a-hansen Thresholding is not a good idea. It depends on what the Jacobian is used for. For quasi-Newton methods, inexact Jacobian is useful with the cost of more steps. For eigen value and vectors, sometime it becomes sensitive to the small numbers for chemical kinetics. Considering energy in the system, small perturbation of radical may influence heavily.
@chengdi123000 agreed. If the goal is to estimate sparsity, however, it might be useful to use a threshold to eliminate numbers on the order of machine epsilon. That's all I was suggesting.
@chengdi123000 I'm going to close this issue as it appears to be resolved
@arghdos OK
about 98% of the elements are not zero?
output looks like: