// maillage d'un huitieme du cube final cube et du reseau de fibres interieur
// on fait toujours la meme methode, mais les dimensions seront les bonnes
// parametre de finesse du maillage, plus c'est petit plus c'est fin
lc = 0.02 ;
// rayon du cylindre
r = 0.1;
n = 4;
R = 0.2;
// cote du cube que l'on construit, huitieme du cube final
// cote cube final = 2*C donc
C = 0.5;
// longueur des cylindres
H = C-R;
// le rayon de la sphere
RS =  Sqrt(R*R+r*r);
// pour le point supplementaire, de coordonnes (rs, rs, rs) et appartenant a la sphere
rs = RS/Sqrt(3);


// point central dans le cube final
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 points additionnels pour rendre le maillage plus regulier
Point(17) = {C, r/Sqrt(2), r/Sqrt(2), lc};
Point(18) = {r/Sqrt(2), C, r/Sqrt(2), lc};
Point(19) = {r/Sqrt(2), r/Sqrt(2), C, lc};

Point(20) = {RS/Sqrt(2), RS/Sqrt(2), 0, lc};
Point(21) = {RS/Sqrt(2), 0, RS/Sqrt(2), lc};
Point(22) = {0, RS/Sqrt(2), RS/Sqrt(2), 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};

Circle(3101) = {3, 100, 101};
Circle(1015) = {101, 100, 5};
Circle(35) = {3, 100, 5};

Circle(9101) = {9, 100, 101};
Circle(1012) = {101, 100, 2};
Circle(92) = {9, 100, 2};

// 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) = {59, 9101, 1015};
Ruled Surface(88) = {8};

Line Loop(9) = {-89, -1018, -9101};
Ruled Surface(99) = {9};

Line Loop(10) = {83, 3101, 1018};
Ruled Surface(1010) = {10};

Line Loop(12) = {-23, -1012, -3101};
Ruled Surface(1212) = {12};

Line Loop(13) = {26, 6101, 1012};
Ruled Surface(1313) = {13};

Line Loop(14) = {-56, -1015, -6101};
Ruled Surface(1414) = {14};

// les lignes complementaires pour les line loop
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};

// les lignes transverse jusqua 14
Line(1714) = {17, 14};
Line(1814) = {18, 14};
Line(1914) = {19, 14};

// autres lignes, des points complementaires au bon sommet
Line(2113) = {21, 13};
Line(2011) = {20, 11};
Line(2215) = {22, 15};

// 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};

// les huitiemes de cercle au bout des cylindres
Circle(11819) = {118, 16, 19};
Circle(19116) = {19, 16, 116};

Circle(10817) = {108, 10, 17};
Circle(17103) = {17, 10, 103};

Circle(11518) = {115, 12, 18};
Circle(18110) = {18, 12, 110};

// les huitiemes de cercle sur la big sphere
Circle(229) = {22, 100, 9};
Circle(522) = {5, 100, 22};

Circle(821) = {8, 100, 21};
Circle(213) = {21, 100, 3};

Circle(220) = {2, 100, 20};
Circle(206) = {20, 100, 6};


// on y va pour les line loop
Line Loop(2007) = {1415, -11815, 11819, 1914};
Line Loop(2008) = {-1914, 19116, 11613, -1413};

Line Loop(2009) = {1413, -10813, 10817, 1714};
Line Loop(2010) = {-1411, -1714, 17103, 10311};

Line Loop(2011) = {11015, -1415, -1814, 18110};
Line Loop(2012) = {1814, 1411, -11511, 11518};

Line Loop(2013) = {9142, 11815, -2215, 229};
Line Loop(2014) = {522, 2215, -11015, -9125};


Line Loop(2015) = {9112, 10813, -2113, 213};
Line Loop(2016) = {2113, -11613, -9141, 821};

Line Loop(2017) = {-9108, 220, 2011, -10311};
Line Loop(2018) = {9129, 11511, -2011, 206};

Plane Surface(2007) = {2007};
Plane Surface(2008) = {2008};
Plane Surface(2009) = {2009};
Plane Surface(2010) = {2010};
Plane Surface(2011) = {2011};
Plane Surface(2012) = {2012};
Plane Surface(2013) = {2013};
Plane Surface(2014) = {2014};
Plane Surface(2015) = {2015};
Plane Surface(2016) = {2016};
Plane Surface(2017) = {2017};
Plane Surface(2018) = {2018};


// on detruit d'abord les volumes crees par extrusion
Delete{ Volume{1, 2, 3}; }
// on créé les volumes
Surface Loop(1) = {9118, 9109, 9117, 9113, -11};
Surface Loop(2) = {9135, 9134, 9130, 9126, -44};
Surface Loop(3) = {9152, 9151, 9147, 9143, -77};
Surface Loop(4) = {2000, 2001, 2002, 2003, 2004, 2005, 2006,  88, 99, 1010, 1212, 1313, 1414, 77, 44, 11};

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

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

Surface Loop(5) = {2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, -1414, -1313, -1212, -1010, -99, -88, -9130, -9143, -9113};

Volume(5) = {5};

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