Newer
Older
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
@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 = op.normal(dcoll, 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)
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
# {{{ DiscretizationCollection testing
def test_dcoll_nodes_and_normals(actx_factory):
actx = actx_factory()
from meshmode.mesh import BTAG_ALL
from meshmode.mesh.generation import generate_warped_rect_mesh
mesh = generate_warped_rect_mesh(dim=2, order=4, nelements_side=6)
dcoll = DiscretizationCollection(actx, mesh, order=3)
# Nodes should be *indentical*
nodes = thaw(op.nodes(dcoll), actx)
dcoll_nodes = thaw(dcoll.nodes(), actx)
assert op.norm(dcoll, nodes - dcoll_nodes, np.inf) == 0.0
nodes_btag = thaw(op.nodes(dcoll, BTAG_ALL), actx)
dcoll_nodes_btag = thaw(dcoll.nodes(BTAG_ALL), actx)
assert op.norm(dcoll, nodes_btag - dcoll_nodes_btag, np.inf) == 0.0
# Normals should be *indentical*
normals = thaw(op.normal(dcoll, "int_faces"), actx)
dcoll_normals = thaw(dcoll.normal("int_faces"), actx)
assert op.norm(dcoll, normals - dcoll_normals, np.inf) == 0.0
normals_btag = thaw(op.normal(dcoll, BTAG_ALL), actx)
dcoll_normals_btag = thaw(dcoll.normal(BTAG_ALL), actx)
assert op.norm(dcoll, normals_btag - dcoll_normals_btag, np.inf) == 0.0
# }}}
# $ python test_grudge.py 'test_routine()'
if __name__ == "__main__":
import sys
if len(sys.argv) > 1:
exec(sys.argv[1])
else:
pytest.main([__file__])