00001
00002
00003
00004 #include "cddefines.h"
00005 #include "thermal.h"
00006 #include "radius.h"
00007 #include "conv.h"
00008 #include "lines_service.h"
00009 #include "dense.h"
00010 #include "taulines.h"
00011 #include "phycon.h"
00012 #include "elementnames.h"
00013 #include "dynamics.h"
00014 #include "save.h"
00015
00016
00017
00018 static const int IPRINT= 9;
00019
00020
00021
00022 void SaveHeat(FILE* io)
00023 {
00024 char **chLabel,
00025 chLbl[11];
00026 bool lgHeatLine;
00027 int nFail;
00028 long int i,
00029 ipnt,
00030 *ipOrdered,
00031 *ipsave,
00032 j,
00033 *jpsave,
00034 k;
00035 double CS,
00036 ColHeat,
00037 EscP,
00038 Pump,
00039 TauIn,
00040 cool_total,
00041 heat_total;
00042 realnum *SaveVal;
00043
00044 DEBUG_ENTRY( "SaveHeat()" );
00045
00046 SaveVal = (realnum *) CALLOC(LIMELM*LIMELM, sizeof(realnum));
00047 ipsave = (long int *) CALLOC(LIMELM*LIMELM, sizeof(long int));
00048 jpsave = (long int *) CALLOC(LIMELM*LIMELM, sizeof(long int));
00049 ipOrdered = (long int *) CALLOC(LIMELM*LIMELM, sizeof(long int));
00050 chLabel = (char **) CALLOC(LIMELM*LIMELM, sizeof(char *));
00051
00052 for( i=0; i<LIMELM*LIMELM; ++i )
00053 {
00054 ipsave[i] = INT_MIN;
00055 jpsave[i] = INT_MIN;
00056 SaveVal[i] = -FLT_MAX;
00057 chLabel[i] = (char *) CALLOC(10, sizeof(char));
00058 }
00059
00060 cool_total = thermal.ctot;
00061 heat_total = thermal.htot;
00062
00063
00064
00065
00066
00067
00068 cool_total -= dynamics.Cool();
00069 heat_total -= dynamics.Heat();
00070 # if 0
00071 if(dynamics.Cool() > dynamics.Heat())
00072 {
00073 cool_total -= dynamics.Heat();
00074 heat_total -= dynamics.Heat();
00075 }
00076 else
00077 {
00078 cool_total -= dynamics.Cool();
00079 heat_total -= dynamics.Cool();
00080 }
00081 # endif
00082
00083 ipnt = 0;
00084
00085
00086
00087
00088 for( i=0; i < LIMELM; i++ )
00089 {
00090 for( j=0; j < LIMELM; j++ )
00091 {
00092 if( thermal.heating[i][j]/SDIV(heat_total) > SMALLFLOAT )
00093 {
00094 ipsave[ipnt] = i;
00095 jpsave[ipnt] = j;
00096 SaveVal[ipnt] = (realnum)(thermal.heating[i][j]/SDIV(heat_total));
00097 ipnt++;
00098 }
00099 }
00100 }
00101
00102
00103
00104
00105 for( i=0; i < thermal.ncltot; i++ )
00106 {
00107 if( thermal.heatnt[i]/SDIV(heat_total) > save.WeakHeatCool )
00108 {
00109 realnum awl;
00110 awl = thermal.collam[i];
00111
00112 if( awl > 100000 )
00113 awl /= 10000;
00114 fprintf( io, " Negative coolant was %s %.2f %.2e\n",
00115 thermal.chClntLab[i], awl, thermal.heatnt[i]/SDIV(heat_total) );
00116 }
00117 }
00118
00119 if( !conv.lgConvTemp )
00120 {
00121 fprintf( io, "#>>>> Temperature not converged.\n" );
00122 }
00123 else if( !conv.lgConvEden )
00124 {
00125 fprintf( io, "#>>>> Electron density not converged.\n" );
00126 }
00127 else if( !conv.lgConvIoniz() )
00128 {
00129 fprintf( io, "#>>>> Ionization not converged.\n" );
00130 }
00131 else if( !conv.lgConvPres )
00132 {
00133 fprintf( io, "#>>>> Pressure not converged.\n" );
00134 }
00135
00136
00137
00138 i = INT_MIN;
00139 j = INT_MIN;
00140
00141 for( k=0; k < ipnt; k++ )
00142 {
00143
00144
00145
00146 i = ipsave[k];
00147 j = jpsave[k];
00148
00149 if( i >= j )
00150 {
00151 if( dense.xIonDense[i][j] == 0. && thermal.heating[i][j]>SMALLFLOAT )
00152 fprintf(ioQQQ,"DISASTER assert about to be thrown - search for hit it\n");
00153
00154
00155
00156 ASSERT( dense.xIonDense[i][j] > 0. || thermal.heating[i][j]<SMALLFLOAT );
00157
00158 strcpy( chLabel[k], elementnames.chElementSym[i] );
00159 strcat( chLabel[k], elementnames.chIonStage[j] );
00160 }
00161
00162 else if( i == 0 && j == 1 )
00163 {
00164
00165
00166 strcpy( chLabel[k], "Hn=2" );
00167 }
00168 else if( i == 0 && j == 3 )
00169 {
00170
00171
00172 strcpy( chLabel[k], "Hion" );
00173 }
00174 else if( i == 0 && j == 7 )
00175 {
00176
00177 strcpy( chLabel[k], " UTA" );
00178 }
00179 else if( i == 0 && j == 8 )
00180 {
00181
00182
00183 strcpy( chLabel[k], "H2vH" );
00184 }
00185 else if( i == 0 && j == 17 )
00186 {
00187
00188
00189
00190 strcpy( chLabel[k], "H2dH" );
00191 }
00192 else if( i == 0 && j == 9 )
00193 {
00194
00195 strcpy( chLabel[k], "COds" );
00196 }
00197 else if( i == 0 && j == 20 )
00198 {
00199
00200 strcpy( chLabel[k], "extH" );
00201 }
00202 else if( i == 0 && j == 21 )
00203 {
00204
00205 strcpy( chLabel[k], "pair" );
00206 }
00207 else if( i == 0 && j == 11 )
00208 {
00209
00210 strcpy( chLabel[k], "H FF" );
00211 }
00212 else if( i == 0 && j == 12 )
00213 {
00214
00215 strcpy( chLabel[k], "Hcol" );
00216 }
00217 else if( i == 0 && j == 13 )
00218 {
00219
00220 strcpy( chLabel[k], "GrnP" );
00221 }
00222 else if( i == 0 && j == 14 )
00223 {
00224
00225 strcpy( chLabel[k], "GrnC" );
00226 }
00227 else if( i == 0 && j == 15 )
00228 {
00229
00230 strcpy( chLabel[k], "H- " );
00231 }
00232 else if( i == 0 && j == 16 )
00233 {
00234
00235 strcpy( chLabel[k], "H2+ " );
00236 }
00237 else if( i == 0 && j == 18 )
00238 {
00239
00240 strcpy( chLabel[k], "H2ph" );
00241 }
00242 else if( i == 0 && j == 19 )
00243 {
00244
00245 strcpy( chLabel[k], "Comp" );
00246 }
00247 else if( i == 0 && j == 22 )
00248 {
00249
00250 strcpy( chLabel[k], "line" );
00251 }
00252 else if( i == 0 && j == 23 )
00253 {
00254
00255
00256 strcpy( chLabel[k], "Hlin" );
00257 }
00258 else if( i == 0 && j == 24 )
00259 {
00260
00261 strcpy( chLabel[k], "ChaT" );
00262 }
00263 else if( i == 1 && j == 3 )
00264 {
00265
00266 strcpy( chLabel[k], "He3l" );
00267 }
00268 else if( i == 1 && j == 5 )
00269 {
00270
00271 strcpy( chLabel[k], "adve" );
00272 }
00273 else if( i == 1 && j == 6 )
00274 {
00275
00276 strcpy( chLabel[k], "CR H" );
00277 }
00278 else if( i == 25 && j == 27 )
00279 {
00280
00281 strcpy( chLabel[k], "Fe 2" );
00282 }
00283 else
00284 {
00285 sprintf( chLabel[k], "[%ld][%ld]" , i , j );
00286 }
00287 }
00288
00289
00290
00291 spsort(
00292
00293 SaveVal,
00294
00295 ipnt,
00296
00297 ipOrdered,
00298
00299
00300 -1,
00301
00302 &nFail);
00303
00304
00305
00306
00307 fprintf( io, "%.5e\t%.4e\t%.4e\t%.4e",
00308 radius.depth_mid_zone,
00309 phycon.te,
00310 heat_total,
00311 cool_total );
00312
00313
00314 ipnt = MIN2( ipnt , IPRINT );
00315
00316 for( k=0; k < ipnt; k++ )
00317 {
00318 int ip = ipOrdered[k];
00319 i = ipsave[ip];
00320 j = jpsave[ip];
00321 ASSERT( i<LIMELM && j<LIMELM );
00322 if(k > 4 && thermal.heating[i][j]/SDIV(heat_total) < save.WeakHeatCool )
00323 break;
00324 fprintf( io, "\t%s\t%.7f ",
00325 chLabel[ip], SaveVal[ip] );
00326 }
00327 fprintf( io, " \n" );
00328
00329
00330
00331 lgHeatLine = false;
00332
00333
00334 for( i=0; i < ipnt; i++ )
00335 {
00336
00337 if( ipsave[i] == 0 && jpsave[i] == 22 )
00338 lgHeatLine = true;
00339 }
00340
00341 if( lgHeatLine )
00342 {
00343 long level = -1;
00344
00345 TransitionProxy t = FndLineHt(&level);
00346 if( t.Coll().heat()/SDIV(heat_total) > 0.005 )
00347 {
00348 ASSERT( t.associated() );
00349 strcpy( chLbl, chLineLbl(t) );
00350 TauIn = t.Emis().TauIn();
00351 Pump = t.Emis().pump();
00352 EscP = t.Emis().Pesc();
00353 CS = t.Coll().col_str();
00354
00355 ColHeat = t.Coll().heat()/SDIV(heat_total);
00356
00357 fprintf( io, " LHeat lv%2ld %10.10s TIn%10.2e Pmp%9.1e EscP%9.1e CS%9.1e Hlin/tot%10.2e\n",
00358 level, chLbl, TauIn, Pump, EscP, CS, ColHeat );
00359 }
00360 }
00361 for( i=0; i<LIMELM*LIMELM; ++i )
00362 {
00363 free(chLabel[i]);
00364 }
00365
00366 free(chLabel);
00367 free(ipOrdered);
00368 free(jpsave);
00369 free(ipsave);
00370 free(SaveVal);
00371 return;
00372 }