new ProcessingArray; Processing returns next interval for process()

Processing now uses a timestep interval in which Process() will do it's work
and returns the next interval it doesn't need another Process() call

all Processing routines can be put into these array
and it will take care of calling Process() at the right time
This commit is contained in:
Thorsten Liebig 2010-03-10 12:15:14 +01:00
parent c8dacd8c31
commit f73bf210ed
11 changed files with 143 additions and 49 deletions

View File

@ -26,9 +26,10 @@ void ProcessCurrent::DefineStartStopCoord(double* dstart, double* dstop)
if (Op->SnapToMesh(dstop,stop,true)==false) cerr << "ProcessCurrent::DefineStartStopCoord: Warning: Snapping problem, check stop value!!" << endl; if (Op->SnapToMesh(dstop,stop,true)==false) cerr << "ProcessCurrent::DefineStartStopCoord: Warning: Snapping problem, check stop value!!" << endl;
} }
void ProcessCurrent::Process() int ProcessCurrent::Process()
{ {
if (Enabled==false) return; if (Enabled==false) return -1;
if (CheckTimestep()==false) return GetNextInterval();
FDTD_FLOAT current=0; FDTD_FLOAT current=0;
// FDTD_FLOAT help=0; // FDTD_FLOAT help=0;
double sign[3]={1,1,1}; double sign[3]={1,1,1};
@ -68,4 +69,5 @@ void ProcessCurrent::Process()
// cerr << "ts: " << Eng->numTS << " i: " << current << endl; // cerr << "ts: " << Eng->numTS << " i: " << current << endl;
v_current.push_back(current); v_current.push_back(current);
file << (double)Eng->numTS*Op->GetTimestep() << "\t" << current << endl; file << (double)Eng->numTS*Op->GetTimestep() << "\t" << current << endl;
return GetNextInterval();
} }

View File

@ -13,7 +13,7 @@ public:
virtual void DefineStartStopCoord(double* dstart, double* dstop); virtual void DefineStartStopCoord(double* dstart, double* dstop);
virtual void Process(); virtual int Process();
protected: protected:
ofstream file; ofstream file;

View File

@ -16,6 +16,8 @@ public:
//! Used file pattern e.g. pattern="tmp/efield_" --> "tmp/efield_000045.vtk" for timestep 45 or "tmp/efield_2.40000e9.vtk" for 2.4GHz E-field dump. //! Used file pattern e.g. pattern="tmp/efield_" --> "tmp/efield_000045.vtk" for timestep 45 or "tmp/efield_2.40000e9.vtk" for 2.4GHz E-field dump.
void SetFilePattern(string fp) {filePattern=fp;} void SetFilePattern(string fp) {filePattern=fp;}
//! Define the Dump-Mode
void SetDumpMode(int mode) {DumpMode=mode;}
//! This methode will dump all fields in the center of a main cell (dual-node) using 4 E-field and 2 H-fields per direction. (default) //! This methode will dump all fields in the center of a main cell (dual-node) using 4 E-field and 2 H-fields per direction. (default)
void SetDumpMode2Cell() {DumpMode=2;} void SetDumpMode2Cell() {DumpMode=2;}

View File

@ -138,20 +138,22 @@ void ProcessFieldsTD::DumpNoInterpol(ofstream &file)
} }
} }
void ProcessFieldsTD::Process() int ProcessFieldsTD::Process()
{ {
if (Enabled==false) return; if (Enabled==false) return -1;
if (filePattern.empty()) return; if (filePattern.empty()) return -1;
if (CheckTimestep()==false) return GetNextInterval();
stringstream ss; stringstream ss;
ss << std::setw( pad_length ) << std::setfill( '0' ) << Eng->numTS; ss << std::setw( pad_length ) << std::setfill( '0' ) << Eng->numTS;
string filename = filePattern + ss.str() + ".vtk"; string filename = filePattern + ss.str() + ".vtk";
ofstream file(filename.c_str()); ofstream file(filename.c_str());
if (file.is_open()==false) { cerr << "ProcessFieldsTD::Process: can't open file '" << filename << "' for writing... abort! " << endl; return;}; if (file.is_open()==false) { cerr << "ProcessFieldsTD::Process: can't open file '" << filename << "' for writing... abort! " << endl; return GetNextInterval();};
if (DumpMode==0) if (DumpMode==0)
DumpNoInterpol(file); DumpNoInterpol(file);
if (DumpMode==2) if (DumpMode==2)
DumpCellInterpol(file); DumpCellInterpol(file);
file.close(); file.close();
return GetNextInterval();
} }

View File

@ -9,7 +9,7 @@ public:
ProcessFieldsTD(Operator* op, Engine* eng); ProcessFieldsTD(Operator* op, Engine* eng);
virtual ~ProcessFieldsTD(); virtual ~ProcessFieldsTD();
virtual void Process(); virtual int Process();
//! Set the length of the filename timestep pad filled with zeros (default is 8) //! Set the length of the filename timestep pad filled with zeros (default is 8)
void SetPadLength(int val) {pad_length=val;}; void SetPadLength(int val) {pad_length=val;};

View File

@ -11,6 +11,17 @@ Processing::~Processing()
{ {
} }
bool Processing::CheckTimestep()
{
if (Eng->GetNumberOfTimesteps()%ProcessInterval==0) return true;
return false;
}
int Processing::GetNextInterval()
{
if (Enabled==false) return -1;
return ProcessInterval - Eng->GetNumberOfTimesteps()%ProcessInterval;
}
void Processing::DefineStartStopCoord(double* dstart, double* dstop) void Processing::DefineStartStopCoord(double* dstart, double* dstop)
{ {
@ -18,3 +29,30 @@ void Processing::DefineStartStopCoord(double* dstart, double* dstop)
if (Op->SnapToMesh(dstop,stop)==false) cerr << "Processing::DefineStartStopCoord: Warning: Snapping problem, check stop value!!" << endl; if (Op->SnapToMesh(dstop,stop)==false) cerr << "Processing::DefineStartStopCoord: Warning: Snapping problem, check stop value!!" << endl;
} }
void ProcessingArray::AddProcessing(Processing* proc)
{
ProcessArray.push_back(proc);
}
void ProcessingArray::DeleteAll()
{
for (size_t i=0;i<ProcessArray.size();++i)
{
delete ProcessArray.at(i);
}
ProcessArray.clear();
}
int ProcessingArray::Process()
{
int nextProcess=1e100;
//this could be done nicely in parallel??
for (size_t i=0;i<ProcessArray.size();++i)
{
int step = ProcessArray.at(i)->Process();
if ((step>0) && (step<nextProcess))
nextProcess=step;
}
return nextProcess;
}

View File

@ -13,7 +13,8 @@ public:
virtual void DefineStartStopCoord(double* dstart, double* dstop); virtual void DefineStartStopCoord(double* dstart, double* dstop);
virtual void Process() {}; void SetProcessInterval(unsigned int interval) {ProcessInterval=interval;}
virtual int Process() {return GetNextInterval();}
//! If Disabled Process() will do nothing... //! If Disabled Process() will do nothing...
virtual void SetEnable(bool val) {Enabled=val;} virtual void SetEnable(bool val) {Enabled=val;}
@ -27,8 +28,29 @@ protected:
bool Enabled; bool Enabled;
bool CheckTimestep();
int GetNextInterval();
unsigned int ProcessInterval;
unsigned int start[3]; unsigned int start[3];
unsigned int stop[3]; unsigned int stop[3];
}; };
class ProcessingArray
{
public:
ProcessingArray() {};
~ProcessingArray() {};
void AddProcessing(Processing* proc);
//! Deletes all given processing's, can be helpful, but use carefull!!!
void DeleteAll();
int Process();
protected:
vector<Processing*> ProcessArray;
};
#endif // PROCESSING_H #endif // PROCESSING_H

View File

@ -21,9 +21,10 @@ void ProcessVoltage::OpenFile(string outfile)
} }
} }
void ProcessVoltage::Process() int ProcessVoltage::Process()
{ {
if (Enabled==false) return; if (Enabled==false) return -1;
if (CheckTimestep()==false) return GetNextInterval();
FDTD_FLOAT voltage=0; FDTD_FLOAT voltage=0;
unsigned int pos[3]={start[0],start[1],start[2]}; unsigned int pos[3]={start[0],start[1],start[2]};
// cerr << Eng->volt[1][pos[0]][pos[1]][pos[2]] << endl; // cerr << Eng->volt[1][pos[0]][pos[1]][pos[2]] << endl;
@ -47,4 +48,5 @@ void ProcessVoltage::Process()
// cerr << voltage << endl; // cerr << voltage << endl;
voltages.push_back(voltage); voltages.push_back(voltage);
file << (double)Eng->numTS*Op->GetTimestep() << "\t" << voltage << endl; file << (double)Eng->numTS*Op->GetTimestep() << "\t" << voltage << endl;
return GetNextInterval();
} }

View File

@ -12,7 +12,7 @@ public:
virtual void OpenFile(string outfile); virtual void OpenFile(string outfile);
virtual void Process(); virtual int Process();
protected: protected:
ofstream file; ofstream file;

View File

@ -100,7 +100,8 @@ void BuildPlaneWave(ContinuousStructure &CSX)
//E-field dump //E-field dump
CSPropDumpBox* Edump = new CSPropDumpBox(CSX.GetParameterSet()); CSPropDumpBox* Edump = new CSPropDumpBox(CSX.GetParameterSet());
Edump->SetEFieldDump(true); Edump->SetDumpType(0);
Edump->SetName("tmp/Et_");
CSX.AddProperty(Edump); CSX.AddProperty(Edump);
box = new CSPrimBox(CSX.GetParameterSet(),Edump); box = new CSPrimBox(CSX.GetParameterSet(),Edump);
box->SetCoord(0,width/-3.0);box->SetCoord(1,width/3.0); box->SetCoord(0,width/-3.0);box->SetCoord(1,width/3.0);
@ -108,6 +109,17 @@ void BuildPlaneWave(ContinuousStructure &CSX)
box->SetCoord(4,length/-2.0+abs_l);box->SetCoord(5,length/2.0-abs_l); box->SetCoord(4,length/-2.0+abs_l);box->SetCoord(5,length/2.0-abs_l);
CSX.AddPrimitive(box); CSX.AddPrimitive(box);
//H-field dump
CSPropDumpBox* Hdump = new CSPropDumpBox(CSX.GetParameterSet());
Hdump->SetDumpType(1);
Hdump->SetName("tmp/Ht_");
CSX.AddProperty(Hdump);
box = new CSPrimBox(CSX.GetParameterSet(),Hdump);
box->SetCoord(0,width/-3.0);box->SetCoord(1,width/3.0);
box->SetCoord(2,0.0);box->SetCoord(3,0.0);
box->SetCoord(4,length/-2.0+abs_l);box->SetCoord(5,length/2.0-abs_l);
CSX.AddPrimitive(box);
// CSPropMetal* metal = new CSPropMetal(CSX.GetParameterSet()); // CSPropMetal* metal = new CSPropMetal(CSX.GetParameterSet());
// CSX.AddProperty(metal); // CSX.AddProperty(metal);
// CSPrimCylinder* cyl = new CSPrimCylinder(CSX.GetParameterSet(),metal); // CSPrimCylinder* cyl = new CSPrimCylinder(CSX.GetParameterSet(),metal);
@ -188,7 +200,8 @@ void BuildMSL(ContinuousStructure &CSX)
//E-field dump //E-field dump
CSPropDumpBox* Edump = new CSPropDumpBox(CSX.GetParameterSet()); CSPropDumpBox* Edump = new CSPropDumpBox(CSX.GetParameterSet());
Edump->SetEFieldDump(true); Edump->SetDumpType(0);
Edump->SetName("tmp/Et_");
CSX.AddProperty(Edump); CSX.AddProperty(Edump);
box = new CSPrimBox(CSX.GetParameterSet(),Edump); box = new CSPrimBox(CSX.GetParameterSet(),Edump);
box->SetCoord(0,width/-2.0);box->SetCoord(1,width/2.0); box->SetCoord(0,width/-2.0);box->SetCoord(1,width/2.0);

View File

