[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 |
---|
[7213] | 10 | #import numpy as num # not used? |
---|
[239] | 11 | |
---|
[1629] | 12 | |
---|
[239] | 13 | ###################### |
---|
| 14 | # Domain |
---|
| 15 | |
---|
[2380] | 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 |
---|
[239] | 19 | |
---|
[2380] | 20 | |
---|
[239] | 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) |
---|
[2380] | 27 | domain.set_default_order(2) |
---|
| 28 | domain.set_quantities_to_be_stored(None) |
---|
[239] | 29 | |
---|
[244] | 30 | |
---|
[2380] | 31 | print 'Setting initial conditions' |
---|
| 32 | |
---|
[239] | 33 | def slope(x, y): |
---|
| 34 | return -x |
---|
[1629] | 35 | |
---|
[239] | 36 | domain.set_quantity('elevation', slope) |
---|
[2380] | 37 | domain.set_quantity('friction', 0.03) |
---|
| 38 | domain.set_quantity('stage', expression = 'elevation + 0.5') |
---|
[239] | 39 | |
---|
| 40 | |
---|
[2380] | 41 | |
---|
| 42 | print 'Setting boundary conditions' |
---|
[239] | 43 | Br = Reflective_boundary(domain) |
---|
| 44 | domain.set_boundary({'left': Br, 'right': Br, 'bottom': Br, 'top': Br}) |
---|
| 45 | |
---|
| 46 | |
---|
[5297] | 47 | #print 'Checking integrity' |
---|
| 48 | #domain.check_integrity() |
---|
[239] | 49 | |
---|
[1629] | 50 | |
---|
[239] | 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 | |
---|
[5847] | 59 | #for t in domain.evolve(yieldstep = 0.02, finaltime = 0.2): domain.write_time() |
---|
[239] | 60 | |
---|
[5847] | 61 | |
---|
[239] | 62 | import profile, pstats |
---|
| 63 | FN = 'profile.dat' |
---|
| 64 | |
---|
| 65 | profile.run(s, FN) |
---|
[1629] | 66 | |
---|
[239] | 67 | print 'That took %.2f seconds' %(time.time()-t0) |
---|
| 68 | |
---|
| 69 | S = pstats.Stats(FN) |
---|
[5320] | 70 | s = S.sort_stats('cumulative').print_stats(20) |
---|
[239] | 71 | |
---|
| 72 | print s |
---|
[5320] | 73 | |
---|
| 74 | |
---|