h = 0.002;
ramp_length = 7.5*h*Cos(24*Pi/180);
ramp_halfwidth = 7.5*h*Sin(24*Pi/180);

cl_ramp = h/3;
cl_near_ramp = h/2;

unstruct_ramp = 0.1;

halfwidth = 3*ramp_halfwidth;
height = 2*halfwidth;
inlet_loc = 50*h;
length = 100*h;

Mesh.Algorithm = 4; // 1=MeshAdapt, 2=Automatic, 5=Delaunay, 6=Frontal, 7=bamg, 8=delquad
Mesh.Algorithm3D = 4; // 1=Delaunay, 4=Frontal, 5=Frontal Delaunay, 6=Frontal Hex, 7=MMG3D, 9=R-tree
Mesh.Optimize=0;
Mesh.OptimizeNetgen=0;

Mesh.RecombineAll = 1;


Point(1) = {0,0,0};

Point(2) = {0,0,h};

Point(3) = {-ramp_length,0,0};

Point(4) = {-ramp_length,-ramp_halfwidth,0};

Point(5) = {-ramp_length*(1-unstruct_ramp),-ramp_halfwidth*(1-unstruct_ramp),h*unstruct_ramp};
Point(6) = {-ramp_length*(1-unstruct_ramp),-ramp_halfwidth*(1-unstruct_ramp),0};
Point(7) = {-ramp_length*(1-unstruct_ramp),0,h*unstruct_ramp};

Point(8) = {-ramp_length*unstruct_ramp,-ramp_halfwidth*unstruct_ramp,h*(1-unstruct_ramp)};
Point(9) = {-ramp_length*unstruct_ramp,-ramp_halfwidth*unstruct_ramp,0};
Point(10) = {-ramp_length*unstruct_ramp,0,(1-unstruct_ramp)*h};

Point(11) = {-ramp_length*0.95,-ramp_halfwidth*0.95,0};
//Point(12) = {-ramp_length*unstruct_ramp,-ramp_halfwidth*unstruct_ramp,(1-unstruct_ramp)*h/2};

//Point(13) = {0,0,h/2};

Point(14) = {-inlet_loc, 0, 0};
Point(15) = {-inlet_loc, -ramp_halfwidth, 0};
Point(16) = {-inlet_loc, -halfwidth, 0};

Point(17) = {-ramp_length,-halfwidth,0};
Point(18) = {-ramp_length*(1-unstruct_ramp),-halfwidth,h*unstruct_ramp};
Point(19) = {-ramp_length*(1-unstruct_ramp),-halfwidth,0};
Point(20) = {-ramp_length*0.95,-halfwidth,0};

Point(21) = {-ramp_length*unstruct_ramp,-halfwidth,h*(1-unstruct_ramp)};
Point(22) = {-ramp_length*unstruct_ramp,-halfwidth,0};
//Point(23) = {-ramp_length*unstruct_ramp,-halfwidth,(1-unstruct_ramp)*h/2};

Point(24) = {halfwidth*Tan(12*Pi/180), -halfwidth, 0};
Point(25) = {halfwidth*Tan(12*Pi/180), -halfwidth, h};
//Point(26) = {halfwidth*Tan(12*Pi/180), -halfwidth, h/2};

Point(27) = {length-inlet_loc, 0, 0};
Point(28) = {length-inlet_loc, 0, h};
//Point(29) = {length-inlet_loc, 0, h/2};

Point(30) = {length-inlet_loc, -halfwidth, 0};
Point(31) = {length-inlet_loc, -halfwidth, h};
//Point(32) = {length-inlet_loc, -halfwidth, h/2};

Point(33) = {halfwidth*Tan(12*Pi/180), -halfwidth, height};
Point(34) = {length-inlet_loc, 0, height};
Point(35) = {length-inlet_loc, -halfwidth, height};
Point(36) = {0, 0, height};
Point(37) = {-ramp_length*unstruct_ramp, -halfwidth, height};
Point(38) = {-ramp_length*unstruct_ramp,-ramp_halfwidth*unstruct_ramp,height};
Point(39) = {-ramp_length*unstruct_ramp,0,height};

