From 8cc42b911c634bba357b0f04d6750cf5e2db3808 Mon Sep 17 00:00:00 2001 From: Thorsten Liebig Date: Sat, 3 Apr 2010 17:36:50 +0200 Subject: [PATCH] added processing steps and fix in end criteria check, now checking max excite TS --- FDTD/operator.cpp | 15 ++++++++++++ FDTD/operator.h | 3 +++ FDTD/processing.cpp | 57 ++++++++++++++++++++++++++++++++++++++++++--- FDTD/processing.h | 17 +++++++++++--- openems.cpp | 20 ++++++++++++++-- 5 files changed, 104 insertions(+), 8 deletions(-) diff --git a/FDTD/operator.cpp b/FDTD/operator.cpp index 381f754..4042ccf 100644 --- a/FDTD/operator.cpp +++ b/FDTD/operator.cpp @@ -230,6 +230,21 @@ void Operator::ShowStat() const cout << "-----------------------------------" << endl; } +unsigned int Operator::GetMaxExcitationTimestep() const +{ + FDTD_FLOAT maxAmp=0; + unsigned int maxStep=0; + for (unsigned int n=1;nmaxAmp) + { + maxAmp = fabs(ExciteSignal[n]); + maxStep = n; + } + } + return maxStep; +} + unsigned int Operator::CalcGaussianPulsExcitation(double f0, double fc) { if (dT==0) return 0; diff --git a/FDTD/operator.h b/FDTD/operator.h index 9ec8916..11a27e1 100644 --- a/FDTD/operator.h +++ b/FDTD/operator.h @@ -44,6 +44,9 @@ public: //! Calculate a step excitation \return number of Nyquist timesteps virtual unsigned int CalcStepExcitation(); + //! Get the excitation timestep with the (first) max amplitude + virtual unsigned int GetMaxExcitationTimestep() const; + virtual void ApplyElectricBC(bool* dirs); //applied by default to all boundaries virtual void ApplyMagneticBC(bool* dirs); diff --git a/FDTD/processing.cpp b/FDTD/processing.cpp index a54dcca..4f25a3f 100644 --- a/FDTD/processing.cpp +++ b/FDTD/processing.cpp @@ -22,22 +22,65 @@ Processing::Processing(Operator* op, Engine* eng) Op=op; Eng=eng; Enabled = true; + m_PS_pos = 0; + ProcessInterval=0; } Processing::~Processing() { } +void Processing::Reset() +{ + m_PS_pos=0; +} + bool Processing::CheckTimestep() { - if (Eng->GetNumberOfTimesteps()%ProcessInterval==0) return true; + if (m_ProcessSteps.size()>m_PS_pos) + { + if (m_ProcessSteps.at(m_PS_pos)==Eng->GetNumberOfTimesteps()) + { + ++m_PS_pos; + return true; + } + } + if (ProcessInterval) + { + if (Eng->GetNumberOfTimesteps()%ProcessInterval==0) return true; + } return false; } -int Processing::GetNextInterval() +int Processing::GetNextInterval() const { if (Enabled==false) return -1; - return ProcessInterval - Eng->GetNumberOfTimesteps()%ProcessInterval; + unsigned int next=-1; + if (m_ProcessSteps.size()>m_PS_pos) + { + next = m_ProcessSteps.at(m_PS_pos)-Eng->GetNumberOfTimesteps(); + } + if (ProcessInterval==0) return next; + unsigned int next_Interval = ProcessInterval - Eng->GetNumberOfTimesteps()%ProcessInterval; + if (next_Interval steps) +{ + for (size_t n=0;nReset(); + } +} + void ProcessingArray::DeleteAll() { for (size_t i=0;i steps); + + bool CheckTimestep(); virtual int Process() {return GetNextInterval();} //! If Disabled Process() will do nothing... virtual void SetEnable(bool val) {Enabled=val;} //! If Disabled Process() will do nothing... - virtual bool GetEnable() {return Enabled;} + virtual bool GetEnable() const {return Enabled;} protected: Operator* Op; @@ -45,10 +52,12 @@ protected: bool Enabled; - bool CheckTimestep(); - int GetNextInterval(); + int GetNextInterval() const; unsigned int ProcessInterval; + size_t m_PS_pos; //! current position in list of processing steps + vector m_ProcessSteps; //! list of processing steps + unsigned int start[3]; unsigned int stop[3]; @@ -63,6 +72,8 @@ public: void AddProcessing(Processing* proc); + void Reset(); + //! Deletes all given processing's, can be helpful, but use carefull!!! void DeleteAll(); diff --git a/openems.cpp b/openems.cpp index 6ec27dc..8515c4c 100644 --- a/openems.cpp +++ b/openems.cpp @@ -358,8 +358,16 @@ void openEMS::RunFDTD() { cout << "Running FDTD engine... this may take a while... grab a cup of coffee?!?" << endl; - ProcessFields ProcField(FDTD_Op,FDTD_Eng); + //special handling of a field processing, needed to realize the end criteria... + ProcessFields* ProcField = new ProcessFields(FDTD_Op,FDTD_Eng); + PA->AddProcessing(ProcField); double maxE=0,currE=0; + + //add all timesteps to end-crit field processing with max excite amplitude + unsigned int maxExcite = FDTD_Op->GetMaxExcitationTimestep(); + for (unsigned int n=0;nE_Exc_Count;++n) + ProcField->AddStep(FDTD_Op->E_Exc_delay[n]+maxExcite); + double change=1; int prevTS=0,currTS=0; double speed = FDTD_Op->GetNumberCells()/1e6; @@ -378,6 +386,14 @@ void openEMS::RunFDTD() { FDTD_Eng->IterateTS(step); step=PA->Process(); + + if (ProcField->CheckTimestep()) + { + currE = ProcField->CalcTotalEnergy(); + if (currE>maxE) + maxE=currE; + } + // cout << " do " << step << " steps; current: " << eng.GetNumberOfTimesteps() << endl; currTS = FDTD_Eng->GetNumberOfTimesteps(); if ((step<0) || (step>(int)(NrTS - currTS))) step=NrTS - currTS; @@ -387,7 +403,7 @@ void openEMS::RunFDTD() t_diff = CalcDiffTime(currTime,prevTime); if (t_diff>4) { - currE = ProcField.CalcTotalEnergy(); + currE = ProcField->CalcTotalEnergy(); if (currE>maxE) maxE=currE; cout << "[@" << setw(8) << (int)CalcDiffTime(currTime,startTime) << "s] Timestep: " << setw(12) << currTS << " (" << setw(6) << setprecision(2) << std::fixed << (double)currTS/(double)NrTS*100.0 << "%)" ;