Geometry.AutoCoherence=0;

teta=0;
d1=0.5;
pi_2=Pi/2.;
ln_array[]={};
pt_array[] = {};
latt_lines[]={};

// a circle
x1=0; y1=0; z1=0;
pt_array[] += newp;
Point(pt_array[#pt_array[]-1]) = {x1,y1,z1};
// points
For _n In {1:4}
    pt_array[] += newp;
    Point(pt_array[#pt_array[]-1]) = {x1+d1/2.*Cos(teta), y1+d1/2.*Sin(teta), z1};
    teta += pi_2;
EndFor
// first point on circle (center)
pc = (#pt_array[])-5;
ln_array[]+=newreg; Circle(ln_array[#ln_array[]-1]) = {pt_array[pc+1], pt_array[pc], pt_array[pc+2]};
ln_array[]+=newreg; Circle(ln_array[#ln_array[]-1]) = {pt_array[pc+2], pt_array[pc], pt_array[pc+3]};
ln_array[]+=newreg; Circle(ln_array[#ln_array[]-1]) = {pt_array[pc+3], pt_array[pc], pt_array[pc+4]};
ln_array[]+=newreg; Circle(ln_array[#ln_array[]-1]) = {pt_array[pc+4], pt_array[pc], pt_array[pc+1]};




// a circle
x1=0; y1=0; z1=1;
pt_array[] += newp;
Point(pt_array[#pt_array[]-1]) = {x1,y1,z1};

// points
For _n In {1:4}
    pt_array[] += newp;
    Point(pt_array[#pt_array[]-1]) = {x1+d1/2.*Cos(teta), y1+d1/2.*Sin(teta), z1};
    teta += pi_2;
EndFor
// first point on circle (center)
pc = (#pt_array[])-5;
ln_array[]+=newreg; Circle(ln_array[#ln_array[]-1]) = {pt_array[pc+1], pt_array[pc], pt_array[pc+2]};
ln_array[]+=newreg; Circle(ln_array[#ln_array[]-1]) = {pt_array[pc+2], pt_array[pc], pt_array[pc+3]};
ln_array[]+=newreg; Circle(ln_array[#ln_array[]-1]) = {pt_array[pc+3], pt_array[pc], pt_array[pc+4]};
ln_array[]+=newreg; Circle(ln_array[#ln_array[]-1]) = {pt_array[pc+4], pt_array[pc], pt_array[pc+1]};



// lines connecting to the 2 previous circle
pc_prev = pc-5;
latt_lines[]+=newreg; Line(latt_lines[#latt_lines[]-1]) = {pt_array[pc+1], pt_array[pc_prev+1]};
latt_lines[]+=newreg; Line(latt_lines[#latt_lines[]-1]) = {pt_array[pc+2], pt_array[pc_prev+2]};
latt_lines[]+=newreg; Line(latt_lines[#latt_lines[]-1]) = {pt_array[pc+3], pt_array[pc_prev+3]};
latt_lines[]+=newreg; Line(latt_lines[#latt_lines[]-1]) = {pt_array[pc+4], pt_array[pc_prev+4]};



// a circle
x1=0; y1=0; z1=1; phi=0.3;
pt_array[] += newp;
Point(pt_array[#pt_array[]-1]) = {x1,y1,z1};

// points
For _n In {1:4}
    pt_array[] += newp;
    Point(pt_array[#pt_array[]-1]) = {x1+d1/2.*Cos(teta+phi), y1+d1/2.*Sin(teta+phi), z1};
    teta += pi_2;
EndFor
// first point on circle (center)
pc = (#pt_array[])-5;
ln_array[]+=newreg; Circle(ln_array[#ln_array[]-1]) = {pt_array[pc+1], pt_array[pc], pt_array[pc+2]};
ln_array[]+=newreg; Circle(ln_array[#ln_array[]-1]) = {pt_array[pc+2], pt_array[pc], pt_array[pc+3]};
ln_array[]+=newreg; Circle(ln_array[#ln_array[]-1]) = {pt_array[pc+3], pt_array[pc], pt_array[pc+4]};
ln_array[]+=newreg; Circle(ln_array[#ln_array[]-1]) = {pt_array[pc+4], pt_array[pc], pt_array[pc+1]};


// a circle
x1=0; y1=0; z1=2; phi=0.3;
pt_array[] += newp;
Point(pt_array[#pt_array[]-1]) = {x1,y1,z1};
// points
For _n In {1:4}
    pt_array[] += newp;
    Point(pt_array[#pt_array[]-1]) = {x1+d1/2.*Cos(teta+phi), y1+d1/2.*Sin(teta+phi), z1};
    teta += pi_2;
EndFor
// first point on circle (center)
pc = (#pt_array[])-5;
ln_array[]+=newreg; Circle(ln_array[#ln_array[]-1]) = {pt_array[pc+1], pt_array[pc], pt_array[pc+2]};
ln_array[]+=newreg; Circle(ln_array[#ln_array[]-1]) = {pt_array[pc+2], pt_array[pc], pt_array[pc+3]};
ln_array[]+=newreg; Circle(ln_array[#ln_array[]-1]) = {pt_array[pc+3], pt_array[pc], pt_array[pc+4]};
ln_array[]+=newreg; Circle(ln_array[#ln_array[]-1]) = {pt_array[pc+4], pt_array[pc], pt_array[pc+1]};

// lines connecting to the previous circle
pc_prev = pc-5;
latt_lines[]+=newreg; Line(latt_lines[#latt_lines[]-1]) = {pt_array[pc+1], pt_array[pc_prev+1]};
latt_lines[]+=newreg; Line(latt_lines[#latt_lines[]-1]) = {pt_array[pc+2], pt_array[pc_prev+2]};
latt_lines[]+=newreg; Line(latt_lines[#latt_lines[]-1]) = {pt_array[pc+3], pt_array[pc_prev+3]};
latt_lines[]+=newreg; Line(latt_lines[#latt_lines[]-1]) = {pt_array[pc+4], pt_array[pc_prev+4]};
Line Loop(25) = {20, 21, -16, -24};
Ruled Surface(26) = {25};
Line Loop(27) = {21, 13, -22, -17};
Ruled Surface(28) = {27};
Line Loop(29) = {22, 14, -23, -18};
Ruled Surface(30) = {29};
Line Loop(31) = {24, -15, -23, 19};
Ruled Surface(32) = {31};
Line Loop(33) = {7, 12, -3, -11};
Ruled Surface(34) = {33};
Line Loop(35) = {6, 11, -2, -10};
Ruled Surface(36) = {35};
Line Loop(37) = {5, 10, -1, -9};
Ruled Surface(38) = {37};
Line Loop(39) = {8, 9, -4, -12};
Ruled Surface(40) = {39};
Line Loop(41) = {19, 20, 17, 18};
Plane Surface(42) = {41};
Line Loop(43) = {4, 1, 2, 3};
Plane Surface(44) = {43};
Coherence;
Coherence;
Coherence;
Coherence;
Coherence;
Coherence;
Coherence;
Coherence;
