Include "units.geo";
Include "functions.geo";
Include "ring2_ringwrap.geo";

// diffuser

r = 0.45 * m;

jetwidth = 10 * mm;

length_td = 20 * m;
h_td = 21 * m;
bl_td = 1 * m;

alpha = (180/Pi) * Atan ( 0.5 * jetwidth / r);
Printf("alpha : %f", alpha);

For iterator In {0:0}

spacing_td = 4.075+8.15*iterator;

point_td = newp;
reg_td = newreg;

Printf("point_td : %f", point_td);
Printf("reg_td : %f", reg_td);

point_td = 52;
reg_td = 289;

Point(point_td) = {0, spacing_td, h_td - r, wallcellthick};
Point(point_td+1) = {0, spacing_td + r * Sin(degrad * 27), h_td - r * Cos(degrad * 27),  2 * wallcellthick};
Point(point_td+2) = {0, spacing_td + r * Sin(degrad * 33), h_td - r * Cos(degrad * 33), 2 * wallcellthick};
Point(point_td+3) = {0, spacing_td + r * Sin(degrad * 135), h_td - r * Cos(degrad * 135), 2 * wallcellthick};
Point(point_td+4) = {0, spacing_td, h_td + r, 2 * wallcellthick};
Point(point_td+5) = {0, spacing_td + r * Sin(degrad * 225), h_td - r * Cos(degrad * 225), 2 * wallcellthick};
Point(point_td+6) = {0, spacing_td + r * Sin(degrad * -33), h_td - r * Cos(degrad * -33), 2 * wallcellthick};
Point(point_td+7) = {0, spacing_td + r * Sin(degrad * -27), h_td - r * Cos(degrad * -27), 2 * wallcellthick};
Point(point_td+8) = {0, spacing_td, h_td, 2 * wallcellthick};

Point(point_td+9) = {0, spacing_td, h_td - bl_td, lc};
Point(point_td+10) = {0, spacing_td + bl_td * Sin(degrad * 27), h_td - bl_td * Cos(degrad * 27), lc};
Point(point_td+11) = {0, spacing_td + bl_td * Sin(degrad * 33), h_td - bl_td * Cos(degrad * 33), lc};
Point(point_td+12) = {0, spacing_td + bl_td * Sin(degrad * 135), h_td - bl_td * Cos(degrad * 135), lc};
Point(point_td+13) = {0, spacing_td, h_td + bl_td, lc};
Point(point_td+14) = {0, spacing_td + bl_td * Sin(degrad * 225), h_td - bl_td * Cos(degrad * 225), lc};
Point(point_td+15) = {0, spacing_td + bl_td * Sin(degrad * -33), h_td - bl_td * Cos(degrad * -33), lc};
Point(point_td+16) = {0, spacing_td + bl_td * Sin(degrad * -27), h_td - bl_td * Cos(degrad * -27), lc};

Circle (reg_td) = {point_td, point_td+8, point_td+1} Plane{1, 0, 0};
Circle (reg_td+1) = {point_td+1, point_td+8, point_td+2} Plane{1, 0, 0};
Circle (reg_td+2) = {point_td+2, point_td+8, point_td+3} Plane{1, 0, 0};
Circle (reg_td+3) = {point_td+3, point_td+8, point_td+4} Plane{1, 0, 0};
Circle (reg_td+4) = {point_td+4, point_td+8, point_td+5} Plane{1, 0, 0};
Circle (reg_td+5) = {point_td+5, point_td+8, point_td+6} Plane{1, 0, 0};
Circle (reg_td+6) = {point_td+6, point_td+8, point_td+7} Plane{1, 0, 0};
Circle (reg_td+7) = {point_td+7, point_td+8, point_td} Plane{1, 0, 0};

Circle (reg_td+8) = {point_td+9, point_td+8, point_td+10} Plane{1, 0, 0};
Circle (reg_td+9) = {point_td+10, point_td+8, point_td+11} Plane{1, 0, 0};
Circle (reg_td+10) = {point_td+11, point_td+8, point_td+12} Plane{1, 0, 0};
Circle (reg_td+11) = {point_td+12, point_td+8, point_td+13} Plane{1, 0, 0};
Circle (reg_td+12) = {point_td+13, point_td+8, point_td+14} Plane{1, 0, 0};
Circle (reg_td+13) = {point_td+14, point_td+8, point_td+15} Plane{1, 0, 0};
Circle (reg_td+14) = {point_td+15, point_td+8, point_td+16} Plane{1, 0, 0};
Circle (reg_td+15) = {point_td+16, point_td+8, point_td+9} Plane{1, 0, 0};

