Interfacing GEOS-Chem with KPP
This page describes how to install and run KPP, and how to interface it with GEOS-Chem.
Installing KPP and Running the examples
The source code, examples and the documentation to install and run KPP are available directly from A. Sandu web page.
For version 2.2.1 of KPP to work with GEOS-Chem, you must modify the source code so duplicate and proportional reactions in the input files will trigger a warning instead of an error. (Thanks to Paul Eller.)
In the file kpp/src/scanner.c , search for the following line of code around line 665 (may be slightly different):
ScanError( "Duplicate equation: " " (eqn<%d> = eqn<%d> )", i+1, EqnNr+1 );
and change it to the following:
ScanWarning( "Duplicate equation: " " (eqn<%d> = eqn<%d> )", i+1, EqnNr+1 );
Then replace :
ScanError( "Linearly dependent equations: " "( %.0f eqn<%d> = %.0f eqn<%d> )", r1, i+1, r2, EqnNr+1 );
ScanWarning( "Linearly dependent equations: " "( %.0f eqn<%d> = %.0f eqn<%d> )", r1, i+1, r2, EqnNr+1 );
This should allow you to create the KPP model. Having duplicate and proportional equations should not be a problem for KPP.
(1) Installation of KPP is simple. You need to double check the location of the flex library. Ask your system administrator, or just use the "find" command.
(2) Running examples should not be a problem either. The kpp executable being on the $path, you just need to be in the directory were the model file (*.kpp) is to run kpp on it. (Some examples names are different between the distribution and the manual, but it is straightforward to figure it out.)
Generating KPP input files from GEOS-Chem globchem.dat
"geos2kpp_parser.pl" is a Perl script from Paul Eller that automatically generates the three input files for KPP from globchem.dat:
> geos2kpp_parser.pl globchem.dat
the script is available in two versions, one for the original globchem.dat format (geos2kpp_parser.pl), one for the new format used by Fabien Paulot for the alternate isoprene chemistry (paulot_geos2kpp_parser.pl).
this will create 3 files (globchem.def, globchem.eqn, globchem.spc). Then you must use "globchem" for the MODEL flag in the *.kpp file. So create a "gckpp.kpp", with a rosenbrock solver, like that:
#MODEL globchem #INTEGRATOR rosenbrock #LANGUAGE Fortran90 #DRIVER none #HESSIAN on #STOICMAT on
The "none" driver is enough to get the files needed for GEOS-Chem. We are not generating a standalone code.
Put the gckpp.kpp file and the globchem* files in the same directory, and call kpp there:
> kpp gckpp.kpp
this will generate all the necessary files:
gckpp_Function.f90 gckpp_Global.f90 gckpp_Hessian.f90 gckpp_HessianSP.f90 gckpp_Initialize.f90 gckpp_Integrator.f90 gckpp_Jacobian.f90 gckpp_JacobianSP.f90 gckpp_LinearAlgebra.f90 gckpp_Model.f90 gckpp_Monitor.f90 gckpp_Parameters.f90 gckpp_Precision.f90 gckpp_Rates.f90 gckpp_Stoichiom.f90 gckpp_StoichiomSP.f90 gckpp_Util.f90
Interfacing the generated Code into GEOS-Chem
--phs 14:23, 16 October 2009 (EDT)