
mm  = 0.001;
gap = 1*mm;

lc_gap  = 1*mm;
lc_core = 3*mm;
lc_ind  = 4*mm;
lc_air  = 50*mm/2;
lc_plate = 3*mm;

//right core halve
Point(1) = {0*mm, 0*mm,  0, lc_gap};
Point(2) = {10*mm,0*mm,  0, lc_core};
Point(3) = {30*mm,20*mm, 0, lc_core};
Point(4) = {30*mm,30*mm, 0, lc_core};
Point(5) = {10*mm,50*mm, 0, lc_core};
Point(6) = {0*mm, 50*mm, 0, lc_gap};
Point(7) = {0*mm, 40*mm, 0, lc_gap};
Point(8) = {10*mm,40*mm, 0, lc_core};
Point(9) = {20*mm,30*mm, 0, lc_core};
Point(10)= {20*mm,20*mm, 0, lc_core};
Point(11)= {10*mm,10*mm, 0, lc_core};
Point(12)= {0*mm, 10*mm, 0, lc_gap};
//center points of arcs
Point(13) = {10*mm, 20*mm, 0};
Point(14) = {10*mm, 30*mm, 0};

Line(1)   = {1, 2};
Circle(2) = {2, 13, 3};
Line(3)   = {3, 4};
Circle(4) = {4, 14, 5};
Line(5)   = {5, 6};
Line(6)   = {6, 7};
Line(7)   = {7, 8};
Circle(8) = {8, 14, 9};
Line(9)   = {9, 10};
Circle(10)= {10, 13, 11};
Line(11)  = {11, 12};
Line(12)  = {12, 1};

Line Loop(13) = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12};
Plane Surface(14) = {13};

//right core halve
Point(101) = {0*mm, 0*mm,  10*mm, lc_gap};
Point(102) = {10*mm,0*mm,  10*mm, lc_core};
Point(103) = {30*mm,20*mm, 10*mm, lc_core};
Point(104) = {30*mm,30*mm, 10*mm, lc_core};
Point(105) = {10*mm,50*mm, 10*mm, lc_core};
Point(106) = {0*mm, 50*mm, 10*mm, lc_gap};
Point(107) = {0*mm, 40*mm, 10*mm, lc_gap};
Point(108) = {10*mm,40*mm, 10*mm, lc_core};
Point(109) = {20*mm,30*mm, 10*mm, lc_core};
Point(110)= {20*mm,20*mm, 10*mm, lc_core};
Point(111)= {10*mm,10*mm, 10*mm, lc_core};
Point(112)= {0*mm, 10*mm, 10*mm, lc_gap};
//center points of arcs
Point(113) = {10*mm, 20*mm, 10*mm};
Point(114) = {10*mm, 30*mm, 10*mm};

Line(101)   = {101, 102};
Circle(102) = {102, 113, 103};
Line(103)   = {103, 104};
Circle(104) = {104, 114, 105};
Line(105)   = {105, 106};
Line(106)   = {106, 107};
Line(107)   = {107, 108};
Circle(108) = {108, 114, 109};
Line(109)   = {109, 110};
Circle(110) = {110, 113, 111};
Line(111)   = {111, 112};
Line(112)   = {112, 101};

Line Loop(113) = {101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112};
Plane Surface(114) = {113};

Line(201)={1, 101};
Line(202)={2, 102};
Line Loop(301) = {1, 202, -101, -201};
Plane Surface(302) = {301};

Line(203)={3,103};
Line Loop(303) = {2, 203, -102, -202};
Ruled Surface(304) = {303};

Line(204)={4,104};
Line Loop(305) = {3, 204, -103, -203};
Plane Surface(306) = {305};

Line(205)={5,105};
Line Loop(307) = {4, 205, -104, -204};
Ruled Surface(308) = {307};

Line(206)={6,106};
Line Loop(309) = {5, 206, -105, -205};
Plane Surface(310) = {309};
 
Line(207)={7,107};
Line Loop(311) = {6, 207, -106, -206};
Plane Surface(312) = {311};
 
Line(208)={8,108};
Line Loop(313) = {7, 208, -107, -207};
Plane Surface(314) = {313};

