2010-03-01 18:35:28 +00:00
|
|
|
#include <fstream>
|
2010-03-01 08:19:39 +00:00
|
|
|
#include "operator.h"
|
2010-03-01 13:56:27 +00:00
|
|
|
#include "tools/array_ops.h"
|
2010-03-01 08:19:39 +00:00
|
|
|
|
|
|
|
Operator::Operator()
|
|
|
|
{
|
|
|
|
Operator::Init();
|
|
|
|
}
|
|
|
|
|
|
|
|
Operator::~Operator()
|
|
|
|
{
|
|
|
|
Operator::Reset();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Operator::Init()
|
|
|
|
{
|
|
|
|
CSX = NULL;
|
|
|
|
|
2010-03-01 13:56:27 +00:00
|
|
|
ExciteSignal = NULL;
|
2010-03-01 08:19:39 +00:00
|
|
|
E_Ex_delay = NULL;
|
2010-03-01 13:56:27 +00:00
|
|
|
vv=NULL;
|
|
|
|
vi=NULL;
|
|
|
|
iv=NULL;
|
|
|
|
ii=NULL;
|
2010-03-01 08:19:39 +00:00
|
|
|
for (int n=0;n<3;++n)
|
|
|
|
{
|
|
|
|
discLines[n]=NULL;
|
|
|
|
E_Ex_amp[n]=NULL;
|
2010-03-01 13:56:27 +00:00
|
|
|
E_Ex_index[n]=NULL;
|
2010-03-01 08:19:39 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Operator::Reset()
|
|
|
|
{
|
2010-03-01 13:56:27 +00:00
|
|
|
delete[] ExciteSignal;
|
2010-03-01 08:19:39 +00:00
|
|
|
delete[] E_Ex_delay;
|
2010-03-01 13:56:27 +00:00
|
|
|
Delete_N_3DArray(vv,numLines);
|
|
|
|
Delete_N_3DArray(vi,numLines);
|
|
|
|
Delete_N_3DArray(iv,numLines);
|
|
|
|
Delete_N_3DArray(ii,numLines);
|
2010-03-01 08:19:39 +00:00
|
|
|
for (int n=0;n<3;++n)
|
|
|
|
{
|
2010-03-01 13:56:27 +00:00
|
|
|
delete[] discLines[n];
|
2010-03-01 08:19:39 +00:00
|
|
|
delete[] E_Ex_amp[n];
|
2010-03-01 13:56:27 +00:00
|
|
|
delete[] E_Ex_index[n];
|
2010-03-01 08:19:39 +00:00
|
|
|
}
|
|
|
|
Operator::Init();
|
|
|
|
}
|
|
|
|
|
2010-03-01 18:35:28 +00:00
|
|
|
unsigned int Operator::GetNyquistNum(double fmax)
|
|
|
|
{
|
|
|
|
if (dT==0) return 1;
|
|
|
|
double T0 = 1/fmax;
|
|
|
|
return floor(T0/2/dT);
|
|
|
|
}
|
|
|
|
|
2010-03-02 13:54:50 +00:00
|
|
|
bool Operator::SnapToMesh(double* dcoord, unsigned int* uicoord, bool lower)
|
2010-03-01 18:35:28 +00:00
|
|
|
{
|
|
|
|
bool ok=true;
|
|
|
|
for (int n=0;n<3;++n)
|
|
|
|
{
|
2010-03-02 13:54:50 +00:00
|
|
|
uicoord[n]=0;
|
|
|
|
if (dcoord[n]<discLines[n][0]) {ok=false;uicoord[n]=0;}
|
|
|
|
else if (dcoord[n]==discLines[n][0]) {uicoord[n]=0;}
|
|
|
|
else if (dcoord[n]>discLines[n][numLines[n]-1]) {ok=false;uicoord[n]=numLines[n]-1; if (lower) uicoord[n]=numLines[n]-2;}
|
|
|
|
else if (dcoord[n]==discLines[n][numLines[n]-1]) {uicoord[n]=numLines[n]-1; if (lower) uicoord[n]=numLines[n]-2;}
|
|
|
|
else
|
|
|
|
for (unsigned int i=0;i<numLines[n]-1;++i)
|
2010-03-01 18:35:28 +00:00
|
|
|
{
|
2010-03-02 13:54:50 +00:00
|
|
|
if (dcoord[n]<=discLines[n][i])
|
|
|
|
{
|
|
|
|
if (fabs(dcoord[n]-discLines[n][i])<(fabs(dcoord[n]-discLines[n][i+1])))
|
|
|
|
uicoord[n]=i;
|
|
|
|
else
|
|
|
|
uicoord[n]=i+1;
|
|
|
|
if (lower) uicoord[n]=i;
|
|
|
|
i = numLines[n];
|
|
|
|
}
|
2010-03-01 18:35:28 +00:00
|
|
|
}
|
|
|
|
}
|
2010-03-02 13:54:50 +00:00
|
|
|
// cerr << "Operator::SnapToMesh Wish: " << dcoord[0] << " " << dcoord[1] << " " << dcoord[2] << endl;
|
|
|
|
// cerr << "Operator::SnapToMesh Found: " << discLines[0][uicoord[0]] << " " << discLines[1][uicoord[1]] << " " << discLines[2][uicoord[2]] << endl;
|
|
|
|
// cerr << "Operator::SnapToMesh Index: " << uicoord[0] << " " << uicoord[1] << " " << uicoord[2] << endl;
|
2010-03-01 18:35:28 +00:00
|
|
|
return ok;
|
|
|
|
}
|
|
|
|
|
2010-03-01 08:19:39 +00:00
|
|
|
void Operator::SetGeometryCSX(ContinuousStructure* geo)
|
|
|
|
{
|
|
|
|
if (geo==NULL) return;
|
|
|
|
|
|
|
|
Reset();
|
|
|
|
CSX = geo;
|
|
|
|
}
|
2010-03-01 13:56:27 +00:00
|
|
|
|
|
|
|
double Operator::GetNumberCells()
|
|
|
|
{
|
|
|
|
if (numLines)
|
|
|
|
return (numLines[0]-1)*(numLines[1]-1)*(numLines[2]-1);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Operator::ShowSize()
|
|
|
|
{
|
|
|
|
unsigned int OpSize = 12*numLines[0]*numLines[1]*numLines[2]*sizeof(FDTD_FLOAT);
|
|
|
|
unsigned int FieldSize = 6*numLines[0]*numLines[1]*numLines[2]*sizeof(FDTD_FLOAT);
|
|
|
|
double MBdiff = 1024*1024;
|
|
|
|
|
2010-03-02 13:54:50 +00:00
|
|
|
cout << "---- Stat: FDTD Operator ----" << endl;
|
|
|
|
cout << "Size of Operator : " << OpSize << " Byte (" << (double)OpSize/MBdiff << " MB) " << endl;
|
|
|
|
cout << "Size of Field-Data: " << FieldSize << " Byte (" << (double)FieldSize/MBdiff << " MB) " << endl;
|
2010-03-01 13:56:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Operator::CalcGaussianPulsExcitation(double f0, double fc)
|
|
|
|
{
|
|
|
|
if (dT==0) return;
|
|
|
|
|
|
|
|
ExciteLength = (unsigned int)(2.0 * 9.0/(2.0*PI*fc) / dT);
|
|
|
|
cerr << "Operator::CalcGaussianPulsExcitation: Length of the excite signal: " << ExciteLength << " timesteps" << endl;
|
|
|
|
delete[] ExciteSignal;
|
|
|
|
ExciteSignal = new FDTD_FLOAT[ExciteLength+1];
|
|
|
|
ExciteSignal[0]=0.0;
|
|
|
|
for (unsigned int n=1;n<ExciteLength+1;++n)
|
|
|
|
{
|
|
|
|
ExciteSignal[n] = cos(2.0*PI*f0*(n*dT-9.0/(2.0*PI*fc)))*exp(-1*pow(2.0*PI*fc*n*dT/3.0-3,2));
|
|
|
|
// cerr << ExciteSignal[n] << endl;
|
|
|
|
}
|
|
|
|
}
|
2010-03-01 18:35:28 +00:00
|
|
|
|
|
|
|
void Operator::DumpOperator2File(string filename)
|
|
|
|
{
|
|
|
|
ofstream file(filename.c_str(),ios_base::out);
|
|
|
|
// file.open;
|
|
|
|
if (file.is_open()==false)
|
|
|
|
{
|
|
|
|
cerr << "Operator::DumpOperator2File: Can't open file: " << filename << endl;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
file << "########### Operator vv ###########" << endl;
|
|
|
|
file << "ix\tiy\tiz\tvv_x\tvv_y\tvv_z" << endl;
|
|
|
|
Dump_N_3DArray2File(file,vv,numLines);
|
|
|
|
|
|
|
|
file << "########### Operator vi ###########" << endl;
|
|
|
|
file << "ix\tiy\tiz\tvi_x\tvi_y\tvi_z" << endl;
|
|
|
|
Dump_N_3DArray2File(file,vi,numLines);
|
|
|
|
|
|
|
|
file << "########### Operator iv ###########" << endl;
|
|
|
|
file << "ix\tiy\tiz\tiv_x\tiv_y\tiv_z" << endl;
|
|
|
|
Dump_N_3DArray2File(file,iv,numLines);
|
|
|
|
|
|
|
|
file << "########### Operator ii ###########" << endl;
|
|
|
|
file << "ix\tiy\tiz\tii_x\tii_y\tii_z" << endl;
|
|
|
|
Dump_N_3DArray2File(file,ii,numLines);
|
|
|
|
|
|
|
|
file.close();
|
|
|
|
}
|