45 realnum mass_amu,
double frac );
59 map <string,count_ptr<molecule> >
spectab;
60 map <string,count_ptr<mole_reaction> >
reactab;
61 map <string,count_ptr<chem_element> >
elemtab;
62 map <string,count_ptr<chem_atom> >
atomtab;
63 map <string,count_ptr<mole_reaction> >
functab;
78 class MoleCmp :
public binary_function<const count_ptr<molecule>,
79 const count_ptr<molecule>,bool>
85 return mol1->
compare(*mol2) < 0;
89 return mol1->
compare(*mol2) < 0;
95 t_mole_global::MoleculeList::iterator end)
97 std::sort(start,end,MoleCmp());
101 std::sort(start,end,MoleCmp());
112 static const char chFile[] =
"isotope_fractions.dat";
116 while(
read_whole_line( chLine, (
int)
sizeof(chLine), ioDATA ) != NULL )
118 if( chLine[0] ==
'#' )
128 if( (
unsigned)Z <= lgResolveNelem.size() && lgResolveNelem[Z-1] )
150 null_molezone->
den = 0.;
173 atom12C->
frac = ratio / (ratio + 1.);
174 atom13C->
frac = 1. / (ratio + 1.);
194 for(
long nelem=0; nelem<
LIMELM; ++nelem )
216 null_mole->
index = -1;
265 long int nelem = (*atom)->el->Z-1;
267 for(
long ion=0; ion<=nelem+1; ion++ )
274 sprintf( temp,
"+" );
276 sprintf( temp,
"+%ld", ion );
277 sprintf( str,
"%s%s", (*atom)->label().c_str(), temp );
350 atom->ipMl[sp->
charge] = i;
367 while( getline( ioDATA,line ) )
373 istringstream iss( line );
375 double formation_enthalpy;
377 iss >> formation_enthalpy;
389 vector< int >& numAtoms,
392 string embellishments,
393 vector<string>& newLabels )
399 for(
unsigned position = 0; position < atoms.size(); ++position )
402 if( atoms[position]->label() == atom_old )
404 for(
unsigned i=0; i<position; ++i )
406 str << atoms[i]->label();
411 if( numAtoms[position] > 1 )
414 if( numAtoms[position] > 2 )
415 str << numAtoms[position]-1;
419 if( position+1 == atoms.size() )
422 for(
unsigned i=position+1; i<atoms.size(); ++i )
427 if( atom_new == atoms[i]->label() )
429 str << atoms[i]->label();
430 ASSERT( numAtoms[i] + 1 > 1 );
431 str << numAtoms[i] + 1;
436 str << atoms[i]->label();
437 if( numAtoms[i] > 1 )
443 str << atoms[i]->label();
444 if( numAtoms[i] > 1 )
450 str << embellishments;
452 newLabels.push_back( str.str() );
468 int len = strlen(label)+1;
470 char *mylab = mylab_v.
data();
471 strncpy(mylab,label,len);
472 s = strchr(mylab,
' ');
488 realnum mass_amu,
double frac )
493 ASSERT( massNumberA < 3 *
LIMELM && ( massNumberA > 0 || massNumberA == -1 ) );
494 ASSERT( mass_amu < 3. * LIMELM && mass_amu > 0. );
495 ASSERT( frac <= 1. + FLT_EPSILON && frac >= 0. );
498 isotope->
A = massNumberA;
500 isotope->
frac = frac;
501 isotope->
ipMl.resize(el->
Z+1);
503 for (
long int ion = 0; ion < el->
Z+1; ion++)
504 isotope->
ipMl[ion] = -1;
512 el->
isotopes[massNumberA] = isotope;
523 realnum averageMass = 0., fracsum = 0.;
526 fracsum += it->second->frac;
527 averageMass += it->second->mass_amu * it->second->frac;
540 return newspecies( label, type, state, form_enthalpy,
true);
549 bool lgCreateIsotopologues )
555 vector< int > numAtoms;
556 string embellishments;
571 int len = strlen(label)+1;
573 char *mylab = mylab_v.
data();
574 strncpy(mylab,label,len);
575 s = strchr(mylab,
' ');
585 for(
unsigned i = 0; i < atomsLeftToRight.size(); ++i )
587 mol->
nAtom[ atomsLeftToRight[i] ] += numAtoms[i];
599 fprintf(
ioQQQ,
"No species %s as molecules off\n",label);
611 fprintf(
ioQQQ,
"No species %s as heavy molecules off\n",label);
621 fprintf(
ioQQQ,
"Warning: duplicate species %s - using first one\n",
622 mol->
label.c_str() );
638 if( lgCreateIsotopologues && type==
MOLECULE && mol->
label.compare(
"CO")==0 )
650 it2 != it1->first->el->isotopes.end(); ++it2 )
653 if( it1->first->el->Z-1 ==
ipHYDROGEN && it2->second->A != 2 )
657 if( it2->second->lgMeanAbundance() )
659 vector<string> isoLabs;
660 create_isotopologues_one( atomsLeftToRight, numAtoms, it1->first->label(), it2->second->label(), embellishments, isoLabs );
665 for( vector<string>::iterator newLabel = isoLabs.begin(); newLabel != isoLabs.end(); ++newLabel )
669 if( sp!=NULL && it2->second->A != 2 )
680 bool lgExcit, lgGas_Phase;
682 bool lgOK =
parse_species_label( label, atomsLeftToRight, numAtoms, embellishments, lgExcit, charge, lgGas_Phase );
686 bool &lgExcit,
int &charge,
bool &lgGas_Phase )
688 long int i, n, ipAtom;
697 s = strpbrk(mylab,
"*");
706 s = strpbrk(mylab,
"+-");
717 embellishments = s + embellishments;
721 s = strstr(mylab,
"grn");
725 embellishments = s + embellishments;
736 while (mylab[i] !=
'\0' && mylab[i] !=
' ' && mylab[i] !=
'*')
743 thisAtom[ipAtom++] = mylab[i++];
744 ASSERT( isdigit(mylab[i]) );
745 thisAtom[ipAtom++] = mylab[i++];
746 if(isdigit(mylab[i]))
748 thisAtom[ipAtom++] = mylab[i++];
752 thisAtom[ipAtom++] = mylab[i++];
753 if(islower(mylab[i]))
755 thisAtom[ipAtom++] = mylab[i++];
757 thisAtom[ipAtom] =
'\0';
763 fprintf(stderr,
"Did not recognize atom at %s in \"%s \"[%ld]\n",thisAtom,mylab,i);
769 fprintf(
ioQQQ,
"No species %s as element %s off\n",mylab,atom->
el->
label.c_str() );
773 if(isdigit(mylab[i]))
777 n = 10*n+(
long int)(mylab[i]-
'0');
779 }
while (isdigit(mylab[i]));
785 atomsLeftToRight.push_back( atom );
786 numAtoms.push_back( n );
819 for (
const char *pb = buf; *pb && *pb !=
' '; ++pb)
827 return &(*p->second);
838 for (
const char *pb = buf; *pb && *pb !=
' '; ++pb)
868 double den_times_area, den_grains, adsorbed_density;
872 enum { DEBUG_MOLE =
false };
898 den_times_area = den_grains = 0.0;
899 for(
size_t nd=0; nd <
gv.
bin.size(); nd++ )
902 den_times_area +=
gv.
bin[nd]->IntArea/4.*
gv.
bin[nd]->cnv_H_pCM3;
903 den_grains +=
gv.
bin[nd]->cnv_GR_pCM3;
906 adsorbed_density = 0.0;
916 double mole_cs = 1e-15;
917 if (4*den_times_area <= mole_cs*adsorbed_density)
929 fprintf(
ioQQQ,
"Dust: %f %f %f\n",
970 realnum frac = (new_pop-old_pop)/
SDIV(new_pop+old_pop+1e-8*
985 return ncpt>0 ? sqrt(delta/ncpt) : 0.f;
990 DEBUG_ENTRY(
"t_mole_local::set_isotope_abundances()");
996 for(
isotopes_i it = (*atom)->el->isotopes.begin(); it != (*atom)->el->isotopes.end(); ++it )
999 if( it->second->lgMeanAbundance() )
1003 for(
unsigned long ion=0; ion<it->second->ipMl.size(); ++ion )
1005 if( it->second->ipMl[ion] != -1 &&
1006 (
species[ it->second->ipMl[ion] ].location == NULL ) && (*atom)->ipMl[ion] != -1 )
1008 species[ it->second->ipMl[ion] ].den =
species[ (*atom)->ipMl[ion] ].den * it->second->frac;
1022 ASSERT( ion < nelem + 2 );
1025 if( mole_index == -1 )
1028 species[mole_index].location = density;
1046 for( molecule::nAtomsMap::iterator atom=
mole_global.
list[i]->nAtom.begin();
1049 long int nelem = atom->first->el->Z-1;
1050 if( nelem==0 && atom->first->A==2 )
1075 for( molecule::nAtomsMap::iterator atom=
mole_global.
list[i]->nAtom.begin();
1078 ASSERT( atom->second > 0 );
1079 long int nelem = atom->first->el->Z-1;
1080 if( atom->first->lgMeanAbundance() )
1099 for( molecule::nAtomsMap::iterator atom=
mole_global.
list[i]->nAtom.begin();
1102 long int nelem = atom->first->el->Z-1;
1150 groupspecies = NULL;
1183 ASSERT( it->second > 0 );
t_mole_global mole_global
map< int, count_ptr< chem_atom > > isotopes
static void sort(MoleculeList::iterator start, MoleculeList::iterator end)
FILE * open_data(const char *fname, const char *mode, access_scheme scheme)
const double ENERGY_H2_STAR
vector< bool > lgTreatIsotopes
realnum total_molecules(void)
void total_molecule_deut(realnum &total)
STATIC count_ptr< chem_atom > findatom(const char buf[])
map< string, count_ptr< molecule > >::iterator molecule_i
bool lgLeiden_Keep_ipMH2s
void mole_make_list(void)
map< string, count_ptr< mole_reaction > > reactab
map< int, count_ptr< chem_atom > >::iterator isotopes_i
STATIC molecule * newspecies(const char label[], enum spectype type, enum mole_state state, realnum form_enthalpy)
molezone * findspecieslocal(const char buf[])
void InitDeuteriumIonization()
t_elementnames elementnames
element_type * data() const
bool fp_equal(sys_float x, sys_float y, int n=3)
STATIC realnum MeanMassOfElement(const count_ptr< chem_element > &el)
const ios_base::openmode mode_r
STATIC bool isactive(const molecule &mol)
map< string, count_ptr< chem_element > > elemtab
STATIC void read_species_file(string filename, bool lgCreateIsotopologues=true)
molecule * findspecies(const char buf[])
molecule::nAtomsMap::reverse_iterator nAtoms_ri
bool parse_species_label(const char label[], ChemAtomList &atomsLeftToRight, vector< int > &numAtoms, string &embellishments)
valarray< class molezone > species
const int INPUT_LINE_LENGTH
void create_isotopologues_one(ChemAtomList &atoms, vector< int > &numAtoms, string atom_old, string atom_new, string embellishments, vector< string > &newLabels)
realnum AtomicWeight[LIMELM]
map< string, count_ptr< chem_atom > >::iterator chem_atom_i
realnum total_molecules_gasphase(void)
map< string, count_ptr< mole_reaction > > functab
STATIC void newelement(const char label[], int ipion)
realnum mole_return_cached_species(const GroupMap &MoleMap)
diatomics h2("h2", 4100.,&hmi.H2_total, Yan_H2_CS)
void SetDeuteriumFractionation(const realnum &frac)
void SetGasPhaseDeuterium(const realnum &Hdensity)
char chElementSym[LIMELM][CHARS_ELEMENT_SYM]
int compare(const molecule &mol2) const
map< string, count_ptr< chem_atom > > atomtab
realnum gas_phase[LIMELM]
bool lgMeanAbundance(void) const
void set_isotope_abundances(void)
STATIC void start(long, realnum[], realnum[], long, long[], realnum *, int *)
void total_network_elems(double total[LIMELM])
vector< count_ptr< chem_element > > element_list
void set_location(long nelem, long ion, double *dense)
bool isMonatomic(void) const
STATIC void ReadIsotopeFractions(const vector< bool > &lgResolveNelem)
#define DEBUG_ENTRY(funcname)
const double ELECTRON_MASS
realnum C12_C13_isotope_ratio
STATIC void newisotope(const count_ptr< chem_element > &el, int massNumberA, realnum mass_amu, double frac)
bool lgGrain_mole_deplete
bool lgDifferByExcitation(const molecule &mol1, const molecule &mol2)
void mole_update_species_cache(void)
STATIC bool ispassive(const molecule &mol)
ChemAtomList unresolved_atom_list
sys_float SDIV(sys_float x)
char * read_whole_line(char *chLine, int nChar, FILE *ioIN)
bool lgElemsConserved(void)
void mole_make_groups(void)
map< string, count_ptr< molecule > > spectab
chem_element * null_element
void total_molecule_elems(realnum total[LIMELM])
const double ATOMIC_MASS_UNIT
vector< count_ptr< chem_atom > > ChemAtomList
double FFmtRead(const char *chCard, long int *ipnt, long int last, bool *lgEOL)
molecule::nAtomsMap::iterator nAtoms_i