dom = 0.5; //half-width of the edge of the cube representing the exterior boundary of the air domain
pml = 0.4; //width of the pml
ray = 0.3; //radius of the sphere
prec = 0.1; //mesh density for the exterior boundary of the air domain and for the pml
precs = 0.03;//mesh density for the sphere

x3 = 0;
y3 = 0;
z3 = 0;

x1 = -dom-pml;
y1 = -dom-pml;
z1 = -dom-pml;

x2 = -dom;
y2 = -dom;
z2 = -dom;

x4 = -x2;
y4 = -y2;
z4 = -z2;

x5 = -x1;
y5 = -y1;
z5 = -z1;

c15=ray;

//box
Point(111) = {x1,y1,z1,prec};
Point(112) = {x2,y1,z1,prec};
Point(113) = {x3,y1,z1,prec};
Point(114) = {x4,y1,z1,prec};
Point(115) = {x5,y1,z1,prec};
Point(121) = {x1,y2,z1,prec};
Point(122) = {x2,y2,z1,prec};
Point(123) = {x3,y2,z1,prec};
Point(124) = {x4,y2,z1,prec};
Point(125) = {x5,y2,z1,prec};
Point(131) = {x1,y3,z1,prec};
Point(132) = {x2,y3,z1,prec};
Point(133) = {x3,y3,z1,prec};
Point(134) = {x4,y3,z1,prec};
Point(135) = {x5,y3,z1,prec};
Point(211) = {x1,y1,z2,prec};
Point(212) = {x2,y1,z2,prec};
Point(213) = {x3,y1,z2,prec};
Point(214) = {x4,y1,z2,prec};
Point(215) = {x5,y1,z2,prec};
Point(221) = {x1,y2,z2,prec};
Point(222) = {x2,y2,z2,prec};
Point(223) = {x3,y2,z2,prec};
Point(224) = {x4,y2,z2,prec};
Point(225) = {x5,y2,z2,prec};
Point(231) = {x1,y3,z2,prec};
Point(232) = {x2,y3,z2,prec};
Point(233) = {x3,y3,z2,prec};
Point(234) = {x4,y3,z2,prec};
Point(235) = {x5,y3,z2,prec};
Point(311) = {x1,y1,z3,prec};
Point(312) = {x2,y1,z3,prec};
Point(313) = {x3,y1,z3,prec};
Point(314) = {x4,y1,z3,prec};
Point(315) = {x5,y1,z3,prec};
Point(321) = {x1,y2,z3,prec};
Point(322) = {x2,y2,z3,prec};
Point(323) = {x3,y2,z3,prec};
Point(324) = {x4,y2,z3,prec};
Point(325) = {x5,y2,z3,prec};
Point(331) = {x1,y3,z3,prec};
Point(332) = {x2,y3,z3,prec};

Point(333) = {x3,y3,z3,precs};

Point(334) = {x4,y3,z3,prec};
Point(335) = {x5,y3,z3,prec};

Line(111112) = {111,112};
Line(112113) = {112,113};
Line(113114) = {113,114};
Line(114115) = {114,115};
Line(121122) = {121,122};
Line(122123) = {122,123};
Line(123124) = {123,124};
Line(124125) = {124,125};
Line(131132) = {131,132};
Line(132133) = {132,133};
Line(133134) = {133,134};
Line(134135) = {134,135};
Line(211212) = {211,212};
Line(212213) = {212,213};
Line(213214) = {213,214};
Line(214215) = {214,215};
Line(221222) = {221,222};
Line(222223) = {222,223};
Line(223224) = {223,224};
Line(224225) = {224,225};
Line(231232) = {231,232};
Line(232233) = {232,233};
Line(233234) = {233,234};
Line(234235) = {234,235};
Line(311312) = {311,312};
Line(312313) = {312,313};
Line(313314) = {313,314};
Line(314315) = {314,315};
Line(321322) = {321,322};
Line(322323) = {322,323};
Line(323324) = {323,324};
Line(324325) = {324,325};
Line(331332) = {331,332};
Line(334335) = {334,335};
Line(111121) = {111,121};
Line(121131) = {121,131};
Line(112122) = {112,122};
Line(122132) = {122,132};
Line(113123) = {113,123};
Line(123133) = {123,133};
Line(114124) = {114,124};
Line(124134) = {124,134};
Line(115125) = {115,125};
Line(125135) = {125,135};
Line(211221) = {211,221};
Line(221231) = {221,231};
Line(212222) = {212,222};
Line(222232) = {222,232};
Line(213223) = {213,223};
Line(223233) = {223,233};
Line(214224) = {214,224};
Line(224234) = {224,234};
Line(215225) = {215,225};
Line(225235) = {225,235};
Line(311321) = {311,321};
Line(321331) = {321,331};
Line(312322) = {312,322};
Line(322332) = {322,332};
Line(313323) = {313,323};
Line(314324) = {314,324};
Line(324334) = {324,334};
Line(315325) = {315,325};
Line(325335) = {325,335};
Line(111211) = {111,211};
Line(211311) = {211,311};
Line(121221) = {121,221};
Line(221321) = {221,321};
Line(131231) = {131,231};
Line(231331) = {231,331};
Line(112212) = {112,212};
Line(212312) = {212,312};
Line(122222) = {122,222};
Line(222322) = {222,322};
Line(132232) = {132,232};
Line(232332) = {232,332};
Line(113213) = {113,213};
Line(213313) = {213,313};
Line(123223) = {123,223};
Line(223323) = {223,323};
Line(133233) = {133,233};
Line(114214) = {114,214};
Line(214314) = {214,314};
Line(124224) = {124,224};
Line(224324) = {224,324};
Line(134234) = {134,234};
Line(234334) = {234,334};
Line(115215) = {115,215};
Line(215315) = {215,315};
Line(125225) = {125,225};
Line(225325) = {225,325};
Line(135235) = {135,235};
Line(235335) = {235,335};

