Created
November 7, 2016 18:31
-
-
Save speth/2043f3abc269f5e823158dab917eefab to your computer and use it in GitHub Desktop.
Cantera Matlab interface using "loadlibrary"
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "ct.h" | |
#include "ctfunc.h" | |
#include "ctmultiphase.h" | |
#include "ctonedim.h" | |
#include "ctreactor.h" | |
#include "ctrpath.h" | |
#include "ctsurf.h" | |
#include "ctxml.h" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
cantera_root = '/path/to/cantera/installation' | |
[notfound,warnings] = loadlibrary([cantera_root '/lib/libcantera_shared.so'], ... | |
'include/cantera/clib/ctmatlab.h', ... | |
'includepath', [cantera_root '/include'], ... | |
'addheader','ct','addheader','ctfunc', ... | |
'addheader','ctmultiphase','addheader', ... | |
'ctonedim','addheader','ctreactor', ... | |
'addheader','ctrpath','addheader','ctsurf', ... | |
'addheader','ctxml'); | |
% Read an input file | |
xml_file = calllib('libcantera_shared','xml_get_XML_File','gri30.xml', 0) | |
phase_node = calllib('libcantera_shared','xml_findID',xml_file, 'gri30_mix') | |
% Create a Thermo object | |
thermo = calllib('libcantera_shared','thermo_newFromXML',phase_node) | |
% Set/get properties | |
nsp = calllib('libcantera_shared','thermo_nSpecies',thermo) | |
calllib('libcantera_shared','thermo_setTemperature', thermo, 500) | |
calllib('libcantera_shared','thermo_setPressure', thermo, 5*101325) | |
calllib('libcantera_shared','thermo_setMoleFractionsByName', thermo, 'CH4:1.0, O2:2.0, N2:7.52') | |
rho = calllib('libcantera_shared','thermo_density', thermo) | |
% Getting an array | |
Y = zeros(nsp, 1) | |
[flag, Y] = calllib('libcantera_shared','thermo_getMassFractions', thermo, nsp, Y) | |
% Getting a string | |
k = 25; | |
len = calllib('libcantera_shared','thermo_getSpeciesName', thermo, k, 0, ''); | |
[flag,name] = calllib('libcantera_shared','thermo_getSpeciesName', ... | |
thermo, k, len, blanks(len)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment