Re: How do I use Cantera in Julia?

309 views
Skip to first unread message
Message has been deleted

R Surya Narayan

unread,
Dec 13, 2020, 11:33:58 AM12/13/20
to Cantera Users' Group
Hello all,
I finally found a way of running Cantera in Julia using PyCall. For the benefit of new users who had the same question, I am posting what I did. 
Step 1: Go to the Cantera Downloads page and install Cantera in your system using Python installation. Follow the steps in the website as is and test if Cantera works in the Python IDLE. Copy the location of the python.exe.
Step 2: Open the Julia interpreter/REPL in your IDE (I used Juno) and use the following commands to add PyCall.
julia>>using Pkg
julia>>Pkg.add("PyCall")
Step 3: Once Julia is done updating its registries, update the local python environment that has the Cantera installation using the following commands:
julia>>using PyCall
julia>>ENV["PYTHON"] = "location of the python.exe"
(The location should look something like C:\Users\hi\AppData\Local\Programs\Python\Python37)
Step 4: Rebuild PyCall using: 
julia>>using Pkg
julia>>Pkg.build("PyCall")
Step 5: STOP Julia and restart. 
Step 6: Test run Cantera in the Julia REPL using the following commands
julia>>using PyCall
julia>>pyimport("cantera")
PyObject <cantera.composite.Solution object at 0x000000004581D908>
julia>>gas1=cantera.Solution("gri30.xml")
gri30:

       temperature             300  K
          pressure          101325  Pa
           density       0.0818891  kg/m^3
  mean mol. weight         2.01588  amu

                          1 kg            1 kmol
                       -----------      ------------
          enthalpy           26470        5.336e+04     J
   internal energy     -1.2109e+06       -2.441e+06     J
           entropy           64914        1.309e+05     J/K
    Gibbs function     -1.9448e+07        -3.92e+07     J
 heat capacity c_p           14312        2.885e+04     J/K
 heat capacity c_v           10187        2.054e+04     J/K

                           X                 Y          Chem. Pot. / RT
                     -------------     ------------     ------------
                H2              1                1         -15.7173
     [  +52 minor]              0                0

NOTE: Pls note that julia uses double quotes instead of single quotes inside the Solution() function. The python version works with single quotes. 
Julia throws the following error if single quotes are used. 
ERROR: syntax: character literal contains multiple characters


On Sunday, 13 December 2020 at 01:20:14 UTC+5:30 R Surya Narayan wrote:
Hello everyone, I am trying to implement a chemically coupled method of characteristics application for designing a rocket nozzle, and I feel Cantera has all I need in terms of chemistry and kinetics. Any suggestions on how I can invoke Cantera via Julia will be helpful as I have written the bulk of my code for the main program in Julia. I am using the Juno editor in atom IDE. 
After going through the google groups I figured there's a way using PyCall in Julia but users have reported it to be unstable ( I'd want to try it out nonetheless and am looking for guidance) 
Thanks 
Surya

Steven DeCaluwe

unread,
Dec 14, 2020, 12:39:49 AM12/14/20
to canter...@googlegroups.com
Many thanks, Surya!  This is very useful information.

Best,
Steven

--
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/9cf7e35f-109e-4688-a821-462b52317783n%40googlegroups.com.

R Surya Narayan

unread,
Dec 14, 2020, 3:01:45 AM12/14/20
to Cantera Users' Group
Your welcome :) Mr.Steven

Weiqi Ji

unread,
Feb 19, 2021, 11:58:30 PM2/19/21
to Cantera Users' Group
Hi Surya,

Just saw this discussion. I have been working on a native Julia package for combustion those days, called Arrhenius.jl at https://github.com/DENG-MIT/Arrhenius.jl. I made the initial version within a couple of hours since it is built on top of Cantera's mechanism interpreter! Part of the reason to make it is to avoid the pain of coupling between python and Julia ... But the most important motivation is to have a native Julia code so that we can use Julia's auto-differentiation packages.

I assume what you are looking for is the reaction source term since it is relatively simple to code governing equations. If that's the case, definitely check out the package.

Best,
Weiqi

R Surya Narayan

unread,
Feb 20, 2021, 5:01:49 AM2/20/21
to Cantera Users' Group
Hello Weiqi 
Thanks for the update on this. I have indeed been looking for the reaction source term to integrate 1-D finite rate chemistry along a streamline. Could I know if this gives the same as cantera's "net_production_rates" function? 
Thanks

Message has been deleted

Ingmar Schoegl

unread,
Feb 20, 2021, 8:04:02 PM2/20/21
to Cantera Users' Group
Hi Surya,

Could you post a feature request to start a discussion on ideas for a Julia/Cantera integration on https://github.com/Cantera/enhancements? (Ray also had some thoughts on https://github.com/Cantera/enhancements/issues/39, but I think some discussions should be more specific.) Also, it may make sense to reformat your initial post in form of a 'Gist' and link to it. It would be good to have a discussion of merits of building within the existing code base versus a complete re-implementation like Arrhenius.jl. Best,

-ingmar-

R Surya Narayan

unread,
Feb 20, 2021, 11:38:46 PM2/20/21
to Cantera Users' Group
Hello Dr.Schoegel
I shall do that. It would be a great way of starting discussions on building a new Cantera from scratch or having cantera integrated with Julia (as I did in my initial post).
Best
Surya
Reply all
Reply to author
Forward
0 new messages