//Geometry

P = DefineNumber[12, Name "1Parameters/2Patch/1Radius", 
		 Label "Radius [mm]"];
L = DefineNumber[P+4, Name "1Parameters/3Skin/1Radius", Highlight "AliceBlue",
		 Label "Skin Radius [mm]"];
H = DefineNumber[0.1, Name "1Parameters/3Skin/2Epidermis", 
		 Label "Epidermis Thickness [mm]"];
HP = DefineNumber[0.3, Name "1Parameters/2Patch/2Thickness", 
		  Label "Thickness [mm]"];
HD = DefineNumber[1.5, Name "1Parameters/3Skin/3Dermis", 
		  Label "Dermis Thickness [mm]"];
N = DefineNumber[100, Name "1Parameters/1Simulation/5Nb", 
		 Label "Mesh refinement [%]"];
T = DefineNumber[1, Name "1Parameters/1Simulation/9Structured", 
		 Label "Structured mesh in thin regions", Choices {0,1}];

mm = 1e-3;

L = L*mm;
H = H*mm;
P = P*mm;
HP = HP*mm;
HD = HD*mm;
N = N/100;

lc1 = 0.024/150 / N;
lc2 = lc1 / 2;
lc3 = lc1;
lc4 = 3 * lc1;
lcfar = L/P * lc4;

Point(1) = {0, 0, 0, lc3};
Point(2) = {L, 0, 0, lcfar};
Point(3) = {L, H, 0, lcfar};
Point(4) = {0, H, 0, lc2};
Point(5) = {P, H, 0, lc2};

Point(6) = {P, H + HP, 0, lc1};
Point(7) = {0, H + HP, 0, lc1};
Point(8) = {0, -HD, 0, lc4};
Point(9) = {L, -HD, 0, lcfar};

Point(10) = {P, 0, 0, lc3};
Point(11) = {P, -HD, 0, lc4};

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

Line(6) = {5, 6};
Line(7) = {6, 7};
Line(8) = {7, 4};
Line(9) = {1, 8};
Line(10) = {11, 9};
Line(11) = {9, 2};

Line(12) = {1, 10};
Line(13) = {8, 11};
Line(14) = {5, 10};

Line Loop(1) = {12, -14, 5, 4}; //Epidermis left
Line Loop(2) = {6, 7, 8, -5}; //Patch
Line Loop(3) = {9, 13, 10, 11, -1, -12}; //Dermis
Line Loop(4) = {14, 1, 2, 3}; //Epidermis right

Plane Surface(1) = {1};
Plane Surface(2) = {2};
Plane Surface(3) = {3};
Plane Surface(4) = {4};

If(T== 1)
Transfinite Line {2,4, 14} = 6 ; // across epidermis
Transfinite Line {6, 8} = 15 ;  // across patch
Transfinite Line {5, 7, 12} = 40 ; // along patch
Transfinite Line {1, 3} = 15 ; // along dermis
Transfinite Surface {1,2,4} ;
Recombine Surface {1,2,4} ;
EndIf

Physical Surface(1) = {1,4};
Physical Surface(2) = {2};
Physical Surface(3) = {3};
Physical Line(1) = {10, 13}; //Frontiere inferieure
Physical Line(2) = {2, 11}; //Frontiere distante
Physical Line(3) = {3,4,6,7,8,9};//Neumann
Physical Line(4) = {5};
Physical Line(5) = {1, 12};

