1 | """ This is a script for profiling the code. It uses the structures code. |
---|
2 | |
---|
3 | This example includes a Model Topography that shows a TYPICAL Headwall Configuration |
---|
4 | |
---|
5 | The aim is to change the Culvert Routine to Model more precisely the abstraction |
---|
6 | from a vertical face. |
---|
7 | |
---|
8 | The inflow must include the impact of Approach velocity. |
---|
9 | Similarly the Outflow has MOMENTUM Not just Up welling as in the Horizontal Style |
---|
10 | abstraction |
---|
11 | |
---|
12 | """ |
---|
13 | print 'Starting.... Importing Modules...' |
---|
14 | #------------------------------------------------------------------------------ |
---|
15 | # Import necessary modules |
---|
16 | #------------------------------------------------------------------------------ |
---|
17 | import anuga |
---|
18 | |
---|
19 | from anuga.abstract_2d_finite_volumes.mesh_factory import rectangular_cross |
---|
20 | from anuga.shallow_water.shallow_water_domain import Domain |
---|
21 | from anuga.shallow_water.forcing import Rainfall, Inflow |
---|
22 | |
---|
23 | from anuga.culvert_flows.culvert_class import Culvert_flow |
---|
24 | from anuga.culvert_flows.culvert_routines import boyd_generalised_culvert_model |
---|
25 | from math import pi, pow, sqrt |
---|
26 | |
---|
27 | import numpy as num |
---|
28 | |
---|
29 | |
---|
30 | #------------------------------------------------------------------------------ |
---|
31 | # Setup computational domain |
---|
32 | #------------------------------------------------------------------------------ |
---|
33 | print 'Setting up domain' |
---|
34 | |
---|
35 | length = 200. #x-Dir |
---|
36 | width = 200. #y-dir |
---|
37 | |
---|
38 | dx = dy = 2.5 # Resolution: Length of subdivisions on both axes |
---|
39 | |
---|
40 | points, vertices, boundary = rectangular_cross(int(length/dx), int(width/dy), |
---|
41 | len1=length, len2=width) |
---|
42 | domain = Domain(points, vertices, boundary) |
---|
43 | domain.set_name('profile_structure') # Output name |
---|
44 | domain.set_default_order(2) |
---|
45 | domain.H0 = 0.01 |
---|
46 | domain.tight_slope_limiters = 1 |
---|
47 | |
---|
48 | print 'Size', len(domain) |
---|
49 | |
---|
50 | #------------------------------------------------------------------------------ |
---|
51 | # Setup initial conditions |
---|
52 | #------------------------------------------------------------------------------ |
---|
53 | |
---|
54 | def topography(x, y): |
---|
55 | """Set up a weir |
---|
56 | |
---|
57 | A culvert will connect either side |
---|
58 | """ |
---|
59 | # General Slope of Topography |
---|
60 | z=10.0-x/100.0 # % Longitudinal Slope |
---|
61 | |
---|
62 | # NOW Add bits and Pieces to topography |
---|
63 | bank_hgt=10.0 |
---|
64 | bridge_width = 50.0 |
---|
65 | bank_width = 10.0 |
---|
66 | |
---|
67 | us_apron_skew = 1.0 # 1.0 = 1 Length: 1 Width, 2.0 = 2 Length : 1 Width |
---|
68 | us_start_x = 10.0 |
---|
69 | top_start_y = 50.0 |
---|
70 | us_slope = 3.0 #Horiz : Vertic |
---|
71 | ds_slope = 3.0 |
---|
72 | ds_apron_skew = 1.0 # 1.0 = 1 Length: 1 Width, 2.0 = 2 Length : 1 Width |
---|
73 | centre_line_y= top_start_y+bridge_width/2.0 |
---|
74 | |
---|
75 | # CALCULATE PARAMETERS TO FORM THE EMBANKMENT |
---|
76 | us_slope_length = bank_hgt*us_slope |
---|
77 | us_end_x =us_start_x + us_slope_length |
---|
78 | us_toe_start_y =top_start_y - us_slope_length / us_apron_skew |
---|
79 | us_toe_end_y = top_start_y + bridge_width + us_slope_length / us_apron_skew |
---|
80 | |
---|
81 | top_end_y = top_start_y + bridge_width |
---|
82 | ds_slope_length = bank_hgt*ds_slope |
---|
83 | ds_start_x = us_end_x + bank_width |
---|
84 | ds_end_x = ds_start_x + ds_slope_length |
---|
85 | |
---|
86 | ds_toe_start_y =top_start_y - ds_slope_length / ds_apron_skew |
---|
87 | ds_toe_end_y = top_start_y + bridge_width + ds_slope_length / ds_apron_skew |
---|
88 | |
---|
89 | |
---|
90 | N = len(x) |
---|
91 | for i in range(N): |
---|
92 | |
---|
93 | # Sloping Embankment Across Channel |
---|
94 | if us_start_x < x[i] < us_end_x +0.1: # For UPSLOPE on the Upstream FACE |
---|
95 | if us_toe_start_y +(x[i] - us_start_x)/us_apron_skew < y[i] < us_toe_end_y - (x[i] - us_start_x)/us_apron_skew: |
---|
96 | z[i]=z[i] # Flat Apron |
---|
97 | else: |
---|
98 | z[i] += z[i] + (x[i] - us_start_x)/us_slope # Set elevation for Sloping Segment U/S Face |
---|
99 | if us_end_x < x[i] < ds_start_x + 0.1: # FOR The TOP of BANK Segment |
---|
100 | if top_start_y < y[i] < top_end_y: |
---|
101 | z[i]=z[i] # Flat Apron |
---|
102 | else: |
---|
103 | z[i] += z[i]+bank_hgt # Flat Crest of Embankment |
---|
104 | if ds_start_x < x[i] < ds_end_x: # DOWN SDLOPE Segment on Downstream face |
---|
105 | if top_start_y-(x[i]-ds_start_x)/ds_apron_skew < y[i] < top_end_y + (x[i]-ds_start_x)/ds_apron_skew: # Cut Out Segment for Culvert FACE |
---|
106 | z[i]=z[i] # Flat Apron |
---|
107 | else: |
---|
108 | z[i] += z[i]+bank_hgt-(x[i] -ds_start_x)/ds_slope # Sloping D/S Face |
---|
109 | |
---|
110 | |
---|
111 | |
---|
112 | return z |
---|
113 | |
---|
114 | print 'Setting Quantities....' |
---|
115 | domain.set_quantity('elevation', topography) # Use function for elevation |
---|
116 | domain.set_quantity('friction', 0.01) # Constant friction |
---|
117 | domain.set_quantity('stage', |
---|
118 | expression='elevation') # Dry initial condition |
---|
119 | |
---|
120 | #------------------------------------------------------------------------------ |
---|
121 | # Setup boundary conditions |
---|
122 | #------------------------------------------------------------------------------ |
---|
123 | print 'Setting Boundary Conditions' |
---|
124 | Br = anuga.Reflective_boundary(domain) # Solid reflective wall |
---|
125 | Bi = anuga.Dirichlet_boundary([0.0, 0.0, 0.0]) # Inflow based on Flow Depth and Approaching Momentum !!! |
---|
126 | |
---|
127 | Bo = anuga.Dirichlet_boundary([-5.0, 0, 0]) # Outflow water at -5.0 |
---|
128 | Bd = anuga.Dirichlet_boundary([0,0,0]) # Outflow water at 0.0 |
---|
129 | |
---|
130 | Btus = anuga.Dirichlet_boundary([18.0, 0, 0]) # Outflow water at 5.0 |
---|
131 | Btds = anuga.Dirichlet_boundary([0.0, 0, 0]) # Outflow water at 1.0 |
---|
132 | domain.set_boundary({'left': Btus, 'right': Btds, 'top': Br, 'bottom': Br}) |
---|
133 | |
---|
134 | #------------------------------------------------------------------------------ |
---|
135 | # Evolve system through time |
---|
136 | #------------------------------------------------------------------------------ |
---|
137 | |
---|
138 | def ev(): |
---|
139 | |
---|
140 | for t in domain.evolve(yieldstep = 1, finaltime = 20): |
---|
141 | print domain.timestepping_statistics() |
---|
142 | |
---|
143 | import cProfile |
---|
144 | import time |
---|
145 | import os |
---|
146 | import platform |
---|
147 | |
---|
148 | if not os.path.isdir('profile_structure'): |
---|
149 | os.mkdir('profile_structure') |
---|
150 | |
---|
151 | t = time.ctime().replace(' ', '_') |
---|
152 | t = t.replace(':', '-') |
---|
153 | uname_ = platform.uname() |
---|
154 | |
---|
155 | os.mkdir(os.path.join('profile_structure', t)) |
---|
156 | |
---|
157 | f = open(os.path.join('profile_structure', t, 'uname'), 'w') |
---|
158 | f.write(str(uname_)) |
---|
159 | f.close() |
---|
160 | |
---|
161 | cProfile.run('ev()', os.path.join('profile_structure', t, 'profile_structure.prf')) |
---|
162 | |
---|
163 | #import pstats |
---|
164 | #p = pstats.Stats('profile_structure.prf') |
---|
165 | #p.strip_dirs().sort_stats(-1).print_stats() |
---|
166 | #p.sort_stats('cumulative').print_stats(10) |
---|
167 | |
---|
168 | |
---|