// Fichier: disques3D.geo

/*
  Conventions de langage:
    arrière == vers Z négatifs
	avant   == vers Z positfs

*/

//Mesh.Algorithm = 1;

Include "disques3D-dat.pro";


/// Les griffes -------------------------------------------------------
//p_gr = point griffes
//l_gr = ligne griffes (= arêtes)
//ll_gr = line loop griffes
//s_gr = surface griffes

//face arrière du disque 6
p_gr[]+=newp; Point(newp) = { 0,               0,               -e1-e2-e1, lc}; // 0
p_gr[]+=newp; Point(newp) = { r3*Sin[angle/2], r3*Cos[angle/2], -e1-e2-e1, lc_gr}; // 1
p_gr[]+=newp; Point(newp) = {-r3*Sin[angle/2], r3*Cos[angle/2], -e1-e2-e1, lc_gr}; // 2

l_gr[]+=newl; Line(newl)   = {p_gr[0], p_gr[1]};         // 0
l_gr[]+=newl; Circle(newl) = {p_gr[1], p_gr[0], p_gr[2]}; // 1
l_gr[]+=newl; Line(newl)   = {p_gr[2], p_gr[0]};         // 2

ll_gr[]+=newll; Line Loop(newll) = {l_gr[0], l_gr[1], l_gr[2]}; // 0

s_gr[]+=news; Plane Surface(news) = {ll_gr[0]}; // 0

//face avant disque 6
p_gr[]+=newp; Point(newp) = { 0,               0,               -e1-e2, lc}; // 3
p_gr[]+=newp; Point(newp) = { r1*Sin[angle/2], r1*Cos[angle/2], -e1-e2, lc_gr}; // 4
p_gr[]+=newp; Point(newp) = { r3*Sin[angle/2], r3*Cos[angle/2], -e1-e2, lc_gr}; // 5
p_gr[]+=newp; Point(newp) = {-r3*Sin[angle/2], r3*Cos[angle/2], -e1-e2, lc_gr}; // 6
p_gr[]+=newp; Point(newp) = {-r1*Sin[angle/2], r1*Cos[angle/2], -e1-e2, lc_gr}; // 7

l_gr[]+=newl; Line(newl)   = {p_gr[4], p_gr[5]};         // 3
l_gr[]+=newl; Circle(newl) = {p_gr[5], p_gr[3], p_gr[6]}; // 4
l_gr[]+=newl; Line(newl)   = {p_gr[6], p_gr[7]};         // 5
l_gr[]+=newl; Circle(newl) = {p_gr[7], p_gr[3], p_gr[4]}; // 6

ll_gr[]+=newll; Line Loop(newll) = {l_gr[3], l_gr[4], l_gr[5], l_gr[6]}; // 1

s_gr[]+=news;  Plane Surface(news) = {ll_gr[1]}; // 1

//face supérieure disque 6
l_gr[]+=newl; Line(newl)   = {p_gr[5], p_gr[1]}; // 7
l_gr[]+=newl; Line(newl)   = {p_gr[2], p_gr[6]}; // 8

ll_gr[]+=newll; Line Loop(newll) = {l_gr[7], l_gr[1], l_gr[8], -l_gr[4]}; // 2

s_gr[]+=news; Ruled Surface(news) = {ll_gr[2]};  // 2

//face arrière disque 4
p_gr[]+=newp; Point(newp) = { 0,               0,               -e1, lc}; // 8
p_gr[]+=newp; Point(newp) = { r1*Sin[angle/2], r1*Cos[angle/2], -e1, lc_gr}; // 9
p_gr[]+=newp; Point(newp) = { r3*Sin[angle/2], r3*Cos[angle/2], -e1, lc_gr}; // 10
p_gr[]+=newp; Point(newp) = {-r3*Sin[angle/2], r3*Cos[angle/2], -e1, lc_gr}; // 11
p_gr[]+=newp; Point(newp) = {-r1*Sin[angle/2], r1*Cos[angle/2], -e1, lc_gr}; // 12

