cl1 = 1;
/*
 points are identified  by firts two cardinals 00 01 02 03... (at most 100 lines)
 the third ... identify the point number of the line
 
 the 2d "dessus" plane wil be introduced through an include

 parameters are  given at the beginning of the file
*/
//thickness
h1 = 0.00125;
h2 = 0.00125;
h3 = 0.00125;
// entrance radius
r1 = 0.01205;
// center of entrance
c1 = 0.007500;
// length of the exchanger
lo1 = 0.133923;
// width of the entrance
wi_en = 0.015;
// length of the entrance <-> width of the exchanger *0.5
wi_ex = 0.030;

yc = wi_en/2.;

scaling_factor = 1.0;

//
// discretisation parameters
//
nx1 = 6;
ny1 = 15;
nz1 = 5;
//

toto = Sqrt(r1*r1 -0.0075*0.0075);

//Point(100) = {0.0000, 0.000000, 0, cl1};
//Point(200) = {toto, 0.000000, 0, cl1};
//Point(300) = {wi_ex, 0.000000, 0, cl1};

/*Point(102) = {0.0000, wi_en, 0, cl1};
Point(202) = {toto, wi_en, 0, cl1};
Point(302) = {wi_ex, wi_en, 0, cl1};


Point(103) = {0.0000, lo1-wi_en, 0, cl1};
Point(203) = {toto, lo1-wi_en, 0, cl1};
Point(303) = {wi_ex, lo1-wi_en, 0, cl1};
*/




x = 0.0;
y = 0.0;
z = 0.0;
width_se=0.0015;

Point(10) = {x,  y,  z,  cl1} ;
x += width_se*0.5;
For t In {2:21}

  Point(t*10) = {x,  y,  z,  cl1} ;
  indl = (t-1)*1000 + t*10;
  Line(indl) = {(t-1)*10, t*10};
  Transfinite Line {indl} = nx1 Using Progression 1;
  x += width_se;

  Printf("p excha %g (coordinates = {%g,%g,%g}, ",t, x, y, z ) ;
EndFor


x = 0.0;
y = scaling_factor*wi_en;
z = 0.0;

Point(11) = {x,  y,  z,  cl1} ;
x += width_se*0.5;
For t In {2:21}

  Point(t*10+1) = {x,  y,  z,  cl1} ;
  indl = (t-1)*1000 + t*10+1;
  Line(indl) = {(t-1)*10+1, t*10+1};
  Transfinite Line {indl} = nx1 Using Progression 1;
  x += width_se;

  Printf("p excha %g (coordinates = {%g,%g,%g}, ",t, x, y, z ) ;

EndFor

x = 0.0;
y = scaling_factor*(wi_en + lo1);

z = 0.0;

Point(12) = {x,  y,  z,  cl1} ;
x += width_se*0.5;
For t In {2:21}

  Point(t*10+2) = {x,  y,  z,  cl1} ;
  indl = (t-1)*1000 + t*10+2;
  Line(indl) = {(t-1)*10+2, t*10+2};
  Transfinite Line {indl} = nx1 Using Progression 1;
  x += width_se;

  Printf("p excha %g (coordinates = {%g,%g,%g}, ",t, x, y, z ) ;

EndFor

x = 0.0;
y = scaling_factor*(2.*wi_en + lo1);
z = 0.0;

Point(13) = {x,  y,  z,  cl1} ;
x += width_se*0.5;
For t In {2:21}

  Point(t*10+3) = {x,  y,  z,  cl1} ;
  indl = (t-1)*1000 + t*10+3;
  Line(indl) = {(t-1)*10+3, t*10+3};
  Transfinite Line {indl} = nx1 Using Progression 1;
  x += width_se;

  Printf("p excha %g (coordinates = {%g,%g,%g}, ",t, x, y, z ) ;

EndFor

/*
For t In {2:21}

  Point(t*10+3) = {x,  y,  z,  cl1} ;
  indl = (t-1)*1000 + t*10+3;
  Line(indl) = {(t-1)*10+3, t*10+3};
  Transfinite Line {indl} = nx1 Using Progression 1;
  x += width_se;

  Printf("p excha %g (coordinates = {%g,%g,%g}, ",t, x, y, z ) ;

EndFor
*/
//
// line y level 0
//
For t In {1:21}

  indl = (t-1)*10 + ((t-1)*10+1)*1000;
  Line(indl) = {(t)*10, (t)*10+1};
  Transfinite Line {indl} = ny1 Using Progression 1;
  Printf("p excha %g (coordinates = {%g,%g,%g}, ",t, x, y, z ) ;

EndFor
//
// line y level 1
//
For t In {1:21}

  indl = (t-1)*10 + 1 + ((t-1)*10+2)*1000;
  Line(indl) = {(t)*10+1, (t)*10+2};
  Transfinite Line {indl} = ny1 Using Progression 1;

EndFor
//
// line y level 2
//
For t In {1:21}

  indl = (t-1)*10 + 2 + ((t-1)*10+3)*1000;
  Line(indl) = {(t)*10+ 2, (t)*10+3};
  Transfinite Line {indl} = ny1 Using Progression 1;


EndFor
//
// surfaces at the first level
//
inds = 1;
For t In {2:21}

