How to integrate Cantera Solution method (Solution.m contained in a @class folder) to a Matlab function used in Simulink

I have the problem that I create a Simulink model which includes an additional user defined function which contained a call to an external Cantera toolbox (gas = Solution('gri30.cti','gri30')). I had just copy and paste the running code from a regular matlab file and put it to a Simulink Matlab Function block. But if I started the Simulink model I got the error "No class Solution". So I have read something about the propably underlying problem with @class folders but I cannot find a solution. Does anybody know how I can fix this problem?

Answers (1)

Hi Timo,
I am facing similar issue. Were you able to resolve it?

6 Comments

Hi Prasad,
you can integrate Cantera properties with a function call from Simulink (Easy but not the fastest way)
simulink -->load 'Matlab System' Block --> into this function you can integrate cantera with
coder.extrinsic(' .m file with cantera content')
Maybe another and faster way is to write a C-code with desired Cantera functionality and integrate it to simulink with a s-function
Hi Timo,
I tried but it's still throwing errors.
I am trying to run constant volume combustion through simulink.
Its basically reactor2 function from matlab cantera examples.
Any help you could would be great. Thank you so much.
Hi Prasd,
the for loop handling (into the reactor2) isn't a trivial task to bring this functionality into simulink (this means you have a time integration including another time integration). Maybe separate the "reactor2.m" in simulink and loop over a do while loop (for the single reactors) but i'm not sure that it will be working well. Another way is to implement cantera functionality into C and integrated with a S-function to simulink.
I attached a quick but dirty linking principle but this is not a final solution for your time integration proplem.
Unfortunately the intregation of third party application to simulink is not very easy respectively complicated.
Let me know if you find a better solution.
Hi Timo,
I am able to run bits and pieces of reactor2 matlab example. such as setting temperature, pressure mass fractions and other in gas structure.
Problem comes when I am trying design Idealgasreactor with gas. I have attached the error. I will try to work out c code into s-function. I am not a software guy actually so I think it will take quiet a bit time.
Another option I though which I haven't ventured is using python code of same reactor and calling python from simulink if it's possible.
Let's see I will you keep you updated if I come across easier method.
I had/have the same problem creating a reactor network but for my application the equilibrium state was sufficient respectivley accurate enough (works fine). Including python to simulink/matlab is possible but the output format of python numpy array's is not directly readable in matlab so you can store results to csv file and reloaded the csv into matlab (also not very nice). Or make the complete implementation in python :-) (often easier and faster).
maybe there is a possiblity to create your own class in matlab with classdef and integrate cantera into this class (https://de.mathworks.com/help/matlab/matlab_oop/create-a-simple-class.html)
Hi Timo
same problem as you but tried to go ahead...
I was succesful in running reactor2.m then I'm trying to run it in Simulink
I have converted @class to classdef Solution.m, ThermoPhase.m and Kinetics.m and some more.
I'm using matlab.system object to make it run on Simulink and it all works as interpreted execution.
Problems arise when I try and use it as Code Generation (I would this model to run as hardware in the loop...) and Simulink complains about mxArray (probably in ctmethods but it is a mexw64).
Did you succeed on your side? How?
Thank you very much
Roberto Paolinelli

Sign in to comment.

Asked:

on 15 Nov 2017

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!