38 double *
const ervals,
double *
const amat,
const bool lgJac,
bool *lgConserve);
44 #define SMALLABUND 1e-24
48 int nBad, nPrevBad, i;
60 fixit(
"Need to treat hmi.H2_frac_abund_set in revised network");
61 fprintf(stderr,
"Need to treat hmi.H2_frac_abund_set in revised network\n");
69 const double BIGERROR = 1e-8;
72 const int LIM_LOOP = 100;
79 double rlimit=-1., rmax=0.0;
82 for(i=0; i < LIM_LOOP;i++)
92 enum {DEBUG_LOC=
false};
94 if( DEBUG_LOC && (
nzone>140) )
110 MoleMap.setup(
get_ptr(oldmols));
129 double oldMolsTmp = 0.;
130 double newMolsTmp = 0.;
134 if( newmols[mol] < 0. )
136 if( -newmols[mol]*oldMolsTmp >= oldmols[mol]*newMolsTmp )
139 oldMolsTmp = abs(oldmols[mol]);
140 newMolsTmp = abs(newmols[mol]);
155 fprintf(
ioQQQ,
"-ve density in inner chemistry loop %ld, worst is %s rlimit %g\n",j,
groupspecies[iworst]->label.c_str(),rlimit);
174 if ( error < 0.01*eqerror )
177 MoleMap.updateMolecules( newmols );
180 if (eqerror < BIGERROR && nBad == 0 && nPrevBad == 0)
186 if( (i == LIM_LOOP && eqerror > BIGERROR) || nBad != 0 )
196 if (effect_delta > delta_threshold)
204 fprintf(
ioQQQ,
"Internal error %15.8g nBad %4d loops %3d\n",
206 fprintf(
ioQQQ,
"Scaling delta on ions %15.8g; threshold %15.8g\n",
207 effect_delta, delta_threshold);
215 enum {DEBUG_LOC=
false};
225 "\terror\t%.4e\tH0\t%.4e\tH+\t%.4e\tsink\t%.4e\t%.4e\tsour\t%.4e\t%.4e\tion\t%.4e\trec\t%.4e",
331 for(
size_t nd=0; nd <
gv.
bin.size(); nd++ )
333 gv.
bin[nd]->rate_h2_form_grains_used = 0.;
345 # define MAT(a,I_,J_) ((a)[(I_)*(mole_global.num_compacted)+(J_)])
352 double *
const amat,
const bool lgJac,
bool *lgConserve)
422 c[jlist[0]][i] *= MoleMap.
fion[j][0];
424 for (
unsigned long ion=1;ion<jlist.size();ion++)
426 double fion = MoleMap.
fion[j][ion];
427 if (jlist[ion] != -1 && fion != 0.0)
431 c[jlist[0]][i] += fion*c[jlist[ion]][i];
446 for (
unsigned long ion=0;ion<jlist.size();ion++)
448 if (jlist[ion] != -1)
450 sum += c[i][jlist[ion]];
453 c[i][jlist[0]] = sum;
468 for (
unsigned long ion=0;ion<jlist.size();ion++)
470 if (jlist[ion] != -1)
475 sum += b[jlist[ion]];
490 for (
unsigned long j = 0; j <
nuclide_list.size(); ++j )
496 double scale=1.0/MoleMap.
molElems[j];
511 for (
unsigned long j = 0; j <
nuclide_list.size(); ++j )
517 double scale = c[ncons][ncons];
518 b[ncons] = (molnow[j]-MoleMap.
molElems[j])*scale;
551 sum1 += fabs(
MAT(amat,j,i));
565 map<chem_nuclide*, long> nuclide_to_index;
573 if(
groupspecies[i]->isIsotopicTotalSpecies() ==
false )
576 for (molecule::nNucsMap::const_iterator el =
groupspecies[i]->nNuclide.begin();
579 mole_elems[nuclide_to_index[el->first.get_ptr()]] += bvec[i]*el->second;
599 for (
unsigned long ion=0; ion<
nuclide_list[j]->ipMl.size(); ion++)
606 double factor = 1./sum;
607 for (
unsigned long ion=0; ion<
nuclide_list[j]->ipMl.size(); ion++)
618 for (
unsigned long ion=0; ion<
nuclide_list[j]->ipMl.size(); ion++)
633 for (
unsigned long ion=0; ion<
nuclide_list[j]->ipMl.size(); ion++)
656 double densAtom = 0.;
675 fprintf(
ioQQQ,
"PROBLEM molElems BAD %li\t%s\t%.12e\t%.12e\t%.12e\n",
707 if( !it->first->lgMeanAbundance() )
709 mole.
species[mol].den *= pow( it->first->frac, it->second );
722 for (
unsigned long ion=0;ion<
nuclide_list[j]->ipMl.size();ion++)
730 ASSERT(fabs(sum-grouptot) <= 1e-10 * fabs(grouptot));
774 long nelem = atom->el->Z-1;
t_mole_global mole_global
molecule::nNucsMap::iterator nNucs_i
void check_co_ion_converge(void)
STATIC void funjac(GroupMap &MoleMap, const valarray< double > &b2vec, double *const ervals, double *const amat, const bool lgJac, bool *lgConserve)
vector< double > molecules
ConvergenceCounter register_(const string name)
long int IonHigh[LIMELM+1]
STATIC void mole_h_fixup(void)
bool lgTimeDependentStatic
realnum GasPhaseAbundErrorAllowed
void setup(double *b0vec)
molezone * findspecieslocal(const char buf[])
ChemNuclideList nuclide_list
realnum deriv_HeatH2Dexc_TH85
double xIonDense[LIMELM][LIMELM+1]
bool newton_step(GroupMap &MoleMap, const valarray< double > &b0vec, valarray< double > &b2vec, realnum *eqerror, realnum *error, const long n, double *rlimit, double *rmax, valarray< double > &escale, void(*jacobn)(GroupMap &MoleMap, const valarray< double > &b2vec, double *const ervals, double *const amat, const bool lgJac, bool *lgConserve))
valarray< double > molElems
long int IonLow[LIMELM+1]
void updateMolecules(const valarray< double > &b2)
valarray< class molezone > species
realnum IonizErrorAllowed
realnum mole_return_cached_species(const GroupMap &MoleMap)
diatomics h2("h2", 4100.,&hmi.H2_total, Yan_H2_CS)
multi_arr< double, 2 > fion
realnum gas_phase[LIMELM]
void set_isotope_abundances(void)
void mole_eval_balance(long int num_total, double *b, bool lgJac, multi_arr< double, 2 > &c)
#define DEBUG_ENTRY(funcname)
double RateIonizTot(long nelem, long ion) const
int fprintf(const Output &stream, const char *format,...)
vector< molecule * > groupspecies
sys_float SDIV(sys_float x)
void setConvIonizFail(const char *reason, double oldval, double newval)
bool lgElemsConserved(void)
STATIC void mole_eval_dynamic_balance(long int num_total, double *b, bool lgJac, multi_arr< double, 2 > &c)
STATIC void grouped_elems(const double bvec[], double mole_elems[])