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