示例#1
0
    def generateThermo(self):
        """
        Generate the thermodynamic data for the species and fit it to the
        desired heat capacity model (as specified in the `thermoClass` 
        attribute).
        """
        if self.thermoClass.lower() not in ['wilhoit', 'nasa']:
            raise Exception('Unknown thermodynamic model "{0}".'.format(
                self.thermoClass))

        species = self.species

        logging.info('Generating {0} thermo model for {1}...'.format(
            self.thermoClass, species))

        Tlist = numpy.arange(10.0, 3001.0, 10.0, numpy.float64)
        Cplist = numpy.zeros_like(Tlist)
        H298 = 0.0
        S298 = 0.0
        conformer = self.species.conformer
        for i in range(Tlist.shape[0]):
            Cplist[i] += conformer.getHeatCapacity(Tlist[i])
        H298 += conformer.getEnthalpy(298.) + conformer.E0.value_si
        S298 += conformer.getEntropy(298.)

        if not any([
                isinstance(mode, (LinearRotor, NonlinearRotor))
                for mode in conformer.modes
        ]):
            # Monatomic species
            linear = False
            Nfreq = 0
            Nrotors = 0
            Cp0 = 2.5 * constants.R
            CpInf = 2.5 * constants.R
        else:
            # Polyatomic species
            linear = True if isinstance(conformer.modes[1],
                                        LinearRotor) else False
            Nfreq = len(conformer.modes[2].frequencies.value)
            Nrotors = len(conformer.modes[3:])
            Cp0 = (3.5 if linear else 4.0) * constants.R
            CpInf = Cp0 + (Nfreq + 0.5 * Nrotors) * constants.R

        wilhoit = Wilhoit()
        if Nfreq == 0 and Nrotors == 0:
            wilhoit.Cp0 = (Cplist[0], "J/(mol*K)")
            wilhoit.CpInf = (Cplist[0], "J/(mol*K)")
            wilhoit.B = (500., "K")
            wilhoit.H0 = (0.0, "J/mol")
            wilhoit.S0 = (0.0, "J/(mol*K)")
            wilhoit.H0 = (H298 - wilhoit.getEnthalpy(298.15), "J/mol")
            wilhoit.S0 = (S298 - wilhoit.getEntropy(298.15), "J/(mol*K)")
        else:
            wilhoit.fitToData(Tlist, Cplist, Cp0, CpInf, H298, S298, B0=500.0)

        if self.thermoClass.lower() == 'nasa':
            species.thermo = wilhoit.toNASA(Tmin=10.0, Tmax=3000.0, Tint=500.0)
        else:
            species.thermo = wilhoit
 def generateThermo(self):
     """
     Generate the thermodynamic data for the species and fit it to the
     desired heat capacity model (as specified in the `thermoClass` 
     attribute).
     """
     if self.thermoClass.lower() not in ['wilhoit', 'nasa']:
         raise Exception('Unknown thermodynamic model "{0}".'.format(self.thermoClass))
 
     species = self.species
 
     logging.debug('Generating {0} thermo model for {1}...'.format(self.thermoClass, species))
     
     if species.thermo is not None:
         logging.info("Thermo already generated for species {}. Skipping thermo generation.".format(species))
         return None
     
     Tlist = np.arange(10.0, 3001.0, 10.0, np.float64)
     Cplist = np.zeros_like(Tlist)
     H298 = 0.0
     S298 = 0.0
     conformer = self.species.conformer
     for i in range(Tlist.shape[0]):
         Cplist[i] += conformer.getHeatCapacity(Tlist[i])
     H298 += conformer.getEnthalpy(298.) + conformer.E0.value_si
     S298 += conformer.getEntropy(298.)
     
     if not any([isinstance(mode, (LinearRotor, NonlinearRotor)) for mode in conformer.modes]):
         # Monatomic species
         linear = False
         Nfreq = 0
         Nrotors = 0
         Cp0 = 2.5 * constants.R
         CpInf = 2.5 * constants.R
     else:
         # Polyatomic species
         linear = True if isinstance(conformer.modes[1], LinearRotor) else False
         Nfreq = len(conformer.modes[2].frequencies.value)
         Nrotors = len(conformer.modes[3:])
         Cp0 = (3.5 if linear else 4.0) * constants.R
         CpInf = Cp0 + (Nfreq + 0.5 * Nrotors) * constants.R
 
     wilhoit = Wilhoit()
     if Nfreq == 0 and Nrotors == 0:
         wilhoit.Cp0 = (Cplist[0],"J/(mol*K)") 
         wilhoit.CpInf = (Cplist[0],"J/(mol*K)")
         wilhoit.B = (500.,"K") 
         wilhoit.H0 = (0.0,"J/mol")
         wilhoit.S0 = (0.0,"J/(mol*K)") 
         wilhoit.H0 =  (H298 -wilhoit.getEnthalpy(298.15), "J/mol") 
         wilhoit.S0 = (S298 - wilhoit.getEntropy(298.15),"J/(mol*K)")
     else:
         wilhoit.fitToData(Tlist, Cplist, Cp0, CpInf, H298, S298, B0=500.0)
     
     if self.thermoClass.lower() == 'nasa':
         species.thermo = wilhoit.toNASA(Tmin=10.0, Tmax=3000.0, Tint=500.0)
     else:
         species.thermo = wilhoit
Tlist = numpy.array([300.0,400.0,500.0,600.0,800.0,1000.0])
Cplist = numpy.array([24.2, 31.1, 36.9, 41.4, 48, 52.55])*4.184 #J/mol*K
H298 = 40.5*4184 #J/mol
S298 = 81.35*4.184 #J/mol*K

# Polyatomic species
linear = False
Nfreq = 30
Nrotors = 0
Cp0 = (3.5 if linear else 4.0) * constants.R
CpInf = Cp0 + (Nfreq + 0.5 * Nrotors) * constants.R

wilhoit = Wilhoit()

wilhoit.fitToData(Tlist, Cplist, Cp0, CpInf, H298, S298, B0=500.0)\

NASA_fit = wilhoit.toNASA(Tlist[0], Tlist[-1], Tint=500.0)

string = ''

f = open('chem.inp', 'a')

# Line 1
string += '{0:<16}        '.format(SpeciesIdentifier)
if len(elementCounts) <= 4:
    # Use the original Chemkin syntax for the element counts
    for key, count in elementCounts.iteritems():
        if isinstance(key, tuple):
            symbol, isotope = key
            chemkinName = getElement(symbol, isotope=isotope).chemkinName