From daaf898e832a9513fa2ae540665e7171918f655d Mon Sep 17 00:00:00 2001 From: Thorsten Liebig Date: Sun, 14 Mar 2010 23:03:18 +0100 Subject: [PATCH] Helix example --- examples/FDTD_examples.cpp | 154 +++++++++++++++++++++++++++++++++++++ examples/FDTD_examples.h | 1 + examples/Helix.xml | 78 +++++++++++++++++++ main.cpp | 8 +- 4 files changed, 239 insertions(+), 2 deletions(-) create mode 100644 examples/Helix.xml diff --git a/examples/FDTD_examples.cpp b/examples/FDTD_examples.cpp index e73c035..57fd17c 100644 --- a/examples/FDTD_examples.cpp +++ b/examples/FDTD_examples.cpp @@ -597,3 +597,157 @@ void BuildCoaxial_Cartesian(const char* filename) doc.SaveFile(); } +void BuildHelix(const char* filename) +{ + int maxIter = 10000; + double f0=0.15e9; + double fc=0.15e9; + int Excit_Type=0; + int bounds[] = {1,1,1,1,0,0}; + + cerr << "Create Helix Geometry..." << endl; + ContinuousStructure CSX; + + double width = 800; + double length = 800; + double delta[] = {5,5,5}; + + //MSL + CSPropMaterial* copper = new CSPropMaterial(CSX.GetParameterSet()); + copper->SetKappa(56e6); + copper->SetName("copper"); + CSX.AddProperty(copper); + + CSPrimUserDefined* helix = new CSPrimUserDefined(CSX.GetParameterSet(),copper); + helix->SetCoordSystem(CSPrimUserDefined::CYLINDER_SYSTEM); + helix->SetFunction("(r<110)&(r>90)&(sqrt(pow(x-r*cos(2*pi*z/100),2)+pow(y-r*sin(2*pi*z/100),2))<20)&(z>200)&(z<600)"); + CSX.AddPrimitive(helix); + CSPrimCylinder* cyl = new CSPrimCylinder(CSX.GetParameterSet(),copper); + cyl->SetRadius(10); + cyl->SetCoord(0,100.0);cyl->SetCoord(1,310.0); + cyl->SetCoord(2,0.0);cyl->SetCoord(3,0.0); + cyl->SetCoord(4,200.0);cyl->SetCoord(5,200.0); + CSX.AddPrimitive(cyl); + cyl = new CSPrimCylinder(CSX.GetParameterSet(),copper); + cyl->SetRadius(10); + cyl->SetCoord(0,100.0);cyl->SetCoord(1,310.0); + cyl->SetCoord(2,0.0);cyl->SetCoord(3,0.0); + cyl->SetCoord(4,600.0);cyl->SetCoord(5,600.0); + CSX.AddPrimitive(cyl); + + CSPropElectrode* elec = new CSPropElectrode(CSX.GetParameterSet()); + elec->SetExcitation(1.0,2); + elec->SetExcitType(1); +// elec->SetDelay(2.0e-9); + CSX.AddProperty(elec); + cyl = new CSPrimCylinder(CSX.GetParameterSet(),elec); + cyl->SetRadius(10); + cyl->SetCoord(0,300.0);cyl->SetCoord(1,300.0); + cyl->SetCoord(2,0.0);cyl->SetCoord(3,0.0); + cyl->SetCoord(4,200.0);cyl->SetCoord(5,600.0); + CSX.AddPrimitive(cyl); + + CSPropDumpBox* Edump = NULL; + //E-field dump xz + Edump = new CSPropDumpBox(CSX.GetParameterSet()); + Edump->SetDumpType(0); + Edump->SetName("Et_xz_"); + CSX.AddProperty(Edump); + CSPrimBox* box = new CSPrimBox(CSX.GetParameterSet(),Edump); + box->SetCoord(0,width/-2.0);box->SetCoord(1,width/2.0); + box->SetCoord(2,0.0);box->SetCoord(3,0.0); + box->SetCoord(4,-50.0);box->SetCoord(5,length); + CSX.AddPrimitive(box); +// +// //E-field dump xy +// Edump = new CSPropDumpBox(CSX.GetParameterSet()); +// Edump->SetDumpType(0); +// Edump->SetName("Et_xy_"); +// CSX.AddProperty(Edump); +// box = new CSPrimBox(CSX.GetParameterSet(),Edump); +// box->SetCoord(0,width/-2.0);box->SetCoord(1,width/2.0); +// box->SetCoord(2,0.0);box->SetCoord(3,height); +// box->SetCoord(4,0.0);box->SetCoord(5,0.0); +// CSX.AddPrimitive(box); + +// //E-field dump 3D +// Edump = new CSPropDumpBox(CSX.GetParameterSet()); +// Edump->SetDumpType(0); +// Edump->SetDumpMode(2); //cell interpolated dump +// Edump->SetName("Et_"); +// CSX.AddProperty(Edump); +// box = new CSPrimBox(CSX.GetParameterSet(),Edump); +// box->SetCoord(0,MSL_width*-1.5);box->SetCoord(1,MSL_width*1.5); +// box->SetCoord(2,0.0);box->SetCoord(3,MSL_height*1.5); +// box->SetCoord(4,length/-2.0);box->SetCoord(5,length/2.0); +// CSX.AddPrimitive(box); +// + //voltage calc + CSPropProbeBox* volt = new CSPropProbeBox(CSX.GetParameterSet()); + volt->SetProbeType(0); + volt->SetName("u1"); + CSX.AddProperty(volt); + box = new CSPrimBox(CSX.GetParameterSet(),volt); + box->SetCoord(0,300.0);box->SetCoord(1,300.0); + box->SetCoord(2,0.0);box->SetCoord(3,0.0); + box->SetCoord(4,200.0);box->SetCoord(5,600.0); + CSX.AddPrimitive(box); + + //current calc + CSPropProbeBox* curr = new CSPropProbeBox(CSX.GetParameterSet()); + curr->SetProbeType(1); + curr->SetName("i1"); + CSX.AddProperty(curr); + box = new CSPrimBox(CSX.GetParameterSet(),curr); + box->SetCoord(0,200.0);box->SetCoord(1,200.0); + box->SetCoord(2,-50.0);box->SetCoord(3,50.0); + box->SetCoord(4,150.0);box->SetCoord(5,250.0); + CSX.AddPrimitive(box); + + CSRectGrid* grid = CSX.GetGrid(); + + for (double n=width/-2.0;n<=width/2;n+=delta[0]) + grid->AddDiscLine(0,n); + for (double n=width/-2.0;n<=width/2;n+=delta[0]) + grid->AddDiscLine(1,n); + for (double n=-50;n<=length;n+=delta[2]) + grid->AddDiscLine(2,n); + + grid->SetDeltaUnit(1e-3); + + //*************** Create XML file ********************** + TiXmlDocument doc(filename); + doc.InsertEndChild(TiXmlDeclaration("1.0","ISO-8859-1","yes")); + + TiXmlElement openEMS("openEMS"); + + TiXmlElement FDTD_Opts("FDTD"); + FDTD_Opts.SetAttribute("NumberOfTimesteps",maxIter); + + TiXmlElement Excite("Excitation"); + Excite.SetAttribute("Type",Excit_Type); + Excite.SetAttribute("f0",f0); + Excite.SetAttribute("fc",fc); + FDTD_Opts.InsertEndChild(Excite); + + TiXmlElement BC("BoundaryCond"); + BC.SetAttribute("xmin",bounds[0]); + BC.SetAttribute("xmax",bounds[1]); + BC.SetAttribute("ymin",bounds[2]); + BC.SetAttribute("ymax",bounds[3]); + BC.SetAttribute("zmin",bounds[4]); + BC.SetAttribute("zmax",bounds[5]); + FDTD_Opts.InsertEndChild(BC); + + openEMS.InsertEndChild(FDTD_Opts); + + if (CSX.Write2XML(&openEMS,true)==false) + { + cerr << "writing failed" << endl; + exit(-1); + } + + doc.InsertEndChild(openEMS); + + doc.SaveFile(); +} diff --git a/examples/FDTD_examples.h b/examples/FDTD_examples.h index b098c86..7c5d200 100644 --- a/examples/FDTD_examples.h +++ b/examples/FDTD_examples.h @@ -29,5 +29,6 @@ void BuildMSL(const char* filename); void BuildCoaxial_Cartesian(const char* filename); +void BuildHelix(const char* filename); #endif // FDTD_EXAMPLES_H diff --git a/examples/Helix.xml b/examples/Helix.xml new file mode 100644 index 0000000..92f725e --- /dev/null +++ b/examples/Helix.xml @@ -0,0 +1,78 @@ + + + + + + + + + -400,-395,-390,-385,-380,-375,-370,-365,-360,-355,-350,-345,-340,-335,-330,-325,-320,-315,-310,-305,-300,-295,-290,-285,-280,-275,-270,-265,-260,-255,-250,-245,-240,-235,-230,-225,-220,-215,-210,-205,-200,-195,-190,-185,-180,-175,-170,-165,-160,-155,-150,-145,-140,-135,-130,-125,-120,-115,-110,-105,-100,-95,-90,-85,-80,-75,-70,-65,-60,-55,-50,-45,-40,-35,-30,-25,-20,-15,-10,-5,0,5,10,15,20,25,30,35,40,45,50,55,60,65,70,75,80,85,90,95,100,105,110,115,120,125,130,135,140,145,150,155,160,165,170,175,180,185,190,195,200,205,210,215,220,225,230,235,240,245,250,255,260,265,270,275,280,285,290,295,300,305,310,315,320,325,330,335,340,345,350,355,360,365,370,375,380,385,390,395,400 + -400,-395,-390,-385,-380,-375,-370,-365,-360,-355,-350,-345,-340,-335,-330,-325,-320,-315,-310,-305,-300,-295,-290,-285,-280,-275,-270,-265,-260,-255,-250,-245,-240,-235,-230,-225,-220,-215,-210,-205,-200,-195,-190,-185,-180,-175,-170,-165,-160,-155,-150,-145,-140,-135,-130,-125,-120,-115,-110,-105,-100,-95,-90,-85,-80,-75,-70,-65,-60,-55,-50,-45,-40,-35,-30,-25,-20,-15,-10,-5,0,5,10,15,20,25,30,35,40,45,50,55,60,65,70,75,80,85,90,95,100,105,110,115,120,125,130,135,140,145,150,155,160,165,170,175,180,185,190,195,200,205,210,215,220,225,230,235,240,245,250,255,260,265,270,275,280,285,290,295,300,305,310,315,320,325,330,335,340,345,350,355,360,365,370,375,380,385,390,395,400 + -50,-45,-40,-35,-30,-25,-20,-15,-10,-5,0,5,10,15,20,25,30,35,40,45,50,55,60,65,70,75,80,85,90,95,100,105,110,115,120,125,130,135,140,145,150,155,160,165,170,175,180,185,190,195,200,205,210,215,220,225,230,235,240,245,250,255,260,265,270,275,280,285,290,295,300,305,310,315,320,325,330,335,340,345,350,355,360,365,370,375,380,385,390,395,400,405,410,415,420,425,430,435,440,445,450,455,460,465,470,475,480,485,490,495,500,505,510,515,520,525,530,535,540,545,550,555,560,565,570,575,580,585,590,595,600,605,610,615,620,625,630,635,640,645,650,655,660,665,670,675,680,685,690,695,700,705,710,715,720,725,730,735,740,745,750,755,760,765,770,775,780,785,790,795,800 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + (r<110)&(r>90)&(sqrt(pow(x-r*cos(2*pi*z/100),2)+pow(y-r*sin(2*pi*z/100),2))<20)&(z>200)&(z<600) + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/main.cpp b/main.cpp index 1a7437a..cbfb569 100644 --- a/main.cpp +++ b/main.cpp @@ -23,7 +23,7 @@ #include "examples/FDTD_examples.h" -#define STANDALONE +//#define STANDALONE using namespace std; @@ -73,11 +73,15 @@ int main(int argc, char *argv[]) const char* fileCoax="../examples/Coax_Cart.xml"; BuildCoaxial_Cartesian(fileCoax); - const char* file=fileMSL; + const char* fileHelix="../examples/Helix.xml"; + BuildHelix(fileHelix); + + const char* file=fileHelix; // cerr << CSX.ReadFromXML("examples/PlaneWave.xml") << endl; #endif + FDTD.DebugMaterial(); int EC = FDTD.SetupFDTD(file); if (EC) return EC; FDTD.RunFDTD();