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-03-02 13:54:50 +00:00
|
|
|
#include "processfields_td.h"
|
2010-12-06 08:59:42 +00:00
|
|
|
#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-03-02 13:54:50 +00:00
|
|
|
#include <iomanip>
|
|
|
|
#include <sstream>
|
|
|
|
#include <string>
|
|
|
|
|
2010-12-07 15:47:23 +00:00
|
|
|
ProcessFieldsTD::ProcessFieldsTD(Engine_Interface_Base* eng_if) : ProcessFields(eng_if)
|
2010-03-02 13:54:50 +00:00
|
|
|
{
|
|
|
|
pad_length = 8;
|
|
|
|
}
|
|
|
|
|
|
|
|
ProcessFieldsTD::~ProcessFieldsTD()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2010-12-27 12:54:09 +00:00
|
|
|
void ProcessFieldsTD::InitProcess()
|
|
|
|
{
|
2011-02-09 11:28:28 +00:00
|
|
|
if (Enabled==false) return;
|
|
|
|
|
2010-12-27 12:54:09 +00:00
|
|
|
ProcessFields::InitProcess();
|
|
|
|
|
2012-02-02 09:20:49 +00:00
|
|
|
if (m_Vtk_Dump_File)
|
|
|
|
m_Vtk_Dump_File->SetHeader(string("openEMS TD 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)
|
|
|
|
m_HDF5_Dump_File->SetCurrentGroup("/FieldData/TD");
|
2010-12-27 12:54:09 +00:00
|
|
|
}
|
|
|
|
|
2010-12-02 12:51:34 +00:00
|
|
|
int ProcessFieldsTD::Process()
|
2010-03-02 13:54:50 +00:00
|
|
|
{
|
2010-12-02 12:51:34 +00:00
|
|
|
if (Enabled==false) return -1;
|
|
|
|
if (CheckTimestep()==false) return GetNextInterval();
|
2010-07-15 10:58:48 +00:00
|
|
|
|
2011-04-01 13:29:56 +00:00
|
|
|
string filename = m_filename;
|
2010-07-15 10:58:48 +00:00
|
|
|
|
2011-04-01 13:29:56 +00:00
|
|
|
float**** field = CalcField();
|
2012-02-02 09:20:49 +00:00
|
|
|
bool success = true;
|
2010-03-09 20:35:57 +00:00
|
|
|
|
2010-04-05 18:22:03 +00:00
|
|
|
if (m_fileType==VTK_FILETYPE)
|
|
|
|
{
|
2012-02-02 09:20:49 +00:00
|
|
|
m_Vtk_Dump_File->SetTimestep(m_Eng_Interface->GetNumberOfTimesteps());
|
|
|
|
m_Vtk_Dump_File->ClearAllFields();
|
|
|
|
m_Vtk_Dump_File->AddVectorField(GetFieldNameByType(m_DumpType),field);
|
|
|
|
success &= m_Vtk_Dump_File->Write();
|
2010-04-05 18:22:03 +00:00
|
|
|
}
|
|
|
|
else if (m_fileType==HDF5_FILETYPE)
|
|
|
|
{
|
2010-12-02 12:51:34 +00:00
|
|
|
stringstream ss;
|
2010-12-02 13:29:46 +00:00
|
|
|
ss << std::setw( pad_length ) << std::setfill( '0' ) << m_Eng_Interface->GetNumberOfTimesteps();
|
2012-02-02 09:20:49 +00:00
|
|
|
size_t datasize[]={numLines[0],numLines[1],numLines[2]};
|
|
|
|
success &= m_HDF5_Dump_File->WriteVectorField(ss.str(), field, datasize);
|
|
|
|
float time[1]={m_Eng_Interface->GetTime(m_dualTime)};
|
|
|
|
success &= m_HDF5_Dump_File->WriteAtrribute("/FieldData/TD/"+ss.str(),"time",time,1);
|
2010-04-05 18:22:03 +00:00
|
|
|
}
|
2010-12-02 12:51:34 +00:00
|
|
|
else
|
2012-02-02 09:20:49 +00:00
|
|
|
{
|
|
|
|
success = false;
|
2010-12-02 12:51:34 +00:00
|
|
|
cerr << "ProcessFieldsTD::Process: unknown File-Type" << endl;
|
2012-02-02 09:20:49 +00:00
|
|
|
}
|
2010-12-02 12:51:34 +00:00
|
|
|
|
2011-01-24 10:11:45 +00:00
|
|
|
Delete_N_3DArray<FDTD_FLOAT>(field,numLines);
|
2010-12-02 12:51:34 +00:00
|
|
|
|
2012-02-02 09:20:49 +00:00
|
|
|
if (success==false)
|
|
|
|
{
|
|
|
|
SetEnable(false);
|
|
|
|
cerr << "ProcessFieldsTD::Process: can't dump to file... disabled! " << endl;
|
|
|
|
}
|
|
|
|
|
2010-03-10 11:15:14 +00:00
|
|
|
return GetNextInterval();
|
2010-03-02 13:54:50 +00:00
|
|
|
}
|