new ProcessingIntegral as abstract base class to voltage and current processing

pull/1/head
Thorsten Liebig 2010-06-28 19:45:19 +02:00
parent e880fa3ee8
commit 0f4a78cdbf
8 changed files with 108 additions and 53 deletions

View File

@ -20,13 +20,12 @@
#include <iomanip> #include <iomanip>
#include <complex.h> #include <complex.h>
ProcessCurrent::ProcessCurrent(Operator* op, Engine* eng) : Processing(op, eng) ProcessCurrent::ProcessCurrent(Operator* op, Engine* eng) : ProcessIntegral(op, eng)
{ {
} }
ProcessCurrent::~ProcessCurrent() ProcessCurrent::~ProcessCurrent()
{ {
ProcessCurrent::FlushData();
} }
void ProcessCurrent::DefineStartStopCoord(double* dstart, double* dstop) void ProcessCurrent::DefineStartStopCoord(double* dstart, double* dstop)
@ -46,16 +45,6 @@ void ProcessCurrent::DefineStartStopCoord(double* dstart, double* dstop)
} }
} }
void ProcessCurrent::InitProcess()
{
m_filename = m_Name;
OpenFile(m_filename);
FD_currents.clear();
for (size_t n=0;n<m_FD_Samples.size();++n)
FD_currents.push_back(0);
}
int ProcessCurrent::Process() int ProcessCurrent::Process()
{ {
if (Enabled==false) return -1; if (Enabled==false) return -1;
@ -157,11 +146,12 @@ int ProcessCurrent::Process()
// cerr << "ts: " << Eng->numTS << " i: " << current << endl; // cerr << "ts: " << Eng->numTS << " i: " << current << endl;
current*=m_weight; current*=m_weight;
if (ProcessInterval) if (ProcessInterval)
{ {
if (Eng->GetNumberOfTimesteps()%ProcessInterval==0) if (Eng->GetNumberOfTimesteps()%ProcessInterval==0)
{ {
v_current.push_back(current); TD_Values.push_back(current);
//current is sampled half a timestep later then the voltages //current is sampled half a timestep later then the voltages
file << setprecision(m_precision) << (0.5 + (double)Eng->GetNumberOfTimesteps())*Op->GetTimestep() << "\t" << current << endl; file << setprecision(m_precision) << (0.5 + (double)Eng->GetNumberOfTimesteps())*Op->GetTimestep() << "\t" << current << endl;
} }
@ -174,7 +164,7 @@ int ProcessCurrent::Process()
double T = ((double)Eng->GetNumberOfTimesteps() + 0.5) * Op->GetTimestep(); double T = ((double)Eng->GetNumberOfTimesteps() + 0.5) * Op->GetTimestep();
for (size_t n=0;n<m_FD_Samples.size();++n) for (size_t n=0;n<m_FD_Samples.size();++n)
{ {
FD_currents.at(n) += current * cexp( -2.0 * 1.0i * M_PI * m_FD_Samples.at(n) * T ); FD_Values.at(n) += current * cexp( -2.0 * 1.0i * M_PI * m_FD_Samples.at(n) * T );
} }
++m_FD_SampleCount; ++m_FD_SampleCount;
if (m_Flush) if (m_Flush)
@ -191,7 +181,3 @@ void ProcessCurrent::DumpBox2File( string vtkfilenameprefix, bool /*dualMesh*/ )
Processing::DumpBox2File( vtkfilenameprefix, true ); Processing::DumpBox2File( vtkfilenameprefix, true );
} }
void ProcessCurrent::FlushData()
{
Dump_FD_Data(FD_currents,1.0/(double)m_FD_SampleCount,m_filename + "_FD");
}

View File

@ -18,9 +18,9 @@
#ifndef PROCESSCURRENT_H #ifndef PROCESSCURRENT_H
#define PROCESSCURRENT_H #define PROCESSCURRENT_H
#include "processing.h" #include "processintegral.h"
class ProcessCurrent : public Processing class ProcessCurrent : public ProcessIntegral
{ {
public: public:
ProcessCurrent(Operator* op, Engine* eng); ProcessCurrent(Operator* op, Engine* eng);
@ -28,16 +28,11 @@ public:
virtual void DefineStartStopCoord(double* dstart, double* dstop); virtual void DefineStartStopCoord(double* dstart, double* dstop);
virtual void InitProcess();
virtual void FlushData();
virtual int Process(); virtual int Process();
virtual void DumpBox2File( string vtkfilenameprefix, bool dualMesh = false ) const; //!< dump geometry to file virtual void DumpBox2File( string vtkfilenameprefix, bool dualMesh = false ) const; //!< dump geometry to file
protected:
vector<FDTD_FLOAT> v_current;
vector<_Complex double> FD_currents; protected:
void WriteFDCurrents();
}; };
#endif // PROCESSCURRENT_H #endif // PROCESSCURRENT_H

View File

@ -275,11 +275,21 @@ void Processing::DumpBox2File( string vtkfilenameprefix, bool dualMesh ) const
void Processing::Dump_FD_Data(vector<_Complex double> value, double factor, string filename) void Processing::Dump_FD_Data(vector<_Complex double> value, double factor, string filename)
{ {
if (value.size()==0)
return;
if (value.size()!=m_FD_Samples.size())
{
cerr << "Processing::Dump_FD_Data: Error: Complex value and frequency vector have different size! This should never happend!!!" << endl;
return;
}
ofstream file; ofstream file;
file.open( filename.c_str() ); file.open( filename.c_str() );
if (!file.is_open()) if (!file.is_open())
cerr << "Can't open file: " << filename << endl; cerr << "Can't open file: " << filename << endl;
time_t rawTime;
time(&rawTime);
file << "%dump by openEMS @" << ctime(&rawTime) << "%frequency\treal\timag\n";
for (size_t n=0;n<value.size();++n) for (size_t n=0;n<value.size();++n)
{ {
file << m_FD_Samples.at(n) << "\t" << 2.0 * creal(value.at(n))*factor << "\t" << 2.0 * cimag(value.at(n))*factor << "\n"; file << m_FD_Samples.at(n) << "\t" << 2.0 * creal(value.at(n))*factor << "\t" << 2.0 * cimag(value.at(n))*factor << "\n";

44
FDTD/processintegral.cpp Normal file
View File

@ -0,0 +1,44 @@
/*
* 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 <http://www.gnu.org/licenses/>.
*/
#include "processintegral.h"
ProcessIntegral::ProcessIntegral(Operator* op, Engine* eng) : Processing(op, eng)
{
}
ProcessIntegral::~ProcessIntegral()
{
ProcessIntegral::FlushData();
}
void ProcessIntegral::InitProcess()
{
m_filename = m_Name;
OpenFile(m_filename);
FD_Values.clear();
for (size_t n=0;n<m_FD_Samples.size();++n)
FD_Values.push_back(0);
}
void ProcessIntegral::FlushData()
{
if (m_FD_Samples.size())
Dump_FD_Data(FD_Values,1.0/(double)m_FD_SampleCount,m_filename + "_FD");
}

40
FDTD/processintegral.h Normal file
View File

@ -0,0 +1,40 @@
/*
* 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 <http://www.gnu.org/licenses/>.
*/
#ifndef PROCESSINTEGRAL_H
#define PROCESSINTEGRAL_H
#include "processing.h"
//! Abstract base class for integral parameter processing
class ProcessIntegral : public Processing
{
public:
virtual ~ProcessIntegral();
virtual void InitProcess();
virtual void FlushData();
protected:
ProcessIntegral(Operator* op, Engine* eng);
vector<FDTD_FLOAT> TD_Values;
vector<_Complex double> FD_Values;
};
#endif // PROCESSINTEGRAL_H

View File

@ -19,22 +19,12 @@
#include <complex.h> #include <complex.h>
#include <iomanip> #include <iomanip>
ProcessVoltage::ProcessVoltage(Operator* op, Engine* eng) : Processing(op, eng) ProcessVoltage::ProcessVoltage(Operator* op, Engine* eng) : ProcessIntegral(op, eng)
{ {
} }
ProcessVoltage::~ProcessVoltage() ProcessVoltage::~ProcessVoltage()
{ {
ProcessVoltage::FlushData();
}
void ProcessVoltage::InitProcess()
{
m_filename = m_Name;
OpenFile(m_filename);
FD_voltages.clear();
for (size_t n=0;n<m_FD_Samples.size();++n)
FD_voltages.push_back(0);
} }
int ProcessVoltage::Process() int ProcessVoltage::Process()
@ -49,7 +39,7 @@ int ProcessVoltage::Process()
{ {
if (Eng->GetNumberOfTimesteps()%ProcessInterval==0) if (Eng->GetNumberOfTimesteps()%ProcessInterval==0)
{ {
voltages.push_back(voltage); TD_Values.push_back(voltage);
file << setprecision(m_precision) << (double)Eng->GetNumberOfTimesteps()*Op->GetTimestep() << "\t" << voltage << endl; file << setprecision(m_precision) << (double)Eng->GetNumberOfTimesteps()*Op->GetTimestep() << "\t" << voltage << endl;
} }
} }
@ -61,7 +51,7 @@ int ProcessVoltage::Process()
double T = (double)Eng->GetNumberOfTimesteps() * Op->GetTimestep(); double T = (double)Eng->GetNumberOfTimesteps() * Op->GetTimestep();
for (size_t n=0;n<m_FD_Samples.size();++n) for (size_t n=0;n<m_FD_Samples.size();++n)
{ {
FD_voltages.at(n) += voltage * cexp( -2.0 * 1.0i * M_PI * m_FD_Samples.at(n) * T ); FD_Values.at(n) += voltage * cexp( -2.0 * 1.0i * M_PI * m_FD_Samples.at(n) * T );
} }
++m_FD_SampleCount; ++m_FD_SampleCount;
if (m_Flush) if (m_Flush)
@ -72,8 +62,3 @@ int ProcessVoltage::Process()
return GetNextInterval(); return GetNextInterval();
} }
void ProcessVoltage::FlushData()
{
Dump_FD_Data(FD_voltages,1.0/(double)m_FD_SampleCount,m_filename + "_FD");
}

View File

@ -18,25 +18,18 @@
#ifndef PROCESSVOLTAGE_H #ifndef PROCESSVOLTAGE_H
#define PROCESSVOLTAGE_H #define PROCESSVOLTAGE_H
#include "processing.h" #include "processintegral.h"
//! Process voltage along a line from start to stop coordinates. ATM integration along the axis e.g.: in x, then y then z direction (Future: diagonal integration) //! Process voltage along a line from start to stop coordinates. ATM integration along the axis e.g.: in x, then y then z direction (Future: diagonal integration)
class ProcessVoltage : public Processing class ProcessVoltage : public ProcessIntegral
{ {
public: public:
ProcessVoltage(Operator* op, Engine* eng); ProcessVoltage(Operator* op, Engine* eng);
virtual ~ProcessVoltage(); virtual ~ProcessVoltage();
virtual void InitProcess();
virtual void FlushData();
virtual int Process(); virtual int Process();
protected: protected:
vector<FDTD_FLOAT> voltages;
vector<_Complex double> FD_voltages;
void WriteFDVoltages();
}; };
#endif // PROCESSVOLTAGE_H #endif // PROCESSVOLTAGE_H

View File

@ -38,6 +38,7 @@ SOURCES += main.cpp \
tools/array_ops.cpp \ tools/array_ops.cpp \
FDTD/processvoltage.cpp \ FDTD/processvoltage.cpp \
FDTD/processing.cpp \ FDTD/processing.cpp \
FDTD/processintegral.cpp \
FDTD/processfields.cpp \ FDTD/processfields.cpp \
FDTD/processfields_td.cpp \ FDTD/processfields_td.cpp \
FDTD/processcurrent.cpp \ FDTD/processcurrent.cpp \
@ -66,6 +67,7 @@ HEADERS += tools/ErrorMsg.h \
tools/array_ops.h \ tools/array_ops.h \
FDTD/processvoltage.h \ FDTD/processvoltage.h \
FDTD/processing.h \ FDTD/processing.h \
FDTD/processintegral.h \
FDTD/processfields.h \ FDTD/processfields.h \
FDTD/processfields_td.h \ FDTD/processfields_td.h \
FDTD/processcurrent.h \ FDTD/processcurrent.h \