// maillage d'un cube et du reseau de fibres interieur
lc = 0.01 ;
r = 0.05;
n = 4;
R = 0.1;
C = 0.25;
H = C-R;
// le rayon de la sphere
RS =  Sqrt(R*R+r*r);
rs = RS/Sqrt(3);

Point(100) = {0., 0., 0., lc};

// points x = R 
Point(1) = {R, 0, 0, lc};
Point(2) = {R, r, 0, lc};
Point(3) = {R, 0, r, lc};

// y = R
Point(4) = {0, R, 0, lc};
Point(5) = {0, R, r, lc};
Point(6) = {r, R, 0, lc};

// z = R
Point(7) = {0, 0, R, lc};
Point(8) = {r, 0, R, lc};
Point(9) = {0, r, R, lc};


// autres points du cube
Point(10) = {C, 0, 0, lc};
Point(11) = {C, C, 0, lc};
Point(12) = {0, C, 0, lc};
Point(13) = {C, 0, C, lc};
Point(14) = {C, C, C, lc};
Point(15) = {0, C, C, lc};
Point(16) = {0, 0, C, lc};

// le point bizarre
Point(101) = {rs, rs, rs, lc};


// les cercles des cylindres
Circle(23) = {2, 1, 3};
Circle(56) = {5, 4, 6};
Circle(89) = {8, 7, 9};

// les cercles de la sphere
Circle(83) = {8, 100, 3};
Circle(26) = {2, 100, 6};
Circle(59) = {5, 100, 9};

Circle(1018) = {101, 100, 8};
Circle(6101) = {6, 100, 101};
Circle(68) = {6, 100, 8};

// relions 14, le point oppose
Line(1415) = {14, 15};
Line(1411) = {14, 11};
Line(1413) = {14, 13};

// Les liens entre les points qui manquent, bases des cylindres
Line(31) = {3, 1};
Line(12) = {1, 2};

Line Loop(11) = {12, 23, 31};
Plane Surface(11) = {11};

out11[] = Extrude{H,0,0}{Surface{11}; };

Line(45) = {4, 5};
Line(64) = {6, 4};

Line Loop(44) = {45, 56, 64};
Plane Surface(44) = {44};

out44[] = Extrude{0,H,0}{ Surface{44}; };

Line(97) = {9, 7};
Line(78) = {7, 8};

Line Loop(77) = {89, 97, 78};
Plane Surface(77) = {77};

out77[] = Extrude{0,0,H}{Surface{77};};

// il nous faut definir les surfaces de la boule
Line Loop(8) = {83, -23, 26, 68};
Ruled Surface(88) = {8};

Line Loop(9) = {-89, -68, -56, 59};
Ruled Surface(99) = {9};

// les lignes complementaires pour les line loop
Line(211) = {2, 11};
Line(915) = {9, 15};
Line(313) = {3, 13};
Line(11514) = {115, 14};
Line(10814) = {108, 14};
Line(11814) = {118, 14};
Line(11014) = {110, 14};
Line(813) = {8, 13};
Line(515) = {5, 15};
Line(611) = {6, 11};
Line(11614) = {116, 14};
Line(10314) = {103, 14};
Line(1007) = {100, 7};
Line(1001) = {100, 1};
Line(1004) = {100, 4};
Line(11015) = {110, 15};
Line(11511) = {115, 11};
Line(11815) = {118, 15};
Line(10311) = {103, 11};
Line(10813) = {108, 13};
Line(11613) = {116, 13};
Line(1005) = {100, 5};
Line(1006) = {100, 6};
Line(1003) = {100, 3};
Line(1008) = {100, 8};

// maintenant les line loop
Line Loop(2000) = {-59, -1005, 1007, -97};
Line Loop(2001) = { 1005, -45, -1004};
Line Loop(2002) = {-64, -1006, 1004};
Line Loop(2003) = {-26, -12, -1001, 1006};
Line Loop(2004) = {-1008, 1003, -83};
Line Loop(2005) = {-1003, 1001, -31};
Line Loop(2006) = {1008, -78, -1007};

Plane Surface(2000) = {2000};
Plane Surface(2001) = {2001};
Plane Surface(2002) = {2002};
Plane Surface(2003) = {2003};
Plane Surface(2004) = {2004};
Plane Surface(2005) = {2005};
Plane Surface(2006) = {2006};

Line Loop(2007) = {-6141, 813, -11613};
Line Loop(2008) = {-813, 83, 313};
Line Loop(2009) = {-313, 6112, 10813};

Plane Surface(2007) = {2007};
Plane Surface(2008) = {2008};
Plane Surface(2009) = {2009};

Line Loop(2010) = {-6125, 515, -11015};
Line Loop(2011) = {-515, 59, 915};

Plane Surface(2010) = {2010};
Plane Surface(2011) = {2011};

Line Loop(2012) = {-915, 6142, 11815};

Plane Surface(2012) =  {2012};

Line Loop(2013) = {1415, -11815, 11814};
Plane Surface(2013) = {2013};

Line Loop(2014) = {-11814, -6137, 11614};
Plane Surface(2014) = {2014};

Line Loop(2015) = {-11614, 11613, -1413};
Plane Surface(2015) = {2015};

Line Loop(2016) = {-611, 6129, 11511};
Plane Surface(2016) = {2016};

Line Loop(2017) = {-211, 26, 611};
Plane Surface(2017) = {2017};

Line Loop(2018) = {-10311, -6108, 211};
Plane Surface(2018) = {2018};

Line Loop(2019) = {-11014, 11015, -1415};
Plane Surface(2019) = {2019};

Line Loop(2020) = {-11514, -6121, 11014};
Plane Surface(2020) = {2020};

Line Loop(2021) = {-11511, 11514, 1411};
Plane Surface(2021) = {2021};

Line Loop(2022) = {-10314, 10311, -1411};
Plane Surface(2022) = {2022};

Line Loop(2023) = {-10814, -6104, 10314};
Plane Surface(2023) = {2023};

Line Loop(2024) = {10814, 1413, -10813};
Plane Surface(2024) = {2024};

// on detruit d'abord les volumes crees par extrusion
Delete{ Volume{1, 2, 3}; }
// on créé les volumes
//Surface Loop(1) = {6118, 6109, 6117, 6113, -11};
//Surface Loop(2) = {6135, 6134, 6130, 6126, -44};
//Surface Loop(3) = {6152, 6151, 6147, 6143, -77};
//Surface Loop(4) = {2000, 2001, 2002, 2003, 2004, 2005, 2006,  88, 99, 77, 44, 11};
//Surface Loop(1) = {6118, 6109, 6117, 6113, 6135, 6134, 6130, 6126, 6152, 6151, 6147, 6143, 2000, 2001, 2002, 2003, 2004, 2005, 2006,  88, 99};

//Volume(1) = {1};
//Volume(2) = {2};
//Volume(3) = {3};
//Volume(4) = {4};

//Physical Volume(1) = {1, 2, 3, 4};

//Surface Loop(5) = {2013, 2014, 2015, 2024, 2023, 2022, 2016, 2017, 2018, 2010, 2011, 2012, 2019, 2020, 2021, 2007, 2008, 2009, -99, -88, -6130, -6143, -6113};

//Volume(5) = {5};

//Physical Volume(5) = {5};

Surface Loop(11816) = {6135, 6126, 6134, 6130, 44};
Volume(11817) = {11816};
Surface Loop(11818) = {44, 99, 88, 77, 2000, 2001, 2002, 2003, 2005, 2004, 2006, 11};
Volume(11819) = {11818};
Surface Loop(11820) = {6113, 6109, 6118, 6117, 11};
Volume(11821) = {11820};
Surface Loop(11822) = {6147, 6151, 6152, 6143, 77};
Volume(11823) = {11822};
