1515 from xml .etree .ElementTree import parse
1616except ImportError :
1717 from elementtree import parse
18- from numpy import empty , array , dot , log
18+ import numpy as np
1919
2020# Universal gas constant R
2121R = 8.314472
@@ -62,11 +62,11 @@ def cpo(self, T):
6262 # I know perfectly that the most efficient way of evaluatin
6363 # polynomials is recursively but I want the implementation to
6464 # be as explicit as possible
65- Ta = array ([1 , T , T ** 2 , T ** 3 , T ** 4 ], 'd' )
65+ Ta = np . array ([1 , T , T ** 2 , T ** 3 , T ** 4 ], 'd' )
6666 if T > 200 and T <= 1000 :
67- return dot (self .Tmin_ [:5 ], Ta ) * R
67+ return np . dot (self .Tmin_ [:5 ], Ta ) * R
6868 elif T > 1000 and T < 6000 :
69- return dot (self ._Tmax [:5 ], Ta ) * R
69+ return np . dot (self ._Tmax [:5 ], Ta ) * R
7070 else :
7171 raise ValueError ("Temperature out of range" )
7272
@@ -87,11 +87,11 @@ def ho(self, T):
8787 """
8888 Computes the sensible enthalpy in J/mol
8989 """
90- Ta = array ([1 , T / 2 , T ** 2 / 3 , T ** 3 / 4 , T ** 4 / 5 , 1 / T ], 'd' )
90+ Ta = np . array ([1 , T / 2 , T ** 2 / 3 , T ** 3 / 4 , T ** 4 / 5 , 1 / T ], 'd' )
9191 if T > 200 and T <= 1000 :
92- return dot (self .Tmin_ [:6 ], Ta ) * R * T
92+ return np . dot (self .Tmin_ [:6 ], Ta ) * R * T
9393 elif T > 1000 and T < 6000 :
94- return dot (self ._Tmax [:6 ], Ta ) * R * T
94+ return np . dot (self ._Tmax [:6 ], Ta ) * R * T
9595 else :
9696 raise ValueError ("Temperature out of range" )
9797
@@ -105,11 +105,11 @@ def so(self, T):
105105 """
106106 Computes enthropy in J/mol K
107107 """
108- Ta = array ([log (T ), T , T ** 2 / 2 , T ** 3 / 3 , T ** 4 / 4 , 0 , 1 ], 'd' )
108+ Ta = np . array ([np . log (T ), T , T ** 2 / 2 , T ** 3 / 3 , T ** 4 / 4 , 0 , 1 ], 'd' )
109109 if T > 200 and T <= 1000 :
110- return dot (self .Tmin_ , Ta ) * R
110+ return np . dot (self .Tmin_ , Ta ) * R
111111 elif T > 1000 and T < 6000 :
112- return dot (self ._Tmax , Ta ) * R
112+ return np . dot (self ._Tmax , Ta ) * R
113113 else :
114114 raise ValueError ("Temperature out of range" )
115115
@@ -324,7 +324,6 @@ def __unicode__(self):
324324
325325
326326class Elementdb (object ):
327-
328327 """
329328 Class that reads the Alexander Burcat's thermochemical database
330329 for combustion.
@@ -416,41 +415,32 @@ def getelementdata(self, formula):
416415 """
417416 Returns an element instance given the name of the element.
418417 """
419- Tmin_ = empty (( 7 ), 'd' )
420- _Tmax = empty (( 7 ), 'd' )
418+ Tmin_ = np . zeros ( 7 )
419+ _Tmax = np . zeros ( 7 )
421420 comp = []
422421 for specie in self .db :
423- try :
424- for element in specie :
425- try :
426- if element .tag == "phase" :
427- if formula == element .find ("formula" ).text :
428- phase = element
429- coefficients = phase .find ("coefficients" )
430- low = coefficients .find ("range_Tmin_to_1000" )
431- for (i , c ) in zip (range (7 ), low ):
432- Tmin_ [i ] = float (c .text )
433-
434- high = coefficients .find ("range_1000_to_Tmax" )
435- for (i , c ) in zip (range (7 ), high ):
436- _Tmax [i ] = float (c .text )
437-
438- elements = phase .find ("elements" )
439- elements = elements .getchildren ()
440- for elem in elements :
441- it = elem .items ()
442- # First is name of element, second is number
443- # of atoms
444- comp .append ((it [0 ][1 ], int (it [1 ][1 ])))
445-
446- mm = float (phase .find ("molecular_weight" ).text ) / 1000
447- hfr = float (coefficients .find ("hf298_div_r" ).text )
448-
449- return Element (formula , Tmin_ , _Tmax , mm , hfr , comp )
450- except :
451- pass
452- except :
453- pass
422+ for element in specie :
423+ if element .tag == "phase" :
424+ if formula == element .find ("formula" ).text :
425+ phase = element
426+ coefficients = phase .find ("coefficients" )
427+ low = coefficients .find ("range_Tmin_to_1000" )
428+ for (i , c ) in zip (range (7 ), low ):
429+ Tmin_ [i ] = float (c .text )
430+
431+ high = coefficients .find ("range_1000_to_Tmax" )
432+ for (i , c ) in zip (range (7 ), high ):
433+ _Tmax [i ] = float (c .text )
434+
435+ elements = phase .find ("elements" ).getchildren ()
436+ for elem in elements :
437+ elem_data = elem .attrib
438+ comp .append ((elem_data ['name' ], int (elem_data ['num_of_atoms' ])))
439+
440+ mm = float (phase .find ("molecular_weight" ).text ) / 1000
441+ hfr = float (coefficients .find ("hf298_div_r" ).text )
442+
443+ return Element (formula , Tmin_ , _Tmax , mm , hfr , comp )
454444
455445 def getmixturedata (self , components ):
456446 """
0 commit comments