00001 // BLElementField.hh 00002 /* 00003 This source file is part of G4beamline, http://g4beamline.muonsinc.com 00004 Copyright (C) 2003,2004,2005,2006 by Tom Roberts, all rights reserved. 00005 00006 This program is free software; you can redistribute it and/or 00007 modify it under the terms of the GNU General Public License 00008 as published by the Free Software Foundation; either version 2 00009 of the License, or (at your option) any later version. 00010 00011 This program is distributed in the hope that it will be useful, 00012 but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00014 GNU General Public License for more details. 00015 00016 http://www.gnu.org/copyleft/gpl.html 00017 */ 00018 00019 #ifndef BLELEMENTFIELD_HH 00020 #define BLELEMENTFIELD_HH 00021 00022 #include "globals.hh" 00023 00024 const G4double LARGE=9.0e99; 00025 00026 00027 /** class BLElementField - interface for the EM field of one element 00028 * 00029 * This is the interface class used by BLGlobalField to compute the field 00030 * value at a given point[]. 00031 * 00032 * An element command that represents an element with an EM field will 00033 * derive a class from this one and implement the computation for the 00034 * element. The construct() function of the element command class will add 00035 * the derived object into BLGlobalField. Such derived classes are 00036 * typically local to the file implementing the element command. 00037 **/ 00038 class BLElementField { 00039 BLElementField(const BLElementField&); // undefined 00040 BLElementField& operator=(const BLElementField&); // undefined 00041 protected: 00042 G4double minX, minY, minZ, maxX, maxY,maxZ; 00043 public: 00044 /// Constructor. 00045 BLElementField() 00046 { minX=minY=minZ=-LARGE; maxX=maxY=maxZ=LARGE; } 00047 00048 /// Destructor. 00049 virtual ~BLElementField() { } 00050 00051 /// setGlobalPoint() ensures that the point is within the global 00052 /// bounding box of this ElementField. global coordinates. 00053 /// Normally called 8 times for the corners of the local bounding 00054 /// box, after a local->global coordinate transform. 00055 /// If never called, the global bounding box is infinite. 00056 /// BEWARE: if called only once, the bounding box is just a point. 00057 void setGlobalPoint(const G4double point[4]) { 00058 if(minX == -LARGE || minX > point[0]) minX = point[0]; 00059 if(minY == -LARGE || minY > point[1]) minY = point[1]; 00060 if(minZ == -LARGE || minZ > point[2]) minZ = point[2]; 00061 if(maxX == LARGE || maxX < point[0]) maxX = point[0]; 00062 if(maxY == LARGE || maxY < point[1]) maxY = point[1]; 00063 if(maxZ == LARGE || maxZ < point[2]) maxZ = point[2]; 00064 } 00065 00066 /// isInBoundingBox() returns true if the point is within the 00067 /// global bounding box. global coordinates. 00068 bool isInBoundingBox(const G4double point[4]) const { 00069 if(point[2] < minZ || point[2] > maxZ) return false; 00070 if(point[0] < minX || point[0] > maxX) return false; 00071 if(point[1] < minY || point[1] > maxY) return false; 00072 return true; 00073 } 00074 00075 /// addFieldValue() will add the field value for this element to 00076 /// field[]. 00077 /// Implementations must be sure to verify that point[] is within 00078 /// the field region, and do nothing if not. 00079 /// point[] is in global coordinates and geant4 units; x,y,z,t. 00080 /// field[] is in geant4 units; Bx,By,Bz,Ex,Ey,Ez. 00081 /// For efficiency, the caller may (but need not) call 00082 /// isInBoundingBox(point), and only call this function if that 00083 /// returns true. 00084 virtual void addFieldValue(const G4double point[4], G4double field[6]) 00085 const = 0; 00086 }; 00087 00088 #endif // BLELEMENTFIELD_HH