source: trunk/anuga_work/development/kv/profiling.py @ 8153

Last change on this file since 8153 was 8113, checked in by steve, 14 years ago

comment in profile

File size: 1.8 KB
Line 
1from anuga.abstract_2d_finite_volumes.generic_domain import Generic_Domain
2import anuga.abstract_2d_finite_volumes.mesh_factory as mesh_factory
3import anuga.abstract_2d_finite_volumes.neighbour_mesh as neighbour_mesh
4from anuga.abstract_2d_finite_volumes.generic_boundary_conditions import Dirichlet_boundary
5from kinematic_viscosity import Kinematic_Viscosity_Operator
6import numpy as num
7import anuga.utilities.log as log
8
9
10# FIXME SR: Seems a little strange that the timing for the elliptic and parabolic solves
11# are the same. should investigate
12
13print "Setting up"
14grid_rows = 40
15grid_cols = 40
16#Set up a rectangular grid
17points,elements,boundary = mesh_factory.rectangular_cross(grid_rows,grid_cols)
18mesh = neighbour_mesh.Mesh(points,elements)
19n = len(mesh)
20print "n =",n
21boundary_map = {}
22for (vol_id,edge) in boundary.keys():
23    x = mesh.get_edge_midpoint_coordinate(vol_id,edge)[0]
24    y = mesh.get_edge_midpoint_coordinate(vol_id,edge)[1]
25    #Define boundary conditions: u=x^2-y^2, v=x-y+2
26    boundary_map[(vol_id,edge)] = Dirichlet_boundary([1,x*x-y*y,x-y+2])
27#Now define an operator
28domain = Generic_Domain(source=points,triangles=elements,boundary=boundary_map)
29KV_Operator = Kinematic_Viscosity_Operator(domain)
30print "Applying stage heights"
31#Set up the operator and RHS
32h = num.ones((n,),num.float)
33   
34def solve():   
35    KV_Operator.apply_stage_heights(h)
36    rhs = num.zeros((n,2),num.float) #we will solve for u and v
37    print "Solving"
38    #Solve
39    velocities = KV_Operator.cg_solve(rhs)
40    new_velocities = KV_Operator.parabolic_solver(velocities)
41
42#Do the profiling
43import profile, pstats
44FN = 'kv_profile.dat'
45print "Starting solve..."
46profile.run('solve()', FN)
47S = pstats.Stats(FN)
48s = S.sort_stats('cumulative').print_stats(30)
Note: See TracBrowser for help on using the repository browser.