1 /* 2 * Copyright (C) 2010 Thorsten Liebig (Thorsten.Liebig@gmx.de) 3 * 4 * This program is free software: you can redistribute it and/or modify 5 * it under the terms of the GNU General Public License as published by 6 * the Free Software Foundation, either version 3 of the License, or 7 * (at your option) any later version. 8 * 9 * This program is distributed in the hope that it will be useful, 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 * GNU General Public License for more details. 13 * 14 * You should have received a copy of the GNU General Public License 15 * along with this program. If not, see <http://www.gnu.org/licenses/>. 16 */ 17 18 #ifndef OPERATOR_BASE_H 19 #define OPERATOR_BASE_H 20 21 #include "ContinuousStructure.h" 22 #include "tools/global.h" 23 #include "Common/processing.h" 24 #include "string" 25 26 typedef struct 27 { 28 std::vector<unsigned int> posPath[3]; 29 std::vector<unsigned short> dir; 30 } Grid_Path; 31 32 //! Abstract base-class for a common operator 33 class Operator_Base 34 { 35 public: 36 virtual ~Operator_Base(); 37 38 virtual bool SetGeometryCSX(ContinuousStructure* geo); GetGeometryCSX()39 virtual ContinuousStructure* GetGeometryCSX() const {return CSX;} 40 41 //! Get the timestep used by this operator GetTimestep()42 virtual double GetTimestep() const {return dT;} 43 44 //! Get the number of cells or nodes defined by this operator 45 virtual double GetNumberCells() const =0; 46 47 //! Get the number of timesteps satisfying the nyquist condition (may depend on the excitation) 48 virtual unsigned int GetNumberOfNyquistTimesteps() const =0; 49 50 //! Returns the number of lines as needed for post-processing etc. 51 virtual unsigned int GetNumberOfLines(int ny, bool full=false) const =0; 52 53 //! Get the name for the given direction: 0 -> x, 1 -> y, 2 -> z 54 virtual std::string GetDirName(int ny) const; 55 56 //! Get the grid drawing unit in m 57 virtual double GetGridDelta() const =0; 58 59 //! Get the disc line in \a n direction (in drawing units) 60 virtual double GetDiscLine(int n, unsigned int pos, bool dualMesh=false) const =0; 61 62 //! Get the disc line delta in \a n direction (in drawing units) 63 virtual double GetDiscDelta(int n, unsigned int pos, bool dualMesh=false) const =0; 64 65 //! Get the node width for a given direction \a n and a given mesh position \a pos 66 virtual double GetNodeWidth(int ny, const unsigned int pos[3], bool dualMesh = false) const =0; 67 68 //! Get the node area for a given direction \a n and a given mesh position \a pos 69 virtual double GetNodeArea(int ny, const unsigned int pos[3], bool dualMesh = false) const =0; 70 71 //! Get the length of an FDTD edge (unit is meter). 72 virtual double GetEdgeLength(int ny, const unsigned int pos[3], bool dualMesh = false) const =0; 73 74 //! Get the area around an edge for a given direction \a n and a given mesh posisition \a pos 75 /*! 76 This will return the area around an edge with a given direction, measured at the middle of the edge. 77 In a cartesian mesh this is equal to the NodeArea, may be different in other coordinate systems. 78 */ 79 virtual double GetEdgeArea(int ny, const unsigned int pos[3], bool dualMesh = false) const =0; 80 81 //! Get the volume of an FDTD cell 82 virtual double GetCellVolume(const unsigned int pos[3], bool dualMesh = false) const =0; 83 84 //! Snap the given coodinates to mesh indices, return box dimension 85 virtual bool SnapToMesh(const double* coord, unsigned int* uicoord, bool dualMesh=false, bool fullMesh=false, bool* inside=NULL) const =0; 86 87 //! Snap a given box to the operator mesh, uiStart will be always <= uiStop 88 /*! 89 \param[in] start the box-start coorindate 90 \param[in] stop the box-stopt coorindate 91 \param[out] uiStart the snapped box-start coorindate index 92 \param[out] uiStop the snapped box-stop coorindate index 93 \param[in] dualMesh snap to main or dual mesh (default is main mesh) 94 \param[in] SnapMethod Snapping method, 0=snap to closest line, 1/(2)=snap such that given box is inside (outside) the snapped lines 95 \return returns the box dimension or -1 if box is not inside the simulation domain 96 */ 97 virtual int SnapBox2Mesh(const double* start, const double* stop, unsigned int* uiStart, unsigned int* uiStop, bool dualMesh=false, bool fullMesh=false, int SnapMethod=0, bool* bStartIn=NULL, bool* bStopIn=NULL) const =0; 98 99 //! Set the boundary conditions SetBoundaryCondition(int * BCs)100 virtual void SetBoundaryCondition(int* BCs) {for (int n=0; n<6; ++n) m_BC[n]=BCs[n];} 101 102 //! Set flags to store material data for post-processing 103 virtual void SetMaterialStoreFlags(int type, bool val); 104 105 //! Check storage flags and cleanup 106 virtual void CleanupMaterialStorage() = 0; 107 108 //! Get stored discrete material (if storage is enabled). 109 virtual double GetDiscMaterial(int type, int ny, const unsigned int pos[3]) const = 0; 110 111 //! Get the cell center coordinate usable for material averaging (Warning, may not be the yee cell center) 112 bool GetCellCenterMaterialAvgCoord(const unsigned int pos[3], double coord[3]) const; 113 114 //! Get the cell center coordinate usable for material averaging (Warning, may not be the yee cell center) 115 virtual bool GetCellCenterMaterialAvgCoord(const int pos[3], double coord[3]) const = 0; 116 117 virtual std::vector<CSPrimitives*> GetPrimitivesBoundBox(int posX, int posY, int posZ, CSProperties::PropertyType type=CSProperties::ANY) const = 0; 118 119 //! Set the background material (default is vacuum) 120 virtual void SetBackgroundMaterial(double epsR=0, double mueR=0, double kappa=0, double sigma=0, double density=0); 121 122 //! Get background rel. electric permittivity GetBackgroundEpsR()123 double GetBackgroundEpsR() const {return m_BG_epsR;} 124 //! Set background rel. electric permittivity 125 void SetBackgroundEpsR(double val); 126 127 //! Get background rel. magnetic permeability GetBackgroundMueR()128 double GetBackgroundMueR() const {return m_BG_mueR;} 129 //! Set background rel. magnetic permeability 130 void SetBackgroundMueR(double val); 131 132 //! Get background electric conductivity GetBackgroundKappa()133 double GetBackgroundKappa() const {return m_BG_kappa;} 134 //! Set background electric conductivity 135 void SetBackgroundKappa(double val); 136 137 //! Get background magnetic conductivity (artificial) GetBackgroundSigma()138 double GetBackgroundSigma() const {return m_BG_sigma;} 139 //! Set background magnetic conductivity (artificial) 140 void SetBackgroundSigma(double val); 141 142 //! Get background mass density GetBackgroundDensity()143 double GetBackgroundDensity() const {return m_BG_density;} 144 //! Set background mass density 145 void SetBackgroundDensity(double val); 146 147 protected: 148 Operator_Base(); 149 150 ContinuousStructure* CSX; 151 152 virtual void Init(); 153 //! Cleanup data and reset 154 void Delete(); 155 virtual void Reset(); 156 157 //! boundary conditions 158 int m_BC[6]; 159 160 //! The operator timestep 161 double dT; 162 163 //! bool flag array to store material data for post-processing 164 bool m_StoreMaterial[4]; 165 166 //! background materials 167 double m_BG_epsR; 168 double m_BG_mueR; 169 double m_BG_kappa; 170 double m_BG_sigma; 171 double m_BG_density; 172 173 CoordinateSystem m_MeshType; 174 unsigned int numLines[3]; 175 double* discLines[3]; 176 double gridDelta; 177 }; 178 179 #endif // OPERATOR_BASE_H 180