// Gmsh project created on Tue Jul 31 18:27:24 2018

SetFactory("OpenCASCADE"); //Built-in

//r1 = 0.1/(Sin(45*Pi/180));
//r2 = 0.11/(Sin(45*Pi/180));
//r3 = 0.4/(Sin(45*Pi/180));

Point(1) = {0, 0, 0, 1};
Point(2) = {0.1,0.1, 0, 0.001};
Point(3) = {-0.1, 0.1, 0, 0.001};
Point(4) = {-0.1, -0.1, 0, 0.001};
Point(5) = {0.1, -0.1, 0, 0.001};

Point(6) = {0.101, 0.101, 0, 0.001};
Point(7) = {-0.101, 0.101, 0, 0.001};
Point(8) = {-0.101, -0.101, 0, 0.001};
Point(9) = {0.101, -0.101, 0, 0.001};

Point(10) = {0.3, 0.3, 0, 0.1};
Point(11) = {-0.3, 0.3, 0, 0.1};
Point(12) = {-0.3, -0.3, 0, 0.1};
Point(13) = {0.3, -0.3, 0, 0.1};

Point(14) = {3.6, 1.6, 0, 1};
Point(15) = {-1.2, 1.6, 0, 1};
Point(16) = {-1.2, -1.6, 0, 1};
Point(17) = {3.6, -1.6, 0, 1};

Point(18) = {0.3, 1.6, 0, 1};
Point(19) = {-0.3, 1.6, 0, 1};
Point(20) = {-0.3, -1.6, 0, 1};
Point(21) = {0.3, -1.6, 0, 1};

Point(22) = {-1.2, 0.3, 0, 1};
Point(23) = {-1.2, -0.3, 0, 1};
Point(24) = {3.6, 0.3, 0, 1};
Point(25) = {3.6, -0.3, 0, 1};

Circle(1) = {2, 1, 3};
Circle(2) = {3, 1, 4};
Circle(3) = {4, 1, 5};
Circle(4) = {5, 1, 2};

Circle(5) = {6, 1, 7};
Circle(6) = {7, 1, 8};
Circle(7) = {8, 1, 9};
Circle(8) = {9, 1, 6};

//Circle(9) = {10, 1, 11};
Line(9) = {10, 11};
//Circle(10) = {11, 1, 12};
Line(10) = {11, 12};
//Circle(11) = {12, 1, 13};
Line(11) = {12, 13};
//Circle(12) = {13, 1, 10};
Line(12) = {13, 10};

Line(13) = {14, 18};
Line(14) = {18, 19};
Line(15) = {19, 15};
Line(16) = {15, 22};
Line(17) = {22, 23};
Line(18) = {23, 16};
Line(19) = {16, 20};
Line(20) = {20, 21};
Line(21) = {21, 17};
Line(22) = {17, 25};
Line(23) = {25, 24};
Line(24) = {24, 14};

Line(25) = {10, 6};
Line(26) = {11, 7};
Line(27) = {12, 8};
Line(28) = {13, 9};
Line(29) = {6, 2};
Line(30) = {7, 3};
Line(31) = {8, 4};
Line(32) = {9, 5};

Line(33) = {18,10};
Line(34) = {19,11};
Line(35) = {22,11};
Line(36) = {23,12};
Line(37) = {20,12};
Line(38) = {21,13};
Line(39) = {25,13};
Line(40) = {24,10};



Line Loop(1) = {13, 33, -40, 24};
Plane Surface(1) = {1};
Line Loop(2) = {14, 34, -9, -33};
Plane Surface(2) = {2};
Line Loop(3) = {15, 16, 35, -34};
Plane Surface(3) = {3};
Line Loop(4) = {17, 36, -10, -35};
Plane Surface(4) = {4};
Line Loop(5) = {18, 19, 37, -36};
Plane Surface(5) = {5};
Line Loop(6) = {20, 38, -11, -37};
Plane Surface(6) = {6};
Line Loop(7) = {21, 22, 39, -38};
Plane Surface(7) = {7};
Line Loop(8) = {23, 40, -12, -39};
Plane Surface(8) = {8};
Line Loop(9) = {9, 26, -5, -25};
Plane Surface(9) = {9};
Line Loop(10) = {10, 27, -6, -26};
Plane Surface(10) = {10};
Line Loop(11) = {11, 28, -7, -27};
Plane Surface(11) = {11};
Line Loop(12) = {12, 25, -8, -28};
Plane Surface(12) = {12};

Line Loop(13) = {5, 30, -1, -29};
Plane Surface(13) = {13};
Line Loop(14) = {6, 31, -2, -30};
Plane Surface(14) = {14};
Line Loop(15) = {7, 32, -3, -31};
Plane Surface(15) = {15};
Line Loop(16) = {8, 29, -4, -32};
Plane Surface(16) = {16};


Transfinite Line {1, 5, 9, 14, 2, 6, 10, 17, 3, 7, 11, 20, 4, 8, 12, 23} = 251 Using Bump 1.5;

//Inlet side
Transfinite Line {19,35,36} = 151 Using Progression 0.99;
Transfinite Line {15} = 151 Using Progression 1.01;
//Exit side
Transfinite Line {13,39,40} = 116 Using Progression 0.97;
Transfinite Line {21} = 116 Using Progression 1.03;


//Outlet Vertical Lines
Transfinite Line {16,37,38,22,33,34} = 121 Using Progression 0.98;
Transfinite Line {18,24} = 121 Using Progression 1.02;

//Circle arc segments
Transfinite Line {25,26,27,28} = 121 Using Progression 0.983;
Transfinite Line {29,30,31,32} = 21 Using Progression 0.95;

Transfinite Surface {1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16}; Recombine Surface {1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16};

//External Flow
Extrude {0, 0, 0.1} 
{
  Surface{1:16};
  Layers{1};
  Recombine;
}

Physical Surface("frontAndBack") = {1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,62,84,106,128,150,172,194,216,238,260,282,304,326,348,370,392};
Physical Surface("inlet") = {97,115,137};
Physical Surface("outlet") = {93,71,49,61,203,185,181,159,141};
Physical Surface("cylinder") = {321,343,387,365};
Physical Volume("externalFlow") = {1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16};


