From 9c806728553953389a590a8db1fb31ff6a4d06b6 Mon Sep 17 00:00:00 2001 From: Thorsten Liebig Date: Thu, 3 Sep 2015 22:53:31 +0200 Subject: [PATCH] excitation: store only 2 periods of periodic excitations Signed-off-by: Thorsten Liebig --- FDTD/excitation.cpp | 4 ++-- FDTD/extensions/engine_ext_excitation.cpp | 8 ++++++++ FDTD/extensions/engine_ext_tfsf.cpp | 12 ++++++++++-- openems.cpp | 22 +++++++++++++++++----- 4 files changed, 37 insertions(+), 9 deletions(-) diff --git a/FDTD/excitation.cpp b/FDTD/excitation.cpp index c2a0c8f..118c205 100644 --- a/FDTD/excitation.cpp +++ b/FDTD/excitation.cpp @@ -251,8 +251,8 @@ void Excitation::CalcSinusExcitation(double f0, int nTS) if (dT==0) return; if (nTS<=0) return; - Length = (unsigned int)(nTS); -// cerr << "Operator::CalcSinusExcitation: Length of the excite signal: " << ExciteLength << " timesteps" << endl; + Length = (unsigned int)(2.0/f0/dT); + //cerr << "Operator::CalcSinusExcitation: Length of the excite signal: " << Length << " timesteps " << Length*dT << "s" << endl; delete[] Signal_volt; delete[] Signal_curr; Signal_volt = new FDTD_FLOAT[Length+1]; diff --git a/FDTD/extensions/engine_ext_excitation.cpp b/FDTD/extensions/engine_ext_excitation.cpp index bcb7b6e..5f26637 100644 --- a/FDTD/extensions/engine_ext_excitation.cpp +++ b/FDTD/extensions/engine_ext_excitation.cpp @@ -40,6 +40,10 @@ void Engine_Ext_Excitation::Apply2Voltages() unsigned int length = m_Op_Exc->m_Exc->GetLength(); FDTD_FLOAT* exc_volt = m_Op_Exc->m_Exc->GetVoltageSignal(); + int p = int(m_Op_Exc->m_Exc->GetSignalPeriod()/m_Op_Exc->m_Exc->GetTimestep()); + if (p>0) + numTS = (numTS % p) + p; + //switch for different engine types to access faster inline engine functions switch (m_Eng->GetType()) { @@ -100,6 +104,10 @@ void Engine_Ext_Excitation::Apply2Current() unsigned int length = m_Op_Exc->m_Exc->GetLength(); FDTD_FLOAT* exc_curr = m_Op_Exc->m_Exc->GetCurrentSignal(); + int p = int(m_Op_Exc->m_Exc->GetSignalPeriod()/m_Op_Exc->m_Exc->GetTimestep()); + if (p>0) + numTS = (numTS % p) + p; + //switch for different engine types to access faster inline engine functions switch (m_Eng->GetType()) { diff --git a/FDTD/extensions/engine_ext_tfsf.cpp b/FDTD/extensions/engine_ext_tfsf.cpp index e9ac796..cd3b107 100644 --- a/FDTD/extensions/engine_ext_tfsf.cpp +++ b/FDTD/extensions/engine_ext_tfsf.cpp @@ -38,14 +38,18 @@ void Engine_Ext_TFSF::DoPostVoltageUpdates() unsigned int numTS = m_Eng->GetNumberOfTimesteps(); unsigned int length = m_Op_TFSF->m_Exc->GetLength(); + int p = int(m_Op_TFSF->m_Exc->GetSignalPeriod()/m_Op_TFSF->m_Exc->GetTimestep()); + for (unsigned int n=0;n<=m_Op_TFSF->m_maxDelay;++n) { if ( numTS < n ) m_DelayLookup[n]=0; - else if ( numTS-n > length) + else if ((numTS-n > length) && (p==0)) m_DelayLookup[n]=0; else m_DelayLookup[n] = numTS - n; + if (p>0) + m_DelayLookup[n] = (m_DelayLookup[n] % p); } //get the current signal since an H-field is added ... @@ -124,14 +128,18 @@ void Engine_Ext_TFSF::DoPostCurrentUpdates() unsigned int numTS = m_Eng->GetNumberOfTimesteps(); unsigned int length = m_Op_TFSF->m_Exc->GetLength(); + int p = int(m_Op_TFSF->m_Exc->GetSignalPeriod()/m_Op_TFSF->m_Exc->GetTimestep()); + for (unsigned int n=0;nm_maxDelay;++n) { if ( numTS < n ) m_DelayLookup[n]=0; - else if ( numTS-n > length) + else if ((numTS-n > length) && (p==0)) m_DelayLookup[n]=0; else m_DelayLookup[n] = numTS - n; + if (p>0) + m_DelayLookup[n] = (m_DelayLookup[n] % p); } //get the current signal since an E-field is added ... diff --git a/openems.cpp b/openems.cpp index 90a3fec..8489257 100644 --- a/openems.cpp +++ b/openems.cpp @@ -805,11 +805,23 @@ int openEMS::SetupFDTD(const char* file) if (m_Exc->GetNyquistNum()>1000) cerr << "openEMS::SetupFDTD: Warning, the timestep seems to be very small --> long simulation. Check your mesh!?" << endl; - cout << "Excitation signal length is: " << m_Exc->GetLength() << " timesteps (" << m_Exc->GetLength()*FDTD_Op->GetTimestep() << "s)" << endl; - cout << "Max. number of timesteps: " << NrTS << " ( --> " << (double)NrTS/(double)(m_Exc->GetLength()) << " * Excitation signal length)" << endl; - if ( ((double)NrTS/(double)m_Exc->GetLength() < 3) && (m_Exc->GetExciteType()==0)) - cerr << "openEMS::SetupFDTD: Warning, max. number of timesteps is smaller than three times the excitation. " << endl << \ - "\tYou may want to choose a higher number of max. timesteps... " << endl; + if (m_Exc->GetSignalPeriod()==0) + { + cout << "Excitation signal length is: " << m_Exc->GetLength() << " timesteps (" << m_Exc->GetLength()*FDTD_Op->GetTimestep() << "s)" << endl; + cout << "Max. number of timesteps: " << NrTS << " ( --> " << (double)NrTS/(double)(m_Exc->GetLength()) << " * Excitation signal length)" << endl; + if ( ((double)NrTS/(double)m_Exc->GetLength() < 3) && (m_Exc->GetExciteType()==0)) + cerr << "openEMS::SetupFDTD: Warning, max. number of timesteps is smaller than three times the excitation. " << endl << \ + "\tYou may want to choose a higher number of max. timesteps... " << endl; + } + else + { + int p = int(m_Exc->GetSignalPeriod()/FDTD_Op->GetTimestep()); + cout << "Excitation signal period is: " << p << " timesteps (" << m_Exc->GetSignalPeriod() << "s)" << endl; + cout << "Max. number of timesteps: " << NrTS << " ( --> " << (double)NrTS/(double)(m_Exc->GetLength()) << " * Excitation signal period)" << endl; + if (NrTS/p < 3) + cerr << "openEMS::SetupFDTD: Warning, max. number of timesteps is smaller than three times the excitation signal period. " << endl << \ + "\tYou may want to choose a higher number of max. timesteps... " << endl; + } if (m_no_simulation) {