diff --git a/FDTD/processcurrent.cpp b/FDTD/processcurrent.cpp index ad74233..9279e82 100644 --- a/FDTD/processcurrent.cpp +++ b/FDTD/processcurrent.cpp @@ -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(); } diff --git a/FDTD/processcurrent.h b/FDTD/processcurrent.h index 1910994..978d31c 100644 --- a/FDTD/processcurrent.h +++ b/FDTD/processcurrent.h @@ -13,7 +13,7 @@ public: virtual void DefineStartStopCoord(double* dstart, double* dstop); - virtual void Process(); + virtual int Process(); protected: ofstream file; diff --git a/FDTD/processfields.h b/FDTD/processfields.h index c6e55bc..2c3141c 100644 --- a/FDTD/processfields.h +++ b/FDTD/processfields.h @@ -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;} diff --git a/FDTD/processfields_td.cpp b/FDTD/processfields_td.cpp index a511fef..bb6096d 100644 --- a/FDTD/processfields_td.cpp +++ b/FDTD/processfields_td.cpp @@ -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(); } diff --git a/FDTD/processfields_td.h b/FDTD/processfields_td.h index 6f00ebf..e51c420 100644 --- a/FDTD/processfields_td.h +++ b/FDTD/processfields_td.h @@ -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;}; diff --git a/FDTD/processing.cpp b/FDTD/processing.cpp index 0f4fdff..09e89b9 100644 --- a/FDTD/processing.cpp +++ b/FDTD/processing.cpp @@ -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;iProcess(); + if ((step>0) && (step ProcessArray; +}; + #endif // PROCESSING_H diff --git a/FDTD/processvoltage.cpp b/FDTD/processvoltage.cpp index 711568f..d3683ce 100644 --- a/FDTD/processvoltage.cpp +++ b/FDTD/processvoltage.cpp @@ -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(); } diff --git a/FDTD/processvoltage.h b/FDTD/processvoltage.h index 604e827..772fd5a 100644 --- a/FDTD/processvoltage.h +++ b/FDTD/processvoltage.h @@ -12,7 +12,7 @@ public: virtual void OpenFile(string outfile); - virtual void Process(); + virtual int Process(); protected: ofstream file; diff --git a/examples/FDTD_examples.cpp b/examples/FDTD_examples.cpp index 05eff48..10fdc93 100644 --- a/examples/FDTD_examples.cpp +++ b/examples/FDTD_examples.cpp @@ -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); diff --git a/main.cpp b/main.cpp index 737cc87..b759e90 100644 --- a/main.cpp +++ b/main.cpp @@ -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 DumpProps = CSX.GetPropertyByType(CSProperties::DUMPBOX); - vector TD_Dump; - ProcessFieldsTD PETD(&cop,&eng); - if (DumpProps.size()>0) + for (size_t i=0;iGetPrimitive(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;imaxIter - 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; }