Title: Multithreaded iterator with the hybrid kernels drops the OpenCASCADE-only items of a mixed representation (and duplicates the CGAL part single-threaded) · Issue #10223 · IfcOpenShell/IfcOpenShell · GitHub
Open Graph Title: Multithreaded iterator with the hybrid kernels drops the OpenCASCADE-only items of a mixed representation (and duplicates the CGAL part single-threaded) · Issue #10223 · IfcOpenShell/IfcOpenShell
X Title: Multithreaded iterator with the hybrid kernels drops the OpenCASCADE-only items of a mixed representation (and duplicates the CGAL part single-threaded) · Issue #10223 · IfcOpenShell/IfcOpenShell
Description: Bug Description With hybrid-cgal-simple-opencascade (and hybrid-cgal-opencascade), when a product's Body has some items CGAL can build and some it can't (here a curved IfcAdvancedBrep), ifcopenshell.geom.iterator returns different geomet...
Open Graph Description: Bug Description With hybrid-cgal-simple-opencascade (and hybrid-cgal-opencascade), when a product's Body has some items CGAL can build and some it can't (here a curved IfcAdvancedBrep), ifcopenshel...
X Description: Bug Description With hybrid-cgal-simple-opencascade (and hybrid-cgal-opencascade), when a product's Body has some items CGAL can build and some it can't (here a curved IfcAdvancedBrep), ifc...
Opengraph URL: https://github.com/IfcOpenShell/IfcOpenShell/issues/10223
X: @github
Domain: github.com
IPv4 address: 140.82.113.3
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Multithreaded iterator with the hybrid kernels drops the OpenCASCADE-only items of a mixed representation (and duplicates the CGAL part single-threaded)","articleBody":"### Bug Description\n\nWith `hybrid-cgal-simple-opencascade` (and `hybrid-cgal-opencascade`), when a product's Body has some items CGAL can build and some it can't (here a curved `IfcAdvancedBrep`), `ifcopenshell.geom.iterator` returns different geometry depending on the thread count:\n\n- **2 or more threads:** only the CGAL-built item comes back. The curved item is missing, and nothing is logged. The result is the same as `cgal-simple` on its own.\n- **1 thread:** the full shape comes back, but the CGAL-built item is in it **twice** (its triangles appear once from each kernel).\n\n`create_shape` with the same library gives the 1-thread result (duplicated part). `opencascade` gives the correct shape at any thread count. A product whose only item is the curved brep is fine under both, because the whole representation goes to OpenCASCADE.\n\nThe result is the same on every run (5 runs per setting), so this is not the nondeterminism in #8050. It looks related to #8052, where the hybrid was changed to defer to OpenCASCADE when cgal-simple only partly succeeds: under multithreading that fallback doesn't seem to happen, and single-threaded the partial CGAL result is kept alongside the fallback. #10049 (fixed in #10052) was a different hybrid-iterator fault, on mapped bodies with openings.\n\nI found this on a Revit 2026 export, where the body of each affected element is one `IfcMappedItem` over 11 `IfcAdvancedBrep`s: two flat-faced ones and nine with cylindrical faces or faces of revolution. With the multithreaded iterator, only the two flat-faced breps are returned, so the element appears moved by about 0.55 m (its centroid) and loses most of its shape. The mapped item isn't needed to trigger it, as the reproduction shows.\n\n### Minimal reproduction\n\n`make_repro.py` writes `hybrid_repro.ifc` from scratch (IFC4, millimetres, four `IfcBuildingElementProxy`s 1 m apart). Each has a 200 × 100 × 100 mm box on top of a cylinder 50 mm in radius and 600 mm tall:\n\n| Product | Body |\n|---|---|\n| `mapped-mixed` | `IfcMappedItem` (identity origin and target) of [box `IfcAdvancedBrep` with `IfcPlane` faces, cylinder `IfcAdvancedBrep`] |\n| `direct-mixed` | the same two `IfcAdvancedBrep`s directly in the representation |\n| `extrusion-mix` | box as `IfcExtrudedAreaSolid` + the cylinder `IfcAdvancedBrep` |\n| `cyl-only` | the cylinder `IfcAdvancedBrep` alone (control) |\n\nThe cylinder brep has one `IfcCylindricalSurface` face with a seam edge and two `IfcPlane` caps bounded by `IfcCircle` edges.\n\n`check_repro.py` meshes the file with default settings (`ifcopenshell.geom.settings()`, local coordinates) using `opencascade` and `hybrid-cgal-simple-opencascade`, with 1 and 4 iterator threads, and prints each product's vertex count, Z range and enclosed volume:\n\n```\npython make_repro.py hybrid_repro.ifc\npython check_repro.py hybrid_repro.ifc 4\n```\n\n\u003cdetails>\u003csummary>make_repro.py\u003c/summary>\n\n```python\n\"\"\"Write a minimal IFC4 file, from scratch, with a few proxies whose Body mixes a planar-only solid with a curved\nIfcAdvancedBrep (a cylinder: IfcCylindricalSurface side, IfcPlane caps bounded by IfcCircle edges).\n\n python -I make_repro.py \u003cout.ifc>\n\nProducts (millimetres, the file's length unit; near the origin, 1000 mm apart along X):\n mapped-mixed IfcMappedItem (identity origin and target) of [planar box IfcAdvancedBrep, cylinder IfcAdvancedBrep]\n direct-mixed the same two IfcAdvancedBreps directly in the Body representation, no mapping\n extrusion-mix an IfcExtrudedAreaSolid box + the cylinder IfcAdvancedBrep, directly\n cyl-only the cylinder IfcAdvancedBrep alone\n\"\"\"\nimport sys\nimport ifcopenshell\nimport ifcopenshell.api.aggregate, ifcopenshell.api.context, ifcopenshell.api.project\nimport ifcopenshell.api.root, ifcopenshell.api.spatial, ifcopenshell.api.unit\n\nf = ifcopenshell.api.project.create_file(version='IFC4')\nproject = ifcopenshell.api.root.create_entity(f, ifc_class='IfcProject', name='Hybrid kernel repro')\nifcopenshell.api.unit.assign_unit(f) # its default: millimetres\nmodel = ifcopenshell.api.context.add_context(f, context_type='Model')\nbody = ifcopenshell.api.context.add_context(f, context_type='Model', context_identifier='Body',\n target_view='MODEL_VIEW', parent=model)\nsite = ifcopenshell.api.root.create_entity(f, ifc_class='IfcSite', name='Site')\nifcopenshell.api.aggregate.assign_object(f, products=[site], relating_object=project)\n\nP = lambda *c: f.createIfcCartesianPoint([float(x) for x in c])\nD = lambda *c: f.createIfcDirection([float(x) for x in c])\nA3 = lambda o, z=None, x=None: f.createIfcAxis2Placement3D(P(*o), D(*z) if z else None, D(*x) if x else None)\n\n\ndef vertex(*c):\n return f.createIfcVertexPoint(P(*c))\n\n\ndef edge(v0, v1, curve):\n return f.createIfcEdgeCurve(v0, v1, curve, True)\n\n\ndef loop(*oriented):\n return f.createIfcEdgeLoop([f.createIfcOrientedEdge(None, None, e, s) for e, s in oriented])\n\n\ndef face(surface, bound, same_sense=True):\n return f.createIfcAdvancedFace([f.createIfcFaceOuterBound(bound, True)], surface, same_sense)\n\n\ndef box_brep(x0, y0, z0, dx, dy, dz):\n \"\"\"Axis-aligned box as an IfcAdvancedBrep of six IfcPlane faces bounded by IfcPolyline edges.\"\"\"\n c = [(x0 + i * dx, y0 + j * dy, z0 + k * dz) for k in (0, 1) for j in (0, 1) for i in (0, 1)]\n v = [vertex(*p) for p in c]\n E = {}\n\n def e(a, b):\n if (b, a) in E:\n return E[(b, a)], False\n if (a, b) not in E:\n E[(a, b)] = edge(v[a], v[b], f.createIfcPolyline([P(*c[a]), P(*c[b])]))\n return E[(a, b)], True\n\n # vertex index = i + 2j + 4k; each quad listed counter-clockwise seen from outside\n quads = {(0, 0, -1): (0, 2, 3, 1), (0, 0, 1): (4, 5, 7, 6), (0, -1, 0): (0, 1, 5, 4),\n (0, 1, 0): (2, 6, 7, 3), (-1, 0, 0): (0, 4, 6, 2), (1, 0, 0): (1, 3, 7, 5)}\n faces = []\n for n, q in quads.items():\n o = c[q[0]]\n ref = [c[q[1]][i] - o[i] for i in range(3)]\n plane = f.createIfcPlane(A3(o, n, [r / max(abs(x) for x in ref) for r in ref]))\n faces.append(face(plane, loop(*[e(q[i], q[(i + 1) % 4]) for i in range(4)])))\n return f.createIfcAdvancedBrep(f.createIfcClosedShell(faces))\n\n\ndef cylinder_brep(cx, cy, z0, r, h):\n \"\"\"Vertical cylinder as an IfcAdvancedBrep: one IfcCylindricalSurface face with a seam, two IfcPlane caps.\"\"\"\n vb, vt = vertex(cx + r, cy, z0), vertex(cx + r, cy, z0 + h)\n cb = edge(vb, vb, f.createIfcCircle(A3((cx, cy, z0), (0, 0, 1), (1, 0, 0)), r))\n ct = edge(vt, vt, f.createIfcCircle(A3((cx, cy, z0 + h), (0, 0, 1), (1, 0, 0)), r))\n seam = edge(vb, vt, f.createIfcPolyline([P(cx + r, cy, z0), P(cx + r, cy, z0 + h)]))\n side = face(f.createIfcCylindricalSurface(A3((cx, cy, z0), (0, 0, 1), (1, 0, 0)), r),\n loop((cb, True), (seam, True), (ct, False), (seam, False)))\n bottom = face(f.createIfcPlane(A3((cx, cy, z0), (0, 0, 1), (1, 0, 0))), loop((cb, True)), False)\n top = face(f.createIfcPlane(A3((cx, cy, z0 + h), (0, 0, 1), (1, 0, 0))), loop((ct, True)), True)\n return f.createIfcAdvancedBrep(f.createIfcClosedShell([side, bottom, top]))\n\n\ndef extruded_box(x0, y0, z0, dx, dy, dz):\n prof = f.createIfcRectangleProfileDef('AREA', None, f.createIfcAxis2Placement2D(\n f.createIfcCartesianPoint([x0 + dx / 2, y0 + dy / 2]), None), dx, dy)\n return f.createIfcExtrudedAreaSolid(prof, A3((0, 0, z0)), D(0, 0, 1), dz)\n\n\ndef shape(items, rep_type):\n return f.createIfcProductDefinitionShape(None, None, [f.createIfcShapeRepresentation(body, 'Body', rep_type, items)])\n\n\ndef proxy(name, x, product_shape):\n p = ifcopenshell.api.root.create_entity(f, ifc_class='IfcBuildingElementProxy', name=name)\n p.ObjectPlacement = f.createIfcLocalPlacement(None, A3((x, 0, 0)))\n p.Representation = product_shape\n ifcopenshell.api.spatial.assign_container(f, products=[p], relating_structure=site)\n return p\n\n\n# the parts: a 200 x 100 x 100 mm box sitting on top of a 50 mm radius, 600 mm tall cylinder\nBOX = (-100.0, -50.0, 600.0, 200.0, 100.0, 100.0)\nCYL = (0.0, 0.0, 0.0, 50.0, 600.0)\n\nsource = f.createIfcRepresentationMap(A3((0, 0, 0)), f.createIfcShapeRepresentation(\n body, 'Body', 'AdvancedBrep', [box_brep(*BOX), cylinder_brep(*CYL)]))\ntarget = f.createIfcCartesianTransformationOperator3D(None, None, P(0, 0, 0), 1.0, None)\nproxy('mapped-mixed', 0.0, shape([f.createIfcMappedItem(source, target)], 'MappedRepresentation'))\nproxy('direct-mixed', 1000.0, shape([box_brep(*BOX), cylinder_brep(*CYL)], 'AdvancedBrep'))\nproxy('extrusion-mix', 2000.0, shape([extruded_box(*BOX), cylinder_brep(*CYL)], 'SolidModel'))\nproxy('cyl-only', 3000.0, shape([cylinder_brep(*CYL)], 'AdvancedBrep'))\n\nf.write(sys.argv[1])\nprint('wrote', sys.argv[1])\n```\n\n\u003c/details>\n\n\u003cdetails>\u003csummary>check_repro.py\u003c/summary>\n\n```python\n\"\"\"Mesh a file with the default and the hybrid kernel, with 1 and N iterator threads, and print each product's\nvertex count, bounding box (local coordinates) and enclosed volume.\n\n python -I check_repro.py \u003cfile.ifc> [N=4]\n\"\"\"\nimport sys\nimport numpy as np\nimport ifcopenshell, ifcopenshell.geom\n\npath = sys.argv[1]\nn_threads = int(sys.argv[2]) if len(sys.argv) > 2 else 4\nf = ifcopenshell.open(path)\nprint('IfcOpenShell', ifcopenshell.version, '| python', sys.version.split()[0])\n\n\ndef volume(v, t):\n a, b, c = v[t[:, 0]], v[t[:, 1]], v[t[:, 2]]\n return float(np.einsum('ij,ij->i', a, np.cross(b, c)).sum() / 6)\n\n\ndef run(lib, threads):\n s = ifcopenshell.geom.settings() # defaults, local coordinates\n it = ifcopenshell.geom.iterator(s, f, threads, geometry_library=lib)\n assert it.initialize()\n out = {}\n while True:\n sh = it.get()\n v = np.asarray(sh.geometry.verts).reshape(-1, 3)\n t = np.asarray(sh.geometry.faces).reshape(-1, 3)\n out[f.by_id(sh.id).Name] = (len(v), v.min(0), v.max(0), volume(v, t))\n if not it.next():\n break\n return out\n\n\nfor lib in ('opencascade', 'hybrid-cgal-simple-opencascade'):\n for threads in (1, n_threads):\n print('\\n%s, %d thread(s)' % (lib, threads))\n for name, (nv, lo, hi, vol) in sorted(run(lib, threads).items()):\n print(' %-14s verts %5d z %.3f..%.3f volume %.6f m3' % (name, nv, lo[2], hi[2], vol))\n```\n\n\u003c/details>\n\n### Expected\n\nEvery mixed product: the box and the cylinder, Z from 0.000 to 0.700 m and a volume of about 0.00667 m³ (box 0.002 m³ + cylinder ≈ 0.00467 m³ as tessellated), whatever the thread count, as with `opencascade`.\n\n### Actual\n\n```\nopencascade, 1 or 4 thread(s)\n cyl-only verts 52 z 0.000..0.600 volume 0.004667 m3\n direct-mixed verts 60 z 0.000..0.700 volume 0.006667 m3\n extrusion-mix verts 60 z 0.000..0.700 volume 0.006667 m3\n mapped-mixed verts 60 z 0.000..0.700 volume 0.006667 m3\n\nhybrid-cgal-simple-opencascade, 1 thread(s)\n cyl-only verts 52 z 0.000..0.600 volume 0.004667 m3\n direct-mixed verts 68 z 0.000..0.700 volume 0.008667 m3 \u003c- box counted twice\n extrusion-mix verts 68 z 0.000..0.700 volume 0.008667 m3 \u003c- box counted twice\n mapped-mixed verts 68 z 0.000..0.700 volume 0.008667 m3 \u003c- box counted twice\n\nhybrid-cgal-simple-opencascade, 4 thread(s)\n cyl-only verts 52 z 0.000..0.600 volume 0.004667 m3\n direct-mixed verts 8 z 0.600..0.700 volume 0.002000 m3 \u003c- cylinder missing\n extrusion-mix verts 8 z 0.600..0.700 volume 0.002000 m3 \u003c- cylinder missing\n mapped-mixed verts 8 z 0.600..0.700 volume 0.002000 m3 \u003c- cylinder missing\n```\n\nCounting triangles with every vertex at z ≥ 0.6 m (the box plus the cylinder's top cap): `opencascade` gives 36 (24 cap + 12 box). The hybrid gives 48 at 1 thread (the box's 12 triangles twice), and 12 at 4 threads (the box only).\n\nOther observations:\n\n- `hybrid-cgal-opencascade` gives exactly the same numbers as `hybrid-cgal-simple-opencascade`.\n- `cgal-simple` and `cgal` give the 8-vertex box for the mixed products at any thread count, and no shape for `cyl-only`.\n- An `include=[one product]` iterator gives the same result (124 triangles at 1 thread, 12 at 2 and 8 threads), so one product and two threads are enough.\n- `create_shape(settings, product, geometry_library=\"hybrid-cgal-simple-opencascade\")` gives 124 triangles (the duplicated box). `opencascade` gives 112.\n\n### Versions\n\n- IfcOpenShell 0.9.0.post1 from PyPI (`pip install ifcopenshell`), the newest release on PyPI at the time of writing\n- Python 3.13.15, 64-bit\n- Windows Server 2025 (10.0.26100), x64\n\nAlso the same on two newer builds, with identical numbers:\n- `0.9.1+4d75f46`, `ifcopenshell-python-313-v0.9.1-4d75f46-win64.zip` from the builds bucket, 4 November 2026. It includes #10052: a mapped box with an opening, meshed by the threaded hybrid iterator, gives 0 vertices on 0.9.0.post1 and 16 on this build.\n- `ifcopenshell-0.9.1a261114` (core `0.9.1-7b8f129`), the wheel in the 14 November 2026 Bonsai unstable release.","author":{"url":"https://github.com/python-flow","@type":"Person","name":"python-flow"},"datePublished":"2026-11-14T11:40:33Z","url":"https://github.com/IfcOpenShell/IfcOpenShell/issues/10223"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:1c36b8a5-864a-e212-65d5-1c795cfe99a7 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | E8C0:19AD56:1AAB7C:23A845:6B04AF09 |
| html-safe-nonce | 6d1138288639c256c29658b513a122e46dd87fbc8dee49c85ec24c36fb585908 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJFOEMwOjE5QUQ1NjoxQUFCN0M6MjNBODQ1OjZCMDRBRjA5IiwidmlzaXRvcl9pZCI6IjM1NDY5ODY4NTA0MzI2MjY0NDEiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 7cd1ea61a022e3374d186f127bcd2b8bf6fd4699e26205721611b114c00931ee |
| hovercard-subject-tag | issue:6389491291 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/IfcOpenShell/IfcOpenShell/10223/issue_layout |
| twitter:image | https://opengraph.githubassets.com/6994bb5188df77ea71280ba7fca75ede9ff77d472a83dd4e2a0425b17150e156/IfcOpenShell/IfcOpenShell/issues/10223 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/6994bb5188df77ea71280ba7fca75ede9ff77d472a83dd4e2a0425b17150e156/IfcOpenShell/IfcOpenShell/issues/10223 |
| og:image:alt | Bug Description With hybrid-cgal-simple-opencascade (and hybrid-cgal-opencascade), when a product's Body has some items CGAL can build and some it can't (here a curved IfcAdvancedBrep), ifcopenshel... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | python-flow |
| hostname | github.com |
| expected-hostname | github.com |
| None | f1d110ea058a0915c1d8aa3fc2069fa15801e128f591e5762525abe77490ecb1 |
| turbo-cache-control | no-preview |
| go-import | github.com/IfcOpenShell/IfcOpenShell git https://github.com/IfcOpenShell/IfcOpenShell.git |
| octolytics-dimension-user_id | 13692563 |
| octolytics-dimension-user_login | IfcOpenShell |
| octolytics-dimension-repository_id | 40473201 |
| octolytics-dimension-repository_nwo | IfcOpenShell/IfcOpenShell |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 40473201 |
| octolytics-dimension-repository_network_root_nwo | IfcOpenShell/IfcOpenShell |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | ffa22a65e4c46d376940fe34b05e6a7e9c7fdb9b |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
| Server | github.com |
| Content-Type | text/html; charset=utf-8 |
| Cache-Control | max-age=0, private, must-revalidate |
Viewport: width=device-width