Skip to content

Particle balance constraint#4139

Open
chris-ashe wants to merge 42 commits into
mainfrom
particle_balance_constraint
Open

Particle balance constraint#4139
chris-ashe wants to merge 42 commits into
mainfrom
particle_balance_constraint

Conversation

@chris-ashe

@chris-ashe chris-ashe commented Mar 23, 2026

Copy link
Copy Markdown
Collaborator

This pull request introduces a comprehensive plasma fuelling model to the codebase, including new physical variables, input parameters, constraints, and documentation. The main focus is to enable detailed particle balance and burnup fraction calculations for deuterium, tritium, and helium-3 in the plasma, and to ensure consistency through new constraint equations. Several new variables and iteration parameters are added to support these models, and the documentation is expanded to explain the physical basis and equations.

Key changes:

1. Plasma fuelling and particle balance model:

  • Added a detailed plasma fuelling model and particle balance equations for deuterium, tritium, helium-3, and alpha particles to the documentation (plasma_fuelling.md). This includes explanations of fuelling efficiency, recycling, and burnup fractions.
  • Added new physics variables in PhysicsData for burnup fractions and detailed fusion reaction rates, enabling more granular tracking of fuel species and reactions. [1] [2]

2. New input and iteration variables:

  • Introduced new input parameters in input.py for fuelling efficiency, injected fuel rates, and fuelling fractions for each species.
  • Added corresponding iteration variables for these new inputs, allowing them to be varied during optimization and scans.

3. Particle balance and consistency constraints:

  • Implemented new constraint equations (93–97) in constraints.py to enforce particle balance for tritium, deuterium, helium-3, alpha particles, and to ensure fuelling fractions sum to unity. These constraints help maintain physical consistency in the plasma model.
  • Updated numerics to include these new constraints, increasing the total number of constraints and variables. [1] [2] [3]

4. Documentation and navigation updates:

  • Added the new plasma fuelling documentation page to the navigation in mkdocs.yml, making the new model easily accessible in the documentation site.

5. Miscellaneous improvements:

  • Added Avogadro's number to the constants module for use in physical calculations.
  • Improved output reporting for constraint errors in scan.py.

These changes collectively provide a robust framework for modeling plasma fuelling, tracking individual fuel species, and ensuring physical consistency in fusion plasma simulations.

Checklist

I confirm that I have completed the following checks:

  • My changes follow the PROCESS style guide
  • I have justified any large differences in the regression tests caused by this pull request in the comments.
  • I have added new tests where appropriate for the changes I have made.
  • If I have had to change any existing unit or integration tests, I have justified this change in the pull request comments.
  • If I have made documentation changes, I have checked they render correctly.
  • I have added documentation for my change, if appropriate.

@chris-ashe chris-ashe added Physics Relating to the physics models Plotting labels Mar 23, 2026
@chris-ashe chris-ashe force-pushed the particle_balance_constraint branch 2 times, most recently from 1397135 to 7687c7b Compare March 31, 2026 09:25
@chris-ashe chris-ashe marked this pull request as ready for review March 31, 2026 09:27
@chris-ashe chris-ashe requested a review from a team as a code owner March 31, 2026 09:28
@chris-ashe chris-ashe requested a review from jonmaddock March 31, 2026 09:28
@chris-ashe

Copy link
Copy Markdown
Collaborator Author

Opening this up now just to get the ball rolling with the review. @jonmaddock a discussion should be had about how we implement this into the regression tests, e.g is the 4 balance constraints always on as default

@jonmaddock

jonmaddock commented Apr 20, 2026

Copy link
Copy Markdown
Contributor

As this is contingent on the wider "solution mode" work going in (which I am currently working on), I am converting this to a draft until that is merged.

Edit: I'm wrong about this: this can go in without waiting for the above work.

@jonmaddock jonmaddock marked this pull request as draft April 20, 2026 15:11
@chris-ashe chris-ashe force-pushed the particle_balance_constraint branch 3 times, most recently from 1dd8c7f to 49236ad Compare June 2, 2026 09:39
@chris-ashe chris-ashe force-pushed the particle_balance_constraint branch 2 times, most recently from 40ad502 to b37ac1f Compare June 17, 2026 12:58
@codecov-commenter

