Skip to content

Added a PFR reactor to the flux diagram generator - #162

Merged
alongd merged 4 commits into
mainfrom
pfr_flux
Aug 14, 2026
Merged

Added a PFR reactor to the flux diagram generator#162
alongd merged 4 commits into
mainfrom
pfr_flux

Conversation

@alongd

@alongd alongd commented Apr 14, 2025

Copy link
Copy Markdown
Member

No description provided.

@alongd

alongd commented Aug 14, 2026

Copy link
Copy Markdown
Member Author

Rebased onto main (673b866); the three original commits are preserved. Conflicts were all in t3/utils/flux.py, where main had since rewritten the typing (PEP 585/604) and added the molecule-image / logger parameters — the PFR parameters are merged in alongside those, and the new set_pfr / run_pfr now use list / dict / tuple / | None annotations.

Two things surfaced while verifying the rebase, fixed in a fourth commit:

  • PFR pressure was off by 1e5. set_pfr and run_pfr did gas.TPX = T, P, ..., but P travels in bar throughout this module — set_jsr and run_batch_p both convert with P * 1e5. A PFR requested at 1 bar was simulated at 1 Pa.
  • ct.PressureController(master=...) no longer exists. It was renamed primary= in Cantera 3.x, and environment.yml pins cantera >=3.2.0, so run_pfr raised TypeError on its first call. The PFR path could not have run against the pinned Cantera.

With both fixed, a PFR at P=1 now returns 1.0000e+05 Pa, matching the JSR path on the same input. tests/test_utils/test_flux.py is 26 passed, same as main. The three create_digraph tests main added needed reactor_type='JSR' added at the call site, since this PR makes reactor_type a required parameter — folded into the first commit.

⚠️ The surface_names path in run_pfr is untested. No model in tests/data/models carries a surface phase, so surface(surface_names.index(surface.name)).thermo was never exercised; it's left exactly as authored. Given that the gas-phase path was written against a pre-3.x Cantera, that line is worth a look before this merges.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds Plug Flow Reactor (PFR) support to T3’s flux diagram generation utilities by introducing a PFR simulation path and threading reactor-type metadata through diagram generation so outputs are labeled appropriately.

Changes:

  • Added reactor_type, surface_names, and n_cells plumbing into generate_flux() / simulation profile generation, including a new run_pfr() / set_pfr() implementation.
  • Updated flux diagram generation APIs (generate_flux_diagrams(), create_digraph()) to accept reactor_type and include it in diagram labels.
  • Updated unit tests to pass reactor_type into create_digraph() calls.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 5 comments.

File Description
tests/test_utils/test_flux.py Updates test invocations to match the updated create_digraph() signature.
t3/utils/flux.py Adds PFR simulation support and threads reactor_type through flux diagram generation and labeling.
Suppressed comments (2)

t3/utils/flux.py:171

  • Same issue as in generate_flux: n_cells is annotated as optional, but the PFR path requires a positive integer. The signature should reflect the actual contract.
                                 n_cells: int | None = 100,

t3/utils/flux.py:477

  • run_pfr() divides by tau to compute flow_rate; if any requested residence time is 0 or negative, this will crash (or yield meaningless results). Add input validation similar to run_batch_p().
    profiles = dict()
    stoichiometry = get_rxn_stoichiometry(gas)
    for tau in times:

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread t3/utils/flux.py Outdated
Comment thread t3/utils/flux.py Outdated
Comment thread t3/utils/flux.py
Comment thread t3/utils/flux.py
Comment on lines +509 to +513
if surface_names:
for surface in surfaces:
surface_reactions = surface.reactions()
surface_phase = surface(surface_names.index(surface.name)).thermo
surface_rops = surface_phase.net_rates_of_progress

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Confirmed, and the second half of your comment is the more serious part — deliberately left as-authored for now rather than fixed blind. set_pfr builds its own ct.Interface per cell and attaches those to the reactors, so the surfaces list run_pfr reads ROPs from was never attached to anything and never advanced: even with the call fixed, those ROPs would come from an unintegrated phase still at the inlet state. No model in tests/data/models carries a surface phase, so any rewrite here would be untestable in this repo. Flagging rather than guessing; this wants either a surface-bearing test fixture or set_pfr returning the interfaces it created.

Comment thread t3/utils/flux.py
@codecov-commenter

codecov-commenter commented Aug 14, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 72.76%. Comparing base (673b866) to head (5949ba1).

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #162      +/-   ##
==========================================
- Coverage   72.77%   72.76%   -0.01%     
==========================================
  Files          37       37              
  Lines        5932     6004      +72     
  Branches     1289     1307      +18     
==========================================
+ Hits         4317     4369      +52     
- Misses       1170     1187      +17     
- Partials      445      448       +3     
Flag Coverage Δ
unittests 72.76% <ø> (-0.01%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

alongd added 4 commits August 14, 2026 16:36
Two defects that kept the PFR path from producing correct results:

- `set_pfr` and `run_pfr` assigned `gas.TPX = T, P, ...`, but `P` arrives in
  bar everywhere in this module -- `set_jsr` and `run_batch_p` both convert
  with `P * 1e5`. A PFR requested at 1 bar was simulated at 1 Pa.

- `set_pfr` passed `master=` to `ct.PressureController`, renamed `primary=`
  in Cantera 3.x. Since the repo pins `cantera >=3.2.0`, `run_pfr` raised
  TypeError on its first call and the PFR path never ran.

The `surface_names` path remains untested; no test model carries a surface
phase.
@alongd
alongd merged commit 0f0737c into main Aug 14, 2026
4 checks passed
@alongd
alongd deleted the pfr_flux branch August 14, 2026 14:42
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