phystota

eduPIC_excitation_tracking_stable

May 23rd, 2025 (edited)
44
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 64.95 KB | None | 0 0
  1. //-------------------------------------------------------------------//
  2. //         eduPIC : educational 1d3v PIC/MCC simulation code         //
  3. //           version 1.0, release date: March 16, 2021               //
  4. //                       :) Share & enjoy :)                         //
  5. //-------------------------------------------------------------------//
  6. // When you use this code, you are required to acknowledge the       //
  7. // authors by citing the paper:                                      //
  8. // Z. Donko, A. Derzsi, M. Vass, B. Horvath, S. Wilczek              //
  9. // B. Hartmann, P. Hartmann:                                         //
  10. // "eduPIC: an introductory particle based  code for radio-frequency //
  11. // plasma simulation"                                                //
  12. // Plasma Sources Science and Technology, vol 30, pp. 095017 (2021)  //
  13. //-------------------------------------------------------------------//
  14. // Disclaimer: The eduPIC (educational Particle-in-Cell/Monte Carlo  //
  15. // Collisions simulation code), Copyright (C) 2021                   //
  16. // Zoltan Donko et al. is free software: you can redistribute it     //
  17. // and/or modify it under the terms of the GNU General Public License//
  18. // as published by the Free Software Foundation, version 3.          //
  19. // This program is distributed in the hope that it will be useful,   //
  20. // but WITHOUT ANY WARRANTY; without even the implied warranty of    //
  21. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU  //
  22. // General Public License for more details at                        //
  23. // https://www.gnu.org/licenses/gpl-3.0.html.                        //
  24. //-------------------------------------------------------------------//
  25.  
  26. #include <cstdio>
  27. #include <cstdlib>
  28. #include <cstring>
  29. #include <cstdbool>
  30. #include <cmath>
  31. #include <ctime>
  32. #include <random>
  33. #include <vector>
  34. #include <string>
  35. #include <fstream>
  36. #include <sstream>
  37. #include <algorithm>    
  38. #include <stdexcept>
  39. #include <iostream>
  40.  
  41. using namespace::std;
  42.  
  43. // constants
  44.  
  45. const double     PI             = 3.141592653589793;          // mathematical constant Pi
  46. const double     TWO_PI         = 2.0 * PI;                   // two times Pi
  47. const double     E_CHARGE       = 1.60217662e-19;             // electron charge [C]
  48. const double     EV_TO_J        = E_CHARGE;                   // eV <-> Joule conversion factor
  49. const double     E_MASS         = 9.109e-31;                  // mass of electron [kg]
  50. const double     HE_MASS        = 6.67e-27;                   // mass of He atom [kg]
  51. const double     MU_HEHE        = HE_MASS / 2.0;              // reduced mass of two He atoms [kg]
  52. const double     K_BOLTZMANN    = 1.38064852e-23;             // Boltzmann's constant [J/K]
  53. const double     EPSILON0       = 8.85418781e-12;             // permittivity of free space [F/m]
  54.  
  55. // simulation parameters
  56.  
  57. const int        N_G            = 129;                        // number of grid points
  58. const int        N_T            = 400;                        // time steps within an RF period
  59. const double     FREQUENCY      = 13.56e6;                    // driving frequency [Hz]
  60. const double     VOLTAGE        = 450.0;                      // voltage amplitude [V]
  61. const double     L              = 0.067;                      // electrode gap [m]
  62. const double     PRESSURE       = 3.99283551984;              // gas pressure [Pa] // n*k*T to match Turner's case
  63. const double     T_neutral      = 300.0;                      // background gas temperature [K] (also ion temperature)
  64. const double     T_electron     = 30000.0;                    // initial electron temperatutre [K]
  65. const double     WEIGHT         = 41875.0;                  // weight of superparticles
  66. const double     ELECTRODE_AREA = 1.6e-4;                     // (fictive) electrode area [m^2]
  67. const int        N_INIT         = 65536;                      // number of initial electrons and ions
  68.  
  69. // additional (derived) constants
  70.  
  71. const double     PERIOD         = 1.0 / FREQUENCY;                           // RF period length [s]
  72. const double     DT_E           = PERIOD / (double)(N_T);                    // electron time step [s]
  73. const int        N_SUB          = 5;                                         // ions move only in these cycles (subcycling)
  74. const double     DT_I           = N_SUB * DT_E;                              // ion time step [s]
  75. const double     DX             = L / (double)(N_G - 1);                     // spatial grid division [m]
  76. const double     INV_DX         = 1.0 / DX;                                  // inverse of spatial grid size [1/m]
  77. const double     GAS_DENSITY    = PRESSURE / (K_BOLTZMANN * T_neutral);      // background gas density [1/m^3]
  78. const double     OMEGA          = TWO_PI * FREQUENCY;                        // angular frequency [rad/s]
  79.  
  80. // electron and ion cross sections
  81.  
  82. const int        N_CS           = 8;                          // total number of processes / cross sections
  83. const int        E_ELA          = 0;                          // process identifier: electron/elastic
  84. const int        E_EXC_1        = 1;                          // process identifier: electron/excitation1
  85. const int        E_EXC_2        = 2;                          // process identifier: electron/excitation1
  86. const int        E_ION          = 3;                          // process identifier: electron/ionization
  87. const int        I_ISO          = 4;                          // process identifier: ion/elastic/isotropic
  88. const int        I_BACK         = 5;                          // process identifier: ion/elastic/backscattering
  89.  
  90. const int        E_SUPER_1      = 6;                          // triplet excitation - Artem
  91. const int        E_SUPER_2      = 7;                          // singlet excitation - Artem
  92.  
  93. const double     E_EXC_TH_1     = 19.82;                      // electron impact excitation threshold [eV]
  94. const double     E_EXC_TH_2     = 20.61;                      // electron impact excitation threshold [eV]
  95. const double     E_ION_TH       = 24.587;                     // electron impact ionization threshold [eV]
  96. const int        CS_RANGES      = 1000000;                    // number of entries in cross section arrays
  97. const double     DE_CS          = 0.001;                      // energy division in cross section arrays [eV]
  98. typedef float    cross_section[CS_RANGES];                    // cross section array
  99. cross_section    sigma[N_CS];                                 // set of cross section arrays
  100. cross_section    sigma_tot_e;                                 // total macroscopic cross section of electrons
  101. cross_section    sigma_tot_i;                                 // total macroscopic cross section of ions
  102.  
  103. // particle coordinates
  104.  
  105. const int        MAX_N_P = 10000000;                           // maximum number of particles (electrons / ions)
  106. typedef double   particle_vector[MAX_N_P];                    // array for particle properties
  107. int              N_e = 0;                                     // number of electrons
  108. int              N_i = 0;                                     // number of ions
  109. int              N_e1 = 0;                                    // number of singlet excited states
  110. int              N_e2 = 0;                                    // number of triplet excited states
  111. particle_vector  x_e, vx_e, vy_e, vz_e;                       // coordinates of electrons (one spatial, three velocity components)
  112. particle_vector  x_i, vx_i, vy_i, vz_i;                       // coordinates of ions (one spatial, three velocity components)
  113.  
  114.  
  115.  
  116.  
  117. typedef double   xvector[N_G];                                // array for quantities defined at gird points
  118. xvector          efield,pot;                                  // electric field and potential
  119. xvector          e_density,i_density;                         // electron and ion densities
  120. xvector          cumul_e_density,cumul_i_density;             // cumulative densities
  121.  
  122. //excited states handling
  123. xvector e1_density;
  124. xvector e2_density;
  125.  
  126. typedef unsigned long long int Ullong;                        // compact name for 64 bit unsigned integer
  127. Ullong       N_e_abs_pow  = 0;                                // counter for electrons absorbed at the powered electrode
  128. Ullong       N_e_abs_gnd  = 0;                                // counter for electrons absorbed at the grounded electrode
  129. Ullong       N_i_abs_pow  = 0;                                // counter for ions absorbed at the powered electrode
  130. Ullong       N_i_abs_gnd  = 0;                                // counter for ions absorbed at the grounded electrode
  131.  
  132. // electron energy probability function
  133.  
  134. const int    N_EEPF  = 2000;                                 // number of energy bins in Electron Energy Probability Function (EEPF)
  135. const double DE_EEPF = 0.05;                                 // resolution of EEPF [eV]
  136. typedef double eepf_vector[N_EEPF];                          // array for EEPF
  137. eepf_vector eepf     = {0.0};                                // time integrated EEPF in the center of the plasma
  138.  
  139. // ion flux-energy distributions
  140.  
  141. const int    N_IFED   = 200;                                 // number of energy bins in Ion Flux-Energy Distributions (IFEDs)
  142. const double DE_IFED  = 1.0;                                 // resolution of IFEDs [eV]
  143. typedef int  ifed_vector[N_IFED];                            // array for IFEDs
  144. ifed_vector  ifed_pow = {0};                                 // IFED at the powered electrode
  145. ifed_vector  ifed_gnd = {0};                                 // IFED at the grounded electrode
  146. double       mean_i_energy_pow;                              // mean ion energy at the powered electrode
  147. double       mean_i_energy_gnd;                              // mean ion energy at the grounded electrode
  148.  
  149. // spatio-temporal (XT) distributions
  150.  
  151. const int N_BIN                     = 20;                    // number of time steps binned for the XT distributions
  152. const int N_XT                      = N_T / N_BIN;           // number of spatial bins for the XT distributions
  153. typedef double xt_distr[N_G][N_XT];                          // array for XT distributions (decimal numbers)
  154. xt_distr pot_xt                     = {0.0};                 // XT distribution of the potential
  155. xt_distr efield_xt                  = {0.0};                 // XT distribution of the electric field
  156. xt_distr ne_xt                      = {0.0};                 // XT distribution of the electron density
  157. xt_distr ni_xt                      = {0.0};                 // XT distribution of the ion density
  158. xt_distr ue_xt                      = {0.0};                 // XT distribution of the mean electron velocity
  159. xt_distr ui_xt                      = {0.0};                 // XT distribution of the mean ion velocity
  160. xt_distr je_xt                      = {0.0};                 // XT distribution of the electron current density
  161. xt_distr ji_xt                      = {0.0};                 // XT distribution of the ion current density
  162. xt_distr powere_xt                  = {0.0};                 // XT distribution of the electron powering (power absorption) rate
  163. xt_distr poweri_xt                  = {0.0};                 // XT distribution of the ion powering (power absorption) rate
  164. xt_distr meanee_xt                  = {0.0};                 // XT distribution of the mean electron energy
  165. xt_distr meanei_xt                  = {0.0};                 // XT distribution of the mean ion energy
  166. xt_distr counter_e_xt               = {0.0};                 // XT counter for electron properties
  167. xt_distr counter_i_xt               = {0.0};                 // XT counter for ion properties
  168. xt_distr ioniz_rate_xt              = {0.0};                 // XT distribution of the ionisation rate
  169.  
  170. xt_distr e1_xt                      = {0.0};                 // XT distribution of triplet excited states density - Artem
  171. xt_distr e2_xt                      = {0.0};                 // XT distribution of singlet excited states density - Artem
  172.  
  173. double   mean_energy_accu_center    = 0;                     // mean electron energy accumulator in the center of the gap
  174. Ullong   mean_energy_counter_center = 0;                     // mean electron energy counter in the center of the gap
  175. Ullong   N_e_coll                   = 0;                     // counter for electron collisions
  176. Ullong   N_i_coll                   = 0;                     // counter for ion collisions
  177. double   Time;                                               // total simulated time (from the beginning of the simulation)
  178. int      cycle,no_of_cycles,cycles_done;                     // current cycle and total cycles in the run, cycles completed
  179. int      arg1;                                               // used for reading command line arguments
  180. char     st0[80];                                            // used for reading command line arguments
  181. FILE     *datafile;                                          // used for saving data
  182. bool     measurement_mode;                                   // flag that controls measurements and data saving
  183.  
  184. //---------------------------------------------------------------------------//
  185. // C++ Mersenne Twister 19937 generator                                      //
  186. // R01(MTgen) will genarate uniform distribution over [0,1) interval         //
  187. // RMB(MTgen) will generate Maxwell-Boltzmann distribution (of gas atoms)    //
  188. //---------------------------------------------------------------------------//
  189.  
  190. std::random_device rd{};
  191. std::mt19937 MTgen(rd());
  192. std::uniform_real_distribution<> R01(0.0, 1.0);
  193. std::normal_distribution<> RMB_n(0.0,sqrt(K_BOLTZMANN * T_neutral / HE_MASS));
  194. std::normal_distribution<> RMB_e(0.0,sqrt(K_BOLTZMANN * T_electron / E_MASS));
  195.  
  196. //----------------------------------------------------------------------------//
  197. //  electron cross sections: A V Phelps & Z Lj Petrovic, PSST 8 R21 (1999)    //
  198. //----------------------------------------------------------------------------//
  199.  
  200. class CSInterpolator {
  201. public:
  202.   // load "filename" which must have two whitespace‐separated columns:
  203.   //    energy (eV)    cross_section (in m^2 or cm^2 as you prefer)
  204.   CSInterpolator(const std::string &filename) {
  205.     std::ifstream in(filename);
  206.     if (!in) throw std::runtime_error("CSInterpolator: cannot open " + filename);
  207.     double E, sigma;
  208.     std::string line;
  209.     while (std::getline(in, line)) {
  210.       std::istringstream iss(line);
  211.       if (iss >> E >> sigma) {
  212.         E_pts_.push_back(E);
  213.         sigma_pts_.push_back(sigma);
  214.       }
  215.     }
  216.     if (E_pts_.size()<2)
  217.       throw std::runtime_error("CSInterpolator: need at least two data points in " + filename);
  218.   }
  219.  
  220.   // return σ(E) by simple linear interpolation (clamped to end‐points)
  221.   double operator()(double E) const {
  222.     auto it = std::lower_bound(E_pts_.begin(), E_pts_.end(), E);
  223.     if (it == E_pts_.begin()) {
  224.         std::cerr << "Warning: E="<<E<<" below data range, clamping to "<< 0.0 <<"\n";
  225.         return 0.0;
  226.     }  
  227.     if (it == E_pts_.end()){
  228.         std::cerr << "Warning: E="<<E<<" above data range, clamping to "<< sigma_pts_.back() <<"\n";
  229.         return sigma_pts_.back();
  230.     }    
  231.     size_t idx = (it - E_pts_.begin());
  232.     double E1 = E_pts_[idx-1], E2 = E_pts_[idx];
  233.     double s1 = sigma_pts_[idx-1], s2 = sigma_pts_[idx];
  234.     // linear interp
  235.     return s1 + (s2 - s1) * (E - E1)/(E2 - E1);
  236.   }
  237.  
  238. private:
  239.   std::vector<double> E_pts_, sigma_pts_;
  240. };
  241.  
  242. void set_electron_cross_sections_ar(void){
  243.     int    i;
  244.     double en,qmel,qexc_1,qexc_2,qion;
  245.    
  246.     printf(">> eduPIC: Setting e- / He cross sections\n");
  247.  
  248.     // load your four datafiles (make sure these names match your files!)
  249.     CSInterpolator cs_ela  ("CS/He_electron_elastic.dat");   // two‐col: E σ_ela
  250.     CSInterpolator cs_exc1 ("CS/He_electron_exc1.dat");      // two‐col: E σ_exc1
  251.     CSInterpolator cs_exc2 ("CS/He_electron_exc2.dat");      // two‐col: E σ_exc2
  252.     CSInterpolator cs_ion  ("CS/He_electron_ionization.dat");// two‐col: E σ_ion
  253.  
  254.     for(int i=0; i<CS_RANGES; i++){
  255.         // your energy grid
  256.         double en = (i==0 ? DE_CS : DE_CS * i);
  257.  
  258.         // interpolate
  259.         sigma[E_ELA][i]   = cs_ela(en);
  260.         sigma[E_EXC_1][i] = cs_exc1(en);
  261.         sigma[E_EXC_2][i] = cs_exc2(en);
  262.         sigma[E_ION][i]   = cs_ion(en);
  263.  
  264.         // Superelastic for triplet (E_SUPER_1)
  265.         double en_plus_1 = en + E_EXC_TH_1;
  266.         int idx1 = en_plus_1 / DE_CS;
  267.         if (idx1 < CS_RANGES && en > 0) {
  268.             sigma[E_SUPER_1][i] = (1.0 / 3.0) * (en_plus_1 / en) * sigma[E_EXC_1][idx1];
  269.         } else {
  270.             sigma[E_SUPER_1][i] = 0.0;
  271.         }        
  272.  
  273.         // Superelastic for singlet (E_SUPER_2)
  274.         double en_plus_2 = en + E_EXC_TH_2;
  275.         int idx2 = en_plus_2 / DE_CS;
  276.         if (idx2 < CS_RANGES && en > 0) {
  277.             sigma[E_SUPER_2][i] = (1.0 / 1.0) * (en_plus_2 / en) * sigma[E_EXC_2][idx2];
  278.         } else {
  279.             sigma[E_SUPER_2][i] = 0.0;
  280.         }        
  281.     }
  282.  
  283.     for(int i=0; i<CS_RANGES; i++){
  284.         // your energy grid
  285.         double en = (i==0 ? DE_CS : DE_CS * i);
  286.  
  287.         // Superelastic for triplet (E_SUPER_1)
  288.         double en_plus_1 = en + E_EXC_TH_1;
  289.         int idx1 = en_plus_1 / DE_CS;
  290.         if (idx1 < CS_RANGES && en > 0) {
  291.             sigma[E_SUPER_1][i] = (1.0 / 3.0) * (en_plus_1 / en) * sigma[E_EXC_1][idx1];
  292.         } else {
  293.             sigma[E_SUPER_1][i] = 0.0;
  294.         }        
  295.  
  296.         // Superelastic for singlet (E_SUPER_2)
  297.         double en_plus_2 = en + E_EXC_TH_2;
  298.         int idx2 = en_plus_2 / DE_CS;
  299.         if (idx2 < CS_RANGES && en > 0) {
  300.             sigma[E_SUPER_2][i] = (1.0 / 1.0) * (en_plus_2 / en) * sigma[E_EXC_2][idx2];
  301.         } else {
  302.             sigma[E_SUPER_2][i] = 0.0;
  303.         }        
  304.     }    
  305.  
  306. }
  307.  
  308. //------------------------------------------------------------------------------//
  309. //  ion cross sections: A. V. Phelps, J. Appl. Phys. 76, 747 (1994)             //
  310. //------------------------------------------------------------------------------//
  311.  
  312. void set_ion_cross_sections_ar(void){
  313.     int    i;
  314.     double e_com,e_lab,qmom,qback,qiso;
  315.    
  316.     printf(">> eduPIC: Setting He+ / He cross sections\n");
  317.     for(i=0; i<CS_RANGES; i++){
  318.         if (i == 0) {e_com = DE_CS;} else {e_com = DE_CS * i;}             // ion energy in the center of mass frame of reference
  319.         e_lab = 2.0 * e_com;                                               // ion energy in the laboratory frame of reference
  320.         qiso  = 7.63 *pow(10,-20) * pow(e_com, -0.5);
  321.         qback = 1.0 * pow(10,-19) * pow( (e_com/1000.0), -0.15 ) * pow( (1.0 + e_com/1000.0), -0.25 ) * pow( (1.0 + 5.0/e_com), -0.15 );
  322.         sigma[I_ISO][i]  = qiso;             // cross section for He+ / He isotropic part of elastic scattering
  323.         sigma[I_BACK][i] = qback;            // cross section for He+ / He backward elastic scattering
  324.     }
  325. }
  326.  
  327. //----------------------------------------------------------------------//
  328. //  calculation of total cross sections for electrons and ions          //
  329. //----------------------------------------------------------------------//
  330.  
  331. void calc_total_cross_sections(void){
  332.     int i;
  333.    
  334.     for(i=0; i<CS_RANGES; i++){
  335.         sigma_tot_e[i] = (sigma[E_ELA][i] + sigma[E_EXC_1][i] + sigma[E_EXC_2][i] + sigma[E_ION][i]) * GAS_DENSITY;   // total macroscopic cross section of electrons
  336.         sigma_tot_i[i] = (sigma[I_ISO][i] + sigma[I_BACK][i]) * GAS_DENSITY;                    // total macroscopic cross section of ions
  337.     }
  338. }
  339.  
  340. //----------------------------------------------------------------------//
  341. //  test of cross sections for electrons and ions                       //
  342. //----------------------------------------------------------------------//
  343.  
  344. void test_cross_sections(void){
  345.     FILE  * f;
  346.     int   i,j;
  347.    
  348.     f = fopen("cross_sections.dat","w");        // cross sections saved in data file: cross_sections.dat
  349.     for(i=0; i<CS_RANGES; i++){
  350.         fprintf(f,"%12.4f ",i*DE_CS);
  351.         for(j=0; j<N_CS; j++) fprintf(f,"%14e ",sigma[j][i]);
  352.         fprintf(f,"\n");
  353.     }
  354.     fclose(f);
  355. }
  356.  
  357. //---------------------------------------------------------------------//
  358. // find upper limit of collision frequencies                           //
  359. //---------------------------------------------------------------------//
  360.  
  361. double max_electron_coll_freq (void){
  362.     int i;
  363.     double e,v,nu,nu_max;
  364.     nu_max = 0;
  365.     for(i=0; i<CS_RANGES; i++){
  366.         e  = i * DE_CS;
  367.         v  = sqrt(2.0 * e * EV_TO_J / E_MASS);
  368.         nu = v * sigma_tot_e[i];
  369.         if (nu > nu_max) {nu_max = nu;}
  370.     }
  371.     return nu_max;
  372. }
  373.  
  374. double max_ion_coll_freq (void){
  375.     int i;
  376.     double e,g,nu,nu_max;
  377.     nu_max = 0;
  378.     for(i=0; i<CS_RANGES; i++){
  379.         e  = i * DE_CS;
  380.         g  = sqrt(2.0 * e * EV_TO_J / MU_HEHE);
  381.         nu = g * sigma_tot_i[i];
  382.         if (nu > nu_max) nu_max = nu;
  383.     }
  384.     return nu_max;
  385. }
  386.  
  387. //----------------------------------------------------------------------//
  388. // initialization of the simulation by placing a given number of        //
  389. // electrons and ions at random positions between the electrodes        //
  390. //----------------------------------------------------------------------//
  391.  
  392. // initialization of excited states distribtuion, assuming Maxwellian-Boltzmann balance -- Artem
  393. std::pair<int, int> init_excited_distr() {
  394.     double part_ground = 1.0*exp(-0.0/T_neutral); // partition function for ground state
  395.     double part_triplet = 3.0*exp(-E_EXC_TH_1*EV_TO_J/(K_BOLTZMANN*T_neutral)); // partition function for triplet excited state
  396.     double part_singlet = 1.0*exp(-E_EXC_TH_2*EV_TO_J/(K_BOLTZMANN*T_neutral)); // partition function for singlet excited state
  397.     double part_func_total = part_ground + part_triplet + part_singlet; // total partition function
  398.     double n_triplet = ((part_triplet/part_func_total)*GAS_DENSITY); // denisty population of tripet state
  399.     double n_singlet = ((part_singlet/part_func_total)*GAS_DENSITY); // density population of singlet state
  400.  
  401.     return {n_triplet, n_singlet};
  402. }
  403.  
  404. void print_excitation_densities(void) {
  405.     double total_e1 = 0.0, total_e2 = 0.0;
  406.     const double cell_volume = ELECTRODE_AREA * DX;
  407.    
  408.     // Sum densities across all grid cells
  409.     for (int p = 0; p < N_G; p++) {
  410.         total_e1 += e1_density[p];  // triplet state density
  411.         total_e2 += e2_density[p];  // singlet state density
  412.     }
  413.    
  414.     printf("Triplet SP = %8.2e | Singlet SP = %8.2e\n", total_e1, total_e2);
  415. }
  416.  
  417.  
  418. void init(int nseed){
  419.     int i;
  420.    
  421.     for (i=0; i<nseed; i++){
  422.         x_e[i]  = L * R01(MTgen);                                                   // initial random position of the electron
  423.         vx_e[i] = RMB_e(MTgen); vy_e[i] = RMB_e(MTgen); vz_e[i] = RMB_e(MTgen);     // initial velocity components of the electron
  424.         x_i[i]  = L * R01(MTgen);                                                   // initial random position of the ion
  425.         vx_i[i] = RMB_n(MTgen); vy_i[i] = RMB_n(MTgen); vz_i[i] = RMB_n(MTgen);     // initial velocity components of the ion
  426.     }
  427.     N_e = nseed;    // initial number of electrons
  428.     N_i = nseed;    // initial number of ions
  429.  
  430.     auto exc = init_excited_distr();
  431.     for (int p = 0; p < N_G; p++) {
  432.         e1_density[p] = exc.first;
  433.         e2_density[p] = exc.second;
  434.     }
  435. }
  436.  
  437.  
  438.  
  439. //----------------------------------------------------------------------//
  440. // e / He collision  (cold gas approximation)                           //
  441. //----------------------------------------------------------------------//
  442.  
  443. void collision_electron (double xe, double *vxe, double *vye, double *vze, int eindex){
  444.     const double F1 = E_MASS  / (E_MASS + HE_MASS);
  445.     const double F2 = HE_MASS / (E_MASS + HE_MASS);
  446.     double t0,t1,t2,t3,t4,t5,rnd;
  447.     double g,g2,gx,gy,gz,wx,wy,wz,theta,phi;
  448.     double chi,eta,chi2,eta2,sc,cc,se,ce,st,ct,sp,cp,energy,e_sc,e_ej;
  449.  
  450.     // - Artem
  451.     // Determine cell p where the electron is
  452.     double c0 = xe * INV_DX;
  453.     int p = std::max(0, std::min(N_G - 1, static_cast<int>(c0)));
  454.  
  455.     // Local densities -- Artem
  456.     double e1_dens = e1_density[p];
  457.     double e2_dens = e2_density[p];
  458.     double ground_dens = GAS_DENSITY - e1_dens - e2_dens;    
  459.  
  460.    
  461.     // calculate relative velocity before collision & velocity of the centre of mass
  462.    
  463.     gx = (*vxe);
  464.     gy = (*vye);
  465.     gz = (*vze);
  466.     g  = sqrt(gx * gx + gy * gy + gz * gz);
  467.     wx = F1 * (*vxe);
  468.     wy = F1 * (*vye);
  469.     wz = F1 * (*vze);
  470.    
  471.     // find Euler angles
  472.    
  473.     if (gx == 0) {theta = 0.5 * PI;}
  474.     else {theta = atan2(sqrt(gy * gy + gz * gz),gx);}
  475.     if (gy == 0) {
  476.         if (gz > 0){phi = 0.5 * PI;} else {phi = - 0.5 * PI;}
  477.     } else {phi = atan2(gz, gy);}
  478.     st  = sin(theta);
  479.     ct  = cos(theta);
  480.     sp  = sin(phi);
  481.     cp  = cos(phi);
  482.    
  483.     // choose the type of collision based on the cross sections
  484.     // take into account energy loss in inelastic collisions
  485.     // generate scattering and azimuth angles
  486.     // in case of ionization handle the 'new' electron
  487.    
  488.     t0   =      sigma[E_ELA][eindex] * ground_dens;
  489.     t1   = t0 + sigma[E_EXC_1][eindex] * ground_dens;
  490.     t2   = t1 + sigma[E_EXC_2][eindex] * ground_dens;
  491.     t3   = t2 + sigma[E_ION][eindex] * ground_dens;
  492.     t4   = t3 + sigma[E_SUPER_1][eindex]  * e1_dens;   // account for superelastic triplet - Artem
  493.     t5   = t4 + sigma[E_SUPER_2][eindex] * e2_dens;   // account for superelastic singlet- Artem
  494.  
  495.     rnd  = R01(MTgen);
  496.     if (rnd < (t0/t5)){                              // elastic scattering
  497.         chi = acos(1.0 - 2.0 * R01(MTgen));          // isotropic scattering
  498.         eta = TWO_PI * R01(MTgen);                   // azimuthal angle
  499.  
  500.     } else if (rnd < (t1/t5)){                       // excitation 1 (triplet)
  501.         energy = 0.5 * E_MASS * g * g;               // electron energy
  502.         energy = fabs(energy - E_EXC_TH_1 * EV_TO_J);  // subtract energy loss for excitation
  503.         g   = sqrt(2.0 * energy / E_MASS);           // relative velocity after energy loss
  504.         chi = acos(1.0 - 2.0 * R01(MTgen));          // isotropic scattering
  505.         eta = TWO_PI * R01(MTgen);                   // azimuthal angle
  506.  
  507.         //add new triplet excited He atom density to this grid point, sample velocities from Maxwellian distribution - Artem
  508.         e1_density[p] += WEIGHT / (ELECTRODE_AREA * DX);
  509.  
  510.     } else if (rnd < (t2/t5)){                       // excitation 2 (singlet)
  511.         energy = 0.5 * E_MASS * g * g;               // electron energy
  512.         energy = fabs(energy - E_EXC_TH_2 * EV_TO_J);  // subtract energy loss for excitation
  513.         g   = sqrt(2.0 * energy / E_MASS);           // relative velocity after energy loss
  514.         chi = acos(1.0 - 2.0 * R01(MTgen));          // isotropic scattering
  515.         eta = TWO_PI * R01(MTgen);                   // azimuthal angle    
  516.  
  517.         //add new singet excited He atom, sample velocities from Maxwellian distribution - Artem
  518.         e2_density[p] += WEIGHT / (ELECTRODE_AREA * DX);
  519.  
  520.     } else if (rnd < (t3/t5)) {                                         // ionization
  521.         energy = 0.5 * E_MASS * g * g;               // electron energy
  522.         energy = fabs(energy - E_ION_TH * EV_TO_J);  // subtract energy loss of ionization
  523.         // e_ej  = 10.0 * tan(R01(MTgen) * atan(energy/EV_TO_J / 20.0)) * EV_TO_J; // energy of the ejected electron
  524.         // e_sc = fabs(energy - e_ej);                  // energy of scattered electron after the collision
  525.         e_ej = 0.5*energy;                          // energy of the ejected electron
  526.         e_sc = fabs(energy - e_ej);                  // energy of scattered electron after the collision        
  527.         g    = sqrt(2.0 * e_sc / E_MASS);            // relative velocity of scattered electron
  528.         g2   = sqrt(2.0 * e_ej / E_MASS);            // relative velocity of ejected electron
  529.         // chi  = acos(sqrt(e_sc / energy));            // scattering angle for scattered electron
  530.         // chi2 = acos(sqrt(e_ej / energy));            // scattering angle for ejected electrons
  531.         chi = acos(1.0 - 2.0 * R01(MTgen));          // isotropic scattering for scattered electron (as in Turner's case)
  532.         chi2 = acos(1.0 - 2.0 * R01(MTgen));          // isotropic scattering for ejected electrons (as in Turner's case)
  533.         eta  = TWO_PI * R01(MTgen);                  // azimuthal angle for scattered electron
  534.         eta2 = eta + PI;                             // azimuthal angle for ejected electron
  535.         sc  = sin(chi2);
  536.         cc  = cos(chi2);
  537.         se  = sin(eta2);
  538.         ce  = cos(eta2);
  539.         gx  = g2 * (ct * cc - st * sc * ce);
  540.         gy  = g2 * (st * cp * cc + ct * cp * sc * ce - sp * sc * se);
  541.         gz  = g2 * (st * sp * cc + ct * sp * sc * ce + cp * sc * se);
  542.         x_e[N_e]  = xe;                              // add new electron
  543.         vx_e[N_e] = wx + F2 * gx;
  544.         vy_e[N_e] = wy + F2 * gy;
  545.         vz_e[N_e] = wz + F2 * gz;
  546.         N_e++;
  547.         x_i[N_i]  = xe;                              // add new ion
  548.         vx_i[N_i] = RMB_n(MTgen);                      // velocity is sampled from background thermal distribution
  549.         vy_i[N_i] = RMB_n(MTgen);
  550.         vz_i[N_i] = RMB_n(MTgen);
  551.         N_i++;
  552.     }
  553.      else if (rnd < (t4/t5)) {                      // accounting for superelastic collisions - triplet - Artem
  554.         energy = 0.5 * E_MASS * g * g;               // electron energy
  555.         energy = fabs(energy + E_EXC_TH_1 * EV_TO_J);  // add energy for deexcitation
  556.         g   = sqrt(2.0 * energy / E_MASS);           // relative velocity after energy loss
  557.         chi = acos(1.0 - 2.0 * R01(MTgen));          // isotropic scattering
  558.         eta = TWO_PI * R01(MTgen);                   // azimuthal angle    
  559.  
  560.         //substract  excited He atom density from the grid point - Artem
  561.         e1_density[p] = std::max(e1_density[p] - WEIGHT / (ELECTRODE_AREA * DX), 0.0);
  562.    
  563.     } else {                                         // account for supeelastic collision - singlet - Artem
  564.         energy = 0.5 * E_MASS * g * g;               // electron energy
  565.         energy = fabs(energy + E_EXC_TH_2 * EV_TO_J);  // add energy for deexcitation
  566.         g   = sqrt(2.0 * energy / E_MASS);           // relative velocity after energy loss
  567.         chi = acos(1.0 - 2.0 * R01(MTgen));          // isotropic scattering
  568.         eta = TWO_PI * R01(MTgen);                   // azimuthal angle    
  569.  
  570.         //substract  excited He atom density from the grid point - Artem
  571.         e2_density[p] = std::max(e2_density[p] - WEIGHT / (ELECTRODE_AREA * DX), 0.0);
  572.     }
  573.  
  574.    
  575.     // scatter the primary electron
  576.    
  577.     sc = sin(chi);
  578.     cc = cos(chi);
  579.     se = sin(eta);
  580.     ce = cos(eta);
  581.    
  582.     // compute new relative velocity:
  583.    
  584.     gx = g * (ct * cc - st * sc * ce);
  585.     gy = g * (st * cp * cc + ct * cp * sc * ce - sp * sc * se);
  586.     gz = g * (st * sp * cc + ct * sp * sc * ce + cp * sc * se);
  587.    
  588.     // post-collision velocity of the colliding electron
  589.    
  590.     (*vxe) = wx + F2 * gx;
  591.     (*vye) = wy + F2 * gy;
  592.     (*vze) = wz + F2 * gz;
  593. }
  594.  
  595. //----------------------------------------------------------------------//
  596. // He+ / He collision                                                   //
  597. //----------------------------------------------------------------------//
  598.  
  599. void collision_ion (double *vx_1, double *vy_1, double *vz_1,
  600.                     double *vx_2, double *vy_2, double *vz_2, int e_index){
  601.     double   g,gx,gy,gz,wx,wy,wz,rnd;
  602.     double   theta,phi,chi,eta,st,ct,sp,cp,sc,cc,se,ce,t1,t2;
  603.    
  604.     // calculate relative velocity before collision
  605.     // random Maxwellian target atom already selected (vx_2,vy_2,vz_2 velocity components of target atom come with the call)
  606.    
  607.     gx = (*vx_1)-(*vx_2);
  608.     gy = (*vy_1)-(*vy_2);
  609.     gz = (*vz_1)-(*vz_2);
  610.     g  = sqrt(gx * gx + gy * gy + gz * gz);
  611.     wx = 0.5 * ((*vx_1) + (*vx_2));
  612.     wy = 0.5 * ((*vy_1) + (*vy_2));
  613.     wz = 0.5 * ((*vz_1) + (*vz_2));
  614.    
  615.     // find Euler angles
  616.    
  617.     if (gx == 0) {theta = 0.5 * PI;} else {theta = atan2(sqrt(gy * gy + gz * gz),gx);}
  618.     if (gy == 0) {
  619.         if (gz > 0){phi = 0.5 * PI;} else {phi = - 0.5 * PI;}
  620.     } else {phi = atan2(gz, gy);}
  621.    
  622.     // determine the type of collision based on cross sections and generate scattering angle
  623.    
  624.     t1  =      sigma[I_ISO][e_index];
  625.     t2  = t1 + sigma[I_BACK][e_index];
  626.     rnd = R01(MTgen);
  627.     if  (rnd < (t1 /t2)){                        // isotropic scattering
  628.         chi = acos(1.0 - 2.0 * R01(MTgen));      // scattering angle
  629.     } else {                                     // backward scattering
  630.         chi = PI;                                // scattering angle
  631.     }
  632.     eta = TWO_PI * R01(MTgen);                   // azimuthal angle
  633.     sc  = sin(chi);
  634.     cc  = cos(chi);
  635.     se  = sin(eta);
  636.     ce  = cos(eta);
  637.     st  = sin(theta);
  638.     ct  = cos(theta);
  639.     sp  = sin(phi);
  640.     cp  = cos(phi);
  641.    
  642.     // compute new relative velocity
  643.    
  644.     gx = g * (ct * cc - st * sc * ce);
  645.     gy = g * (st * cp * cc + ct * cp * sc * ce - sp * sc * se);
  646.     gz = g * (st * sp * cc + ct * sp * sc * ce + cp * sc * se);
  647.    
  648.     // post-collision velocity of the ion
  649.    
  650.     (*vx_1) = wx + 0.5 * gx;
  651.     (*vy_1) = wy + 0.5 * gy;
  652.     (*vz_1) = wz + 0.5 * gz;
  653. }
  654.  
  655. //-----------------------------------------------------------------//
  656. // solve Poisson equation (Thomas algorithm)                       //
  657. //-----------------------------------------------------------------//
  658.  
  659. void solve_Poisson (xvector rho1, double tt){
  660.     const double A =  1.0;
  661.     const double B = -2.0;
  662.     const double C =  1.0;
  663.     const double S = 1.0 / (2.0 * DX);
  664.     const double ALPHA = -DX * DX / EPSILON0;
  665.     xvector      g, w, f;
  666.     int          i;
  667.    
  668.     // apply potential to the electrodes - boundary conditions
  669.    
  670.     pot[0]     = VOLTAGE * cos(OMEGA * tt);         // potential at the powered electrode
  671.     pot[N_G-1] = 0.0;                               // potential at the grounded electrode
  672.    
  673.     // solve Poisson equation
  674.    
  675.     for(i=1; i<=N_G-2; i++) f[i] = ALPHA * rho1[i];
  676.     f[1] -= pot[0];
  677.     f[N_G-2] -= pot[N_G-1];
  678.     w[1] = C/B;
  679.     g[1] = f[1]/B;
  680.     for(i=2; i<=N_G-2; i++){
  681.         w[i] = C / (B - A * w[i-1]);
  682.         g[i] = (f[i] - A * g[i-1]) / (B - A * w[i-1]);
  683.     }
  684.     pot[N_G-2] = g[N_G-2];
  685.     for (i=N_G-3; i>0; i--) pot[i] = g[i] - w[i] * pot[i+1];            // potential at the grid points between the electrodes
  686.    
  687.     // compute electric field
  688.    
  689.     for(i=1; i<=N_G-2; i++) efield[i] = (pot[i-1] - pot[i+1]) * S;      // electric field at the grid points between the electrodes
  690.     efield[0]     = (pot[0]     - pot[1])     * INV_DX - rho1[0]     * DX / (2.0 * EPSILON0);   // powered electrode
  691.     efield[N_G-1] = (pot[N_G-2] - pot[N_G-1]) * INV_DX + rho1[N_G-1] * DX / (2.0 * EPSILON0);   // grounded electrode
  692. }
  693.  
  694. //---------------------------------------------------------------------//
  695. // simulation of one radiofrequency cycle                              //
  696. //---------------------------------------------------------------------//
  697.  
  698. void do_one_cycle (void){
  699.     const double DV       = ELECTRODE_AREA * DX;
  700.     const double FACTOR_W = WEIGHT / DV;
  701.     const double FACTOR_E = DT_E / E_MASS * E_CHARGE;
  702.     const double FACTOR_I = DT_I / HE_MASS * E_CHARGE;
  703.     const double MIN_X    = 0.45 * L;                       // min. position for EEPF collection
  704.     const double MAX_X    = 0.55 * L;                       // max. position for EEPF collection
  705.     int      k, t, p, energy_index;
  706.     double   g, g_sqr, gx, gy, gz, vx_a, vy_a, vz_a, e_x, energy, nu, p_coll, v_sqr, velocity;
  707.     double   mean_v, c0, c1, c2, rate;
  708.     bool     out;
  709.     xvector  rho;
  710.     int      t_index;
  711.  
  712.    
  713.     for (t=0; t<N_T; t++){          // the RF period is divided into N_T equal time intervals (time step DT_E)
  714.         Time += DT_E;               // update of the total simulated time
  715.         t_index = t / N_BIN;        // index for XT distributions
  716.        
  717.         // step 1: compute densities at grid points
  718.        
  719.         for(p=0; p<N_G; p++) e_density[p] = 0;                             // electron density - computed in every time step
  720.         for(k=0; k<N_e; k++){
  721.  
  722.             if      (p < 0)        p = 0;
  723.             else if (p > N_G - 2)  p = N_G - 2;
  724.             c0 = x_e[k] * INV_DX;
  725.             p  = int(c0);
  726.             e_density[p]   += (p + 1 - c0) * FACTOR_W;
  727.             e_density[p+1] += (c0 - p) * FACTOR_W;
  728.         }
  729.         e_density[0]     *= 2.0; // double at the edge bcs working with half-domain (no left/right neighbour)
  730.         e_density[N_G-1] *= 2.0;
  731.         for(p=0; p<N_G; p++) cumul_e_density[p] += e_density[p];
  732.        
  733.         if ((t % N_SUB) == 0) {                                            // ion density - computed in every N_SUB-th time steps (subcycling)
  734.             for(p=0; p<N_G; p++) i_density[p] = 0;
  735.             for(k=0; k<N_i; k++){
  736.                 c0 = x_i[k] * INV_DX;
  737.                 p  = int(c0);
  738.                 i_density[p]   += (p + 1 - c0) * FACTOR_W;  
  739.                 i_density[p+1] += (c0 - p) * FACTOR_W;
  740.             }
  741.             i_density[0]     *= 2.0; // double at the edge bcs working with half-domain (no left/right neighbour)
  742.             i_density[N_G-1] *= 2.0;
  743.         }
  744.         for(p=0; p<N_G; p++) cumul_i_density[p] += i_density[p];
  745.        
  746.         // step 2: solve Poisson equation
  747.        
  748.         for(p=0; p<N_G; p++) rho[p] = E_CHARGE * (i_density[p] - e_density[p]);  // get charge density
  749.         solve_Poisson(rho,Time);                                                 // compute potential and electric field
  750.        
  751.         // steps 3 & 4: move particles according to electric field interpolated to particle positions
  752.        
  753.         for(k=0; k<N_e; k++){                       // move all electrons in every time step
  754.             c0  = x_e[k] * INV_DX;
  755.             p   = int(c0);
  756.             c1  = p + 1.0 - c0;
  757.             c2  = c0 - p;
  758.             e_x = c1 * efield[p] + c2 * efield[p+1];
  759.            
  760.             if (measurement_mode) {
  761.                
  762.                 // measurements: 'x' and 'v' are needed at the same time, i.e. old 'x' and mean 'v'
  763.                
  764.                 mean_v = vx_e[k] - 0.5 * e_x * FACTOR_E;
  765.                 counter_e_xt[p][t_index]   += c1;
  766.                 counter_e_xt[p+1][t_index] += c2;
  767.                 ue_xt[p][t_index]   += c1 * mean_v;
  768.                 ue_xt[p+1][t_index] += c2 * mean_v;
  769.                 v_sqr  = mean_v * mean_v + vy_e[k] * vy_e[k] + vz_e[k] * vz_e[k];
  770.                 energy = 0.5 * E_MASS * v_sqr / EV_TO_J;
  771.                 meanee_xt[p][t_index]   += c1 * energy;
  772.                 meanee_xt[p+1][t_index] += c2 * energy;
  773.                 energy_index = min( int(energy / DE_CS + 0.5), CS_RANGES-1);
  774.                 velocity = sqrt(v_sqr);
  775.                 double local_neut_dens = GAS_DENSITY - e1_density[p] - e2_density[p];
  776.                 rate = sigma[E_ION][energy_index] * velocity * DT_E * GAS_DENSITY;
  777.                 ioniz_rate_xt[p][t_index]   += c1 * rate;
  778.                 ioniz_rate_xt[p+1][t_index] += c2 * rate;
  779.  
  780.                 // measure EEPF in the center
  781.                
  782.                 if ((MIN_X < x_e[k]) && (x_e[k] < MAX_X)){
  783.                     energy_index = (int)(energy / DE_EEPF);
  784.                     if (energy_index < N_EEPF) {eepf[energy_index] += 1.0;}
  785.                     mean_energy_accu_center += energy;
  786.                     mean_energy_counter_center++;
  787.                 }
  788.             }
  789.            
  790.             // update velocity and position
  791.            
  792.             vx_e[k] -= e_x * FACTOR_E;
  793.             x_e[k]  += vx_e[k] * DT_E;
  794.         }
  795.        
  796.         if ((t % N_SUB) == 0) {                       // move all ions in every N_SUB-th time steps (subcycling)
  797.             for(k=0; k<N_i; k++){
  798.                 c0  = x_i[k] * INV_DX;
  799.                 p   = int(c0);
  800.                 c1  = p + 1 - c0;
  801.                 c2  = c0 - p;
  802.                 e_x = c1 * efield[p] + c2 * efield[p+1];
  803.                
  804.                 if (measurement_mode) {
  805.                    
  806.                     // measurements: 'x' and 'v' are needed at the same time, i.e. old 'x' and mean 'v'
  807.  
  808.                     mean_v = vx_i[k] + 0.5 * e_x * FACTOR_I;
  809.                     counter_i_xt[p][t_index]   += c1;
  810.                     counter_i_xt[p+1][t_index] += c2;
  811.                     ui_xt[p][t_index]   += c1 * mean_v;
  812.                     ui_xt[p+1][t_index] += c2 * mean_v;
  813.                     v_sqr  = mean_v * mean_v + vy_i[k] * vy_i[k] + vz_i[k] * vz_i[k];
  814.                     energy = 0.5 * HE_MASS * v_sqr / EV_TO_J;
  815.                     meanei_xt[p][t_index]   += c1 * energy;
  816.                     meanei_xt[p+1][t_index] += c2 * energy;
  817.                 }
  818.                
  819.                 // update velocity and position and accumulate absorbed energy
  820.                
  821.                 vx_i[k] += e_x * FACTOR_I;
  822.                 x_i[k]  += vx_i[k] * DT_I;
  823.             }
  824.         }
  825.        
  826.         // step 5: check boundaries
  827.        
  828.         k = 0;
  829.         while(k < N_e) {    // check boundaries for all electrons in every time step
  830.             out = false;
  831.             if (x_e[k] < 0) {N_e_abs_pow++; out = true;}    // the electron is out at the powered electrode
  832.             if (x_e[k] > L) {N_e_abs_gnd++; out = true;}    // the electron is out at the grounded electrode
  833.             if (out) {                                      // remove the electron, if out
  834.                 x_e [k] = x_e [N_e-1]; // pushing last element on a vacant place
  835.                 vx_e[k] = vx_e[N_e-1];
  836.                 vy_e[k] = vy_e[N_e-1];
  837.                 vz_e[k] = vz_e[N_e-1];
  838.                 N_e--;
  839.             } else k++;
  840.         }
  841.        
  842.         if ((t % N_SUB) == 0) {   // check boundaries for all ions in every N_SUB-th time steps (subcycling)
  843.             k = 0;
  844.             while(k < N_i) {
  845.                 out = false;
  846.                 if (x_i[k] < 0) {       // the ion is out at the powered electrode
  847.                     N_i_abs_pow++;
  848.                     out    = true;
  849.                     v_sqr  = vx_i[k] * vx_i[k] + vy_i[k] * vy_i[k] + vz_i[k] * vz_i[k];
  850.                     energy = 0.5 * HE_MASS *  v_sqr/ EV_TO_J;
  851.                     energy_index = (int)(energy / DE_IFED);
  852.                     if (energy_index < N_IFED) {ifed_pow[energy_index]++;}       // save IFED at the powered electrode
  853.                 }
  854.                 if (x_i[k] > L) {       // the ion is out at the grounded electrode
  855.                     N_i_abs_gnd++;
  856.                     out    = true;
  857.                     v_sqr  = vx_i[k] * vx_i[k] + vy_i[k] * vy_i[k] + vz_i[k] * vz_i[k];
  858.                     energy = 0.5 * HE_MASS * v_sqr / EV_TO_J;
  859.                     energy_index = (int)(energy / DE_IFED);
  860.                     if (energy_index < N_IFED) {ifed_gnd[energy_index]++;}        // save IFED at the grounded electrode
  861.                 }
  862.                 if (out) {  // delete the ion, if out
  863.                     x_i [k] = x_i [N_i-1];
  864.                     vx_i[k] = vx_i[N_i-1];
  865.                     vy_i[k] = vy_i[N_i-1];
  866.                     vz_i[k] = vz_i[N_i-1];
  867.                     N_i--;
  868.                 } else k++;
  869.             }
  870.         }
  871.        
  872.         // step 6: collisions
  873.        
  874.         for (k=0; k<N_e; k++){                              // checking for occurrence of a collision for all electrons in every time step
  875.             v_sqr = vx_e[k] * vx_e[k] + vy_e[k] * vy_e[k] + vz_e[k] * vz_e[k];
  876.             velocity = sqrt(v_sqr);
  877.             energy   = 0.5 * E_MASS * v_sqr / EV_TO_J;
  878.             energy_index = min( int(energy / DE_CS + 0.5), CS_RANGES-1);
  879.  
  880.             // Artem  - adding superelastic impact on total collisoinal probability//
  881.  
  882.             double c0_temp = x_e[k] * INV_DX;
  883.             int p_temp = std::max(0, std::min(N_G - 1, static_cast<int>(c0_temp)));
  884.             double sigma_super_e = sigma[E_SUPER_1][energy_index] * e1_density[p_temp] + sigma[E_SUPER_2][energy_index] * e2_density[p_temp];
  885.             double ground_dens_local = GAS_DENSITY - e1_density[p_temp] - e2_density[p_temp];
  886.             double sigma_ground = (sigma[E_ELA][energy_index] + sigma[E_EXC_1][energy_index] +
  887.                                 sigma[E_EXC_2][energy_index] + sigma[E_ION][energy_index]) * ground_dens_local;
  888.             nu = (sigma_ground + sigma_super_e) * velocity;
  889.            
  890.             p_coll = 1 - exp(- nu * DT_E);                  // collision probability for electrons
  891.             if (R01(MTgen) < p_coll) {                      // electron collision takes place
  892.                 collision_electron(x_e[k], &vx_e[k], &vy_e[k], &vz_e[k], energy_index);
  893.                 N_e_coll++;
  894.             }
  895.         }
  896.        
  897.         if ((t % N_SUB) == 0) {                             // checking for occurrence of a collision for all ions in every N_SUB-th time steps (subcycling)
  898.             for (k=0; k<N_i; k++){
  899.                 vx_a = RMB_n(MTgen);                          // pick velocity components of a random target gas atom
  900.                 vy_a = RMB_n(MTgen);
  901.                 vz_a = RMB_n(MTgen);
  902.                 gx   = vx_i[k] - vx_a;                       // compute the relative velocity of the collision partners
  903.                 gy   = vy_i[k] - vy_a;
  904.                 gz   = vz_i[k] - vz_a;
  905.                 g_sqr = gx * gx + gy * gy + gz * gz;
  906.                 g = sqrt(g_sqr);
  907.                 energy = 0.5 * MU_HEHE * g_sqr / EV_TO_J;
  908.                 energy_index = min( int(energy / DE_CS + 0.5), CS_RANGES-1);
  909.                 nu = sigma_tot_i[energy_index] * g;
  910.                 p_coll = 1 - exp(- nu * DT_I);              // collision probability for ions
  911.                 if (R01(MTgen)< p_coll) {                   // ion collision takes place
  912.                     collision_ion (&vx_i[k], &vy_i[k], &vz_i[k], &vx_a, &vy_a, &vz_a, energy_index);
  913.                     N_i_coll++;
  914.                 }
  915.             }
  916.         }
  917.        
  918.         if (measurement_mode) {
  919.            
  920.             // collect 'xt' data from the grid
  921.            
  922.             for (p=0; p<N_G; p++) {
  923.                 pot_xt   [p][t_index] += pot[p];
  924.                 efield_xt[p][t_index] += efield[p];
  925.                 ne_xt    [p][t_index] += e_density[p];
  926.                 ni_xt    [p][t_index] += i_density[p];
  927.                 e1_xt    [p][t_index] += e1_density[p];  // Artem
  928.                 e2_xt    [p][t_index] += e2_density[p];  // Artem
  929.             }
  930.         }
  931.        
  932.         if ((t % 1000) == 0) printf(" c = %8d  t = %8d  #e = %8d  #i = %8d\n", cycle,t,N_e,N_i);
  933.     }
  934.     fprintf(datafile,"%8d  %8d  %8d\n",cycle,N_e,N_i);
  935.     print_excitation_densities();
  936. }
  937.  
  938. //---------------------------------------------------------------------//
  939. // save particle coordinates                                           //
  940. //---------------------------------------------------------------------//
  941.  
  942. void save_particle_data(){
  943.     double   d;
  944.     FILE   * f;
  945.     char fname[80];
  946.    
  947.     strcpy(fname,"picdata.bin");
  948.     f = fopen(fname,"wb");
  949.     fwrite(&Time,sizeof(double),1,f);
  950.     d = (double)(cycles_done);
  951.     fwrite(&d,sizeof(double),1,f);
  952.     d = (double)(N_e);
  953.     fwrite(&d,sizeof(double),1,f);
  954.     fwrite(x_e, sizeof(double),N_e,f);
  955.     fwrite(vx_e,sizeof(double),N_e,f);
  956.     fwrite(vy_e,sizeof(double),N_e,f);
  957.     fwrite(vz_e,sizeof(double),N_e,f);
  958.     d = (double)(N_i);
  959.     fwrite(&d,sizeof(double),1,f);
  960.     fwrite(x_i, sizeof(double),N_i,f);
  961.     fwrite(vx_i,sizeof(double),N_i,f);
  962.     fwrite(vy_i,sizeof(double),N_i,f);
  963.     fwrite(vz_i,sizeof(double),N_i,f);
  964.  
  965.     // saving excited state densities - Artem
  966.  
  967.     fwrite(e1_density, sizeof(double), N_G, f);
  968.     fwrite(e2_density, sizeof(double), N_G, f);    
  969.  
  970.     fclose(f);
  971.     printf(">> eduPIC: data saved : %d electrons %d ions, excited states densities , %d cycles completed, time is %e [s]\n",N_e,N_i,cycles_done,Time);
  972. }
  973.  
  974. //---------------------------------------------------------------------//
  975. // load particle coordinates                                           //
  976. //---------------------------------------------------------------------//
  977.  
  978. void load_particle_data(){
  979.     double   d;
  980.     FILE   * f;
  981.     char fname[80];
  982.    
  983.     strcpy(fname,"picdata.bin");
  984.     f = fopen(fname,"rb");
  985.     if (f==NULL) {printf(">> eduPIC: ERROR: No particle data file found, try running initial cycle using argument '0'\n"); exit(0); }
  986.     fread(&Time,sizeof(double),1,f);
  987.     fread(&d,sizeof(double),1,f);
  988.     cycles_done = int(d);
  989.     fread(&d,sizeof(double),1,f);
  990.     N_e = int(d);
  991.     fread(x_e, sizeof(double),N_e,f);
  992.     fread(vx_e,sizeof(double),N_e,f);
  993.     fread(vy_e,sizeof(double),N_e,f);
  994.     fread(vz_e,sizeof(double),N_e,f);
  995.     fread(&d,sizeof(double),1,f);
  996.     N_i = int(d);
  997.     fread(x_i, sizeof(double),N_i,f);
  998.     fread(vx_i,sizeof(double),N_i,f);
  999.     fread(vy_i,sizeof(double),N_i,f);
  1000.     fread(vz_i,sizeof(double),N_i,f);
  1001.  
  1002.     // reading excited states densities -- Artem
  1003.  
  1004.     fread(e1_density, sizeof(double), N_G, f);
  1005.     fread(e2_density, sizeof(double), N_G, f);    
  1006.  
  1007.     fclose(f);
  1008.     printf(">> eduPIC: data loaded : %d electrons %d ions, excited states densities, %d cycles completed before, time is %e [s]\n",N_e,N_i,cycles_done,Time);
  1009. }
  1010.  
  1011. //---------------------------------------------------------------------//
  1012. // save density data                                                   //
  1013. //---------------------------------------------------------------------//
  1014.  
  1015. void save_density(void){
  1016.     FILE *f;
  1017.     double c;
  1018.     int m;
  1019.    
  1020.     f = fopen("density.dat","w");
  1021.     c = 1.0 / (double)(no_of_cycles) / (double)(N_T);
  1022.     for(m=0; m<N_G; m++){
  1023.         fprintf(f,"%8.5f  %12e  %12e\n",m * DX, cumul_e_density[m] * c, cumul_i_density[m] * c);
  1024.     }
  1025.     fclose(f);
  1026. }
  1027.  
  1028. // save Final excited states densities - Artem
  1029.  
  1030. void save_final_excited_densities(void) {
  1031.     FILE *f = fopen("excited_densities.dat", "w");
  1032.     for(int p=0; p<N_G; p++) {
  1033.         fprintf(f, "%8.5f %12e %12e\n", p*DX, e1_density[p], e2_density[p]);
  1034.     }
  1035.     fclose(f);
  1036. }
  1037.  
  1038. //---------------------------------------------------------------------//
  1039. // save EEPF data                                                      //
  1040. //---------------------------------------------------------------------//
  1041.  
  1042. void save_eepf(void) {
  1043.     FILE   *f;
  1044.     int    i;
  1045.     double h,energy;
  1046.    
  1047.     h = 0.0;
  1048.     for (i=0; i<N_EEPF; i++) {h += eepf[i];}
  1049.     h *= DE_EEPF;
  1050.     f = fopen("eepf.dat","w");
  1051.     for (i=0; i<N_EEPF; i++) {
  1052.         energy = (i + 0.5) * DE_EEPF;
  1053.         fprintf(f,"%e  %e\n", energy, eepf[i] / h / sqrt(energy));
  1054.     }
  1055.     fclose(f);
  1056. }
  1057.  
  1058. //---------------------------------------------------------------------//
  1059. // save IFED data                                                      //
  1060. //---------------------------------------------------------------------//
  1061.  
  1062. void save_ifed(void) {
  1063.     FILE   *f;
  1064.     int    i;
  1065.     double h_pow,h_gnd,energy;
  1066.    
  1067.     h_pow = 0.0;
  1068.     h_gnd = 0.0;
  1069.     for (i=0; i<N_IFED; i++) {h_pow += ifed_pow[i]; h_gnd += ifed_gnd[i];}
  1070.     h_pow *= DE_IFED;
  1071.     h_gnd *= DE_IFED;
  1072.     mean_i_energy_pow = 0.0;
  1073.     mean_i_energy_gnd = 0.0;
  1074.     f = fopen("ifed.dat","w");
  1075.     for (i=0; i<N_IFED; i++) {
  1076.         energy = (i + 0.5) * DE_IFED;
  1077.         fprintf(f,"%6.2f %10.6f %10.6f\n", energy, (double)(ifed_pow[i])/h_pow, (double)(ifed_gnd[i])/h_gnd);
  1078.         mean_i_energy_pow += energy * (double)(ifed_pow[i]) / h_pow;
  1079.         mean_i_energy_gnd += energy * (double)(ifed_gnd[i]) / h_gnd;
  1080.     }
  1081.     fclose(f);
  1082. }
  1083.  
  1084. //--------------------------------------------------------------------//
  1085. // save XT data                                                       //
  1086. //--------------------------------------------------------------------//
  1087.  
  1088. void save_xt_1(xt_distr distr, char *fname) {
  1089.     FILE   *f;
  1090.     int    i, j;
  1091.    
  1092.     f = fopen(fname,"w");
  1093.     for (i=0; i<N_G; i++){
  1094.         for (j=0; j<N_XT; j++){
  1095.             fprintf(f,"%e  ", distr[i][j]);
  1096.         }
  1097.         fprintf(f,"\n");
  1098.     }
  1099.     fclose(f);
  1100. }
  1101.  
  1102. void norm_all_xt(void){
  1103.     double f1, f2;
  1104.     int    i, j;
  1105.    
  1106.     // normalize all XT data
  1107.    
  1108.     f1 = (double)(N_XT) / (double)(no_of_cycles * N_T);
  1109.     f2 = WEIGHT / (ELECTRODE_AREA * DX) / (no_of_cycles * (PERIOD / (double)(N_XT)));
  1110.    
  1111.     for (i=0; i<N_G; i++){
  1112.         for (j=0; j<N_XT; j++){
  1113.             pot_xt[i][j]    *= f1;
  1114.             efield_xt[i][j] *= f1;
  1115.             ne_xt[i][j]     *= f1;
  1116.             ni_xt[i][j]     *= f1;
  1117.             e1_xt[i][j]     *= f1;   // Artem
  1118.             e2_xt[i][j]     *= f1;   // Artem
  1119.             if (counter_e_xt[i][j] > 0) {
  1120.                 ue_xt[i][j]     =  ue_xt[i][j] / counter_e_xt[i][j];
  1121.                 je_xt[i][j]     = -ue_xt[i][j] * ne_xt[i][j] * E_CHARGE;
  1122.                 meanee_xt[i][j] =  meanee_xt[i][j] / counter_e_xt[i][j];
  1123.                 ioniz_rate_xt[i][j] *= f2;
  1124.              } else {
  1125.                 ue_xt[i][j]         = 0.0;
  1126.                 je_xt[i][j]         = 0.0;
  1127.                 meanee_xt[i][j]     = 0.0;
  1128.                 ioniz_rate_xt[i][j] = 0.0;
  1129.             }
  1130.             if (counter_i_xt[i][j] > 0) {
  1131.                 ui_xt[i][j]     = ui_xt[i][j] / counter_i_xt[i][j];
  1132.                 ji_xt[i][j]     = ui_xt[i][j] * ni_xt[i][j] * E_CHARGE;
  1133.                 meanei_xt[i][j] = meanei_xt[i][j] / counter_i_xt[i][j];
  1134.             } else {
  1135.                 ui_xt[i][j]     = 0.0;
  1136.                 ji_xt[i][j]     = 0.0;
  1137.                 meanei_xt[i][j] = 0.0;
  1138.             }
  1139.             powere_xt[i][j] = je_xt[i][j] * efield_xt[i][j];
  1140.             poweri_xt[i][j] = ji_xt[i][j] * efield_xt[i][j];
  1141.         }
  1142.     }
  1143. }
  1144.  
  1145. void save_all_xt(void){
  1146.     char fname[80];
  1147.    
  1148.     strcpy(fname,"pot_xt.dat");     save_xt_1(pot_xt, fname);
  1149.     strcpy(fname,"efield_xt.dat");  save_xt_1(efield_xt, fname);
  1150.     strcpy(fname,"ne_xt.dat");      save_xt_1(ne_xt, fname);
  1151.     strcpy(fname,"ni_xt.dat");      save_xt_1(ni_xt, fname);
  1152.     strcpy(fname,"je_xt.dat");      save_xt_1(je_xt, fname);
  1153.     strcpy(fname,"ji_xt.dat");      save_xt_1(ji_xt, fname);
  1154.     strcpy(fname,"powere_xt.dat");  save_xt_1(powere_xt, fname);
  1155.     strcpy(fname,"poweri_xt.dat");  save_xt_1(poweri_xt, fname);
  1156.     strcpy(fname,"meanee_xt.dat");  save_xt_1(meanee_xt, fname);
  1157.     strcpy(fname,"meanei_xt.dat");  save_xt_1(meanei_xt, fname);
  1158.     strcpy(fname,"ioniz_xt.dat");   save_xt_1(ioniz_rate_xt, fname);
  1159.     strcpy(fname,"e1_xt.dat");      save_xt_1(e1_xt, fname);
  1160.     strcpy(fname,"e2_xt.dat");      save_xt_1(e2_xt, fname);
  1161. }
  1162.  
  1163. //---------------------------------------------------------------------//
  1164. // simulation report including stability and accuracy conditions       //
  1165. //---------------------------------------------------------------------//
  1166.  
  1167. void check_and_save_info(void){
  1168.     FILE     *f;
  1169.     double   plas_freq, meane, kT, debye_length, density, ecoll_freq, icoll_freq, sim_time, e_max, v_max, power_e, power_i, c;
  1170.     int      i,j;
  1171.     bool     conditions_OK;
  1172.    
  1173.     density    = cumul_e_density[N_G / 2] / (double)(no_of_cycles) / (double)(N_T);  // e density @ center
  1174.     plas_freq  = E_CHARGE * sqrt(density / EPSILON0 / E_MASS);                       // e plasma frequency @ center
  1175.     meane      = mean_energy_accu_center / (double)(mean_energy_counter_center);     // e mean energy @ center
  1176.     kT         = 2.0 * meane * EV_TO_J / 3.0;                                        // k T_e @ center (approximate)
  1177.     sim_time   = (double)(no_of_cycles) / FREQUENCY;                                 // simulated time
  1178.     ecoll_freq = (double)(N_e_coll) / sim_time / (double)(N_e);                      // e collision frequency
  1179.     icoll_freq = (double)(N_i_coll) / sim_time / (double)(N_i);                      // ion collision frequency
  1180.     debye_length = sqrt(EPSILON0 * kT / density) / E_CHARGE;                         // e Debye length @ center
  1181.    
  1182.     f = fopen("info.txt","w");
  1183.     fprintf(f,"########################## eduPIC simulation report ############################\n");
  1184.     fprintf(f,"Simulation parameters:\n");
  1185.     fprintf(f,"Gap distance                          = %12.3e [m]\n",  L);
  1186.     fprintf(f,"# of grid divisions                   = %12d\n",      N_G);
  1187.     fprintf(f,"Frequency                             = %12.3e [Hz]\n", FREQUENCY);
  1188.     fprintf(f,"# of time steps / period              = %12d\n",      N_T);
  1189.     fprintf(f,"# of electron / ion time steps        = %12d\n",      N_SUB);
  1190.     fprintf(f,"Voltage amplitude                     = %12.3e [V]\n",  VOLTAGE);
  1191.     fprintf(f,"Pressure (Ar)                         = %12.3e [Pa]\n", PRESSURE);
  1192.     fprintf(f,"Temperature                           = %12.3e [K]\n",  T_neutral);
  1193.     fprintf(f,"Superparticle weight                  = %12.3e\n",      WEIGHT);
  1194.     fprintf(f,"# of simulation cycles in this run    = %12d\n",      no_of_cycles);
  1195.     fprintf(f,"--------------------------------------------------------------------------------\n");
  1196.     fprintf(f,"Plasma characteristics:\n");
  1197.     fprintf(f,"Electron density @ center             = %12.3e [m^{-3}]\n", density);
  1198.     fprintf(f,"Plasma frequency @ center             = %12.3e [rad/s]\n",  plas_freq);
  1199.     fprintf(f,"Debye length @ center                 = %12.3e [m]\n",      debye_length);
  1200.     fprintf(f,"Electron collision frequency          = %12.3e [1/s]\n",    ecoll_freq);
  1201.     fprintf(f,"Ion collision frequency               = %12.3e [1/s]\n",    icoll_freq);
  1202.     fprintf(f,"--------------------------------------------------------------------------------\n");
  1203.     fprintf(f,"Stability and accuracy conditions:\n");
  1204.     conditions_OK = true;
  1205.     c = plas_freq * DT_E;
  1206.     fprintf(f,"Plasma frequency @ center * DT_E      = %12.3f (OK if less than 0.20)\n", c);
  1207.     if (c > 0.2) {conditions_OK = false;}
  1208.     c = DX / debye_length;
  1209.     fprintf(f,"DX / Debye length @ center            = %12.3f (OK if less than 1.00)\n", c);
  1210.     if (c > 1.0) {conditions_OK = false;}
  1211.     c = max_electron_coll_freq() * DT_E;
  1212.     fprintf(f,"Max. electron coll. frequency * DT_E  = %12.3f (OK if less than 0.05)\n", c);
  1213.     if (c > 0.05) {conditions_OK = false;}
  1214.     c = max_ion_coll_freq() * DT_I;
  1215.     fprintf(f,"Max. ion coll. frequency * DT_I       = %12.3f (OK if less than 0.05)\n", c);
  1216.     if (c > 0.05) {conditions_OK = false;}
  1217.     if (conditions_OK == false){
  1218.         fprintf(f,"--------------------------------------------------------------------------------\n");
  1219.         fprintf(f,"** STABILITY AND ACCURACY CONDITION(S) VIOLATED - REFINE SIMULATION SETTINGS! **\n");
  1220.         fprintf(f,"--------------------------------------------------------------------------------\n");
  1221.         fclose(f);
  1222.         printf(">> eduPIC: ERROR: STABILITY AND ACCURACY CONDITION(S) VIOLATED!\n");
  1223.         printf(">> eduPIC: for details see 'info.txt' and refine simulation settings!\n");
  1224.     }
  1225.     else
  1226.     {
  1227.         // calculate maximum energy for which the Courant-Friedrichs-Levy condition holds:
  1228.        
  1229.         v_max = DX / DT_E;
  1230.         e_max = 0.5 * E_MASS * v_max * v_max / EV_TO_J;
  1231.         fprintf(f,"Max e- energy for CFL condition       = %12.3f [eV]\n", e_max);
  1232.         fprintf(f,"Check EEPF to ensure that CFL is fulfilled for the majority of the electrons!\n");
  1233.         fprintf(f,"--------------------------------------------------------------------------------\n");
  1234.        
  1235.         // saving of the following data is done here as some of the further lines need data
  1236.         // that are computed / normalized in these functions
  1237.        
  1238.         printf(">> eduPIC: saving diagnostics data\n");
  1239.         save_density();
  1240.         save_final_excited_densities();   // Artem
  1241.         save_eepf();
  1242.         save_ifed();
  1243.         norm_all_xt();
  1244.         save_all_xt();
  1245.         fprintf(f,"Particle characteristics at the electrodes:\n");
  1246.         fprintf(f,"Ion flux at powered electrode         = %12.3e [m^{-2} s^{-1}]\n", N_i_abs_pow * WEIGHT / ELECTRODE_AREA / (no_of_cycles * PERIOD));
  1247.         fprintf(f,"Ion flux at grounded electrode        = %12.3e [m^{-2} s^{-1}]\n", N_i_abs_gnd * WEIGHT / ELECTRODE_AREA / (no_of_cycles * PERIOD));
  1248.         fprintf(f,"Mean ion energy at powered electrode  = %12.3e [eV]\n", mean_i_energy_pow);
  1249.         fprintf(f,"Mean ion energy at grounded electrode = %12.3e [eV]\n", mean_i_energy_gnd);
  1250.         fprintf(f,"Electron flux at powered electrode    = %12.3e [m^{-2} s^{-1}]\n", N_e_abs_pow * WEIGHT / ELECTRODE_AREA / (no_of_cycles * PERIOD));
  1251.         fprintf(f,"Electron flux at grounded electrode   = %12.3e [m^{-2} s^{-1}]\n", N_e_abs_gnd * WEIGHT / ELECTRODE_AREA / (no_of_cycles * PERIOD));
  1252.         fprintf(f,"--------------------------------------------------------------------------------\n");
  1253.        
  1254.         // calculate spatially and temporally averaged power absorption by the electrons and ions
  1255.        
  1256.         power_e = 0.0;
  1257.         power_i = 0.0;
  1258.         for (i=0; i<N_G; i++){
  1259.             for (j=0; j<N_XT; j++){
  1260.                 power_e += powere_xt[i][j];
  1261.                 power_i += poweri_xt[i][j];
  1262.             }
  1263.         }
  1264.         power_e /= (double)(N_XT * N_G);
  1265.         power_i /= (double)(N_XT * N_G);
  1266.         fprintf(f,"Absorbed power calculated as <j*E>:\n");
  1267.         fprintf(f,"Electron power density (average)      = %12.3e [W m^{-3}]\n", power_e);
  1268.         fprintf(f,"Ion power density (average)           = %12.3e [W m^{-3}]\n", power_i);
  1269.         fprintf(f,"Total power density(average)          = %12.3e [W m^{-3}]\n", power_e + power_i);
  1270.         fprintf(f,"--------------------------------------------------------------------------------\n");
  1271.         fclose(f);
  1272.     }
  1273. }
  1274.  
  1275. //------------------------------------------------------------------------------------------//
  1276. // main                                                                                     //
  1277. // command line arguments:                                                                  //
  1278. // [1]: number of cycles (0 for init)                                                       //
  1279. // [2]: "m" turns on data collection and saving                                             //
  1280. //------------------------------------------------------------------------------------------//
  1281.  
  1282. int main (int argc, char *argv[]){
  1283.     printf(">> eduPIC: starting...\n");
  1284.     printf(">> eduPIC: **************************************************************************\n");
  1285.     printf(">> eduPIC: Copyright (C) 2021 Z. Donko et al.\n");
  1286.     printf(">> eduPIC: This program comes with ABSOLUTELY NO WARRANTY\n");
  1287.     printf(">> eduPIC: This is free software, you are welcome to use, modify and redistribute it\n");
  1288.     printf(">> eduPIC: according to the GNU General Public License, https://www.gnu.org/licenses/\n");
  1289.     printf(">> eduPIC: **************************************************************************\n");
  1290.  
  1291.     if (argc == 1) {
  1292.         printf(">> eduPIC: error = need starting_cycle argument\n");
  1293.         return 1;
  1294.     } else {
  1295.         strcpy(st0,argv[1]);
  1296.         arg1 = atol(st0);
  1297.         if (argc > 2) {
  1298.             if (strcmp (argv[2],"m") == 0){
  1299.                 measurement_mode = true;                  // measurements will be done
  1300.             } else {
  1301.                 measurement_mode = false;
  1302.             }
  1303.         }
  1304.     }
  1305.     if (measurement_mode) {
  1306.         printf(">> eduPIC: measurement mode: on\n");
  1307.     } else {
  1308.         printf(">> eduPIC: measurement mode: off\n");
  1309.     }
  1310.     set_electron_cross_sections_ar();
  1311.     set_ion_cross_sections_ar();
  1312.     calc_total_cross_sections();
  1313.  
  1314.     auto exc = init_excited_distr();
  1315.     printf("Excited state population - superparticles!!!\n");
  1316.     printf("%d %d\n", exc.first, exc.second);
  1317.  
  1318.     printf("Sanity check \n");
  1319.     fflush(stdout);
  1320.  
  1321.     //test_cross_sections(); return 1;
  1322.     datafile = fopen("conv.dat","a");
  1323.     if (arg1 == 0) {
  1324.         if (FILE *file = fopen("picdata.bin", "r")) { fclose(file);
  1325.             printf(">> eduPIC: Warning: Data from previous calculation are detected.\n");
  1326.             printf("           To start a new simulation from the beginning, please delete all output files before running ./eduPIC 0\n");
  1327.             printf("           To continue the existing calculation, please specify the number of cycles to run, e.g. ./eduPIC 100\n");
  1328.             exit(0);
  1329.         }
  1330.         no_of_cycles = 1;
  1331.         cycle = 1;                                        // init cycle
  1332.         init(N_INIT);                                     // seed initial electrons & ions
  1333.         printf(">> eduPIC: running initializing cycle\n");
  1334.         Time = 0;
  1335.         do_one_cycle();
  1336.         print_excitation_densities();
  1337.         cycles_done = 1;
  1338.     } else {
  1339.         no_of_cycles = arg1;                              // run number of cycles specified in command line
  1340.         load_particle_data();                            // read previous configuration from file
  1341.         printf(">> eduPIC: running %d cycle(s)\n",no_of_cycles);
  1342.         for (cycle=cycles_done+1;cycle<=cycles_done+no_of_cycles;cycle++) {do_one_cycle();}
  1343.         cycles_done += no_of_cycles;
  1344.     }
  1345.     fclose(datafile);
  1346.     save_particle_data();
  1347.     if (measurement_mode) {
  1348.         check_and_save_info();
  1349.     }
  1350.     printf(">> eduPIC: simulation of %d cycle(s) is completed.\n",no_of_cycles);
  1351. }
  1352.  
Add Comment
Please, Sign In to add comment