Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add and improve to_cantera methods for conversion to in-memory Cantera objects #2700

Open
wants to merge 8 commits into
base: main
Choose a base branch
from

Conversation

rwest
Copy link
Member

@rwest rwest commented Aug 2, 2024

Replaces #2597

Motivation or Problem

The conversion to Cantera YAML files currently implemented in #2321 involves converting things to Cantera objects in memory then having Cantera return the properties. That revealed that some to_cantera methods were missing, namely for surface kinetics, and went about adding them.
Meanwhile #2597 added some to_cantera methods for surface kinetics to enable creating and updating Cantera simulations.

Description of Changes

This PR takes both those, merges them, cleans them up a bit, and adds unit tests.

Testing

I added and extended unit tests that reads a small chemkin file and compares the results of chemkinfile->RMG->Cantera vs chemkinfile->ck2yaml->Cantera.

Additional notes

#2321 has been rebased to separate out these changes from the YAML-writing changes, so this can be reviewed and merged first, and that PR will be greatly shorter.

This replaces #2597 which can be closed once this is merged.

rwest and others added 8 commits August 2, 2024 10:20
This took me a while to figure out  what was happening.
So I changed variable name, removed a redundant if block,
and added a couple of comments.
It was fragile, depending on the precise ordering of lines
in the test file.
To enable proper conversion in Cantera (for a future test)
we need some gas phase parts to the chemkin mechanism.
I added two extra types of surface reaction, an adsorption
sticking coefficient, and an associative desorption.
I also tidied up the species names and formatting.
to_cantera for Reaction and Species and some surface kinetics types

squashed commit from Richard:
Should be able to use the to_cantera_kinetics methods.
Not sure about all these nested elifs. I think some are confused.

Co-authored-by:  Nora Khalil <[email protected]>
Co-authored-by:  Richard West <[email protected]>
Nick add cm^5/(mol^2*s) dimensionality

Co-authored-by:  Sevy Harris <[email protected]>
Co-authored-by:  Nicholas Tietje <[email protected]>
Cantera now has a BlowersMasel kinetics class.

This requires Cantera > 2.6
As described in
https://cantera.org/dev/python/kinetics.html#cantera.BlowersMaselRate
the API may change suddenly on some versions.
This is in the canteramodelTest. We load a gas/surface mechanism 
saved in chemkin format (updated in prior commit) into both RMG
and into Cantera. We then convert the RMG objects into Cantera objects
and then compare them all - species and reactions.
This mirrors the way the gas phase parts were tested.
Hopefully increases test coverage of the new to_cantera_kinetics methods.
Copy link

github-actions bot commented Aug 2, 2024

Regression Testing Results

WARNING:root:Initial mole fractions do not sum to one; normalizing.
WARNING:root:Initial mole fractions do not sum to one; normalizing.
WARNING:root:Initial mole fractions do not sum to one; normalizing.
⚠️ One or more regression tests failed.
Please download the failed results and run the tests locally or check the log to see why.

Detailed regression test results.

Regression test aromatics:

Reference: Execution time (DD:HH:MM:SS): 00:00:01:06
Current: Execution time (DD:HH:MM:SS): 00:00:01:09
Reference: Memory used: 2776.74 MB
Current: Memory used: 2770.02 MB

aromatics Passed Core Comparison ✅

Original model has 15 species.
Test model has 15 species. ✅
Original model has 11 reactions.
Test model has 11 reactions. ✅

aromatics Failed Edge Comparison ❌

Original model has 106 species.
Test model has 106 species. ✅
Original model has 358 reactions.
Test model has 358 reactions. ✅

Non-identical thermo! ❌
original: C=CC1C=CC2=CC1C=C2
tested: C=CC1C=CC2=CC1C=C2

Hf(300K) S(300K) Cp(300K) Cp(400K) Cp(500K) Cp(600K) Cp(800K) Cp(1000K) Cp(1500K)
83.22 84.16 35.48 45.14 53.78 61.40 73.58 82.20 95.08
83.22 82.78 35.48 45.14 53.78 61.40 73.58 82.20 95.08

