-
Notifications
You must be signed in to change notification settings - Fork 35
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
Test for DiscontinuousTestODE #368
Merged
brownbaerchen
merged 4 commits into
Parallel-in-Time:master
from
lisawim:testing_disc_test_ode
Oct 26, 2023
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
2ec681c
Test for DiscontinuousTestODE + added stop_at_nan as attribute
lisawim 1e9c3d7
New line at the end of file for black
lisawim 03f11a0
Added WorkCounter for Newton
lisawim 3cda182
Test if absolute value of h is less than some threshold
lisawim 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 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 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,82 @@ | ||
import pytest | ||
|
||
|
||
@pytest.mark.base | ||
def test_event(): | ||
""" | ||
Test if the event occurs at correct time. | ||
""" | ||
import numpy as np | ||
from pySDC.implementations.problem_classes.DiscontinuousTestODE import DiscontinuousTestODE | ||
|
||
problem_params = { | ||
'newton_tol': 1e-13, | ||
} | ||
|
||
DODE = DiscontinuousTestODE(**problem_params) | ||
|
||
u_event = DODE.u_exact(DODE.t_switch_exact) | ||
h = u_event[0] - 5 | ||
|
||
assert abs(h) < 1e-15, 'Value of state function at exact event time is not zero!' | ||
|
||
t0 = 1.6 | ||
dt = 1e-2 | ||
u0 = DODE.u_exact(t0) | ||
|
||
args = { | ||
'rhs': u0, | ||
'dt': dt, | ||
'u0': u0, | ||
't': t0, | ||
} | ||
|
||
sol = DODE.solve_system(**args) | ||
assert np.isclose( | ||
sol[0], DODE.u_exact(t0 + dt)[0], atol=2e-3 | ||
), 'Solution after one time step is too far away from exact value!' | ||
|
||
|
||
@pytest.mark.base | ||
def test_capture_errors_and_warnings(caplog): | ||
r""" | ||
Test that checks if the errors in the problem classes are raised. | ||
""" | ||
import numpy as np | ||
from pySDC.core.Errors import ProblemError | ||
from pySDC.implementations.problem_classes.DiscontinuousTestODE import DiscontinuousTestODE | ||
|
||
problem_params = { | ||
'newton_tol': 1e-13, | ||
'stop_at_nan': True, | ||
} | ||
|
||
DODE = DiscontinuousTestODE(**problem_params) | ||
|
||
t0 = 1.0 | ||
dt = 1e-3 | ||
u0 = DODE.u_exact(t0) | ||
|
||
args = { | ||
'rhs': u0, | ||
'dt': np.nan, | ||
'u0': u0, | ||
't': t0, | ||
} | ||
|
||
# test of ProblemError is raised | ||
with pytest.raises(ProblemError): | ||
DODE.solve_system(**args) | ||
|
||
# test if warnings are raised when nan values arises | ||
DODE.stop_at_nan = False | ||
DODE.solve_system(**args) | ||
assert 'Newton got nan after 100 iterations...' in caplog.text | ||
assert 'Newton did not converge after 100 iterations, error is nan' in caplog.text | ||
|
||
# test if warning is raised when local error is tried to computed | ||
u1 = DODE.u_exact(t0 + dt, u_init=u0, t_init=t0) | ||
assert ( | ||
'DiscontinuousTestODE uses an analytic exact solution from t=0. If you try to compute the local error, you will get the global error instead!' | ||
in caplog.text | ||
) |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why don't you use
np.allclose
and test all of the values instead of just the first one?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Your are right, but in this case, the solution consists of only one value.