2010-06-28 17:45:19 +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 "processintegral.h"
|
2011-01-18 09:34:13 +00:00
|
|
|
#include "Common/operator_base.h"
|
2011-01-06 09:08:58 +00:00
|
|
|
#include "time.h"
|
2010-08-11 10:28:09 +00:00
|
|
|
#include <iomanip>
|
2010-06-28 17:45:19 +00:00
|
|
|
|
2010-12-07 15:47:23 +00:00
|
|
|
ProcessIntegral::ProcessIntegral(Engine_Interface_Base* eng_if) : Processing(eng_if)
|
2010-06-28 17:45:19 +00:00
|
|
|
{
|
2010-09-09 08:02:33 +00:00
|
|
|
m_Results=NULL;
|
2011-01-05 15:25:50 +00:00
|
|
|
m_FD_Results=NULL;
|
2010-06-28 17:45:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ProcessIntegral::~ProcessIntegral()
|
|
|
|
{
|
2010-09-09 08:02:33 +00:00
|
|
|
delete[] m_Results;
|
2011-01-05 15:25:50 +00:00
|
|
|
delete[] m_FD_Results;
|
2010-09-09 08:02:33 +00:00
|
|
|
m_Results = NULL;
|
2011-01-05 15:25:50 +00:00
|
|
|
m_FD_Results = NULL;
|
2010-06-28 17:45:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void ProcessIntegral::InitProcess()
|
|
|
|
{
|
2011-02-16 07:10:59 +00:00
|
|
|
delete[] m_Results; m_Results = NULL;
|
|
|
|
delete[] m_FD_Results; m_FD_Results = NULL;
|
|
|
|
|
|
|
|
if (!Enabled)
|
|
|
|
return;
|
|
|
|
|
2011-01-05 15:25:50 +00:00
|
|
|
m_Results = new double[GetNumberOfIntegrals()];
|
|
|
|
m_FD_Results = new vector<double_complex>[GetNumberOfIntegrals()];
|
|
|
|
|
2010-06-28 17:45:19 +00:00
|
|
|
m_filename = m_Name;
|
|
|
|
OpenFile(m_filename);
|
2011-01-05 15:25:50 +00:00
|
|
|
|
2011-01-18 09:34:13 +00:00
|
|
|
//write header
|
|
|
|
time_t rawTime;
|
|
|
|
time(&rawTime);
|
|
|
|
file << "% time-domain " << GetProcessingName() << " by openEMS " << GIT_VERSION << " @" << ctime(&rawTime);
|
|
|
|
file << "% start-coordinates: ("
|
|
|
|
<< 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 << "% stop-coordinates: ("
|
|
|
|
<< Op->GetDiscLine(0,stop[0])*Op->GetGridDelta() << ","
|
|
|
|
<< Op->GetDiscLine(1,stop[1])*Op->GetGridDelta() << ","
|
|
|
|
<< Op->GetDiscLine(2,stop[2])*Op->GetGridDelta() << ") m -> [" << stop[0] << "," << stop[1] << "," << stop[2] << "]" << endl;
|
|
|
|
file << "% t/s";
|
|
|
|
for (int n=0;n<GetNumberOfIntegrals();++n)
|
|
|
|
{
|
|
|
|
file << "\t" << GetIntegralName(n);
|
|
|
|
}
|
|
|
|
file << endl;
|
|
|
|
|
2011-01-05 15:25:50 +00:00
|
|
|
for (int i=0;i<GetNumberOfIntegrals();++i)
|
|
|
|
{
|
|
|
|
for (size_t n=0; n<m_FD_Samples.size(); ++n)
|
|
|
|
{
|
|
|
|
m_FD_Results[i].push_back(0);
|
|
|
|
}
|
|
|
|
}
|
2010-06-28 17:45:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ProcessIntegral::FlushData()
|
|
|
|
{
|
2011-02-16 07:10:59 +00:00
|
|
|
if (!Enabled)
|
|
|
|
return;
|
2010-06-28 17:45:19 +00:00
|
|
|
if (m_FD_Samples.size())
|
2011-01-31 10:10:18 +00:00
|
|
|
Dump_FD_Data(1.0,m_filename + "_FD");
|
2011-01-05 15:25:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void ProcessIntegral::Dump_FD_Data(double factor, string filename)
|
|
|
|
{
|
|
|
|
if (m_FD_Samples.size()==0)
|
|
|
|
return;
|
|
|
|
ofstream file;
|
|
|
|
file.open( filename.c_str() );
|
|
|
|
if (!file.is_open())
|
|
|
|
cerr << "ProcessIntegral::Dump_FD_Data: Error: Can't open file: " << filename << endl;
|
2011-01-18 09:34:13 +00:00
|
|
|
|
|
|
|
//write header
|
2011-01-05 15:25:50 +00:00
|
|
|
time_t rawTime;
|
|
|
|
time(&rawTime);
|
2011-01-18 09:34:13 +00:00
|
|
|
file << "% frequency-domain " << GetProcessingName() << " by openEMS " << GIT_VERSION << " @" << ctime(&rawTime);
|
|
|
|
file << "% start-coordinates: ("
|
|
|
|
<< 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 << "% stop-coordinates: ("
|
|
|
|
<< Op->GetDiscLine(0,stop[0])*Op->GetGridDelta() << ","
|
|
|
|
<< Op->GetDiscLine(1,stop[1])*Op->GetGridDelta() << ","
|
|
|
|
<< Op->GetDiscLine(2,stop[2])*Op->GetGridDelta() << ") m -> [" << stop[0] << "," << stop[1] << "," << stop[2] << "]" << endl;
|
|
|
|
file << "% f/Hz";
|
|
|
|
for (int n=0;n<GetNumberOfIntegrals();++n)
|
|
|
|
{
|
|
|
|
file << "\t" << GetIntegralName(n) << "\t";
|
|
|
|
}
|
|
|
|
file << endl << "%";
|
2011-01-05 15:25:50 +00:00
|
|
|
for (int i = 0; i < GetNumberOfIntegrals();++i)
|
|
|
|
file << "\treal\timag";
|
2011-01-18 09:34:13 +00:00
|
|
|
file << endl;
|
2011-01-05 15:25:50 +00:00
|
|
|
|
|
|
|
for (size_t n=0; n<m_FD_Samples.size(); ++n)
|
|
|
|
{
|
|
|
|
file << m_FD_Samples.at(n) ;
|
|
|
|
for (int i = 0; i < GetNumberOfIntegrals();++i)
|
|
|
|
file << "\t" << std::real(m_FD_Results[i].at(n))*factor << "\t" << std::imag(m_FD_Results[i].at(n))*factor;
|
|
|
|
file << "\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
file.close();
|
2010-06-28 17:45:19 +00:00
|
|
|
}
|
|
|
|
|
2010-08-11 10:28:09 +00:00
|
|
|
int ProcessIntegral::Process()
|
|
|
|
{
|
|
|
|
if (Enabled==false) return -1;
|
|
|
|
if (CheckTimestep()==false) return GetNextInterval();
|
|
|
|
|
2010-09-09 08:02:33 +00:00
|
|
|
CalcMultipleIntegrals();
|
|
|
|
int NrInt = GetNumberOfIntegrals();
|
2010-12-19 19:41:08 +00:00
|
|
|
double time = m_Eng_Interface->GetTime(m_dualTime);
|
2010-08-11 10:28:09 +00:00
|
|
|
|
|
|
|
if (ProcessInterval)
|
|
|
|
{
|
2010-12-02 13:29:46 +00:00
|
|
|
if (m_Eng_Interface->GetNumberOfTimesteps()%ProcessInterval==0)
|
2010-08-11 10:28:09 +00:00
|
|
|
{
|
2010-09-09 08:02:33 +00:00
|
|
|
file << setprecision(m_precision) << time;
|
2010-12-06 12:04:37 +00:00
|
|
|
for (int n=0; n<NrInt; ++n)
|
2010-09-09 08:02:33 +00:00
|
|
|
file << "\t" << m_Results[n] * m_weight;
|
|
|
|
file << endl;
|
2010-08-11 10:28:09 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (m_FD_Interval)
|
|
|
|
{
|
2010-12-02 13:29:46 +00:00
|
|
|
if (m_Eng_Interface->GetNumberOfTimesteps()%m_FD_Interval==0)
|
2010-08-11 10:28:09 +00:00
|
|
|
{
|
2010-12-06 12:04:37 +00:00
|
|
|
for (size_t n=0; n<m_FD_Samples.size(); ++n)
|
2010-08-11 10:28:09 +00:00
|
|
|
{
|
2011-01-05 15:25:50 +00:00
|
|
|
for (int i=0; i<NrInt; ++i)
|
2011-01-31 14:00:55 +00:00
|
|
|
m_FD_Results[i].at(n) += (double)m_Results[i] * m_weight * std::exp( -2.0 * _I * M_PI * m_FD_Samples.at(n) * time ) * 2.0 * Op->GetTimestep() * (double)m_FD_Interval;
|
2010-08-11 10:28:09 +00:00
|
|
|
}
|
|
|
|
++m_FD_SampleCount;
|
|
|
|
if (m_Flush)
|
2010-12-06 12:04:37 +00:00
|
|
|
FlushData();
|
2010-08-11 10:28:09 +00:00
|
|
|
m_Flush = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return GetNextInterval();
|
|
|
|
}
|
|
|
|
|
2010-09-09 08:02:33 +00:00
|
|
|
double* ProcessIntegral::CalcMultipleIntegrals()
|
|
|
|
{
|
|
|
|
m_Results[0] = CalcIntegral();
|
|
|
|
return m_Results;
|
|
|
|
}
|