ProcessEField and ProcessHField replaced by new ProcessFieldProbe

pull/1/head
Thorsten Liebig 2011-01-18 10:45:03 +01:00
parent dff20e51cd
commit 8986ef1f31
7 changed files with 118 additions and 338 deletions

View File

@ -1,137 +0,0 @@
/*
* 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 <iomanip>
#include "time.h"
#include "process_efield.h"
ProcessEField::ProcessEField(Engine_Interface_Base* eng_if, Engine* eng) : Processing(eng_if)
{
Eng = eng;
}
ProcessEField::~ProcessEField()
{
FlushData();
}
string ProcessEField::GetIntegralName(int row) const
{
if (row==0)
return "Ex/(V/m)";
if (row==1)
return "Ey/(V/m)";
if (row==2)
return "Ez/(V/m)";
return "unknown";
}
void ProcessEField::InitProcess()
{
OpenFile(m_Name);
for (int n=0; n<3; n++)
FD_Values[n].assign(m_FD_Samples.size(),double_complex(0.0,0.0));
file << "% time-domain E-field probe by openEMS " GIT_VERSION << endl;
file << "% coords: (" << Op->GetDiscLine(0,start[0])*Op->GetGridDelta() << ","
<< Op->GetDiscLine(1,start[1])*Op->GetGridDelta() << ","
<< Op->GetDiscLine(2,start[2])*Op->GetGridDelta() << ") m -> [" << start[0] << "," << start[1] << "," << start[2] << "]" << endl;
file << "% t/s\tEx/(V/m)\tEy/(V/m)\tEz/(V/m)" << endl;
}
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<double_complex> 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 * std::real(value[0].at(n))*factor << "\t" << 2.0 * std::imag(value[0].at(n))*factor
<< "\t" << 2.0 * std::real(value[1].at(n))*factor << "\t" << 2.0 * std::imag(value[1].at(n))*factor
<< "\t" << 2.0 * std::real(value[2].at(n))*factor << "\t" << 2.0 * std::imag(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->GetEdgeLength(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->GetEdgeLength(pol,start);
field *= m_weight;
for (size_t n=0; n<m_FD_Samples.size(); ++n)
{
FD_Values[pol].at(n) += (double)field * std::exp( -2.0 * _I * M_PI * m_FD_Samples.at(n) * T );
}
++m_FD_SampleCount;
}
if (m_Flush)
FlushData();
m_Flush = false;
}
}
return GetNextInterval();
}

View File

@ -1,49 +0,0 @@
/*
* 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"
#include "FDTD/engine.h"
/*! \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(Engine_Interface_Base* eng_if, Engine* eng);
virtual ~ProcessEField();
virtual string GetProcessingName() const {return "electric field probe";}
virtual string GetIntegralName(int row) const;
virtual void InitProcess();
virtual void FlushData();
void Dump_FD_Data(vector<double_complex> value[3], double factor, string filename);
virtual int Process();
protected:
Engine* Eng;
vector<double_complex> FD_Values[3];
};
#endif // PROCESS_EFIELD_H

View File

@ -1,121 +0,0 @@
/*
* 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 <iomanip>
#include "tools/global.h"
#include "process_hfield.h"
ProcessHField::ProcessHField(Engine_Interface_Base* eng_if, Engine* eng) : ProcessEField(eng_if, eng)
{
}
ProcessHField::~ProcessHField()
{
}
string ProcessHField::GetIntegralName(int row) const
{
if (row==0)
return "Hx/(A/m)";
if (row==1)
return "Hy/(A/m)";
if (row==2)
return "Hz/(A/m)";
return "unknown";
}
void ProcessHField::InitProcess()
{
OpenFile(m_Name);
for (int n=0; n<3; n++)
FD_Values[n].assign(m_FD_Samples.size(),double_complex(0.0,0.0));
file << "% time-domain H-field probe by openEMS " GIT_VERSION << endl;
file << "% coords: (" << Op->GetDiscLine(0,start[0],true)*Op->GetGridDelta() << ","
<< Op->GetDiscLine(1,start[1],true)*Op->GetGridDelta() << ","
<< Op->GetDiscLine(2,start[2],true)*Op->GetGridDelta() << ") m -> [" << start[0] << "," << start[1] << "," << start[2] << "]" << endl;
file << "% t/s\tEx/(A/m)\tEy/(A/m)\tEz/(A/m)" << endl;
}
void ProcessHField::DefineStartStopCoord(double* dstart, double* dstop)
{
if (Op->SnapToMesh(dstart,start,true,m_start_inside)==false)
cerr << "ProcessHField::DefineStartStopCoord: Warning: Snapped line outside field domain!!" << endl;
if (Op->SnapToMesh(dstop,stop,true,m_stop_inside)==false)
cerr << "ProcessHField::DefineStartStopCoord: Warning: Snapped line outside field domain!!" << endl;
if (g_settings.showProbeDiscretization())
{
cerr << m_Name << ": snapped coords: (" << Op->GetDiscLine( 0, start[0], true ) << ","
<< Op->GetDiscLine( 1, start[1], true ) << "," << Op->GetDiscLine( 2, start[2], true ) << ") -> ("
<< Op->GetDiscLine( 0, stop[0], true ) << ","<< Op->GetDiscLine( 1, stop[1], true ) << ","
<< Op->GetDiscLine( 2, stop[2], true ) << ")";
cerr << " [" << start[0] << "," << start[1] << "," << start[2] << "] -> ["
<< stop[0] << "," << stop[1] << "," << stop[2] << "]" << endl;
}
}
int ProcessHField::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()+0.5)*Op->GetTimestep();
for (int n=0; n<3; n++)
{
FDTD_FLOAT field = Eng->GetCurr(n,start) / Op->GetEdgeLength(n,start,true);
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->GetCurr(pol,start) / Op->GetEdgeLength(pol,start,true);
field *= m_weight;
for (size_t n=0; n<m_FD_Samples.size(); ++n)
{
FD_Values[pol].at(n) += (double)field * std::exp( -2.0 * _I * M_PI * m_FD_Samples.at(n) * T );
}
++m_FD_SampleCount;
}
if (m_Flush)
FlushData();
m_Flush = false;
}
}
return GetNextInterval();
}

View File

@ -0,0 +1,90 @@
/*
* Copyright (C) 2011 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 "processfieldprobe.h"
ProcessFieldProbe::ProcessFieldProbe(Engine_Interface_Base* eng_if, int type) : ProcessIntegral(eng_if)
{
SetFieldType(type);
}
ProcessFieldProbe::~ProcessFieldProbe()
{
}
string ProcessFieldProbe::GetProcessingName() const
{
if (m_ModeFieldType==0)
return "electric field probe";
if (m_ModeFieldType==1)
return "magnetic field probe";
return "unknown field probe";
}
string ProcessFieldProbe::GetIntegralName(int row) const
{
if (row==0)
{
if (m_ModeFieldType==0)
return "Ex/(V/m)";
if (m_ModeFieldType==1)
return "Hx/(A/m)";
}
if (row==1)
{
if (m_ModeFieldType==0)
return "Ey/(V/m)";
if (m_ModeFieldType==1)
return "Hy/(A/m)";
}
if (row==2)
{
if (m_ModeFieldType==0)
return "Ez/(V/m)";
if (m_ModeFieldType==1)
return "Hz/(A/m)";
}
return "unknown";
}
void ProcessFieldProbe::SetFieldType(int type)
{
if ((type<0) || (type>1))
{
cerr << "ProcessFieldProbe::SetFieldType: Error: unknown field type... skipping" << endl;
Enabled=false;
}
m_ModeFieldType = type;
}
double* ProcessFieldProbe::CalcMultipleIntegrals()
{
m_Eng_Interface->SetInterpolationType(Engine_Interface_Base::NO_INTERPOLATION);
switch (m_ModeFieldType)
{
case 0:
default:
m_Eng_Interface->GetEField(start,m_Results);
break;
case 1:
m_Eng_Interface->GetHField(start,m_Results);
break;
}
return m_Results;
}

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (C) 2010 Sebastian Held (sebastian.held@gmx.de) * Copyright (C) 2011 Thorsten Liebig (Thorsten.Liebig@gmx.de)
* *
* This program is free software: you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
@ -15,29 +15,29 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#ifndef PROCESS_HFIELD_H #ifndef PROCESSFIELDPROBE_H
#define PROCESS_HFIELD_H #define PROCESSFIELDPROBE_H
#include "process_efield.h" #include "processintegral.h"
/*! \brief Process H-field at a point class ProcessFieldProbe : public ProcessIntegral
This class calculates the E-field at a point in the FDTD lattice.
Other primitives than \c Point are not supported.
*/
class ProcessHField : public ProcessEField
{ {
public: public:
ProcessHField(Engine_Interface_Base* eng_if, Engine* eng); ProcessFieldProbe(Engine_Interface_Base* eng_if, int type=0);
virtual ~ProcessHField(); virtual ~ProcessFieldProbe();
virtual string GetProcessingName() const {return "magnetic field probe";} virtual string GetProcessingName() const;
virtual string GetIntegralName(int row) const; virtual string GetIntegralName(int row) const;
virtual void InitProcess(); //! Set the field type (0 electric field, 1 magnetic field)
void DefineStartStopCoord(double* dstart, double* dstop); void SetFieldType(int type);
virtual int Process();
virtual int GetNumberOfIntegrals() const {return 3;}
virtual double* CalcMultipleIntegrals();
protected:
int m_ModeFieldType;
}; };
#endif // PROCESS_HFIELD_H #endif // PROCESSFIELDPROBE_H

