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

Last change on this file since 8073 was 8073, checked in by steve, 13 years ago

Added in a unit test for inlet operator

File size: 1.6 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
10print "Setting up"
11grid_rows = 40
12grid_cols = 40
13#Set up a rectangular grid
14points,elements,boundary = mesh_factory.rectangular_cross(grid_rows,grid_cols)
15mesh = neighbour_mesh.Mesh(points,elements)
16n = len(mesh)
17print "n =",n
18boundary_map = {}
19for (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
25domain = Generic_Domain(source=points,triangles=elements,boundary=boundary_map)
26KV_Operator = Kinematic_Viscosity_Operator(domain)
27print "Applying stage heights"
28#Set up the operator and RHS
29h = num.ones((n,),num.float)
30   
31def solve():   
32    KV_Operator.apply_stage_heights(h)
33    rhs = num.zeros((n,2),num.float) #we will solve for u and v
34    print "Solving"
35    #Solve
36    velocities = KV_Operator.cg_solve(rhs)
37    new_velocities = KV_Operator.parabolic_solver(velocities)
38
39#Do the profiling
40import profile, pstats
41FN = 'kv_profile.dat'
42print "Starting solve..."
43profile.run('solve()', FN)
44S = pstats.Stats(FN)
45s = S.sort_stats('cumulative').print_stats(30)
Note: See TracBrowser for help on using the repository browser.