2010-02-28 21:48:03 +00:00
|
|
|
#include <iostream>
|
2010-03-01 18:35:28 +00:00
|
|
|
#include <fstream>
|
|
|
|
#include <sstream>
|
2010-02-28 21:48:03 +00:00
|
|
|
#include <time.h>
|
2010-03-01 18:35:28 +00:00
|
|
|
#include "tools/array_ops.h"
|
2010-03-05 13:20:25 +00:00
|
|
|
#include "FDTD/operator.h"
|
2010-03-01 13:56:27 +00:00
|
|
|
#include "FDTD/engine.h"
|
2010-03-01 18:35:28 +00:00
|
|
|
#include "FDTD/processvoltage.h"
|
2010-03-04 10:53:58 +00:00
|
|
|
#include "FDTD/processcurrent.h"
|
2010-03-02 13:54:50 +00:00
|
|
|
#include "FDTD/processfields_td.h"
|
2010-03-01 13:56:27 +00:00
|
|
|
|
2010-02-28 21:48:03 +00:00
|
|
|
#include "ContinuousStructure.h"
|
|
|
|
|
|
|
|
using namespace std;
|
|
|
|
|
2010-02-28 22:42:10 +00:00
|
|
|
void BuildMSL(ContinuousStructure &CSX);
|
2010-03-01 19:50:42 +00:00
|
|
|
void BuildDipol(ContinuousStructure &CSX);
|
2010-03-02 18:01:03 +00:00
|
|
|
void BuildPlaneWave(ContinuousStructure &CSX);
|
2010-02-28 22:42:10 +00:00
|
|
|
|
2010-02-28 21:48:03 +00:00
|
|
|
int main(int argc, char *argv[])
|
|
|
|
{
|
|
|
|
time_t startTime=time(NULL);
|
|
|
|
|
2010-03-01 18:35:28 +00:00
|
|
|
//*************** setup/read geometry ************//
|
2010-03-04 10:53:58 +00:00
|
|
|
cerr << "Create Geometry..." << endl;
|
2010-03-01 18:35:28 +00:00
|
|
|
ContinuousStructure CSX;
|
2010-03-02 21:55:50 +00:00
|
|
|
|
2010-03-04 10:53:58 +00:00
|
|
|
//BuildPlaneWave(CSX);
|
|
|
|
BuildMSL(CSX);
|
2010-02-28 21:48:03 +00:00
|
|
|
|
2010-03-01 18:35:28 +00:00
|
|
|
//*************** setup operator ************//
|
2010-03-04 10:53:58 +00:00
|
|
|
cerr << "Create Operator..." << endl;
|
2010-03-05 13:20:25 +00:00
|
|
|
Operator cop;
|
2010-02-28 21:48:03 +00:00
|
|
|
cop.SetGeometryCSX(&CSX);
|
|
|
|
|
|
|
|
cop.CalcECOperator();
|
|
|
|
|
2010-03-01 18:35:28 +00:00
|
|
|
double fmax=1e9;
|
2010-03-04 10:53:58 +00:00
|
|
|
cop.CalcGaussianPulsExcitation(fmax/2,fmax/2);
|
2010-03-01 13:56:27 +00:00
|
|
|
|
2010-02-28 21:48:03 +00:00
|
|
|
time_t OpDoneTime=time(NULL);
|
|
|
|
|
2010-03-01 13:56:27 +00:00
|
|
|
cop.ShowSize();
|
2010-03-04 10:53:58 +00:00
|
|
|
bool bnd[] = {1,1,0,1,0,1};
|
2010-03-02 18:01:03 +00:00
|
|
|
cop.ApplyMagneticBC(bnd);
|
2010-03-01 13:56:27 +00:00
|
|
|
|
2010-03-01 18:35:28 +00:00
|
|
|
cerr << "Nyquist number of timesteps: " << cop.GetNyquistNum(fmax) << endl;
|
2010-03-01 19:50:42 +00:00
|
|
|
unsigned int NrIter = cop.GetNyquistNum(fmax)/3;
|
2010-03-01 18:35:28 +00:00
|
|
|
|
2010-02-28 21:48:03 +00:00
|
|
|
cerr << "Time for operator: " << difftime(OpDoneTime,startTime) << endl;
|
|
|
|
|
2010-03-01 18:35:28 +00:00
|
|
|
//create FDTD engine
|
2010-03-01 13:56:27 +00:00
|
|
|
Engine eng(&cop);
|
|
|
|
|
|
|
|
time_t currTime = time(NULL);
|
|
|
|
|
2010-03-01 18:35:28 +00:00
|
|
|
//*************** setup processing ************//
|
|
|
|
ProcessVoltage PV(&cop,&eng);
|
|
|
|
PV.OpenFile("tmp/u1");
|
2010-03-04 10:53:58 +00:00
|
|
|
double start[]={0,50,0};
|
|
|
|
double stop[]={0,0,0};
|
2010-03-01 18:35:28 +00:00
|
|
|
PV.DefineStartStopCoord(start,stop);
|
2010-03-04 10:53:58 +00:00
|
|
|
|
|
|
|
ProcessCurrent PCurr(&cop,&eng);
|
|
|
|
PCurr.OpenFile("tmp/i1");
|
|
|
|
start[0]=-50;start[1]=40;start[2]=-0;
|
|
|
|
stop[0]=50;stop[1]=60;stop[2]=-0;
|
|
|
|
PCurr.DefineStartStopCoord(start,stop);
|
|
|
|
|
|
|
|
unsigned int maxIter = 1800;
|
2010-03-01 18:35:28 +00:00
|
|
|
|
2010-03-02 13:54:50 +00:00
|
|
|
ProcessFieldsTD PETD(&cop,&eng);
|
2010-03-04 10:53:58 +00:00
|
|
|
start[0]=-500;start[1]=25;start[2]=-800;
|
|
|
|
stop[0] = 500;stop[1] =24;stop[2] = 800;
|
|
|
|
// start[0]=-300;start[1]=0;start[2]=-4000;
|
|
|
|
// stop[0]=300;stop[1]=300;stop[2]=-4000;
|
2010-03-02 14:37:00 +00:00
|
|
|
PETD.SetDumpType(0);
|
2010-03-02 13:54:50 +00:00
|
|
|
PETD.SetFilePattern("tmp/Et_");
|
|
|
|
PETD.DefineStartStopCoord(start,stop);
|
|
|
|
|
2010-03-02 14:37:00 +00:00
|
|
|
ProcessFieldsTD PHTD(&cop,&eng);
|
|
|
|
start[0]=-1000;start[2]=0;start[1]=-1000;
|
|
|
|
stop[0]=1000;stop[2]=0;stop[1]=1000;
|
|
|
|
PHTD.SetDumpType(1);
|
|
|
|
PHTD.SetFilePattern("tmp/Ht_");
|
|
|
|
PHTD.DefineStartStopCoord(start,stop);
|
|
|
|
|
2010-03-02 21:55:50 +00:00
|
|
|
PETD.SetEnable(true);
|
2010-03-02 18:01:03 +00:00
|
|
|
PHTD.SetEnable(false);
|
|
|
|
|
2010-03-01 19:50:42 +00:00
|
|
|
PV.Process();
|
2010-03-04 10:53:58 +00:00
|
|
|
PCurr.Process();
|
2010-03-02 13:54:50 +00:00
|
|
|
PETD.Process();
|
2010-03-02 18:01:03 +00:00
|
|
|
PHTD.Process();
|
2010-03-02 13:54:50 +00:00
|
|
|
|
2010-03-01 18:35:28 +00:00
|
|
|
//*************** simulate ************//
|
|
|
|
for (unsigned int i=0;i<maxIter;i+=NrIter)
|
|
|
|
{
|
|
|
|
eng.IterateTS(NrIter);
|
|
|
|
PV.Process();
|
2010-03-04 10:53:58 +00:00
|
|
|
PCurr.Process();
|
2010-03-02 13:54:50 +00:00
|
|
|
PETD.Process();
|
2010-03-02 14:37:00 +00:00
|
|
|
PHTD.Process();
|
2010-03-01 18:35:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//*************** postproc ************//
|
2010-03-01 13:56:27 +00:00
|
|
|
time_t prevTime = currTime;
|
|
|
|
currTime = time(NULL);
|
|
|
|
|
|
|
|
double t_diff = difftime(currTime,prevTime);
|
|
|
|
|
2010-03-01 18:35:28 +00:00
|
|
|
cerr << "Time for " << eng.GetNumberOfTimesteps() << " iterations with " << cop.GetNumberCells() << " cells : " << t_diff << " sec" << endl;
|
2010-03-04 10:53:58 +00:00
|
|
|
cerr << "Speed: " << (double)cop.GetNumberCells()*(double)eng.GetNumberOfTimesteps()/t_diff/1e6 << " MCells/s " << endl;
|
2010-02-28 21:48:03 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2010-02-28 22:42:10 +00:00
|
|
|
|
2010-03-01 19:50:42 +00:00
|
|
|
void BuildDipol(ContinuousStructure &CSX)
|
|
|
|
{
|
|
|
|
CSPropMaterial* mat = new CSPropMaterial(CSX.GetParameterSet());
|
|
|
|
mat->SetKappa(0.001);
|
|
|
|
CSX.AddProperty(mat);
|
|
|
|
|
|
|
|
CSPrimBox* matbox = new CSPrimBox(CSX.GetParameterSet(),mat);
|
|
|
|
matbox->SetCoord(0,-1000.0);matbox->SetCoord(1,1000.0);
|
|
|
|
matbox->SetCoord(2,-1000.0);matbox->SetCoord(3,1000.0);
|
|
|
|
matbox->SetCoord(4,-1000.0);matbox->SetCoord(5,1000.0);
|
|
|
|
CSX.AddPrimitive(matbox);
|
|
|
|
|
|
|
|
CSPropElectrode* elec = new CSPropElectrode(CSX.GetParameterSet());
|
|
|
|
elec->SetExcitation(1,1);
|
2010-03-02 13:54:50 +00:00
|
|
|
elec->SetExcitType(1);
|
|
|
|
elec->SetActiveDir(0,0);//disable x
|
|
|
|
elec->SetActiveDir(0,2);//disable z
|
2010-03-01 19:50:42 +00:00
|
|
|
// elec->SetDelay(2.0e-9);
|
|
|
|
CSX.AddProperty(elec);
|
|
|
|
|
|
|
|
CSPrimBox* box = new CSPrimBox(CSX.GetParameterSet(),elec);
|
2010-03-02 14:37:00 +00:00
|
|
|
box->SetCoord(0,-10.0);box->SetCoord(1,10.0);
|
2010-03-01 19:50:42 +00:00
|
|
|
box->SetCoord(2,-75.0);box->SetCoord(3,75.0);
|
2010-03-02 14:37:00 +00:00
|
|
|
box->SetCoord(4,-10.0);box->SetCoord(5,10.0);
|
2010-03-01 19:50:42 +00:00
|
|
|
CSX.AddPrimitive(box);
|
|
|
|
|
|
|
|
CSRectGrid* grid = CSX.GetGrid();
|
|
|
|
|
2010-03-02 14:37:00 +00:00
|
|
|
for (int n=-990;n<=990;n+=20)
|
2010-03-01 19:50:42 +00:00
|
|
|
grid->AddDiscLine(2,(double)n);
|
2010-03-02 14:37:00 +00:00
|
|
|
for (int n=-990;n<=990;n+=20)
|
2010-03-01 19:50:42 +00:00
|
|
|
grid->AddDiscLine(0,(double)n);
|
2010-03-02 14:37:00 +00:00
|
|
|
for (int n=-990;n<=990;n+=20)
|
2010-03-01 19:50:42 +00:00
|
|
|
grid->AddDiscLine(1,(double)n);
|
|
|
|
|
|
|
|
grid->SetDeltaUnit(1e-3);
|
|
|
|
|
|
|
|
CSX.Write2XML("tmp/Dipol.xml");
|
|
|
|
}
|
|
|
|
|
2010-03-02 18:01:03 +00:00
|
|
|
void BuildPlaneWave(ContinuousStructure &CSX)
|
|
|
|
{
|
|
|
|
// CSPropMaterial* mat = new CSPropMaterial(CSX.GetParameterSet());
|
|
|
|
//// mat->SetKappa(0.001);
|
|
|
|
// CSX.AddProperty(mat);
|
|
|
|
//
|
|
|
|
// CSPrimBox* matbox = new CSPrimBox(CSX.GetParameterSet(),mat);
|
|
|
|
// matbox->SetCoord(0,-1000.0);matbox->SetCoord(1,1000.0);
|
|
|
|
// matbox->SetCoord(2,-1000.0);matbox->SetCoord(3,1000.0);
|
2010-03-02 21:55:50 +00:00
|
|
|
// matbox->SetCoord(4,-4000.0);matbox->SetCoord(5,4000.0);
|
2010-03-02 18:01:03 +00:00
|
|
|
// CSX.AddPrimitive(matbox);
|
|
|
|
|
|
|
|
CSPropElectrode* elec = new CSPropElectrode(CSX.GetParameterSet());
|
|
|
|
elec->SetExcitation(1,1);
|
|
|
|
elec->SetExcitType(0);
|
|
|
|
elec->SetActiveDir(0,0);//disable x
|
|
|
|
elec->SetActiveDir(0,2);//disable z
|
|
|
|
// elec->SetDelay(2.0e-9);
|
|
|
|
CSX.AddProperty(elec);
|
|
|
|
|
|
|
|
CSPrimBox* box = new CSPrimBox(CSX.GetParameterSet(),elec);
|
2010-03-02 21:55:50 +00:00
|
|
|
box->SetCoord(0,-500.0);box->SetCoord(1,500.0);
|
|
|
|
box->SetCoord(2,-500.0);box->SetCoord(3,500.0);
|
|
|
|
box->SetCoord(4,-4000.0);box->SetCoord(5,-4000.0);
|
2010-03-02 18:01:03 +00:00
|
|
|
CSX.AddPrimitive(box);
|
|
|
|
|
2010-03-02 21:55:50 +00:00
|
|
|
CSPropMetal* metal = new CSPropMetal(CSX.GetParameterSet());
|
|
|
|
CSX.AddProperty(metal);
|
|
|
|
CSPrimCylinder* cyl = new CSPrimCylinder(CSX.GetParameterSet(),metal);
|
|
|
|
cyl->SetRadius(100);
|
|
|
|
cyl->SetCoord(0,0.0);cyl->SetCoord(1,0.0);
|
|
|
|
cyl->SetCoord(2,-250.0);cyl->SetCoord(3,250.0);
|
|
|
|
cyl->SetCoord(4,-0000.0);cyl->SetCoord(5,-0000.0);
|
|
|
|
CSX.AddPrimitive(cyl);
|
|
|
|
|
2010-03-02 18:01:03 +00:00
|
|
|
CSRectGrid* grid = CSX.GetGrid();
|
|
|
|
|
2010-03-02 21:55:50 +00:00
|
|
|
for (int n=-500;n<=500;n+=20)
|
2010-03-02 18:01:03 +00:00
|
|
|
grid->AddDiscLine(0,(double)n);
|
2010-03-02 21:55:50 +00:00
|
|
|
for (int n=-500;n<=500;n+=20)
|
2010-03-02 18:01:03 +00:00
|
|
|
grid->AddDiscLine(1,(double)n);
|
2010-03-02 21:55:50 +00:00
|
|
|
for (int n=-4000;n<=4000;n+=20)
|
2010-03-02 18:01:03 +00:00
|
|
|
grid->AddDiscLine(2,(double)n);
|
|
|
|
|
|
|
|
grid->SetDeltaUnit(1e-3);
|
|
|
|
|
|
|
|
CSX.Write2XML("tmp/PlaneWave.xml");
|
|
|
|
}
|
|
|
|
|
2010-02-28 22:42:10 +00:00
|
|
|
void BuildMSL(ContinuousStructure &CSX)
|
|
|
|
{
|
2010-03-04 10:53:58 +00:00
|
|
|
double width = 1000;
|
|
|
|
double hight = 500;
|
|
|
|
double length = 2000;
|
|
|
|
double abs_l = 200;
|
|
|
|
|
|
|
|
//substrate....
|
|
|
|
CSPropMaterial* mat = new CSPropMaterial(CSX.GetParameterSet());
|
2010-03-01 18:35:28 +00:00
|
|
|
// mat->SetEpsilon(3.6);
|
2010-03-04 10:53:58 +00:00
|
|
|
double finalKappa = 3/pow(abs_l,4);
|
|
|
|
mat->SetKappa(finalKappa);
|
|
|
|
std::ostringstream fct;
|
|
|
|
fct << "pow(abs(z)-" << length/2.0-abs_l << ",4)";
|
|
|
|
mat->SetKappaWeightFunction(fct.str(),0);
|
|
|
|
mat->SetKappaWeightFunction(fct.str(),1);
|
|
|
|
mat->SetKappaWeightFunction(fct.str(),2);
|
|
|
|
mat->SetSigma(finalKappa*__MUE0__/__EPS0__);
|
|
|
|
mat->SetSigmaWeightFunction(fct.str(),0);
|
|
|
|
mat->SetSigmaWeightFunction(fct.str(),1);
|
|
|
|
mat->SetSigmaWeightFunction(fct.str(),2);
|
|
|
|
CSX.AddProperty(mat);
|
|
|
|
CSPrimBox* box = new CSPrimBox(CSX.GetParameterSet(),mat);
|
|
|
|
box->SetCoord(0,width/-2.0);box->SetCoord(1,width/2.0);
|
|
|
|
box->SetCoord(2,0.0);box->SetCoord(3,hight);
|
|
|
|
box->SetCoord(4,length/2.0-abs_l); box->SetCoord(5,length/2.0);
|
|
|
|
CSX.AddPrimitive(box);
|
|
|
|
box = new CSPrimBox(CSX.GetParameterSet(),mat);
|
|
|
|
box->SetCoord(0,width/-2.0);box->SetCoord(1,width/2.0);
|
|
|
|
box->SetCoord(2,0.0);box->SetCoord(3,hight);
|
|
|
|
box->SetCoord(4,length/-2.0+abs_l); box->SetCoord(5,length/-2.0);
|
|
|
|
CSX.AddPrimitive(box);
|
|
|
|
|
|
|
|
// double coords[]={0,0,length/2};
|
|
|
|
// cerr << fct.str() << endl;
|
|
|
|
// cerr << finalKappa*pow(abs_l,4) << endl;
|
|
|
|
// cerr << mat->GetKappaWeighted(0,coords) << endl;
|
|
|
|
// exit(0);
|
|
|
|
|
|
|
|
//MSL
|
|
|
|
CSPropMetal* MSL = new CSPropMetal(CSX.GetParameterSet());
|
2010-03-01 18:35:28 +00:00
|
|
|
// MSL->SetKappa(56e6);
|
2010-03-04 10:53:58 +00:00
|
|
|
CSX.AddProperty(MSL);
|
|
|
|
box = new CSPrimBox(CSX.GetParameterSet(),MSL);
|
|
|
|
box->SetCoord(0,-40.0);box->SetCoord(1,40.0);
|
|
|
|
box->SetCoord(2,50.0);box->SetCoord(3,50.0);
|
|
|
|
box->SetCoord(4,length/-2);box->SetCoord(5,length/2.0);
|
|
|
|
CSX.AddPrimitive(box);
|
2010-02-28 22:42:10 +00:00
|
|
|
|
2010-03-04 10:53:58 +00:00
|
|
|
//MSL excite...
|
2010-02-28 22:42:10 +00:00
|
|
|
CSPropElectrode* elec = new CSPropElectrode(CSX.GetParameterSet());
|
2010-03-04 10:53:58 +00:00
|
|
|
elec->SetExcitation(-1,1);
|
|
|
|
elec->SetExcitType(1);
|
2010-03-01 13:56:27 +00:00
|
|
|
// elec->SetDelay(2.0e-9);
|
2010-02-28 22:42:10 +00:00
|
|
|
CSX.AddProperty(elec);
|
2010-03-04 10:53:58 +00:00
|
|
|
box = new CSPrimBox(CSX.GetParameterSet(),elec);
|
|
|
|
box->SetCoord(0,-40.0);box->SetCoord(1,40.0);
|
2010-02-28 22:42:10 +00:00
|
|
|
box->SetCoord(2,0.0);box->SetCoord(3,50.0);
|
2010-03-04 10:53:58 +00:00
|
|
|
box->SetCoord(4,length/-2.0);box->SetCoord(5,length/-2.0);
|
2010-02-28 22:42:10 +00:00
|
|
|
CSX.AddPrimitive(box);
|
|
|
|
|
|
|
|
CSRectGrid* grid = CSX.GetGrid();
|
|
|
|
|
2010-03-04 10:53:58 +00:00
|
|
|
for (double n=width/-2.0;n<=width/2;n+=20)
|
|
|
|
grid->AddDiscLine(0,n);
|
|
|
|
for (double n=0;n<=500;n+=10)
|
|
|
|
grid->AddDiscLine(1,n);
|
|
|
|
for (double n=length/-2.0;n<=length/2.0;n+=20)
|
|
|
|
grid->AddDiscLine(2,n);
|
2010-02-28 22:42:10 +00:00
|
|
|
|
2010-03-01 07:43:31 +00:00
|
|
|
grid->SetDeltaUnit(1e-3);
|
|
|
|
|
2010-03-01 19:50:42 +00:00
|
|
|
CSX.Write2XML("tmp/MSL.xml");
|
2010-02-28 22:42:10 +00:00
|
|
|
}
|