source: trunk/anuga_validation/performance_tests/run_cross_section_flow_profile.py @ 8288

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

work on performance profiling

File size: 1.6 KB
Line 
1"""Example of shallow water wave equation.
2
3This version is for profiling of get_flow_through_cross_section
4"""
5
6######################
7# Module imports
8from anuga.shallow_water import Domain, Reflective_boundary
9from anuga.shallow_water.data_manager import get_flow_through_cross_section
10from mesh_factory import rectangular
11from Numeric import array
12
13
14######################
15# Domain
16
17N = 16   #Should take less than 0.1 s
18#N = 64  #Should take less than 3s
19#N = 128  #Should take less than 20s
20
21
22print 'Creating domain'
23#Create basic mesh
24points, vertices, boundary = rectangular(N, N)
25
26#Create shallow water domain
27domain = Domain(points, vertices, boundary)
28domain.set_default_order(2)       
29domain.set_name('test_file')
30
31print 'Setting initial conditions'
32
33def slope(x, y):
34    return -x
35
36domain.set_quantity('elevation', slope)
37domain.set_quantity('friction', 0.03)
38domain.set_quantity('stage', expression = 'elevation + 0.5')
39
40
41
42print 'Setting boundary conditions'
43Br = Reflective_boundary(domain)
44domain.set_boundary({'left': Br, 'right': Br, 'bottom': Br, 'top': Br})
45
46
47
48######################
49#Evolution
50
51import time
52for t in domain.evolve(yieldstep = 0.02, finaltime = 0.2):
53    domain.write_time()
54
55print 'Doing cross section'
56t0 = time.time()
57
58#--------------
59# Cross section
60swwfile = domain.get_name() + '.sww'
61
62s = 't, Q = get_flow_through_cross_section(swwfile, [[0.5, 0.1],[0.7, 0.9]], verbose=True)'
63import profile, pstats
64FN = 'profile.dat'
65profile.run(s, FN)
66
67print 'That took %.2f seconds' %(time.time()-t0)
68
69S = pstats.Stats(FN)
70print S.sort_arg_dict_default
71
72s = S.sort_stats('cumulative').print_stats(30)
73#s = S.sort_stats('time').print_stats(30)
74print s
75
76
77
Note: See TracBrowser for help on using the repository browser.