lc= 100;

//Point(1) = {0, 50, 338,lc};
//Point(2) = {25, 25, 338,lc};
//Point(3) = {0, 0, 338,lc};
//Point(4) = {-25, 25, 338,lc};
Point(1) = {0, 40, 338,lc};
Point(2) = {15, 25, 338,lc};
Point(3) = {0, 10, 338,lc};
Point(4) = {-15, 25, 338,lc};
Point(5) = {-15, 40, 338,lc};
Point(6) = {-15, 10, 338,lc};
Point(7) = {15, 10, 338,lc};
Point(8) = {15, 40, 338,lc};
Point(9) = {-200, 225,938,lc};
Point(10) = {-200, -175, 938,lc};
Point(11) = {200, -175, 938,lc};
Point(12) = {200, 225, 938,lc};

Point(13) = {-500, -500, 310,lc};
Point(14) = {-500, 0, 310,lc};
Point(15) = {500, -500, 310,lc};
Point(16) = {500, 0, 310,lc};
Point(17) = {-500, -500, 300,lc};
Point(18) = {-500, 0, 300,lc};
Point(19) = {500, 0, 300,lc};
Point(20) = {500, -500, 300,lc};

Point(21) = {-500, -500, 300,lc};
Point(22) = {-500, 500, 300,lc};
Point(23) = {500, -500, 300,lc};
Point(24) = {500, 500, 300,lc};
Point(25) = {-500, -500, 0,lc};
Point(26) = {-500, 500, 0,lc};
Point(27) = {500, 500, 0,lc};
Point(28) = {500, -500, 0,lc};
Point(30) = {0, 25, 338,lc};
Point(57) = {500, 500, 1000,lc};
Point(58) = {-500, 500, 1000,lc};
Point(60) = {500, -500, 1000,lc};
Point(61) = {-500, -500, 1000,lc};
//Point(62) = {0, 25, 338,lc};
//Point(63) = {25, 25, 338,lc};
//Point(64) = {0, 50, 338,lc};
//Point(65) = {-25, 25, 338,lc};
//Point(66) = {0, 0, 338,lc};
//new sphere
//Point(67) = {0, 25, 313,lc};
//Point(68) = {0, 25, 363,lc};
Point(67) = {0, 25, 323,lc};
Point(68) = {0, 25, 353,lc};
Line(6) = {5, 4};
Line(7) = {1, 5};
Line(8) = {6, 3};
Line(9) = {4, 6};
Line(10) = {7, 2};
Line(11) = {3, 7};
Line(12) = {8, 1};
Line(13) = {2, 8};
Line(14) = {9, 10};
Line(15) = {10, 11};
Line(16) = {11, 12};
Line(17) = {12, 9};
Line(18) = {10, 6};
Line(19) = {9, 5};
Line(20) = {12, 8};
Line(21) = {11, 7};
Line(22) = {13, 14};
Line(23) = {15, 13};
Line(24) = {16, 15};
Line(25) = {14, 16};
Line(26) = {17, 18};
Line(27) = {18, 19};
Line(28) = {19, 20};
Line(29) = {20, 17};
Line(30) = {18, 14};
//Line(31) = {17, 13};
//Line(32) = {20, 15};
Line(33) = {19, 16};
Line(34) = {21, 22};
Line(35) = {23, 21};
Line(36) = {24, 23};
Line(37) = {22, 24};
Line(38) = {25, 26};
Line(39) = {26, 27};
Line(40) = {27, 28};
Line(41) = {28, 25};
Line(42) = {26, 22};
Line(43) = {25, 21};
Line(44) = {28, 23};
Line(45) = {27, 24};
Line(46) = {22, 58};
Line(47) = {24, 57};
Line(48) = {57, 58};
Line(49) = {57, 60};
//Line(50) = {23, 60};
Line(51) = {60, 61};
//Line(52) = {61, 21};
Line(53) = {61, 58};
Line(54) = {19, 24};
Line(55) = {18, 22};
Line(56) = {60,15};
Line(57) = {61,13};

Circle(72) = {2, 30, 1};
Circle(73) = {1, 30, 4};
Circle(74) = {4, 30, 3};
Circle(75) = {3, 30, 2};
Circle(76) = {1, 30, 67};
Circle(77) = {67, 30, 3};
Circle(78) = {3, 30, 68};
Circle(79) = {68, 30, 1};
Circle(80) = {2, 30, 68};
Circle(81) = {68, 30, 4};
Circle(82) = {4, 30, 67};
Circle(83) = {67, 30, 2};
Line Loop(7) = {14, 15, 16, 17};
Plane Surface(7) = {7};
Line Loop(8) = {6, 9, -18, -14, 19};
Plane Surface(8) = {8};
Line Loop(9) = {12, 7, -19, -17, 20};
Plane Surface(9) = {9};
Line Loop(10) = {10, 13, -20, -16, 21};
Plane Surface(10) = {10};
Line Loop(11) = {8, 11, -21, -15, 18};
Plane Surface(11) = {11};
Line Loop(12) = {22, 25, 24, 23};
Plane Surface(12) = {12};
Line Loop(13) = {26, 27, 28, 29};
Plane Surface(13) = {13};
//Line Loop(14) = {22, -30, -26, 31};
//Plane Surface(14) = {14};
//Line Loop(15) = {23, -31, -29, 32};
//Plane Surface(15) = {15};
//Line Loop(16) = {24, -32, -28, 33};
//Plane Surface(16) = {16};
Line Loop(17) = {25, -33, -27, 30};
Plane Surface(17) = {17};

//Translate {0, 0, -1} {
// Surface{12, 13, 17, 16, 14, 15};
//}

Line Loop(18) = {34, 37, 36, 35};
Plane Surface(18) = {18};

Line Loop(19) = {38, 39, 40, 41};
Plane Surface(19) = {19};
Line Loop(20) = {34, -42, -38, 43};
Plane Surface(20) = {20};
Line Loop(21) = {35, -43, -41, 44};
Plane Surface(21) = {21};
Line Loop(22) = {36, -44, -40, 45};
Plane Surface(22) = {22};
Line Loop(23) = {37, -45, -39, 42};
Plane Surface(23) = {23};
Line Loop(55) = {51, 53, -48, 49};
Plane Surface(55) = {55};
Line Loop(57) = {48, -46, 37, 47};
Plane Surface(57) = {57};

Line Loop(58) = {37,-54,-27,55};
Plane Surface(58) = {58};

Line Loop(59) = {53, -46, -55,30,-22, -57};
Plane Surface(59) = {59};

Line Loop(66) = {51, 57, -23, -56};
Plane Surface(66) = {66};


Line Loop(68) = { -49, -47, -54,33,24,-56};
Plane Surface(68) = {68};

Line Loop(71) = {12, 7, 6, 9, 8, 11, 10, 13};
Plane Surface(71) = {71};
Line Loop(85) = {73, -81, 79};
Ruled Surface(85) = {85};
Line Loop(87) = {81, 74, 78};
Ruled Surface(87) = {87};
Line Loop(89) = {-79, -80, 72};
Ruled Surface(89) = {89};
Line Loop(91) = {-82, -73, 76};
Ruled Surface(91) = {91};
Line Loop(93) = {-76, -72, -83};
Ruled Surface(93) = {93};
Line Loop(95) = {-74, 82, 77};
Ruled Surface(95) = {95};
Line Loop(97) = {-78, 75, 80};
Ruled Surface(97) = {97};
Line Loop(99) = {-75, -77, 83};
Ruled Surface(99) = {99};
Line Loop(107) = {11, 10, -75};
Plane Surface(107) = {107};
Line Loop(109) = {7, 6, -73};
Plane Surface(109) = {109};
Line Loop(111) = {9, 8, -74};
Plane Surface(111) = {111};
Line Loop(113) = {12, -72, 13};
Plane Surface(113) = {113};

//Line Loop(200) = {34, 37, 36, 35};
//Plane Surface(200) = {200};
//try 58 and 13 instead of 200, works (with delauny)
Surface Loop(3) = {58,13, 19, 20, 21, 22, 23};
Volume(3) = {3};

//translate the tip around from its initial position

Translate {0, 0, -20} {
  Surface{7, 10, 8, 11, 9, 89, 87, 95, 93, 91, 99, 97, 85, 71,107,111,109,113};
}

Surface Loop(114) = {58,17,12,66, 55, 57, 68, 59, 7, 10, 8, 11, 9, 95, 93, 91, 99,107,111,109,113};
Volume(115) = {114};

Delete {
  Surface{85, 89, 97, 87};
}
Delete {
  Surface{71};
}

Field[1] = Box;
Field[1].VIn = lc/200;
Field[1].VOut = lc;
Field[1].XMax = 20;
Field[1].XMin = -20;
Field[1].YMax = 40;
Field[1].YMin = -5;
Field[1].ZMax = 311;
Field[1].ZMin = 298;

Field[2] = Attractor;
Field[2].EdgesList = {25};
Field[2].NNodesByEdge = 50;

Field[3] = Threshold;
Field[3].DistMax = 10;
Field[3].DistMin = 0;
Field[3].IField = 2;
Field[3].LcMax = lc;
Field[3].LcMin = lc/20;

Field[4] = Box;
Field[4].VIn = lc/20;
Field[4].VOut = lc;
Field[4].XMax = 50;
Field[4].XMin = -50;
Field[4].YMax = 75;
Field[4].YMin = -25;
Field[4].ZMax = 350;
Field[4].ZMin = 275;

// need a box between the tip and electrode edge, not finely enough meshed

Field[5] = Box;
Field[5].VIn = lc/200;
Field[5].VOut = lc;
Field[5].XMax = 20;
Field[5].XMin = -20;
Field[5].YMax = 15;
Field[5].YMin = -5;
Field[5].ZMax = 312;
Field[5].ZMin = 300;


Field[6] = Min;
Field[6].FieldsList = {1,3,4,5};
Background Field = 6;

