cl1=120;
//main pipe diam
D=630.0-24;
R=D/2.0;
//piquage diametre, branch pipe diameter
dp=360.0;
//hauteur piquage à l'axe, height of crossing, at axis
z0=2192.0;
//longueur piquage, length of branch pipe
lp=1292;
//angle piquage, angle of branch
alpha=Pi/4;
//ellipse petit diam, intresecting ellips small diamter
by=dp/2;
//ellipse grand diam, large diameter
cz=by/Cos(alpha);
//rayon hauban shroud radius on ground
Rh=6000;

h3=6500.0;
h4=9000.0;
h5=13500.0;
h6=15000.0;

Point(1) = {0, 0, 0, cl1};
Point(2) = {R/2, -R*Cos(Pi/6), 0, cl1};
Point(3) = {R/2, R*Cos(Pi/6), 0, cl1};
Point(4) = {-R, 0, 0, cl1};




Point(10) = {0, 0, z0, cl1};

Point(21) = {0, 0, h3, cl1};

Point(22) = {R/2, -R*Cos(Pi/6), h3, cl1};
Point(23) = {R/2, R*Cos(Pi/6), h3, cl1};
Point(24) = {-R, 0, h3, cl1};

Line(12) = {2, 22};
Line(13) = {3, 23};
Line(14) = {4, 24};


//this function calculates the intresting point of of two lines
//one on main pipe, one one on branch
//for a given y
Function intersect1
	x=Sqrt(R*R-y*y);
	z0l=z0-Sqrt((1-y*y/by/by)*cz*cz);
	z=-Tan(alpha)*x+z0l;
	Point(1000+n) = {x, y, z, cl1};
Return


For i In {0:6}
	n=i+1;
	y=i*30;
	Call intersect1;
EndFor

Spline(1)= {1001:1007};

Symmetry {0, 0, 1, -z} {
  Duplicata { Line{1}; }
}

Symmetry {0, 1, 0, 0} {
  Duplicata { Line{1, 15}; }
}

Point(11) = {0, 0, z, cl1};
Point(101) = {lp*Sin(alpha), 0, z0-lp*Cos(alpha), cl1};
Point(102) = {lp*Sin(alpha)-dp/2*Cos(alpha), 0, z0-lp*Cos(alpha)-dp/2*Sin(alpha), cl1};
Point(103) = {lp*Sin(alpha), dp/2, z0-lp*Cos(alpha), cl1};
Point(104) = {lp*Sin(alpha)+dp/2*Cos(alpha), 0, z0-lp*Cos(alpha)+dp/2*Sin(alpha), cl1};
Point(105) = {lp*Sin(alpha), -dp/2, z0-lp*Cos(alpha), cl1};
Circle(102) = {102, 101, 103};
Circle(103) = {103, 101, 104};
Circle(104) = {104, 101, 105};
Circle(105) = {105, 101, 102};
Line(112) = {102, 1001};
Line(113) = {103, 1007};
Line(114) = {104, 1008};
Line(115) = {105, 1020};
Line Loop(122) = {102, 113, -1, -112};
Ruled Surface(122) = {-122};
Line Loop(123) = {103, 114, 15, -113};
Ruled Surface(123) = {-123};
Line Loop(124) = {104, 115, -17, -114};
Ruled Surface(124) = {-124};
Line Loop(125) = {105, 112, 16, -115};
Ruled Surface(125) = {-125};

Circle(2) = {2, 1, 3};
Circle(3) = {3, 1, 4};
Circle(4) = {4, 1, 2};

Circle(22) = {22, 21, 23};
Circle(23) = {23, 21, 24};
Circle(24) = {24, 21, 22};

Line Loop(28) = {2, 13, -22, -12};
Line Loop(29) = {16, -17, 15, -1};
Ruled Surface(30) = {28, 29};

Line Loop(126) = {3, 14, -23, -13};
Ruled Surface(127) = {126};
Line Loop(128) = {4, 12, -24, -14};
Ruled Surface(129) = {128};

Point(41) = {0, 0, h4, cl1};
Point(42) = {R/2, -R*Cos(Pi/6), h4, cl1};
Point(43) = {R/2, R*Cos(Pi/6), h4, cl1};
Point(44) = {-R, 0, h4, cl1};
Point(51) = {0, 0, h5, cl1};
Point(52) = {R/2, -R*Cos(Pi/6), h5, cl1};
Point(53) = {R/2, R*Cos(Pi/6), h5, cl1};
Point(54) = {-R, 0, h5, cl1};
Point(61) = {0, 0, h6, cl1};
Point(62) = {R/2, -R*Cos(Pi/6), h6, cl1};
Point(63) = {R/2, R*Cos(Pi/6), h6, cl1};
Point(64) = {-R, 0, h6, cl1};
Line(32) = {22, 42};
Line(33) = {23, 43};
Line(34) = {24, 44};

For i In {4:6}
	Circle(i*10 +2) = {i*10 +2, i*10 +1, i*10 +3};
	Circle(i*10 +3) = {i*10 +3, i*10 +1, i*10 +4};
	Circle(i*10 +4) = {i*10 +4, i*10 +1, i*10 +2};
	//Line((i-1)*10+2) = {(i-1)*10+2, i*10+2};
EndFor

For i In {5:6}
	Line((i-1)*10+5) = {(i-1)*10+2, i*10+2};
	Line((i-1)*10+6) = {(i-1)*10+3, i*10+3};
	Line((i-1)*10+7) = {(i-1)*10+4, i*10+4};
	//Line Loop((i-1)*10+5) = {(i-1)*10+2, (i-1)*10+6, -i*10+2, -(i-1)*10+5};
	//Ruled Surface((i-1)*10+5) = {(i-1)*10+5};
EndFor
//Line Loop(130) = {42, 46, -52, -45};
//Ruled Surface(131) = {130};
Line Loop(130) = {22, 33, -42, -32};
Ruled Surface(131) = {130};
Line Loop(132) = {23, 34, -43, -33};
Ruled Surface(133) = {132};
Line Loop(134) = {24, 32, -44, -34};
Ruled Surface(135) = {134};
Line Loop(136) = {42, 46, -52, -45};
Ruled Surface(137) = {136};
Line Loop(138) = {43, 47, -53, -46};
Ruled Surface(139) = {138};
Line Loop(140) = {44, 45, -54, -47};
Ruled Surface(141) = {140};
Line Loop(142) = {52, 56, -62, -55};
Ruled Surface(143) = {142};
Line Loop(144) = {53, 57, -63, -56};
Ruled Surface(145) = {144};
Line Loop(146) = {54, 55, -64, -57};
Ruled Surface(147) = {146};


Point(2002) = {Rh/2, -Rh*Cos(Pi/6), 0, cl1};
Point(2003) = {Rh/2, Rh*Cos(Pi/6), 0, cl1};
Point(2004) = {-Rh, 0, 0, cl1};
For i In {2:4}
	Line(2000+i) = {20+i, 2000+i};
	hb3[]+={(2000+i)};
	Line(2100+i) = {50+i, 2000+i};
	hb5[]+={(2100+i)};
EndFor

Transfinite Line {hb3[],hb5[]} = 2 Using Progression 1;

Physical Point("fixhb") = {2002:2004};
Physical Line("fixchem") = {2:4};
Physical Line("cerc") = {22, 23, 24, 52, 53, 54};


Physical Line("hb3") = hb3[];
Physical Line("hb5") = hb5[];
Physical Surface("piqa") = {122:125};
Physical Surface("chemb") = {30, 127, 129, 131, 133, 135};
Physical Surface("chemh") = {137, 139,141, 143, 145, 147};
