[239] | 1 | """Example of shallow water wave equation. |
---|
| 2 | |
---|
[2380] | 3 | This version is for profiling of timestepping |
---|
[239] | 4 | """ |
---|
| 5 | |
---|
| 6 | ###################### |
---|
[1629] | 7 | # Module imports |
---|
[3567] | 8 | from anuga.shallow_water import Domain, Reflective_boundary |
---|
[239] | 9 | from mesh_factory import rectangular |
---|
| 10 | |
---|
[1629] | 11 | |
---|
[239] | 12 | ###################### |
---|
| 13 | # Domain |
---|
| 14 | |
---|
[2380] | 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 |
---|
[239] | 18 | |
---|
[2380] | 19 | |
---|
[239] | 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) |
---|
[2380] | 26 | domain.set_default_order(2) |
---|
| 27 | domain.set_quantities_to_be_stored(None) |
---|
[239] | 28 | |
---|
[244] | 29 | |
---|
[2380] | 30 | print 'Setting initial conditions' |
---|
| 31 | |
---|
[239] | 32 | def slope(x, y): |
---|
| 33 | return -x |
---|
[1629] | 34 | |
---|
[239] | 35 | domain.set_quantity('elevation', slope) |
---|
[2380] | 36 | domain.set_quantity('friction', 0.03) |
---|
| 37 | domain.set_quantity('stage', expression = 'elevation + 0.5') |
---|
[239] | 38 | |
---|
| 39 | |
---|
[2380] | 40 | |
---|
| 41 | print 'Setting boundary conditions' |
---|
[239] | 42 | Br = Reflective_boundary(domain) |
---|
| 43 | domain.set_boundary({'left': Br, 'right': Br, 'bottom': Br, 'top': Br}) |
---|
| 44 | |
---|
| 45 | |
---|
[5297] | 46 | #print 'Checking integrity' |
---|
| 47 | #domain.check_integrity() |
---|
[239] | 48 | |
---|
[1629] | 49 | |
---|
[239] | 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 | |
---|
[5847] | 58 | #for t in domain.evolve(yieldstep = 0.02, finaltime = 0.2): domain.write_time() |
---|
[239] | 59 | |
---|
[5847] | 60 | |
---|
[239] | 61 | import profile, pstats |
---|
| 62 | FN = 'profile.dat' |
---|
| 63 | |
---|
| 64 | profile.run(s, FN) |
---|
[1629] | 65 | |
---|
[239] | 66 | print 'That took %.2f seconds' %(time.time()-t0) |
---|
| 67 | |
---|
| 68 | S = pstats.Stats(FN) |
---|
[5320] | 69 | s = S.sort_stats('cumulative').print_stats(20) |
---|
[239] | 70 | |
---|
| 71 | print s |
---|
[5320] | 72 | |
---|
| 73 | |
---|