63 fprintf(
ioQQQ,
" PROBLEM DISASTER - the kinetic temperature, %.3eK,"
64 " is above the upper limit of the code, %.3eK.\n",
66 fprintf(
ioQQQ,
" This calculation is aborting.\n Sorry.\n");
74 fprintf(
ioQQQ,
" PROBLEM DISASTER - the kinetic temperature, %.3eK,"
75 " is below the lower limit of the code, %.3eK.\n",
77 fprintf(
ioQQQ,
" Consider setting a lowest temperature with the SET TEMPERATURE FLOOR command.\n");
78 fprintf(
ioQQQ,
" This calculation is aborting.\n Sorry.\n");
85 fprintf(
ioQQQ,
"temp_change: temp change floor hit, TempNew=%.3e TeFloor=%.3e, "
86 "setting constant temperature, nTotalIoniz=%li\n",
120 fprintf(
ioQQQ,
" PROBLEM DISASTER - the kinetic temperature, %.3eK,"
121 " is above the upper limit of the code, %.3eK.\n",
123 fprintf(
ioQQQ,
" This calculation is aborting.\n Sorry.\n");
131 fprintf(
ioQQQ,
" PROBLEM DISASTER - the kinetic temperature, %.3eK,"
132 " is below the lower limit of the code, %.3eK.\n",
134 fprintf(
ioQQQ,
" Consider setting a lowest temperature with the SET TEMPERATURE FLOOR command.\n");
135 fprintf(
ioQQQ,
" This calculation is aborting.\n Sorry.\n");
154 static double tgffused=-1.,
156 static long int nff_defined=-1;
157 static long maxion = 0, oldmaxion = 0;
158 static double ttused = 0.;
159 static bool lgZLogSet =
false;
183 fprintf(
ioQQQ,
"tfidle called with a zero or negative electron density,%10.2e\n",
191 fprintf(
ioQQQ,
"tfidle called with a negative electron temperature,%10.2e\n",
199 for( nelem=0; nelem<
LIMELM; ++nelem )
228 for( i=1; i < 7; i++ )
341 for( nelem = 0; nelem <
LIMELM; nelem++ )
355 static bool lgFirstRunDone =
false;
393 if( lgFirstRunDone ==
false )
396 lgFirstRunDone =
true;
405 for( ion=1; ion<=
LIMELM; ion++ )
411 fprintf(
ioQQQ,
" LinterpTable for GffTable called with te out of bounds \n");
423 fprintf(
ioQQQ,
" LinterpVector for GffTable called with photon energy out of bounds \n");
438 fprintf(
ioQQQ,
" tfidle; gaunt factors?" );
441 fprintf(
ioQQQ,
"%2f g 1 2=%10.2e%9.2ld flag%2f guv(1,n)%10.2e\n",
503 ASSERT( massAMU < 10000. );
562 long i1,i2,i3,j,charge,GffMAGIC = 100804;
573 for(
long i = 0; i <
N_TE_GFF; i++ )
591 for(
long i = 1; i <=
LIMELM; i++ )
601 for(
long i = 1; i <=
LIMELM; i++ )
609 fprintf(
ioQQQ,
" FillGFF opening gauntff.dat:");
613 ioDATA =
open_data(
"gauntff.dat",
"r" );
617 fprintf(
ioQQQ,
" Defaulting to on-the-fly computation, ");
618 fprintf(
ioQQQ,
"but the code runs much faster if you compile gauntff.dat!\n");
625 for( charge=1; charge<=
LIMELM; charge++ )
643 fprintf(
ioQQQ,
" FillGFF could not read first line of gauntff.dat.\n");
647 i1 = (long)
FFmtRead(chLine,&i,
sizeof(chLine),&lgEOL);
648 i2 = (long)
FFmtRead(chLine,&i,
sizeof(chLine),&lgEOL);
649 i3 = (long)
FFmtRead(chLine,&i,
sizeof(chLine),&lgEOL);
654 " FillGFF: the version of gauntff.dat is not the current version.\n" );
656 " FillGFF: I expected to find the numbers %li %li %li and got %li %li %li instead.\n" ,
661 fprintf(
ioQQQ,
"Here is the line image:\n==%s==\n", chLine );
663 " FillGFF: please recompile the data file with the COMPILE GAUNT command.\n" );
668 for( charge = 1; charge <=
LIMELM; charge++ )
675 fprintf(
ioQQQ,
" FillGFF could not read first line of gauntff.dat.\n");
680 i1 = (long)
FFmtRead(chLine,&i3,
sizeof(chLine),&lgEOL);
681 i2 = (long)
FFmtRead(chLine,&i3,
sizeof(chLine),&lgEOL);
683 if( i1!=charge || i2!=i )
685 fprintf(
ioQQQ,
" FillGFF detected insanity in gauntff.dat.\n");
687 " FillGFF: please recompile the data file with the COMPILE GAUNT command.\n" );
698 fprintf(
ioQQQ,
" FillGFF detected insanity in gauntff.dat.\n");
700 " FillGFF: please recompile the data file with the COMPILE GAUNT command.\n" );
711 fprintf(
ioQQQ,
" FillGFF could not read first line of gauntff.dat.\n");
715 i1 = (long)
FFmtRead(chLine,&i,
sizeof(chLine),&lgEOL);
716 i2 = (long)
FFmtRead(chLine,&i,
sizeof(chLine),&lgEOL);
717 i3 = (long)
FFmtRead(chLine,&i,
sizeof(chLine),&lgEOL);
722 " FillGFF: the version of gauntff.dat is not the current version.\n" );
724 " FillGFF: I expected to find the numbers %li %li %li and got %li %li %li instead.\n" ,
729 fprintf(
ioQQQ,
"Here is the line image:\n==%s==\n", chLine );
731 " FillGFF: please recompile the data file with the COMPILE GAUNT command.\n" );
739 fprintf(
ioQQQ,
" - opened and read ok.\n");
749 fprintf(ioGFF,
"%li\t%li\t%li\tGFF free-free gaunt factors, created by COMPILE GAUNT command, with %li energy levels and %li temperatures.\n",
756 for( charge = 1; charge <=
LIMELM; charge++ )
760 fprintf(ioGFF,
"%li\t%li", charge, i );
768 fprintf(ioGFF,
"\t%f",
GauntFF[charge][i][j] );
770 fprintf(ioGFF,
"\n" );
775 fprintf(ioGFF,
"%li\t%li\t%li\tGFF free-free gaunt factors, created by COMPILE GAUNT command, with %li energy levels and %li temperatures.\n",
784 fprintf(
ioQQQ,
"FillGFF: compilation complete, gauntff.dat created.\n" );
794 long logu, loggamma2;
796 for( logu=-4; logu<=4; logu++)
798 for(loggamma2=-4; loggamma2<=4; loggamma2++)
800 double SutherlandGff[9][9]=
801 { {5.5243, 5.5213, 5.4983, 5.3780, 5.0090, 4.4354, 3.8317, 3.2472, 2.7008},
802 {4.2581, 4.2577, 4.2403, 4.1307, 3.7816, 3.2436, 2.7008, 2.2126, 1.8041},
803 {3.0048, 3.0125, 3.0152, 2.9434, 2.6560, 2.2131, 1.8071, 1.4933, 1.2771},
804 {1.8153, 1.8367, 1.8880, 1.9243, 1.7825, 1.5088, 1.2886, 1.1507, 1.0747},
805 {0.8531, 0.8815, 0.9698, 1.1699, 1.2939, 1.1988, 1.1033, 1.0501, 1.0237},
806 {0.3101, 0.3283, 0.3900, 0.5894, 0.9725, 1.1284, 1.0825, 1.0419, 1.0202},
807 {0.1007, 0.1080, 0.1335, 0.2281, 0.5171, 0.9561, 1.1065, 1.0693, 1.0355},
808 {0.0320, 0.0344, 0.0432, 0.0772, 0.1997, 0.5146, 0.9548, 1.1042, 1.0680},
809 {0.0101, 0.0109, 0.0138, 0.0249, 0.0675, 0.1987, 0.5146, 0.9547, 1.1040}};
813 double ERyd = pow(10.,(
double)(logu-loggamma2));
817 error = fabs( gaunt - SutherlandGff[logu+4][loggamma2+4] ) /gaunt;
820 fprintf(
ioQQQ,
" PROBLEM DISASTER tfidle found insane gff. log(u) %li, log(gamma2) %li, error %.3e\n",
821 logu, loggamma2, error );
837 double GauntAtLowerPho, GauntAtUpperPho;
838 static long int ipTe=-1, ipPho=-1;
850 fprintf(
ioQQQ,
" InterpolateGff called with te out of bounds \n");
894 fprintf(
ioQQQ,
" InterpolateGff called with photon energy out of bounds \n");
899 if( log10(ERyd) >
PhoGFF[i] && log10(ERyd) <=
PhoGFF[i+1] )
908 else if( log10(ERyd) <
PhoGFF[ipPho] )
911 while( log10(ERyd) <
PhoGFF[ipPho] && ipPho > 0)
914 else if( log10(ERyd) >
PhoGFF[ipPho+1] )
932 (
GauntFF[charge][ipPho+1][ipTe+1] -
GauntFF[charge][ipPho+1][ipTe]) +
GauntFF[charge][ipPho+1][ipTe];
935 (GauntAtUpperPho - GauntAtLowerPho) + GauntAtLowerPho;
965 fhunt (v,ltb,x,&ipx);
969 if( ipx == -1 || ipx == ltb )
974 ASSERT( (ipx >=0) && (ipx < ltb-1) );
975 ASSERT( x >= v[ipx] && x <= v[ipx+1]);
977 frac = (x - v[ipx]) / (v[ipx+1] - v[ipx]);
978 for( i=0; i<lta; i++ )
980 a[i] = frac*t[i][ipx+1]+(1.f-frac)*t[i][ipx];
995 if( yy[0] < v[0] || yy[ly-1] > v[ltb-1] )
1002 for(j = 1; j < ltb && n < ly; j++) {
1003 while (yl < v[j] && n < ly) {
1004 frac = (yl-v[j-1])/(v[j]-v[j-1]);
1005 for(i = 0; i < lta; i++)
1006 a[i][n] = frac*t[i][j]+(1.f-frac)*t[i][j-1];
1010 ASSERT( yy[n] >= yy[n-1] );
1020 long int jl, jm, jh, in;
1024 up = (xx[n-1] > xx[0]);
1025 if(jl < 0 || jl >= n)
1033 if((x >= xx[jl]) == up)
1041 while ((x >= xx[jh]) == up)
1061 while ((x < xx[jl]) == up)
1077 if((x > xx[jm]) == up)
sys_float sexp(sys_float x)
double FFmtRead(const char *chCard, long int *ipnt, long int last, bool *lgEOL)
bool fp_equal(sys_float x, sys_float y, int n=3)
char * read_whole_line(char *chLine, int nChar, FILE *ioIN)
NORETURN void TotalInsanity(void)
#define DEBUG_ENTRY(funcname)
double cont_gaunt_calc(double temp, double z, double photon)
FILE * open_data(const char *fname, const char *mode, access_scheme scheme)
t_iso_sp iso_sp[NISO][LIMELM]
UNUSED const double BOLTZMANN
UNUSED const double EVDEGK
UNUSED const double ATOMIC_MASS_UNIT
UNUSED const double COLL_CONST
UNUSED const double TE1RYD
bool lgStatic(void) const
bool lgBallistic(void) const
long int IonHigh[LIMELM+1]
double xIonDense[LIMELM][LIMELM+1]
const double TEMP_LIMIT_HIGH
const double TEMP_LIMIT_LOW
long int ipEnergyBremsThin
bool lgTemperatureConstant
void TempChange(double TempNew, bool lgForceUpdate)
STATIC void tfidle(bool lgForceUpdate)
STATIC int LinterpTable(realnum **t, realnum *v, long int lta, long int ltb, realnum x, realnum *a, long int *pipx)
realnum GetDopplerWidth(realnum massAMU)
STATIC void FillGFF(void)
realnum GetAveVelocity(realnum massAMU)
static long lgGffNotFilled
static realnum TeGFF[N_TE_GFF]
STATIC realnum InterpolateGff(long charge, double ERyd)
static realnum *** GauntFF
static realnum ** GauntFF_T
STATIC void fhunt(realnum *xx, long int n, realnum x, long int *j)
STATIC int LinterpVector(realnum **t, realnum *v, long lta, long ltb, realnum *yy, long ny, realnum **a)