Point(40) = {-ramp_length,0,height};
Point(41) = {-ramp_length,-ramp_halfwidth,height};
Point(42) = {-ramp_length*(1-unstruct_ramp),-ramp_halfwidth*(1-unstruct_ramp),height};
Point(43) = {-ramp_length*(1-unstruct_ramp),0,height};
Point(44) = {-ramp_length,-halfwidth,height};
Point(45) = {-ramp_length*(1-unstruct_ramp),-halfwidth,height};

Point(46) = {-inlet_loc, 0, height};
Point(47) = {-inlet_loc, -ramp_halfwidth, height};
Point(48) = {-inlet_loc, -halfwidth, height};

Point(49) = {-ramp_length,-ramp_halfwidth/2,0};
Point(50) = {-ramp_length*(1-unstruct_ramp),-ramp_halfwidth*(1-unstruct_ramp)/2,h*unstruct_ramp};

Point(51) = {-ramp_length,-ramp_halfwidth/2,height};
Point(52) = {-ramp_length*(1-unstruct_ramp),-ramp_halfwidth*(1-unstruct_ramp)/2,height};
Point(53) = {-ramp_length*0.125,-ramp_halfwidth/2*0.125,h*0.875};
Point(54) = {-ramp_length*0.125,-ramp_halfwidth/2*0.125,height};

Point(55) = {-inlet_loc,-ramp_halfwidth/2,0};
Point(56) = {-inlet_loc,-ramp_halfwidth/2,height};




Line(1) = {3, 7};
Line(2) = {7, 10};
Line(3) = {10, 2};
Line(4) = {2, 1};
Line(5) = {1, 9};
Line(6) = {9, 6};
Line(7) = {6, 11};
Line(8) = {11, 4};
Line(9) = {4, 49};
Line(10) = {49, 3};
Line(11) = {49, 50};
Line(12) = {50, 53};
Line(13) = {53, 10};
Line(14) = {53, 8};
Line(15) = {8, 9};
Line(16) = {8, 2};
//Line(17) = {1, 3};
Line(18) = {7, 50};
Line(19) = {50, 5};
Line(20) = {5, 6};
Line(21) = {5, 4};
Line(22) = {5, 8};
Line(23) = {4, 17};
Line(24) = {17, 20};
Line(25) = {20, 19};
Line(26) = {19, 18};
Line(27) = {18, 5};
Line(28) = {6, 19};
Line(29) = {18, 17};
Line(30) = {19, 22};
Line(31) = {18, 21};
Line(32) = {21, 8};
Line(33) = {9, 22};
Line(34) = {22, 21};
Line(35) = {24, 22};
Line(36) = {21, 25};
Line(37) = {25, 24};
Line(38) = {25, 2};
Line(39) = {1, 24};
Line(40) = {3, 40};
Line(41) = {40, 43};
Line(42) = {43, 52};
Line(43) = {52, 42};
Line(44) = {42, 41};
Line(45) = {41, 51};
Line(46) = {51, 40};
Line(47) = {51, 52};
Line(48) = {41, 4};
Line(49) = {49, 51};
Line(50) = {43, 7};
Line(51) = {50, 52};
Line(52) = {42, 5};
Line(53) = {41, 44};
Line(54) = {44, 45};
Line(55) = {45, 42};
Line(56) = {44, 17};
Line(57) = {18, 45};
Line(58) = {45, 37};
Line(59) = {37, 33};
Line(60) = {37, 21};
Line(61) = {25, 33};
Line(62) = {33, 36};
Line(63) = {38, 36};
Line(64) = {38, 37};
Line(65) = {42, 38};
Line(66) = {38, 54};
Line(67) = {54, 39};
Line(68) = {39, 36};
Line(69) = {39, 43};
Line(70) = {52, 54};
Line(71) = {54, 53};
Line(72) = {8, 38};
Line(73) = {39, 10};
Line(74) = {2, 36};
Line(75) = {14, 55};
Line(76) = {55, 15};
Line(77) = {15, 16};
Line(78) = {16, 17};
Line(79) = {16, 48};
Line(80) = {48, 47};
Line(81) = {47, 56};
Line(82) = {56, 46};
Line(83) = {46, 14};
Line(84) = {55, 56};
Line(85) = {47, 15};
Line(86) = {48, 44};
Line(87) = {15, 4};
Line(88) = {49, 55};
Line(89) = {14, 3};
Line(90) = {47, 41};
Line(91) = {51, 56};
Line(92) = {46, 40};
Line(93) = {24, 30};
Line(94) = {30, 31};
Line(95) = {31, 28};
Line(96) = {28, 27};
Line(97) = {27, 30};
Line(98) = {25, 31};
Line(99) = {31, 35};
Line(100) = {35, 34};
Line(101) = {34, 28};
Line(102) = {27, 1};
Line(103) = {2, 28};
Line(104) = {34, 36};
Line(105) = {33, 35};
Line(106) = {11, 20};


