s1 = 8.765000E-05 ;
s3 = 8.765000E-04 ;
s2 = 2.629500E-04 ;

Cx = 7.350000E-03 ;
Cx0 = 0.000000E+00 ;
Cy = 0.000000E+00 ;
Cz = 0.000000E+00 ;
R1 = 8.765000E-04 ;
R2 = 1.587500E-03 ;
R3 = 1.250000E-02 ;
dh = 1.190000E-03 ;

// Points for tube inner and outer surfaces

Point (1) = { Cx, Cy, Cz,s1};
Point (2) = { Cx+R1, Cy, Cz,s1};
Point (3) = { Cx, Cy+R1, Cz,s1};
Point (4) = { Cx-R1, Cy, Cz,s1};
Point (5) = { Cx, Cy-R1, Cz,s1};
Point (6) = { Cx+R2, Cy, Cz,s2};
Point (7) = { Cx, Cy+R2, Cz,s2};
Point (8) = { Cx-R2, Cy, Cz,s2};
Point (9) = { Cx, Cy-R2, Cz,s2};

// Points for shell inner surface

Point (10) = { Cx0, Cy-dh-Cx/2-7.350000E-03, Cz,s1};
Point (11) = { Cx0+R3, Cy-dh-Cx/2-7.350000E-03, Cz,s3};
Point (12) = { Cx0, Cy-dh-Cx/2-7.350000E-03, Cz+R3,s3};
Point (13) = { Cx0-R3, Cy-dh-Cx/2-7.350000E-03, Cz,s3};
Point (14) = { Cx0, Cy-dh-Cx/2-7.350000E-03, Cz-R3,s3};

Point (15) = { Cx0+R2, Cy-dh-Cx/2-7.350000E-03, Cz,s2};
Point (16) = { Cx0, Cy-dh-Cx/2-7.350000E-03, Cz+R2,s2};
Point (17) = { Cx0-R2, Cy-dh-Cx/2-7.350000E-03, Cz,s2};
Point (18) = { Cx0, Cy-dh-Cx/2-7.350000E-03, Cz-R2,s2};

Point (19) = { Cx0, Cy+(4*2+1)*dh+Cx/2+7.350000E-03, Cz,s1};
Point (20) = { Cx0+R3, Cy+(4*2+1)*dh+Cx/2+7.350000E-03, Cz,s1};
Point (21) = { Cx0, Cy+(4*2+1)*dh+Cx/2+7.350000E-03, Cz+R3,s1};
Point (22) = { Cx0-R3, Cy+(4*2+1)*dh+Cx/2+7.350000E-03, Cz,s1};
Point (23) = { Cx0, Cy+(4*2+1)*dh+Cx/2+7.350000E-03, Cz-R3,s1};
Point (24) = { Cx0+R2, Cy+(4*2+1)*dh+Cx/2+7.350000E-03, Cz,s2};
Point (25) = { Cx0, Cy+(4*2+1)*dh+Cx/2+7.350000E-03, Cz+R2,s2};
Point (26) = { Cx0-R2, Cy+(4*2+1)*dh+Cx/2+7.350000E-03, Cz,s2};
Point (27) = { Cx0, Cy+(4*2+1)*dh+Cx/2+7.350000E-03, Cz-R2,s2};

// Circles for tube inner and outer surfaces

Circle(1) = {2,1,3};
Circle(2) = {3,1,4};
Circle(3) = {4,1,5};
Circle(4) = {5,1,2};
Circle(5) = {6,1,7};
Circle(6) = {7,1,8};
Circle(7) = {8,1,9};
Circle(8) = {9,1,6};

// Circle for shell inner surface

Circle(9)  = {11,10,12};
Circle(10) = {12,10,13};
Circle(11) = {13,10,14};
Circle(12) = {14,10,11};

Circle(13) = {15,10,16};
Circle(14) = {16,10,17};
Circle(15) = {17,10,18};
Circle(16) = {18,10,15};

Circle(17) = {20,19,21};
Circle(18) = {21,19,22};
Circle(19) = {22,19,23};
Circle(20) = {23,19,20};

Circle(21) = {24,19,25};
Circle(22) = {25,19,26};
Circle(23) = {26,19,27};
Circle(24) = {27,19,24};

// lines for shell inner surface

Line(25) = {11,20};
Line(26) = {12,21};
Line(27) = {13,22};
Line(28) = {14,23};

// line loops for tube inner and outer surfaces

Line Loop(10) = {1,2,3,4};		//tube int circ
Line Loop(20) = {5,6,7,8};		//tube ext circ

// surface for tube inner and outer surfaces

Plane Surface(30) = {10};
Plane Surface(40) = {20,10};

// notes: Layers{n}, n is the number of node in the extrusion direction

/* ********* FLUID PART ************ */

ext1[] = Extrude {{0,dh,0}, {0,1,0}, {0,0,0}, Pi/2} {
  Surface{30};
 Layers{5}; Recombine;};

