Last change
on this file since 8912 was
7877,
checked in by James Hudson, 15 years ago
|
Moved all development files into trunk.
|
File size:
1.3 KB
|
Rev | Line | |
---|
[1590] | 1 | """Example of shallow water wave equation. |
---|
| 2 | |
---|
| 3 | This version is for profiling |
---|
| 4 | (The original) |
---|
[2380] | 5 | |
---|
| 6 | |
---|
| 7 | FIXME: This should really measure something else, such as profiling the set up of domains. |
---|
[1590] | 8 | """ |
---|
| 9 | |
---|
| 10 | ###################### |
---|
| 11 | # Module imports |
---|
| 12 | # |
---|
[7846] | 13 | import anuga |
---|
| 14 | from numpy import array |
---|
[1590] | 15 | |
---|
| 16 | |
---|
| 17 | ###################### |
---|
| 18 | # Domain |
---|
| 19 | # |
---|
| 20 | |
---|
[1592] | 21 | N = 128 |
---|
[1590] | 22 | |
---|
| 23 | print 'Creating domain' |
---|
| 24 | #Create basic mesh |
---|
[7846] | 25 | points, vertices, boundary = anuga.rectangular(N, N) |
---|
[1590] | 26 | |
---|
| 27 | #Create shallow water domain |
---|
[7846] | 28 | domain = anuga.Domain(points, vertices, boundary) |
---|
[1590] | 29 | domain.default_order = 2 |
---|
[2380] | 30 | domain.set_quantities_to_be_stored(None) |
---|
[1592] | 31 | #domain.visualise = True |
---|
[1590] | 32 | |
---|
| 33 | |
---|
| 34 | print 'Field values' |
---|
| 35 | def slope(x, y): |
---|
| 36 | return -x |
---|
| 37 | |
---|
| 38 | domain.set_quantity('elevation', slope) |
---|
| 39 | domain.set_quantity('friction', 0.3) |
---|
| 40 | |
---|
| 41 | |
---|
| 42 | # Boundary conditions |
---|
| 43 | # |
---|
[7846] | 44 | Br = anuga.Reflective_boundary(domain) |
---|
[1590] | 45 | domain.set_boundary({'left': Br, 'right': Br, 'bottom': Br, 'top': Br}) |
---|
| 46 | |
---|
| 47 | |
---|
| 48 | ###################### |
---|
| 49 | #Initial condition |
---|
[5320] | 50 | domain.set_quantity('stage', expression='elevation + 0.3') |
---|
[1590] | 51 | |
---|
| 52 | domain.check_integrity() |
---|
| 53 | |
---|
| 54 | |
---|
| 55 | ###################### |
---|
| 56 | #Evolution |
---|
| 57 | |
---|
| 58 | import time |
---|
| 59 | t0 = time.time() |
---|
| 60 | |
---|
| 61 | s = 'for t in domain.evolve(yieldstep = 0.02, finaltime = 0.2): domain.write_time()' |
---|
| 62 | |
---|
| 63 | |
---|
| 64 | |
---|
| 65 | import profile, pstats |
---|
| 66 | FN = 'profile.dat' |
---|
| 67 | |
---|
| 68 | profile.run(s, FN) |
---|
| 69 | |
---|
| 70 | print 'That took %.2f seconds' %(time.time()-t0) |
---|
| 71 | |
---|
| 72 | S = pstats.Stats(FN) |
---|
| 73 | #S.sort_stats('time').print_stats(20) |
---|
| 74 | s = S.sort_stats('cumulative').print_stats(30) |
---|
| 75 | |
---|
| 76 | print s |
---|
Note: See
TracBrowser
for help on using the repository browser.