removed FDTD engine from (nearly) all processing classes

todo:
 - remove FTDT operator from all processingX and replace by abstract-base-operator?
 - remove FDTD engine from ProcessCurrent
 - remove or cleanup ProcessEField + ProcessHField

Signed-off-by: Thorsten Liebig <Thorsten.Liebig@gmx.de>
pull/1/head
Thorsten Liebig 2010-12-02 14:29:46 +01:00
parent ab1119f468
commit 32cbdc5d0b
20 changed files with 183 additions and 189 deletions

View File

@ -44,9 +44,18 @@ public:
//! Get the (interpolated) magnetic field at \p pos. \sa SetInterpolationType
virtual double* GetHField(const unsigned int* pos, double* out) const {UNUSED(pos);return out;}
//! Calculate the electric field integral along a given line
virtual double CalcVoltageIntegral(const unsigned int* start, const unsigned int* stop) const {UNUSED(start);UNUSED(stop);return 0.0;}
//! Convert the interpolation type into a string.
static std::string GetInterpolationNameByType(InterpolationType mode);
//! Get the current simulation time
virtual double GetTime(bool dualTime=false) const {UNUSED(dualTime);return 0.0;}
//! Get the current number of timesteps
virtual unsigned int GetNumberOfTimesteps() const {return 0;}
protected:
Engine_Interface_Base();

View File

@ -161,3 +161,24 @@ double* Engine_Interface_FDTD::GetHField(const unsigned int* pos, double* out) c
return out;
}
double Engine_Interface_FDTD::CalcVoltageIntegral(const unsigned int* start, const unsigned int* stop) const
{
double result=0;
for (int n=0;n<3;++n)
{
if (start[n]<stop[n])
{
unsigned int pos[3]={start[0],start[1],start[2]};
for (;pos[n]<stop[n];++pos[n])
result += m_Eng->GetVolt(n,pos[0],pos[1],pos[2]);
}
else
{
unsigned int pos[3]={stop[0],stop[1],stop[2]};
for (;pos[n]<start[n];++pos[n])
result -= m_Eng->GetVolt(n,pos[0],pos[1],pos[2]);
}
}
return result;
}

View File

@ -44,6 +44,11 @@ public:
virtual double* GetEField(const unsigned int* pos, double* out) const;
virtual double* GetHField(const unsigned int* pos, double* out) const;
virtual double CalcVoltageIntegral(const unsigned int* start, const unsigned int* stop) const;
virtual double GetTime(bool dualTime=false) const {return ((double)m_Eng->GetNumberOfTimesteps() + (double)dualTime*0.5)*m_Op->GetTimestep();};
virtual unsigned int GetNumberOfTimesteps() const {return m_Eng->GetNumberOfTimesteps();}
protected:
Operator* m_Op;
Engine* m_Eng;

View File

@ -19,8 +19,9 @@
#include "time.h"
#include "process_efield.h"
ProcessEField::ProcessEField(Operator* op, Engine* eng) : Processing(op, eng)
ProcessEField::ProcessEField(Operator* op, Engine* eng) : Processing(op)
{
Eng = eng;
}
ProcessEField::~ProcessEField()

View File

@ -37,6 +37,7 @@ public:
virtual int Process();
protected:
Engine* Eng;
vector<double_complex> FD_Values[3];
};

View File

@ -17,9 +17,10 @@
#include "tools/global.h"
#include "processcurrent.h"
#include "engine_interface_fdtd.h"
#include <iomanip>
ProcessCurrent::ProcessCurrent(Operator* op, Engine* eng) : ProcessIntegral(op, eng)
ProcessCurrent::ProcessCurrent(Operator* op) : ProcessIntegral(op)
{
m_TimeShift = op->GetTimestep()/2.0;
m_dualMesh = true;
@ -33,6 +34,12 @@ double ProcessCurrent::CalcIntegral()
{
FDTD_FLOAT current=0;
Engine_Interface_FDTD* EI_FDTD = dynamic_cast<Engine_Interface_FDTD*>(m_Eng_Interface);
if (EI_FDTD)
{
const Engine* Eng = EI_FDTD->GetFDTDEngine();
int Dump_Dim = 0;
int NormDir = 0;
@ -124,6 +131,7 @@ double ProcessCurrent::CalcIntegral()
return 0.0;
break;
}
}
return current;
}

View File

