Skip to content

Commit 49eb91d

Browse files
committed
feat: add tests for system kernels
1 parent 6aa3ee2 commit 49eb91d

1 file changed

Lines changed: 82 additions & 0 deletions

File tree

sumpy/test/test_misc.py

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,15 +59,20 @@
5959
from sumpy.kernel import (
6060
BiharmonicKernel,
6161
BrinkmanletKernel,
62+
BrinkmanletSystemKernel,
6263
BrinkmanStressKernel,
64+
BrinkmanStressSystemKernel,
6365
ElasticityKernel,
66+
ElasticitySystemKernel,
6467
ExpressionKernel,
6568
HelmholtzKernel,
6669
LaplaceKernel,
6770
LineOfCompressionKernel,
6871
ScalarKernel,
6972
StokesletKernel,
73+
StokesletSystemKernel,
7074
StressletKernel,
75+
StressletSystemKernel,
7176
YukawaKernel,
7277
)
7378

@@ -778,6 +783,83 @@ def test_get_storage_index(order, knl, compressed):
778783
# }}}
779784

780785

786+
# {{{ test_system_kernel_components
787+
788+
def _get_scalar_cls(knl):
789+
if isinstance(knl, ElasticitySystemKernel):
790+
return ElasticityKernel
791+
elif isinstance(knl, StokesletSystemKernel):
792+
return StokesletKernel
793+
elif isinstance(knl, StressletSystemKernel):
794+
return StressletKernel
795+
elif isinstance(knl, BrinkmanletSystemKernel):
796+
return BrinkmanletKernel
797+
elif isinstance(knl, BrinkmanStressSystemKernel):
798+
return BrinkmanStressKernel
799+
else:
800+
raise AssertionError
801+
802+
803+
@pytest.mark.parametrize("dim", [2, 3])
804+
@pytest.mark.parametrize("cls", [
805+
ElasticitySystemKernel,
806+
StokesletSystemKernel,
807+
StressletSystemKernel,
808+
BrinkmanletSystemKernel,
809+
BrinkmanStressSystemKernel,
810+
])
811+
def test_system_kernel_components(dim, cls):
812+
knl = cls(dim=dim)
813+
scalar_cls = _get_scalar_cls(knl)
814+
shape = knl.shape
815+
816+
from itertools import product
817+
818+
if len(shape) == 2:
819+
assert shape == (dim, dim)
820+
for i, j in product(range(dim), repeat=2):
821+
comp = knl[i, j]
822+
expected_ij = tuple(sorted([i, j]))
823+
assert isinstance(comp, scalar_cls)
824+
assert comp.dim == dim
825+
assert (comp.icomp, comp.jcomp) == expected_ij
826+
# symmetry
827+
assert knl[i, j] is knl[j, i]
828+
else:
829+
assert shape == (dim, dim, dim)
830+
for i, j, k in product(range(dim), repeat=3):
831+
comp = knl[i, j, k]
832+
expected_ijk = tuple(sorted([i, j, k]))
833+
834+
assert isinstance(comp, scalar_cls)
835+
assert comp.dim == dim
836+
assert (comp.icomp, comp.jcomp, comp.kcomp) == expected_ijk
837+
# symmetry: all permutations of sorted indices are the same
838+
s = tuple(sorted([i, j, k]))
839+
assert knl[i, j, k] is knl[s]
840+
841+
# }}}
842+
843+
844+
# {{{ test_system_kernel_pickle
845+
846+
@pytest.mark.parametrize("dim", [2, 3])
847+
@pytest.mark.parametrize("cls", [
848+
ElasticitySystemKernel,
849+
StokesletSystemKernel,
850+
StressletSystemKernel,
851+
BrinkmanletSystemKernel,
852+
BrinkmanStressSystemKernel,
853+
])
854+
def test_system_kernel_pickle(dim, cls):
855+
from pickle import dumps, loads
856+
857+
knl = cls(dim=dim)
858+
assert loads(dumps(knl)) == knl
859+
860+
# }}}
861+
862+
781863
# You can test individual routines by typing
782864
# $ python test_misc.py 'test_pde_check_kernels(_acf,
783865
# KernelInfo(HelmholtzKernel(2), k=5), order=5)'

0 commit comments

Comments
 (0)