Advertisement
phystota

superelastic+field_heating(v4)

Apr 17th, 2025
337
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 43.21 KB | None | 0 0
  1. #include <iostream>
  2. #include <random>
  3. #include <fstream>
  4. #include <assert.h>
  5.  
  6. #include <math.h>
  7. #include <time.h>
  8. #include <iomanip>  // For std::fixed and std::setprecision
  9.  
  10. #include <algorithm>  // For std::shuffle
  11. #include <numeric>    // For std::iota
  12.  
  13. //physical constants
  14.  
  15. #define m_e 9.1093837E-31 // electron mass in kg
  16. #define M_n 6.6464731E-27 // Helium atom mass
  17. #define k_b 1.380649E-23 // Boltzmann constant
  18. #define q 1.602176634E-19 // elementary charge    - eV -> J transfer param
  19. #define Coulomb_log 15.87 // Coulomb logarithm
  20. #define epsilon_0 8.854188E-12 // Vacuum permittivity
  21. #define Coulomb_const pow(q,4)/(pow(4.0*M_PI*epsilon_0,2)) // e^4/(4*pi*eps0)^2
  22. #define thresh1 19.82 // threshold energy excitation tripet state
  23. #define thresh2 20.61 // threshold energy excitation singlet state
  24.  
  25. // simulation parameters
  26.  
  27. #define n_e 100000
  28. // #define N_He 1000000 // Helium neutrals number
  29. #define T_n 2.0 // Helium neutral temperature in eV
  30. #define T_e 5.0    // electron Maxwell initial distribution
  31. #define Emin 0.0
  32. #define Emax 4000.0
  33. #define Volume 1.0E-12 // Volume to calculate netral density and collision frequency
  34. #define time 5.0E-4 // 500 microsec time to equalibrate the system
  35. #define dopant 1.0E-5 // addition to avoid zero
  36. #define E_reduced 1.0 // constant electrin field along z-axis
  37.  
  38. #define bin_width 0.05 // keep energy step ~ this to maintain cross-section clarity (Ramsauer minimum etc)
  39. #define N ( (int)((Emax-Emin)/bin_width) + 1) // add 1 to include E_max if needed?
  40.  
  41. // handling final energy bin
  42.  
  43. #define bin_width_smooth 0.05 // energy bin for smooth final distribution
  44. #define N_smooth ( (int)((Emax-Emin)/bin_width_smooth) )
  45.  
  46.  
  47.  
  48. double solve_A(double s) { // Netwon method solver
  49.  
  50.     if (s > 3) {
  51.         return 3*exp(-s);
  52.     }
  53.     if (s < 0.01) {
  54.         return 1.0/s;
  55.     }
  56.    
  57.     double A0 = 0.01; // initial guess
  58.     double A = A0;  //starting with initial guess
  59.     double tol = 1.0E-7; // accuracy
  60.  
  61.              
  62.     for (int i = 0; i < 1000; i++){
  63.  
  64.         double tanhA = tanh(A);
  65.         // Avoid division by an extremely small tanh(A)
  66.         if (fabs(tanhA) < 1e-12) {
  67.             std::cerr << "tanh(A) too small, returning fallback at iteration " << i << "\n";
  68.             return 1.0E-7;
  69.         }        
  70.  
  71.         double f = 1.0 / tanhA - 1.0 / A - exp(-s);
  72.         if (fabs(f) < tol)
  73.             break;
  74.  
  75.         double sinhA = sinh(A);
  76.         if (fabs(sinhA) < 1e-12) {
  77.             std::cerr << "sinh(A) too small, returning fallback at iteration " << i << "\n";
  78.             return 1.0E-5;
  79.         }
  80.  
  81.         double dfdA = -1.0/(sinh(A)*sinh(A)) + 1.0/(A*A);
  82.  
  83.         // Check if derivative is too close to zero to avoid huge updates
  84.         if (fabs(dfdA) < 1e-12) {
  85.             std::cerr << "dfdA is too small at iteration " << i << ", returning fallback\n";
  86.             if (s < 0.01) {
  87. //                std::cout << "Small s! Huge A!" << "\n";
  88.                 return 1.0/s;
  89.             }
  90.             if (s > 3) {
  91.                 return 3.0*exp(-s);
  92.             }
  93.         }        
  94.  
  95.         A -= f/dfdA;
  96.  
  97.         // Early check for numerical issues
  98.         if (std::isnan(A) || std::isinf(A)) {
  99.             std::cerr << "Numerical error detected, invalid A at iteration " << i << "\n";
  100.             return (A > 0) ? 1.0E-5 : -1.0E-5;  // Fallback value based on sign
  101.         }        
  102.  
  103.  
  104.     }
  105.  
  106.     return A;
  107. }
  108.  
  109. struct Electron {
  110.  
  111.     //velocity components
  112.     double vx = 0.0;
  113.     double vy = 0.0;
  114.     double vz = 0.0;
  115.     //energy in eV
  116.     double energy = 0.0;
  117.     //Collision flag
  118.     bool collided_en = false;
  119.     bool collided_ee = false;
  120.  
  121.     // initializing Maxwell-Boltzmann distribution with T_e
  122.     void initialize(std::mt19937& gen, std::uniform_real_distribution<double>& dis, std::gamma_distribution<double>& maxwell) {
  123.  
  124.         double R = dis(gen);
  125.  
  126.         // velocity angles in spherical coordinates
  127.         double phi = 2*M_PI*dis(gen);
  128.         double cosTheta = 2.0*dis(gen) - 1.0;
  129.         double sinTheta = sqrt(1.0 - cosTheta*cosTheta);
  130.  
  131.            
  132.         energy = maxwell(gen); // neutrals energies sampled as Maxwell distribution in eV
  133.            
  134.         double speed = sqrt(2*energy*q/m_e);
  135.  
  136.         //velocity components of neutrals in m/s
  137.         vx = speed * sinTheta * cos(phi);
  138.         vy = speed * sinTheta * sin(phi);
  139.         vz = speed * cosTheta;
  140.     }
  141.  
  142.  
  143. };
  144.  
  145. struct CrossSection {
  146.     double energy;
  147.     double sigma;
  148. };
  149.  
  150. double interpolate (double energy, const std::vector<CrossSection>& CS) {
  151.  
  152.  
  153.     if (energy < CS.front().energy) {
  154. //        std::cout << " required energy value lower than range of cross-section data at energy: " << energy << "\n";
  155.         return 0.0;
  156.     }
  157.     if (energy > CS.back().energy) {
  158. //        std::cout << " required energy value higher than range of cross-section data" << "\n";
  159.         return 0.0;        
  160.     }
  161.  
  162.     int step = 0;  
  163.         while (step < CS.size() && energy > CS[step].energy) {
  164.             step++;
  165.         }
  166.  
  167.     double k = (CS[step].sigma - CS[step-1].sigma)/(CS[step].energy - CS[step-1].energy);
  168.     double m = CS[step].sigma - k*CS[step].energy;
  169.    
  170.     return k*energy + m;
  171. }
  172.  
  173.  
  174. struct NeutralParticle {
  175.  
  176.     double energy = 0.0;
  177.     double vx = 0.0;
  178.     double vy = 0.0;
  179.     double vz = 0.0;
  180.  
  181.     void initialize(std::mt19937& gen, std::uniform_real_distribution<double>& dis, std::gamma_distribution<double>& maxwell) {
  182.  
  183.         double R = dis(gen);
  184.  
  185.         // velocity angles in spherical coordinates
  186.         double phi = 2*M_PI*dis(gen);
  187.         double cosTheta = 2.0*dis(gen) - 1.0;
  188.         double sinTheta = sqrt(1.0 - cosTheta*cosTheta);
  189.  
  190.            
  191.         energy = maxwell(gen); // neutrals energies sampled as Maxwell distribution in eV
  192.            
  193.         double speed = sqrt(2*energy*q/M_n);
  194.  
  195.         //velocity components of neutrals in m/s
  196.         vx = speed * sinTheta * cos(phi);
  197.         vy = speed * sinTheta * sin(phi);
  198.         vz = speed * cosTheta;
  199.     }
  200.    
  201. };
  202.  
  203. struct Excited_neutral {
  204.  
  205.     double energy;
  206.     double vx;
  207.     double vy;
  208.     double vz;
  209.    
  210. };
  211.  
  212.  
  213.  
  214. int main() {
  215.  
  216.     clock_t start = clock();
  217.  
  218.     int N_He = 100000000;
  219.  
  220.     std::vector<Electron> electrons(n_e); // better to use vector instead of simple array as it's dynamically allocated (beneficial for ionization)
  221. //    std::vector<NeutralParticle> neutrals(N_He); // I don't need a vector of neutrals bcs it's like a backhround in MCC-simulation
  222.  
  223.     std::vector<int> histo_random(N, 0); // initialize N size zero-vector for random (initial) histogram
  224.     std::vector<int> histo_maxwell(N, 0); // initialize N size zero-vector for maxwellian histogram
  225.     std::vector<int> histo_neutral(N, 0); // initialize N size zero-vector for neutral distribution histogram
  226.     std::vector<int> histo_excited(N, 0); // initialize N size zero-vector for excited He distribution histogram
  227.  
  228.     std::vector<double> elastic_vec(N, 0); // precompiled elastic cross-section-energy vector
  229.     std::vector<double> inelastic1_vec(N, 0); // precompiled inelastic(triplet excitation) cross-section-energy vector
  230.     std::vector<double> inelastic2_vec(N, 0); // precompiled inelastic(singlet excitation) cross-section-energy vector    
  231.     std::vector<double> superelastic1_vec(N, 0); // precompiled superelastic(triplet de-excitation) cross-section-energy vector
  232.     std::vector<double> superelastic2_vec(N, 0); // precompiled superelastic(triplet de-excitation) cross-section-energy vector
  233.  
  234.     std::random_device rd;
  235.     std::mt19937 gen(rd());
  236.     std::uniform_real_distribution<double> dis(0.0, 1.0);
  237.     std::gamma_distribution<double> maxwell_neutral(1.5, T_n);
  238.     std::gamma_distribution<double> maxwell_electron(1.5, T_e);
  239.  
  240.     std::ifstream elastic_cs_dat("cross_sections/elastic.dat");
  241.     if (!elastic_cs_dat.is_open()) {
  242.         std::cerr << "Error opening elastic cross-sections file!" << std::endl;
  243.         return 1;
  244.     }    
  245.  
  246.     std::ifstream excitation1_cs_dat("cross_sections/inelastic_triplet.dat");
  247.     if (!excitation1_cs_dat.is_open()) {
  248.         std::cerr << "Error opening inelastic triplet cross-sections file!" << std::endl;
  249.         return 1;
  250.     }
  251.  
  252.     std::ifstream excitation2_cs_dat("cross_sections/inelastic_singlet.dat");
  253.     if (!excitation2_cs_dat.is_open()) {
  254.         std::cerr << "Error opening inelastic singlet cross-sections file!" << std::endl;
  255.         return 1;
  256.     }
  257.  
  258.     // --- starts reading cross section datafiles
  259.  
  260. //-----------------elastic---------------------------//
  261.     std::vector<CrossSection> elastic_CS_temp;
  262.  
  263.     double energy, sigma;
  264.  
  265.     while (elastic_cs_dat >> energy >> sigma) {
  266.         elastic_CS_temp.push_back({energy, sigma});
  267.     }    
  268.     elastic_cs_dat.close();
  269.  
  270.     energy = 0.0;
  271.     sigma = 0.0;
  272. //-----------------triplet excitation---------------------------//
  273.     std::vector<CrossSection> inelastic1_CS_temp;
  274.  
  275.     while (excitation1_cs_dat >> energy >> sigma) {
  276.         inelastic1_CS_temp.push_back({energy, sigma});
  277.     }    
  278.     excitation1_cs_dat.close();    
  279. //-----------------singlet excitation---------------------------//
  280.     energy = 0.0;
  281.     sigma = 0.0;
  282.  
  283.     std::vector<CrossSection> inelastic2_CS_temp;
  284.  
  285.     while (excitation2_cs_dat >> energy >> sigma) {
  286.         inelastic2_CS_temp.push_back({energy, sigma});
  287.     }    
  288.     excitation2_cs_dat.close();    
  289.  
  290.     // --- finish reading cross-section datafiles  
  291.  
  292.     std::ofstream file0("output_files/velocities.dat");    
  293.     std::ofstream file1("output_files/energies.dat");        
  294.     std::ofstream file2("output_files/energies_final.dat");    
  295.     std::ofstream file3("output_files/histo_random.dat");    
  296.     file3 << std::fixed << std::setprecision(10);
  297.    
  298.     std::ofstream file4("output_files/histo_maxwell.dat");
  299.     file4 << std::fixed << std::setprecision(10);          
  300.    
  301.     std::ofstream file5("output_files/neutral_distribution.dat");    
  302.     std::ofstream file6("output_files/E*f(E).dat");    
  303.     std::ofstream file7("output_files/nu_max.dat");
  304.     std::ofstream file8("output_files/electron_mean_energy.dat");
  305.     std::ofstream file9("output_files/nu_elastic_average_initial.dat");
  306.     std::ofstream file10("output_files/nu_inelastic1_average_initial.dat");
  307.     std::ofstream file11("output_files/nu_elastic_average_final.dat");
  308.     std::ofstream file12("output_files/nu_inelastic1_average_final.dat");
  309.     std::ofstream file13("output_files/log_output.dat");  
  310.     std::ofstream file14("output_files/excited_energies.dat");      
  311.     std::ofstream file15("output_files/excited_histo.dat");            
  312.     std::ofstream file_temp("output_files/collision_rates.dat");  
  313.  
  314.     // Initialize all electrons
  315.     for (auto& e : electrons) {
  316.         e.initialize(gen, dis, maxwell_electron);
  317.     }
  318.  
  319.     // precalculate cross-sections for each energy bin
  320.     for (int i = 0; i < N; i++){
  321.         elastic_vec[i] = interpolate(bin_width*(i+0.5), elastic_CS_temp); //elastiuc
  322.         inelastic1_vec[i] = interpolate(bin_width*(i+0.5), inelastic1_CS_temp); //triplet excitation
  323.         inelastic2_vec[i] = interpolate(bin_width*(i+0.5), inelastic2_CS_temp); //singlet excitation
  324.     }
  325.  
  326.     // precalculate superelastic cross-section (triplet -> ground) for each energy bin
  327.     // detailed balance gives: sigma_j_i(E) = (g_i/g_j)*((E+theshold)/E)*sigma_i_j(E+theshold)
  328.     for (int i = 0; i < N; i++){
  329.         double energy = Emin + (i + 0.5) * bin_width;
  330.         int thresh_bin = (int)( (thresh1 - Emin)/bin_width ); // calculating bin for threshold energy
  331.         superelastic1_vec[i] = (1.0/3.0)*((energy + thresh1)/energy)*interpolate(energy + thresh1, inelastic1_CS_temp); // using detailed balance, calculating backward deexcitation cross-section
  332.         superelastic2_vec[i] = (1.0/1.0)*((energy + thresh2)/energy)*interpolate(energy + thresh2, inelastic2_CS_temp);
  333.     }
  334.  
  335.     for (int i = 0; i < n_e; i++){
  336.         file1 << i << " " << electrons.at(i).energy << "\n";
  337.         file0 << i << " " << electrons[i].vx << " " << electrons[i].vy << " " << electrons[i].vz << "\n";
  338.     }
  339.  
  340.     // -----initial electrons energy distribution starts------------////
  341.     for (int i = 0; i < n_e; i++){
  342.         int bin = (int)( (electrons[i].energy - Emin)/bin_width );
  343.         if (bin >=0 && bin < histo_random.size())
  344.             histo_random[bin]++;
  345.     }
  346.  
  347.     for (int i = 0; i < histo_random.size(); i++){
  348.         double bin_center = Emin + (i + 0.5) * bin_width;
  349.         file3 << bin_center << " " <<  static_cast<double>(histo_random[i])/(electrons.size()*bin_width) << "\n"; // this is electron normalized distribution function
  350.     }
  351.  
  352.  
  353.  
  354.     //calculating excited specied population
  355.  
  356.     /*From Boltzman distribution y_k = g_k*exp(-E_k/kT)/norm, where g_k - stat weight of k-state,
  357.     E_k - threshold energy for k-state, norm is a total partition function or normaliztion factor     */
  358.  
  359.     double part_ground = 1.0*exp(-0.0/T_n); // partition function for ground state
  360.     double part_triplet = 3.0*exp(-thresh1/T_n); // partition function for triplet excited state
  361.     double part_singlet = 1.0*exp(-thresh2/T_n); // partition function for singlet excited state
  362.     double part_func_total = part_ground + part_triplet + part_singlet; // total partition function
  363.     double N_trpilet = (part_triplet/part_func_total)*N_He; // population of tripet state
  364.     double N_singlet = (part_singlet/part_func_total)*N_He; // population of singlet state
  365.  
  366.     std::vector<Excited_neutral> exc_1(static_cast<int>(N_trpilet));  // vector to track triplet excited atoms of Helium
  367.     std::vector<Excited_neutral> exc_2(static_cast<int>(N_singlet));  // vector to track singlet excited atoms of Helium    
  368.  
  369.     // adjusting neutrals number:
  370.  
  371.     N_He -= (N_trpilet + N_singlet);
  372.  
  373.     std::cout << N_He << "\n";
  374.  
  375.     // initializing excited species with Maxwellian distribution
  376.  
  377.     for (auto& exc : exc_1) {
  378.     NeutralParticle tmp_neutral;
  379.     tmp_neutral.initialize(gen, dis, maxwell_neutral);
  380.     exc.energy = tmp_neutral.energy;
  381.     exc.vx = tmp_neutral.vx;
  382.     exc.vy = tmp_neutral.vy;
  383.     exc.vz = tmp_neutral.vz;
  384.     }
  385.  
  386.     for (auto& exc : exc_2) {
  387.     NeutralParticle tmp_neutral;
  388.     tmp_neutral.initialize(gen, dis, maxwell_neutral);
  389.     exc.energy = tmp_neutral.energy;
  390.     exc.vx = tmp_neutral.vx;
  391.     exc.vy = tmp_neutral.vy;
  392.     exc.vz = tmp_neutral.vz;
  393.     }
  394.  
  395.     std::cout << "Triplet population initialized: " << exc_1.size() << "\n";
  396.     std::cout << "Singlet population initialized: " << exc_2.size() << "\n";    
  397.  
  398.     // calculating excited specied population finished //
  399.  
  400.     // -----calculating nu-max for null-collision method starts ------------////
  401.     double nu_max = 0.0;
  402.     double nu_max_temp = 0.0;
  403.     double sigma_total = 0.0;
  404.    
  405.     for (int i = 0; i < N; i++){
  406. //        sigma_total = elastic_vec[i] + inelastic1_vec[i] + superelastic1_vec[i] + inelastic2_vec[i] +  superelastic2_vec[i];
  407.         sigma_total = elastic_vec[i] + inelastic1_vec[i] + inelastic2_vec[i]; // ??? densities of excited states are much lower!!!
  408.         nu_max_temp = (N_He/Volume)*sigma_total * sqrt(2.0*(i*bin_width + bin_width/2.0)*q/m_e);
  409.         file7 << i << " " << nu_max_temp << "\n";
  410.         if (nu_max_temp > nu_max)
  411.             nu_max = nu_max_temp;
  412.     }
  413.  
  414. //    std::cout << nu_max << "\n";
  415.     // -----calculating nu-max for null-collision method ends ------------////
  416.  
  417.     //----- calculating number to calculate nu-average (both elastic/inelastic )from our electron distribution starts---------///
  418.     // --- calculating nu(E)*f(E) for later external integration, using initial f(E)
  419.     for (int i = 0; i < N; i++){
  420.         double bin_center = Emin + (i + 0.5) * bin_width;
  421.         file9 << bin_center << " " << (N_He/Volume)*elastic_vec[i] * sqrt(2.0*bin_center*q/m_e)*static_cast<double>(histo_random[i])/(electrons.size()*bin_width) << "\n";
  422.         file10 << bin_center << " " << (N_He/Volume)*inelastic1_vec[i] * sqrt(2.0*bin_center*q/m_e)*static_cast<double>(histo_random[i])/(electrons.size()*bin_width) << "\n";
  423.     }
  424.     //----- calculating nu-average from our electron distribution ends ---------///    
  425.  
  426.     double dt = 0.1/nu_max;   // minimum should be 0.1/nu_max to get acceptable numerical error range see Vahedi Surrendra 1995
  427.     double steps = static_cast<int>(time/dt);
  428.  
  429.     std::cout << steps << "\n";
  430.     std::cout << dt << "\n";
  431.  
  432.     //using  null-collision technique, getting the number of particles colliding each step: P_collision = 1 - exp(-nu_max*dt)
  433.     int Ne_collided = (1.0-exp(-1.0*dt*nu_max))*n_e;
  434.  
  435.     std::cout << "Ne_collided:" << Ne_collided << "\n";
  436.  
  437.     int print_interval = 100;
  438.     int el_coll_counter = 0; // track all elastic collisions
  439.     int exc1_coll_counter = 0; // track all triplet excitation collisions
  440.     int exc2_coll_counter = 0; // track all singlet excitation collisions
  441.     int null_coll_counter = 0; // track null-collisions
  442.     int ee_coll_counter = 0; //track e-e Coulomb collisions
  443.     int super1_coll_counter = 0; // track superelastic triplet collisions
  444.     int super2_coll_counter = 0; // track superelastic triplet collisions    
  445.  
  446.  
  447.     for (int t = 0; t < steps; t++){
  448.  
  449. //              
  450.        
  451. //        std::cout << N_He + exc_1.size() + exc_2.size() << "\n";        
  452.  
  453.         // Generate shuffled list of electron indices
  454.         int reshuffle_interval = 1;
  455.         std::vector<int> electron_indices(n_e);
  456.         std::iota(electron_indices.begin(), electron_indices.end(), 0); // fill with index
  457. //        std::shuffle(electron_indices.begin(), electron_indices.end(), gen); // shuffle the indexes    
  458.  
  459.         for (int i = 0; i < Ne_collided; ++i) {
  460.             int j = i + std::uniform_int_distribution<int>(0, n_e - i - 1)(gen);
  461.             std::swap(electron_indices[i], electron_indices[j]);
  462.         }
  463.  
  464.         // Generate shuffled list of triplet excited atoms indices
  465.         std::vector<int> excited1_indices(exc_1.size());
  466.         std::iota(excited1_indices.begin(), excited1_indices.end(), 0); // fill with index
  467.         std::shuffle(excited1_indices.begin(), excited1_indices.end(), gen); // shuffle the indexes
  468.  
  469.  
  470.         // Generate shuffled list of singlet excited atoms indices
  471.         std::vector<int> excited2_indices(exc_2.size());
  472.         std::iota(excited2_indices.begin(), excited2_indices.end(), 0); // fill with index
  473.         std::shuffle(excited2_indices.begin(), excited2_indices.end(), gen); // shuffle the indexes
  474.  
  475.         int exc1_coll_counter_temp = 0;
  476.         int super1_coll_counter_temp = 0;
  477.         int exc2_coll_counter_temp = 0;
  478.         int super2_coll_counter_temp = 0;
  479.         int null_coll_counter_temp = 0;
  480.  
  481.    
  482.         // calculating mean energy
  483.         if (t%print_interval == 0) {
  484.             double total_energy = 0.0;
  485.             for (const auto& e : electrons) total_energy += e.energy;
  486.             double mean_energy = total_energy / n_e;
  487.             file8 << t*dt << " " << mean_energy << "\n";            
  488.             file_temp << t << " " << exc_1.size() << " " << exc_2.size() << "\n";
  489.             std::cout << "progress: " << (t/steps)*100 << "%" << "\n";
  490.         }
  491.  
  492.         // setting flags to false each timestep
  493.         for (auto& e : electrons) e.collided_en = false;
  494.         for (auto& e : electrons) e.collided_ee = false;        
  495.  
  496.         int collision_counter_en = 0; // electron-neutral collision counter
  497.         int collision_counter_ee = 0; // e-e collisoin counter
  498.  
  499.         /// -- electrin field heating along E-Z axis begin--- /// -- first half!!!
  500.         for (int idx : electron_indices) {
  501.  
  502.             // Update velocity component due to electric field
  503.             double a_z = ((-1.0)*q * E_reduced) / m_e; // acceleration in z-direction, m/s^2
  504.             electrons[idx].vz += a_z * (dt*0.5); // only half timestep
  505.  
  506.             // Recalculate energy from updated velocity
  507.             double vx = electrons[idx].vx;
  508.             double vy = electrons[idx].vy;
  509.             double vz = electrons[idx].vz;
  510.             electrons[idx].energy = 0.5 * m_e * (vx*vx + vy*vy + vz*vz) / q;
  511.         }
  512.         // -------------------------------------------- filed heating ends ------------------------//  
  513.  
  514.  
  515.         for (int idx : electron_indices) {
  516.  
  517.             if (collision_counter_en >= Ne_collided) break; // quit if reached all collisions
  518.  
  519.             Electron& e = electrons[idx];
  520.             if (e.collided_en) continue;  // Skip already collided electrons
  521.  
  522.             double electron_energy = e.energy;
  523.             int bin_energy = static_cast<int>(electron_energy / bin_width);
  524.             double nu_elastic = (N_He/Volume) * elastic_vec[bin_energy] * sqrt(2.0*electron_energy*q/m_e);
  525.             double nu_inelastic1 = (N_He/Volume) * inelastic1_vec[bin_energy] * sqrt(2.0*electron_energy*q/m_e);
  526.             double nu_superelastic1 = (exc_1.size()/Volume) * superelastic1_vec[bin_energy] * sqrt(2.0*electron_energy*q/m_e);
  527.             double nu_inelastic2 = (N_He/Volume) * inelastic2_vec[bin_energy] * sqrt(2.0*electron_energy*q/m_e);
  528.             double nu_superelastic2 = (exc_2.size()/Volume) * superelastic2_vec[bin_energy] * sqrt(2.0*electron_energy*q/m_e);
  529.  
  530.             double r = dis(gen);
  531.  
  532.             double P0 = nu_elastic/nu_max;
  533.             double P1 = (nu_elastic + nu_inelastic1)/nu_max;
  534.             double P2 = (nu_elastic + nu_inelastic1 + nu_superelastic1)/nu_max;
  535.             double P3 = (nu_elastic + nu_inelastic1 + nu_superelastic1 + nu_inelastic2)/nu_max;
  536.             double P4 = (nu_elastic + nu_inelastic1 + nu_superelastic1 + nu_inelastic2 + nu_superelastic2)/nu_max;            
  537.  
  538.             if (r < P0) {
  539.  
  540.                 // elastic collision happens
  541.  
  542.                 // ----   Collision energy redistribution module
  543.  
  544.  
  545.                 // electron particle X Y Z initial velocities and energy
  546.                 double V0_x = e.vx;
  547.                 double V0_y = e.vy;
  548.                 double V0_z = e.vz;
  549.                 double E_0 = e.energy;
  550.                
  551.                 // neutral that collides with electron
  552.  
  553.                 // randomize particles each collision
  554.  
  555.                 NeutralParticle tmp_neutral;
  556.                 tmp_neutral.initialize(gen, dis, maxwell_neutral);
  557.                 double V_x_n = tmp_neutral.vx;
  558.                 double V_y_n = tmp_neutral.vy;
  559.                 double V_z_n = tmp_neutral.vz;
  560.                 double E_n = tmp_neutral.energy;
  561.  
  562.  
  563.                 double V0 = sqrt(V0_x*V0_x + V0_y*V0_y + V0_z*V0_z);
  564.                
  565.                 // generating random variables to calculate random direction of center-of-mass after the collision
  566.  
  567.                 double R1 = dis(gen);
  568.                 double R2 = dis(gen);
  569.  
  570.                 //// calculating spherical angles for center-of-mass random direction
  571.                 // double theta = acos(1.0- 2.0*R1);
  572.                 // double phi = 2*M_PI*R2;
  573.                 double cos_khi = (2.0 + E_0 - 2.0*pow((1+E_0), R1))/E_0;
  574.                 if (cos_khi >= 1)
  575.                     cos_khi = 1.0 - dopant;
  576.                 if (cos_khi <= -1)
  577.                     cos_khi = -1.0 + dopant;
  578.                                      
  579.                 double sin_khi = sqrt(1.0 - cos_khi*cos_khi);
  580.  
  581.                 double phi = 2.0*M_PI*R2;
  582.                 double cos_theta = V0_x/V0;
  583.                 double sin_theta = sqrt(1.0 - cos_theta*cos_theta);
  584.                 // //calculating final relative velocity with random direction
  585.  
  586.                 //calculating final velocity of electron
  587.  
  588.                 double i_scat = (V0_x/V0)*cos_khi + (1.0 - (V0_x/V0)*(V0_x/V0))*(sin_khi*cos(phi)/sin_theta);
  589.                 double j_scat = (V0_y/V0)*cos_khi +  (V0_z/V0)*sin_khi*sin(phi)/sin_theta - (V0_x/V0)*(V0_y/V0)*sin_khi*cos(phi)/sin_theta;
  590.                 double k_scat = (V0_z/V0)*cos_khi - (V0_y/V0)*sin_khi*sin(phi)/sin_theta - (V0_x/V0)*(V0_z/V0)*sin_khi*cos(phi)/sin_theta;
  591.  
  592.                 //updating electron energy and velocities  
  593.  
  594.                 double delta_E = 2.0*(m_e/M_n)*(1.0 - cos_khi)*E_0;
  595.                 if (e.energy < delta_E) {
  596.                     null_coll_counter++;
  597.                     collision_counter_en++;
  598.                     e.collided_en = true;
  599.                     continue;
  600.                 }    
  601.                 else {                          
  602.                     e.energy = E_0 - delta_E;
  603.                 }
  604.                
  605.  
  606.                 double speed = sqrt(2*e.energy*q/m_e);
  607.  
  608.                 e.vx = speed*i_scat;
  609.                 e.vy = speed*j_scat;
  610.                 e.vz = speed*k_scat;              
  611.  
  612.                 collision_counter_en++;
  613.                 el_coll_counter++;
  614.  
  615.                 e.collided_en = true;
  616.             }        
  617.  
  618.             else if (r < P1) {
  619.  
  620.                 //inelastic 1(triplet) collision happens
  621.  
  622.                 // ----   Collision energy redistribution module
  623.  
  624.                 // electron particle X Y Z initial velocities and energy
  625.                 double V0_x = e.vx;
  626.                 double V0_y = e.vy;
  627.                 double V0_z = e.vz;
  628.                 double E_0 = e.energy;
  629.                
  630.                 // neutral that collides with electron
  631.  
  632.                 // randomize particles each collision
  633.  
  634.                 NeutralParticle tmp_neutral;
  635.                 tmp_neutral.initialize(gen, dis, maxwell_neutral);
  636.                 double V_x_n = tmp_neutral.vx;
  637.                 double V_y_n = tmp_neutral.vy;
  638.                 double V_z_n = tmp_neutral.vz;
  639.                 double E_n = tmp_neutral.energy;
  640.  
  641.  
  642.                 double V0 = sqrt(V0_x*V0_x + V0_y*V0_y + V0_z*V0_z);
  643.                
  644.                 // generating random variables to calculate random direction of center-of-mass after the collision
  645.  
  646.                 double R1 = dis(gen);
  647.                 double R2 = dis(gen);
  648.  
  649.                 //// calculating spherical angles for center-of-mass random direction
  650.                 // double theta = acos(1.0- 2.0*R1);
  651.                 // double phi = 2*M_PI*R2;
  652.                 double cos_khi = (2.0 + E_0 - 2.0*pow((1+E_0), R1))/E_0;
  653.                 double sin_khi = sqrt(1.0 - cos_khi*cos_khi);
  654.  
  655.                 double phi = 2.0*M_PI*R2;
  656.                 double cos_theta = V0_x/V0;
  657.                 double sin_theta = sqrt(1.0 - cos_theta*cos_theta);
  658.                 // //calculating final relative velocity with random direction
  659.  
  660.                 //calculating final velocity of electron
  661.  
  662.                 double i_scat = (V0_x/V0)*cos_khi + (1.0 - (V0_x/V0)*(V0_x/V0))*(sin_khi*cos(phi)/sin_theta);
  663.                 double j_scat = (V0_y/V0)*cos_khi +  (V0_z/V0)*sin_khi*sin(phi)/sin_theta - (V0_x/V0)*(V0_y/V0)*sin_khi*cos(phi)/sin_theta;
  664.                 double k_scat = (V0_z/V0)*cos_khi - (V0_y/V0)*sin_khi*sin(phi)/sin_theta - (V0_x/V0)*(V0_z/V0)*sin_khi*cos(phi)/sin_theta;
  665.  
  666.                 //updating electron energy and velocities        
  667.                
  668.                 if (e.energy < thresh1) {
  669.                     null_coll_counter++;
  670.                     collision_counter_en++;
  671.                     e.collided_en = true;
  672.                     continue;
  673.                 }
  674.                 else {
  675.                     e.energy = E_0 - thresh1;
  676.  
  677.                     double speed = sqrt(2*e.energy*q/m_e);
  678.  
  679.                     e.vx = speed*i_scat;
  680.                     e.vy = speed*j_scat;
  681.                     e.vz = speed*k_scat;
  682.  
  683.                     collision_counter_en++;  
  684.                     exc1_coll_counter++;
  685.                     exc1_coll_counter_temp++;
  686.  
  687.                     e.collided_en = true;
  688.  
  689.                     // pushing this neutral to an array of excited species exc_1
  690.                     if (N_He > 0) {
  691.                         exc_1.push_back({E_n, V_x_n, V_y_n, V_z_n});
  692.                         N_He--;
  693.                     }
  694.                 }
  695.             }    
  696.  
  697.             else if (r < P2) {
  698.  
  699.                 //superelastic 1(triplet -> ground state) collision happens
  700.  
  701.                 if (exc_1.empty()) {
  702.                     null_coll_counter++;
  703.                     collision_counter_en++;
  704.                     e.collided_en = true;
  705.                     continue;            
  706.                 }
  707.  
  708.                 // ----   Collision energy redistribution module
  709.  
  710.                 // electron particle X Y Z initial velocities and energy
  711.                 double V0_x = e.vx;
  712.                 double V0_y = e.vy;
  713.                 double V0_z = e.vz;
  714.                 double E_0 = e.energy;
  715.  
  716.                 double V0 = sqrt(V0_x*V0_x + V0_y*V0_y + V0_z*V0_z);
  717.  
  718.                 // neutral that collides with electron
  719.                 // taking particles from dynamic array of excited neutrals
  720.  
  721.                 int index = std::uniform_int_distribution<int>(0, exc_1.size()-1)(gen);
  722.                 Excited_neutral& exc = exc_1[index];
  723.                 double V_x = exc.vx;
  724.                 double V_y = exc.vy;
  725.                 double V_z = exc.vz;
  726.                 double E = exc.energy;
  727.                
  728.                 // generating random variables to calculate random direction of center-of-mass after the collision
  729.  
  730.                 double R1 = dis(gen);
  731.                 double R2 = dis(gen);
  732.  
  733.                 //// calculating spherical angles for center-of-mass random direction
  734.                 // double theta = acos(1.0- 2.0*R1);
  735.                 // double phi = 2*M_PI*R2;
  736.                 double cos_khi = (2.0 + E_0 - 2.0*pow((1+E_0), R1))/E_0;
  737.                 double sin_khi = sqrt(1.0 - cos_khi*cos_khi);
  738.  
  739.                 double phi = 2.0*M_PI*R2;
  740.                 double cos_theta = V0_x/V0;
  741.                 double sin_theta = sqrt(1.0 - cos_theta*cos_theta);
  742.                 // //calculating final relative velocity with random direction
  743.  
  744.                 //calculating final velocity of electron
  745.  
  746.                 double i_scat = (V0_x/V0)*cos_khi + (1.0 - (V0_x/V0)*(V0_x/V0))*(sin_khi*cos(phi)/sin_theta);
  747.                 double j_scat = (V0_y/V0)*cos_khi +  (V0_z/V0)*sin_khi*sin(phi)/sin_theta - (V0_x/V0)*(V0_y/V0)*sin_khi*cos(phi)/sin_theta;
  748.                 double k_scat = (V0_z/V0)*cos_khi - (V0_y/V0)*sin_khi*sin(phi)/sin_theta - (V0_x/V0)*(V0_z/V0)*sin_khi*cos(phi)/sin_theta;
  749.  
  750.                 //updating electron energy and velocities        
  751.                
  752.                 e.energy = E_0 + thresh1;
  753.  
  754.                 double speed = sqrt(2*e.energy*q/m_e);
  755.  
  756.                 e.vx = speed*i_scat;
  757.                 e.vy = speed*j_scat;
  758.                 e.vz = speed*k_scat;
  759.  
  760.                 //counting collisions, working with flags, popping atom out of the vector
  761.                 if (!exc_1.empty()) {
  762.                     std::swap(exc_1[index], exc_1.back());
  763.                     exc_1.pop_back();
  764.                     N_He++;
  765.                 }
  766.                 collision_counter_en++;  
  767.                 super1_coll_counter++;
  768.                 super1_coll_counter_temp++;
  769.  
  770.                 e.collided_en = true;
  771.             }  
  772.  
  773.             else if (r < P3) {
  774.  
  775.                 //inelastic 1(singlet) excitation collision happens
  776.  
  777.                 // ----   Collision energy redistribution module
  778.  
  779.                 // electron particle X Y Z initial velocities and energy
  780.                 double V0_x = e.vx;
  781.                 double V0_y = e.vy;
  782.                 double V0_z = e.vz;
  783.                 double E_0 = e.energy;
  784.                
  785.                 // neutral that collides with electron
  786.  
  787.                 // randomize particles each collision
  788.  
  789.                 NeutralParticle tmp_neutral;
  790.                 tmp_neutral.initialize(gen, dis, maxwell_neutral);
  791.                 double V_x_n = tmp_neutral.vx;
  792.                 double V_y_n = tmp_neutral.vy;
  793.                 double V_z_n = tmp_neutral.vz;
  794.                 double E_n = tmp_neutral.energy;
  795.  
  796.  
  797.                 double V0 = sqrt(V0_x*V0_x + V0_y*V0_y + V0_z*V0_z);
  798.                
  799.                 // generating random variables to calculate random direction of center-of-mass after the collision
  800.  
  801.                 double R1 = dis(gen);
  802.                 double R2 = dis(gen);
  803.  
  804.                 //// calculating spherical angles for center-of-mass random direction
  805.                 // double theta = acos(1.0- 2.0*R1);
  806.                 // double phi = 2*M_PI*R2;
  807.                 double cos_khi = (2.0 + E_0 - 2.0*pow((1+E_0), R1))/E_0;
  808.                 double sin_khi = sqrt(1.0 - cos_khi*cos_khi);
  809.  
  810.                 double phi = 2.0*M_PI*R2;
  811.                 double cos_theta = V0_x/V0;
  812.                 double sin_theta = sqrt(1.0 - cos_theta*cos_theta);
  813.                 // //calculating final relative velocity with random direction
  814.  
  815.                 //calculating final velocity of electron
  816.  
  817.                 double i_scat = (V0_x/V0)*cos_khi + (1.0 - (V0_x/V0)*(V0_x/V0))*(sin_khi*cos(phi)/sin_theta);
  818.                 double j_scat = (V0_y/V0)*cos_khi +  (V0_z/V0)*sin_khi*sin(phi)/sin_theta - (V0_x/V0)*(V0_y/V0)*sin_khi*cos(phi)/sin_theta;
  819.                 double k_scat = (V0_z/V0)*cos_khi - (V0_y/V0)*sin_khi*sin(phi)/sin_theta - (V0_x/V0)*(V0_z/V0)*sin_khi*cos(phi)/sin_theta;
  820.  
  821.                 //updating electron energy and velocities        
  822.                
  823.                 if (e.energy < thresh2) {
  824.                     null_coll_counter++;
  825.                     collision_counter_en++;
  826.                     e.collided_en = true;
  827.                     continue;
  828.                 }
  829.                 else {
  830.                     e.energy = E_0 - thresh2;
  831.  
  832.                     double speed = sqrt(2*e.energy*q/m_e);
  833.  
  834.                     e.vx = speed*i_scat;
  835.                     e.vy = speed*j_scat;
  836.                     e.vz = speed*k_scat;
  837.  
  838.                     collision_counter_en++;  
  839.                     exc2_coll_counter++;
  840.                     exc2_coll_counter_temp++;
  841.  
  842.                     e.collided_en = true;
  843.  
  844.                     // pushing this neutral to an array of excited species exc_2
  845.  
  846.                     if (N_He > 0) {
  847.                         exc_2.push_back({E_n, V_x_n, V_y_n, V_z_n});
  848.                         N_He--;
  849.                     }
  850.                 }
  851.             }
  852.  
  853.             else if (r < P4) {
  854.  
  855.                 //supernelastic 1(singlet -> ground state) collision happens
  856.  
  857.                 if (exc_2.empty()) {
  858.                     null_coll_counter++;
  859.                     collision_counter_en++;
  860.                     e.collided_en = true;
  861.                     continue;            
  862.                 }
  863.  
  864.                 // ----   Collision energy redistribution module
  865.  
  866.                 // electron particle X Y Z initial velocities and energy
  867.                 double V0_x = e.vx;
  868.                 double V0_y = e.vy;
  869.                 double V0_z = e.vz;
  870.                 double E_0 = e.energy;
  871.  
  872.                 double V0 = sqrt(V0_x*V0_x + V0_y*V0_y + V0_z*V0_z);
  873.  
  874.                 // neutral that collides with electron
  875.                 // taking particles from dynamic array of excited neutrals
  876.  
  877.                 int index = std::uniform_int_distribution<int>(0, exc_2.size()-1)(gen);
  878.                 Excited_neutral& exc = exc_2[index];
  879.                 double V_x = exc.vx;
  880.                 double V_y = exc.vy;
  881.                 double V_z = exc.vz;
  882.                 double E = exc.energy;
  883.                
  884.                 // generating random variables to calculate random direction of center-of-mass after the collision
  885.  
  886.                 double R1 = dis(gen);
  887.                 double R2 = dis(gen);
  888.  
  889.                 //// calculating spherical angles for center-of-mass random direction
  890.                 // double theta = acos(1.0- 2.0*R1);
  891.                 // double phi = 2*M_PI*R2;
  892.                 double cos_khi = (2.0 + E_0 - 2.0*pow((1+E_0), R1))/E_0;
  893.                 double sin_khi = sqrt(1.0 - cos_khi*cos_khi);
  894.  
  895.                 double phi = 2.0*M_PI*R2;
  896.                 double cos_theta = V0_x/V0;
  897.                 double sin_theta = sqrt(1.0 - cos_theta*cos_theta);
  898.                 // //calculating final relative velocity with random direction
  899.  
  900.                 //calculating final velocity of electron
  901.  
  902.                 double i_scat = (V0_x/V0)*cos_khi + (1.0 - (V0_x/V0)*(V0_x/V0))*(sin_khi*cos(phi)/sin_theta);
  903.                 double j_scat = (V0_y/V0)*cos_khi +  (V0_z/V0)*sin_khi*sin(phi)/sin_theta - (V0_x/V0)*(V0_y/V0)*sin_khi*cos(phi)/sin_theta;
  904.                 double k_scat = (V0_z/V0)*cos_khi - (V0_y/V0)*sin_khi*sin(phi)/sin_theta - (V0_x/V0)*(V0_z/V0)*sin_khi*cos(phi)/sin_theta;
  905.  
  906.                 //updating electron energy and velocities        
  907.                
  908.                 e.energy = E_0 + thresh2;
  909.  
  910.                 double speed = sqrt(2*e.energy*q/m_e);
  911.  
  912.                 e.vx = speed*i_scat;
  913.                 e.vy = speed*j_scat;
  914.                 e.vz = speed*k_scat;
  915.  
  916.                 //counting collisions, working with flags, popping atom out of the vector
  917.  
  918.                 if (!exc_2.empty()) {
  919.                     std::swap(exc_2[index], exc_2.back());
  920.                     exc_2.pop_back();
  921.                     N_He++;
  922.                 }
  923.  
  924.                 collision_counter_en++;  
  925.                 super2_coll_counter++;
  926.                 super2_coll_counter_temp++;
  927.  
  928.                 e.collided_en = true;
  929.             }              
  930.  
  931.             else {
  932.                 // null-collision
  933.                 collision_counter_en++;
  934.                 null_coll_counter++;
  935.                 e.collided_en = true;
  936.             }
  937.         }
  938.  
  939.  
  940.  
  941.         /// -- electrin field heating along E-Z axis begin--- /// -- second half!!!
  942.         for (int idx : electron_indices) {
  943.  
  944.             // Update velocity component due to electric field
  945.             double a_z = ((-1.0)*q * E_reduced) / m_e; // acceleration in z-direction, m/s^2
  946.             electrons[idx].vz += a_z * (dt*0.5); // only half timestep
  947.  
  948.             // Recalculate energy from updated velocity
  949.             double vx = electrons[idx].vx;
  950.             double vy = electrons[idx].vy;
  951.             double vz = electrons[idx].vz;
  952.             electrons[idx].energy = 0.5 * m_e * (vx*vx + vy*vy + vz*vz) / q;
  953.         }
  954.         // -------------------------------------------- filed heating ends ------------------------////////////////
  955.  
  956.         /// ---- data writing starts -----------////////////
  957.  
  958.             // if ((t%print_interval == 0) || (t == steps - 1)){
  959.             // // open datafiles to write each time step to see evolution
  960.             // std::ostringstream filename;
  961.             // filename << "data/distribution_" << std::setw(4) << std::setfill('0') << t << ".dat";
  962.  
  963.             // std::ofstream file(filename.str());
  964.             // if (!file.is_open()){
  965.             // std::cerr << "Error opening file: " << filename.str() << std::endl;
  966.             // return 1;
  967.             // }
  968.             // // end opening datafiles for each timestep
  969.            
  970.             // // creating histogram each timestep
  971.             // for (int i = 0; i < n_e; i++){
  972.             //     int bin = (int)( (electrons[i].energy - Emin)/bin_width_smooth );
  973.             //     if (bin >=0 && bin < N)
  974.             //     histo_maxwell[bin]++;
  975.             // }
  976.  
  977.             // // writing data each time step
  978.             // for (int i = 0; i < N_smooth; i++){
  979.             //     double bin_center = Emin + (i + 0.5) * bin_width_smooth;
  980.             //     file << bin_center << " " <<  static_cast<double>(histo_maxwell[i])/(electrons.size()*bin_width_smooth) << "\n"; //f(E)
  981.             //     histo_maxwell[i] = 0;
  982.             // }
  983.  
  984.             // //     //instead, writing energies each timestep:
  985.  
  986.             // // for (int i = 0; i < n_e; i++){
  987.             // //     file << i << " " << electrons[i].energy << "\n";
  988.             // // }
  989.  
  990.  
  991.             // file.close();
  992.  
  993.             // }
  994.  
  995.  
  996.             // end writing data each timestep
  997.  
  998.             // std::cout << "number excitation collisions at timestep: " << t << " " << "is: " << exc2_coll_counter_temp << "\n";            
  999.             // std::cout << "number superelatic collisions at timestep: " << t << " " << "is: " << super2_coll_counter_temp << "\n";  
  1000.             // file_temp << t << " " <<  super1_coll_counter_temp << " " << exc1_coll_counter_temp;
  1001.             // file_temp << " " <<  super2_coll_counter_temp << " " << exc2_coll_counter_temp << "\n";      
  1002.  
  1003. //            file_temp << t << " " <<  exc_1.size() << " " << exc_2.size() << "\n";    
  1004.  
  1005.  
  1006.     }
  1007.  
  1008.     // ----- final electron energies distribution begins
  1009.     for (int i = 0; i < n_e; i++){
  1010.  
  1011.         file2 << i << " " << electrons[i].energy << "\n";
  1012.  
  1013.         int bin = static_cast<int>( (electrons[i].energy - Emin)/bin_width_smooth);
  1014.         if (bin >=0 && bin < histo_maxwell.size())
  1015.             histo_maxwell[bin]++;
  1016.     }
  1017.  
  1018.     int check = 0;
  1019.     for (int i = 0; i < N_smooth; i++){
  1020.         check += histo_maxwell[i];
  1021.         double bin_center = Emin + (i + 0.5) * bin_width_smooth;
  1022.         file4 << bin_center << " " <<  static_cast<double>(histo_maxwell[i])/(electrons.size()*bin_width_smooth) << "\n"; // getting f(E)
  1023.     }
  1024.  
  1025.         std::cout << "Total # of electrons in a final histogram: " << check << "\n";
  1026.  
  1027.     // ----- final electron energies distribution ends
  1028.  
  1029.     // // ------ excited atoms histogram --------/////
  1030.  
  1031.     // for (int i = 0; i < exc_1.size(); i++) {
  1032.  
  1033.     //     file14 << i << " " << exc_1[i].energy << "\n";
  1034.  
  1035.     //     int bin = static_cast<int>( (exc_1[i].energy - Emin)/bin_width);
  1036.     //     if (bin >=0 && bin < histo_excited.size())
  1037.     //         histo_excited[bin]++;        
  1038.     // }
  1039.  
  1040.     // for (int i = 0; i < histo_excited.size(); i++){
  1041.  
  1042.     //     double bin_center = Emin + (i + 0.5) * bin_width;
  1043.     //     file15 << bin_center << " " <<  static_cast<double>(histo_excited[i])/(electrons.size()*bin_width) << "\n"; // getting f(E)
  1044.     // }
  1045.  
  1046.  
  1047.     file0.close();
  1048.     file1.close();
  1049.     file2.close();
  1050.     file3.close();
  1051.     file4.close();
  1052.     file5.close();
  1053.     file6.close();
  1054.     file7.close();
  1055.     file8.close();
  1056.     file9.close();
  1057.     file10.close();
  1058.     file11.close();
  1059.     file12.close();
  1060.     file13.close();
  1061.     file14.close();
  1062.     file15.close();
  1063.     file_temp.close();
  1064.  
  1065.     clock_t end = clock();
  1066.  
  1067.     double elapsed = (double)(end - start) / CLOCKS_PER_SEC;
  1068.  
  1069.     std::cout << "# of steps: " << steps << "\n";
  1070.     std::cout << "# of electrons collided each timesteps:" << Ne_collided << "\n";
  1071.    
  1072.     std::cout << "Average elastic collisions per timestep: " << static_cast<int>(el_coll_counter/steps) << "\n";
  1073.     std::cout << "Average null collisions per timestep: " << static_cast<int>(null_coll_counter/steps) << "\n";
  1074.     std::cout << "\n";
  1075.  
  1076.     std::cout << "triplet:________" << "\n";
  1077.     std::cout << "Average triplet excitation collisions per timestep: " << static_cast<int>(exc1_coll_counter/steps) << "\n";
  1078.     std::cout << "\n";
  1079.     std::cout << "Average superelastic triplet collisions per timestep: " << static_cast<int>(super1_coll_counter/steps) << "\n";
  1080.     std::cout << "\n";
  1081.  
  1082.     std::cout << "singlet:________" << "\n";
  1083.     std::cout << "Average singlet excitation collisions per timestep: " << static_cast<int>(exc2_coll_counter/steps) << "\n";
  1084.     std::cout << "\n";
  1085.     std::cout << "Average superelastic singlet collisions per timestep: " << static_cast<int>(super2_coll_counter/steps) << "\n";
  1086.     std::cout << "\n";    
  1087.  
  1088.     std::cout << "Average e-e collisions per timestep: " << static_cast<int>(ee_coll_counter/steps) << "\n";
  1089.  
  1090.     std::cout << "Elapsed time: %f seconds " << elapsed << "\n";
  1091.  
  1092.  
  1093.     return 0;
  1094.  
  1095. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement