source: branches/numpy_anuga_validation/performance_tests/run_profile.py @ 7952

Last change on this file since 7952 was 7213, checked in by rwilson, 16 years ago

Removed Numeric import - wasn't used.

File size: 1.5 KB
RevLine 
[239]1"""Example of shallow water wave equation.
2
[2380]3This version is for profiling of timestepping
[239]4"""
5
6######################
[1629]7# Module imports
[3567]8from anuga.shallow_water import Domain, Reflective_boundary
[239]9from 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
18N = 128  #Should take less than 20s
[239]19
[2380]20
[239]21print 'Creating domain'
22#Create basic mesh
23points, vertices, boundary = rectangular(N, N)
24
25#Create shallow water domain
26domain = Domain(points, vertices, boundary)
[2380]27domain.set_default_order(2)       
28domain.set_quantities_to_be_stored(None)
[239]29
[244]30
[2380]31print 'Setting initial conditions'
32
[239]33def slope(x, y):
34    return -x
[1629]35
[239]36domain.set_quantity('elevation', slope)
[2380]37domain.set_quantity('friction', 0.03)
38domain.set_quantity('stage', expression = 'elevation + 0.5')
[239]39
40
[2380]41
42print 'Setting boundary conditions'
[239]43Br = Reflective_boundary(domain)
44domain.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
54import time
55t0 = time.time()
56
57s = '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]62import profile, pstats
63FN = 'profile.dat'
64
65profile.run(s, FN)
[1629]66
[239]67print 'That took %.2f seconds' %(time.time()-t0)
68
69S = pstats.Stats(FN)
[5320]70s = S.sort_stats('cumulative').print_stats(20)
[239]71
72print s
[5320]73
74
Note: See TracBrowser for help on using the repository browser.