// 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 ;
lc_box = 4*lc ;
lc_box2 = lc_box ;
// 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_box2};

// 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_box2};
Point(11) = {C, C, 0, lc_box};
Point(12) = {0, C, 0, lc_box2};
Point(13) = {C, 0, C, lc_box};
Point(14) = {C, C, C, lc_box};
Point(15) = {0, C, C, lc_box};
Point(16) = {0, 0, C, lc_box2};

// 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}; };
vol11 = out11[1];

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}; };
vol44 = out44[1];

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};};
vol77 = out77[1];

 
// il nous faut definir les surfaces de la boule
Line Loop(8) = {59, 9101, 1015};
Ruled Surface(88) = {8};
// modif 23nov
Physical Surface(88) = {88};

Line Loop(9) = {-89, -1018, -9101};
Ruled Surface(99) = {9};
// modif 23nov
Physical Surface(99) = {99};

Line Loop(10) = {83, 3101, 1018};
Ruled Surface(1010) = {10};
// modif 23nov
Physical Surface(1010) = {1010};

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

Line Loop(13) = {26, 6101, 1012};
Ruled Surface(1313) = {13};
// modif 23nov
Physical Surface(1313) = {1313};

Line Loop(14) = {-56, -1015, -6101};
Ruled Surface(1414) = {14};
// modif 23nov
Physical Surface(1414) = {1414};


// 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 Loop(11816) = {11815, -1415, 1413, -11613, 9137};
Plane Surface(11817) = {11816};
Line Loop(11818) = {11815, -11015, -9125, 59, 9142};
Plane Surface(11819) = {11818};
Line Loop(11820) = {11613, -10813, -9112, -83, 9141};
Plane Surface(11821) = {11820};
Line Loop(11822) = {11015, -1415, 1411, -11511, -9121};
Plane Surface(11823) = {11822};
Line Loop(11824) = {11511, -10311, -9108, 26, 9129};
Plane Surface(11825) = {11824};
Line Loop(11826) = {26, 64, -1004, 1001, 12};
Plane Surface(11827) = {11826};
Line Loop(11828) = {1004, 45, 59, 97, -1007};
Plane Surface(11829) = {11828};
Line Loop(11830) = {1007, 78, 83, 31, -1001};
Plane Surface(11831) = {11830};
Line Loop(11832) = {10311, -1411, 1413, -10813, -9104};
Plane Surface(11833) = {11832};

// les surfaces dont on aura besoin dans le code freefem
// modif 23nov
Physical Surface(9130) = {9130};
Physical Surface(9113) = {9113};
Physical Surface(9118) = {9118};
Physical Surface(9143) = {9143};
Physical Surface(9135) = {9135};
Physical Surface(9152) = {9152};
Physical Surface(11833) = {11833};
Physical Surface(11823) = {11823};
Physical Surface(11817) = {11817};


Surface Loop(4) = {11829, 11827, 11831, 88, 99, 1010, 1212, 1313, 1414, 11, 44, 77};
Volume(4) = {4};

Surface Loop(5) = {11823, 11819, 11817, 11833, 11825, 11821, 9130, 9143, 9113, 88, 99, 1010, 1212, 1313, 1414};
Volume(5) = {5};

Physical Volume(1) = {vol11, vol44, vol77, 4};
Physical Volume(5) = {5};
