From 7647893d733c5f5217ccc0b558b15da96599ee29 Mon Sep 17 00:00:00 2001 From: ssun30 Date: Tue, 31 Jan 2023 19:07:56 -0500 Subject: [PATCH] Changed all callct2 to ctString --- interfaces/matlab_experimental/1D/Domain1D.m | 4 ++-- interfaces/matlab_experimental/1D/Sim1D.m | 2 +- interfaces/matlab_experimental/Base/Interface.m | 2 +- interfaces/matlab_experimental/Base/Kinetics.m | 4 ++-- interfaces/matlab_experimental/Base/Solution.m | 2 +- .../matlab_experimental/Base/ThermoPhase.m | 15 ++++++++------- interfaces/matlab_experimental/Base/Transport.m | 2 +- interfaces/matlab_experimental/Func/Func.m | 2 +- interfaces/matlab_experimental/Phases/Mixture.m | 2 +- .../matlab_experimental/Reactor/FlowDevice.m | 2 +- .../matlab_experimental/Reactor/Reactor.m | 2 +- .../matlab_experimental/Reactor/ReactorNet.m | 2 +- .../Reactor/ReactorSurface.m | 2 +- interfaces/matlab_experimental/Reactor/Wall.m | 2 +- interfaces/matlab_experimental/Utility/callct.m | 4 ++-- .../matlab_experimental/Utility/checklib.m | 3 --- ...getDataDirectories.m => ctDataDirectories.m} | 2 +- .../matlab_experimental/Utility/ctGetErr.m | 11 +++++++++++ .../{canteraGitCommit.m => ctGitCommit.m} | 4 ++-- .../matlab_experimental/Utility/ctIsLoaded.m | 8 ++++++++ .../Utility/{ct.m => ctLib.m} | 4 ++-- interfaces/matlab_experimental/Utility/ctLoad.m | 2 +- .../Utility/{callct2.m => ctString.m} | 10 +++++----- .../matlab_experimental/Utility/ctUnload.m | 4 ++-- .../Utility/{canteraVersion.m => ctVersion.m} | 8 ++++---- interfaces/matlab_experimental/Utility/geterr.m | 17 ----------------- samples/matlab_experimental/test_examples.m | 4 ++-- 27 files changed, 63 insertions(+), 63 deletions(-) delete mode 100644 interfaces/matlab_experimental/Utility/checklib.m rename interfaces/matlab_experimental/Utility/{getDataDirectories.m => ctDataDirectories.m} (97%) create mode 100644 interfaces/matlab_experimental/Utility/ctGetErr.m rename interfaces/matlab_experimental/Utility/{canteraGitCommit.m => ctGitCommit.m} (80%) create mode 100644 interfaces/matlab_experimental/Utility/ctIsLoaded.m rename interfaces/matlab_experimental/Utility/{ct.m => ctLib.m} (54%) rename interfaces/matlab_experimental/Utility/{callct2.m => ctString.m} (59%) rename interfaces/matlab_experimental/Utility/{canteraVersion.m => ctVersion.m} (53%) delete mode 100644 interfaces/matlab_experimental/Utility/geterr.m diff --git a/interfaces/matlab_experimental/1D/Domain1D.m b/interfaces/matlab_experimental/1D/Domain1D.m index 917daf7d7..97299878c 100644 --- a/interfaces/matlab_experimental/1D/Domain1D.m +++ b/interfaces/matlab_experimental/1D/Domain1D.m @@ -125,7 +125,7 @@ classdef Domain1D < handle function d = Domain1D(varargin) % Create a :mat:class:`Domain1D` object. - checklib; + ctIsLoaded; if nargin == 1 a = varargin{1}; @@ -317,7 +317,7 @@ classdef Domain1D < handle for i = 1:n id = index(i) - 1; - output = callct2('domain_componentName', d.domainID, id); + output = ctString('domain_componentName', d.domainID, id); s{i} = output; end diff --git a/interfaces/matlab_experimental/1D/Sim1D.m b/interfaces/matlab_experimental/1D/Sim1D.m index db9508156..e5e473bc8 100644 --- a/interfaces/matlab_experimental/1D/Sim1D.m +++ b/interfaces/matlab_experimental/1D/Sim1D.m @@ -30,7 +30,7 @@ classdef Sim1D < handle function s = Sim1D(domains) % Create a :mat:class:`Sim1D` object. - checklib; + ctIsLoaded; s.stID = -1; s.domains = domains; diff --git a/interfaces/matlab_experimental/Base/Interface.m b/interfaces/matlab_experimental/Base/Interface.m index 7ec47f113..4a39e173e 100644 --- a/interfaces/matlab_experimental/Base/Interface.m +++ b/interfaces/matlab_experimental/Base/Interface.m @@ -40,7 +40,7 @@ classdef Interface < handle & ThermoPhase & Kinetics function s = Interface(src, id, p1, p2, p3, p4) % Create an :mat:class:`Interface` object. - checklib; + ctIsLoaded; t = ThermoPhase(src, id); s@ThermoPhase(src, id); diff --git a/interfaces/matlab_experimental/Base/Kinetics.m b/interfaces/matlab_experimental/Base/Kinetics.m index 13f2ac95e..53a0830f7 100644 --- a/interfaces/matlab_experimental/Base/Kinetics.m +++ b/interfaces/matlab_experimental/Base/Kinetics.m @@ -108,7 +108,7 @@ classdef Kinetics < handle % Instance of class :mat:class:`Kinetics` % - checklib; + ctIsLoaded; % indices for bulk phases in a heterogeneous mechanism inb1 = -1; @@ -395,7 +395,7 @@ classdef Kinetics < handle % :return: % String reaction equation. - rxn = callct2('kin_getReactionString', kin.kinID, irxn - 1); + rxn = ctString('kin_getReactionString', kin.kinID, irxn - 1); end function rxn = get.reactionEqns(kin) diff --git a/interfaces/matlab_experimental/Base/Solution.m b/interfaces/matlab_experimental/Base/Solution.m index 036a1e447..6432fbccc 100644 --- a/interfaces/matlab_experimental/Base/Solution.m +++ b/interfaces/matlab_experimental/Base/Solution.m @@ -56,7 +56,7 @@ classdef Solution < handle & ThermoPhase & Kinetics & Transport function s = Solution(src, id, trans) % Create a :mat:class:`Solution` object. - checklib; + ctIsLoaded; if nargin < 2 || nargin > 3 error('Solution class constructor expects 2 or 3 input arguments.'); diff --git a/interfaces/matlab_experimental/Base/ThermoPhase.m b/interfaces/matlab_experimental/Base/ThermoPhase.m index bac9e542b..5e0852214 100644 --- a/interfaces/matlab_experimental/Base/ThermoPhase.m +++ b/interfaces/matlab_experimental/Base/ThermoPhase.m @@ -252,7 +252,7 @@ classdef ThermoPhase < handle function tp = ThermoPhase(src, id) % Create a :mat:class:`ThermoPhase` object. - checklib; + ctIsLoaded; if nargin ~= 2 error('ThermoPhase expects 2 input arguments.'); @@ -275,13 +275,14 @@ classdef ThermoPhase < handle function display(tp) % Display thermo properties - buflen = 0 - calllib(ct, 'thermo_report', tp.tpID, 0, '', 1); + buflen = 0 - calllib(ctLib, 'thermo_report', tp.tpID, 0, '', 1); aa = char(ones(1, buflen)); ptr = libpointer('cstring', aa); - [iok, bb] = calllib(ct, 'thermo_report', tp.tpID, buflen, ptr, 1); + [iok, bb] = calllib(ctLib, 'thermo_report', tp.tpID, buflen, ... + ptr, 1); if iok < 0 - error(geterr); + error(ctGetErr); else disp(bb); end @@ -528,7 +529,7 @@ classdef ThermoPhase < handle return end - n = callct('thermo_nAtoms', tp.tpID, k - 1, m - 1) + n = callct('thermo_nAtoms', tp.tpID, k - 1, m - 1); end @@ -612,7 +613,7 @@ classdef ThermoPhase < handle for j = 1:n ksp = k(i, j) - 1; - output = callct2('thermo_getSpeciesName', tp.tpID, ksp); + output = ctString('thermo_getSpeciesName', tp.tpID, ksp); nm{i, j} = output; end @@ -799,7 +800,7 @@ classdef ThermoPhase < handle end function e = get.eosType(tp) - e = callct2('thermo_getEosType', tp.tpID); + e = ctString('thermo_getEosType', tp.tpID); end function v = get.isIdealGas(tp) diff --git a/interfaces/matlab_experimental/Base/Transport.m b/interfaces/matlab_experimental/Base/Transport.m index 5d4af80b6..c5254489f 100644 --- a/interfaces/matlab_experimental/Base/Transport.m +++ b/interfaces/matlab_experimental/Base/Transport.m @@ -53,7 +53,7 @@ classdef Transport < handle % Instance of class :mat:class:`Transport`. % - checklib; + ctIsLoaded; tr.trID = 0; if nargin == 2 diff --git a/interfaces/matlab_experimental/Func/Func.m b/interfaces/matlab_experimental/Func/Func.m index 94a15c63c..0b526a883 100644 --- a/interfaces/matlab_experimental/Func/Func.m +++ b/interfaces/matlab_experimental/Func/Func.m @@ -65,7 +65,7 @@ classdef Func < handle % Instance of class :mat:class:`Func` % - checklib; + ctIsLoaded; if ~isa(typ, 'char') error('Function type must be a string'); diff --git a/interfaces/matlab_experimental/Phases/Mixture.m b/interfaces/matlab_experimental/Phases/Mixture.m index d6701cef6..9649e8d11 100644 --- a/interfaces/matlab_experimental/Phases/Mixture.m +++ b/interfaces/matlab_experimental/Phases/Mixture.m @@ -152,7 +152,7 @@ classdef Mixture < handle function m = Mixture(phases) % Create a :mat:class:`Mixture` object. - checklib; + ctIsLoaded; if nargin > 1 error('Mixture: wrong number of arguments'); diff --git a/interfaces/matlab_experimental/Reactor/FlowDevice.m b/interfaces/matlab_experimental/Reactor/FlowDevice.m index 00273d1fc..8d66dcef5 100644 --- a/interfaces/matlab_experimental/Reactor/FlowDevice.m +++ b/interfaces/matlab_experimental/Reactor/FlowDevice.m @@ -61,7 +61,7 @@ classdef FlowDevice < handle function x = FlowDevice(typ) % Create a :mat:class:`FlowDevice` object. - checklib; + ctIsLoaded; if nargin == 0 error('please specify the type of flow device to be created'); diff --git a/interfaces/matlab_experimental/Reactor/Reactor.m b/interfaces/matlab_experimental/Reactor/Reactor.m index 055330a32..581842adb 100644 --- a/interfaces/matlab_experimental/Reactor/Reactor.m +++ b/interfaces/matlab_experimental/Reactor/Reactor.m @@ -113,7 +113,7 @@ classdef Reactor < handle function r = Reactor(content, typ) % Create a :mat:class:`Reactor` object. - checklib; + ctIsLoaded; if nargin == 0 content = 0; diff --git a/interfaces/matlab_experimental/Reactor/ReactorNet.m b/interfaces/matlab_experimental/Reactor/ReactorNet.m index 7ffa5c6b5..5e6041d74 100644 --- a/interfaces/matlab_experimental/Reactor/ReactorNet.m +++ b/interfaces/matlab_experimental/Reactor/ReactorNet.m @@ -61,7 +61,7 @@ classdef ReactorNet < handle function r = ReactorNet(reactors) % Create a :mat:class:`ReactorNet` object. - checklib; + ctIsLoaded; if nargin ~= 1 error('Wrong number of arguments to ReactorNet constructor.'); diff --git a/interfaces/matlab_experimental/Reactor/ReactorSurface.m b/interfaces/matlab_experimental/Reactor/ReactorSurface.m index 72d767e71..7993b8c01 100644 --- a/interfaces/matlab_experimental/Reactor/ReactorSurface.m +++ b/interfaces/matlab_experimental/Reactor/ReactorSurface.m @@ -46,7 +46,7 @@ classdef ReactorSurface < handle function s = ReactorSurface(surf, reactor, area) % Create a :mat:class:`ReactorSurface` object. - checklib; + ctIsLoaded; s.surfID = callct('reactorsurface_new', 0); s.reactor = -1; diff --git a/interfaces/matlab_experimental/Reactor/Wall.m b/interfaces/matlab_experimental/Reactor/Wall.m index 4b1b6e857..a66d89300 100644 --- a/interfaces/matlab_experimental/Reactor/Wall.m +++ b/interfaces/matlab_experimental/Reactor/Wall.m @@ -88,7 +88,7 @@ classdef Wall < handle function w = Wall(l, r) % Create a :mat:class:`Wall` object. - checklib; + ctIsLoaded; % At the moment, only one wall type is implemented typ = 'Wall'; diff --git a/interfaces/matlab_experimental/Utility/callct.m b/interfaces/matlab_experimental/Utility/callct.m index 5b13980f8..782114f8c 100644 --- a/interfaces/matlab_experimental/Utility/callct.m +++ b/interfaces/matlab_experimental/Utility/callct.m @@ -5,10 +5,10 @@ function output = callct(varargin) errorcode = [-1, -999.999, double(intmax('uint64'))]; funcName = varargin{1}; - output = calllib(ct, funcName, varargin{2:end}); + output = calllib(ctLib, funcName, varargin{2:end}); if ismember(output, errorcode) - error(geterr); + error(ctGetErr); end end diff --git a/interfaces/matlab_experimental/Utility/checklib.m b/interfaces/matlab_experimental/Utility/checklib.m deleted file mode 100644 index fcf4d9ddc..000000000 --- a/interfaces/matlab_experimental/Utility/checklib.m +++ /dev/null @@ -1,3 +0,0 @@ -if ~libisloaded(ct) - error('Cantera is not loaded'); -end diff --git a/interfaces/matlab_experimental/Utility/getDataDirectories.m b/interfaces/matlab_experimental/Utility/ctDataDirectories.m similarity index 97% rename from interfaces/matlab_experimental/Utility/getDataDirectories.m rename to interfaces/matlab_experimental/Utility/ctDataDirectories.m index ca7c3840f..eec451648 100644 --- a/interfaces/matlab_experimental/Utility/getDataDirectories.m +++ b/interfaces/matlab_experimental/Utility/ctDataDirectories.m @@ -8,7 +8,7 @@ function d = getDataDirectories() % :return: % Cell array with strings representing the data file search directories % - checklib; + ctIsLoaded; buflen = calllib(ct, 'ct_getDataDirectories', 0, '', ';'); aa = char(ones(1, buflen)); ptr = libpointer('cstring', aa); diff --git a/interfaces/matlab_experimental/Utility/ctGetErr.m b/interfaces/matlab_experimental/Utility/ctGetErr.m new file mode 100644 index 000000000..1f39a4496 --- /dev/null +++ b/interfaces/matlab_experimental/Utility/ctGetErr.m @@ -0,0 +1,11 @@ +function e = ctGetErr() + % Get the error message from a Cantera error. + % + + try + e = ctString('ct_getCanteraError'); + catch ME + e = getReport(ME); + end + +end diff --git a/interfaces/matlab_experimental/Utility/canteraGitCommit.m b/interfaces/matlab_experimental/Utility/ctGitCommit.m similarity index 80% rename from interfaces/matlab_experimental/Utility/canteraGitCommit.m rename to interfaces/matlab_experimental/Utility/ctGitCommit.m index 446a0dec5..4beac00f4 100644 --- a/interfaces/matlab_experimental/Utility/canteraGitCommit.m +++ b/interfaces/matlab_experimental/Utility/ctGitCommit.m @@ -6,6 +6,6 @@ function v = canteraGitCommit() % :return: % A string containing the Git commit hash for the current version of Cantera. % - checklib; - v = callct2('ct_getGitCommit'); + ctIsLoaded; + v = ctString('ct_getGitCommit'); end diff --git a/interfaces/matlab_experimental/Utility/ctIsLoaded.m b/interfaces/matlab_experimental/Utility/ctIsLoaded.m new file mode 100644 index 000000000..c78ff2968 --- /dev/null +++ b/interfaces/matlab_experimental/Utility/ctIsLoaded.m @@ -0,0 +1,8 @@ +function i = ctIsLoaded() + if ~libisloaded(ctLib) + error('Cantera is not loaded'); + end + + i = true; + +end diff --git a/interfaces/matlab_experimental/Utility/ct.m b/interfaces/matlab_experimental/Utility/ctLib.m similarity index 54% rename from interfaces/matlab_experimental/Utility/ct.m rename to interfaces/matlab_experimental/Utility/ctLib.m index d7211d7a6..3595261f3 100644 --- a/interfaces/matlab_experimental/Utility/ct.m +++ b/interfaces/matlab_experimental/Utility/ctLib.m @@ -1,5 +1,5 @@ -function str = ct() - % Return name of 'cantera_shared' library. +function str = ctLib() + % Return name of Cantera Shared Library depending on OS. if ispc str = 'cantera_shared'; else diff --git a/interfaces/matlab_experimental/Utility/ctLoad.m b/interfaces/matlab_experimental/Utility/ctLoad.m index c5a08a400..a821d6acc 100644 --- a/interfaces/matlab_experimental/Utility/ctLoad.m +++ b/interfaces/matlab_experimental/Utility/ctLoad.m @@ -12,7 +12,7 @@ function ctLoad() return; end - if ~libisloaded(ctSharedLibrary) + if ~libisloaded(ctLib) [~, warnings] = loadlibrary([ctRoot, ctName], ... [ctRoot, '/include/cantera/clib/ctmatlab.h'], ... 'includepath', [ctRoot '/include'], ... diff --git a/interfaces/matlab_experimental/Utility/callct2.m b/interfaces/matlab_experimental/Utility/ctString.m similarity index 59% rename from interfaces/matlab_experimental/Utility/callct2.m rename to interfaces/matlab_experimental/Utility/ctString.m index f3e588f46..1ae3c37ad 100644 --- a/interfaces/matlab_experimental/Utility/callct2.m +++ b/interfaces/matlab_experimental/Utility/ctString.m @@ -1,24 +1,24 @@ -function output = callct2(varargin) +function output = ctString(varargin) % Calls Cantera library functions with string outputs and returns % errors if necessary. err1 = -1; funcName = varargin{1}; - buflen = calllib(ct, funcName, varargin{2:end}, 0, ''); + buflen = calllib(ctLib, funcName, varargin{2:end}, 0, ''); if buflen > 0 aa = char(ones(1, buflen)); ptr = libpointer('cstring', aa); - [iok, bb] = calllib(ct, funcName, varargin{2:end}, buflen, ptr); + [iok, bb] = calllib(ctLib, funcName, varargin{2:end}, buflen, ptr); output = bb; clear aa bb ptr; else - error(geterr); + error(ctGetErr); end if iok == -err1 - error(geterr); + error(ctGetErr); end end diff --git a/interfaces/matlab_experimental/Utility/ctUnload.m b/interfaces/matlab_experimental/Utility/ctUnload.m index fb69c1f84..923da2e80 100644 --- a/interfaces/matlab_experimental/Utility/ctUnload.m +++ b/interfaces/matlab_experimental/Utility/ctUnload.m @@ -1,9 +1,9 @@ function ctUnload() % Unload the Cantear C Library from the Memory % - if libisloaded(ctSharedLibrary) + if libisloaded(ctLib) ctCleanUp; - unloadlibrary(ctSharedLibrary); + unloadlibrary(ctLib); end disp('Cantera has been unloaded'); diff --git a/interfaces/matlab_experimental/Utility/canteraVersion.m b/interfaces/matlab_experimental/Utility/ctVersion.m similarity index 53% rename from interfaces/matlab_experimental/Utility/canteraVersion.m rename to interfaces/matlab_experimental/Utility/ctVersion.m index 6dbe16c96..6e0e53ece 100644 --- a/interfaces/matlab_experimental/Utility/canteraVersion.m +++ b/interfaces/matlab_experimental/Utility/ctVersion.m @@ -1,11 +1,11 @@ -function v = canteraVersion() +function v = ctVersion() % Get Cantera version information. :: % - % >> canteraVersion() + % >> ctVersion() % % :return: % A string containing the Cantera version. % - checklib; - v = callct2('ct_getCanteraVersion'); + ctIsLoaded; + v = ctString('ct_getCanteraVersion'); end diff --git a/interfaces/matlab_experimental/Utility/geterr.m b/interfaces/matlab_experimental/Utility/geterr.m deleted file mode 100644 index cc150a9cc..000000000 --- a/interfaces/matlab_experimental/Utility/geterr.m +++ /dev/null @@ -1,17 +0,0 @@ -function e = geterr() - % Get the error message from a Cantera error. - % - checklib; - - try - buflen = calllib(ct, 'ct_getCanteraError', 0, ''); - aa = char(ones(1, buflen)); - ptr = libpointer('cstring', aa); - [iok, bb] = calllib(ct, 'ct_getCanteraError', buflen, ptr); - e = bb; - clear aa bb ptr - catch ME - e = getReport(ME); - end - -end diff --git a/samples/matlab_experimental/test_examples.m b/samples/matlab_experimental/test_examples.m index e97f964b4..f3038c137 100644 --- a/samples/matlab_experimental/test_examples.m +++ b/samples/matlab_experimental/test_examples.m @@ -1,6 +1,6 @@ % runs selected examples without pausing -LoadCantera +ctLoad clear all close all @@ -26,6 +26,6 @@ diamond_cvd; clear all close all -UnloadCantera +ctUnload disp('Test example run successful.')