From 8dc89ecac218e3c69937536e30e90dd11954edb2 Mon Sep 17 00:00:00 2001 From: Thorsten Liebig Date: Mon, 15 Mar 2010 16:59:37 +0100 Subject: [PATCH] end Criteria with energy estimate; more engine stats while running --- FDTD/engine.h | 1 + FDTD/processfields.cpp | 22 ++++++++++++++++++++++ FDTD/processfields.h | 5 +++-- FDTD/processing.h | 2 +- main.cpp | 4 ++-- openems.cpp | 34 +++++++++++++++++++++++++++++----- openems.h | 2 ++ 7 files changed, 60 insertions(+), 10 deletions(-) diff --git a/FDTD/engine.h b/FDTD/engine.h index f727c86..401fa13 100644 --- a/FDTD/engine.h +++ b/FDTD/engine.h @@ -25,6 +25,7 @@ class Engine friend class Processing; friend class ProcessVoltage; friend class ProcessCurrent; + friend class ProcessFields; friend class ProcessFieldsTD; public: Engine(Operator* op); diff --git a/FDTD/processfields.cpp b/FDTD/processfields.cpp index b23debe..bb10899 100644 --- a/FDTD/processfields.cpp +++ b/FDTD/processfields.cpp @@ -25,6 +25,7 @@ ProcessFields::ProcessFields(Operator* op, Engine* eng) : Processing(op, eng) for (int n=0;n<3;++n) { + numLines[n]=0; discDLines[n]=NULL; discLines[n]=NULL; } @@ -97,6 +98,27 @@ void ProcessFields::DefineStartStopCoord(double* dstart, double* dstop) } } + +double ProcessFields::CalcTotalEnergy() +{ + double energy=0; + if (Eng==NULL) return 0.0; + unsigned int pos[3]; + for (pos[0]=0;pos[0]numLines[0];++pos[0]) + { + for (pos[1]=0;pos[1]numLines[1];++pos[1]) + { + for (pos[2]=0;pos[2]numLines[2];++pos[2]) + { + energy+=fabs(Eng->volt[0][pos[0]][pos[1]][pos[2]] * Eng->curr[0][pos[0]][pos[1]][pos[2]]); + energy+=fabs(Eng->volt[1][pos[0]][pos[1]][pos[2]] * Eng->curr[1][pos[0]][pos[1]][pos[2]]); + energy+=fabs(Eng->volt[2][pos[0]][pos[1]][pos[2]] * Eng->curr[2][pos[0]][pos[1]][pos[2]]); + } + } + } + return energy*0.5; +} + //void ProcessFields::SetSubSampling(unsigned int subSampleRate, int dir) //{ // if (dir>2) return; diff --git a/FDTD/processfields.h b/FDTD/processfields.h index 5d39a16..82e1ce9 100644 --- a/FDTD/processfields.h +++ b/FDTD/processfields.h @@ -24,6 +24,7 @@ class ProcessFields : public Processing { public: + ProcessFields(Operator* op, Engine* eng); virtual ~ProcessFields(); virtual void DefineStartStopCoord(double* dstart, double* dstop); @@ -46,10 +47,10 @@ public: static bool DumpScalarArray2VTK(ofstream &file, string name, FDTD_FLOAT*** array, double** discLines, unsigned int* numLines); static bool DumpMultiScalarArray2VTK(ofstream &file, string names[], FDTD_FLOAT*** array[], unsigned int numFields, double** discLines, unsigned int* numLines); + double CalcTotalEnergy(); + // virtual void Process(); protected: - ProcessFields(Operator* op, Engine* eng); - static void WriteVTKHeader(ofstream &file, double** discLines, unsigned int* numLines); static void WriteVTKVectorArray(ofstream &file, string name, FDTD_FLOAT**** array, unsigned int* numLines); static void WriteVTKScalarArray(ofstream &file, string name, FDTD_FLOAT*** array, unsigned int* numLines); diff --git a/FDTD/processing.h b/FDTD/processing.h index 7605e93..f0c073c 100644 --- a/FDTD/processing.h +++ b/FDTD/processing.h @@ -26,6 +26,7 @@ class Processing { public: + Processing(Operator* op, Engine* eng); virtual ~Processing(); virtual void DefineStartStopCoord(double* dstart, double* dstop); @@ -39,7 +40,6 @@ public: virtual bool GetEnable() {return Enabled;} protected: - Processing(Operator* op, Engine* eng); Operator* Op; Engine* Eng; diff --git a/main.cpp b/main.cpp index de800d3..2c278db 100644 --- a/main.cpp +++ b/main.cpp @@ -76,12 +76,12 @@ int main(int argc, char *argv[]) const char* fileHelix="../examples/Helix.xml"; BuildHelix(fileHelix); - const char* file=fileHelix; + const char* file=fileMSL; // cerr << CSX.ReadFromXML("examples/PlaneWave.xml") << endl; #endif - FDTD.DebugMaterial(); +// FDTD.DebugMaterial(); int EC = FDTD.SetupFDTD(file); if (EC) return EC; FDTD.RunFDTD(); diff --git a/openems.cpp b/openems.cpp index 21cad84..ec30157 100644 --- a/openems.cpp +++ b/openems.cpp @@ -34,6 +34,7 @@ openEMS::openEMS() PA=NULL; Enable_Dumps = true; DebugMat = false; + endCrit = 1e-6; } openEMS::~openEMS() @@ -245,23 +246,46 @@ void openEMS::RunFDTD() { cout << "Running FDTD engine... this may take a while... grab a coup of coffee?!?" << endl; time_t currTime = time(NULL); + time_t startTime = currTime; + time_t prevTime=currTime; + ProcessFields ProcField(FDTD_Op,FDTD_Eng); + double maxE=0,currE=0; + double change=1; + int prevTS=0,currTS=0; + double speed = (double)FDTD_Op->GetNumberCells()/1e6; + double t_diff; //*************** simulate ************// int step=PA->Process(); if ((step<0) || (step>NrTS)) step=NrTS; - while (FDTD_Eng->GetNumberOfTimesteps()GetNumberOfTimesteps()endCrit)) { FDTD_Eng->IterateTS(step); step=PA->Process(); // cout << " do " << step << " steps; current: " << eng.GetNumberOfTimesteps() << endl; - if ((step<0) || (step>NrTS - FDTD_Eng->GetNumberOfTimesteps())) step=NrTS - FDTD_Eng->GetNumberOfTimesteps(); + currTS = FDTD_Eng->GetNumberOfTimesteps(); + if ((step<0) || (step>NrTS - currTS)) step=NrTS - currTS; + + currTime = time(NULL); + t_diff = difftime(currTime,prevTime); + if (t_diff>4) + { + currE = ProcField.CalcTotalEnergy(); + if ((currE>0) && (currE>maxE)) + maxE=currE; + cout << "Timestep:\t" << currTS << " of " << NrTS << " (" << (double)currTS/(double)NrTS*100.0 << "%)" ; + cout << "\t with currently " << speed*(double)(currTS-prevTS)/t_diff << " MCells/s" ; + cout << "\t current Energy estimate: " << currE << " (decrement: " << -10.0*log10(currE/maxE) << "dB)" << endl; + prevTime=currTime; + prevTS=currTS; + } } //*************** postproc ************// - time_t prevTime = currTime; + prevTime = currTime; currTime = time(NULL); - double t_diff = difftime(currTime,prevTime); + t_diff = difftime(currTime,startTime); cout << "Time for " << FDTD_Eng->GetNumberOfTimesteps() << " iterations with " << FDTD_Op->GetNumberCells() << " cells : " << t_diff << " sec" << endl; - cout << "Speed: " << (double)FDTD_Op->GetNumberCells()*(double)FDTD_Eng->GetNumberOfTimesteps()/t_diff/1e6 << " MCells/s " << endl; + cout << "Speed: " << speed*(double)FDTD_Eng->GetNumberOfTimesteps()/t_diff << " MCells/s " << endl; } diff --git a/openems.h b/openems.h index a39d934..6899fec 100644 --- a/openems.h +++ b/openems.h @@ -35,6 +35,7 @@ public: void Reset(); void SetEnableDumps(bool val) {Enable_Dumps=val;} + void SetEndCriteria(double val) {endCrit=val;} void DebugMaterial() {DebugMat=true;} @@ -43,6 +44,7 @@ protected: int NrTS; bool Enable_Dumps; bool DebugMat; + double endCrit; Operator* FDTD_Op; Engine* FDTD_Eng; ProcessingArray* PA;