/********************************************************************* 
 *
 *  Gmsh mesh for triangular obstacle of Sanquer's Thesis
 * 
 *  By Wladimyr M. C. Dourado, 06/Aug/03 SJC/BR
 *
 *********************************************************************/
 
 
// Including the parameters

Include "triang-obst-parameters.geo" ;


// The new anisotropic 2D mesh generator can be selected with:

Mesh.Algorithm = 2 ;

// One can force a 4 step Laplacian smoothing of the mesh with:

Mesh.Smoothing = 4 ;

/********************************************************************* 
 * GEOMETRY DEFINITION
 * 
 *********************************************************************/

/***********************************
 * Defining the points of obstacle
 * 
 ***********************************/
If( pts_obst_def == 0)
  lastp = 0;
  p1=newp+lastp; Point(p1) = {xpd1,ypd1,Z0,lc_died};
  p2=newp; Point(p2) = {xpd2,ypd2,Z0,lc_died};
  p3=newp; Point(p3) = {xpd3,ypd3,Z0,lc_died};
  
  pts_obst_def = 1; 
  lastp=p3+1;
  
EndIf

hblffo = 0.11*H;   // Altura do bloco estrut. junto as par. frontais obstaculo
hblbfo = 0.21*d;   // Altura do bloco estrut. junto a parede traz. obstaculo
hblwoz = 0.07*H;   // Altura do bloco estruturado prox. parede do canal
Lblwoz = ht + hblffo;

p8=newp+lastp; Point(p8) = {X0-Lblwoz,Y0+delta,Z0,lc};
p9=newp;
Symmetry { 0,1,0,Y0-h } {
  Duplicata { Point{p8}; }
}
p10=newp;Point(p10) = {X0,Y0+delta,Z0,lc_he};
p11=newp;
Symmetry { 0,1,0,Y0-h } {
  Duplicata { Point{p10}; }
}

p12=newp; Point(p12) = {X0-Lblwoz,Y0+hblwoz+delta,Z0,lc/5.};
p13=newp;
Symmetry { 0,1,0,Y0-h } {
  Duplicata { Point{p12}; }
}

p14=newp; Point(p14) = {X0,Y0+(hp/h)*hblwoz+delta,Z0,lc/5.};
p15=newp;
Symmetry { 0,1,0,Y0-h } {
  Duplicata { Point{p14}; }
}

alt_triag_fict = (ht+deltaobst*(1.+1./Sin(alpha/2.)));
d_triag_fict = 2*alt_triag_fict*Tan(alpha/2.);
p16=newp; Point(p16) = {X0-(ht+deltaobst/Sin(alpha/2.)),Y0+h,Z0,lc/20.};

p17=newp; Point(p17) = {X0+deltaobst,Y0+h-alt_triag_fict*Tan(alpha/2.),Z0,lc};
p18=newp;
Symmetry { 0,1,0,Y0-h } {
  Duplicata { Point{p17}; }
}

p19=newp; Point(p19) = {X0+deltaobst-alt_triag_fict-Cos(alpha)*hblffo,Y0+h-Sin(alpha)*hblffo,Z0,lc/20.};
p20=newp;
Symmetry { 0,1,0,Y0-h } {
  Duplicata { Point{p19}; }
}

p21=newp; Point(p21) = {X0+deltaobst,Y0+h-alt_triag_fict*Tan(alpha/2.)-(hp/h)*hblffo/Cos(alpha/2.),Z0,lc};
p22=newp;
Symmetry { 0,1,0,Y0-h } {
  Duplicata { Point{p21}; }
}

p23=newp; Point(p23) = {X0+deltaobst+hblbfo,Y0+h-alt_triag_fict*Tan(alpha/2.),Z0,lc};
p24=newp;
Symmetry { 0,1,0,Y0-h } {
  Duplicata { Point{p23}; }
}


/********************* 
 * LINES DEFINITION
 * 
 *********************/

lastc = 4;

l5 = newc+lastc; Line(l5) = {p8,p10};
l6 = newc; Line(l6) = {p10,p14};
l7 = newc; Line(l7) = {p12,p14};
l8 = newc; Line(l8) = {p8,p12};
 
l9 = newc; Line(l9) = {p9,p11};
l10 = newc; Line(l10) = {p9,p13};
l11 = newc; Line(l11) = {p13,p15};
l12 = newc; Line(l12) = {p11,p15};

l13 = newc; Line(l13) = {p16,p17};
l14 = newc; Line(l14) = {p19,p21};
l15 = newc; Line(l15) = {p16,p19};
l16 = newc; Line(l16) = {p17,p21};

l17 = newc; Line(l17) = {p16,p18};
l18 = newc; Line(l18) = {p20,p22};
l19 = newc; Line(l19) = {p16,p20};
l20 = newc; Line(l20) = {p18,p22};

l21 = newc; Line(l21) = {p17,p18};
l22 = newc; Line(l22) = {p23,p24};
l23 = newc; Line(l23) = {p17,p23};
l24 = newc; Line(l24) = {p18,p24};

 /********************* 
 * SURFACES DEFINITION
 * 
 *********************/
