1 | """Example of shallow water wave equation. |
---|
2 | |
---|
3 | This version is for profiling |
---|
4 | (The original) |
---|
5 | |
---|
6 | |
---|
7 | FIXME: This should really measure something else, such as profiling the set up of domains. |
---|
8 | """ |
---|
9 | |
---|
10 | ###################### |
---|
11 | # Module imports |
---|
12 | # |
---|
13 | from shallow_water import Domain, Reflective_boundary, Dirichlet_boundary,\ |
---|
14 | Transmissive_boundary, Time_boundary,\ |
---|
15 | Weir_simple as Weir, Constant_height |
---|
16 | |
---|
17 | from mesh_factory import rectangular |
---|
18 | from Numeric import array |
---|
19 | |
---|
20 | |
---|
21 | ###################### |
---|
22 | # Domain |
---|
23 | # |
---|
24 | |
---|
25 | N = 128 |
---|
26 | |
---|
27 | print 'Creating domain' |
---|
28 | #Create basic mesh |
---|
29 | points, vertices, boundary = rectangular(N, N) |
---|
30 | |
---|
31 | #Create shallow water domain |
---|
32 | domain = Domain(points, vertices, boundary) |
---|
33 | domain.default_order = 2 |
---|
34 | domain.set_quantities_to_be_stored(None) |
---|
35 | #domain.visualise = True |
---|
36 | |
---|
37 | |
---|
38 | print 'Field values' |
---|
39 | def slope(x, y): |
---|
40 | return -x |
---|
41 | |
---|
42 | domain.set_quantity('elevation', slope) |
---|
43 | domain.set_quantity('friction', 0.3) |
---|
44 | |
---|
45 | |
---|
46 | # Boundary conditions |
---|
47 | # |
---|
48 | Br = Reflective_boundary(domain) |
---|
49 | domain.set_boundary({'left': Br, 'right': Br, 'bottom': Br, 'top': Br}) |
---|
50 | |
---|
51 | |
---|
52 | ###################### |
---|
53 | #Initial condition |
---|
54 | domain.set_quantity('stage', Constant_height(slope, 0.3)) |
---|
55 | |
---|
56 | domain.check_integrity() |
---|
57 | |
---|
58 | |
---|
59 | ###################### |
---|
60 | #Evolution |
---|
61 | |
---|
62 | import time |
---|
63 | t0 = time.time() |
---|
64 | |
---|
65 | s = 'for t in domain.evolve(yieldstep = 0.02, finaltime = 0.2): domain.write_time()' |
---|
66 | |
---|
67 | |
---|
68 | |
---|
69 | import profile, pstats |
---|
70 | FN = 'profile.dat' |
---|
71 | |
---|
72 | profile.run(s, FN) |
---|
73 | |
---|
74 | print 'That took %.2f seconds' %(time.time()-t0) |
---|
75 | |
---|
76 | S = pstats.Stats(FN) |
---|
77 | #S.sort_stats('time').print_stats(20) |
---|
78 | s = S.sort_stats('cumulative').print_stats(30) |
---|
79 | |
---|
80 | print s |
---|