// =====================
// Geometrie du pont :
// =====================
// Largeur du pont :
B_up		= 27.2 /2.;
B_mid		= 29.  /2;
B_down		= 20.  /2;	

// Hauteur du pont :
H_min		= 1.;
H_max		= 3.;

// Longueur du pont (*1/2):
L_pont		= 728/2;
L_rigid		= 181;

// Domaine
lx_ext		= 500;
ly_ext		= L_pont+L_rigid;
lz_ext		= 200;

lx_box		= 15;
ly_box		= 15;
lz_box		= lx_box*0.75;

x_shift		= 100;
lx_sillage	= 300;

lx_sheet	= 3;
ly_sheet	= 0.3;

lx_sillage1	= 50;
lx_sillage2	= 50;
lx_sillage3	= 250;
lz_sillage	= 50;


// Longueur characteristiques 
l_char_ext	= lx_ext/5;
l_char_pont	= H_min/15;
l_char_sillage1	= lz_sillage/2;
l_char_sillage2	= lz_sillage/2;

// Domaine de calcul :
// -------------------
Point(1) = {-lx_ext+x_shift, 	-ly_ext, lz_ext, l_char_ext};
Point(2) = {-lx_ext+x_shift, 	 ly_ext, lz_ext, l_char_ext};
Point(3) = { lx_ext+x_shift,	 ly_ext, lz_ext, l_char_ext};
Point(4) = { lx_ext+x_shift, 	-ly_ext, lz_ext, l_char_ext};

Point(5) = {-lx_ext+x_shift, 	-ly_ext, -lz_ext, l_char_ext};
Point(6) = {-lx_ext+x_shift, 	 ly_ext, -lz_ext, l_char_ext};
Point(7) = { lx_ext+x_shift,	 ly_ext, -lz_ext, l_char_ext};
Point(8) = { lx_ext+x_shift, 	-ly_ext, -lz_ext, l_char_ext};




// ==================
// Profil du pont :
// ==================
// Section 0 :
Point(101) = {-B_up,	-L_pont-L_rigid,     0., l_char_pont};
Point(102) = { B_up,	-L_pont-L_rigid,     0., l_char_pont};
Point(103) = { B_mid,	-L_pont-L_rigid, -H_min, l_char_pont};
Point(104) = { B_down,	-L_pont-L_rigid, -H_max, l_char_pont};
Point(105) = {-B_down,	-L_pont-L_rigid, -H_max, l_char_pont};
Point(106) = {-B_mid,	-L_pont-L_rigid, -H_min, l_char_pont};

// Section 1 :
Point(111) = {-B_up,	-L_pont,     0., l_char_pont};
Point(112) = { B_up,	-L_pont,     0., l_char_pont};
Point(113) = { B_mid,	-L_pont, -H_min, l_char_pont};
Point(114) = { B_down,	-L_pont, -H_max, l_char_pont};
Point(115) = {-B_down,	-L_pont, -H_max, l_char_pont};
Point(116) = {-B_mid,	-L_pont, -H_min, l_char_pont};

// Section 2 :
Point(121) = {-B_up,	L_pont,     0., l_char_pont};
Point(122) = { B_up,	L_pont,     0., l_char_pont};
Point(123) = { B_mid,	L_pont, -H_min, l_char_pont};
Point(124) = { B_down,	L_pont, -H_max, l_char_pont};
Point(125) = {-B_down,	L_pont, -H_max, l_char_pont};
Point(126) = {-B_mid,	L_pont, -H_min, l_char_pont};

// Section 3 :
Point(131) = {-B_up,	L_pont+L_rigid,     0., l_char_pont};
Point(132) = { B_up,	L_pont+L_rigid,     0., l_char_pont};
Point(133) = { B_mid,	L_pont+L_rigid, -H_min, l_char_pont};
Point(134) = { B_down,	L_pont+L_rigid, -H_max, l_char_pont};
Point(135) = {-B_down,	L_pont+L_rigid, -H_max, l_char_pont};
Point(136) = {-B_mid,	L_pont+L_rigid, -H_min, l_char_pont};

// Couche limite :
// ===============
// Section 200 :

