2010-12-19 19:41:08 +00:00
|
|
|
/*
|
|
|
|
* 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 "processfields_fd.h"
|
|
|
|
#include "Common/operator_base.h"
|
2012-02-02 09:20:49 +00:00
|
|
|
#include "tools/vtk_file_writer.h"
|
|
|
|
#include "tools/hdf5_file_writer.h"
|
2010-12-19 19:41:08 +00:00
|
|
|
#include <iomanip>
|
|
|
|
#include <sstream>
|
|
|
|
#include <string>
|
|
|
|
|
2015-06-18 19:45:22 +00:00
|
|
|
using namespace std;
|
|
|
|
|
2010-12-19 19:41:08 +00:00
|
|
|
ProcessFieldsFD::ProcessFieldsFD(Engine_Interface_Base* eng_if) : ProcessFields(eng_if)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
ProcessFieldsFD::~ProcessFieldsFD()
|
|
|
|
{
|
|
|
|
for (size_t n = 0; n<m_FD_Fields.size(); ++n)
|
|
|
|
{
|
|
|
|
Delete_N_3DArray(m_FD_Fields.at(n),numLines);
|
|
|
|
}
|
|
|
|
m_FD_Fields.clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
void ProcessFieldsFD::InitProcess()
|
|
|
|
{
|
|
|
|
if (Enabled==false) return;
|
|
|
|
|
|
|
|
if (m_FD_Samples.size()==0)
|
|
|
|
{
|
|
|
|
cerr << "ProcessFieldsFD::InitProcess: No frequencies found... skipping this dump!" << endl;
|
|
|
|
Enabled=false;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
//setup the hdf5 file
|
|
|
|
ProcessFields::InitProcess();
|
|
|
|
|
2012-02-02 09:20:49 +00:00
|
|
|
if (m_Vtk_Dump_File)
|
|
|
|
m_Vtk_Dump_File->SetHeader(string("openEMS FD Field Dump -- Interpolation: ")+m_Eng_Interface->GetInterpolationTypeString());
|
2011-04-01 13:29:56 +00:00
|
|
|
|
2012-02-02 09:20:49 +00:00
|
|
|
if (m_HDF5_Dump_File)
|
2010-12-27 12:54:09 +00:00
|
|
|
{
|
2012-02-02 09:20:49 +00:00
|
|
|
m_HDF5_Dump_File->SetCurrentGroup("/FieldData/FD");
|
2012-02-17 11:33:05 +00:00
|
|
|
m_HDF5_Dump_File->WriteAtrribute("/FieldData/FD","frequency",m_FD_Samples);
|
2010-12-27 12:54:09 +00:00
|
|
|
}
|
|
|
|
|
2010-12-19 19:41:08 +00:00
|
|
|
//create data structures...
|
|
|
|
for (size_t n = 0; n<m_FD_Samples.size(); ++n)
|
|
|
|
{
|
|
|
|
std::complex<float>**** field_fd = Create_N_3DArray<std::complex<float> >(numLines);
|
|
|
|
m_FD_Fields.push_back(field_fd);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int ProcessFieldsFD::Process()
|
|
|
|
{
|
|
|
|
if (Enabled==false) return -1;
|
|
|
|
if (CheckTimestep()==false) return GetNextInterval();
|
|
|
|
|
|
|
|
if ((m_FD_Interval==0) || (m_Eng_Interface->GetNumberOfTimesteps()%m_FD_Interval!=0))
|
|
|
|
return GetNextInterval();
|
|
|
|
|
|
|
|
FDTD_FLOAT**** field_td = CalcField();
|
|
|
|
std::complex<float>**** field_fd = NULL;
|
|
|
|
|
|
|
|
double T = m_Eng_Interface->GetTime(m_dualTime);
|
|
|
|
unsigned int pos[3];
|
|
|
|
for (size_t n = 0; n<m_FD_Samples.size(); ++n)
|
|
|
|
{
|
2011-01-31 10:10:18 +00:00
|
|
|
std::complex<float> exp_jwt_2_dt = std::exp( (std::complex<float>)(-2.0 * _I * M_PI * m_FD_Samples.at(n) * T) );
|
|
|
|
exp_jwt_2_dt *= 2; // *2 for single-sided spectrum
|
2011-01-31 14:00:55 +00:00
|
|
|
exp_jwt_2_dt *= Op->GetTimestep() * m_FD_Interval; // multiply with timestep-interval
|
2010-12-19 19:41:08 +00:00
|
|
|
field_fd = m_FD_Fields.at(n);
|
|
|
|
for (pos[0]=0; pos[0]<numLines[0]; ++pos[0])
|
|
|
|
{
|
|
|
|
for (pos[1]=0; pos[1]<numLines[1]; ++pos[1])
|
|
|
|
{
|
|
|
|
for (pos[2]=0; pos[2]<numLines[2]; ++pos[2])
|
|
|
|
{
|
2011-01-31 10:10:18 +00:00
|
|
|
field_fd[0][pos[0]][pos[1]][pos[2]] += field_td[0][pos[0]][pos[1]][pos[2]] * exp_jwt_2_dt;
|
|
|
|
field_fd[1][pos[0]][pos[1]][pos[2]] += field_td[1][pos[0]][pos[1]][pos[2]] * exp_jwt_2_dt;
|
|
|
|
field_fd[2][pos[0]][pos[1]][pos[2]] += field_td[2][pos[0]][pos[1]][pos[2]] * exp_jwt_2_dt;
|
2010-12-19 19:41:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2011-01-24 10:11:45 +00:00
|
|
|
Delete_N_3DArray<FDTD_FLOAT>(field_td,numLines);
|
2010-12-19 19:41:08 +00:00
|
|
|
++m_FD_SampleCount;
|
|
|
|
return GetNextInterval();
|
|
|
|
}
|
|
|
|
|
|
|
|
void ProcessFieldsFD::PostProcess()
|
|
|
|
{
|
|
|
|
DumpFDData();
|
|
|
|
}
|
|
|
|
|
|
|
|
void ProcessFieldsFD::DumpFDData()
|
|
|
|
{
|
|
|
|
if (m_fileType==VTK_FILETYPE)
|
|
|
|
{
|
|
|
|
unsigned int pos[3];
|
|
|
|
FDTD_FLOAT**** field = Create_N_3DArray<float>(numLines);
|
|
|
|
std::complex<float>**** field_fd = NULL;
|
|
|
|
double angle=0;
|
|
|
|
int Nr_Ph = 21;
|
|
|
|
|
|
|
|
for (size_t n = 0; n<m_FD_Samples.size(); ++n)
|
|
|
|
{
|
|
|
|
//dump multiple phase to vtk-files
|
|
|
|
for (int p=0; p<Nr_Ph; ++p)
|
|
|
|
{
|
|
|
|
angle = 2.0 * M_PI * p / Nr_Ph;
|
|
|
|
std::complex<float> exp_jwt = std::exp( (std::complex<float>)( _I * angle) );
|
|
|
|
field_fd = m_FD_Fields.at(n);
|
|
|
|
for (pos[0]=0; pos[0]<numLines[0]; ++pos[0])
|
|
|
|
{
|
|
|
|
for (pos[1]=0; pos[1]<numLines[1]; ++pos[1])
|
|
|
|
{
|
|
|
|
for (pos[2]=0; pos[2]<numLines[2]; ++pos[2])
|
|
|
|
{
|
2011-01-31 10:10:18 +00:00
|
|
|
field[0][pos[0]][pos[1]][pos[2]] = real(field_fd[0][pos[0]][pos[1]][pos[2]] * exp_jwt);
|
|
|
|
field[1][pos[0]][pos[1]][pos[2]] = real(field_fd[1][pos[0]][pos[1]][pos[2]] * exp_jwt);
|
|
|
|
field[2][pos[0]][pos[1]][pos[2]] = real(field_fd[2][pos[0]][pos[1]][pos[2]] * exp_jwt);
|
2010-12-19 19:41:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
stringstream ss;
|
2011-04-01 13:29:56 +00:00
|
|
|
ss << m_filename << fixed << "_f=" << m_FD_Samples.at(n) << "_p=" << std::setw( 3 ) << std::setfill( '0' ) <<(int)(angle * 180 / M_PI);
|
|
|
|
|
2012-02-02 09:20:49 +00:00
|
|
|
m_Vtk_Dump_File->SetFilename(ss.str());
|
|
|
|
m_Vtk_Dump_File->ClearAllFields();
|
|
|
|
m_Vtk_Dump_File->AddVectorField(GetFieldNameByType(m_DumpType),field);
|
|
|
|
if (m_Vtk_Dump_File->Write()==false)
|
2011-04-01 13:29:56 +00:00
|
|
|
cerr << "ProcessFieldsFD::Process: can't dump to file... abort! " << endl;
|
2010-12-19 19:41:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
//dump magnitude to vtk-files
|
|
|
|
for (pos[0]=0; pos[0]<numLines[0]; ++pos[0])
|
|
|
|
{
|
|
|
|
for (pos[1]=0; pos[1]<numLines[1]; ++pos[1])
|
|
|
|
{
|
|
|
|
for (pos[2]=0; pos[2]<numLines[2]; ++pos[2])
|
|
|
|
{
|
2011-01-31 10:10:18 +00:00
|
|
|
field[0][pos[0]][pos[1]][pos[2]] = abs(field_fd[0][pos[0]][pos[1]][pos[2]]);
|
|
|
|
field[1][pos[0]][pos[1]][pos[2]] = abs(field_fd[1][pos[0]][pos[1]][pos[2]]);
|
|
|
|
field[2][pos[0]][pos[1]][pos[2]] = abs(field_fd[2][pos[0]][pos[1]][pos[2]]);
|
2010-12-19 19:41:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
stringstream ss;
|
2011-04-01 13:29:56 +00:00
|
|
|
ss << m_filename << fixed << "_f=" << m_FD_Samples.at(n) << "_abs";
|
2012-02-02 09:20:49 +00:00
|
|
|
m_Vtk_Dump_File->SetFilename(ss.str());
|
|
|
|
m_Vtk_Dump_File->ClearAllFields();
|
|
|
|
m_Vtk_Dump_File->AddVectorField(GetFieldNameByType(m_DumpType),field);
|
|
|
|
if (m_Vtk_Dump_File->Write()==false)
|
2011-04-01 13:29:56 +00:00
|
|
|
cerr << "ProcessFieldsFD::Process: can't dump to file... abort! " << endl;
|
2010-12-19 19:41:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
//dump phase to vtk-files
|
|
|
|
for (pos[0]=0; pos[0]<numLines[0]; ++pos[0])
|
|
|
|
{
|
|
|
|
for (pos[1]=0; pos[1]<numLines[1]; ++pos[1])
|
|
|
|
{
|
|
|
|
for (pos[2]=0; pos[2]<numLines[2]; ++pos[2])
|
|
|
|
{
|
|
|
|
field[0][pos[0]][pos[1]][pos[2]] = arg(field_fd[0][pos[0]][pos[1]][pos[2]]);
|
|
|
|
field[1][pos[0]][pos[1]][pos[2]] = arg(field_fd[1][pos[0]][pos[1]][pos[2]]);
|
|
|
|
field[2][pos[0]][pos[1]][pos[2]] = arg(field_fd[2][pos[0]][pos[1]][pos[2]]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
stringstream ss;
|
2011-04-01 13:29:56 +00:00
|
|
|
ss << m_filename << fixed << "_f=" << m_FD_Samples.at(n) << "_arg";
|
2012-02-02 09:20:49 +00:00
|
|
|
m_Vtk_Dump_File->SetFilename(ss.str());
|
|
|
|
m_Vtk_Dump_File->ClearAllFields();
|
|
|
|
m_Vtk_Dump_File->AddVectorField(GetFieldNameByType(m_DumpType),field);
|
|
|
|
if (m_Vtk_Dump_File->Write()==false)
|
2011-04-01 13:29:56 +00:00
|
|
|
cerr << "ProcessFieldsFD::Process: can't dump to file... abort! " << endl;
|
2010-12-19 19:41:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
Delete_N_3DArray(field,numLines);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (m_fileType==HDF5_FILETYPE)
|
|
|
|
{
|
|
|
|
for (size_t n = 0; n<m_FD_Samples.size(); ++n)
|
|
|
|
{
|
|
|
|
stringstream ss;
|
|
|
|
ss << "f" << n;
|
2012-02-02 09:20:49 +00:00
|
|
|
size_t datasize[]={numLines[0],numLines[1],numLines[2]};
|
|
|
|
if (m_HDF5_Dump_File->WriteVectorField(ss.str(), m_FD_Fields.at(n), datasize)==false)
|
|
|
|
cerr << "ProcessFieldsFD::Process: can't dump to file...! " << endl;
|
2012-02-17 11:33:05 +00:00
|
|
|
|
|
|
|
//legacy support, use /FieldData/FD frequency-Attribute in the future
|
2012-11-15 20:44:43 +00:00
|
|
|
float freq[1] = {(float)m_FD_Samples.at(n)};
|
2012-02-17 11:33:05 +00:00
|
|
|
if (m_HDF5_Dump_File->WriteAtrribute("/FieldData/FD/"+ss.str()+"_real","frequency",freq,1)==false)
|
|
|
|
cerr << "ProcessFieldsFD::Process: can't dump to file...! " << endl;
|
|
|
|
if (m_HDF5_Dump_File->WriteAtrribute("/FieldData/FD/"+ss.str()+"_imag","frequency",freq,1)==false)
|
2012-02-02 09:20:49 +00:00
|
|
|
cerr << "ProcessFieldsFD::Process: can't dump to file...! " << endl;
|
2010-12-19 19:41:08 +00:00
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-02-02 09:20:49 +00:00
|
|
|
cerr << "ProcessFieldsFD::Process: unknown File-Type" << endl;
|
2010-12-19 19:41:08 +00:00
|
|
|
}
|