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

A tetrahedral mesh geometry. More...

#include <egs_mesh.h>

Inheritance diagram for EGS_Mesh:
EGS_BaseGeometry

Classes

struct  Nodes
 

Public Member Functions

 EGS_Mesh (EGS_MeshSpec spec)
 
 EGS_Mesh (const EGS_Mesh &)=delete
 
EGS_Meshoperator= (const EGS_Mesh &)=delete
 
 EGS_Mesh (EGS_Mesh &&)
 
EGS_Meshoperator= (EGS_Mesh &&)
 
int num_elements () const
 Returns the number of mesh elements.
 
int num_nodes () const
 Returns the number of unique mesh nodes.
 
const std::array< int, 4 > & element_neighbours (int i) const
 
EGS_Float element_volume (int i) const
 Returns the volume in cm3 of element i.
 
EGS_Float element_density (int i) const
 Returns the density in g/cm3 of element i.
 
int element_tag (int i) const
 
bool is_boundary (int reg) const
 
void printElement (int i, std::ostream &elt_info=std::cout) const
 Print information about element i to the stream elt_info.
 
const std::string & getType () const override
 
bool isInside (const EGS_Vector &x) override
 
int inside (const EGS_Vector &x) override
 
int medium (int ireg) const override
 
int isWhere (const EGS_Vector &x) override
 
int howfar (int ireg, const EGS_Vector &x, const EGS_Vector &u, EGS_Float &t, int *newmed=0, EGS_Vector *normal=0) override
 
EGS_Float hownear (int ireg, const EGS_Vector &x) override
 
void printInfo () const override
 
bool insideElement (int i, const EGS_Vector &x)
 Check if a point x is inside element i.
 
Nodes element_nodes (int element) const
 Given an element offset, return the element's node coordinates.
 
const EGS_Vectornode_coordinates (int node_offset) const
 
const std::array< int, 4 > & element_node_offsets (int element) const
 Given an element offset, return its four node offsets.
 
- Public Member Functions inherited from EGS_BaseGeometry
 EGS_BaseGeometry (const string &Name)
 Construct a geometry named Name. More...
 
virtual ~EGS_BaseGeometry ()
 Destructor. More...
 
bool isConvex () const
 Is the geometry convex? More...
 
virtual EGS_Float howfarToOutside (int ireg, const EGS_Vector &x, const EGS_Vector &u)
 
virtual EGS_Float getVolume (int ireg)
 Calculates the volume of region ireg. More...
 
virtual EGS_Float getBound (int idir, int ind)
 Returns region boundaries in direction determined by idir. More...
 
virtual int getNRegDir (int idir)
 
int regions () const
 Returns the number of local regions in this geometry. More...
 
virtual bool isRealRegion (int ireg) const
 Returnes true if ireg is a real region, false otherwise. More...
 
virtual int getMaxStep () const
 Returns the maximum number of steps through the geometry. More...
 
virtual int computeIntersections (int ireg, int n, const EGS_Vector &x, const EGS_Vector &u, EGS_GeometryIntersections *isections)
 Calculates intersection distances to region boundaries. More...
 
void setMedium (const string &Name)
 Set all regions to a medium with name Name. More...
 
void setMedium (int start, int end, const string &Name, int delta=1)
 Set every delta'th region between start and end to the medium named Name. More...
 
void setMedium (int imed)
 Set all regions to a medium with index imed. More...
 
void setMedium (int istart, int iend, int imed, int delta=1)
 Set every delta'th region between start and end (inclusive) to imed. More...
 
void setMedia (EGS_Input *inp)
 Set the media in the geometry from the input pointed to by inp. More...
 
bool hasRhoScaling () const
 Does this geometry object have a mass density scaling feature? More...
 
virtual EGS_Float getRelativeRho (int ireg) const
 Get the relative mass density in region ireg. More...
 
virtual void setRelativeRho (int start, int end, EGS_Float rho)
 Set the relative mass density in regions. More...
 
virtual void setRelativeRho (EGS_Input *)
 Set the relative mass density from an user input. More...
 
EGS_Float getMediumRho (int ind) const
 
virtual void setApplication (EGS_Application *app)
 
bool hasBScaling () const
 Does this geometry object have a B field scaling feature?
 
