//Hemisphere mesh for limb bud sim
//Ben Jordan
//4/20/2007


//x is the PD axis, y is the DV axis, z is the AP axis

//Parameters
lc = 1; 		//Characteristic length
AER_x=.01;		//AER thickness (at center) in PD direction (1 cell)
AER_xn=.02;		//PD height of nml disty (nipple up to 4 cells)
AER_yn=.04;		//DV width of AER (up to 30 cells)
AER_zn=.02;		//height of ectoderm at flank
			// "Dev of AER in chick leg bud vs wing bud", 
			// Todt and Fallon, The Anitomical Record.

AER_y=.05;		//AER width in DV direction
AER_z=.5; 		//AER height in AP direction

ZPA_d=.35;		//depth of ZPA region into mesoderm
R_x = .3;		//Radius of ellipse in PD
R_y = .4;		//Radius of ellipse in DV
R_z = .5;		//Radius of ellipse in AP
x_center = 0;
y_center = 0;
z_center = 0;

//Mesoderm points
Point(1) = {x_center, y_center, z_center, lc};
Point(2) = {x_center, y_center + R_y, z_center, lc};
Point(5) = {x_center, y_center - R_y, z_center, lc};
Point(30) = {x_center, y_center + R_y-AER_zn/2, z_center, lc};
Point(31) = {x_center, y_center - R_y+AER_zn/2, z_center, lc};

Point(8) = {x_center, y_center-AER_yn/2, z_center - R_z, lc};
Point(7) = {x_center, y_center-AER_yn/2, z_center + R_z, lc};
Point(24) = {x_center, y_center+AER_yn/2, z_center - R_z, lc};
Point(25) = {x_center, y_center+AER_yn/2, z_center + R_z, lc};

Point(26) = {x_center, y_center-AER_yn/2, z_center - R_z+AER_zn/2, lc};
Point(27) = {x_center, y_center+AER_yn/2, z_center - R_z+AER_zn/2, lc};
Point(28) = {x_center, y_center-AER_yn/2, z_center + R_z-AER_zn/2, lc};
Point(29) = {x_center, y_center+AER_yn/2, z_center + R_z-AER_zn/2, lc};

//AER points
Point(10) = {x_center + R_x+AER_xn, y_center, z_center, .01*lc};
Point(15) = {x_center + R_x-AER_x, y_center, z_center, .01*lc};
Point(11) = {x_center + R_x-AER_x, y_center-AER_y/2, z_center, .01*lc};
Point(12) = {x_center + R_x-AER_x, y_center+AER_y/2, z_center, .01*lc};
Point(13) = {x_center + R_x-AER_x, y_center+AER_yn/2, z_center-AER_z/2, .01*lc};
Point(14) = {x_center + R_x-AER_x, y_center+AER_yn/2, z_center+AER_z/2, .01*lc};
Point(16) = {x_center + R_x, y_center-AER_y/2, z_center, .01*lc};
Point(17) = {x_center + R_x, y_center+AER_y/2, z_center, .01*lc};
Point(18) = {x_center + R_x, y_center-AER_yn/2, z_center-AER_z/2, .01*lc};
Point(19) = {x_center + R_x, y_center+AER_yn/2, z_center+AER_z/2, .01*lc};

Point(20) = {x_center + R_x, y_center+AER_yn/2, z_center-AER_z/2, .01*lc};
Point(21) = {x_center + R_x-AER_x, y_center-AER_yn/2, z_center-AER_z/2, .01*lc};
Point(22) = {x_center + R_x, y_center-AER_yn/2, z_center+AER_z/2, .01*lc};
Point(23) = {x_center + R_x-AER_x, y_center-AER_yn/2, z_center+AER_z/2, .01*lc};

//ZPA points
Point(40)={x_center+.1, y_center, z_center-.35, .01*lc};

//Mesoderm lines
Ellipse(3) = {2, 1,1, 8} Plane{0, 0, 1};
Ellipse(9) = {2, 1,1, 7} Plane{0, 0, 1};
Ellipse(15) = {8, 1,1, 5} Plane{0, 0, 1};
Ellipse(21) = {7, 1,1, 5} Plane{0, 0, 1};

Ellipse(26) = {25,1,1,19};
Ellipse(35) = {7,1,1,22};

Ellipse(27) = {30,1,1,12};
Ellipse(28) = {24,1,1,20};
Ellipse(30) = {8,1,1,18};
Ellipse(29) = {31,1,1,11};

Ellipse(93) = {2,1,1,17};
Ellipse(94) = {5,1,1,16};

Ellipse(31) = {27,1,1,13};
Ellipse(32) = {26,1,1,21};
Ellipse(33) = {29,1,1,14};
Ellipse(34) = {28,1,1,23};

//AER Lines
CatmullRom(42) = {17,10,16};
CatmullRom(43) = {22,10,18};
CatmullRom(44) = {19,10,20};

Line(85) = {12,17};
Line(86) = {11,16};
Ellipse(89) = {30,1,1,29};
Ellipse(90) = {28,1,1,31};
Ellipse(91) = {31,1,1,26};
Ellipse(92) = {27,1,1,30};
CatmullRom(95) = {14,12};
CatmullRom(96) = {13,12};
CatmullRom(97) = {20,17};
CatmullRom(98) = {19,17};
CatmullRom(99) = {22,16};
CatmullRom(100) = {23,11};
CatmullRom(101) = {21,11};
CatmullRom(102) = {18,16};

Line(49) = {22,19};
Line(50) = {23,22};
Line(51) = {14,19};
Line(52) = {14,23};
Line(53) = {13,20};
Line(54) = {13,21};
Line(55) = {21,18};
Line(56) = {18,20};
Line(57) = {27,26};
Line(58) = {8,26};
Line(59) = {27,24};
Line(60) = {28,29};
Line(61) = {29,25};
Line(62) = {28,7};
Line(105) = {11,12};

//AER Surfaces and Elementary Volume
Line Loop(107) = {44,-56,-43,49};
Ruled Surface(108) = {107};
Line Loop(109) = {51,-49,-50,-52};
Ruled Surface(110) = {109};
Line Loop(111) = {56,-53,54,55};
Ruled Surface(112) = {111};
Line Loop(113) = {102,-99,43};
Ruled Surface(114) = {113};
Line Loop(115) = {97,-98,44};
Ruled Surface(116) = {115};
Line Loop(117) = {55,102,-86,-101};
Ruled Surface(118) = {117};
Line Loop(119) = {86,-99,-50,100};
Ruled Surface(120) = {119};
Line Loop(121) = {85,-97,-53,96};
Ruled Surface(122) = {121};
Line Loop(123) = {51,98,-85,-95};
Ruled Surface(124) = {123};
Line Loop(125) = {52,100,105,-95};
Ruled Surface(126) = {125};
Line Loop(127) = {105,-96,54,101};
Ruled Surface(128) = {127};
Surface Loop(129) = {116,122,124,110,108,112,128,126,120,118,114};
Volume(130) = {129};

//Mesoderm+Ectoderm Surfaces and elementary volume


//Physical Volumes (Put this last for Mech3d compatibility)