Point(201) = {-B_up-lx_box/3,	-L_pont-L_rigid,     0.+lz_box, l_char_pont};
Point(202) = { B_up+lx_box/3,	-L_pont-L_rigid,     0.+lz_box, l_char_pont};
Point(203) = { B_mid+lx_box,	-L_pont-L_rigid, -H_min-lz_box/3, l_char_pont};
Point(204) = { B_down+lx_box/5,	-L_pont-L_rigid, -H_max-lz_box, l_char_pont};
Point(205) = {-B_down-lx_box/5,	-L_pont-L_rigid, -H_max-lz_box, l_char_pont};
Point(206) = {-B_mid-lx_box,	-L_pont-L_rigid, -H_min-lz_box/3, l_char_pont};


// Section 201 :
Point(211) = {-B_up-lx_box/3,	-L_pont,     0.+lz_box,   l_char_pont};
Point(212) = { B_up+lx_box/3,	-L_pont,     0.+lz_box,   l_char_pont};
Point(213) = { B_mid+lx_box,	-L_pont, -H_min-lz_box/3, l_char_pont};
Point(214) = { B_down+lx_box/5,	-L_pont, -H_max-lz_box,   l_char_pont};
Point(215) = {-B_down-lx_box/5,	-L_pont, -H_max-lz_box,   l_char_pont};
Point(216) = {-B_mid-lx_box,	-L_pont, -H_min-lz_box/3, l_char_pont};

// Section 202 :
Point(221) = {-B_up-lx_box/3,	L_pont,     0.+lz_box,   l_char_pont};
Point(222) = { B_up+lx_box/3,	L_pont,     0.+lz_box,   l_char_pont};
Point(223) = { B_mid+lx_box,	L_pont, -H_min-lz_box/3, l_char_pont};
Point(224) = { B_down+lx_box/5,	L_pont, -H_max-lz_box,   l_char_pont};
Point(225) = {-B_down-lx_box/5,	L_pont, -H_max-lz_box,   l_char_pont};
Point(226) = {-B_mid-lx_box,	L_pont, -H_min-lz_box/3, l_char_pont};

// Section 203 :
Point(231) = {-B_up-lx_box/3,	+L_pont+L_rigid,     0.+lz_box,   l_char_pont};
Point(232) = { B_up+lx_box/3,	+L_pont+L_rigid,     0.+lz_box,   l_char_pont};
Point(233) = { B_mid+lx_box,	+L_pont+L_rigid, -H_min-lz_box/3, l_char_pont};
Point(234) = { B_down+lx_box/5,	+L_pont+L_rigid, -H_max-lz_box,   l_char_pont};
Point(235) = {-B_down-lx_box/5,	+L_pont+L_rigid, -H_max-lz_box,   l_char_pont};
Point(236) = {-B_mid-lx_box,	+L_pont+L_rigid, -H_min-lz_box/3, l_char_pont};

// Sillage :
Point(301) = { -B_mid-lx_sillage1,	-L_pont-L_rigid,     	0.+lz_box+lz_sillage, l_char_sillage1};
Point(302) = { -B_mid-lx_sillage1,	+L_pont+L_rigid,     	0.+lz_box+lz_sillage, l_char_sillage1};
Point(303) = { -B_mid-lx_sillage1,	-L_pont-L_rigid,    -H_min-lz_box-lz_sillage, l_char_sillage1};
Point(304) = { -B_mid-lx_sillage1,	+L_pont+L_rigid,    -H_min-lz_box-lz_sillage, l_char_sillage1};

Point(305) = { B_mid+lx_sillage2,	-L_pont-L_rigid,     	0.+lz_box+lz_sillage, l_char_sillage1};
Point(306) = { B_mid+lx_sillage2,	+L_pont+L_rigid,     	0.+lz_box+lz_sillage, l_char_sillage1};
Point(307) = { B_mid+lx_sillage2,	-L_pont-L_rigid,    -H_min-lz_box-lz_sillage, l_char_sillage1};
Point(308) = { B_mid+lx_sillage2,	+L_pont+L_rigid,    -H_min-lz_box-lz_sillage, l_char_sillage1};