Line Loop(106) = {89, -10, 88, -75};
Plane Surface(107) = {106};
Line Loop(108) = {9, 88, 76, 87};
Plane Surface(109) = {108};
Line Loop(110) = {77, 78, -23, -87};
Plane Surface(111) = {110};
Line Loop(112) = {83, 89, 40, -92};
Plane Surface(113) = {112};
Line Loop(114) = {91, -84, -88, 49};
Plane Surface(115) = {114};
Line Loop(116) = {87, -48, -90, 85};
Plane Surface(117) = {116};
Line Loop(118) = {78, -56, -86, -79};
Plane Surface(119) = {118};
Line Loop(120) = {77, 79, 80, 85};
Plane Surface(121) = {120};
Line Loop(122) = {76, -85, 81, -84};
Plane Surface(123) = {122};
Line Loop(124) = {75, 84, 82, 83};
Plane Surface(125) = {124};
Line Loop(126) = {82, 92, -46, 91};
Plane Surface(127) = {126};
Line Loop(128) = {81, -91, -45, -90};
Plane Surface(129) = {128};
Line Loop(130) = {80, 90, 53, -86};
Plane Surface(131) = {130};
Line Loop(132) = {23, -56, -53, 48};
Plane Surface(133) = {132};
Line Loop(134) = {9, 49, -45, 48};
Plane Surface(135) = {134};
Line Loop(136) = {10, 40, -46, -49};
Plane Surface(137) = {136};
Line Loop(138) = {10, 1, 18, -11};
Plane Surface(139) = {138};
Line Loop(140) = {9, 11, 19, 21};
Plane Surface(141) = {140};
Line Loop(142) = {7, 8, -21, 20};
Plane Surface(143) = {142};
Line Loop(144) = {25, 26, 29, 24};
Plane Surface(145) = {144};
Line Loop(146) = {23, 24, -106, 8};
Plane Surface(147) = {146};
Line Loop(148) = {7, 106, 25, -28};
Plane Surface(149) = {148};
Line Loop(150) = {26, 27, 20, 28};
Plane Surface(151) = {150};
Line Loop(152) = {21, 23, -29, 27};
Plane Surface(153) = {152};
Line Loop(154) = {29, -56, 54, -57};
Plane Surface(155) = {154};
Line Loop(156) = {1, -50, -41, -40};
Plane Surface(157) = {156};
Line Loop(158) = {46, 41, 42, -47};
Plane Surface(159) = {158};
Line Loop(160) = {47, -51, -11, 49};
Plane Surface(161) = {160};
Line Loop(162) = {21, -48, -44, 52};
Plane Surface(163) = {162};
Line Loop(164) = {44, 45, 47, 43};
Plane Surface(165) = {164};
Line Loop(166) = {51, 43, 52, -19};
Plane Surface(167) = {166};
Line Loop(168) = {18, 51, -42, 50};
Plane Surface(169) = {168};
Line Loop(170) = {42, 70, 67, 69};
Plane Surface(171) = {170};
Line Loop(172) = {67, 68, -63, 66};
Plane Surface(173) = {172};
Line Loop(174) = {70, -66, -65, -43};
Plane Surface(175) = {174};
Line Loop(176) = {44, 53, 54, 55};
Plane Surface(177) = {176};
Line Loop(178) = {27, -52, -55, -57};
Plane Surface(179) = {178};
Line Loop(180) = {30, 34, -31, -26};
Plane Surface(181) = {180};
Line Loop(182) = {30, -33, 6, 28};
Plane Surface(183) = {182};
Line Loop(184) = {34, 32, 15, 33};
Plane Surface(185) = {184};
Line Loop(186) = {6, -20, 22, 15};
Plane Surface(187) = {186};
Line Loop(188) = {19, 22, -14, -12};
Plane Surface(189) = {188};
Line Loop(190) = {13, -2, 18, 12};
Plane Surface(191) = {190};
Line Loop(192) = {50, 2, -73, 69};
Plane Surface(193) = {192};
Line Loop(194) = {67, 73, -13, -71};
Plane Surface(195) = {194};
Line Loop(196) = {3, 74, -68, 73};
Plane Surface(197) = {196};
Line Loop(198) = {70, 71, -12, 51};
Plane Surface(199) = {198};
Line Loop(200) = {14, 72, 66, 71};
Plane Surface(201) = {200};
Line Loop(202) = {16, -3, -13, 14};
Plane Surface(203) = {202};
Line Loop(204) = {16, 74, -63, -72};
Plane Surface(205) = {204};
Line Loop(206) = {5, -15, 16, 4};
Plane Surface(207) = {206};
Line Loop(208) = {35, -33, -5, 39};
Plane Surface(209) = {208};
Line Loop(210) = {22, -32, -31, 27};
Plane Surface(211) = {210};
Line Loop(212) = {38, -16, -32, 36};
Plane Surface(213) = {212};
Line Loop(214) = {34, 36, 37, 35};
Plane Surface(215) = {214};
Line Loop(216) = {60, 36, 61, -59};
Plane Surface(217) = {216};
Line Loop(218) = {59, 62, -63, 64};
Plane Surface(219) = {218};
Line Loop(220) = {58, -64, -65, -55};
Plane Surface(221) = {220};
Line Loop(222) = {31, -60, -58, -57};
Plane Surface(223) = {222};
Line Loop(224) = {39, -37, 38, 4};
Plane Surface(225) = {224};
Line Loop(226) = {38, 74, -62, -61};
Plane Surface(227) = {226};
Line Loop(228) = {62, -104, -100, -105};
Plane Surface(229) = {228};
Line Loop(230) = {94, 95, 96, 97};
Plane Surface(231) = {230};
Line Loop(232) = {99, 100, 101, -95};
Plane Surface(233) = {232};
Line Loop(234) = {95, -103, -38, 98};
Plane Surface(235) = {234};
Line Loop(236) = {39, 93, -97, 102};
Plane Surface(237) = {236};
Line Loop(238) = {96, 102, -4, 103};
Plane Surface(239) = {238};
Line Loop(240) = {103, -101, 104, -74};
Plane Surface(241) = {240};
Line Loop(242) = {94, -98, 37, 93};
Plane Surface(243) = {242};
Line Loop(244) = {98, 99, -105, -61};
Plane Surface(245) = {244};
Line Loop(246) = {22, 72, -65, 52};
Plane Surface(247) = {246};
Line Loop(248) = {60, 32, 72, 64};
Plane Surface(249) = {248};


