SetFactory("OpenCASCADE");

mm2m = 0.001;
i2m = 0.0254;
Geometry.AutoCoherence = 1;
Mesh.CharacteristicLengthMin = 0.125*i2m;
Mesh.CharacteristicLengthMax = 0.250*i2m;
Geometry.Tolerance = 0.01*mm2m;
lc  = 0.125*i2m;


a  = 2.0 * i2m;
p1=newp; Point(p1) = { a, 0.0,  a, lc};
p2=newp; Point(p2) = {-a, 0.0,  a, lc};
p3=newp; Point(p3) = {-a, 0.0, -a, lc};
p4=newp; Point(p4) = { a, 0.0, -a, lc};
l1=newl; Line(l1) = {p1, p2};
l2=newl; Line(l2) = {p2, p3};
l3=newl; Line(l3) = {p3, p4};
l4=newl; Line(l4) = {p4, p1};
ll1=newll; Curve Loop(ll1) = {l1, l2, l3, l4};
s1=news; Plane Surface(s1)={ll1};
hh = 0.5*i2m;
id[] = Extrude {0,hh,0} { Surface{s1}; Layers{ 1 }; Recombine; };
v1 = id[1];


p5=newp; Point(p5) = { a/2, 0.0,  a/2, lc};
p6=newp; Point(p6) = {-a/2, 0.0,  a/2, lc};
p7=newp; Point(p7) = {-a/2, 0.0, -a/2, lc};
p8=newp; Point(p8) = { a/2, 0.0, -a/2, lc};
l5=newl; Line(l5) = {p5, p6};
l6=newl; Line(l6) = {p6, p7};
l7=newl; Line(l7) = {p7, p8};
l8=newl; Line(l8) = {p8, p5};
Point {p5,p6,p7,p8} In Surface{s1};
Line {l5,l6,l7,l8} In Surface{s1};

ll2=newll; Curve Loop(ll2) = {l5, l6, l7, l8};
s2=news; Plane Surface(s2)={ll2};
id[] = Extrude {0,-hh,0} { Surface{s2}; Layers{ 1 }; Recombine; };
v2 = id[1];

Surface {s2} In Volume{v1};


v() = BooleanFragments{ Volume{v1}; Delete;}{ Volume{v2}; Delete;};
n=#v();
For i In {0:n-1}
	Printf("v(%g) = %g",i,v(i));
EndFor


Mesh 3;
Coherence Mesh;
