136 static double te_old=-1;
137 double timestep_Hp_temp , timestep_return;
141 timestep_return = dynamics.
timestep;
159 double dTdStep = fabs(te_new-te_old)/te_new;
161 double dT_factor = 0.04/
SDIV(dTdStep);
162 dT_factor =
MIN2( 2.0 , dT_factor );
163 dT_factor =
MAX2( 0.01 , dT_factor );
164 timestep_Hp_temp = dynamics.
timestep * dT_factor;
168 timestep_Hp_temp = -1.;
171 if( timestep_Hp_temp > 0. )
172 timestep_return = timestep_Hp_temp;
178 fprintf(
ioQQQ,
"DEBUG timestep_next returns %.3e, old temp %.2e\n" , timestep_return, te_old );
180 return( timestep_return );
225 for(
long ion=0; ion<nelem+2; ++ion )
227 dynamics.
Source[nelem][ion] = 0.;
232 for(
long nelem=ipISO; nelem<
LIMELM; ++nelem)
238 dynamics.
StatesElem[nelem][nelem-ipISO][level] = 0.;
252 fprintf(
ioQQQ,
"workwork\t%li\t%.3e\t%.3e\t%.3e\n",
272 "dynamics cool-heat\t%li\t%.3e\t%i\t%.3e\t%.3e\t%.3e\t%.3e\t%.3e\t%.3e\t%.3e\n",
314 "PROBLEM conservation error: zn %li elem %li upstream %.8e abund %.8e (up-ab)/up %.2e\n",
325 dynamics.
Source[nelem][ion] = 0.;
333 dynamics.
Source[nelem][ion] =
340 for(
long ion=
dense.
IonHigh[nelem]+1;ion<nelem+2; ++ion )
342 dynamics.
Source[nelem][ion] = 0.;
351 for(
long nelem=ipISO; nelem<
LIMELM; ++nelem)
357 dynamics.
StatesElem[nelem][nelem-ipISO][level] =
365 fprintf(
ioQQQ,
"dynamiccc\t%li\t%.2e\t%.2e\t%.2e\t%.2e\n",
376 fprintf(
ioQQQ,
"dynaionizeeee\t%li\t%i\t%.3e\t%.3e\t%.3e\t%.3e\t%.3e\t%.3e\t%.3e\t%.3e\t%.3e\t%.3e\n",
388 dynamics.
Source[nelem][ion]
393 fprintf(
ioQQQ,
" DynaIonize, %4li photo=%.2e , H recom= %.2e \n",
415 double upstream, dilution, dilutionleft, dilutionright, frac_next;
418 double hupstream, hnextfrac=-
BIGFLOAT, hion, hmol, hiso;
421 double ynextfrac=-
BIGFLOAT, yion, ymol, yiso;
423 long int nelem , ion, mol;
434 for( ion=0; ion<nelem+2; ++ion )
441 for( nelem=ipISO; nelem<
LIMELM; ++nelem)
516 fprintf(
ioQQQ,
"PROBLEM interpolated enthalpy density is not within range %.16e\t%.16e\t%.16e\t%e\t%e\n",
517 lo, x, hi, (hi-x)/(hi-lo), (x-lo)/(hi-lo));
525 for( ion=0; ion<nelem+2; ++ion )
546 for( nelem=ipISO; nelem<
LIMELM; ++nelem)
573 for(molecule::nAtomsMap::iterator atom=
mole_global.
list[mol]->nAtom.begin();
596 for( ion=0; ion<nelem+2; ++ion )
607 for( nelem=ipISO; nelem<
LIMELM; ++nelem)
627 for(molecule::nAtomsMap::iterator atom=
mole_global.
list[mol]->nAtom.begin();
669 if(ipUpstream != -1 && ipUpstream <
nOld_zone-1)
675 const double STEP_FACTOR=0.05;
679 for( ion=0; ion<nelem+2; ++ion )
734 for( nelem=ipISO; nelem<
LIMELM; ++nelem)
741 if(ipyUpstream != -1 && ipyUpstream !=
nOld_zone-1 &&
757 if(iphUpstream != -1 && iphUpstream !=
nOld_zone-1 &&
846 fprintf(
ioQQQ,
" DynaStartZone, %4li photo=%.2e , H recom= %.2e dil %.2e \n",
862 fprintf(
ioQQQ,
"Check dp: %g %g mom %g %g mas %g\n",
881 static long int nTime_dt_array_element = 0;
893 fprintf(
ioQQQ,
"DYNAMICS DynaIterEnd sets stop radius to %.2e after "
894 "dynamics.n_initial_relax=%li iterations.\n",
938 fprintf(
ioQQQ,
" DynaIterEnd, dr=%.2e \n",
951 static double HeatInitial=-1. , HeatRadiated=-1. ,
957 "DEBUG times enter dynamics.timestep %.2e elapsed_time %.2e iteration %li relax %li \n",
1000 fprintf(
ioQQQ,
"DEBUG relaxing times requested %li this is step %li\n",
1003 fprintf(
ioQQQ,
"DEBUG heat conser HeatInitial=%.2e HeatRadiated=%.2e\n",
1004 HeatInitial , HeatRadiated );
1012 ++nTime_dt_array_element;
1020 fprintf(
ioQQQ,
"DEBUG dynamics turn on recombination logic\n");
1033 fprintf(
ioQQQ,
"DEBUG lgtimes increment Time to %li %.2e\n" ,nTime_dt_array_element,
1045 fprintf(
ioQQQ,
"DEBUG lgtimes increment Timeby dynamics.timestep_factor to %li %.2e\n" ,
1046 nTime_dt_array_element,
1050 fprintf(
ioQQQ,
"DEBUG lgtimes but reset to %.2e\n" ,dynamics.
timestep );
1067 fprintf(
ioQQQ,
"DEBUG times exit dynamics.timestep %.2e elapsed_time %.2e scale %.2e ",
1077 fprintf(
ioQQQ,
"\n" );
1116 for(i=0;i<
nzone;++i)
1142 for( ion=0; ion<nelem+2; ++ion )
1164 for( nelem=ipISO; nelem<
LIMELM; ++nelem)
1215 fprintf(
ioQQQ,
"DYNAMICS DynaNewStep: Dyn_dr %.2e convergence_error %.2e discretization_error %.2e error_scale1 %.2e error_scale2 %.2e\n",
1240 for( i=0; i<
nzone; ++i )
1264 for( ion=0; ion<nelem+2; ++ion )
1271 for( nelem=ipISO; nelem<
LIMELM; ++nelem)
1378 dynamics.
lgISO[ipISO] =
true;
1421 dynamics.
Source[nelem] = ((
double*)
MALLOC( (
size_t)(nelem+2)*
sizeof(
double) ));
1423 for( ion=0; ion<nelem+2; ++ion )
1425 dynamics.
Source[nelem][ion] = 0.;
1435 for(
long ion=0; ion<nelem+1; ion++ )
1437 long ipISO = nelem-ion;
1452 dynamics.
StatesElem = ((
double***)
MALLOC( (
size_t)LIMELM*
sizeof(
double **) ));
1457 dynamics.
StatesElem[nelem] = (
double**)
MALLOC(
sizeof(
double*)*(unsigned)(nelem+1) );
1458 for(
long ion=0; ion<nelem+1; ion++ )
1460 long ipISO = nelem-ion;
1463 dynamics.
StatesElem[nelem][nelem-ipISO] = (
double*)
MALLOC(
sizeof(
double)*(unsigned)
iso_sp[ipISO][nelem].numLevels_max);
1468 dynamics.
StatesElem[nelem][nelem-ipISO] = NULL;
1526 for( nelem=0; nelem<
LIMELM; ++nelem )
1532 for( nelem=0; nelem<
LIMELM; ++nelem )
1538 for( ion=0; ion<nelem+1; ion++ )
1540 long ipISO = nelem-ion;
1572 for( nelem=0; nelem<
LIMELM; ++nelem )
1574 for( ion=0; ion<LIMELM+1; ++ion )
1581 for( nelem=ipISO; nelem<
LIMELM; ++nelem)
1687 " Hit EOF while reading time-continuum list; use END to end list.\n" );
1695 while( p.
strcmp(
"END") != 0 )
1700 " Too many time points have been entered; the limit is %d. Increase variable NTIME in dynamics.c.\n",
1719 fprintf(
ioQQQ,
" Adding cycles with period = %e s.\n", period );
1725 fprintf(
ioQQQ,
" Hit EOF while reading line list; use END to end list.\n" );
1746 "scale factor to increase time",-1.);
1749 if( p.
nMatch(
"RECOMBIN") )
1767 fprintf(
ioQQQ,
" Hit EOF while reading line list; use END to end list.\n" );
1775 fprintf(
ioQQQ,
" At least two instances of time must be specified. There is an implicit instance at t=0.\n" \
1776 " The user must specify at least one additional time. Sorry.\n" );
1782 fprintf(
ioQQQ,
"DEBUG time dep %.2e %.2e %.2e %.2e\n",
1788 fprintf(
ioQQQ,
"\n" );
1796 bool lgModeSet=
false;
1835 if ( 1 == iVelocity_Type && !lgModeSet)
1839 fprintf(
ioQQQ,
"Warning, BALListic option needed to switch off pressure gradient terms\n");
1843 fprintf(
ioQQQ,
"Warning, STATic option needed for zero speed solutions\n");
1859 "centre of mass flux distribution");
1867 "power law index of mass flux distribution");
1871 if(iVelocity_Type == 1)
1899 else if(iVelocity_Type == 2)
1903 fprintf(
ioQQQ,
"Can't specify gradient when flux is constant!\n");
1955 fprintf(
ioQQQ,
"Scale %g (*%c) Index %g Center %g\n",
1974 fprintf(
ioQQQ,
" >>>>Initial wind velocity should be greater than speed of sound; calculation only valid above sonic point.\n" );
2013 fprintf(
ioQQQ,
" DYNAMICS Advection: Uad %.2f Uwd%.2e FRCcool: %4.2f Heat %4.2f\n",
2022 fprintf(
ioQQQ,
" DYNAMICS Eexcit:%.4e Eion:%.4e Ebin:%.4e Ekin:%.4e ET+pdv %.4e EnthalpyDensity/rho%.4e AdvSpWork%.4e\n",
2039 if( strcmp( chJob ,
"END" ) == 0 )
2121 "%.5e\t%.5e\t%.5e\t%.5e\t%.5e\t%.5e\t%.5e\t%.5e\t%.5e\t%.5e\t%.5e\t%.5e\n" ,
2150 fprintf( ipPnunit ,
"%.5e\t%.3e\t%.3e\t%.3e\t%.3e\t%.3e\t%.3e\t%.3e\t%.3e\n",
2219 " PROBLEM - DynaIterStart - I need the continuum at time %.2e but the table ends at %.2e.\n" ,
2237 fprintf(
ioQQQ,
"DEBUG time dep reset continuum iter %ld dynamics.timestep %.2e elapsed time %.2e scale %.2e",
2244 fprintf(
ioQQQ,
" recom");
2246 fprintf(
ioQQQ,
"\n");
2249 long int nTimeVary = 0;
2262 fprintf(
ioQQQ,
"DEBUG TurbHeat vary new heat %.2e\n",
2265 else if( !nTimeVary )
2267 fprintf(
ioQQQ,
" DISASTER - there were no variable continua "
2268 "or heat sources - put TIME option on at least one "
2269 "luminosity or hextra command.\n");
bool nMatch(const char *chKey) const
t_mole_global mole_global
static realnum * EnthalpyDensity
static double * Upstream_molecules
static realnum *** Old_xIonDense
STATIC void advection_set_default(bool lgWind)
static realnum * Old_pressure
void ParseDynaWind(Parser &p)
double convergence_tolerance
NORETURN void TotalInsanity(void)
static double *** UpstreamStatesElem
void DynaCreateArrays(void)
static realnum ** Old_molecules
void DynaSave(FILE *ipPnunit, char chJob)
bool lgTimeDependentStatic
int cdIonFrac(const char *chLabel, long int IonStage, double *fracin, const char *chWeight, bool lgDensity)
static double ** UpstreamIon
double getNumberDefaultAlwaysLog(const char *chDesc, double fdef)
int cdTemp(const char *chLabel, long int IonStage, double *TeMean, const char *chWeight)
molezone * findspecieslocal(const char buf[])
static realnum * Old_hiistr
realnum time_continuum_scale
static double * time_dt_scale_factor
realnum PressureErrorAllowed
double xIonDense[LIMELM][LIMELM+1]
double getNumberPlain(const char *chDesc)
t_iso_sp iso_sp[NISO][LIMELM]
static long int nOld_zone
STATIC void DynaNewStep(void)
bool lgTemperatureConstant
STATIC double timestep_next(void)
static realnum * Old_density
static realnum * Old_ednstr
static realnum * Old_EnthalpyDensity
realnum DynaFlux(double depth)
long int IonHigh[LIMELM+1]
static double * time_elapsed_time
valarray< class molezone > species
double discretization_error
STATIC void DynaSaveLast(void)
bool fp_bound(sys_float lo, sys_float x, sys_float hi, int n=3)
static realnum * Old_histr
void ParseDynaTime(Parser &p)
realnum HeatCoolRelErrorAllowed
static realnum * Old_DenMass
realnum scalingZoneDensity(long i)
int strcmp(const char *s2)
static realnum * Old_xLyman_depth
static long int nTime_flux
realnum TempLoStopIteration
realnum gas_phase[LIMELM]
double getNumberCheckAlwaysLogLim(const char *chDesc, double flim)
long int IonLow[LIMELM+1]
double sound_speed_adiabatic
static realnum ** Old_gas_phase
#define DEBUG_ENTRY(funcname)
realnum scalingDensity(void)
double linint(const double x[], const double y[], long n, double xval)
double getNumberCheckAlwaysLog(const char *chDesc)
double getNumberDefault(const char *chDesc, double fdef)
realnum GetHubbleFactor(realnum z)
sys_float SDIV(sys_float x)
void DynaPunchTimeDep(FILE *ipPnunit, const char *chJob)
bool lgStatic(void) const
static realnum **** Old_StatesElem
static double * time_flux_ratio
static double AdvecSpecificEnthalpy
static realnum * Old_depth
bool lg_coronal_time_init
static double * UpstreamElem
realnum TempHiStopIteration
double getNumberCheck(const char *chDesc)