Line(209)={9,109};
Line Loop(315) = {8, 209, -108, -208};
Ruled Surface(316) = {315};

Line(210)={10,110};
Line Loop(317) = {9, 210, -109, -209};
Plane Surface(318) = {317};

Line(211)={11,111};
Line Loop(319) = {10, 211, -110, -210};
Ruled Surface(320) = {319};
 
Line(212)={12,112};
Line Loop(321) = {11, 212, -111, -211};
Plane Surface(322) = {321};

Line Loop(323) = {12, 201, -112, -212};
Plane Surface(324) = {323};

Surface Loop(324)={14, 114, 302, 304, 306, 308, 310, 312, 314, 316, 318, 320, 322, 324};
Volume(325)={324};

//plate
plate_d = 10*mm;

Point(51) = {-plate_d-gap, -5*mm,  -5*mm, lc_plate};
Point(52) = {-0*mm-gap, -5*mm,  -5*mm, lc_plate};
Point(53) = {-0*mm-gap, 55*mm,  -5*mm, lc_plate};
Point(54) = {-plate_d-gap, 55*mm,  -5*mm, lc_plate};

Point(55) = {-plate_d-gap, -5*mm,  15*mm, lc_plate};
Point(56) = {-0*mm-gap, -5*mm,  15*mm, lc_plate};
Point(57) = {-0*mm-gap, 55*mm,  15*mm, lc_plate};
Point(58) = {-plate_d-gap, 55*mm,  15*mm, lc_plate};

Line(51)={51,52};
Line(52)={52,53};
Line(53)={53,54};
Line(54)={54,51};

Line(55)={55,56};
Line(56)={56,57};
Line(57)={57,58};
Line(58)={58,55};

Line(151)={51, 55};
Line(152)={52, 56};
Line(153)={53, 57};
Line(154)={54, 58};

Line Loop(251)={51, 152, -55, -151};
Plane Surface(252) = {251};
Line Loop(253)={52, 153, -56, -152};
Plane Surface(254) = {253};
Line Loop(255)={53, 154, -57, -153};
Plane Surface(256) = {255};
Line Loop(257)={54, 151, -58, -154};
Plane Surface(258) = {257};

Line Loop(259)={51, 52, 53, 54};
Plane Surface(260) = {259};
Line Loop(261)={55, 56, 57, 58};
Plane Surface(262) = {261};

Surface Loop(263)={252, 254, 256, 258, 260, 262};
Volume(264)={263};

Translate {0*mm, 0, 0} {
  Volume{264}; 
}

//Inductor 
Point(20) = { 5*mm, 15*mm,   5*mm, lc_ind};
Point(21) = {25*mm, 15*mm,  25*mm, lc_ind};
Point(22) = {45*mm, 15*mm,   5*mm, lc_ind};
Point(23) = {25*mm, 15*mm, -15*mm, lc_ind};

Point(24) = {15*mm, 15*mm,   5*mm, lc_ind};
Point(25) = {25*mm, 15*mm,  15*mm, lc_ind};
Point(26) = {35*mm, 15*mm,   5*mm, lc_ind};
Point(27) = {25*mm, 15*mm, - 5*mm, lc_ind};

Point(28) = {25*mm, 15*mm, 5*mm};

Circle(20) = {20, 28, 21};
Circle(21) = {21, 28, 22};
Circle(22) = {22, 28, 23};
Circle(23) = {23, 28, 20};

Circle(24) = {24, 28, 25};
Circle(25) = {25, 28, 26};
Circle(26) = {26, 28, 27};
Circle(27) = {27, 28, 24};


Point(30) = { 5*mm, 35*mm,   5*mm, lc_ind};
Point(31) = {25*mm, 35*mm,  25*mm, lc_ind};
Point(32) = {45*mm, 35*mm,   5*mm, lc_ind};
Point(33) = {25*mm, 35*mm, -15*mm, lc_ind};

Point(34) = {15*mm, 35*mm,   5*mm, lc_ind};
Point(35) = {25*mm, 35*mm,  15*mm, lc_ind};
Point(36) = {35*mm, 35*mm,   5*mm, lc_ind};
Point(37) = {25*mm, 35*mm, - 5*mm, lc_ind};

Point(38) = {25*mm, 35*mm, 5*mm};