lastll = 1; lasts=1;
ll2 = (newll+lastll); newll++; Line Loop(ll2) = {l6,-l7,-l8,l5};
s2 = news+lasts;Ruled Surface(s2) = {ll2};
ll3 = newll+lastll; newll++; Line Loop(ll3) = {l16,-l14,-l15,l13};
s3 = news; Ruled Surface(s3) = {ll3};
ll4 = newll+lastll; newll++; Line Loop(ll4) = {l24,-l22,-l23,l21};
s4 = news; Ruled Surface(s4) = {ll4};
ll5 = newll+lastll; newll++; Line Loop(ll5) = {-l17,l19,l18,-l20};
s5 = news; Ruled Surface(s5) = {ll5};
ll6 = newll+lastll; newll++; Line Loop(ll6) = {-l12,-l9,l10,l11};
s6 = news; Ruled Surface(s6) = {ll6};


/********************* 
 * PHYSICAL DEFINITION
 * 
 *********************/
Physical Point(cc_parede_canal) = {p8,p10};
Physical Point(cc_parede_canal) = {p9,p11};
Physical Point(cc_paredes_frontais) = {p16,p17,p18};

Physical Line(cc_parede_canal) = {l5};
Physical Line(cc_parede_canal) = {l9};
Physical Line(cc_paredes_frontais) = {l13,l17};
Physical Line(cc_parede_trazeira) = {l21};

Physical Point(dominio1) = {p12,p14};
Physical Point(dominio1) = {p19,p21,p23,p24,p22,p20};
Physical Point(dominio1) = {p13,p15};

Physical Line(dominio1) = {l14,l16,l23,l22,l24,l20,l18,l19,l15};
Physical Line(dominio1) = {l8,l7,l6};
Physical Line(dominio1) = {l10,l11,l12};

/********************************************************************* 
 * MESH DEFINITION
 * 
 *********************************************************************/


lastp = newp - 1;
lastc = newc - 1;
lasts = news - 1;
lastll = newll - 1;
lastreg = newreg - 1;


nys2s6 = 10;             // Numero de pontos na dir y das superfs s2 e s6
nxs2s6 = 13;             // Numero de pontos na dir x das superfs s2 e s6
stchy_s2s6 = 1.3;        // Stretching na dir y da superficies s2 e s6

Transfinite Line {l6,l8} = nys2s6 Using Progression stchy_s2s6;
Transfinite Line {l10,l12} =  nys2s6 Using Progression stchy_s2s6;
Transfinite Line {l5,l7} = nxs2s6;
Transfinite Line {l9,l11} = nxs2s6;

Transfinite Surface {s2} = {p8,p10,p14,p12};
Recombine Surface {s2};

Transfinite Surface {s6} = {p11,p9,p13,p15};
Recombine Surface {s6};

nys3s5 = 10;              // Numero de pontos na dir y das superfs s3 e s5
stchy_s3s5 = 1.3;         // Stretching na dir y da superficies s3 e s5
nxs3s5 = 30;              // Numero de pontos na dir x das superfs s3 e s5
stchx_s3s5 = 1./6.;       // Stretching na dir x da superficies s3 e s5

Transfinite Line {l16,l15} = nys3s5 Using Progression stchy_s3s5;
Transfinite Line {l14,l13} = nxs3s5 Using Bump stchx_s3s5;
Transfinite Surface {s3} = {p19,p21,p17,p16};
Recombine Surface {s3};

Transfinite Line {l19,l20} = nys3s5 Using Progression stchy_s3s5;
Transfinite Line {l17,l18} = nxs3s5 Using Bump stchx_s3s5;
Transfinite Surface {s5} = {p16,p18,p22,p20};
Recombine Surface {s5};

nys4 = 10;              // Numero de pontos na dir y das superf s4
stchy_s4 = 1.3;         // Stretching na dir y da superficie s4
nxs4 = 30;              // Numero de pontos na dir x das superf s4
stchx_s4 = 1./2.;       // Stretching na dir x da superficie s4

Transfinite Line {l23,l24} = nys4 Using Progression stchy_s4;
Transfinite Line {l21,l22} = nxs4 Using Bump stchx_s4;
Transfinite Surface {s4} = {p17,p23,p24,p18};
Recombine Surface {s4};



/********************************************************************* 
 * TO TEST
 * 
 *********************************************************************/

Line(25) = {14,21};
Line(26) = {12,19};
Line(27) = {15,22};
Line(28) = {13,20};
Circle(29) = {20,16,19};
Line Loop(7) = {18,-27,-11,28};
Plane Surface(7) = {7};
Line Loop(8) = {14,-25,-7,26};
Plane Surface(8) = {8};
Line Loop(9) = {-15,19,29};
Plane Surface(9) = {9};
Transfinite Line {28,27,26,25} = 10 Using Bump .3;
Attractor Line{l18,l11} = {1,.25,8};