Line(reg_td+16) = {point_td,point_td+9};
Line(reg_td+17) = {point_td+1,point_td+10};
Line(reg_td+18) = {point_td+2,point_td+11};
Line(reg_td+19) = {point_td+3,point_td+12};
Line(reg_td+20) = {point_td+4,point_td+13};
Line(reg_td+21) = {point_td+5,point_td+14};
Line(reg_td+22) = {point_td+6,point_td+15};
Line(reg_td+23) = {point_td+7,point_td+16};

Line Loop(reg_td+23) = {reg_td+16,reg_td+8,-reg_td-17,-reg_td};
Line Loop(reg_td+24) = {reg_td+17,reg_td+9,-reg_td-18,-reg_td-1};
Line Loop(reg_td+25) = {reg_td+18,reg_td+10,-reg_td-19,-reg_td-2};
Line Loop(reg_td+26) = {reg_td+19,reg_td+11,-reg_td-20,-reg_td-3};
Line Loop(reg_td+27) = {reg_td+20,reg_td+12,-reg_td-21,-reg_td-4};
Line Loop(reg_td+28) = {reg_td+21,reg_td+13,-reg_td-22,-reg_td-5};
Line Loop(reg_td+29) = {reg_td+22,reg_td+14,-reg_td-23,-reg_td-6};
Line Loop(reg_td+30) = {reg_td+23,reg_td+15,-reg_td-16,-reg_td-7};

Plane Surface(reg_td+31) = {reg_td+23};
Plane Surface(reg_td+32) = {reg_td+24};
Plane Surface(reg_td+33) = {reg_td+25};
Plane Surface(reg_td+34) = {reg_td+26};
Plane Surface(reg_td+35) = {reg_td+27};
Plane Surface(reg_td+36) = {reg_td+28};
Plane Surface(reg_td+37) = {reg_td+29};
Plane Surface(reg_td+38) = {reg_td+30};

Transfinite Surface{reg_td+31} = {point_td,point_td+9,point_td+10,point_td+1};
Transfinite Surface{reg_td+32} = {point_td+1,point_td+10,point_td+11,point_td+2};
Transfinite Surface{reg_td+33} = {point_td+2,point_td+11,point_td+12,point_td+3};
Transfinite Surface{reg_td+34} = {point_td+3,point_td+12,point_td+13,point_td+4};
Transfinite Surface{reg_td+35} = {point_td+4,point_td+13,point_td+14,point_td+5};
Transfinite Surface{reg_td+36} = {point_td+5,point_td+14,point_td+15,point_td+6};
Transfinite Surface{reg_td+37} = {point_td+6,point_td+15,point_td+16,point_td+7};
Transfinite Surface{reg_td+38} = {point_td+7,point_td+16,point_td+9,point_td};

//Recombine Surface {reg_td+31:reg_td+38};

EndFor
pt_rwrap = newp;
reg_rwrap = newreg;

