Cantera with Matlab - Error Using ctmethods

419 views
Skip to first unread message

Marjinal Çapulcu

unread,
Nov 11, 2019, 8:19:48 AM11/11/19
to Cantera Users' Group
Hello all,
I'm trying to using Cantera on Matlab. But i am getting these following errors. It would be nice anyone help me on this topic.
I am using Matlab R2019a - Python 2.7 - Cantera 2.4
Error is;

>> Yanma_Matlab
Error using ctmethods

***********************************************************************
CanteraError thrown by Phase::setMoleFractionsByName:
Unknown species 'C02'
***********************************************************************


Error in phase_set (line 5)
    ctmethods(30, n, -job, a);

Error in ThermoPhase/setMoleFractions (line 42)
    phase_set(tp.tp_id, 30, x);

Error in ThermoPhase/set (line 99)
            setMoleFractions(tp, val);

Error in Yanma_Matlab (line 7)
    set(gas,'Temperature',T1,'P',oneatm,'X',['C02:',num2str(1),',H20:',num2str(2),...
 
>> 

I'm attaching m file and screenshot of the error. 

Thank you very much.
Ps: I am an amateur on Matlab and coding something else. I'm trying to use Cantera tool on Matlab to obtain flue gases mechnaical properties like density, viscosity etc.
Yanma_Matlab.m
matlab-cantera-error.PNG

Bryan W. Weber

unread,
Nov 11, 2019, 8:29:51 AM11/11/19
to Cantera Users' Group
Hi,

You have colons in your species names in the set line, delete those colons and that should fix it. In other words, turn 'CO2:' into 'CO2'.

Best,
Bryan

Steven DeCaluwe

unread,
Nov 11, 2019, 8:30:45 AM11/11/19
to canter...@googlegroups.com
Hi Marjinal,

Welcome to Cantera! I was in a similar position when I first started using Cantera (no coding experience, trying to get things running on Matlab). 

The error here is that you have a typo in your species name: you are writing C02 (“C-zero-two’), when it should be CO2 (“C-letter o-two”). 

This is in the line:

set(gas,'Temperature',T1,'P',oneatm,'X',['C02:',num2str(1),',H20:',num2str(2),...

It looks like you have a similar error in H20 vs H2O, and perhaps elsewhere. 

Hope this helps!  Also, a request for the future: please do not attach or insert screenshots. These cannot be searched by people looking for help on similar error messages, and also cannot be read by the screen-readers commonly used by people with visual impairments. 

Best of luck!
Steven


Sent from my iPhone

On Nov 11, 2019, at 6:19 AM, Marjinal Çapulcu <zelfore...@gmail.com> wrote:


--
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/c6700fc7-a8aa-42f8-9148-b8e68ea760a2%40googlegroups.com.
<Yanma_Matlab.m>
<matlab-cantera-error.PNG>

Steven DeCaluwe

unread,
Nov 11, 2019, 9:51:04 AM11/11/19
to canter...@googlegroups.com

Bryan, I think those colons are for specifying the composition string, and are necessary.  I.e:

 

‘CO2:1,H2O:2,…”

--

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.

Marjinal Çapulcu

unread,
Nov 11, 2019, 9:51:45 AM11/11/19
to Cantera Users' Group
Dear Bryan & Steven,
First of all thank you so much for your interest. I've done things that you suggested me. So, i got another error like;

>> Yanma_Matlab_ForumREV
Error using ctmethods

***********************************************************************
CanteraError thrown by Phase::setMoleFractionsByName:
Unknown species 'CO21,H2O2,O2'
***********************************************************************


Error in phase_set (line 5)
    ctmethods(30, n, -job, a);

Error in ThermoPhase/setMoleFractions (line 42)
    phase_set(tp.tp_id, 30, x);

Error in ThermoPhase/set (line 99)
            setMoleFractions(tp, val);

Error in Yanma_Matlab_ForumREV (line 7)
    set(gas,'Temperature',T1,'P',oneatm,'X',['CO2',num2str(1),',H2O',num2str(2),...
 
>> 

What should i do? Again, thank you so much. I am attaching new m file after these updates (ends with REV).
Best,
Guven
Yanma_Matlab_ForumREV.m

Marjinal Çapulcu

unread,
Nov 11, 2019, 10:58:16 AM11/11/19
to Cantera Users' Group
Hello again,
Now i've tried correcting Typos only, not colons. And interesting, it worked. Now, i am attaching the last m file which is working.
Thank you so much for your interest guys.
Its really exciting to talking with you guys. 
And sorry for my easy mistakes. As i said, i am beginner. Thank you for your patient.
Best,
Güven

Special thanks to Steven.
Yanma_Matlab_REV_2.m

Bryan W. Weber

unread,
Nov 11, 2019, 11:00:40 AM11/11/19
to Cantera Users' Group
Thanks Steven! I misread how the code was working.

Güven, I'm glad your code is working now, thanks for sharing it back with us!

Best,
Bryan

Furkan Yildirim

unread,
Jul 29, 2021, 7:02:46 AM7/29/21
to Cantera Users' Group
Hello everyone my name is Furkan Enes,

I am also a new user of Cantera. This was a very old forum but I want to ask something about the error that appears on Matlab.
Mister Guven said the fact that the error was solved. Although I directly use the last Matlab code, it gives an error that says error using ctmedhods. The whole error statements are below.

Error using ctmethods

***********************************************************************
CanteraError thrown by Phase::setMoleFractionsByName:
Unknown species 'CO21,H2O2,O2'

***********************************************************************


Error in phase_set (line 5)
    ctmethods(30, n, -job, a);

Error in ThermoPhase/setMoleFractions (line 42)
    phase_set(tp.tp_id, 30, x);

Error in ThermoPhase/set (line 99)
            setMoleFractions(tp, val);

Error in Yanma_Matlab_ForumREV (line 7)
    set(gas,'Temperature',T1,'P',oneatm,'X',['CO2',num2str(1),',H2O',num2str(2),...

I am thanking you in advance. I will be so glad if someone helps me.


11 Kasım 2019 Pazartesi tarihinde saat 19:00:40 UTC+3 itibarıyla bryan....@gmail.com şunları yazdı:

Bryan Weber

unread,
Jul 29, 2021, 11:25:09 AM7/29/21
to Cantera Users' Group
Hi,

As Steven mentioned further up, you need colons between the species name and the number to specify the mole fractions.

Best,
Bryan

Reply all
Reply to author
Forward
0 new messages