Skip to content

Commit

Permalink
[Transport] Fix transport geometry flag check for charged species
Browse files Browse the repository at this point in the history
Electrons should not be counted when determining the number of atoms in a
molecule and the corresponding allowable molecular geometries.
  • Loading branch information
speth committed Dec 18, 2016
1 parent b20c0c6 commit 2284bc9
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 15 deletions.
39 changes: 28 additions & 11 deletions interfaces/cython/cantera/test/test_transport.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import cantera as ct
from . import utilities
import copy


class TestTransport(utilities.CanteraTest):
Expand Down Expand Up @@ -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'
)
Expand All @@ -121,19 +122,35 @@ class TestTransportGeometryFlags(utilities.CanteraTest):
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):
Expand Down
10 changes: 6 additions & 4 deletions src/transport/TransportData.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 2284bc9

Please sign in to comment.