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-05-28 13:13:14 +00:00
|
|
|
#include "tools/global.h"
|
2010-06-28 16:05:03 +00:00
|
|
|
#include "tools/useful.h"
|
2010-12-06 08:59:42 +00:00
|
|
|
#include "Common/operator_base.h"
|
|
|
|
#include <algorithm>
|
2010-03-01 18:35:28 +00:00
|
|
|
#include "processing.h"
|
2010-06-28 16:05:03 +00:00
|
|
|
#include <climits>
|
2010-03-01 18:35:28 +00:00
|
|
|
|
2010-12-07 15:47:23 +00:00
|
|
|
Processing::Processing(Engine_Interface_Base* eng_if)
|
2010-03-01 18:35:28 +00:00
|
|
|
{
|
2010-12-07 15:47:23 +00:00
|
|
|
m_Eng_Interface = NULL;
|
|
|
|
SetEngineInterface(eng_if);
|
|
|
|
|
2010-03-04 15:54:16 +00:00
|
|
|
Enabled = true;
|
2010-04-03 15:36:50 +00:00
|
|
|
m_PS_pos = 0;
|
2010-04-12 07:38:24 +00:00
|
|
|
SetPrecision(12);
|
2010-04-03 15:36:50 +00:00
|
|
|
ProcessInterval=0;
|
2010-06-28 16:05:03 +00:00
|
|
|
m_FD_SampleCount=0;
|
|
|
|
m_FD_Interval=0;
|
2010-06-16 10:50:19 +00:00
|
|
|
m_weight=1;
|
2010-06-28 16:05:03 +00:00
|
|
|
m_Flush = false;
|
2010-08-11 10:28:09 +00:00
|
|
|
m_dualMesh = false;
|
2010-12-19 19:41:08 +00:00
|
|
|
m_dualTime = false;
|
2010-08-11 16:46:47 +00:00
|
|
|
m_Mesh_Type = CARTESIAN_MESH;
|
2010-03-01 18:35:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Processing::~Processing()
|
|
|
|
{
|
2010-12-02 12:51:34 +00:00
|
|
|
SetEngineInterface(NULL);
|
2010-04-19 14:09:41 +00:00
|
|
|
file.close();
|
2010-03-01 18:35:28 +00:00
|
|
|
}
|
|
|
|
|
2010-04-03 15:36:50 +00:00
|
|
|
void Processing::Reset()
|
|
|
|
{
|
|
|
|
m_PS_pos=0;
|
|
|
|
}
|
|
|
|
|
2010-12-02 12:51:34 +00:00
|
|
|
void Processing::SetEngineInterface(Engine_Interface_Base* eng_if)
|
|
|
|
{
|
|
|
|
delete m_Eng_Interface;
|
|
|
|
m_Eng_Interface = eng_if;
|
2010-12-07 15:47:23 +00:00
|
|
|
if (m_Eng_Interface)
|
|
|
|
Op=m_Eng_Interface->GetOperator();
|
|
|
|
else
|
|
|
|
Op=NULL;
|
2010-12-02 12:51:34 +00:00
|
|
|
}
|
|
|
|
|
2010-03-10 11:15:14 +00:00
|
|
|
bool Processing::CheckTimestep()
|
|
|
|
{
|
2010-04-03 15:36:50 +00:00
|
|
|
if (m_ProcessSteps.size()>m_PS_pos)
|
|
|
|
{
|
2010-12-02 13:29:46 +00:00
|
|
|
if (m_ProcessSteps.at(m_PS_pos)==m_Eng_Interface->GetNumberOfTimesteps())
|
2010-04-03 15:36:50 +00:00
|
|
|
{
|
|
|
|
++m_PS_pos;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (ProcessInterval)
|
|
|
|
{
|
2010-12-02 13:29:46 +00:00
|
|
|
if (m_Eng_Interface->GetNumberOfTimesteps()%ProcessInterval==0) return true;
|
2010-04-03 15:36:50 +00:00
|
|
|
}
|
2010-06-28 16:05:03 +00:00
|
|
|
|
|
|
|
if (m_FD_Interval)
|
|
|
|
{
|
2010-12-02 13:29:46 +00:00
|
|
|
if (m_Eng_Interface->GetNumberOfTimesteps()%m_FD_Interval==0) return true;
|
2010-06-28 16:05:03 +00:00
|
|
|
}
|
2010-03-10 11:15:14 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2010-04-03 15:36:50 +00:00
|
|
|
int Processing::GetNextInterval() const
|
2010-03-10 11:15:14 +00:00
|
|
|
{
|
|
|
|
if (Enabled==false) return -1;
|
2010-06-28 16:05:03 +00:00
|
|
|
int next=INT_MAX;
|
2010-04-03 15:36:50 +00:00
|
|
|
if (m_ProcessSteps.size()>m_PS_pos)
|
|
|
|
{
|
2010-12-02 13:29:46 +00:00
|
|
|
next = (int)m_ProcessSteps.at(m_PS_pos)-(int)m_Eng_Interface->GetNumberOfTimesteps();
|
2010-06-28 16:05:03 +00:00
|
|
|
}
|
|
|
|
if (ProcessInterval!=0)
|
|
|
|
{
|
2010-12-02 13:29:46 +00:00
|
|
|
int next_Interval = (int)ProcessInterval - (int)m_Eng_Interface->GetNumberOfTimesteps()%ProcessInterval;
|
2010-06-28 16:05:03 +00:00
|
|
|
if (next_Interval<next)
|
|
|
|
next = next_Interval;
|
|
|
|
}
|
|
|
|
|
|
|
|
//check for FD sample interval
|
|
|
|
if (m_FD_Interval!=0)
|
|
|
|
{
|
2010-12-02 13:29:46 +00:00
|
|
|
int next_Interval = (int)m_FD_Interval - (int)m_Eng_Interface->GetNumberOfTimesteps()%m_FD_Interval;
|
2010-06-28 16:05:03 +00:00
|
|
|
if (next_Interval<next)
|
|
|
|
next = next_Interval;
|
2010-04-03 15:36:50 +00:00
|
|
|
}
|
|
|
|
return next;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Processing::AddStep(unsigned int step)
|
|
|
|
{
|
|
|
|
if (m_ProcessSteps.size()==0)
|
|
|
|
m_ProcessSteps.push_back(step);
|
|
|
|
else if (find(m_ProcessSteps.begin(), m_ProcessSteps.end(),step)==m_ProcessSteps.end())
|
|
|
|
m_ProcessSteps.push_back(step);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Processing::AddSteps(vector<unsigned int> steps)
|
|
|
|
{
|
2010-12-06 12:04:37 +00:00
|
|
|
for (size_t n=0; n<steps.size(); ++n)
|
2010-04-03 15:36:50 +00:00
|
|
|
{
|
|
|
|
AddStep(steps.at(n));
|
|
|
|
}
|
2010-03-10 11:15:14 +00:00
|
|
|
}
|
2010-03-01 18:35:28 +00:00
|
|
|
|
2010-06-28 16:05:03 +00:00
|
|
|
void Processing::AddFrequency(double freq)
|
|
|
|
{
|
|
|
|
unsigned int nyquistTS = CalcNyquistNum(freq,Op->GetTimestep());
|
|
|
|
|
|
|
|
if (nyquistTS == 0)
|
|
|
|
{
|
|
|
|
cerr << "Processing::AddFrequency: Requested frequency " << freq << " is too high for the current timestep used... skipping..." << endl;
|
|
|
|
return;
|
|
|
|
}
|
2010-12-06 08:59:42 +00:00
|
|
|
else if (nyquistTS<Op->GetNumberOfNyquistTimesteps())
|
2010-06-28 16:05:03 +00:00
|
|
|
{
|
|
|
|
cerr << "Processing::AddFrequency: Warning: Requested frequency " << freq << " is higher than maximum excited frequency..." << endl;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (m_FD_Interval==0)
|
2010-12-06 08:59:42 +00:00
|
|
|
m_FD_Interval = Op->GetNumberOfNyquistTimesteps();
|
2010-06-28 16:05:03 +00:00
|
|
|
if (m_FD_Interval>nyquistTS)
|
|
|
|
m_FD_Interval = nyquistTS;
|
|
|
|
|
|
|
|
m_FD_Samples.push_back(freq);
|
|
|
|
}
|
|
|
|
|
2010-08-11 16:48:23 +00:00
|
|
|
void Processing::AddFrequency(vector<double> *freqs)
|
2010-06-28 16:05:03 +00:00
|
|
|
{
|
2010-12-06 12:04:37 +00:00
|
|
|
for (size_t n=0; n<freqs->size(); ++n)
|
2010-06-28 16:05:03 +00:00
|
|
|
{
|
2010-08-11 16:48:23 +00:00
|
|
|
AddFrequency(freqs->at(n));
|
2010-06-28 16:05:03 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-03-02 13:54:50 +00:00
|
|
|
void Processing::DefineStartStopCoord(double* dstart, double* dstop)
|
|
|
|
{
|
2011-02-08 15:50:38 +00:00
|
|
|
for (int n=0;n<3;++n)
|
|
|
|
{
|
|
|
|
double min = Op->GetDiscLine(n,0);
|
|
|
|
double max = Op->GetDiscLine(n,Op->GetNumberOfLines(n)-1);
|
|
|
|
if ( ((dstart[n]<min) && (dstop[n]<min)) || ((dstart[n]>max) && (dstop[n]>max)) )
|
|
|
|
{
|
|
|
|
cerr << "Processing::DefineStartStopCoord: Warning in " << m_Name << " (" << GetProcessingName() << ") : Box is outside the field domain!! Disabling" << endl;
|
|
|
|
Enabled = false;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-08-11 10:28:09 +00:00
|
|
|
if (Op->SnapToMesh(dstart,start,m_dualMesh,m_start_inside)==false)
|
2011-01-20 13:39:01 +00:00
|
|
|
cerr << "Processing::DefineStartStopCoord: Warning in " << m_Name << " (" << GetProcessingName() << ") : Snapped start line outside field domain!!" << endl;
|
2010-08-11 10:28:09 +00:00
|
|
|
if (Op->SnapToMesh(dstop,stop,m_dualMesh,m_stop_inside)==false)
|
2011-01-20 13:39:01 +00:00
|
|
|
cerr << "Processing::DefineStartStopCoord: Warning in " << m_Name << " (" << GetProcessingName() << ") : Snapped stop line outside field domain!!" << endl;
|
2010-05-28 13:13:14 +00:00
|
|
|
|
2010-12-06 12:04:37 +00:00
|
|
|
if (g_settings.showProbeDiscretization())
|
|
|
|
{
|
2010-08-11 10:28:09 +00:00
|
|
|
cerr << m_Name << ": snapped coords: (" << Op->GetDiscLine( 0, start[0], m_dualMesh ) << ","
|
2010-12-06 12:04:37 +00:00
|
|
|
<< Op->GetDiscLine( 1, start[1], m_dualMesh ) << "," << Op->GetDiscLine( 2, start[2], m_dualMesh ) << ") -> ("
|
|
|
|
<< Op->GetDiscLine( 0, stop[0], m_dualMesh ) << ","<< Op->GetDiscLine( 1, stop[1], m_dualMesh ) << ","
|
|
|
|
<< Op->GetDiscLine( 2, stop[2], m_dualMesh ) << ")";
|
2010-05-28 13:13:14 +00:00
|
|
|
cerr << " [" << start[0] << "," << start[1] << "," << start[2] << "] -> ["
|
2010-12-06 12:04:37 +00:00
|
|
|
<< stop[0] << "," << stop[1] << "," << stop[2] << "]" << endl;
|
2010-05-28 13:13:14 +00:00
|
|
|
}
|
2010-03-01 18:35:28 +00:00
|
|
|
}
|
2010-03-02 13:54:50 +00:00
|
|
|
|
2010-04-19 14:09:41 +00:00
|
|
|
void Processing::OpenFile( string outfile )
|
|
|
|
{
|
|
|
|
if (file.is_open())
|
|
|
|
file.close();
|
|
|
|
|
|
|
|
file.open( outfile.c_str() );
|
|
|
|
if (!file.is_open())
|
|
|
|
cerr << "Can't open file: " << outfile << endl;
|
|
|
|
|
|
|
|
m_filename = outfile;
|
|
|
|
}
|
|
|
|
|
2011-01-05 15:25:50 +00:00
|
|
|
void Processing::PostProcess()
|
|
|
|
{
|
|
|
|
FlushData();
|
|
|
|
}
|
|
|
|
|
2010-04-19 14:09:41 +00:00
|
|
|
void Processing::DumpBox2File( string vtkfilenameprefix, bool dualMesh ) const
|
|
|
|
{
|
|
|
|
string vtkfilename = vtkfilenameprefix + m_filename + ".vtk";
|
|
|
|
|
|
|
|
ofstream file( vtkfilename.c_str() );
|
|
|
|
if (!file.is_open())
|
|
|
|
{
|
|
|
|
cerr << "Processing::DumpBoxes2File(): Can't open file: " << vtkfilename << endl;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// normalize coordinates
|
|
|
|
double s1[3], s2[3];
|
2010-12-06 12:04:37 +00:00
|
|
|
for (int i=0; i<3; i++)
|
|
|
|
{
|
2010-04-19 14:09:41 +00:00
|
|
|
s1[i] = min(Op->GetDiscLine(i,start[i],dualMesh),Op->GetDiscLine(i,stop[i],dualMesh));
|
|
|
|
s2[i] = max(Op->GetDiscLine(i,start[i],dualMesh),Op->GetDiscLine(i,stop[i],dualMesh));
|
|
|
|
}
|
|
|
|
|
|
|
|
// fix degenerate box/plane -> line (paraview display problem)
|
2010-12-06 12:04:37 +00:00
|
|
|
if (((s1[0] == s2[0]) && (s1[1] == s2[1])) || ((s1[0] == s2[0]) && (s1[2] == s2[2])) || ((s1[2] == s2[2]) && (s1[1] == s2[1])))
|
|
|
|
{
|
2010-04-19 14:09:41 +00:00
|
|
|
// line are not displayed correctly -> enlarge
|
2010-12-06 12:04:37 +00:00
|
|
|
for (int i=0; i<3; i++)
|
|
|
|
{
|
2010-12-08 15:55:27 +00:00
|
|
|
double delta = min( Op->GetEdgeLength( i, start,dualMesh ), Op->GetEdgeLength( i, stop,dualMesh ) ) / Op->GetGridDelta() / 4.0;
|
2010-04-19 14:09:41 +00:00
|
|
|
s1[i] -= delta;
|
|
|
|
s2[i] += delta;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-10-11 19:03:34 +00:00
|
|
|
// rescale coordinates
|
|
|
|
#ifndef OUTPUT_IN_DRAWINGUNITS
|
|
|
|
double scaling = Op->GetGridDelta();
|
2010-12-06 12:04:37 +00:00
|
|
|
for (int i=0; i<3; i++)
|
|
|
|
{
|
2010-10-11 19:03:34 +00:00
|
|
|
s1[i] *= scaling;
|
|
|
|
s2[i] *= scaling;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2010-04-19 14:09:41 +00:00
|
|
|
file << "# vtk DataFile Version 2.0" << endl;
|
|
|
|
file << "" << endl;
|
|
|
|
file << "ASCII" << endl;
|
|
|
|
file << "DATASET POLYDATA" << endl;
|
|
|
|
|
|
|
|
file << "POINTS 8 float" << endl;
|
|
|
|
file << s1[0] << " " << s1[1] << " " << s1[2] << endl;
|
|
|
|
file << s2[0] << " " << s1[1] << " " << s1[2] << endl;
|
|
|
|
file << s2[0] << " " << s2[1] << " " << s1[2] << endl;
|
|
|
|
file << s1[0] << " " << s2[1] << " " << s1[2] << endl;
|
|
|
|
file << s1[0] << " " << s1[1] << " " << s2[2] << endl;
|
|
|
|
file << s2[0] << " " << s1[1] << " " << s2[2] << endl;
|
|
|
|
file << s2[0] << " " << s2[1] << " " << s2[2] << endl;
|
|
|
|
file << s1[0] << " " << s2[1] << " " << s2[2] << endl;
|
|
|
|
|
|
|
|
file << "POLYGONS 6 30" << endl;
|
|
|
|
file << "4 0 1 2 3" << endl;
|
|
|
|
file << "4 4 5 6 7" << endl;
|
|
|
|
file << "4 7 6 2 3" << endl;
|
|
|
|
file << "4 4 5 1 0" << endl;
|
|
|
|
file << "4 0 4 7 3" << endl;
|
|
|
|
file << "4 5 6 2 1" << endl;
|
|
|
|
|
|
|
|
file.close();
|
|
|
|
}
|
2010-03-10 11:15:14 +00:00
|
|
|
|
|
|
|
void ProcessingArray::AddProcessing(Processing* proc)
|
|
|
|
{
|
|
|
|
ProcessArray.push_back(proc);
|
|
|
|
}
|
|
|
|
|
2011-02-16 09:11:39 +00:00
|
|
|
void ProcessingArray::InitAll()
|
|
|
|
{
|
|
|
|
for (size_t i=0; i<ProcessArray.size(); ++i)
|
|
|
|
{
|
|
|
|
ProcessArray.at(i)->InitProcess();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-06-28 16:05:03 +00:00
|
|
|
void ProcessingArray::FlushNext()
|
|
|
|
{
|
2010-12-06 12:04:37 +00:00
|
|
|
for (size_t i=0; i<ProcessArray.size(); ++i)
|
2010-06-28 16:05:03 +00:00
|
|
|
{
|
|
|
|
ProcessArray.at(i)->FlushNext();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-04-03 15:36:50 +00:00
|
|
|
void ProcessingArray::Reset()
|
|
|
|
{
|
2010-12-06 12:04:37 +00:00
|
|
|
for (size_t i=0; i<ProcessArray.size(); ++i)
|
2010-04-03 15:36:50 +00:00
|
|
|
{
|
|
|
|
ProcessArray.at(i)->Reset();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-03-10 11:15:14 +00:00
|
|
|
void ProcessingArray::DeleteAll()
|
|
|
|
{
|
2010-12-06 12:04:37 +00:00
|
|
|
for (size_t i=0; i<ProcessArray.size(); ++i)
|
2010-03-10 11:15:14 +00:00
|
|
|
{
|
|
|
|
delete ProcessArray.at(i);
|
|
|
|
}
|
|
|
|
ProcessArray.clear();
|
|
|
|
}
|
|
|
|
|
2010-12-17 14:13:43 +00:00
|
|
|
void ProcessingArray::PreProcess()
|
|
|
|
{
|
|
|
|
for (size_t i=0; i<ProcessArray.size(); ++i) ProcessArray.at(i)->PreProcess();
|
|
|
|
}
|
|
|
|
|
2010-03-10 11:15:14 +00:00
|
|
|
int ProcessingArray::Process()
|
|
|
|
{
|
2010-03-15 21:19:51 +00:00
|
|
|
int nextProcess=maxInterval;
|
2010-03-10 11:15:14 +00:00
|
|
|
//this could be done nicely in parallel??
|
2010-12-06 12:04:37 +00:00
|
|
|
for (size_t i=0; i<ProcessArray.size(); ++i)
|
2010-03-10 11:15:14 +00:00
|
|
|
{
|
|
|
|
int step = ProcessArray.at(i)->Process();
|
|
|
|
if ((step>0) && (step<nextProcess))
|
|
|
|
nextProcess=step;
|
|
|
|
}
|
|
|
|
return nextProcess;
|
|
|
|
}
|
2010-04-19 14:09:41 +00:00
|
|
|
|
2010-12-17 14:13:43 +00:00
|
|
|
void ProcessingArray::PostProcess()
|
|
|
|
{
|
|
|
|
for (size_t i=0; i<ProcessArray.size(); ++i) ProcessArray.at(i)->PostProcess();
|
|
|
|
}
|
|
|
|
|
2010-04-19 14:09:41 +00:00
|
|
|
void ProcessingArray::DumpBoxes2File( string vtkfilenameprefix ) const
|
|
|
|
{
|
2010-12-06 12:04:37 +00:00
|
|
|
for (size_t i=0; i<ProcessArray.size(); ++i)
|
2010-04-19 14:09:41 +00:00
|
|
|
ProcessArray.at(i)->DumpBox2File( vtkfilenameprefix );
|
|
|
|
}
|