// y   indl = (t-1)*10 + ((t-1)*10+1)*1000;

  Line Loop(inds) = {(t-1)*1000 + t*10, (t-1)*10 + ((t-1)*10+1)*1000, -1*((t-1)*1000 + t*10 + 1), -1*((t-2)*10 + ((t-2)*10+1)*1000)};
  Ruled Surface(inds) = {inds};
  Transfinite Surface {inds};Recombine Surface {inds};
  inds+=1;
  Printf(" y lines = {%g,%g,%g,%g}, ",(t-1)*1000 + t*10, (t-1)*10 + ((t-1)*10+1)*1000, -1*((t-1)*1000 + t*10 + 1), -1*1000 ) ;

EndFor
//
// surfaces at the second level
//
For t In {2:21}

// y   indl = (t-1)*10 + ((t-1)*10+1)*1000;

  Line Loop(inds) = {(t-1)*1000 + t*10 +1, (t-1)*10 + 1 + ((t-1)*10+2)*1000, -1*((t-1)*1000 + t*10 + 2), -1*((t-2)*10 + 1 + ((t-2)*10+2)*1000)};
  Ruled Surface(inds) = {inds};
  Transfinite Surface {inds};Recombine Surface {inds};
  Printf(" surf  y lines = {%g,%g,%g,%g,%g}, ",inds, (t-1)*1000 + t*10 +1, (t-1)*10 + 1 + ((t-1)*10+2)*1000, -1*((t-1)*1000 + t*10 + 2), -1*((t-2)*10 + 1 + ((t-2)*10+2)*1000)) ;
  inds+=1;

EndFor
//
// surfaces at the third level
//
For t In {2:21}

// y   indl = (t-1)*10 + ((t-1)*10+1)*1000;

  Line Loop(inds) = {(t-1)*1000 + t*10 +2, (t-1)*10 + 2 + ((t-1)*10+3)*1000, -1*((t-1)*1000 + t*10 + 3), -1*((t-2)*10 + 2 + ((t-2)*10+3)*1000)};
  Ruled Surface(inds) = {inds};
  Transfinite Surface {inds};Recombine Surface {inds};
  Printf(" surf  y lines = {%g,%g,%g,%g,%g}, ",inds,(t-1)*1000 + t*10 +2, (t-1)*10 + 2 + ((t-1)*10+3)*1000, -1*((t-1)*1000 + t*10 + 3), -1*((t-2)*10 + 2 + ((t-2)*10+3)*1000)) ;
  inds+=1;

EndFor


Extrude {0,0,h1} {
Surface{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60}; Layers {5}; Recombine;}


Extrude {0,0,h2} {
Surface{203224, 203246, 203268, 203290, 203312, 203334, 203356, 203378, 203400, 203422, 203444, 203466, 203488, 203510, 203532, 203554, 203576, 203598, 203620, 203642};
Layers {5};
Recombine;
}



Extrude {0,0,-1*h3} {
Surface{41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60};
Layers {5};
Recombine;
}


Extrude {0,0,h2} {
Surface{204544, 204566, 204588, 204610, 204632, 204654};
Layers {5};
Recombine;
}

p1 = newp; Point(p1) = {toto, 0.000000, h1+h2+h2, cl1};
p2 = newp; Point(p2) = {toto, wi_en, h1+h2+h2, cl1};
y =0.5*wi_en;
p3 = newp; Point(p3) = {0.0, y, h1+h2+h2, cl1};
c1 = newreg; Circle(c1) = {p1, p3, p2};
Transfinite Line {c1} = ny1 Using Progression 1;
//Line(207535) = {p1, p2};
//Transfinite Line {207535} = ny1 Using Progression 1;

l1 = newl; Line(l1) = {869, p1};
l2 = newl; Line(l2) = {p2, 873};
Transfinite Line {l1,l2} = nx1 Using Progression 1;
l3 = newll; Line Loop(l3) = {l1, 205535, l2, -205515};
s3 = news; Ruled Surface(s3) = {l3};
Transfinite Surface(s3) = {869, 874, 875, 873};//Recombine Surface{s3};

l4 = newl; Line(l4) = {627, p1};
l5 = newl; Line(l5) = {631, p2};
Transfinite Line {l4,l5} = nz1+1 Using Progression 1;
//
// S1
//
l5 = newll; Line Loop(l5) = {205540, -205536, -205520, 204656};
s4 = news; Ruled Surface(s4) = {l5};
Transfinite Surface(s4) = {621, 627, 874, 869};//Recombine Surface{s4};
//
// S3
//
l6 = newll; Line Loop(l6) = {205541, 205537, -205524, -204658};
s5 = news; Ruled Surface(s5) = {l6};
Transfinite Surface(s5) = {625, 631, 875, 873};//Recombine Surface{s5};

l7 = newll; Line Loop(l7) = {205535, -205541, -204657, 205540};
s6 = news; Ruled Surface(s6) = {l7};
Transfinite Surface(s6) = {874, 875, 631, 627};//Recombine Surface{s6};

/*
Extrude {0,0,h2} {
Surface{204676};
Layers {nz1};
Recombine;
}
*/

Extrude {0,0,-1*h2} {
Surface{204984,205006, 205028, 205050, 205072, 205094};
Layers {nz1};
Recombine;
}

Extrude {0,0,-1*h2} {
Surface{205116};
Layers {nz1};
Recombine;
}


s8 = news; Surface Loop(s8) = {205543, 205539, 205545, 204676, 205547, 205525};
v1 = newv;
Volume(v1)= {s8};
//Transfinite Volume '*';
