Add support for uniform grid sizing across subdomains (#720)#5253
Add support for uniform grid sizing across subdomains (#720)#5253agriyakhetarpal merged 9 commits intopybamm-team:developfrom
Conversation
159fbc8 to
5567fc0
Compare
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## develop #5253 +/- ##
========================================
Coverage 98.77% 98.77%
========================================
Files 321 321
Lines 27717 27727 +10
========================================
+ Hits 27377 27387 +10
Misses 340 340 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
valentinsulzer
left a comment
There was a problem hiding this comment.
Thanks for taking this on!
I think the current implementation is a little bit arbitrary - since it's hard to know which of the variables will be "found" first to be set as the sepcified domain.
Instead, I would recommend having a helper function:
- input: electrode thicknesses, grid size required
- output: var pts dict
PS feel free to ping me on slack for a re-review, I don't always check pybamm PR review requests
… grid size Includes a unit test validating proportional scaling across domains.
valentinsulzer
left a comment
There was a problem hiding this comment.
thanks, this is cleaner, but could we make grid_size the size of the mesh cell in metres (dx in your code) so it's very explicit
…ts_from_thicknesses, edited added test accordingly
|
@swastim01, it looks like the only thing remaining for this PR is for you to fix the two lines of missing coverage. It looks trivial to me. Would you like to try it? |
|
Thanks for pointing that out. I’ve added the extra tests to cover the uncovered lines, so the patch should now have full coverage. Happy to make any further adjustments if needed. |
agriyakhetarpal
left a comment
There was a problem hiding this comment.
Thanks, looks good, @swastim01! Let's merge this once tests pass.
* Don't be too strict with func_args longer than symbol.children * Add a test * Add support for uniform grid sizing across subdomains (#720) (#5253) Co-authored-by: Valentin Sulzer <valentinsulzer@hotmail.com> * Fix typo in Butler-Volmer equation docstring (#5279) * fix bug with bulk ocp lithiation (#5280) * doc: fix typo in concentration description in notebook (#5284) * Fix typo in concentration description in notebook * Add CHANGELOG.md entry for typo fix * Remove unneccesary changelog entry Co-authored-by: Agriya Khetarpal <74401230+agriyakhetarpal@users.noreply.github.com> --------- Co-authored-by: Agriya Khetarpal <74401230+agriyakhetarpal@users.noreply.github.com> * fix: instruct uv to install into system for CI (#5288) * Fix `InputParameter` serialisation (#5289) * fix `InputParameter` serialisation * Update CHANGELOG.md * Bugfix: inputs for `initial_conditions_from` scale evaluation (#5285) Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> * Add `silence_sundials_errors` solver option (#5290) * feat: add`silence_sundial_warnings` solver option * refactor: `silence_sundials_warnings` -> `silence_sundials_errors` * Update C-Rate current for changing nominal capacity (#5286) Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> * Update `IDAKLUSolver` error handling (#5291) * raise `SolverError` at failure to init sundials * Update simulation.py * Update idaklu_solver.py * reuse `pybammsolvers` error messages * Update test_idaklu_solver.py * bump `pybammsolvers` * Update CHANGELOG.md * Update CHANGELOG.md Update CHANGELOG.md * #5299 add inverse linear kinetics * #5299 check domain options for inverse kinetics * update notebook * #5299 brady comments * #5299 fix composite total kinetics --------- Co-authored-by: Agriya Khetarpal <74401230+agriyakhetarpal@users.noreply.github.com> Co-authored-by: Swasti Mishra <140950062+swastim01@users.noreply.github.com> Co-authored-by: Valentin Sulzer <valentinsulzer@hotmail.com> Co-authored-by: Chase Naples <cnaples79@gmail.com> Co-authored-by: Gregor Decristoforo <gregor.decristoforo@gmail.com> Co-authored-by: Pip Liggins <philippa.liggins@dtc.ox.ac.uk> Co-authored-by: Marc Berliner <34451391+MarcBerliner@users.noreply.github.com> Co-authored-by: Brady Planden <55357039+BradyPlanden@users.noreply.github.com> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
…#5308) * Don't be too strict with func_args longer than symbol.children * Add a test * Add support for uniform grid sizing across subdomains (#720) (#5253) Co-authored-by: Valentin Sulzer <valentinsulzer@hotmail.com> * Fix typo in Butler-Volmer equation docstring (#5279) * fix bug with bulk ocp lithiation (#5280) * doc: fix typo in concentration description in notebook (#5284) * Fix typo in concentration description in notebook * Add CHANGELOG.md entry for typo fix * Remove unneccesary changelog entry Co-authored-by: Agriya Khetarpal <74401230+agriyakhetarpal@users.noreply.github.com> --------- Co-authored-by: Agriya Khetarpal <74401230+agriyakhetarpal@users.noreply.github.com> * fix: instruct uv to install into system for CI (#5288) * Fix `InputParameter` serialisation (#5289) * fix `InputParameter` serialisation * Update CHANGELOG.md * Bugfix: inputs for `initial_conditions_from` scale evaluation (#5285) Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> * Add `silence_sundials_errors` solver option (#5290) * feat: add`silence_sundial_warnings` solver option * refactor: `silence_sundials_warnings` -> `silence_sundials_errors` * Update C-Rate current for changing nominal capacity (#5286) Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> * Update `IDAKLUSolver` error handling (#5291) * raise `SolverError` at failure to init sundials * Update simulation.py * Update idaklu_solver.py * reuse `pybammsolvers` error messages * Update test_idaklu_solver.py * bump `pybammsolvers` * Update CHANGELOG.md * Update CHANGELOG.md Update CHANGELOG.md * revive `SymbolReplacer` * add `VariableReplacementMap` * Create replace_symbols.rst * Update index.rst * cleanup * attach `parameter_values` to model for lazy post-processing * update `model.parameter_values` serialization * Update test_serialisation.py * Update test_parameter_values.py * add `observe` to solution for lazy evaluation of discretized symbols * Update test_solution.py * style * Update CHANGELOG.md * fix docstrings * docs * docs2 * Update replace_symbols.py * Update replace_symbols.py * remove `SymbolReplacer` * add slots to `SpatialMethod` for memory * add `SymbolProcessor` for `BaseModel` symbol eval * add `ModelSolutionObservability` enums for `BaseModel` * parameter_values: delay variable processing * fix stale symbol id: use `scale` and `reference` setters * discretisation delayed var processing, don't overwrite `model.variables` * pass `delayed_variable_processing` args through `process_model` * add `DUMMY_INPUT_PARAMETER_VALUE` const * Update __init__.py * Update index.rst * Delete replace_symbols.py * update symbol `scale` and `reference` setters * update variable hash * explicit `_variables_processed` base model attribute * use `get_processed_variable_or_event` getter * copy model in `Simulation` * disable observability with `output_variables` * delay variable processing in `Simulation` build * add `Solution.observe(symbol)` * update serialization * update examples * Update CONTRIBUTING.md * Update CHANGELOG.md * add observe tests * update serialization tests * Update test_base_model.py * update symbol processor getters * add model observability tests * update symbol and base variable id setters * Update symbol_processor.py * Update CHANGELOG.md * fix model serialization notebook * Update symbol_processor.py * remove unused serialisation methods * remove debug statement * update observe test comments * add observe test failure for new parameters * remove `_solution_observable` from custom model serialization * fix observe test error * set `DUMMY_INPUT_PARAMETER_VALUE = np.nan` to make errors more obvious --------- Co-authored-by: Agriya Khetarpal <74401230+agriyakhetarpal@users.noreply.github.com> Co-authored-by: Swasti Mishra <140950062+swastim01@users.noreply.github.com> Co-authored-by: Valentin Sulzer <valentinsulzer@hotmail.com> Co-authored-by: Chase Naples <cnaples79@gmail.com> Co-authored-by: Robert Timms <43040151+rtimms@users.noreply.github.com> Co-authored-by: Gregor Decristoforo <gregor.decristoforo@gmail.com> Co-authored-by: Pip Liggins <philippa.liggins@dtc.ox.ac.uk> Co-authored-by: Brady Planden <55357039+BradyPlanden@users.noreply.github.com> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
* Add error * Add test * Add to changelog, edit message * Don't be too strict with func_args longer than symbol.children * Add a test * Add support for uniform grid sizing across subdomains (#720) (#5253) Co-authored-by: Valentin Sulzer <valentinsulzer@hotmail.com> * Fix typo in Butler-Volmer equation docstring (#5279) * fix bug with bulk ocp lithiation (#5280) * doc: fix typo in concentration description in notebook (#5284) * Fix typo in concentration description in notebook * Add CHANGELOG.md entry for typo fix * Remove unneccesary changelog entry Co-authored-by: Agriya Khetarpal <74401230+agriyakhetarpal@users.noreply.github.com> --------- Co-authored-by: Agriya Khetarpal <74401230+agriyakhetarpal@users.noreply.github.com> * fix: instruct uv to install into system for CI (#5288) * Fix `InputParameter` serialisation (#5289) * fix `InputParameter` serialisation * Update CHANGELOG.md * Bugfix: inputs for `initial_conditions_from` scale evaluation (#5285) Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> --------- Co-authored-by: Agriya Khetarpal <74401230+agriyakhetarpal@users.noreply.github.com> Co-authored-by: Swasti Mishra <140950062+swastim01@users.noreply.github.com> Co-authored-by: Valentin Sulzer <valentinsulzer@hotmail.com> Co-authored-by: Chase Naples <cnaples79@gmail.com> Co-authored-by: Robert Timms <43040151+rtimms@users.noreply.github.com> Co-authored-by: Gregor Decristoforo <gregor.decristoforo@gmail.com> Co-authored-by: Marc Berliner <34451391+MarcBerliner@users.noreply.github.com> Co-authored-by: Brady Planden <55357039+BradyPlanden@users.noreply.github.com> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Martin Robinson <martinjrobins@gmail.com>
* Add error * Add test * Add to changelog, edit message * Don't be too strict with func_args longer than symbol.children * Add a test * Add support for uniform grid sizing across subdomains (pybamm-team#720) (pybamm-team#5253) Co-authored-by: Valentin Sulzer <valentinsulzer@hotmail.com> * Fix typo in Butler-Volmer equation docstring (pybamm-team#5279) * fix bug with bulk ocp lithiation (pybamm-team#5280) * doc: fix typo in concentration description in notebook (pybamm-team#5284) * Fix typo in concentration description in notebook * Add CHANGELOG.md entry for typo fix * Remove unneccesary changelog entry Co-authored-by: Agriya Khetarpal <74401230+agriyakhetarpal@users.noreply.github.com> --------- Co-authored-by: Agriya Khetarpal <74401230+agriyakhetarpal@users.noreply.github.com> * fix: instruct uv to install into system for CI (pybamm-team#5288) * Fix `InputParameter` serialisation (pybamm-team#5289) * fix `InputParameter` serialisation * Update CHANGELOG.md * Bugfix: inputs for `initial_conditions_from` scale evaluation (pybamm-team#5285) Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> --------- Co-authored-by: Agriya Khetarpal <74401230+agriyakhetarpal@users.noreply.github.com> Co-authored-by: Swasti Mishra <140950062+swastim01@users.noreply.github.com> Co-authored-by: Valentin Sulzer <valentinsulzer@hotmail.com> Co-authored-by: Chase Naples <cnaples79@gmail.com> Co-authored-by: Robert Timms <43040151+rtimms@users.noreply.github.com> Co-authored-by: Gregor Decristoforo <gregor.decristoforo@gmail.com> Co-authored-by: Marc Berliner <34451391+MarcBerliner@users.noreply.github.com> Co-authored-by: Brady Planden <55357039+BradyPlanden@users.noreply.github.com> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Martin Robinson <martinjrobins@gmail.com>
* Don't be too strict with func_args longer than symbol.children * Add a test * Add support for uniform grid sizing across subdomains (#720) (#5253) Co-authored-by: Valentin Sulzer <valentinsulzer@hotmail.com> * Fix typo in Butler-Volmer equation docstring (#5279) * fix bug with bulk ocp lithiation (#5280) * doc: fix typo in concentration description in notebook (#5284) * Fix typo in concentration description in notebook * Add CHANGELOG.md entry for typo fix * Remove unneccesary changelog entry Co-authored-by: Agriya Khetarpal <74401230+agriyakhetarpal@users.noreply.github.com> --------- Co-authored-by: Agriya Khetarpal <74401230+agriyakhetarpal@users.noreply.github.com> * fix: instruct uv to install into system for CI (#5288) * Fix `InputParameter` serialisation (#5289) * fix `InputParameter` serialisation * Update CHANGELOG.md * Bugfix: inputs for `initial_conditions_from` scale evaluation (#5285) Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> * Add `silence_sundials_errors` solver option (#5290) * feat: add`silence_sundial_warnings` solver option * refactor: `silence_sundials_warnings` -> `silence_sundials_errors` * Update C-Rate current for changing nominal capacity (#5286) Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> * Update `IDAKLUSolver` error handling (#5291) * raise `SolverError` at failure to init sundials * Update simulation.py * Update idaklu_solver.py * reuse `pybammsolvers` error messages * Update test_idaklu_solver.py * bump `pybammsolvers` * Update CHANGELOG.md * Update CHANGELOG.md Update CHANGELOG.md * implement heat equation export * Move DiffslExport to evaluate_python.py Co-authored-by: martinjrobins <martinjrobins@gmail.com> * add tests for DiffSLExport * rename DiffslExport to DiffSLExport * consider both options for heat flux output * move diffsl code to new file * add spm, spme and dfn tests, apply fixes for these * can export dfn and spme, but output is incorrect * new input syntax * move model export to integration, tidy up float formattting * update changelog * update to new delayed variable pipeline * minor fixes, remove dead code * turn off pydiffsol dep for mac intel * don't use inplace for integration tests * improve coverage * fix: reg functions * doc: minor comment to explain function fallback * refactor: eqn -> eqn_str * refactor: use ordered dict, remove unnecessary code * test: remove diffsl integration tests * test: add snapshot tests for unit diffsl export tests * test: reg_power and arcsinh2 * dep: remove pydiffsol --------- Co-authored-by: Agriya Khetarpal <74401230+agriyakhetarpal@users.noreply.github.com> Co-authored-by: Swasti Mishra <140950062+swastim01@users.noreply.github.com> Co-authored-by: Valentin Sulzer <valentinsulzer@hotmail.com> Co-authored-by: Chase Naples <cnaples79@gmail.com> Co-authored-by: Robert Timms <43040151+rtimms@users.noreply.github.com> Co-authored-by: Gregor Decristoforo <gregor.decristoforo@gmail.com> Co-authored-by: Pip Liggins <philippa.liggins@dtc.ox.ac.uk> Co-authored-by: Marc Berliner <34451391+MarcBerliner@users.noreply.github.com> Co-authored-by: Brady Planden <55357039+BradyPlanden@users.noreply.github.com> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Description
This PR adds functionality to enable uniform grid sizing across subdomains in the x-dimension, addressing issue #720.
Previously, grid points had to be specified manually for each subdomain, which could result in non-uniform spacing across domain interfaces.
With this update, the user can now define grid points in one subdomain, and the remaining subdomains automatically adopt grid sizes that ensure consistent spacing across the full geometry.
Key changes:
meshes.pyto automatically compute grid points for adjacent subdomains based on the uniformdx.This feature simplifies geometry setup and ensures smooth mesh transitions between subdomains for both 1D and higher-dimensional cases.
Fixes #720
Type of change
Important checks:
Please confirm the following before marking the PR as ready for review:
nox -s pre-commitnox -s testsnox -s doctestsOpen to feedback/suggestions. I was wondering if i should add a dedicated test (e.g.,
test_uniform_grid_sizing) intest_meshes.py, or prefer a new test file undertests/unit/test_meshes/?