// // electron_boris.h // mc_electron // // Created by Christian Reiling on 16.05.19. // Copyright © 2019 Christian Reiling. All rights reserved. // #ifndef electron_boris_h #define electron_boris_h #include "mover_base.h" class E_Mover_Boris : public Mover_Base { double dt_s; public: E_Mover_Boris(double dt_s, Particle_Logger_Base *Logger, Population_Base *Population) : Mover_Base(electron, Logger, Population) { this->dt_s = dt_s; }; void move(Particle *movePart, const double ¯o_sigma_m); private: double doBoris_singleStep_m(Particle *movePart, const vec3 &E_Vm , const vec3 &B_T); void doBoris_speedChange(Particle *movePart, const vec3 &E_Vm, const vec3 &B_T); bool doBoris_WallInteraction(Particle *movePart); void doBoris_LogzDirChange(Particle *movePart, double *oldzDir, vec3 *oldLoc_m); }; void E_Mover_Boris::move(Particle *movePart, const double ¯o_sigma_m) { // Prepare detection for change of z direction for logging double oldzDir = movePart->get_v_ms()[2] < 0 ? -1 : 1; vec3 oldLoc_m = movePart->get_x_m(); if (macro_sigma_m == 0) { // If infinite movement distance let electron leave at only exit... Prob extremly faulty, but also impossible. movePart->set_x_m(z_RW_m); Logger->log(*movePart,oldLoc_m); return; } double distance_m = 1/macro_sigma_m; double traveledDistance_m = 0; vec3 loc_m, E_Vm ,B_T; while (traveledDistance_m < distance_m) { loc_m = movePart->get_x_m(); E_Vm = Katrin_Fields::getElField_Vm(loc_m); B_T = Katrin_Fields::getMagField_T(loc_m); traveledDistance_m += doBoris_singleStep_m(movePart, E_Vm, B_T); if (doBoris_WallInteraction(movePart) == true) { Logger->log(*movePart, oldLoc_m); Population->increase_density(*movePart, oldLoc_m); return; } doBoris_LogzDirChange(movePart, &oldzDir, &oldLoc_m); // Log if z direction changes, and adapt quantities } Logger->log(*movePart,oldLoc_m); Population->increase_density(*movePart, oldLoc_m); return; } double E_Mover_Boris::doBoris_singleStep_m(Particle *movePart, const vec3 &E_Vm , const vec3 &B_T) { double distance_m; vec3 x_m = movePart->get_x_m(); vec3 v_ms = movePart->get_v_ms(); x_m += dt_s/2 * v_ms; distance_m = dt_s/2 * calc_vec3_abs(v_ms); doBoris_speedChange(movePart, E_Vm , B_T); x_m += dt_s/2 * v_ms; distance_m += dt_s/2 * calc_vec3_abs(v_ms); movePart->set_x_m(x_m); return distance_m; } void E_Mover_Boris::doBoris_speedChange(Particle *movePart, const vec3 &E_Vm, const vec3 &B_T) { double q_C = movePart->get_Z() * e_C; double m_kg = movePart->get_m_eV() * e_C/c_ms/c_ms; vec3 v_ms = movePart->get_v_ms(); vec3 t = q_C*dt_s/(2*m_kg) * B_T; vec3 s = (2*t)/(1+dot(t,t)); vec3 vMinus_ms = v_ms + (q_C*E_Vm*dt_s)/(2*m_kg); vec3 vPrime_ms = vMinus_ms + cross(vMinus_ms,t); vec3 vPlus_ms = vMinus_ms + cross(vPrime_ms,s); v_ms = vPlus_ms + q_C/m_kg*E_Vm*0.5*dt_s; movePart->set_v_ms(v_ms); } bool E_Mover_Boris::doBoris_WallInteraction(Particle *movePart) { vec3 loc_m = movePart->get_x_m(); double r_m = movePart->get_r_m(); if (loc_m[2]<=z_RW_m) { // Rear Wall Termination vec3 newLoc_m = movePart->get_x_m(); newLoc_m[2] = 0; movePart->set_x_m(newLoc_m); return true; } if (r_m>=r_WGTS_m) { // WGTS Wall Termination vec3 newLoc_m = movePart->get_x_m(); double z_m = newLoc_m[2]; newLoc_m[2] = 0; newLoc_m = (r_WGTS_m * 1.01)/calc_vec3_abs(newLoc_m) * newLoc_m; //1.01 to move Particle slightly out of WGTS newLoc_m[2] = z_m; return true; } if (loc_m[2]>=z_WGTS_end_m) { // Spectrometer Reflection movePart->set_v_ms( -1*(movePart->get_v_ms()) ); } return false; } void E_Mover_Boris::doBoris_LogzDirChange(Particle *movePart, double *oldzDir, vec3 *oldLoc_m) { double zDir = movePart->get_v_ms()[2] < 0 ? -1 : 1; if (*oldzDir != zDir) { Logger->log(*movePart, *oldLoc_m); Population->increase_density(*movePart, *oldLoc_m); *oldzDir = zDir; *oldLoc_m = movePart->get_x_m(); } return; } #endif /* electron_boris_h */