Newer
Older
# FIXME: Bessel functions need to brought out of the symbolic
# layer. Related issue: https://github.com/inducer/grudge/issues/93
def bessel_j(actx, n, r):
from grudge import sym, bind
return bind(dcoll, sym.bessel_j(n, sym.var("r")))(actx, r=r)
# https://dlmf.nist.gov/10.6.1
n = 3
bessel_zero = (bessel_j(actx, n+1, r)
+ bessel_j(actx, n-1, r)
- 2*n/r * bessel_j(actx, n, r))
z = op.norm(dcoll, bessel_zero, 2)
assert z < 1e-15
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
@pytest.mark.parametrize("p", [2, np.inf])
def test_norm_complex(actx_factory, p):
actx = actx_factory()
dim = 2
mesh = mgen.generate_regular_rect_mesh(
a=(0,)*dim, b=(1,)*dim,
nelements_per_axis=(8,)*dim, order=1)
dcoll = DiscretizationCollection(actx, mesh, order=4)
nodes = thaw(dcoll.nodes(), actx)
f = nodes[0] + 1j * nodes[0]
norm = op.norm(dcoll, f, p)
if p == 2:
ref_norm = ((1/3)*dim)**0.5
elif p == np.inf:
ref_norm = 2**0.5
assert abs(norm-ref_norm) / abs(ref_norm) < 1e-13
def test_norm_obj_array(actx_factory, p):
"""Test :func:`grudge.op.norm` for object arrays."""
mesh = mgen.generate_regular_rect_mesh(
nelements_per_axis=(8,)*dim, order=1)
dcoll = DiscretizationCollection(actx, mesh, order=4)
w = make_obj_array([1.0, 2.0, 3.0])[:dim]
# {{ scalar
norm_exact = w[0]
logger.info("norm: %.5e %.5e", norm, norm_exact)
assert abs(norm - norm_exact) < 1.0e-14
norm_exact = np.sqrt(np.sum(w**2)) if p == 2 else np.max(w)
logger.info("norm: %.5e %.5e", norm, norm_exact)
assert abs(norm - norm_exact) < 1.0e-14
def test_empty_boundary(actx_factory):
# https://github.com/inducer/grudge/issues/54
from meshmode.mesh import BTAG_NONE
mesh = mgen.generate_regular_rect_mesh(
nelements_per_axis=(8,)*dim, order=4)
dcoll = DiscretizationCollection(actx, mesh, order=4)
normal = dcoll.normal(BTAG_NONE)
from meshmode.dof_array import DOFArray
for component in normal:
assert isinstance(component, DOFArray)
assert len(component) == len(dcoll.discr_from_dd(BTAG_NONE).groups)
# $ python test_grudge.py 'test_routine()'
if __name__ == "__main__":
import sys
if len(sys.argv) > 1:
exec(sys.argv[1])
else:
pytest.main([__file__])