Identical thermo comments:
thermo: Thermo group additivity estimation: group(Cs-(Cds-Cds)(Cds-Cds)CsH) + group(Cs-(Cds-Cds)(Cds-Cds)CsH) + group(Cds-Cds(Cds-Cds)(Cds-Cds)) + group(Cds- CdsCsH) + group(Cds-CdsCsH) + group(Cds-CdsCsH) + group(Cds-CdsCsH) + group(Cds-Cds(Cds-Cds)H) + group(Cds-Cds(Cds-Cds)H) + group(Cds-CdsHH) + Estimated bicyclic component: polycyclic(s3_5_6_ane) - ring(Cyclohexane) - ring(Cyclopentane) + ring(1,3-Cyclohexadiene) + ring(Cyclopentadiene)

Observables Test Case: Aromatics Comparison

✅ All Observables varied by less than 0.500 on average between old model and new model in all conditions!

aromatics Passed Observable Testing ✅

Regression test liquid_oxidation:

Reference: Execution time (DD:HH:MM:SS): 00:00:02:10
Current: Execution time (DD:HH:MM:SS): 00:00:02:15
Reference: Memory used: 2923.08 MB
Current: Memory used: 2903.60 MB

liquid_oxidation Failed Core Comparison ❌

Original model has 37 species.
Test model has 37 species. ✅
Original model has 215 reactions.
Test model has 216 reactions. ❌
The tested model has 1 reactions that the original model does not have. ❌
rxn: CCO[O](29) <=> [OH](22) + CC=O(69) origin: intra_H_migration

liquid_oxidation Failed Edge Comparison ❌

Original model has 202 species.
Test model has 202 species. ✅
Original model has 1610 reactions.
Test model has 1610 reactions. ✅
The original model has 1 reactions that the tested model does not have. ❌
rxn: CCO[O](30) <=> C[CH]OO(70) origin: intra_H_migration
The tested model has 1 reactions that the original model does not have. ❌
rxn: CCO[O](29) <=> [OH](22) + CC=O(69) origin: intra_H_migration

Non-identical kinetics! ❌
original:
rxn: CCCCCO[O](104) + CC(CC(C)OO)O[O](103) <=> oxygen(1) + CCCCC[O](127) + CC([O])CC(C)OO(129) origin: Peroxyl_Disproportionation
tested:
rxn: CCCCCO[O](103) + CC(CC(C)OO)O[O](104) <=> oxygen(1) + CCCCC[O](128) + CC([O])CC(C)OO(127) origin: Peroxyl_Disproportionation

k(1bar) 300K 400K 500K 600K 800K 1000K 1500K 2000K
k(T): 7.79 7.46 7.21 7.00 6.67 6.41 5.94 5.60
k(T): 3.52 4.27 4.71 5.01 5.39 5.61 5.91 6.06

kinetics: Arrhenius(A=(3.18266e+20,'cm^3/(mol*s)'), n=-2.694, Ea=(0.053,'kcal/mol'), T0=(1,'K'), comment="""Estimated from node Root_Ext-5R-R_7R!H->C_N-7C-inRing Ea raised from 0.0 to 0.2 kJ/mol to match endothermicity of reaction.""")
kinetics: Arrhenius(A=(3.2e+12,'cm^3/(mol*s)'), n=0, Ea=(4.096,'kcal/mol'), T0=(1,'K'), comment="""Estimated from node Root_Ext-5R-R_7R!H->C_N-7C-inRing_Ext-5R-R""")
kinetics: Estimated from node Root_Ext-5R-R_7R!H->C_N-7C-inRing
Ea raised from 0.0 to 0.2 kJ/mol to match endothermicity of reaction.
kinetics: Estimated from node Root_Ext-5R-R_7R!H->C_N-7C-inRing_Ext-5R-R

Observables Test Case: liquid_oxidation Comparison

