r=1;        // Rayon
e=1.e-1;    // Epaisseur

n = 2+1;      // Nb elem epaisseur
//DefineConstant[ p = {6, Min 1, Max 120, Step 1,
//                         Name "Nb elem tranche"} ];

p=8;


a = (r-e)/Sqrt(3);
b = r/Sqrt(3);

Point(1)   = {0, 0, 0, 1.};
Point(2)   = {(r-e), 0, 0, 1.};
Point(3)   = {r, 0, 0, 1.};
Point(4)   = {0, (r-e), 0, 1.};
Point(5)   = {0, r, 0, 1.};
Point(6)   = {0, 0, (r-e), 1.};
Point(7)   = {0, 0, r, 1.};
Point(8)   = {(r-e)*Cos(Pi/4),(r-e)*Cos(Pi/4),0, 1.};   // XY Plane inner sphere
Point(9)   = {r*Cos(Pi/4),r*Cos(Pi/4),0, 1.}; // XY Plane outer sphere
Point(10)  = {0, (r-e)*Cos(Pi/4),(r-e)*Cos(Pi/4),1.};   // YZ Plane inner sphere
Point(11)  = {0, r*Cos(Pi/4),r*Cos(Pi/4),1.};   // YZ Plane outer sphere
Point(12)  = {(r-e)*Cos(Pi/4), 0,(r-e)*Cos(Pi/4),1.};   // XZ Plane inner sphere
Point(13)  = {r*Cos(Pi/4), 0, r*Cos(Pi/4),1.};   // XZ Plane outer sphere
Point(14)  = {a, a, a, 1.};
Point(15)  = {b, b, b, 1.};

Line(1) = {2, 3};
Line(2) = {4, 5};
Line(3) = {6, 7};
Line(4) = {8, 9};
Line(5) = {10, 11};
Line(6) = {12, 13};
Circle(7) = {2, 1, 12};
Circle(8) = {12, 1, 6};
Circle(9) = {6, 1, 10};
Circle(10) = {10, 1, 4};
Circle(11) = {4, 1, 8};
Circle(12) = {8, 1, 2};
Circle(13) = {3, 1, 13};
Circle(14) = {13, 1, 7};
Circle(15) = {7, 1, 11};
Circle(16) = {11, 1, 5};
Circle(17) = {5, 1, 9};
Circle(18) = {9, 1, 3};
Circle(19) = {12, 1, 14};
Circle(20) = {14, 1, 8};
Circle(21) = {14, 1, 10};
Circle(22) = {13, 1, 15};
Circle(23) = {15, 1, 9};
Circle(24) = {15, 1, 11};
Line(37) = {14, 15};

Line Loop(25) = {16, -2, -10, 5};
Plane Surface(26) = {25};
Line Loop(27) = {15, -5, -9, 3};
Plane Surface(28) = {27};
Line Loop(29) = {2, 17, -4, -11};
Plane Surface(30) = {29};
Line Loop(31) = {4, 18, -1, -12};
Plane Surface(32) = {31};
Line Loop(33) = {3, -14, -6, 8};
Plane Surface(34) = {33};
Line Loop(35) = {6, -13, -1, 7};
Plane Surface(36) = {35};
Line Loop(38) = {22, -37, -19, 6};
Plane Surface(39) = {38};
Line Loop(40) = {37, 23, -4, -20};
Plane Surface(41) = {40};
Line Loop(42) = {24, -5, -21, 37};
Plane Surface(43) = {42};
Line Loop(44) = {21, -9, -8, 19};
Ruled Surface(45) = {44};
Line Loop(46) = {21, 10, 11, -20};
Ruled Surface(47) = {46};
Line Loop(48) = {19, 20, 12, 7};
Ruled Surface(49) = {48};
Line Loop(50) = {22, 24, -15, -14};
Ruled Surface(51) = {50};
Line Loop(52) = {13, 22, 23, 18};
Ruled Surface(53) = {52};
Line Loop(54) = {23, -17, -16, -24};
Ruled Surface(55) = {54};

