compile C++&python scripts with cantera

284 views
Skip to first unread message

Yu Ji

unread,
Apr 12, 2021, 9:37:01 AM4/12/21
to Cantera Users' Group
Hello everyone,

I'm using cantera 2.5.0 on windows with VSCode, but encountered some problems when compiling P-R EoS class(cpp & h files):
(1) What should I do to prepare relevant config files in VSCode? By now, I cloned the project for github and assigned it as workspace but Boost library couldn't be included. I tried to build Boost with this instruction (https://roboticslab-uc3m.github.io/installation-guides/install-boost.html#install-boost-windows), but Visual Studio is needed(vswhere).
(2) I've prepared cti input (with a, b and omega) for python scripts, What else should I modifify to read from cti files? (current error is: name 'PengRobinsonMFTP' is not defined)
(3) Is there a easier way to construct input files (in cti or yaml format) from ChemKin inputs with parameters in non-ideal EoS, or convert such cti file into yaml file? I've constructed cti input for R-K EoS, but couldn't convert it into corresponding yaml files (by ctml2yaml method). So I further conducted it on nDodecane_Reitz.cti (used in example 'nonidealshocktube.py') and received similar error message (xml.etree.ElementTree.ParseError: not well-formed (invalid token)). How to correct such files?

Sorry for so many questions but I was totally confused about the compilation process. I would appreciate any guide.

Yu

Ingmar Schoegl

unread,
Apr 12, 2021, 1:17:38 PM4/12/21
to Cantera Users' Group
Hi Yu,

Those are good questions ... For (1) compilation from source uses the 'scons' build system irrespective of operating system; while there may be a way to configure VSCode to build, I'm not aware of it (others may though); it's still a very good editor if you need to look at / change source code. For compilation questions, you should find some pointers on cantera's website or in previous threads on this forum; if there's anything beyond, this is still the right place to ask, though! For (2), Peng-Robinson is still under development, so it's not part of the standard package yet. For further information, see here: https://github.com/Cantera/cantera/pull/641. For (3), the standard examples should work; there is a nDodecane_Reitz.yaml available also (https://github.com/Cantera/cantera/blob/main/data/nDodecane_Reitz.yaml), which may provide some insights. Please note that CTI will be phased out, and YAML will become the standard.

-ingmar-

Yu Ji

unread,
Apr 13, 2021, 8:58:54 AM4/13/21
to Cantera Users' Group
Hello Mr. Ingmar,

Thanks for your generous help, but I'm still confused about these questions:
(1) I change to compile cantera via Visual Studio, and take many useful references from https://groups.google.com/g/cantera-users/c/gS0F2MpvRvc/m/-CtyXB1qBgAJhttps://gist.github.com/ischoegl/ab777f871a48d7f40ecc32c1c849faa3. I also try to compile with scons via Git bash, but don't make much progress. Specifically, I installed boost library, yet scons couldn't found it (even if I specified the path in 'cantera.conf').
(2) Apart from P-R EoS, I also plan to work out another EoS class into cantera, but I'm not sure how to integrate them with cantera ,compile them, and use them with prepared inputs. 
(3) As you said, CTI intput would be replaced by YAML input gradually, so I'd like to change my cti inputs (based on another kinetic model for R-K EoS) into yaml inputs, but receive error message (xml.etree.ElementTree.ParseError: not well-formed (invalid token)). What modification should I make in my cti file to correct such error?

Yu

Ingmar Schoegl

