/* parameters */

d=0.05 ; /* magnet-polar piece distance */
a= 0.10 ; /* magnetic system-boundary distance*/

p0 = 0.001;
p1 = 0.01;
p2 = 0.02;
e=0.05;

/* points */
/* inner boundary box points */
Point(1) = {0,0,0,p1};
Point(114) = {0,a,0,p1};
Point(116) = {0,-a,0,p1};
Point(2) = {a,0,0,p1};
Point(3) = {-a,0,0,p1};
Point(4) = {0,0,2*a+0.05+d+0.01,p1};
Point(115) = {0,a,2*a+0.05+d+0.01,p1};
Point(117) = {0,-a,2*a+0.05+d+0.01,p1};
Point(5) = {a,0,2*a+0.05+d+0.01,p1};
Point(6) = {-a,0,2*a+0.05+d+0.01,p1};
/* magnet points */
Point(7) = {0,0,a,p0};
Point(100) = {0,0.005,a,p0};
Point(104) = {0,-0.005,a,p0};
Point(8) = {0.005,0,a,p0};
Point(9) = {-0.005,0,a,p0};
Point(10) = {0,0,a+0.050,p0};
Point(101) = {0,0.005,a+0.050,p0};
Point(105) = {0,-0.005,a+0.050,p0};
Point(11) = {0.005,0,a+0.050,p0};
Point(12) = {-0.005,0,a+0.050,p0};
/* polar piece points */
Point(13) = {0,0,a+0.050+d,p0};
Point(102) = {0,0.005,a+0.050+d,p0};
Point(106) = {0,-0.005,a+0.050+d,p0};
Point(14) = {0.005,0,a+0.050+d,p0};
Point(15) = {-0.005,0,a+0.050+d,p0};
Point(16) = {0,0,a+0.050+d+0.010,p0};
Point(103) = {0,0.005,a+0.050+d+0.010,p0};
Point(107) = {0,-0.005,a+0.050+d+0.010,p0};
Point(17) = {0.005,0,a+0.050+d+0.010,p0};
Point(18) = {-0.005,0,a+0.050+d+0.010,p0};

/* outer boundary box points */
Point(19) = {0,0,-e,p2};
Point(20) = {0,a+e,-e,p2};
Point(108) = {0,-(a+e),-e,p2};
Point(21) = {a+e,0,-e,p2};
Point(22) = {-a-e,0,-e,p2};
Point(23) = {0,0,2*a+0.05+d+0.01+e,p2};
Point(24) = {0,a+e,2*a+0.05+d+0.01+e,p2};
Point(109) = {0,-(a+e),2*a+0.05+d+0.01+e,p2};
Point(25) = {a+e,0,2*a+0.05+d+0.01+e,p2};
Point(26) = {-a-e,0,2*a+0.05+d+0.01+e,p2};

/* lines */
/* inner boundary box lines */
Line(1) = {3,1} ;
Line(2) = {1,2} ;
Line(3) = {2,5} ;
Line(4) = {5,4} ;
Line(5) = {4,6} ;
Line(6) = {6,3} ;
Line(116) = {114,115} ;
Line(1001)={116,117};       //
Circle (7) = {2,1,114} ;
Circle (117) = {114,1,3};
Circle (8) = {5,4,115} ;
Circle(118) = {115,4,6} ;
Circle(1002)={3,1,116};     //
Circle(1003)={116,1,2};     //
Circle(1004)={6,4,117};     //
Circle(1005)={117,4,5};     //
/* outer boundary box lines */
Line(120)={22,19};
Line(121)={19,21};
Circle(122)={21,19,20};
Circle(123)={20,19,22};
Circle(1006)={22,19,108};   //
Circle(1007)={108,19,21};   //
Line(124)={26,23};
Line(125)={23,25};
Circle(126)={25,23,24};
Circle(127)={24,23,26};
Circle(1008)={26,23,109};   //
Circle(1009)={109,23,25};   //
Line(128)={22,26};
Line(129)={21,25};
Line(130)={20,24};
Line(1010)={108,109};       //
/* magnet lines */
Line(9) = {9,7} ;
Line(10) = {7,8} ;
Line(11) = {8,11} ;
Line(12) = {11,10} ;
Line(13) = {10,12} ;
Line(14) = {12,9} ;
Line(108)= {100,101};
Line(1011)={104,105};       //
Circle (15) = {8,7,100} ;   
Circle (104) = {100,7,9} ;
Circle (16) = {11,10,101} ;
Circle (105) = {101,10,12} ;
Circle(1012)={9,7,104};     //
Circle(1013)={104,7,8};     //
Circle(1014)={12,10,105};   //
Circle(1015)={105,10,11};   //
/* polar piece lines */
Line(17) = {15,13} ;
Line(18) = {13,14} ;
Line(19) = {14,17} ;
Line(20) = {17,16} ;
Line(21) = {16,18} ;
Line(22) = {18,15} ;
Line(1016)={106,107};       //
Line(109)= {102,103};
Circle (23) = {14,13,102} ;
Circle (106) = {102,13,15} ;
Circle (24) = {17,16,103} ;
Circle (107) = {103,16,18} ;
Circle(1017)={15,13,106};
Circle(1018)={106,13,14};
Circle(1019)={18,16,107};
Circle(1020)={107,16,17};


