Automatic commit. Fri Sep 21 12:00:07 WST 2012
[matches/honours.git] / thesis / theory.py
1 #!/usr/bin/python -u
2
3 #
4 # @file theory.py
5 # @purpose Do theory stuff
6 #               Because sadly, Mathematica does not work on my new laptop
7 # @author Sam Moore
8 # @date August 2012
9 #
10
11 import sys
12 import os
13 import math
14 import re # Regular expressions - for removing comments
15 #import odict #ordered dictionary
16
17 import Gnuplot, Gnuplot.funcutils
18
19 gnuplot = Gnuplot.Gnuplot()
20
21
22 #
23 # @function se_dist
24 # @purpose Model the secondary electron distribution using M. Furman's formula
25 #
26 def se_dist(s, Ep, sigma_p, dE, n_max=0.75):
27         results = []
28         E = 0.0
29         while (E < 8.0):
30                 results.append([E, n_max *s * E / (s - 1.0 + E**s) , math.exp(-(E - Ep)**2.0 / (2.0*sigma_p**2.0))])
31                 E += dE
32         return results
33
34
35 # @function write_data
36 # @purpose Write a list of data to a file suitable for gnuplotting
37 #
38 def write_data(data, fileName):
39         out = open(fileName, "w")
40         for line in data:
41                 for column in line:
42                         out.write(str(column) + "\t")
43                 out.write("\n")
44         out.close()
45
46 def Plot(*args):
47         gnuplot.plot(args)
48
49
50 def main():     
51         
52         test = se_dist(4.0, 7.0, 0.2, 0.01)
53         #gnuplot.replot(map(lambda e : [e[0], e[1] + e[2]], test))
54         #gnuplot.replot(map(lambda e : [e[0], e[2]], test))
55         write_data(test, "se_dist.dat") 
56         
57         print("Press enter to exit")
58         sys.stdin.readline()
59                 
60         return 0
61
62
63 if __name__ == "__main__":
64         sys.exit(main())

UCC git Repository :: git.ucc.asn.au