// Cas d'étude thèse, TFO simplifié
// 2D axisym, support de bobinage non représenté (n'influe pas en magnétodynamique)
// Les conducteurs dédoublés sont pris comme simples conducteurs séparés(on augmente le nombre d' ampères-tours donc)
// Pas de demi-enroulement considéré -> 5 au lieu de 10
// Dimensions : basées sur dossier fait à la main

// IMPORTANT : Les conducteurs, en tant que domaines physiques, doivent impérativement être numérotés dans l'ordre croissant, sans trous (pour le post-processing). L'enroulement 1 est celui le plus à droite de la fénêtre de bobinage, et on continue vers l'intérieur du TFO.

Include 'lc_cond.txt';

// Noyau en ferrite - Via GUI
lc_ferrite = 0.00025;
Point(1) = {0, 0, 0, lc_ferrite};
Point(2) = {0, 0.0067, 0, lc_ferrite};
Point(3) = {0, -0.0067, 0, lc_ferrite};
Point(4) = {0.01015, 0.0067, 0, lc_ferrite};
Point(5) = {0.01015, -0.0067, 0, lc_ferrite};
Point(6) = {0.003625, 0.0042, 0, lc_ferrite};
Point(7) = {0.003625, -0.0042, 0, lc_ferrite};
Point(8) = {0.007375, 0.0042, 0, lc_ferrite};
Point(9) = {0.007375, -0.0042, 0, lc_ferrite};
Line(1) = {4, 2};
Line(2) = {2, 3};
Line(3) = {3, 5};
Line(4) = {5, 4};
Line(5) = {8, 6};
Line(6) = {6, 7};
Line(7) = {7, 9};
Line(8) = {9, 8};
Line Loop(12) = {1, 2, 3, 4};
Line Loop(13) = {5, 6, 7, 8};
Plane Surface(14) = {12, 13}; // noyau en ferrite

// Boite d'air environnante - Via GUI
Point(10) = {0, 0.02, 0, lc_ferrite*5};
Point(11) = {0, -0.02, 0, lc_ferrite*5};
Circle(9) = {11, 1, 10};
Line(10) = {10, 2};
Line(11) = {3, 11};
Line Loop(15) = {9, 10, -1, -4, -3, 11};
Plane Surface(16) = {15}; //boite d'air entourant le noyau

//Bobines du TFO
//Enroulement 5
// 2 couches
ncond1 = 16 ;
ncond2 = 16 ;
xa=0.0044435;
ya=0.0030165;
xstep = 0.000387/2;
ystep = 0.000387/2;
p1 = newp ; Point(p1) = {xa-xstep,ya+ystep, 0, lc_cond};
p2 = newp ; Point(p2) = {xa-xstep,ya-(2*ncond1-1)*ystep, 0, lc_cond};
p3 = newp ; Point(p3) = {xa+3*xstep,ya-(2*ncond2-1)*ystep, 0, lc_cond};
p4 = newp ; Point(p4) = {xa+3*xstep,ya+ystep, 0, lc_cond};
// Enroulement 4
ncond = 8;
xa=0.0052175;
ya=0.0016125;
xstep = 0.000387/2;
ystep = 0.000387/2;
p1 = newp ; Point(p1) = {xa-xstep,ya+ystep, 0, lc_cond};
p2 = newp ; Point(p2) = {xa-xstep,ya-(2*ncond-1)*ystep, 0, lc_cond};
p3 = newp ; Point(p3) = {xa+xstep,ya-(2*ncond-1)*ystep, 0, lc_cond};
p4 = newp ; Point(p4) = {xa+xstep,ya+ystep, 0, lc_cond};
// Enroulement 3
ncond = 14;
xa=0.0055695;
ya=0.002311;
xstep = 0.000317/2;
ystep = 0.000317/2;
p1 = newp ; Point(p1) = {xa-xstep,ya+ystep, 0, lc_cond};
p2 = newp ; Point(p2) = {xa-xstep,ya-(2*ncond-1)*ystep, 0, lc_cond};
p3 = newp ; Point(p3) = {xa+xstep,ya-(2*ncond-1)*ystep, 0, lc_cond};
p4 = newp ; Point(p4) = {xa+xstep,ya+ystep, 0, lc_cond};
// Enroulement 2
ncond = 6;
xa=0.0059215;
ya=0.0012265;
xstep = 0.000387/2;
ystep = 0.000387/2;
p1 = newp ; Point(p1) = {xa-xstep,ya+ystep, 0, lc_cond};
p2 = newp ; Point(p2) = {xa-xstep,ya-(2*ncond-1)*ystep, 0, lc_cond};
p3 = newp ; Point(p3) = {xa+xstep,ya-(2*ncond-1)*ystep, 0, lc_cond};
p4 = newp ; Point(p4) = {xa+xstep,ya+ystep, 0, lc_cond};
// Enroulement 1
ncond = 14;
xa=0.0063085;
ya=0.0027735;
xstep = 0.000387/2;
ystep = 0.000387/2;
p1 = newp ; Point(p1) = {xa-xstep,ya+ystep, 0, lc_cond};
p2 = newp ; Point(p2) = {xa-xstep,ya-(2*ncond-1)*ystep, 0, lc_cond};
p3 = newp ; Point(p3) = {xa+xstep,ya-(2*ncond-1)*ystep, 0, lc_cond};
p4 = newp ; Point(p4) = {xa+xstep,ya+ystep, 0, lc_cond};

