1 | from anuga.abstract_2d_finite_volumes.generic_domain import Generic_Domain |
---|
2 | import anuga.abstract_2d_finite_volumes.mesh_factory as mesh_factory |
---|
3 | import anuga.abstract_2d_finite_volumes.neighbour_mesh as neighbour_mesh |
---|
4 | from anuga.abstract_2d_finite_volumes.generic_boundary_conditions import Dirichlet_boundary |
---|
5 | from kinematic_viscosity import Kinematic_Viscosity_Operator |
---|
6 | import numpy as num |
---|
7 | import 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 | |
---|
13 | print "Setting up" |
---|
14 | grid_rows = 40 |
---|
15 | grid_cols = 40 |
---|
16 | #Set up a rectangular grid |
---|
17 | points,elements,boundary = mesh_factory.rectangular_cross(grid_rows,grid_cols) |
---|
18 | mesh = neighbour_mesh.Mesh(points,elements) |
---|
19 | n = len(mesh) |
---|
20 | print "n =",n |
---|
21 | boundary_map = {} |
---|
22 | for (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 |
---|
28 | domain = Generic_Domain(source=points,triangles=elements,boundary=boundary_map) |
---|
29 | KV_Operator = Kinematic_Viscosity_Operator(domain) |
---|
30 | print "Applying stage heights" |
---|
31 | #Set up the operator and RHS |
---|
32 | h = num.ones((n,),num.float) |
---|
33 | |
---|
34 | def 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 |
---|
43 | import profile, pstats |
---|
44 | FN = 'kv_profile.dat' |
---|
45 | print "Starting solve..." |
---|
46 | profile.run('solve()', FN) |
---|
47 | S = pstats.Stats(FN) |
---|
48 | s = S.sort_stats('cumulative').print_stats(30) |
---|