Sensitivity analysis using Cantera, python interface

1,787 views
Skip to first unread message

Alan Kong

unread,
Apr 7, 2015, 5:42:12 PM4/7/15
to canter...@googlegroups.com
Hi all,

I am using the sensitivity1.py files to carry out sensitivity analysis on my own kinetic mechanism to aid in the process of reduction
The mechanism I am using is similar to gri30 with some added reactions. Fuel is pure CH4 and oxidizer is pure O2 (no or very little diluent)

I noticed the files calculates the sensitivity of the rate coefficient but struggles to understand what is it calculating against? T, flame speed, species mole fraction?

Right now, I can only guess it is the sensitivity w.r.t to individual reaction??? This is infer from the code line below.

# enable sensitivity with respect to the rates of the first 10
# reactions (reactions 0 through 9)

Secondly, I tried running the default code just to check out what the output is. The last line states that:

To view a plot of these results, run this script with the option '--plot

I have matplotlib install. how do I port the directory into the script so that I can plot the graph?

Nick Curtis

unread,
Apr 7, 2015, 10:22:22 PM4/7/15
to canter...@googlegroups.com
The sensitivity reactions are a wrapper for CVodeGetSens, see this thread
If your python install has matplotlib, you should be able to plot by calling the script as follows:

./sensitivity1.py --plot

Nick

Alan Kong

unread,
Apr 8, 2015, 8:16:24 AM4/8/15
to canter...@googlegroups.com
Thanks Nick,

Manage to run the default code now and saw some plots. Are there any documentation and information on how to use this function sensitivity()in the code?

Another concern I had is whether this code can handle a large kinetic mechanisms. Currently I am playing around with 200+ species and 2200-2300 reactions. (All the more I need some computation power for that, else I will have to do by hand....)
At the same time, I also have CHEMKIN II to do similar calculation with and will be used to compare with Cantera.

Thanks for the help in advance!

Alan

Nick Curtis

unread,
Apr 8, 2015, 11:12:42 AM4/8/15
to canter...@googlegroups.com
Alan,
The Cantera documentation lists the various available methods.
To my understanding reactions are added using the add_sensitivity_reaction method, while the sensitivities can be queried via the following methods:

sensitivities(self)
sensitivity(self, species, int p, int r=0)

Note that the r parameter is (likely) an optional parameter indicating the reactor id.

The ReactorNet.h file also has some more details (in particular look at the comments above the various sensitivity methods)

As far as computational power, I'm not sure.  I have never done extensive sensitivity analysis before.  Perhaps someone else with more extensive experience can help.  However, I doubt that Chemkin will be significantly more efficient at it. 

One thing I would highly encourage you to do is to make sure your Cantera build is using an optimized BLAS/LAPACK library (e.g. mkl, atlas, etc.), as this can definitely speed up the matrix operations required w/ larger mechanisms

Nick

Ray Speth

unread,
Apr 8, 2015, 12:16:45 PM4/8/15
to canter...@googlegroups.com
Hi,

The documentation for the current development version (https://cantera.github.io/dev-docs/sphinx/html/cython/zerodim.html) is much more clear about the meaning of the parameters in the various sensitivity-related functions and what they return. 

Running mechanisms with several hundred species shouldn't be a problem, as long as you use the reactor models specifically for ideal gases, i.e. IdealGasReactor and IdealGasConstPressureReactor. The computational expense will increase as you add sensitivity parameters, so you may want to be somewhat selective about which reactions you want sensitivities from. I agree with Nick's advice about making sure you're using an optimized BLAS/LAPACK library when working with large mechanisms.

Regards,
Ray

Alan Kong

unread,
Apr 9, 2015, 5:26:41 AM4/9/15
to canter...@googlegroups.com
Hi Ray and Nick,

Thanks for the tips and the new documentation page! I will get on with optimizing the BLAS/LAPACK library.

Few last question, sorry about that, I just started using Cantera so I am a little confused with the all the module and function call available

1) Is there a option to calculate the sensitivities against final equilibrium T or heat release with the sensitivity() ? I am a little fuzzy with the theory here on which T to use at which time.

2) Secondly, what does the value on the arrow means in the reaction path diagram? Are they element flux? Is there currently a option to trace species flux like OH?

3) Which reactor is the best for adiabatic, constant volume condition. IdealGasReactor and IdealGasConstantPressureReactor has variable Volume which for my case is undesirable. is there a way to fixed the volume of the reactor?

4) Trying to incorporate 1D counterflow diffusion flames calculation into my reaction path diagram, is these possible?

Thanks in advance for all the great help!

Alan

Ray Speth

unread,
Apr 9, 2015, 10:39:01 AM4/9/15
to canter...@googlegroups.com
Alan,

1) The sensitivities are calculated for the current simulation time. Sundials Cantera gives you sensitivities of the state variables (i.e. temperature, volume, mass fractions) with respect to the reaction rate constants. If you want the sensitivity of a different quantity, you need to express that quantity in terms of the state variables, and then determine the various partial derivatives necessary to compute that sensitivity from the known ones. For an adiabatic, constant volume reactor, the sensitivity of the equilibrium temperature to any (reversible) reaction rate is zero.

2) Yes, the arrows indicate element fluxes. I'm not what it would mean to trace a species flux.

3) IdealGasReactor has a fixed volume unless you add a wall with a non-zero expansion rate coefficient.

4) The reaction path diagram tool currently only creates diagrams for a single point in space, not integrated over space or time. This would be a good capability to add at some point.