l_gr[]+=newl; Line(newl)   = {p_gr[9],  p_gr[10]};         // 9
l_gr[]+=newl; Circle(newl) = {p_gr[10], p_gr[8], p_gr[11]}; // 10
l_gr[]+=newl; Line(newl)   = {p_gr[11], p_gr[12]};         // 11
l_gr[]+=newl; Circle(newl) = {p_gr[12], p_gr[8], p_gr[9]};  // 12

ll_gr[]+=newll; Line Loop(newll) = {l_gr[9], l_gr[10], l_gr[11], l_gr[12]}; // 3

s_gr[]+=news; Ruled Surface(news) = {ll_gr[3]};  // 3

//face supérieure disque 5
l_gr[]+=newl; Line(newl)   = {p_gr[9], p_gr[4]};  // 13
l_gr[]+=newl; Line(newl)   = {p_gr[7], p_gr[12]}; // 14

ll_gr[]+=newll; Line Loop(newll) = {l_gr[13], -l_gr[6], l_gr[14], l_gr[12]}; // 4

s_gr[]+=news; Ruled Surface(news) = {ll_gr[4]};  // 4

//face avant disque 3
p_gr[]+=newp; Point(newp) = { 0,               0,                e1, lc}; // 13
p_gr[]+=newp; Point(newp) = { r1*Sin[angle/2], r1*Cos[angle/2],  e1, lc_gr}; // 14
p_gr[]+=newp; Point(newp) = { r3*Sin[angle/2], r3*Cos[angle/2],  e1, lc_gr}; // 15
p_gr[]+=newp; Point(newp) = {-r3*Sin[angle/2], r3*Cos[angle/2],  e1, lc_gr}; // 16
p_gr[]+=newp; Point(newp) = {-r1*Sin[angle/2], r1*Cos[angle/2],  e1, lc_gr}; // 17

l_gr[]+=newl; Line(newl)   = {p_gr[14], p_gr[15]};          // 15
l_gr[]+=newl; Circle(newl) = {p_gr[15], p_gr[13], p_gr[16]}; // 16
l_gr[]+=newl; Line(newl)   = {p_gr[16], p_gr[17]};          // 17
l_gr[]+=newl; Circle(newl) = {p_gr[17], p_gr[13], p_gr[14]}; // 18

ll_gr[]+=newll; Line Loop(newll) = {l_gr[15], l_gr[16], l_gr[17], l_gr[18]}; // 5

s_gr[]+=news; Ruled Surface(news) = {ll_gr[5]};  // 5

//surface supérieure disques 3 et 4
l_gr[]+=newl; Line(newl)   = {p_gr[15], p_gr[10]}; // 19
l_gr[]+=newl; Line(newl)   = {p_gr[11], p_gr[16]}; // 20

ll_gr[]+=newll; Line Loop(newll) = {l_gr[19], l_gr[10], l_gr[20], -l_gr[16]}; // 6

s_gr[]+=news; Ruled Surface(news) = {ll_gr[6]};  // 6

//face arrière disque 1
p_gr[]+=newp; Point(newp) = { 0,               0,                e1+e2,    lc}; // 18
p_gr[]+=newp; Point(newp) = { r1*Sin[angle/2], r1*Cos[angle/2],  e1+e2,    lc_gr}; // 19
p_gr[]+=newp; Point(newp) = { r3*Sin[angle/2], r3*Cos[angle/2],  e1+e2,    lc_gr}; // 20
p_gr[]+=newp; Point(newp) = {-r3*Sin[angle/2], r3*Cos[angle/2],  e1+e2,    lc_gr}; // 21
p_gr[]+=newp; Point(newp) = {-r1*Sin[angle/2], r1*Cos[angle/2],  e1+e2,    lc_gr}; // 22

l_gr[]+=newl; Line(newl)   = {p_gr[19], p_gr[20]};          // 21
l_gr[]+=newl; Circle(newl) = {p_gr[20], p_gr[18], p_gr[21]}; // 22
l_gr[]+=newl; Line(newl)   = {p_gr[21], p_gr[22]};          // 23
l_gr[]+=newl; Circle(newl) = {p_gr[22], p_gr[18], p_gr[19]}; // 24

ll_gr[]+=newll; Line Loop(newll) = {l_gr[21], l_gr[22], l_gr[23], l_gr[24]}; // 7

