Skip to content

Commit 4a0426e

Browse files
committed
clipping vectors on non tets + test
1 parent d0a082a commit 4a0426e

5 files changed

Lines changed: 37 additions & 4 deletions

File tree

ngsolve_webgpu/mesh.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -672,7 +672,7 @@ def update(self, options: RenderOptions):
672672

673673
# indices and colors: one color entry per segment index
674674
indices = segs["index"].astype(np.uint32)
675-
edge_indices = indices - 1
675+
edge_indices = indices
676676
max_index = int(edge_indices.max()) if edge_indices.size > 0 else -1
677677
# TODO: Colors not yet available in NGSolve
678678
colors = np.zeros((max_index + 1, 4), dtype=np.float32)

ngsolve_webgpu/vectors.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,8 @@ def compute_vectors(self):
242242
return super().compute_vectors()
243243

244244
def update(self, options):
245-
self.n_search_els = self.function_data.mesh_data.ngs_mesh.GetNE(ngs.VOL)
245+
self.function_data.update(options)
246+
self.n_search_els = self.function_data.mesh_data.num_elements["tets"]
246247
self.clipping.update(options)
247248
if not hasattr(self.__clipping, "uniforms"):
248249
self.__clipping.update(options)
Lines changed: 3 additions & 0 deletions
Loading

tests/baselines/fieldlines.png

Lines changed: 2 additions & 2 deletions
Loading

tests/test_vectors.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,35 @@ def test_clipping_vectors_direct(self, webgpu_env):
6464

6565
webgpu_env.assert_matches_baseline(scene, "clipping_vectors_direct.png")
6666

67+
def test_clipping_vectors_mixed_elements(self, webgpu_env):
68+
import ngsolve as ngs
69+
import webgpu.jupyter as wj
70+
from netgen.occ import Box, Pnt, OCCGeometry
71+
from netgen.meshing import BoundaryLayerParameters
72+
from ngsolve_webgpu.mesh import MeshData
73+
from ngsolve_webgpu.cf import FunctionData
74+
from ngsolve_webgpu.vectors import ClippingVectors
75+
from webgpu.clipping import Clipping
76+
77+
webgpu_env.ensure_canvas(600, 600)
78+
box = Box(Pnt(0, 0, 0), Pnt(1, 1, 1))
79+
geo = OCCGeometry(box)
80+
blayer = [
81+
BoundaryLayerParameters(boundary=".*", thickness=[0.05], domain=".*", outside=False)]
82+
ngmesh = geo.GenerateMesh(maxh=0.3, boundary_layers=blayer)
83+
mesh = ngs.Mesh(ngmesh)
84+
assert sum(1 for el in mesh.Elements() if el.type == ngs.ET.PRISM) > 0, "Mesh should contain prism elements"
85+
mesh_data = MeshData(mesh)
86+
cf = ngs.CF((ngs.x, ngs.y, ngs.z))
87+
function_data = FunctionData(mesh_data, cf, order=2)
88+
clipping = Clipping()
89+
clipping.mode = clipping.Mode.PLANE
90+
clipping.center = [0.5, 0.5, 0.5]
91+
renderer = ClippingVectors(function_data, grid_size=200, clipping=clipping)
92+
scene = wj.Draw([renderer], 600, 600)
93+
94+
webgpu_env.assert_matches_baseline(scene, "clipping_vectors_mixed_elements.png")
95+
6796
def test_fieldlines(self, webgpu_env):
6897
import ngsolve as ngs
6998
import webgpu.jupyter as wj

0 commit comments

Comments
 (0)