2010-03-11 23:47:40 +08:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2010 Thorsten Liebig (Thorsten.Liebig@gmx.de)
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2010-03-01 16:19:39 +08:00
|
|
|
#ifndef OPERATOR_H
|
|
|
|
#define OPERATOR_H
|
|
|
|
|
|
|
|
#include "tools/AdrOp.h"
|
|
|
|
#include "tools/constants.h"
|
2010-05-04 00:33:14 +08:00
|
|
|
#include "excitation.h"
|
2010-12-06 16:59:42 +08:00
|
|
|
#include "Common/operator_base.h"
|
2010-03-01 16:19:39 +08:00
|
|
|
|
2010-04-26 03:59:05 +08:00
|
|
|
class Operator_Extension;
|
2010-05-09 00:12:44 +08:00
|
|
|
class Engine;
|
2010-08-19 16:13:03 +08:00
|
|
|
class TiXmlElement;
|
2010-04-26 03:59:05 +08:00
|
|
|
|
2010-12-07 21:47:22 +08:00
|
|
|
//! Basic FDTD-operator
|
2010-12-06 16:59:42 +08:00
|
|
|
class Operator : public Operator_Base
|
2010-03-01 16:19:39 +08:00
|
|
|
{
|
2010-05-07 04:55:59 +08:00
|
|
|
friend class Engine;
|
2011-01-07 23:12:07 +08:00
|
|
|
friend class Engine_Interface_FDTD;
|
2010-07-06 16:01:26 +08:00
|
|
|
friend class Operator_Ext_LorentzMaterial; //we need to find a way around this... friend class Operator_Extension only would be nice
|
2010-07-16 23:25:32 +08:00
|
|
|
friend class Operator_Ext_PML_SF_Plane;
|
2011-03-16 23:26:01 +08:00
|
|
|
friend class Operator_Ext_Excitation;
|
2011-03-18 21:17:09 +08:00
|
|
|
friend class Operator_Ext_UPML;
|
|
|
|
friend class Operator_Ext_Cylinder;
|
2010-12-06 20:04:37 +08:00
|
|
|
public:
|
2010-10-27 17:17:58 +08:00
|
|
|
enum DebugFlags {None=0,debugMaterial=1,debugOperator=2,debugPEC=4};
|
|
|
|
|
2010-04-09 21:51:37 +08:00
|
|
|
//! Create a new operator
|
|
|
|
static Operator* New();
|
2010-03-01 16:19:39 +08:00
|
|
|
virtual ~Operator();
|
|
|
|
|
2010-05-10 02:27:17 +08:00
|
|
|
virtual Engine* CreateEngine() const;
|
2010-05-09 00:12:44 +08:00
|
|
|
|
2010-03-11 17:48:47 +08:00
|
|
|
virtual bool SetGeometryCSX(ContinuousStructure* geo);
|
2010-03-01 16:19:39 +08:00
|
|
|
|
2010-10-27 20:49:16 +08:00
|
|
|
virtual int CalcECOperator( DebugFlags debugFlags = None );
|
2010-03-01 16:19:39 +08:00
|
|
|
|
2010-08-19 16:13:03 +08:00
|
|
|
virtual bool SetupExcitation(TiXmlElement* Excite, unsigned int maxTS) {return Exc->setupExcitation(Excite,maxTS);};
|
|
|
|
|
2011-03-08 20:35:38 +08:00
|
|
|
virtual void DumpExciationSignals();
|
|
|
|
|
2010-10-20 13:26:16 +08:00
|
|
|
// the next four functions need to be reimplemented in a derived class
|
|
|
|
inline virtual FDTD_FLOAT GetVV( unsigned int n, unsigned int x, unsigned int y, unsigned int z ) const { return vv[n][x][y][z]; }
|
|
|
|
inline virtual FDTD_FLOAT GetVI( unsigned int n, unsigned int x, unsigned int y, unsigned int z ) const { return vi[n][x][y][z]; }
|
|
|
|
inline virtual FDTD_FLOAT GetII( unsigned int n, unsigned int x, unsigned int y, unsigned int z ) const { return ii[n][x][y][z]; }
|
|
|
|
inline virtual FDTD_FLOAT GetIV( unsigned int n, unsigned int x, unsigned int y, unsigned int z ) const { return iv[n][x][y][z]; }
|
2010-05-01 01:40:08 +08:00
|
|
|
|
2010-10-27 17:17:58 +08:00
|
|
|
// convenient access functions
|
|
|
|
inline virtual FDTD_FLOAT GetVV( unsigned int n, unsigned int pos[3] ) const { return GetVV(n,pos[0],pos[1],pos[2]); }
|
|
|
|
inline virtual FDTD_FLOAT GetVI( unsigned int n, unsigned int pos[3] ) const { return GetVI(n,pos[0],pos[1],pos[2]); }
|
|
|
|
inline virtual FDTD_FLOAT GetII( unsigned int n, unsigned int pos[3] ) const { return GetII(n,pos[0],pos[1],pos[2]); }
|
|
|
|
inline virtual FDTD_FLOAT GetIV( unsigned int n, unsigned int pos[3] ) const { return GetIV(n,pos[0],pos[1],pos[2]); }
|
|
|
|
|
2010-10-20 13:26:16 +08:00
|
|
|
// the next four functions need to be reimplemented in a derived class
|
|
|
|
inline virtual void SetVV( unsigned int n, unsigned int x, unsigned int y, unsigned int z, FDTD_FLOAT value ) { vv[n][x][y][z] = value; }
|
|
|
|
inline virtual void SetVI( unsigned int n, unsigned int x, unsigned int y, unsigned int z, FDTD_FLOAT value ) { vi[n][x][y][z] = value; }
|
|
|
|
inline virtual void SetII( unsigned int n, unsigned int x, unsigned int y, unsigned int z, FDTD_FLOAT value ) { ii[n][x][y][z] = value; }
|
|
|
|
inline virtual void SetIV( unsigned int n, unsigned int x, unsigned int y, unsigned int z, FDTD_FLOAT value ) { iv[n][x][y][z] = value; }
|
2010-05-01 01:40:08 +08:00
|
|
|
|
2010-03-05 21:20:25 +08:00
|
|
|
virtual void ApplyElectricBC(bool* dirs); //applied by default to all boundaries
|
|
|
|
virtual void ApplyMagneticBC(bool* dirs);
|
2010-03-01 16:19:39 +08:00
|
|
|
|
2010-08-19 16:12:09 +08:00
|
|
|
//! Set a forced timestep to use by the operator
|
|
|
|
virtual void SetTimestep(double ts) {dT = ts;}
|
2010-09-08 22:07:28 +08:00
|
|
|
bool GetTimestepValid() const {return !m_InvaildTimestep;}
|
2010-09-08 13:36:32 +08:00
|
|
|
virtual double GetNumberCells() const;
|
2010-03-01 21:56:27 +08:00
|
|
|
|
2010-12-07 21:47:22 +08:00
|
|
|
virtual unsigned int GetNumberOfNyquistTimesteps() const {return Exc->GetNyquistNum();}
|
|
|
|
|
|
|
|
virtual unsigned int GetNumberOfLines(int ny) const {return numLines[ny];}
|
2010-12-06 16:59:42 +08:00
|
|
|
|
|
|
|
//! Returns the number of lines as needed for the engine etc. (for post-processing etc, use GetNumLines())
|
2010-05-10 02:27:17 +08:00
|
|
|
virtual unsigned int GetOriginalNumLines(int ny) const {return numLines[ny];}
|
2010-04-12 05:42:54 +08:00
|
|
|
|
2010-05-19 17:42:56 +08:00
|
|
|
virtual void ShowStat() const;
|
2010-07-12 05:45:41 +08:00
|
|
|
virtual void ShowExtStat() const;
|
2010-03-01 16:19:39 +08:00
|
|
|
|
2010-04-14 00:40:43 +08:00
|
|
|
virtual double GetGridDelta() const {return gridDelta;}
|
2010-03-01 16:19:39 +08:00
|
|
|
|
2010-07-16 16:41:12 +08:00
|
|
|
//! Get the disc line in \a n direction (in drawing units)
|
2010-04-14 00:40:43 +08:00
|
|
|
virtual double GetDiscLine(int n, unsigned int pos, bool dualMesh=false) const;
|
2010-07-15 18:12:52 +08:00
|
|
|
|
2011-03-16 19:26:41 +08:00
|
|
|
//! Get the coordinates for a given node index and component, according to the yee-algorithm. Returns true if inside the FDTD domain.
|
|
|
|
virtual bool GetYeeCoords(int ny, unsigned int pos[3], double* coords, bool dualMesh) const;
|
|
|
|
|
2010-09-17 18:08:49 +08:00
|
|
|
//! Get the node width for a given direction \a n and a given mesh position \a pos
|
2010-12-08 23:55:27 +08:00
|
|
|
virtual double GetNodeWidth(int ny, const unsigned int pos[3], bool dualMesh = false) const {return GetEdgeLength(ny,pos,!dualMesh);}
|
2011-03-18 21:17:09 +08:00
|
|
|
//! Get the node width for a given direction \a n and a given mesh position \a pos
|
|
|
|
virtual double GetNodeWidth(int ny, const int pos[3], bool dualMesh = false) const;
|
2010-09-02 21:35:13 +08:00
|
|
|
|
2010-09-17 18:08:49 +08:00
|
|
|
//! Get the node area for a given direction \a n and a given mesh position \a pos
|
2010-09-17 20:51:07 +08:00
|
|
|
virtual double GetNodeArea(int ny, const unsigned int pos[3], bool dualMesh = false) const;
|
2011-03-18 21:17:09 +08:00
|
|
|
//! Get the node area for a given direction \a n and a given mesh position \a pos
|
|
|
|
virtual double GetNodeArea(int ny, const int pos[3], bool dualMesh = false) const;
|
2010-07-30 00:30:50 +08:00
|
|
|
|
2010-09-17 18:08:49 +08:00
|
|
|
//! Get the length of an FDTD edge (unit is meter).
|
2010-12-08 23:55:27 +08:00
|
|
|
virtual double GetEdgeLength(int ny, const unsigned int pos[3], bool dualMesh = false) const;
|
2010-09-02 21:35:13 +08:00
|
|
|
|
|
|
|
//! Get the area around an edge for a given direction \a n and a given mesh posisition \a pos
|
|
|
|
/*!
|
|
|
|
This will return the area around an edge with a given direction, measured at the middle of the edge.
|
|
|
|
In a cartesian mesh this is equal to the NodeArea, may be different in other coordinate systems.
|
|
|
|
*/
|
2010-09-17 20:51:07 +08:00
|
|
|
virtual double GetEdgeArea(int ny, const unsigned int pos[3], bool dualMesh = false) const {return GetNodeArea(ny,pos,dualMesh);}
|
2010-09-02 21:35:13 +08:00
|
|
|
|
2011-04-27 19:01:02 +08:00
|
|
|
virtual unsigned int SnapToMeshLine(int ny, double coord, bool &inside, bool dualMesh=false) const;
|
|
|
|
|
2011-07-22 15:58:02 +08:00
|
|
|
//! Snap the given coodinates to mesh indices
|
2011-04-27 19:01:02 +08:00
|
|
|
virtual bool SnapToMesh(const double* coord, unsigned int* uicoord, bool dualMesh=false, bool* inside=NULL) const;
|
2010-03-02 02:35:28 +08:00
|
|
|
|
2011-07-22 15:58:02 +08:00
|
|
|
//! Snap a given box to the FDTD mesh
|
|
|
|
virtual int SnapBox2Mesh(const double* start, const double* stop, unsigned int* uiStart, unsigned int* uiStop, bool dualMesh=false, int SnapMethod=0, bool* bStartIn=NULL, bool* bStopIn=NULL) const;
|
|
|
|
|
2010-04-26 03:59:05 +08:00
|
|
|
virtual void AddExtension(Operator_Extension* op_ext);
|
2011-07-25 20:57:09 +08:00
|
|
|
virtual void DeleteExtension(Operator_Extension* op_ext);
|
2010-04-28 05:06:42 +08:00
|
|
|
virtual size_t GetNumberOfExtentions() const {return m_Op_exts.size();}
|
|
|
|
virtual Operator_Extension* GetExtension(size_t index) const {return m_Op_exts.at(index);}
|
2010-04-26 03:59:05 +08:00
|
|
|
|
2011-01-07 17:45:26 +08:00
|
|
|
virtual void CleanupMaterialStorage();
|
|
|
|
|
2011-01-31 19:22:21 +08:00
|
|
|
virtual double GetDiscMaterial(int type, int ny, const unsigned int pos[3]) const;
|
|
|
|
|
2010-03-01 16:19:39 +08:00
|
|
|
protected:
|
2010-04-09 21:51:37 +08:00
|
|
|
//! use New() for creating a new Operator
|
|
|
|
Operator();
|
|
|
|
|
2010-03-01 16:19:39 +08:00
|
|
|
virtual void Init();
|
2011-01-24 18:11:45 +08:00
|
|
|
void Delete();
|
2010-04-14 00:40:43 +08:00
|
|
|
virtual void Reset();
|
2010-03-05 21:20:25 +08:00
|
|
|
virtual void InitOperator();
|
2011-01-07 17:45:26 +08:00
|
|
|
virtual void InitDataStorage();
|
2010-05-04 00:33:14 +08:00
|
|
|
virtual void InitExcitation();
|
2010-03-05 21:20:25 +08:00
|
|
|
|
2011-03-18 21:17:09 +08:00
|
|
|
virtual bool SetupCSXGrid(CSRectGrid* grid);
|
|
|
|
|
2010-03-26 18:28:54 +08:00
|
|
|
struct Grid_Path
|
2010-03-22 15:19:17 +08:00
|
|
|
{
|
|
|
|
vector<unsigned int> posPath[3];
|
|
|
|
vector<unsigned short> dir;
|
|
|
|
};
|
|
|
|
struct Grid_Path FindPath(double start[], double stop[]);
|
|
|
|
|
2010-10-27 17:17:58 +08:00
|
|
|
// debug
|
|
|
|
virtual void DumpOperator2File(string filename);
|
|
|
|
virtual void DumpMaterial2File(string filename);
|
|
|
|
virtual void DumpPEC2File( string filename );
|
|
|
|
|
2010-06-06 07:47:32 +08:00
|
|
|
unsigned int m_Nr_PEC[3]; //count PEC edges
|
2010-03-05 21:20:25 +08:00
|
|
|
virtual bool CalcPEC();
|
2010-06-06 07:47:32 +08:00
|
|
|
virtual void CalcPEC_Range(unsigned int startX, unsigned int stopX, unsigned int* counter); //internal to CalcPEC
|
2010-06-06 06:53:05 +08:00
|
|
|
virtual void CalcPEC_Curves(); //internal to CalcPEC
|
2010-03-05 21:20:25 +08:00
|
|
|
|
2010-03-01 16:19:39 +08:00
|
|
|
//Calc timestep only internal use
|
2011-02-16 22:28:14 +08:00
|
|
|
int m_TimeStepVar;
|
2010-03-05 21:20:25 +08:00
|
|
|
virtual double CalcTimestep();
|
2010-09-03 04:12:03 +08:00
|
|
|
double opt_dT;
|
2010-09-08 22:07:28 +08:00
|
|
|
bool m_InvaildTimestep;
|
2010-07-13 21:37:56 +08:00
|
|
|
string m_Used_TS_Name;
|
2010-03-05 21:20:25 +08:00
|
|
|
|
2010-06-22 18:49:51 +08:00
|
|
|
double CalcTimestep_Var1();
|
|
|
|
double CalcTimestep_Var3();
|
|
|
|
|
2011-03-18 21:17:09 +08:00
|
|
|
//! Calculate the FDTD equivalent circuit parameter for the given position and direction ny. \sa Calc_EffMat_Pos
|
|
|
|
virtual bool Calc_ECPos(int ny, const unsigned int* pos, double* EC) const;
|
|
|
|
|
|
|
|
//! Get the FDTD raw disc delta, needed by Calc_EffMatPos() \sa Calc_EffMatPos
|
|
|
|
/*!
|
|
|
|
Get the raw disc delta for a given position and direction.
|
|
|
|
The result will be positive if a disc delta inside the simulation domain is requested.
|
|
|
|
The result will be the negative value of the first or last disc delta respectivly if the position is outside the field domain.
|
|
|
|
*/
|
|
|
|
virtual double GetRawDiscDelta(int ny, const int pos) const;
|
|
|
|
|
|
|
|
//! Get the material at a given coordinate, direction and type from CSX (internal use only)
|
|
|
|
virtual double GetMaterial(int ny, const double coords[3], int MatType, bool markAsUsed=true) const;
|
|
|
|
|
|
|
|
//! Calculate the effective/averaged material properties at the given position and direction ny.
|
|
|
|
virtual bool Calc_EffMatPos(int ny, const unsigned int* pos, double* EffMat) const;
|
|
|
|
|
2010-07-16 16:41:12 +08:00
|
|
|
//! Calc operator at certain \a pos
|
2010-04-21 21:43:39 +08:00
|
|
|
virtual void Calc_ECOperatorPos(int n, unsigned int* pos);
|
2010-04-09 21:51:37 +08:00
|
|
|
|
2011-04-08 15:59:48 +08:00
|
|
|
//! Calculate and setup lumped elements
|
|
|
|
virtual bool Calc_LumpedElements();
|
|
|
|
|
2011-01-07 17:45:26 +08:00
|
|
|
//store material properties for post-processing
|
|
|
|
float**** m_epsR;
|
|
|
|
float**** m_kappa;
|
|
|
|
float**** m_mueR;
|
|
|
|
float**** m_sigma;
|
|
|
|
|
2010-03-05 21:20:25 +08:00
|
|
|
//EC elements, internal only!
|
2010-06-05 17:47:21 +08:00
|
|
|
virtual void Init_EC();
|
2010-04-09 21:51:37 +08:00
|
|
|
virtual bool Calc_EC();
|
2010-03-05 21:20:25 +08:00
|
|
|
double* EC_C[3];
|
|
|
|
double* EC_G[3];
|
|
|
|
double* EC_L[3];
|
|
|
|
double* EC_R[3];
|
2010-03-26 18:28:54 +08:00
|
|
|
|
2010-04-02 23:07:56 +08:00
|
|
|
AdrOp* MainOp;
|
2010-03-26 18:28:54 +08:00
|
|
|
|
2010-04-26 03:59:05 +08:00
|
|
|
vector<Operator_Extension*> m_Op_exts;
|
|
|
|
|
2010-04-14 00:40:43 +08:00
|
|
|
// engine/post-proc needs access
|
|
|
|
public:
|
2010-03-26 18:28:54 +08:00
|
|
|
//EC operator
|
|
|
|
FDTD_FLOAT**** vv; //calc new voltage from old voltage
|
|
|
|
FDTD_FLOAT**** vi; //calc new voltage from old current
|
|
|
|
FDTD_FLOAT**** ii; //calc new current from old current
|
|
|
|
FDTD_FLOAT**** iv; //calc new current from old voltage
|
|
|
|
|
2010-05-04 00:33:14 +08:00
|
|
|
Excitation* Exc;
|
2010-03-01 16:19:39 +08:00
|
|
|
};
|
|
|
|
|
2010-10-27 17:17:58 +08:00
|
|
|
inline Operator::DebugFlags operator|( Operator::DebugFlags a, Operator::DebugFlags b ) { return static_cast<Operator::DebugFlags>(static_cast<int>(a) | static_cast<int>(b)); }
|
|
|
|
inline Operator::DebugFlags& operator|=( Operator::DebugFlags& a, const Operator::DebugFlags& b ) { return a = a | b; }
|
|
|
|
|
2010-03-01 16:19:39 +08:00
|
|
|
#endif // OPERATOR_H
|