/*
* Copyright (C) 2010 Thorsten Liebig (Thorsten.Liebig@gmx.de)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*/
#include "tools/array_ops.h"
#include "tools/useful.h"
#include
#include
#include "fparser.hh"
#include "tinyxml.h"
#include "excitation.h"
Excitation::Excitation( double timestep )
{
Signal_volt = 0;
Signal_curr = 0;
Volt_delay = 0;
Volt_amp = 0;
Volt_dir = 0;
Volt_Count = 0;
Curr_delay = 0;
Curr_amp = 0;
Curr_dir = 0;
Curr_Count = 0;
for (int n=0; n<3; ++n)
{
Volt_index[n] = 0;
Curr_index[n] = 0;
Volt_Count_Dir[n] = 0;
Curr_Count_Dir[n] = 0;
}
dT = timestep;
m_nyquistTS = 0;
}
Excitation::~Excitation()
{
delete[] Signal_volt;
delete[] Signal_curr;
delete[] Volt_delay;
delete[] Volt_dir;
delete[] Volt_amp;
delete[] Curr_delay;
delete[] Curr_dir;
delete[] Curr_amp;
for (int n=0; n<3; ++n)
{
delete[] Volt_index[n];
delete[] Curr_index[n];
}
}
void Excitation::Reset( double timestep )
{
delete[] Signal_volt;
Signal_volt = 0;
delete[] Signal_curr;
Signal_curr = 0;
delete[] Volt_delay;
Volt_delay = 0;
delete[] Volt_dir;
Volt_dir = 0;
delete[] Volt_amp;
Volt_amp = 0;
delete[] Curr_delay;
Curr_delay = 0;
delete[] Curr_dir;
Curr_dir = 0;
delete[] Curr_amp;
Curr_amp = 0;
Volt_Count = 0;
Curr_Count = 0;
for (int n=0; n<3; ++n)
{
delete[] Volt_index[n];
Volt_index[n] = 0;
delete[] Curr_index[n];
Curr_index[n] = 0;
Volt_Count_Dir[n] = 0;
Curr_Count_Dir[n] = 0;
}
dT = timestep;
m_nyquistTS = 0;
}
bool Excitation::setupExcitation( TiXmlElement* Excite, unsigned int maxTS )
{
if (!Excite)
{
cerr << "Can't read openEMS excitation settings... " << endl;
return false;
}
int Excit_Type=0;
double f0=0;
double fc=0;
Excite->QueryIntAttribute("Type",&Excit_Type);
switch (Excit_Type)
{
case 0:
Excite->QueryDoubleAttribute("f0",&f0);
Excite->QueryDoubleAttribute("fc",&fc);
CalcGaussianPulsExcitation(f0,fc,maxTS);
break;
case 1:
Excite->QueryDoubleAttribute("f0",&f0);
CalcSinusExcitation(f0,maxTS);
break;
case 2:
CalcDiracPulsExcitation();
break;
case 3:
CalcStepExcitation();
break;
case 10:
Excite->QueryDoubleAttribute("f0",&f0);
CalcCustomExcitation(f0,maxTS,Excite->Attribute("Function"));
break;
default:
cerr << "Excitation::setupExcitation: Unknown excitation type: \"" << Excit_Type<< "\" !!" << endl;
return false;
}
if (GetNyquistNum() == 0)
{
cerr << "Excitation::setupExcitation: Unknown error... excitation setup failed!!" << endl;
return false;
}
return true;
}
unsigned int Excitation::GetMaxExcitationTimestep() const
{
FDTD_FLOAT maxAmp=0;
unsigned int maxStep=0;
for (unsigned int n=1; nmaxAmp)
{
maxAmp = fabs(Signal_volt[n]);
maxStep = n;
}
}
return maxStep;
}
void Excitation::CalcGaussianPulsExcitation(double f0, double fc, int nTS)
{
if (dT==0) return;
Length = (unsigned int)(2.0 * 9.0/(2.0*PI*fc) / dT);
if (Length>(unsigned int)nTS)
{
cerr << "Operator::CalcGaussianPulsExcitation: Requested excitation pusle would be " << Length << " timesteps or " << Length * dT << " s long. Cutting to max number of timesteps!" << endl;
Length=(unsigned int)nTS;
}
delete[] Signal_volt;
delete[] Signal_curr;
Signal_volt = new FDTD_FLOAT[Length+1];
Signal_curr = new FDTD_FLOAT[Length+1];
Signal_volt[0]=0.0;
Signal_curr[0]=0.0;
for (unsigned int n=1; n const volt_vIndex[3], vector const& volt_vExcit,
vector const& volt_vDelay, vector const& volt_vDir )
{
Volt_Count = volt_vIndex[0].size();
for (int n=0; n<3; n++)
{
Volt_Count_Dir[n]=0;
delete[] Volt_index[n];
Volt_index[n] = new unsigned int[Volt_Count];
}
delete[] Volt_delay;
delete[] Volt_amp;
delete[] Volt_dir;
Volt_delay = new unsigned int[Volt_Count];
Volt_amp = new FDTD_FLOAT[Volt_Count];
Volt_dir = new unsigned short[Volt_Count];
// cerr << "Excitation::setupVoltageExcitation(): Number of voltage excitation points: " << Volt_Count << endl;
// if (Volt_Count==0)
// cerr << "No E-Field/voltage excitation found!" << endl;
for (int n=0; n<3; n++)
for (unsigned int i=0; i const curr_vIndex[3], vector const& curr_vExcit,
vector const& curr_vDelay, vector const& curr_vDir )
{
Curr_Count = curr_vIndex[0].size();
for (int n=0; n<3; n++)
{
Curr_Count_Dir[n]=0;
delete[] Curr_index[n];
Curr_index[n] = new unsigned int[Curr_Count];
}
delete[] Curr_delay;
delete[] Curr_amp;
delete[] Curr_dir;
Curr_delay = new unsigned int[Curr_Count];
Curr_amp = new FDTD_FLOAT[Curr_Count];
Curr_dir = new unsigned short[Curr_Count];
// cerr << "Excitation::setupCurrentExcitation(): Number of current excitation points: " << Curr_Count << endl;
// if (Curr_Count==0)
// cerr << "No H-Field/current excitation found!" << endl;
for (int n=0; n<3; ++n)
for (unsigned int i=0; i