Skip to content

Commit 29456c6

Browse files
committed
tests: Fix typo in interpolation and shore up tests
1 parent e5fb8ed commit 29456c6

File tree

3 files changed

+40
-22
lines changed

3 files changed

+40
-22
lines changed

devito/operations/interpolators.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,8 @@ def _augment_implicit_dims(self, implicit_dims, extras=None):
254254
for v in extras:
255255
try:
256256
if v.grid.is_SubDomain:
257-
edims.extend([d for d in v.grid.dims if d.root in self._gdims])
257+
edims.extend([d for d in v.grid.dimensions
258+
if d.is_Sub and d.root in self._gdims])
258259
except AttributeError:
259260
pass
260261

examples/userapi/07_functions_on_subdomains.ipynb

+23-21
Original file line numberDiff line numberDiff line change
@@ -2887,34 +2887,22 @@
28872887
"name": "stderr",
28882888
"output_type": "stream",
28892889
"text": [
2890-
"Operator `Kernel` ran in 0.68 s\n"
2890+
"Operator `Kernel` ran in 0.74 s\n"
28912891
]
2892-
},
2893-
{
2894-
"data": {
2895-
"text/plain": [
2896-
"PerformanceSummary([(PerfKey(name='section0', rank=None),\n",
2897-
" PerfEntry(time=0.198681000000007, gflopss=0.0, gpointss=0.0, oi=0.0, ops=0, itershapes=[])),\n",
2898-
" (PerfKey(name='section1', rank=None),\n",
2899-
" PerfEntry(time=0.19470700000000477, gflopss=0.0, gpointss=0.0, oi=0.0, ops=0, itershapes=[])),\n",
2900-
" (PerfKey(name='section2', rank=None),\n",
2901-
" PerfEntry(time=0.14005600000000007, gflopss=0.0, gpointss=0.0, oi=0.0, ops=0, itershapes=[])),\n",
2902-
" (PerfKey(name='section3', rank=None),\n",
2903-
" PerfEntry(time=0.1434430000000003, gflopss=0.0, gpointss=0.0, oi=0.0, ops=0, itershapes=[]))])"
2904-
]
2905-
},
2906-
"execution_count": 45,
2907-
"metadata": {},
2908-
"output_type": "execute_result"
29092892
}
29102893
],
29112894
"source": [
29122895
"#NBVAL_IGNORE_OUTPUT\n",
2913-
"op1 = Operator([eq_v,\n",
2896+
"from devito import switchconfig\n",
2897+
"\n",
2898+
"# Note: switchconfig(safe_math=True) is only required here to get consistent norms for testing purposes\n",
2899+
"# This is not required more widely and can be omitted in practical applications\n",
2900+
"with switchconfig(safe_math=True):\n",
2901+
" op1 = Operator([eq_v,\n",
29142902
" eq_p, eq_t,\n",
29152903
" eq_p_tr, eq_txx_tr, eq_tyy_tr]\n",
29162904
" + src_term + rec_term)\n",
2917-
"op1(dt=dt)"
2905+
" op1(dt=dt)"
29182906
]
29192907
},
29202908
{
@@ -3020,8 +3008,22 @@
30203008
}
30213009
],
30223010
"metadata": {
3011+
"kernelspec": {
3012+
"display_name": "Python 3 (ipykernel)",
3013+
"language": "python",
3014+
"name": "python3"
3015+
},
30233016
"language_info": {
3024-
"name": "python"
3017+
"codemirror_mode": {
3018+
"name": "ipython",
3019+
"version": 3
3020+
},
3021+
"file_extension": ".py",
3022+
"mimetype": "text/x-python",
3023+
"name": "python",
3024+
"nbconvert_exporter": "python",
3025+
"pygments_lexer": "ipython3",
3026+
"version": "3.11.5"
30253027
}
30263028
},
30273029
"nbformat": 4,

tests/test_interpolation.py

+15
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import pytest
44
from sympy import Float
55

6+
from conftest import assert_structure
67
from devito import (Grid, Operator, Dimension, SparseFunction, SparseTimeFunction,
78
Function, TimeFunction, DefaultDimension, Eq, switchconfig,
89
PrecomputedSparseFunction, PrecomputedSparseTimeFunction,
@@ -958,6 +959,10 @@ def test_interpolate_subdomain(self):
958959
assert np.all(np.isclose(sr0.data, check0))
959960
assert np.all(np.isclose(sr1.data, check1))
960961
assert np.all(np.isclose(sr2.data, check2))
962+
assert_structure(op,
963+
['p_sr0', 'p_sr0rsr0xrsr0y', 'p_sr1',
964+
'p_sr1rsr1xrsr1y', 'p_sr2', 'p_sr2rsr2xrsr2y'],
965+
'p_sr0rsr0xrsr0yp_sr1rsr1xrsr1yp_sr2rsr2xrsr2y')
961966

962967
def test_interpolate_subdomain_sinc(self):
963968
"""
@@ -997,6 +1002,10 @@ def test_interpolate_subdomain_sinc(self):
9971002

9981003
assert np.all(np.isclose(sr0.data, sr2.data))
9991004
assert np.all(np.isclose(sr1.data, sr2.data))
1005+
assert_structure(op,
1006+
['p_sr0', 'p_sr0rsr0xrsr0y', 'p_sr1',
1007+
'p_sr1rsr1xrsr1y', 'p_sr2', 'p_sr2rsr2xrsr2y'],
1008+
'p_sr0rsr0xrsr0yp_sr1rsr1xrsr1yp_sr2rsr2xrsr2y')
10001009

10011010
def test_inject_subdomain(self):
10021011
"""
@@ -1041,6 +1050,9 @@ def test_inject_subdomain(self):
10411050

10421051
assert np.all(np.isclose(f0.data, check0))
10431052
assert np.all(np.isclose(f1.data, check1))
1053+
assert_structure(op,
1054+
['p_sr0rsr0xrsr0y'],
1055+
'p_sr0rsr0xrsr0y')
10441056

10451057
def test_inject_subdomain_sinc(self):
10461058
"""
@@ -1070,6 +1082,9 @@ def test_inject_subdomain_sinc(self):
10701082

10711083
assert np.all(np.isclose(f0.data, f2.data[:9, -9:]))
10721084
assert np.all(np.isclose(f1.data, f2.data[1:-1, 1:-1]))
1085+
assert_structure(op,
1086+
['p_sr0rsr0xrsr0y'],
1087+
'p_sr0rsr0xrsr0y')
10731088

10741089
@pytest.mark.parallel(mode=4)
10751090
def test_interpolate_subdomain_mpi(self, mode):

0 commit comments

Comments
 (0)