new probe type: E-field

pull/1/head
Sebastian Held 2010-07-16 15:55:35 +02:00
parent 55ac7137a3
commit 0ccbbab593
6 changed files with 175 additions and 5 deletions

119
FDTD/process_efield.cpp Normal file
View File

@ -0,0 +1,119 @@
/*
* Copyright (C) 2010 Sebastian Held (sebastian.held@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 <complex.h>
#include <iomanip>
#include "process_efield.h"
ProcessEField::ProcessEField(Operator* op, Engine* eng) : Processing(op, eng)
{
}
ProcessEField::~ProcessEField()
{
FlushData();
}
void ProcessEField::InitProcess()
{
OpenFile(m_Name);
for (int n=0; n<3; n++)
FD_Values[n].assign(m_FD_Samples.size(),0);
}
void ProcessEField::FlushData()
{
if (m_FD_Samples.size())
Dump_FD_Data(FD_Values,1.0/(double)m_FD_SampleCount,m_filename + "_FD");
}
void ProcessEField::Dump_FD_Data(vector<complexdouble> value[3], double factor, string filename)
{
if (value[0].size()==0)
return;
if (value[0].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;
file.open( filename.c_str() );
if (!file.is_open())
cerr << "Can't open file: " << filename << endl;
time_t rawTime;
time(&rawTime);
file << "%dump by openEMS @" << ctime(&rawTime) << "%frequency\treal_x\timag_x\treal_y\timag_y\treal_z\timag_z\n";
for (size_t n=0;n<value[0].size();++n)
{
file << m_FD_Samples.at(n)
<< "\t" << 2.0 * creal(value[0].at(n))*factor << "\t" << 2.0 * cimag(value[0].at(n))*factor
<< "\t" << 2.0 * creal(value[1].at(n))*factor << "\t" << 2.0 * cimag(value[1].at(n))*factor
<< "\t" << 2.0 * creal(value[2].at(n))*factor << "\t" << 2.0 * cimag(value[2].at(n))*factor << "\n";
}
file.close();
}
int ProcessEField::Process()
{
if (!Enabled)
return -1;
if (CheckTimestep()==false)
return GetNextInterval();
if (ProcessInterval)
{
// time-domain processing
if (Eng->GetNumberOfTimesteps()%ProcessInterval==0)
{
file << setprecision(m_precision) << (double)Eng->GetNumberOfTimesteps()*Op->GetTimestep();
for (int n=0; n<3; n++)
{
FDTD_FLOAT field = Eng->GetVolt(n,start) / Op->GetMeshDelta(n,start);
field *= m_weight;
// TD_Values.push_back(voltage);
file << "\t" << field;
}
file << endl;
}
}
if (m_FD_Interval)
{
// frequency-domain processing
if (Eng->GetNumberOfTimesteps()%m_FD_Interval==0)
{
double T = (double)Eng->GetNumberOfTimesteps() * Op->GetTimestep();
for (int pol=0; pol<3; pol++)
{
FDTD_FLOAT field = Eng->GetVolt(pol,start) / Op->GetMeshDelta(pol,start);
field *= m_weight;
for (size_t n=0;n<m_FD_Samples.size();++n)
{
FD_Values[pol].at(n) += field * cexp( -2.0 * 1.0i * M_PI * m_FD_Samples.at(n) * T );
}
++m_FD_SampleCount;
}
if (m_Flush)
FlushData();
m_Flush = false;
}
}
return GetNextInterval();
}

45
FDTD/process_efield.h Normal file
View File

@ -0,0 +1,45 @@
/*
* Copyright (C) 2010 Sebastian Held (sebastian.held@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 PROCESS_EFIELD_H
#define PROCESS_EFIELD_H
#include "processing.h"
typedef _Complex double complexdouble;
/*! \brief Process E-field at a point
This class calculates the E-field at a point in the FDTD lattice.
Other primitives than \c Point are not supported.
*/
class ProcessEField : public Processing
{
public:
ProcessEField(Operator* op, Engine* eng);
virtual ~ProcessEField();
virtual void InitProcess();
virtual void FlushData();
void Dump_FD_Data(vector<complexdouble> value[3], double factor, string filename);
virtual int Process();
protected:
vector<complexdouble> FD_Values[3];
};
#endif // PROCESS_EFIELD_H

View File

@ -146,7 +146,7 @@ void Processing::DefineStartStopCoord(double* dstart, double* dstop)
cerr << "Processing::DefineStartStopCoord: Warning: Snapped line outside field domain!!" << endl;
if (g_settings.showProbeDiscretization()) {
cerr << m_filename << ": snapped coords: (" << Op->GetDiscLine( 0, start[0], false ) << ","
cerr << m_Name << ": snapped coords: (" << Op->GetDiscLine( 0, start[0], false ) << ","
<< Op->GetDiscLine( 1, start[1], false ) << "," << Op->GetDiscLine( 2, start[2], false ) << ") -> ("
<< Op->GetDiscLine( 0, stop[0], false ) << ","<< Op->GetDiscLine( 1, stop[1], false ) << ","
<< Op->GetDiscLine( 2, stop[2], false ) << ")";

View File

@ -20,7 +20,6 @@
#include <iostream>
#include <fstream>
#include <complex>
#include <cmath>
#include "operator.h"
#include "engine.h"

View File

@ -51,7 +51,8 @@ SOURCES += main.cpp \
FDTD/operator.cpp \
tools/array_ops.cpp \
FDTD/processvoltage.cpp \
FDTD/processing.cpp \
FDTD/process_efield.cpp \
FDTD/processing.cpp \
FDTD/processintegral.cpp \
FDTD/processfields.cpp \
FDTD/processfields_td.cpp \
@ -84,7 +85,8 @@ HEADERS += tools/ErrorMsg.h \
FDTD/operator.h \
tools/array_ops.h \
FDTD/processvoltage.h \
FDTD/processing.h \
FDTD/process_efield.h \
FDTD/processing.h \
FDTD/processintegral.h \
FDTD/processfields.h \
FDTD/processfields_td.h \

View File

@ -24,6 +24,7 @@
#include "FDTD/operator_ext_mur_abc.h"
#include "FDTD/processvoltage.h"
#include "FDTD/processcurrent.h"
#include "FDTD/process_efield.h"
#include "FDTD/processfields_td.h"
#include <sys/time.h>
#include <time.h>
@ -338,6 +339,10 @@ int openEMS::SetupFDTD(const char* file)
ProcessCurrent* procCurr = new ProcessCurrent(FDTD_Op,FDTD_Eng);
proc=procCurr;
}
else if (pb->GetProbeType()==2)
proc = new ProcessEField(FDTD_Op,FDTD_Eng);
// else if (pb->GetProbeType()==3)
// proc = new ProcessHField(FDTD_Op,FDTD_Eng);
else
{
cerr << "openEMS::SetupFDTD: Warning: Probe type " << pb->GetProbeType() << " of property '" << pb->GetName() << "' is unknown..." << endl;
@ -345,9 +350,9 @@ int openEMS::SetupFDTD(const char* file)
}
proc->SetProcessInterval(Nyquist/m_OverSampling);
proc->AddFrequency(pb->GetFDSamples());
proc->SetName(pb->GetName());
proc->DefineStartStopCoord(start,stop);
proc->SetWeight(pb->GetWeighting());
proc->SetName(pb->GetName());
proc->InitProcess();
PA->AddProcessing(proc);
prim->SetPrimitiveUsed(true);