Supporting sub-sampled dumps

pull/1/head
Thorsten Liebig 2010-04-07 12:57:45 +02:00
parent fc41909810
commit 52f5764976
9 changed files with 72 additions and 57 deletions

View File

@ -25,7 +25,7 @@ ProcessFields::ProcessFields(Operator* op, Engine* eng) : Processing(op, eng)
m_DumpType = E_FIELD_DUMP;
// vtk-file is default
m_fileType = VTK_FILETYPE;
// SetSubSampling(1);
SetSubSampling(1);
for (int n=0;n<3;++n)
{
@ -107,6 +107,7 @@ string ProcessFields::GetFieldNameByType(DumpType type)
void ProcessFields::DefineStartStopCoord(double* dstart, double* dstop)
{
vector<double> lines;
if (m_DumpMode==NO_INTERPOLATION)
{
if (Op->SnapToMesh(dstart,start)==false) cerr << "ProcessFields::DefineStartStopCoord: Warning: Snapping problem, check start value!!" << endl;
@ -121,15 +122,16 @@ void ProcessFields::DefineStartStopCoord(double* dstart, double* dstop)
start[n]=stop[n];
stop[n]=help;
}
numLines[n]=stop[n]-start[n]+1;
// cerr << " number of lines " << numDLines[n] << endl;
lines.clear();
for (unsigned int i=start[n];i<=stop[n];i+=subSample[n])
{
lines.push_back(Op->discLines[n][i]);
}
numLines[n] = lines.size();
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;
}
discLines[n][i] = lines.at(i);
}
}
else if (m_DumpMode==CELL_INTERPOLATE)
@ -148,15 +150,16 @@ void ProcessFields::DefineStartStopCoord(double* dstart, double* dstop)
stop[n]=help;
}
++stop[n];
numDLines[n]=stop[n]-start[n];
// cerr << " number of lines " << numDLines[n] << endl;
lines.clear();
for (unsigned int i=start[n];i<stop[n];i+=subSample[n])
{
lines.push_back(0.5*(Op->discLines[n][i+1] + Op->discLines[n][i]));
}
numDLines[n] = lines.size();
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;
}
discDLines[n][i] = lines.at(i);
}
}
}
@ -187,17 +190,17 @@ double ProcessFields::CalcTotalEnergy()
return energy*0.5;
}
//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;
//}
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;
}
void ProcessFields::WriteVTKHeader(ofstream &file, double** discLines, unsigned int* numLines)
{

View File

@ -35,7 +35,8 @@ public:
virtual void DefineStartStopCoord(double* dstart, double* dstop);
// virtual void SetSubSampling(unsigned int subSampleRate, int dir=-1);
//! Define a field dump sub sampling rate for a given direction (default: dir = -1 means all directions)
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. (VTK FileType only) \sa SetFileType
void SetFilePattern(string fp) {filePattern=fp;}
@ -75,7 +76,8 @@ protected:
string m_fileName;
FileType m_fileType;
// unsigned int subSample[3];
//! field dump sub-sampling
unsigned int subSample[3];
//! dump mesh
unsigned int numLines[3];

View File

@ -44,13 +44,13 @@ void ProcessFieldsTD::DumpCellInterpol(string filename)
// cerr << "processing e-fields... " << endl;
for (pos[0]=0;pos[0]<numDLines[0];++pos[0])
{
OpPos[0]=start[0]+pos[0];
OpPos[0]=start[0]+pos[0]*subSample[0];
for (pos[1]=0;pos[1]<numDLines[1];++pos[1])
{
OpPos[1]=start[1]+pos[1];
OpPos[1]=start[1]+pos[1]*subSample[0];
for (pos[2]=0;pos[2]<numDLines[2];++pos[2])
{
OpPos[2]=start[2]+pos[2];
OpPos[2]=start[2]+pos[2]*subSample[0];
//in x
delta = Op->discLines[0][OpPos[0]+1] - Op->discLines[0][OpPos[0]];
E_T[0][pos[0]][pos[1]][pos[2]] = volt[0][OpPos[0]][OpPos[1]][OpPos[2]] + volt[0][OpPos[0]][OpPos[1]+1][OpPos[2]] + volt[0][OpPos[0]][OpPos[1]][OpPos[2]+1] + volt[0][OpPos[0]][OpPos[1]+1][OpPos[2]+1];
@ -96,13 +96,13 @@ void ProcessFieldsTD::DumpCellInterpol(string filename)
// cerr << "processing h-fields... " << endl;
for (pos[0]=0;pos[0]<numDLines[0];++pos[0])
{
OpPos[0]=start[0]+pos[0];
OpPos[0]=start[0]+pos[0]*subSample[0];
for (pos[1]=0;pos[1]<numDLines[1];++pos[1])
{
OpPos[1]=start[1]+pos[1];
OpPos[1]=start[1]+pos[1]*subSample[1];
for (pos[2]=0;pos[2]<numDLines[2];++pos[2])
{
OpPos[2]=start[2]+pos[2];
OpPos[2]=start[2]+pos[2]*subSample[2];
//in x
if (OpPos[0]==0) delta = Op->discLines[0][OpPos[0]+1] - Op->discLines[0][OpPos[0]];
else delta = 0.5* (Op->discLines[0][OpPos[0]+1] - Op->discLines[0][OpPos[0]-1]);
@ -145,6 +145,7 @@ void ProcessFieldsTD::DumpNoInterpol(string filename)
FDTD_FLOAT**** curr = Eng->GetCurrents();
unsigned int pos[3];
unsigned int OpPos[3];
double delta[3];
if (m_DumpType==E_FIELD_DUMP)
{
@ -152,16 +153,19 @@ void ProcessFieldsTD::DumpNoInterpol(string filename)
FDTD_FLOAT**** E_T = Create_N_3DArray(numLines);
for (pos[0]=0;pos[0]<numLines[0];++pos[0])
{
delta[0]=fabs(Op->MainOp->GetIndexDelta(0,pos[0]+start[0]));
OpPos[0]=start[0]+pos[0]*subSample[0];
delta[0]=fabs(Op->MainOp->GetIndexDelta(0,OpPos[0]));
for (pos[1]=0;pos[1]<numLines[1];++pos[1])
{
delta[1]=fabs(Op->MainOp->GetIndexDelta(1,pos[1]+start[1]));
OpPos[1]=start[1]+pos[1]*subSample[1];
delta[1]=fabs(Op->MainOp->GetIndexDelta(1,OpPos[1]));
for (pos[2]=0;pos[2]<numLines[2];++pos[2])
{
delta[2]=fabs(Op->MainOp->GetIndexDelta(2,pos[2]+start[2]));
E_T[0][pos[0]][pos[1]][pos[2]] = volt[0][pos[0]+start[0]][pos[1]+start[1]][pos[2]+start[2]]/delta[0]/Op->gridDelta;
E_T[1][pos[0]][pos[1]][pos[2]] = volt[1][pos[0]+start[0]][pos[1]+start[1]][pos[2]+start[2]]/delta[1]/Op->gridDelta;
E_T[2][pos[0]][pos[1]][pos[2]] = volt[2][pos[0]+start[0]][pos[1]+start[1]][pos[2]+start[2]]/delta[2]/Op->gridDelta;
OpPos[2]=start[2]+pos[2]*subSample[2];
delta[2]=fabs(Op->MainOp->GetIndexDelta(2,OpPos[2]));
E_T[0][pos[0]][pos[1]][pos[2]] = volt[0][OpPos[0]][OpPos[1]][OpPos[2]]/delta[0]/Op->gridDelta;
E_T[1][pos[0]][pos[1]][pos[2]] = volt[1][OpPos[0]][OpPos[1]][OpPos[2]]/delta[1]/Op->gridDelta;
E_T[2][pos[0]][pos[1]][pos[2]] = volt[2][OpPos[0]][OpPos[1]][OpPos[2]]/delta[2]/Op->gridDelta;
}
}
}
@ -191,17 +195,20 @@ void ProcessFieldsTD::DumpNoInterpol(string filename)
FDTD_FLOAT**** H_T = Create_N_3DArray(numLines);
for (pos[0]=0;pos[0]<numLines[0];++pos[0])
{
delta[0]=fabs(Op->MainOp->GetIndexWidth(0,pos[0]+start[0]));
OpPos[0]=start[0]+pos[0]*subSample[0];
delta[0]=fabs(Op->MainOp->GetIndexWidth(0,OpPos[0]));
for (pos[1]=0;pos[1]<numLines[1];++pos[1])
{
delta[1]=fabs(Op->MainOp->GetIndexWidth(1,pos[1]+start[1]));
OpPos[1]=start[1]+pos[1]*subSample[1];
delta[1]=fabs(Op->MainOp->GetIndexWidth(1,OpPos[1]));
for (pos[2]=0;pos[2]<numLines[2];++pos[2])
{
delta[2]=fabs(Op->MainOp->GetIndexWidth(2,pos[2]+start[2]));
OpPos[2]=start[2]+pos[2]*subSample[2];
delta[2]=fabs(Op->MainOp->GetIndexWidth(2,OpPos[2]));
//in x
H_T[0][pos[0]][pos[1]][pos[2]] = curr[0][pos[0]+start[0]][pos[1]+start[1]][pos[2]+start[2]]/delta[0]/Op->gridDelta;
H_T[1][pos[0]][pos[1]][pos[2]] = curr[1][pos[0]+start[0]][pos[1]+start[1]][pos[2]+start[2]]/delta[1]/Op->gridDelta;
H_T[2][pos[0]][pos[1]][pos[2]] = curr[2][pos[0]+start[0]][pos[1]+start[1]][pos[2]+start[2]]/delta[2]/Op->gridDelta;
H_T[0][pos[0]][pos[1]][pos[2]] = curr[0][OpPos[0]][OpPos[1]][OpPos[2]]/delta[0]/Op->gridDelta;
H_T[1][pos[0]][pos[1]][pos[2]] = curr[1][OpPos[0]][OpPos[1]][OpPos[2]]/delta[1]/Op->gridDelta;
H_T[2][pos[0]][pos[1]][pos[2]] = curr[2][OpPos[0]][OpPos[1]][OpPos[2]]/delta[2]/Op->gridDelta;
}
}
}

View File

@ -63,12 +63,12 @@ CSX = SetExcitationWeight(CSX, 'excite', weight );
CSX = AddCylindricalShell(CSX,'excite',0 ,start,stop,0.5*(coax_rad_i+coax_rad_ai),(coax_rad_ai-coax_rad_i));
%dump
CSX = AddDump(CSX,'Et_',0,2);
CSX = AddDump(CSX,'Et_','DumpMode',2);
start = [mesh.x(1) , 0 , mesh.z(1)];
stop = [mesh.x(end) , 0 , mesh.z(end)];
CSX = AddBox(CSX,'Et_',0 , start,stop);
CSX = AddDump(CSX,'Ht_',1,2);
CSX = AddDump(CSX,'Ht_','DumpType',1,'DumpMode',2);
CSX = AddBox(CSX,'Ht_',0,start,stop);
%voltage calc

View File

@ -102,12 +102,12 @@ stop(1) = stop(1)+2;stop(2) = stop(2)+2;
CSX = AddBox(CSX,'it1', 0 ,start,stop);
%dump
CSX = AddDump(CSX,'Et_',0,0);
CSX = AddDump(CSX,'Et_');
start = [mesh.x(1) , 0 , mesh.z(1)];
stop = [mesh.x(end) , 0 , mesh.z(end)];
CSX = AddBox(CSX,'Et_',0 , start,stop);
CSX = AddDump(CSX,'Ht_',1,0);
CSX = AddDump(CSX,'Ht_','DumpType',1);
start = [mesh.x(1) , 0 , mesh.z(1)];
stop = [mesh.x(end) , 0 , mesh.z(end)];
CSX = AddBox(CSX,'Ht_',0 , start,stop);

View File

@ -59,12 +59,12 @@ stop = [mesh.x(end) mesh.y(end) length];
CSX = AddBox(CSX,'pml',0 ,start,stop);
%dump
CSX = AddDump(CSX,'Et_',0,2);
CSX = AddDump(CSX,'Et_','DumpMode',2);
start = [mesh.x(1) , MSL_height/2 , mesh.z(1)];
stop = [mesh.x(end) , MSL_height/2 , mesh.z(end)];
CSX = AddBox(CSX,'Et_',0 , start,stop);
CSX = AddDump(CSX,'Ht_',1,2);
CSX = AddDump(CSX,'Ht_','DumpType',1,'DumpMode',2);
CSX = AddBox(CSX,'Ht_',0,start,stop);
%voltage calc

View File

@ -15,6 +15,7 @@ openEMS_Path = [pwd() '/../../']
openEMS_opts = '';
% openEMS_opts = [openEMS_opts ' --disable-dumps'];
% openEMS_opts = [openEMS_opts ' --debug-material'];
openEMS_opts = [openEMS_opts ' --engine=multithreaded'];
Sim_Path = 'tmp';
Sim_CSX = 'plane_wave.xml';
@ -53,12 +54,12 @@ CSX = AddExcitation(CSX,'excite',0,[0 1 0]);
CSX = AddBox(CSX,'excite',0 ,start,stop);
%dump
CSX = AddDump(CSX,'Et',0,0,1);
CSX = AddDump(CSX,'Et','FileType',1);
start = [mesh.x(1) , 0 , mesh.z(1)];
stop = [mesh.x(end) , 0 , mesh.z(end)];
CSX = AddBox(CSX,'Et',0 , start,stop);
CSX = AddDump(CSX,'Ht',1,0,1);
CSX = AddDump(CSX,'Ht','DumpType',1,'FileType',1);
CSX = AddBox(CSX,'Ht',0,start,stop);
%Write openEMS compatoble xml-file
@ -75,8 +76,8 @@ cd(savePath);
% plotting
PlotArgs.plane='zx';
PlotArgs.pauseTime=0.01;
PlotArgs.component=1;
PlotArgs.component=2;
PlotArgs.zlim='auto';
PlotHDF5FieldData('tmp/Ht_.h5',PlotArgs)
PlotHDF5FieldData('tmp/Et.h5',PlotArgs)

View File

@ -23,7 +23,7 @@ f0 = 1e9;
k = 2*pi*f0/C0;
kc = sqrt((m*pi/a/unit)^2 + (n*pi/b/unit)^2);
fc = C0*kc;
fc = C0*kc/2/pi
beta = sqrt(k^2 - kc^2);
func_Ex = [num2str(n/b/unit) '*cos(' num2str(m*pi/a) '*x)*sin(' num2str(n*pi/b) '*y)'];
@ -79,12 +79,12 @@ CSX = SetExcitationWeight(CSX,'excite',weight);
CSX = AddBox(CSX,'excite',0 ,start,stop);
%dump
CSX = AddDump(CSX,'Et',0,0,1);
CSX = AddDump(CSX,'Et','FileType',1);
start = [mesh.x(1) , height/2 , mesh.z(1)];
stop = [mesh.x(end) , height/2 , mesh.z(end)];
CSX = AddBox(CSX,'Et',0 , start,stop);
CSX = AddDump(CSX,'Ht',1,0,1);
CSX = AddDump(CSX,'Ht','DumpType',1,'FileType',1);
CSX = AddBox(CSX,'Ht',0,start,stop);
%Write openEMS compatoble xml-file

View File

@ -349,6 +349,8 @@ int openEMS::SetupFDTD(const char* file)
ProcTD->SetDumpType((ProcessFields::DumpType)db->GetDumpType());
ProcTD->SetDumpMode((ProcessFields::DumpMode)db->GetDumpMode());
ProcTD->SetFileType((ProcessFields::FileType)db->GetFileType());
for (int n=0;n<3;++n)
ProcTD->SetSubSampling(db->GetSubSampling(n),n);
ProcTD->SetFilePattern(db->GetName());
ProcTD->SetFileName(db->GetName());
ProcTD->DefineStartStopCoord(start,stop);