h = 6;
w = 8;
R = 15;

X0 = 0;
Y0 = 2;
Z0 = 2;

MeshSize = 0.75;

PEC = 1001;
FreeSpace = 1000;


Function AddCorner

ConerPoints = newp;

Point(ConerPoints+0) = {-w/2,0,0,MeshSize};
Point(ConerPoints+1) = { w/2,0,0,MeshSize};

Point(ConerPoints+2) = {-w/2,h,0,MeshSize};
Point(ConerPoints+3) = { w/2,h,0,MeshSize};

Point(ConerPoints+4) = {-w/2,0,h,MeshSize};
Point(ConerPoints+5) = { w/2,0,h,MeshSize};

CornerLines = newl;
Line(CornerLines+0) = {ConerPoints+0,ConerPoints+1};
Line(CornerLines+1) = {ConerPoints+2,ConerPoints+3};
Line(CornerLines+2) = {ConerPoints+4,ConerPoints+5};
Line(CornerLines+3) = {ConerPoints+0,ConerPoints+2};
Line(CornerLines+4) = {ConerPoints+0,ConerPoints+4};
Line(CornerLines+5) = {ConerPoints+1,ConerPoints+3};
Line(CornerLines+6) = {ConerPoints+1,ConerPoints+5};

Return

Function AddSphere

	SpherePoints = newp;

	Point(SpherePoints+0) = {X0,Y0,Z0,MeshSize};

	Point(SpherePoints+1) = {-R,Y0,Z0,MeshSize};
	Point(SpherePoints+2) = { R,Y0,Z0,MeshSize};

	Point(SpherePoints+3) = {X0,Y0-R,Z0,MeshSize};
	Point(SpherePoints+4) = {X0,Y0+R,Z0,MeshSize};

	Point(SpherePoints+5) = {X0,Y0,Z0-R,MeshSize};
	Point(SpherePoints+6) = {X0,Y0,Z0+R,MeshSize};

	SphereLines = newl;
	Circle(newl+0) = {SpherePoints+1,SpherePoints,SpherePoints+3};
	Circle(newl+1) = {SpherePoints+1,SpherePoints,SpherePoints+4};
	Circle(newl+2) = {SpherePoints+1,SpherePoints,SpherePoints+5};
	Circle(newl+3) = {SpherePoints+1,SpherePoints,SpherePoints+6};

	Circle(newl+4) = {SpherePoints+2,SpherePoints,SpherePoints+3};
	Circle(newl+5) = {SpherePoints+2,SpherePoints,SpherePoints+4};
	Circle(newl+6) = {SpherePoints+2,SpherePoints,SpherePoints+5};
	Circle(newl+7) = {SpherePoints+2,SpherePoints,SpherePoints+6};

	Circle(newl+8)  = {SpherePoints+3,SpherePoints,SpherePoints+5};
	Circle(newl+9)  = {SpherePoints+3,SpherePoints,SpherePoints+6};
	Circle(newl+10) = {SpherePoints+4,SpherePoints,SpherePoints+5};
	Circle(newl+11) = {SpherePoints+4,SpherePoints,SpherePoints+6};

Return

Call AddCorner;
Call AddSphere;

Line Loop(86) = {2,-6,-1,4};
Plane Surface(87) = {86};
Line Loop(88) = {5,3,-7,-1};
Plane Surface(89) = {88};

Line Loop(90) = {17,-62,-8};
Ruled Surface(91) = {90};
Line Loop(92) = {13,-52,-8};
Ruled Surface(93) = {92};
Line Loop(94) = {22,52,-35};
Ruled Surface(95) = {94};
Line Loop(96) = {62,-43,22};
Ruled Surface(97) = {96};
Line Loop(98) = {28,85,-43};
Ruled Surface(99) = {98};
Line Loop(100) = {73,-35,28};
Ruled Surface(101) = {100};
Line Loop(102) = {10,73,-13};
Ruled Surface(103) = {102};
Line Loop(104) = {17,-85,-10};
Ruled Surface(105) = {104};

Surface Loop(106) = {103,105,-91,-97,99,-101,95,93,87,89};
Volume(107) = {106};

Physical Surface(PEC) = {87,89};
Physical Volume(FreeSpace) = {107};