Point(309) = { B_mid+lx_sillage2+lx_sillage3,	-L_pont-L_rigid,     	0.+lz_box+lz_sillage, l_char_sillage2};
Point(310) = { B_mid+lx_sillage2+lx_sillage3,	+L_pont+L_rigid,     	0.+lz_box+lz_sillage, l_char_sillage2};
Point(311) = { B_mid+lx_sillage2+lx_sillage3,	-L_pont-L_rigid,    -H_min-lz_box-lz_sillage, l_char_sillage2};
Point(312) = { B_mid+lx_sillage2+lx_sillage3,	+L_pont+L_rigid,    -H_min-lz_box-lz_sillage, l_char_sillage2};


Line(11) = {101,102};	// Section 0
Line(12) = {102,103};
Line(13) = {103,104};
Line(14) = {104,105};
Line(15) = {105,106};
Line(16) = {106,101};

Line(21) = {111,112};	// Section 1
Line(22) = {112,113};
Line(23) = {113,114};
Line(24) = {114,115};
Line(25) = {115,116};
Line(26) = {116,111};

Line(31) = {121,122}; 	// Section 2
Line(32) = {122,123};
Line(33) = {123,124};
Line(34) = {124,125};
Line(35) = {125,126};
Line(36) = {126,121};

Line(41) = {131,132};	// Section 3
Line(42) = {132,133};
Line(43) = {133,134};
Line(44) = {134,135};
Line(45) = {135,136};
Line(46) = {136,131};

Line(51) = {101,111};	// Section 0->1
Line(52) = {102,112};
Line(53) = {103,113};
Line(54) = {104,114};
Line(55) = {105,115};
Line(56) = {106,116};

Line(61) = {111,121};	// Section 1->2
Line(62) = {112,122};
Line(63) = {113,123};
Line(64) = {114,124};
Line(65) = {115,125};
Line(66) = {116,126};

Line(71) = {121,131};	// Section 2->3
Line(72) = {122,132};
Line(73) = {123,133};
Line(74) = {124,134};
Line(75) = {125,135};
Line(76) = {126,136};

// Domaine de calcul
Line(1001) = {1,2};	// Face sup.
Line(1002) = {2,3};
Line(1003) = {3,4};
Line(1004) = {4,1};
Line(1005) = {5,6};	// Face inf.
Line(1006) = {6,7};
Line(1007) = {7,8};
Line(1008) = {8,5};
Line(1009) = {1,5};	// Verticales
Line(1010) = {2,6};
Line(1011) = {3,7};
Line(1012) = {4,8};


// "Couche limite"
Line(111) = {201,202};	// Section 0
Line(112) = {202,203};
Line(113) = {203,204};
Line(114) = {204,205};
Line(115) = {205,206};
Line(116) = {206,201};

Line(121) = {211,212};	// Section 1
Line(122) = {212,213};
Line(123) = {213,214};
Line(124) = {214,215};
Line(125) = {215,216};
Line(126) = {216,211};

Line(131) = {221,222};	// Section 2
Line(132) = {222,223};
Line(133) = {223,224};
Line(134) = {224,225};
Line(135) = {225,226};
Line(136) = {226,221};

Line(141) = {231,232};	// Section 3
Line(142) = {232,233};
Line(143) = {233,234};
Line(144) = {234,235};
Line(145) = {235,236};
Line(146) = {236,231};

Line(151) = {201,211};	// Section 0->1
Line(152) = {202,212};
Line(153) = {203,213};
Line(154) = {204,214};
Line(155) = {205,215};
Line(156) = {206,216};

Line(161) = {211,221};	// Section 1->2
Line(162) = {212,222};
Line(163) = {213,223};
Line(164) = {214,224};
Line(165) = {215,225};
Line(166) = {216,226};

Line(171) = {221,231};	// Section 2->3
Line(172) = {222,232};
Line(173) = {223,233};
Line(174) = {224,234};
Line(175) = {225,235};
Line(176) = {226,236};


