end Criteria with energy estimate; more engine stats while running
parent
3bf292c95c
commit
8dc89ecac2
|
@ -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);
|
||||
|
|
|
@ -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]<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)
|
||||
//{
|
||||
// if (dir>2) return;
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
4
main.cpp
4
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();
|
||||
|
|
34
openems.cpp
34
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()<NrTS)
|
||||
while ((FDTD_Eng->GetNumberOfTimesteps()<NrTS) && (change>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;
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in New Issue