Cantera + Simulink

115 views
Skip to first unread message

Roberto Paolinelli

unread,
Nov 22, 2021, 11:01:18 AM11/22/21
to Cantera Users' Group
Hello all,
I'm newbie to this community.

We would like to integrate Cantera library in our Simulink model.
From simulation point of view it works using an interpreted Matlab.System object.
But as soon as I choose Code Generation option (think about that model could be used in a hardware in the loop system) it fails.
We have contacted the Mathworks support and they told us the problem relies on that Cantera interface to matlab is written in old style object oriented programming (i.e. without classdef, methods and properties).

Have you planned or are you planning to move Cantera matlab classes to new style making it possible using Cantera in Simulink models supporting code generation?
Do you have a roadmap for that?

Thanks a lot
Roberto

Su Sun

unread,
Nov 24, 2021, 9:37:30 AM11/24/21
to Cantera Users' Group
Hi Roberto, 

I'm working on a Matlab toolbox revamp using the newer style of object oriented programming. The new interface is in testing phase and an early release which replicates all functionalities of the older toolbox should be ready mid-December. I haven't tested how this new interface would work with code generation and I happen to be looking for Matlab users for feedback. At this point there isn't much documentation to help users familiarize to this new style (with methods and properties instead of functions like the old interface). If you were interested I could put together a quick installation and user guide for you to try out this this new interface in a couple of days.

Regards,
Su

Roberto Paolinelli

unread,
Nov 24, 2021, 10:15:38 AM11/24/21
to canter...@googlegroups.com
Hi Su,
thank you very much for your reply.

Yes I would be very glad to try and test the new class style interface if it works in Simulink, especially for code generation purposes (I would like to use Cantera libraries in a Hardware In The Loop system interfacing with first Simulink Coder and then Simulink Real Time).

Another question: as far as I could understand, the Cantera C++ interface has more capability than Matlab one, hasn't it?
I mean Flame Ionization Current and something else more...

If so, are you planning to change only the class style interface or are you (or one of your team) even working on aligning the two interfaces as for capabilities?

Thank you very much
Best Regards
Roberto





--
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/5oBTlzpfmag/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/97110ca6-d309-425e-9a68-afcef8c867c3n%40googlegroups.com.


--
Ing. Roberto Paolinelli
Electronics Engineering & Consulting
P.IVA (Vat Number): IT 02643190420

Su Sun

unread,
Dec 7, 2021, 2:22:32 PM12/7/21
to Cantera Users' Group
Hi Roberto, 

I haven't tested the toolbox in Simulink and I have not used it for code generation before. 

You are right the Cantera C++ library has more functionalities than Matlab. Due to its hard to maintain nature, the older Matlab interface was way behind on features. My current goal is to replicate all features that were already in the old toolbox and make sure they are stable. Currently there is one issue that is known to cause crash on Windows 10 so all calculations are now done assuming ideal gas, which is not 'ideal'. Sorry for the late reply as this problem has caused a lot of my recent test examples to fail or return incorrect results. 

As for making the matlab interface up to date with the main C++ library, it requires expanding the clib library, which is a collection of wrapper functions that wrap the C++ code in C for compatibility with Matlab. Direct C++ to Matlab interface is currently very restrictive, so we have to use this workaround. I think once the new interface proves to be stable we can look into expanding it. 

Regards,
Su

Roberto Paolinelli

unread,
Dec 8, 2021, 12:13:27 PM12/8/21
to canter...@googlegroups.com
Hello Su
ok, let me know when you think release is quite stable and I can help you testing it (in Simulink too)
Thank you very much
Best Regards
Roberto

Pravin Kumar Sundaram

unread,
Jun 15, 2022, 10:35:40 AM6/15/22
to Cantera Users' Group
Hello Roberto,
I am a beginner with Cantera. I am facing issues with connecting Cantera with Simulink Model. Is it possible to explain how you resolved the issue with Matlab.System object?
I still recieve "No class Solution" just like i recieve with Matlab fuction rather than Matlab System object in Simulink. Do we need to add the source code of %Solution.m file somewhere in the system file ?
I added cantera matlab fuctions to the simulation path. Also the standalone Matlab model with cantera fuction is running without any errors (in Matlab). But i am just not able to couple it with Simulink.
I need to couple it with simulink so that I can  generate a functional mock up (fmu) file to conduct a CoSimulation with AVL Cruise M Software (Software in the Loop).

Your suggestions would be highly useful !! :-)

Thanks a lot !

Roberto Paolinelli

unread,
Jun 16, 2022, 9:16:32 AM6/16/22
to Cantera Users' Group
Hello Spravin,
I have turned to Cantera C++ and generated an S-function :(
Cantera Matlab toolbox has much less features than C++.

This worked in simulation but and in code generation but not with unsupported RTOS environment.

I hope something will change in the future and I'm waiting new matlab toolbox too.

Hope this helps

Best Regards
Roberto

Reply all
Reply to author
Forward
0 new messages