//                   DESCRIPTION GENERALE D'UNE ELECTRODE
//                   ------------------------------------

Function Electrode

// Construction de la matrice de changement de repère

// Calcul de la norme du vecteur axe électrode

  NormeK = Sqrt(Kx*Kx + Ky*Ky + Kz*Kz) ;

  Kx = Kx / NormeK ;
  Ky = Ky / NormeK ;
  Kz = Kz / NormeK ; 

  N = Sqrt( Kx*Kx + Ky*Ky);
 
If ( N == 0.)

  Ix = 1. ;
  Iy = 0. ;
  Iz = 0. ;

  Jx = 0. ;
  Jy = 1. ;
  Jz = 0. ;

EndIf

If ( N > 0.)

  Ix = - Ky / N ;
  Iy =   Kx / N ;
  Iz =   0. ;

  Jx = - Kx * Kz / N ;
  Jy = - Ky * Kz / N ;
  Jz =   N ;

/*
  Printf("Ix  = %g  ", Ix ) ;
  Printf("Iy  = %g  ", Iy );
  Printf("Iz  = %g  ", Iz );

  Printf("Jx  = %g  ", Jx ) ;
  Printf("Jy  = %g  ", Jy );
  Printf("Jz  = %g  ", Jz );

  Printf("Kx  = %g  ", Kx ) ;
  Printf("Ky  = %g  ", Ky );
  Printf("Kz  = %g  ", Kz );
*/

EndIf


// Coordonnées des points de constructions de l'electrode dans son repère local
// cercle inférieur

  X[0] = 0 ; Y[0] = 0 ; Z[0] = 0. ;
  X[1] = r ; Y[1] = 0 ; Z[1] = 0. ;
  X[2] = 0 ; Y[2] = r ; Z[2] = 0. ;
  X[3] =-r ; Y[3] = 0 ; Z[3] = 0. ;
  X[4] = 0 ; Y[4] =-r ; Z[4] = 0. ;



// Cercle supérieur

  X[10] = 0 ; Y[10] = 0 ; Z[10] = h ;
  X[11] = r ; Y[11] = 0 ; Z[11] = h ;
  X[12] = 0 ; Y[12] = r ; Z[12] = h ;
  X[13] =-r ; Y[13] = 0 ; Z[13] = h ;
  X[14] = 0 ; Y[14] =-r ; Z[14] = h ;

// Coordonnées des points de constructions de l'electrode dans son repère global

 For i In {0:4}

  x[i] = Ix*X[i] + Jx*Y[i] + Kx*Z[i] + xc;
  y[i] = Iy*X[i] + Jy*Y[i] + Ky*Z[i] + yc;
  z[i] = Iz*X[i] + Jz*Y[i] + Kz*Z[i] + zc;

/*
  Printf("x[%g]  : %g  ", i, x[i]) ;
  Printf("y[%g]  : %g  ", i, y[i]) ;
  Printf("z[%g]  : %g  ", i, z[i]) ;
*/

 EndFor

 For i In {10:14}

  x[i] = Ix*X[i] + Jx*Y[i] + Kx*Z[i] + xc;
  y[i] = Iy*X[i] + Jy*Y[i] + Ky*Z[i] + yc;
  z[i] = Iz*X[i] + Jz*Y[i] + Kz*Z[i] + zc;

 EndFor

// Définition des densité de discrétisation
 
  dpE = NbEl +1;
  kr = 1.;
  kh = 1.5;
  lcElec = kr*2.*Pi*r/(4.*NbEl) ;
  lElec  = kh*2.*Pi*r/(4.*NbEl) ;

// Constuction du cercle de base (centre de coordonnées xc,yc,zc)

  p0 = newp; Point(p0) = {x[0], y[0],  z[0],  lcElec} ;
  p1 = newp; Point(p1) = {x[1], y[1],  z[1],  lElec} ;
  p2 = newp; Point(p2) = {x[2], y[2],  z[2],  lElec} ;
  p3 = newp; Point(p3) = {x[3], y[3],  z[3],  lElec} ;
  p4 = newp; Point(p4) = {x[4], y[4],  z[4],  lElec} ;

  c1 = newreg; Circle(c1) = {p1,p0,p2};
  c2 = newreg; Circle(c2) = {p2,p0,p3};
  c3 = newreg; Circle(c3) = {p3,p0,p4};
  c4 = newreg; Circle(c4) = {p4,p0,p1};

// Constuction du cercle supérieur
 
  p10 = newp; Point(p10) = {x[10], y[10],  z[10],  lcElec} ;
  p11 = newp; Point(p11) = {x[11], y[11],  z[11],  lElec} ;
  p12 = newp; Point(p12) = {x[12], y[12],  z[12],  lElec} ;
  p13 = newp; Point(p13) = {x[13], y[13],  z[13],  lElec} ;
  p14 = newp; Point(p14) = {x[14], y[14],  z[14],  lElec} ;

  c11 = newreg; Circle(c11) = {p11,p10,p12};
  c12 = newreg; Circle(c12) = {p12,p10,p13};
  c13 = newreg; Circle(c13) = {p13,p10,p14};
  c14 = newreg; Circle(c14) = {p14,p10,p11};

// Construction des génératrices
 
  l1 = newreg; Line(l1) = {p1,p11};
  l2 = newreg; Line(l2) = {p2,p12};
  l3 = newreg; Line(l3) = {p3,p13};
  l4 = newreg; Line(l4) = {p4,p14};

// Constructions des surfaces

// Disque supérieur 

  ll1 = newreg; Line Loop(ll1) = {c11,c12,c13,c14}; Plane Surface(ll1) = {ll1};

// Bords de l'electrode

  ll2 = newreg; Line Loop(ll2) = {c1,l2,-c11,-l1};  Ruled Surface(ll2) = {ll2};
  ll3 = newreg; Line Loop(ll3) = {c2,l3,-c12,-l2};  Ruled Surface(ll3) = {ll3};
  ll4 = newreg; Line Loop(ll4) = {c3,l4,-c13,-l3};  Ruled Surface(ll4) = {ll4};
  ll5 = newreg; Line Loop(ll5) = {c4,l1,-c14,-l4};  Ruled Surface(ll5) = {ll5};

// Définition de lla frontière électrode-verre

  FrontElect[t-1] = newreg ;
  Surface Loop (FrontElect[t-1])    = { -ll1, -ll2, -ll3, -ll4, -ll5};
  Physical Surface(FrontElect[t-1]) = {  ll1,  ll2,  ll3,  ll4,  ll5};
  Printf("Numeros  de la frontiere Electrode %g - verre : %g  ", t, FrontElect[t-1]) ;

// Définition du contour de pied d'electrode

  ContPiedElect[t]= newreg ;
  Line Loop (ContPiedElect[t]) = { c1,c2,c3,c4} ;

// Discrétisation du contour circulaire (Nb de Noeuds / quart périmètre)

  Transfinite Line {c1,c2,c3,c4,c11,c12,c13,c14} = dpE;


Return



