Moved the examples into seperate files

pull/1/head
Thorsten Liebig 2010-03-07 12:49:38 +01:00
parent 5208d3f9a2
commit 6dd89ca409
4 changed files with 214 additions and 187 deletions

172
examples/FDTD_examples.cpp Normal file
View File

@ -0,0 +1,172 @@
#include "FDTD_examples.h"
#include "../tools/constants.h"
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);
elec->SetExcitType(1);
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);
box->SetCoord(0,-10.0);box->SetCoord(1,10.0);
box->SetCoord(2,-75.0);box->SetCoord(3,75.0);
box->SetCoord(4,-10.0);box->SetCoord(5,10.0);
CSX.AddPrimitive(box);
CSRectGrid* grid = CSX.GetGrid();
for (int n=-990;n<=990;n+=20)
grid->AddDiscLine(2,(double)n);
for (int n=-990;n<=990;n+=20)
grid->AddDiscLine(0,(double)n);
for (int n=-990;n<=990;n+=20)
grid->AddDiscLine(1,(double)n);
grid->SetDeltaUnit(1e-3);
CSX.Write2XML("tmp/Dipol.xml");
}
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);
// matbox->SetCoord(4,-4000.0);matbox->SetCoord(5,4000.0);
// 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);
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);
CSX.AddPrimitive(box);
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);
CSRectGrid* grid = CSX.GetGrid();
for (int n=-500;n<=500;n+=20)
grid->AddDiscLine(0,(double)n);
for (int n=-500;n<=500;n+=20)
grid->AddDiscLine(1,(double)n);
for (int n=-4000;n<=4000;n+=20)
grid->AddDiscLine(2,(double)n);
grid->SetDeltaUnit(1e-3);
CSX.Write2XML("tmp/PlaneWave.xml");
}
void BuildMSL(ContinuousStructure &CSX)
{
double width = 1000;
double hight = 500;
double length = 2000;
double abs_l = 200;
//substrate....
CSPropMaterial* mat = new CSPropMaterial(CSX.GetParameterSet());
// mat->SetEpsilon(3.6);
double finalKappa = 3.0/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);
//MSL
CSPropMetal* MSL = new CSPropMetal(CSX.GetParameterSet());
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);
box->SetPriority(100);
CSX.AddPrimitive(box);
//MSL excite...
CSPropElectrode* elec = new CSPropElectrode(CSX.GetParameterSet());
elec->SetExcitation(-1,1);
elec->SetExcitType(0);
// elec->SetDelay(2.0e-9);
CSX.AddProperty(elec);
box = new CSPrimBox(CSX.GetParameterSet(),elec);
box->SetCoord(0,-40.0);box->SetCoord(1,40.0);
box->SetCoord(2,0.0);box->SetCoord(3,50.0);
box->SetCoord(4,length/-2.0);box->SetCoord(5,length/-2.0);
CSX.AddPrimitive(box);
//E-field dump
CSPropDumpBox* Edump = new CSPropDumpBox(CSX.GetParameterSet());
Edump->SetEFieldDump(true);
CSX.AddProperty(Edump);
box = new CSPrimBox(CSX.GetParameterSet(),Edump);
box->SetCoord(0,width/-2.0);box->SetCoord(1,width/2.0);
box->SetCoord(2,25.0);box->SetCoord(3,25.);
box->SetCoord(4,length/-2.0);box->SetCoord(5,length/2.0);
CSX.AddPrimitive(box);
CSRectGrid* grid = CSX.GetGrid();
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);
grid->SetDeltaUnit(1e-3);
CSX.Write2XML("tmp/MSL.xml");
}

12
examples/FDTD_examples.h Normal file
View File

@ -0,0 +1,12 @@
#ifndef FDTD_EXAMPLES_H
#define FDTD_EXAMPLES_H
#include "ContinuousStructure.h"
void BuildDipol(ContinuousStructure &CSX);
void BuildPlaneWave(ContinuousStructure &CSX);
void BuildMSL(ContinuousStructure &CSX);
#endif // FDTD_EXAMPLES_H

205
main.cpp
View File