s_gr[]+=news; Ruled Surface(news) = {ll_gr[7]};  // 7

//face supérieure disque 2
l_gr[]+=newl; Line(newl)   = {p_gr[19], p_gr[14]}; // 25
l_gr[]+=newl; Line(newl)   = {p_gr[17], p_gr[22]}; // 26

ll_gr[]+=newll; Line Loop(newll) = {l_gr[25], -l_gr[18], l_gr[26], l_gr[24]}; // 8

s_gr[]+=news; Ruled Surface(news) = {ll_gr[8]};  // 8

//face avant disque 1
p_gr[]+=newp; Point(newp) = { 0,               0,                e1+e2+e1, lc}; // 23
p_gr[]+=newp; Point(newp) = { r3*Sin[angle/2], r3*Cos[angle/2],  e1+e2+e1, lc_gr}; // 24
p_gr[]+=newp; Point(newp) = {-r3*Sin[angle/2], r3*Cos[angle/2],  e1+e2+e1, lc_gr}; // 25

l_gr[]+=newl; Line(newl)   = {p_gr[23], p_gr[24]};          // 27
l_gr[]+=newl; Circle(newl) = {p_gr[24], p_gr[23], p_gr[25]}; // 28
l_gr[]+=newl; Line(newl)   = {p_gr[25], p_gr[23]};          // 29

ll_gr[]+=newll; Line Loop(newll) = {l_gr[27], l_gr[28], l_gr[29]}; // 9

s_gr[]+=news; Plane Surface(news) = {ll_gr[9]}; // 9

//face supérieure disque 1
l_gr[]+=newl; Line(newl)   = {p_gr[24], p_gr[20]}; // 30
l_gr[]+=newl; Line(newl)   = {p_gr[21], p_gr[25]}; // 31

ll_gr[]+=newll; Line Loop(newll) = {l_gr[30], l_gr[22], l_gr[31], -l_gr[28]}; // 10

s_gr[]+=news; Ruled Surface(news) = {ll_gr[10]};  // 10

//face droite
l_gr[]+=newl; Line(newl)   = {p_gr[23], p_gr[0]}; // 32

ll_gr[]+=newll;
Line Loop(newll) = {
  l_gr[0], -l_gr[7], -l_gr[3], -l_gr[13], l_gr[9], -l_gr[19], -l_gr[15], -l_gr[25], l_gr[21],
  -l_gr[30], -l_gr[27], l_gr[32]
}; // 11

s_gr[]+=news; Plane Surface(news) = {ll_gr[11]};  // 11

//face gauche
ll_gr[]+=newll;
Line Loop(newll) = {
  -l_gr[2], l_gr[8], l_gr[5], l_gr[14], -l_gr[11], l_gr[20], l_gr[17], l_gr[26], -l_gr[23],
  l_gr[31], l_gr[29], l_gr[32]
}; // 12

s_gr[]+=news; Plane Surface(news) = {ll_gr[12]};  // 12

//volume
//sl_gr = surface loop griffes
sl_gr=newsl;
Surface Loop(newsl) = { -s_gr[0], s_gr[1], s_gr[2], -s_gr[3], s_gr[4],
  s_gr[5], s_gr[6], -s_gr[7], s_gr[8],s_gr[9], s_gr[10], s_gr[11],
  -s_gr[12]
};

v_gr=newv; Volume(newv) = {sl_gr};


/// l'inducteur 2 (le plus en arrière) --------------------------------
//p_ind2 = point arrière inducteur 2 (back)
p_ind2[]+=newp; Point(newp) = { 0,                      0,                      -e1-e2+isol, lc}; // 1
p_ind2[]+=newp; Point(newp) = { (r1+isol)*Sin[angle/2], (r1+isol)*Cos[angle/2], -e1-e2+isol, lc_ind}; // 2
p_ind2[]+=newp; Point(newp) = { (r2-isol)*Sin[angle/2], (r2-isol)*Cos[angle/2], -e1-e2+isol, lc_ind}; // 3
p_ind2[]+=newp; Point(newp) = {-(r2-isol)*Sin[angle/2], (r2-isol)*Cos[angle/2], -e1-e2+isol, lc_ind}; // 4
p_ind2[]+=newp; Point(newp) = {-(r1+isol)*Sin[angle/2], (r1+isol)*Cos[angle/2], -e1-e2+isol, lc_ind}; // 5

