2010-03-11 15:47:40 +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/>.
|
|
|
|
*/
|
|
|
|
|
2010-04-12 07:38:24 +00:00
|
|
|
#include <iomanip>
|
2010-04-28 09:15:59 +00:00
|
|
|
#include <H5Cpp.h>
|
2010-07-20 09:42:47 +00:00
|
|
|
#include "tools/global.h"
|
2012-02-02 09:20:49 +00:00
|
|
|
#include "tools/vtk_file_writer.h"
|
|
|
|
#include "tools/hdf5_file_writer.h"
|
2010-07-20 09:42:47 +00:00
|
|
|
#include "processfields.h"
|
2010-12-06 09:44:25 +00:00
|
|
|
#include "FDTD/engine_interface_fdtd.h"
|
2010-04-05 18:22:03 +00:00
|
|
|
|
2010-12-07 15:47:23 +00:00
|
|
|
ProcessFields::ProcessFields(Engine_Interface_Base* eng_if) : Processing(eng_if)
|
2010-03-02 13:54:50 +00:00
|
|
|
{
|
2010-04-05 18:22:03 +00:00
|
|
|
m_DumpType = E_FIELD_DUMP;
|
|
|
|
// vtk-file is default
|
|
|
|
m_fileType = VTK_FILETYPE;
|
2010-12-27 20:23:51 +00:00
|
|
|
m_SampleType = NONE;
|
2012-02-02 09:20:49 +00:00
|
|
|
m_Vtk_Dump_File = NULL;
|
|
|
|
m_HDF5_Dump_File = NULL;
|
2010-04-12 07:38:24 +00:00
|
|
|
SetPrecision(6);
|
2010-12-19 19:41:08 +00:00
|
|
|
m_dualTime = false;
|
2010-03-02 13:54:50 +00:00
|
|
|
|
2011-07-22 08:01:19 +00:00
|
|
|
// dump box should be always inside the snapped lines
|
|
|
|
m_SnapMethod = 1;
|
|
|
|
|
2010-12-06 12:04:37 +00:00
|
|
|
for (int n=0; n<3; ++n)
|
2010-03-02 13:54:50 +00:00
|
|
|
{
|
2010-03-15 15:59:37 +00:00
|
|
|
numLines[n]=0;
|
2010-12-27 20:23:51 +00:00
|
|
|
posLines[n]=NULL;
|
2010-03-09 20:35:57 +00:00
|
|
|
discLines[n]=NULL;
|
2011-02-21 11:12:59 +00:00
|
|
|
subSample[n]=1;
|
|
|
|
optResolution[n]=0;
|
2010-03-02 13:54:50 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ProcessFields::~ProcessFields()
|
|
|
|
{
|
2012-02-02 09:20:49 +00:00
|
|
|
delete m_Vtk_Dump_File;
|
|
|
|
m_Vtk_Dump_File = NULL;
|
2010-12-06 12:04:37 +00:00
|
|
|
for (int n=0; n<3; ++n)
|
2010-03-02 13:54:50 +00:00
|
|
|
{
|
2010-12-27 20:23:51 +00:00
|
|
|
delete[] posLines[n];
|
|
|
|
posLines[n]=NULL;
|
2010-03-09 20:35:57 +00:00
|
|
|
delete[] discLines[n];
|
|
|
|
discLines[n]=NULL;
|
2010-03-02 13:54:50 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-04-05 18:22:03 +00:00
|
|
|
string ProcessFields::GetFieldNameByType(DumpType type)
|
|
|
|
{
|
|
|
|
switch (type)
|
|
|
|
{
|
2010-12-06 12:04:37 +00:00
|
|
|
case E_FIELD_DUMP:
|
|
|
|
return "E-Field";
|
|
|
|
case H_FIELD_DUMP:
|
|
|
|
return "H-Field";
|
2011-01-07 15:12:07 +00:00
|
|
|
case J_FIELD_DUMP:
|
|
|
|
return "J-Field";
|
2011-01-10 10:15:22 +00:00
|
|
|
case ROTH_FIELD_DUMP:
|
|
|
|
return "RotH-Field";
|
2011-01-31 11:25:55 +00:00
|
|
|
case SAR_LOCAL_DUMP:
|
|
|
|
return "SAR-local";
|
2010-04-05 18:22:03 +00:00
|
|
|
}
|
|
|
|
return "unknown field";
|
|
|
|
}
|
|
|
|
|
2010-12-27 20:23:51 +00:00
|
|
|
void ProcessFields::InitProcess()
|
2010-03-02 13:54:50 +00:00
|
|
|
{
|
2011-02-09 11:28:28 +00:00
|
|
|
if (Enabled==false) return;
|
|
|
|
|
2010-12-27 20:23:51 +00:00
|
|
|
CalcMeshPos();
|
2011-04-01 13:29:56 +00:00
|
|
|
|
|
|
|
if (m_fileType==VTK_FILETYPE)
|
|
|
|
{
|
2012-02-02 09:20:49 +00:00
|
|
|
delete m_Vtk_Dump_File;
|
|
|
|
m_Vtk_Dump_File = new VTK_File_Writer(m_filename,(int)m_Mesh_Type);
|
2011-04-01 13:29:56 +00:00
|
|
|
|
|
|
|
#ifdef OUTPUT_IN_DRAWINGUNITS
|
|
|
|
double discScaling = 1;
|
|
|
|
#else
|
|
|
|
double discScaling = Op->GetGridDelta();
|
|
|
|
#endif
|
2012-02-02 09:20:49 +00:00
|
|
|
m_Vtk_Dump_File->SetMeshLines(discLines,numLines,discScaling);
|
|
|
|
m_Vtk_Dump_File->SetNativeDump(g_settings.NativeFieldDumps());
|
|
|
|
}
|
|
|
|
if (m_fileType==HDF5_FILETYPE)
|
|
|
|
{
|
|
|
|
delete m_HDF5_Dump_File;
|
|
|
|
m_HDF5_Dump_File = new HDF5_File_Writer(m_filename+".h5");
|
|
|
|
|
|
|
|
#ifdef OUTPUT_IN_DRAWINGUNITS
|
|
|
|
double discScaling = 1;
|
|
|
|
#else
|
|
|
|
double discScaling = Op->GetGridDelta();
|
|
|
|
#endif
|
|
|
|
m_HDF5_Dump_File->WriteRectMesh(numLines,discLines,(int)m_Mesh_Type,discScaling);
|
2012-02-17 11:33:37 +00:00
|
|
|
|
|
|
|
m_HDF5_Dump_File->WriteAtrribute("/","openEMS_HDF5_version",0.2);
|
2011-04-01 13:29:56 +00:00
|
|
|
}
|
2010-12-27 20:23:51 +00:00
|
|
|
}
|
2010-07-20 14:30:41 +00:00
|
|
|
|
2010-12-27 20:23:51 +00:00
|
|
|
void ProcessFields::SetDumpMode(Engine_Interface_Base::InterpolationType mode)
|
|
|
|
{
|
|
|
|
m_Eng_Interface->SetInterpolationType(mode);
|
|
|
|
if (mode==Engine_Interface_Base::CELL_INTERPOLATE)
|
|
|
|
m_dualMesh=true;
|
2011-01-05 11:11:59 +00:00
|
|
|
else if (mode==Engine_Interface_Base::NODE_INTERPOLATE)
|
2010-12-27 20:23:51 +00:00
|
|
|
m_dualMesh=false;
|
2011-01-05 11:11:59 +00:00
|
|
|
//else keep the preset/user defined case
|
2010-12-27 20:23:51 +00:00
|
|
|
}
|
2010-07-20 14:30:41 +00:00
|
|
|
|
2010-12-27 20:23:51 +00:00
|
|
|
void ProcessFields::DefineStartStopCoord(double* dstart, double* dstop)
|
|
|
|
{
|
|
|
|
Processing::DefineStartStopCoord(dstart,dstop);
|
2010-07-20 14:30:41 +00:00
|
|
|
|
2010-12-27 20:23:51 +00:00
|
|
|
// normalize order of start and stop
|
|
|
|
for (int n=0; n<3; ++n)
|
2010-05-11 18:38:58 +00:00
|
|
|
{
|
2010-12-27 20:23:51 +00:00
|
|
|
if (start[n]>stop[n])
|
2010-05-11 18:38:58 +00:00
|
|
|
{
|
2010-12-27 20:23:51 +00:00
|
|
|
unsigned int help = start[n];
|
|
|
|
start[n]=stop[n];
|
|
|
|
stop[n]=help;
|
2010-05-11 18:38:58 +00:00
|
|
|
}
|
|
|
|
}
|
2010-03-02 13:54:50 +00:00
|
|
|
}
|
|
|
|
|
2011-11-07 11:07:55 +00:00
|
|
|
double ProcessFields::CalcTotalEnergyEstimate() const
|
2010-03-15 15:59:37 +00:00
|
|
|
{
|
2011-11-07 11:07:55 +00:00
|
|
|
return m_Eng_Interface->CalcFastEnergy();
|
2010-03-15 15:59:37 +00:00
|
|
|
}
|
|
|
|
|
2010-12-02 13:29:46 +00:00
|
|
|
void ProcessFields::SetSubSampling(unsigned int subSampleRate, int dir)
|
2010-04-07 10:57:45 +00:00
|
|
|
{
|
|
|
|
if (dir>2) return;
|
|
|
|
if (dir<0)
|
|
|
|
{
|
|
|
|
subSample[0]=subSampleRate;
|
|
|
|
subSample[1]=subSampleRate;
|
|
|
|
subSample[2]=subSampleRate;
|
|
|
|
}
|
|
|
|
else subSample[dir]=subSampleRate;
|
2010-12-27 20:23:51 +00:00
|
|
|
m_SampleType = SUBSAMPLE;
|
|
|
|
}
|
|
|
|
|
2010-12-28 10:15:08 +00:00
|
|
|
void ProcessFields::SetOptResolution(double optRes, int dir)
|
|
|
|
{
|
|
|
|
if (dir>2) return;
|
|
|
|
if (dir<0)
|
|
|
|
{
|
|
|
|
optResolution[0]=optRes;
|
|
|
|
optResolution[1]=optRes;
|
|
|
|
optResolution[2]=optRes;
|
|
|
|
}
|
|
|
|
else optResolution[dir]=optRes;
|
|
|
|
m_SampleType = OPT_RESOLUTION;
|
|
|
|
}
|
|
|
|
|
2010-12-27 20:23:51 +00:00
|
|
|
void ProcessFields::CalcMeshPos()
|
|
|
|
{
|
|
|
|
if ((m_SampleType==SUBSAMPLE) || (m_SampleType==NONE))
|
|
|
|
{
|
|
|
|
vector<unsigned int> tmp_pos;
|
|
|
|
|
|
|
|
for (int n=0; n<3; ++n)
|
|
|
|
{
|
|
|
|
// construct new discLines
|
|
|
|
tmp_pos.clear();
|
|
|
|
for (unsigned int i=start[n]; i<=stop[n]; i+=subSample[n])
|
|
|
|
tmp_pos.push_back(i);
|
|
|
|
|
|
|
|
numLines[n] = tmp_pos.size();
|
|
|
|
delete[] discLines[n];
|
|
|
|
discLines[n] = new double[numLines[n]];
|
|
|
|
delete[] posLines[n];
|
|
|
|
posLines[n] = new unsigned int[numLines[n]];
|
|
|
|
for (unsigned int i=0; i<numLines[n]; ++i)
|
|
|
|
{
|
|
|
|
posLines[n][i] = tmp_pos.at(i);
|
|
|
|
discLines[n][i] = Op->GetDiscLine(n,tmp_pos.at(i),m_dualMesh);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2010-12-28 10:15:08 +00:00
|
|
|
if ((m_SampleType==OPT_RESOLUTION))
|
|
|
|
{
|
|
|
|
vector<unsigned int> tmp_pos;
|
|
|
|
double oldPos=0;
|
|
|
|
for (int n=0; n<3; ++n)
|
|
|
|
{
|
|
|
|
// construct new discLines
|
|
|
|
tmp_pos.clear();
|
|
|
|
tmp_pos.push_back(start[n]);
|
|
|
|
oldPos=Op->GetDiscLine(n,start[n],m_dualMesh);
|
2011-07-07 06:05:49 +00:00
|
|
|
if (stop[n]==0)
|
|
|
|
tmp_pos.push_back(stop[n]);
|
|
|
|
else
|
|
|
|
for (unsigned int i=start[n]+1; i<=stop[n]-1; ++i)
|
2010-12-28 10:15:08 +00:00
|
|
|
{
|
2011-07-07 06:05:49 +00:00
|
|
|
if ( (Op->GetDiscLine(n,i+1,m_dualMesh)-oldPos) >= optResolution[n])
|
|
|
|
{
|
|
|
|
tmp_pos.push_back(i);
|
|
|
|
oldPos=Op->GetDiscLine(n,i,m_dualMesh);
|
|
|
|
}
|
2010-12-28 10:15:08 +00:00
|
|
|
}
|
|
|
|
if (start[n]!=stop[n])
|
|
|
|
tmp_pos.push_back(stop[n]);
|
|
|
|
numLines[n] = tmp_pos.size();
|
|
|
|
delete[] discLines[n];
|
|
|
|
discLines[n] = new double[numLines[n]];
|
|
|
|
delete[] posLines[n];
|
|
|
|
posLines[n] = new unsigned int[numLines[n]];
|
|
|
|
for (unsigned int i=0; i<numLines[n]; ++i)
|
|
|
|
{
|
|
|
|
posLines[n][i] = tmp_pos.at(i);
|
|
|
|
discLines[n][i] = Op->GetDiscLine(n,tmp_pos.at(i),m_dualMesh);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2010-04-07 10:57:45 +00:00
|
|
|
}
|
2010-03-09 20:35:57 +00:00
|
|
|
|
2010-12-17 14:14:34 +00:00
|
|
|
FDTD_FLOAT**** ProcessFields::CalcField()
|
|
|
|
{
|
|
|
|
unsigned int pos[3];
|
|
|
|
double out[3];
|
|
|
|
//create array
|
|
|
|
FDTD_FLOAT**** field = Create_N_3DArray<FDTD_FLOAT>(numLines);
|
2011-01-07 15:12:07 +00:00
|
|
|
switch (m_DumpType)
|
2010-12-17 14:14:34 +00:00
|
|
|
{
|
2011-01-07 15:12:07 +00:00
|
|
|
case E_FIELD_DUMP:
|
2010-12-27 20:23:51 +00:00
|
|
|
for (unsigned int i=0; i<numLines[0]; ++i)
|
2010-12-17 14:14:34 +00:00
|
|
|
{
|
2010-12-27 20:23:51 +00:00
|
|
|
pos[0]=posLines[0][i];
|
|
|
|
for (unsigned int j=0; j<numLines[1]; ++j)
|
2010-12-17 14:14:34 +00:00
|
|
|
{
|
2010-12-27 20:23:51 +00:00
|
|
|
pos[1]=posLines[1][j];
|
|
|
|
for (unsigned int k=0; k<numLines[2]; ++k)
|
2010-12-17 14:14:34 +00:00
|
|
|
{
|
2010-12-27 20:23:51 +00:00
|
|
|
pos[2]=posLines[2][k];
|
|
|
|
|
|
|
|
m_Eng_Interface->GetEField(pos,out);
|
|
|
|
field[0][i][j][k] = out[0];
|
|
|
|
field[1][i][j][k] = out[1];
|
|
|
|
field[2][i][j][k] = out[2];
|
2010-12-17 14:14:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2010-12-19 19:41:08 +00:00
|
|
|
return field;
|
2011-01-07 15:12:07 +00:00
|
|
|
case H_FIELD_DUMP:
|
2010-12-27 20:23:51 +00:00
|
|
|
for (unsigned int i=0; i<numLines[0]; ++i)
|
2010-12-17 14:14:34 +00:00
|
|
|
{
|
2010-12-27 20:23:51 +00:00
|
|
|
pos[0]=posLines[0][i];
|
|
|
|
for (unsigned int j=0; j<numLines[1]; ++j)
|
2010-12-17 14:14:34 +00:00
|
|
|
{
|
2010-12-27 20:23:51 +00:00
|
|
|
pos[1]=posLines[1][j];
|
|
|
|
for (unsigned int k=0; k<numLines[2]; ++k)
|
2010-12-17 14:14:34 +00:00
|
|
|
{
|
2010-12-27 20:23:51 +00:00
|
|
|
pos[2]=posLines[2][k];
|
|
|
|
|
|
|
|
m_Eng_Interface->GetHField(pos,out);
|
|
|
|
field[0][i][j][k] = out[0];
|
|
|
|
field[1][i][j][k] = out[1];
|
|
|
|
field[2][i][j][k] = out[2];
|
2010-12-17 14:14:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2010-12-19 19:41:08 +00:00
|
|
|
return field;
|
2011-01-07 15:12:07 +00:00
|
|
|
case J_FIELD_DUMP:
|
|
|
|
for (unsigned int i=0; i<numLines[0]; ++i)
|
|
|
|
{
|
|
|
|
pos[0]=posLines[0][i];
|
|
|
|
for (unsigned int j=0; j<numLines[1]; ++j)
|
|
|
|
{
|
|
|
|
pos[1]=posLines[1][j];
|
|
|
|
for (unsigned int k=0; k<numLines[2]; ++k)
|
|
|
|
{
|
|
|
|
pos[2]=posLines[2][k];
|
|
|
|
|
|
|
|
m_Eng_Interface->GetJField(pos,out);
|
|
|
|
field[0][i][j][k] = out[0];
|
|
|
|
field[1][i][j][k] = out[1];
|
|
|
|
field[2][i][j][k] = out[2];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return field;
|
2011-01-10 10:15:22 +00:00
|
|
|
case ROTH_FIELD_DUMP:
|
|
|
|
for (unsigned int i=0; i<numLines[0]; ++i)
|
|
|
|
{
|
|
|
|
pos[0]=posLines[0][i];
|
|
|
|
for (unsigned int j=0; j<numLines[1]; ++j)
|
|
|
|
{
|
|
|
|
pos[1]=posLines[1][j];
|
|
|
|
for (unsigned int k=0; k<numLines[2]; ++k)
|
|
|
|
{
|
|
|
|
pos[2]=posLines[2][k];
|
2010-12-19 19:41:08 +00:00
|
|
|
|
2011-01-10 10:15:22 +00:00
|
|
|
m_Eng_Interface->GetRotHField(pos,out);
|
|
|
|
field[0][i][j][k] = out[0];
|
|
|
|
field[1][i][j][k] = out[1];
|
|
|
|
field[2][i][j][k] = out[2];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return field;
|
2012-04-27 14:31:36 +00:00
|
|
|
default:
|
|
|
|
cerr << "ProcessFields::CalcField(): Error, unknown dump type..." << endl;
|
|
|
|
return field;
|
2011-01-10 10:15:22 +00:00
|
|
|
}
|
2010-12-17 14:14:34 +00:00
|
|
|
}
|
|
|
|
|