1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88
|
// 1 particle pulse EM accel.cpp
//--------------------------------------------------
//A Runge-Kutta Method for solving Differential Equations
//pertaining to Electron acceleration
//by an intense laser pulse with echelon phase modulation
//--------------------------------------------------
#include <iostream>
#include <iomanip>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
using namespace std;
//Define constants
#define E0 0.01
#define zR 20.0
#define omega 8.0*atan(1.0)//or use pi=3.141592653589793238462643383279502884197
#define k 8.0*atan(1.0)
#define a 1.0 //representing elementary charge over electron mass
#define T0 0.0
#define X0 0.001
#define Y0 0.001
#define Z0 0.001
#define VX0 0.001 //need electrons at 300K = 95335.79 m/s
#define VY0 0.001
#define VZ0 0.001
#define H 0.01
#define I 550
//#define s 0.1
//#define E0 6*pow(10.0,11.0) //3.22*10^11 is an approximate minimum for a high power laser
//#define me 9.11*pow(10.0,-31.0)
//#define cspd 3*pow(10.0,8.0), represented by a 3 below
//Define Functions
double rungevx(double t, double vx, double vy, double vz, double x, double y, double z);
double rungevy(double t, double vx, double vy, double vz, double x, double y, double z);
double rungevz(double t, double vx, double vy, double vz, double x, double y, double z);
double rungex(double t, double vx, double vy, double vz, double x, double y, double z);
double rungey(double t, double vx, double vy, double vz, double x, double y, double z);
double rungez(double t, double vx, double vy, double vz, double x, double y, double z);
double fvx(double t, double vx, double vy, double vz, double x, double y, double z);
double fvy(double t, double vx, double vy, double vz, double x, double y, double z);
double fvz(double t, double vx, double vy, double vz, double x, double y, double z);
double fx(double t, double vx, double vy, double vz, double x, double y, double z);
double fy(double t, double vx, double vy, double vz, double x, double y, double z);
double fz(double t, double vx, double vy, double vz, double x, double y, double z);
//--------------------------------------------------
//Main Function
int main()
{
FILE * ElectronData;
int i;
double t=T0;
double vx=VX0;
double vy=VY0;
double vz=VZ0;
double x=X0;
double y=Y0;
double z=Z0;
//double cspd=3*pow(10.0,8.0);
for(i=1;i<=I-1;i++)
{
vx=rungevx(t,vx,vy,vz,x,y,z);
vy=rungevy(t,vx,vy,vz,x,y,z);
vz=rungevz(t,vx,vy,vz,x,y,z);
x=rungex(t,vx,vy,vz,x,y,z);
y=rungey(t,vx,vy,vz,x,y,z);
z=rungez(t,vx,vy,vz,x,y,z);
if(i==1)
ElectronData = fopen("Electron_Data.txt","w");
else
ElectronData = fopen("Electron_Data.txt","a");
fprintf(ElectronData,"%E, %E, %E, %E, %E, %E, %E\n",x,y,z,vx,vy,vz,t);
t = t + H;
}
fclose(ElectronData);
return 0;
}
//write functions below
|