From ad791e12d57b9d1d9303c08be54d3d0e8a863b21 Mon Sep 17 00:00:00 2001 From: Dave Goodwin Date: Mon, 17 May 2004 22:59:37 +0000 Subject: [PATCH] *** empty log message *** --- .../matlab/cantera/@FlowDevice/massFlowRate.m | 4 +-- .../matlab/cantera/@ReactorNet/ReactorNet.m | 13 ++++--- Cantera/matlab/cantera/@ReactorNet/advance.m | 8 ++--- Cantera/matlab/cantera/@ReactorNet/step.m | 4 +-- Cantera/matlab/cantera/@ThermoPhase/minTemp.m | 17 ++++++--- Cantera/matlab/cantera/examples/ignite2.m | 2 +- .../matlab/cantera/examples/periodic_cstr.m | 31 +++++++++------- Cantera/matlab/cantera/examples/prandtl1.m | 1 + Cantera/matlab/cantera/examples/reactor1.m | 9 +++-- Cantera/matlab/cantera/examples/reactor2.m | 5 ++- .../matlab/cantera/examples/run_examples.m | 6 ++++ Cantera/matlab/cantera/examples/surfreactor.m | 23 ++++++++---- Cantera/matlab/cantera/private/ctmatutils.h | 2 ++ Cantera/matlab/cantera/private/ctmethods.cpp | 3 +- .../cantera/private/flowdevicemethods.cpp | 10 +++--- .../matlab/cantera/private/reactormethods.cpp | 21 ++++++----- .../cantera/private/reactornetmethods.cpp | 36 ++++++++++++++++++- .../matlab/cantera/private/wallmethods.cpp | 5 ++- 18 files changed, 138 insertions(+), 62 deletions(-) diff --git a/Cantera/matlab/cantera/@FlowDevice/massFlowRate.m b/Cantera/matlab/cantera/@FlowDevice/massFlowRate.m index d8e998203..967bf21e0 100644 --- a/Cantera/matlab/cantera/@FlowDevice/massFlowRate.m +++ b/Cantera/matlab/cantera/@FlowDevice/massFlowRate.m @@ -1,5 +1,5 @@ -function mdot = massFlowRate(f) +function mdot = massFlowRate(f, time) % MASSFLOWRATE - mass flow rate in kg/s % -mdot = flowdevicemethods(21, f.index) +mdot = flowdevicemethods(21, f.index, time); diff --git a/Cantera/matlab/cantera/@ReactorNet/ReactorNet.m b/Cantera/matlab/cantera/@ReactorNet/ReactorNet.m index c11d708be..fd94174aa 100644 --- a/Cantera/matlab/cantera/@ReactorNet/ReactorNet.m +++ b/Cantera/matlab/cantera/@ReactorNet/ReactorNet.m @@ -4,20 +4,23 @@ function x = ReactorNet(reactors) % A ReactorNet object is a container that holds one or more % Reactor objects. % -% See also: Reservoir -% if nargin == 1 else - error('wrong number of arguments'); + error('wrong number of arguments to ReactorNet constructor'); end -x.index = reactornetmethods(0); +x.index = reactornetmethods(0,0); if x.index < 0 error(geterr); end x = class(x,'ReactorNet'); % add reactors -unfinished +nr = length(reactors); +for i = 1:nr + addReactor(x,reactors{i}); +end + + diff --git a/Cantera/matlab/cantera/@ReactorNet/advance.m b/Cantera/matlab/cantera/@ReactorNet/advance.m index c728dc2ba..6bd7be98e 100644 --- a/Cantera/matlab/cantera/@ReactorNet/advance.m +++ b/Cantera/matlab/cantera/@ReactorNet/advance.m @@ -1,17 +1,17 @@ -function advance(r, tout) +function advance(n, tout) % ADVANCE - Advance the state of the reactor network in time. % % Method advance integrates the system of ordinary differential % equations that determine the rate of change of the volume, the % mass of each species, and the total energy for each reactor. The -% integration is carried out from the current reactor time to time +% integration is carried out from the current time to time % 'tout.' (Note 'tout' is an absolute time, not a time interval.) % The integrator may take many internal time steps before reaching % tout. % % for i in 1:10 % tout = 0.1*i -% advance(r, tout) +% advance(n, tout) % ... % % ... @@ -19,4 +19,4 @@ function advance(r, tout) % % See also: ReactorNet/step % -reactormethods(8, reactornet_hndl(r), tout); +reactornetmethods(8, reactornet_hndl(n), tout); diff --git a/Cantera/matlab/cantera/@ReactorNet/step.m b/Cantera/matlab/cantera/@ReactorNet/step.m index 4e299682c..13ebe1380 100644 --- a/Cantera/matlab/cantera/@ReactorNet/step.m +++ b/Cantera/matlab/cantera/@ReactorNet/step.m @@ -9,7 +9,7 @@ function t = step(r, tout) % % Method 'step' takes one internal time step and returns. This % can be useful when it is desired to resolve a rapidly-changing -% solution in the output file. +% solution. % % This method can be used as follows: % @@ -24,5 +24,5 @@ function t = step(r, tout) % % See also: Reactor/advance % -t = reactormethods(21, reactor_hndl(r), tout); +t = reactornetmethods(21, reactornet_hndl(r), tout); diff --git a/Cantera/matlab/cantera/@ThermoPhase/minTemp.m b/Cantera/matlab/cantera/@ThermoPhase/minTemp.m index b9fc5980a..aa51949c1 100644 --- a/Cantera/matlab/cantera/@ThermoPhase/minTemp.m +++ b/Cantera/matlab/cantera/@ThermoPhase/minTemp.m @@ -1,6 +1,13 @@ -function v = critTemperature(a) -% CRITTEMPERATURE - Critical temperature [K]. +function v = minTemp(p) +% MINTEMP - Minimum temperature. +% +% The parameterizations used to represent the temperature-dependent +% species thermodynamic properties are generally only valid in some +% finite temperature range, which may be different for each species +% in the phase. This method returns the lowest temperature at which +% the parameterizations are valid for all species in the phase. % -% The critical temperature is the temperature at the critical point -% - v = thermo_get(p.tp_id,19); +% See also: maxTemp +% + v = thermo_get(p.tp_id,16); + diff --git a/Cantera/matlab/cantera/examples/ignite2.m b/Cantera/matlab/cantera/examples/ignite2.m index 02f260b5c..8bbcd0ee8 100755 --- a/Cantera/matlab/cantera/examples/ignite2.m +++ b/Cantera/matlab/cantera/examples/ignite2.m @@ -1,7 +1,7 @@ function ignite2(g) % IGNITE2 Zero-dimensional kinetics: adiabatic, constant volume. % -% This example illustrates how to use function 'reactor' for +% This example illustrates how to use function 'reactor_ode' for % zero-dimensional kinetics simulations with arbitrary heat flux % and volume vs. time. Here a constant-volume, adiabatic simulation % is conducted by setting vdot and q to zero. diff --git a/Cantera/matlab/cantera/examples/periodic_cstr.m b/Cantera/matlab/cantera/examples/periodic_cstr.m index 1843d3fe6..0aa766ab7 100644 --- a/Cantera/matlab/cantera/examples/periodic_cstr.m +++ b/Cantera/matlab/cantera/examples/periodic_cstr.m @@ -2,26 +2,29 @@ function periodic_cstr % % Periodic CSTR % -% This example illustrates a CSTR with steady inputs but periodic interior state. -% A stoichiometric hydrogen/oxygen mixture is introduced and reacts to produce water. -% But since water has a large efficiency as a third body in the chain termination reaction +% This example illustrates a CSTR with steady inputs but periodic +% interior state. A stoichiometric hydrogen/oxygen mixture is +% introduced and reacts to produce water. But since water has a +% large efficiency as a third body in the chain termination reaction % % H + O2 + M = HO2 + M % -% as soon as a significant amount of water is produced the reaction stops. After enough time has -% passed that the water is exhausted from the reactor, the mixture explodes again and the -% process repeats. This explanation can be verified by decreasing the rate for reaction 7 in -% file 'h2o2.xml' and re-running the example. +% as soon as a significant amount of water is produced the reaction +% stops. After enough time has passed that the water is exhausted from +% the reactor, the mixture explodes again and the process +% repeats. This explanation can be verified by decreasing the rate for +% reaction 7 in file 'h2o2.cti' and re-running the example. % -% Acknowledgments: The idea for this example and an estimate of the conditions needed to -% see the oscillations came from Bob Kee, Colorado School of Mines +% Acknowledgments: The idea for this example and an estimate of the +% conditions needed to see the oscillations came from Bob Kee, +% Colorado School of Mines % -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% help periodic_cstr % create the gas mixture -gas = IdealGasMix('h2o2.xml'); +gas = IdealGasMix('h2o2.cti'); % pressure = 60 Torr, T = 770 K p = 60.0*133.3; @@ -86,8 +89,9 @@ downstream = Reservoir(gas); v = Valve; install(v, cstr, downstream); setValveCoeff(v, 1.0e-9); -% mdot (kg/s) = coeff * (delta P, Pascals) +% create the network +network = ReactorNet({cstr}); % now integrate in time tme = 0.0; @@ -97,12 +101,13 @@ n = 0; while tme < 300.0 n = n + 1; tme = tme + dt; - advance(cstr, tme); + advance(network, tme); tm(n) = tme; y(1,n) = massFraction(cstr,'H2'); y(2,n) = massFraction(cstr,'O2'); y(3,n) = massFraction(cstr,'H2O'); end +clf figure(1) plot(tm,y) legend('H2','O2','H2O') diff --git a/Cantera/matlab/cantera/examples/prandtl1.m b/Cantera/matlab/cantera/examples/prandtl1.m index a2273724e..0a65d1662 100755 --- a/Cantera/matlab/cantera/examples/prandtl1.m +++ b/Cantera/matlab/cantera/examples/prandtl1.m @@ -51,6 +51,7 @@ disp(['CPU time = ' num2str(cputime - t0)]); % plot results clf; +%figure(1); subplot(2,2,1); surf(xo2,t,pr); xlabel('Elemental O/(O+H)'); diff --git a/Cantera/matlab/cantera/examples/reactor1.m b/Cantera/matlab/cantera/examples/reactor1.m index 79818b828..2d583a091 100644 --- a/Cantera/matlab/cantera/examples/reactor1.m +++ b/Cantera/matlab/cantera/examples/reactor1.m @@ -33,18 +33,21 @@ env = Reservoir(a); w = Wall; install(w,r,env); -% set expansion parameter. dV/dt = K(P_1 - P_2) +% set expansion parameter. dV/dt = KA(P_1 - P_2) setExpansionRateCoeff(w, 1.0e6); % set wall area setArea(w, 1.0); -t = 0; +% create a reactor network and insert the reactor: +network = ReactorNet({r}); + +t = 0.0; dt = 1.0e-5; t0 = cputime; for n = 1:100 t = t + dt; - advance(r, t); + advance(network, t); tim(n) = time(r); temp(n) = temperature(r); x(n,1:3) = moleFraction(gas,{'OH','H','H2'}); diff --git a/Cantera/matlab/cantera/examples/reactor2.m b/Cantera/matlab/cantera/examples/reactor2.m index 252359d44..2f52e61de 100644 --- a/Cantera/matlab/cantera/examples/reactor2.m +++ b/Cantera/matlab/cantera/examples/reactor2.m @@ -22,12 +22,15 @@ set(gas,'T',1001.0,'P',oneatm,'X','H2:2,O2:1,N2:4'); % create a reactor, and insert the gas r = Reactor(gas); +% create a reactor network and insert the reactor +network = ReactorNet({r}); + t = 0; dt = 1.0e-5; t0 = cputime; for n = 1:100 t = t + dt; - advance(r, t); + advance(network, t); tim(n) = time(r); temp(n) = temperature(r); x(n,1:3) = moleFraction(gas,{'OH','H','H2'}); diff --git a/Cantera/matlab/cantera/examples/run_examples.m b/Cantera/matlab/cantera/examples/run_examples.m index 387efc65f..63d0a68cf 100755 --- a/Cantera/matlab/cantera/examples/run_examples.m +++ b/Cantera/matlab/cantera/examples/run_examples.m @@ -15,6 +15,12 @@ pause surfreactor; disp('press any key to continue'); pause +periodic_cstr; +disp('press any key to continue'); +pause; +rankine(300.0, 2.0*oneatm, 0.8, 0.7); +disp('press any key to continue'); +pause; prandtl1(0); disp('press any key to continue'); pause diff --git a/Cantera/matlab/cantera/examples/surfreactor.m b/Cantera/matlab/cantera/examples/surfreactor.m index dc28e6e6b..695fe3f83 100644 --- a/Cantera/matlab/cantera/examples/surfreactor.m +++ b/Cantera/matlab/cantera/examples/surfreactor.m @@ -12,6 +12,9 @@ gas = importPhase('ptcombust.cti','gas'); % set the initial conditions set(gas,'T',t,'P',oneatm,'X','CH4:0.01, O2:0.21, N2:0.78'); +% The surface reaction mechanism describes catalytic combustion of +% methane on platinum, and is from Deutschman et al., 26th +% Symp. (Intl.) on Combustion,1996, pp. 1747-1754 surf = importInterface('ptcombust.cti','Pt_surf', gas); setTemperature(surf, t); @@ -39,22 +42,24 @@ setKinetics(w, surf, 0); % set the wall area and heat transfer coefficient. setArea(w, 1.0e-4); -setHeatTransferCoeff(w,0.1); +setHeatTransferCoeff(w,1.0e1); % W/m2/K -% set expansion parameter. dV/dt = K(P_1 - P_2) -setExpansionRateCoeff(w, 1.0); +% set expansion rate parameter. dV/dt = KA(P_1 - P_2) +setExpansionRateCoeff(w, 1.0e2); +network = ReactorNet({r}); t = 0; dt = 0.1; t0 = cputime; -names = {'CH4','O2','CO','CO2','H2O'}; -x = zeros([100 5]); +names = {'CH4','CO','CO2','H2O'}; +x = zeros([100 4]); for n = 1:100 t = t + dt; - advance(r, t); + advance(network, t); tim(n) = t; temp(n) = temperature(r); + pres(n) = pressure(r); cov(n,:) = coverages(surf)'; x(n,:) = moleFraction(gas,names); end @@ -66,11 +71,15 @@ plot(tim,temp); xlabel('Time (s)'); ylabel('Temperature (K)'); subplot(2,2,2); +plot(tim,pres); +xlabel('Time (s)'); +ylabel('Pressure (Pa)'); +subplot(2,2,3); semilogy(tim,cov); xlabel('Time (s)'); ylabel('Coverages'); legend(speciesNames(surf)); -subplot(2,2,3); +subplot(2,2,4); plot(tim,x); xlabel('Time (s)'); ylabel('Mole Fractions'); diff --git a/Cantera/matlab/cantera/private/ctmatutils.h b/Cantera/matlab/cantera/private/ctmatutils.h index 54acbdd47..410aec469 100755 --- a/Cantera/matlab/cantera/private/ctmatutils.h +++ b/Cantera/matlab/cantera/private/ctmatutils.h @@ -1,3 +1,5 @@ +const double Undef = -999.123; + void reportError(); void checkNArgs(const int n, const int nrhs); diff --git a/Cantera/matlab/cantera/private/ctmethods.cpp b/Cantera/matlab/cantera/private/ctmethods.cpp index 5a95da858..53be9da87 100644 --- a/Cantera/matlab/cantera/private/ctmethods.cpp +++ b/Cantera/matlab/cantera/private/ctmethods.cpp @@ -110,7 +110,8 @@ extern "C" { case FUNC_CLASS: funcmethods(nlhs, plhs, nrhs, prhs); break; default: - mexErrMsgTxt("unknown class"); + mexPrintf("iclass = %d",iclass); + //mexErrMsgTxt("unknown class"); } } } diff --git a/Cantera/matlab/cantera/private/flowdevicemethods.cpp b/Cantera/matlab/cantera/private/flowdevicemethods.cpp index a8cd270b3..09d15edeb 100644 --- a/Cantera/matlab/cantera/private/flowdevicemethods.cpp +++ b/Cantera/matlab/cantera/private/flowdevicemethods.cpp @@ -43,7 +43,7 @@ iok = flowdev_install(i, int(v), m); break; case 3: - iok = flowdev_setSetpoint(i, v); + iok = flowdev_setMassFlowRate(i, v); break; case 4: iok = flowdev_setParameters(i, 1, &v); @@ -54,6 +54,9 @@ case 6: iok = flowdev_ready(i); break; + case 7: + iok = flowdev_setMaster(i, int(v)); + break; default: mexErrMsgTxt("unknown job parameter"); } @@ -70,10 +73,7 @@ else if (job < 40) { switch (job) { case 21: - r = flowdev_massFlowRate(i); - break; - case 22: - r = flowdev_setpoint(i); + r = flowdev_massFlowRate(i, v); break; default: mexErrMsgTxt("unknown job parameter"); diff --git a/Cantera/matlab/cantera/private/reactormethods.cpp b/Cantera/matlab/cantera/private/reactormethods.cpp index 75788696b..b1000b1bd 100644 --- a/Cantera/matlab/cantera/private/reactormethods.cpp +++ b/Cantera/matlab/cantera/private/reactormethods.cpp @@ -4,8 +4,6 @@ #include "../../../clib/src/ct.h" #include "ctmatutils.h" -//const double Undef = -999.123; - void reactormethods( int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[] ) { @@ -46,18 +44,18 @@ case 4: iok = reactor_setInitialVolume(i, v); break; - // case 5: - //iok = reactor_setInitialTime(i, v); - //break; + case 5: + iok = reactor_setInitialTime(i, v); + break; case 6: iok = reactor_setThermoMgr(i, int(v)); break; case 7: iok = reactor_setKineticsMgr(i, int(v)); break; - //case 8: - //iok = reactor_advance(i, v); - //break; + case 8: + iok = reactor_advance(i, v); + break; case 9: iok = reactor_setEnergy(i, int(v)); break; @@ -76,9 +74,9 @@ else if (job < 40) { switch (job) { - //case 21: - //r = reactor_step(i, v); - //break; + case 21: + r = reactor_step(i, v); + break; case 22: r = reactor_time(i); break; @@ -116,3 +114,4 @@ return; } } + diff --git a/Cantera/matlab/cantera/private/reactornetmethods.cpp b/Cantera/matlab/cantera/private/reactornetmethods.cpp index 10cbbc41b..90b541c5f 100644 --- a/Cantera/matlab/cantera/private/reactornetmethods.cpp +++ b/Cantera/matlab/cantera/private/reactornetmethods.cpp @@ -17,7 +17,9 @@ double r = Undef; double v = Undef; + double v2 = -1.0; if (nrhs > 3) v = getDouble(prhs[3]); + if (nrhs > 4) v2 = getDouble(prhs[4]); // constructor if (job == 0) { @@ -45,10 +47,16 @@ break; case 4: iok = reactornet_addreactor(i, int(v)); - break; + break; case 5: iok = reactornet_setInitialTime(i, v); break; + case 6: + iok = reactornet_setMaxTimeStep(i, v); + break; + case 7: + iok = reactornet_setTolerances(i, v, v2); + break; case 8: iok = reactornet_advance(i, v); break; @@ -61,4 +69,30 @@ if (iok < 0) reportError(); return; } + + // options that return a value of type 'double' + + else if (job < 40) { + switch (job) { + case 21: + r = reactornet_step(i, v); + break; + case 22: + r = reactornet_time(i); + break; + case 23: + r = reactornet_rtol(i); + break; + case 24: + r = reactornet_atol(i); + break; + default: + mexErrMsgTxt("unknown job parameter"); + } + plhs[0] = mxCreateNumericMatrix(1,1,mxDOUBLE_CLASS,mxREAL); + double *h = mxGetPr(plhs[0]); + *h = r; + if (r == Undef) reportError(); + return; + } } diff --git a/Cantera/matlab/cantera/private/wallmethods.cpp b/Cantera/matlab/cantera/private/wallmethods.cpp index 86bf02edc..d705428d9 100644 --- a/Cantera/matlab/cantera/private/wallmethods.cpp +++ b/Cantera/matlab/cantera/private/wallmethods.cpp @@ -63,7 +63,7 @@ iok = wall_setExpansionRateCoeff(i, v); break; case 10: - iok = wall_setExpansionRate(i, int(v)); + iok = wall_setVelocity(i, int(v)); break; case 11: iok = wall_ready(i); @@ -73,6 +73,9 @@ m = getInt(prhs[4]); iok = wall_setkinetics(i, n, m); break; + case 13: + iok = wall_setEmissivity(i, v); + break; default: mexErrMsgTxt("unknown job parameter"); }