36 static double HeatOld=-1. , CoolOld=-1.;
53 double HeatRelChange = fabs(HeatChange)/
SDIV( HeatCoolMax );
54 double CoolRelChange = fabs(CoolChange)/
SDIV( HeatCoolMax );
55 bool lgConverged =
true;
74 bool lgConvergeCoolHeat =
false;
78 while( loop < LOOP_MAX && !lgConvergeCoolHeat && !
lgAbort )
87 fprintf(
ioQQQ,
" lgCoolNetConverge %li calls to ConvEdenIoniz, converged? %c\n",
88 loop ,
TorF( lgConvergeCoolHeat ) );
121 fprintf(
ioQQQ,
"PROBLEM CoolNet derivative oscillating in initial solution "
122 "Te=%.3e dCoolNetDT=%.3e CoolNet=%.3e dCooldT=%.3e dHeatdT=%.3e\n",
128 return lgConvergeCoolHeat;
142 for( molecule::nNucsMap::iterator atom=
mole_global.
list[i]->nNuclide.begin();
145 long nelem = atom->first->el->Z-1;
173 enum {DEBUG_LOC=
false};
176 fprintf(
ioQQQ,
"DEBUG fraction molecular %.2e species %li O ices %.2e\n" ,
186 double TeChangeFactor;
210 TeChangeFactor = 0.999;
214 TeChangeFactor = 0.99;
221 TeChangeFactor = 0.97;
228 TeChangeFactor = 0.95;
233 TeChangeFactor = 0.8;
235 return TeChangeFactor;
248 bool lgConvergeCoolHeat;
303 const bool lgDoInitConv =
false;
305 const bool lgSearchPhaseLogicEnabled =
true;
317 fprintf(
ioQQQ,
" ConvInitSolution called, ITER=%2ld resetting Te to %10.2e\n",
349 fprintf(
ioQQQ,
" ========================================================================================================================\n");
350 fprintf(
ioQQQ,
" ConvInitSolution: search set false 2 Te=%.3e========================================================================================\n" ,
phycon.
te);
351 fprintf(
ioQQQ,
" ========================================================================================================================\n");
383 fprintf(
ioQQQ,
" ConvInitSolution called, new temperature.\n" );
410 TeFirst =
MAX2( 4000. , TeFirst );
419 TeFirst =
MIN2( 1e6 , TeBoundHigh );
424 TeFirst =
MAX2( 4000., TeBoundLow );
436 fprintf(
ioQQQ,
"ConvInitSolution doing initial solution with temp=%.2e\n",
450 double CoolNet=0, dCoolNetDT=0;
452 lgConvergeCoolHeat =
false;
453 for( ionlup=0; ionlup<2; ++ionlup )
456 fprintf(
ioQQQ,
"ConvInitSolution calling lgCoolNetConverge "
457 "initial setup %li with Te=%.3e C=%.2e H=%.2e d(C-H)/dT %.3e\n",
470 if( !lgConvergeCoolHeat )
471 fprintf(
ioQQQ,
" PROBLEM ConvInitSolution did not converge the heating-cooling during initial search.\n");
476 fprintf(
ioQQQ,
" DISASTER PROBLEM ConvInitSolution: Search for "
477 "initial conditions aborted - lgAbort set true.\n" );
487 bool lgConvergedLoop =
false;
488 long int LoopThermal = 0;
492 const long int LIMIT_THERMAL_LOOP=300;
493 double CoolMHeatSave=-1. , TempSave=-1. , TeNew=-1.,
CoolSave=-1;
494 while( !lgConvergedLoop && LoopThermal < LIMIT_THERMAL_LOOP )
497 CoolMHeatSave = CoolNet;
504 ASSERT( TeChangeFactor>0. && TeChangeFactor< 1. );
506 TeNew =
phycon.
te - CoolNet / dCoolNetDT;
516 "TeChangeFactor=%.3e Cnet/H=%.2e dCnet/dT=%10.2e Ne=%.3e"
517 " Ograins %.2e FracMoleMax %.2e\n",
518 LoopThermal , TeNew , TeChangeFactor ,
531 lgConvergedLoop =
true;
532 else if( (CoolNet/fabs(CoolNet))*(CoolMHeatSave/fabs(CoolMHeatSave)) <= 0)
534 lgConvergedLoop =
true;
536 lgConvergedLoop =
true;
540 if( !lgConvergedLoop )
541 fprintf(
ioQQQ,
"PROBLEM ConvInitSolution: temperature solution not "
542 "found in initial search, final Te=%.2e\n",
552 fprintf(
ioQQQ,
" Change in sign of C-H found, Te brackets %.3e "
553 "%.3e Cool brackets %.3e %.3e ",
554 TempSave ,
phycon.
te , CoolMHeatSave , CoolNet);
568 double TeLn = (log(
thermal.
htot ) - Alog) / alpha ;
576 TeNew = pow( EE , TeLn );
614 fprintf(
ioQQQ,
"\nConvInitSolution: end 1st iteration search phase "
620 fprintf(
ioQQQ,
" ConvInitSolution return, TE:%10.2e==================\n",
648 " PresTotCurrent 1st zn old values of PresTotlInit:%.3e"
660 static double PresTotalInitTime;
733 for( nelem=2; nelem <
LIMELM; nelem++ )
736 for( i=0; i < nelem; i++ )
743 nelem_reflux = nelem;
775 fprintf(
ioQQQ,
" nflux updated from %li to %li, anu from %g to %g \n",
779 nelem_reflux ,ion_reflux );
790 static const double PCHNG = 0.98;
t_mole_global mole_global
static const long LOOP_MAX
void CoolSave(FILE *io, const char chJob[])
NORETURN void TotalInsanity(void)
double PressureInitialSpecified
void set_NaN(sys_float &x)
bool lgFirstSweepThisZone
static double FracMoleMax
void rfield_opac_zero(long lo, long ihi)
bool lgTimeDependentStatic
long int nTotalIoniz_start
bool lgTemperatureConstant
realnum AverHeatCoolError
double anu(size_t i) const
void TempChange(double TempNew, bool lgForceUpdate)
int ConvTempEdenIoniz(void)
void PresTotCurrent(void)
STATIC void ChemImportance(void)
const double TEMP_LIMIT_LOW
double xIonDense[LIMELM][LIMELM+1]
bool fp_equal(sys_float x, sys_float y, int n=3)
static double dCoolNetDTOld
double PressureVaryTimeIndex
const double TEMP_LIMIT_HIGH
STATIC double FindTempChangeFactor(void)
valarray< class molezone > species
realnum HeatCoolRelErrorAllowed
realnum gas_phase[LIMELM]
double PressureVaryTimeTimescale
bool lgPressureInitialSpecified
STATIC bool lgCoolNetConverge(double *CoolNet, double *dCoolNetDT, bool lgReset)
#define DEBUG_ENTRY(funcname)
int ConvPresTempEdenIoniz(void)
int fprintf(const Output &stream, const char *format,...)
sys_float SDIV(sys_float x)
STATIC bool lgCoolHeatCheckConverge(double *CoolNet, bool lgReset)
long int ipHeavy[LIMELM][LIMELM]
static double OxyInGrains