Surface Loop(246) = {107, 113, 125, 127, 115, 137};
Volume(247) = {246};
Surface Loop(248) = {109, 123, 129, 117, 115, 135};
Volume(249) = {248};
Surface Loop(250) = {111, 121, 119, 131, 117, 133};
Volume(251) = {250};
Surface Loop(252) = {147, 145, 149, 143, 151, 153};
Volume(253) = {252};
Surface Loop(254) = {183, 181, 187, 211, 185, 151};
Volume(255) = {254};
Surface Loop(256) = {141, 135, 167, 165, 163, 161};
Volume(257) = {256};
Surface Loop(258) = {159, 157, 139, 169, 161, 137};
Volume(259) = {258};
Surface Loop(260) = {171, 193, 191, 199, 169, 195};
Volume(261) = {260};
Surface Loop(262) = {179, 133, 177, 155, 163, 153};
Volume(263) = {262};
Surface Loop(264) = {247, 199, 175, 201, 189, 167};
Volume(265) = {264};
Surface Loop(266) = {223, 221, 211, 247, 179, 249};
Volume(267) = {266};
Surface Loop(268) = {215, 209, 207, 213, 185, 225};
Volume(269) = {268};
Surface Loop(270) = {217, 219, 227, 249, 213, 205};
Volume(271) = {270};
Surface Loop(272) = {203, 197, 173, 195, 201, 205};
Volume(273) = {272};
Surface Loop(274) = {225, 239, 231, 243, 237, 235};
Volume(275) = {274};
Surface Loop(276) = {235, 227, 245, 233, 229, 241};
Volume(277) = {276};

