added support for exceptions from tpx

This commit is contained in:
Dave Goodwin 2004-10-09 15:13:48 +00:00
parent 0f723ca045
commit 684ee95a9d
6 changed files with 43 additions and 19 deletions

View file

@ -4,7 +4,7 @@
# $Date$ # $Date$
# $Revision$ # $Revision$
# #
# Copyright 2001 California Institute of Technology # Copyright 2001-2004 California Institute of Technology
# See file License.txt for licensing information # See file License.txt for licensing information
# #
############################################################### ###############################################################
@ -25,6 +25,7 @@ SRCS = cantera/private/ctmethods.cpp \
cantera/private/surfmethods.cpp \ cantera/private/surfmethods.cpp \
cantera/private/funcmethods.cpp cantera/private/funcmethods.cpp
CANTERA_LIBDIR=@buildlib@ CANTERA_LIBDIR=@buildlib@
os_is_win=@OS_IS_WIN@ os_is_win=@OS_IS_WIN@
@ -38,6 +39,11 @@ LIB_DEPS = $(CANTERA_LIBDIR)/cantera.lib $(CANTERA_LIBDIR)/zeroD.lib \
$(CANTERA_LIBDIR)/transport.lib $(CANTERA_LIBDIR)/transport.lib
endif endif
DEPENDS = $(SRCS:.cpp=.d)
.cpp.d:
g++ -MM $(CXX_INCLUDES) $*.cpp > $*.d
all: cantera/ctmethods.@mex_ext@ all: cantera/ctmethods.@mex_ext@
cantera/ctmethods.@mex_ext@: $(SRCS) $(LIBDEPS) Makefile cantera/ctmethods.@mex_ext@: $(SRCS) $(LIBDEPS) Makefile
@ -49,7 +55,6 @@ endif
(@MATLAB_CMD@ -nojvm -nosplash -r setup) (@MATLAB_CMD@ -nojvm -nosplash -r setup)
rm -f setup.m rm -f setup.m
install: install:
@INSTALL@ -d @prefix@/matlab/toolbox/cantera/cantera @INSTALL@ -d @prefix@/matlab/toolbox/cantera/cantera
@INSTALL@ -d @prefix@/matlab/toolbox/cantera/cantera-demos @INSTALL@ -d @prefix@/matlab/toolbox/cantera/cantera-demos
@ -125,10 +130,22 @@ install:
clean: clean:
echo '-' rm -f cantera/private/*.o
rm -f cantera/ctmethods.@mex_ext@
#depends: $(DEPENDS)
# cat *.d > .depends
# $(RM) $(DEPENDS)
depends: depends:
echo '-' echo "-"
TAGS:
etags *.h *.cpp
ifeq ($(wildcard .depends), .depends)
include .depends
endif
run-demo: run-demo:
(cd @ct_dir@; matlab -nojvm -nosplash -r cantera_demos) (cd @ct_dir@; matlab -nojvm -nosplash -r cantera_demos)

View file

@ -22,7 +22,7 @@ s3 = entropy_mass(w);
heat_added = h3 - h2; heat_added = h3 - h2;
% expand isentropically to the initial pressure % expand adiabatically back to the initial pressure
work = expand(w, p1, eta_turbine); work = expand(w, p1, eta_turbine);
h4 = enthalpy_mass(w); h4 = enthalpy_mass(w);
x4 = vaporFraction(w); x4 = vaporFraction(w);
@ -33,8 +33,9 @@ efficiency = (work - pump_work)/heat_added;
function w = pump(fluid, pfinal, eta) function w = pump(fluid, pfinal, eta)
% Adiabatically pump a fluid to pressure pfinal, using % PUMP - Adiabatically pump a fluid to pressure pfinal, using a pump
% a pump with isentropic efficiency eta.""" % with isentropic efficiency eta.
%
h0 = enthalpy_mass(fluid); h0 = enthalpy_mass(fluid);
s0 = entropy_mass(fluid); s0 = entropy_mass(fluid);
set(fluid, 'S', s0, 'P', pfinal); set(fluid, 'S', s0, 'P', pfinal);
@ -47,8 +48,9 @@ w = actual_work;
function w = expand(fluid, pfinal, eta) function w = expand(fluid, pfinal, eta)
% Adiabatically expand a fluid to pressure pfinal, using % EXPAND - Adiabatically expand a fluid to pressure pfinal, using a
% a turbine with isentropic efficiency eta % turbine with isentropic efficiency eta.
%
h0 = enthalpy_mass(fluid); h0 = enthalpy_mass(fluid);
s0 = entropy_mass(fluid); s0 = entropy_mass(fluid);
set(fluid, 'S', s0, 'P', pfinal); set(fluid, 'S', s0, 'P', pfinal);

View file

@ -9,7 +9,7 @@
void reportError() { void reportError() {
int buflen = 0; int buflen = 0;
char* output_buf = 0; char* output_buf = 0;
buflen = getCanteraError(buflen, output_buf); buflen = getCanteraError(buflen, output_buf) + 1;
output_buf = (char*)mxCalloc(buflen, sizeof(char)); output_buf = (char*)mxCalloc(buflen, sizeof(char));
getCanteraError(buflen, output_buf); getCanteraError(buflen, output_buf);
mexErrMsgTxt(output_buf); mexErrMsgTxt(output_buf);

View file

@ -1,4 +1,5 @@
const double Undef = -999.123; const double Undef = -999.123;
//const double DERR = -999.999;
void reportError(); void reportError();

View file

@ -7,7 +7,7 @@
int nrhs, const mxArray *prhs[] ) int nrhs, const mxArray *prhs[] )
{ {
double vv; double vv;
int iok, k, m; int iok=0, k, m;
int ph = getInt(prhs[1]); int ph = getInt(prhs[1]);
int job = getInt(prhs[2]); int job = getInt(prhs[2]);
@ -34,9 +34,9 @@
switch (mjob) { switch (mjob) {
case 1: case 1:
phase_setTemperature(ph,*ptr); break; iok = phase_setTemperature(ph,*ptr); break;
case 2: case 2:
phase_setDensity(ph,*ptr); break; iok = phase_setDensity(ph,*ptr); break;
default: default:
ok = false; ok = false;
} }
@ -48,18 +48,18 @@
int norm = 1; int norm = 1;
switch (mjob) { switch (mjob) {
case 20: case 20:
phase_setMoleFractions(ph, nsp, ptr, norm); iok = phase_setMoleFractions(ph, nsp, ptr, norm);
break; break;
case 21: case 21:
phase_setMassFractions(ph, nsp, ptr, norm); iok = phase_setMassFractions(ph, nsp, ptr, norm);
break; break;
case 22: case 22:
norm = 0; norm = 0;
phase_setMoleFractions(ph, nsp, ptr, norm); iok = phase_setMoleFractions(ph, nsp, ptr, norm);
break; break;
case 23: case 23:
norm = 0; norm = 0;
phase_setMassFractions(ph, nsp, ptr, norm); iok = phase_setMassFractions(ph, nsp, ptr, norm);
break; break;
default: default:
ok = false; ok = false;
@ -88,10 +88,10 @@
switch (mjob) { switch (mjob) {
case 30: case 30:
phase_setMoleFractionsByName(ph, input_buf); iok = phase_setMoleFractionsByName(ph, input_buf);
break; break;
case 31: case 31:
phase_setMassFractionsByName(ph, input_buf); iok = phase_setMassFractionsByName(ph, input_buf);
break; break;
default: default:
mexErrMsgTxt("what?"); mexErrMsgTxt("what?");
@ -139,6 +139,7 @@
ok = false; ok = false;
} }
if (ok) { if (ok) {
if (vv == DERR) reportError();
plhs[0] = mxCreateNumericMatrix(1,1,mxDOUBLE_CLASS,mxREAL); plhs[0] = mxCreateNumericMatrix(1,1,mxDOUBLE_CLASS,mxREAL);
double *h = mxGetPr(plhs[0]); double *h = mxGetPr(plhs[0]);
*h = vv; *h = vv;
@ -236,6 +237,7 @@
} }
else { else {
mexErrMsgTxt("error or unknown method."); mexErrMsgTxt("error or unknown method.");
reportError();
return; return;
} }
} }
@ -243,4 +245,5 @@
mexErrMsgTxt("unimplemented method."); mexErrMsgTxt("unimplemented method.");
return; return;
} }
if (iok < 0) reportError();
} }

View file

@ -138,6 +138,7 @@ static void thermoget( int nlhs, mxArray *plhs[],
ok = false; ok = false;
} }
if (ok) { if (ok) {
if (vv == DERR) reportError();
plhs[0] = mxCreateNumericMatrix(1,1,mxDOUBLE_CLASS,mxREAL); plhs[0] = mxCreateNumericMatrix(1,1,mxDOUBLE_CLASS,mxREAL);
double *h = mxGetPr(plhs[0]); double *h = mxGetPr(plhs[0]);
*h = vv; *h = vv;