@ -43,7 +43,7 @@ int main(int argc, char *argv[])
cop.ApplyMagneticBC(bnd); cop.ApplyMagneticBC(bnd);
cerr << "Nyquist number of timesteps: " << cop.GetNyquistNum(fmax) << endl; cerr << "Nyquist number of timesteps: " << cop.GetNyquistNum(fmax) << endl;
unsigned int NrIter = cop.GetNyquistNum(fmax)/3; unsigned int Nyquist = cop.GetNyquistNum(fmax);
cerr << "Time for operator: " << difftime(OpDoneTime,startTime) << endl; cerr << "Time for operator: " << difftime(OpDoneTime,startTime) << endl;
@ -53,59 +53,68 @@ int main(int argc, char *argv[])
time_t currTime = time(NULL); time_t currTime = time(NULL);
//*************** setup processing ************// //*************** setup processing ************//
ProcessVoltage PV(&cop,&eng); ProcessingArray PA;
PV.OpenFile("tmp/u1");
ProcessVoltage* PV = new ProcessVoltage(&cop,&eng);
PA.AddProcessing(PV);
PV->SetProcessInterval(Nyquist/3); //three times as often as nyquist dictates
PV->OpenFile("tmp/u1");
double start[]={0,50,0}; double start[]={0,50,0};
double stop[]={0,0,0}; double stop[]={0,0,0};
PV.DefineStartStopCoord(start,stop); PV->DefineStartStopCoord(start,stop);
ProcessCurrent PCurr(&cop,&eng); ProcessCurrent* PCurr = new ProcessCurrent(&cop,&eng);
PCurr.OpenFile("tmp/i1"); PA.AddProcessing(PCurr);
PCurr->SetProcessInterval(Nyquist/3); //three times as often as nyquist dictates
PCurr->OpenFile("tmp/i1");
start[0]=-50;start[1]=40;start[2]=-0; start[0]=-50;start[1]=40;start[2]=-0;
stop[0]=50;stop[1]=60;stop[2]=-0; stop[0]=50;stop[1]=60;stop[2]=-0;
PCurr.DefineStartStopCoord(start,stop); PCurr->DefineStartStopCoord(start,stop);
unsigned int maxIter = 1800; unsigned int maxIter = 1800;
bool EnableDump = true;
vector<CSProperties*> DumpProps = CSX.GetPropertyByType(CSProperties::DUMPBOX); vector<CSProperties*> DumpProps = CSX.GetPropertyByType(CSProperties::DUMPBOX);
vector<ProcessFieldsTD*> TD_Dump; for (size_t i=0;i<DumpProps.size();++i)
ProcessFieldsTD PETD(&cop,&eng);
if (DumpProps.size()>0)
{ {
CSPrimitives* prim = DumpProps.at(0)->GetPrimitive(0); ProcessFieldsTD* ProcTD = new ProcessFieldsTD(&cop,&eng);
bool acc; ProcTD->SetEnable(EnableDump);
double* bnd = prim->GetBoundBox(acc); ProcTD->SetProcessInterval(Nyquist/2); //twice as often as nyquist dictates
start[0]= bnd[0];start[1]=bnd[2];start[2]=bnd[4];
stop[0] = bnd[1];stop[1] =bnd[3];stop[2] =bnd[5]; //only looking for one prim atm
CSPropDumpBox* db = DumpProps.at(0)->ToDumpBox(); CSPrimitives* prim = DumpProps.at(i)->GetPrimitive(0);
if (db) if (prim==NULL)
delete ProcTD;
else
{ {
if (db->GetEFieldDump()) bool acc;
double* bnd = prim->GetBoundBox(acc);
start[0]= bnd[0];start[1]=bnd[2];start[2]=bnd[4];
stop[0] = bnd[1];stop[1] =bnd[3];stop[2] =bnd[5];
ProcTD->DefineStartStopCoord(start,stop);
CSPropDumpBox* db = DumpProps.at(i)->ToDumpBox();
if (db)
{ {
PETD.SetDumpType(0); ProcTD->SetDumpType(db->GetDumpType());
PETD.SetFilePattern("tmp/Et_"); ProcTD->SetDumpMode(db->GetDumpMode());
ProcTD->SetFilePattern(db->GetName());
PA.AddProcessing(ProcTD);
} }
else else
PETD.SetEnable(false); delete ProcTD;
} }
else
PETD.SetEnable(false);
PETD.DefineStartStopCoord(start,stop);
} }
PETD.SetEnable(true); int step=PA.Process();
if ((step<0) || (step>maxIter)) step=maxIter;
PV.Process();
PCurr.Process();
PETD.Process();
//*************** simulate ************// //*************** simulate ************//
for (unsigned int i=0;i<maxIter;i+=NrIter) while (eng.GetNumberOfTimesteps()<maxIter)
{ {
eng.IterateTS(NrIter); eng.IterateTS(step);
PV.Process(); step=PA.Process();
PCurr.Process(); // cerr << " do " << step << " steps; current: " << eng.GetNumberOfTimesteps() << endl;
PETD.Process(); if ((step<0) || (step>maxIter - eng.GetNumberOfTimesteps())) step=maxIter - eng.GetNumberOfTimesteps();
} }
//*************** postproc ************// //*************** postproc ************//
@ -116,5 +125,9 @@ int main(int argc, char *argv[])
cerr << "Time for " << eng.GetNumberOfTimesteps() << " iterations with " << cop.GetNumberCells() << " cells : " << t_diff << " sec" << endl; cerr << "Time for " << eng.GetNumberOfTimesteps() << " iterations with " << cop.GetNumberCells() << " cells : " << t_diff << " sec" << endl;
cerr << "Speed: " << (double)cop.GetNumberCells()*(double)eng.GetNumberOfTimesteps()/t_diff/1e6 << " MCells/s " << endl; cerr << "Speed: " << (double)cop.GetNumberCells()*(double)eng.GetNumberOfTimesteps()/t_diff/1e6 << " MCells/s " << endl;
//cleanup
PA.DeleteAll();
return 0; return 0;
} }