Problem 1456

Summary: Voxelisation of G4TessellatedSolid results in Navigation problems with Hollow Solid Volumes
Product: Geant4 Reporter: alex_leatherland
Component: geometry/solidsAssignee: tatiana.nikitina
Status: RESOLVED FIXED    
Severity: normal    
Priority: P5    
Version: 9.6   
Hardware: All   
OS: All   
Attachments: Fix for G4TessellatedSolid in case of hollow solids.

Description alex_leatherland 2013-03-13 11:43:06 CET
Bug Report resulting from a discussion on the geant4 hypernews forum: http://hypernews.slac.stanford.edu/HyperNews/geant4/get/geometry/1262/2/1/2/1/1/1/1/1.html

I am describing a single solid object using triangular facets, this object is hollow (aka has a cavity). One set of facets are created using vertices that define a cube with outward facing normals of size 5x5x5mm, another set use vertices that define a cube 4.5 x 4.5 x 4.5mm. These are all added to a single G4Tessellated solid.

When this detector arrangeement (code to follow) is compilied and run against geant4.9.5.1 it works fine. A geantino traveling through the volume will: -

1) Encounter the outside of the walled/hollow cube
2) Spend a step passing through one cube wall
3) exit the cube into the world volume
4) travel through the world volume space the walled cube surrounds
5) encounter an inner surface of the cube
6) pass through the cube wall
7) exit cube and enter the world

In tracking verbose one this is effectively listed as going through volumes in this order

world -> cube(side 1) -> world -> cube (side 2) -> world

However, when comilied and ran in geant4.9.6.1, once the geantino reaches step 3 of this it seems to ignore the rest of the geometry and exit the world system. Effectively: -

world -> cube(side 1) -> world


I've checked the orientation with rspect to an observer of each facet looking at the outward side, and they are counterclockwise. Although as the geometry works fine a older version of geant4, I'm inclined to believe it is an issue with the newer version.


C++ Code used to describe Solid:

G4TessellatedSolid* target = new G4TessellatedSolid("target");

G4double side = 0.5*cm;
G4double side2 = 0.45*cm

// External vertices
G4ThreeVector v1(side,side,side);
G4ThreeVector v2(side,side,-side);
G4ThreeVector v3(side,-side,side);
G4ThreeVector v4(side,-side,-side);
G4ThreeVector v5(-side,side,side);
G4ThreeVector v6(-side,side,-side);
G4ThreeVector v7(-side,-side,side);
G4ThreeVector v8(-side,-side,-side);

// Internal Vertices
G4ThreeVector i0(side2,side2,side2);
G4ThreeVector i1(-side2,side2,side2);
G4ThreeVector i2(side2,-side2,side2);
G4ThreeVector i3(-side2,-side2,side2);
G4ThreeVector i4(side2,-side2,-side2);
G4ThreeVector i5(-side2,-side2,-side2);
G4ThreeVector i6(side2,side2,-side2);
G4ThreeVector i7(-side2,side2,-side2);

// Facets for External Surface
G4TriangularFacet *f1 = new TriangularFacet(v1,v4,v2,ABSOLUTE);
G4TriangularFacet *f2 = new TriangularFacet(v1,v3,v4,ABSOLUTE);
G4TriangularFacet *f3 = new TriangularFacet(v1,v5,v7,ABSOLUTE);
G4TriangularFacet *f4 = new TriangularFacet(v1,v7,v3,ABSOLUTE);
G4TriangularFacet *f5 = new TriangularFacet(v1,v6,v5,ABSOLUTE);
G4TriangularFacet *f6 = new TriangularFacet(v1,v2,v6,ABSOLUTE);
G4TriangularFacet *f7 = new TriangularFacet(v7,v5,v8,ABSOLUTE);
G4TriangularFacet *f8 = new TriangularFacet(v5,v6,v8,ABSOLUTE);
G4TriangularFacet *f9 = new TriangularFacet(v7,v8,v4,ABSOLUTE);
G4TriangularFacet *f10 = new TriangularFacet(v7,v4,v3,ABSOLUTE);
G4TriangularFacet *f11 = new TriangularFacet(v8,v6,v2,ABSOLUTE);
G4TriangularFacet *f12 = new TriangularFacet(v2,v4,v8,ABSOLUTE);

