Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Matlab] Initial version of 'experimental' Matlab toolbox
New toolbox replacing old-style classes with 'classdef' classes, and using 'calllib' to interact directly with the Cantera C interface rather than the 'ctmethods' MEX file.
- Loading branch information
Showing
23 changed files
with
2,660 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
function gas = Air() | ||
% Create an object representing air. | ||
gas = Solution('air.yaml', 'air'); | ||
end |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
function c = CarbonDioxide() | ||
% Return an object representing carbon dioxide. | ||
h = Solution('liquidvapor.yaml', 'carbon-dioxide'); | ||
end |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
function h = HFC134a() | ||
% Return an object representing refrigerant HFC134a. | ||
h = Solution('liquidvapor.yaml', 'HFC-134a'); | ||
end |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
function h = Heptane | ||
% Return an object representing n-heptane. | ||
h = Solution('liquidvapor.yaml', 'heptane'); | ||
end |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
function h = Hydrogen() | ||
% Return an object representing hydrogen. | ||
h = Solution('liquidvapor.yaml', 'hydrogen'); | ||
end |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,130 @@ | ||
classdef Interface < handle | ||
|
||
properties | ||
th | ||
kin | ||
end | ||
|
||
properties(Constant = true) | ||
lib = 'cantera_shared' | ||
end | ||
|
||
methods | ||
%% Interface class constructor | ||
|
||
function s = Interface(src, id, p1, p2, p3, p4) | ||
checklib; | ||
t = ThermoPhase(src, id); | ||
if nargin == 2 | ||
k = Kinetics(t, src, id); | ||
elseif nargin == 3 | ||
k = Kinetics(t, src, id, p1); | ||
elseif nargin == 4 | ||
k = Kinetics(t, src, id, p1, p2); | ||
elseif nargin == 5 | ||
k = Kinetics(t, src, id, p1, p2, p3); | ||
elseif nargin == 6 | ||
k = Kinetics(t, src, id, p1, p2, p3, p4); | ||
end | ||
|
||
s.kin = k; | ||
s.th = t; | ||
end | ||
|
||
%% Interface methods | ||
|
||
function c = coverages(s) | ||
% Get the surface coverages of the species on an interface. | ||
% | ||
% :return: | ||
% If no output value is assigned, a bar graph will be | ||
% plotted. Otherwise, a vector of length "n_surf_species" | ||
% will be returned. | ||
|
||
checklib; | ||
surf_id = s.th.tr_id; | ||
nsp = s.th.nSpecies; | ||
xx = zeros(1, nsp); | ||
pt = libpointer('doublePtr', xx); | ||
calllib(s.lib, 'surf_getCoverages', surf_id, xx); | ||
c = pt.Value; | ||
|
||
if nargout == 0 | ||
figure | ||
set(gcf, 'Name', 'Coverages') | ||
bar(c); | ||
colormap(summer); | ||
nm = speciesNames(s); | ||
set(gca, 'XTickLabel', nm); | ||
xlabel('Species Name'); | ||
ylabel('Coverage'); | ||
title('Surface Species Coverages'); | ||
end | ||
end | ||
|
||
function c = concentrations(s) | ||
% Get the concentrations of the species on an interface. | ||
% | ||
% :return: | ||
% If no output value is assigned, a bar graph will be | ||
% plotted. Otherwise, a vector of length "n_surf_species" | ||
% will be returned. | ||
|
||
checklib; | ||
surf_id = s.th.tr_id; | ||
nsp = s.th.nSpecies; | ||
xx = zeros(1, nsp); | ||
pt = libpointer('doublePtr', xx); | ||
calllib(s.lib, 'surf_getConcentrations', surf_id, xx); | ||
c = pt.Value; | ||
|
||
if nargout == 0 | ||
figure | ||
set(gcf, 'Name', 'Concentrations') | ||
bar(c); | ||
colormap(summer); | ||
nm = speciesNames(s); | ||
set(gca, 'XTickLabel', nm); | ||
xlabel('Species Name'); | ||
ylabel('Concentration [kmol/m^2]'); | ||
title('Surface Species Concentrations'); | ||
end | ||
end | ||
|
||
function setCoverages(s, cov, norm) | ||
% Set surface coverages of the species on an interface. | ||
% | ||
% :param cov: | ||
% Coverage of the species. "Cov" can be either a vector of | ||
% length "n_surf_species", or a string in the format | ||
% "Species:Coverage, Species:Coverage". | ||
|
||
checklib; | ||
|
||
if nargin == 3 && strcmp(norm, 'nonorm') | ||
norm_flag = 0; | ||
else | ||
norm_flag = 1; | ||
end | ||
|
||
surf_id = s.th.tr_id; | ||
nsp = s.th.nSpecies; | ||
[m, n] = size(cov); | ||
|
||
if isa(cov, 'double') | ||
sz = length(cov); | ||
if sz == nsp | ||
if ((m == nsp && n == 1) || (m == 1 & n == nsp)) | ||
calllib(s.lib, 'surf_setCoverages', surf_id, cov, norm_flag); | ||
else error('wrong size for coverage array'); | ||
end | ||
else | ||
error('wrong size for coverage array'); | ||
end | ||
elseif isa(cov, 'char') | ||
calllib(s.lib, 'surf_setCoveragesByName', surf_id, cov); | ||
end | ||
end | ||
|
||
end | ||
end |
Oops, something went wrong.