//-----GaAs FET------//

mesh_coarse_1 = 0.3;
mesh_coarse_2 = 0.15;
mesh_medium = 0.04;
mesh_fine = 0.02;

x_off = 0;	y_off = 0; 	z_off = 0;

//----size of GaAs p- Buffer Layer----//
lx_sub = 6;	
ly_sub = 2;
lz_sub = 0.4;

// size of GaAs n- Depletion Layer----//
lz_GaAs_n = 0.2; 

//-----size of AlGaAs Cap/Channel layer------//
lz_AlGaAs = 0.05;

//----size of Source & Drain n+ GaAs region-----//
lx_sd = 1.5;
lz_sd = 0.05; 

//----size of Source & Drain Contact------//			
lx_sdcont = 0.8*(lx_sd);
ly_sdcont = 0.75*(ly_sub);

//-----size of Gate Contact---------------------------------------------------------//
lx_gatecont= 0.8;
//-----distance from edge of source region to gate contact--------//
lx_gs = 0.6;
//ly_gatecont = ly_sub;

//------source, drain & gate contact centering co-ordinates-----///
xsd_off = 0.5*(lx_sd - lx_sdcont);			xsd = xsd_off + lx_sdcont;	
ysd_off = 0.5*(ly_sub - ly_sdcont);			ysd = ysd_off + ly_sdcont;
//yg_off = 0.5*(ly_sub-ly_gatecont);			yg = yg_off + ly_gatecont;
						
//------ GaAs p- Buffer Layer Points--------//
Point(1) = {x_off, y_off, z_off, mesh_coarse_2};
Point(2) = {lx_sub, y_off, z_off, mesh_coarse_2};
Point(3) = {lx_sub, ly_sub, z_off, mesh_coarse_2};
Point(4) = {x_off, ly_sub, z_off, mesh_coarse_2};
Point(5) = {x_off, y_off, lz_sub, mesh_medium};
Point(6) = {lx_sub, y_off, lz_sub, mesh_medium};
Point(7) = {lx_sub, ly_sub, lz_sub, mesh_medium};
Point(8) = {x_off, ly_sub, lz_sub, mesh_medium};

//-------GaAs n- Channel Layer Points--------//
Point(9) = {x_off, y_off, lz_sub + lz_GaAs_n, mesh_medium};
Point(10) = {lx_sub, y_off, lz_sub + lz_GaAs_n, mesh_medium};
Point(11) = {lx_sub, ly_sub, lz_sub + lz_GaAs_n, mesh_medium};
Point(12) = {x_off, ly_sub, lz_sub + lz_GaAs_n, mesh_medium};

//------- AlGaAs Layer Bottom 4 points --------//
 Point(13) = {lx_sd, y_off, lz_sub + lz_GaAs_n, mesh_medium};
Point(14) = {lx_sub - lx_sd, y_off,+lz_sub + lz_GaAs_n, mesh_medium};
Point(15) = {lx_sub - lx_sd, ly_sub, lz_sub + lz_GaAs_n, mesh_medium};
Point(16) = {lx_sd, ly_sub, lz_sub + lz_GaAs_n, mesh_medium};

//------- AlGaAs Layer Top 4 points --------//
Point(17) = {lx_sd, y_off, lz_sub + lz_GaAs_n + lz_AlGaAs, mesh_medium};
Point(18) = {lx_sub - lx_sd, y_off,+lz_sub + lz_GaAs_n + lz_AlGaAs, mesh_medium};
Point(19) = {lx_sub - lx_sd, ly_sub, lz_sub + lz_GaAs_n +lz_AlGaAs, mesh_medium};
Point(20) = {lx_sd, ly_sub, lz_sub + lz_GaAs_n + lz_AlGaAs, mesh_medium};

//--------Source (GaAs n+) region Top 4 points --------//
Point(21) = {x_off, y_off, lz_sub + lz_GaAs_n + lz_sd, mesh_medium};
Point(22) = {lx_sd, y_off, lz_sub + lz_GaAs_n + lz_sd, mesh_medium};
Point(23) = {lx_sd, ly_sub, lz_sub + lz_GaAs_n + lz_sd, mesh_medium};
Point(24) = {x_off, ly_sub, lz_sub + lz_GaAs_n + lz_sd, mesh_medium};

//-------Drain (GaAs n+) region Top 4 points ---------//
Point(25) = {lx_sub - lx_sd, y_off, lz_sub + lz_GaAs_n + lz_sd, mesh_medium};
Point(26) = {lx_sub, y_off, lz_sub + lz_GaAs_n + lz_sd, mesh_medium};
Point(27) = {lx_sub, ly_sub, lz_sub + lz_GaAs_n + lz_sd, mesh_medium};
Point(28) = {lx_sub - lx_sd, ly_sub, lz_sub + lz_GaAs_n + lz_sd, mesh_medium};

//-------Source Contact Points--------//
Point(29) = {xsd_off, ysd_off, lz_sub + lz_GaAs_n + lz_sd, mesh_fine};
Point(30) = {xsd, ysd_off, lz_sub + lz_GaAs_n + lz_sd,  mesh_fine};
Point(31) = {xsd, ysd, lz_sub + lz_GaAs_n + lz_sd,  mesh_fine};
Point(32) = {xsd_off, ysd, lz_sub + lz_GaAs_n + lz_sd,  mesh_fine};

//-------Drain Contact Points--------//
Point(33) = {lx_sub - xsd, ysd_off, lz_sub + lz_GaAs_n + lz_sd,  mesh_fine};
Point(34) = {lx_sub - xsd_off, ysd_off, lz_sub + lz_GaAs_n + lz_sd,  mesh_fine};
Point(35) = {lx_sub - xsd_off, ysd, lz_sub + lz_GaAs_n + lz_sd,  mesh_fine};
Point(36) = {lx_sub - xsd, ysd, lz_sub + lz_GaAs_n + lz_sd,  mesh_fine};

//-------Gate Contact Points--------//
Point(37) = {lx_sd + lx_gs, y_off, lz_sub + lz_GaAs_n + lz_AlGaAs, mesh_medium};
Point(38) = {lx_sd + lx_gs + lx_gatecont, y_off, lz_sub + lz_GaAs_n + lz_AlGaAs,  mesh_medium};
Point(39) = {lx_sd + lx_gs + lx_gatecont, ly_sub, lz_sub + lz_GaAs_n + lz_AlGaAs,  mesh_medium};
Point(40) = {lx_sd + lx_gs, ly_sub, lz_sub + lz_GaAs_n + lz_AlGaAs, mesh_medium};

//-------GaAs p- Buffer Layer & Volume-----------------------------------------------//
Line(1) = {1, 2};
Line(2) = {2, 3};
Line(3) = {3, 4};
Line(4) = {4, 1};
Line(5) = {5, 6};
Line(6) = {6, 7};
Line(7) = {7, 8};
Line(8) = {8, 5};
Line(9) = {5, 1};
Line(10) = {2, 6};
Line(11) = {8, 4};
Line(12) = {3, 7};

Curve Loop(1) = {5, -10, -1, -9};
Plane Surface(1) = {1};
//+
Curve Loop(2) = {10, 6, -12, -2};
Plane Surface(2) = {2};
//+
Curve Loop(3) = {3, -11, -7, -12};
Plane Surface(3) = {3};
//+
Curve Loop(4) = {11, 4, -9, -8};
Plane Surface(4) = {4};
//+
Curve Loop(5) = {8, 5, 6, 7};
Plane Surface(5) = {5};
//+
Curve Loop(6) = {4, 1, 2, 3};
Plane Surface(6) = {6};
//+
Surface Loop(1) = {5, 4, 3, 6, 1, 2};
Volume(1) = {1};
Physical Volume("GaAs p- Substrate") = {1};

//-------GaAs n- Channel Layer Lines--------------------------------------------------//
Line(13) = {9, 5};
Line(14) = {9, 13};
Line(15) = {13, 14};
Line(16) = {14, 10};
Line(17) = {10, 6};
Line(18) = {10, 11};
Line(19) = {11, 7};
Line(20) = {11, 15};
Line(21) = {15, 16};
Line(22) = {16, 12};
Line(23) = {12, 8};
Line(24) = {12, 9};

//-------------GaAs n- Depletion Layer Surfaces----------//
Curve Loop(7) = {13, 5, -17, -16, -15, -14};
Plane Surface(7) = {7};
//+
Curve Loop(8) = {17, 6, -19, -18};
Plane Surface(8) = {8};
//+
Curve Loop(9) = {7, -23, -22, -21, -20, 19};
Plane Surface(9) = {9};
//+
Curve Loop(10) = {23, 8, -13, -24};
Plane Surface(10) = {10};
//+
Curve Loop(11) = {14, 15, 16, 18, 20, 21, 22, 24};
Plane Surface(11) = {11};

//--------------- GaAs n- Channel Layer Volume-----------//
Surface Loop(2) = {5, 11, 7, 10, 9, 8};
Volume(2) = {2};
Physical Volume("GaAs n- Channel Layer") = {2};

//-------GaAs n+ Source Region Lines-------------------------------------------------------------------------//
Line(25) = {9, 21};
Line(26) = {21, 17};
Line(27) = {17, 13};
Line(28) = {13, 16};
Line(29) = {16, 20};
Line(30) = {20, 17};
Line(31) = {20, 24};
Line(32) = {24, 12};
Line(33) = {24, 21};

//-------Source Contact------------------//
Line(34) = {29, 30};
Line(35) = {30, 31};
Line(36) = {31, 32};
Line(37) = {32, 29};

Line Loop(12) = {37, 34, 35, 36};
Plane Surface(12) = {12};
Physical Surface("Source-Contact") = {12};

//-----------Top surface of source region & embed Source contact in top face--------//
Curve Loop(13) = {33, 26, -30, 31};
Plane Surface(13) = {13,12};

//--------Other faces of source region---------//
Curve Loop(14) = {25, 26, 27, -14};
Plane Surface(14) = {14};
//+
Curve Loop(15) = {27, 28, 29, 30};
Plane Surface(15) = {15};
//+
Curve Loop(16) = {22, -32, -31, -29};
Plane Surface(16) = {16};
//+
Curve Loop(17) = {24, 25, -33, 32};
Plane Surface(17) = {17};
//+
Curve Loop(18) = {14, 28, 22, 24};
Plane Surface(18) = {18};

//------------Source Region Volume---------------//
Surface Loop(3) = {14, 17, 13, 15, 18, 16, 12};
Volume(3) = {3};
Physical Volume("Source (n+ GaAs)") = {3};

//-------GaAs n+ Drain Region Lines------------------------------------------------------------------------//
Line(38) = {18, 14};
Line(39) = {18, 26};
Line(40) = {26, 10};
Line(41) = {26, 27};
Line(42) = {27, 11};
Line(43) = {27, 19};
Line(44) = {19, 15};
Line(45) = {15, 14};
Line(46) = {18, 19};

//-------Drain Contact------------------//
Line(47) = {36, 33};
Line(48) = {33, 34};
Line(49) = {34, 35};
Line(50) = {35, 36};

Line Loop(19) = {47, 48, 49, 50};
Plane Surface(19) = {19};
Physical Surface("Drain-Contact") = {19};

//-----------Top surface of drain region & embed Drain contact in top face--------//
Curve Loop(20) = {46, -43, -41, -39};
Plane Surface(20) = {20,19};

//--------Other faces of drain region---------//
Curve Loop(21) = {38, 16, -40, -39};
Plane Surface(21) = {21};
//+
Curve Loop(22) = {40, 18, -42, -41};
Plane Surface(22) = {22};
//+
Curve Loop(23) = {20, -44, -43, 42};
Plane Surface(23) = {23};
//+
Curve Loop(24) = {44, 45, -38, 46};
Plane Surface(24) = {24};
//+
Curve Loop(25) = {45, 16, 18, 20};
Plane Surface(25) = {25};

//------------Drain Region Volume---------------//
Surface Loop(4) = {25, 24, 23, 20, 22, 21, 19};
Volume(4) = {4};
Physical Volume("Drain (n+ GaAs)") = {4};

//-------AlGaAs Barrier Region Lines--------------------------------------------------------// 
Line(51) = {17, 37};
Line(52) = {37, 38};
Line(53) = {38, 18};
Line(54) = {19, 39};
Line(55) = {39, 40};
Line(56) = {40, 20};

//-------Gate Contact-------------------------------------------------------------------------//
Line(57) = {37, 40};
Line(58) = {39, 38};

Line Loop(26) = {57, -55, 58, -52};
Plane Surface(26) = {26};
Physical Surface("Gate-Contact") = {26};

//-----------Top surface of AlGaAs Barrier & embed Gate contact in top face--------//
Curve Loop(27) = {30, 51, 52, 53, 46, 54, 55, 56};
Plane Surface(27) = {27,26};

//------- Other Surfaces of AlGaAs Barrier Region --------------------------------------------------------// 
Curve Loop(28) = {27, 15, -38, -53, -52, -51};
Plane Surface(28) = {28};
//+
Curve Loop(29) = {44, 21, 29, -56, -55, -54};
Plane Surface(29) = {29};
//+
Curve Loop(30) = {28, -21, 45, -15};
Plane Surface(30) = {30};

//------------AlGaAs Barrier Layer Volume---------------//
Surface Loop(5) = {27, 28, 30, 29, 26, 15, 24};
Volume(5) = {5};
Physical Volume("AlGaAs Barrier Layer") = {5};



