CCL Home Page
Up Directory CCL rxn.c
/*
The permission is granted to use the software as is and redistribute it in
its original and complete form. If you find this program useful and publish
results obtained by it, please cite the program as:
Michael Whitbeck, Desert Research Institute, 1991, "REACT - Program to solve
kinetic equations for chemical systems". Version 1.00, this code is
available from the authors or from Dr. Whitbeck.
*/

/*
 rxn    chemical reaction simulation
*/

#include 
#include "rxn.h"

extern void lsoda();
extern void rxnparse();
extern void reprint();
extern void initial();
extern void *derivs();
extern void setfiles();
main (argc,argv) int argc; char **argv;
{
double rwork1, rwork5, rwork6, rwork7;
double *atol, *rtol, t, tout, step, stop, tol;
int iwork1, iwork2, iwork5, iwork6, iwork7, iwork8, iwork9;
int itol, itask, istate, iopt, jt, iout, j, jdum;
int n,s;
char *help=" you must specify a file name\n\n\n\
 REACT is a chemical kinetics simulation program.\n\
 This code may be freely used and distributed but must not be sold;\n\
 you may make a reasonable charge for handling/copying for others.\n\n\
 There are two input files required. If you invoke the code by typing\n\
	react foo\n\
 then react opens file foo.m to read a reaction mechanism of the form\n\
	k-value	reactants -> products\n\
 It also opens a file foo.p containing the run parameters of the form\n\
	start-time stop-time output-time-interval tolerance\n\
	species-name initial-value abs-tolerance relative-tolerance\n\
\n\n\n\
Send corresponance and bug reports to :\n\
___________________________________________________________\n\
|Mike Whitbeck             | whitbeck@unssun.unr.edu      |\n\
|Desert Research Inst.     | whitbeck@wheeler.wrc.unr.edu |\n\
|POB 60220                 | whitbeck@sanjuan.UUCP        |\n\
|RENO, NV 89506 USA        | 702-673-7348                 |\n\
|__________________________|______________________________|\n\
the University of Nevada\n\n";

extern void wr_results();
extern void wr_species();

if (argc <2)  bail(help);
iwork1= iwork2= iwork5= iwork6= iwork7= iwork8= iwork9= 0;
rwork1= rwork5= rwork6= rwork7= 0.0;

setfiles(argv[1]); /* build file names */
rxnparse(&n,&s); /* input mechanism and parse */
rtol = (double *) malloc((unsigned)((s+1)*sizeof(double)));
atol = (double *) malloc((unsigned)((s+1)*sizeof(double)));
atol[0]  = rtol[0] = 0.0;
initial(s,&t,&tout,&stop,&step, atol, rtol); /* set initial values */
wr_species();

#ifdef DEBUG
reprint(n,s);
for (iout=1; iout <= s; iout++) printf("%15.4e %15.4e\n",atol[iout],rtol[iout]);
#endif

itol = 4; itask = 1; istate = 1; iopt = 0; jt = 2;
 
if ((Ywrite = fopen(results,"w+")) == NULL) 
  bail ("Could not open results file");
wr_results(s,t,Y); /* initial values */
/* for (iout=1; iout <= 50; iout++) */
do {
  lsoda(derivs,s,Y,&t,tout,itol,rtol,atol,itask,&istate,iopt,jt,
	iwork1, iwork2, iwork5, iwork6, iwork7, iwork8, iwork9,
	rwork1,rwork5,rwork6,rwork7);
  wr_results(s,t,Y);
/*  if (istate <= 0) {
		printf("error istate = %d\n",istate);
		exit(0);
		} */
  switch (istate+7){
	case 6: istate = 2; break;
	case 5: bail("reduce tolerances"); break;
	case 3: bail("possible singularity");break;
	case 4:
	case 2: bail("not converging"); break;
	case 1: bail("component vanished");break;
	case 0: bail("code problem"); break;
	case 8:
	case 9:
	default: break;
	}
  tout += step;
	} while(t < stop);
fclose(Ywrite);
}
Modified: Tue May 14 16:00:00 1991 GMT
Page accessed 4999 times since Sat Apr 17 21:58:36 1999 GMT