// pi/6 extrusion. 2 element per wavelength @ fmax
f=44000;   // frequency of interest.  Sets mesh density.
c=344;
lc=0.25*c/f;  //characteristic length for all nodes as function of freq.  Mesh density
s=1;      // characteristic length scalar for internal regions.
x0=0;y0=0; // origin


r1=0.03175;     // device radius
r2=0.05;     // quiet boundary radius
r3=0.06;     // uppermost face ROC
r4=0.06;     // lowermost surface ROC
r5=0.5*0.021*0;    // rod radius

y1=0.0044;    // height of cavity
y2=0.025;     // lower straight section height
y3=0.026;     // upper section height


f0=35000; // lowest freq of interest.  Sets position of boundary.
l=c/f0;

xr = 0.013;  // radius to center of transducer.  Sets drive / observe nodes.


Point (1) =    {       x0     ,y0-0.5*y1       ,       0 ,lc/s};    //lower face, center
Point (2) =    {    x0-r1     ,y0-0.5*y1       ,       0 ,lc/s};    //lower face, outer edge
Point (3) =    {    x0-r1     ,y0-0.5*y1-y2    ,       0 ,lc};    //

h2=Sqrt(r3*r3-r1*r1);
Point(11) = {x0,0.5*y1+y3-h2,0,lc};        // center of lower ROC
h1=Sqrt(r4*r4-r1*r1);
Point(12) = {x0,-0.5*y1-y2+h1,0,lc}; // center of upper ROC


Point (4) =    {    x0-r5     ,-0.5*y1-y2+h1-Sqrt(r4*r4-r5*r5)    ,       0 ,lc};    //
Point (5) =    {    x0-r5     ,y0-Sqrt(r2*r2-r5*r5)               ,       0 ,lc};    // bottom of qb
Point (6) =    {x0,y0+r2,0,lc}; // top of qb

Point (7) = {x0,0.5*y1+y3-h2+r3,0,lc};
Point (8) = {x0-r1,y0+0.5*y1+y3,0,lc};
Point (9) = {x0-r1,y0+0.5*y1,0,lc/s};
Point(10) = {x0,y0+0.5*y1,0,lc/s};
Point(13) = {x0,y0,0,lc/s};
Point(14) = {x0-r2,y0,0,lc};

Point(15) = {x0-r1,y0,0,lc};  // These three set the boundary
Point(16) = {x0-r1,y0+l,0,lc};
Point(17) = {x0-r1-l,y0,0,lc};
Point(18) = {x0-r1,y0-l,0,lc};

Point(19) = {x0-xr,y0+0.5*y1,0,lc/s};  // observation / excitation nodes.
Point(20) = {x0-xr,y0-0.5*y1,0,lc/s};  // opposite face, reqd to force mesh

// large boundary case : needs updating. check pre m17 files for resultant shape.
//Line(1) = {1,2};
//Line(2) = {2,3};
//Circle(3) = {3,12,4};
//Line(4) = {4,5};
//Circle(5) = {5,13,14};
//Circle(6) = {14,13,6};
//Line(7) = {6,7};
//Circle(8) = {7,11,8};
//Line(9) = {8,9};
//Line(10) = {9,10};
//Line(11) = {10,1};
//Line Loop(12) = {9,10,11,1,2,3,4,5,6,7,8};
//Plane Surface(13) = {12};

// small boundary case
Line(1) = {1,20};  //inner block
Line(2) = {20,19};
Line(3) = {19,10};
Line(4) = {10,1};

 Line(5) = {20,2}; // outer block
 Line(6) = {2,18};
 Circle(7) = {18,15,17};
 Circle(8) = {17,15,16};
 Line(9) = {16,9};
 Line(10) = {9,19};
Line(11) = {19,20};



 Line Loop(12) = {5,6,7,8,9,10,11};
 Plane Surface(13) = {12};
Line Loop(14) = {1,-11,3,4};
Plane Surface(15) = {14};
Coherence; // is essential, otherwise gmesh crashes.
Extrude {{0,1,0}, {0,0,0}, Pi/6} {
  Surface{13,15};
}
   Extrude {{0,1,0}, {0,0,0}, Pi/6} {
     Surface{52,69};
   }
   Extrude {{0,1,0}, {0,0,0}, Pi/6} {
     Surface{106,123};
   }
   Extrude {{0,1,0}, {0,0,0}, Pi/6} {
     Surface{177,160};
   }
   Extrude {{0,1,0}, {0,0,0}, Pi/6} {
     Surface{194,231};
   }
   Extrude {{0,1,0}, {0,0,0}, Pi/6} {
     Surface{248,285};
   }
   Extrude {{0,1,0}, {0,0,0}, Pi/6} {
     Surface{339,302};
   }
   Extrude {{0,1,0}, {0,0,0}, Pi/6} {
     Surface{393,376};
   }
   Extrude {{0,1,0}, {0,0,0}, Pi/6} {
     Surface{447,410};
   }
   Extrude {{0,1,0}, {0,0,0}, Pi/6} {
     Surface{501,484};
   }
   Extrude {{0,1,0}, {0,0,0}, Pi/6} {
     Surface{518,555};
   }
   Extrude {{0,1,0}, {0,0,0}, Pi/6} {
     Surface{572,609};
 }
Coherence;
Coherence;
