/*
-----------------------------------------------------------
    This create geometry of 3D Magnet Assembly for
      Cuvette Washing using Spinning
-----------------------------------------------------------
*/

/*  define some parameters */

air_b = 1e-1;  // boundary for air
mag_w = 3.18e-3;  // magnet width
mag_l = 14e-3;  //magnet length
mag_h = 6.35e-3;  //magnet height

mag1x = 163.855e-3; // magnet 1 stating vertex X-coord
mag1y = mag_h; // magnet 1 stating vertex Y-coord
mag1z = 0.0e-3; // magnet 1 stating vertex Z-coord
mag4x = 167.03e-3; // magnet 4 stating vertex X-coord
mag4y = mag_h; // magnet 4 stating vertex Y-coord
mag4z = 0.0e-3; // magnet 4 stating vertex Z-coord
mag7x = 160.8445e-3; // magnet 7 stating vertex X-coord
mag7y = mag_h; // magnet 7 stating vertex Y-coord
mag7z = -31.0265e-3; // magnet 7 stating vertex Z-coord
mag10x = 163.9612e-3; // magnet 10 stating vertex X-coord
mag10y = mag_h; // magnet 10 stating vertex Y-coord
mag10z = -31.8708e-3; // magnet 10 stating vertex Z-coord

mag13x = 163.8534e-3; // magnet 13 stating vertex X-coord
mag13y = mag_h; // magnet 13 stating vertex Y-coord
mag13z = 0.715e-3; // magnet 13 stating vertex Z-coord
mag16x = 167.0284e-3; // magnet 16 stating vertex X-coord
mag16y = mag_h; // magnet 16 stating vertex Y-coord
mag16z = 0.7288e-3; // magnet 16 stating vertex Z-coord
mag19x = 161.24e-3; // magnet 19 stating vertex X-coord
mag19y = mag_h; // magnet 19 stating vertex Y-coord
mag19z = 29.1569e-3; // magnet 19 stating vertex Z-coord
mag22x = 164.3643e-3; // magnet 22 stating vertex X-coord
mag22y = mag_h; // magnet 22 stating vertex Y-coord
mag22z = 29.7219e-3; // magnet 22 stating vertex Z-coord

mag25x = 31.7579e-3; // air corner 1 in X-dir
mag25y = 0.0e-3;     // air corner 1 in Y-dir
mag25z = 55.5647e-3; // air corner 1 in Z-dir
mag26x = 31.0278e-3; // air corner 2 in X-dir
mag26y = 0.0e-3;     // air corner 2 in Y-dir
mag26z = -55.9757e-3; // air corner 2 in Z-dir
mag27x = 133.9785e-3; // air corner 3 in X-dir
mag27y = 0.0e-3;     // air corner 3 in Y-dir
mag27z = 234.4137e-3; // air corner 3 in Z-dir
mag28x = 130.8986e-3; // air corner 4 in X-dir
mag28y = 0.0e-3;     // air corner 4 in Y-dir
mag28z = -236.1473e-3; // air corner 4 in Z-dir


p = mag_w/4;   // characterisitcs length for the magnet
p1 = p/2;      // characteristics length for the gap
q = 8*p;   //characterisitcs length for air

Point(1) = {0, mag1y, 0, p};
Point(2) = {0, mag1y - mag_h, 0, p};
Point(3) = {0, mag1y - (2 * mag_h), 0, p};
Point(101) = {  mag1x, mag1y, mag1z, p };
Point(102) = {  mag1x, mag1y - mag_h, mag1z, p };
Point(103) = {  mag1x, mag1y - (2 * mag_h), mag1z, p };
Point(104) = {  mag4x, mag4y, mag4z, p };
Point(105) = {  mag4x, mag4y - mag_h, mag4z, p };
Point(106) = {  mag4x, mag4y - (2 * mag_h), mag4z, p };
Point(107) = {  mag7x, mag7y, mag7z, p };
Point(108) = {  mag7x, mag7y - mag_h, mag7z, p };
Point(109) = {  mag7x, mag7y - (2 * mag_h), mag7z, p };
Point(110) = {  mag10x, mag10y, mag10z, p };
Point(111) = {  mag10x, mag10y - mag_h, mag10z, p };
Point(112) = {  mag10x, mag10y - (2 * mag_h), mag10z, p };

Point(113) = {  mag13x, mag13y, mag13z, p };
Point(114) = {  mag13x, mag13y - mag_h, mag13z, p };
Point(115) = {  mag13x, mag13y - (2 * mag_h), mag13z, p };
Point(116) = {  mag16x, mag16y, mag16z, p };
Point(117) = {  mag16x, mag16y - mag_h, mag16z, p };
Point(118) = {  mag16x, mag16y - (2 * mag_h), mag16z, p };
Point(119) = {  mag19x, mag19y, mag19z, p };
Point(120) = {  mag19x, mag19y - mag_h, mag19z, p };
Point(121) = {  mag19x, mag19y - (2 * mag_h), mag19z, p };
Point(122) = {  mag22x, mag22y, mag22z, p };
Point(123) = {  mag22x, mag22y - mag_h, mag22z, p };
Point(124) = {  mag22x, mag22y - (2 * mag_h), mag22z, p };

Line(1) = {101, 102};
Line(2) = {102, 103};
Line(3) = {103, 106};
Line(4) = {106, 105};
Line(5) = {105, 104};
Line(6) = {104, 101};
Line(7) = {102, 105};
Line(8) = {107, 108};
Line(9) = {108, 109};
Line(10) = {109, 112};
Line(11) = {112, 111};
Line(12) = {111, 110};
Line(13) = {110, 107};
Line(14) = {108, 111};
Circle(15) = {101, 1, 107};
Circle(16) = {102, 2, 108};
Circle(17) = {103, 3, 109};
Circle(18) = {104, 1, 110};
Circle(19) = {105, 2, 111};
Circle(20) = {106, 3, 112};
Line Loop(21) = {1, 16, -8, -15};
Ruled Surface(22) = {21};
Line Loop(23) = {2, 17, -9, -16};
Ruled Surface(24) = {23};
Line Loop(25) = {18, -12, -19, 5};
Ruled Surface(26) = {25};
Line Loop(27) = {19, -11, -20, 4};
Ruled Surface(28) = {27};
Line Loop(29) = {6, 15, -13, -18};
Plane Surface(30) = {29};
Line Loop(31) = {7, 19, -14, -16};
Plane Surface(32) = {31};
Line Loop(33) = {3, 20, -10, -17};
Plane Surface(34) = {33};
Line Loop(35) = {13, 8, 14, 12};
Plane Surface(36) = {35};
Line Loop(37) = {14, -11, -10, -9};
Plane Surface(38) = {37};
Line Loop(39) = {6, 1, 7, 5};
Plane Surface(40) = {39};
Line Loop(41) = {7, -4, -3, -2};
Plane Surface(42) = {41};
Surface Loop(43) = {22, 40, 30, 36, 26, 32};
Volume(44) = {43};
Surface Loop(45) = {24, 42, 28, 38, 34, 32};
Volume(46) = {45};
Line(47) = {113, 114};
Line(48) = {114, 115};
Line(49) = {115, 118};
Line(50) = {118, 117};
Line(51) = {117, 116};
Line(52) = {113, 116};
Line(53) = {114, 117};
Line(54) = {119, 120};
Line(55) = {120, 121};
Line(56) = {121, 124};
Line(57) = {124, 123};
Line(58) = {123, 122};
Line(59) = {122, 119};
Line(60) = {120, 123};
Circle(61) = {113, 1, 119};
Circle(62) = {114, 2, 120};
Circle(63) = {115, 3, 121};
Circle(64) = {116, 1, 122};
Circle(65) = {117, 2, 123};
Circle(66) = {118, 3, 124};
Line Loop(67) = {54, -62, -47, 61};
Ruled Surface(68) = {67};
Line Loop(69) = {55, -63, -48, 62};
Ruled Surface(70) = {69};
Line Loop(71) = {64, -58, -65, 51};
Ruled Surface(72) = {71};
Line Loop(73) = {65, -57, -66, 50};
Ruled Surface(74) = {73};
Line Loop(75) = {64, 59, -61, 52};
Ruled Surface(76) = {75};
Line Loop(77) = {65, -60, -62, 53};
Ruled Surface(78) = {77};
Line Loop(79) = {66, -56, -63, 49};
Ruled Surface(80) = {79};
Line Loop(81) = {59, 54, 60, 58};
Plane Surface(82) = {81};
Line Loop(83) = {60, -57, -56, -55};
Plane Surface(84) = {83};
Line Loop(85) = {52, -51, -53, -47};
Plane Surface(86) = {85};
Line Loop(87) = {53, -50, -49, -48};
Plane Surface(88) = {87};
Surface Loop(89) = {68, 82, 76, 72, 86, 78};
Volume(90) = {89};
Surface Loop(91) = {70, 84, 74, 80, 88, 78};
Volume(92) = {91};

// air volume
Point(125) = {mag25x, mag25y - (air_b / 2), mag25z, q};
Point(126) = {mag26x, mag26y - (air_b / 2), mag26z, q};
Point(127) = {mag27x, mag27y - (air_b / 2), mag27z, q};
Point(128) = {mag28x, mag28y - (air_b / 2), mag28z, q};
Point(129) = {mag25x, mag25y + (air_b / 2), mag25z, q};
Point(130) = {mag26x, mag26y + (air_b / 2), mag26z, q};
Point(131) = {mag27x, mag27y + (air_b / 2), mag27z, q};
Point(132) = {mag28x, mag28y + (air_b / 2), mag28z, q};
Point(133) = {0, mag25y - (air_b / 2), 0, p};
Point(134) = {0, (air_b / 2), 0, p};
Circle(93) = {129, 134, 130};
Circle(94) = {125, 133, 126};
Circle(95) = {131, 134, 132};
Circle(96) = {127, 133, 128};
Line(97) = {130, 132};
Line(98) = {126, 128};
Line(99) = {126, 130};
Line(100) = {125, 129};
Line(101) = {129, 131};
Line(102) = {125, 127};
Line(103) = {127, 131};
Line(104) = {128, 132};
Line Loop(105) = {93, -99, -94, 100};
Ruled Surface(106) = {105};
Line Loop(107) = {95, -104, -96, 103};
Ruled Surface(108) = {107};
Line Loop(109) = {95, -97, -93, 101};
Plane Surface(110) = {109};
Line Loop(111) = {96, -98, -94, 102};
Plane Surface(112) = {111};
Line Loop(113) = {104, -97, -99, 98};
Plane Surface(114) = {113};
Line Loop(115) = {101, -103, -102, 100};
Plane Surface(116) = {115};
Surface Loop(117) = {110, 108, 114, 106, 112, 116};
Surface Loop(118) = {30, 40, 22, 36, 26, 34, 42, 28, 38, 24};
Surface Loop(119) = {76, 72, 82, 68, 86, 80, 74, 84, 70, 88};
Volume(120) = {117, 118, 119};

Physical Volume(600) = {44}; //magnet #1
Physical Volume(601) = {46}; //magnet #2
Physical Volume(602) = {90}; //magnet #3
Physical Volume(603) = {92}; //magnet #4
Physical Volume(605) = {120}; //air
Physical Surface(1000) = {106, 108, 110, 112, 114, 116};  //system boundary