✅ All Observables varied by less than 0.100 on average between old model and new model in all conditions!

liquid_oxidation Passed Observable Testing ✅

Regression test nitrogen:

Reference: Execution time (DD:HH:MM:SS): 00:00:01:28
Current: Execution time (DD:HH:MM:SS): 00:00:01:25
Reference: Memory used: 2909.51 MB
Current: Memory used: 2908.81 MB

nitrogen Passed Core Comparison ✅

Original model has 41 species.
Test model has 41 species. ✅
Original model has 360 reactions.
Test model has 360 reactions. ✅

nitrogen Passed Edge Comparison ✅

Original model has 133 species.
Test model has 133 species. ✅
Original model has 983 reactions.
Test model has 983 reactions. ✅

Observables Test Case: NC Comparison

✅ All Observables varied by less than 0.200 on average between old model and new model in all conditions!

nitrogen Passed Observable Testing ✅

Regression test oxidation:

Reference: Execution time (DD:HH:MM:SS): 00:00:02:27
Current: Execution time (DD:HH:MM:SS): 00:00:02:28
Reference: Memory used: 2773.98 MB
Current: Memory used: 2760.68 MB

oxidation Passed Core Comparison ✅

Original model has 59 species.
Test model has 59 species. ✅
Original model has 694 reactions.
Test model has 694 reactions. ✅

oxidation Passed Edge Comparison ✅

Original model has 230 species.
Test model has 230 species. ✅
Original model has 1526 reactions.
Test model has 1526 reactions. ✅

Observables Test Case: Oxidation Comparison

✅ All Observables varied by less than 0.500 on average between old model and new model in all conditions!

oxidation Passed Observable Testing ✅

Regression test sulfur:

Reference: Execution time (DD:HH:MM:SS): 00:00:00:56
Current: Execution time (DD:HH:MM:SS): 00:00:00:56
Reference: Memory used: 2880.59 MB
Current: Memory used: 2868.71 MB

sulfur Passed Core Comparison ✅

Original model has 27 species.
Test model has 27 species. ✅
Original model has 74 reactions.
Test model has 74 reactions. ✅

sulfur Failed Edge Comparison ❌

Original model has 89 species.
Test model has 89 species. ✅
Original model has 227 reactions.
Test model has 227 reactions. ✅
The original model has 1 reactions that the tested model does not have. ❌
rxn: O(4) + SO2(15) (+N2) <=> SO3(16) (+N2) origin: primarySulfurLibrary
The tested model has 1 reactions that the original model does not have. ❌
rxn: O(4) + SO2(15) (+N2) <=> SO3(16) (+N2) origin: primarySulfurLibrary

Observables Test Case: SO2 Comparison

The following observables did not match:

❌ Observable species O=S=O varied by more than 0.100 on average between old model SO2(15) and new model SO2(15) in condition 1.

⚠️ The following reaction conditions had some discrepancies:
Condition 1:
Reactor Type: IdealGasReactor
Reaction Time: 0.01 s
T0: 900 K
P0: 30 bar
Initial Mole Fractions: {'S': 0.000756, '[O][O]': 0.00129, 'N#N': 0.997954}

sulfur Failed Observable Testing ❌

Regression test superminimal:

Reference: Execution time (DD:HH:MM:SS): 00:00:00:39
Current: Execution time (DD:HH:MM:SS): 00:00:00:35
Reference: Memory used: 3007.02 MB
Current: Memory used: 2977.35 MB

superminimal Passed Core Comparison ✅

Original model has 13 species.
Test model has 13 species. ✅
Original model has 21 reactions.
Test model has 21 reactions. ✅

superminimal Passed Edge Comparison ✅

Original model has 18 species.
Test model has 18 species. ✅
Original model has 28 reactions.
Test model has 28 reactions. ✅

Regression test RMS_constantVIdealGasReactor_superminimal:

