2020THE SOFTWARE.
2121"""
2222
23- import numpy as np
23+ import pytest
2424import sys
2525
26- import pyopencl as cl
27- from pyopencl .tools import ( # noqa
28- pytest_generate_tests_for_pyopencl as pytest_generate_tests )
26+ import numpy as np
27+
28+ from arraycontext import pytest_generate_tests_for_array_contexts
29+ from sumpy .array_context import ( # noqa: F401
30+ PytestPyOpenCLArrayContextFactory , _acf )
31+
32+ from sumpy .expansion .local import (
33+ LineTaylorLocalExpansion ,
34+ VolumeTaylorLocalExpansion )
2935
3036import logging
3137logger = logging .getLogger (__name__ )
32- from sumpy .expansion .local import (
33- LineTaylorLocalExpansion , VolumeTaylorLocalExpansion )
34- import pytest
3538
39+ pytest_generate_tests = pytest_generate_tests_for_array_contexts ([
40+ PytestPyOpenCLArrayContextFactory ,
41+ ])
42+
43+
44+ # {{{ test_direct_qbx_vs_eigval
3645
3746@pytest .mark .parametrize ("expn_class" , [
3847 LineTaylorLocalExpansion ,
3948 VolumeTaylorLocalExpansion ,
4049 ])
41- def test_direct_qbx_vs_eigval (ctx_factory , expn_class ):
50+ def test_direct_qbx_vs_eigval (actx_factory , expn_class , visualize = False ):
4251 """This evaluates a single layer potential on a circle using a known
4352 eigenvalue/eigenvector combination.
4453 """
54+ if visualize :
55+ logging .basicConfig (level = logging .INFO )
4556
46- logging .basicConfig (level = logging .INFO )
47-
48- ctx = ctx_factory ()
49- queue = cl .CommandQueue (ctx )
57+ actx = actx_factory ()
5058
5159 from sumpy .kernel import LaplaceKernel
5260 lknl = LaplaceKernel (2 )
@@ -55,8 +63,10 @@ def test_direct_qbx_vs_eigval(ctx_factory, expn_class):
5563
5664 from sumpy .qbx import LayerPotential
5765
58- lpot = LayerPotential (ctx , expansion = expn_class (lknl , order ),
59- target_kernels = (lknl ,), source_kernels = (lknl ,))
66+ lpot = LayerPotential (actx .context ,
67+ expansion = expn_class (lknl , order ),
68+ target_kernels = (lknl ,),
69+ source_kernels = (lknl ,))
6070
6171 mode_nr = 25
6272
@@ -85,30 +95,36 @@ def test_direct_qbx_vs_eigval(ctx_factory, expn_class):
8595 expansion_radii = np .ones (n ) * radius
8696
8797 strengths = (sigma * h ,)
88- evt , (result_qbx ,) = lpot (queue , targets , sources , centers , strengths ,
98+ evt , (result_qbx ,) = lpot (
99+ actx .queue ,
100+ targets , sources , centers , strengths ,
89101 expansion_radii = expansion_radii )
90102
91103 eocrec .add_data_point (h , np .max (np .abs (result_ref - result_qbx )))
92104
93- print ( eocrec )
105+ logger . info ( "eoc: \n %s" , eocrec )
94106
95107 slack = 1.5
96108 assert eocrec .order_estimate () > order - slack
97109
110+ # }}}
111+
112+
113+ # {{{ test_direct_qbx_vs_eigval_with_tgt_deriv
98114
99115@pytest .mark .parametrize ("expn_class" , [
100116 LineTaylorLocalExpansion ,
101117 VolumeTaylorLocalExpansion ,
102118 ])
103- def test_direct_qbx_vs_eigval_with_tgt_deriv (ctx_factory , expn_class ):
119+ def test_direct_qbx_vs_eigval_with_tgt_deriv (
120+ actx_factory , expn_class , visualize = False ):
104121 """This evaluates a single layer potential on a circle using a known
105122 eigenvalue/eigenvector combination.
106123 """
124+ if visualize :
125+ logging .basicConfig (level = logging .INFO )
107126
108- logging .basicConfig (level = logging .INFO )
109-
110- ctx = ctx_factory ()
111- queue = cl .CommandQueue (ctx )
127+ actx = actx_factory ()
112128
113129 from sumpy .kernel import LaplaceKernel , AxisTargetDerivative
114130 lknl = LaplaceKernel (2 )
@@ -117,9 +133,9 @@ def test_direct_qbx_vs_eigval_with_tgt_deriv(ctx_factory, expn_class):
117133
118134 from sumpy .qbx import LayerPotential
119135
120- lpot_dx = LayerPotential (ctx , expansion = expn_class (lknl , order ),
136+ lpot_dx = LayerPotential (actx . context , expansion = expn_class (lknl , order ),
121137 target_kernels = (AxisTargetDerivative (0 , lknl ),), source_kernels = (lknl ,))
122- lpot_dy = LayerPotential (ctx , expansion = expn_class (lknl , order ),
138+ lpot_dy = LayerPotential (actx . context , expansion = expn_class (lknl , order ),
123139 target_kernels = (AxisTargetDerivative (1 , lknl ),), source_kernels = (lknl ,))
124140
125141 mode_nr = 15
@@ -151,9 +167,11 @@ def test_direct_qbx_vs_eigval_with_tgt_deriv(ctx_factory, expn_class):
151167
152168 strengths = (sigma * h ,)
153169
154- evt , (result_qbx_dx ,) = lpot_dx (queue , targets , sources , centers , strengths ,
170+ evt , (result_qbx_dx ,) = lpot_dx (actx .queue ,
171+ targets , sources , centers , strengths ,
155172 expansion_radii = expansion_radii )
156- evt , (result_qbx_dy ,) = lpot_dy (queue , targets , sources , centers , strengths ,
173+ evt , (result_qbx_dy ,) = lpot_dy (actx .queue ,
174+ targets , sources , centers , strengths ,
157175 expansion_radii = expansion_radii )
158176
159177 normals = unit_circle
@@ -162,17 +180,21 @@ def test_direct_qbx_vs_eigval_with_tgt_deriv(ctx_factory, expn_class):
162180 eocrec .add_data_point (h , np .max (np .abs (result_ref - result_qbx )))
163181
164182 if expn_class is not LineTaylorLocalExpansion :
165- print ( eocrec )
183+ logger . info ( "eoc: \n %s" , eocrec )
166184
167185 slack = 1.5
168186 assert eocrec .order_estimate () > order - slack
169187
188+ # }}}
189+
190+
191+ # You can test individual routines by typing
192+ # $ python test_qbx.py 'test_direct_qbx_vs_eigval(_acf, LineTaylorLocalExpansion)'
170193
171194if __name__ == "__main__" :
172195 if len (sys .argv ) > 1 :
173196 exec (sys .argv [1 ])
174197 else :
175- from pytest import main
176- main ([__file__ ])
198+ pytest .main ([__file__ ])
177199
178200# vim: fdm=marker
0 commit comments