Line Loop(1001119) = {111112,112122,-121122,-111121};
Plane Surface(100111) = {1001119};
Line Loop(1001129) = {112113,113123,-122123,-112122};
Plane Surface(100112) = {1001129};
Line Loop(1001139) = {113114,114124,-123124,-113123};
Plane Surface(100113) = {1001139};
Line Loop(1001149) = {114115,115125,-124125,-114124};
Plane Surface(100114) = {1001149};
Line Loop(1001219) = {121122,122132,-131132,-121131};
Plane Surface(100121) = {1001219};
Line Loop(1001229) = {122123,123133,-132133,-122132};
Plane Surface(100122) = {1001229};
Line Loop(1001239) = {123124,124134,-133134,-123133};
Plane Surface(100123) = {1001239};
Line Loop(1001249) = {124125,125135,-134135,-124134};
Plane Surface(100124) = {1001249};
Line Loop(1002119) = {211212,212222,-221222,-211221};
Plane Surface(100211) = {1002119};
Line Loop(1002129) = {212213,213223,-222223,-212222};
Plane Surface(100212) = {1002129};
Line Loop(1002139) = {213214,214224,-223224,-213223};
Plane Surface(100213) = {1002139};
Line Loop(1002149) = {214215,215225,-224225,-214224};
Plane Surface(100214) = {1002149};
Line Loop(1002219) = {221222,222232,-231232,-221231};
Plane Surface(100221) = {1002219};
Line Loop(1002229) = {222223,223233,-232233,-222232};
Plane Surface(100222) = {1002229};
Line Loop(1002239) = {223224,224234,-233234,-223233};
Plane Surface(100223) = {1002239};
Line Loop(1002249) = {224225,225235,-234235,-224234};
Plane Surface(100224) = {1002249};
Line Loop(1003119) = {311312,312322,-321322,-311321};
Plane Surface(100311) = {1003119};
Line Loop(1003129) = {312313,313323,-322323,-312322};
Plane Surface(100312) = {1003129};
Line Loop(1003139) = {313314,314324,-323324,-313323};
Plane Surface(100313) = {1003139};
Line Loop(1003149) = {314315,315325,-324325,-314324};
Plane Surface(100314) = {1003149};
Line Loop(1003219) = {321322,322332,-331332,-321331};
Plane Surface(100321) = {1003219};
Line Loop(1003249) = {324325,325335,-334335,-324334};
Plane Surface(100324) = {1003249};
Line Loop(2001119) = {111112,112212,-211212,-111211};
Plane Surface(200111) = {2001119};
Line Loop(2001129) = {112113,113213,-212213,-112212};
Plane Surface(200112) = {2001129};
Line Loop(2001139) = {113114,114214,-213214,-113213};
Plane Surface(200113) = {2001139};
Line Loop(2001149) = {114115,115215,-214215,-114214};
Plane Surface(200114) = {2001149};
Line Loop(2002119) = {211212,212312,-311312,-211311};
Plane Surface(200211) = {2002119};
Line Loop(2002129) = {212213,213313,-312313,-212312};
Plane Surface(200212) = {2002129};
Line Loop(2002139) = {213214,214314,-313314,-213313};
Plane Surface(200213) = {2002139};
Line Loop(2002149) = {214215,215315,-314315,-214314};
Plane Surface(200214) = {2002149};
Line Loop(2001219) = {121122,122222,-221222,-121221};
Plane Surface(200121) = {2001219};
Line Loop(2001229) = {122123,123223,-222223,-122222};
Plane Surface(200122) = {2001229};
Line Loop(2001239) = {123124,124224,-223224,-123223};
Plane Surface(200123) = {2001239};
Line Loop(2001249) = {124125,125225,-224225,-124224};
Plane Surface(200124) = {2001249};
Line Loop(2002219) = {221222,222322,-321322,-221321};
Plane Surface(200221) = {2002219};
Line Loop(2002229) = {222223,223323,-322323,-222322};
Plane Surface(200222) = {2002229};
Line Loop(2002239) = {223224,224324,-323324,-223323};
Plane Surface(200223) = {2002239};
Line Loop(2002249) = {224225,225325,-324325,-224324};
Plane Surface(200224) = {2002249};
Line Loop(2001319) = {131132,132232,-231232,-131231};
Plane Surface(200131) = {2001319};
Line Loop(2001329) = {132133,133233,-232233,-132232};
Plane Surface(200132) = {2001329};
Line Loop(2001339) = {133134,134234,-233234,-133233};
Plane Surface(200133) = {2001339};
Line Loop(2001349) = {134135,135235,-234235,-134234};
Plane Surface(200134) = {2001349};
Line Loop(2002319) = {231232,232332,-331332,-231331};
Plane Surface(200231) = {2002319};
Line Loop(2002349) = {234235,235335,-334335,-234334};
Plane Surface(200234) = {2002349};
Line Loop(3001119) = {111121,121221,-211221,-111211};
Plane Surface(300111) = {3001119};
Line Loop(3002119) = {211221,221321,-311321,-211311};
Plane Surface(300211) = {3002119};
Line Loop(3001219) = {121131,131231,-221231,-121221};
Plane Surface(300121) = {3001219};
Line Loop(3002219) = {221231,231331,-321331,-221321};
Plane Surface(300221) = {3002219};
Line Loop(3001129) = {112122,122222,-212222,-112212};
Plane Surface(300112) = {3001129};
Line Loop(3002129) = {212222,222322,-312322,-212312};
Plane Surface(300212) = {3002129};
Line Loop(3001229) = {122132,132232,-222232,-122222};
Plane Surface(300122) = {3001229};
Line Loop(3002229) = {222232,232332,-322332,-222322};
Plane Surface(300222) = {3002229};
Line Loop(3001139) = {113123,123223,-213223,-113213};
Plane Surface(300113) = {3001139};
Line Loop(3002139) = {213223,223323,-313323,-213313};
Plane Surface(300213) = {3002139};
Line Loop(3001239) = {123133,133233,-223233,-123223};
Plane Surface(300123) = {3001239};
Line Loop(3001149) = {114124,124224,-214224,-114214};
Plane Surface(300114) = {3001149};
Line Loop(3002149) = {214224,224324,-314324,-214314};
Plane Surface(300214) = {3002149};
Line Loop(3001249) = {124134,134234,-224234,-124224};
Plane Surface(300124) = {3001249};
Line Loop(3002249) = {224234,234334,-324334,-224324};
Plane Surface(300224) = {3002249};
Line Loop(3001159) = {115125,125225,-215225,-115215};
Plane Surface(300115) = {3001159};
Line Loop(3002159) = {215225,225325,-315325,-215315};
Plane Surface(300215) = {3002159};
Line Loop(3001259) = {125135,135235,-225235,-125225};
Plane Surface(300125) = {3001259};
Line Loop(3002259) = {225235,235335,-325335,-225325};
Plane Surface(300225) = {3002259};

//sphere
Point(1015) = {c15,0,0,precs};
Point(2015) = {-c15,0,0,precs};
Point(4015) = {0,-c15,0,precs};
Point(6015) = {0,0,-c15,precs};

Line(3331015) = {333,1015};
Line(3332015) = {333,2015};
Line(3334015) = {333,4015};
Line(3336015) = {333,6015};
Circle(20154015) = {2015,333,4015};
Circle(40151015) = {4015,333,1015};
Circle(20156015) = {2015,333,6015};
Circle(60151015) = {6015,333,1015};
Circle(40156015) = {4015,333,6015};

//sphere - box
Line(1015334) = {1015,334};
Line(2015332) = {2015,332};
Line(4015323) = {4015,323};
Line(6015233) = {6015,233};
//pml volumes
Surface Loop(60151016) = {-300111,-100111,200111,300112,-200121,100211};
Volume(60151017) = {60151016};
Physical Volume(111) = {60151017}; //-z -y -x
Surface Loop(60151018) = {-300112,-100112,200112,300113,-200122,100212};
Volume(60151019) = {60151018};
Physical Volume(112) = {60151019}; //-z -y
Surface Loop(60151020) = {-300113,-100113,200113,300114,-200123,100213};
Volume(60151021) = {60151020};
Physical Volume(113) = {60151021}; //-z -y
Surface Loop(60151022) = {-300114,-100114,200114,300115,-200124,100214};
Volume(60151023) = {60151022};
Physical Volume(114) = {60151023}; //-z -y +x
Surface Loop(60151024) = {-300121,-100121,200121,300122,-200131,100221};
Volume(60151025) = {60151024};
Physical Volume(121) = {60151025}; //-z -x
Surface Loop(60151026) = {-300122,-100122,200122,+300123,-200132,100222};
Volume(60151027) = {60151026};
Physical Volume(122) = {60151027}; //-z
Surface Loop(60151028) = {-300123,-100123,200123,300124,-200133,100223};
Volume(60151029) = {60151028};
Physical Volume(123) = {60151029}; //-z
Surface Loop(60151030) = {-300124,-100124,200124,300125,-200134,100224};
Volume(60151031) = {60151030};
Physical Volume(124) = {60151031}; //-z +x
Surface Loop(60151032) = {-300211,-100211,200211,300212,-200221,100311};
Volume(60151033) = {60151032};
Physical Volume(211) = {60151033}; //-y -x
Surface Loop(60151034) = {-300212,-100212,200212,300213,-200222,100312};
Volume(60151035) = {60151034};
Physical Volume(212) = {60151035}; //-y
Surface Loop(60151036) = {-300213,-100213,200213,300214,-200223,100313};
Volume(60151037) = {60151036};
Physical Volume(213) = {60151037}; //-y
Surface Loop(60151038) = {-300214,-100214,200214,300215,-200224,100314};
Volume(60151039) = {60151038};
Physical Volume(214) = {60151039}; //-y +x
Surface Loop(60151040) = {-300221,-100221,200221,300222,-200231,100321};
Volume(60151041) = {60151040};
Physical Volume(221) = {60151041}; //-x
Surface Loop(60151042) = {-300224,-100224,200224,300225,-200234,100324};
Volume(60151043) = {60151042};
Physical Volume(224) = {60151043}; //+x


Line Loop(60151044) = {6015233,-223233,223323,-4015323,-3334015,3336015};
Line Loop(60151045) = {40156015,6015233,-223233,223323,-4015323};
Plane Surface(60151046) = {60151045};
Line Loop(60151047) = {4015323,323324,324334,-1015334,-40151015};
Plane Surface(60151048) = {60151047};
Line Loop(60151049) = {234334,-1015334,-60151015,6015233,233234};
Plane Surface(60151050) = {60151049};
Line Loop(60151051) = {60151015,-3331015,3336015};
Plane Surface(60151052) = {60151051};
Line Loop(60151053) = {40151015,-3331015,3334015};
Plane Surface(60151054) = {60151053};
Line Loop(60151055) = {40156015,-3336015,3334015};
Plane Surface(60151056) = {60151055};
Line Loop(60151057) = {20156015,-3336015,3332015};
Plane Surface(60151058) = {60151057};
Line Loop(60151059) = {3332015,20154015,-3334015};
Plane Surface(60151060) = {60151059};
Line Loop(60151061) = {6015233,-232233,232332,-2015332,20156015};
Plane Surface(60151062) = {60151061};
Line Loop(60151063) = {2015332,-322332,322323,-4015323,-20154015};
Plane Surface(60151064) = {60151063};
Line Loop(60151065) = {40156015,60151015,-40151015};
Ruled Surface(60151066) = {60151065};
Line Loop(60151067) = {20156015,-40156015,-20154015};
Ruled Surface(60151068) = {60151067};

//air
Surface Loop(60151069) = {60151064,60151062,-60151046,-60151068,-100222,200222,-300222};
Volume(60151070) = {60151069};
Physical Volume(1) = {60151070}; //-x
Surface Loop(60151071) = {-60151066,60151046,-60151050,300224,-100223,200223,60151048};
Volume(60151072) = {60151071};
Physical Volume(2) = {60151072}; //+x

//sphere
Surface Loop(60151073) = {60151060,-60151058,60151068,60151056};
Volume(60151074) = {60151073};
Physical Volume(7157) = {60151074}; //-x
Surface Loop(60151075) = {-60151056,60151066,-60151052,60151054};
Volume(60151076) = {60151075};
Physical Volume(8157) = {60151076}; //+x


//boundaries
Physical Surface(31) = {300221,300211,300111,300121}; //-x
Physical Surface(32) = {300225,300215,300125,300115}; //+x
Physical Surface(21) = {200212,200112,200111,200211,200213,200113,200114,200214}; //-y
Physical Surface(20012) = {200132,200131,200231,60151062,60151058,60151052,60151050,200234,200134,200133};//xz y=0
Physical Surface(11) = {100121,100111,100122,100112,100113,100114,100124,100123}; //-z
Physical Surface(10012) = {100321,100311,100312,60151064,100313,100314,100324,60151048,60151054,60151060};//xy z=0