// GUI
Line(17) = {12, 13};
Line(18) = {13, 14};
Line(19) = {14, 17};
Line(20) = {17, 18};
Line(21) = {18, 21};
Line(22) = {21, 22};
Line(23) = {22, 25};
Line(24) = {25, 26};
Line(25) = {26, 29};
Line(26) = {29, 30};
Line(27) = {30, 31};
Line(28) = {31, 28};
Line(29) = {28, 27};
Line(30) = {27, 24};
Line(31) = {24, 23};
Line(32) = {23, 20};
Line(33) = {20, 19};
Line(34) = {19, 16};
Line(35) = {16, 15};
Line(36) = {15, 12};
Line(37) = {16, 17};
Line(38) = {18, 19};
Line(39) = {24, 25};
Line(40) = {26, 27};
Line Loop(41) = {36, 17, 18, 19, -37, 35};
Plane Surface(42) = {41};//win5
Line Loop(43) = {34, 37, 20, 38};
Plane Surface(44) = {43};//win4
Line Loop(45) = {32, 33, -38, 21, 22, 23, -39, 31};
Plane Surface(46) = {45};//win3
Line Loop(47) = {30, 39, 24, 40};
Plane Surface(48) = {47};//win2
Line Loop(49) = {28, 29, -40, 25, 26, 27};
Plane Surface(50) = {49};//win1
Line Loop(51) = {36, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35};
Plane Surface(52) = {13, 51};//Insulation

// Physical groups. ATTENTION: SYNTAXE DES COMMENTAIRES ULTRA IMPORTANTE, DOIT ETRE RESPECTEE RIGOUREUSEMENT
Physical Line(53) = {9, 10, 2, 11};//%%%GammaExt
Physical Surface(54) = {16};//%%%AirBox
Physical Surface(55) = {14};//%%%FerriteCore
Physical Surface(56) = {52};//%%%Insulation
// Stranded inductors. SYNTAX FOR COMMENTS: \%\%\%WindingName - number_of_turns  (3 spaces) number_of_layers (3 spaces) dist2axisym_layer1 (3spaces) conductor_diameter (3 spaces)   centre2centre_distance (3 spaces) WireType 
// Numbering starting from biggest winding index (important for post processing purposes)
Physical Surface(57) = {50};//%%%Winding1 - 14   1   0.0063085  0.000315   0.000387   Mag0315 
Physical Surface(58) = {48};//%%%Winding2 - 6   1   0.0059215   0.000315   0.000387   Mag0315
Physical Surface(59) = {46};//%%%Winding3 - 14   1   0.0055695  0.00025   0.000317   Mag025
Physical Surface(60) = {44};//%%%Winding4 - 8   1   0.0052175   0.000315   0.000387   Mag0315
Physical Surface(61) = {42};//%%%Winding5 - 32   2-16-16   0.0044435 0.000315   0.000387   Mag0315

// Winding i:
//Axisym 
// |                     layer1                        layer2   
// |                      * *                           * *
// | <----dist2axis----> *   *  <-centre2centredist->  *   *
// |                     *   *                         *   *
// |                      * *                           * *
// |                       
// |                      / \
// |                       |
// |                       |
// |               centre2centredist
// |                       |
// |                       | 
// |                      \ /
// |                       
// |                      * *                           * *
// |                     *   *                         *   *
// |                     *   *                         *   *
// |                      * *                           * *
