source: trunk/anuga_profile/profile_structure.py @ 8453

Last change on this file since 8453 was 8427, checked in by davies, 12 years ago

Adding the trapezoidal channel validation test, and editing the ANUGA manual

File size: 6.2 KB
Line 
1""" This is a script for profiling the code. It uses the structures code.
2
3This example includes a Model Topography that shows a TYPICAL Headwall Configuration
4
5The aim is to change the Culvert Routine to Model more precisely the abstraction
6from a vertical face.
7
8The inflow must include the impact of Approach velocity.
9Similarly the Outflow has MOMENTUM Not just Up welling as in the Horizontal Style
10abstraction
11
12"""
13print 'Starting.... Importing Modules...'
14#------------------------------------------------------------------------------
15# Import necessary modules
16#------------------------------------------------------------------------------
17import anuga
18
19from anuga.abstract_2d_finite_volumes.mesh_factory import rectangular_cross
20from anuga.shallow_water.shallow_water_domain import Domain
21from anuga.shallow_water.forcing import Rainfall, Inflow
22
23from anuga.culvert_flows.culvert_class import Culvert_flow
24from anuga.culvert_flows.culvert_routines import boyd_generalised_culvert_model
25from math import pi, pow, sqrt
26
27import numpy as num
28
29
30#------------------------------------------------------------------------------
31# Setup computational domain
32#------------------------------------------------------------------------------
33print 'Setting up domain'
34
35length = 200. #x-Dir
36width = 200.  #y-dir
37
38dx = dy = 2.5          # Resolution: Length of subdivisions on both axes
39
40points, vertices, boundary = rectangular_cross(int(length/dx), int(width/dy),
41                                               len1=length, len2=width)
42domain = Domain(points, vertices, boundary)   
43domain.set_name('profile_structure') # Output name
44domain.set_default_order(2)
45domain.H0 = 0.01
46domain.tight_slope_limiters = 1
47
48print 'Size', len(domain)
49
50#------------------------------------------------------------------------------
51# Setup initial conditions
52#------------------------------------------------------------------------------
53
54def 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
114print 'Setting Quantities....'
115domain.set_quantity('elevation', topography)  # Use function for elevation
116domain.set_quantity('friction', 0.01)         # Constant friction
117domain.set_quantity('stage',
118                    expression='elevation')   # Dry initial condition
119
120#------------------------------------------------------------------------------
121# Setup boundary conditions
122#------------------------------------------------------------------------------
123print 'Setting Boundary Conditions'
124Br = anuga.Reflective_boundary(domain)              # Solid reflective wall
125Bi = anuga.Dirichlet_boundary([0.0, 0.0, 0.0])          # Inflow based on Flow Depth and Approaching Momentum !!!
126
127Bo = anuga.Dirichlet_boundary([-5.0, 0, 0])           # Outflow water at -5.0
128Bd = anuga.Dirichlet_boundary([0,0,0])                # Outflow water at 0.0
129
130Btus = anuga.Dirichlet_boundary([18.0, 0, 0])           # Outflow water at 5.0
131Btds = anuga.Dirichlet_boundary([0.0, 0, 0])           # Outflow water at 1.0
132domain.set_boundary({'left': Btus, 'right': Btds, 'top': Br, 'bottom': Br})
133
134#------------------------------------------------------------------------------
135# Evolve system through time
136#------------------------------------------------------------------------------
137
138def ev():
139
140    for t in domain.evolve(yieldstep = 1, finaltime = 20):
141        print domain.timestepping_statistics()
142
143import cProfile
144import time
145import os
146import platform
147
148if not os.path.isdir('profile_structure'):
149    os.mkdir('profile_structure')
150
151t = time.ctime().replace(' ', '_')
152t = t.replace(':', '-')
153uname_ = platform.uname()
154
155os.mkdir(os.path.join('profile_structure', t))
156
157f = open(os.path.join('profile_structure', t, 'uname'), 'w')
158f.write(str(uname_))
159f.close()
160
161cProfile.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
Note: See TracBrowser for help on using the repository browser.