nv = 0;

For i In {247:277:2}

	vol[]=Symmetry {0, 1, 0, 0} {
	  Duplicata { Volume{i}; }
	};
	
	new_vols[nv] = vol[0];
	
	nv=nv+1;

EndFor


Transfinite Line {78, 87, 88, 89, 282, 310, 335, 86, 90, 91, 92, 298, 320, 346} = 32 Using Progression 1;
Transfinite Line {93, 98, 102, 103, 631, 629, 105, 104, 652} = 32 Using Progression 1;
Transfinite Line {30, 31, 6, 22, 12, 2, 467, 390, 400, 388, 395, 58, 65, 70, 69, 455, 500, 522} = 8 Using Progression 1;
Transfinite Line {35, 36, 5, 16, 59, 63, 67, 456, 581, 577, 548, 550, 554, 559, 13, 464, 18, 10, 281, 449, 75, 283, 82, 292, 46, 42, 439, 297} = 4 Using Progression 1;
Transfinite Line {79, 85, 84, 83, 291, 313, 340, 56, 57, 52, 51, 48, 50, 49, 420, 40, 422, 303, 323, 345, 484, 521, 576, 61, 60, 74, 72, 73, 71, 499, 470, 99, 101, 651} = 16 Using Progression 1;
Transfinite Line {25, 24, 29, 26, 34, 21, 8, 7, 20, 15, 4, 401, 11, 1, 411, 378, 371, 364, 366, 362, 368, 394, 549, 37, 94, 96, 623, 44, 47, 41, 427, 425, 54, 493, 379, 367} = 2 Using Progression 1;
Transfinite Line {77, 334, 80, 341, 28, 27, 106, 23, 336, 363, 382, 382, 382, 374, 55, 53, 351, 483, 64, 62, 526, 580, 33, 32, 39, 38, 389, 404, 555, 562, 97, 95, 626, 624, 100, 656} = 8 Using Progression 1;
Transfinite Line {3, 14, 513, 19, 9, 307, 412, 76, 309, 81, 314, 45, 43, 319, 421, 66, 509, 68} = 2 Using Progression 1;

For i In {247:277:2}

	Transfinite Surface{Boundary{Volume{i};}};
	
	Transfinite Volume{i};

EndFor

For i In {0:nv-1}

	Transfinite Surface{Boundary{Volume{new_vols[i]};}};
	
	Transfinite Volume{new_vols[i]};

EndFor

Smoother Surface {143,145,375,365} = 100;


Physical Surface("bottom") = {111, 109, 107, 279, 306, 333, 147, 149, 143, 141, 139, 446, 409, 375, 360, 370, 189, 191, 463, 517, 183, 187, 207, 556, 397, 387, 203, 600, 209, 237, 632, 551};
Physical Surface("top") = {131, 129, 127, 294, 316, 348, 490, 524, 578, 659, 229, 219, 177, 221, 175, 171, 453, 507, 424, 436, 159, 165, 173, 610, 173, 610};
Physical Surface("back") = {343, 495, 519, 392, 546, 573, 365, 627, 649};
Physical Surface("front") = {119, 155, 223, 217, 245, 243, 181, 215, 145};
Physical Surface("outlet") = {622, 231, 233, 654};
Physical Surface("inlet") = {121, 123, 125, 289, 311, 338};
Physical Volume("volume") = {251, 249, 247, 278, 305, 332, 253, 359, 386, 545, 255, 269, 271, 273, 572, 518, 496, 452, 265, 261, 263, 267, 257, 259, 435, 408, 479, 611, 275, 277, 638, 599};

