EGSnrc C++ class library  Report PIRS-898 (2021)
Iwan Kawrakow, Ernesto Mainegra-Hing, Frederic Tessier, Reid Townson and Blake Walters
Public Member Functions | Static Public Member Functions | Protected Attributes | List of all members
EGS_GeometryTester Class Reference

A class for testing geometries. More...

#include <egs_geometry_tester.h>

Public Member Functions

 EGS_GeometryTester (EGS_Input *)
 Construct a geometry tester from an input tree.
 
virtual ~EGS_GeometryTester ()
 Destructor.
 
void testInside (EGS_BaseGeometry *g)
 Performs an inside test. More...
 
void testInsideTime (EGS_BaseGeometry *)
 Performs an inside time test. More...
 
void testHownear (int ntry, EGS_BaseGeometry *g)
 Performs a hownear test. More...
 
void testHownearTime (EGS_BaseGeometry *)
 Performs a hownear time test. More...
 
void testHowfar (EGS_BaseGeometry *)
 Performs a howfar test. More...
 
void testHowfarTime (EGS_BaseGeometry *)
 Performs a howfar time test. More...
 
virtual void printPosition (const EGS_Vector &x)
 Outputs the position x to a file. More...
 

Static Public Member Functions

static EGS_GeometryTestergetGeometryTester (EGS_Input *i)
 Creates a geometry tester object from the input i. More...
 

Protected Attributes

EGS_PrivateTester * p
 Hides the implementation details.
 

Detailed Description

A class for testing geometries.

This class can perform various tests on a geometry object, which is useful in the development process of new geometry classes. The various tests available are described in the documentation of the testing functions testInside(), testInsideTime(), testHowfar(), testHowfarTime(), testHownear(), and testHownearTime(). As the geometry to be tested will be typically defined via an input file, we use the same input file to also specify the tests to be run => EGS_GeometryTester::EGS_GeometryTester(EGS_Input *) is the only constructor defined so far. This class can be used by external developers to test their own geometries => we hide the implementation in the class EGS_PrivateTester to demonstrate good coding practices. The input needed to perform a set of tests on a geometry is discussed in the getGeometryTester() documentation. The file test_geometry.cpp has a simple main program for performing a geometry test. and is compiled and linked against the main egspp library when building the library to create a geometry testing utility called gtest (gtest.exe on Windows). One uses it by executing

gtest input_file

where input_file is the name of a file (including absoulute path, if not in the local directory) specifying a geometry and the tests to be performed on the geometry.

Definition at line 77 of file egs_geometry_tester.h.

Member Function Documentation

void EGS_GeometryTester::testInside ( EGS_BaseGeometry g)

Performs an inside test.

For a given number of trials (specified in the input file), generates a random point within a bounding shape (specified in the input file) and tests if the point is inside the geometry g using the inside() method. Prints the point to a file using the printPosition() function, if the point is inside the geometry g. If one plots the resulting data file with some 3D capable plotting program, one can verify by visual inspection that the inside() method of the geometry does what it is supposed to do. An inside test is requested by including

:start inside test:
    :start bounding shape:
        type = box
        box size = 16
    :stop bounding shape:
    ntest = 10000
    file name = box_test.inside
:stop inside test:

into the geometry tester definition in an input file (see getGeometryTester()). Any shape available can be used to create the points, not just a box as in the above example (see Shapes).

Definition at line 128 of file egs_geometry_tester.cpp.

void EGS_GeometryTester::testInsideTime ( EGS_BaseGeometry g)

Performs an inside time test.

Same as the above function, but now inside points are not printed to a file. Instead, the number of inside points is counted and the CPU time necessary to perform the given number of inside calls is measured. This test method may be useful to test the speed of alternative inside() implementations. An inside time test is specified in the same way in the input file as the inside test, except that now the file name input is not needed (and ignored, if present) as no output is generated.

Definition at line 132 of file egs_geometry_tester.cpp.

void EGS_GeometryTester::testHownear ( int  ntry,
EGS_BaseGeometry g 
)

Performs a hownear test.

For a given number of points x within a bounding shape calls the hownear(x) method of the geometry g. Picks ntry random points at a distance hownear() from x. For each of these new ntry points checks if they are in the same region using inside(). If the hownear() method works properly, all such points should be inside the same region => prints points where this condition is not satisfied to a file so that the developer can check if and where the hownear() method is failing. A hownear test is specified in the same way as the inside test in the input file, except that the input is between :start hownear test: :stop nownear test:

