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