ext2[] = Extrude {{0,dh,0}, {0,1,0}, {0,0,0}, Pi/2} {
  Surface{ext1[0]};
 Layers{5}; Recombine;};

ext3[] = Extrude {{0,dh,0}, {0,1,0}, {0,0,0}, Pi/2} {
  Surface{ext2[0]};
 Layers{5}; Recombine;};

ext4[] = Extrude {{0,dh,0}, {0,1,0}, {0,0,0}, Pi/2} {
  Surface{ext3[0]};
 Layers{5}; Recombine;};

ext5[] = Extrude {{0,dh,0}, {0,1,0}, {0,0,0}, Pi/2} {
  Surface{ext4[0]};
 Layers{5}; Recombine;};

ext6[] = Extrude {{0,dh,0}, {0,1,0}, {0,0,0}, Pi/2} {
  Surface{ext5[0]};
 Layers{5}; Recombine;};

ext7[] = Extrude {{0,dh,0}, {0,1,0}, {0,0,0}, Pi/2} {
  Surface{ext6[0]};
 Layers{5}; Recombine;};

ext8[] = Extrude {{0,dh,0}, {0,1,0}, {0,0,0}, Pi/2} {
  Surface{ext7[0]};
 Layers{5}; Recombine;};

ext9[] = Extrude {{0,dh,0}, {0,1,0}, {Cx/2,Cy,Cz}, Pi/2} {
  Surface{ext8[0]};
 Layers{5}; Recombine;};

ext10[] = Extrude {{0,-dh,0}, {0,1,0}, {Cx/2,Cy,Cz}, -Pi/2} {
  Surface{30};
 Layers{5}; Recombine;};

ext11[] = Extrude {{0,0,Cx/2}, {0,0,1}, {Cx/2, Cy+(4*2+1)*dh+Cx/2,Cz}, -Pi/2}  {
  Surface{ext9[0]};
 Layers{2*5}; Recombine;};

ext12[] = Extrude {{0,0,-Cx/2}, {0,0,1}, {Cx/2,Cy-dh-Cx/2,Cz}, Pi/2} {
  Surface{ext10[0]};
 Layers{2*5}; Recombine;};

ext13[] =Extrude {0,7.350000E-03, 0} {
  Surface{ext11[0]};
 Layers{4*5}; Recombine;};

ext14[] =Extrude {0,-7.350000E-03, 0} {
  Surface{ext12[0]};
 Layers{4*5}; Recombine;};

Physical Surface("inlet") = {ext13[0]};
Physical Surface("outlet") = {ext14[0]};

Physical Surface("coilInnerSurface")= {ext1[2],ext1[3],ext1[4],ext1[5],ext2[2],ext2[3],ext2[4],ext2[5],ext3[2],ext3[3],ext3[4],ext3[5],ext4[2],ext4[3],ext4[4],ext4[5],ext5[2],ext5[3],ext5[4],ext5[5],
ext6[2],ext6[3],ext6[4],ext6[5],ext7[2],ext7[3],ext7[4],ext7[5],ext8[2],ext8[3],ext8[4],ext8[5],ext9[2],ext9[3],ext9[4],ext9[5],ext10[2],ext10[3],ext10[4],ext10[5],
ext11[2],ext11[3],ext11[4],ext11[5],ext12[2],ext12[3],ext12[4],ext12[5],ext13[2],ext13[3],ext13[4],ext13[5],ext14[2],ext14[3],ext14[4],ext14[5],ext14[2],ext14[3],ext14[4],ext14[5]};

Physical Volume("hotFluid")= {ext1[1],ext2[1],ext3[1],ext4[1],ext5[1],ext6[1],ext7[1],ext8[1],ext9[1],ext10[1],
ext11[1],ext12[1],ext13[1],ext14[1],ext14[1]};

/* ********* SOLID PART ************ */

ext15[] = Extrude {{0,dh,0}, {0,1,0}, {0,0,0}, Pi/2} {
  Surface{40};
 Layers{5}; Recombine;};

ext16[] = Extrude {{0,dh,0}, {0,1,0}, {0,0,0}, Pi/2} {
  Surface{ext15[0]};
 Layers{5}; Recombine;};

ext17[] = Extrude {{0,dh,0}, {0,1,0}, {0,0,0}, Pi/2} {
  Surface{ext16[0]};
 Layers{5}; Recombine;};

ext18[] = Extrude {{0,dh,0}, {0,1,0}, {0,0,0}, Pi/2} {
  Surface{ext17[0]};
 Layers{5}; Recombine;};

ext19[] = Extrude {{0,dh,0}, {0,1,0}, {0,0,0}, Pi/2} {
  Surface{ext18[0]};
 Layers{5}; Recombine;};

ext20[] = Extrude {{0,dh,0}, {0,1,0}, {0,0,0}, Pi/2} {
  Surface{ext19[0]};
 Layers{5}; Recombine;};