// Facets for Internal Surface (Hollow/Cavity)
G4TriangularFacet *if0 = new TriangularFacet(i2,i0,i4,ABSOLUTE);
G4TriangularFacet *if1 = new TriangularFacet(i0,i6,i4,ABSOLUTE);
G4TriangularFacet *if2 = new TriangularFacet(i2,i1,i0,ABSOLUTE);
G4TriangularFacet *if3 = new TriangularFacet(i2,i3,i1,ABSOLUTE);
G4TriangularFacet *if4 = new TriangularFacet(i0,i1,i7,ABSOLUTE);
G4TriangularFacet *if5 = new TriangularFacet(i0,i7,i6,ABSOLUTE);
G4TriangularFacet *if6 = new TriangularFacet(i6,i7,i5,ABSOLUTE);
G4TriangularFacet *if7 = new TriangularFacet(i6,i5,i4,ABSOLUTE);
G4TriangularFacet *if8 = new TriangularFacet(i5,i3,i2,ABSOLUTE);
G4TriangularFacet *if9 = new TriangularFacet(i5,i2,i4,ABSOLUTE);
G4TriangularFacet *if10 = new TriangularFacet(i5,i1,i3,ABSOLUTE);
G4TriangularFacet *if11 = new TriangularFacet(i5,i7,i1,ABSOLUTE);

// Add external surfaces
target -> AddFacet((G4VFacet*) f1);
target -> AddFacet((G4VFacet*) f2);
target -> AddFacet((G4VFacet*) f3);
target -> AddFacet((G4VFacet*) f4);
target -> AddFacet((G4VFacet*) f5);
target -> AddFacet((G4VFacet*) f6);
target -> AddFacet((G4VFacet*) f7);
target -> AddFacet((G4VFacet*) f8);
target -> AddFacet((G4VFacet*) f9);
target -> AddFacet((G4VFacet*) f10);
target -> AddFacet((G4VFacet*) f11);
target -> AddFacet((G4VFacet*) f12);

Add internal surfaces
target -> AddFacet((G4VFacet*) if0);
target -> AddFacet((G4VFacet*) if1);
target -> AddFacet((G4VFacet*) if2);
target -> AddFacet((G4VFacet*) if3);
target -> AddFacet((G4VFacet*) if4);
target -> AddFacet((G4VFacet*) if5);
target -> AddFacet((G4VFacet*) if6);
target -> AddFacet((G4VFacet*) if7);
target -> AddFacet((G4VFacet*) if8);
target -> AddFacet((G4VFacet*) if9);
target -> AddFacet((G4VFacet*) if10);
target -> AddFacet((G4VFacet*) if11);

target->SetSolidClosed(true);


Following instructions from Tatiana Nikitina the following line of code was added to the detector construction: 

target->SetMaxVoxels(0); 

Placed before the command:

target->SetSolidClosed(true); 

Which provided a work around fix for the specific case of a G4TessellatedSolid described in the Detector Construction, by disabling voxelisation of the solid described.

Looking into the different setting for the maximum number voxels. It also seems to be "fixed" when setting the maximum number of voxels to an integer value from 1 to 15 inclusive. 


So the issue is the voxelisation of G4TessellatedSolid implemented in Geant4.9.6.1 causes problems when faced with hollow solids or solids with cavities.
Comment 1 tatiana.nikitina 2013-03-18 21:22:49 CET
Created attachment 210 [details]
Fix for G4TessellatedSolid in case of hollow solids.

Fix for G4TessellatedSolid in case of hollow solids.
Comment 2 tatiana.nikitina 2013-03-18 22:08:55 CET
Dear Alex,
Thank you for reporting this problem, the fix was found and will be available in next Geant4 release.
In attachments you can find the file with fix, this file has to replace G4TessellatedSolid.cc in your geant4/source/geometry/solids/specifics/src.

Best Rerards,
Tatiana.
----------------------------------------------
Here you can find the message from the developer of Voxelisation for TessellatedSolid, he found this fix.
Dear Alex,
 
I apologize for the time you have spent so far because of a bug in the code I have written. The bug was affecting tessellated solids with concave surfaces.
I managed to fix the code. Thank you for such a detailed and clear explanation of the problem as well as C++ code which helped us to locate the problem.
 
Best regards, Marek
Comment 3 alex_leatherland 2013-03-19 09:59:09 CET
Thankyou for the code fix. Could you pass my thanks on to Marek please?

Best Regards,

Alex