diff --git a/FDTD/operator.cpp b/FDTD/operator.cpp index ed8904a..6bff8b3 100644 --- a/FDTD/operator.cpp +++ b/FDTD/operator.cpp @@ -345,25 +345,47 @@ void Operator::DumpOperator2File(string filename) #endif ofstream file(filename.c_str(),ios_base::out); - if (file.is_open()==false) + if (!file.is_open()) { - cerr << "Operator::DumpOperator2File: Can't open file: " << filename << endl; + cerr << "Operator::DumpOperator2File(): Can't open file: " << filename << endl; return; } - cout << "Operator::Dumping FDTD operator information to vtk file: " << filename << " ..." << flush ; + cout << "Operator: Dumping FDTD operator information to vtk file: " << filename << " ..." << flush; FDTD_FLOAT**** exc = Create_N_3DArray(numLines); - if (Exc) { + if (Exc) + { for (unsigned int n=0;nVolt_Count;++n) exc[Exc->Volt_dir[n]][Exc->Volt_index[0][n]][Exc->Volt_index[1][n]][Exc->Volt_index[2][n]] = Exc->Volt_amp[n]; } + FDTD_FLOAT**** vv_temp = Create_N_3DArray(numLines); + FDTD_FLOAT**** vi_temp = Create_N_3DArray(numLines); + FDTD_FLOAT**** iv_temp = Create_N_3DArray(numLines); + FDTD_FLOAT**** ii_temp = Create_N_3DArray(numLines); + + unsigned int pos[3], n; + for (n=0; n<3; n++) + for (pos[0]=0; pos[0]( numLines ); unsigned int pos[3]; @@ -399,19 +422,19 @@ void Operator::DumpPEC2File( string filename ) if ((pos[1] != 0) && (pos[2] != 0)) { // PEC surrounds the computational area; do not output this - if ((GetVV(0,pos[0],pos[1],pos[2]) == 0) && (GetVI(0,pos[0],pos[1],pos[2]) == 0)) + if ((GetVV(0,pos) == 0) && (GetVI(0,pos) == 0)) pec[0][pos[0]][pos[1]][pos[2]] = GetEdgeLength( 0, pos ) * scaling; // PEC-x found } if ((pos[0] != 0) && (pos[2] != 0)) { // PEC surrounds the computational area; do not output this - if ((GetVV(1,pos[0],pos[1],pos[2]) == 0) && (GetVI(1,pos[0],pos[1],pos[2]) == 0)) + if ((GetVV(1,pos) == 0) && (GetVI(1,pos) == 0)) pec[1][pos[0]][pos[1]][pos[2]] = GetEdgeLength( 1, pos ) * scaling; // PEC-y found } if ((pos[0] != 0) && (pos[1] != 0)) { // PEC surrounds the computational area; do not output this - if ((GetVV(2,pos[0],pos[1],pos[2]) == 0) && (GetVI(2,pos[0],pos[1],pos[2]) == 0)) + if ((GetVV(2,pos) == 0) && (GetVI(2,pos) == 0)) pec[2][pos[0]][pos[1]][pos[2]] = GetEdgeLength( 2, pos ) * scaling; // PEC-z found } } @@ -463,25 +486,20 @@ void Operator::DumpMaterial2File(string filename) #endif ofstream file(filename.c_str(),ios_base::out); - if (file.is_open()==false) + if (!file.is_open()) { - cerr << "Operator::DumpMaterial2File: Can't open file: " << filename << endl; + cerr << "Operator::DumpMaterial2File(): Can't open file: " << filename << endl; return; } - cout << "Dumping material information to vtk file: " << filename << " ..." << flush; + cout << "Operator: Dumping material information to vtk file: " << filename << " ..." << flush; + + FDTD_FLOAT**** epsilon = Create_N_3DArray(numLines); + FDTD_FLOAT**** mue = Create_N_3DArray(numLines); + FDTD_FLOAT**** kappa = Create_N_3DArray(numLines); + FDTD_FLOAT**** sigma = Create_N_3DArray(numLines); - FDTD_FLOAT**** epsilon; - FDTD_FLOAT**** mue; - FDTD_FLOAT**** kappa; - FDTD_FLOAT**** sigma; unsigned int pos[3]; - double inMat[4]; - - epsilon = Create_N_3DArray( numLines); - mue = Create_N_3DArray( numLines); - kappa = Create_N_3DArray( numLines); - sigma = Create_N_3DArray( numLines); for (pos[0]=0;pos[0]BuildExtension(); + if (debugFlags & debugMaterial) + DumpMaterial2File( "material_dump.vtk" ); + if (debugFlags & debugOperator) + DumpOperator2File( "operator_dump.vtk" ); + if (debugFlags & debugPEC) + DumpPEC2File( "PEC_dump.vtk" ); + //cleanup for (int n=0;n<3;++n) { diff --git a/FDTD/operator.h b/FDTD/operator.h index d7ab48c..f60cd7e 100644 --- a/FDTD/operator.h +++ b/FDTD/operator.h @@ -33,7 +33,9 @@ class Operator friend class Engine; friend class Operator_Ext_LorentzMaterial; //we need to find a way around this... friend class Operator_Extension only would be nice friend class Operator_Ext_PML_SF_Plane; -public: +public: + enum DebugFlags {None=0,debugMaterial=1,debugOperator=2,debugPEC=4}; + //! Create a new operator static Operator* New(); virtual ~Operator(); @@ -43,7 +45,7 @@ public: virtual bool SetGeometryCSX(ContinuousStructure* geo); virtual ContinuousStructure* GetGeometryCSX() {return CSX;} - virtual int CalcECOperator(); + virtual int CalcECOperator( DebugFlags ); //! 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; @@ -59,6 +61,12 @@ public: 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]; } + // 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]); } + // 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; } @@ -83,10 +91,6 @@ public: virtual void ShowStat() const; virtual void ShowExtStat() const; - virtual void DumpOperator2File(string filename); - virtual void DumpMaterial2File(string filename); - virtual void DumpPEC2File( string filename ); - //! Get the name for the given direction: 0 -> x, 1 -> y, 2 -> z virtual string GetDirName(int ny) const; @@ -142,6 +146,11 @@ protected: //! Calculate the field excitations. virtual bool CalcFieldExcitation(); + // debug + virtual void DumpOperator2File(string filename); + virtual void DumpMaterial2File(string filename); + virtual void DumpPEC2File( string filename ); + unsigned int m_Nr_PEC[3]; //count PEC edges virtual bool CalcPEC(); virtual void CalcPEC_Range(unsigned int startX, unsigned int stopX, unsigned int* counter); //internal to CalcPEC @@ -188,4 +197,7 @@ public: Excitation* Exc; }; +inline Operator::DebugFlags operator|( Operator::DebugFlags a, Operator::DebugFlags b ) { return static_cast(static_cast(a) | static_cast(b)); } +inline Operator::DebugFlags& operator|=( Operator::DebugFlags& a, const Operator::DebugFlags& b ) { return a = a | b; } + #endif // OPERATOR_H diff --git a/FDTD/operator_cylindermultigrid.cpp b/FDTD/operator_cylindermultigrid.cpp index b8ff83d..cc184c7 100644 --- a/FDTD/operator_cylindermultigrid.cpp +++ b/FDTD/operator_cylindermultigrid.cpp @@ -146,25 +146,25 @@ void Operator_CylinderMultiGrid::CalcStartStopLines(unsigned int &numThreads, ve } -int Operator_CylinderMultiGrid::CalcECOperator() +int Operator_CylinderMultiGrid::CalcECOperator( DebugFlags debugFlags ) { int retCode=0; if (dT) m_InnerOp->SetTimestep(dT); //calc inner child first - m_InnerOp->CalcECOperator(); + m_InnerOp->CalcECOperator( debugFlags ); dT = m_InnerOp->GetTimestep(); - retCode = Operator_Cylinder::CalcECOperator(); + retCode = Operator_Cylinder::CalcECOperator( debugFlags ); if (GetTimestepValid()==false) { cerr << "Operator_CylinderMultiGrid::CalcECOperator(): Warning, timestep invalid... resetting..." << endl; dT = opt_dT; m_InnerOp->SetTimestep(dT); - m_InnerOp->CalcECOperator(); - return Operator_Cylinder::CalcECOperator(); + m_InnerOp->CalcECOperator( debugFlags ); + return Operator_Cylinder::CalcECOperator( debugFlags ); } return retCode; diff --git a/FDTD/operator_cylindermultigrid.h b/FDTD/operator_cylindermultigrid.h index 6fb7503..ce9cc40 100644 --- a/FDTD/operator_cylindermultigrid.h +++ b/FDTD/operator_cylindermultigrid.h @@ -41,7 +41,7 @@ public: virtual unsigned int GetSplitPos() const {return m_Split_Pos;} - virtual int CalcECOperator(); + virtual int CalcECOperator( DebugFlags ); virtual bool SetupExcitation(TiXmlElement* Excite, unsigned int maxTS); diff --git a/FDTD/operator_multithread.cpp b/FDTD/operator_multithread.cpp index f058ea6..d8109d9 100644 --- a/FDTD/operator_multithread.cpp +++ b/FDTD/operator_multithread.cpp @@ -94,7 +94,7 @@ void Operator_Multithread::CalcStartStopLines(unsigned int &numThreads, vector(numLines); - if (Exc) { - for (unsigned int n=0;nVolt_Count;++n) - exc[Exc->Volt_dir[n]][Exc->Volt_index[0][n]][Exc->Volt_index[1][n]][Exc->Volt_index[2][n]] = Exc->Volt_amp[n]; - } - - vv = Create_N_3DArray(numLines); - vi = Create_N_3DArray(numLines); - iv = Create_N_3DArray(numLines); - ii = Create_N_3DArray(numLines); - - unsigned int pos[3]; - for (pos[0]=0;pos[0]SetTimestep(timestep); - FDTD_Op->CalcECOperator(); + Operator::DebugFlags debugFlags = Operator::None; + if (DebugMat) + debugFlags |= Operator::debugMaterial; + if (DebugOp) + debugFlags |= Operator::debugOperator; + if (m_debugPEC) + debugFlags |= Operator::debugPEC; + FDTD_Op->CalcECOperator( debugFlags ); unsigned int maxTime_TS = (unsigned int)(maxTime/FDTD_Op->GetTimestep()); if ((maxTime_TS>0) && (maxTime_TSSetupExcitation( FDTD_Opts->FirstChildElement("Excitation"), NrTS )) exit(2); - // create debug output, if requested - if (DebugMat) - FDTD_Op->DumpMaterial2File("material_dump.vtk"); - if (DebugOp) - FDTD_Op->DumpOperator2File("operator_dump.vtk"); - if (m_debugPEC) - FDTD_Op->DumpPEC2File("PEC_dump.vtk"); - timeval OpDoneTime; gettimeofday(&OpDoneTime,NULL);