// Sillage
Line(300) = {301,302};	// Horizontales selon y
Line(301) = {303,304};
Line(302) = {305,306};
Line(303) = {307,308};
Line(304) = {309,310};
Line(305) = {311,312};
Line(306) = {301,305};	// Horizontales selon x
Line(307) = {302,306};
Line(308) = {303,307};
Line(309) = {304,308};
Line(310) = {305,309};
Line(311) = {306,310};
Line(312) = {307,311};
Line(313) = {308,312};
Line(314) = {301,303};	// Verticales
Line(315) = {302,304};
Line(316) = {305,307};
Line(317) = {306,308};
Line(318) = {309,311};
Line(319) = {310,312};


// Connections int.->ext.
For i In {0:3}
	For j In {1:6}
		Line(500+i*10+j) = {100+i*10+j, 200+i*10+j};
	EndFor
EndFor


// ===================
// Surfaces :
// ===================
// Pont et Couche limite:
For n In {0:1}
	For i In{1:3}
		For j In{1:5}
			Line Loop(n*100+i*10+j) = {-(n*100+10*i+j), n*100+10*i+j+40, n*100+10*i+j+10, -(n*100+10*i+j+41) };
			Plane Surface(n*100+i*10+j) = {n*100+i*10+j};
		EndFor
		Line Loop(n*100+i*10+6) = {-(n*100+10*i+6), n*100+10*i+6+40, n*100+10*i+6+10, -(n*100+10*i+41) };
		Plane Surface(n*100+i*10+6) = {n*100+i*10+6};
	EndFor
EndFor


// Connection pont->couche limite
For i In{0:3}
		For j In{1:5}
			Line Loop(300+i*10+j) = {(500+10*i+j), 100+10*(i+1)+j, -(500+10*i+j+1), -(10*(i+1)+j) };
			Plane Surface(300+i*10+j) = {300+i*10+j};
		EndFor
		Line Loop(300+i*10+6) = {(500+10*i+6), 100+10*(i+1)+6, -(500+10*i+1), -(10*(i+1)+6) };
		Plane Surface(300+i*10+6) = {300+i*10+6};
EndFor

For i In{0:2}
		For j In{1:6}
			Line Loop(400+i*10+j) = {(500+10*i+j), 100+10*(i+5)+j, -(500+10*(i+1)+j), -(10*(i+5)+j) };
			Plane Surface(400+i*10+j) = {400+i*10+j};
		EndFor
EndFor


// Sillage

Line Loop(601) = {306,302,-307,-300};		Plane Surface(601) = {601};
Line Loop(602) = {308,303,-309,-301};		Plane Surface(602) = {602};
Line Loop(603) = {314,301,-315,-300};		Plane Surface(603) = {603};
Line Loop(604) = {316,303,-317,-302};		Plane Surface(604) = {604};
Line Loop(605) = {306,316,-308,-314};		
Line Loop(606) = {111,112,113,114,115,116};	Plane Surface(605) = {605,606};
Line Loop(607) = {307,317,-309,-315};
Line Loop(608) = {141,142,143,144,145,146};	Plane Surface(607) = {607,608};
Line Loop(609) = {310,304,-311,-302};		Plane Surface(609) = {609};
Line Loop(610) = {312,305,-313,-303};		Plane Surface(610) = {610};
Line Loop(611) = {310,318,-312,-316};		Plane Surface(611) = {611};
Line Loop(612) = {311,319,-313,-317};		Plane Surface(612) = {612};
Line Loop(613) = {304,319,-305,-318};		Plane Surface(613) = {613};


// Domaine de calcul
Line Loop(1000) = {1004,1001,1002,1003};	Plane Surface(1000) = {1000};
Line Loop(1001) = {1008,1005,1006,1007};	Plane Surface(1001) = {1001};
Line Loop(1002) = {1001,1010,-1005,-1009};	Plane Surface(1002) = {1002};
Line Loop(1003) = {1003,1012,-1007,-1011};	Plane Surface(1003) = {1003};
Line Loop(1004) = {1004,1009,-1008,-1012};	
Line Loop(1005) = {306,310,318,-312,-308,-314};	Plane Surface(1004) = {1004,1005};
Line Loop(1006) = {1002,1011,-1006,-1010};
Line Loop(1007) = {307,311,319,-313,-309,-315};	Plane Surface(1006) = {1006,1007};


