end Criteria with energy estimate; more engine stats while running

pull/1/head
Thorsten Liebig 2010-03-15 16:59:37 +01:00
parent 3bf292c95c
commit 8dc89ecac2
7 changed files with 60 additions and 10 deletions

View File

@ -25,6 +25,7 @@ class Engine
friend class Processing; friend class Processing;
friend class ProcessVoltage; friend class ProcessVoltage;
friend class ProcessCurrent; friend class ProcessCurrent;
friend class ProcessFields;
friend class ProcessFieldsTD; friend class ProcessFieldsTD;
public: public:
Engine(Operator* op); Engine(Operator* op);

View File

@ -25,6 +25,7 @@ ProcessFields::ProcessFields(Operator* op, Engine* eng) : Processing(op, eng)
for (int n=0;n<3;++n) for (int n=0;n<3;++n)
{ {
numLines[n]=0;
discDLines[n]=NULL; discDLines[n]=NULL;
discLines[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]<Op->numLines[0];++pos[0])
{
for (pos[1]=0;pos[1]<Op->numLines[1];++pos[1])
{
for (pos[2]=0;pos[2]<Op->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) //void ProcessFields::SetSubSampling(unsigned int subSampleRate, int dir)
//{ //{
// if (dir>2) return; // if (dir>2) return;

View File

@ -24,6 +24,7 @@
class ProcessFields : public Processing class ProcessFields : public Processing
{ {
public: public:
ProcessFields(Operator* op, Engine* eng);
virtual ~ProcessFields(); virtual ~ProcessFields();
virtual void DefineStartStopCoord(double* dstart, double* dstop); 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 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); static bool DumpMultiScalarArray2VTK(ofstream &file, string names[], FDTD_FLOAT*** array[], unsigned int numFields, double** discLines, unsigned int* numLines);
double CalcTotalEnergy();
// virtual void Process(); // virtual void Process();
protected: protected:
ProcessFields(Operator* op, Engine* eng);
static void WriteVTKHeader(ofstream &file, double** discLines, unsigned int* numLines); 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 WriteVTKVectorArray(ofstream &file, string name, FDTD_FLOAT**** array, unsigned int* numLines);
static void WriteVTKScalarArray(ofstream &file, string name, FDTD_FLOAT*** array, unsigned int* numLines); static void WriteVTKScalarArray(ofstream &file, string name, FDTD_FLOAT*** array, unsigned int* numLines);

View File

@ -26,6 +26,7 @@
class Processing class Processing
{ {
public: public:
Processing(Operator* op, Engine* eng);
virtual ~Processing(); virtual ~Processing();
virtual void DefineStartStopCoord(double* dstart, double* dstop); virtual void DefineStartStopCoord(double* dstart, double* dstop);
@ -39,7 +40,6 @@ public:
virtual bool GetEnable() {return Enabled;} virtual bool GetEnable() {return Enabled;}
protected: protected:
Processing(Operator* op, Engine* eng);
Operator* Op; Operator* Op;
Engine* Eng; Engine* Eng;

View File

@ -76,12 +76,12 @@ int main(int argc, char *argv[])
const char* fileHelix="../examples/Helix.xml"; const char* fileHelix="../examples/Helix.xml";
BuildHelix(fileHelix); BuildHelix(fileHelix);
const char* file=fileHelix; const char* file=fileMSL;
// cerr << CSX.ReadFromXML("examples/PlaneWave.xml") << endl; // cerr << CSX.ReadFromXML("examples/PlaneWave.xml") << endl;
#endif #endif
FDTD.DebugMaterial(); // FDTD.DebugMaterial();
int EC = FDTD.SetupFDTD(file); int EC = FDTD.SetupFDTD(file);
if (EC) return EC; if (EC) return EC;
FDTD.RunFDTD(); FDTD.RunFDTD();

View File

@ -34,6 +34,7 @@ openEMS::openEMS()
PA=NULL; PA=NULL;
Enable_Dumps = true; Enable_Dumps = true;
DebugMat = false; DebugMat = false;
endCrit = 1e-6;
} }
openEMS::~openEMS() openEMS::~openEMS()
@ -245,23 +246,46 @@ void openEMS::RunFDTD()
{ {
cout << "Running FDTD engine... this may take a while... grab a coup of coffee?!?" << endl; cout << "Running FDTD engine... this may take a while... grab a coup of coffee?!?" << endl;
time_t currTime = time(NULL); 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 ************// //*************** simulate ************//
int step=PA->Process(); int step=PA->Process();
if ((step<0) || (step>NrTS)) step=NrTS; if ((step<0) || (step>NrTS)) step=NrTS;
while (FDTD_Eng->GetNumberOfTimesteps()<NrTS) while ((FDTD_Eng->GetNumberOfTimesteps()<NrTS) && (change>endCrit))
{ {
FDTD_Eng->IterateTS(step); FDTD_Eng->IterateTS(step);
step=PA->Process(); step=PA->Process();
// cout << " do " << step << " steps; current: " << eng.GetNumberOfTimesteps() << endl; // 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 ************// //*************** postproc ************//
time_t prevTime = currTime; prevTime = currTime;
currTime = time(NULL); 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 << "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;
} }

View File

@ -35,6 +35,7 @@ public:
void Reset(); void Reset();
void SetEnableDumps(bool val) {Enable_Dumps=val;} void SetEnableDumps(bool val) {Enable_Dumps=val;}
void SetEndCriteria(double val) {endCrit=val;}
void DebugMaterial() {DebugMat=true;} void DebugMaterial() {DebugMat=true;}
@ -43,6 +44,7 @@ protected:
int NrTS; int NrTS;
bool Enable_Dumps; bool Enable_Dumps;
bool DebugMat; bool DebugMat;
double endCrit;
Operator* FDTD_Op; Operator* FDTD_Op;
Engine* FDTD_Eng; Engine* FDTD_Eng;
ProcessingArray* PA; ProcessingArray* PA;