1 | """Example of shallow water wave equation. |
---|
2 | |
---|
3 | This version is for profiling of timestepping |
---|
4 | """ |
---|
5 | |
---|
6 | ###################### |
---|
7 | # Module imports |
---|
8 | from anuga.shallow_water import Domain, Reflective_boundary |
---|
9 | from mesh_factory import rectangular |
---|
10 | from Numeric import array |
---|
11 | |
---|
12 | |
---|
13 | ###################### |
---|
14 | # Domain |
---|
15 | |
---|
16 | #N = 16 #Should take less than 0.1 s |
---|
17 | #N = 64 #Should take less than 3s |
---|
18 | N = 128 #Should take less than 20s |
---|
19 | |
---|
20 | |
---|
21 | print 'Creating domain' |
---|
22 | #Create basic mesh |
---|
23 | points, vertices, boundary = rectangular(N, N) |
---|
24 | |
---|
25 | #Create shallow water domain |
---|
26 | domain = Domain(points, vertices, boundary) |
---|
27 | domain.set_default_order(2) |
---|
28 | domain.set_quantities_to_be_stored(None) |
---|
29 | |
---|
30 | |
---|
31 | print 'Setting initial conditions' |
---|
32 | |
---|
33 | def slope(x, y): |
---|
34 | return -x |
---|
35 | |
---|
36 | domain.set_quantity('elevation', slope) |
---|
37 | domain.set_quantity('friction', 0.03) |
---|
38 | domain.set_quantity('stage', expression = 'elevation + 0.5') |
---|
39 | |
---|
40 | |
---|
41 | |
---|
42 | print 'Setting boundary conditions' |
---|
43 | Br = Reflective_boundary(domain) |
---|
44 | domain.set_boundary({'left': Br, 'right': Br, 'bottom': Br, 'top': Br}) |
---|
45 | |
---|
46 | |
---|
47 | print 'Checking integrity' |
---|
48 | domain.check_integrity() |
---|
49 | |
---|
50 | |
---|
51 | ###################### |
---|
52 | #Evolution |
---|
53 | |
---|
54 | import time |
---|
55 | t0 = time.time() |
---|
56 | |
---|
57 | s = 'for t in domain.evolve(yieldstep = 0.02, finaltime = 0.2): domain.write_time()' |
---|
58 | |
---|
59 | |
---|
60 | import profile, pstats |
---|
61 | FN = 'profile.dat' |
---|
62 | |
---|
63 | profile.run(s, FN) |
---|
64 | |
---|
65 | print 'That took %.2f seconds' %(time.time()-t0) |
---|
66 | |
---|
67 | S = pstats.Stats(FN) |
---|
68 | #S.sort_stats('time').print_stats(20) |
---|
69 | s = S.sort_stats('cumulative').print_stats(30) |
---|
70 | |
---|
71 | print s |
---|