Added python module for native solution and parameter setting
[pde-python.git] / main.py
blob896daecc44c85a46b219d6ae0e873ca27decb7b9
1 #!/usr/bin/python
2 # -*- coding: utf-8
4 import psyco
5 psyco.full()
8 from optparse import OptionParser
10 import numpy as np
11 import pylab as plt
13 from grid import ImplicitSolver, ExplicitSolver
14 from waves import Exm
15 import const
17 def prof_main():
18 parser = OptionParser()
19 parser.add_option("-t", "--time", dest="time", help="Time", metavar="TIME", default="1e-14")
20 parser.add_option("-y", dest="ny", help="Y capacity", metavar="I", default="20")
21 parser.add_option("-z", dest="nz", help="Z capacity", metavar="J", default="20")
22 parser.add_option("-s", "--ht", dest="ht", help="time step", metavar="STEP", default="")
23 (options, args) = parser.parse_args()
25 time = np.float64(options.time)
26 ny = np.int(options.ny)
27 nz = np.int(options.nz)
28 ht = None
29 if (len(options.ht) != 0):
30 ht = np.float64(options.ht)
32 solver_s = Solver(ny, nz, time, ht, solver='python', debug=True)
33 solver_w = Solver(ny, nz, time, ht, solver='blitz', debug=True)
34 solver_i = Solver(ny, nz, time, ht, solver='inline', debug=True)
36 import time
37 t1 = time.time()
38 solver_s.solve()
39 t2 = time.time()
40 solver_w.solve()
41 t3 = time.time()
42 solver_i.solve()
43 t4 = time.time()
44 print 'standard:', t2 - t1
45 print 'blitz:', t3 - t2
46 print 'inline:', t4 - t3
49 def main():
50 parser = OptionParser()
51 parser.add_option("-t", "--time", dest="time", help="Time", metavar="TIME", default="1e-14")
52 parser.add_option("-y", dest="ny", help="Y capacity", metavar="I", default="20")
53 parser.add_option("-z", dest="nz", help="Z capacity", metavar="J", default="20")
54 parser.add_option("-s", "--ht", dest="ht", help="time step", metavar="STEP", default="")
55 (options, args) = parser.parse_args()
57 time = np.float64(options.time)
58 ny = np.int(options.ny)
59 nz = np.int(options.nz)
60 ht = None
61 if (len(options.ht) != 0):
62 ht = np.float64(options.ht)
64 # solver = Solver(ny, nz, time, ht, solver='inline', debug=True)
65 # u = solver.solve()
67 solver = ImplicitSolver(ny, nz, time, ht, debug=True)
68 u = solver.solve()
70 #solvere = Solver(ny, nz, time, ht, scheme='explicit')
71 #ue = solvere.solve()
73 d = np.arange(0, solver.J + 1)
74 z = [solver.hz * j for j in d]
75 Ea = [Exm(const.LY/2, z_, time, 1000) for z_ in z]
76 En = u[u.shape[0] / 2, :]
78 a_line, = plt.plot(z, Ea, lw=1, color="red")
79 n_line, = plt.plot(z, En, lw=1, color="green")
80 plt.legend((a_line, n_line), (u"Analitycal", u"Implicit scheme"))
81 plt.grid(True)
82 plt.xlim((min(z), max(z)))
83 plt.show()
85 if __name__ == '__main__':
86 main()