Skip to content

Commit

Permalink
[Input] finalize transitional handling of gri30 phases
Browse files Browse the repository at this point in the history
  • Loading branch information
Ingmar Schoegl authored and ischoegl committed Dec 12, 2019
1 parent d6382a4 commit 4acb3dc
Show file tree
Hide file tree
Showing 9 changed files with 75 additions and 59 deletions.
41 changes: 26 additions & 15 deletions interfaces/cython/cantera/base.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -109,21 +109,32 @@ cdef class _SolutionBase:
elif source:
root = AnyMapFromYamlString(stringify(source))

if name == 'gri30_mix' or name == 'gri30_multi':
# catch transitional behavior
warnings.warn(
"The phases 'gri30_mix' and 'gri30_multi' are no longer "
"defined in the input file 'gri30.yaml'. The YAML version uses "
"the 'Mix' transport manager by default instead, which can be "
"overridden by specifying a transport manager via the "
"`transport_model' keyword argument during initialization. "
"Support for transitional behavior will be removed after "
"Cantera 2.5.", DeprecationWarning)
phaseNode = root[stringify("phases")].getMapWhere(stringify("name"),
stringify("gri30"))
else:
phaseNode = root[stringify("phases")].getMapWhere(stringify("name"),
stringify(name))
try:
phaseNode = root[stringify("phases")].getMapWhere(
stringify("name"), stringify(name))
except CanteraError:
if name in ['gri30_mix', 'gri30_multi']:
# catch transitional behavior
warnings.warn(
"The phases named 'gri30_mix' and 'gri30_multi' are no "
"longer defined in the input file 'gri30.yaml'. By "
"default, 'gri30.yaml' uses the mixture-averaged transport "
"model. The following options are available:\n"
" * ct.Solution('gri30.yaml') "
" # Mixture-averaged transport\n"
" * ct.Solution('gri30.yaml', transport_model='mix') "
" # Mixture-averaged transport\n"
" * ct.Solution('gri30.yaml', transport_model=None) "
" # No transport model, useful for 0-D simulations\n"
" * ct.Solution('gri30.yaml', "
"transport_model='multicomponent') "
" # Multicomponent transport\n"
"Support for transitional behavior will be removed after "
"Cantera 2.5.", DeprecationWarning)
phaseNode = root[stringify("phases")].getMapWhere(
stringify("name"), stringify("gri30"))
else:
raise

# Thermo
if isinstance(self, ThermoPhase):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

# Create the gas object used to evaluate all thermodynamic, kinetic, and
# transport properties.
gas = ct.Solution('gri30.yaml', 'gri30')
gas = ct.Solution('gri30.yaml')
gas.TP = gas.T, p

# Create an object representing the counterflow flame configuration,
Expand Down
2 changes: 1 addition & 1 deletion interfaces/cython/cantera/examples/onedim/flame_fixed_T.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
# transport properties. It is created with two transport managers, to enable
# switching from mixture-averaged to multicomponent transport on the last
# solution.
gas = ct.Solution('gri30.yaml', 'gri30')
gas = ct.Solution('gri30.yaml')

# set its state to that of the unburned gas at the burner
gas.TPX = tburner, p, comp
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
width = 0.03 # m

# Solution object used to compute mixture properties
gas = ct.Solution('gri30.yaml', 'gri30')
gas = ct.Solution('gri30.yaml')
gas.TPX = Tin, p, reactants

# Flame object
Expand Down
33 changes: 8 additions & 25 deletions interfaces/cython/cantera/test/test_convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
from cantera import ck2cti, ck2yaml, cti2yaml, ctml2yaml


import warnings

class converterTestCommon:
def convert(self, inputFile, thermo=None, transport=None,
surface=None, output=None, quiet=True, permissive=None):
Expand Down Expand Up @@ -85,29 +83,14 @@ def test_gri30(self):
self.checkKinetics(ref, gas, [300, 1500], [5e3, 1e5, 2e6])

def test_gri30_phases(self):

# cause all warnings to always be triggered.
warnings.simplefilter("always")

with warnings.catch_warnings(record=True) as w:

gas = ct.Solution('gri30.yaml', 'gri30_mix')

self.assertEqual(gas.transport_model, 'Mix')
self.assertEqual(len(w), 1)
self.assertTrue(issubclass(w[-1].category, DeprecationWarning))
self.assertIn("be removed after Cantera 2.5.",
str(w[-1].message))

with warnings.catch_warnings(record=True) as w:

gas = ct.Solution('gri30.yaml', 'gri30_multi')