@ -23,7 +23,7 @@
class ProcessCurrent : public ProcessIntegral
{
public:
ProcessCurrent(Operator* op, Engine* eng);
ProcessCurrent(Operator* op);
virtual ~ProcessCurrent();
//! Integrate currents flowing through an area

View File

@ -19,8 +19,9 @@
#include <H5Cpp.h>
#include "tools/global.h"
#include "processfields.h"
#include "engine_interface_fdtd.h"
ProcessFields::ProcessFields(Operator* op, Engine* eng) : Processing(op, eng)
ProcessFields::ProcessFields(Operator* op) : Processing(op)
{
m_DumpType = E_FIELD_DUMP;
// vtk-file is default
@ -212,10 +213,14 @@ void ProcessFields::DefineStartStopCoord(double* dstart, double* dstop)
double ProcessFields::CalcTotalEnergy() const
{
if (!Eng)
return 0;
double energy=0.0;
Engine_Interface_FDTD* EI_FDTD = dynamic_cast<Engine_Interface_FDTD*>(m_Eng_Interface);
if (EI_FDTD)
{
const Engine* Eng = EI_FDTD->GetFDTDEngine();
double energy=0;
unsigned int pos[3];
for (pos[0]=0;pos[0]<Op->GetNumberOfLines(0);++pos[0])
{
@ -232,6 +237,7 @@ double ProcessFields::CalcTotalEnergy() const
}
}
}
}
return energy*0.5;
}

View File