View File

@ -64,8 +64,7 @@ SOURCES += main.cpp \
FDTD/excitation.cpp \ FDTD/excitation.cpp \
FDTD/operator_cylindermultigrid.cpp \ FDTD/operator_cylindermultigrid.cpp \
FDTD/engine_cylindermultigrid.cpp \ FDTD/engine_cylindermultigrid.cpp \
FDTD/engine_interface_fdtd.cpp \ FDTD/engine_interface_fdtd.cpp
Common/processfields_fd.cpp
# FDTD/extensions source files # FDTD/extensions source files
SOURCES += FDTD/extensions/engine_extension.cpp \ SOURCES += FDTD/extensions/engine_extension.cpp \
@ -89,13 +88,13 @@ SOURCES += Common/operator_base.cpp \
Common/engine_interface_base.cpp \ Common/engine_interface_base.cpp \
Common/processmodematch.cpp \ Common/processmodematch.cpp \
Common/processvoltage.cpp \ Common/processvoltage.cpp \
Common/process_efield.cpp \
Common/process_hfield.cpp \
Common/processing.cpp \ Common/processing.cpp \
Common/processintegral.cpp \ Common/processintegral.cpp \
Common/processfields.cpp \ Common/processfields.cpp \
Common/processfields_td.cpp \ Common/processfields_td.cpp \
Common/processcurrent.cpp Common/processcurrent.cpp \
Common/processfields_fd.cpp \
Common/processfieldprobe.cpp
HEADERS += tools/ErrorMsg.h \ HEADERS += tools/ErrorMsg.h \
tools/AdrOp.h \ tools/AdrOp.h \
@ -117,8 +116,7 @@ HEADERS += tools/ErrorMsg.h \
FDTD/operator_cylindermultigrid.h \ FDTD/operator_cylindermultigrid.h \
FDTD/engine_cylindermultigrid.h \ FDTD/engine_cylindermultigrid.h \
tools/aligned_allocator.h \ tools/aligned_allocator.h \
FDTD/engine_interface_fdtd.h \ FDTD/engine_interface_fdtd.h
Common/processfields_fd.h
# FDTD/extensions header files # FDTD/extensions header files
HEADERS += FDTD/operator_extension.h \ HEADERS += FDTD/operator_extension.h \
@ -141,14 +139,14 @@ HEADERS += FDTD/operator_extension.h \
HEADERS += Common/operator_base.h \ HEADERS += Common/operator_base.h \
Common/engine_interface_base.h \ Common/engine_interface_base.h \
Common/processvoltage.h \ Common/processvoltage.h \
Common/process_efield.h \
Common/process_hfield.h \
Common/processing.h \ Common/processing.h \
Common/processintegral.h \ Common/processintegral.h \
Common/processfields.h \ Common/processfields.h \
Common/processfields_td.h \ Common/processfields_td.h \
Common/processcurrent.h \ Common/processcurrent.h \
Common/processmodematch.h Common/processmodematch.h \
Common/processfields_fd.h \
Common/processfieldprobe.h
QMAKE_CXXFLAGS_RELEASE = -O3 \ QMAKE_CXXFLAGS_RELEASE = -O3 \
-g \ -g \

