initial import

This commit is contained in:
Dave Goodwin 2004-04-24 12:55:47 +00:00
parent 06f94656f2
commit e66da6df6a
6 changed files with 152 additions and 0 deletions

View file

@ -0,0 +1,23 @@
function x = ReactorNet(reactors)
% REACTOR - Create a ReactorNet object.
%
% 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');
end
x.index = reactornetmethods(0);
if x.index < 0
error(geterr);
end
x = class(x,'ReactorNet');
% add reactors
unfinished

View file

@ -0,0 +1,22 @@
function advance(r, 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
% '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)
% ...
% <add output commands here>
% ...
% end
%
% See also: ReactorNet/step
%
reactormethods(8, reactornet_hndl(r), tout);

View file

@ -0,0 +1,13 @@
function v = reactornetmethods(n, job, a, b, c, d)
%
if nargin == 2
v = ctmethods(65, n, job);
elseif nargin == 3
v = ctmethods(65, n, job, a);
elseif nargin == 4
v = ctmethods(65, n, job, a, b);
elseif nargin == 5
v = ctmethods(65, n, job, a, b, c);
elseif nargin == 6
v = ctmethods(65, n, job, a, b, c, d);
end

View file

@ -0,0 +1,2 @@
function i = reactor_hndl(r)
i = r.index;

View file

@ -0,0 +1,28 @@
function t = step(r, tout)
% STEP - Take one internal time step toward tout.
%
% The integrator used to integrate the ODEs (CVODE) takes
% variable-size steps, chosen so that a specified error
% tolerance is maintained. At times when the solution is rapidly
% changing, the time step becomes smaller to resolve the
% solution.
%
% 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.
%
% This method can be used as follows:
%
% t = 0.0
% tout = 0.1
% while t < tout
% t = step(r, tout)
% ,,,
% <commands to save desired variables>
% ...
% end
%
% See also: Reactor/advance
%
t = reactormethods(21, reactor_hndl(r), tout);

View file

@ -0,0 +1,64 @@
#include "mex.h"
#include "../../../clib/src/ctreactor.h"
#include "../../../clib/src/ct.h"
#include "ctmatutils.h"
//const double Undef = -999.123;
void reactornetmethods( int nlhs, mxArray *plhs[],
int nrhs, const mxArray *prhs[] )
{
int j, m, iok, n;
char *file, *key, *val;
int job = getInt(prhs[1]);
int i = getInt(prhs[2]);
double r = Undef;
double v = Undef;
if (nrhs > 3) v = getDouble(prhs[3]);
// constructor
if (job == 0) {
n = reactornet_new(i);
plhs[0] = mxCreateNumericMatrix(1,1,mxDOUBLE_CLASS,mxREAL);
double *h = mxGetPr(plhs[0]);
*h = double(n);
if (n < 0) reportError();
return;
}
// options that do not return a value
if (job < 20) {
switch (job) {
case 1:
iok = reactornet_del(i);
break;
case 2:
iok = reactornet_copy(i);
break;
case 3:
iok = reactornet_assign(i,int(v));
break;
case 4:
iok = reactornet_addreactor(i, int(v));
break;
case 5:
iok = reactornet_setInitialTime(i, v);
break;
case 8:
iok = reactornet_advance(i, v);
break;
default:
mexErrMsgTxt("unknown job parameter");
}
plhs[0] = mxCreateNumericMatrix(1,1,mxDOUBLE_CLASS,mxREAL);
double *h = mxGetPr(plhs[0]);
*h = double(iok);
if (iok < 0) reportError();
return;
}
}