Modifying reaction parameters on the fly using Cantera 2.5

550 views
Skip to first unread message

Adhiraj Dasgupta

unread,
Sep 12, 2019, 5:15:48 PM9/12/19
to Cantera Users' Group
Hello all,

I am using an in-house chemistry optimization program in conjunction with Cantera. Essentially I want to optimize some reaction(s) in a given chemical mechanism. This involves running multiple calculations using Cantera, and varying the reaction parameters .


Thus what I need to do is this:

1. Read the mechanism (cti file) into Cantera.

2. Access the reaction parameters (A, n, E, order) for all reactions, and change them when needed.


I have attached a minimal working example with this post. In it, I read in a made-up mechanism data, and loop over all elementary reactions.

However, trying to change the reaction order is not affecting the reaction rate, as can be seen on the output: the rate of reaction (rop_fwd) is not changed when I try to modify the reaction order. 

I can successfully change the parameters A, n, and E, and it is only the reaction order that I am unable to change.

How do I update the reaction order on the fly using Cantera, within the framework of the example program I wrote?

Any help will be appreciated.

Thank you.
modifyReactions.cpp
Makefile
output.txt
SampleMech.cti

Bryan W. Weber

unread,
Sep 13, 2019, 11:44:23 AM9/13/19
to Cantera Users' Group
Hello,

When I've needed to do something like this in the past, I've create a string variable that represents the CTI file, with format spots for where I need to fill in values. Then, I create a new Solution object each time I modify the string. Something like:

cti_str = """\
units(...)
...
reaction(..., order="{o_spec}:{o_1}")
""".format(o_spec="species_name", o_1=3.0)
gas = ct.Solution(source=cti_str)

Of course, this works in Python, I'm not sure how to do that in C++. Although it is slower, you could write a new CTI file with each change and then read it in with the updates.

Best,
Bryan

Ray Speth

unread,
Sep 13, 2019, 3:13:16 PM9/13/19
to Cantera Users' Group

Hi,

Currently, this can’t be done using the modifyReaction method — only the parameters of the rate constant can be changed. This is specified in the documentation for the method: “The stoichiometric equation, type of the reaction, reaction orders, third body efficiencies, reversibility, etc. must be unchanged.”

Regards,
Ray

On Thursday, September 12, 2019 at 5:15:48 PM UTC-4, Adhiraj Dasgupta wrote:

Adhiraj Dasgupta

unread,
Sep 16, 2019, 11:59:22 AM9/16/19
to Cantera Users' Group
Bryan and Ray:

thanks for the replies.

The code has to be in C++, so using Python is not an option for me.

I saw that the modifyReaction function can only be used to change the rate coefficient, and so I was trying to access and modify the orders like this (in the example I attached to my original post):


// Get access to the orders
 Composition& orders(size_t iRxn)
 {
     return m_reactions[iRxn]->orders;
 }

//Change the orders
for
(
    Composition::iterator it0 = orders.begin();
    it0 != orders.end();
    it0 ++
)
{
    (*it0).second = 2.0*(*it0).second;
}



Is there a way to do this correctly, so that  the reaction rates are computed using the updated orders?

Thanks.


Ray Speth

unread,
Sep 16, 2019, 1:31:50 PM9/16/19
to Cantera Users' Group

Adhiraj,

The way that the Kinetics object works is that it makes copies of the parameters in Reaction objects when the reactions are added to the kinetics manager, putting these values into various arrays so that they can be used efficiently for repeatedly evaluating rates. The original Reaction object is rarely used after this. This is the reason the modifyReaction method is necessary in the first place — changes to the rate constant of a Reaction object would otherwise have no effect. The problem you are running into is that modifyReaction doesn’t support your use case — it only updates the internal parameters associated with the rate constant, not reaction orders or other parameters.

If you’re trying to optimize a parameters for a mechanism with only a small number of reactions, it may be efficient enough to delete and recreate the Kinetics object each time. You can reuse the ThermoPhase object, and if you’re doing ReactorNet simulations, you should be able to reuse the Reactor object as well by calling setKineticsMgr with the new Kinetics object.

Regards,
Ray

Adhiraj Dasgupta

unread,
Oct 6, 2019, 11:38:15 AM10/6/19
to Cantera Users' Group
Ray,

thanks for the update.

Can you point me to the data array that stores the order information in Kinetics? 

My working gas is inherited from IdealGasMix. Is there some function I can call to access this data?

Thanks.
Reply all
Reply to author
Forward
0 new messages