Definition at line 136 of file egs_geometry_tester.cpp.

void EGS_GeometryTester::testHownearTime ( EGS_BaseGeometry g)

Performs a hownear time test.

Measures the time to do a certain number of hownear() calls in a way similar to the previous function but without generating output of failing points. A hownear time test is specified in the same way as the inside test in the input file, except that the input is between :start hownear time test: :stop nownear time test: and the file name key is not needed.

Definition at line 140 of file egs_geometry_tester.cpp.

void EGS_GeometryTester::testHowfar ( EGS_BaseGeometry g)

Performs a howfar test.

For a given number of trials (specified in the input file), generates a random point x within a bounding shape (specified in the input file) and a random direction u. Determines all intersection points of the line x + u*t with the various regions of the geometry and prints these intersection points to a file using printPosition(). Visual inspection of the plot generated from the data should be useful to determine if the howfar() geometry method is doing what it is supposed to do. A howfar test is specified in the same way as the inside test in the input file, except that the input is between :start howfar test: :stop nowfar test:

Definition at line 144 of file egs_geometry_tester.cpp.

void EGS_GeometryTester::testHowfarTime ( EGS_BaseGeometry g)

Performs a howfar time test.

Same as the above function but now intersection points are not printed to a file. Instead, the CPU time needed to perform the given number of howfar() calls is measured. This may be useful to test the speed of alternative howfar() implementations. A howfar time test is specified in the same way as the inside test in the input file, except that the input is between :start howfar time test: :stop nowfar time test: and the file name key is not needed.

Definition at line 148 of file egs_geometry_tester.cpp.

void EGS_GeometryTester::printPosition ( const EGS_Vector x)
virtual

Outputs the position x to a file.

This function is called from the various testing methods to print the position x to a file. Its default implementation is to just print the 3 coordinates of x. It is declared virtual so that one can overwrite it with alternative implementations, e.g. print x.z and sqrt(x.x*x.x + x.y*x.y) when testing cylindrical geometries, etc.

Definition at line 152 of file egs_geometry_tester.cpp.

References EGS_Vector::x, EGS_Vector::y, and EGS_Vector::z.

EGS_GeometryTester * EGS_GeometryTester::getGeometryTester ( EGS_Input i)
static

Creates a geometry tester object from the input i.

This static function can be used to obtain a pointer to a EGS_GeometryTester object constructed from the specifications in the input pointed to by i.The input required to create a geometry tester is

:start geometry tester:
    output type = normal or spherical or cylindrical or transformed
    :start some test:
        definition of a test
    :stop some test:
    :start some_other test:
        definition of a test
    :stop some_other test:
    ...
:stop geometry tester:

In the above some or some_other stands for one of the possible tests (inside, inside time, howfar, howfar time, hownear, hownear time). The output type key is optional and results in a "normal" output, if missing. The type of output determines how the positions of the points in the various tests are written to the file:

  • normal: write a triplet with x-, y- and z-position
  • spherical: In this case an optional midpoint key can be used to specify the midpoint of the sphere. The output produced is $x'_z, \sqrt{x_x^{\prime 2} + x_y^{\prime 2}}$, where $\vec{x}' = \vec{x} - \vec{x}_0$ is the position in the frame with origin coinciding with the sphere midpoint. This type of output us useful, for instance, to more easily check that the howfar intersections are on a spherical surface.
  • cylindrical: In this case one must input an axis key specifying the cylinder axis. The output produced will be $x'_z, \sqrt{x_x^{\prime 2} + x_y^{\prime 2}}$, where $\vec{x}'$ is the particle position in a frame where the z-axis coincides with the cylinder axis. This is useful, for instance, to more easily check that the howfar intersections are on a cylindrical or conical surface
  • transformed: in this case one must specify an affine transformation in the inpout (see EGS_AffineTransform::getTransformation()) and the position will be transformed before being output to the file.

Definition at line 573 of file egs_geometry_tester.cpp.

References EGS_Input::compare(), EGS_BaseShape::createShape(), egsWarning, EGS_Input::getInput(), EGS_AffineTransform::getTransformation(), EGS_Input::isA(), and EGS_Input::takeInputItem().


The documentation for this class was generated from the following files: