a = 20; 
d = 4; //3.5;  //4;
d1 = 1;

// hw = well  thickness
hw = 3.0; // 4.00 ; // 4.25; // 2.0; //3.0; // 4.5;

hb = 10;
h1 = 190;
h2 = 190;
h3=50;
N=4;

lay_gan = 12 ; //16; // 22  12

Function add_GaN_side_surfaces

   interface_plane = news - 1;
   For i1 In {0:5}
       GaN_side_surface_number++;
       GaN_side_surface[GaN_side_surface_number] = interface_plane - 1 - i1*4;
   EndFor

Return


Function add_AlGaN_side_surfaces

   interface_plane = news - 1;
   For i2 In {0:5}
       AlGaN_side_surface_number++;
       AlGaN_side_surface[AlGaN_side_surface_number] = interface_plane - 1 - i2*4;
   EndFor

Return


Point(1) = {Sqrt(3)/2*a, a/2, 0, d};
Point(2) = {0,a,0,d};
Point(3) = {-Sqrt(3)/2*a,a/2,0,d};
Point(4) = {-Sqrt(3)/2*a,-a/2,0,d};
Point(5) = {0,-a,0,d};
Point(6) = {Sqrt(3)/2*a, -a/2, 0, d};

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

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


//-----------------------------
// GaN
GaN_side_surface_number =  0;
AlGaN_side_surface_number =  0;
volume = 1;
//------------n_part------------------------------------------------------------------






t[] = Extrude   {0.0,0.0,h1} { Surface{1}; Layers {40}; Recombine; };  //AlGaN 
volume = t[1];
AlGaN_volumes[0] = volume;
Call add_AlGaN_side_surfaces;
volume++;






t[] = Extrude {0.0,0.0,hb} {Surface{news - 1}; Layers {12}; Recombine; } ;//AlGaN 
volume = t[1];
AlGaN_volumes[1] = volume;
Call add_AlGaN_side_surfaces;
volume++;

//----i_part--------------------------------------------------------------------------



t[] = Extrude {0.0,0.0,hw} {Surface{news - 1};Layers{lay_gan}; Recombine; };//GaN  12 lay
volume = t[1];
GaN_volumes[0] =  volume;
Call add_GaN_side_surfaces;
volume++;


//----p_part------------------------------------------------------------------------



t[] = Extrude {0.0,0.0,hb} {Surface{news - 1}; Layers {12}; Recombine; } ;//AlGaN 
volume = t[1];

AlGaN_volumes[2] = volume;
Call add_AlGaN_side_surfaces;
volume++;



t[] = Extrude {0.0,0.0,h1} {Surface{news - 1}; Layers {40}; Recombine; } ;//AlGaN 
volume = t[1];
AlGaN_volumes[3] = volume;
Call add_AlGaN_side_surfaces;
volume++;





//-----------end_of_buffer-----------------------------------------------------------

//----------------------------------------------------------------------------------------
//Physical volumes------------------------------------------------------------------------

Physical Volume(1) =GaN_volumes[0] ;
Physical Volume(2) =AlGaN_volumes[0];
Physical Volume(3) =AlGaN_volumes[1];
Physical Volume(4) =AlGaN_volumes[2];
Physical Volume(5) =AlGaN_volumes[3];








//------------------------------------------------------------------------------------------
//-----------------------------------------------------------------------------------------
//Physical surfaces------------------------------------------------------------------------

Physical Surface(1) =  {news - 1}; //p_contact
Physical Surface(2) = {1}; //n_contact
Physical Surface(3) =  GaN_side_surface[];    //GaN side surfaces
Physical Surface(4) =  AlGaN_side_surface[];  //AlGaN side surfaces




