Skip to content

Commit

Permalink
examples: add stability tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mloubout committed Jun 10, 2020
1 parent 83a1da7 commit be78b32
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 9 deletions.
8 changes: 6 additions & 2 deletions examples/seismic/acoustic/acoustic_example.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import numpy as np
import pytest

from devito.logger import info
from devito import Constant, Function, smooth
Expand Down Expand Up @@ -62,8 +63,11 @@ def run(shape=(50, 50, 50), spacing=(20.0, 20.0, 20.0), tn=1000.0,
return summary.gflopss, summary.oi, summary.timings, [rec, u.data]


def test_isoacoustic_stability():
rec, _, _ = run(shape=(11, 11), tn=20000.0, nbl=0)
@pytest.mark.parametrize('ndim', [1, 2, 3])
def test_isoacoustic_stability(ndim):
shape = tuple([11]*ndim)
spacing = tuple([20]*ndim)
_, _, _, [rec, _] = run(shape=shape, spacing=spacing, tn=20000.0, nbl=0)
norm = lambda x: np.linalg.norm(x.data.reshape(-1))
assert np.isfinite(norm(rec))

Expand Down
8 changes: 6 additions & 2 deletions examples/seismic/elastic/elastic_example.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import numpy as np
import pytest

from devito.logger import info
from examples.seismic.elastic import ElasticWaveSolver
Expand Down Expand Up @@ -40,8 +41,11 @@ def test_elastic():
assert np.isclose(norm(rec2), 0.627606, atol=1e-3, rtol=0)


def test_elastic_stability():
_, _, _, [rec1, rec2, v, tau] = run(shape=(11, 11), tn=20000.0, nbl=0)
@pytest.mark.parametrize('ndim', [1, 2, 3])
def test_elastic_stability(ndim):
shape = tuple([11]*ndim)
spacing = tuple([20]*ndim)
_, _, _, [rec1, rec2, v, tau] = run(shape=shape, spacing=spacing, tn=20000.0, nbl=0)
norm = lambda x: np.linalg.norm(x.data.reshape(-1))
assert np.isfinite(norm(rec1))

Expand Down
14 changes: 9 additions & 5 deletions examples/seismic/viscoelastic/viscoelastic_example.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import numpy as np
import pytest

from devito.logger import info
from examples.seismic.viscoelastic import ViscoelasticWaveSolver
Expand Down Expand Up @@ -37,12 +38,15 @@ def run(shape=(50, 50), spacing=(20.0, 20.0), tn=1000.0,
def test_viscoelastic():
_, _, _, [rec1, rec2, v, tau] = run()
norm = lambda x: np.linalg.norm(x.data.reshape(-1))
assert np.isclose(norm(rec1), 11.75186, atol=1e-3, rtol=0)
assert np.isclose(norm(rec2), 0.275607, atol=1e-3, rtol=0)
assert np.isclose(norm(rec1), 12.28040, atol=1e-3, rtol=0)
assert np.isclose(norm(rec2), 0.312461, atol=1e-3, rtol=0)


def test_viscoelastic_stability():
_, _, _, [rec1, rec2, v, tau] = run(shape=(11, 11), tn=20000.0, nbl=0)
@pytest.mark.parametrize('ndim', [1, 2, 3])
def test_viscoelastic_stability(ndim):
shape = tuple([11]*ndim)
spacing = tuple([20]*ndim)
_, _, _, [rec1, rec2, v, tau] = run(shape=shape, spacing=spacing, tn=20000.0, nbl=0)
norm = lambda x: np.linalg.norm(x.data.reshape(-1))
assert np.isfinite(norm(rec1))

Expand All @@ -55,7 +59,7 @@ def test_viscoelastic_stability():
ndim = args.ndim
shape = args.shape[:args.ndim]
spacing = tuple(ndim * [10.0])
tn = 750. if ndim < 3 else 1250.
tn = 750. if ndim < 3 else 7250.

run(shape=shape, spacing=spacing, nbl=args.nbl, tn=tn, opt=args.opt,
space_order=args.space_order, autotune=args.autotune, constant=args.constant)

0 comments on commit be78b32

Please sign in to comment.