unread,
Apr 13, 2021, 1:41:58 PM4/13/21
to Cantera Users' Group
Hi Yu,
ad (1) the gist instructions (at least at this point) use the VS compilers from the command line, and rely on `scons` to handle the build process. In theory, you never need to open the graphical interface (I have never used it in another context, this unfortunately goes beyond my own experience.) Regarding the boost issue, make sure that you have your conda environment activated and set up as recommended. Note that there are also other tutorials on how to get your system set up (see https://cantera.org/compiling/installation-reqs.html#sec-windows ... as I have no recent experience with that process, I cannot comment).
For (2) and (3), I believe this may deserve a separate thread.
-ingmar-

Yu Ji

unread,
Apr 15, 2021, 7:55:02 AM4/15/21
to Cantera Users' Group
Hello Ingmar,

I've completed the compilation and the tests with your help, thanks a lot. But I'm afraid there is a small question: how to use them on .cpp or .py files? I tried the simpletest.cpp but encountered errors. Is it achieveable to run cpp/py scripts via git bash? For (2) and (3), I'll start a new thread later.

Yu
FE}_O00%MATRB7DXZHARYR5.png
3%6Z6FRY}X2{@3(4L%$3O)H.png
D%M6[`5VDC4TWM3{3IC`R4K.png

Bryan Weber

unread,
Apr 15, 2021, 9:36:35 AM4/15/21
to Cantera Users' Group
Hi Yu

If this is a C++ program, you have to compile it using whatever C++ compiler you have configured. If it is a Python script, you have to run it with Python, e.g., python name_of_script.py

Best,
Bryan

Yu Ji

unread,
Apr 15, 2021, 11:27:19 PM4/15/21
to Cantera Users' Group
Hello Byran

Thank for your reply. I've compiled and installed cantera before. And I tried to compile my cpp file as well as run python scripts, but it seemed that cantera is not included in the environment. What else should I do to include it?

Yu
X$9_7@YQ]`E}(T_@FO_EPDW.png
H[CSL$USC_[I~MWBR8LNB}H.png
4DFVJZ4Z0)~YDL{LX5}[ODY.png
F9V~I`1(DT{MQ{O)SHNJ5IA.png

Ingmar Schoegl

unread,
Apr 16, 2021, 12:39:59 AM4/16/21
to Cantera Users' Group
Hi Yu,

Cantera is installed inside the conda environment (see note at the bottom of the Gist write-up) - did you activate it?

-ingmar-

--
You received this message because you are subscribed to a topic in the Google Groups "Cantera Users' Group" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/cantera-users/_bcq0utPjBk/unsubscribe.
To unsubscribe from this group and all its topics, send an email to cantera-user...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/cantera-users/1995327b-c8ec-4347-a123-34ac0aae604en%40googlegroups.com.

Yu Ji

unread,
Apr 16, 2021, 2:36:41 AM4/16/21
to Cantera Users' Group
Hi Ingmar,

thanks for your prompt response. I did activate the environment (named cantera),  and followed your instructions to prepare conda environment and cantera. But still, when I run py scripts or compile c++ programs with g++, cantera was not included. I'm really confused.

Yu
3678]JLSF[84G)3B03~SO$R.png
RLY62(IQQ7$@E3MWU$A6_{N.png
{54OP34]@$D{~]EWKQ4~B_2.png
1MO7YJQ@Z34JVCU3C(S3MRQ.png

Ingmar Schoegl

unread,
Apr 16, 2021, 7:12:14 AM4/16/21
to canter...@googlegroups.com
Ok - yes, I saw that you were able to install Cantera based on the previous discussion. However, when using it you need to likewise have the conda environment activated, as everything is tied to this environment, I.e. outside of this environment a compiler (or Python, for that matter) will not be able to locate Cantera.

-Ingmar-

Yu Ji

unread,
Apr 16, 2021, 7:56:18 AM4/16/21
to Cantera Users' Group
Hello Ingmar,

Thanks for your reply. Can I understand it as you can run py script and compile cpp file only under conda cantera environment? In my screenshot I deactivated present environment and activated cantera environment in conda, then I used python to run a py script, but still raised similar error? Do I need other package to support it? I used MINGW64 for c++, and python 3.8 for python.

Yu
OBHJ~5_ZYGR7)VJHO(H6SAI.png

Ingmar Schoegl

unread,
Apr 16, 2021, 10:36:58 AM4/16/21
to Cantera Users' Group
I just ran the following on my machine (on the Anaconda powershell) - my environment is cantera-dev just like on the Gist:

(base) PS C:\Users\ischo> conda activate cantera-dev
(cantera-dev) PS C:\Users\ischo> ipython
Python 3.8.3 (default, Jul  2 2020, 17:30:36) [MSC v.1916 64 bit (AMD64)]
Type 'copyright', 'credits' or 'license' for more information
IPython 7.16.1 -- An enhanced Interactive Python. Type '?' for help.

In [1]: import cantera as ct

In [2]: ct.__version__
Out[2]: '2.6.0a1'

I.e. you'd change into the environment, and then run python. Similarly, you'd have to make sure that the entire Visual Studio context is set up for compilation of C++ code. I.e. you will have to repeat the second step of what you did for setting up the conda environment (the vcvars64.bat). For this tool chain, those things are not persistent.
-ingmar-


Ingmar Schoegl

unread,
Apr 16, 2021, 11:03:15 AM4/16/21
to Cantera Users' Group
PS: As it looks like you used MINGW64 for c++, I'm not exactly sure how this would work (I used a different compiler). You'd still need to make sure that all the paths are set the same way.

Yu Ji

unread,
Apr 17, 2021, 3:36:36 AM4/17/21
to Cantera Users' Group
Hello Ingmar and byran,

I tested cantera as you mentioned, but raised error "cantera has no attribute '__version__'". So I uninstalled cantera, turned to use MSVC and exactly followed your instructions, and now it works well with python.
For Visual Studio, I launched it under conda cantera-dev environment (using command 'start devenv') and add cantera & boost into additional library, but raised the following question:
unresolved external symbol "class Cantera::ThermoPhase * __cdecl Cantera::newPhase(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >)" (?newPhase@Cantera@@YAPEAVThermoPhase@1@AEBV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@V34@@Z)

To solve it, I added cantera.lib (in cantera\lib), but encountered another question:
LNK2038 mismatch detected for '_iterator_debug_level' value '2'(in simpletest.obj)

So I switched to 'Release' mode and compile again, it worked well.
PAOZ%UPCDQ3YRDRIW~S5}X.png
Now I can start my work on cantera. Thanks for your generous help.

Yu

Ingmar Schoegl

unread,
Apr 17, 2021, 11:42:50 AM4/17/21
to Cantera Users' Group
Hi Yu,
I'm pretty happy to hear that you got this to work. Windows toolchains are pretty hard to set up; the main reason I used conda here was it's much easier to set up the boost libraries.
-ingmar-

litian SU

unread,
Dec 7, 2021, 2:24:15 AM12/7/21
to Cantera Users' Group
Hi, Yu

can I ask you a question about how to compile Cantera with visual studio 2019? Detailed description is in the link below
Thanks a lot!

Best regards!
SU
Reply all
Reply to author
Forward
0 new messages