-
Notifications
You must be signed in to change notification settings - Fork 50
add smoke test checking error measures for the Shima_et_al_2009 box example. Closes #327 #1191
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
Merged
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
b97d064
add smoke test checking error measures for the Shima_et_al_2009 box e…
slayoo ef160c5
make pylint happier
slayoo 12886b6
Merge branch 'main' into new_shima_2009_smoke_test
AgnieszkaZaba fa45e3f
update bibliography
AgnieszkaZaba adb8687
remove plot from Berry spectrumplotter as it is in parent class
AgnieszkaZaba 7e1a0d5
Merge branch 'main' into new_shima_2009_smoke_test
AgnieszkaZaba a2196ad
change parameterisation and hope it is right
AgnieszkaZaba 7052369
add plot function to Berry (deleted one) with changed signature
AgnieszkaZaba 18e0e32
change the list of considered particles number to exemplify reduced e…
AgnieszkaZaba 048324d
Merge branch 'main' into new_shima_2009_smoke_test
AgnieszkaZaba a3f476b
bump matplotlib CI requirement
AgnieszkaZaba 9018115
del axes before clf
AgnieszkaZaba 955e1ac
update setup
AgnieszkaZaba 7ef56b3
use previous matplotlib setup; add workaround matplotlib bug
AgnieszkaZaba File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
85 changes: 85 additions & 0 deletions
85
tests/smoke_tests/box/shima_et_al_2009/test_convergence.py
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,85 @@ | ||
| """ | ||
| Tests checking if, for the example case from Fig 4 in | ||
| [Shima et al. 2009](https://doi.org/10.1002/qj.441), | ||
| the simulations converge towards analytic solution. | ||
| """ | ||
|
|
||
| from inspect import signature | ||
| from itertools import islice | ||
|
|
||
| import pytest | ||
| from matplotlib import pyplot | ||
| from PySDM_examples.Shima_et_al_2009.example import run | ||
| from PySDM_examples.Shima_et_al_2009.settings import Settings | ||
| from PySDM_examples.Shima_et_al_2009.spectrum_plotter import SpectrumPlotter | ||
|
|
||
| from PySDM.physics import si | ||
|
|
||
| COLORS = ("red", "green", "blue") | ||
|
|
||
|
|
||
| class TestConvergence: # pylint: disable=missing-class-docstring | ||
| @staticmethod | ||
| @pytest.mark.parametrize( | ||
| "adaptive, dt", | ||
| ( | ||
| pytest.param(False, 100 * si.s, marks=pytest.mark.xfail(strict=True)), | ||
| (True, 100 * si.s), | ||
| pytest.param(False, 50 * si.s, marks=pytest.mark.xfail(strict=True)), | ||
| (True, 50 * si.s), | ||
| ), | ||
| ) | ||
| def test_convergence_with_sd_count(dt, adaptive, plot=False): | ||
| """check if increasing the number of super particles indeed | ||
| reduces the error of the simulation (vs. analytic solution)""" | ||
| # arrange | ||
| settings = Settings(steps=[3600]) | ||
| settings.adaptive = adaptive | ||
| plotter = SpectrumPlotter(settings) | ||
| errors = {} | ||
|
|
||
| # act | ||
| for i, ln2_nsd in enumerate((11, 15, 19)): | ||
| settings.dt = dt | ||
| settings.n_sd = 2**ln2_nsd | ||
| values, _ = run(settings) | ||
|
|
||
| title = ( | ||
| "" | ||
| if i != 0 | ||
| else ( | ||
| f"{settings.dt=} settings.times={settings.steps} {settings.adaptive=}" | ||
| ) | ||
| ) | ||
| errors[ln2_nsd] = plotter.plot( | ||
| **dict( | ||
| islice( | ||
| { # supporting older versions of PySDM-examples | ||
| "t": settings.steps[-1], | ||
| "spectrum": values[tuple(values.keys())[-1]], | ||
| "label": f"{ln2_nsd=}", | ||
| "color": COLORS[i], | ||
| "title": title, | ||
| "add_error_to_label": True, | ||
| }.items(), | ||
| len(signature(plotter.plot).parameters), | ||
| ) | ||
| ) | ||
| ) | ||
|
|
||
| # plot | ||
| if plot: | ||
| plotter.show() | ||
| else: | ||
| # https://github.com/matplotlib/matplotlib/issues/9970 | ||
| pyplot.xscale("linear") | ||
| pyplot.clf() | ||
|
|
||
| # assert monotonicity (i.e., the larger the sd count, the smaller the error) | ||
| assert tuple(errors.keys()) == tuple(sorted(errors.keys())) | ||
| assert tuple(errors.values()) == tuple(reversed(sorted(errors.values()))) | ||
|
|
||
| @staticmethod | ||
| def test_convergence_with_timestep(): | ||
| """ditto for timestep""" | ||
| pytest.skip("# TODO #1189") | ||
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.