Printf("%f",pt_rwrap);
Printf("%f",reg_rwrap);
Point(pt_rwrap) = {0,4.075,16.5,0.5};
Point(pt_rwrap+1) = {0,2.075,16.5,0.5};
Point(pt_rwrap+2) = {0,1.075,16.5,0.5};
Point(pt_rwrap+3) = {0, 1.075, h_td - bl_td * Cos(degrad * 135), 0.5};
Point(pt_rwrap+4) = {0, 1.075,25,0.5};
Point(pt_rwrap+5) = {0, spacing_td - bl_td * Sin(degrad * 135), 25, 0.5};
Point(pt_rwrap+6) = {0, 4.075, 25, 0.5};
Point(pt_rwrap+7) = {0, spacing_td + bl_td * Sin(degrad * 135), 25, 0.5};
Point(pt_rwrap+8) = {0, 4.075 + 3, 25, 0.5};
Point(pt_rwrap+9) = {0, 4.075 + 3, h_td - bl_td * Cos(degrad * 135), 0.5};
Point(pt_rwrap+10) = {0,4.075 + 3, 16.5, 0.5};
Point(pt_rwrap+11) = {0,4.075 + 3 - 1, 16.5, 0.5};
Line(reg_rwrap) = {point_td+9,pt_rwrap};
Line(reg_rwrap+1) = {point_td+16,pt_rwrap+1};
Line(reg_rwrap+2) = {point_td+15,pt_rwrap+2};
Line(reg_rwrap+3) = {point_td+14,pt_rwrap+3};
Line(reg_rwrap+4) = {point_td+14,pt_rwrap+5};
Line(reg_rwrap+5) = {point_td+12,pt_rwrap+7};
Line(reg_rwrap+6) = {point_td+12,pt_rwrap+9};
Line(reg_rwrap+7) = {point_td+11,pt_rwrap+10};
Line(reg_rwrap+8) = {point_td+10,pt_rwrap+11};
Line(reg_rwrap+9) = {pt_rwrap,pt_rwrap+1};
Line(reg_rwrap+10) = {pt_rwrap+1,pt_rwrap+2};
Line(reg_rwrap+11) = {pt_rwrap+2,pt_rwrap+3};
Line(reg_rwrap+12) = {pt_rwrap+3,pt_rwrap+4};
Line(reg_rwrap+13) = {pt_rwrap+4,pt_rwrap+5};
Line(reg_rwrap+14) = {point_td+13,pt_rwrap+6};
Line(reg_rwrap+15) = {pt_rwrap+5,pt_rwrap+6};
Line(reg_rwrap+16) = {pt_rwrap+6,pt_rwrap+7};
Line(reg_rwrap+17) = {pt_rwrap+7,pt_rwrap+8};
Line(reg_rwrap+18) = {pt_rwrap+8,pt_rwrap+9};
Line(reg_rwrap+19) = {pt_rwrap+9,pt_rwrap+10};
Line(reg_rwrap+20) = {pt_rwrap+10,pt_rwrap+11};
Line(reg_rwrap+21) = {pt_rwrap+11,pt_rwrap};
Line Loop(reg_rwrap+22) = {reg_rwrap+9,-reg_rwrap-1,304,reg_rwrap};
Plane Surface(reg_rwrap+23) = {reg_rwrap+22};
Line Loop(reg_rwrap+24) = {reg_rwrap+10,-reg_rwrap-2,303,reg_rwrap+1};
Plane Surface(reg_rwrap+25) = {reg_rwrap+24};
Line Loop(reg_rwrap+26) = {reg_rwrap+2,reg_rwrap+11,-reg_rwrap-3,302};
Plane Surface(reg_rwrap+27) = {reg_rwrap+26};
Line Loop(reg_rwrap+28) = {reg_rwrap+3,reg_rwrap+12,reg_rwrap+13,-reg_rwrap-4};
Plane Surface(reg_rwrap+29) = {reg_rwrap+28};
Line Loop(reg_rwrap+30) = {reg_rwrap+4,reg_rwrap+15,-reg_rwrap-14,301};
Plane Surface(reg_rwrap+31) = {reg_rwrap+30};
Line Loop(reg_rwrap+32) = {300,reg_rwrap+14,reg_rwrap+16,-reg_rwrap-5};
Plane Surface(reg_rwrap+33) = {reg_rwrap+32};
Line Loop(reg_rwrap+34) = {reg_rwrap+6,-reg_rwrap-18,-reg_rwrap-17,-reg_rwrap-5};
Plane Surface(reg_rwrap+35) = {reg_rwrap+34};
Line Loop(reg_rwrap+36) = {reg_rwrap+6,reg_rwrap+19,-reg_rwrap-7,299};
Plane Surface(reg_rwrap+37) = {reg_rwrap+36};
Line Loop(reg_rwrap+38) = {reg_rwrap+7,reg_rwrap+20,-reg_rwrap-8,298};
Plane Surface(reg_rwrap+39) = {reg_rwrap+38};
Line Loop(reg_rwrap+40) = {reg_rwrap+21,-reg_rwrap,297,reg_rwrap+8};
Plane Surface(reg_rwrap+41) = {reg_rwrap+40};
Transfinite Surface {reg_rwrap+23} = {69,70,68,61};
Transfinite Surface {reg_rwrap+25} = {70,71,67,68};
Transfinite Surface {reg_rwrap+27} = {71,72,66,67};
Transfinite Surface {reg_rwrap+29} = {72,73,74,66};
Transfinite Surface {reg_rwrap+31} = {66,74,75,65};
Transfinite Surface {reg_rwrap+33} = {65,75,76,64};
Transfinite Surface {reg_rwrap+35} = {64,76,77,78};
Transfinite Surface {reg_rwrap+37} = {63,64,78,79};
Transfinite Surface {reg_rwrap+39} = {80,62,63,79};
Transfinite Surface {reg_rwrap+41} = {69,61,62,80};

//Recombine Surface {reg_rwrap+23,reg_rwrap+25,reg_rwrap+27,reg_rwrap+29,reg_rwrap+31,reg_rwrap+33,reg_rwrap+35,reg_rwrap+37,reg_rwrap+39,reg_rwrap+41};

