From 2284bc9186d8ba8d1a7c1cff889cc476741c9e84 Mon Sep 17 00:00:00 2001 From: Ray Speth Date: Fri, 16 Dec 2016 14:22:18 -0500 Subject: [PATCH] [Transport] Fix transport geometry flag check for charged species Electrons should not be counted when determining the number of atoms in a molecule and the corresponding allowable molecular geometries. --- .../cython/cantera/test/test_transport.py | 39 +++++++++++++------ src/transport/TransportData.cpp | 10 +++-- 2 files changed, 34 insertions(+), 15 deletions(-) diff --git a/interfaces/cython/cantera/test/test_transport.py b/interfaces/cython/cantera/test/test_transport.py index 428de724d..78a7aa590 100644 --- a/interfaces/cython/cantera/test/test_transport.py +++ b/interfaces/cython/cantera/test/test_transport.py @@ -2,6 +2,7 @@ import numpy as np import cantera as ct from . import utilities +import copy class TestTransport(utilities.CanteraTest): @@ -93,8 +94,8 @@ class TestTransportGeometryFlags(utilities.CanteraTest): units(length="cm", time="s", quantity="mol", act_energy="cal/mol") ideal_gas(name="test", - elements="O H", - species="H2 H H2O", + elements="O H E", + species="H2 H H2O OHp E", initial_state=state(temperature=300.0, pressure=OneAtm), transport='Mix' ) @@ -121,19 +122,35 @@ species(name="H2O", geom="{H2O}", diam=2.60, well_depth=572.40, dipole=1.84, rot_relax=4.00) ) + +species(name="OHp", + atoms=" H:1 O:1 E:-1", + thermo=const_cp(t0=1000, h0=51.7, s0=19.5, cp0=8.41), + transport=gas_transport( + geom="{OHp}", + diam=2.60, well_depth=572.40, dipole=1.84, rot_relax=4.00) +) + +species(name="E", + atoms=" E:1 ", + thermo=const_cp(t0=1000, h0=0, s0=0, cp0=0), + transport=gas_transport( + geom="{E}", diam=0.01, well_depth=1.00) +) """ def test_bad_geometry(self): - ct.Solution(source=self.phase_data.format(H='atom', - H2='linear', - H2O='nonlinear')) - bad = [{'H':'linear', 'H2':'linear', 'H2O':'nonlinear'}, - {'H':'nonlinear', 'H2':'linear', 'H2O':'nonlinear'}, - {'H':'atom', 'H2':'atom', 'H2O':'nonlinear'}, - {'H':'atom', 'H2':'nonlinear', 'H2O':'nonlinear'}, - {'H':'atom', 'H2':'linear', 'H2O':'atom'}] + good = {'H':'atom', 'H2':'linear', 'H2O':'nonlinear', 'OHp':'linear', + 'E':'atom'} + ct.Solution(source=self.phase_data.format(**good)) + + bad = [{'H':'linear'}, {'H':'nonlinear'}, {'H2':'atom'}, + {'H2':'nonlinear'}, {'H2O':'atom'}, {'OHp':'atom'}, + {'OHp':'nonlinear'}, {'E':'linear'}] for geoms in bad: + test = copy.copy(good) + test.update(geoms) with self.assertRaises(ct.CanteraError): - ct.Solution(source=self.phase_data.format(**geoms)) + ct.Solution(source=self.phase_data.format(**test)) class TestDustyGas(utilities.CanteraTest): diff --git a/src/transport/TransportData.cpp b/src/transport/TransportData.cpp index 6762022c3..ae5d33270 100644 --- a/src/transport/TransportData.cpp +++ b/src/transport/TransportData.cpp @@ -53,20 +53,22 @@ void GasTransportData::validate(const Species& sp) { double nAtoms = 0; for (const auto& elem : sp.composition) { - nAtoms += elem.second; + if (!ba::iequals(elem.first, "E")) { + nAtoms += elem.second; + } } if (geometry == "atom") { - if (nAtoms != 1) { + if (nAtoms > 1) { throw CanteraError("GasTransportData::validate", "invalid geometry for species '{}'. 'atom' specified, but " "species contains multiple atoms.", sp.name); } } else if (geometry == "linear") { - if (nAtoms == 1) { + if (nAtoms < 2) { throw CanteraError("GasTransportData::validate", "invalid geometry for species '{}'. 'linear' specified, but " - "species only contains one atom.", sp.name); + "species does not contain multiple atoms.", sp.name); } } else if (geometry == "nonlinear") { if (nAtoms < 3) {