//l_ind2 = ligne arrière inducteur 2
l_ind2[]+=newl; Line(newl)   = {p_ind2[1], p_ind2[2]};             // right
l_ind2[]+=newl; Circle(newl) = {p_ind2[2], p_ind2[0], p_ind2[3]};  // top
l_ind2[]+=newl; Line(newl)   = {p_ind2[3], p_ind2[4]};             // left
l_ind2[]+=newl; Circle(newl) = {p_ind2[4], p_ind2[0], p_ind2[1]};  // bottom

//ll_ind2 = line loop arrière inducteur 2
ll_ind2=newll; Line Loop(newll) = {l_ind2[]};

//s_ind2 = surface inducteur 2
s_ind2[]=news; Plane Surface(news) = {ll_ind2}; // 0, back

//v_ind2 = volume inducteur 2
out[] = Extrude {0, 0, e2-2*isol} { Surface{s_ind2[0]}; };
		// 0 --> front face
		// 1 --> volume
		// 2 --> right face
		// 3 --> top face
		// 4 --> left face
		// 5 --> bottom face
v_ind2=out[1];
s_right_ind2=out[2];
ll_right_ind2[] = Boundary{ Surface{s_right_ind2}; };
s_left_ind2=out[4];
ll_left_ind2[] = Boundary{ Surface{s_left_ind2}; };
s_ind2[] += {out[0],out[2],out[3],out[4],out[5]};
				// 1, front
				// 2, right
				// 3, top
				// 4, left
				// 5, bottom
//sl_ind2 = surface loop inducteur 2
sl_ind2=newsl; Surface Loop(newsl) = {s_ind2[]};

/// air slot 2 (back) -------------------------------------------------
// back, front, bottom
s_asl2[] = {s_gr[1], s_gr[3], s_gr[4]}; // 0, back
									    // 1, front
										// 2, bottom

l_asl2[]+=newl; Line(newl) = {p_gr[5], p_gr[10]};  // 0
l_asl2[]+=newl; Line(newl) = {p_gr[6], p_gr[11]};  // 1

// right face
ll_asl2[]+=newll; Line Loop(newll) = {l_gr[3], l_asl2[0], -l_gr[9], l_gr[13], ll_right_ind2[]}; // 0
s_asl2[]+=news; Plane Surface(news) = {ll_asl2[0]};  // 3, right
s_right_ind2=s_asl2[3];

// left face
ll_asl2[]+=newll; Line Loop(newll) = {-l_gr[5], l_asl2[1], l_gr[11], -l_gr[14], ll_left_ind2[]}; // 1
s_asl2[]+=news; Plane Surface(news) = {-ll_asl2[1]};  // 4, left
s_left_asl2=s_asl2[4];

// top
ll_asl2[]+=newll; Line Loop(newll) = {-l_asl2[0], l_gr[4], l_asl2[1], -l_gr[10]}; // 2
s_asl2[]+=news; Ruled Surface(news) = {ll_asl2[2]};  // 5, top

sl_asl2=newsl;
Surface Loop(newsl) = {
  -s_asl2[0], s_asl2[1], -s_asl2[2], s_asl2[3], -s_asl2[4], s_asl2[5],
  s_ind2[0], s_ind2[1], s_ind2[3], s_ind2[5]
  };
v_asl2=newv; Volume(newv) = {sl_asl2};

s_slt2 = {-s_asl2[0], s_asl2[1], -s_asl2[2], s_asl2[5], s_asl2[3], -s_asl2[4],
  s_ind2[2], s_ind2[4]};
sl_slt2=newsl;
Surface Loop(newsl) = {s_slt2[]};

