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 11, 2020
1 parent a98b462 commit a92f081
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 13 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
4 changes: 1 addition & 3 deletions examples/seismic/model.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import numpy as np
from sympy import sin, Abs
from sympy import finite_diff_weights as fd_w

from sympy import sin, Abs, finite_diff_weights as fd_w

from devito import (Grid, SubDomain, Function, Constant,
SubDimension, Eq, Inc, Operator, div)
Expand Down
15 changes: 9 additions & 6 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 @@ -28,21 +29,23 @@ def run(shape=(50, 50), spacing=(20.0, 20.0), tn=1000.0,
info("Applying Forward")
# Define receiver geometry (spread across x, just below surface)
rec1, rec2, v, tau, summary = solver.forward(autotune=autotune)
from devito import norm
print(norm(rec1), norm(rec2), norm(v[0]))

return (summary.gflopss, summary.oi, summary.timings,
[rec1, rec2, v, tau])


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 Down

0 comments on commit a92f081

Please sign in to comment.