ext21[] = Extrude {{0,dh,0}, {0,1,0}, {0,0,0}, Pi/2} {
  Surface{ext20[0]};
 Layers{5}; Recombine;};

ext22[] = Extrude {{0,dh,0}, {0,1,0}, {0,0,0}, Pi/2} {
  Surface{ext21[0]};
 Layers{5}; Recombine;};

ext23[] = Extrude {{0,dh,0}, {0,1,0}, {Cx/2,Cy,Cz}, Pi/2} {
  Surface{ext22[0]};
 Layers{5}; Recombine;};

ext24[] = Extrude {{0,-dh,0}, {0,1,0}, {Cx/2,Cy,Cz}, -Pi/2} {
  Surface{40};
 Layers{5}; Recombine;};

ext25[] = Extrude {{0,0,Cx/2}, {0,0,1}, {Cx/2, Cy+(4*2+1)*dh+Cx/2,Cz}, -Pi/2}  {
  Surface{ext23[0]};
 Layers{2*5}; Recombine;};

ext26[] = Extrude {{0,0,-Cx/2}, {0,0,1}, {Cx/2,Cy-dh-Cx/2,Cz}, Pi/2} {
  Surface{ext24[0]};
 Layers{2*5}; Recombine;};

ext27[] =Extrude {0,7.350000E-03, 0} {
  Surface{ext25[0]};
 Layers{4*5}; Recombine;};

ext28[] =Extrude {0,-7.350000E-03, 0} {
  Surface{ext26[0]};
 Layers{4*5}; Recombine;};

Physical Surface("inletTubeEnd") = {ext27[0]};
Physical Surface("outletTubeEnd") = {ext28[0]};

Physical Surface("coilOuterSurface")= {ext15[2],ext15[3],ext15[4],ext15[5],
ext16[2],ext16[3],ext16[4],ext16[5],ext17[2],ext17[3],ext17[4],ext17[5],ext18[2],ext18[3],ext18[4],ext18[5],ext19[2],ext19[3],ext19[4],ext19[5],ext20[2],ext20[3],ext20[4],ext20[5],
ext21[2],ext21[3],ext21[4],ext21[5],ext22[2],ext22[3],ext22[4],ext22[5],ext23[2],ext23[3],ext23[4],ext23[5],ext24[2],ext24[3],ext24[4],ext24[5],ext25[2],ext25[3],ext25[4],ext25[5],
ext26[2],ext26[3],ext26[4],ext26[5],ext27[2],ext27[3],ext27[4],ext27[5],ext28[2],ext28[3],ext28[4],ext28[5],ext28[2],ext28[3],ext28[4],ext28[5]};

Physical Volume("tube")= {ext15[1],ext16[1],ext17[1],ext18[1],ext19[1],ext20[1],
ext21[1],ext22[1],ext23[1],ext24[1],ext25[1],ext26[1],ext27[1],ext28[1],ext28[1]};

/* ********* SHELL PART ************ */

// line loops for shell inner surface

Line Loop(50) = {9,10,11,12};		//shell int circ (lower end)
Line Loop(60) = {13,14,15,16};		//tube ext circ (lower end)

Line Loop(70) = {17,18,19,20};		//shell int circ (upper end)
Line Loop(80) = {21,22,23,24};		//tube ext circ (upper end)

Line Loop(90)  = {9,26,-17,-25};		//shell int circ (side)
Line Loop(100) = {10,27,-18,-26};		//shell int circ (side)
Line Loop(110) = {11,28,-19,-27};		//shell int circ (side)
Line Loop(120) = {12,25,-20,-28};		//shell int circ (side)
// make a hole on the shell lower end surface

Plane Surface(130) = {50,60};

Plane Surface(140) = {70,80};

Ruled Surface(190) = {90};
Ruled Surface(160) = {100};
Ruled Surface(170) = {110};
Ruled Surface(180) = {120};

Physical Surface("shellInnerWall") = {130,140,190,160,170,180};

Surface Loop(80) = {130,140,150,160,170,180, 		//shell int circ
ext15[2],ext15[3],ext15[4],ext15[5],
ext16[2],ext16[3],ext16[4],ext16[5],ext17[2],ext17[3],ext17[4],ext17[5],ext18[2],ext18[3],ext18[4],ext18[5],ext19[2],ext19[3],ext19[4],ext19[5],ext20[2],ext20[3],ext20[4],ext20[5],
ext21[2],ext21[3],ext21[4],ext21[5],ext22[2],ext22[3],ext22[4],ext22[5],ext23[2],ext23[3],ext23[4],ext23[5],ext24[2],ext24[3],ext24[4],ext24[5],ext25[2],ext25[3],ext25[4],ext25[5],
ext26[2],ext26[3],ext26[4],ext26[5],ext27[2],ext27[3],ext27[4],ext27[5],ext28[2],ext28[3],ext28[4],ext28[5],ext28[2],ext28[3],ext28[4],ext28[5]};

Volume(90)= {80};
Physical Volume("coldFluid")= {90};
