/****************************************************************************** KPP - The Kinetic PreProcessor Builds simulation code for chemical kinetic systems Copyright (C) 1995-1996 Valeriu Damian and Adrian Sandu Copyright (C) 1997-2005 Adrian Sandu KPP is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation (http://www.gnu.org/copyleft/gpl.html); either version 2 of the License, or (at your option) any later version. KPP is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, consult http://www.gnu.org/copyleft/gpl.html or write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. Adrian Sandu Computer Science Department Virginia Polytechnic Institute and State University Blacksburg, VA 24060 E-mail: sandu@cs.vt.edu ******************************************************************************/ #include #include #include "gdata.h" #include "scan.h" char *eqFileName; char *rootFileName = "ff"; char Home[ MAX_PATH ] = ""; short int linStru[ MAX_SPECIES ]; short int colStru[ MAX_SPECIES ]; short int bestStru[ MAX_SPECIES ]; short int *Stru; enum stru_criteria { UNSORT, LINSORT, COLSORT, BESTSORT }; void EqCopy( EQ_VECT e1, EQ_VECT e2 ) { int i; for( i = 0; i < EqnNr; i++ ) e2[i] = e1[i]; } int NoSort( const void *p1, const void *p2 ) { return -1; } int CodeCmp( const void *p1, const void *p2 ) { CODE *c1, *c2; c1 = (CODE*)p1; c2 = (CODE*)p2; if ( *c1 < *c2 ) return -1; if ( *c1 > *c2 ) return 1; return 0; } int CodeRCmp( const void *p1, const void *p2 ) { int rc1, rc2; CODE *c1, *c2; c1 = (CODE*)p1; c2 = (CODE*)p2; rc1 = Reactive[ ReverseCode[ *c1 ] ]; rc2 = Reactive[ ReverseCode[ *c2 ] ]; if ( rc1 > rc2 ) return -1; if ( rc1 < rc2 ) return 1; if ( *c1 < *c2 ) return -1; if ( *c1 > *c2 ) return 1; return 0; } int CodeSSCmp( const void *p1, const void *p2 ) { return -CodeRCmp(p1,p2); } int CodeSCmp( const void *p1, const void *p2 ) { CODE *c1, *c2; short int sc1, sc2; c1 = (CODE*)p1; c2 = (CODE*)p2; sc1 = Stru[ ReverseCode[ *c1 ] ]; sc2 = Stru[ ReverseCode[ *c2 ] ]; if ( sc1 > sc2 ) return 1; if ( sc1 < sc2 ) return -1; if ( *c1 < *c2 ) return 1; if ( *c1 > *c2 ) return -1; return 0; } void UpdateStructJ() { int i,j,k; for ( i=0; i j) nl++; if(i <= j) nu++; } return nu+nl; } int LUnonZero() { CODE v[MAX_SPECIES]; CODE *var; int i,j,k; int nu,nl; var = v; if( Stru != bestStru ) { for( i=0; i tmp; mv tmp %s_Update_RCONST.m;", root, root, root ); system( buf ); } /* Postprocessing to replace parameter names by values in the declarations strcpy( cmd, "sed " ); sprintf( cmd, "%s -e 's/(NVAR)/(%d)/g'", cmd, VarNr ); sprintf( cmd, "%s -e 's/(NFIX)/(%d)/g'", cmd, FixNr ); sprintf( cmd, "%s -e 's/(NSPEC)/(%d)/g'", cmd,SpcNr ); sprintf( cmd, "%s -e 's/(NREACT)/(%d)/g'", cmd, EqnNr ); sprintf( cmd, "%s -e 's/(NONZERO)/(%d)/g'", cmd, Jac_NZ ); sprintf( cmd, "%s -e 's/(LU_NONZERO)/(%d)/g'", cmd, LU_Jac_NZ ); sprintf( cmd, "%s -e 's/(NHESS)/(%)/g'", cmd, Hess_NZ ); sprintf( buf, "%s_Function", rootFileName ); switch( useLang ) { case F77_LANG: sprintf( buf, "%s.f", buf ); break; case F90_LANG: sprintf( buf, "%s.f90", buf ); break; case C_LANG: sprintf( buf, "%s.c", buf ); break; case MATLAB_LANG: sprintf( buf, "%s.m", buf ); break; default: printf("\n Language '%d' not implemented!\n",useLang); exit(1); } sprintf( cmdexe, "%s %s > %s; mv %s %s;", cmd, buf, tmpfile, tmpfile, buf ); printf("\n\nCMDEXE='%s'\n",cmdexe); system( cmdexe ); */ } /*******************************************************************/ int main( int argc, char * argv[] ) { int status; char name[ 200 ]; char *p; int i,j; AllocInternalArrays(); p = getenv("KPP_HOME"); if( p ) strcpy( Home, p ); switch( argc ) { case 3: eqFileName = argv[1]; rootFileName = argv[2]; break; case 2: eqFileName = argv[1]; strcpy( name, eqFileName ); p = name + strlen(name); while( p > name ) { if( *p == '.') { *p = '\0'; break; } p--; } rootFileName = name; break; default: FatalError(1,"\nUsage :" "\n kpp [output file]\n"); } printf("\nThis is KPP-%s.\n", KPP_VERSION); printf("\nKPP is parsing the equation file."); status = ParseEquationFile( argv[1] ); if( status ) FatalError(2,"%d errors and %d warnings encountered.", nError, nWarning ); /* Allocate some internal data structures */ AllocStructArrays(); printf("\nKPP is computing Jacobian sparsity structure."); ReorderSpecies( UNSORT ); if (useReorder==1){ BestSparsity(); ReorderSpecies( BESTSORT ); } UpdateStructJ(); ComputeLUStructJ(); if( initNr == -1 ) initNr = VarNr; printf("\nKPP is starting the code generation."); Generate( rootFileName ); printf("\nKPP is starting the code post-processing."); Postprocess( rootFileName ); printf("\n\nKPP has succesfully created the model \"%s\".\n\n",rootFileName); if( nError ) exit(4); if( nWarning ) exit(5); exit(0); }