Reference: Execution time (DD:HH:MM:SS): 00:00:02:22
Current: Execution time (DD:HH:MM:SS): 00:00:02:23
Reference: Memory used: 3464.70 MB
Current: Memory used: 3440.52 MB

RMS_constantVIdealGasReactor_superminimal Passed Core Comparison ✅

Original model has 13 species.
Test model has 13 species. ✅
Original model has 19 reactions.
Test model has 19 reactions. ✅

RMS_constantVIdealGasReactor_superminimal Passed Edge Comparison ✅

Original model has 13 species.
Test model has 13 species. ✅
Original model has 19 reactions.
Test model has 19 reactions. ✅

Observables Test Case: RMS_constantVIdealGasReactor_superminimal Comparison

✅ All Observables varied by less than 0.100 on average between old model and new model in all conditions!

RMS_constantVIdealGasReactor_superminimal Passed Observable Testing ✅

Regression test RMS_CSTR_liquid_oxidation:

Reference: Execution time (DD:HH:MM:SS): 00:00:05:53
Current: Execution time (DD:HH:MM:SS): 00:00:05:55
Reference: Memory used: 3377.87 MB
Current: Memory used: 3371.85 MB

RMS_CSTR_liquid_oxidation Passed Core Comparison ✅

Original model has 37 species.
Test model has 37 species. ✅
Original model has 232 reactions.
Test model has 232 reactions. ✅

RMS_CSTR_liquid_oxidation Passed Edge Comparison ✅

Original model has 206 species.
Test model has 206 species. ✅
Original model has 1508 reactions.
Test model has 1508 reactions. ✅

Observables Test Case: RMS_CSTR_liquid_oxidation Comparison

✅ All Observables varied by less than 0.100 on average between old model and new model in all conditions!

RMS_CSTR_liquid_oxidation Passed Observable Testing ✅

Regression test fragment:

Reference: Execution time (DD:HH:MM:SS): 00:00:00:43
Current: Execution time (DD:HH:MM:SS): 00:00:00:40
Reference: Memory used: 2706.92 MB
Current: Memory used: 2700.21 MB

fragment Passed Core Comparison ✅

Original model has 10 species.
Test model has 10 species. ✅
Original model has 2 reactions.
Test model has 2 reactions. ✅

fragment Passed Edge Comparison ✅

Original model has 33 species.
Test model has 33 species. ✅
Original model has 47 reactions.
Test model has 47 reactions. ✅

Observables Test Case: fragment Comparison

✅ All Observables varied by less than 0.100 on average between old model and new model in all conditions!

fragment Passed Observable Testing ✅

Regression test RMS_constantVIdealGasReactor_fragment:

Reference: Execution time (DD:HH:MM:SS): 00:00:03:04
Current: Execution time (DD:HH:MM:SS): 00:00:03:02
Reference: Memory used: 3584.24 MB
Current: Memory used: 3614.52 MB

RMS_constantVIdealGasReactor_fragment Passed Core Comparison ✅

Original model has 10 species.
Test model has 10 species. ✅
Original model has 2 reactions.
Test model has 2 reactions. ✅

RMS_constantVIdealGasReactor_fragment Passed Edge Comparison ✅

Original model has 27 species.
Test model has 27 species. ✅
Original model has 24 reactions.
Test model has 24 reactions. ✅

Observables Test Case: RMS_constantVIdealGasReactor_fragment Comparison

✅ All Observables varied by less than 0.100 on average between old model and new model in all conditions!

RMS_constantVIdealGasReactor_fragment Passed Observable Testing ✅

beep boop this comment was written by a bot 🤖

Copy link

github-actions bot commented Nov 1, 2024

This pull request is being automatically marked as stale because it has not received any interaction in the last 90 days. Please leave a comment if this is still a relevant pull request, otherwise it will automatically be closed in 30 days.

@github-actions github-actions bot added the stale stale issue/PR as determined by actions bot label Nov 1, 2024
@sevyharris sevyharris removed the stale stale issue/PR as determined by actions bot label Nov 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants