default dump not-interpolated

pull/1/head
Thorsten Liebig 2010-03-09 21:35:57 +01:00
parent 9e86a96436
commit d31799e912
4 changed files with 143 additions and 31 deletions

View File

@ -4,10 +4,12 @@ ProcessFields::ProcessFields(Operator* op, Engine* eng) : Processing(op, eng)
{
DumpMode=0;
DumpType = 0;
// SetSubSampling(1);
for (int n=0;n<3;++n)
{
discDLines[n]=NULL;
discLines[n]=NULL;
}
}
@ -17,36 +19,79 @@ ProcessFields::~ProcessFields()
{
delete[] discDLines[n];
discDLines[n]=NULL;
delete[] discLines[n];
discLines[n]=NULL;
}
}
void ProcessFields::DefineStartStopCoord(double* dstart, double* dstop)
{
if (Op->SnapToMesh(dstart,start,true)==false) cerr << "ProcessFields::DefineStartStopCoord: Warning: Snapping problem, check start value!!" << endl;
if (Op->SnapToMesh(dstop,stop,true)==false) cerr << "ProcessFields::DefineStartStopCoord: Warning: Snapping problem, check stop value!!" << endl;
for (int n=0;n<3;++n)
if (DumpMode==0)
{
// cerr << "start " << start[n] << "stop " << stop[n];
if (start[n]>stop[n])
if (Op->SnapToMesh(dstart,start)==false) cerr << "ProcessFields::DefineStartStopCoord: Warning: Snapping problem, check start value!!" << endl;
if (Op->SnapToMesh(dstop,stop)==false) cerr << "ProcessFields::DefineStartStopCoord: Warning: Snapping problem, check stop value!!" << endl;
//create dual mesh
for (int n=0;n<3;++n)
{
unsigned int help = start[n];
start[n]=stop[n];
stop[n]=help;
// cerr << "start " << start[n] << "stop " << stop[n];
if (start[n]>stop[n])
{
unsigned int help = start[n];
start[n]=stop[n];
stop[n]=help;
}
numLines[n]=stop[n]-start[n]+1;
// cerr << " number of lines " << numDLines[n] << endl;
delete[] discLines[n];
discLines[n] = new double[numLines[n]];
for (unsigned int i=0;i<numLines[n];++i)
{
discLines[n][i] = Op->discLines[n][start[n]+i];
// cerr << n << " : " << discDLines[n][i] << endl;
}
}
++stop[n];
numDLines[n]=stop[n]-start[n];
// cerr << " number of lines " << numDLines[n] << endl;
delete[] discDLines[n];
discDLines[n] = new double[numDLines[n]];
for (unsigned int i=0;i<numDLines[n];++i)
}
else if (DumpMode==2)
{
if (Op->SnapToMesh(dstart,start,true)==false) cerr << "ProcessFields::DefineStartStopCoord: Warning: Snapping problem, check start value!!" << endl;
if (Op->SnapToMesh(dstop,stop,true)==false) cerr << "ProcessFields::DefineStartStopCoord: Warning: Snapping problem, check stop value!!" << endl;
//create dual mesh
for (int n=0;n<3;++n)
{
discDLines[n][i] = 0.5*(Op->discLines[n][start[n]+i+1] + Op->discLines[n][start[n]+i]);
// cerr << n << " : " << discDLines[n][i] << endl;
// cerr << "start " << start[n] << "stop " << stop[n];
if (start[n]>stop[n])
{
unsigned int help = start[n];
start[n]=stop[n];
stop[n]=help;
}
++stop[n];
numDLines[n]=stop[n]-start[n];
// cerr << " number of lines " << numDLines[n] << endl;
delete[] discDLines[n];
discDLines[n] = new double[numDLines[n]];
for (unsigned int i=0;i<numDLines[n];++i)
{
discDLines[n][i] = 0.5*(Op->discLines[n][start[n]+i+1] + Op->discLines[n][start[n]+i]);
// cerr << n << " : " << discDLines[n][i] << endl;
}
}
}
}
//void ProcessFields::SetSubSampling(unsigned int subSampleRate, int dir)
//{
// if (dir>2) return;
// if (dir<0)
// {
// subSample[0]=subSampleRate;
// subSample[1]=subSampleRate;
// subSample[2]=subSampleRate;
// }
// else subSample[dir]=subSampleRate;
//}
bool ProcessFields::DumpFieldArray2VTK(ofstream &file, string name, FDTD_FLOAT**** array, double** discLines, unsigned int* numLines)
{
file << "# vtk DataFile Version 2.0" << endl;

View File

@ -11,11 +11,13 @@ public:
virtual void DefineStartStopCoord(double* dstart, double* dstop);
// virtual void SetSubSampling(unsigned int subSampleRate, int dir=-1);
//! Used file pattern e.g. pattern="tmp/efield_" --> "tmp/efield_000045.vtk" for timestep 45 or "tmp/efield_2.40000e9.vtk" for 2.4GHz E-field dump.
void SetFilePattern(string fp) {filePattern=fp;}
//! This methode will dump all fields in the center of a main cell (dual-node) using 4 E-field and 2 H-fields per direction. (default)
void SetDumpMode2Cell() {DumpMode=0;}
void SetDumpMode2Cell() {DumpMode=2;}
//! Set dump type: 0 for E-fields, 1 for H-fields, 2 for D-fields, 3 for B-fields, 4 for J-fields, etc...
void SetDumpType(int type) {DumpType=type;}
@ -30,6 +32,12 @@ protected:
int DumpType;
string filePattern;
// unsigned int subSample[3];
//! dump mesh
unsigned int numLines[3];
double* discLines[3];
//! dual dump mesh
unsigned int numDLines[3];
double* discDLines[3];
};

