Skip to content

simulate: convert Cantera adapter conditions to SI - #230

Draft
alongd wants to merge 1 commit into
mainfrom
i102-adapter-units
Draft

alongd wants to merge 1 commit into
mainfrom
i102-adapter-units

Conversation

@alongd

@alongd alongd commented Nov 28, 2026

Copy link
Copy Markdown
Member

Summary

CanteraBase.set_up passed pressure in bar and the termination time in its declared unit to a
shim Quantity that stores units without applying them — so every CanteraBase-derived adapter
ran at 1 Pa for a 1 bar input, and integrated for the wrong duration unless the unit was
already 's'.

 CanteraBase.set_up
-  reactor pressure  <- P (bar)        -> Quantity stores "bar", Cantera reads 1 Pa
+  reactor pressure  <- P * 1e5 (Pa)
-  termination time  <- t (as declared) -> Quantity stores the unit, Cantera reads the number
+  termination time  <- convert_termination_time_to_seconds(t)

 rmg_shim.Quantity
+  refuses any unit other than K, Pa or s
 schema micro-s normalisation
-  value * 1000        # 1 micro-s became 1 s
+  value / 1000

Evidence

Before: two JSR tests and one PFR test passed because nothing reacted at 1 Pa. A test that
passes only because the physics was switched off is the failure mode here, not the arithmetic.

After: the JSR tests assert the pressure-controller law and compare the steady state, so they
fail if the pressure is wrong. The PFR chain-vs-Lagrangian test is a strict xfail with its reason
named: the chain method feeds every cell the original inlet, which is a separate defect and is
tracked on its own.

tests/test_simulate/test_cantera_base.py   +76   (new: unit conversion, controller law)
tests/test_utils/test_rmg_shim_quantity.py +25   (new: the shim refuses K/Pa/s violations)
tests/test_common.py                       +36   (convert_termination_time_to_seconds, incl. the
                                                  ValueError naming the unknown unit)

Merge Danger

Door: two-way.

Blast Radius: every Cantera simulation result.

This changes the conditions every CanteraBase-derived adapter actually simulates at, by five
orders of magnitude in pressure. Results produced before it are not comparable with results after
it — that is the point of the fix, and it is also the reason nothing that cites a pre-fix Cantera
number should be read as still valid.

CanteraBase.set_up handed the reactor pressure in bar and the
termination time in its declared unit to the shim Quantity, which
stores units without applying them. Cantera therefore ran every
CanteraBase-derived adapter at 1 Pa for a 1 bar input, and integrated
for the wrong duration unless the unit was 's'.

set_up now converts P to Pa and the termination time to seconds via
convert_termination_time_to_seconds. The shim Quantity refuses any
unit other than K, Pa or s, and the converter raises a ValueError
naming an unknown unit and the supported set.

Also fix the schema's micro-s normalisation, which multiplied by 1000
instead of dividing, turning 1 micro-s into 1 s.

Two JSR tests and one PFR test passed only because nothing reacted at
1 Pa. The JSR tests now assert the pressure-controller law and compare
the steady state; the PFR chain-vs-Lagrangian test is a strict xfail,
since the chain method feeds every cell the original inlet.
Comment thread tests/test_common.py
common.convert_termination_time_to_seconds((1.0, 'fortnights'))
message = str(error.value)
assert 'fortnights' in message
for unit in TerminationTimeEnum:

This branch has not been deployed

No deployments
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.

2 participants