//-------------------------------

Printf("Jet, width direction");

GBPNND_length = jetwidth;
GBPNND_dx0 = scale * jetwidth / 20;
GBPNND_ratio = 1.2;

Call BumpProgrNbNodesBRatio;

Transfinite Line {reg_td+1,reg_td+9,-reg_td-6,-reg_td-14} = GBPNND_nbnodes Using Bump GBPNND_bumpratio;
Transfinite Line {338,348} = GBPNND_nbnodes;
Characteristic Length{70,338,80,79} = Floor(1/GBPNND_nbnodes);
Characteristic Length{point_td+10, point_td+11, point_td+15, point_td+16} =  10 * GBPNND_dx0 * bl_td / r;

//-------------------------------

Printf("Jet, streamwise");

GPNND_length = 0.55;
GPNND_dx0 = GBPNND_olddx0;
GPNND_ratio = 1.2;

Call GeomProgrNbNodesDx0;

Transfinite Line {reg_td+16:reg_td+23} = GPNND_nbnodes Using Progression GPNND_ratio;

//------------------------------- 

Printf("Orthoradial direction, left of jet");

GPNND_length = Pi *r * 40 / 360;
GPNND_dx0 = GBPNND_olddx0;
GPNND_ratio = 1.1;

Call GeomProgrNbNodesDx0;

Transfinite Line {-reg_td,-reg_td-8,reg_td+7,reg_td+15} = GPNND_nbnodes Using Progression GPNND_ratio;

Transfinite Line {-reg_td-8,reg_td+15} = GPNND_nbnodes Using Progression 1.03;
Characteristic Length{point_td+9} = 10 * GPNND_dxN * bl_td / r;
Transfinite Line {349,337} = GPNND_nbnodes;
//------------------------------- 

Printf("Orthoradial direction, right of jet");

GPNND_length = Pi *r * 85 / 360;
GPNND_dx0 = GBPNND_olddx0;
GPNND_ratio = 1.1;

Call GeomProgrNbNodesDx0;

Transfinite Line {reg_td+2,reg_td+10,-reg_td-5,-reg_td-13} = GPNND_nbnodes Using Progression GPNND_ratio;

Transfinite Line {reg_td+10,-reg_td-13} = GPNND_nbnodes Using Progression 1.05;
Characteristic Length{point_td+12, point_td+14} = 10 * GPNND_dxN * bl_td / r;
Transfinite Line {339,347} = GPNND_nbnodes;
//------------------------------- 

Printf("Orthoradial direction, right/right of jet");

GPNND_length = Pi *r * 45 / 360;
GPNND_dx0 = GPNND_dxN;
GPNND_ratio = 1.0;

Call GeomProgrNbNodesDx0;

Transfinite Line {reg_td+3,reg_td+11,-reg_td-4,-reg_td-12} = GPNND_nbnodes Using Progression GPNND_ratio;
Characteristic Length{point_td+13} = 10 * GPNND_dxN * bl_td / r;
Transfinite Line {344,343} = GPNND_nbnodes;

//------------------------------- 

Printf("Top");

nbnodes = 9;
Transfinite Line {333,342,332} = 7 Using Progression 1.0;
Transfinite Line {331,334,346,340} = 7 Using Progression 1.0;

//------------------------------- 

Printf("C");

GPNND_length = 5;
GPNND_dx0 = 0.25;
GPNND_ratio = 1.2;

Call GeomProgrNbNodesDx0;

Transfinite Line {334,335,336,328,329,330,331} = GPNND_nbnodes Using Progression GPNND_ratio;
Transfinite Line {345,341} = GPNND_nbnodes;


pt_rwrap = newp;
reg_rwrap = newreg;

Printf("%f",pt_rwrap);
Printf("%f",reg_rwrap);

Point(pt_rwrap) = {0, 0, 16.5, lc};
Point(pt_rwrap+1) = {halfw_core+l_seat, 0, 16.5, lc};
Point(pt_rwrap+2) = {halfw_core+l_seat, halfl_core, 16.5, lc};
Point(pt_rwrap+3) = {0, halfl_core, 16.5, lc};

