Adding new surface types is relatively easy as well. If your geometry needs a surface that is not supported by Serpent (see Sec. 3.2.1 in the User's Manual for available surface types), the easiest and fastest way for me to add it in the code is that you provide the description of two routines either in "pseudo-code" or, more preferably, in C.

The first routine determines whether an arbitrary point (x,y,z) is inside the boundary or not. For example, for a cube centered at (x0,y0,z0) with half-width r, this routine could be written as:

- Code: Select all
`if ((x - x0 > r) || (x - x0 < -r) || (y - y0 > r) || (y - y0 < -r)|| (z - z0 > r) || (z - z0 < -r))`

return 0;

else

return 1;

Return value 0 indicates that the point is out and return value 1 that the point is in.

The second routine is a bit more complicated, and it determines the shortest possible distance to the boundary in an arbitrary direction (u,v,w). For the same cube this routine could be written as:

- Code: Select all
`min = INFTY;`

if (u != 0.0)

{

if (((d = -(x - x0 - r)/u) > 0.0) && (d < min))

min = d;

if (((d = -(x - x0 + r)/u) > 0.0) && (d < min))

min = d;

}

if (v != 0.0)

{

if (((d = -(y - y0 - r)/v) > 0.0) && (d < min))

min = d;

if (((d = -(y - y0 + r)/v) > 0.0) && (d < min))

min = d;

}

if (w != 0.0)

{

if (((d = -(z - z0 - r)/w) > 0.0) && (d < min))

min = d;

if (((d = -(z - z0 + r)/w) > 0.0) && (d < min))

min = d;

}

return min;

Notice that the returned distance doesn't have to be the actual shortest distance. It is sufficient that it is not longer than the shortest distance. In the cube example, if point (x,y,z) is outside the cube, the routine may actually find an intersection on one of the six planes that make up the cube, but also extend over the actual boundaries. This is not a problem, as long as none of the surfaces is ever missed.