virtual EGS_Float getBScaling (int ireg) const
 Get the B field scaling factor in region ireg.
 
virtual void setBScaling (int start, int end, EGS_Float bf)
 Set the B field scaling factor in regions. More...
 
virtual void setBScaling (EGS_Input *)
 Set the B field scaling factor from an user input. More...
 
const string & getName () const
 Get the name of this geometry. More...
 
void setDebug (bool deb)
 Turn debugging on. More...
 
void setName (EGS_Input *inp)
 Set the name of the geometry from the input inp. More...
 
void setBoundaryTolerance (EGS_Input *inp)
 Set the value of the boundary tolerance from the input inp. More...
 
void setBoundaryTolerance (EGS_Float tol)
 Set the value of the boundary tolerance from argument.
 
virtual bool hasBooleanProperty (int ireg, EGS_BPType prop) const
 Is the boolean property prop set for region ireg ?
 
virtual void setBooleanProperty (EGS_BPType prop)
 Set the boolean properties of the entire geometry to prop. More...
 
virtual void addBooleanProperty (int bit)
 Add a boolean property for the entire geometry by setting the bit'th bit. More...
 
virtual void setBooleanProperty (EGS_BPType prop, int start, int end, int step=1)
 Set the boolean properties of every step'th region between start and end (inclusive) to prop. More...
 
virtual void addBooleanProperty (int bit, int start, int end, int step=1)
 Add a boolean property to every step'th region between start and end (inclusive) by setting the bit'th bit. More...
 
int ref ()
 Increase the reference count to this geometry. More...
 
int deref ()
 Decrease the reference count to this geometry. More...
 
EGS_Float getBoundaryTolerance ()
 Get the value of the boundary tolerance.
 
virtual void getNumberRegions (const string &str, vector< int > &regs)
 Get a list of all the regions labeled with a number.
 
virtual void getLabelRegions (const string &str, vector< int > &regs)
 Get the list of all regions labeled with str.
 
virtual const string & getLabelName (const int i)
 Get the name of the i-th explicit label in the geometry.
 
virtual int getLabelCount ()
 Get the number of explicit labels in the geometry.
 
int setLabels (EGS_Input *input)
 Set the labels from an input block.
 
int setLabels (const string &inp)
 Set the labels from an input string.
 

Static Public Member Functions

static EGS_Float get_min_step_size ()
 Returns the minimum step size (i.e. the fuzzy plane tolerance).
 
- Static Public Member Functions inherited from EGS_BaseGeometry
static int findRegion (EGS_Float xp, int np, const EGS_Float *p)
 Find the bin to which xp belongs, given np bin edges p. More...
 
static int nMedia ()
 Get the number of media registered so far by all geometries. More...
 
static const char * getMediumName (int ind)
 Get the name of medium with index ind. More...
 
static int addMedium (const string &medname)
 Add a medium or get the index of an existing medium. More...
 
static int getMediumIndex (const string &medname)
 Get the index of a medium named medname. More...
 
static EGS_BaseGeometrycreateGeometry (EGS_Input *)
 Create a geometry (or geometries) from a given input. More...
 
static EGS_BaseGeometrycreateSingleGeometry (EGS_Input *inp)
 Create a single geometry from the input inp. More...
 
static void clearGeometries ()
 Clears (deletes) all geometries in the currently active geometry list. More...
 
static EGS_BaseGeometrygetGeometry (const string &Name)
 Get a pointer to the geometry named Name. More...
 
static EGS_BaseGeometry ** getGeometries ()
 
static int getNGeometries ()
 
static string getUniqueName ()
 Get a unique geometry name. More...
 
static void describeGeometries ()
 Describes all existing geometries. More...
 
static void setActiveGeometryList (int list)
 Set the currently active geometry list. More...
 
static int getLastError ()
 
static void resetErrorFlag ()
 

Additional Inherited Members

- Protected Member Functions inherited from EGS_BaseGeometry
virtual void setMedia (EGS_Input *inp, int nmed, const int *med_ind)
 Set media. More...
 
- Protected Attributes inherited from EGS_BaseGeometry
int nreg
 Number of local regions in this geometry. More...
 
string name
 Name of this geometry. More...
 
short * region_media
 Array of media indeces. More...
 
int med
 Medium index. More...
 
