phystota

eduPIC_excitation_tracking

May 21st, 2025 (edited)
42
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 64.13 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          = 1;                                         // 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] = (3.0 / 1.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. }
  284.  
  285. //------------------------------------------------------------------------------//
  286. //  ion cross sections: A. V. Phelps, J. Appl. Phys. 76, 747 (1994)             //
  287. //------------------------------------------------------------------------------//
  288.  
  289. void set_ion_cross_sections_ar(void){
  290.     int    i;
  291.     double e_com,e_lab,qmom,qback,qiso;
  292.    
  293.     printf(">> eduPIC: Setting He+ / He cross sections\n");
  294.     for(i=0; i<CS_RANGES; i++){
  295.         if (i == 0) {e_com = DE_CS;} else {e_com = DE_CS * i;}             // ion energy in the center of mass frame of reference
  296.         e_lab = 2.0 * e_com;                                               // ion energy in the laboratory frame of reference
  297.         qiso  = 7.63 *pow(10,-20) * pow(e_com, -0.5);
  298.         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 );
  299.         sigma[I_ISO][i]  = qiso;             // cross section for He+ / He isotropic part of elastic scattering
  300.         sigma[I_BACK][i] = qback;            // cross section for He+ / He backward elastic scattering
  301.     }
  302. }
  303.  
  304. //----------------------------------------------------------------------//
  305. //  calculation of total cross sections for electrons and ions          //
  306. //----------------------------------------------------------------------//
  307.  
  308. void calc_total_cross_sections(void){
  309.     int i;
  310.    
  311.     for(i=0; i<CS_RANGES; i++){
  312.         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
  313.         sigma_tot_i[i] = (sigma[I_ISO][i] + sigma[I_BACK][i]) * GAS_DENSITY;                    // total macroscopic cross section of ions
  314.     }
  315. }
  316.  
  317. //----------------------------------------------------------------------//
  318. //  test of cross sections for electrons and ions                       //
  319. //----------------------------------------------------------------------//
  320.  
  321. void test_cross_sections(void){
  322.     FILE  * f;
  323.     int   i,j;
  324.    
  325.     f = fopen("cross_sections.dat","w");        // cross sections saved in data file: cross_sections.dat
  326.     for(i=0; i<CS_RANGES; i++){
  327.         fprintf(f,"%12.4f ",i*DE_CS);
  328.         for(j=0; j<N_CS; j++) fprintf(f,"%14e ",sigma[j][i]);
  329.         fprintf(f,"\n");
  330.     }
  331.     fclose(f);
  332. }
  333.  
  334. //---------------------------------------------------------------------//
  335. // find upper limit of collision frequencies                           //
  336. //---------------------------------------------------------------------//
  337.  
  338. double max_electron_coll_freq (void){
  339.     int i;
  340.     double e,v,nu,nu_max;
  341.     nu_max = 0;
  342.     for(i=0; i<CS_RANGES; i++){
  343.         e  = i * DE_CS;
  344.         v  = sqrt(2.0 * e * EV_TO_J / E_MASS);
  345.         nu = v * sigma_tot_e[i];
  346.         if (nu > nu_max) {nu_max = nu;}
  347.     }
  348.     return nu_max;
  349. }
  350.  
  351. double max_ion_coll_freq (void){
  352.     int i;
  353.     double e,g,nu,nu_max;
  354.     nu_max = 0;
  355.     for(i=0; i<CS_RANGES; i++){
  356.         e  = i * DE_CS;
  357.         g  = sqrt(2.0 * e * EV_TO_J / MU_HEHE);
  358.         nu = g * sigma_tot_i[i];
  359.         if (nu > nu_max) nu_max = nu;
  360.     }
  361.     return nu_max;
  362. }
  363.  
  364. //----------------------------------------------------------------------//
  365. // initialization of the simulation by placing a given number of        //
  366. // electrons and ions at random positions between the electrodes        //
  367. //----------------------------------------------------------------------//
  368.  
  369. // initialization of excited states distribtuion, assuming Maxwellian-Boltzmann balance -- Artem
  370. std::pair<int, int> init_excited_distr() {
  371.     double part_ground = 1.0*exp(-0.0/T_neutral); // partition function for ground state
  372.     double part_triplet = 3.0*exp(-E_EXC_TH_1*EV_TO_J/(K_BOLTZMANN*T_neutral)); // partition function for triplet excited state
  373.     double part_singlet = 1.0*exp(-E_EXC_TH_2*EV_TO_J/(K_BOLTZMANN*T_neutral)); // partition function for singlet excited state
  374.     double part_func_total = part_ground + part_triplet + part_singlet; // total partition function
  375.     double n_triplet = ((part_triplet/part_func_total)*GAS_DENSITY); // denisty population of tripet state
  376.     double n_singlet = ((part_singlet/part_func_total)*GAS_DENSITY); // density population of singlet state
  377.  
  378.     return {n_triplet, n_singlet};
  379. }
  380.  
  381. void print_excitation_densities(void) {
  382.     double total_e1 = 0.0, total_e2 = 0.0;
  383.     const double cell_volume = ELECTRODE_AREA * DX;
  384.    
  385.     // Sum densities across all grid cells
  386.     for (int p = 0; p < N_G; p++) {
  387.         total_e1 += e1_density[p];  // triplet state density
  388.         total_e2 += e2_density[p];  // singlet state density
  389.     }
  390.    
  391.     printf("Triplet SP = %8.2e | Singlet SP = %8.2e\n", total_e1, total_e2);
  392. }
  393.  
  394.  
  395. void init(int nseed){
  396.     int i;
  397.    
  398.     for (i=0; i<nseed; i++){
  399.         x_e[i]  = L * R01(MTgen);                                                   // initial random position of the electron
  400.         vx_e[i] = RMB_e(MTgen); vy_e[i] = RMB_e(MTgen); vz_e[i] = RMB_e(MTgen);     // initial velocity components of the electron
  401.         x_i[i]  = L * R01(MTgen);                                                   // initial random position of the ion
  402.         vx_i[i] = RMB_n(MTgen); vy_i[i] = RMB_n(MTgen); vz_i[i] = RMB_n(MTgen);     // initial velocity components of the ion
  403.     }
  404.     N_e = nseed;    // initial number of electrons
  405.     N_i = nseed;    // initial number of ions
  406.  
  407.     auto exc = init_excited_distr();
  408.     for (int p = 0; p < N_G; p++) {
  409.         e1_density[p] = exc.first;
  410.         e2_density[p] = exc.second;
  411.     }
  412. }
  413.  
  414.  
  415.  
  416. //----------------------------------------------------------------------//
  417. // e / He collision  (cold gas approximation)                           //
  418. //----------------------------------------------------------------------//
  419.  
  420. void collision_electron (double xe, double *vxe, double *vye, double *vze, int eindex){
  421.     const double F1 = E_MASS  / (E_MASS + HE_MASS);
  422.     const double F2 = HE_MASS / (E_MASS + HE_MASS);
  423.     double t0,t1,t2,t3,t4,t5,rnd;
  424.     double g,g2,gx,gy,gz,wx,wy,wz,theta,phi;
  425.     double chi,eta,chi2,eta2,sc,cc,se,ce,st,ct,sp,cp,energy,e_sc,e_ej;
  426.  
  427.     // - Artem
  428.     // Determine cell p where the electron is
  429.     double c0 = xe * INV_DX;
  430.     int p = std::max(0, std::min(N_G - 1, static_cast<int>(c0)));
  431.  
  432.     // Local densities -- Artem
  433.     double e1_dens = e1_density[p];
  434.     double e2_dens = e2_density[p];
  435.     double ground_dens = GAS_DENSITY - e1_dens - e2_dens;    
  436.  
  437.    
  438.     // calculate relative velocity before collision & velocity of the centre of mass
  439.    
  440.     gx = (*vxe);
  441.     gy = (*vye);
  442.     gz = (*vze);
  443.     g  = sqrt(gx * gx + gy * gy + gz * gz);
  444.     wx = F1 * (*vxe);
  445.     wy = F1 * (*vye);
  446.     wz = F1 * (*vze);
  447.    
  448.     // find Euler angles
  449.    
  450.     if (gx == 0) {theta = 0.5 * PI;}
  451.     else {theta = atan2(sqrt(gy * gy + gz * gz),gx);}
  452.     if (gy == 0) {
  453.         if (gz > 0){phi = 0.5 * PI;} else {phi = - 0.5 * PI;}
  454.     } else {phi = atan2(gz, gy);}
  455.     st  = sin(theta);
  456.     ct  = cos(theta);
  457.     sp  = sin(phi);
  458.     cp  = cos(phi);
  459.    
  460.     // choose the type of collision based on the cross sections
  461.     // take into account energy loss in inelastic collisions
  462.     // generate scattering and azimuth angles
  463.     // in case of ionization handle the 'new' electron
  464.    
  465.     t0   =      sigma[E_ELA][eindex] * ground_dens;
  466.     t1   = t0 + sigma[E_EXC_1][eindex] * ground_dens;
  467.     t2   = t1 + sigma[E_EXC_2][eindex] * ground_dens;
  468.     t3   = t2 + sigma[E_ION][eindex] * ground_dens;
  469.     t4   = t3 + sigma[E_SUPER_1][eindex]  * e1_dens;   // account for superelastic triplet - Artem
  470.     t5   = t4 + sigma[E_SUPER_2][eindex] * e2_dens;   // account for superelastic singlet- Artem
  471.  
  472.     rnd  = R01(MTgen);
  473.     if (rnd < (t0/t5)){                              // elastic scattering
  474.         chi = acos(1.0 - 2.0 * R01(MTgen));          // isotropic scattering
  475.         eta = TWO_PI * R01(MTgen);                   // azimuthal angle
  476.  
  477.     } else if (rnd < (t1/t5)){                       // excitation 1 (triplet)
  478.         energy = 0.5 * E_MASS * g * g;               // electron energy
  479.         energy = fabs(energy - E_EXC_TH_1 * EV_TO_J);  // subtract energy loss for excitation
  480.         g   = sqrt(2.0 * energy / E_MASS);           // relative velocity after energy loss
  481.         chi = acos(1.0 - 2.0 * R01(MTgen));          // isotropic scattering
  482.         eta = TWO_PI * R01(MTgen);                   // azimuthal angle
  483.  
  484.         //add new triplet excited He atom density to this grid point, sample velocities from Maxwellian distribution - Artem
  485.         e1_density[p] += WEIGHT / (ELECTRODE_AREA * DX);
  486.  
  487.     } else if (rnd < (t2/t5)){                       // excitation 2 (singlet)
  488.         energy = 0.5 * E_MASS * g * g;               // electron energy
  489.         energy = fabs(energy - E_EXC_TH_2 * EV_TO_J);  // subtract energy loss for excitation
  490.         g   = sqrt(2.0 * energy / E_MASS);           // relative velocity after energy loss
  491.         chi = acos(1.0 - 2.0 * R01(MTgen));          // isotropic scattering
  492.         eta = TWO_PI * R01(MTgen);                   // azimuthal angle    
  493.  
  494.         //add new singet excited He atom, sample velocities from Maxwellian distribution - Artem
  495.         e2_density[p] += WEIGHT / (ELECTRODE_AREA * DX);
  496.  
  497.     } else if (rnd < (t3/t5)){                                         // ionization
  498.         energy = 0.5 * E_MASS * g * g;               // electron energy
  499.         energy = fabs(energy - E_ION_TH * EV_TO_J);  // subtract energy loss of ionization
  500.         // e_ej  = 10.0 * tan(R01(MTgen) * atan(energy/EV_TO_J / 20.0)) * EV_TO_J; // energy of the ejected electron
  501.         // e_sc = fabs(energy - e_ej);                  // energy of scattered electron after the collision
  502.         e_ej = 0.5*energy;                          // energy of the ejected electron
  503.         e_sc = fabs(energy - e_ej);                  // energy of scattered electron after the collision        
  504.         g    = sqrt(2.0 * e_sc / E_MASS);            // relative velocity of scattered electron
  505.         g2   = sqrt(2.0 * e_ej / E_MASS);            // relative velocity of ejected electron
  506.         // chi  = acos(sqrt(e_sc / energy));            // scattering angle for scattered electron
  507.         // chi2 = acos(sqrt(e_ej / energy));            // scattering angle for ejected electrons
  508.         chi = acos(1.0 - 2.0 * R01(MTgen));          // isotropic scattering for scattered electron (as in Turner's case)
  509.         chi2 = acos(1.0 - 2.0 * R01(MTgen));          // isotropic scattering for ejected electrons (as in Turner's case)
  510.         eta  = TWO_PI * R01(MTgen);                  // azimuthal angle for scattered electron
  511.         eta2 = eta + PI;                             // azimuthal angle for ejected electron
  512.         sc  = sin(chi2);
  513.         cc  = cos(chi2);
  514.         se  = sin(eta2);
  515.         ce  = cos(eta2);
  516.         gx  = g2 * (ct * cc - st * sc * ce);
  517.         gy  = g2 * (st * cp * cc + ct * cp * sc * ce - sp * sc * se);
  518.         gz  = g2 * (st * sp * cc + ct * sp * sc * ce + cp * sc * se);
  519.         x_e[N_e]  = xe;                              // add new electron
  520.         vx_e[N_e] = wx + F2 * gx;
  521.         vy_e[N_e] = wy + F2 * gy;
  522.         vz_e[N_e] = wz + F2 * gz;
  523.         N_e++;
  524.         x_i[N_i]  = xe;                              // add new ion
  525.         vx_i[N_i] = RMB_n(MTgen);                      // velocity is sampled from background thermal distribution
  526.         vy_i[N_i] = RMB_n(MTgen);
  527.         vz_i[N_i] = RMB_n(MTgen);
  528.         N_i++;
  529.  
  530.     } else if (rnd < (t4/t5)) {                      // accounting for superelastic collisions - triplet - Artem
  531.         energy = 0.5 * E_MASS * g * g;               // electron energy
  532.         energy = fabs(energy + E_EXC_TH_1 * EV_TO_J);  // add energy for deexcitation
  533.         g   = sqrt(2.0 * energy / E_MASS);           // relative velocity after energy loss
  534.         chi = acos(1.0 - 2.0 * R01(MTgen));          // isotropic scattering
  535.         eta = TWO_PI * R01(MTgen);                   // azimuthal angle    
  536.  
  537.         //substract  excited He atom density from the grid point - Artem
  538.         e1_density[p] = std::max(e1_density[p] - WEIGHT / (ELECTRODE_AREA * DX), 0.0);
  539.    
  540.     } else {                                         // account for supeelastic collision - singlet - Artem
  541.         energy = 0.5 * E_MASS * g * g;               // electron energy
  542.         energy = fabs(energy + E_EXC_TH_2 * EV_TO_J);  // add energy for deexcitation
  543.         g   = sqrt(2.0 * energy / E_MASS);           // relative velocity after energy loss
  544.         chi = acos(1.0 - 2.0 * R01(MTgen));          // isotropic scattering
  545.         eta = TWO_PI * R01(MTgen);                   // azimuthal angle    
  546.  
  547.         //substract  excited He atom density from the grid point - Artem
  548.         e2_density[p] = std::max(e2_density[p] - WEIGHT / (ELECTRODE_AREA * DX), 0.0);
  549.     }
  550.  
  551.    
  552.     // scatter the primary electron
  553.    
  554.     sc = sin(chi);
  555.     cc = cos(chi);
  556.     se = sin(eta);
  557.     ce = cos(eta);
  558.    
  559.     // compute new relative velocity:
  560.    
  561.     gx = g * (ct * cc - st * sc * ce);
  562.     gy = g * (st * cp * cc + ct * cp * sc * ce - sp * sc * se);
  563.     gz = g * (st * sp * cc + ct * sp * sc * ce + cp * sc * se);
  564.    
  565.     // post-collision velocity of the colliding electron
  566.    
  567.     (*vxe) = wx + F2 * gx;
  568.     (*vye) = wy + F2 * gy;
  569.     (*vze) = wz + F2 * gz;
  570. }
  571.  
  572. //----------------------------------------------------------------------//
  573. // He+ / He collision                                                   //
  574. //----------------------------------------------------------------------//
  575.  
  576. void collision_ion (double *vx_1, double *vy_1, double *vz_1,
  577.                     double *vx_2, double *vy_2, double *vz_2, int e_index){
  578.     double   g,gx,gy,gz,wx,wy,wz,rnd;
  579.     double   theta,phi,chi,eta,st,ct,sp,cp,sc,cc,se,ce,t1,t2;
  580.    
  581.     // calculate relative velocity before collision
  582.     // random Maxwellian target atom already selected (vx_2,vy_2,vz_2 velocity components of target atom come with the call)
  583.    
  584.     gx = (*vx_1)-(*vx_2);
  585.     gy = (*vy_1)-(*vy_2);
  586.     gz = (*vz_1)-(*vz_2);
  587.     g  = sqrt(gx * gx + gy * gy + gz * gz);
  588.     wx = 0.5 * ((*vx_1) + (*vx_2));
  589.     wy = 0.5 * ((*vy_1) + (*vy_2));
  590.     wz = 0.5 * ((*vz_1) + (*vz_2));
  591.    
  592.     // find Euler angles
  593.    
  594.     if (gx == 0) {theta = 0.5 * PI;} else {theta = atan2(sqrt(gy * gy + gz * gz),gx);}
  595.     if (gy == 0) {
  596.         if (gz > 0){phi = 0.5 * PI;} else {phi = - 0.5 * PI;}
  597.     } else {phi = atan2(gz, gy);}
  598.    
  599.     // determine the type of collision based on cross sections and generate scattering angle
  600.    
  601.     t1  =      sigma[I_ISO][e_index];
  602.     t2  = t1 + sigma[I_BACK][e_index];
  603.     rnd = R01(MTgen);
  604.     if  (rnd < (t1 /t2)){                        // isotropic scattering
  605.         chi = acos(1.0 - 2.0 * R01(MTgen));      // scattering angle
  606.     } else {                                     // backward scattering
  607.         chi = PI;                                // scattering angle
  608.     }
  609.     eta = TWO_PI * R01(MTgen);                   // azimuthal angle
  610.     sc  = sin(chi);
  611.     cc  = cos(chi);
  612.     se  = sin(eta);
  613.     ce  = cos(eta);
  614.     st  = sin(theta);
  615.     ct  = cos(theta);
  616.     sp  = sin(phi);
  617.     cp  = cos(phi);
  618.    
  619.     // compute new relative velocity
  620.    
  621.     gx = g * (ct * cc - st * sc * ce);
  622.     gy = g * (st * cp * cc + ct * cp * sc * ce - sp * sc * se);
  623.     gz = g * (st * sp * cc + ct * sp * sc * ce + cp * sc * se);
  624.    
  625.     // post-collision velocity of the ion
  626.    
  627.     (*vx_1) = wx + 0.5 * gx;
  628.     (*vy_1) = wy + 0.5 * gy;
  629.     (*vz_1) = wz + 0.5 * gz;
  630. }
  631.  
  632. //-----------------------------------------------------------------//
  633. // solve Poisson equation (Thomas algorithm)                       //
  634. //-----------------------------------------------------------------//
  635.  
  636. void solve_Poisson (xvector rho1, double tt){
  637.     const double A =  1.0;
  638.     const double B = -2.0;
  639.     const double C =  1.0;
  640.     const double S = 1.0 / (2.0 * DX);
  641.     const double ALPHA = -DX * DX / EPSILON0;
  642.     xvector      g, w, f;
  643.     int          i;
  644.    
  645.     // apply potential to the electrodes - boundary conditions
  646.    
  647.     pot[0]     = VOLTAGE * cos(OMEGA * tt);         // potential at the powered electrode
  648.     pot[N_G-1] = 0.0;                               // potential at the grounded electrode
  649.    
  650.     // solve Poisson equation
  651.    
  652.     for(i=1; i<=N_G-2; i++) f[i] = ALPHA * rho1[i];
  653.     f[1] -= pot[0];
  654.     f[N_G-2] -= pot[N_G-1];
  655.     w[1] = C/B;
  656.     g[1] = f[1]/B;
  657.     for(i=2; i<=N_G-2; i++){
  658.         w[i] = C / (B - A * w[i-1]);
  659.         g[i] = (f[i] - A * g[i-1]) / (B - A * w[i-1]);
  660.     }
  661.     pot[N_G-2] = g[N_G-2];
  662.     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
  663.    
  664.     // compute electric field
  665.    
  666.     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
  667.     efield[0]     = (pot[0]     - pot[1])     * INV_DX - rho1[0]     * DX / (2.0 * EPSILON0);   // powered electrode
  668.     efield[N_G-1] = (pot[N_G-2] - pot[N_G-1]) * INV_DX + rho1[N_G-1] * DX / (2.0 * EPSILON0);   // grounded electrode
  669. }
  670.  
  671. //---------------------------------------------------------------------//
  672. // simulation of one radiofrequency cycle                              //
  673. //---------------------------------------------------------------------//
  674.  
  675. void do_one_cycle (void){
  676.     const double DV       = ELECTRODE_AREA * DX;
  677.     const double FACTOR_W = WEIGHT / DV;
  678.     const double FACTOR_E = DT_E / E_MASS * E_CHARGE;
  679.     const double FACTOR_I = DT_I / HE_MASS * E_CHARGE;
  680.     const double MIN_X    = 0.45 * L;                       // min. position for EEPF collection
  681.     const double MAX_X    = 0.55 * L;                       // max. position for EEPF collection
  682.     int      k, t, p, energy_index;
  683.     double   g, g_sqr, gx, gy, gz, vx_a, vy_a, vz_a, e_x, energy, nu, p_coll, v_sqr, velocity;
  684.     double   mean_v, c0, c1, c2, rate;
  685.     bool     out;
  686.     xvector  rho;
  687.     int      t_index;
  688.  
  689.    
  690.     for (t=0; t<N_T; t++){          // the RF period is divided into N_T equal time intervals (time step DT_E)
  691.         Time += DT_E;               // update of the total simulated time
  692.         t_index = t / N_BIN;        // index for XT distributions
  693.        
  694.         // step 1: compute densities at grid points
  695.        
  696.         for(p=0; p<N_G; p++) e_density[p] = 0;                             // electron density - computed in every time step
  697.         for(k=0; k<N_e; k++){
  698.  
  699.             if      (p < 0)        p = 0;
  700.             else if (p > N_G - 2)  p = N_G - 2;
  701.             c0 = x_e[k] * INV_DX;
  702.             p  = int(c0);
  703.             e_density[p]   += (p + 1 - c0) * FACTOR_W;
  704.             e_density[p+1] += (c0 - p) * FACTOR_W;
  705.         }
  706.         e_density[0]     *= 2.0; // double at the edge bcs working with half-domain (no left/right neighbour)
  707.         e_density[N_G-1] *= 2.0;
  708.         for(p=0; p<N_G; p++) cumul_e_density[p] += e_density[p];
  709.        
  710.         if ((t % N_SUB) == 0) {                                            // ion density - computed in every N_SUB-th time steps (subcycling)
  711.             for(p=0; p<N_G; p++) i_density[p] = 0;
  712.             for(k=0; k<N_i; k++){
  713.                 c0 = x_i[k] * INV_DX;
  714.                 p  = int(c0);
  715.                 i_density[p]   += (p + 1 - c0) * FACTOR_W;  
  716.                 i_density[p+1] += (c0 - p) * FACTOR_W;
  717.             }
  718.             i_density[0]     *= 2.0; // double at the edge bcs working with half-domain (no left/right neighbour)
  719.             i_density[N_G-1] *= 2.0;
  720.         }
  721.         for(p=0; p<N_G; p++) cumul_i_density[p] += i_density[p];
  722.        
  723.         // step 2: solve Poisson equation
  724.        
  725.         for(p=0; p<N_G; p++) rho[p] = E_CHARGE * (i_density[p] - e_density[p]);  // get charge density
  726.         solve_Poisson(rho,Time);                                                 // compute potential and electric field
  727.        
  728.         // steps 3 & 4: move particles according to electric field interpolated to particle positions
  729.        
  730.         for(k=0; k<N_e; k++){                       // move all electrons in every time step
  731.             c0  = x_e[k] * INV_DX;
  732.             p   = int(c0);
  733.             c1  = p + 1.0 - c0;
  734.             c2  = c0 - p;
  735.             e_x = c1 * efield[p] + c2 * efield[p+1];
  736.            
  737.             if (measurement_mode) {
  738.                
  739.                 // measurements: 'x' and 'v' are needed at the same time, i.e. old 'x' and mean 'v'
  740.                
  741.                 mean_v = vx_e[k] - 0.5 * e_x * FACTOR_E;
  742.                 counter_e_xt[p][t_index]   += c1;
  743.                 counter_e_xt[p+1][t_index] += c2;
  744.                 ue_xt[p][t_index]   += c1 * mean_v;
  745.                 ue_xt[p+1][t_index] += c2 * mean_v;
  746.                 v_sqr  = mean_v * mean_v + vy_e[k] * vy_e[k] + vz_e[k] * vz_e[k];
  747.                 energy = 0.5 * E_MASS * v_sqr / EV_TO_J;
  748.                 meanee_xt[p][t_index]   += c1 * energy;
  749.                 meanee_xt[p+1][t_index] += c2 * energy;
  750.                 energy_index = min( int(energy / DE_CS + 0.5), CS_RANGES-1);
  751.                 velocity = sqrt(v_sqr);
  752.                 double local_neut_dens = GAS_DENSITY - e1_density[p] - e2_density[p];
  753.                 rate = sigma[E_ION][energy_index] * velocity * DT_E * GAS_DENSITY;
  754.                 ioniz_rate_xt[p][t_index]   += c1 * rate;
  755.                 ioniz_rate_xt[p+1][t_index] += c2 * rate;
  756.  
  757.                 // measure EEPF in the center
  758.                
  759.                 if ((MIN_X < x_e[k]) && (x_e[k] < MAX_X)){
  760.                     energy_index = (int)(energy / DE_EEPF);
  761.                     if (energy_index < N_EEPF) {eepf[energy_index] += 1.0;}
  762.                     mean_energy_accu_center += energy;
  763.                     mean_energy_counter_center++;
  764.                 }
  765.             }
  766.            
  767.             // update velocity and position
  768.            
  769.             vx_e[k] -= e_x * FACTOR_E;
  770.             x_e[k]  += vx_e[k] * DT_E;
  771.         }
  772.        
  773.         if ((t % N_SUB) == 0) {                       // move all ions in every N_SUB-th time steps (subcycling)
  774.             for(k=0; k<N_i; k++){
  775.                 c0  = x_i[k] * INV_DX;
  776.                 p   = int(c0);
  777.                 c1  = p + 1 - c0;
  778.                 c2  = c0 - p;
  779.                 e_x = c1 * efield[p] + c2 * efield[p+1];
  780.                
  781.                 if (measurement_mode) {
  782.                    
  783.                     // measurements: 'x' and 'v' are needed at the same time, i.e. old 'x' and mean 'v'
  784.  
  785.                     mean_v = vx_i[k] + 0.5 * e_x * FACTOR_I;
  786.                     counter_i_xt[p][t_index]   += c1;
  787.                     counter_i_xt[p+1][t_index] += c2;
  788.                     ui_xt[p][t_index]   += c1 * mean_v;
  789.                     ui_xt[p+1][t_index] += c2 * mean_v;
  790.                     v_sqr  = mean_v * mean_v + vy_i[k] * vy_i[k] + vz_i[k] * vz_i[k];
  791.                     energy = 0.5 * HE_MASS * v_sqr / EV_TO_J;
  792.                     meanei_xt[p][t_index]   += c1 * energy;
  793.                     meanei_xt[p+1][t_index] += c2 * energy;
  794.                 }
  795.                
  796.                 // update velocity and position and accumulate absorbed energy
  797.                
  798.                 vx_i[k] += e_x * FACTOR_I;
  799.                 x_i[k]  += vx_i[k] * DT_I;
  800.             }
  801.         }
  802.        
  803.         // step 5: check boundaries
  804.        
  805.         k = 0;
  806.         while(k < N_e) {    // check boundaries for all electrons in every time step
  807.             out = false;
  808.             if (x_e[k] < 0) {N_e_abs_pow++; out = true;}    // the electron is out at the powered electrode
  809.             if (x_e[k] > L) {N_e_abs_gnd++; out = true;}    // the electron is out at the grounded electrode
  810.             if (out) {                                      // remove the electron, if out
  811.                 x_e [k] = x_e [N_e-1]; // pushing last element on a vacant place
  812.                 vx_e[k] = vx_e[N_e-1];
  813.                 vy_e[k] = vy_e[N_e-1];
  814.                 vz_e[k] = vz_e[N_e-1];
  815.                 N_e--;
  816.             } else k++;
  817.         }
  818.        
  819.         if ((t % N_SUB) == 0) {   // check boundaries for all ions in every N_SUB-th time steps (subcycling)
  820.             k = 0;
  821.             while(k < N_i) {
  822.                 out = false;
  823.                 if (x_i[k] < 0) {       // the ion is out at the powered electrode
  824.                     N_i_abs_pow++;
  825.                     out    = true;
  826.                     v_sqr  = vx_i[k] * vx_i[k] + vy_i[k] * vy_i[k] + vz_i[k] * vz_i[k];
  827.                     energy = 0.5 * HE_MASS *  v_sqr/ EV_TO_J;
  828.                     energy_index = (int)(energy / DE_IFED);
  829.                     if (energy_index < N_IFED) {ifed_pow[energy_index]++;}       // save IFED at the powered electrode
  830.                 }
  831.                 if (x_i[k] > L) {       // the ion is out at the grounded electrode
  832.                     N_i_abs_gnd++;
  833.                     out    = true;
  834.                     v_sqr  = vx_i[k] * vx_i[k] + vy_i[k] * vy_i[k] + vz_i[k] * vz_i[k];
  835.                     energy = 0.5 * HE_MASS * v_sqr / EV_TO_J;
  836.                     energy_index = (int)(energy / DE_IFED);
  837.                     if (energy_index < N_IFED) {ifed_gnd[energy_index]++;}        // save IFED at the grounded electrode
  838.                 }
  839.                 if (out) {  // delete the ion, if out
  840.                     x_i [k] = x_i [N_i-1];
  841.                     vx_i[k] = vx_i[N_i-1];
  842.                     vy_i[k] = vy_i[N_i-1];
  843.                     vz_i[k] = vz_i[N_i-1];
  844.                     N_i--;
  845.                 } else k++;
  846.             }
  847.         }
  848.        
  849.         // step 6: collisions
  850.        
  851.         for (k=0; k<N_e; k++){                              // checking for occurrence of a collision for all electrons in every time step
  852.             v_sqr = vx_e[k] * vx_e[k] + vy_e[k] * vy_e[k] + vz_e[k] * vz_e[k];
  853.             velocity = sqrt(v_sqr);
  854.             energy   = 0.5 * E_MASS * v_sqr / EV_TO_J;
  855.             energy_index = min( int(energy / DE_CS + 0.5), CS_RANGES-1);
  856.  
  857.             // Artem  - adding superelastic impact on total collisoinal probability//
  858.  
  859.             double c0_temp = x_e[k] * INV_DX;
  860.             int p_temp = std::max(0, std::min(N_G - 1, static_cast<int>(c0_temp)));
  861.             double sigma_super_e = sigma[E_SUPER_1][energy_index] * e1_density[p_temp] + sigma[E_SUPER_2][energy_index] * e2_density[p_temp];
  862.             double ground_dens_local = GAS_DENSITY - e1_density[p_temp] - e2_density[p_temp];
  863.             double sigma_ground = (sigma[E_ELA][energy_index] + sigma[E_EXC_1][energy_index] +
  864.                                 sigma[E_EXC_2][energy_index] + sigma[E_ION][energy_index]) * ground_dens_local;
  865.             nu = (sigma_ground + sigma_super_e) * velocity;
  866.            
  867.             p_coll = 1 - exp(- nu * DT_E);                  // collision probability for electrons
  868.             if (R01(MTgen) < p_coll) {                      // electron collision takes place
  869.                 collision_electron(x_e[k], &vx_e[k], &vy_e[k], &vz_e[k], energy_index);
  870.                 N_e_coll++;
  871.             }
  872.         }
  873.        
  874.         if ((t % N_SUB) == 0) {                             // checking for occurrence of a collision for all ions in every N_SUB-th time steps (subcycling)
  875.             for (k=0; k<N_i; k++){
  876.                 vx_a = RMB_n(MTgen);                          // pick velocity components of a random target gas atom
  877.                 vy_a = RMB_n(MTgen);
  878.                 vz_a = RMB_n(MTgen);
  879.                 gx   = vx_i[k] - vx_a;                       // compute the relative velocity of the collision partners
  880.                 gy   = vy_i[k] - vy_a;
  881.                 gz   = vz_i[k] - vz_a;
  882.                 g_sqr = gx * gx + gy * gy + gz * gz;
  883.                 g = sqrt(g_sqr);
  884.                 energy = 0.5 * MU_HEHE * g_sqr / EV_TO_J;
  885.                 energy_index = min( int(energy / DE_CS + 0.5), CS_RANGES-1);
  886.                 nu = sigma_tot_i[energy_index] * g;
  887.                 p_coll = 1 - exp(- nu * DT_I);              // collision probability for ions
  888.                 if (R01(MTgen)< p_coll) {                   // ion collision takes place
  889.                     collision_ion (&vx_i[k], &vy_i[k], &vz_i[k], &vx_a, &vy_a, &vz_a, energy_index);
  890.                     N_i_coll++;
  891.                 }
  892.             }
  893.         }
  894.        
  895.         if (measurement_mode) {
  896.            
  897.             // collect 'xt' data from the grid
  898.            
  899.             for (p=0; p<N_G; p++) {
  900.                 pot_xt   [p][t_index] += pot[p];
  901.                 efield_xt[p][t_index] += efield[p];
  902.                 ne_xt    [p][t_index] += e_density[p];
  903.                 ni_xt    [p][t_index] += i_density[p];
  904.                 e1_xt    [p][t_index] += e1_density[p];  // Artem
  905.                 e2_xt    [p][t_index] += e2_density[p];  // Artem
  906.             }
  907.         }
  908.        
  909.         if ((t % 1000) == 0) printf(" c = %8d  t = %8d  #e = %8d  #i = %8d\n", cycle,t,N_e,N_i);
  910.     }
  911.     fprintf(datafile,"%8d  %8d  %8d\n",cycle,N_e,N_i);
  912.     print_excitation_densities();
  913. }
  914.  
  915. //---------------------------------------------------------------------//
  916. // save particle coordinates                                           //
  917. //---------------------------------------------------------------------//
  918.  
  919. void save_particle_data(){
  920.     double   d;
  921.     FILE   * f;
  922.     char fname[80];
  923.    
  924.     strcpy(fname,"picdata.bin");
  925.     f = fopen(fname,"wb");
  926.     fwrite(&Time,sizeof(double),1,f);
  927.     d = (double)(cycles_done);
  928.     fwrite(&d,sizeof(double),1,f);
  929.     d = (double)(N_e);
  930.     fwrite(&d,sizeof(double),1,f);
  931.     fwrite(x_e, sizeof(double),N_e,f);
  932.     fwrite(vx_e,sizeof(double),N_e,f);
  933.     fwrite(vy_e,sizeof(double),N_e,f);
  934.     fwrite(vz_e,sizeof(double),N_e,f);
  935.     d = (double)(N_i);
  936.     fwrite(&d,sizeof(double),1,f);
  937.     fwrite(x_i, sizeof(double),N_i,f);
  938.     fwrite(vx_i,sizeof(double),N_i,f);
  939.     fwrite(vy_i,sizeof(double),N_i,f);
  940.     fwrite(vz_i,sizeof(double),N_i,f);
  941.  
  942.     // saving excited state densities - Artem
  943.  
  944.     fwrite(e1_density, sizeof(double), N_G, f);
  945.     fwrite(e2_density, sizeof(double), N_G, f);    
  946.  
  947.     fclose(f);
  948.     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);
  949. }
  950.  
  951. //---------------------------------------------------------------------//
  952. // load particle coordinates                                           //
  953. //---------------------------------------------------------------------//
  954.  
  955. void load_particle_data(){
  956.     double   d;
  957.     FILE   * f;
  958.     char fname[80];
  959.    
  960.     strcpy(fname,"picdata.bin");
  961.     f = fopen(fname,"rb");
  962.     if (f==NULL) {printf(">> eduPIC: ERROR: No particle data file found, try running initial cycle using argument '0'\n"); exit(0); }
  963.     fread(&Time,sizeof(double),1,f);
  964.     fread(&d,sizeof(double),1,f);
  965.     cycles_done = int(d);
  966.     fread(&d,sizeof(double),1,f);
  967.     N_e = int(d);
  968.     fread(x_e, sizeof(double),N_e,f);
  969.     fread(vx_e,sizeof(double),N_e,f);
  970.     fread(vy_e,sizeof(double),N_e,f);
  971.     fread(vz_e,sizeof(double),N_e,f);
  972.     fread(&d,sizeof(double),1,f);
  973.     N_i = int(d);
  974.     fread(x_i, sizeof(double),N_i,f);
  975.     fread(vx_i,sizeof(double),N_i,f);
  976.     fread(vy_i,sizeof(double),N_i,f);
  977.     fread(vz_i,sizeof(double),N_i,f);
  978.  
  979.     // reading excited states densities -- Artem
  980.  
  981.     fread(e1_density, sizeof(double), N_G, f);
  982.     fread(e2_density, sizeof(double), N_G, f);    
  983.  
  984.     fclose(f);
  985.     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);
  986. }
  987.  
  988. //---------------------------------------------------------------------//
  989. // save density data                                                   //
  990. //---------------------------------------------------------------------//
  991.  
  992. void save_density(void){
  993.     FILE *f;
  994.     double c;
  995.     int m;
  996.    
  997.     f = fopen("density.dat","w");
  998.     c = 1.0 / (double)(no_of_cycles) / (double)(N_T);
  999.     for(m=0; m<N_G; m++){
  1000.         fprintf(f,"%8.5f  %12e  %12e\n",m * DX, cumul_e_density[m] * c, cumul_i_density[m] * c);
  1001.     }
  1002.     fclose(f);
  1003. }
  1004.  
  1005. // save Final excited states densities - Artem
  1006.  
  1007. void save_final_excited_densities(void) {
  1008.     FILE *f = fopen("excited_densities.dat", "w");
  1009.     for(int p=0; p<N_G; p++) {
  1010.         fprintf(f, "%8.5f %12e %12e\n", p*DX, e1_density[p], e2_density[p]);
  1011.     }
  1012.     fclose(f);
  1013. }
  1014.  
  1015. //---------------------------------------------------------------------//
  1016. // save EEPF data                                                      //
  1017. //---------------------------------------------------------------------//
  1018.  
  1019. void save_eepf(void) {
  1020.     FILE   *f;
  1021.     int    i;
  1022.     double h,energy;
  1023.    
  1024.     h = 0.0;
  1025.     for (i=0; i<N_EEPF; i++) {h += eepf[i];}
  1026.     h *= DE_EEPF;
  1027.     f = fopen("eepf.dat","w");
  1028.     for (i=0; i<N_EEPF; i++) {
  1029.         energy = (i + 0.5) * DE_EEPF;
  1030.         fprintf(f,"%e  %e\n", energy, eepf[i] / h / sqrt(energy));
  1031.     }
  1032.     fclose(f);
  1033. }
  1034.  
  1035. //---------------------------------------------------------------------//
  1036. // save IFED data                                                      //
  1037. //---------------------------------------------------------------------//
  1038.  
  1039. void save_ifed(void) {
  1040.     FILE   *f;
  1041.     int    i;
  1042.     double h_pow,h_gnd,energy;
  1043.    
  1044.     h_pow = 0.0;
  1045.     h_gnd = 0.0;
  1046.     for (i=0; i<N_IFED; i++) {h_pow += ifed_pow[i]; h_gnd += ifed_gnd[i];}
  1047.     h_pow *= DE_IFED;
  1048.     h_gnd *= DE_IFED;
  1049.     mean_i_energy_pow = 0.0;
  1050.     mean_i_energy_gnd = 0.0;
  1051.     f = fopen("ifed.dat","w");
  1052.     for (i=0; i<N_IFED; i++) {
  1053.         energy = (i + 0.5) * DE_IFED;
  1054.         fprintf(f,"%6.2f %10.6f %10.6f\n", energy, (double)(ifed_pow[i])/h_pow, (double)(ifed_gnd[i])/h_gnd);
  1055.         mean_i_energy_pow += energy * (double)(ifed_pow[i]) / h_pow;
  1056.         mean_i_energy_gnd += energy * (double)(ifed_gnd[i]) / h_gnd;
  1057.     }
  1058.     fclose(f);
  1059. }
  1060.  
  1061. //--------------------------------------------------------------------//
  1062. // save XT data                                                       //
  1063. //--------------------------------------------------------------------//
  1064.  
  1065. void save_xt_1(xt_distr distr, char *fname) {
  1066.     FILE   *f;
  1067.     int    i, j;
  1068.    
  1069.     f = fopen(fname,"w");
  1070.     for (i=0; i<N_G; i++){
  1071.         for (j=0; j<N_XT; j++){
  1072.             fprintf(f,"%e  ", distr[i][j]);
  1073.         }
  1074.         fprintf(f,"\n");
  1075.     }
  1076.     fclose(f);
  1077. }
  1078.  
  1079. void norm_all_xt(void){
  1080.     double f1, f2;
  1081.     int    i, j;
  1082.    
  1083.     // normalize all XT data
  1084.    
  1085.     f1 = (double)(N_XT) / (double)(no_of_cycles * N_T);
  1086.     f2 = WEIGHT / (ELECTRODE_AREA * DX) / (no_of_cycles * (PERIOD / (double)(N_XT)));
  1087.    
  1088.     for (i=0; i<N_G; i++){
  1089.         for (j=0; j<N_XT; j++){
  1090.             pot_xt[i][j]    *= f1;
  1091.             efield_xt[i][j] *= f1;
  1092.             ne_xt[i][j]     *= f1;
  1093.             ni_xt[i][j]     *= f1;
  1094.             e1_xt[i][j]     *= f1;   // Artem
  1095.             e2_xt[i][j]     *= f1;   // Artem
  1096.             if (counter_e_xt[i][j] > 0) {
  1097.                 ue_xt[i][j]     =  ue_xt[i][j] / counter_e_xt[i][j];
  1098.                 je_xt[i][j]     = -ue_xt[i][j] * ne_xt[i][j] * E_CHARGE;
  1099.                 meanee_xt[i][j] =  meanee_xt[i][j] / counter_e_xt[i][j];
  1100.                 ioniz_rate_xt[i][j] *= f2;
  1101.              } else {
  1102.                 ue_xt[i][j]         = 0.0;
  1103.                 je_xt[i][j]         = 0.0;
  1104.                 meanee_xt[i][j]     = 0.0;
  1105.                 ioniz_rate_xt[i][j] = 0.0;
  1106.             }
  1107.             if (counter_i_xt[i][j] > 0) {
  1108.                 ui_xt[i][j]     = ui_xt[i][j] / counter_i_xt[i][j];
  1109.                 ji_xt[i][j]     = ui_xt[i][j] * ni_xt[i][j] * E_CHARGE;
  1110.                 meanei_xt[i][j] = meanei_xt[i][j] / counter_i_xt[i][j];
  1111.             } else {
  1112.                 ui_xt[i][j]     = 0.0;
  1113.                 ji_xt[i][j]     = 0.0;
  1114.                 meanei_xt[i][j] = 0.0;
  1115.             }
  1116.             powere_xt[i][j] = je_xt[i][j] * efield_xt[i][j];
  1117.             poweri_xt[i][j] = ji_xt[i][j] * efield_xt[i][j];
  1118.         }
  1119.     }
  1120. }
  1121.  
  1122. void save_all_xt(void){
  1123.     char fname[80];
  1124.    
  1125.     strcpy(fname,"pot_xt.dat");     save_xt_1(pot_xt, fname);
  1126.     strcpy(fname,"efield_xt.dat");  save_xt_1(efield_xt, fname);
  1127.     strcpy(fname,"ne_xt.dat");      save_xt_1(ne_xt, fname);
  1128.     strcpy(fname,"ni_xt.dat");      save_xt_1(ni_xt, fname);
  1129.     strcpy(fname,"je_xt.dat");      save_xt_1(je_xt, fname);
  1130.     strcpy(fname,"ji_xt.dat");      save_xt_1(ji_xt, fname);
  1131.     strcpy(fname,"powere_xt.dat");  save_xt_1(powere_xt, fname);
  1132.     strcpy(fname,"poweri_xt.dat");  save_xt_1(poweri_xt, fname);
  1133.     strcpy(fname,"meanee_xt.dat");  save_xt_1(meanee_xt, fname);
  1134.     strcpy(fname,"meanei_xt.dat");  save_xt_1(meanei_xt, fname);
  1135.     strcpy(fname,"ioniz_xt.dat");   save_xt_1(ioniz_rate_xt, fname);
  1136.     strcpy(fname,"e1_xt.dat");      save_xt_1(e1_xt, fname);
  1137.     strcpy(fname,"e2_xt.dat");      save_xt_1(e2_xt, fname);
  1138. }
  1139.  
  1140. //---------------------------------------------------------------------//
  1141. // simulation report including stability and accuracy conditions       //
  1142. //---------------------------------------------------------------------//
  1143.  
  1144. void check_and_save_info(void){
  1145.     FILE     *f;
  1146.     double   plas_freq, meane, kT, debye_length, density, ecoll_freq, icoll_freq, sim_time, e_max, v_max, power_e, power_i, c;
  1147.     int      i,j;
  1148.     bool     conditions_OK;
  1149.    
  1150.     density    = cumul_e_density[N_G / 2] / (double)(no_of_cycles) / (double)(N_T);  // e density @ center
  1151.     plas_freq  = E_CHARGE * sqrt(density / EPSILON0 / E_MASS);                       // e plasma frequency @ center
  1152.     meane      = mean_energy_accu_center / (double)(mean_energy_counter_center);     // e mean energy @ center
  1153.     kT         = 2.0 * meane * EV_TO_J / 3.0;                                        // k T_e @ center (approximate)
  1154.     sim_time   = (double)(no_of_cycles) / FREQUENCY;                                 // simulated time
  1155.     ecoll_freq = (double)(N_e_coll) / sim_time / (double)(N_e);                      // e collision frequency
  1156.     icoll_freq = (double)(N_i_coll) / sim_time / (double)(N_i);                      // ion collision frequency
  1157.     debye_length = sqrt(EPSILON0 * kT / density) / E_CHARGE;                         // e Debye length @ center
  1158.    
  1159.     f = fopen("info.txt","w");
  1160.     fprintf(f,"########################## eduPIC simulation report ############################\n");
  1161.     fprintf(f,"Simulation parameters:\n");
  1162.     fprintf(f,"Gap distance                          = %12.3e [m]\n",  L);
  1163.     fprintf(f,"# of grid divisions                   = %12d\n",      N_G);
  1164.     fprintf(f,"Frequency                             = %12.3e [Hz]\n", FREQUENCY);
  1165.     fprintf(f,"# of time steps / period              = %12d\n",      N_T);
  1166.     fprintf(f,"# of electron / ion time steps        = %12d\n",      N_SUB);
  1167.     fprintf(f,"Voltage amplitude                     = %12.3e [V]\n",  VOLTAGE);
  1168.     fprintf(f,"Pressure (Ar)                         = %12.3e [Pa]\n", PRESSURE);
  1169.     fprintf(f,"Temperature                           = %12.3e [K]\n",  T_neutral);
  1170.     fprintf(f,"Superparticle weight                  = %12.3e\n",      WEIGHT);
  1171.     fprintf(f,"# of simulation cycles in this run    = %12d\n",      no_of_cycles);
  1172.     fprintf(f,"--------------------------------------------------------------------------------\n");
  1173.     fprintf(f,"Plasma characteristics:\n");
  1174.     fprintf(f,"Electron density @ center             = %12.3e [m^{-3}]\n", density);
  1175.     fprintf(f,"Plasma frequency @ center             = %12.3e [rad/s]\n",  plas_freq);
  1176.     fprintf(f,"Debye length @ center                 = %12.3e [m]\n",      debye_length);
  1177.     fprintf(f,"Electron collision frequency          = %12.3e [1/s]\n",    ecoll_freq);
  1178.     fprintf(f,"Ion collision frequency               = %12.3e [1/s]\n",    icoll_freq);
  1179.     fprintf(f,"--------------------------------------------------------------------------------\n");
  1180.     fprintf(f,"Stability and accuracy conditions:\n");
  1181.     conditions_OK = true;
  1182.     c = plas_freq * DT_E;
  1183.     fprintf(f,"Plasma frequency @ center * DT_E      = %12.3f (OK if less than 0.20)\n", c);
  1184.     if (c > 0.2) {conditions_OK = false;}
  1185.     c = DX / debye_length;
  1186.     fprintf(f,"DX / Debye length @ center            = %12.3f (OK if less than 1.00)\n", c);
  1187.     if (c > 1.0) {conditions_OK = false;}
  1188.     c = max_electron_coll_freq() * DT_E;
  1189.     fprintf(f,"Max. electron coll. frequency * DT_E  = %12.3f (OK if less than 0.05)\n", c);
  1190.     if (c > 0.05) {conditions_OK = false;}
  1191.     c = max_ion_coll_freq() * DT_I;
  1192.     fprintf(f,"Max. ion coll. frequency * DT_I       = %12.3f (OK if less than 0.05)\n", c);
  1193.     if (c > 0.05) {conditions_OK = false;}
  1194.     if (conditions_OK == false){
  1195.         fprintf(f,"--------------------------------------------------------------------------------\n");
  1196.         fprintf(f,"** STABILITY AND ACCURACY CONDITION(S) VIOLATED - REFINE SIMULATION SETTINGS! **\n");
  1197.         fprintf(f,"--------------------------------------------------------------------------------\n");
  1198.         fclose(f);
  1199.         printf(">> eduPIC: ERROR: STABILITY AND ACCURACY CONDITION(S) VIOLATED!\n");
  1200.         printf(">> eduPIC: for details see 'info.txt' and refine simulation settings!\n");
  1201.     }
  1202.     else
  1203.     {
  1204.         // calculate maximum energy for which the Courant-Friedrichs-Levy condition holds:
  1205.        
  1206.         v_max = DX / DT_E;
  1207.         e_max = 0.5 * E_MASS * v_max * v_max / EV_TO_J;
  1208.         fprintf(f,"Max e- energy for CFL condition       = %12.3f [eV]\n", e_max);
  1209.         fprintf(f,"Check EEPF to ensure that CFL is fulfilled for the majority of the electrons!\n");
  1210.         fprintf(f,"--------------------------------------------------------------------------------\n");
  1211.        
  1212.         // saving of the following data is done here as some of the further lines need data
  1213.         // that are computed / normalized in these functions
  1214.        
  1215.         printf(">> eduPIC: saving diagnostics data\n");
  1216.         save_density();
  1217.         save_final_excited_densities();   // Artem
  1218.         save_eepf();
  1219.         save_ifed();
  1220.         norm_all_xt();
  1221.         save_all_xt();
  1222.         fprintf(f,"Particle characteristics at the electrodes:\n");
  1223.         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));
  1224.         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));
  1225.         fprintf(f,"Mean ion energy at powered electrode  = %12.3e [eV]\n", mean_i_energy_pow);
  1226.         fprintf(f,"Mean ion energy at grounded electrode = %12.3e [eV]\n", mean_i_energy_gnd);
  1227.         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));
  1228.         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));
  1229.         fprintf(f,"--------------------------------------------------------------------------------\n");
  1230.        
  1231.         // calculate spatially and temporally averaged power absorption by the electrons and ions
  1232.        
  1233.         power_e = 0.0;
  1234.         power_i = 0.0;
  1235.         for (i=0; i<N_G; i++){
  1236.             for (j=0; j<N_XT; j++){
  1237.                 power_e += powere_xt[i][j];
  1238.                 power_i += poweri_xt[i][j];
  1239.             }
  1240.         }
  1241.         power_e /= (double)(N_XT * N_G);
  1242.         power_i /= (double)(N_XT * N_G);
  1243.         fprintf(f,"Absorbed power calculated as <j*E>:\n");
  1244.         fprintf(f,"Electron power density (average)      = %12.3e [W m^{-3}]\n", power_e);
  1245.         fprintf(f,"Ion power density (average)           = %12.3e [W m^{-3}]\n", power_i);
  1246.         fprintf(f,"Total power density(average)          = %12.3e [W m^{-3}]\n", power_e + power_i);
  1247.         fprintf(f,"--------------------------------------------------------------------------------\n");
  1248.         fclose(f);
  1249.     }
  1250. }
  1251.  
  1252. //------------------------------------------------------------------------------------------//
  1253. // main                                                                                     //
  1254. // command line arguments:                                                                  //
  1255. // [1]: number of cycles (0 for init)                                                       //
  1256. // [2]: "m" turns on data collection and saving                                             //
  1257. //------------------------------------------------------------------------------------------//
  1258.  
  1259. int main (int argc, char *argv[]){
  1260.     printf(">> eduPIC: starting...\n");
  1261.     printf(">> eduPIC: **************************************************************************\n");
  1262.     printf(">> eduPIC: Copyright (C) 2021 Z. Donko et al.\n");
  1263.     printf(">> eduPIC: This program comes with ABSOLUTELY NO WARRANTY\n");
  1264.     printf(">> eduPIC: This is free software, you are welcome to use, modify and redistribute it\n");
  1265.     printf(">> eduPIC: according to the GNU General Public License, https://www.gnu.org/licenses/\n");
  1266.     printf(">> eduPIC: **************************************************************************\n");
  1267.  
  1268.     if (argc == 1) {
  1269.         printf(">> eduPIC: error = need starting_cycle argument\n");
  1270.         return 1;
  1271.     } else {
  1272.         strcpy(st0,argv[1]);
  1273.         arg1 = atol(st0);
  1274.         if (argc > 2) {
  1275.             if (strcmp (argv[2],"m") == 0){
  1276.                 measurement_mode = true;                  // measurements will be done
  1277.             } else {
  1278.                 measurement_mode = false;
  1279.             }
  1280.         }
  1281.     }
  1282.     if (measurement_mode) {
  1283.         printf(">> eduPIC: measurement mode: on\n");
  1284.     } else {
  1285.         printf(">> eduPIC: measurement mode: off\n");
  1286.     }
  1287.     set_electron_cross_sections_ar();
  1288.     set_ion_cross_sections_ar();
  1289.     calc_total_cross_sections();
  1290.  
  1291.     auto exc = init_excited_distr();
  1292.     printf("Excited state population - superparticles!!!\n");
  1293.     printf("%d %d\n", exc.first, exc.second);
  1294.  
  1295.     printf("Sanity check \n");
  1296.     fflush(stdout);
  1297.  
  1298.     //test_cross_sections(); return 1;
  1299.     datafile = fopen("conv.dat","a");
  1300.     if (arg1 == 0) {
  1301.         if (FILE *file = fopen("picdata.bin", "r")) { fclose(file);
  1302.             printf(">> eduPIC: Warning: Data from previous calculation are detected.\n");
  1303.             printf("           To start a new simulation from the beginning, please delete all output files before running ./eduPIC 0\n");
  1304.             printf("           To continue the existing calculation, please specify the number of cycles to run, e.g. ./eduPIC 100\n");
  1305.             exit(0);
  1306.         }
  1307.         no_of_cycles = 1;
  1308.         cycle = 1;                                        // init cycle
  1309.         init(N_INIT);                                     // seed initial electrons & ions
  1310.         printf(">> eduPIC: running initializing cycle\n");
  1311.         Time = 0;
  1312.         do_one_cycle();
  1313.         print_excitation_densities();
  1314.         cycles_done = 1;
  1315.     } else {
  1316.         no_of_cycles = arg1;                              // run number of cycles specified in command line
  1317.         load_particle_data();                            // read previous configuration from file
  1318.         printf(">> eduPIC: running %d cycle(s)\n",no_of_cycles);
  1319.         for (cycle=cycles_done+1;cycle<=cycles_done+no_of_cycles;cycle++) {do_one_cycle();}
  1320.         cycles_done += no_of_cycles;
  1321.     }
  1322.     fclose(datafile);
  1323.     save_particle_data();
  1324.     if (measurement_mode) {
  1325.         check_and_save_info();
  1326.     }
  1327.     printf(">> eduPIC: simulation of %d cycle(s) is completed.\n",no_of_cycles);
  1328. }
  1329.  
Add Comment
Please, Sign In to add comment