Advertisement
Guest User

Untitled

a guest
Nov 22nd, 2017
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 4.41 KB | None | 0 0
  1. /*
  2. Soud Kharusi 260620452
  3. PHYS 557 Assignment 7
  4. Due Nov 22 2017
  5. */
  6.  
  7. //To compile
  8. //gcc "filename.c" -c -o -lm execfilename
  9. #include <stdio.h>
  10. #include <stdlib.h>
  11. #include <math.h>
  12. #include <string.h>
  13.  
  14. #define PI (3.1415926535897932384626433832795028841971693994)
  15.  
  16. #include "init.h"
  17. #include "dens.h"
  18. #include "fields.h"
  19. #include "sources.h"
  20. #include "init.c"
  21. #include "update.c"
  22.  
  23. struct init_data com_dat;
  24. struct fields mesons;
  25. struct densities dens;
  26. struct sources srcs;
  27.  
  28. //struct fields *LOCAL_MESONS;
  29. //struct sources *LOCAL_SRCS;
  30. //struct densities *LOCAL_DENS;
  31. //struct init_data COMMON_DATA;
  32.  
  33. //declaring my functions to be used in main. Full functions are below main.
  34. //p_or_n is 1 for proton and 0 for neutron
  35. void FillData();
  36. //double GetEFermi(double mu, double eA, double grho, double gomega, int p_or_n);
  37. //double GetPFermi(double EFermi, double mass);
  38. //void GetRho(double *vecRhopn, double mup, double *vecSigma, double *vecRho0, double *vecOmega, double *vecA0, int nMax, int p_or_n);
  39.  
  40.  
  41. //The main part of the programme, where I will run and print as well as output the dat file.
  42. int main() {
  43.   //filling in all the initial data.
  44.   FillData();
  45.   //Allocate memory space for the density vectors and fill with initial guess.
  46.   InitializeDensities(&dens);
  47.  
  48.   //Allocate memory space to meson (and A0) vectors and also make the Green function matrices
  49.   InitializeFields(&mesons);
  50.  
  51.   //Allocate memory space for the source vectors and fill them with the initial guess
  52.   InitializeSources(&srcs, &dens, &mesons);
  53.  
  54.   // Fill the meson and A0 vectors with the initial values according to the intial density values
  55.   MakeInitFields(&mesons, &srcs, &dens);
  56.  
  57.   double mu_p = COMMON_DATA.m_proton; // Initial guess for the proton chemical potential
  58.   double mu_n = COMMON_DATA.m_neutron; // Ditto for the neutrons
  59.   double err = UpdateDensities(&mesons,&srcs,&dens, mu_p, mu_n, COMMON_DATA.rmax, COMMON_DATA.nmax);
  60.   int iter_max = 100; // suitably large number. 100 will do
  61.   for(int iter=0; iter<iter_max; iter++){
  62.     UpdateSources(&srcs, &dens, &mesons, COMMON_DATA.rmax, COMMON_DATA.nmax);
  63.     UpdateFields(&mesons, &srcs, &dens, COMMON_DATA.rmax, COMMON_DATA.nmax);
  64.     err = UpdateDensities(&mesons,&srcs,&dens, mu_p, mu_n, COMMON_DATA.rmax, COMMON_DATA.nmax);
  65.     double tol = 1e-10;
  66.     if(err < tol){
  67.       break;
  68.     }
  69.     //PrintOut(Mesons, Dens) // Print out densities and fields
  70.     return 0;
  71.   }
  72. /*
  73.  
  74.   //Tests below
  75.   double* integ = makeVector(com_dat.nmax + 1);
  76.   double dr = com_dat.rmax/com_dat.nmax;
  77.   for(int i = 0; i<com_dat.nmax+1; i++){
  78.     integ[i] = 4.0*M_PI*pow(i*dr, 2)*dens.rho_n[i];
  79.     //printf("%.12f\n",integ[i]);
  80.   }
  81.   double test = numIntegrateVec(integ, com_dat.rmax/com_dat.nmax , 0, com_dat.nmax, com_dat.nmax);
  82.  
  83.   printf("Test should give either Z=20 or N=22: %.12f \n", test);
  84.  
  85. */
  86.  
  87. /*
  88.  
  89.   //Outputting the results to a .dat file.
  90.   FILE *fp;
  91.   // "w" means that we are going to write on this file
  92.   fp = fopen("Kharusi_Result_HW6_labelled.dat", "w");
  93.   double dr = com_dat.rmax/com_dat.nmax;
  94.   for(int i = 0; i < com_dat.nmax; i++){
  95.     fprintf(fp, "radius = %.2f \t sigma = %.12f \t A0 = %.12f \t omega = %.12f \t rho0= %.12f \n", i*dr, mesons.sigma[i]*com_dat.hbarc, mesons.A0[i]*com_dat.hbarc, mesons.omega[i]*com_dat.hbarc, mesons.rho0[i]*com_dat.hbarc);
  96.   }
  97.   fclose(fp);
  98.  
  99.   FILE *fp2;
  100.   // "w" means that we are going to write on this file
  101.   fp2 = fopen("Kharusi_Result_HW6.dat", "w");
  102.   for(int i = 0; i < com_dat.nmax; i++){
  103.     fprintf(fp2, "%.2f \t %.12f \t %.12f \t %.12f \t %.12f \n", i*dr, mesons.sigma[i]*com_dat.hbarc, mesons.A0[i]*com_dat.hbarc, mesons.omega[i]*com_dat.hbarc, mesons.rho0[i]*com_dat.hbarc);
  104.   }
  105.   fclose(fp2);
  106. */
  107.  
  108. return 0;
  109. }
  110.  
  111.  
  112.  
  113. void FillData(){
  114.   //Example for this assignment
  115.   com_dat.nmax = 200;
  116.   com_dat.rmax = 12.0;
  117.   com_dat.A = 42.;
  118.   com_dat.Z = 20.;
  119.   com_dat.N = 22.;
  120.  
  121.   com_dat.hbarc = 197.3;
  122.   com_dat.m_rho = 770./com_dat.hbarc;
  123.   com_dat.m_omega = 783./com_dat.hbarc;
  124.   com_dat.m_sigma = 550./com_dat.hbarc;
  125.   com_dat.g_rho = 2.629;
  126.   com_dat.e_EM = 0.3028221199;
  127.   com_dat.g_omega = 13.80557973;
  128.   com_dat.g_sigma = 11.07849711;
  129.   com_dat.m_proton = 938.27/com_dat.hbarc;
  130.   //com_dat.m_proton = 939.0/com_dat.hbarc;
  131.   com_dat.m_neutron = 939.57/com_dat.hbarc;
  132.   //com_dat.m_neutron = 939.0/com_dat.hbarc;
  133.   COMMON_DATA.old_frac = 0.6;
  134.   COMMON_DATA.new_frac = 1.0 - COMMON_DATA.old_frac;
  135. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement