///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//
//         Génération de la géométrie Jonction AREVA GMSH
//
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

//Data
lc  = 5.;      

N1  = 20;    
N2  = N1;      
N3  = 2*N1;    

arctheta1 = 11;  
arctheta2 = 20;   

f   = 1.1;     

h1  = 50;   
Nz1 = 30;    

d1=7.0711; 
d2=14.1421; 
d3=16.2635; 
d4=50; 

//---------------------------------------------------------------------------
Point(1)={0, 0, 0, lc};
Point(2)={-d1, 0, d1, lc};
Point(3)={d1, 0, d1, lc};
Point(4)={d1, 0, -d1, lc};
Point(5)={-d1, 0, -d1, lc};
Point(6)={-d2, 0, d2, lc};
Point(7)={d2, 0, d2, lc};
Point(8)={d2, 0, -d2, lc};
Point(9)={-d2, 0, -d2, lc};
Point(10)={-d3, 0, d3, lc};
Point(11)={d3, 0, d3, lc};
Point(12)={d3, 0, -d3, lc};
Point(13)={-d3, 0, -d3, lc};
Point(14)={-d4, 0, d4, lc};
Point(15)={-d3, 0, d4, lc};
Point(16)={d3, 0, d4, lc};
Point(17)={d4, 0, d4, lc};
Point(18)={d4, 0, d3, lc};
Point(19)={d4, 0, -d3, lc};
Point(20)={d4, 0, -d4, lc};
Point(21)={d3, 0, -d4, lc};
Point(22)={-d3, 0, -d4, lc};
Point(23)={-d4, 0, -d4, lc};
Point(24)={-d4, 0, -d3, lc};
Point(25)={-d4, 0, d3, lc};
Point(26)={100, 0, d4, lc};
Point(27)={100, 0, d3, lc};
Point(28)={100, 0, -d3, lc};
Point(29)={100, 0, -d4, lc};
Point(30)={-100, 0, d4, lc};
Point(31)={-100, 0, d3, lc};
Point(32)={-100, 0, -d3, lc};
Point(33)={-100, 0, -d4, lc};
Point(34)={150, 0, d4, lc};
Point(35)={150, 0, d3, lc};
Point(36)={150, 0, -d3, lc};
Point(37)={150, 0, -d4, lc};

//---------------------------------------------------------------------------
Line(1) = {2,3}; 
Line(2) = {3,4}; 
Line(3) = {4,5}; 
Line(4) = {5,2}; 
Circle(5) = {6,1,7};
Circle(6) = {7,1,8};
Circle(7) = {8,1,9};
Circle(8) = {9,1,6};
Line(9 ) = {14,15}; 
Line(10) = {15,16}; 
Line(11) = {16,17}; 
Line(12) = {17,18}; 
Line(13) = {18,19}; 
Line(14) = {19,20}; 
Line(15) = {20,21}; 
Line(16) = {21,22}; 
Line(17) = {22,23}; 
Line(18) = {23,24}; 
Line(19) = {24,25}; 
Line(20) = {25,14}; 
Line(32) = {21,12}; 
Line(33) = {24,13}; 
Line(34) = {13,22}; 
Line(35) = {15,10}; 
Line(36) = {10,25}; 
Line(37) = {18,11}; 
Line(38) = {11,16}; 
Line(21) = {17,26}; 
Line(22) = {26,27}; 
Line(23) = {27,28}; 
Line(24) = {28,29}; 
Line(25) = {29,20}; 
Line(41) = {27,18}; 
Line(42) = {28,19};
Line(31) = {12,19}; 
Line(26) = {23,33}; 
Line(27) = {33,32}; 
Line(28) = {32,31}; 
Line(29) = {31,30}; 
Line(30) = {30,14}; 
Line(39) = {25,31}; 
Line(40) = {24,32}; 
Line(43) = {26,34}; 
Line(44) = {27,35}; 
Line(45) = {28,36}; 
Line(46) = {29,37};
Line(47) = {34,35}; 
Line(48) = {35,36}; 
Line(49) = {36,37}; 
Line(50) = {2,6};
Line(51) = {3,7}; 
Line(52) = {4,8}; 
Line(53) = {5,9}; 
Line(54) = {6,10};
Line(55) = {7,11}; 
Line(56) = {8,12}; 
Line(57) = {9,13}; 
Circle(58) = {10,1,11};
Circle(59) = {10,1,13};
Circle(60) = {13,1,12};
Circle(61) = {12,1,11};


//---------------------------------------------------------------------------
Line Loop(1) = {2,3,4,1}; 
Line Loop(2) = {-51,-1,50,5}; 
Line Loop(3) = {6,-52,-2,51}; 
Line Loop(4) = {52,7,-53,-3}; 
Line Loop(5) = {53,8,-50,-4}; 
Line Loop(6) = {-55,-5,54,58}; 
Line Loop(7) = {-61,-56,-6,55}; 
Line Loop(8) = {56,-60,-57,-7}; 
Line Loop(9) = {-8,57,-59,-54}; 
Line Loop(10) = {13,-31,61,-37}; 
Line Loop(11) = {-32,16,-34,60}; 
Line Loop(12) = {59,-33,19,-36}; 
Line Loop(13) = {-38,-58,-35,10}; 
Line Loop(14) = {12,37,38,11}; 
Line Loop(15) = {14,15,32,31}; 
Line Loop(16) = {34,17,18,33}; 
Line Loop(17) = {35,36,20,9}; 
Line Loop(18) = {22,41,-12,21}; 
Line Loop(19) = {23,42,-13,-41}; 
Line Loop(20) = {24,25,-14,-42}; 
Line Loop(21) = {-20,39,29,30}; 
Line Loop(22) = {-19,40,28,-39}; 
Line Loop(23) = {-18,26,27,-40}; 
Line Loop(24) = {47,-44,-22,43}; 
Line Loop(25) = {48,-45,-23,44}; 
Line Loop(26) = {49,-46,-24,45}; 

//---------------------------------------------------------------------------
s1  = newreg; Plane Surface(s1) = {1}; 
s2  = newreg; Plane Surface(s2) = {2}; 
s3  = newreg; Plane Surface(s3) = {3}; 
s4  = newreg; Plane Surface(s4) = {4}; 
s5  = newreg; Plane Surface(s5) = {5}; 
s6  = newreg; Plane Surface(s6) = {6}; 
s7  = newreg; Plane Surface(s7) = {7}; 
s8  = newreg; Plane Surface(s8) = {8}; 
s9  = newreg; Plane Surface(s9) = {9}; 
s10 = newreg; Plane Surface(s10) = {10}; 
s11 = newreg; Plane Surface(s11) = {11}; 
s12 = newreg; Plane Surface(s12) = {12}; 
s13 = newreg; Plane Surface(s13) = {13}; 
s14 = newreg; Plane Surface(s14) = {14}; 
s15 = newreg; Plane Surface(s15) = {15}; 
s16 = newreg; Plane Surface(s16) = {16}; 
s17 = newreg; Plane Surface(s17) = {17}; 
s18 = newreg; Plane Surface(s18) = {18}; 
s19 = newreg; Plane Surface(s19) = {19}; 
s20 = newreg; Plane Surface(s20) = {20}; 
s21 = newreg; Plane Surface(s21) = {21}; 
s22 = newreg; Plane Surface(s22) = {22}; 
s23 = newreg; Plane Surface(s23) = {23}; 
s24 = newreg; Plane Surface(s24) = {24}; 
s25 = newreg; Plane Surface(s25) = {25}; 
s26 = newreg; Plane Surface(s26) = {26}; 


//---------------------------------------------------------------------------
Transfinite Line{54,55,56,57}=arctheta1 Using Progression f;
Transfinite Line{50,51,52,53}=arctheta2 Using Progression 1/f; 

Transfinite Line {11,37,31,15,9,36,33,17} = N1 Using Progression 1.0;
Transfinite Line {20,19,18,35,59,34,38,61,32,12,13,14,58,10,16,5,7,60,61,6,8,1,2,3,4} = N1 Using Progression 1.0;
Transfinite Line {20,35,38,12} = N1 Using Progression 1.0;
Transfinite Line {19,13} = N1 Using Progression 1.0;
Transfinite Line {18,34,32,14} = N1 Using Progression 1.0;
Transfinite Line {21,41,42,25,30,39,40,26} = N3 Using Progression 1.0;
Transfinite Line {22,12,20,23,13,19,24,14,18} = N1 Using Progression 1.0;
Transfinite Line {43,44,45,46,30,39,40,26} = N3 Using Progression 1.0;
Transfinite Line {47,48,49,22,23,24,20,19,18,29,28,27} = N1 Using Progression 1.0;

Transfinite Surface {s1} = {2,3,4,5};
Transfinite Surface {s2} = {2,6,7,3};
Transfinite Surface {s3} = {3,7,8,4};
Transfinite Surface {s4} = {4,8,9,5};
Transfinite Surface {s5} = {5,9,6,2};
Transfinite Surface {s6} = {11,7,6,10};
Transfinite Surface {s7} = {11,7,8,12};
Transfinite Surface {s8} = {8,12,13,9};
Transfinite Surface {s9} = {9,13,10,6};
Transfinite Surface {s10} = {11,18,19,12};
Transfinite Surface {s11} = {12,21,22,13};
Transfinite Surface {s12} = {13,24,25,10};
Transfinite Surface {s13} = {11,10,15,16};
Transfinite Surface {s14} = {18,11,16,17};
Transfinite Surface {s15} = {12,19,20,21};
Transfinite Surface {s16} = {13,22,23,24};
Transfinite Surface {s17} = {10,25,14,15};
Transfinite Surface {s18} = {17,26,27,18};
Transfinite Surface {s19} = {18,27,28,19};
Transfinite Surface {s20} = {19,28,29,20};
Transfinite Surface {s21} = {14,25,31,30};
Transfinite Surface {s22} = {25,24,32,31};
Transfinite Surface {s23} = {23,24,32,33};
Transfinite Surface {s24} = {34,26,27,35};
Transfinite Surface {s25} = {36,35,27,28};
Transfinite Surface {s26} = {37,36,28,29};

Recombine Surface {s1:s26};

//---------------------------------------------------------------------------
i  = 1;
For s In {s1:s26}  
out1[] = Extrude {0,h1,0} { 
  Surface { s }; Layers{10};   Recombine; 
};
ns[i] = out1[0];
fg[i] = out1[2];
fb[i] = out1[3];
fd[i] = out1[4];
fh[i] = out1[5];

nv[i] = newreg;
Physical Volume (nv[i]) = {out1[1]};
i += 1;
EndFor


//---------------------------------------------------------------------------
Physical Surface("inlet") = {fg[1]};            
Physical Surface("outlet") = {fd[1]};   

Physical Surface("interface") = {s10:s20};                                                                
Physical Surface("jonction") = {s1:s9};  

Physical Surface("wall") = {ns[1],ns[2],ns[3],ns[4],ns[5],ns[6],ns[7],ns[8],
                            ns[9],ns[10],ns[11],ns[12],ns[13],ns[14],ns[15],ns[16],
                            ns[17],ns[18],ns[19],ns[20],ns[21],ns[22],ns[23],ns[24],ns[25],ns[26]};    




