Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix upwind/downwind finite volume operators #3979

Merged
merged 29 commits into from
Apr 12, 2024
Merged

Conversation

brosaplanella
Copy link
Member

@brosaplanella brosaplanella commented Apr 10, 2024

Description

Fixed the issue with the upwind and downwind operators. I am now leveraging the add_ghost_nodes method, to which I had to do some minor changes.

Fixes #3526

Type of change

Please add a line in the relevant section of CHANGELOG.md to document the change (include PR #) - note reverse order of PR #s. If necessary, also add to the list of breaking changes.

  • New feature (non-breaking change which adds functionality)
  • Optimization (back-end change that speeds up the code)
  • Bug fix (non-breaking change which fixes an issue)

Key checklist:

  • No style issues: $ pre-commit run (or $ nox -s pre-commit) (see CONTRIBUTING.md for how to set this up to run automatically when committing locally, in just two lines of code)
  • All tests pass: $ python run-tests.py --all (or $ nox -s tests)
  • The documentation builds: $ python run-tests.py --doctest (or $ nox -s doctests)

You can run integration tests, unit tests, and doctests together at once, using $ python run-tests.py --quick (or $ nox -s quick).

Further checks:

  • Code is commented, particularly in hard-to-understand areas
  • Tests added that prove fix is effective or that feature works

Copy link

Check out this pull request on  ReviewNB

See visual diffs & provide feedback on Jupyter Notebooks.


Powered by ReviewNB

Copy link

codecov bot commented Apr 10, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 99.58%. Comparing base (4cf09f3) to head (d57c0d7).

❗ Current head d57c0d7 differs from pull request most recent head 08fd731. Consider uploading reports for the commit 08fd731 to get more accurate results

Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #3979      +/-   ##
===========================================
- Coverage    99.58%   99.58%   -0.01%     
===========================================
  Files          257      257              
  Lines        21254    21248       -6     
===========================================
- Hits         21166    21160       -6     
  Misses          88       88              

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

@brosaplanella brosaplanella marked this pull request as ready for review April 10, 2024 12:57
Copy link
Member

@valentinsulzer valentinsulzer left a comment

Choose a reason for hiding this comment

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

Thanks, looks good. Can you show plots of the upwinding example vs analytical solution before and after the fix?

Co-authored-by: Eric G. Kratz <kratman@users.noreply.github.com>
@brosaplanella
Copy link
Member Author

Before & after plots

$$ u_t + u_x = s, \quad 0 < x < 1$$

$$u(t,0) = b$$

$$u(0,x) = 0$$

Example 1

s = 1, b = 0

Before

After

Example 2

s = 0, b = 1

Before

After

@valentinsulzer
Copy link
Member

Thanks, that does look much better! Is the mismatch with the analytical solution because it's not a high-enough order scheme?

@brosaplanella
Copy link
Member Author

I think so, as refining the mesh gives a better result. I need to do some more reading on this, and potentially implement higher order methods, but that's a separate issue.

@brosaplanella brosaplanella merged commit d764a18 into develop Apr 12, 2024
37 of 38 checks passed
@brosaplanella brosaplanella deleted the issue-3526-upwind branch April 12, 2024 08:36
js1tr3 pushed a commit to js1tr3/PyBaMM that referenced this pull request Aug 12, 2024
* pybamm-team#3526 initialise branch

* pybamm-team#3256 add UpwindDivergence and DownwindDivergence

* work in progress for fixing upwind scheme

* pybamm-team#3526 add missing argument docstring

* pybamm-team#3526 fix upwind/downwind methods

* style: pre-commit fixes

* pybamm-team#3526 get finite volume notebook from develop

* 3526 add temporary test

* ruff

* style: pre-commit fixes

* pybamm-team#3526 remove unused variable

* pybamm-team#3526 clarify wording

* pybamm-team#3526 fix tests

* pybamm-team#3526 add to CHANGELOG

* pybamm-team#3526 update coverage

* pybamm-team#3526 add integration test

* style: pre-commit fixes

* pybamm-team#3526 remove example for debugging

* Remove print for debug

Co-authored-by: Eric G. Kratz <kratman@users.noreply.github.com>

* pybamm-team#3526 add second test

* pybamm-team#3526 generalised example but did not add test as was hard to know what to measure

* style: pre-commit fixes

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Eric G. Kratz <kratman@users.noreply.github.com>
Co-authored-by: Valentin Sulzer <valentinsulzer@hotmail.com>
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.

[Bug]: Upwind/downwind schemes are not working properly
3 participants