@ -11,11 +11,9 @@
#include "ContinuousStructure.h" #include "ContinuousStructure.h"
using namespace std; #include "examples/FDTD_examples.h"
void BuildMSL(ContinuousStructure &CSX); using namespace std;
void BuildDipol(ContinuousStructure &CSX);
void BuildPlaneWave(ContinuousStructure &CSX);
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
@ -69,29 +67,37 @@ int main(int argc, char *argv[])
unsigned int maxIter = 1800; unsigned int maxIter = 1800;
vector<CSProperties*> DumpProps = CSX.GetPropertyByType(CSProperties::DUMPBOX);
vector<ProcessFieldsTD*> TD_Dump;
ProcessFieldsTD PETD(&cop,&eng); ProcessFieldsTD PETD(&cop,&eng);
start[0]=-500;start[1]=25;start[2]=-800; if (DumpProps.size()>0)
stop[0] = 500;stop[1] =24;stop[2] = 800; {
// start[0]=-300;start[1]=0;start[2]=-4000; CSPrimitives* prim = DumpProps.at(0)->GetPrimitive(0);
// stop[0]=300;stop[1]=300;stop[2]=-4000; bool acc;
double* bnd = prim->GetBoundBox(acc);
start[0]= bnd[0];start[1]=bnd[2];start[2]=bnd[4];
stop[0] = bnd[1];stop[1] =bnd[3];stop[2] =bnd[5];
CSPropDumpBox* db = DumpProps.at(0)->ToDumpBox();
if (db)
{
if (db->GetEFieldDump())
{
PETD.SetDumpType(0); PETD.SetDumpType(0);
PETD.SetFilePattern("tmp/Et_"); PETD.SetFilePattern("tmp/Et_");
}
else
PETD.SetEnable(false);
}
else
PETD.SetEnable(false);
PETD.DefineStartStopCoord(start,stop); PETD.DefineStartStopCoord(start,stop);
}
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);
PETD.SetEnable(true); PETD.SetEnable(true);
PHTD.SetEnable(false);
PV.Process(); PV.Process();
PCurr.Process(); PCurr.Process();
PETD.Process(); PETD.Process();
PHTD.Process();
//*************** simulate ************// //*************** simulate ************//
for (unsigned int i=0;i<maxIter;i+=NrIter) for (unsigned int i=0;i<maxIter;i+=NrIter)
@ -100,7 +106,6 @@ int main(int argc, char *argv[])
PV.Process(); PV.Process();
PCurr.Process(); PCurr.Process();
PETD.Process(); PETD.Process();
PHTD.Process();
} }
//*************** postproc ************// //*************** postproc ************//
@ -113,167 +118,3 @@ int main(int argc, char *argv[])
cerr << "Speed: " << (double)cop.GetNumberCells()*(double)eng.GetNumberOfTimesteps()/t_diff/1e6 << " MCells/s " << endl; cerr << "Speed: " << (double)cop.GetNumberCells()*(double)eng.GetNumberOfTimesteps()/t_diff/1e6 << " MCells/s " << endl;
return 0; return 0;
} }
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);
elec->SetExcitType(1);
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);
box->SetCoord(0,-10.0);box->SetCoord(1,10.0);
box->SetCoord(2,-75.0);box->SetCoord(3,75.0);
box->SetCoord(4,-10.0);box->SetCoord(5,10.0);
CSX.AddPrimitive(box);
CSRectGrid* grid = CSX.GetGrid();
for (int n=-990;n<=990;n+=20)
grid->AddDiscLine(2,(double)n);
for (int n=-990;n<=990;n+=20)
grid->AddDiscLine(0,(double)n);
for (int n=-990;n<=990;n+=20)
grid->AddDiscLine(1,(double)n);
grid->SetDeltaUnit(1e-3);
CSX.Write2XML("tmp/Dipol.xml");
}
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);
// matbox->SetCoord(4,-4000.0);matbox->SetCoord(5,4000.0);
// 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);
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);
CSX.AddPrimitive(box);
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);
CSRectGrid* grid = CSX.GetGrid();
for (int n=-500;n<=500;n+=20)
grid->AddDiscLine(0,(double)n);
for (int n=-500;n<=500;n+=20)
grid->AddDiscLine(1,(double)n);
for (int n=-4000;n<=4000;n+=20)
grid->AddDiscLine(2,(double)n);
grid->SetDeltaUnit(1e-3);
CSX.Write2XML("tmp/PlaneWave.xml");
}
void BuildMSL(ContinuousStructure &CSX)
{
double width = 1000;
double hight = 500;
double length = 2000;
double abs_l = 200;
//substrate....
CSPropMaterial* mat = new CSPropMaterial(CSX.GetParameterSet());
// mat->SetEpsilon(3.6);
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());
// MSL->SetKappa(56e6);
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);
//MSL excite...
CSPropElectrode* elec = new CSPropElectrode(CSX.GetParameterSet());
elec->SetExcitation(-1,1);
elec->SetExcitType(1);
// elec->SetDelay(2.0e-9);
CSX.AddProperty(elec);
box = new CSPrimBox(CSX.GetParameterSet(),elec);
box->SetCoord(0,-40.0);box->SetCoord(1,40.0);
box->SetCoord(2,0.0);box->SetCoord(3,50.0);
box->SetCoord(4,length/-2.0);box->SetCoord(5,length/-2.0);
CSX.AddPrimitive(box);
CSRectGrid* grid = CSX.GetGrid();
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);
grid->SetDeltaUnit(1e-3);
CSX.Write2XML("tmp/MSL.xml");
}

View File

@ -25,7 +25,8 @@ SOURCES += main.cpp \
FDTD/processing.cpp \ FDTD/processing.cpp \
FDTD/processfields.cpp \ FDTD/processfields.cpp \
FDTD/processfields_td.cpp \ FDTD/processfields_td.cpp \
FDTD/processcurrent.cpp FDTD/processcurrent.cpp \
examples/FDTD_examples.cpp
HEADERS += tools/ErrorMsg.h \ HEADERS += tools/ErrorMsg.h \
tools/AdrOp.h \ tools/AdrOp.h \
tools/constants.h \ tools/constants.h \
@ -36,4 +37,5 @@ HEADERS += tools/ErrorMsg.h \
FDTD/processing.h \ FDTD/processing.h \
FDTD/processfields.h \ FDTD/processfields.h \
FDTD/processfields_td.h \ FDTD/processfields_td.h \
FDTD/processcurrent.h FDTD/processcurrent.h \
examples/FDTD_examples.h