self.assertEqual(gas.transport_model, 'Multi')
self.assertEqual(len(w), 1)
self.assertTrue(issubclass(w[-1].category, DeprecationWarning))
self.assertIn("be removed after Cantera 2.5.",
str(w[-1].message))
yml_file = pjoin(self.cantera_data, "gri30.yaml")
with self.assertWarnsRegex(DeprecationWarning,
'be removed after Cantera 2.5.'):
gas = ct.Solution(yml_file, 'gri30_mix')

with self.assertWarnsRegex(DeprecationWarning,
'be removed after Cantera 2.5.'):
gas = ct.Solution(yml_file, 'gri30_multi')

def test_soot(self):
self.convert('soot.inp', thermo='soot-therm.dat', output='soot_test')
Expand Down
3 changes: 2 additions & 1 deletion interfaces/matlab/toolbox/@Solution/Solution.m
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@
s.kin = k;
s.th = t;
if nargin == 3
if strcmp(trans, 'default') || strcmp(trans, 'Mix') || strcmp(trans, 'Multi')
if strcmp(trans, 'default') || strcmp(trans, 'Mix') || ...
strcmp(trans, 'Multi') || strcmp(trans, 'None')
tr = Transport(t, trans, 0);
else
error('Unknown transport modeling specified.')
Expand Down
41 changes: 28 additions & 13 deletions src/thermo/ThermoFactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -130,20 +130,35 @@ ThermoPhase* newPhase(const std::string& infile, std::string id)
if (extension == "yml" || extension == "yaml") {
AnyMap root = AnyMap::fromYamlFile(infile);
std::string name = id;
if (name=="gri30_mix" || name=="gri30_multi") {
name = "gri30";
warn_deprecated("newPhase",
"The phases 'gri30_mix' and 'gri30_multi' are no longer "
"defined in the input file 'gri30.yaml'. The YAML version uses "
"the 'Mix' transport manager by default instead, which can be "
"overridden by specifying a transport manager during "
"initialization. Support for transitional behavior will be "
"removed after Cantera 2.5.");
try {
AnyMap& phase = root["phases"].getMapWhere("name", name);
unique_ptr<ThermoPhase> t(newThermoPhase(phase["thermo"].asString()));
setupPhase(*t, phase, root);
return t.release();
} catch (CanteraError& err) {
if (name=="gri30_mix" || name=="gri30_multi") {
warn_deprecated("newPhase",
"\nThe phases named 'gri30_mix' and 'gri30_multi' are no "
"longer defined in the input file 'gri30.yaml'. By default, "
"'gri30.yaml' uses the mixture-averaged transport model. The "
"following options are available:\n"
" * 'Mix': Mixture-averaged transport\n"
" * 'Multi': Multicomponent transport\n"
" * 'None': No transport model, useful for 0-D simulations\n"
"Examples for setting of transport model:\n"
" - MATLAB: Solution('gri30.yaml', 'gri30', 'None')\n"
" - C++: newSolution(\"gri30.yaml\", \"gri30\", \"Mix\")\n"
"Support for transitional behavior will be removed after "
"Cantera 2.5.");
AnyMap& phase = root["phases"].getMapWhere("name", "gri30");
unique_ptr<ThermoPhase> t(newThermoPhase(phase["thermo"].asString()));
setupPhase(*t, phase, root);
t->setName(name);
return t.release();
} else {
throw;
}
}
AnyMap& phase = root["phases"].getMapWhere("name", name);
unique_ptr<ThermoPhase> t(newThermoPhase(phase["thermo"].asString()));
setupPhase(*t, phase, root);
return t.release();
} else {
XML_Node* root = get_XML_File(infile);
XML_Node* xphase = get_XML_NameID("phase", "#"+id, root);
Expand Down
2 changes: 1 addition & 1 deletion test/equil/equil_gas.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ TEST_F(OverconstrainedEquil, DISABLED_BasisOptimize2)
class GriEquilibriumTest : public testing::Test
{
public:
GriEquilibriumTest() : gas("gri30.yaml", "gri30") {
GriEquilibriumTest() : gas("gri30.yaml") {
X.resize(gas.nSpecies());
Yelem.resize(gas.nElements());
};
Expand Down
8 changes: 7 additions & 1 deletion test/matlab/TestImport.m
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,13 @@
end

function testImportYAML(self)
gas = Solution('gri30.yaml', 'gri30', 'Mix');
gas = Solution('gri30.yaml');
dkm = mixDiffCoeffs(gas);
assertEqual(length(dkm), nSpecies(gas))
end

function testImportXML(self)
gas = Solution('gri30.xml', 'gri30_mix');
dkm = mixDiffCoeffs(gas);
assertEqual(length(dkm), nSpecies(gas))
end
Expand Down

0 comments on commit 4acb3dc

Please sign in to comment.