source: trunk/anuga_work/development/2010-projects/kv/profiling.py @ 8051

Last change on this file since 8051 was 8051, checked in by steve, 9 years ago

Added in Lindon's code

File size: 1.7 KB
Line 
1from anuga.abstract_2d_finite_volumes.domain import 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
9def evolve():
10    print "Setting up"
11    grid_rows = 40
12    grid_cols = 40
13    #Set up a rectangular grid
14    points,elements,boundary = mesh_factory.rectangular_cross(grid_rows,grid_cols)
15    mesh = neighbour_mesh.Mesh(points,elements)
16    n = len(mesh)
17    print "n =",n
18    boundary_map = {}
19    for (vol_id,edge) in boundary.keys():
20        x = mesh.get_edge_midpoint_coordinate(vol_id,edge)[0]
21        y = mesh.get_edge_midpoint_coordinate(vol_id,edge)[1]
22        #Define boundary conditions: u=x^2-y^2, v=x-y+2
23        boundary_map[(vol_id,edge)] = Dirichlet_boundary([1,x*x-y*y,x-y+2])
24    #Now define an operator
25    domain = Domain(source=points,triangles=elements,boundary=boundary_map)
26    KV_Operator = Kinematic_Viscosity_Operator(domain)
27    print "Applying stage heights"
28    #Set up the operator and RHS
29    h = num.ones((n,),num.float)
30    KV_Operator.apply_stage_heights(h)
31    rhs = num.zeros((n,2),num.float) #we will solve for u and v
32    print "Solving"
33    #Solve
34    velocities = KV_Operator.cg_solve(rhs)
35    new_velocities = KV_Operator.parabolic_solver(velocities)
36
37#Do the profiling
38import profile, pstats
39FN = 'kv_profile.dat'
40print "Starting..."
41profile.run('evolve()', FN)
42S = pstats.Stats(FN)
43s = S.sort_stats('cumulative').print_stats(30)
Note: See TracBrowser for help on using the repository browser.