1 | """Example of shallow water wave equation. |
---|

2 | |
---|

3 | This version is for profiling of timestepping |
---|

4 | """ |
---|

5 | |
---|

6 | ###################### |
---|

7 | # Module imports |
---|

8 | import anuga |
---|

9 | |
---|

10 | ###################### |
---|

11 | # Domain |
---|

12 | |
---|

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 |
---|

16 | |
---|

17 | |
---|

18 | print 'Creating domain' |
---|

19 | #Create basic mesh |
---|

20 | points, vertices, boundary = anuga.rectangular(N, N) |
---|

21 | |
---|

22 | #Create shallow water domain |
---|

23 | domain = anuga.Domain(points, vertices, boundary) |
---|

24 | domain.set_default_order(2) |
---|

25 | domain.set_quantities_to_be_stored(None) |
---|

26 | |
---|

27 | |
---|

28 | print 'Setting initial conditions' |
---|

29 | |
---|

30 | def slope(x, y): |
---|

31 | return -x |
---|

32 | |
---|

33 | domain.set_quantity('elevation', slope) |
---|

34 | domain.set_quantity('friction', 0.03) |
---|

35 | domain.set_quantity('stage', expression = 'elevation + 0.5') |
---|

36 | |
---|

37 | |
---|

38 | |
---|

39 | print 'Setting boundary conditions' |
---|

40 | Br = anuga.Reflective_boundary(domain) |
---|

41 | domain.set_boundary({'left': Br, 'right': Br, 'bottom': Br, 'top': Br}) |
---|

42 | |
---|

43 | |
---|

44 | #print 'Checking integrity' |
---|

45 | #domain.check_integrity() |
---|

46 | |
---|

47 | |
---|

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 | |
---|

56 | #for t in domain.evolve(yieldstep = 0.02, finaltime = 0.2): domain.write_time() |
---|

57 | |
---|

58 | |
---|

59 | import profile, pstats |
---|

60 | FN = 'profile.dat' |
---|

61 | |
---|

62 | profile.run(s, FN) |
---|

63 | |
---|

64 | print 'That took %.2f seconds' %(time.time()-t0) |
---|

65 | |
---|

66 | S = pstats.Stats(FN) |
---|

67 | s = S.sort_stats('cumulative').print_stats(20) |
---|

68 | |
---|

69 | print s |
---|

70 | |
---|

71 | |
---|