/// L'inducteur 1 -----------------------------------------------------
// (le plus en avant, identique à l'inducteur 2)
//v_ind1 = volume inducteur 1
/*
   En utilisant Transform/Duplicata, il faut faire les choses dans l'ordre.
   D'abord les surfaces intéressantes du volume à dupliquer.
   Ensuite le volume.
   Car en duplicant le volume, Gmsh duplique aussi les surface latérales et
   SUPPRIME les surfaces identiques à celles qui existent déjà.
   C'est le principe du premier arrivé, premier servi.
*/
out[] = Translate {0, 0, e2+2*e1} { Duplicata{ Surface{s_right_ind2,s_left_ind2};} };
s_right_ind1=out[0];
s_left_ind1=out[1];
v_ind1 = Translate {0, 0, e2+2*e1} { Duplicata{ Volume{v_ind2};} };
sl_ind1=newsl; Surface Loop(newsl) = { Boundary{ Volume{ v_ind1 }; } };


/// Le tambour --------------------------------------------------------
//p_tb = point tambour
//l_tb = ligne arrière tambour
//ll_tb_b = line loop arrière tambour
//s_tb_bz = surface arrière tambour
//ll_tb_f = line loop avant tambour
//s_tb_fz = surface avant tambour
//slbtb = surface loop tambour
//v_tb = volume tambour
p_tb[]+=newp; Point(newp) = { 0,                      0,                      -e1-e2-e1-e3, lc}; // 0
p_tb[]+=newp; Point(newp) = { (r4+isol)*Sin[angle/2], (r4+isol)*Cos[angle/2], -e1-e2-e1-e3, lc_tb}; // 1
p_tb[]+=newp; Point(newp) = { (r5-isol)*Sin[angle/2], (r5-isol)*Cos[angle/2], -e1-e2-e1-e3, lc}; // 2
p_tb[]+=newp; Point(newp) = {-(r5-isol)*Sin[angle/2], (r5-isol)*Cos[angle/2], -e1-e2-e1-e3, lc}; // 3
p_tb[]+=newp; Point(newp) = {-(r4+isol)*Sin[angle/2], (r4+isol)*Cos[angle/2], -e1-e2-e1-e3, lc_tb}; // 4

l_tb[]+=newl; Line(newl)   = {p_tb[1], p_tb[2]};          // right
l_tb[]+=newl; Circle(newl) = {p_tb[2], p_tb[0], p_tb[3]};  // top
l_tb[]+=newl; Line(newl)   = {p_tb[3], p_tb[4]};          // left
l_tb[]+=newl; Circle(newl) = {p_tb[4], p_tb[0], p_tb[1]};  // bottom

ll_tb_b=newll; Line Loop(newll) = {l_tb[]};

s_tb_bz=news; Plane Surface(news) = {ll_tb_b}; // back

//s_tb[] = surface lateral tambour
out[] = Extrude {0, 0, e3} { Line{l_tb[]}; };
s_tb[] = {out[1], out[5], out[9], out[13]}; // right, top, left, bottom
mylines = {out[0], out[4], out[8], out[12]};

out[] = Extrude {0, 0, 2*(e1+e2+e1)} { Line{mylines[]}; };
s_tb[] += {out[1], out[5], out[9], out[13]};
surftgap = out[13]; // surface top airgap
mylines = {out[0], out[4], out[8], out[12]};

out[] = Extrude {0, 0, e3} { Line{mylines[]}; };
s_tb[] += {out[1], out[5], out[9], out[13]};
mylines = {out[0], out[4], out[8], out[12]};

ll_tb_f=newll; Line Loop(newll) = {mylines[]};

s_tb_fz=news; Plane Surface(news) = {ll_tb_f};  // front

st_tb=newsl; Surface Loop(newsl) = { s_tb_bz, s_tb[], s_tb_fz };

v_tb=newv; Volume(newv) = {st_tb};

/// L'air -------------------------------------------------------------
//p_air = point air
p_air[]+=newp; Point(newp) = {axl, ayb, azb, lc_air}; // 0
p_air[]+=newp; Point(newp) = {axl, ayt, azb, lc_air}; // 1
p_air[]+=newp; Point(newp) = {axr, ayt, azb, lc_air}; // 2
p_air[]+=newp; Point(newp) = {axr, ayb, azb, lc_air}; // 3
p_air[]+=newp; Point(newp) = {axl, ayb, azf, lc_air}; // 4
p_air[]+=newp; Point(newp) = {axl, ayt, azf, lc_air}; // 5
p_air[]+=newp; Point(newp) = {axr, ayt, azf, lc_air}; // 6
p_air[]+=newp; Point(newp) = {axr, ayb, azf, lc_air}; // 7

