/* I, Raphael Champeimont, the author of this program,
 * hereby release it into the public domain.
 * This applies worldwide.
 * 
 * In case this is not legally possible:
 * I grant anyone the right to use this work for any purpose,
 * without any conditions, unless such conditions are required by law.
 * 
 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 */

#include <stdio.h>

#define COUCHES 6

const char noms[COUCHES][6] =  {"1s", "2s,2p", "3s,3p", "3d", "4s,4p", "4d"};
const unsigned int n[COUCHES] = {1,    2,        3,         3,    4,       4};
unsigned int el[COUCHES] = {0, 0, 0, 0, 0, 0};
double E = 0;
double Ecouche = 0;
double ajouterE = 0;
double Z = 1;
double Zeff = 0;
double sigma = 0;
const double Ry = 13.61;
/* constantes d'ecran du modele de Slater */
const double cst[COUCHES][COUCHES] = { {0.31, 0,    0,    0,    0,    0},
				       {0.85, 0.35, 0,    0,    0,    0},
				       {1,    0.85, 0.35, 0,    0,    0},
				       {1,    1,    1,    0.35, 0,    0},
				       {1,    1,    0.85, 0.85, 0.35, 0},
				       {1,    1,    1,    1,    1,    0.35} };

int main() {
  int i, j;
  printf("\nCe programme calcule l'energie d'un atome avec le modele de Slater.\n\n");
  printf("Z = ");
  /* lecture des nombres d'electrons */
  scanf("%lf", &Z);
    for (i=0; i<COUCHES; i++) {
    printf("Nombre d'electrons de la couche %s : ", noms[i]);
    scanf("%u", &el[i]);
    }
  printf("\n\n");
  
  /* calcul */
  for (i=0; i<COUCHES; i++) {
    if (el[i] != 0) {
      printf("Couche %s :\n", noms[i]);
      printf("    Zeff = Z");
      Zeff = Z;
      for (j=0; j<=i; j++) {
	sigma = cst[i][j];
	if (i != j) {
	  printf(" - %u*%f", el[j], sigma);
	  Zeff -= (double)el[j]*sigma;
	} else {
	  printf(" - (%u-1)*%f", el[j], sigma);
	  Zeff -= (double)(el[j]-1)*sigma;
	}
      }
      printf(" = %f\n", Zeff);
      Ecouche = -(Ry/((double)(n[i]*n[i])) * Zeff*Zeff);
      ajouterE = (double)el[i]*Ecouche;
      printf("    %u * E(%s) = -Ry/(%u^2) * Zeff^2 = %f\n", el[i], noms[i], n[i], ajouterE);
      E += ajouterE;
    }
  }
  
  printf("E = %f eV\n", E);
  
  
  
  return 0;
}
