Skip to content

Commit dfb6a32

Browse files
committed
plot pder for the elements too
1 parent e868553 commit dfb6a32

File tree

1 file changed

+45
-11
lines changed

1 file changed

+45
-11
lines changed

test/test_symbolic.py

Lines changed: 45 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -334,19 +334,32 @@ def test_node_reduction(actx_factory):
334334

335335
# {{{ test_stretch_factor
336336

337+
# {{{ twisted mesh
338+
337339
def make_twisted_mesh(order, cls):
340+
# 2 3 5
341+
# o------o-----------o
342+
# | | |
343+
# | | |
344+
# | | |
345+
# o------o-----------o
346+
# 0 1 4
347+
#
348+
#
338349
vertices = np.array([
339350
[-1, -1, 0], [1, -1, 0], [-1, 1, 0], [1, 1, 0],
351+
[4, -1, 0], [4, 1, 0],
340352
], dtype=np.float64).T
341353

342354
import meshmode.mesh as mm
343355
if issubclass(cls, mm.SimplexElementGroup):
344356
vertex_indices = np.array([
345357
(0, 1, 2), (1, 3, 2),
358+
(1, 4, 3), (4, 5, 3),
346359
], dtype=np.int32)
347360
elif issubclass(cls, mm.TensorProductElementGroup):
348361
vertex_indices = np.array([
349-
(0, 1, 2, 3),
362+
(0, 1, 2, 3), (1, 4, 3, 5),
350363
], dtype=np.int32)
351364
else:
352365
raise ValueError
@@ -358,13 +371,10 @@ def make_twisted_mesh(order, cls):
358371
group_cls=cls)
359372

360373
def wobble(x):
361-
rx, ry = 2, 0.5
362-
theta = np.pi / 4
363-
364374
result = np.empty_like(x)
365-
result[0] = rx * (np.cos(theta) * x[0] - np.sin(theta) * x[1])
366-
result[1] = np.sin(ry * (np.sin(theta) * x[0] + np.cos(theta) * x[1]))
367-
result[2] = x[2]
375+
result[0] = x[0] + 0.5 * np.sin(x[1])
376+
result[1] = x[1] + 0.5 * np.cos(x[0])
377+
result[2] = x[2] + 0.5 * np.cos(x[1]) + 0.5 * np.sin(x[0])
368378
# result[2] = np.sin(x[1]) * np.sin(x[0])
369379

370380
return result
@@ -373,6 +383,10 @@ def wobble(x):
373383
mesh = mm.Mesh(vertices, [grp], is_conforming=True)
374384
return map_mesh(mesh, wobble)
375385

386+
# }}}
387+
388+
389+
# {{{ torus elements
376390

377391
def make_torus_mesh(order, cls, a=2.0, b=1.0, n_major=12, n_minor=6):
378392
u, v = np.mgrid[0:2*np.pi:2*np.pi/n_major, 0:2*np.pi:2*np.pi/n_minor]
@@ -421,6 +435,10 @@ def idx(i, j):
421435

422436
return mm.Mesh(vertices, [grp.copy(nodes=nodes)], is_conforming=True)
423437

438+
# }}}
439+
440+
441+
# {{{ gmsh sphere
424442

425443
def make_gmsh_sphere(order: int, cls: type):
426444
from meshmode.mesh.io import ScriptSource
@@ -460,6 +478,10 @@ def make_gmsh_sphere(order: int, cls: type):
460478
target_unit="MM",
461479
)
462480

481+
# }}}
482+
483+
484+
# {{{ gmsh torus
463485

464486
def make_gmsh_torus(order: int, cls: type):
465487
from meshmode.mesh.io import ScriptSource
@@ -499,6 +521,10 @@ def make_gmsh_torus(order: int, cls: type):
499521
target_unit="MM",
500522
)
501523

524+
# }}}
525+
526+
527+
# {{{ symbolic
502528

503529
def metric_from_form1(form1, metric_type: str):
504530
from pytential.symbolic.primitives import _small_mat_eigenvalues
@@ -540,10 +566,12 @@ def make_quad_stretch_factors(ambient_dim: int, metric_type: str):
540566

541567
return metric_from_form1(form1, metric_type)
542568

569+
# }}}
570+
543571

544572
@pytest.mark.parametrize("order", [4, 8])
545573
def test_stretch_factor(actx_factory, order,
546-
mesh_name="torus", metric_type="eigs",
574+
mesh_name="torus", metric_type="singvals",
547575
visualize=False):
548576
logging.basicConfig(level=logging.INFO)
549577
actx = actx_factory()
@@ -598,7 +626,8 @@ def print_bounds(x, name):
598626
name, i,
599627
actx.to_numpy(actx.np.min(si))[()],
600628
actx.to_numpy(actx.np.min(si))[()]
601-
))
629+
), end=" ")
630+
print()
602631

603632
print_bounds(s, "s")
604633
print_bounds(q, "q")
@@ -610,15 +639,20 @@ def print_bounds(x, name):
610639

611640
# {{{ plot vtk
612641

642+
s_pder = bind(simplex_discr, sym.parametrization_derivative_matrix(3, 2))(actx)
643+
q_pder = bind(quad_discr, sym.parametrization_derivative_matrix(3, 2))(actx)
644+
613645
from meshmode.discretization.visualization import make_visualizer
614646
vis = make_visualizer(actx, simplex_discr, order, force_equidistant=True)
615647
vis.write_vtk_file(f"simplex_{suffix}.vtu",
616-
[(f"s{i}", si) for i, si in enumerate(s)],
648+
[(f"s{i}", si) for i, si in enumerate(s)]
649+
+ [(f"J_{i}_{j}", pder) for (i, j), pder in np.ndenumerate(s_pder)],
617650
overwrite=True, use_high_order=True)
618651

619652
vis = make_visualizer(actx, quad_discr, order, force_equidistant=True)
620653
vis.write_vtk_file(f"quad_{suffix}.vtu",
621-
[(f"q{i}", qi) for i, qi in enumerate(q)],
654+
[(f"q{i}", qi) for i, qi in enumerate(q)]
655+
+ [(f"J_{i}_{j}", pder) for (i, j), pder in np.ndenumerate(q_pder)],
622656
overwrite=True, use_high_order=True)
623657

624658
# }}}

0 commit comments

Comments
 (0)