Add mass_balance and energy_balance utility functions - #44
Draft
FrancescaWatson with Copilot wants to merge 1 commit into
Draft
FrancescaWatson with Copilot wants to merge 1 commit into
FrancescaWatson with Copilot wants to merge 1 commit into
Conversation
Copilot created this pull request from a session on behalf of
FrancescaWatson
July 9, 2026 14:17
View session
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds two post-processing utility functions to check conservation law closure over a specified simulation period (default: full simulation).
New functions
mass_balance(states, timesteps, model, forces; state0, component, t_start, t_end)((n_in − n_out) − Δn_col) / |Δn_col|— molar conservation residual for a given component (default: CO₂).energy_balance(states, timesteps, model, forces; state0, t_start, t_end)(Q_in + Q_gen − (Q_out + ΔE_solid + ΔE_fluid + ΔE_ads)) / |Q_out + ΔE_solid + ΔE_fluid + ΔE_ads|— thermal energy conservation residual including adsorption heat generation and wall exchange.Implementation notes
AdsorptionBC,PressurisationBC,BlowdownBC,EvacuationBC, matching the sign conventions in each BC'sapply_forces_to_equation!.ΔH) fromDualSiteLangmuiris applied asQ_gen = −ΔH · Δq · V_solid(positive for exothermic CO₂ adsorption).Q_in/Q_outbased on sign ofh_in · (T_col − T_wall).t_start/t_endfor cycle-level diagnostics.Usage
Known issue in tests
The test file calls
simulate_processwithoutput_substates=true, which causes Jutul'sexpand_to_ministepsto emit more state/timestep entries than force entries, triggering a bounds error in_get_force_at_step. Tests should be run withoutoutput_substates=true(or with explicitoutput_substates=false); thesrc/balance.jlimplementation itself is unaffected.