Surface Loop(56) = {53, 36, 32, 49, 41, 39};
Volume(57) = {56};
Surface Loop(58) = {51, 28, 45, 34, 43, 39};
Volume(59) = {58};
Surface Loop(60) = {30, 26, 55, 47, 43, 41};
Volume(61) = {60};

Transfinite Line {1,2,3,4,5,6,37}       = n Using Progression 1;
Transfinite Line {9,12,15,18,19,22}     = p Using Progression 1;
Transfinite Line {20,21,23,24,10,11,16,17,7,8,13,14} = p Using Progression 1;

Transfinite Surface {26,28,30,32,34,36,39,41,43,45,47,49,51,53,55};
Recombine Surface {26,28,30,32,34,36,39,41,43,45,47,49,51,53,55};

Transfinite Volume {57,59,61};
Recombine Volume {57,59,61};

Geometry.CopyMeshingMethod = 1; // en plus de la geometrie, copie aussi les parametres de maillage

Symmetry {0, 1, 0, 0} {
  Duplicata { Volume {57,59,61}; }
}
Symmetry {1, 0, 0, 0} {
  Duplicata { Volume {57,59,61,62,93,124}; }
}
Symmetry {0, 0, 1, 0} {
  Duplicata { Volume {57,59,61,62,93,124,141,172,203,234,265,296}; }
}
Physical Volume("Volume") = {57,59,61,62,93,124,141,172,203,234,265,296,654,623,592,561,530,499,468,437,406,375,344,313};

// Pour generer le maillage : gmsh -3 -format med -o sphere.med sphere-reglee.geo


p1=newp; Point(p1)={r/3,0,0,1.};
p2=newp; Point(p2)={0,r/3,0,1.};
p3=newp; Point(p3)={r/3,r/3,0,1.};
Line(671) = {1, 1705};
Line(672) = {1705, 1706};
Line(673) = {1706, 1704};
Line(674) = {1704, 1};
Transfinite Line {673, 674, 671, 672}     = p Using Progression 1;

Line Loop(675) = {673, 674, 671, 672};
Ruled Surface(676) = {675};
Transfinite Surface {676};
Recombine Surface {676};
Extrude {0, 0, -r/3} {
  Surface{676};Layers{p-1}; Recombine;
}
Transfinite Surface {685,697};
Recombine Surface {685,697};

Line(699) = {1716, 775};
Line(700) = {1712, 780};
Line(701) = {1707, 695};
Line(702) = {1708, 657};
Line(703) = {1705, 4};
Line(704) = {1706, 8};
Line(705) = {1704, 2};
Transfinite Line {699,700,701,702,703,704,705}     = p Using Progression 1;

Line Loop(706) = {703, 384, -699, -692};
Ruled Surface(707) = {706};
Line Loop(708) = {699, 353, -700, 680};
Ruled Surface(709) = {708};
Line Loop(710) = {700, 358, -702, 679};
Ruled Surface(711) = {710};
Line Loop(712) = {702, -323, -705, 684};
Ruled Surface(713) = {712};
Line Loop(714) = {12, -705, -673, 704};
Ruled Surface(715) = {714};
Line Loop(716) = {11, -704, -672, 703};
Ruled Surface(717) = {716};
Line Loop(718) = {704, -331, -701, -683};
Ruled Surface(719) = {718};
Line Loop(720) = {678, 702, 330, -701};
Ruled Surface(721) = {720};
Line Loop(722) = {701, 356, -699, 681};
Plane Surface(723) = {722};
Transfinite Surface {707,709,711,713,715,717,719,721,723};
Recombine Surface {707,709,711,713,715,717,719,721,723};


Surface Loop(724) = {717, 707, 719, 391, 723, 697};
Volume(725) = {724};
Surface Loop(726) = {715, 713, 329, 719, 721, 685};
Volume(727) = {726};
Surface Loop(728) = {711, 709, 355, 723, 721, 698};
Volume(729) = {728};
Transfinite Volume {725,727,729};
Recombine Volume {725,727,729};

Symmetry {0, 1, 0, 0} {
  Duplicata { Volume {655,725,727,729}; }
}
