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
pull/1/head
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;
}
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 help=0;
double sign[3]={1,1,1};
@ -68,4 +69,5 @@ void ProcessCurrent::Process()
// cerr << "ts: " << Eng->numTS << " i: " << current << endl;
v_current.push_back(current);
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 Process();
virtual int Process();
protected:
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.
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)
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 (filePattern.empty()) return;
if (Enabled==false) return -1;
if (filePattern.empty()) return -1;
if (CheckTimestep()==false) return GetNextInterval();
stringstream ss;
ss << std::setw( pad_length ) << std::setfill( '0' ) << Eng->numTS;
string filename = filePattern + ss.str() + ".vtk";
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)
DumpNoInterpol(file);
if (DumpMode==2)
DumpCellInterpol(file);
file.close();
return GetNextInterval();
}

View File

@ -9,7 +9,7 @@ public:
ProcessFieldsTD(Operator* op, Engine* eng);
virtual ~ProcessFieldsTD();
virtual void Process();
virtual int Process();
//! Set the length of the filename timestep pad filled with zeros (default is 8)
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)
{
@ -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;
}
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 Process() {};
void SetProcessInterval(unsigned int interval) {ProcessInterval=interval;}
virtual int Process() {return GetNextInterval();}
//! If Disabled Process() will do nothing...
virtual void SetEnable(bool val) {Enabled=val;}
@ -27,8 +28,29 @@ protected:
bool Enabled;
bool CheckTimestep();
int GetNextInterval();
unsigned int ProcessInterval;
unsigned int start[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

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;
unsigned int pos[3]={start[0],start[1],start[2]};
// cerr << Eng->volt[1][pos[0]][pos[1]][pos[2]] << endl;
@ -47,4 +48,5 @@ void ProcessVoltage::Process()
// cerr << voltage << endl;
voltages.push_back(voltage);
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 Process();
virtual int Process();
protected:
ofstream file;

View File

@ -100,7 +100,8 @@ void BuildPlaneWave(ContinuousStructure &CSX)
//E-field dump
CSPropDumpBox* Edump = new CSPropDumpBox(CSX.GetParameterSet());
Edump->SetEFieldDump(true);
Edump->SetDumpType(0);
Edump->SetName("tmp/Et_");
CSX.AddProperty(Edump);
box = new CSPrimBox(CSX.GetParameterSet(),Edump);
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);
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());
// CSX.AddProperty(metal);
// CSPrimCylinder* cyl = new CSPrimCylinder(CSX.GetParameterSet(),metal);
@ -188,7 +200,8 @@ void BuildMSL(ContinuousStructure &CSX)
//E-field dump
CSPropDumpBox* Edump = new CSPropDumpBox(CSX.GetParameterSet());
Edump->SetEFieldDump(true);
Edump->SetDumpType(0);
Edump->SetName("tmp/Et_");
CSX.AddProperty(Edump);
box = new CSPrimBox(CSX.GetParameterSet(),Edump);
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);
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;
@ -53,59 +53,68 @@ int main(int argc, char *argv[])
time_t currTime = time(NULL);
//*************** setup processing ************//
ProcessVoltage PV(&cop,&eng);
PV.OpenFile("tmp/u1");
ProcessingArray PA;
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 stop[]={0,0,0};
PV.DefineStartStopCoord(start,stop);
PV->DefineStartStopCoord(start,stop);
ProcessCurrent PCurr(&cop,&eng);
PCurr.OpenFile("tmp/i1");
ProcessCurrent* PCurr = new ProcessCurrent(&cop,&eng);
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;
stop[0]=50;stop[1]=60;stop[2]=-0;
PCurr.DefineStartStopCoord(start,stop);
PCurr->DefineStartStopCoord(start,stop);
unsigned int maxIter = 1800;
bool EnableDump = true;
vector<CSProperties*> DumpProps = CSX.GetPropertyByType(CSProperties::DUMPBOX);
vector<ProcessFieldsTD*> TD_Dump;
ProcessFieldsTD PETD(&cop,&eng);
if (DumpProps.size()>0)
for (size_t i=0;i<DumpProps.size();++i)
{
CSPrimitives* prim = DumpProps.at(0)->GetPrimitive(0);
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];
CSPropDumpBox* db = DumpProps.at(0)->ToDumpBox();
if (db)
ProcessFieldsTD* ProcTD = new ProcessFieldsTD(&cop,&eng);
ProcTD->SetEnable(EnableDump);
ProcTD->SetProcessInterval(Nyquist/2); //twice as often as nyquist dictates
//only looking for one prim atm
CSPrimitives* prim = DumpProps.at(i)->GetPrimitive(0);
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);
PETD.SetFilePattern("tmp/Et_");
ProcTD->SetDumpType(db->GetDumpType());
ProcTD->SetDumpMode(db->GetDumpMode());
ProcTD->SetFilePattern(db->GetName());
PA.AddProcessing(ProcTD);
}
else
PETD.SetEnable(false);
delete ProcTD;
}
else
PETD.SetEnable(false);
PETD.DefineStartStopCoord(start,stop);
}
PETD.SetEnable(true);
PV.Process();
PCurr.Process();
PETD.Process();
int step=PA.Process();
if ((step<0) || (step>maxIter)) step=maxIter;
//*************** simulate ************//
for (unsigned int i=0;i<maxIter;i+=NrIter)
while (eng.GetNumberOfTimesteps()<maxIter)
{
eng.IterateTS(NrIter);
PV.Process();
PCurr.Process();
PETD.Process();
eng.IterateTS(step);
step=PA.Process();
// cerr << " do " << step << " steps; current: " << eng.GetNumberOfTimesteps() << endl;
if ((step<0) || (step>maxIter - eng.GetNumberOfTimesteps())) step=maxIter - eng.GetNumberOfTimesteps();
}
//*************** 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 << "Speed: " << (double)cop.GetNumberCells()*(double)eng.GetNumberOfTimesteps()/t_diff/1e6 << " MCells/s " << endl;
//cleanup
PA.DeleteAll();
return 0;
}