source: anuga_validation/performance_tests/run_profile2.py @ 5320

Last change on this file since 5320 was 5320, checked in by ole, 16 years ago

work on performance profiling

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