Circle(30) = {30, 38, 31};
Circle(31) = {31, 38, 32};
Circle(32) = {32, 38, 33};
Circle(33) = {33, 38, 30};

Circle(34) = {34, 38, 35};
Circle(35) = {35, 38, 36};
Circle(36) = {36, 38, 37};
Circle(37) = {37, 38, 34};

Line(220) = {20, 30};
Line(221) = {21, 31};
Line(222) = {22, 32};
Line(223) = {23, 33};

Line(224) = {24, 34};
Line(225) = {25, 35};
Line(226) = {26, 36};
Line(227) = {27, 37};

Line Loop(420) = {20, 221, -30, -220};
Ruled Surface(421) = {420};
Line Loop(422) = {21, 222, -31, -221};
Ruled Surface(423) = {422};
Line Loop(424) = {22, 223, -32, -222};
Ruled Surface(425) = {424};
Line Loop(426) = {23, 220, -33, -223};
Ruled Surface(427) = {426};

Line Loop(430) = {24, 225, -34, -224};
Ruled Surface(431) = {430};
Line Loop(432) = {25, 226, -35, -225};
Ruled Surface(433) = {432};
Line Loop(434) = {26, 227, -36, -226};
Ruled Surface(435) = {434};
Line Loop(436) = {27, 224, -37, -227};
Ruled Surface(437) = {436};

Line Loop(428) = {20,21,22,23};
Line Loop(429) = {24,25,26,27};
Plane Surface(440) = {428, 429};

Line Loop(438) = {30,31,32,33};
Line Loop(439) = {34,35,36,37};
Plane Surface(441) = {438, 439};

Surface Loop(442) = {421, 423, 425, 427, 431, 433, 435, 437, 440, 441};
Volume(443) = {442};



scale = 4 ;
//air
axl=-300*mm/scale;  //left of airbox 
axr=300*mm/scale;  //right of airbox 
ayb=-300*mm/scale; //bottom of airbox
ayt=1.5*300*mm/scale;  //top of airbox
azb=-300*mm/scale; //back of airbox
azf=300*mm/scale;  //front of airbos
 
Point(80) = {axl, ayb, azf, lc_air};
Point(81) = {axr, ayb, azf, lc_air};
Point(82) = {axr, ayt, azf, lc_air};
Point(83) = {axl, ayt, azf, lc_air};

Point(84) = {axl, ayb, azb, lc_air};
Point(85) = {axr, ayb, azb, lc_air};
Point(86) = {axr, ayt, azb, lc_air};
Point(87) = {axl, ayt, azb, lc_air};

Line(80) = {80,81};
Line(81) = {81,82};
Line(82) = {82,83};
Line(83) = {83,80};

Line(84) = {84,85};
Line(85) = {85,86};
Line(86) = {86,87};
Line(87) = {87,84};

Line(180) = {80,84};
Line(181) = {81,85};
Line(182) = {82,86};
Line(183) = {83,87};


Line Loop(280) = {80, 81, 82, 83};
Plane Surface(281)={280};
Line Loop(282) = {81, 182, -85, -181};
Plane Surface(283)={282};
Line Loop(284) = {84, 85, 86, 87};
Plane Surface(285)={284};
Line Loop(286) = {83, 180, -87, -183};
Plane Surface(287)={286};
Line Loop(288) = {80, 181, -84, -180};
Plane Surface(289)={288};
Line Loop(290) = {82, 183, -86, -182};
Plane Surface(291)={290};

Surface Loop(292) = {281, 283, 285, 287, 289, 291};
Volume(293)={292, 442, 324, 263};


//physical stuff
Physical Volume(1000) = {325}; //Left half core
Physical Volume(1050) = {264}; //Plate
Physical Volume(1001) = {443}; //Inductor 
Physical Volume(1003) = {293}; //Air

//Skin of Air to set boundary for magnetic potential
Physical Surface(1004) = {281, 283, 285, 287, 289, 291}; //outside edge of air (collection of surfaces)

surfCore[] = Boundary{Volume{325};};
surfPlate[] = Boundary{Volume{264};};

Physical Surface(1005) = {surfCore[]}; //skin core
Physical Surface(1006) = {surfPlate[]}; //skin core




