CPP   15

source

Guest on 20th July 2022 06:48:44 AM

  1. #include <iostream.h>   //for text input/output
  2. #include <fstream.h>    //for file input/output
  3. #include <math.h>       //for trig functions, etc.
  4.  
  5. //Mathematical, Physical, and LIGO constants
  6. #define pi  3.14159        //pi
  7. #define c   3e8            //speed of light
  8. #define G   6.67e-11       //gravitational constant
  9. #define L   4000           //interferometer arm length in meters
  10. #define w_laser 6*pi*1e14  //angular frequency of laser (rad/s)
  11.  
  12. //include the following local header files
  13. #include "GWsource.h"      //defines certain grav-wave sources
  14. #include "detector.h"      //defines the LIGO detector
  15.  
  16. //The simulation program
  17. int main()
  18. {
  19.   //Create instances of the two important objects
  20.    Binary   src;    //A grav. wave source
  21.    Detector det;    //will receive GW signal, convert to laser phase shift
  22.  
  23.   //These variables will hold dynamic information for the simulation
  24.     //variables for the grav. wave source:
  25.        double R=10;              //distance to source in Mpc
  26.        double m1=3e30, m2=3e30;  //masses of two stars
  27.        double r = 1000;           //separation of stars in km
  28.        double psi=0;             //tilt of star system relative to earth
  29.        double theta=0, phi=0;    //angular position of source
  30.  
  31.     //variables for the detector
  32.        double alpha=0, beta=0,gamma=0;   //orientations of detector
  33.  
  34.     //variables for the simulation
  35.        double frequency=0;        //instantaneous GW frequency
  36.        double h_plus, h_cross;    //instantaneous polarizations
  37.  
  38.        double time = 0.0;             //the clock variable
  39.        const double t_final = 0.2;    //ending time
  40.        const double t_step = 0.0002;  //time increment (WATCH OUT FOR ALIASING)
  41.        char filename[20];             //the name of the output file
  42.  
  43.     //open an input file from which the simulation will read the values
  44.        char param_file_name[20];
  45.        cout << "Please enter the parameter file: ";
  46.        cin >> param_file_name;
  47.        ifstream param_file;
  48.        param_file.open(param_file_name);
  49.  
  50.     while(1)  //loop indefinitely
  51.     {
  52.         param_file >> time; //read in the simulation start time
  53.         if(time == 187)     //stop looping on this "kill" signal
  54.           break;
  55.  
  56.         //read in all the important information  
  57.          param_file >> R;
  58.          param_file >> m1;
  59.          param_file >> m2;
  60.          param_file >> r;
  61.          param_file >> theta;
  62.          param_file >> phi;
  63.          param_file >> psi;
  64.          param_file >> alpha;
  65.          param_file >> beta;
  66.          param_file >> gamma;
  67.          param_file >> filename;
  68.  
  69.         //convert all angles from degrees to radians
  70.          theta *= pi/180;
  71.          phi *= pi/180;
  72.          psi *= pi/180;
  73.          alpha *= pi/180;
  74.          beta *= pi/180;
  75.          gamma *= pi/180;
  76.  
  77.         //Using this new information, perform initializations
  78.          src.init(R,m1,m2,r,theta,phi,psi);   //initialize the source
  79.          det.init(alpha,beta,gamma,filename); //initialize the detector
  80.  
  81.       //THE ACTUAL SIMULATION LOOP
  82.        while(time <= t_final)  //loop within the time range
  83.        {
  84.         //Update the source and get the new information
  85.          src.action(time);  //update the source at this time step
  86.          src.get_freq(frequency);  //get the current frequency
  87.          src.get_amplitudes(h_plus, h_cross); //get the current amplitudes
  88.  
  89.         //Update the detector and write the new information to file
  90.          det.action(time, frequency, theta, phi, h_plus, h_cross);
  91.          det.record_data(time, frequency, h_plus, h_cross);
  92.  
  93.         time += t_step;   //go to next time step
  94.        }//end of this simulation
  95.  
  96.        //Call the detector's termination function
  97.         det.kill(theta, phi, psi);  //writes the filename.txt file
  98.          
  99.     }//end of the program loop  
  100.  
  101.     param_file.close();  //close the parameter file
  102.   return 1;       //program is done
  103. }

Raw Paste


Login or Register to edit or fork this paste. It's free.