//******************** Channel *********************//

Point(1) = {0, 0, 0};
Point(3) = {0, 25, 0};
Point(5) = {0, 0, 250};
Point(6) = {0, 25, 250};
Point(7) = {0, 0, 340};
Point(8) = {0, 90, 340};
Point(9) = {0, 90, 250};
Point(10) = {0, 25, 340};

Line(1) = {1, 3};
Line(2) = {3, 6};
Line(3) = {6, 9};
Line(4) = {9, 8};
Line(5) = {8, 10};
Line(6) = {10, 7};
Line(7) = {7, 5};
Line(8) = {5, 1};
Line(9) = {6, 5};
Line(10) = {6, 10};

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

Extrude {230, 0, 0} {
  Surface{12, 14, 16};
}
Extrude {120, 0, 0} {
  Surface{60, 82, 38};
}

//***************** Tank *******************//

Point(300)={175,0,-1700};
Point(301)={825,0,-1700};
Point(302)={-475,0,-1700};
Point(303)={175,650,-1700};
Point(304)={175,-650,-1700};

Circle(203) = {302, 300, 304};
Circle(204) = {304, 300, 301};
Circle(205) = {301, 300, 303};
Circle(206) = {303, 300, 302};
Line Loop(207) = {203, 204, 205, 206};
Plane Surface(208) = {207};
Extrude {0, 0, 1700}{
 Surface {208};
}
Delete {
  Volume{7};
}
Delete {
  Surface{230};
}

Line(230) = {305, 1};
Line(231) = {62, 312};
Line Loop(232) = {230, 32, 142, 231, -211, -210};
Plane Surface(233) = {232};
Line Loop(234) = {213, 230, 1, 23, 133, -131, 231, 212};
Plane Surface(235) = {234};
Surface Loop(236) = {217, 208, 221, 225, 229, 235, 233, 37, 147};
Volume(237) = {236};


//***************** Outlet ************************//

Point(400)={230,-4,340};
Point(401)={230,-4,250};
Point(402)={350,-4,340};
Point(403)={350,-4,250};
Point(405)={290,-4,340};
Point(406)={230,-4,295};
Point(407)={350,-4,295};
Point(408)={290,-4,295};  // center for the point 409 -> 412
Point(409)={290,-4,795};
Point(410)={290,-504,295};
Point(411)={790,-4,295};
Point(412)={-210,-4,295};
Point(413) = {716.35, -4, 33.8};
Point(414) = {-136.35, -4, 33.8};
Point(415) = {290, -430,33.8};
Point(416) = {290, -4, 33.8};  // center for the point 413 -> 415


Line(238) = {407, 402};
Line(239) = {402, 42};
Line(240) = {402, 405};
Line(241) = {405, 400};
Line(242) = {400, 26};
Line(243) = {400, 406};
Line(244) = {406, 401};
Line(245) = {401, 16};
Line(246) = {401, 403};
Line(247) = {403, 38};
Line(248) = {403, 407};
Circle(249) = {411, 408, 409};
Circle(250) = {409, 408, 412};
Circle(251) = {411, 408, 413};
Circle(252) = {412, 408, 414};
Circle(253) = {412, 408, 410};
Circle(254) = {410, 408, 411};
Circle(255) = {415, 408, 410};
Circle(256) = {414, 416, 415};
Circle(257) = {415, 416, 413};
Circle(278) = {410, 408, 409};
Line(258) = {413, 414};
Line(259) = {412, 406};
Line(260) = {407, 411};
Line(261) = {405, 409};

Line Loop(262) = {261, -249, -260, 238, 240};
Plane Surface(263) = {262};
Line Loop(264) = {247, 85, -239, -238, -248};
Plane Surface(265) = {264};
Line Loop(266) = {239, -94, -242, -241, -240};
Plane Surface(267) = {266};
Line Loop(268) = {41, -242, 243, 244, 245};
Plane Surface(269) = {268};
Line Loop(270) = {245, 90, -247, -246};
Plane Surface(271) = {270};
Line Loop(272) = {246, 248, 238, 240, 241, 243, 244};
Plane Surface(273) = {272};
Line Loop(274) = {261, 250, 259, -243, -241};
Plane Surface(275) = {274};
Line Loop(276) = {259, 244, 246, 248, 260, 251, 258, -252};
Plane Surface(277) = {276};
Line Loop(279) = {278, -249, -254};
Ruled Surface(280) = {279};
Line Loop(281) = {254, 251, -257, 255};
Ruled Surface(282) = {281};
Line Loop(283) = {253, 278, 250};
Ruled Surface(284) = {283};
Line Loop(285) = {252, 256, 255, -253};
Ruled Surface(286) = {285};
Line Loop(287) = {257, 258, 256};
Ruled Surface(288) = {287};

Surface Loop(289) = {265, 271, 269, 267, 95, 273};
Volume(290) = {289};
Surface Loop(291) = {280, 284, 286, 277, 275, 263, 282, 288, 273};
Volume(292) = {291};


//*************** Meshing **********************//
Field[1] = Attractor;
Field[1].FacesList = { 12, 14, 16, 33, 25, 135, 148, 143, 126, 117, 73, 69, 113, 77, 121, 99, 104, 55, 51,95};

Field[2] = Threshold;
Field[2].DistMax = 542;
Field[2].DistMin = 0;
Field[2].IField = 1;
Field[2].LcMax = 80;
Field[2].LcMin = 8;

Field[3] = Restrict;
Field[3].IField = 2;
Field[3].RegionsList = {296, 294, 302, 298, 300, 304, 305,292};
Background Field = 3;



//************** Physical groups ****************//




Delete {
  Volume{4, 290, 5, 3, 2, 1, 6, 292, 237};
}

Volume(292) = {236};
Surface Loop(293) = {37, 38, 12, 25, 33, 29};
Volume(294) = {293};
Surface Loop(295) = {147, 143, 148, 135, 38, 91};
Volume(296) = {295};
Surface Loop(297) = {16, 69, 73, 77, 82, 59};
Volume(298) = {297};
Surface Loop(299) = {14, 51, 55, 29, 60, 59};
Volume(300) = {299};
Surface Loop(301) = {121, 126, 113, 117, 82, 103};
Volume(302) = {301};
Surface Loop(303) = {99, 104, 103, 60, 91, 95};
Volume(304) = {303};
Volume(305) = {289};
Volume(306) = {291};
Physical Surface(307) = {208};  //Inlet
Physical Surface(308) = {284, 280, 282, 286, 288};   //outlet
Physical Surface(309) = {225, 221, 235, 233, 217, 229, 277, 263, 275, 25, 135, 117, 73, 148, 104, 126, 265, 99, 267, 121, 55, 77, 14, 16, 12, 33, 143, 69, 113, 269, 271, 51};  //wall
Physical Volume(310) = {302, 304, 298, 300, 305, 306, 294, 296, 292};



Mesh.ScalingFactor = 0.001;