View File

@ -12,18 +12,9 @@ ProcessFieldsTD::~ProcessFieldsTD()
{
}
void ProcessFieldsTD::Process()
void ProcessFieldsTD::DumpCellInterpol(ofstream &file)
{
if (Enabled==false) return;
if (filePattern.empty()) return;
stringstream ss;
ss << std::setw( pad_length ) << std::setfill( '0' ) << Eng->numTS;
string filename = filePattern + ss.str() + ".vtk";
ofstream file(filename.c_str());
if (file.is_open()==false) { cerr << "ProcessFieldsTD::Process: can't open file '" << filename << "' for writing... abort! " << endl; return;};
if (DumpType==0)
if (DumpType==0)
{
//create array
FDTD_FLOAT**** E_T = Create_N_3DArray(numDLines);
@ -84,11 +75,11 @@ void ProcessFieldsTD::Process()
H_T[0][pos[0]][pos[1]][pos[2]] /= (2*delta*Op->gridDelta);
//in y
delta = Op->discLines[1][OpPos[1]+1] - Op->discLines[1][OpPos[1]];
H_T[1][pos[0]][pos[1]][pos[2]] = Eng->curr[0][OpPos[0]][OpPos[1]][OpPos[2]] + Eng->curr[0][OpPos[0]][OpPos[1]+1][OpPos[2]];
H_T[1][pos[0]][pos[1]][pos[2]] = Eng->curr[1][OpPos[0]][OpPos[1]][OpPos[2]] + Eng->curr[1][OpPos[0]][OpPos[1]+1][OpPos[2]];
H_T[1][pos[0]][pos[1]][pos[2]] /= (2*delta*Op->gridDelta);
//in z
delta = Op->discLines[2][OpPos[2]+1] - Op->discLines[2][OpPos[2]];
H_T[2][pos[0]][pos[1]][pos[2]] = Eng->curr[0][OpPos[0]][OpPos[1]][OpPos[2]] + Eng->curr[0][OpPos[0]][OpPos[1]][OpPos[2]+1];
H_T[2][pos[0]][pos[1]][pos[2]] = Eng->curr[2][OpPos[0]][OpPos[1]][OpPos[2]] + Eng->curr[2][OpPos[0]][OpPos[1]][OpPos[2]+1];
H_T[2][pos[0]][pos[1]][pos[2]] /= (2*delta*Op->gridDelta);
}
}
@ -97,5 +88,70 @@ void ProcessFieldsTD::Process()
Delete_N_3DArray(H_T,numDLines);
H_T = NULL;
}
}
void ProcessFieldsTD::DumpNoInterpol(ofstream &file)
{
if (DumpType==0)
{
//create array
FDTD_FLOAT**** E_T = Create_N_3DArray(numLines);
unsigned int pos[3];
for (pos[0]=0;pos[0]<numLines[0];++pos[0])
{
for (pos[1]=0;pos[1]<numLines[1];++pos[1])
{
for (pos[2]=0;pos[2]<numLines[2];++pos[2])
{
E_T[0][pos[0]][pos[1]][pos[2]] = Eng->volt[0][pos[0]+start[0]][pos[1]+start[1]][pos[2]+start[2]];
E_T[1][pos[0]][pos[1]][pos[2]] = Eng->volt[1][pos[0]+start[0]][pos[1]+start[1]][pos[2]+start[2]];
E_T[2][pos[0]][pos[1]][pos[2]] = Eng->volt[2][pos[0]+start[0]][pos[1]+start[1]][pos[2]+start[2]];
}
}
}
DumpFieldArray2VTK(file,string("E-Field"),E_T,discLines,numLines);
Delete_N_3DArray(E_T,numLines);
E_T = NULL;
}
if (DumpType==1)
{
//create array
FDTD_FLOAT**** H_T = Create_N_3DArray(numLines);
unsigned int pos[3] = {start[0],start[1],start[2]};
for (pos[0]=0;pos[0]<numLines[0];++pos[0])
{
for (pos[1]=0;pos[1]<numLines[1];++pos[1])
{
for (pos[2]=0;pos[2]<numLines[2];++pos[2])
{
//in x
H_T[0][pos[0]][pos[1]][pos[2]] = Eng->curr[0][pos[0]+start[0]][pos[1]+start[1]][pos[2]+start[2]];
H_T[1][pos[0]][pos[1]][pos[2]] = Eng->curr[1][pos[0]+start[0]][pos[1]+start[1]][pos[2]+start[2]];
H_T[2][pos[0]][pos[1]][pos[2]] = Eng->curr[2][pos[0]+start[0]][pos[1]+start[1]][pos[2]+start[2]];
}
}
}
DumpFieldArray2VTK(file,string("H-Field"),H_T,discLines,numLines);
Delete_N_3DArray(H_T,numLines);
H_T = NULL;
}
}
void ProcessFieldsTD::Process()
{
if (Enabled==false) return;
if (filePattern.empty()) return;
stringstream ss;
ss << std::setw( pad_length ) << std::setfill( '0' ) << Eng->numTS;
string filename = filePattern + ss.str() + ".vtk";
ofstream file(filename.c_str());
if (file.is_open()==false) { cerr << "ProcessFieldsTD::Process: can't open file '" << filename << "' for writing... abort! " << endl; return;};
if (DumpMode==0)
DumpNoInterpol(file);
if (DumpMode==2)
DumpCellInterpol(file);
file.close();
}

View File

@ -16,6 +16,9 @@ public:
protected:
int pad_length;
void DumpNoInterpol(ofstream &file);
void DumpCellInterpol(ofstream &file);
};
#endif // PROCESSFIELDS_TD_H