Function CreateVolume			

p1=newp; Point(p1) = {PX+l1, 		PY+l1, 		PZ+(-(l2-l1)*2), c1};
p2=newp; Point(p2) = {PX+(-l1),		PY+l1, 		PZ+(-(l2-l1)*2), c1};
p3=newp; Point(p3) = {PX+(-l1),		PY+(-l1),	PZ+(-(l2-l1)*2), c1};
p4=newp; Point(p4) = {PX+l1, 		PY+(-l1),	PZ+(-(l2-l1)*2), c1};

p5=newp; Point(p5) = {PX+l1, 		PY+l1,		PZ+(+(l2-l1)*2), c1};
p6=newp; Point(p6) = {PX+(-l1), 	PY+l1, 		PZ+(+(l2-l1)*2), c1};
p7=newp; Point(p7) = {PX+(-l1), 	PY+(-l1), 	PZ+(+(l2-l1)*2), c1};
p8=newp; Point(p8) = {PX+l1, 		PY+(-l1), 	PZ+(+(l2-l1)*2), c1};

p9=newp; Point(p9) = {PX+l2, 		PY+l2, 		PZ+(-(l2-l1)*2), c1};
p10=newp; Point(p10) = {PX+(-l2), 	PY+l2, 		PZ+(-(l2-l1)*2), c1};
p11=newp; Point(p11) = {PX+(-l2), 	PY+(-l2),	PZ+(-(l2-l1)*2), c1};
p12=newp; Point(p12) = {PX+l2, 		PY+(-l2), 	PZ+(-(l2-l1)*2), c1};

p13=newp; Point(p13) = {PX+l2, 		PY+l2, 		PZ+(+(l2-l1)*2), c1};
p14=newp; Point(p14) = {PX+(-l2), 	PY+l2, 		PZ+(+(l2-l1)*2), c1};
p15=newp; Point(p15) = {PX+(-l2), 	PY+(-l2), 	PZ+(+(l2-l1)*2), c1};
p16=newp; Point(p16) = {PX+l2, 		PY+(-l2), 	PZ+(+(l2-l1)*2), c1};


L1=newreg; Line(L1) = {p1, p9};
L2=newreg; Line(L2) = {p9, p13};
L3=newreg; Line(L3) = {p13, p5};
L4=newreg; Line(L4) = {p5, p1};
L5=newreg; Line(L5) = {p5, p6};
L6=newreg; Line(L6) = {p1, p2};
L7=newreg; Line(L7) = {p9, p10};
L8=newreg; Line(L8) = {p13, p14};
L9=newreg; Line(L9) = {p6, p14};
L10=newreg; Line(L10) = {p14, p10};
L11=newreg; Line(L11) = {p10, p2};
L12=newreg; Line(L12) = {p2, p6};
L13=newreg; Line(L13) = {p2, p3};
L14=newreg; Line(L14) = {p6, p7};
L15=newreg; Line(L15) = {p14, p15};
L16=newreg; Line(L16) = {p10, p11};
L17=newreg; Line(L17) = {p11, p3};
L18=newreg; Line(L18) = {p3, p7};
L19=newreg; Line(L19) = {p7, p15};
L20=newreg; Line(L20) = {p15, p11};
L21=newreg; Line(L21) = {p3, p4};
L22=newreg; Line(L22) = {p7, p8};
L23=newreg; Line(L23) = {p15, p16};
L24=newreg; Line(L24) = {p11, p12};
L25=newreg; Line(L25) = {p4, p12};
L26=newreg; Line(L26) = {p12, p16};
L27=newreg; Line(L27) = {p16, p8};
L28=newreg; Line(L28) = {p8, p4};
L29=newreg; Line(L29) = {p12, p9};
L30=newreg; Line(L30) = {p16, p13};
L31=newreg; Line(L31) = {p4, p1};
L32=newreg; Line(L32) = {p8, p5};


//suraface corner

Line Loop(newreg) = {L1, L2, L3, L4};
Plane Surface(newreg) = {newreg-1}; ps1=newreg-1;	
Line Loop(newreg) = {L12, L9, L10, L11};
Plane Surface(newreg) = {newreg-1}; ps2=newreg-1;	
Line Loop(newreg) = {L19, L20, L17, L18}; 
Plane Surface(newreg) = {newreg-1}; ps3=newreg-1;
Line Loop(newreg) = {L28, L25, L26, L27};
Plane Surface(newreg) = {newreg-1}; ps4=newreg-1;

//pachet 1
Line Loop(newreg) = {-L3, -L30, L27, L32};
Plane Surface(newreg) = {newreg-1}; ps5=newreg-1;
Line Loop(newreg) = {-L30, -L26, L29, L2};
Plane Surface(newreg) = {newreg-1}; ps6=newreg-1;
Line Loop(newreg) = {L29, -L1, -L31, L25};
Plane Surface(newreg) = {newreg-1}; ps7=newreg-1;
Line Loop(newreg) = {L31, -L4, -L32, L28};
Plane Surface(newreg) = {newreg-1}; ps8=newreg-1;

//pachet 2
Line Loop(newreg) = {L9, -L8, L3, L5};
Plane Surface(newreg) = {newreg-1}; ps9=newreg-1;
Line Loop(newreg) = {-L7, L2, L8, L10};
Plane Surface(newreg) = {newreg-1}; ps10=newreg-1;
Line Loop(newreg) = {L11, -L6, L1, L7};
Plane Surface(newreg) = {newreg-1}; ps11=newreg-1;
Line Loop(newreg) = {-L5, L4, L6, L12};
Plane Surface(newreg) = {newreg-1}; ps12=newreg-1;

//pachet 3
Line Loop(newreg) = {L13, -L17, -L16, L11};
Plane Surface(newreg) = {newreg-1}; ps13=newreg-1;
Line Loop(newreg) = {-L18, -L13, L12, L14};
Plane Surface(newreg) = {newreg-1}; ps14=newreg-1;
Line Loop(newreg) = {L19, -L15, -L9, L14};
Plane Surface(newreg) = {newreg-1}; ps15=newreg-1;
Line Loop(newreg) = {-L20, -L15, L10, L16};
Plane Surface(newreg) = {newreg-1}; ps16=newreg-1;

//pachet 4

Line Loop(newreg) = {-L23, L20, L24, L26};
Plane Surface(newreg) = {newreg-1}; ps17=newreg-1;
Line Loop(newreg) = {-L24, L17, L21, L25};
Plane Surface(newreg) = {newreg-1}; ps18=newreg-1;
Line Loop(newreg) = {L22, L28, -L21, L18};
Plane Surface(newreg) = {newreg-1}; ps19=newreg-1;
Line Loop(newreg) = {-L22, L19, L23, L27};
Plane Surface(newreg) = {newreg-1}; ps20=newreg-1;

sl1=newreg; Surface Loop(sl1) = {ps4,ps8,ps7,ps6,ps5,ps1};
V1=newreg; Volume(V1) = {sl1};
sl2=newreg; Surface Loop(sl2) = {ps1,ps11,ps2,ps12,ps9,ps10};
V2=newreg; Volume(V2) = {sl2};
sl3=newreg; Surface Loop(sl3) = {ps3,ps15,ps16,ps2,ps14,ps13};
V3=newreg; Volume(V3) = {sl3};
sl4=newreg; Surface Loop(sl4) = {ps4,ps19,ps20,ps3,ps17,ps18};
V4=newreg; Volume(V4) = {sl4};

phvX=newreg; CooperV=phvX; Physical Volume(phvX) = {V1,V2,V3,V4};

Return				

Function CreateVolumeInterior	

Printf("L: =%G =%G =%G =%G ",L22,L32,L5,L14);
Line Loop(newreg) = {L22,L32,L5,L14};
Plane Surface(newreg) = {newreg-1}; Mps1=newreg-1; 
Line Loop(newreg) = {L21,L31,L6,L13};
Printf("L: =%G =%G =%G =%G ",L21,L31,L6,L13);
Plane Surface(newreg) = {newreg-1}; Mps2=newreg-1; 
Printf("ps14=%G,ps12=%G,ps8=%G,ps19=%G,Mps1=%G,Mps2=%G",ps14,ps12,ps8,ps19,Mps1,Mps2);
Msl1=newreg; Surface Loop(Msl1) = {ps19,Mps1,ps14,Mps2,ps12,ps8};
V5=newreg; IronX1=V5; Volume(V5) = {Msl1};
phvX=newreg; IronVol=phvX; Physical Volume(phvX) = {V5};

Return								


c1 = 0.1;
l1 = 0.1; l2 = 0.15;
PX=0.0;PY=0.0;PZ=0.0;
Call CreateVolume;
Call CreateVolumeInterior; 