View File

@ -29,8 +29,7 @@
#include "FDTD/engine_interface_fdtd.h" #include "FDTD/engine_interface_fdtd.h"
#include "Common/processvoltage.h" #include "Common/processvoltage.h"
#include "Common/processcurrent.h" #include "Common/processcurrent.h"
#include "Common/process_efield.h" #include "Common/processfieldprobe.h"
#include "Common/process_hfield.h"
#include "Common/processmodematch.h" #include "Common/processmodematch.h"
#include "Common/processfields_td.h" #include "Common/processfields_td.h"
#include "Common/processfields_fd.h" #include "Common/processfields_fd.h"
@ -313,9 +312,9 @@ bool openEMS::SetupProcessing(ContinuousStructure& CSX)
proc=procCurr; proc=procCurr;
} }
else if (pb->GetProbeType()==2) else if (pb->GetProbeType()==2)
proc = new ProcessEField(new Engine_Interface_FDTD(FDTD_Op,FDTD_Eng),FDTD_Eng); proc = new ProcessFieldProbe(new Engine_Interface_FDTD(FDTD_Op,FDTD_Eng),0);
else if (pb->GetProbeType()==3) else if (pb->GetProbeType()==3)
proc = new ProcessHField(new Engine_Interface_FDTD(FDTD_Op,FDTD_Eng),FDTD_Eng); proc = new ProcessFieldProbe(new Engine_Interface_FDTD(FDTD_Op,FDTD_Eng),1);
else if ((pb->GetProbeType()==10) || (pb->GetProbeType()==11)) else if ((pb->GetProbeType()==10) || (pb->GetProbeType()==11))
{ {
ProcessModeMatch* pmm = new ProcessModeMatch(new Engine_Interface_FDTD(FDTD_Op,FDTD_Eng)); ProcessModeMatch* pmm = new ProcessModeMatch(new Engine_Interface_FDTD(FDTD_Op,FDTD_Eng));