Yes I understand, and when it fails, it emits the warning I posted above. However there is a subtlety here in that the 100k limit is only for the binary Boolean solids—there is no 100k limit (and associated warning) for multi-union. What is happening is that it is getting stuck in the do/while loop of MultiUnion::GetPointOnSurface. I have added comments to the loop to try to explain:
// MultiUnion::GetPointOnSurface
do
{
G4long rnd = G4RandFlat::shootInt(G4long(0), size);
G4VSolid& solid = *fSolids[rnd];
point = solid.GetPointOnSurface(); // This part is fine, generally successfully generating points on the surfaces of a node.
const G4Transform3D& transform = fTransformObjs[rnd];
point = GetGlobalPoint(transform, point);
}
while (Inside(point) != EInside::kSurface); // This part fails repeatedly!
IT is the Inside(point) in G4MultiUnion::GetPointOnSurface that is failing repeatedly. The occasional warning of the type I posted above is just a rare occurrence that will occasionally happen as the above do/while loop is looping many times. That is why I said that it is a red herring, it is just a side-effect of the fact that the do/while loop is stuck in an infinite (or at least very very very long) loop.
To be clear: if the point = solid.GetPointOnSurface(); is successfully getting a point on the surface of a node, how can it be that it is never on the surface of the multi-union itself? I cannot imagine such a shape, and the example I uploaded is actually very simple geometrically anyway. If Geant4 can generate a point on the surface of a node then that point should also correspond to the surface of the multi-union itself a good proportion of the time unless the geometry is obscenely pathological.
Multi-union has one advantage even for only 2 components over binary union in that its nodes can be disconnected (whereas G4Union the two components must be overlapping somehow), admittedly in this instance it is not relevant as the two nodes are overlapping. Otherwise I understand yes it will offer no speedup and may even be slower, but to demonstrate the issue that I am facing, I have reduced the multi-union to feature fewer nods. In my real application this multi-union has 5 nodes, but I am simplifying the problem as much as I can. Perhaps I can go down to a single node and see if it persists. I can try this tomorrow.
What I am trying to say is that I think there’s either a bug in G4MultiUnion or G4Voxelizer or there are undocumented constraints (or at least ones that I have not read) about the type of CSG trees that multi-unions can be used with that I wish to know.
I am dependent on being able to make arbitrary multi-unions (in code that I have written elsewhere for automatic writing of geometry) and if Geant4 is unable to handle arbitrary multi-unions then I need to understand why, and if it turns out to be a bug in Geant4 then I would like to fix it. Simply using G4Union instead is not really an option for me due to reasons that are not important and are unrelated to this problem.