Advertisement
phystota

integral_inside_loop

Apr 1st, 2025
550
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.10 KB | None | 0 0
  1.  
  2.         // calculating the integral each timestep    
  3.         double integral = 0.0;
  4.         double E_n = 1.5 * T_n;
  5.  
  6.         // creating histogram each timestep
  7.         for (int i = 0; i < n_e; i++){
  8.             int bin = (int)( (electrons[i].energy - Emin)/bin_width );
  9.             if (bin >=0 && bin < N)
  10.             histo_maxwell[bin]++;
  11.         }
  12.  
  13.         for (int i = 0; i < N; i++){
  14.             double bin_center = Emin + (i + 0.5) * bin_width;
  15.             integral+= (bin_center - E_n)*elastic_vec[i]*sqrt(bin_center)*( static_cast<double>(histo_maxwell[i])/(electrons.size()*bin_width) ) * delta * (N_He/Volume) * sqrt(2*q/m_e) * bin_width; //
  16.         }
  17.  
  18.         E_mean -= integral*dt;
  19.  
  20.         file10 << t*dt << " " << E_mean << "\n";
  21.  
  22.         for (int i = 0; i < N; i++){
  23.             histo_maxwell[i] = 0;
  24.         }        
  25.  
  26.  
  27.         // calculating mean energy
  28.         double total_energy = 0.0;
  29.         for (const auto& e : electrons) total_energy += e.energy;
  30.         double mean_energy = total_energy / n_e;
  31.         file8 << t*dt << " " << mean_energy << "\n";                
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement