m = 1;
mm = 0.001;

degrad = Pi/180;

Include "functions.geo";


// diffuser

shift = 2 * m;

scale = 1;
r = 1 * m;

jetwidth = 10 * mm;

wallcellthick = 2 * mm;

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

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

spacing_td = 4.075;

point_td = newp;
reg_td = newreg;

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

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

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};

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

Printf("Jet, width direction");

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

Call BumpProgrNbNodesBRatio;

Transfinite Line {reg_td+1,-reg_td-6} = GBPNND_nbnodes Using Bump GBPNND_bumpratio;

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

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

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

Call GeomProgrNbNodesDx0;

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

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

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

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

Call GeomProgrNbNodesDx0;

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

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

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-4} = GPNND_nbnodes Using Progression GPNND_ratio;


For t In {8:15}
  Extrude Line { reg_td + t, {1,0,0} } { Layers { 40, 1, 1 };};

Extrude Line { 1, {2,0,0} } { Recombine; Layers { 40, 1, 1 };};
Extrude Line { 2, {2,0,0} } { Recombine; Layers { 40, 1, 1 };};
Extrude Line { 3, {2,0,0} } { Recombine; Layers { 40, 1, 1 };};
Extrude Line { 4, {2,0,0} } { Recombine; Layers { 40, 1, 1 };};
Extrude Line { 5, {2,0,0} } { Recombine; Layers { 40, 1, 1 };};
Extrude Line { 6, {2,0,0} } { Recombine; Layers { 40, 1, 1 };};
Extrude Line { 7, {2,0,0} } { Recombine; Layers { 40, 1, 1 };};
Extrude Line { 8, {2,0,0} } { Recombine; Layers { 40, 1, 1 };};
Line Loop(41) = {17,21,25,29,33,37,9,13};
Plane Surface(42) = {41};

point_td = newp;
reg_td = newreg;

Point(point_td) = {0, 0, 10, 0.5};
Point(point_td+1) = {0, 20, 10, 0.5};
Point(point_td+2) = {20, 20, 10, 0.5};
Point(point_td+3) = {20, 0, 10, 0.5};
Point(point_td+4) = {0, 0, 25, 0.5};
Point(point_td+5) = {0, 20, 25, 0.5};
Point(point_td+6) = {20, 20, 25, 0.5};
Point(point_td+7) = {20, 0, 25, 0.5};
Line(43) = {31,34};
Line(44) = {34,33};
Line(45) = {33,32};
Line(46) = {32,31};
Line(47) = {35,38};
Line(48) = {38,37};
Line(49) = {37,36};
Line(50) = {36,35};
Line(51) = {31,35};
Line(52) = {34,38};
Line(53) = {32,36};
Line(54) = {33,37};
Line Loop(55) = {46,43,44,45};
Plane Surface(56) = {55};
Line Loop(57) = {50,47,48,49};
Plane Surface(58) = {57};
Line Loop(59) = {43,52,-47,-51};
Plane Surface(60) = {59};
Line Loop(61) = {45,53,-49,-54};
Plane Surface(62) = {61};
Line Loop(63) = {44,54,-48,-52};
Plane Surface(64) = {63};

Characteristic Length {3,2,1,8,7,30,27,10,12,15} = 0.06;
Characteristic Length {4,18,5,21,6,24} = 0.12;

Line Loop(65) = {6,7,8,1,2,3,4,5};
Plane Surface(66) = {65};
Line Loop(67) = {51,-50,-53,46};
Plane Surface(68) = {67};
Surface Loop(69) = {60,-56,68,58,64,62};
Surface Loop(70) = {66,-32,-36,-40,-12,-16,-20,-24,-28,-42};
Volume(71) = {69,70};