/* surfaces */
/* magnet surfaces */

Line Loop (33) = {9,10,11,12,13,14} ;
Plane Surface (34) ={33} ;
Line Loop (35) = {-11,15,108,-16} ;
Ruled Surface (36) = {35} ;
Line Loop (110) = {-108,104,-14,-105} ;
Ruled Surface (111) = {110} ;
Line Loop(1021)={14,1012,1011,-1014};
Ruled Surface(1022)={1021};
Line Loop(1023)={11,-1015,-1011,1013};
Ruled Surface(1024)={1023};
Line Loop (37) = {-10,-9,-104,-15} ;
Plane Surface (38) = {37} ;
Line Loop (39) = {16,105,-12,-13} ;
Plane Surface (40) = {39} ;
Line Loop(1025)={9,10,-1013,-1012};
Plane Surface(1026)={1025};
Line Loop(1027)={12,13,1014,1015};
Plane Surface(1028)={1027};

/* polar piece surfaces */

//Line Loop (41) = {17,18,19,20,21,22} ;
//Plane Surface (42) = {41} ;
Line Loop (43) = {-19,23,109,-24} ;
Ruled Surface (44) = {43} ;
Line Loop (112) = {-109,106,-22,-107} ;
Ruled Surface (113) = {112} ;
Line Loop(1029)={22,1017,1016,-1019};
Ruled Surface(1030)={1029};
Line Loop(1031)={19,-1020,-1016,1018};
Ruled Surface(1032)={1031};
Line Loop (45) = {-18,-17,-106,-23} ;
Plane Surface (46) = {45} ;
Line Loop (47) = {-21,-20,24,107} ;
Plane Surface (48) = {47} ;
Line Loop(1032)={20,21,1019,1020};
Plane Surface(1033)={1032};
Line Loop(1034)={17,18,-1018,-1017};
Plane Surface(1035)={1034};

/* inner boundary box surfaces */

//Line Loop (25) = {1,2,3,4,5,6} ;
//Plane Surface (26) = {25,33,41} ;
Line Loop (27) = {-3,7,116,-8} ;
Ruled Surface (28) = {27} ;
Line Loop (119) = {-116,117,-6,-118} ;
Ruled Surface (120) = {119} ;
Line Loop(1036)={6,1002,1001,-1004};
Ruled Surface(1037)={1036};
Line Loop(1038)={-1001,1003,3,-1005};
Ruled Surface(1039)={1038};
Line Loop (29) = {-2,-1,-117,-7};
Plane Surface (30) = {29} ;
Line Loop (31) = {-5,-4,8,118} ;
Plane Surface (32) = {31} ;
Line Loop(1040)={4,5,1004,1005};
Plane Surface(1041)={1040};
Line Loop(1042)={1,2,-1003,-1002};
Plane Surface(1043)={1042};

/* outer boundary box surfaces */

Line Loop(114)={-120,-123,-122,-121};
Plane Surface(114)={114};
Line Loop(115)={124,125,126,127};
Plane Surface(115)={115};
Line Loop(116)={122,130,-126,-129};
Ruled Surface(116)={116};
Line Loop(117)={123,128,-127,-130};
Ruled Surface(117)={117};
//Line Loop(118)={120,121,129,-125,-124,-128};
//Plane Surface(118)={118,25};
Line Loop(1044)={-125,-124,1008,1009};
Plane Surface(1045)={1044};
Line Loop(1046)={120,121,-1007,-1006};
Plane Surface(1047)={1046};
Line Loop(1048)={-128,1006,1010,-1008};
Ruled Surface(1049)={1048};
Line Loop(1050)={1007,129,-1009,-1010};
Ruled Surface(1051)={1050};

/* volumes */
/* magnet volume */

Surface Loop(120) = {36,111,1022,1024,1026,1028,38,40} ;
Volume (121) = {120};

/* pole piece volume */

Surface Loop(122) = {44,113,1030,1032,46,1035,48,1033} ;
Volume (123) = {122} ;

/* air box */

Surface Loop(124) = {28,-120,1037,1039,30,1043,32,1041,-36,-111,-1022,-1024,-38,-1026,-40,-1028,-44,-113,-1030,-1032,-46,-1035,-48,-1033} ;
Volume (125) = {124} ;

/* boundary box */

Surface Loop(126)={114,1047,115,1045,116,117,1049,1051,-30,-1043,-32,-1041,-28,-120,-1037,-1039};
Volume (127)={126};

/* physical volumes */

Physical Volume(126)={121};        //magnet
Physical Volume(127)={123};        //iron
Physical Volume(128)={125};        //air
Physical Volume(129)={127};        //airbox

/* physical surface */

Physical Surface(130)={114,115,116,117};         //SurfaceExt
Physical Surface(140)={34};

