hkmoffat / cantera

Automatically exported from code.google.com/p/cantera
0 stars 0 forks source link

Python / atomicWeights() function bug/inconsistency #149

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?

1. open python commandline and run the following:

import Cantera as cnt
gas = cnt.GRI30()

# each of the statements below throws an error
print gas.atomicWeights('Ar')
print gas.atomicWeights('AR')
print gas.atomicWeights( gas.elementNames() )
print gas.molecularWeights( gas.elementNames() )

2. There are essentially two issues:
 - a mismatch between 'Ar' in atomic species list and 'AR' in molecular species
 - atomicWeights(el) only reads first character of element name

What is the expected output? What do you see instead?

... throws errors

What version of the product are you using? On what operating system?

Cantera 2.0 / linux

Please provide any additional information below.

N/A

Original issue reported on code.google.com by ischo...@gmail.com on 9 Mar 2013 at 7:26

GoogleCodeExporter commented 9 years ago
PS: the exact version is cantera-2.0.0, and the third statement actually works 
(i.e. print gas.atomicWeights( gas.elementNames() ) )

Original comment by ischo...@gmail.com on 9 Mar 2013 at 7:33

GoogleCodeExporter commented 9 years ago
Everything is working here as expected.

- For the first two examples, the documentation for the atomicWeights method 
specifies that it takes a *sequence* of elements. The string 'Ar' is a sequence 
of two characters, neither of which are elements in the gas, so you get an 
exception. If you call "gas.atomicWeights(['Ar'])" it will work fine.

- There is no required correspondence between the species names and the element 
names. Cantera defines all the element names to have only the first letter 
capitalized. The species names in this case are defined by the GRI 3.0 
mechanism, which uses all-caps species identifiers.

- The fourth statement fails because you're asking for the *molecular weights* 
of the pure elements, which aren't necessarily in the list of species by the 
same name (or at all). 

Original comment by yarmond on 12 Mar 2013 at 11:15

GoogleCodeExporter commented 9 years ago
Thanks, yarmond ... 

Your points are technically correct, but I'd dispute that this renders my 
report 'invalid':

- "gas.molecularWeights('H2')" works, and gas.molecularWeights('AR') works, so 
it's not a stretch to expect "gas.atomicWeights('Ar')" to exhibit similar 
behavior.

- while there are no required correspondences between species names and element 
names, it would make sense to make them correspond: if it walks like a duck and 
quacks like a duck it is probably a duck ... btw, the pure element 'Ar' is 
indeed the same as the species 'AR' (I'd agree with your point of elements and 
species being independent if the element names were hard-coded in cantera, but 
the call "gas.elementNames()" indicates that the element information is pulled 
from the mechanism.)

Just my 2 cents. I admit that both fixes are more like 'papercuts', rather than 
major issues ...

Original comment by ischo...@gmail.com on 13 Mar 2013 at 1:34

GoogleCodeExporter commented 9 years ago
Don't read too much into the status "invalid". There are only a few statuses 
that indicate an issue is closed with no corresponding change.

The element names are actually essentially hardcoded. Every Cantera input file 
uses the elements as defined in the file "elements.xml", which uses the mixed 
case convention for the element names.

Species and elements are distinct entities as far as Cantera is concerned. The 
molecularWeights method expects a list of species names. Just because there is 
a species whose chemical formula is 'Ar' does not mean that there is a species 
by that name.

Original comment by yarmond on 13 Mar 2013 at 3:05