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 ENGINE_H 19 #define ENGINE_H 20 21 #include <fstream> 22 #include "operator.h" 23 24 namespace NS_Engine_Multithread 25 { 26 class thread; // evil hack to access numTS from multithreading context 27 } 28 29 class Engine_Extension; 30 31 class Engine 32 { 33 public: 34 enum EngineType 35 { 36 BASIC, SSE, UNKNOWN 37 }; 38 39 static Engine* New(const Operator* op); 40 virtual ~Engine(); 41 42 virtual void Init(); 43 virtual void Reset(); 44 45 //!Iterate a number of timesteps 46 virtual bool IterateTS(unsigned int iterTS); 47 GetNumberOfTimesteps()48 virtual unsigned int GetNumberOfTimesteps() {return numTS;} 49 50 //this access functions muss be overloaded by any new engine using a different storage model GetVolt(unsigned int n,unsigned int x,unsigned int y,unsigned int z)51 inline virtual FDTD_FLOAT GetVolt( unsigned int n, unsigned int x, unsigned int y, unsigned int z ) const { return volt[n][x][y][z]; } GetVolt(unsigned int n,const unsigned int pos[3])52 inline virtual FDTD_FLOAT GetVolt( unsigned int n, const unsigned int pos[3] ) const { return volt[n][pos[0]][pos[1]][pos[2]]; } GetCurr(unsigned int n,unsigned int x,unsigned int y,unsigned int z)53 inline virtual FDTD_FLOAT GetCurr( unsigned int n, unsigned int x, unsigned int y, unsigned int z ) const { return curr[n][x][y][z]; } GetCurr(unsigned int n,const unsigned int pos[3])54 inline virtual FDTD_FLOAT GetCurr( unsigned int n, const unsigned int pos[3] ) const { return curr[n][pos[0]][pos[1]][pos[2]]; } 55 SetVolt(unsigned int n,unsigned int x,unsigned int y,unsigned int z,FDTD_FLOAT value)56 inline virtual void SetVolt( unsigned int n, unsigned int x, unsigned int y, unsigned int z, FDTD_FLOAT value) { volt[n][x][y][z]=value; } SetVolt(unsigned int n,const unsigned int pos[3],FDTD_FLOAT value)57 inline virtual void SetVolt( unsigned int n, const unsigned int pos[3], FDTD_FLOAT value ) { volt[n][pos[0]][pos[1]][pos[2]]=value; } SetCurr(unsigned int n,unsigned int x,unsigned int y,unsigned int z,FDTD_FLOAT value)58 inline virtual void SetCurr( unsigned int n, unsigned int x, unsigned int y, unsigned int z, FDTD_FLOAT value) { curr[n][x][y][z]=value; } SetCurr(unsigned int n,const unsigned int pos[3],FDTD_FLOAT value)59 inline virtual void SetCurr( unsigned int n, const unsigned int pos[3], FDTD_FLOAT value ) { curr[n][pos[0]][pos[1]][pos[2]]=value; } 60 61 //! Execute Pre-Voltage extension updates 62 virtual void DoPreVoltageUpdates(); 63 //! Main FDTD engine voltage updates 64 virtual void UpdateVoltages(unsigned int startX, unsigned int numX); 65 //! Execute Post-Voltage extension updates 66 virtual void DoPostVoltageUpdates(); 67 //! Apply extension voltage changes 68 virtual void Apply2Voltages(); 69 70 //! Execute Pre-Current extension updates 71 virtual void DoPreCurrentUpdates(); 72 //! Main FDTD engine current updates 73 virtual void UpdateCurrents(unsigned int startX, unsigned int numX); 74 //! Execute Post-Current extension updates 75 virtual void DoPostCurrentUpdates(); 76 //! Apply extension current changes 77 virtual void Apply2Current(); 78 GetExtensionCount()79 inline size_t GetExtensionCount() {return m_Eng_exts.size();} GetExtension(size_t nr)80 inline Engine_Extension* GetExtension(size_t nr) {return m_Eng_exts.at(nr);} 81 virtual void SortExtensionByPriority(); 82 GetType()83 EngineType GetType() const {return m_type;} 84 85 protected: 86 EngineType m_type; 87 88 Engine(const Operator* op); 89 const Operator* Op; 90 91 unsigned int numLines[3]; 92 93 FDTD_FLOAT**** volt; 94 FDTD_FLOAT**** curr; 95 unsigned int numTS; 96 97 virtual void InitExtensions(); 98 virtual void ClearExtensions(); 99 vector<Engine_Extension*> m_Eng_exts; 100 101 friend class NS_Engine_Multithread::thread; // evil hack to access numTS from multithreading context 102 }; 103 104 #endif // ENGINE_H 105