Skip to content

Commit

Permalink
[Input/Test] Add tests of solution properties for round-tripped phases
Browse files Browse the repository at this point in the history
  • Loading branch information
speth committed Apr 12, 2021
1 parent 42d5923 commit 2f5ecea
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions interfaces/cython/cantera/test/test_composite.py
Original file line number Diff line number Diff line change
Expand Up @@ -474,6 +474,9 @@ def test_input_data_debye_huckel(self):

def test_yaml_simple(self):
gas = ct.Solution('h2o2.yaml')
gas.TPX = 500, ct.one_atm, 'H2: 1.0, O2: 1.0'
gas.equilibrate('HP')
gas.TP = 1500, ct.one_atm
gas.write_yaml('h2o2-generated.yaml')
with open('h2o2-generated.yaml', 'r') as infile:
generated = yaml.safe_load(infile)
Expand All @@ -485,8 +488,19 @@ def test_yaml_simple(self):
for i, reaction in enumerate(generated['reactions']):
self.assertEqual(reaction['equation'], gas.reaction_equation(i))

gas2 = ct.Solution("h2o2-generated.yaml")
self.assertArrayNear(gas.concentrations, gas2.concentrations)
self.assertArrayNear(gas.partial_molar_enthalpies,
gas2.partial_molar_enthalpies)
self.assertArrayNear(gas.forward_rate_constants,
gas2.forward_rate_constants)
self.assertArrayNear(gas.mix_diff_coeffs, gas2.mix_diff_coeffs)

def test_yaml_outunits(self):
gas = ct.Solution('h2o2.yaml')
gas.TPX = 500, ct.one_atm, 'H2: 1.0, O2: 1.0'
gas.equilibrate('HP')
gas.TP = 1500, ct.one_atm
units = {'length': 'cm', 'quantity': 'mol', 'energy': 'cal'}
gas.write_yaml('h2o2-generated.yaml', units=units)
with open('h2o2-generated.yaml') as infile:
Expand All @@ -500,9 +514,19 @@ def test_yaml_outunits(self):
self.assertNear(r1['rate-constant']['A'], r2['rate-constant']['A'])
self.assertNear(r1['rate-constant']['Ea'], r2['rate-constant']['Ea'])

gas2 = ct.Solution("h2o2-generated.yaml")
self.assertArrayNear(gas.concentrations, gas2.concentrations)
self.assertArrayNear(gas.partial_molar_enthalpies,
gas2.partial_molar_enthalpies)
self.assertArrayNear(gas.forward_rate_constants,
gas2.forward_rate_constants)
self.assertArrayNear(gas.mix_diff_coeffs, gas2.mix_diff_coeffs)

def test_yaml_surface(self):
gas = ct.Solution('ptcombust.yaml', 'gas')
surf = ct.Interface('ptcombust.yaml', 'Pt_surf', [gas])
gas.TPY = 900, ct.one_atm, np.ones(gas.n_species)
surf.coverages = np.ones(surf.n_species)
surf.write_yaml('ptcombust-generated.yaml')

with open('ptcombust-generated.yaml') as infile:
Expand All @@ -513,6 +537,13 @@ def test_yaml_surface(self):
self.assertEqual(len(generated['Pt_surf-reactions']), surf.n_reactions)
self.assertEqual(len(generated['species']), surf.n_total_species)

gas2 = ct.Solution('ptcombust-generated.yaml', 'gas')
surf2 = ct.Solution('ptcombust-generated.yaml', 'Pt_surf', [gas2])
self.assertArrayNear(surf.concentrations, surf2.concentrations)
self.assertArrayNear(surf.partial_molar_enthalpies,
surf2.partial_molar_enthalpies)
self.assertArrayNear(surf.forward_rate_constants,
surf2.forward_rate_constants)

class TestSpeciesSerialization(utilities.CanteraTest):
def test_species_simple(self):
Expand Down

0 comments on commit 2f5ecea

Please sign in to comment.