1function dom = surfacemesh_from_quads(msh)
2%SURFACEMESH_FROM_QUADS Build a surfacemesh from a 4-node quad msh struct.
3% Adapted from surfacemesh.fromGmsh (surfacefun): that version locates a
4% QUADS* field via startsWith over fieldnames — which numbl's startsWith
5% does not support for cell arrays — and handles high-order gmsh quads.
6% Our converter only ever emits plain 4-node quads (Gmsh corner order
7% 1-2-3-4 counterclockwise), where the equispaced and Chebyshev 2-point
8% grids coincide, so each patch is just its corner values arranged as a
9% 2-by-2 tensor grid.
11quads = msh.QUADS;
12nelem = size(quads, 1);
13x = cell(nelem, 1);
14y = cell(nelem, 1);
15z = cell(nelem, 1);
17for k = 1:nelem
18 idx = quads(k, 1:4);
19 px = msh.POS(idx, 1);
20 py = msh.POS(idx, 2);
21 pz = msh.POS(idx, 3);
22 % Gmsh corners 1,2,3,4 -> tensor grid (1,1),(2,1),(2,2),(1,2)
23 x{k} = [px(1) px(4); px(2) px(3)];
24 y{k} = [py(1) py(4); py(2) py(3)];
25 z{k} = [pz(1) pz(4); pz(2) pz(3)];
26end
28dom = surfacemesh(x, y, z);
29end