20 const long VERSION_MAGIC = 20061204
L;
22 static const char chFile[] =
"phfit.dat";
27 long i=-1, j=-1, k=-1, n;
29 lgErr = lgErr || ( fscanf( io,
"%ld", &i ) != 1 );
30 if( lgErr || i != VERSION_MAGIC )
32 fprintf(
ioQQQ,
" File %s has incorrect version: %ld\n", chFile, i );
33 fprintf(
ioQQQ,
" I expected to find version: %ld\n", VERSION_MAGIC );
37 for( n=0; n < 7; n++ )
38 lgErr = lgErr || ( fscanf( io,
"%ld", &
L[n] ) != 1 );
39 for( n=0; n < 30; n++ )
40 lgErr = lgErr || ( fscanf( io,
"%ld", &
NINN[n] ) != 1 );
41 for( n=0; n < 30; n++ )
42 lgErr = lgErr || ( fscanf( io,
"%ld", &
NTOT[n] ) != 1 );
45 lgErr = lgErr || ( fscanf( io,
"%ld %ld %ld", &i, &j, &k ) != 3 );
46 if( i == -1 && j == -1 && k == -1 )
48 lgErr = lgErr || ( fscanf( io,
"%le %le %le %le %le %le", &help[0], &help[1],
49 &help[2], &help[3], &help[4], &help[5] ) != 6 );
50 for(
int l=0; l < 6; ++l )
55 lgErr = lgErr || ( fscanf( io,
"%ld %ld", &i, &j ) != 2 );
56 if( i == -1 && j == -1 )
58 lgErr = lgErr || ( fscanf( io,
"%le %le %le %le %le %le %le", &help[0], &help[1],
59 &help[2], &help[3], &help[4], &help[5], &help[6] ) != 7 );
60 for(
int l=0; l < 7; ++l )
67 static const char chFile2[] =
"hpfit.dat";
71 lgErr = lgErr || ( fscanf( io,
"%ld", &i ) != 1 );
72 if( lgErr || i != VERSION_MAGIC )
74 fprintf(
ioQQQ,
" File %s has incorrect version: %ld\n", chFile2, i );
75 fprintf(
ioQQQ,
" I expected to find version: %ld\n", VERSION_MAGIC );
81 lgErr = lgErr || ( fscanf( io,
"%le %le %le %le %le", &help[0], &help[1],
82 &help[2], &help[3], &help[4] ) != 5 );
83 for(
int l=0; l < 5; ++l )
91 static const char chFile3[] =
"rec_lines.dat";
95 lgErr = lgErr || ( fscanf( io,
"%ld", &i ) != 1 );
96 if( lgErr || i != VERSION_MAGIC )
98 fprintf(
ioQQQ,
" File %s has incorrect version: %ld\n", chFile3, i );
99 fprintf(
ioQQQ,
" I expected to find version: %ld\n", VERSION_MAGIC );
103 for( i=0; i < 110; i++ )
105 lgErr = lgErr || ( fscanf( io,
"%le %le %le %le %le %le %le %le", &help[0], &help[1], &help[2],
106 &help[3], &help[4], &help[5], &help[6], &help[7] ) != 8 );
107 for(
int l=0; l < 8; ++l )
112 for( i=0; i < 405; i++ )
114 lgErr = lgErr || ( fscanf( io,
"%le %le %le %le %le %le %le %le %le", &help[0], &help[1], &help[2],
115 &help[3], &help[4], &help[5], &help[6], &help[7], &help[8] ) != 9 );
116 for(
int l=0; l < 9; ++l )
124 static const char chFile4[] =
"rad_rec.dat";
128 lgErr = lgErr || ( fscanf( io,
"%ld", &i ) != 1 );
129 if( lgErr || i != VERSION_MAGIC )
131 fprintf(
ioQQQ,
" File %s has incorrect version: %ld\n", chFile4, i );
132 fprintf(
ioQQQ,
" I expected to find version: %ld\n", VERSION_MAGIC );
138 lgErr = lgErr || ( fscanf( io,
"%ld %ld", &i, &j ) != 2 );
139 if( i == -1 && j == -1 )
141 lgErr = lgErr || ( fscanf( io,
"%le %le", &help[0], &help[1] ) != 2 );
142 for(
int l=0; l < 2; ++l )
147 lgErr = lgErr || ( fscanf( io,
"%ld %ld", &i, &j ) != 2 );
148 if( i == -1 && j == -1 )
150 lgErr = lgErr || ( fscanf( io,
"%le %le %le %le", &help[0], &help[1],
151 &help[2], &help[3] ) != 4 );
152 for(
int l=0; l < 4; ++l )
157 lgErr = lgErr || ( fscanf( io,
"%ld", &i ) != 1 );
160 lgErr = lgErr || ( fscanf( io,
"%le %le %le", &help[0], &help[1], &help[2] ) != 3 );
161 for(
int l=0; l < 3; ++l )
169 static const char chFile5[] =
"h_rad_rec.dat";
173 lgErr = lgErr || ( fscanf( io,
"%ld", &i ) != 1 );
174 if( lgErr || i != VERSION_MAGIC )
176 fprintf(
ioQQQ,
" File %s has incorrect version: %ld\n", chFile5, i );
177 fprintf(
ioQQQ,
" I expected to find version: %ld\n", VERSION_MAGIC );
183 lgErr = lgErr || ( fscanf( io,
"%le %le %le %le %le %le %le %le %le", &help[0], &help[1], &help[2],
184 &help[3], &help[4], &help[5], &help[6], &help[7], &help[8] ) != 9 );
185 for(
int l=0; l < 9; ++l )
193 static const char chFile6[] =
"h_phot_cs.dat";
197 lgErr = lgErr || ( fscanf( io,
"%ld", &i ) != 1 );
198 if( lgErr || i != VERSION_MAGIC )
200 fprintf(
ioQQQ,
" File %s has incorrect version: %ld\n", chFile6, i );
201 fprintf(
ioQQQ,
" I expected to find version: %ld\n", VERSION_MAGIC );
207 lgErr = lgErr || ( fscanf( io,
"%le", &help[0] ) != 1 );
215 static const char chFile7[] =
"coll_ion.dat";
219 lgErr = lgErr || ( fscanf( io,
"%ld", &i ) != 1 );
220 if( lgErr || i != VERSION_MAGIC )
222 fprintf(
ioQQQ,
" File %s has incorrect version: %ld\n", chFile7, i );
223 fprintf(
ioQQQ,
" I expected to find version: %ld\n", VERSION_MAGIC );
229 lgErr = lgErr || ( fscanf( io,
"%ld %ld", &i, &j ) != 2 );
230 if( i == -1 && j == -1 )
232 lgErr = lgErr || ( fscanf( io,
"%le %le %le %le %le", &
CF[i][j][0], &
CF[i][j][1],
233 &
CF[i][j][2], &
CF[i][j][3], &
CF[i][j][4] ) != 5 );
242 static const char chFile8[] =
"h_coll_str.dat";
246 lgErr = lgErr || ( fscanf( io,
"%ld", &i ) != 1 );
247 if( lgErr || i != VERSION_MAGIC )
249 fprintf(
ioQQQ,
" File %s has incorrect version: %ld\n", chFile8, i );
250 fprintf(
ioQQQ,
" I expected to find version: %ld\n", VERSION_MAGIC );
256 lgErr = lgErr || ( fscanf( io,
"%ld %ld", &i, &j ) != 2 );
257 if( i == -1 && j == -1 )
259 lgErr = lgErr || ( fscanf( io,
"%le %le %le %le %le %le %le %le", &
HCS[i-2][j-1][0], &
HCS[i-2][j-1][1],
260 &
HCS[i-2][j-1][2], &
HCS[i-2][j-1][3], &
HCS[i-2][j-1][4], &
HCS[i-2][j-1][5],
261 &
HCS[i-2][j-1][6], &
HCS[i-2][j-1][7] ) != 8 );
316 if( nz < 1 || nz > 30 )
321 if( ne < 1 || ne > nz )
327 if( nz == ne && nz > 18 )
329 if( nz == (ne + 1) && ((((nz == 20 || nz == 21) || nz == 22) ||
330 nz == 25) || nz == 26) )
337 if( (is == 6 && (nz == 20 || nz == 19)) && ne >= 19 )
342 ASSERT( is >= 1 && is <= 7 );
344 if( e <
PH1[is-1][ne-1][nz-1][0] )
350 if( ((nz == 15 || nz == 17) || nz == 19) || (nz > 20 && nz != 26) )
362 einn =
PH1[nint-1][ne-1][nz-1][0];
368 p1 = -
PH1[is-1][ne-1][nz-1][4];
369 y = e/
PH1[is-1][ne-1][nz-1][1];
370 q = -0.5*p1 -
L[is-1] - 5.5;
371 a =
PH1[is-1][ne-1][nz-1][2]*(
POW2(y - 1.0) +
372 POW2(
PH1[is-1][ne-1][nz-1][5]));
373 b = sqrt(y/
PH1[is-1][ne-1][nz-1][3]) + 1.0;
374 crs = a*pow(y,q)*pow(b,p1);
378 if( (is < nout && is > nint) && e < einn )
382 p1 = -
PH2[ne-1][nz-1][3];
384 x = e/
PH2[ne-1][nz-1][0] -
PH2[ne-1][nz-1][5];
385 z = sqrt(x*x+
POW2(PH2[ne-1][nz-1][6]));
386 a = PH2[ne-1][nz-1][1]*(
POW2(x - 1.0) +
387 POW2(PH2[ne-1][nz-1][4]));
388 b = 1.0 + sqrt(z/PH2[ne-1][nz-1][2]);
389 crs = a*pow(z,q)*pow(b,p1);
428 fprintf(
ioQQQ,
" hpfit called with too large n, =%li\n" , n );
437 q = 3.5 + l - 0.5*
PHH[n][1];
455 eth =
ph1(0,0,iz-1,0)/
POW2((
double)m);
456 ex =
MAX2(1. , e/eth );
467 cs = (
PHH[n][4]*pow(1.0 + ((
double)
PHH[n][2]/x),(
double)
PHH[n][3])/
468 pow(x,q)/pow(1.0 + sqrt(x),(
double)
PHH[n][1])*8.79737e-17/
495 static long jd[6]={143,145,157,360,376,379};
497 static long ip[38]={7,9,12,13,14,16,18,19,20,21,22,44,45,49,50,
498 52,53,54,55,56,57,58,59,60,66,67,78,83,84,87,88,95,96,97,100,
501 static long id[38]={7,3,10,27,23,49,51,64,38,47,60,103,101,112,
502 120,114,143,145,157,152,169,183,200,163,225,223,237,232,235,
503 249,247,300,276,278,376,360,379,384};
522 for( i=0; i < 110; i++ )
527 z =
P[0][i] -
P[1][i] + 1.0;
535 a1 = p1*pow(0.004,p2)/(1.0 + p3*pow(0.004,p4));
536 a = a1/sqrt(te/0.004);
542 a1 = p1*pow(2.0,p2)/(1.0 + p3*pow(2.0,p4));
543 a = a1/pow(te/2.0,1.5);
547 a = p1*pow(te,p2)/(1.0 + p3*pow(te,p4));
550 rr[3][i] = 1.0e-13*z*a*
P[7][i];
553 for( i=0; i < 405; i++ )
567 x = p5*(1.0/te - 1.0/p6);
574 a1 = (p1/p6 + p2 + p3*p6 + p4*p6*p6)/
powpq(p6,3,2)/exp(p5/p6);
582 a1 = (p1/6.0 + p2 + p3*6.0 + p4*36.0)/
powpq(6.0,3,2)/exp(p5/6.0);
583 a = a1/
powpq(te/6.0,3,2);
587 a = (p1/te + p2 + p3*te + p4*te*te)/
powpq(te,3,2)/exp(p5/te);
590 dr[3][i] = 1.0e-12*a;
593 for( i=0; i < 6; i++ )
597 dr[3][ipj1-1] += dr[3][ipj2-1];
601 for( i=0; i < 38; i++ )
605 rr[3][ipj1-1] += dr[3][ipj2-1];
609 for( i=0; i < 110; i++ )
618 for( i=0; i < 405; i++ )
669 if( iz < 1 || iz > 30 )
671 fprintf(
ioQQQ,
" rad_rec called with insane atomic number, =%4ld\n",
675 if( in < 1 || in > iz )
677 fprintf(
ioQQQ,
" rad_rec called with insane number elec =%4ld\n",
681 if( (((in <= 3 || in == 11) || (iz > 5 && iz < 9)) || iz == 10) ||
682 (iz == 26 && in > 11) )
684 tt = sqrt(t/
rnew[in-1][iz-1][2]);
686 rnew[in-1][iz-1][0]/(tt*pow(tt + 1.0,1.0 -
rnew[in-1][iz-1][1])*
687 pow(1.0 + sqrt(t/
rnew[in-1][iz-1][3]),1.0 +
rnew[in-1][iz-1][1]));
692 if( iz == 26 && in <= 13 )
694 rate =
fe[in-1][0]/pow(tt,
fe[in-1][1] +
695 fe[in-1][2]*log10(tt));
699 rate =
rrec[in-1][iz-1][0]/pow(tt,(
double)
rrec[in-1][iz-1][1]);
742 TeScaled = t/
POW2((
double)iz);
746 x1 = sqrt(TeScaled/3.148);
747 x2 = sqrt(TeScaled/7.036e05);
748 rate = 7.982e-11/x1/pow(1.0 + x1,0.252)/pow(1.0 + x2,1.748);
753 rate = (
HRF[n][0] +
HRF[n][2]*x +
HRF[n][4]*
755 (1.0 +
HRF[n][1]*x +
HRF[n][3]*x*x +
HRF[n][5]*
757 rate =
exp10(rate)/TeScaled;
792 u =
CF[in-1][iz-1][0]/te;
798 rate = (
CF[in-1][iz-1][2]*(1.0 +
CF[in-1][iz-1][1]*
799 sqrt(u))/(
CF[in-1][iz-1][3] + u)*pow(u,
CF[in-1][iz-1][4])*
815 static const bool DEBUG_COLL_ION =
false;
819 if( z < 0 || z >
LIMELM-1 )
883 static const double DereRatio[30][30]=
884 {{0.9063,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
885 {1.0389,1.0686,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
886 {0.6466,1.0772,0.963,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
887 {0.9715,0.7079,0.973,0.9899,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
888 {1.0781,1.3336,1.0032,1.1102,0.9874,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
889 {1.0499,0.913,1.0377,1.299,1.2874,1.0656,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
890 {1.0421,1.1966,1.0842,0.9619,1.0583,1.155,1.0648,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
891 {1.041,1.1181,1.0164,1.0271,0.9789,0.6829,1.1805,1.0672,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
892 {0.2636,0.658,1.0431,1.0749,0.894,1.059,0.9888,1.1426,1.0633,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
893 {0.8089,1.1395,1.1041,1.0449,1.1365,1.089,1.0147,0.9135,1.336,1.0429,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
894 {0.9545,1.1302,1.1105,1.2067,1.2569,1.079,0.8866,0.9924,0.9933,1.0488,1.0602,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
895 {0.3793,0.9857,1.1152,1.2826,1.3006,1.2416,1.0893,0.93,0.9953,0.9992,1.3479,1.0622,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
896 {0.7458,0.9975,1.0251,0.9553,1.5023,1.2136,1.2566,1.2417,1.2381,1.3755,1.1113,1.1629,1.0589,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
897 {0.7328,0.8798,0.4492,0.8221,1.7874,1.5418,1.5777,1.3036,1.124,1.0667,1.0009,1.002,1.1284,1.0673,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
898 {0.7075,0.9805,0.9451,0.5937,1.2061,1.1772,1.3818,1.4073,1.2643,1.1095,0.9903,1.3716,1.0058,1.0966,1.0517,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
899 {1.3572,0.8925,0.8119,0.8991,0.6633,1.4519,1.2073,1.4058,1.4519,1.2726,1.1428,0.9818,1.3643,1.0074,1.1836,1.1005,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
900 {0.5412,0.8428,0.9237,0.819,0.9151,0.7909,1.7424,1.2653,1.4513,1.4871,1.2633,1.1373,0.9969,0.9919,1.0091,1.2077,1.105,0,0,0,0,0,0,0,0,0,0,0,0,0},
901 {0.9242,0.8644,0.9752,0.8562,0.6998,0.6273,0.8686,2.0326,1.0364,1.4687,1.4812,1.2701,1.1376,0.9932,1.0001,1.0084,1.2036,1.1074,0,0,0,0,0,0,0,0,0,0,0,0},
902 {0.6381,0.9604,1.3556,0.9364,0.9678,1.0604,1.3067,1.0434,2.0722,0.979,1.5318,1.4968,1.2713,1.1427,1.0036,0.9953,1.03,1.2071,1.1083,0,0,0,0,0,0,0,0,0,0,0},
903 {0.7652,1.1668,1.0422,0.8705,0.9193,0.9982,1.077,1.3875,1.1544,2.4653,1.3188,1.5375,1.5307,1.2776,1.1427,1.0117,0.9872,1.0118,1.1899,1.1119,0,0,0,0,0,0,0,0,0,0},
904 {1.0951,0.5891,0.9222,1.2903,1.287,1.0563,1.0444,1.1405,1.4841,1.2583,2.7347,0.9844,1.034,1.0412,1.1062,1.2211,1.6728,1.6347,1.6554,1.8095,1.9561,0,0,0,0,0,0,0,0,0},
905 {0.9789,0.7389,1.3107,0.9274,0.9921,0.9812,0.8971,0.9936,1.0079,1.0377,1.2073,2.7198,0.9995,1.037,1.0433,1.1093,1.2323,1.6673,1.6231,1.6666,1.8089,1.7302,0,0,0,0,0,0,0,0},
906 {0.6169,0.4618,1.3566,3.3812,1.1951,1.1746,1.0133,0.9195,1.0548,1.0608,1.1016,1.285,3.1081,0.9986,1.0094,1.0379,1.005,0.9932,1.0651,0.8787,0.952,0.9862,1.0083,0,0,0,0,0,0,0},
907 {1.0603,0.262,0.9237,2.4323,1.8345,1.2197,1.0924,1.0205,0.9379,1.0946,1.1001,1.1741,1.3608,3.152,0.9692,0.8866,1.0556,1.1127,1.2289,1.6828,1.6298,1.6469,1.8082,1.0605,0,0,0,0,0,0},
908 {0.9061,0.7287,0.9676,1.9425,1.5785,1.9028,1.3827,1.1136,1.0368,0.9516,1.1389,1.1594,1.1642,1.4161,2.8162,0.9744,0.9246,1.0644,1.1118,1.2332,1.6892,1.6311,1.6347,1.8073,1.0722,0,0,0,0,0},
909 {0.9904,1.0568,1.824,1.6578,1.5033,0.9704,0.8933,0.8579,1.084,1.0308,0.9637,1.1885,1.2179,1.2979,1.4846,3.0344,0.9879,0.8927,1.0534,1.1233,1.2242,1.6794,1.6255,1.6487,1.8141,1.7629,0,0,0,0},
910 {0.9667,1.2622,0.959,2.8444,1.304,1.5632,1.709,2.298,1.427,1.0885,1.0285,0.9767,1.2237,1.2632,1.3585,1.5495,3.1385,0.9959,0.9327,1.0904,1.0357,1.0125,1.0027,0.9788,0.8975,1.0539,1.048,0,0,0},
911 {1.0004,0.8721,1.3073,0.9564,2.7856,1.6197,1.5516,2.229,2.1494,1.4916,1.0871,1.0359,0.9768,1.2269,1.3265,1.4169,1.597,3.4077,0.9979,0.8869,1.0635,1.1063,1.2267,1.6914,1.6401,1.6216,1.0598,1.0363,0,0},
912 {0.728,1.3939,0.4822,0.626,0.5463,2.2491,1.064,1.1998,1.3083,1.6545,1.1149,0.8826,0.8566,0.8196,1.1173,1.17,1.2445,1.394,2.9832,0.8715,0.7703,0.929,0.968,1.0828,1.4973,1.4513,1.4476,0.9621,0.9353,0},
913 {1.0766,0.6459,0.7688,0.2358,0.3709,0.3476,1.6754,0.8288,0.9184,1.0686,1.4546,0.9515,0.7272,0.7048,0.6911,0.9722,1.0308,1.0988,1.1959,2.6404,0.7644,0.6768,0.8181,0.8566,0.9689,1.3344,1.3031,1.3345,0.8676,0.8478}};
916 ASSERT( nelem>=0 && nelem<LIMELM && ion>=0 && ion<=nelem );
917 double rate =
coll_ion(nelem+1,nelem+1-ion,t) * DereRatio[nelem][ion];
FILE * open_data(const char *fname, const char *mode, access_scheme scheme)
NORETURN void TotalInsanity(void)
realnum h_coll_str(long ipLo, long ipHi, long ipTe)
realnum ph1(int i, int j, int k, int l) const
realnum PHH[NHYDRO_MAX_LEVEL][5]
realnum HRF[NHYDRO_MAX_LEVEL][9]
double coll_ion_wrapper(long int z, long int n, double t)
double coll_ion(long int iz, long int in, double t)
realnum PH1[7][30][30][6]
double H_rad_rec(long int iz, long int n, double t)
double powi(double, long int)
double rad_rec(long int iz, long int in, double t)
#define DEBUG_ENTRY(funcname)
double powpq(double x, int p, int q)
double hpfit(long int iz, long int n, double e)
int fprintf(const Output &stream, const char *format,...)
double coll_ion_hybrid(long int z, long int n, double t)
void rec_lines(double t, realnum r[][NRECCOEFCNO])
realnum STH[NHYDRO_MAX_LEVEL]
double phfit(long int nz, long int ne, long int is, double e)
const int NHYDRO_MAX_LEVEL