[ctml_writer] Fix handling of units in some fields

When using Python 3, using -1 as the dummy value for density and site_density
causes probems, because the (ordered) comparison between a density specified
with units (as a tuple) and 0 is not allowed. Instead, use None as the
placeholder value.
This commit is contained in:
Ray Speth 2014-03-13 02:19:28 +00:00
parent 755164397d
commit df908229b1
2 changed files with 20 additions and 4 deletions

View file

@ -2055,7 +2055,7 @@ class incompressible_solid(phase):
elements = '',
species = '',
note = '',
density = -1.0,
density = None,
transport = 'None',
initial_state = None,
options = []):
@ -2064,7 +2064,7 @@ class incompressible_solid(phase):
initial_state, options)
self._dens = density
self._pure = 0
if self._dens < 0.0:
if self._dens is None:
raise CTI_Error('density must be specified.')
self._tr = transport
@ -2093,7 +2093,7 @@ class lattice(phase):
transport = 'None',
initial_state = None,
options = [],
site_density = -1.0,
site_density = None,
vacancy_species = ''):
phase.__init__(self, name, 3, elements, species, note, 'none',
initial_state, options)
@ -2105,7 +2105,7 @@ class lattice(phase):
raise CTI_Error('sublattice name must be specified')
if species == '':
raise CTI_Error('sublattice species must be specified')
if site_density < 0.0:
if site_density is None:
raise CTI_Error('sublattice '+name
+' site density must be specified')

View file

@ -304,3 +304,19 @@ class chemkinConverterTest(utilities.CanteraTest):
quiet=True)
self.assertRaises(ck2cti.InputParseError, convert)
class CtmlConverterTest(utilities.CanteraTest):
def test_sofc(self):
gas_a, anode_bulk, oxide_a = ct.import_phases(
'../../interfaces/cython/cantera/examples/surface_chemistry/sofc.cti',
['gas', 'metal', 'oxide_bulk'])
self.assertNear(gas_a.P, ct.one_atm)
self.assertNear(anode_bulk['electron'].X, 1.0)
self.assertNear(oxide_a.density, 700)
def test_diamond(self):
gas, solid = ct.import_phases('diamond.cti', ['gas','diamond'])
face = ct.Interface('diamond.cti', 'diamond_100', [gas, solid])
self.assertNear(face.site_density, 3e-8)