source: trunk/LMDZ.TITAN/libf/chimtitan/chimie.c @ 2241

Last change on this file since 2241 was 2099, checked in by jvatant, 7 years ago

Fix a problem of interoperability C-Fortran for picky compilers.
Using iso_c_binding could be a smart future improvement to bring.
--JVO

File size: 4.0 KB
Line 
1/* chimie: Chemistry fabric */
2/* GCCM */
3
4/* ko: low pressure limit:  3 body reaction (1st) */
5/* ki: high pressure limit: 2 body reaction (2nd) */
6
7#include "titan.h"
8
9void chimie_( char CORPS[][10], double *NB, double *TEMP, double KRATE[][NLEV], int REACTIF[][5],
10             int *NOM_PERTE, int *NOM_PROD, int PERTE[][200][2], int PROD[][200] )
11{
12   int    dep,i,j,k,l,lat;
13   double  ai,ao,ei,eo,ki,ko,m,ti,to;
14   FILE   *out;
15   static char   reaction[NREAC+1][12][10]={
16#include VERCHIM
17   "",       "",       "",       "",     "",  "","","","","","",""};
18
19   for( i = 0; i <= NC-1; i++ )
20   {
21      NOM_PERTE[i] = NOM_PROD[i] = 0;
22      for( j = 0; j < 200; j++ )
23         PERTE[i][j][0] = PERTE[i][j][1] = PROD[i][j] = 0;
24   }
25   dep = 0;
26   for( i = dep; i <= NREAC-1; i++ )            /* Number of reactions */
27   {
28      for( j = 0; j <= 4; j++ )                 /* Number of compouds in each reactions */
29      {
30         k = 0;
31         if( (strcmp(reaction[i][j],"prod"))   /* prod and soot are not */
32          && (strcmp(reaction[i][j],"soot"))   /* considered in the compounds */
33          && (strcmp(reaction[i][j],""))     ) /* Which compound ? */
34         {
35            while( strcmp(reaction[i][j],CORPS[k]) )     /* Compound in reaction j, column i */
36            {
37               if( k == NC+1 )
38               {
39                  out = fopen( "err.log", "a" );
40                  fprintf( out, "I cannot find %s\n", reaction[i][j] );
41                  fclose( out );
42                  exit(0);
43               }
44               k++;
45            }
46            REACTIF[i][j] = k;                         /* is number k */
47         }
48         else REACTIF[i][j] = NC;
49      }
50   }
51   for( i = dep; i <= NREAC-1; i++ )     /* Total loss and production */
52   {
53      j = REACTIF[i][0];                 /* First compound reaction i */
54      k = NOM_PERTE[j] + 1;              /* Loss one more times */
55      if( k >= 200 ) exit(0);
56      NOM_PERTE[j] = k;
57      PERTE[j][k-1][0] = i;              /* Compound j loss in reaction i for the kth time */
58      PERTE[j][k-1][1] = REACTIF[i][1];  /* Compound j reacts with number 2 in reaction i */
59      j = REACTIF[i][1];                 /* Second compound reaction i */
60      if( j != NC )                      /* Neither photodissociation nor desexcitation */
61      {
62       k = NOM_PERTE[j] + 1;             /* Loss one more times */
63       if( k >= 200 ) exit(0);
64       NOM_PERTE[j] = k;
65       PERTE[j][k-1][0] = i;             /* Compound j is loss in reaction i for the kth times */
66       PERTE[j][k-1][1] = REACTIF[i][0]; /* Compound j reacts with number 1 reaction i */
67      }
68      for( j = 2; j < 5; j++ )           /* Compounds from 3 to 5 */
69      {
70         k = REACTIF[i][j];              /* Number of compound */
71         if( k != NC )
72         {
73            l = NOM_PROD[k] + 1;         /* One more time produced */
74            if( l >= 200 ) exit(0);
75            NOM_PROD[k]  = l;
76            PROD[k][l-1] = i;             /* at reaction i */
77         }
78      }
79   }
80   for( i = RDISS+1; i <= NREAC-1; i++ )   /* 0 a RDISS-1: photodiss, RDISS: disso N2 */
81   {
82      ao = strtod(reaction[i][5], NULL);
83      to = strtod(reaction[i][6], NULL);
84      eo = strtod(reaction[i][7], NULL);
85      ai = strtod(reaction[i][8], NULL);
86      ti = strtod(reaction[i][9], NULL);
87      ei = strtod(reaction[i][10],NULL);
88      m  = strtod(reaction[i][11],NULL);
89      for( j = 0; j <= NLEV-1; j++ )
90      {
91            ko = ao * pow( TEMP[j], to) * exp( eo / TEMP[j] );
92            if( m == 1.0e0 )
93               KRATE[i][j] = ko;
94            else if( m == 2.0e0 )
95            {
96               KRATE[i][j] = ko * pow( NB[j], 2.0e0 );
97            }
98            else if( m == 3.0e0 )
99            {
100               if( ai == 0.0e0 )
101                  KRATE[i][j] = ko * pow( NB[j], 3.0e0 );
102               else
103               {
104                  ki = ai * pow( TEMP[j], ti ) * exp( ei / TEMP[j] );
105                  KRATE[i][j] = pow( NB[j], 3.0e0 ) * ko * ki / ( ko * NB[j] + ki );
106               }
107            }
108      }
109   }
110}
Note: See TracBrowser for help on using the repository browser.