codecov-commenter commented Jun 17, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 32.65993% with 200 lines in your changes missing coverage. Please review.
✅ Project coverage is 48.81%. Comparing base (d84e9dd) to head (3e5c5fd).
⚠️ Report is 18 commits behind head on main.

Files with missing lines Patch % Lines
process/core/io/plot/summary.py 4.13% 139 Missing ⚠️
process/models/physics/fuelling.py 43.54% 35 Missing ⚠️
process/models/physics/physics.py 5.55% 17 Missing ⚠️
process/core/solver/constraints.py 82.60% 4 Missing ⚠️
process/models/physics/fusion_reactions.py 0.00% 3 Missing ⚠️
process/core/scan.py 0.00% 1 Missing ⚠️
process/models/stellarator/stellarator.py 0.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #4139      +/-   ##
==========================================
- Coverage   48.86%   48.81%   -0.06%     
==========================================
  Files         151      152       +1     
  Lines       29461    29671     +210     
==========================================
+ Hits        14397    14484      +87     
- Misses      15064    15187     +123     

☔ 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.

@chris-ashe chris-ashe force-pushed the particle_balance_constraint branch 2 times, most recently from 0d49bab to 43e8f8c Compare June 17, 2026 13:15
@chris-ashe chris-ashe added Variable rename Input/Output Files Issues related to the input and output data files labels Jun 17, 2026
@chris-ashe chris-ashe marked this pull request as ready for review June 17, 2026 14:50
@chris-ashe chris-ashe requested a review from j-a-foster June 17, 2026 15:02
@chris-ashe chris-ashe force-pushed the particle_balance_constraint branch 2 times, most recently from 90086ef to 37c5d94 Compare June 17, 2026 15:36
… rate parameters, and update plotting functions for alpha particle flow rate and fusion DT rate.
…ple files and update related calculations and tests
…iles and update related calculations and tests
…ated plotting functions for tritium, deuterium, and alpha particle flow rates
…uel burnup fraction computation across models
…ing class and update plotting function calls for consistency
…uelling_required' and update references to 'molflow_plasma_fuelling_vv_injected' across models and tests
…ficiency and recycling coefficient, and introduce METIS Alpha Confinement model
… for tritium, deuterium, helium-3, and alpha particle balances
…clarify recycling coefficient, and introduce fuel burnup fraction equations
@chris-ashe chris-ashe force-pushed the particle_balance_constraint branch from 37c5d94 to 3e5c5fd Compare June 17, 2026 15:36

@jonmaddock jonmaddock left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Please fixup these commits to reduce churn and provide more descriptive commit messages: it's a bit hard to review at the moment.

Comment thread process/data_structure/numerics.py Outdated
return self._description_


ipnvars: int = 180

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I don't think this belongs in this PR: it should be separate.

Comment thread process/core/solver/constraints.py Outdated


@ConstraintManager.register_constraint(93, "particles/s", "=")
def constraint_equation_93():

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This appears to be a copy of the previous constraint.

Comment thread process/core/input.py
),
"molflow_plasma_fuelling_vv_injected": InputVariable(
data_structure.physics_variables, float, range=(0.0, 1e24)
),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Please fixup into previous commit where these were created.

Comment thread process/core/solver/constraints.py Outdated

@ConstraintManager.register_constraint(93, "particles/s", "=")
def constraint_equation_93():
def constraint_equation_93(constraint_registration):

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Please fixup the original commit where this constraint was added with this commit to reduce churn for the reviewer.

Comment thread process/core/solver/constraints.py Outdated
)
)

return leq(numerator, 1e10, constraint_registration)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Why 1e10?

Comment thread process/core/solver/constraints.py Outdated


@ConstraintManager.register_constraint(94, "particles/s", "<=")
def constraint_equation_94(constraint_registration):

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Please re-write the commit message to describe why this constraint is being added: "update" is not descriptive for the reviewer. Three constraints have been modified here in a single commit.

Comment thread process/core/solver/constraints.py Outdated
)

return leq(numerator, 1e10, constraint_registration)
return eq(numerator / 1e20, 1e-8, constraint_registration)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

There's a bit too much churn here: please fixup commits and write descriptive commit messages to help me review!

/ (1 - data_structure.physics_variables.f_plasma_particles_lcfs_recycled)
)
)
denominator = (

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Can't understand what the change is as commit message not descriptive: why are you making this change?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Input/Output Files Issues related to the input and output data files Physics Relating to the physics models Plotting Variable rename

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants