// Gmsh file to generate a Kelvin Cell Geometry
// Stick Model
//KSYMMI = 4

l=10; // No of cells in Z
m=1;// No of cells in X
n=10; // No of cells in Y
celldim = 0.005;
scale = celldim/5;
dzwall = 0.5-celldim*l-(l-1)*1*scale+0.5*scale;
dywall = 0.5-celldim*n-(n-1)*1*scale+0.5*scale;
dxwall = 0.5+celldim*m+(m-1)*1*scale;
wtck = 0.02;


SetFactory("OpenCASCADE");
Cylinder(1) = {0,-2,1,0,1,1,0.5, 2*Pi};
Cylinder(2) = {2,-1,0,0,1,1,0.5, 2*Pi};
Cylinder(3) = {2,0,-1,0,1,1,0.5, 2*Pi};
Cylinder(4) = {0,1,-2,0,1,1,0.5, 2*Pi};
Cylinder(5) = {0,-1,-2,0,-1,1,0.5, 2*Pi};
Cylinder(6) = {2,0,-1,0,-1,1,0.5, 2*Pi};
Cylinder(7) = {2,1,0,0,-1,1,0.5, 2*Pi};
Cylinder(8) = {0,2,1,0,-1,1,0.5, 2*Pi};
Cylinder(9) = {-2,0,1,1,0,1,0.5, 2*Pi};
Cylinder(10) = {-1,2,0,1,0,1,0.5, 2*Pi};
Cylinder(11) = {0,2,-1,1,0,1,0.5, 2*Pi};
Cylinder(12) = {1,0,-2,1,0,1,0.5, 2*Pi};
Cylinder(13) = {-1,0,-2,-1,0,1,0.5, 2*Pi};
Cylinder(14) = {0,-2,-1,-1,0,1,0.5, 2*Pi};
Cylinder(15) = {1,-2,0,-1,0,1,0.5, 2*Pi};
Cylinder(16) = {2,0,1,-1,0,1,0.5, 2*Pi};
Cylinder(17) = {-2,1,0,1,1,0,0.5, 2*Pi};
Cylinder(18) = {-1,0,-2,1,1,0,0.5, 2*Pi};
Cylinder(19) = {0,-1,-2,1,1,0,0.5, 2*Pi};
Cylinder(20) = {1,-2,0,1,1,0,0.5, 2*Pi};
Cylinder(21) = {-2,-1,0,1,-1,0,0.5, 2*Pi};
Cylinder(22) = {-1,0,2,1,-1,0,0.5, 2*Pi};
Cylinder(23) = {0,1,2,1,-1,0,0.5, 2*Pi};
Cylinder(24) = {1,2,0,1,-1,0,0.5, 2*Pi};
Sphere(25) = {1,0,2,0.5, -Pi/2, Pi/2, 2*Pi};
Sphere(26) = {0,1,2,0.5, -Pi/2, Pi/2, 2*Pi};
Sphere(27) = {-1,0,2,0.5, -Pi/2, Pi/2, 2*Pi};
Sphere(28) = {0,-1,2,0.5, -Pi/2, Pi/2, 2*Pi};
Sphere(29) = {2,0,1,0.5, -Pi/2, Pi/2, 2*Pi};
Sphere(30) = {0,2,1,0.5, -Pi/2, Pi/2, 2*Pi};
Sphere(31) = {-2,0,1,0.5, -Pi/2, Pi/2, 2*Pi};
Sphere(32) = {0,-2,1,0.5, -Pi/2, Pi/2, 2*Pi};
Sphere(33) = {2,1,0,0.5, -Pi/2, Pi/2, 2*Pi};
Sphere(34) = {1,2,0,0.5, -Pi/2, Pi/2, 2*Pi};
Sphere(35) = {-1,2,0,0.5, -Pi/2, Pi/2, 2*Pi};
Sphere(36) = {-2,1,0,0.5, -Pi/2, Pi/2, 2*Pi};
Sphere(37) = {-2,-1,0,0.5, -Pi/2, Pi/2, 2*Pi};
Sphere(38) = {-1,-2,0,0.5, -Pi/2, Pi/2, 2*Pi};
Sphere(39) = {1,-2,0,0.5, -Pi/2, Pi/2, 2*Pi};
Sphere(40) = {2,-1,0,0.5, -Pi/2, Pi/2, 2*Pi};
Sphere(41) = {2,0,-1,0.5, -Pi/2, Pi/2, 2*Pi};
Sphere(42) = {0,2,-1,0.5, -Pi/2, Pi/2, 2*Pi};
Sphere(43) = {-2,0,-1,0.5, -Pi/2, Pi/2, 2*Pi};
Sphere(44) = {0,-2,-1,0.5, -Pi/2, Pi/2, 2*Pi};
Sphere(45) = {1,0,-2,0.5, -Pi/2, Pi/2, 2*Pi};
Sphere(46) = {0,1,-2,0.5, -Pi/2, Pi/2, 2*Pi};
Sphere(47) = {-1,0,-2,0.5, -Pi/2, Pi/2, 2*Pi};
Sphere(48) = {0,-1,-2,0.5, -Pi/2, Pi/2, 2*Pi};
Cylinder(49) = {-2,0,-1,0,-1,1,0.5, 2*Pi};
Cylinder(50) = {-2,0,-1,0,1,1,0.5, 2*Pi};
Cylinder(51) = {-2,0,1,0,1,-1,0.5, 2*Pi};
Cylinder(52) = {-2,0,1,0,-1,-1,0.5, 2*Pi};
Cylinder(53) = {0,-1,-2,-1,1,0,0.5, 2*Pi};
Cylinder(54) = {1,0,-2,-1,1,0,0.5, 2*Pi};
Cylinder(55) = {0,-2,-1,1,0,1,0.5, 2*Pi};
Cylinder(56) = {-1,-2,0,1,0,1,0.5, 2*Pi};
Cylinder(57) = {-1,0,2,1,1,0,0.5, 2*Pi};
Cylinder(58) = {1,0,2,-1,-1,0,0.5, 2*Pi};
Cylinder(59) = {0,2,1,1,0,-1,0.5, 2*Pi};
Cylinder(60) = {-1,2,0,1,0,-1,0.5, 2*Pi};

Rotate {{0, 1, 1}, {2, -0.5, 0.5}, -Pi/2} {  Volume{2}; }
Rotate {{0, 1, 1}, {2, 0.5, -0.5}, -Pi/2} {  Volume{3}; }
Rotate {{0, -1, 1}, {2, -0.5, -0.5}, -Pi/2} {  Volume{6}; }
Rotate {{0, -1, 1}, {2, 0.5, 0.5}, -Pi/2} {  Volume{7}; }

Rotate {{0, -1, 1}, {-2, -0.5, -0.5}, Pi/2} {  Volume{49}; }
Rotate {{0, 1, 1}, {-2, 0.5, -0.5}, Pi/2} {  Volume{50}; }
Rotate {{0, -1, 1}, {-2, 0.5, 0.5}, -Pi/2} {  Volume{51}; }
Rotate {{0, 1, 1}, {-2, -0.5, 0.5}, -Pi/2} {  Volume{52}; }


BooleanUnion{ Volume{1}; Delete;}{ Volume{2:60}; Delete;}

i=0;
For (1:l-1)
  i=i+1;
  Translate {0, 0, 4*i} { Duplicata { Volume {1};} }
EndFor

If (l>1)
  BooleanUnion{ Volume{1}; Delete;}{ Volume{2:l}; Delete;}
EndIf

j=0;
For (1:m-1)
  j=j+1;
  Translate {4*j, 0, 0} { Duplicata { Volume{1};} }
EndFor

If (m>1)
  BooleanUnion{ Volume{1}; Delete;}{ Volume{2:m}; Delete;}
EndIf

k=0;
  For (1:n-1)
  k=k+1;
  Translate {0, 4*k, 0} { Duplicata { Volume{1};} }
EndFor

If (n>1)
  BooleanUnion{ Volume{1}; Delete;}{ Volume{2:n}; Delete;}
EndIf

Dilate {{0, 0, 0}, {scale, scale, scale}} {  Volume{1}; }


Box(2) = {-celldim/2                                     , 0.5*scale-celldim/2                        , -celldim/2+l*celldim-(l-1)*1*scale        , celldim*m-(m-1)*1*scale , n*celldim-(n-1)*1*scale-0.5*scale           , dzwall                                        };
Box(3) = {-celldim/2                                     , -celldim/2+n*celldim-(n-1)*1*scale         , 0.5*scale-celldim/2                       , celldim*m-(m-1)*1*scale , dywall                                      , dzwall+l*celldim-(l-1)*1*scale-0.5*scale      };
Box(4) = {-celldim/2+m*celldim-(m-1)*1*scale             , 0.5*scale-celldim/2                        , -celldim/2+dzwall+l*celldim-(l-1)*1*scale , -dxwall                 , dywall + n*celldim-(n-1)*1*scale-0.5*scale  , wtck                                          };  // dz = m*celldim-(m-1)*1*scale
Box(5) = {-celldim/2+m*celldim-(m-1)*1*scale             , -celldim/2+n*celldim-(n-1)*1*scale+dywall  , 0.5*scale-celldim/2                       , -dxwall                 , wtck                     , dzwall+l*celldim-(l-1)*1*scale+wtck-0.5*scale };

Box(6) = {-celldim/2, -celldim/2+0.5*scale, -celldim/2+0.5*scale, celldim*m-(m-1)*1*scale, n*celldim-(n-1)*1*scale-0.5*scale, l*celldim-(l-1)*1*scale-0.5*scale};
BooleanIntersection{ Volume{1}; Delete;}{ Volume{6}; Delete; }

BooleanUnion{ Volume{2}; Delete; }{ Volume{3}; Volume{4}; Volume{5};Delete; }
BooleanUnion{ Volume{1}; Delete; }{ Volume{2}; Delete;}
b1() = Boundary{ Volume{1}; };
b2() = Boundary{ Volume{2}; };
Physical Surface("1") = {b1()};
Physical Surface("2") = {b2()};

/* // JUST TO VERIFY SIMMETRY
Rotate {{1, 0, 0}, {-celldim/2, -celldim/2+0.5*scale, -celldim/2+0.5*scale}, Pi/2} {
  Duplicata { Volume{2}; }
}

Rotate {{1, 0, 0}, {-celldim/2, -celldim/2+0.5*scale, -celldim/2+0.5*scale}, Pi/2} {
  Duplicata { Volume{3}; }
}

Rotate {{1, 0, 0}, {-celldim/2, -celldim/2+0.5*scale, -celldim/2+0.5*scale}, Pi/2} {
  Duplicata { Volume{4}; }
}

Rotate {{1, 0, 0}, {-celldim/2, -celldim/2+0.5*scale, -celldim/2+0.5*scale}, Pi/2} {
  Duplicata { Volume{1}; }
}

Rotate {{1, 0, 0}, {-celldim/2, -celldim/2+0.5*scale, -celldim/2+0.5*scale}, Pi/2} {
  Duplicata { Volume{6}; }
}

Rotate {{1, 0, 0}, {-celldim/2, -celldim/2+0.5*scale, -celldim/2+0.5*scale}, Pi/2} {
  Duplicata { Volume{7}; }
}
*/