// Volumes :
// ---------
For i In {1:3}
	For j In {1:5}

		Surface Loop(i*10+j) = {i*10+j, 100+i*10+j, 300+(i-1)*10+j, 300+i*10+j, 400+(i-1)*10+j, 400+(i-1)*10+j+1 };
		Volume(i*10+j) 	     = {i*10+j};
	EndFor
	Surface Loop(i*10+6) = {i*10+6, 100+i*10+6, 300+(i-1)*10+6, 300+i*10+6, 400+(i-1)*10+6, 400+(i-1)*10+1 };
	Volume(i*10+6) 	     = {i*10+6};
EndFor



//===================
// Maillage :
//===================

// Lignes :
// --------
// Section 0 a 3
For i In {1:4}
	Transfinite Line{i*10+1, 100+i*10+1} = 6 Using Bump 0.4;	// 12
	Transfinite Line{i*10+2, i*10+6, 100+i*10+2, 100+i*10+6} = 4;	// 8
	Transfinite Line{i*10+3, i*10+5, 100+i*10+3, 100+i*10+5} = 4;	// 8
	Transfinite Line{i*10+4, 100+i*10+4} = 5 Using Bump 0.6;	// 10
EndFor


// Connections int.->ext.
For i In {0:3}
	For j In {1:6}
		Transfinite Line{500+i*10+j} = 10 Using Progression 1.3;
	EndFor
EndFor


// Section i->i+1
For j In {1:6}
	Transfinite Line{50+j, 150+j, 70+j, 170+j} = 7;
	Transfinite Line{60+j, 160+j}		   = 30;
EndFor


// Surfaces :
// ----------

For n In {0:1}
	For i In {0:2}
		For j In {1:5}
			Transfinite Surface{n*100+(i+1)*10+j} = {(n+1)*100+i*10+j,(n+1)*100+(i+1)*10+j, (n+1)*100+(i+1)*10+j+1, (n+1)*100+i*10+j+1 };
		EndFor
		Transfinite Surface{n*100+(i+1)*10+6} = {(n+1)*100+i*10+6,(n+1)*100+(i+1)*10+6, (n+1)*100+(i+1)*10+1, (n+1)*100+i*10+1 };
	EndFor
EndFor



// Connection pont->couche limite
For i In{0:3}
		For j In{1:5}
			Transfinite Surface{300+i*10+j} = {100+i*10+j, 200+i*10+j, 200+i*10+j+1, 100+i*10+j+1 };
		EndFor
		Transfinite Surface{300+i*10+6} = {100+i*10+6, 200+i*10+6, 200+i*10+1, 100+i*10+1 };
EndFor

For i In{1:3}
		For j In{1:6}
			Transfinite Surface{400+(i-1)*10+j} = {100+(i-1)*10+j, 200+(i-1)*10+j, 200+i*10+j, 100+i*10+j };
		EndFor
EndFor



// Volumes :
// ---------
For i In {1:3}
For j In {1:5}
Transfinite Volume{i*10+j} = { 200+(i-1)*10+j, 200+i*10+j, 200+i*10+j+1, 200+(i-1)*10+j+1, 100+(i-1)*10+j, 100+i*10+j, 100+i*10+j+1, 100+(i-1)*10+j+1 };
EndFor
Transfinite Volume{i*10+6} = {200+(i-1)*10+6, 200+i*10+6, 200+i*10+1, 200+(i-1)*10+1, 100+(i-1)*10+6, 100+i*10+6, 100+i*10+1, 100+(i-1)*10+1 };
EndFor



Surface Loop(1) = {1000,1004,1002,1006,1003,1001,613,609,610,601,603,602};	Volume(1) = {1};
Surface Loop(2) = {601,603,602,605,607,116,126,136,131,121,111,112,122,132,133,123,125,124,115,134,135,113,114,604};
Volume(2) = {2};
Surface Loop(3) = {609,613,610,611,612,604};	Volume(3) = {3};