@ -26,7 +26,7 @@
class ProcessFields : public Processing
{
public:
ProcessFields(Operator* op, Engine* eng);
ProcessFields(Operator* op);
virtual ~ProcessFields();
enum FileType { VTK_FILETYPE, HDF5_FILETYPE};

View File

@ -20,7 +20,7 @@
#include <sstream>
#include <string>
ProcessFieldsTD::ProcessFieldsTD(Operator* op, Engine* eng) : ProcessFields(op, eng)
ProcessFieldsTD::ProcessFieldsTD(Operator* op) : ProcessFields(op)
{
pad_length = 8;
}
@ -40,7 +40,7 @@ int ProcessFieldsTD::Process()
if (m_fileType==VTK_FILETYPE)
{
stringstream ss;
ss << filePattern << std::setw( pad_length ) << std::setfill( '0' ) << Eng->GetNumberOfTimesteps() << ".vtk";
ss << filePattern << std::setw( pad_length ) << std::setfill( '0' ) << m_Eng_Interface->GetNumberOfTimesteps() << ".vtk";
filename = ss.str();
}
else
@ -107,8 +107,8 @@ int ProcessFieldsTD::Process()
else if (m_fileType==HDF5_FILETYPE)
{
stringstream ss;
ss << std::setw( pad_length ) << std::setfill( '0' ) << Eng->GetNumberOfTimesteps();
DumpVectorArray2HDF5(filename.c_str(),string( ss.str() ),field,numLines,(0.5+Eng->GetNumberOfTimesteps())*Op->GetTimestep());
ss << std::setw( pad_length ) << std::setfill( '0' ) << m_Eng_Interface->GetNumberOfTimesteps();
DumpVectorArray2HDF5(filename.c_str(),string( ss.str() ),field,numLines,(0.5+m_Eng_Interface->GetNumberOfTimesteps())*Op->GetTimestep());
}
else
cerr << "ProcessFieldsTD::Process: unknown File-Type" << endl;

View File

@ -23,7 +23,7 @@
class ProcessFieldsTD : public ProcessFields
{
public:
ProcessFieldsTD(Operator* op, Engine* eng);
ProcessFieldsTD(Operator* op);
virtual ~ProcessFieldsTD();
virtual int Process();

View File

@ -21,10 +21,9 @@
#include "time.h"
#include <climits>
Processing::Processing(Operator* op, Engine* eng)
Processing::Processing(Operator* op)
{
Op=op;
Eng=eng;
Enabled = true;
m_PS_pos = 0;
SetPrecision(12);
@ -59,7 +58,7 @@ bool Processing::CheckTimestep()
{
if (m_ProcessSteps.size()>m_PS_pos)
{
if (m_ProcessSteps.at(m_PS_pos)==Eng->GetNumberOfTimesteps())
if (m_ProcessSteps.at(m_PS_pos)==m_Eng_Interface->GetNumberOfTimesteps())
{
++m_PS_pos;
return true;
@ -67,12 +66,12 @@ bool Processing::CheckTimestep()
}
if (ProcessInterval)
{
if (Eng->GetNumberOfTimesteps()%ProcessInterval==0) return true;
if (m_Eng_Interface->GetNumberOfTimesteps()%ProcessInterval==0) return true;
}
if (m_FD_Interval)
{
if (Eng->GetNumberOfTimesteps()%m_FD_Interval==0) return true;
if (m_Eng_Interface->GetNumberOfTimesteps()%m_FD_Interval==0) return true;
}
return false;
}
@ -83,11 +82,11 @@ int Processing::GetNextInterval() const
int next=INT_MAX;
if (m_ProcessSteps.size()>m_PS_pos)
{
next = (int)m_ProcessSteps.at(m_PS_pos)-(int)Eng->GetNumberOfTimesteps();
next = (int)m_ProcessSteps.at(m_PS_pos)-(int)m_Eng_Interface->GetNumberOfTimesteps();
}
if (ProcessInterval!=0)
{
int next_Interval = (int)ProcessInterval - (int)Eng->GetNumberOfTimesteps()%ProcessInterval;
int next_Interval = (int)ProcessInterval - (int)m_Eng_Interface->GetNumberOfTimesteps()%ProcessInterval;
if (next_Interval<next)
next = next_Interval;
}
@ -95,7 +94,7 @@ int Processing::GetNextInterval() const
//check for FD sample interval
if (m_FD_Interval!=0)
{
int next_Interval = (int)m_FD_Interval - (int)Eng->GetNumberOfTimesteps()%m_FD_Interval;
int next_Interval = (int)m_FD_Interval - (int)m_Eng_Interface->GetNumberOfTimesteps()%m_FD_Interval;
if (next_Interval<next)
next = next_Interval;
}
@ -165,58 +164,6 @@ void Processing::DefineStartStopCoord(double* dstart, double* dstop)
}
}
double Processing::CalcLineIntegral(unsigned int* start, unsigned int* stop, int field) const
{
switch (field) {
case 0:
return CalcLineIntegral_V( start, stop );
case 1:
return CalcLineIntegral_I( start, stop );
}
return 0;
}
double Processing::CalcLineIntegral_I(unsigned int* start, unsigned int* stop) const
{
double result=0;
for (int n=0;n<3;++n)
{
if (start[n]<stop[n])
{
unsigned int pos[3]={start[0],start[1],start[2]};
for (;pos[n]<stop[n];++pos[n])
result += Eng->GetCurr(n,pos[0],pos[1],pos[2]);
}
else
{
unsigned int pos[3]={stop[0],stop[1],stop[2]};
for (;pos[n]<start[n];++pos[n])
result -= Eng->GetCurr(n,pos[0],pos[1],pos[2]);
}
}
return result;
}
double Processing::CalcLineIntegral_V(unsigned int* start, unsigned int* stop) const
{
double result=0;
for (int n=0;n<3;++n)
{
if (start[n]<stop[n])
{
unsigned int pos[3]={start[0],start[1],start[2]};
for (;pos[n]<stop[n];++pos[n])
result += Eng->GetVolt(n,pos[0],pos[1],pos[2]);
}
else
{
unsigned int pos[3]={stop[0],stop[1],stop[2]};
for (;pos[n]<start[n];++pos[n])
result -= Eng->GetVolt(n,pos[0],pos[1],pos[2]);
}
}
return result;
}
void Processing::OpenFile( string outfile )
{
if (file.is_open())

View File

@ -33,7 +33,7 @@ typedef std::complex<double> double_complex;
class Processing
{
public:
Processing(Operator* op, Engine* eng);
Processing(Operator* op);
virtual ~Processing();
//! Set the interface to the engine. Each processing needs its own engine interface. This class will take ownership and cleanup the interface on deletion!
@ -85,7 +85,6 @@ public:
protected:
Engine_Interface_Base* m_Eng_Interface;
Operator* Op;
Engine* Eng;
MeshType m_Mesh_Type;
unsigned int m_precision;
@ -128,10 +127,6 @@ protected:
string m_filename;
virtual void OpenFile(string outfile);
double CalcLineIntegral(unsigned int* start, unsigned int* stop, int field) const;
double CalcLineIntegral_I(unsigned int* start, unsigned int* stop) const;
double CalcLineIntegral_V(unsigned int* start, unsigned int* stop) const;
};
class ProcessingArray

View File

@ -18,7 +18,7 @@
#include "processintegral.h"
#include <iomanip>
ProcessIntegral::ProcessIntegral(Operator* op, Engine* eng) : Processing(op, eng)
ProcessIntegral::ProcessIntegral(Operator* op) : Processing(op)
{
m_TimeShift = 0.0;
m_Results=NULL;
@ -56,11 +56,11 @@ int ProcessIntegral::Process()
int NrInt = GetNumberOfIntegrals();
double integral = m_Results[0] * m_weight;
double time = (double)Eng->GetNumberOfTimesteps()*Op->GetTimestep() + m_TimeShift;
double time = m_Eng_Interface->GetTime(false) + m_TimeShift;
if (ProcessInterval)
{
if (Eng->GetNumberOfTimesteps()%ProcessInterval==0)
if (m_Eng_Interface->GetNumberOfTimesteps()%ProcessInterval==0)
{
TD_Values.push_back(integral);
file << setprecision(m_precision) << time;
@ -72,7 +72,7 @@ int ProcessIntegral::Process()
if (m_FD_Interval)
{
if (Eng->GetNumberOfTimesteps()%m_FD_Interval==0)
if (m_Eng_Interface->GetNumberOfTimesteps()%m_FD_Interval==0)
{
double T = time;
for (size_t n=0;n<m_FD_Samples.size();++n)

View File

@ -51,7 +51,7 @@ public:
virtual int Process();
protected:
ProcessIntegral(Operator* op, Engine* eng);
ProcessIntegral(Operator* op);
//! timeshift to be used in TD and FD data, e.g. 0.5*dT in case of current based parameter
double m_TimeShift;

View File

@ -19,7 +19,7 @@
#include "CSFunctionParser.h"
#include "tools/array_ops.h"
ProcessModeMatch::ProcessModeMatch(Operator* op, Engine* eng) : ProcessIntegral(op, eng)
ProcessModeMatch::ProcessModeMatch(Operator* op) : ProcessIntegral(op)
{
for (int n=0;n<2;++n)
{

View File

@ -25,7 +25,7 @@ class CSFunctionParser;
class ProcessModeMatch : public ProcessIntegral
{
public:
ProcessModeMatch(Operator* op, Engine* eng);
ProcessModeMatch(Operator* op);
virtual ~ProcessModeMatch();
virtual void InitProcess();

View File

@ -18,7 +18,7 @@
#include "processvoltage.h"
#include <iomanip>
ProcessVoltage::ProcessVoltage(Operator* op, Engine* eng) : ProcessIntegral(op, eng)
ProcessVoltage::ProcessVoltage(Operator* op) : ProcessIntegral(op)
{
}
@ -29,5 +29,5 @@ ProcessVoltage::~ProcessVoltage()
double ProcessVoltage::CalcIntegral()
{
//integrate voltages from start to stop on a line
return CalcLineIntegral(start,stop,0);
return m_Eng_Interface->CalcVoltageIntegral(start,stop);
}

View File

@ -24,7 +24,7 @@
class ProcessVoltage : public ProcessIntegral
{
public:
ProcessVoltage(Operator* op, Engine* eng);
ProcessVoltage(Operator* op);
virtual ~ProcessVoltage();
virtual double CalcIntegral();

View File

@ -447,12 +447,12 @@ int openEMS::SetupFDTD(const char* file)
{
if (pb->GetProbeType()==0)
{
ProcessVoltage* procVolt = new ProcessVoltage(FDTD_Op,FDTD_Eng);
ProcessVoltage* procVolt = new ProcessVoltage(FDTD_Op);
proc=procVolt;
}
else if (pb->GetProbeType()==1)
{
ProcessCurrent* procCurr = new ProcessCurrent(FDTD_Op,FDTD_Eng);
ProcessCurrent* procCurr = new ProcessCurrent(FDTD_Op);
proc=procCurr;
}
else if (pb->GetProbeType()==2)
@ -461,7 +461,7 @@ int openEMS::SetupFDTD(const char* file)
proc = new ProcessHField(FDTD_Op,FDTD_Eng);
else if ((pb->GetProbeType()==10) || (pb->GetProbeType()==11))
{
ProcessModeMatch* pmm = new ProcessModeMatch(FDTD_Op,FDTD_Eng);
ProcessModeMatch* pmm = new ProcessModeMatch(FDTD_Op);
pmm->SetFieldType(pb->GetProbeType()-10);
pmm->SetModeFunction(0,pb->GetAttributeValue("ModeFunctionX"));
pmm->SetModeFunction(1,pb->GetAttributeValue("ModeFunctionY"));
@ -493,7 +493,7 @@ int openEMS::SetupFDTD(const char* file)
vector<CSProperties*> DumpProps = CSX.GetPropertyByType(CSProperties::DUMPBOX);
for (size_t i=0;i<DumpProps.size();++i)
{
ProcessFieldsTD* ProcTD = new ProcessFieldsTD(FDTD_Op,FDTD_Eng);
ProcessFieldsTD* ProcTD = new ProcessFieldsTD(FDTD_Op);
ProcTD->SetEnable(Enable_Dumps);
ProcTD->SetProcessInterval(Nyquist/m_OverSampling);
@ -581,7 +581,8 @@ void openEMS::RunFDTD()
cout << "Running FDTD engine... this may take a while... grab a cup of coffee?!?" << endl;
//special handling of a field processing, needed to realize the end criteria...
ProcessFields* ProcField = new ProcessFields(FDTD_Op,FDTD_Eng);
ProcessFields* ProcField = new ProcessFields(FDTD_Op);
ProcField->SetEngineInterface(new Engine_Interface_FDTD(FDTD_Op,FDTD_Eng));
PA->AddProcessing(ProcField);
double maxE=0,currE=0;