bool has_rho_scaling
 Does this geometry have relative mass density scvaling? More...
 
EGS_Float * rhor
 Array with relative mass densities. More...
 
bool has_B_scaling
 Does this geometry has B field scaling factor? More...
 
bool has_Ref_rho
 
EGS_Float * bfactor
 Array with B field scaling factors. More...
 
EGS_Float rhoRef
 Reference density for B field scaling. More...
 
int nref
 Number of references to this geometry. More...
 
bool debug
 Debugging flag. More...
 
bool is_convex
 Is this geometry convex? More...
 
EGS_BPType bproperty
 A bit mask of boolean properties for the entire geometry. More...
 
EGS_BPType * bp_array
 An array of boolean properties on a region by region basis. More...
 
EGS_Float boundaryTolerance
 Boundary tolerance for geometries that need it.
 
EGS_Float halfBoundaryTolerance
 
vector< labellabels
 Labels. More...
 
EGS_Applicationapp
 The application this object belongs to.
 
- Static Protected Attributes inherited from EGS_BaseGeometry
static int error_flag = 0
 Set to non-zero status if a geometry problem is encountered.
 

Detailed Description

A tetrahedral mesh geometry.

The EGS_Mesh class implements an unstructured tetrahedral mesh. Mesh data and element media names are specified using a mesh file. The supported mesh formats are:

:start geometry definition:
    :start geometry:
        name        = my_mesh
        library     = egs_mesh
        # Using the msh4.1 format:
        file        = model.msh
        # or, using the TetGen format:
        # file       = model.node # or model.ele
    :stop geometry:

    simulation geometry = my_mesh
:stop geometry definition:

Generally, meshes should be enclosed in an envelope so particles that exit the mesh and reenter (for example, if there's a cutout feature in the mesh) are simulated correctly and not terminated immediately after initially exiting the mesh.

:start geometry definition:
    :start geometry:
        name = my_mesh
        library = egs_mesh
        file = model.msh
    :stop geometry:

    # define a 50cm vacuum cube at the origin
    :start geometry:
        library = egs_box
        name = my_box
        box size = 50 50 50
        :start media input:
            media = vacuum
        :stop media input:
    :stop geometry:

    # embed the mesh in the vacuum box
    :start geometry:
        library = egs_genvelope
        name = my_envelope
        base geometry = my_box
        inscribed geometries = my_mesh
    :stop geometry:

    simulation geometry = my_envelope
:stop geometry definition:

Mesh node coordinates are assumed to be in cm. If you need to scale the input mesh (e.g. if the mesh file uses mm) you can use the scale key in the egsinp file:

:start geometry definition:
    :start geometry:
        name = my_mesh
        library = egs_mesh
        file = model.msh
        scale = 0.1         # multiply all node coordinates by 0.1
    :stop geometry:

    simulation geometry = my_mesh
:stop geometry definition:

Definition at line 242 of file egs_mesh.h.

Constructor & Destructor Documentation

EGS_Mesh::EGS_Mesh ( EGS_MeshSpec  spec)
explicit

Create a new EGS_Mesh from raw mesh data spec. Throws a std::runtime_error if construction fails for any reason.

Definition at line 944 of file egs_mesh.cpp.

References EGS_MeshSpec::checkValid(), EGS_MeshSpec::elements, EGS_MeshSpec::media, and EGS_MeshSpec::nodes.

Member Function Documentation

const std::array<int, 4>& EGS_Mesh::element_neighbours ( int  i) const

Returns the four neighbour element offsets of element i. For faces without neighbours, the array entry is -1.

Definition at line 271 of file egs_mesh.h.

int EGS_Mesh::element_tag ( int  i) const

Returns the tag of element i. This is an arbitrary number from the input mesh file.

Definition at line 288 of file egs_mesh.h.

bool EGS_Mesh::is_boundary ( int  reg) const

Returns true if the element reg is a boundary element, i.e. doesn't have neighbours for at least one face. Returns false if the element has all four neighbours.

Definition at line 295 of file egs_mesh.h.

const EGS_Vector& EGS_Mesh::node_coordinates ( int  node_offset) const

Given a node offset (from 0 to EGS_Mesh::num_nodes() - 1), returns the node coordinates.

Definition at line 376 of file egs_mesh.h.


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