00001
00002
00003
00004
00005 #include "cddefines.h"
00006 #include "physconst.h"
00007 #include "thirdparty.h"
00008 #include "dense.h"
00009 #include "helike.h"
00010 #include "continuum.h"
00011 #include "helike_recom.h"
00012 #include "rfield.h"
00013 #include "taulines.h"
00014 #include "hypho.h"
00015 #include "iso.h"
00016 #include "opacity.h"
00017 #include "hydro_bauman.h"
00018 #include "hydrogenic.h"
00019 #include "heavy.h"
00020 #include "trace.h"
00021 #include "cloudy.h"
00022
00023
00024
00025
00026 static void SanityCheckBegin(void );
00027 static void SanityCheckFinal(void );
00028
00029
00030
00031 void SanityCheck( const char *chJob )
00032 {
00033 if( strcmp(chJob,"begin") == 0 )
00034 {
00035 SanityCheckBegin();
00036 }
00037 else if( strcmp(chJob,"final") == 0 )
00038 {
00039 SanityCheckFinal();
00040 }
00041 else
00042 {
00043 fprintf(ioQQQ,"SanityCheck called with insane argument.\n");
00044 puts( "[Stop in SanityCheck]" );
00045 cdEXIT(EXIT_FAILURE);
00046 }
00047 }
00048
00049 static void SanityCheckFinal(void )
00050 {
00051
00052 }
00053
00054 static void SanityCheckBegin(void )
00055 {
00056 bool lgOK=true;
00057 int lgFlag;
00058 int32 ner, ipiv[3];
00059 long i ,
00060 j ,
00061 nelem ,
00062 ion ,
00063 nshells;
00064 double *A;
00065
00066
00067 double Aul ,
00068 error,
00069 Z4, gaunt;
00070
00071 long n, logu, loggamma2;
00072 long ipISO;
00073
00074 const int NDIM = 10;
00075 double x , ans1 , ans2 , xMatrix[NDIM][NDIM] , yVector[NDIM] ,
00076 rcond;
00077 float *fvector;
00078 long int *ipvector;
00079
00080 DEBUG_ENTRY( "SanityCheck()" );
00081
00082
00083
00084
00085
00086
00087
00088
00089 lgOK = true;
00090
00091
00092
00093
00094
00095
00096 for( nelem=0; nelem<LIMELM; ++nelem )
00097 {
00098
00099 if( dense.lgElmtOn[nelem] )
00100 {
00101
00102 Aul = H_Einstein_A( 2, 1, 1, 0, nelem+1 );
00103
00104 if( fabs( Aul - EmisLines[ipH_LIKE][nelem][ipH2p][ipH1s].Aul ) /Aul > 0.01 )
00105 {
00106 fprintf(ioQQQ," SanityCheck found insane H-like As.\n");
00107 lgOK = false;
00108 }
00109 }
00110 }
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120 for( logu=-4; logu<=4; logu++)
00121 {
00122
00123 for(loggamma2=-4; loggamma2<=4; loggamma2++)
00124 {
00125 double SutherlandGff[9][9]=
00126 { {5.5243, 5.5213, 5.4983, 5.3780, 5.0090, 4.4354, 3.8317, 3.2472, 2.7008},
00127 {4.2581, 4.2577, 4.2403, 4.1307, 3.7816, 3.2436, 2.7008, 2.2126, 1.8041},
00128 {3.0048, 3.0125, 3.0152, 2.9434, 2.6560, 2.2131, 1.8071, 1.4933, 1.2771},
00129 {1.8153, 1.8367, 1.8880, 1.9243, 1.7825, 1.5088, 1.2886, 1.1507, 1.0747},
00130 {0.8531, 0.8815, 0.9698, 1.1699, 1.2939, 1.1988, 1.1033, 1.0501, 1.0237},
00131 {0.3101, 0.3283, 0.3900, 0.5894, 0.9725, 1.1284, 1.0825, 1.0419, 1.0202},
00132 {0.1007, 0.1080, 0.1335, 0.2281, 0.5171, 0.9561, 1.1065, 1.0693, 1.0355},
00133 {0.0320, 0.0344, 0.0432, 0.0772, 0.1997, 0.5146, 0.9548, 1.1042, 1.0680},
00134 {0.0101, 0.0109, 0.0138, 0.0249, 0.0675, 0.1987, 0.5146, 0.9547, 1.1040}};
00135
00136 gaunt = cont_gaunt_calc( TE1RYD/pow(10.,(double)loggamma2), 1., pow(10.,(double)(logu-loggamma2)) );
00137 error = fabs( gaunt - SutherlandGff[logu+4][loggamma2+4] ) /gaunt;
00138
00139 if( error>0.11 || ( loggamma2<2 && error>0.05 ) )
00140 {
00141 fprintf(ioQQQ," SanityCheck found insane gff. log(u) %li, log(gamma2) %li, error %.3e\n",
00142 logu, loggamma2, error );
00143 lgOK = false;
00144 }
00145 }
00146
00147 }
00148
00149
00150
00151
00152
00153
00154 for( nelem=1; nelem<LIMELM; ++nelem )
00155 {
00156
00157 double as[]={
00158
00159 0. ,9.47e+006 ,3.44e+008 ,1.74e+009 ,5.51e+009 ,1.34e+010 ,
00160 2.79e+010 ,5.32E+010 ,8.81e+010 ,1.46E+011 ,2.15e+011 ,3.15e+011 ,
00161 4.46e+011 ,6.39E+011 ,8.26e+011 ,1.09e+012 ,1.41e+012 ,1.86E+012 ,
00162 2.26e+012 ,2.80e+012 ,3.44e+012 ,4.18e+012 ,5.04e+012 ,6.02e+012 ,
00163 7.14e+012 ,8.40e+012 ,9.83e+012 ,1.14e+013 ,1.32e+013 ,1.52e+013
00164 };
00165
00166 if( iso.numLevels_max[ipHE_LIKE][nelem] > 8 && dense.lgElmtOn[nelem])
00167 {
00168
00169
00170 if( fabs( as[nelem] - EmisLines[ipHE_LIKE][nelem][9][1].Aul ) /as[nelem] > 0.025 )
00171 {
00172 fprintf(ioQQQ,
00173 " SanityCheck found insane He-like As: expected, nelem=%li found: %.2e %.2e.\n",
00174 nelem,
00175 as[nelem] ,
00176 EmisLines[ipHE_LIKE][nelem][9][1].Aul );
00177 lgOK = false;
00178 }
00179 }
00180 }
00181
00182
00183 if( !opac.lgCaseB )
00184 {
00185
00186 for( i = 0; i <=110; i++ )
00187 {
00188 double DrakeTotalAuls[111] = {
00189 -1.0000E+00, -1.0000E+00, -1.0000E+00, 1.02160E+07,
00190 1.02160E+07, 1.02160E+07, 1.80090E+09, 2.78530E+07,
00191 1.82990E+07, 1.05480E+07, 7.07210E+07, 6.37210E+07,
00192 5.79960E+08, 1.60330E+07, 1.13640E+07, 7.21900E+06,
00193 3.11920E+07, 2.69830E+07, 1.38380E+07, 1.38330E+07,
00194 2.52270E+08, 9.20720E+06, 6.82220E+06, 4.56010E+06,
00195 1.64120E+07, 1.39290E+07, 7.16030E+06, 7.15560E+06,
00196 4.25840E+06, 4.25830E+06, 1.31150E+08, 5.62960E+06,
00197 4.29430E+06, 2.95570E+06, 9.66980E+06, 8.12340E+06,
00198 4.19010E+06, 4.18650E+06, 2.48120E+06, 2.48120E+06,
00199 1.64590E+06, 1.64590E+06, 7.65750E+07, 3.65330E+06,
00200 2.84420E+06, 1.99470E+06, 6.16640E+06, 5.14950E+06,
00201 2.66460E+06, 2.66200E+06, 1.57560E+06, 1.57560E+06,
00202 1.04170E+06, 1.04170E+06, 7.41210E+05, 7.41210E+05,
00203 4.84990E+07, 2.49130E+06, 1.96890E+06, 1.39900E+06,
00204 4.16900E+06, 3.46850E+06, 1.79980E+06, 1.79790E+06,
00205 1.06410E+06, 1.06410E+06, 7.02480E+05, 7.02480E+05,
00206 4.98460E+05, 4.98460E+05, -1.0000E+00, -1.0000E+00,
00207 3.26190E+07, 1.76920E+06, 1.41440E+06, 1.01460E+06,
00208 2.94830E+06, 2.44680E+06, 1.27280E+06, 1.27140E+06,
00209 7.52800E+05, 7.52790E+05, 4.96740E+05, 4.96740E+05,
00210 3.51970E+05, 3.51970E+05, -1.0000E+00, -1.0000E+00,
00211 -1.0000E+00, -1.0000E+00, 2.29740E+07, 1.29900E+06,
00212 1.04800E+06, 7.57160E+05, 2.16090E+06, 1.79030E+06,
00213 9.33210E+05, 9.32120E+05, 5.52310E+05, 5.52310E+05,
00214 3.64460E+05, 3.64460E+05, 2.58070E+05, 2.58070E+05,
00215 -1.0000E+00, -1.0000E+00, -1.0000E+00, -1.0000E+00,
00216 -1.0000E+00, -1.0000E+00, 1.67840E+07};
00217
00218 if( DrakeTotalAuls[i] > 0. &&
00219 i < iso.numLevels_max[ipHE_LIKE][ipHELIUM] - iso.nCollapsed_max[ipHE_LIKE][ipHELIUM])
00220 {
00221 if( fabs( DrakeTotalAuls[i] - (1./helike.Lifetime[ipHELIUM][i]) ) /DrakeTotalAuls[i] > 0.001 )
00222 {
00223 fprintf(ioQQQ,
00224 " SanityCheck found helium lifetime outside 0.1 pct of Drake values: index, expected, found: %li %.4e %.4e\n",
00225 i,
00226 DrakeTotalAuls[i],
00227 (1./helike.Lifetime[ipHELIUM][i]) );
00228 lgOK = false;
00229 }
00230 }
00231 }
00232 }
00233
00234
00235
00236
00237
00238
00239
00240 if( dense.lgElmtOn[ipHELIUM] && !helike.lgSetBenjamin )
00241 {
00242
00243 const int NHE1CS = 20;
00244 double he1cs[NHE1CS] =
00245 {
00246 5.480E-18 , 9.253E-18 , 1.598E-17 , 1.598E-17 , 1.598E-17 , 1.348E-17 ,
00247 8.025E-18 , 1.449E-17 , 2.852E-17 , 1.848E-17 , 1.813E-17 , 2.699E-17 ,
00248 1.077E-17 , 2.038E-17 , 4.159E-17 , 3.670E-17 , 3.575E-17 , 1.900E-17 ,
00249 1.900E-17 , 4.175E-17
00250 };
00251
00252
00253 j = MIN2( NHE1CS+1 , iso.numLevels_max[ipHE_LIKE][ipHELIUM] -iso.nCollapsed_max[ipHE_LIKE][ipHELIUM] );
00254 for( n=1; n<j; ++n )
00255 {
00256
00257 i = iso.ipOpac[ipHE_LIKE][ipHELIUM][n];
00258 ASSERT( i>0 );
00259
00260
00261
00262
00263
00264
00265
00266 if( fabs( he1cs[n-1] - opac.OpacStack[i - 1] ) /he1cs[n-1] > 0.15 )
00267 {
00268 fprintf(ioQQQ,
00269 " SanityCheck found insane HeI photo cs: expected, n=%li found: %.3e %.3e.\n",
00270 n,
00271 he1cs[n-1] ,
00272 opac.OpacStack[i - 1]);
00273 fprintf(ioQQQ,
00274 " n=%li, l=%li, s=%li\n",
00275 iso.quant_desig[ipHE_LIKE][ipHELIUM][n].n ,
00276 iso.quant_desig[ipHE_LIKE][ipHELIUM][n].l ,
00277 iso.quant_desig[ipHE_LIKE][ipHELIUM][n].s);
00278 lgOK = false;
00279 }
00280 }
00281
00282
00283
00284 if( !helike.lgNoRecombInterp )
00285 {
00286
00287 error = fabs( HelikeCheckRecomb( ipHELIUM , 0 , 7500. ) );
00288 if( error > 0.01 )
00289 {
00290 fprintf(ioQQQ,
00291 " SanityCheck found insane1 HeI recom coef: expected, n=%i error: %.2e \n",
00292 0,
00293 error );
00294 lgOK = false;
00295 }
00296
00297
00298
00299 error = fabs( HelikeCheckRecomb( ipHELIUM , 1 , 12500. ) );
00300 if( error > 0.01 )
00301 {
00302 fprintf(ioQQQ,
00303 " SanityCheck found insane2 HeI recom coef: expected, n=%i error: %.2e \n",
00304 1,
00305 error );
00306 lgOK = false;
00307 }
00308 }
00309 }
00310
00311
00312
00313
00314
00315
00316
00317
00318 const int NSORT = 100 ;
00319
00320 fvector = (float *)MALLOC((NSORT)*sizeof(float) );
00321
00322 ipvector = (long *)MALLOC((NSORT)*sizeof(long int) );
00323
00324 nelem = 1;
00325
00326 for( i=0; i<NSORT; ++i )
00327 {
00328 nelem *= -1;
00329 fvector[i] = (float)nelem * ((float)NSORT-i);
00330 }
00331
00332
00333 spsort(fvector,
00334 NSORT,
00335 ipvector,
00336
00337
00338 1,
00339 &lgFlag);
00340
00341 if( lgFlag ) lgOK = false;
00342
00343 for( i=1; i<NSORT; ++i )
00344 {
00345
00346
00347 if( fvector[ipvector[i]] <= fvector[ipvector[i-1]] )
00348 {
00349 fprintf(ioQQQ," SanityCheck found insane sort\n");
00350 lgOK = false;
00351 }
00352 }
00353
00354 free( fvector );
00355 free( ipvector);
00356
00357 # if 0
00358 ttemp = (float)sqrt(phycon.te);
00359
00360 if( fabs(ttemp - phycon.sqrte )/ttemp > 1e-5 )
00361 {
00362 fprintf(ioQQQ , "SanityCheck finds insane te %e sqrt te %e sqrte %e dif %e\n",
00363 phycon.te ,
00364 sqrt(phycon.te) ,
00365 phycon.sqrte ,
00366 fabs(sqrt(phycon.te) - phycon.sqrte ) );
00367 lgOK = false;
00368 }
00369 # endif
00370
00371
00372
00373
00374
00375
00376
00377
00378 # if 0
00379
00380
00381 # if !defined(NDEBUG)
00382 x = 0.;
00383 for( i=1; i<rfield.nupper-1; ++i )
00384 {
00385 if( fabs( ((rfield.anu[i+1]-rfield.anu[i]) + (rfield.anu[i]-rfield.anu[i-1])) /rfield.widflx[i] /2.-1.) > 0.02 )
00386 {
00387 ans1 = fabs( ((rfield.anu[i+1]-rfield.anu[i]) + (rfield.anu[i]-rfield.anu[i-1])) /rfield.widflx[i] /2.-1.);
00388 fprintf(ioQQQ," SanityCheck found insane widflx anu[i+1]=%e anu[i]=%e widflx=%e delta=%e rel err %e\n",
00389 rfield.anu[i+1] , rfield.anu[i] , rfield.widflx[i] , rfield.anu[i+1] -rfield.anu[i] , ans1 );
00390 lgOK = false;
00391 x = MAX2( ans1 , x);
00392 }
00393
00394
00395 ans1 = rfield.widflx[i] / rfield.anu[i];
00396 if( (rfield.anu[i]+rfield.widflx[i]/2.)*(1.-ans1/10.) > rfield.anu[i+1] - rfield.widflx[i+1]/2.)
00397 {
00398 fprintf(ioQQQ," SanityCheck found insane overlap1 widflx %e %e %e %e %e %e\n",
00399 rfield.anu[i] , rfield.widflx[i], rfield.anu[i] + rfield.widflx[i]/2. , rfield.anu[i+1],
00400 rfield.widflx[i+1], rfield.anu[i+1] -rfield.widflx[i+1]/2. );
00401 lgOK = false;
00402 }
00403 if( !lgOK )
00404 {
00405 fprintf(ioQQQ," big error was %e\n", x);
00406 }
00407 }
00408 # endif
00409 # endif
00410
00411
00412
00413
00414
00415
00416
00417 for( nelem=0; nelem<2; ++nelem )
00418 {
00419
00420 if( dense.lgElmtOn[nelem] )
00421 {
00422
00423
00424 Z4 = (double)(nelem+1);
00425 Z4 *= Z4;
00426 Z4 *= Z4;
00427
00428 ans1 = EmisLines[ipH_LIKE][nelem][ipH2p][ipH1s].Aul;
00429 ans2 = 6.265e8*Z4;
00430 if( fabs(ans1-ans2)/ans2 > 1e-3 )
00431 {
00432 fprintf(ioQQQ , "SanityCheck finds insane A for H Lya %g %g nelem=%li\n",
00433 ans1 , ans2 , nelem );
00434 lgOK = false;
00435 }
00436
00437 # if 0
00438
00439
00440 ans1 = EmisLines[ipH_LIKE][nelem][ipH2s][ipH1s].Aul;
00441 ans2 = 8.226*powi( (1.+nelem) , 6 );
00442 if( fabs(ans1-ans2)/ans2 > 1e-3 )
00443 {
00444 fprintf(ioQQQ , "SanityCheck finds insane A for H 2-phot %g %g nelem=%li\n",
00445 ans1 , ans2 , nelem );
00446 lgOK = false;
00447 }
00448 # endif
00449
00450 # if 0
00451
00452 ans1 = EmisLines[ipH_LIKE][nelem][3][ipH2s].Aul;
00453 ans2 = 1.10318e7*Z4;
00454 if( fabs(ans1-ans2)/ans2 > 1e-3 )
00455 {
00456 fprintf(ioQQQ , "SanityCheck finds insane A for H 2s %g %g nelem=%li\n",
00457 ans1 , ans2 , nelem );
00458 lgOK = false;
00459 }
00460 ans1 = EmisLines[ipH_LIKE][nelem][3][ipH2p].Aul;
00461 ans2 = 3.3095e7*Z4;
00462 if( fabs(ans1-ans2)/ans2 > 1e-3 )
00463 {
00464 fprintf(ioQQQ , "SanityCheck finds insane A for H 2s %g %g nelem=%li\n",
00465 ans1 , ans2 , nelem );
00466 lgOK = false;
00467 }
00468
00469
00470
00471
00472
00473 ans1 = EmisLines[ipH_LIKE][nelem][4][ipH2s].Aul +
00474 EmisLines[ipH_LIKE][nelem][4][ipH2p].Aul + EmisLines[ipH_LIKE][nelem][4][3].Aul;
00475 ans2 = (8.424e6+ 8.991e6)*Z4;
00476 if( fabs(ans1-ans2)/ans2 > 1e-2 )
00477 {
00478 fprintf(ioQQQ ,
00479 "SanityCheck finds insane A for summed H=4 decays found=%g correct=%g nelem=%li\n",
00480 ans1 , ans2 , nelem );
00481 lgOK = false;
00482 }
00483
00484 # endif
00485 if( iso.numLevels_max[ipH_LIKE][ipHYDROGEN] > 5 )
00486 {
00487
00488 ans1 = EmisLines[ipH_LIKE][nelem][5][ipH2s].Aul +
00489 EmisLines[ipH_LIKE][nelem][5][ipH2p].Aul +
00490 EmisLines[ipH_LIKE][nelem][5][3].Aul + EmisLines[ipH_LIKE][nelem][5][4].Aul;
00491 ans2 = (2.532e6+2.20e6+2.70e6)*Z4;
00492 if( fabs(ans1-ans2)/ans2 > 1e-2 )
00493 {
00494 fprintf(ioQQQ ,
00495 "SanityCheck finds insane A for H5-2 found=%g correct=%g nelem=%li\n",
00496 ans1 , ans2 , nelem );
00497 lgOK = false;
00498 }
00499 }
00500 }
00501 }
00502
00503
00504 for( nelem=0; nelem<LIMELM; ++nelem )
00505 {
00506 int ipHi, ipLo;
00507 for( ipHi=4; ipHi<=15; ++ipHi )
00508 {
00509 double sum = 0.;
00510 for( ipLo=2; ipLo<ipHi;++ipLo )
00511 {
00512 sum += HydroBranch(ipHi,ipLo,nelem+1);
00513 }
00514 if( fabs(sum-1.)>0.01 )
00515 {
00516 fprintf(ioQQQ ,
00517 "SanityCheck H branching ratio sum not unity for nelem=%li upper n=%i sum=%.3e\n",
00518 nelem, ipHi, sum );
00519 lgOK = false;
00520 }
00521 }
00522 }
00523
00524
00525 ipISO = 0;
00526 nelem = 0;
00527
00528 for( n=3; n < MIN2(100, iso.numLevels_max[ipISO][nelem]); ++n )
00529 {
00530 float anu[1]={1.} , cs[1];
00531 double energy;
00532
00533
00534
00535 energy = iso.xIsoLevNIonRyd[ipISO][nelem][n];
00536 anu[0] = (float)(energy*1.01);
00537
00538 hypho(
00539
00540 (double)(nelem+1),
00541
00542 n,
00543
00544 0,
00545
00546 n-1,
00547
00548
00549
00550 energy,
00551
00552 1,
00553
00554 anu ,
00555
00556 cs);
00557
00558 error = fabs(cs[0] - opac.OpacStack[iso.ipOpac[ipISO][nelem][n]-1] )/
00559 ( (cs[0] + opac.OpacStack[iso.ipOpac[ipISO][nelem][n]-1] )/2.);
00560
00561
00562 if( error > 0.05 )
00563 {
00564 fprintf(ioQQQ , "SanityCheck finds insane H photo cs\n");
00565 lgOK = false;
00566 }
00567 }
00568
00569
00570
00571
00572
00573
00574
00575
00576
00577 x = 1e-3;
00578 do
00579 {
00580
00581 ans1 = ee1(x);
00582 ans2 = expn( 1 , x );
00583 if( fabs(ans1-ans2)/(ans1+ans2) > 1e-6 )
00584 {
00585 fprintf(ioQQQ , "SanityCheck finds insane E1 %g %g %g\n",
00586 x , ans1 , ans2 );
00587 lgOK = false;
00588 }
00589
00590
00591 ans1 = e2(x);
00592 ans2 = expn( 2 , x );
00593 if( fabs(ans1-ans2)/(ans1+ans2) > 1e-6 )
00594 {
00595 fprintf(ioQQQ , "SanityCheck finds insane E2 %g %g %g\n",
00596 x , ans1 , ans2 );
00597 lgOK = false;
00598 }
00599
00600
00601 x *= 2.;
00602
00603 } while( x < 64. );
00604
00605
00606
00607
00608
00609
00610
00611
00612 yVector[0] = 1.;
00613 yVector[1] = 3.;
00614 yVector[2] = 3.;
00615
00616
00617 for(i=0;i<3;++i)
00618 {
00619 for( j=0;j<3;++j )
00620 {
00621 xMatrix[i][j] = 0.;
00622 }
00623 }
00624
00625
00626 xMatrix[0][0] = 1.;
00627 xMatrix[0][1] = 1.;
00628 xMatrix[1][1] = 1.;
00629 xMatrix[2][2] = 1.;
00630
00631
00632
00633
00634
00635
00636 A = (double*)MALLOC( sizeof(double)*NDIM*NDIM );
00637
00638
00639 for( i=0; i < 3; ++i )
00640 {
00641 for( j=0; j < 3; ++j )
00642 {
00643 A[i*NDIM+j] = xMatrix[i][j];
00644 }
00645 }
00646
00647 ner = 0;
00648
00649
00650
00651 getrf_wrapper(3, 3, A, NDIM, ipiv, &ner);
00652 if( ner != 0 )
00653 {
00654 fprintf( ioQQQ, " SanityCheck DGETRF error\n" );
00655 puts( "[Stop in SanityCheck]" );
00656 cdEXIT(EXIT_FAILURE);
00657 }
00658
00659
00660
00661
00662
00663
00664
00665 getrs_wrapper('N', 3, 1, A, NDIM, ipiv, yVector, 3, &ner);
00666
00667 if( ner != 0 )
00668 {
00669 fprintf( ioQQQ, " SanityCheck DGETRS error\n" );
00670 puts( "[Stop in SanityCheck]" );
00671 cdEXIT(EXIT_FAILURE);
00672 }
00673
00674 free( A );
00675
00676
00677
00678
00679
00680
00681 rcond = 0.;
00682 for(i=0;i<3;++i)
00683 {
00684 x = fabs( yVector[i]-i-1.);
00685 rcond = MAX2( rcond, x );
00686
00687 }
00688
00689 if( rcond>DBL_EPSILON)
00690 {
00691 fprintf(ioQQQ,
00692 "SanityCheck found too large a deviation in matrix solver = %g \n",
00693 rcond);
00694
00695 lgOK = false;
00696 }
00697
00698
00699
00700
00701
00702
00703 for( nelem=0; nelem<LIMELM; ++nelem )
00704 {
00705
00706 float xIonF[NISO][LIMELM];
00707 double hbn[NISO][LIMELM], hn[NISO][LIMELM];
00708
00709 if( dense.lgElmtOn[nelem] )
00710 {
00711
00712 hbn[ipH_LIKE][nelem] = iso.DepartCoef[ipH_LIKE][nelem][ipH1s];
00713 hn[ipH_LIKE][nelem] = iso.Pop2Ion[ipH_LIKE][nelem][ipH1s];
00714 xIonF[ipH_LIKE][nelem] = dense.xIonDense[nelem][nelem+1];
00715
00716 iso.Pop2Ion[ipH_LIKE][nelem][ipH1s] = 1.;
00717 iso.DepartCoef[ipH_LIKE][nelem][ipH1s] = 0.;
00718 dense.xIonDense[nelem][nelem+1] = 1.;
00719
00720 if( nelem > ipHYDROGEN )
00721 {
00722
00723 hbn[ipHE_LIKE][nelem] = iso.DepartCoef[ipHE_LIKE][nelem][ipHe1s1S];
00724 hn[ipHE_LIKE][nelem] = iso.Pop2Ion[ipHE_LIKE][nelem][ipHe1s1S];
00725 xIonF[ipHE_LIKE][nelem] = dense.xIonDense[nelem][nelem];
00726
00727
00728 iso.Pop2Ion[ipHE_LIKE][nelem][ipH1s] = 1.;
00729 iso.DepartCoef[ipHE_LIKE][nelem][ipH1s] = 0.;
00730 dense.xIonDense[nelem][nelem] = 1.;
00731 }
00732
00733 for( ion=0; ion<=nelem; ++ion )
00734 {
00735
00736 for( nshells=0; nshells<Heavy.nsShells[nelem][ion]; ++nshells )
00737 {
00738 for( j=0; j<3; ++j )
00739 {
00740
00741
00742 if( opac.ipElement[nelem][ion][nshells][j] <=0 )
00743 {
00744
00745 fprintf(ioQQQ,
00746 "SanityCheck found insane ipElement for nelem=%li ion=%li nshells=%li j=%li \n",
00747 nelem , ion , nshells, j );
00748 fprintf(ioQQQ,
00749 "value was %li \n", opac.ipElement[nelem][ion][nshells][j] );
00750
00751 lgOK = false;
00752 }
00753 }
00754 }
00755
00756 if( nelem > 1 )
00757 {
00758 float saveion[LIMELM+3];
00759
00760 for( j=1; j <= (nelem + 2); j++ )
00761 {
00762 saveion[j] = dense.xIonDense[nelem][j-1];
00763 dense.xIonDense[nelem][j-1] = 0.;
00764 }
00765
00766 dense.xIonDense[nelem][ion] = 1.;
00767
00768 OpacityZero();
00769 opac.lgRedoStatic = true;
00770
00771
00772
00773 OpacityAdd1Element(nelem);
00774
00775
00776 for( j=Heavy.ipHeavy[nelem][ion]; j < MIN2(rfield.nflux,continuum.KshellLimit); j++ )
00777 {
00778 if( opac.opacity_abs[j]+opac.OpacStatic[j] < FLT_MIN )
00779 {
00780
00781 fprintf(ioQQQ,
00782 "SanityCheck found non-positive photo cs for nelem=%li ion=%li \n",
00783 nelem , ion );
00784 fprintf(ioQQQ,
00785 "value was %.2e + %.2e nelem %li ion %li at energy %.2e\n",
00786 opac.opacity_abs[j] ,
00787 opac.OpacStatic[j] ,
00788 nelem ,
00789 ion ,
00790 rfield.anu[j]);
00791
00792 lgOK = false;
00793 break;
00794 }
00795 }
00796
00797 for( j=1; j <= (nelem + 2); j++ )
00798 {
00799
00800 dense.xIonDense[nelem][j-1] = saveion[j];
00801
00802 }
00803
00804 }
00805 }
00806 iso.DepartCoef[ipH_LIKE][nelem][ipH1s] = hbn[ipH_LIKE][nelem];
00807 iso.Pop2Ion[ipH_LIKE][nelem][ipH1s] = hn[ipH_LIKE][nelem];
00808 dense.xIonDense[nelem][nelem+1] = xIonF[ipH_LIKE][nelem];
00809
00810 if( nelem > ipHYDROGEN )
00811 {
00812 iso.DepartCoef[ipHE_LIKE][nelem][ipHe1s1S] = hbn[ipHE_LIKE][nelem];
00813
00814 iso.Pop2Ion[ipHE_LIKE][nelem][ipHe1s1S] = hn[ipHE_LIKE][nelem];
00815 dense.xIonDense[nelem][nelem] = xIonF[ipHE_LIKE][nelem];
00816 }
00817 }
00818 }
00819
00820
00821
00822
00823
00824
00825
00826
00827 if( lgOK )
00828 {
00829
00830 if( trace.lgTrace )
00831 {
00832 fprintf( ioQQQ, " SanityCheck returns OK\n");
00833 }
00834
00835 DEBUG_EXIT( "SanityCheck()" );
00836 return;
00837 }
00838
00839 else
00840 {
00841
00842 fprintf(ioQQQ , "SanityCheck finds insanity so exiting\n");
00843 ShowMe();
00844 cdEXIT(EXIT_FAILURE);
00845 }
00846 }