Regards,
Ray

Alan Kong

unread,
May 7, 2015, 6:05:54 AM5/7/15
to canter...@googlegroups.com
Hi Ray and Nick.

I have a short question of optimizing Cantera configurations in Windows installation.
 
Currently I do not know where this information is for Windows and also I tried editing the code in Cantera installation folder but apparently there is some restriction on modifying the code.

As for Sundials, I am trying to use CMake in windows to install and update to 2.6.0 but i had not been successful so far. I had heard that Sundials 2.6.0 has fixed some bugs in the solver used by Cantera and I am wondering if there is another way of compiling Sundials in Windows.

I am currently using Cantera 2.1.2, with Python 3.4.0 and Sundials 2.5.0.

Cheers

Alan

Nick Curtis

unread,
May 7, 2015, 11:00:01 AM5/7/15
to canter...@googlegroups.com
Alan,
Sundials 2.6.0 is not yet supported outside of the development version of Cantera (i.e. not 2.1.2)
There are very few restrictions on modifying the Cantera code in the src/ folder, the only thing I can think of off hand is that adding new files might not supported without going into the make/scons configs.  That said, make sure you rebuild and reinstall Cantera after modifying any source code, otherwise your changes will have no effect

Nick
Message has been deleted

Bryan W. Weber

unread,
May 7, 2015, 12:03:23 PM5/7/15
to canter...@googlegroups.com
Alan,

If you try to edit code in the installation directory of Cantera (e.g. if you installed from the binary files), it will not work because the typical installation directory (C:\Program Files\...) is protected by Windows. You need Administrator access to edit any files there. Anyways, you should not edit files in that folder and instead do as Nick suggests, to rebuild and reinstall after you edit the regular source code (downloaded separately) for Cantera.

Bryan

Alan Kong

unread,
May 8, 2015, 4:10:14 AM5/8/15
to canter...@googlegroups.com
Thanks Nick and Bryan for the advice.

I presume we need to use github to clone the development source code onto my laptop?

Thanks for the help

cheers

Alan

Bryan W. Weber

unread,
May 8, 2015, 6:53:15 AM5/8/15
to canter...@googlegroups.com
Hi Alan,

Yes, you should fork the GitHub repository into your account and clone your copy of it (if you want to contribute any changes back to the main repository), or if you just want the code, you can clone the main repository directly.

Best,
Bryan

Xiongbo Duan

unread,
Jun 30, 2019, 10:09:23 AM6/30/19
to Cantera Users' Group
Hi all,

Do you guys have some materials how to conduct sensitivity analysis, since Chemkin tutorials only mentions simply.

Thanks,
Xiongbo  


在 2015年4月7日星期二 UTC-7下午2:42:12,Alan Kong写道:

Weiqi Ji

unread,
Jul 1, 2019, 4:23:50 AM7/1/19
to Cantera Users' Group
Hi Xiongbo,

If you want to know the theory,math and history of the sensitivity analysis in combustion kinetics, you might check this book:
Turányi, T., & Tomlin, A. S. (2014). Analysis of kinetic reaction mechanisms (p. 363). Berlin: Springer.

Best,
Weiqi

Xiongbo Duan

unread,
Jul 1, 2019, 9:23:29 AM7/1/19
to canter...@googlegroups.com
Hi Weiqi,

Thanks for your recommendation of this book. That is really helpful.

Kind regards,
Xiongbo 

Weiqi Ji <jiwe...@gmail.com> 于2019年7月1日周一 上午1:23写道:
--
You received this message because you are subscribed to the Google Groups "Cantera Users' Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cantera-user...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/cantera-users/dc7c8c27-e18d-475a-8484-b8d19601eb89%40googlegroups.com.

Mick Carter

unread,
Jul 1, 2019, 12:58:45 PM7/1/19
to Cantera Users' Group
Hi Xiongbo,

Have you had a look at this example? I found the cell `In [10]` very helpful as a demonstration of how to calculate a normalized sensitivity parameter using the `set_multiplier` method.

Xiongbo Duan

unread,
Jul 1, 2019, 10:20:52 PM7/1/19
to canter...@googlegroups.com
Hi Mick,
Thanks, I am learning this example, thanks for your recommendation.

Best,
Xiongbo 

Sent from my iPhone
--
You received this message because you are subscribed to the Google Groups "Cantera Users' Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cantera-user...@googlegroups.com.

Kévin Bioche

unread,
Jun 20, 2022, 9:27:26 AM6/20/22
to Cantera Users' Group
Hello all.

Regarding the fourth comment here. Was there developments to allow producing reaction path diagram integrated over space (e.g. on a 1D flame). Either an automatic tool or a specific "trick" process ?

Best,
Kévin

Bryan Weber

unread,
Jun 21, 2022, 10:33:46 AM6/21/22
to Cantera Users' Group
Hi Kévin,

No, sorry, there hasn't been any progress on this. The simplest way would be to do a trapezoidal integration, but that's not possible automatically within Cantera at the moment.

Best,
Bryan

Liang Ji

unread,
May 1, 2023, 9:57:44 PM5/1/23
to Cantera Users' Group
Hi Nick,

Your respond is very helpful for my question.  I am wondering if there is any other way to add/edit cpp code without reinstall/rebuild of Cantera.

Previous I add the file path to cmake.list after "added_executable". It works but sometime it is very slower than normal.

Do you have any other suggestion? Thanks for your help.

Best Regards
Liang

CMakeLists.txt
Reply all
Reply to author
Forward
0 new messages