Add name-to-index function to CanteraObjects for species identification
Implement the capability to obtain the index of a species given that species' name.
The most straightforward solution is to include <boost/algorithm/string/predicate.hpp>
for a case-insensitive string comparison (important because some mechanisms use lower-case and others upper-case) and simply loop through all species in CanteraObjects until the specified one is found:
int species_name_to_idx( const std::string speciesName )
{
bool foundIt = false;
int idx = 0;
while( !foundIt ){
if( boost::iequals( CanteraObjects::species_name( idx ), speciesName ) ) foundIt = true;
else{
foundIt = false;
++idx;
}
if( idx == CanteraObjects::number_species() ){
throw std::runtime_error( "could not find species with name " + speciesName );
}
}
return idx;
}
This would enable the following code to initialize mole fractions for any mechanism input.
const int fuelIdx = species_name_to_idx( fuelName );
const int oxyIdx = species_name_to_idx( "o2" );
const int n2Idx = species_name_to_idx( "n2" );
*XPtr[oxyIdx] <<= 1.0;
*XPtr[fuelIdx] <<= fToORatio;
if( !oxygenBool ) *XPtr[n2Idx] <<= 3.73;
else *XPtr[n2Idx] <<= 0.0;
fracSum <<= *XPtr[fuelIdx] + *XPtr[oxyIdx] + *XPtr[n2Idx];