Extrude Surface {363, {20,0,0}} {   Layers { 80, 1, 1 }; };
Extrude Surface {361, {20,0,0}} {   Layers { 80, 1, 1 }; };
Extrude Surface {359, {20,0,0}} {   Layers { 80, 1, 1 }; };
Extrude Surface {357, {20,0,0}} {   Layers { 80, 1, 1 }; };
Extrude Surface {355, {20,0,0}} {   Layers { 80, 1, 1 }; };
Extrude Surface {325, {20,0,0}} {   Layers { 80, 1, 1 }; };
Extrude Surface {324, {20,0,0}} {   Layers { 80, 1, 1 }; };
Extrude Surface {323, {20,0,0}} {   Layers { 80, 1, 1 }; };
Extrude Surface {326, {20,0,0}} {   Layers { 80, 1, 1 }; };
Extrude Surface {327, {20,0,0}} {   Layers { 80, 1, 1 }; };
Extrude Surface {320, {20,0,0}} {   Layers { 80, 1, 1 }; };
Extrude Surface {321, {20,0,0}} {   Layers { 80, 1, 1 }; };
Extrude Surface {322, {20,0,0}} {   Layers { 80, 1, 1 }; };
Extrude Surface {353, {20,0,0}} {   Layers { 80, 1, 1 }; };
Extrude Surface {351, {20,0,0}} {   Layers { 80, 1, 1 }; };
Extrude Surface {369, {20,0,0}} {   Layers { 80, 1, 1 }; };
Extrude Surface {367, {20,0,0}} {   Layers { 80, 1, 1 }; };
Extrude Surface {365, {20,0,0}} {   Layers { 80, 1, 1 }; };

Characteristic Length{70,79,80,169,171,173} = 0.5;

Line(766) = {81,21};
Line(767) = {81,71};
Line(768) = {79,84};
Line(769) = {84,44};
Line(770) = {81,82};
Line(771) = {82,38};
Line(772) = {82,83};
Line(773) = {83,51};
Line(774) = {83,84};
Line Loop(775) = {770,771,-165,-134,-69,-766};
Plane Surface(776) = {775};
Line Loop(777) = {166,-236,-773,-772,771};
Plane Surface(778) = {777};
Line Loop(779) = {235,-773,774,769,187,213};
Plane Surface(780) = {779};
Line Loop(781) = {768,769,-186,-70,-766,767,-338,-337,-349,-348};
Plane Surface(782) = {781};
Point(174) = {0.0,0.0,25,0.5};
Point(175) = {36.75,0,25,0.5};
Point(176) = {36.75,24.45,25,0.5};
Point(177) = {0,24.45,25,0.5};
Line(783) = {111,82};
Line(784) = {173,83};
Line(785) = {84,177};
Line(786) = {83,176};
Line(787) = {82,175};
Line(788) = {81,174};
Line(789) = {73,174};
Line(790) = {174,175};
Line(791) = {175,176};
Line(792) = {176,177};
Line(793) = {177,77};
Line(794) = {109,175};
Line(795) = {90,176};
Line Loop(796) = {767,465,783,-770};
Plane Surface(797) = {796};
Line Loop(798) = {783,787,-794,-438,-460};
Plane Surface(799) = {798};
Line Loop(800) = {794,-790,-789,447};
Plane Surface(801) = {800};
Line Loop(802) = {788,-789,-340,-339,-767};
Plane Surface(803) = {802};
Line Loop(804) = {790,-787,-770,788};
Plane Surface(805) = {804};
Surface Loop(806) = {797,803,-805,-801,-799,448,470};
Volume(807) = {806};
Line Loop(808) = {783,772,-784,724,701,679,657};
Plane Surface(809) = {808};
Line Loop(810) = {373,-395,-416,-439,794,791,-795};
Plane Surface(811) = {810};
Line Loop(812) = {791,-786,-772,787};
Plane Surface(813) = {812};
Line Loop(814) = {784,786,-795,-372,746};
Plane Surface(815) = {814};
Line Loop(816) = {528,638,616,594,572,550,484,506};
Plane Surface(817) = {816};

Surface Loop(818) = {815,809,-799,813,-811,391,-765,-743,-721,-699,-677,-479,-457,-435,-413,545,655,633,611,589,567,501,523,-817};

Volume(819) = {818};


Line Loop(820) = {729,784,774,-768};
Plane Surface(821) = {820};
Line Loop(822) = {768,785,793,346,347};
Plane Surface(823) = {822};
Line Loop(824) = {792,793,381,795};
Plane Surface(825) = {824};
Line Loop(826) = {774,785,-792,-786};
Plane Surface(827) = {826};
Surface Loop(828) = {821,-756,823,-827,-825,382,-815};
Volume(829) = {828};
Characteristic Length {173,171,170,169} = 0.2;
//Recombine Surface {817};
