-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtube.C
More file actions
161 lines (146 loc) · 4.82 KB
/
tube.C
File metadata and controls
161 lines (146 loc) · 4.82 KB
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
#include <iostream>
using namespace std;
// ROOT
#include <TTree.h>
#include <TFile.h>
#include <TMath.h>
#include <TChain.h>
#include <TGraph.h>
using namespace TMath;
// UNIC
#include <UNIC/Units.h>
#include <UNIC/Constants.h>
using namespace UNIC;
// MAD
#include <MAD/GeCrystal.h>
using namespace MAD;
const int N = 2000;
// df at i
double d(double *f, int i)
{
if (i<1 || i>2*N-1) return 0;
return (f[i+1]-f[i-1])/2; // 2 points
//if (i<2 || i>2*N-2) return 0;
//return (-f[i+2]+8*f[i+1]-8*f[i-1]+f[i-2])/12; // 4
//if (i<4 || i>2*N-4) return 0;
//return (-f[i+4]-8*f[i+2]+128*f[i+1]-128*f[i-1]+8*f[i-2]+f[i-4])/180; // 6
}
// thin plasma tube
int main(int argc, char** argv)
{
double dt=5e-7*ns; // large dt causes E to decrease too fast
double dx=0.2*nm; // small dx may cause artificial oscillation
double Ee=500*volt/cm;
double R=1.97e-7*cm, mean=0, sigma=R/3, height=84./(Pi()*R*R);
bool norm;
GeCrystal ge;
double epsilon=ge.Epsilon()*epsilon0;
double Q=Abs(electron_charge);
//double De=0.046*cm2/s, Dh=0.046*cm2/s;
// initialize arrays
// p and n are number densities
double x[2*N+1], p[2*N+1], n[2*N+1], E[2*N+1], pE[2*N+1],nE[2*N+1], T[10000], J[10000];
if (argc==3) {
TChain *ti = new TChain("t");
ti->Add(argv[2]);
ti->SetBranchAddress("x",x);
ti->SetBranchAddress("p",p);
ti->SetBranchAddress("n",n);
ti->SetBranchAddress("E",E);
ti->GetEntry(ti->GetEntries()-1);
} else {
for (int i=0; i<2*N+1; i++) {
x[i]=(i-N)*dx;
p[i]=n[i]=height*Gaus(x[i],mean=0,sigma,norm=kTRUE);
if (p[i]<1e-5/cm3) p[i]=0;
if (n[i]<1e-5/cm3) n[i]=0;
E[i]=Ee;
}
}
for (int i=0; i<2*N+1; i++) {
pE[i]=p[i]*E[i];
nE[i]=n[i]*E[i];
}
for (int i=0; i<1000; i++){
J[i] = 0;
T[i] = 0;
}
// output
TFile *output = new TFile("tube.root","recreate");
TTree *t = new TTree("t","time slices");
t->Branch("x",x,Form("x[%d]/D",2*N+1));
t->Branch("p",p,Form("p[%d]/D",2*N+1));
t->Branch("n",n,Form("n[%d]/D",2*N+1));
t->Branch("E",E,Form("E[%d]/D",2*N+1));
// save units into tree
double CM3=cm3, CM2=cm2, CM=cm, UM=um, V=volt, SEC=s, NS=ns, NM=nm;
t->Branch("cm3",&CM3,"cm3/D");
t->Branch("cm2",&CM2,"cm2/D");
t->Branch("V",&V,"V/D");
t->Branch("cm",&CM,"cm/D");
t->Branch("um",&UM,"um/D");
t->Branch("nm",&NM,"nm/D");
t->Branch("ns",&NS,"ns/D");
t->Branch("s",&SEC,"s/D");
int iStep=0, nSteps = 100;
// evolve
if (argc>1) nSteps = atoi(argv[1]);
while (iStep<nSteps) {
if ((iStep+1)%100==0) cout<<iStep+1<<" steps passed"<<endl;
t->Fill();
// update electron and hole distributions
for (int i=0; i<2*N+1; i++) {
double dn_dt = ge.Mu('e', n[i])*d(nE,i)/dx;
double dp_dt =-ge.Mu('h', p[i])*d(pE,i)/dx;
if (Abs(dn_dt*dt)<1e-10/cm3) dn_dt=0;
if (Abs(dp_dt*dt)<1e-10/cm3) dp_dt=0;
n[i]+=dn_dt*dt;
p[i]+=dp_dt*dt;
if (n[i]<0) n[i]=0;
if (p[i]<0) p[i]=0;
}
if (iStep<=1000&&(iStep+1)%20==0){
double aa = 0; //initialization
for (int i=N; i<2*N+1; i++) aa += (p[i]-n[i]);
J[(iStep+1)/20-1] = aa*Q*dx/(iStep+1)/dt/(coulomb/s/cm2);
T[(iStep+1)/20-1] = (iStep+1);
cout<<"test: "<<(iStep+1)/20-1<<",J: "<<J[(iStep+1)/20-1]<<", T: "<<T[(iStep+1)/20-1]<<endl;
}
if (iStep>1000 && iStep<=2000 && (iStep+1)%100==0){
double aa = 0; //initialization
for (int i=N; i<2*N+1; i++) aa += (p[i]-n[i]);
J[(iStep+1)/100+39] = aa*Q*dx/(iStep+1)/dt/(coulomb/s/cm2);
T[(iStep+1)/100+39] = (iStep+1);
cout<<"test: "<<(iStep+1)/100+39<<",J: "<<J[(iStep+1)/100+39]<<", T: "<<T[(iStep+1)/100+39]<<endl;
}
if (iStep>2000&&(iStep+1)%1000==0){
double aa = 0; //initialization
for (int i=N; i<2*N+1; i++) aa += (p[i]-n[i]);
J[(iStep+1)/1000+57] = aa*Q*dx/(iStep+1)/dt/(coulomb/s/cm2);
T[(iStep+1)/1000+57] = (iStep+1);
cout<<"test: "<<(iStep+1)/1000+57<<",J: "<<J[(iStep+1)/1000+57]<<", T: "<<T[(iStep+1)/1000+57]<<endl;
}
// update electric field distribution
for (int i=0; i<2*N+1; i++) {
E[i]=0;
for (int j=0; j<i; j++)
E[i]+=(p[j]-n[j])*(1-(i-j)*dx/sqrt((i-j)*(i-j)*dx*dx+R*R));
for (int j=i+1; j<2*N+1; j++)
E[i]+=(n[j]-p[j])*(1-(j-i)*dx/sqrt((j-i)*(j-i)*dx*dx+R*R));
E[i]*=Q*dx/2/epsilon;
E[i]+=Ee;
if (E[i]<1e-10*volt/cm) E[i]=0; // large dt may over evolve things
}
// update pE[i]and nE[i]
for (int i=0; i<2*N+1; i++){
pE[i] = p[i]*E[i];
nE[i] = n[i]*E[i];
}
iStep++;
}
t->Write("t",6);
TGraph *g = new TGraph (nSteps, T, J);
g->Write("g");
output->Close();
return 0;
}