1 | /* tractitan: suivi de traceurs avec constantes de temps de rappel */ |
---|
2 | /* GCCM */ |
---|
3 | |
---|
4 | #include "titan.h" |
---|
5 | |
---|
6 | void tractitan_( double *RB, char CORPS[][10], double Y[][NLEV], |
---|
7 | double Y0[][NLEV], double *FIN ) |
---|
8 | { |
---|
9 | char outlog[100],corps[100][10]; |
---|
10 | int i,j,k,l; |
---|
11 | double annee,**tau,**ym1; |
---|
12 | double cm,conv,cp,delta,deltamax,deltao; |
---|
13 | double test,time,ts; |
---|
14 | char str2[15]; |
---|
15 | FILE *out; |
---|
16 | |
---|
17 | for( i = 0; i <= NC; i++) |
---|
18 | { |
---|
19 | strcpy( corps[i], CORPS[i] ); |
---|
20 | corps[i][strcspn(CORPS[i], " ")] = '\0'; |
---|
21 | } |
---|
22 | |
---|
23 | time = ts = 0.0e0; |
---|
24 | annee = 9.46728e8; |
---|
25 | strcpy( outlog, "chimietitan" ); |
---|
26 | strcat( outlog, ".log" ); |
---|
27 | deltamax = 2.e5; |
---|
28 | |
---|
29 | deltao = delta = 1.e5; |
---|
30 | |
---|
31 | ym1 = dm2d( 0, NC-1, 0, NLEV-1 ); |
---|
32 | tau = dm2d( 0, NC-1, 0, NLEV-1 ); |
---|
33 | |
---|
34 | /* debug */ |
---|
35 | /* |
---|
36 | out = fopen( "err.log", "a" ); |
---|
37 | fprintf( out,"%s\n", ); |
---|
38 | fclose( out ); |
---|
39 | */ |
---|
40 | |
---|
41 | /* Composition pour le rappel (identique a inichim): Y0 */ |
---|
42 | |
---|
43 | /* initialisation ym1 */ |
---|
44 | |
---|
45 | for( j = 0; j <= NLEV-1; j++ ) |
---|
46 | for( i = 0; i <= NC-1; i++ ) ym1[i][j] = Y[i][j]; |
---|
47 | |
---|
48 | /* initialisation tau sans dependance en lat */ |
---|
49 | |
---|
50 | for( i = 0; i <= NC-1; i++ ) |
---|
51 | { |
---|
52 | for( j = NLEV-1; j >= 0; j-- ) |
---|
53 | { |
---|
54 | tau[i][j] = 1.e6; /* autres corps = 1.e6 s, donc rappel tres fort */ |
---|
55 | |
---|
56 | if( strcmp(corps[i],"C2H2") == 0 ) |
---|
57 | tau[i][j] = annee*pow( 10., 2.+1.*(100.-(RB[j]-R0))/200. ); |
---|
58 | if( strcmp(corps[i],"C2H6") == 0 ) |
---|
59 | tau[i][j] = annee*pow( 10., 1.+1.*(200.-(RB[j]-R0))/300. ); |
---|
60 | if( strcmp(corps[i],"HCN") == 0 ) |
---|
61 | { |
---|
62 | if( (RB[j]-R0) >= 350. ) |
---|
63 | tau[i][j] = annee*pow( 10., 1.+1.3*((RB[j]-R0)-350.)/150. ); |
---|
64 | else |
---|
65 | tau[i][j] = annee*10.; |
---|
66 | } |
---|
67 | if( strcmp(corps[i],"C4H2") == 0 ) |
---|
68 | { |
---|
69 | if( (RB[j]-R0) >= 300. ) |
---|
70 | tau[i][j] = annee*pow( 10.,-1.+0.3*(300.-(RB[j]-R0))/200. ); |
---|
71 | else |
---|
72 | tau[i][j] = annee*pow( 10., 0.+1.0*(100.-(RB[j]-R0))/200. ); |
---|
73 | } |
---|
74 | } |
---|
75 | /* COUCHES HAUTES: RAPPEL FORCE PLUS GRAND */ |
---|
76 | tau[i][NLEV-1] = min(tau[i][NLEV-1],annee/100.); |
---|
77 | tau[i][NLEV-2] = min(tau[i][NLEV-2],annee/50.); |
---|
78 | tau[i][NLEV-3] = min(tau[i][NLEV-3],annee/10.); |
---|
79 | /* tau[i][NLEV-4] = min(tau[i][NLEV-4],annee/100.); */ |
---|
80 | } |
---|
81 | |
---|
82 | /* out = fopen( outlog, "a" ); */ |
---|
83 | /* vu la rapidite, on laisse le fichier ouvert pendant toute la boucle */ |
---|
84 | |
---|
85 | /* ***************** */ |
---|
86 | /* Main time loop. */ |
---|
87 | /* ***************** */ |
---|
88 | |
---|
89 | while( time < (*FIN) ) |
---|
90 | { |
---|
91 | for( i = 0; i <= NC-1; i++ ) |
---|
92 | { |
---|
93 | /* rappel */ |
---|
94 | /* ------ */ |
---|
95 | for( j = NLEV-2; j >= 0; j-- ) |
---|
96 | Y[i][j] += delta * ( Y0[i][j] - Y[i][j] ) / tau[i][j]; |
---|
97 | /* on laisse fixe la couche la plus haute */ |
---|
98 | Y[i][NLEV-1] = Y0[i][NLEV-1]; |
---|
99 | } |
---|
100 | |
---|
101 | /* test evolution delta */ |
---|
102 | /* -------------------- */ |
---|
103 | for( j = 0; j <= NLEV-2; j++ ) if( (RB[j]-R0) >= 90. ) |
---|
104 | for( i = 0; i <= NC-1; i++ ) |
---|
105 | { |
---|
106 | test = 1.0e-15; |
---|
107 | if( ( Y[i][j] > test ) && ( ym1[i][j] > test ) ) |
---|
108 | { |
---|
109 | conv = fabs( Y[i][j] - ym1[i][j] ) / ym1[i][j]; |
---|
110 | if( conv > ts ) |
---|
111 | { |
---|
112 | /* |
---|
113 | if( conv > 0.1 ) |
---|
114 | { |
---|
115 | fprintf(out, "%d %s %e %e\n",j,corps[i],ym1[i][j],Y[i][j]); |
---|
116 | } |
---|
117 | */ |
---|
118 | ts = conv; |
---|
119 | } |
---|
120 | } |
---|
121 | } |
---|
122 | /* |
---|
123 | fprintf(out, "%e %e %e\n",time,delta,ts); |
---|
124 | */ |
---|
125 | if( ts < 0.1e0 ) |
---|
126 | { |
---|
127 | for( i = 0; i <= NC-1; i++ ) |
---|
128 | for( j = 0; j <= NLEV-1; j++ ) |
---|
129 | if( Y[i][j] >= 1.0e0 ) |
---|
130 | { |
---|
131 | /* |
---|
132 | fprintf( out, "WARNING %s mixing ratio is %e %e at %d", |
---|
133 | corps[i], ym1[i][j], Y[i][j], j ); |
---|
134 | fclose( out ); |
---|
135 | */ |
---|
136 | exit(0); |
---|
137 | } |
---|
138 | for( j = 0; j <= NLEV-1; j++ ) |
---|
139 | for( i = 0; i <= NC-1; i++ ) ym1[i][j] = Y[i][j]; |
---|
140 | time += ( deltao = delta ); |
---|
141 | if( ts < 1.00e-5 ) delta *= 10.e0; |
---|
142 | if( ( ts > 1.00e-5 ) && ( ts < 1.0e-4 ) ) delta *= 5.0e0; |
---|
143 | if( ( ts > 1.00e-4 ) && ( ts < 1.0e-3 ) ) delta *= 2.0e0; |
---|
144 | if( ( ts > 0.001e0 ) && ( ts < 0.01e0 ) ) delta *= 1.5e0; |
---|
145 | if( ( ts > 0.010e0 ) && ( ts < 0.05e0 ) ) delta *= 1.1e0; |
---|
146 | |
---|
147 | delta = min( deltamax, delta ); |
---|
148 | |
---|
149 | if( ( time + delta ) > (*FIN) ) |
---|
150 | { |
---|
151 | delta = (*FIN) - time; |
---|
152 | time = (*FIN); |
---|
153 | } |
---|
154 | } |
---|
155 | else |
---|
156 | { |
---|
157 | for( j = 0; j <= NLEV-1; j++ ) |
---|
158 | for( i = 0; i <= NC-1; i++ ) Y[i][j] = ym1[i][j]; |
---|
159 | delta *= 0.3e0; |
---|
160 | } |
---|
161 | ts = 0.0e0; |
---|
162 | } |
---|
163 | |
---|
164 | /* **************** */ |
---|
165 | /* end of main loop */ |
---|
166 | /* **************** */ |
---|
167 | |
---|
168 | /* |
---|
169 | fprintf( out, "%e\n", time ); |
---|
170 | fclose( out ); |
---|
171 | */ |
---|
172 | fdm2d( ym1, 0, NC-1, 0 ); |
---|
173 | fdm2d( tau, 0, NC-1, 0 ); |
---|
174 | } |
---|