// Primer ensayo con longitud de la tuberia 50 mm mas larga y seccion maciza de diametro 10.42mm

lc=8;
l=500;
a=80;
b=50;

Point(1)={-250,25,40,lc};
Point(2)={-250,-25,40,lc};
Point(3)={-250,-25,-40,lc};
Point(4)={-250,25,-40,lc};

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

Line Loop(1)={1,2,3,4};
Plane Surface(1)={1};


v[] = Extrude Surface{1,{500,0,0}};;

Delete{Volume{v[1]};Surface{25};}

//Primer agujero

lc=5;

r1=5.21;
x11=r1*Sin(0);
y11=r1*Cos(0);

x22=r1*Sin(Pi/2);
y22=r1*Cos(Pi/2);

x33=r1*Sin(Pi);
y33=r1*Cos(Pi);

x44=r1*Sin(Pi*3/2);
y44=r1*Cos(Pi*3/2);

Point(7)={-140+x11, 22.5, 20+y11, lc};
Point(8)={-140+x22, 22.5, 20-y22, lc};
Point(9)={-140+x33, 22.5, 20+y33, lc};
Point(11)={-140+x44, 22.5, 20-y44, lc};
Point(12)={-140, 22.5, 20, lc};

c1=newreg;
Circle(c1)={7,12,8};
c2=newreg;
Circle(c2)={8,12,9};
c3=newreg;
Circle(c3)={9,12,11};
c4=newreg;
Circle(c4)={11,12,7};

Line Loop(2)={c1,c2,c3,c4};
Plane Surface(2)={2};
Extrude Surface{2,{0,2.5,0}};

//Segundo agujero

Point(18)={140+x11, 22.5, 20+y11, lc};
Point(19)={140+x22, 22.5, 20-y22, lc};
Point(20)={140+x33, 22.5, 20+y33, lc};
Point(21)={140+x44, 22.5, 20-y44, lc};
Point(23)={140, 22.5, 20, lc};

c11=newreg;
Circle(c11)={18,23,19};
c22=newreg;
Circle(c22)={19,23,20};
c33=newreg;
Circle(c33)={20,23,21};
c44=newreg;
Circle(c44)={21,23,18};
Line Loop(3)={c11,c22,c33,c44};
Plane Surface(3)={3};
Extrude Surface{3,{0,2.5,0}};

// Tercer agujero

Point(24)={-140+x11, 22.5, -20+y11, lc};
Point(25)={-140+x22, 22.5, -20-y22, lc};
Point(26)={-140+x33, 22.5, -20+y33, lc};
Point(31)={-140+x44, 22.5, -20-y44, lc};
Point(32)={-140, 22.5, -20, lc};

c111=newreg;
Circle(c111)={24,32,25};
c222=newreg;
Circle(c222)={25,32,26};
c333=newreg;
Circle(c333)={26,32,31};
c444=newreg;
Circle(c444)={31,32,24};
Line Loop(4)={c111,c222,c333,c444};
Plane Surface(4)={4};
Extrude Surface{4,{0,2.5,0}};

// Cuarto  agujero

Point(33)={140+x11, 22.5, -20+y11, lc};
Point(34)={140+x22, 22.5, -20-y22, lc};
Point(36)={140+x33, 22.5, -20+y33, lc};
Point(37)={140+x44, 22.5, -20-y44, lc};
Point(38)={140, 22.5, -20, lc};

c1111=newreg;
Circle(c1111)={33,38,34};
c2222=newreg;
Circle(c2222)={34,38,36};
c3333=newreg;
Circle(c3333)={36,38,37};
c4444=newreg;
Circle(c4444)={37,38,33};
Line Loop(5)={c1111,c2222,c3333,c4444};
Plane Surface(5)={5};
Extrude Surface{5,{0,2.5,0}};


Line Loop(53)={20,9,-11,-4};
Line Loop(54)={35,32,33,34};
Line Loop(55)={58,59,60,61};
Line Loop(56)={110,111,112,113};
Line Loop(57)={84,85,86,87};

Plane Surface(55)={53,54,55,56,57};

Surface Loop(56)={1,-13,-17,-21,55,-26,-47,2,-39,-43,-51,73,77,65,69,3,125,129,121,117,5,99,103,91,95,4};
Volume(57)={56};

// Primera tuberia

Extrude Surface{52,{0,60,0}};
Extrude Surface{152,{40,85.5,0}};

Extrude Surface{174,{0,62.5,0}};
Extrude Surface{196,{0,62.5,0}};
Extrude Surface{218,{0,62.5,0}};
Extrude Surface{240,{0,62.5,0}};

Extrude Surface{262,{0,0,1},{0,420.5,20},-Pi/4};
Extrude Surface{284,{0,0,1},{0,420.5,20},-Pi/4};
Extrude Surface{306,{0,0,1},{0,420.5,20},-Pi/4};
Extrude Surface{328,{0,0,1},{0,420.5,20},-Pi/4};

Extrude Surface{350,{0,-62.5,0}};
Extrude Surface{372,{0,-62.5,0}};
Extrude Surface{394,{0,-62.5,0}};
Extrude Surface{416,{0,-62.5,0}};

Extrude Surface{438,{40,-85.5,0}};
Extrude Surface{460,{0,-60,0}};

//Segunda Tuberia

Extrude Surface{104,{0,60,0}};
Extrude Surface{503,{40,85.5,0}};

Extrude Surface{525,{0,62.5,0}};
Extrude Surface{547,{0,62.5,0}};
Extrude Surface{569,{0,62.5,0}};
Extrude Surface{591,{0,62.5,0}};

Extrude Surface{613,{0,0,1},{0,420.5,20},-Pi/4};
Extrude Surface{635,{0,0,1},{0,420.5,20},-Pi/4};
Extrude Surface{657,{0,0,1},{0,420.5,20},-Pi/4};
Extrude Surface{679,{0,0,1},{0,420.5,20},-Pi/4};

Extrude Surface{701,{0,-62.5,0}};
Extrude Surface{723,{0,-62.5,0}};
Extrude Surface{745,{0,-62.5,0}};
Extrude Surface{767,{0,-62.5,0}};

Extrude Surface{789,{40,-85.5,0}};
Extrude Surface{811,{0,-60,0}};
