//l_air = ligne air
l_air[]+=newl; Line(newl)   = {p_air[0], p_air[1]}; // 0
l_air[]+=newl; Line(newl)   = {p_air[1], p_air[2]}; // 1
l_air[]+=newl; Line(newl)   = {p_air[2], p_air[3]}; // 2
l_air[]+=newl; Line(newl)   = {p_air[3], p_air[0]}; // 3
l_air[]+=newl; Line(newl)   = {p_air[4], p_air[5]}; // 4
l_air[]+=newl; Line(newl)   = {p_air[5], p_air[6]}; // 5
l_air[]+=newl; Line(newl)   = {p_air[6], p_air[7]}; // 6
l_air[]+=newl; Line(newl)   = {p_air[7], p_air[4]}; // 7
l_air[]+=newl; Line(newl)   = {p_air[1], p_air[5]}; // 8
l_air[]+=newl; Line(newl)   = {p_air[2], p_air[6]}; // 9
l_air[]+=newl; Line(newl)   = {p_air[7], p_air[3]}; // 10
l_air[]+=newl; Line(newl)   = {p_air[4], p_air[0]}; // 11

//ll_air = line loop air
ll_air[]+=newll; Line Loop(newll) = { l_air[0],   l_air[1],  l_air[2],  l_air[3]};  // 0, arrière
ll_air[]+=newll; Line Loop(newll) = { l_air[4],   l_air[5],  l_air[6],  l_air[7]};  // 1, avant
ll_air[]+=newll; Line Loop(newll) = { l_air[0],   l_air[8], -l_air[4],  l_air[11]}; // 2, droite
ll_air[]+=newll; Line Loop(newll) = {-l_air[2],   l_air[9],  l_air[6],  l_air[10]}; // 3, gauche
ll_air[]+=newll; Line Loop(newll) = { l_air[11], -l_air[3], -l_air[10], l_air[7]};  // 4, dessous
ll_air[]+=newll; Line Loop(newll) = {-l_air[8],   l_air[1],  l_air[9], -l_air[5]};  // 5, dessus

For ki In {0:5}
  s_air[]+=news; Plane Surface(news) = {ll_air[ki]};  // 0, arrière
EndFor

//sl_air = surface loop air
sl_air=newsl;
Surface Loop(newsl) = { -s_air[0], s_air[1], s_air[2], -s_air[3], -s_air[4],
  s_air[5]
};

//v_air = volume air
//v_air=newv; Volume(newv) = {sl_air, sl_gr, st_tb, sl_ind1, sl_ind2};
//v_air=newv; Volume(newv) = {sl_air, sl_gr, st_tb};

allvol[] = Volume '*';

surf[] = CombinedBoundary{ Volume{allvol[]}; };
Surface Loop(newsl) = surf[] ;
v_air=newv; Volume(newv) = {sl_air, newsl-1};


/*
Surface Loop(newsl) = {59, 5, 57, 15, 35, 31, 45, 41, 54, 50, 199, 185, 169, 153, 149, 157, 161, 165, 181, 197, 193, 177, 173, 189, 84, 96, 98, 94, 76};
v_air=newv; Volume(newv) = {143, 226, newsl-1};
*/

/// Les entités physiques ---------------------------------------------
Physical Volume(AIR)        = v_air;
Physical Volume(GRIFFES)    = v_gr;
Physical Volume(INDUCTEUR1) = v_ind1;
Physical Volume(INDUCTEUR2) = v_ind2;
Physical Volume(TAMBOUR)    = v_tb;
Physical Volume(AIR_SLOT2)  = v_asl2;

Physical Surface(SURF_D_IND1) = s_right_ind1;
Physical Surface(SURF_G_IND1) = s_left_ind1;
Physical Surface(SURF_D_IND2) = s_right_ind2;
Physical Surface(SURF_G_IND2) = s_left_ind2;

Physical Surface(SURF_T_AIRGAP) = surftgap;

Physical Surface(SURF_D_AIRSLOT2) = s_right_ind2;
Physical Surface(SURF_AIRSLOT2)   = {s_slt2[]};

// EOF

