Index: /trunk/anuga_core/source/anuga/structures/data/inlet_operator_test1.lic
===================================================================
--- /trunk/anuga_core/source/anuga/structures/data/inlet_operator_test1.lic	(revision 9440)
+++ /trunk/anuga_core/source/anuga/structures/data/inlet_operator_test1.lic	(revision 9440)
@@ -0,0 +1,17 @@
+<?xml version='1.0' encoding='iso-8859-1'?>
+<ga_license_file>
+  <metadata>
+    <author>Stephen Roberts</author>
+  </metadata>
+  <datafile>
+    <filename>inlet_operator_test1.tms</filename>
+    <checksum>2626649089</checksum>
+    <publishable>Yes</publishable>
+    <accountable>Stephen Roberts</accountable>
+    <source>Australian National University</source>
+    <IP_owner>Australian National University</IP_owner>
+    <IP_info>A very simple time series I made up to test inlet_operator
+    </IP_info>
+  </datafile>
+
+</ga_license_file>
Index: /trunk/anuga_core/source/anuga/structures/data/inlet_operator_test2.lic
===================================================================
--- /trunk/anuga_core/source/anuga/structures/data/inlet_operator_test2.lic	(revision 9440)
+++ /trunk/anuga_core/source/anuga/structures/data/inlet_operator_test2.lic	(revision 9440)
@@ -0,0 +1,17 @@
+<?xml version='1.0' encoding='iso-8859-1'?>
+<ga_license_file>
+  <metadata>
+    <author>Stephen Roberts</author>
+  </metadata>
+  <datafile>
+    <filename>inlet_operator_test2.tms</filename>
+    <checksum>4136545855</checksum>
+    <publishable>Yes</publishable>
+    <accountable>Stephen Roberts</accountable>
+    <source>Australian National University</source>
+    <IP_owner>Australian National University</IP_owner>
+    <IP_info>A very simple time series I made up to test inlet_operator
+    </IP_info>
+  </datafile>
+
+</ga_license_file>
Index: /trunk/anuga_core/source/anuga/structures/examples/run_culvert.py
===================================================================
--- /trunk/anuga_core/source/anuga/structures/examples/run_culvert.py	(revision 9440)
+++ /trunk/anuga_core/source/anuga/structures/examples/run_culvert.py	(revision 9440)
@@ -0,0 +1,162 @@
+import os.path
+import sys
+
+from anuga.utilities.system_tools import get_pathname_from_package
+from anuga.geometry.polygon_function import Polygon_function
+        
+from anuga.abstract_2d_finite_volumes.mesh_factory import rectangular_cross
+from anuga.abstract_2d_finite_volumes.quantity import Quantity
+
+import anuga
+
+from anuga.structures.boyd_pipe_operator import Boyd_pipe_operator
+from anuga.structures.inlet_operator import Inlet_operator
+                            
+#from anuga.culvert_flows.culvert_routines import boyd_generalised_culvert_model
+     
+from math import pi, pow, sqrt
+
+import numpy as num
+
+
+
+
+
+"""test_that_culvert_runs_rating
+
+This test exercises the culvert and checks values outside rating curve
+are dealt with       
+"""
+
+path = get_pathname_from_package('anuga.culvert_flows')    
+
+length = 40.
+width = 15.
+
+dx = dy = 0.5          # Resolution: Length of subdivisions on both axes
+
+points, vertices, boundary = rectangular_cross(int(length/dx),
+                                               int(width/dy),
+                                               len1=length, 
+                                               len2=width)
+domain = anuga.Domain(points, vertices, boundary)   
+domain.set_starttime(10)
+domain.set_name()                 # Output name
+domain.set_default_order(2)
+#domain.set_beta(1.5)
+
+
+#----------------------------------------------------------------------
+# Setup initial conditions
+#----------------------------------------------------------------------
+
+def topography(x, y):
+    """Set up a weir
+    
+    A culvert will connect either side
+    """
+    # General Slope of Topography
+    z=-x/1000
+    
+    N = len(x)
+    for i in range(N):
+
+       # Sloping Embankment Across Channel
+        if 5.0 < x[i] < 10.1:
+            # Cut Out Segment for Culvert face                
+            if  1.0+(x[i]-5.0)/5.0 <  y[i]  < 4.0 - (x[i]-5.0)/5.0: 
+               z[i]=z[i]
+            else:
+               z[i] +=  0.5*(x[i] -5.0)    # Sloping Segment  U/S Face
+        if 10.0 < x[i] < 12.1:
+           z[i] +=  2.5                    # Flat Crest of Embankment
+        if 12.0 < x[i] < 14.5:
+            # Cut Out Segment for Culvert face                
+            if  2.0-(x[i]-12.0)/2.5 <  y[i]  < 3.0 + (x[i]-12.0)/2.5:
+               z[i]=z[i]
+            else:
+               z[i] +=  2.5-1.0*(x[i] -12.0) # Sloping D/S Face
+                   
+        
+    return z
+
+
+domain.set_quantity('elevation', topography) 
+domain.set_quantity('friction', 0.01)         # Constant friction 
+domain.set_quantity('stage',
+                    expression='elevation')   # Dry initial condition
+
+filename=os.path.join(path, 'example_rating_curve.csv')
+
+end_point0 = num.array([9.0, 2.5])
+end_point1 = num.array([13.0, 2.5])
+
+Boyd_pipe_operator(domain,
+                    #end_point0=[9.0, 2.5],
+                    #end_point1=[13.0, 2.5],
+                    #exchange_line0=[[9.0, 1.75],[9.0, 3.25]],
+                    #exchange_line1=[[13.0, 1.75],[13.0, 3.25]],
+                    losses=1.5,
+                    end_points=[end_point0, end_point1],
+                    diameter=1.5,
+                    apron=0.5,
+                    use_momentum_jet=True, 
+                    use_velocity_head=False,
+                    manning=0.013,
+                    verbose=False)
+
+
+line = [[0.0, 5.0], [0.0, 10.0]]
+Q = 5.0
+#Inlet_operator(domain, line, Q)
+
+
+
+
+##-----------------------------------------------------------------------
+## Setup boundary conditions
+##-----------------------------------------------------------------------
+
+## Inflow based on Flow Depth and Approaching Momentum
+Bi = anuga.Dirichlet_boundary([2.0, 0.0, 0.0])
+Br = anuga.Reflective_boundary(domain)              # Solid reflective wall
+#Bo = anuga.Dirichlet_boundary([-5, 0, 0])           # Outflow
+
+## Upstream and downstream conditions that will exceed the rating curve
+## I.e produce delta_h outside the range [0, 10] specified in the the 
+## file example_rating_curve.csv
+#Btus = anuga.Time_boundary(domain, \
+            #lambda t: [100*num.sin(2*pi*(t-4)/10), 0.0, 0.0])
+#Btds = anuga.Time_boundary(domain, \
+            #lambda t: [-5*(num.cos(2*pi*(t-4)/20)), 0.0, 0.0])
+#domain.set_boundary({'left': Btus, 'right': Btds, 'top': Br, 'bottom': Br})
+domain.set_boundary({'left': Bi, 'right': Br, 'top': Br, 'bottom': Br})
+
+
+##-----------------------------------------------------------------------
+## Evolve system through time
+##-----------------------------------------------------------------------
+
+#min_delta_w = sys.maxint 
+#max_delta_w = -min_delta_w
+for t in domain.evolve(yieldstep=1.0, finaltime=50.0):
+    domain.write_time()
+
+    #if domain.get_time() > 150.5 and domain.ge t_time() < 151.5 :
+        #Bi = anuga.Dirichlet_boundary([0.0, 0.0, 0.0])
+        #domain.set_boundary({'left': Bi, 'right': Br, 'top': Br, 'bottom': Br})
+
+    #delta_w = culvert.inlet.stage - culvert.outlet.stage
+    
+    #if delta_w > max_delta_w: max_delta_w = delta_w
+    #if delta_w < min_delta_w: min_delta_w = delta_w            
+    
+    pass
+
+## Check that extreme values in rating curve have been exceeded
+## so that we know that condition has been exercised
+#assert min_delta_w < 0
+#assert max_delta_w > 10        
+
+
+#os.remove('Test_culvert.sww')
Index: /trunk/anuga_core/source/anuga/structures/examples/run_culvert_inlet.py
===================================================================
--- /trunk/anuga_core/source/anuga/structures/examples/run_culvert_inlet.py	(revision 9440)
+++ /trunk/anuga_core/source/anuga/structures/examples/run_culvert_inlet.py	(revision 9440)
@@ -0,0 +1,158 @@
+import os.path
+import sys
+
+from anuga.utilities.system_tools import get_pathname_from_package
+from anuga.geometry.polygon_function import Polygon_function
+        
+from anuga.abstract_2d_finite_volumes.mesh_factory import rectangular_cross
+from anuga.abstract_2d_finite_volumes.quantity import Quantity
+
+import anuga
+
+from anuga.structures.boyd_pipe_operator import Boyd_pipe_operator
+from anuga.structures.inlet_operator import Inlet_operator
+                            
+#from anuga.culvert_flows.culvert_routines import boyd_generalised_culvert_model
+     
+from math import pi, pow, sqrt
+
+import numpy as num
+
+
+
+
+
+"""test_that_culvert_runs_rating
+
+This test exercises the culvert and checks values outside rating curve
+are dealt with       
+"""
+
+path = get_pathname_from_package('anuga.culvert_flows')    
+
+length = 40.
+width = 15.
+
+dx = dy = 0.5          # Resolution: Length of subdivisions on both axes
+
+points, vertices, boundary = rectangular_cross(int(length/dx),
+                                               int(width/dy),
+                                               len1=length, 
+                                               len2=width)
+domain = anuga.Domain(points, vertices, boundary)   
+domain.set_name('run_culvert_inlet')                 # Output name
+domain.set_default_order(2)
+#domain.set_beta(1.5)
+
+
+#----------------------------------------------------------------------
+# Setup initial conditions
+#----------------------------------------------------------------------
+
+def topography(x, y):
+    """Set up a weir
+    
+    A culvert will connect either side
+    """
+    # General Slope of Topography
+    z=-x/1000
+    
+    N = len(x)
+    for i in range(N):
+
+       # Sloping Embankment Across Channel
+        if 5.0 < x[i] < 10.1:
+            # Cut Out Segment for Culvert face                
+            if  1.0+(x[i]-5.0)/5.0 <  y[i]  < 4.0 - (x[i]-5.0)/5.0: 
+               z[i]=z[i]
+            else:
+               z[i] +=  0.5*(x[i] -5.0)    # Sloping Segment  U/S Face
+        if 10.0 < x[i] < 12.1:
+           z[i] +=  2.5                    # Flat Crest of Embankment
+        if 12.0 < x[i] < 14.5:
+            # Cut Out Segment for Culvert face                
+            if  2.0-(x[i]-12.0)/2.5 <  y[i]  < 3.0 + (x[i]-12.0)/2.5:
+               z[i]=z[i]
+            else:
+               z[i] +=  2.5-1.0*(x[i] -12.0) # Sloping D/S Face
+                   
+        
+    return z
+
+
+domain.set_quantity('elevation', topography) 
+domain.set_quantity('friction', 0.01)         # Constant friction 
+domain.set_quantity('stage',
+                    expression='elevation')   # Dry initial condition
+
+filename=os.path.join(path, 'example_rating_curve.csv')
+
+
+
+Boyd_pipe_operator(domain,
+                            end_points=[[9.0, 2.5],[13.0, 2.5]],
+                            losses=1.5,
+                            diameter=1.5,
+                            apron=5.0,
+                            use_momentum_jet=True,
+                            use_velocity_head=False,
+                            manning=0.013,
+                            verbose=False)
+
+
+line = [[0.0, 5.0], [0.0, 10.0]]
+Q = 5.0
+Inlet_operator(domain, line, Q)
+
+
+
+
+##-----------------------------------------------------------------------
+## Setup boundary conditions
+##-----------------------------------------------------------------------
+
+## Inflow based on Flow Depth and Approaching Momentum
+Bi = anuga.Dirichlet_boundary([2.0, 0.0, 0.0])
+Br = anuga.Reflective_boundary(domain)              # Solid reflective wall
+#Bo = anuga.Dirichlet_boundary([-5, 0, 0])           # Outflow
+
+## Upstream and downstream conditions that will exceed the rating curve
+## I.e produce delta_h outside the range [0, 10] specified in the the 
+## file example_rating_curve.csv
+#Btus = anuga.Time_boundary(domain, \
+            #lambda t: [100*num.sin(2*pi*(t-4)/10), 0.0, 0.0])
+#Btds = anuga.Time_boundary(domain, \
+            #lambda t: [-5*(num.cos(2*pi*(t-4)/20)), 0.0, 0.0])
+#domain.set_boundary({'left': Btus, 'right': Btds, 'top': Br, 'bottom': Br})
+domain.set_boundary({'left': Br, 'right': Br, 'top': Br, 'bottom': Br})
+
+
+##-----------------------------------------------------------------------
+## Evolve system through time
+##-----------------------------------------------------------------------
+
+#min_delta_w = sys.maxint 
+#max_delta_w = -min_delta_w
+for t in domain.evolve(yieldstep = 1.0, finaltime = 200):
+    domain.write_time()
+
+    #if domain.get_time() > 150.5 and domain.get_time() < 151.5 :
+        #Bi = anuga.Dirichlet_boundary([0.0, 0.0, 0.0])
+        #domain.set_boundary({'left': Bi, 'right': Br, 'top': Br, 'bottom': Br})
+
+    #delta_w = culvert.inlet.stage - culvert.outlet.stage
+    
+    #if delta_w > max_delta_w: max_delta_w = delta_w
+    #if delta_w < min_delta_w: min_delta_w = delta_w
+
+    print domain.volumetric_balance_statistics()
+    
+    pass
+
+## Check that extreme values in rating curve have been exceeded
+## so that we know that condition has been exercised
+#assert min_delta_w < 0
+#assert max_delta_w > 10        
+
+
+#os.remove('Test_culvert.sww')
Index: /trunk/anuga_core/source/anuga/structures/examples/run_gate_operator.py
===================================================================
--- /trunk/anuga_core/source/anuga/structures/examples/run_gate_operator.py	(revision 9440)
+++ /trunk/anuga_core/source/anuga/structures/examples/run_gate_operator.py	(revision 9440)
@@ -0,0 +1,146 @@
+import os.path
+import sys
+
+from anuga.utilities.system_tools import get_pathname_from_package
+from anuga.geometry.polygon_function import Polygon_function
+        
+from anuga.abstract_2d_finite_volumes.mesh_factory import rectangular_cross
+from anuga.abstract_2d_finite_volumes.quantity import Quantity
+
+import anuga
+
+from anuga.structures.boyd_box_operator import Boyd_box_operator
+from anuga.structures.inlet_operator import Inlet_operator
+                            
+#from anuga.culvert_flows.culvert_routines import boyd_generalised_culvert_model
+     
+from math import pi, pow, sqrt
+
+import numpy as num
+
+
+
+
+
+"""test_that_culvert_runs_rating
+
+This test exercises the culvert and checks values outside rating curve
+are dealt with       
+"""
+
+path = get_pathname_from_package('anuga.culvert_flows')    
+
+length = 40.
+width = 15.
+
+dx = dy = 0.5          # Resolution: Length of subdivisions on both axes
+
+points, vertices, boundary = rectangular_cross(int(length/dx),
+                                               int(width/dy),
+                                               len1=length, 
+                                               len2=width)
+domain = anuga.Domain(points, vertices, boundary)   
+domain.set_name('run_gate_operator')                 # Output name
+domain.set_default_order(2)
+#domain.set_beta(1.5)
+
+
+#----------------------------------------------------------------------
+# Setup initial conditions
+#----------------------------------------------------------------------
+
+def topography(x, y):
+    """Set up a weir
+    
+    A culvert will connect either side
+    """
+    # General Slope of Topography
+    z=-x/1000
+    
+    N = len(x)
+    for i in range(N):
+
+       # Sloping Embankment Across Channel
+        if 5.0 < x[i] < 10.1:
+            # Cut Out Segment for Culvert face                
+            if  1.0+(x[i]-5.0)/5.0 <  y[i]  < 4.0 - (x[i]-5.0)/5.0: 
+               z[i]=z[i]
+            else:
+               z[i] +=  0.5*(x[i] -5.0)    # Sloping Segment  U/S Face
+        if 10.0 < x[i] < 12.1:
+           z[i] +=  2.5                    # Flat Crest of Embankment
+        if 12.0 < x[i] < 14.5:
+            # Cut Out Segment for Culvert face                
+            if  2.0-(x[i]-12.0)/2.5 <  y[i]  < 3.0 + (x[i]-12.0)/2.5:
+               z[i]=z[i]
+            else:
+               z[i] +=  2.5-1.0*(x[i] -12.0) # Sloping D/S Face
+                   
+        
+    return z
+
+
+domain.set_quantity('elevation', topography) 
+domain.set_quantity('friction', 0.01)         # Constant friction 
+domain.set_quantity('stage',
+                    expression='elevation')   # Dry initial condition
+
+filename=os.path.join(path, 'example_rating_curve.csv')
+
+
+gate = Boyd_box_operator(domain,
+                            end_points=[[9.0, 2.5],[13.0, 2.5]],
+                            losses=1.5,
+                            width=1.5,
+                            height = 10.0,
+                            apron=5.0,
+                            use_momentum_jet=True,
+                            use_velocity_head=False,
+                            manning=0.013,
+                            verbose=False)
+
+line = [[0.0, 5.0], [0.0, 10.0]]
+Q = 1.0
+Inlet_operator(domain, line, Q)
+
+
+
+
+##-----------------------------------------------------------------------
+## Setup boundary conditions
+##-----------------------------------------------------------------------
+
+## Inflow based on Flow Depth and Approaching Momentum
+Br = anuga.Reflective_boundary(domain)              # Solid reflective wall
+
+domain.set_boundary({'left': Br, 'right': Br, 'top': Br, 'bottom': Br})
+
+
+##-----------------------------------------------------------------------
+## Evolve system through time
+##-----------------------------------------------------------------------
+
+#min_delta_w = sys.maxint 
+#max_delta_w = -min_delta_w
+for t in domain.evolve(yieldstep = 1.0, finaltime = 50):
+    domain.write_time()
+
+    if num.allclose(t, 10.0):
+        gate.set_culvert_height(0.0)
+
+    Q, velocity, depth = gate.discharge_routine()
+
+    print gate.inlets[0].get_enquiry_stage()
+    print gate.inlets[1].get_enquiry_stage()
+    print gate.get_culvert_height()
+
+    print Q
+    print velocity
+    print depth
+        
+    gate.print_timestepping_statistics()
+    
+
+
+
+
Index: /trunk/anuga_core/source/anuga/structures/examples/run_inlet_operator.py
===================================================================
--- /trunk/anuga_core/source/anuga/structures/examples/run_inlet_operator.py	(revision 9440)
+++ /trunk/anuga_core/source/anuga/structures/examples/run_inlet_operator.py	(revision 9440)
@@ -0,0 +1,168 @@
+import os.path
+import sys
+
+from anuga.utilities.system_tools import get_pathname_from_package
+from anuga.geometry.polygon_function import Polygon_function
+        
+from anuga.abstract_2d_finite_volumes.mesh_factory import rectangular_cross
+from anuga.abstract_2d_finite_volumes.quantity import Quantity
+from anuga.abstract_2d_finite_volumes.util import file_function
+
+import anuga
+
+from anuga.structures.boyd_box_operator import Boyd_box_operator
+from anuga.structures.inlet_operator import Inlet_operator
+                            
+#from anuga.culvert_flows.culvert_routines import boyd_generalised_culvert_model
+     
+from math import pi, pow, sqrt
+
+import numpy as num
+
+
+
+
+
+"""test_that_culvert_runs_rating
+
+This test exercises the culvert and checks values outside rating curve
+are dealt with       
+"""
+
+path = get_pathname_from_package('anuga.culvert_flows')    
+
+length = 40.
+width = 15.
+
+dx = dy = 0.5          # Resolution: Length of subdivisions on both axes
+
+points, vertices, boundary = rectangular_cross(int(length/dx),
+                                               int(width/dy),
+                                               len1=length, 
+                                               len2=width)
+domain = anuga.Domain(points, vertices, boundary)   
+domain.set_name('Testing_inlet_operator')                 # Output name
+domain.set_default_order(2)
+#domain.set_beta(1.5)
+
+
+#----------------------------------------------------------------------
+# Setup initial conditions
+#----------------------------------------------------------------------
+
+def topography(x, y):
+    """Set up a weir
+    
+    A culvert will connect either side
+    """
+    # General Slope of Topography
+    z=-x/1000
+    
+    N = len(x)
+    for i in range(N):
+
+       # Sloping Embankment Across Channel
+        if 5.0 < x[i] < 10.1:
+            # Cut Out Segment for Culvert face                
+            if  1.0+(x[i]-5.0)/5.0 <  y[i]  < 4.0 - (x[i]-5.0)/5.0: 
+               z[i]=z[i]
+            else:
+               z[i] +=  0.5*(x[i] -5.0)    # Sloping Segment  U/S Face
+        if 10.0 < x[i] < 12.1:
+           z[i] +=  2.5                    # Flat Crest of Embankment
+        if 12.0 < x[i] < 14.5:
+            # Cut Out Segment for Culvert face                
+            if  2.0-(x[i]-12.0)/2.5 <  y[i]  < 3.0 + (x[i]-12.0)/2.5:
+               z[i]=z[i]
+            else:
+               z[i] +=  2.5-1.0*(x[i] -12.0) # Sloping D/S Face
+                   
+        
+    return z
+
+
+domain.set_quantity('elevation', topography) 
+domain.set_quantity('friction', 0.01)         # Constant friction 
+domain.set_quantity('stage',
+                    expression='elevation')   # Dry initial condition
+
+filename=os.path.join(path, 'example_rating_curve.csv')
+
+
+
+#Boyd_box_operator(domain,
+#                            end_points=[[9.0, 2.5],[13.0, 2.5]],
+#                            losses=1.5,
+#                            width=1.5,
+#                            apron=5.0,
+#                            use_momentum_jet=True,
+#                            use_velocity_head=False,
+#                            manning=0.013,
+#                            verbose=False)
+
+
+line0 = [[0.0, 5.0], [0.0, 10.0]]
+
+
+Q = file_function('test_hydrograph.tms', quantities=['hydrograph'])
+
+#inlet0 = Inlet_operator(domain, line0, Q, label='first inlet')
+
+
+line1 = [[1.0, 5.0], [2.0, 10.0]]
+poly1 = [[1.0, 5.0], [2.0, 5.0], [2.0, 10.0], [1.0, 10.0]]
+inlet1 = Inlet_operator(domain, poly1, 2.0)
+
+
+
+##-----------------------------------------------------------------------
+## Setup boundary conditions
+##-----------------------------------------------------------------------
+
+## Inflow based on Flow Depth and Approaching Momentum
+Bi = anuga.Dirichlet_boundary([2.0, 0.0, 0.0])
+Br = anuga.Reflective_boundary(domain)              # Solid reflective wall
+#Bo = anuga.Dirichlet_boundary([-5, 0, 0])           # Outflow
+
+## Upstream and downstream conditions that will exceed the rating curve
+## I.e produce delta_h outside the range [0, 10] specified in the the 
+## file example_rating_curve.csv
+#Btus = anuga.Time_boundary(domain, \
+            #lambda t: [100*num.sin(2*pi*(t-4)/10), 0.0, 0.0])
+#Btds = anuga.Time_boundary(domain, \
+            #lambda t: [-5*(num.cos(2*pi*(t-4)/20)), 0.0, 0.0])
+#domain.set_boundary({'left': Btus, 'right': Btds, 'top': Br, 'bottom': Br})
+domain.set_boundary({'left': Br, 'right': Br, 'top': Br, 'bottom': Br})
+
+
+##-----------------------------------------------------------------------
+## Evolve system through time
+##-----------------------------------------------------------------------
+
+#min_delta_w = sys.maxint 
+#max_delta_w = -min_delta_w
+for t in domain.evolve(yieldstep = 1.0, finaltime = 38):
+    domain.write_time()
+
+    #if domain.get_time() > 150.5 and domain.get_time() < 151.5 :
+        #Bi = anuga.Dirichlet_boundary([0.0, 0.0, 0.0])
+        #domain.set_boundary({'left': Bi, 'right': Br, 'top': Br, 'bottom': Br})
+
+    #delta_w = culvert.inlet.stage - culvert.outlet.stage
+    
+    #if delta_w > max_delta_w: max_delta_w = delta_w
+    #if delta_w < min_delta_w: min_delta_w = delta_w
+
+    print domain.volumetric_balance_statistics()
+
+    #inlet0.print_timestepping_statistics()
+    inlet1.print_timestepping_statistics()
+    pass
+
+## Check that extreme values in rating curve have been exceeded
+## so that we know that condition has been exercised
+#assert min_delta_w < 0
+#assert max_delta_w > 10        
+
+
+#os.remove('Test_culvert.sww')
Index: /trunk/anuga_core/source/anuga/structures/examples/run_open_slot_wide_bridge.py
===================================================================
--- /trunk/anuga_core/source/anuga/structures/examples/run_open_slot_wide_bridge.py	(revision 9440)
+++ /trunk/anuga_core/source/anuga/structures/examples/run_open_slot_wide_bridge.py	(revision 9440)
@@ -0,0 +1,191 @@
+""" Testing CULVERT (Changing from Horizontal Abstraction to Vertical Abstraction
+
+This example includes a Model Topography that shows a TYPICAL Headwall Configuration
+
+The aim is to change the Culvert Routine to Model more precisely the abstraction
+from a vertical face.
+
+The inflow must include the impact of Approach velocity.
+Similarly the Outflow has MOMENTUM Not just Up welling as in the Horizontal Style
+abstraction
+
+"""
+print 'Starting.... Importing Modules...'
+#------------------------------------------------------------------------------
+# Import necessary modules
+#------------------------------------------------------------------------------
+import anuga
+
+from anuga.abstract_2d_finite_volumes.mesh_factory import rectangular_cross
+from anuga.shallow_water.shallow_water_domain import Domain
+from anuga.shallow_water.forcing import Rainfall, Inflow
+#from anuga.shallow_water.forcing import Reflective_boundary
+#from anuga.shallow_water.forcing import Dirichlet_boundary
+#from anuga.shallow_water.forcing import Transmissive_boundary, Time_boundary
+
+from anuga.culvert_flows.culvert_class import Culvert_flow
+from anuga.culvert_flows.culvert_routines import boyd_generalised_culvert_model
+#from anuga.culvert_flows.culvert_routines import weir_orifice_channel_culvert_model
+from math import pi,pow,sqrt
+
+import numpy as num
+
+
+#------------------------------------------------------------------------------
+# Setup computational domain
+#------------------------------------------------------------------------------
+print 'Setting up domain'
+
+length = 200. #x-Dir
+width = 200.  #y-dir
+
+dx = dy = 2.5          # Resolution: Length of subdivisions on both axes
+#dx = dy = .5           # Resolution: Length of subdivisions on both axes
+#dx = dy = .5           # Resolution: Length of subdivisions on both axes
+#dx = dy = .1           # Resolution: Length of subdivisions on both axes
+
+points, vertices, boundary = rectangular_cross(int(length/dx), int(width/dy),
+                                               len1=length, len2=width)
+domain = Domain(points, vertices, boundary)   
+domain.set_name('Test_Open_slot_WIDE_BRIDGE')                 # Output name
+domain.set_default_order(2)
+domain.H0 = 0.01
+domain.tight_slope_limiters = 1
+
+print 'Size', len(domain)
+
+#------------------------------------------------------------------------------
+# Setup initial conditions
+#------------------------------------------------------------------------------
+
+def topography(x, y):
+    """Set up a weir
+    
+    A culvert will connect either side
+    """
+    # General Slope of Topography
+    z=10.0-x/100.0  # % Longitudinal Slope
+    
+    #       NOW Add bits and Pieces to topography
+    bank_hgt=10.0
+    bridge_width = 50.0
+    bank_width = 10.0
+    
+    us_apron_skew = 1.0 # 1.0 = 1 Length: 1 Width, 2.0 = 2 Length : 1 Width
+    us_start_x = 10.0
+    top_start_y = 50.0
+    us_slope = 3.0  #Horiz : Vertic
+    ds_slope = 3.0
+    ds_apron_skew = 1.0 # 1.0 = 1 Length: 1 Width, 2.0 = 2 Length : 1 Width
+    centre_line_y= top_start_y+bridge_width/2.0
+
+    # CALCULATE PARAMETERS TO FORM THE EMBANKMENT
+    us_slope_length = bank_hgt*us_slope
+    us_end_x =us_start_x + us_slope_length
+    us_toe_start_y =top_start_y - us_slope_length / us_apron_skew
+    us_toe_end_y = top_start_y + bridge_width + us_slope_length / us_apron_skew
+
+    top_end_y = top_start_y + bridge_width
+    ds_slope_length = bank_hgt*ds_slope
+    ds_start_x = us_end_x + bank_width
+    ds_end_x = ds_start_x + ds_slope_length
+
+    ds_toe_start_y =top_start_y - ds_slope_length / ds_apron_skew
+    ds_toe_end_y = top_start_y + bridge_width + ds_slope_length / ds_apron_skew
+
+
+    N = len(x)
+    for i in range(N):
+
+       # Sloping Embankment Across Channel
+        if us_start_x < x[i] < us_end_x +0.1:   # For UPSLOPE on the Upstream FACE
+        #if 5.0 < x[i] < 10.1: # For a Range of X, and over a Range of Y based on X adjust Z
+            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:
+			#if  49.0+(x[i]-5.0)/5.0 <  y[i]  < 151.0 - (x[i]-5.0)/5.0: # Cut Out Base Segment for Culvert FACE
+               z[i]=z[i] # Flat Apron
+            else:
+               z[i] += z[i] + (x[i] - us_start_x)/us_slope    # Set elevation for Sloping Segment  U/S Face
+        if us_end_x < x[i] < ds_start_x + 0.1: # FOR The TOP of BANK Segment
+           if top_start_y < y[i] < top_end_y:
+               z[i]=z[i] # Flat Apron
+           else:
+               z[i] +=  z[i]+bank_hgt        # Flat Crest of Embankment
+        if ds_start_x < x[i] < ds_end_x: # DOWN SDLOPE Segment on Downstream face
+            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
+               z[i]=z[i] # Flat Apron
+            else:
+               z[i] += z[i]+bank_hgt-(x[i] -ds_start_x)/ds_slope       # Sloping D/S Face
+           
+        
+
+    return z
+
+print 'Setting Quantities....'
+domain.set_quantity('elevation', topography)  # Use function for elevation
+domain.set_quantity('friction', 0.01)         # Constant friction 
+domain.set_quantity('stage',
+                    expression='elevation')   # Dry initial condition
+
+
+
+
+#------------------------------------------------------------------------------
+# Setup specialised forcing terms
+#------------------------------------------------------------------------------
+
+#------------------------------------------------------------------------------
+# Setup CULVERT INLETS and OUTLETS in Current Topography
+#------------------------------------------------------------------------------
+print 'DEFINING any Structures if Required'
+
+#  DEFINE CULVERT INLET AND OUTLETS
+
+"""
+culvert_rating = Culvert_flow(domain,
+                       culvert_description_filename='example_rating_curve.csv',
+                       end_point0=[40.0, 75.0], 
+                       end_point1=[50.0, 75.0],
+                       verbose=True)
+
+
+culvert_energy = Culvert_flow(domain,
+                       label='Culvert No. 1',
+                       description='This culvert is a test unit 1.2m Wide by 0.75m High',   
+                       end_point0=[40.0, 75.0], 
+                       end_point1=[50.0, 75.0],
+                       width=50.0,depth=5.0,
+                       culvert_routine=boyd_generalised_culvert_model,        
+                       number_of_barrels=1,
+                       #update_interval=0.25,
+                       log_file=True,
+                       discharge_hydrograph=True,
+                       use_velocity_head=False,
+                       verbose=True)
+
+domain.forcing_terms.append(culvert_energy)
+"""
+
+#------------------------------------------------------------------------------
+# Setup boundary conditions
+#------------------------------------------------------------------------------
+print 'Setting Boundary Conditions'
+Br = anuga.Reflective_boundary(domain)              # Solid reflective wall
+Bi = anuga.Dirichlet_boundary([0.0, 0.0, 0.0])          # Inflow based on Flow Depth and Approaching Momentum !!!
+
+Bo = anuga.Dirichlet_boundary([-5.0, 0, 0])           # Outflow water at -5.0
+Bd = anuga.Dirichlet_boundary([0,0,0])                # Outflow water at 0.0
+
+#Btus = Time_boundary(domain, lambda t: [0.0+ 1.025*(1+num.sin(2*pi*(t-4)/10)), 0.0, 0.0])
+#Btds = Time_boundary(domain, lambda t: [0.0+ 0.0075*(1+num.sin(2*pi*(t-4)/20)), 0.0, 0.0])
+
+Btus = anuga.Dirichlet_boundary([18.0, 0, 0])           # Outflow water at 5.0
+Btds = anuga.Dirichlet_boundary([0.0, 0, 0])           # Outflow water at 1.0
+domain.set_boundary({'left': Btus, 'right': Btds, 'top': Br, 'bottom': Br})
+
+
+#------------------------------------------------------------------------------
+# Evolve system through time
+#------------------------------------------------------------------------------
+
+for t in domain.evolve(yieldstep = 1, finaltime = 100):
+    print domain.timestepping_statistics()
Index: /trunk/anuga_core/source/anuga/structures/examples/run_outlet_control.py
===================================================================
--- /trunk/anuga_core/source/anuga/structures/examples/run_outlet_control.py	(revision 9440)
+++ /trunk/anuga_core/source/anuga/structures/examples/run_outlet_control.py	(revision 9440)
@@ -0,0 +1,232 @@
+""" Testing CULVERT (Changing from Horizontal Abstraction to Vertical Abstraction
+
+This example includes a Model Topography that shows a TYPICAL Headwall Configuration
+
+The aim is to change the Culvert Routine to Model more precisely the abstraction
+from a vertical face.
+
+The inflow must include the impact of Approach velocity.
+Similarly the Outflow has MOMENTUM Not just Up welling as in the Horizontal Style
+abstraction
+
+"""
+print 'Starting.... Importing Modules...'
+#------------------------------------------------------------------------------
+# Import necessary modules
+#------------------------------------------------------------------------------
+import anuga
+
+from anuga.abstract_2d_finite_volumes.mesh_factory import rectangular_cross
+from anuga.shallow_water.shallow_water_domain import Domain
+from anuga.shallow_water.forcing import Rainfall, Inflow
+#from anuga.shallow_water.forcing import Reflective_boundary
+#from anuga.shallow_water.forcing import Dirichlet_boundary
+#from anuga.shallow_water.forcing import Transmissive_boundary, Time_boundary
+
+#from anuga.culvert_flows.culvert_class import Culvert_flow
+from anuga.structures.boyd_pipe_operator import Boyd_pipe_operator
+from anuga.structures.boyd_box_operator import Boyd_box_operator
+#from anuga.culvert_flows.culvert_routines import weir_orifice_channel_culvert_model
+from math import pi,pow,sqrt
+
+import numpy as num
+
+
+
+
+#------------------------------------------------------------------------------
+# Setup computational domain
+#------------------------------------------------------------------------------
+print 'Setting up domain'
+
+length = 120. #x-Dir
+width = 200.  #y-dir
+
+dx = dy = 2.0          # Resolution: Length of subdivisions on both axes
+#dx = dy = .5           # Resolution: Length of subdivisions on both axes
+#dx = dy = .5           # Resolution: Length of subdivisions on both axes
+#dx = dy = .1           # Resolution: Length of subdivisions on both axes
+
+points, vertices, boundary = rectangular_cross(int(length/dx), int(width/dy),
+                                                    len1=length, len2=width)
+domain = Domain(points, vertices, boundary)   
+domain.set_name('Test_Outlet_Ctrl')                 # Output name
+domain.set_default_order(2)
+domain.H0 = 0.01
+domain.tight_slope_limiters = 1
+
+print 'Size', len(domain)
+
+#------------------------------------------------------------------------------
+# Setup initial conditions
+#------------------------------------------------------------------------------
+
+def topography(x, y):
+    """Set up a weir
+    
+    A culvert will connect either side
+    """
+    # General Slope of Topography
+    z=10.0-x/100.0  # % Longitudinal Slope
+    
+    #       NOW Add bits and Pieces to topography
+    bank_hgt=10.0
+    bridge_width = 50.0
+    bank_width = 10.0
+    
+    us_apron_skew = 1.0 # 1.0 = 1 Length: 1 Width, 2.0 = 2 Length : 1 Width
+    us_start_x = 10.0
+    top_start_y = 50.0
+    us_slope = 3.0  #Horiz : Vertic
+    ds_slope = 3.0
+    ds_apron_skew = 1.0 # 1.0 = 1 Length: 1 Width, 2.0 = 2 Length : 1 Width
+    centre_line_y= top_start_y+bridge_width/2.0
+
+    # CALCULATE PARAMETERS TO FORM THE EMBANKMENT
+    us_slope_length = bank_hgt*us_slope
+    us_end_x =us_start_x + us_slope_length
+    us_toe_start_y =top_start_y - us_slope_length / us_apron_skew
+    us_toe_end_y = top_start_y + bridge_width + us_slope_length / us_apron_skew
+
+    top_end_y = top_start_y + bridge_width
+    ds_slope_length = bank_hgt*ds_slope
+    ds_start_x = us_end_x + bank_width
+    ds_end_x = ds_start_x + ds_slope_length
+
+    ds_toe_start_y =top_start_y - ds_slope_length / ds_apron_skew
+    ds_toe_end_y = top_start_y + bridge_width + ds_slope_length / ds_apron_skew
+
+
+    N = len(x)
+    for i in range(N):
+
+       # Sloping Embankment Across Channel
+        if us_start_x < x[i] < us_end_x +0.1:   # For UPSLOPE on the Upstream FACE
+        #if 5.0 < x[i] < 10.1: # For a Range of X, and over a Range of Y based on X adjust Z
+            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:
+                #if  49.0+(x[i]-5.0)/5.0 <  y[i]  < 151.0 - (x[i]-5.0)/5.0: # Cut Out Base Segment for Culvert FACE
+                 z[i]=z[i] # Flat Apron
+                #z[i] += z[i] + (x[i] - us_start_x)/us_slope
+                #pass
+            else:
+               z[i] += z[i] + (x[i] - us_start_x)/us_slope    # Sloping Segment  U/S Face
+        if us_end_x < x[i] < ds_start_x + 0.1:
+           z[i] +=  z[i]+bank_hgt        # Flat Crest of Embankment
+        if ds_start_x < x[i] < ds_end_x: # DOWN SDLOPE Segment on Downstream face
+            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
+                 z[i]=z[i] # Flat Apron
+                #z[i] += z[i]+bank_hgt-(x[i] -ds_start_x)/ds_slope
+                #pass
+            else:
+               z[i] += z[i]+bank_hgt-(x[i] -ds_start_x)/ds_slope       # Sloping D/S Face
+           
+        
+
+    return z
+
+print 'Setting Quantities....'
+domain.set_quantity('elevation', topography)  # Use function for elevation
+domain.set_quantity('friction', 0.01)         # Constant friction 
+domain.set_quantity('stage',
+                    expression='elevation')   # Dry initial condition
+
+
+
+
+#------------------------------------------------------------------------------
+# Setup specialised forcing terms
+#------------------------------------------------------------------------------
+
+#------------------------------------------------------------------------------
+# Setup CULVERT INLETS and OUTLETS in Current Topography
+#------------------------------------------------------------------------------
+print 'Defining Structures'
+
+#  DEFINE CULVERT INLET AND OUTLETS
+
+
+#culvert0 = Culvert_operator(domain,
+#                            end_point0=[40.0, 75.0],
+#                            end_point1=[50.0, 75.0],
+#                            width=50.0,
+#                            depth=10.0,
+#                            apron=5.0,
+#                            verbose=False)
+
+
+#------------------------------------------------------------------------------
+# Setup culverts
+#------------------------------------------------------------------------------
+
+culverts = []
+number_of_culverts = 2
+for i in range(number_of_culverts):
+    culvert_width = 50.0/number_of_culverts
+    y = 100-i*culvert_width - culvert_width/2.0
+    ep0 = num.array([40.0, y])
+    ep1 = num.array([50.0, y])
+    
+    losses = {'inlet':0.5, 'outlet':1, 'bend':0, 'grate':0, 'pier': 0, 'other': 0}
+#    culverts.append(Boyd_pipe_operator(domain,
+#                            end_point0=ep0,
+#                            end_point1=ep1,
+#                            losses=losses,
+#                            diameter=1.5, #culvert_width, #3.658,
+#                            apron=6.0,
+#                            use_momentum_jet=True,
+#                            use_velocity_head=True,
+#                            manning=0.013,
+#                            logging=True,
+#                            label='culvert',
+#                            verbose=False))
+
+
+
+
+
+    Boyd_box_operator(domain,
+                      losses=losses,
+                      width=culvert_width,
+                      height=10.0,
+                      end_points=[ep0,ep1],
+                      apron=6.0,
+                      manning=0.013,
+                      label='box_culvert',
+                      logging=True,
+                      verbose=False)
+
+#losses = {'inlet':1, 'outlet':1, 'bend':1, 'grate':1, 'pier': 1, 'other': 1}
+#culvert2 = Culvert_operator(domain,
+                            #end_point0=[40.0, 62.5],
+                            #end_point1=[50.0, 62.5],
+                            #losses,
+                            #width=25.0,
+                            #depth=10.0,
+                            #apron=5.0,
+                            #manning=0.013,
+                            #verbose=False)
+
+
+
+#------------------------------------------------------------------------------
+# Setup boundary conditions
+#------------------------------------------------------------------------------
+print 'Setting Boundary Conditions'
+Br = anuga.Reflective_boundary(domain)              # Solid reflective wall
+Bi = anuga.Dirichlet_boundary([0.0, 0.0, 0.0])          # Inflow based on Flow Depth and Approaching Momentum !!!
+
+Btus = anuga.Dirichlet_boundary([20.0, 0, 0])           # Outflow water at 10.0
+Btds = anuga.Dirichlet_boundary([19.0, 0, 0])           # Outflow water at 9.0
+domain.set_boundary({'left': Btus, 'right': Btds, 'top': Br, 'bottom': Br})
+
+
+
+#------------------------------------------------------------------------------
+# Evolve system through time
+#------------------------------------------------------------------------------
+
+for t in domain.evolve(yieldstep = 1, finaltime = 100):
+    print domain.timestepping_statistics()
+
+    domain.print_operator_timestepping_statistics()
+
Index: /trunk/anuga_core/source/anuga/structures/examples/run_update_special_condition.py
===================================================================
--- /trunk/anuga_core/source/anuga/structures/examples/run_update_special_condition.py	(revision 9440)
+++ /trunk/anuga_core/source/anuga/structures/examples/run_update_special_condition.py	(revision 9440)
@@ -0,0 +1,184 @@
+import os.path
+import sys
+
+from anuga.utilities.system_tools import get_pathname_from_package
+from anuga.geometry.polygon_function import Polygon_function
+        
+from anuga.abstract_2d_finite_volumes.mesh_factory import rectangular_cross
+from anuga.abstract_2d_finite_volumes.quantity import Quantity
+
+import anuga
+
+from anuga.structures.boyd_pipe_operator import Boyd_pipe_operator
+from anuga.structures.inlet_operator import Inlet_operator
+                            
+#from anuga.culvert_flows.culvert_routines import boyd_generalised_culvert_model
+     
+from math import pi, pow, sqrt
+
+import numpy as num
+
+
+
+
+
+"""test_that_culvert_runs_rating
+
+This test exercises the culvert and checks values outside rating curve
+are dealt with       
+"""
+
+path = get_pathname_from_package('anuga.culvert_flows')    
+
+length = 40.
+width = 15.
+
+dx = dy = 0.5          # Resolution: Length of subdivisions on both axes
+
+points, vertices, boundary = rectangular_cross(int(length/dx),
+                                               int(width/dy),
+                                               len1=length, 
+                                               len2=width)
+domain = anuga.Domain(points, vertices, boundary)   
+domain.set_name('Test_culvert')                 # Output name
+domain.set_default_order(2)
+#domain.set_beta(1.5)
+
+
+#----------------------------------------------------------------------
+# Setup initial conditions
+#----------------------------------------------------------------------
+
+def topography(x, y):
+    """Set up a weir
+    
+    A culvert will connect either side
+    """
+    # General Slope of Topography
+    z=-x/1000
+    
+    N = len(x)
+    for i in range(N):
+
+       # Sloping Embankment Across Channel
+        if 5.0 < x[i] < 10.1:
+            # Cut Out Segment for Culvert face                
+            if  1.0+(x[i]-5.0)/5.0 <  y[i]  < 4.0 - (x[i]-5.0)/5.0: 
+               z[i]=z[i]
+            else:
+               z[i] +=  0.5*(x[i] -5.0)    # Sloping Segment  U/S Face
+        if 10.0 < x[i] < 12.1:
+           z[i] +=  2.5                    # Flat Crest of Embankment
+        if 12.0 < x[i] < 14.5:
+            # Cut Out Segment for Culvert face                
+            if  2.0-(x[i]-12.0)/2.5 <  y[i]  < 3.0 + (x[i]-12.0)/2.5:
+               z[i]=z[i]
+            else:
+               z[i] +=  2.5-1.0*(x[i] -12.0) # Sloping D/S Face
+                   
+        
+    return z
+
+
+line = [[0.01, 5.0], [0.01, 10.0]]
+Q = 50.0
+
+import anuga
+
+inlet = anuga.structures.inlet.Inlet(domain, line)
+
+domain.special_inlet = inlet
+
+def my_update_special_conditions(domain):
+
+    #print 'inside my domain update_special condition'
+
+    domain.special_inlet.set_depths(5.0)
+
+import types
+domain.update_special_conditions = types.MethodType(my_update_special_conditions, domain)
+
+domain.set_quantity('elevation', topography) 
+domain.set_quantity('friction', 0.01)         # Constant friction 
+domain.set_quantity('stage',
+                    expression='elevation')   # Dry initial condition
+
+filename=os.path.join(path, 'example_rating_curve.csv')
+
+
+
+#Boyd_pipe_operator(domain,
+#                            end_point0=[9.0, 2.5],
+#                            end_point1=[13.0, 2.5],
+#                            losses=1.5,
+#                            diameter=1.5,
+#                            apron=5.0,
+#                            use_momentum_jet=True,
+#                            use_velocity_head=False,
+#                            manning=0.013,
+#                            verbose=False)
+
+
+line = [[0.0, 5.0], [0.0, 10.0]]
+Q = 50.0
+#Inlet_operator(domain, line, Q)
+
+
+
+
+
+
+
+##-----------------------------------------------------------------------
+## Setup boundary conditions
+##-----------------------------------------------------------------------
+
+## Inflow based on Flow Depth and Approaching Momentum
+Bi = anuga.Dirichlet_boundary([2.0, 0.0, 0.0])
+Br = anuga.Reflective_boundary(domain)              # Solid reflective wall
+#Bo = anuga.Dirichlet_boundary([-5, 0, 0])           # Outflow
+
+## Upstream and downstream conditions that will exceed the rating curve
+## I.e produce delta_h outside the range [0, 10] specified in the the 
+## file example_rating_curve.csv
+#Btus = anuga.Time_boundary(domain, \
+            #lambda t: [100*num.sin(2*pi*(t-4)/10), 0.0, 0.0])
+#Btds = anuga.Time_boundary(domain, \
+            #lambda t: [-5*(num.cos(2*pi*(t-4)/20)), 0.0, 0.0])
+#domain.set_boundary({'left': Btus, 'right': Btds, 'top': Br, 'bottom': Br})
+domain.set_boundary({'left': Br, 'right': Br, 'top': Br, 'bottom': Br})
+
+
+
+
+##-----------------------------------------------------------------------
+## Evolve system through time
+##-----------------------------------------------------------------------
+
+#min_delta_w = sys.maxint 
+#max_delta_w = -min_delta_w
+for t in domain.evolve(yieldstep = 1.0, finaltime = 30):
+    domain.write_time()
+
+    #if domain.get_time() > 150.5 and domain.get_time() < 151.5 :
+        #Bi = anuga.Dirichlet_boundary([0.0, 0.0, 0.0])
+        #domain.set_boundary({'left': Bi, 'right': Br, 'top': Br, 'bottom': Br})
+
+    #delta_w = culvert.inlet.stage - culvert.outlet.stage
+    
+    #if delta_w > max_delta_w: max_delta_w = delta_w
+    #if delta_w < min_delta_w: min_delta_w = delta_w
+
+    #print domain.volumetric_balance_statistics()
+
+
+
+
+
+## Check that extreme values in rating curve have been exceeded
+## so that we know that condition has been exercised
+#assert min_delta_w < 0
+#assert max_delta_w > 10        
+
+
+#os.remove('Test_culvert.sww')
Index: /trunk/anuga_core/source/anuga/structures/examples/run_wide_bridge.py
===================================================================
--- /trunk/anuga_core/source/anuga/structures/examples/run_wide_bridge.py	(revision 9440)
+++ /trunk/anuga_core/source/anuga/structures/examples/run_wide_bridge.py	(revision 9440)
@@ -0,0 +1,283 @@
+""" Testing CULVERT (Changing from Horizontal Abstraction to Vertical Abstraction
+
+This example includes a Model Topography that shows a TYPICAL Headwall Configuration
+
+The aim is to change the Culvert Routine to Model more precisely the abstraction
+from a vertical face.
+
+The inflow must include the impact of Approach velocity.
+Similarly the Outflow has MOMENTUM Not just Up welling as in the Horizontal Style
+abstraction
+
+"""
+print 'Starting.... Importing Modules...'
+#------------------------------------------------------------------------------
+# Import necessary modules
+#------------------------------------------------------------------------------
+import anuga
+
+from anuga.abstract_2d_finite_volumes.mesh_factory import rectangular_cross
+from anuga.shallow_water.shallow_water_domain import Domain
+from anuga.shallow_water.forcing import Rainfall, Inflow
+#from anuga.shallow_water.forcing import Reflective_boundary
+#from anuga.shallow_water.forcing import Dirichlet_boundary
+#from anuga.shallow_water.forcing import Transmissive_boundary, Time_boundary
+
+
+#from anuga.culvert_flows.culvert_routines import weir_orifice_channel_culvert_model
+from math import pi,pow,sqrt
+
+import numpy as num
+
+
+#------------------------------------------------------------------------------
+# Setup computational domain
+#------------------------------------------------------------------------------
+print 'Setting up domain'
+
+length = 200. #x-Dir
+width = 200.  #y-dir
+
+dx = dy = 2.0          # Resolution: Length of subdivisions on both axes
+#dx = dy = .5           # Resolution: Length of subdivisions on both axes
+#dx = dy = .5           # Resolution: Length of subdivisions on both axes
+#dx = dy = .1           # Resolution: Length of subdivisions on both axes
+
+points, vertices, boundary = rectangular_cross(int(length/dx), int(width/dy),
+                                                    len1=length, len2=width)
+domain = Domain(points, vertices, boundary)   
+domain.set_name('Test_WIDE_BRIDGE')                 # Output name
+#domain.set_default_order(2)
+#omain.H0 = 0.01
+#domain.tight_slope_limiters = 1
+
+domain.set_flow_algorithm('2_0')
+
+print 'Size', len(domain)
+
+#------------------------------------------------------------------------------
+# Setup initial conditions
+#------------------------------------------------------------------------------
+
+def topography(x, y):
+    """Set up a weir
+    
+    A culvert will connect either side
+    """
+    # General Slope of Topography
+    z=10.0-x/100.0  # % Longitudinal Slope
+    
+    #       NOW Add bits and Pieces to topography
+    bank_hgt=10.0
+    bridge_width = 50.0
+    bank_width = 10.0
+    
+    us_apron_skew = 1.0 # 1.0 = 1 Length: 1 Width, 2.0 = 2 Length : 1 Width
+    us_start_x = 10.0
+    top_start_y = 50.0
+    us_slope = 3.0  #Horiz : Vertic
+    ds_slope = 3.0
+    ds_apron_skew = 1.0 # 1.0 = 1 Length: 1 Width, 2.0 = 2 Length : 1 Width
+    centre_line_y= top_start_y+bridge_width/2.0
+
+    # CALCULATE PARAMETERS TO FORM THE EMBANKMENT
+    us_slope_length = bank_hgt*us_slope
+    us_end_x =us_start_x + us_slope_length
+    us_toe_start_y =top_start_y - us_slope_length / us_apron_skew
+    us_toe_end_y = top_start_y + bridge_width + us_slope_length / us_apron_skew
+
+    top_end_y = top_start_y + bridge_width
+    ds_slope_length = bank_hgt*ds_slope
+    ds_start_x = us_end_x + bank_width
+    ds_end_x = ds_start_x + ds_slope_length
+
+    ds_toe_start_y =top_start_y - ds_slope_length / ds_apron_skew
+    ds_toe_end_y = top_start_y + bridge_width + ds_slope_length / ds_apron_skew
+
+
+    N = len(x)
+    for i in range(N):
+
+       # Sloping Embankment Across Channel
+        if us_start_x < x[i] < us_end_x +0.1:   # For UPSLOPE on the Upstream FACE
+        #if 5.0 < x[i] < 10.1: # For a Range of X, and over a Range of Y based on X adjust Z
+            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:
+                #if  49.0+(x[i]-5.0)/5.0 <  y[i]  < 151.0 - (x[i]-5.0)/5.0: # Cut Out Base Segment for Culvert FACE
+                 z[i]=z[i] # Flat Apron
+                #z[i] += z[i] + (x[i] - us_start_x)/us_slope
+                #pass
+            else:
+               z[i] += z[i] + (x[i] - us_start_x)/us_slope    # Sloping Segment  U/S Face
+        if us_end_x < x[i] < ds_start_x + 0.1:
+           z[i] +=  z[i]+bank_hgt        # Flat Crest of Embankment
+        if ds_start_x < x[i] < ds_end_x: # DOWN SDLOPE Segment on Downstream face
+            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
+                 z[i]=z[i] # Flat Apron
+                #z[i] += z[i]+bank_hgt-(x[i] -ds_start_x)/ds_slope
+                #pass
+            else:
+               z[i] += z[i]+bank_hgt-(x[i] -ds_start_x)/ds_slope       # Sloping D/S Face
+           
+        
+
+    return z
+
+print 'Setting Quantities....'
+domain.set_quantity('elevation', topography)  # Use function for elevation
+domain.set_quantity('friction', 0.01)         # Constant friction 
+domain.set_quantity('stage',
+                    expression='elevation')   # Dry initial condition
+
+
+
+
+#------------------------------------------------------------------------------
+# Setup specialised forcing terms
+#------------------------------------------------------------------------------
+
+#------------------------------------------------------------------------------
+# Setup CULVERT INLETS and OUTLETS in Current Topography
+#------------------------------------------------------------------------------
+print 'DEFINING any Structures if Required'
+
+#  DEFINE CULVERT INLET AND OUTLETS
+
+"""
+culvert_rating = Culvert_flow(domain,
+    culvert_description_filename='example_rating_curve.csv',
+    end_point0=[0.0, 75.0], 
+    end_point1=[50.0, 75.0],
+    verbose=True)
+
+culvert_energy = Culvert_flow(domain,
+    label='Culvert No. 1',
+    description='This culvert is a test unit 4m diameter',   
+    end_point0=[40.0, 75.0], 
+    end_point1=[50.0, 75.0],
+    width=4.0,
+    culvert_routine=boyd_generalised_culvert_model,  #culvert_routine=weir_orifice_channel_culvert_model,     
+    number_of_barrels=1,
+    number_of_smoothing_steps=10,
+    #update_interval=0.25,
+    log_file=True,
+    discharge_hydrograph=True,
+    use_velocity_head=False,
+    use_momentum_jet=False,
+    verbose=True)
+
+domain.forcing_terms.append(culvert_energy)
+"""
+#from anuga.structures.boyd_box_operator import Boyd_box_operator
+#culvert0 = Culvert_operator(domain,
+#                            end_point0=[40.0, 75.0],
+#                            end_point1=[50.0, 75.0],
+#                            width=50.0,
+#                            depth=10.0,
+#                            apron=5.0,
+#                            verbose=False)
+
+
+#------------------------------------------------------------------------------
+# Setup culverts
+#------------------------------------------------------------------------------
+culverts = []
+number_of_culverts = 1 
+for i in range(number_of_culverts):
+    culvert_width = 50.0/number_of_culverts
+    y = 100-i*culvert_width - culvert_width/2.0
+    ep0 = num.array([37.0, y])
+    ep1 = num.array([53.0, y])
+    culverts.append(anuga.Boyd_box_operator(domain,
+                                            losses=1.5,
+                                            width=3.658,
+                                            height=3.658,
+                                            end_points=[ep0, ep1],
+                                            apron=0.5,
+                                            manning=0.013,
+                                            enquiry_gap=1.0,
+                                            description='bridge culvert',
+                                            verbose=False))
+
+#culvert2 = Culvert_operator(domain,
+#                            end_point0=[40.0, 62.5],
+#                            end_point1=[50.0, 62.5],
+#                            width=25.0,
+#                            depth=10.0,
+#                            apron=5.0,
+#                            manning=0.013,
+#                            verbose=False)
+
+
+
+"""
+culvert_energy = Culvert_flow(domain,
+    label='Culvert No. 1',
+    description='This culvert is a test unit 50m Wide by 5m High',   
+    end_point0=[40.0, 75.0],
+    end_point1=[50.0, 75.0],
+    width=50.0,depth=5.0,
+    culvert_routine=boyd_generalised_culvert_model,  #culvert_routine=weir_orifice_channel_culvert_model,     
+    number_of_barrels=1,
+    number_of_smoothing_steps=10,
+    #update_interval=0.25,
+    log_file=True,
+    discharge_hydrograph=True,
+    use_velocity_head=False,
+    use_momentum_jet=False,
+    verbose=True)
+
+domain.forcing_terms.append(culvert_energy)
+"""
+
+#------------------------------------------------------------------------------
+# Setup boundary conditions
+#------------------------------------------------------------------------------
+print 'Setting Boundary Conditions'
+Br = anuga.Reflective_boundary(domain)              # Solid reflective wall
+Bi = anuga.Dirichlet_boundary([0.0, 0.0, 0.0])          # Inflow based on Flow Depth and Approaching Momentum !!!
+
+Bo = anuga.Dirichlet_boundary([-5.0, 0, 0])           # Outflow water at -5.0
+Bd = anuga.Dirichlet_boundary([0,0,0])                # Outflow water at 0.0
+
+#Btus = Time_boundary(domain, lambda t: [0.0+ 1.025*(1+num.sin(2*pi*(t-4)/10)), 0.0, 0.0])
+#Btds = Time_boundary(domain, lambda t: [0.0+ 0.0075*(1+num.sin(2*pi*(t-4)/20)), 0.0, 0.0])
+
+Btus = anuga.Dirichlet_boundary([20.0, 0, 0])           # Outflow water at 20
+Btds = anuga.Dirichlet_boundary([19.0, 0, 0])           # Outflow water at 19
+domain.set_boundary({'left': Btus, 'right': Br, 'top': Br, 'bottom': Br})
+
+
+#------------------------------------------------------------------------------
+# Evolve system through time
+#------------------------------------------------------------------------------
+
+for t in domain.evolve(yieldstep = 1, finaltime = 100):
+    print domain.timestepping_statistics()
+    print domain.volumetric_balance_statistics()
+    for i, culvert in enumerate(culverts):
+        print 'culvert: ', i
+        print culvert.timestepping_statistics()
+    
+
+    
+"""    
+#import sys; sys.exit() 
+# Profiling code
+import time
+t0 = time.time()
+   
+s = 'for t in domain.evolve(yieldstep = 0.1, finaltime = 300): domain.write_time()'
+
+import profile, pstats
+FN = 'profile.dat'
+
+profile.run(s, FN)
+    
+print 'That took %.2f seconds' %(time.time()-t0)
+
+S = pstats.Stats(FN)
+#S.sort_stats('time').print_stats(20)
+s = S.sort_stats('cumulative').print_stats(30)
+
+print s
+"""
Index: unk/anuga_core/source/anuga/structures/inlet_operator_test1.lic
===================================================================
--- /trunk/anuga_core/source/anuga/structures/inlet_operator_test1.lic	(revision 9439)
+++ 	(revision )
@@ -1,17 +1,0 @@
-<?xml version='1.0' encoding='iso-8859-1'?>
-<ga_license_file>
-  <metadata>
-    <author>Stephen Roberts</author>
-  </metadata>
-  <datafile>
-    <filename>inlet_operator_test1.tms</filename>
-    <checksum>2626649089</checksum>
-    <publishable>Yes</publishable>
-    <accountable>Stephen Roberts</accountable>
-    <source>Australian National University</source>
-    <IP_owner>Australian National University</IP_owner>
-    <IP_info>A very simple time series I made up to test inlet_operator
-    </IP_info>
-  </datafile>
-
-</ga_license_file>
Index: unk/anuga_core/source/anuga/structures/inlet_operator_test2.lic
===================================================================
--- /trunk/anuga_core/source/anuga/structures/inlet_operator_test2.lic	(revision 9439)
+++ 	(revision )
@@ -1,17 +1,0 @@
-<?xml version='1.0' encoding='iso-8859-1'?>
-<ga_license_file>
-  <metadata>
-    <author>Stephen Roberts</author>
-  </metadata>
-  <datafile>
-    <filename>inlet_operator_test2.tms</filename>
-    <checksum>4136545855</checksum>
-    <publishable>Yes</publishable>
-    <accountable>Stephen Roberts</accountable>
-    <source>Australian National University</source>
-    <IP_owner>Australian National University</IP_owner>
-    <IP_info>A very simple time series I made up to test inlet_operator
-    </IP_info>
-  </datafile>
-
-</ga_license_file>
Index: unk/anuga_core/source/anuga/structures/run_culvert.py
===================================================================
--- /trunk/anuga_core/source/anuga/structures/run_culvert.py	(revision 9439)
+++ 	(revision )
@@ -1,162 +1,0 @@
-import os.path
-import sys
-
-from anuga.utilities.system_tools import get_pathname_from_package
-from anuga.geometry.polygon_function import Polygon_function
-        
-from anuga.abstract_2d_finite_volumes.mesh_factory import rectangular_cross
-from anuga.abstract_2d_finite_volumes.quantity import Quantity
-
-import anuga
-
-from anuga.structures.boyd_pipe_operator import Boyd_pipe_operator
-from anuga.structures.inlet_operator import Inlet_operator
-                            
-#from anuga.culvert_flows.culvert_routines import boyd_generalised_culvert_model
-     
-from math import pi, pow, sqrt
-
-import numpy as num
-
-
-
-
-
-"""test_that_culvert_runs_rating
-
-This test exercises the culvert and checks values outside rating curve
-are dealt with       
-"""
-
-path = get_pathname_from_package('anuga.culvert_flows')    
-
-length = 40.
-width = 15.
-
-dx = dy = 0.5          # Resolution: Length of subdivisions on both axes
-
-points, vertices, boundary = rectangular_cross(int(length/dx),
-                                               int(width/dy),
-                                               len1=length, 
-                                               len2=width)
-domain = anuga.Domain(points, vertices, boundary)   
-domain.set_starttime(10)
-domain.set_name()                 # Output name
-domain.set_default_order(2)
-#domain.set_beta(1.5)
-
-
-#----------------------------------------------------------------------
-# Setup initial conditions
-#----------------------------------------------------------------------
-
-def topography(x, y):
-    """Set up a weir
-    
-    A culvert will connect either side
-    """
-    # General Slope of Topography
-    z=-x/1000
-    
-    N = len(x)
-    for i in range(N):
-
-       # Sloping Embankment Across Channel
-        if 5.0 < x[i] < 10.1:
-            # Cut Out Segment for Culvert face                
-            if  1.0+(x[i]-5.0)/5.0 <  y[i]  < 4.0 - (x[i]-5.0)/5.0: 
-               z[i]=z[i]
-            else:
-               z[i] +=  0.5*(x[i] -5.0)    # Sloping Segment  U/S Face
-        if 10.0 < x[i] < 12.1:
-           z[i] +=  2.5                    # Flat Crest of Embankment
-        if 12.0 < x[i] < 14.5:
-            # Cut Out Segment for Culvert face                
-            if  2.0-(x[i]-12.0)/2.5 <  y[i]  < 3.0 + (x[i]-12.0)/2.5:
-               z[i]=z[i]
-            else:
-               z[i] +=  2.5-1.0*(x[i] -12.0) # Sloping D/S Face
-                   
-        
-    return z
-
-
-domain.set_quantity('elevation', topography) 
-domain.set_quantity('friction', 0.01)         # Constant friction 
-domain.set_quantity('stage',
-                    expression='elevation')   # Dry initial condition
-
-filename=os.path.join(path, 'example_rating_curve.csv')
-
-end_point0 = num.array([9.0, 2.5])
-end_point1 = num.array([13.0, 2.5])
-
-Boyd_pipe_operator(domain,
-                    #end_point0=[9.0, 2.5],
-                    #end_point1=[13.0, 2.5],
-                    #exchange_line0=[[9.0, 1.75],[9.0, 3.25]],
-                    #exchange_line1=[[13.0, 1.75],[13.0, 3.25]],
-                    losses=1.5,
-                    end_points=[end_point0, end_point1],
-                    diameter=1.5,
-                    apron=0.5,
-                    use_momentum_jet=True, 
-                    use_velocity_head=False,
-                    manning=0.013,
-                    verbose=False)
-
-
-line = [[0.0, 5.0], [0.0, 10.0]]
-Q = 5.0
-#Inlet_operator(domain, line, Q)
-
-
-
-
-##-----------------------------------------------------------------------
-## Setup boundary conditions
-##-----------------------------------------------------------------------
-
-## Inflow based on Flow Depth and Approaching Momentum
-Bi = anuga.Dirichlet_boundary([2.0, 0.0, 0.0])
-Br = anuga.Reflective_boundary(domain)              # Solid reflective wall
-#Bo = anuga.Dirichlet_boundary([-5, 0, 0])           # Outflow
-
-## Upstream and downstream conditions that will exceed the rating curve
-## I.e produce delta_h outside the range [0, 10] specified in the the 
-## file example_rating_curve.csv
-#Btus = anuga.Time_boundary(domain, \
-            #lambda t: [100*num.sin(2*pi*(t-4)/10), 0.0, 0.0])
-#Btds = anuga.Time_boundary(domain, \
-            #lambda t: [-5*(num.cos(2*pi*(t-4)/20)), 0.0, 0.0])
-#domain.set_boundary({'left': Btus, 'right': Btds, 'top': Br, 'bottom': Br})
-domain.set_boundary({'left': Bi, 'right': Br, 'top': Br, 'bottom': Br})
-
-
-##-----------------------------------------------------------------------
-## Evolve system through time
-##-----------------------------------------------------------------------
-
-#min_delta_w = sys.maxint 
-#max_delta_w = -min_delta_w
-for t in domain.evolve(yieldstep=1.0, finaltime=50.0):
-    domain.write_time()
-
-    #if domain.get_time() > 150.5 and domain.ge t_time() < 151.5 :
-        #Bi = anuga.Dirichlet_boundary([0.0, 0.0, 0.0])
-        #domain.set_boundary({'left': Bi, 'right': Br, 'top': Br, 'bottom': Br})
-
-    #delta_w = culvert.inlet.stage - culvert.outlet.stage
-    
-    #if delta_w > max_delta_w: max_delta_w = delta_w
-    #if delta_w < min_delta_w: min_delta_w = delta_w            
-    
-    pass
-
-## Check that extreme values in rating curve have been exceeded
-## so that we know that condition has been exercised
-#assert min_delta_w < 0
-#assert max_delta_w > 10        
-
-
-#os.remove('Test_culvert.sww')
Index: unk/anuga_core/source/anuga/structures/run_culvert_inlet.py
===================================================================
--- /trunk/anuga_core/source/anuga/structures/run_culvert_inlet.py	(revision 9439)
+++ 	(revision )
@@ -1,158 +1,0 @@
-import os.path
-import sys
-
-from anuga.utilities.system_tools import get_pathname_from_package
-from anuga.geometry.polygon_function import Polygon_function
-        
-from anuga.abstract_2d_finite_volumes.mesh_factory import rectangular_cross
-from anuga.abstract_2d_finite_volumes.quantity import Quantity
-
-import anuga
-
-from anuga.structures.boyd_pipe_operator import Boyd_pipe_operator
-from anuga.structures.inlet_operator import Inlet_operator
-                            
-#from anuga.culvert_flows.culvert_routines import boyd_generalised_culvert_model
-     
-from math import pi, pow, sqrt
-
-import numpy as num
-
-
-
-
-
-"""test_that_culvert_runs_rating
-
-This test exercises the culvert and checks values outside rating curve
-are dealt with       
-"""
-
-path = get_pathname_from_package('anuga.culvert_flows')    
-
-length = 40.
-width = 15.
-
-dx = dy = 0.5          # Resolution: Length of subdivisions on both axes
-
-points, vertices, boundary = rectangular_cross(int(length/dx),
-                                               int(width/dy),
-                                               len1=length, 
-                                               len2=width)
-domain = anuga.Domain(points, vertices, boundary)   
-domain.set_name('run_culvert_inlet')                 # Output name
-domain.set_default_order(2)
-#domain.set_beta(1.5)
-
-
-#----------------------------------------------------------------------
-# Setup initial conditions
-#----------------------------------------------------------------------
-
-def topography(x, y):
-    """Set up a weir
-    
-    A culvert will connect either side
-    """
-    # General Slope of Topography
-    z=-x/1000
-    
-    N = len(x)
-    for i in range(N):
-
-       # Sloping Embankment Across Channel
-        if 5.0 < x[i] < 10.1:
-            # Cut Out Segment for Culvert face                
-            if  1.0+(x[i]-5.0)/5.0 <  y[i]  < 4.0 - (x[i]-5.0)/5.0: 
-               z[i]=z[i]
-            else:
-               z[i] +=  0.5*(x[i] -5.0)    # Sloping Segment  U/S Face
-        if 10.0 < x[i] < 12.1:
-           z[i] +=  2.5                    # Flat Crest of Embankment
-        if 12.0 < x[i] < 14.5:
-            # Cut Out Segment for Culvert face                
-            if  2.0-(x[i]-12.0)/2.5 <  y[i]  < 3.0 + (x[i]-12.0)/2.5:
-               z[i]=z[i]
-            else:
-               z[i] +=  2.5-1.0*(x[i] -12.0) # Sloping D/S Face
-                   
-        
-    return z
-
-
-domain.set_quantity('elevation', topography) 
-domain.set_quantity('friction', 0.01)         # Constant friction 
-domain.set_quantity('stage',
-                    expression='elevation')   # Dry initial condition
-
-filename=os.path.join(path, 'example_rating_curve.csv')
-
-
-
-Boyd_pipe_operator(domain,
-                            end_points=[[9.0, 2.5],[13.0, 2.5]],
-                            losses=1.5,
-                            diameter=1.5,
-                            apron=5.0,
-                            use_momentum_jet=True,
-                            use_velocity_head=False,
-                            manning=0.013,
-                            verbose=False)
-
-
-line = [[0.0, 5.0], [0.0, 10.0]]
-Q = 5.0
-Inlet_operator(domain, line, Q)
-
-
-
-
-##-----------------------------------------------------------------------
-## Setup boundary conditions
-##-----------------------------------------------------------------------
-
-## Inflow based on Flow Depth and Approaching Momentum
-Bi = anuga.Dirichlet_boundary([2.0, 0.0, 0.0])
-Br = anuga.Reflective_boundary(domain)              # Solid reflective wall
-#Bo = anuga.Dirichlet_boundary([-5, 0, 0])           # Outflow
-
-## Upstream and downstream conditions that will exceed the rating curve
-## I.e produce delta_h outside the range [0, 10] specified in the the 
-## file example_rating_curve.csv
-#Btus = anuga.Time_boundary(domain, \
-            #lambda t: [100*num.sin(2*pi*(t-4)/10), 0.0, 0.0])
-#Btds = anuga.Time_boundary(domain, \
-            #lambda t: [-5*(num.cos(2*pi*(t-4)/20)), 0.0, 0.0])
-#domain.set_boundary({'left': Btus, 'right': Btds, 'top': Br, 'bottom': Br})
-domain.set_boundary({'left': Br, 'right': Br, 'top': Br, 'bottom': Br})
-
-
-##-----------------------------------------------------------------------
-## Evolve system through time
-##-----------------------------------------------------------------------
-
-#min_delta_w = sys.maxint 
-#max_delta_w = -min_delta_w
-for t in domain.evolve(yieldstep = 1.0, finaltime = 200):
-    domain.write_time()
-
-    #if domain.get_time() > 150.5 and domain.get_time() < 151.5 :
-        #Bi = anuga.Dirichlet_boundary([0.0, 0.0, 0.0])
-        #domain.set_boundary({'left': Bi, 'right': Br, 'top': Br, 'bottom': Br})
-
-    #delta_w = culvert.inlet.stage - culvert.outlet.stage
-    
-    #if delta_w > max_delta_w: max_delta_w = delta_w
-    #if delta_w < min_delta_w: min_delta_w = delta_w
-
-    print domain.volumetric_balance_statistics()
-    
-    pass
-
-## Check that extreme values in rating curve have been exceeded
-## so that we know that condition has been exercised
-#assert min_delta_w < 0
-#assert max_delta_w > 10        
-
-
-#os.remove('Test_culvert.sww')
Index: unk/anuga_core/source/anuga/structures/run_gate_operator.py
===================================================================
--- /trunk/anuga_core/source/anuga/structures/run_gate_operator.py	(revision 9439)
+++ 	(revision )
@@ -1,146 +1,0 @@
-import os.path
-import sys
-
-from anuga.utilities.system_tools import get_pathname_from_package
-from anuga.geometry.polygon_function import Polygon_function
-        
-from anuga.abstract_2d_finite_volumes.mesh_factory import rectangular_cross
-from anuga.abstract_2d_finite_volumes.quantity import Quantity
-
-import anuga
-
-from anuga.structures.boyd_box_operator import Boyd_box_operator
-from anuga.structures.inlet_operator import Inlet_operator
-                            
-#from anuga.culvert_flows.culvert_routines import boyd_generalised_culvert_model
-     
-from math import pi, pow, sqrt
-
-import numpy as num
-
-
-
-
-
-"""test_that_culvert_runs_rating
-
-This test exercises the culvert and checks values outside rating curve
-are dealt with       
-"""
-
-path = get_pathname_from_package('anuga.culvert_flows')    
-
-length = 40.
-width = 15.
-
-dx = dy = 0.5          # Resolution: Length of subdivisions on both axes
-
-points, vertices, boundary = rectangular_cross(int(length/dx),
-                                               int(width/dy),
-                                               len1=length, 
-                                               len2=width)
-domain = anuga.Domain(points, vertices, boundary)   
-domain.set_name('run_gate_operator')                 # Output name
-domain.set_default_order(2)
-#domain.set_beta(1.5)
-
-
-#----------------------------------------------------------------------
-# Setup initial conditions
-#----------------------------------------------------------------------
-
-def topography(x, y):
-    """Set up a weir
-    
-    A culvert will connect either side
-    """
-    # General Slope of Topography
-    z=-x/1000
-    
-    N = len(x)
-    for i in range(N):
-
-       # Sloping Embankment Across Channel
-        if 5.0 < x[i] < 10.1:
-            # Cut Out Segment for Culvert face                
-            if  1.0+(x[i]-5.0)/5.0 <  y[i]  < 4.0 - (x[i]-5.0)/5.0: 
-               z[i]=z[i]
-            else:
-               z[i] +=  0.5*(x[i] -5.0)    # Sloping Segment  U/S Face
-        if 10.0 < x[i] < 12.1:
-           z[i] +=  2.5                    # Flat Crest of Embankment
-        if 12.0 < x[i] < 14.5:
-            # Cut Out Segment for Culvert face                
-            if  2.0-(x[i]-12.0)/2.5 <  y[i]  < 3.0 + (x[i]-12.0)/2.5:
-               z[i]=z[i]
-            else:
-               z[i] +=  2.5-1.0*(x[i] -12.0) # Sloping D/S Face
-                   
-        
-    return z
-
-
-domain.set_quantity('elevation', topography) 
-domain.set_quantity('friction', 0.01)         # Constant friction 
-domain.set_quantity('stage',
-                    expression='elevation')   # Dry initial condition
-
-filename=os.path.join(path, 'example_rating_curve.csv')
-
-
-gate = Boyd_box_operator(domain,
-                            end_points=[[9.0, 2.5],[13.0, 2.5]],
-                            losses=1.5,
-                            width=1.5,
-                            height = 10.0,
-                            apron=5.0,
-                            use_momentum_jet=True,
-                            use_velocity_head=False,
-                            manning=0.013,
-                            verbose=False)
-
-line = [[0.0, 5.0], [0.0, 10.0]]
-Q = 1.0
-Inlet_operator(domain, line, Q)
-
-
-
-
-##-----------------------------------------------------------------------
-## Setup boundary conditions
-##-----------------------------------------------------------------------
-
-## Inflow based on Flow Depth and Approaching Momentum
-Br = anuga.Reflective_boundary(domain)              # Solid reflective wall
-
-domain.set_boundary({'left': Br, 'right': Br, 'top': Br, 'bottom': Br})
-
-
-##-----------------------------------------------------------------------
-## Evolve system through time
-##-----------------------------------------------------------------------
-
-#min_delta_w = sys.maxint 
-#max_delta_w = -min_delta_w
-for t in domain.evolve(yieldstep = 1.0, finaltime = 50):
-    domain.write_time()
-
-    if num.allclose(t, 10.0):
-        gate.set_culvert_height(0.0)
-
-    Q, velocity, depth = gate.discharge_routine()
-
-    print gate.inlets[0].get_enquiry_stage()
-    print gate.inlets[1].get_enquiry_stage()
-    print gate.get_culvert_height()
-
-    print Q
-    print velocity
-    print depth
-        
-    gate.print_timestepping_statistics()
-    
-
-
-
-
Index: unk/anuga_core/source/anuga/structures/run_inlet_operator.py
===================================================================
--- /trunk/anuga_core/source/anuga/structures/run_inlet_operator.py	(revision 9439)
+++ 	(revision )
@@ -1,168 +1,0 @@
-import os.path
-import sys
-
-from anuga.utilities.system_tools import get_pathname_from_package
-from anuga.geometry.polygon_function import Polygon_function
-        
-from anuga.abstract_2d_finite_volumes.mesh_factory import rectangular_cross
-from anuga.abstract_2d_finite_volumes.quantity import Quantity
-from anuga.abstract_2d_finite_volumes.util import file_function
-
-import anuga
-
-from anuga.structures.boyd_box_operator import Boyd_box_operator
-from anuga.structures.inlet_operator import Inlet_operator
-                            
-#from anuga.culvert_flows.culvert_routines import boyd_generalised_culvert_model
-     
-from math import pi, pow, sqrt
-
-import numpy as num
-
-
-
-
-
-"""test_that_culvert_runs_rating
-
-This test exercises the culvert and checks values outside rating curve
-are dealt with       
-"""
-
-path = get_pathname_from_package('anuga.culvert_flows')    
-
-length = 40.
-width = 15.
-
-dx = dy = 0.5          # Resolution: Length of subdivisions on both axes
-
-points, vertices, boundary = rectangular_cross(int(length/dx),
-                                               int(width/dy),
-                                               len1=length, 
-                                               len2=width)
-domain = anuga.Domain(points, vertices, boundary)   
-domain.set_name('Testing_inlet_operator')                 # Output name
-domain.set_default_order(2)
-#domain.set_beta(1.5)
-
-
-#----------------------------------------------------------------------
-# Setup initial conditions
-#----------------------------------------------------------------------
-
-def topography(x, y):
-    """Set up a weir
-    
-    A culvert will connect either side
-    """
-    # General Slope of Topography
-    z=-x/1000
-    
-    N = len(x)
-    for i in range(N):
-
-       # Sloping Embankment Across Channel
-        if 5.0 < x[i] < 10.1:
-            # Cut Out Segment for Culvert face                
-            if  1.0+(x[i]-5.0)/5.0 <  y[i]  < 4.0 - (x[i]-5.0)/5.0: 
-               z[i]=z[i]
-            else:
-               z[i] +=  0.5*(x[i] -5.0)    # Sloping Segment  U/S Face
-        if 10.0 < x[i] < 12.1:
-           z[i] +=  2.5                    # Flat Crest of Embankment
-        if 12.0 < x[i] < 14.5:
-            # Cut Out Segment for Culvert face                
-            if  2.0-(x[i]-12.0)/2.5 <  y[i]  < 3.0 + (x[i]-12.0)/2.5:
-               z[i]=z[i]
-            else:
-               z[i] +=  2.5-1.0*(x[i] -12.0) # Sloping D/S Face
-                   
-        
-    return z
-
-
-domain.set_quantity('elevation', topography) 
-domain.set_quantity('friction', 0.01)         # Constant friction 
-domain.set_quantity('stage',
-                    expression='elevation')   # Dry initial condition
-
-filename=os.path.join(path, 'example_rating_curve.csv')
-
-
-
-#Boyd_box_operator(domain,
-#                            end_points=[[9.0, 2.5],[13.0, 2.5]],
-#                            losses=1.5,
-#                            width=1.5,
-#                            apron=5.0,
-#                            use_momentum_jet=True,
-#                            use_velocity_head=False,
-#                            manning=0.013,
-#                            verbose=False)
-
-
-line0 = [[0.0, 5.0], [0.0, 10.0]]
-
-
-Q = file_function('test_hydrograph.tms', quantities=['hydrograph'])
-
-#inlet0 = Inlet_operator(domain, line0, Q, label='first inlet')
-
-
-line1 = [[1.0, 5.0], [2.0, 10.0]]
-poly1 = [[1.0, 5.0], [2.0, 5.0], [2.0, 10.0], [1.0, 10.0]]
-inlet1 = Inlet_operator(domain, poly1, 2.0)
-
-
-
-##-----------------------------------------------------------------------
-## Setup boundary conditions
-##-----------------------------------------------------------------------
-
-## Inflow based on Flow Depth and Approaching Momentum
-Bi = anuga.Dirichlet_boundary([2.0, 0.0, 0.0])
-Br = anuga.Reflective_boundary(domain)              # Solid reflective wall
-#Bo = anuga.Dirichlet_boundary([-5, 0, 0])           # Outflow
-
-## Upstream and downstream conditions that will exceed the rating curve
-## I.e produce delta_h outside the range [0, 10] specified in the the 
-## file example_rating_curve.csv
-#Btus = anuga.Time_boundary(domain, \
-            #lambda t: [100*num.sin(2*pi*(t-4)/10), 0.0, 0.0])
-#Btds = anuga.Time_boundary(domain, \
-            #lambda t: [-5*(num.cos(2*pi*(t-4)/20)), 0.0, 0.0])
-#domain.set_boundary({'left': Btus, 'right': Btds, 'top': Br, 'bottom': Br})
-domain.set_boundary({'left': Br, 'right': Br, 'top': Br, 'bottom': Br})
-
-
-##-----------------------------------------------------------------------
-## Evolve system through time
-##-----------------------------------------------------------------------
-
-#min_delta_w = sys.maxint 
-#max_delta_w = -min_delta_w
-for t in domain.evolve(yieldstep = 1.0, finaltime = 38):
-    domain.write_time()
-
-    #if domain.get_time() > 150.5 and domain.get_time() < 151.5 :
-        #Bi = anuga.Dirichlet_boundary([0.0, 0.0, 0.0])
-        #domain.set_boundary({'left': Bi, 'right': Br, 'top': Br, 'bottom': Br})
-
-    #delta_w = culvert.inlet.stage - culvert.outlet.stage
-    
-    #if delta_w > max_delta_w: max_delta_w = delta_w
-    #if delta_w < min_delta_w: min_delta_w = delta_w
-
-    print domain.volumetric_balance_statistics()
-
-    #inlet0.print_timestepping_statistics()
-    inlet1.print_timestepping_statistics()
-    pass
-
-## Check that extreme values in rating curve have been exceeded
-## so that we know that condition has been exercised
-#assert min_delta_w < 0
-#assert max_delta_w > 10        
-
-
-#os.remove('Test_culvert.sww')
Index: unk/anuga_core/source/anuga/structures/run_open_slot_wide_bridge.py
===================================================================
--- /trunk/anuga_core/source/anuga/structures/run_open_slot_wide_bridge.py	(revision 9439)
+++ 	(revision )
@@ -1,191 +1,0 @@
-""" Testing CULVERT (Changing from Horizontal Abstraction to Vertical Abstraction
-
-This example includes a Model Topography that shows a TYPICAL Headwall Configuration
-
-The aim is to change the Culvert Routine to Model more precisely the abstraction
-from a vertical face.
-
-The inflow must include the impact of Approach velocity.
-Similarly the Outflow has MOMENTUM Not just Up welling as in the Horizontal Style
-abstraction
-
-"""
-print 'Starting.... Importing Modules...'
-#------------------------------------------------------------------------------
-# Import necessary modules
-#------------------------------------------------------------------------------
-import anuga
-
-from anuga.abstract_2d_finite_volumes.mesh_factory import rectangular_cross
-from anuga.shallow_water.shallow_water_domain import Domain
-from anuga.shallow_water.forcing import Rainfall, Inflow
-#from anuga.shallow_water.forcing import Reflective_boundary
-#from anuga.shallow_water.forcing import Dirichlet_boundary
-#from anuga.shallow_water.forcing import Transmissive_boundary, Time_boundary
-
-from anuga.culvert_flows.culvert_class import Culvert_flow
-from anuga.culvert_flows.culvert_routines import boyd_generalised_culvert_model
-#from anuga.culvert_flows.culvert_routines import weir_orifice_channel_culvert_model
-from math import pi,pow,sqrt
-
-import numpy as num
-
-
-#------------------------------------------------------------------------------
-# Setup computational domain
-#------------------------------------------------------------------------------
-print 'Setting up domain'
-
-length = 200. #x-Dir
-width = 200.  #y-dir
-
-dx = dy = 2.5          # Resolution: Length of subdivisions on both axes
-#dx = dy = .5           # Resolution: Length of subdivisions on both axes
-#dx = dy = .5           # Resolution: Length of subdivisions on both axes
-#dx = dy = .1           # Resolution: Length of subdivisions on both axes
-
-points, vertices, boundary = rectangular_cross(int(length/dx), int(width/dy),
-                                               len1=length, len2=width)
-domain = Domain(points, vertices, boundary)   
-domain.set_name('Test_Open_slot_WIDE_BRIDGE')                 # Output name
-domain.set_default_order(2)
-domain.H0 = 0.01
-domain.tight_slope_limiters = 1
-
-print 'Size', len(domain)
-
-#------------------------------------------------------------------------------
-# Setup initial conditions
-#------------------------------------------------------------------------------
-
-def topography(x, y):
-    """Set up a weir
-    
-    A culvert will connect either side
-    """
-    # General Slope of Topography
-    z=10.0-x/100.0  # % Longitudinal Slope
-    
-    #       NOW Add bits and Pieces to topography
-    bank_hgt=10.0
-    bridge_width = 50.0
-    bank_width = 10.0
-    
-    us_apron_skew = 1.0 # 1.0 = 1 Length: 1 Width, 2.0 = 2 Length : 1 Width
-    us_start_x = 10.0
-    top_start_y = 50.0
-    us_slope = 3.0  #Horiz : Vertic
-    ds_slope = 3.0
-    ds_apron_skew = 1.0 # 1.0 = 1 Length: 1 Width, 2.0 = 2 Length : 1 Width
-    centre_line_y= top_start_y+bridge_width/2.0
-
-    # CALCULATE PARAMETERS TO FORM THE EMBANKMENT
-    us_slope_length = bank_hgt*us_slope
-    us_end_x =us_start_x + us_slope_length
-    us_toe_start_y =top_start_y - us_slope_length / us_apron_skew
-    us_toe_end_y = top_start_y + bridge_width + us_slope_length / us_apron_skew
-
-    top_end_y = top_start_y + bridge_width
-    ds_slope_length = bank_hgt*ds_slope
-    ds_start_x = us_end_x + bank_width
-    ds_end_x = ds_start_x + ds_slope_length
-
-    ds_toe_start_y =top_start_y - ds_slope_length / ds_apron_skew
-    ds_toe_end_y = top_start_y + bridge_width + ds_slope_length / ds_apron_skew
-
-
-    N = len(x)
-    for i in range(N):
-
-       # Sloping Embankment Across Channel
-        if us_start_x < x[i] < us_end_x +0.1:   # For UPSLOPE on the Upstream FACE
-        #if 5.0 < x[i] < 10.1: # For a Range of X, and over a Range of Y based on X adjust Z
-            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:
-			#if  49.0+(x[i]-5.0)/5.0 <  y[i]  < 151.0 - (x[i]-5.0)/5.0: # Cut Out Base Segment for Culvert FACE
-               z[i]=z[i] # Flat Apron
-            else:
-               z[i] += z[i] + (x[i] - us_start_x)/us_slope    # Set elevation for Sloping Segment  U/S Face
-        if us_end_x < x[i] < ds_start_x + 0.1: # FOR The TOP of BANK Segment
-           if top_start_y < y[i] < top_end_y:
-               z[i]=z[i] # Flat Apron
-           else:
-               z[i] +=  z[i]+bank_hgt        # Flat Crest of Embankment
-        if ds_start_x < x[i] < ds_end_x: # DOWN SDLOPE Segment on Downstream face
-            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
-               z[i]=z[i] # Flat Apron
-            else:
-               z[i] += z[i]+bank_hgt-(x[i] -ds_start_x)/ds_slope       # Sloping D/S Face
-           
-        
-
-    return z
-
-print 'Setting Quantities....'
-domain.set_quantity('elevation', topography)  # Use function for elevation
-domain.set_quantity('friction', 0.01)         # Constant friction 
-domain.set_quantity('stage',
-                    expression='elevation')   # Dry initial condition
-
-
-
-
-#------------------------------------------------------------------------------
-# Setup specialised forcing terms
-#------------------------------------------------------------------------------
-
-#------------------------------------------------------------------------------
-# Setup CULVERT INLETS and OUTLETS in Current Topography
-#------------------------------------------------------------------------------
-print 'DEFINING any Structures if Required'
-
-#  DEFINE CULVERT INLET AND OUTLETS
-
-"""
-culvert_rating = Culvert_flow(domain,
-                       culvert_description_filename='example_rating_curve.csv',
-                       end_point0=[40.0, 75.0], 
-                       end_point1=[50.0, 75.0],
-                       verbose=True)
-
-
-culvert_energy = Culvert_flow(domain,
-                       label='Culvert No. 1',
-                       description='This culvert is a test unit 1.2m Wide by 0.75m High',   
-                       end_point0=[40.0, 75.0], 
-                       end_point1=[50.0, 75.0],
-                       width=50.0,depth=5.0,
-                       culvert_routine=boyd_generalised_culvert_model,        
-                       number_of_barrels=1,
-                       #update_interval=0.25,
-                       log_file=True,
-                       discharge_hydrograph=True,
-                       use_velocity_head=False,
-                       verbose=True)
-
-domain.forcing_terms.append(culvert_energy)
-"""
-
-#------------------------------------------------------------------------------
-# Setup boundary conditions
-#------------------------------------------------------------------------------
-print 'Setting Boundary Conditions'
-Br = anuga.Reflective_boundary(domain)              # Solid reflective wall
-Bi = anuga.Dirichlet_boundary([0.0, 0.0, 0.0])          # Inflow based on Flow Depth and Approaching Momentum !!!
-
-Bo = anuga.Dirichlet_boundary([-5.0, 0, 0])           # Outflow water at -5.0
-Bd = anuga.Dirichlet_boundary([0,0,0])                # Outflow water at 0.0
-
-#Btus = Time_boundary(domain, lambda t: [0.0+ 1.025*(1+num.sin(2*pi*(t-4)/10)), 0.0, 0.0])
-#Btds = Time_boundary(domain, lambda t: [0.0+ 0.0075*(1+num.sin(2*pi*(t-4)/20)), 0.0, 0.0])
-
-Btus = anuga.Dirichlet_boundary([18.0, 0, 0])           # Outflow water at 5.0
-Btds = anuga.Dirichlet_boundary([0.0, 0, 0])           # Outflow water at 1.0
-domain.set_boundary({'left': Btus, 'right': Btds, 'top': Br, 'bottom': Br})
-
-
-#------------------------------------------------------------------------------
-# Evolve system through time
-#------------------------------------------------------------------------------
-
-for t in domain.evolve(yieldstep = 1, finaltime = 100):
-    print domain.timestepping_statistics()
Index: unk/anuga_core/source/anuga/structures/run_outlet_control.py
===================================================================
--- /trunk/anuga_core/source/anuga/structures/run_outlet_control.py	(revision 9439)
+++ 	(revision )
@@ -1,232 +1,0 @@
-""" Testing CULVERT (Changing from Horizontal Abstraction to Vertical Abstraction
-
-This example includes a Model Topography that shows a TYPICAL Headwall Configuration
-
-The aim is to change the Culvert Routine to Model more precisely the abstraction
-from a vertical face.
-
-The inflow must include the impact of Approach velocity.
-Similarly the Outflow has MOMENTUM Not just Up welling as in the Horizontal Style
-abstraction
-
-"""
-print 'Starting.... Importing Modules...'
-#------------------------------------------------------------------------------
-# Import necessary modules
-#------------------------------------------------------------------------------
-import anuga
-
-from anuga.abstract_2d_finite_volumes.mesh_factory import rectangular_cross
-from anuga.shallow_water.shallow_water_domain import Domain
-from anuga.shallow_water.forcing import Rainfall, Inflow
-#from anuga.shallow_water.forcing import Reflective_boundary
-#from anuga.shallow_water.forcing import Dirichlet_boundary
-#from anuga.shallow_water.forcing import Transmissive_boundary, Time_boundary
-
-#from anuga.culvert_flows.culvert_class import Culvert_flow
-from anuga.structures.boyd_pipe_operator import Boyd_pipe_operator
-from anuga.structures.boyd_box_operator import Boyd_box_operator
-#from anuga.culvert_flows.culvert_routines import weir_orifice_channel_culvert_model
-from math import pi,pow,sqrt
-
-import numpy as num
-
-
-
-
-#------------------------------------------------------------------------------
-# Setup computational domain
-#------------------------------------------------------------------------------
-print 'Setting up domain'
-
-length = 120. #x-Dir
-width = 200.  #y-dir
-
-dx = dy = 2.0          # Resolution: Length of subdivisions on both axes
-#dx = dy = .5           # Resolution: Length of subdivisions on both axes
-#dx = dy = .5           # Resolution: Length of subdivisions on both axes
-#dx = dy = .1           # Resolution: Length of subdivisions on both axes
-
-points, vertices, boundary = rectangular_cross(int(length/dx), int(width/dy),
-                                                    len1=length, len2=width)
-domain = Domain(points, vertices, boundary)   
-domain.set_name('Test_Outlet_Ctrl')                 # Output name
-domain.set_default_order(2)
-domain.H0 = 0.01
-domain.tight_slope_limiters = 1
-
-print 'Size', len(domain)
-
-#------------------------------------------------------------------------------
-# Setup initial conditions
-#------------------------------------------------------------------------------
-
-def topography(x, y):
-    """Set up a weir
-    
-    A culvert will connect either side
-    """
-    # General Slope of Topography
-    z=10.0-x/100.0  # % Longitudinal Slope
-    
-    #       NOW Add bits and Pieces to topography
-    bank_hgt=10.0
-    bridge_width = 50.0
-    bank_width = 10.0
-    
-    us_apron_skew = 1.0 # 1.0 = 1 Length: 1 Width, 2.0 = 2 Length : 1 Width
-    us_start_x = 10.0
-    top_start_y = 50.0
-    us_slope = 3.0  #Horiz : Vertic
-    ds_slope = 3.0
-    ds_apron_skew = 1.0 # 1.0 = 1 Length: 1 Width, 2.0 = 2 Length : 1 Width
-    centre_line_y= top_start_y+bridge_width/2.0
-
-    # CALCULATE PARAMETERS TO FORM THE EMBANKMENT
-    us_slope_length = bank_hgt*us_slope
-    us_end_x =us_start_x + us_slope_length
-    us_toe_start_y =top_start_y - us_slope_length / us_apron_skew
-    us_toe_end_y = top_start_y + bridge_width + us_slope_length / us_apron_skew
-
-    top_end_y = top_start_y + bridge_width
-    ds_slope_length = bank_hgt*ds_slope
-    ds_start_x = us_end_x + bank_width
-    ds_end_x = ds_start_x + ds_slope_length
-
-    ds_toe_start_y =top_start_y - ds_slope_length / ds_apron_skew
-    ds_toe_end_y = top_start_y + bridge_width + ds_slope_length / ds_apron_skew
-
-
-    N = len(x)
-    for i in range(N):
-
-       # Sloping Embankment Across Channel
-        if us_start_x < x[i] < us_end_x +0.1:   # For UPSLOPE on the Upstream FACE
-        #if 5.0 < x[i] < 10.1: # For a Range of X, and over a Range of Y based on X adjust Z
-            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:
-                #if  49.0+(x[i]-5.0)/5.0 <  y[i]  < 151.0 - (x[i]-5.0)/5.0: # Cut Out Base Segment for Culvert FACE
-                 z[i]=z[i] # Flat Apron
-                #z[i] += z[i] + (x[i] - us_start_x)/us_slope
-                #pass
-            else:
-               z[i] += z[i] + (x[i] - us_start_x)/us_slope    # Sloping Segment  U/S Face
-        if us_end_x < x[i] < ds_start_x + 0.1:
-           z[i] +=  z[i]+bank_hgt        # Flat Crest of Embankment
-        if ds_start_x < x[i] < ds_end_x: # DOWN SDLOPE Segment on Downstream face
-            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
-                 z[i]=z[i] # Flat Apron
-                #z[i] += z[i]+bank_hgt-(x[i] -ds_start_x)/ds_slope
-                #pass
-            else:
-               z[i] += z[i]+bank_hgt-(x[i] -ds_start_x)/ds_slope       # Sloping D/S Face
-           
-        
-
-    return z
-
-print 'Setting Quantities....'
-domain.set_quantity('elevation', topography)  # Use function for elevation
-domain.set_quantity('friction', 0.01)         # Constant friction 
-domain.set_quantity('stage',
-                    expression='elevation')   # Dry initial condition
-
-
-
-
-#------------------------------------------------------------------------------
-# Setup specialised forcing terms
-#------------------------------------------------------------------------------
-
-#------------------------------------------------------------------------------
-# Setup CULVERT INLETS and OUTLETS in Current Topography
-#------------------------------------------------------------------------------
-print 'Defining Structures'
-
-#  DEFINE CULVERT INLET AND OUTLETS
-
-
-#culvert0 = Culvert_operator(domain,
-#                            end_point0=[40.0, 75.0],
-#                            end_point1=[50.0, 75.0],
-#                            width=50.0,
-#                            depth=10.0,
-#                            apron=5.0,
-#                            verbose=False)
-
-
-#------------------------------------------------------------------------------
-# Setup culverts
-#------------------------------------------------------------------------------
-
-culverts = []
-number_of_culverts = 2
-for i in range(number_of_culverts):
-    culvert_width = 50.0/number_of_culverts
-    y = 100-i*culvert_width - culvert_width/2.0
-    ep0 = num.array([40.0, y])
-    ep1 = num.array([50.0, y])
-    
-    losses = {'inlet':0.5, 'outlet':1, 'bend':0, 'grate':0, 'pier': 0, 'other': 0}
-#    culverts.append(Boyd_pipe_operator(domain,
-#                            end_point0=ep0,
-#                            end_point1=ep1,
-#                            losses=losses,
-#                            diameter=1.5, #culvert_width, #3.658,
-#                            apron=6.0,
-#                            use_momentum_jet=True,
-#                            use_velocity_head=True,
-#                            manning=0.013,
-#                            logging=True,
-#                            label='culvert',
-#                            verbose=False))
-
-
-
-
-
-    Boyd_box_operator(domain,
-                      losses=losses,
-                      width=culvert_width,
-                      height=10.0,
-                      end_points=[ep0,ep1],
-                      apron=6.0,
-                      manning=0.013,
-                      label='box_culvert',
-                      logging=True,
-                      verbose=False)
-
-#losses = {'inlet':1, 'outlet':1, 'bend':1, 'grate':1, 'pier': 1, 'other': 1}
-#culvert2 = Culvert_operator(domain,
-                            #end_point0=[40.0, 62.5],
-                            #end_point1=[50.0, 62.5],
-                            #losses,
-                            #width=25.0,
-                            #depth=10.0,
-                            #apron=5.0,
-                            #manning=0.013,
-                            #verbose=False)
-
-
-
-#------------------------------------------------------------------------------
-# Setup boundary conditions
-#------------------------------------------------------------------------------
-print 'Setting Boundary Conditions'
-Br = anuga.Reflective_boundary(domain)              # Solid reflective wall
-Bi = anuga.Dirichlet_boundary([0.0, 0.0, 0.0])          # Inflow based on Flow Depth and Approaching Momentum !!!
-
-Btus = anuga.Dirichlet_boundary([20.0, 0, 0])           # Outflow water at 10.0
-Btds = anuga.Dirichlet_boundary([19.0, 0, 0])           # Outflow water at 9.0
-domain.set_boundary({'left': Btus, 'right': Btds, 'top': Br, 'bottom': Br})
-
-
-
-#------------------------------------------------------------------------------
-# Evolve system through time
-#------------------------------------------------------------------------------
-
-for t in domain.evolve(yieldstep = 1, finaltime = 100):
-    print domain.timestepping_statistics()
-
-    domain.print_operator_timestepping_statistics()
-
Index: unk/anuga_core/source/anuga/structures/run_update_special_condition.py
===================================================================
--- /trunk/anuga_core/source/anuga/structures/run_update_special_condition.py	(revision 9439)
+++ 	(revision )
@@ -1,184 +1,0 @@
-import os.path
-import sys
-
-from anuga.utilities.system_tools import get_pathname_from_package
-from anuga.geometry.polygon_function import Polygon_function
-        
-from anuga.abstract_2d_finite_volumes.mesh_factory import rectangular_cross
-from anuga.abstract_2d_finite_volumes.quantity import Quantity
-
-import anuga
-
-from anuga.structures.boyd_pipe_operator import Boyd_pipe_operator
-from anuga.structures.inlet_operator import Inlet_operator
-                            
-#from anuga.culvert_flows.culvert_routines import boyd_generalised_culvert_model
-     
-from math import pi, pow, sqrt
-
-import numpy as num
-
-
-
-
-
-"""test_that_culvert_runs_rating
-
-This test exercises the culvert and checks values outside rating curve
-are dealt with       
-"""
-
-path = get_pathname_from_package('anuga.culvert_flows')    
-
-length = 40.
-width = 15.
-
-dx = dy = 0.5          # Resolution: Length of subdivisions on both axes
-
-points, vertices, boundary = rectangular_cross(int(length/dx),
-                                               int(width/dy),
-                                               len1=length, 
-                                               len2=width)
-domain = anuga.Domain(points, vertices, boundary)   
-domain.set_name('Test_culvert')                 # Output name
-domain.set_default_order(2)
-#domain.set_beta(1.5)
-
-
-#----------------------------------------------------------------------
-# Setup initial conditions
-#----------------------------------------------------------------------
-
-def topography(x, y):
-    """Set up a weir
-    
-    A culvert will connect either side
-    """
-    # General Slope of Topography
-    z=-x/1000
-    
-    N = len(x)
-    for i in range(N):
-
-       # Sloping Embankment Across Channel
-        if 5.0 < x[i] < 10.1:
-            # Cut Out Segment for Culvert face                
-            if  1.0+(x[i]-5.0)/5.0 <  y[i]  < 4.0 - (x[i]-5.0)/5.0: 
-               z[i]=z[i]
-            else:
-               z[i] +=  0.5*(x[i] -5.0)    # Sloping Segment  U/S Face
-        if 10.0 < x[i] < 12.1:
-           z[i] +=  2.5                    # Flat Crest of Embankment
-        if 12.0 < x[i] < 14.5:
-            # Cut Out Segment for Culvert face                
-            if  2.0-(x[i]-12.0)/2.5 <  y[i]  < 3.0 + (x[i]-12.0)/2.5:
-               z[i]=z[i]
-            else:
-               z[i] +=  2.5-1.0*(x[i] -12.0) # Sloping D/S Face
-                   
-        
-    return z
-
-
-line = [[0.01, 5.0], [0.01, 10.0]]
-Q = 50.0
-
-import anuga
-
-inlet = anuga.structures.inlet.Inlet(domain, line)
-
-domain.special_inlet = inlet
-
-def my_update_special_conditions(domain):
-
-    #print 'inside my domain update_special condition'
-
-    domain.special_inlet.set_depths(5.0)
-
-import types
-domain.update_special_conditions = types.MethodType(my_update_special_conditions, domain)
-
-domain.set_quantity('elevation', topography) 
-domain.set_quantity('friction', 0.01)         # Constant friction 
-domain.set_quantity('stage',
-                    expression='elevation')   # Dry initial condition
-
-filename=os.path.join(path, 'example_rating_curve.csv')
-
-
-
-#Boyd_pipe_operator(domain,
-#                            end_point0=[9.0, 2.5],
-#                            end_point1=[13.0, 2.5],
-#                            losses=1.5,
-#                            diameter=1.5,
-#                            apron=5.0,
-#                            use_momentum_jet=True,
-#                            use_velocity_head=False,
-#                            manning=0.013,
-#                            verbose=False)
-
-
-line = [[0.0, 5.0], [0.0, 10.0]]
-Q = 50.0
-#Inlet_operator(domain, line, Q)
-
-
-
-
-
-
-
-##-----------------------------------------------------------------------
-## Setup boundary conditions
-##-----------------------------------------------------------------------
-
-## Inflow based on Flow Depth and Approaching Momentum
-Bi = anuga.Dirichlet_boundary([2.0, 0.0, 0.0])
-Br = anuga.Reflective_boundary(domain)              # Solid reflective wall
-#Bo = anuga.Dirichlet_boundary([-5, 0, 0])           # Outflow
-
-## Upstream and downstream conditions that will exceed the rating curve
-## I.e produce delta_h outside the range [0, 10] specified in the the 
-## file example_rating_curve.csv
-#Btus = anuga.Time_boundary(domain, \
-            #lambda t: [100*num.sin(2*pi*(t-4)/10), 0.0, 0.0])
-#Btds = anuga.Time_boundary(domain, \
-            #lambda t: [-5*(num.cos(2*pi*(t-4)/20)), 0.0, 0.0])
-#domain.set_boundary({'left': Btus, 'right': Btds, 'top': Br, 'bottom': Br})
-domain.set_boundary({'left': Br, 'right': Br, 'top': Br, 'bottom': Br})
-
-
-
-
-##-----------------------------------------------------------------------
-## Evolve system through time
-##-----------------------------------------------------------------------
-
-#min_delta_w = sys.maxint 
-#max_delta_w = -min_delta_w
-for t in domain.evolve(yieldstep = 1.0, finaltime = 30):
-    domain.write_time()
-
-    #if domain.get_time() > 150.5 and domain.get_time() < 151.5 :
-        #Bi = anuga.Dirichlet_boundary([0.0, 0.0, 0.0])
-        #domain.set_boundary({'left': Bi, 'right': Br, 'top': Br, 'bottom': Br})
-
-    #delta_w = culvert.inlet.stage - culvert.outlet.stage
-    
-    #if delta_w > max_delta_w: max_delta_w = delta_w
-    #if delta_w < min_delta_w: min_delta_w = delta_w
-
-    #print domain.volumetric_balance_statistics()
-
-
-
-
-
-## Check that extreme values in rating curve have been exceeded
-## so that we know that condition has been exercised
-#assert min_delta_w < 0
-#assert max_delta_w > 10        
-
-
-#os.remove('Test_culvert.sww')
Index: unk/anuga_core/source/anuga/structures/run_wide_bridge.py
===================================================================
--- /trunk/anuga_core/source/anuga/structures/run_wide_bridge.py	(revision 9439)
+++ 	(revision )
@@ -1,283 +1,0 @@
-""" Testing CULVERT (Changing from Horizontal Abstraction to Vertical Abstraction
-
-This example includes a Model Topography that shows a TYPICAL Headwall Configuration
-
-The aim is to change the Culvert Routine to Model more precisely the abstraction
-from a vertical face.
-
-The inflow must include the impact of Approach velocity.
-Similarly the Outflow has MOMENTUM Not just Up welling as in the Horizontal Style
-abstraction
-
-"""
-print 'Starting.... Importing Modules...'
-#------------------------------------------------------------------------------
-# Import necessary modules
-#------------------------------------------------------------------------------
-import anuga
-
-from anuga.abstract_2d_finite_volumes.mesh_factory import rectangular_cross
-from anuga.shallow_water.shallow_water_domain import Domain
-from anuga.shallow_water.forcing import Rainfall, Inflow
-#from anuga.shallow_water.forcing import Reflective_boundary
-#from anuga.shallow_water.forcing import Dirichlet_boundary
-#from anuga.shallow_water.forcing import Transmissive_boundary, Time_boundary
-
-
-#from anuga.culvert_flows.culvert_routines import weir_orifice_channel_culvert_model
-from math import pi,pow,sqrt
-
-import numpy as num
-
-
-#------------------------------------------------------------------------------
-# Setup computational domain
-#------------------------------------------------------------------------------
-print 'Setting up domain'
-
-length = 200. #x-Dir
-width = 200.  #y-dir
-
-dx = dy = 2.0          # Resolution: Length of subdivisions on both axes
-#dx = dy = .5           # Resolution: Length of subdivisions on both axes
-#dx = dy = .5           # Resolution: Length of subdivisions on both axes
-#dx = dy = .1           # Resolution: Length of subdivisions on both axes
-
-points, vertices, boundary = rectangular_cross(int(length/dx), int(width/dy),
-                                                    len1=length, len2=width)
-domain = Domain(points, vertices, boundary)   
-domain.set_name('Test_WIDE_BRIDGE')                 # Output name
-#domain.set_default_order(2)
-#omain.H0 = 0.01
-#domain.tight_slope_limiters = 1
-
-domain.set_flow_algorithm('2_0')
-
-print 'Size', len(domain)
-
-#------------------------------------------------------------------------------
-# Setup initial conditions
-#------------------------------------------------------------------------------
-
-def topography(x, y):
-    """Set up a weir
-    
-    A culvert will connect either side
-    """
-    # General Slope of Topography
-    z=10.0-x/100.0  # % Longitudinal Slope
-    
-    #       NOW Add bits and Pieces to topography
-    bank_hgt=10.0
-    bridge_width = 50.0
-    bank_width = 10.0
-    
-    us_apron_skew = 1.0 # 1.0 = 1 Length: 1 Width, 2.0 = 2 Length : 1 Width
-    us_start_x = 10.0
-    top_start_y = 50.0
-    us_slope = 3.0  #Horiz : Vertic
-    ds_slope = 3.0
-    ds_apron_skew = 1.0 # 1.0 = 1 Length: 1 Width, 2.0 = 2 Length : 1 Width
-    centre_line_y= top_start_y+bridge_width/2.0
-
-    # CALCULATE PARAMETERS TO FORM THE EMBANKMENT
-    us_slope_length = bank_hgt*us_slope
-    us_end_x =us_start_x + us_slope_length
-    us_toe_start_y =top_start_y - us_slope_length / us_apron_skew
-    us_toe_end_y = top_start_y + bridge_width + us_slope_length / us_apron_skew
-
-    top_end_y = top_start_y + bridge_width
-    ds_slope_length = bank_hgt*ds_slope
-    ds_start_x = us_end_x + bank_width
-    ds_end_x = ds_start_x + ds_slope_length
-
-    ds_toe_start_y =top_start_y - ds_slope_length / ds_apron_skew
-    ds_toe_end_y = top_start_y + bridge_width + ds_slope_length / ds_apron_skew
-
-
-    N = len(x)
-    for i in range(N):
-
-       # Sloping Embankment Across Channel
-        if us_start_x < x[i] < us_end_x +0.1:   # For UPSLOPE on the Upstream FACE
-        #if 5.0 < x[i] < 10.1: # For a Range of X, and over a Range of Y based on X adjust Z
-            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:
-                #if  49.0+(x[i]-5.0)/5.0 <  y[i]  < 151.0 - (x[i]-5.0)/5.0: # Cut Out Base Segment for Culvert FACE
-                 z[i]=z[i] # Flat Apron
-                #z[i] += z[i] + (x[i] - us_start_x)/us_slope
-                #pass
-            else:
-               z[i] += z[i] + (x[i] - us_start_x)/us_slope    # Sloping Segment  U/S Face
-        if us_end_x < x[i] < ds_start_x + 0.1:
-           z[i] +=  z[i]+bank_hgt        # Flat Crest of Embankment
-        if ds_start_x < x[i] < ds_end_x: # DOWN SDLOPE Segment on Downstream face
-            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
-                 z[i]=z[i] # Flat Apron
-                #z[i] += z[i]+bank_hgt-(x[i] -ds_start_x)/ds_slope
-                #pass
-            else:
-               z[i] += z[i]+bank_hgt-(x[i] -ds_start_x)/ds_slope       # Sloping D/S Face
-           
-        
-
-    return z
-
-print 'Setting Quantities....'
-domain.set_quantity('elevation', topography)  # Use function for elevation
-domain.set_quantity('friction', 0.01)         # Constant friction 
-domain.set_quantity('stage',
-                    expression='elevation')   # Dry initial condition
-
-
-
-
-#------------------------------------------------------------------------------
-# Setup specialised forcing terms
-#------------------------------------------------------------------------------
-
-#------------------------------------------------------------------------------
-# Setup CULVERT INLETS and OUTLETS in Current Topography
-#------------------------------------------------------------------------------
-print 'DEFINING any Structures if Required'
-
-#  DEFINE CULVERT INLET AND OUTLETS
-
-"""
-culvert_rating = Culvert_flow(domain,
-    culvert_description_filename='example_rating_curve.csv',
-    end_point0=[0.0, 75.0], 
-    end_point1=[50.0, 75.0],
-    verbose=True)
-
-culvert_energy = Culvert_flow(domain,
-    label='Culvert No. 1',
-    description='This culvert is a test unit 4m diameter',   
-    end_point0=[40.0, 75.0], 
-    end_point1=[50.0, 75.0],
-    width=4.0,
-    culvert_routine=boyd_generalised_culvert_model,  #culvert_routine=weir_orifice_channel_culvert_model,     
-    number_of_barrels=1,
-    number_of_smoothing_steps=10,
-    #update_interval=0.25,
-    log_file=True,
-    discharge_hydrograph=True,
-    use_velocity_head=False,
-    use_momentum_jet=False,
-    verbose=True)
-
-domain.forcing_terms.append(culvert_energy)
-"""
-#from anuga.structures.boyd_box_operator import Boyd_box_operator
-#culvert0 = Culvert_operator(domain,
-#                            end_point0=[40.0, 75.0],
-#                            end_point1=[50.0, 75.0],
-#                            width=50.0,
-#                            depth=10.0,
-#                            apron=5.0,
-#                            verbose=False)
-
-
-#------------------------------------------------------------------------------
-# Setup culverts
-#------------------------------------------------------------------------------
-culverts = []
-number_of_culverts = 1 
-for i in range(number_of_culverts):
-    culvert_width = 50.0/number_of_culverts
-    y = 100-i*culvert_width - culvert_width/2.0
-    ep0 = num.array([37.0, y])
-    ep1 = num.array([53.0, y])
-    culverts.append(anuga.Boyd_box_operator(domain,
-                                            losses=1.5,
-                                            width=3.658,
-                                            height=3.658,
-                                            end_points=[ep0, ep1],
-                                            apron=0.5,
-                                            manning=0.013,
-                                            enquiry_gap=1.0,
-                                            description='bridge culvert',
-                                            verbose=False))
-
-#culvert2 = Culvert_operator(domain,
-#                            end_point0=[40.0, 62.5],
-#                            end_point1=[50.0, 62.5],
-#                            width=25.0,
-#                            depth=10.0,
-#                            apron=5.0,
-#                            manning=0.013,
-#                            verbose=False)
-
-
-
-"""
-culvert_energy = Culvert_flow(domain,
-    label='Culvert No. 1',
-    description='This culvert is a test unit 50m Wide by 5m High',   
-    end_point0=[40.0, 75.0],
-    end_point1=[50.0, 75.0],
-    width=50.0,depth=5.0,
-    culvert_routine=boyd_generalised_culvert_model,  #culvert_routine=weir_orifice_channel_culvert_model,     
-    number_of_barrels=1,
-    number_of_smoothing_steps=10,
-    #update_interval=0.25,
-    log_file=True,
-    discharge_hydrograph=True,
-    use_velocity_head=False,
-    use_momentum_jet=False,
-    verbose=True)
-
-domain.forcing_terms.append(culvert_energy)
-"""
-
-#------------------------------------------------------------------------------
-# Setup boundary conditions
-#------------------------------------------------------------------------------
-print 'Setting Boundary Conditions'
-Br = anuga.Reflective_boundary(domain)              # Solid reflective wall
-Bi = anuga.Dirichlet_boundary([0.0, 0.0, 0.0])          # Inflow based on Flow Depth and Approaching Momentum !!!
-
-Bo = anuga.Dirichlet_boundary([-5.0, 0, 0])           # Outflow water at -5.0
-Bd = anuga.Dirichlet_boundary([0,0,0])                # Outflow water at 0.0
-
-#Btus = Time_boundary(domain, lambda t: [0.0+ 1.025*(1+num.sin(2*pi*(t-4)/10)), 0.0, 0.0])
-#Btds = Time_boundary(domain, lambda t: [0.0+ 0.0075*(1+num.sin(2*pi*(t-4)/20)), 0.0, 0.0])
-
-Btus = anuga.Dirichlet_boundary([20.0, 0, 0])           # Outflow water at 20
-Btds = anuga.Dirichlet_boundary([19.0, 0, 0])           # Outflow water at 19
-domain.set_boundary({'left': Btus, 'right': Br, 'top': Br, 'bottom': Br})
-
-
-#------------------------------------------------------------------------------
-# Evolve system through time
-#------------------------------------------------------------------------------
-
-for t in domain.evolve(yieldstep = 1, finaltime = 100):
-    print domain.timestepping_statistics()
-    print domain.volumetric_balance_statistics()
-    for i, culvert in enumerate(culverts):
-        print 'culvert: ', i
-        print culvert.timestepping_statistics()
-    
-
-    
-"""    
-#import sys; sys.exit() 
-# Profiling code
-import time
-t0 = time.time()
-   
-s = 'for t in domain.evolve(yieldstep = 0.1, finaltime = 300): domain.write_time()'
-
-import profile, pstats
-FN = 'profile.dat'
-
-profile.run(s, FN)
-    
-print 'That took %.2f seconds' %(time.time()-t0)
-
-S = pstats.Stats(FN)
-#S.sort_stats('time').print_stats(20)
-s = S.sort_stats('cumulative').print_stats(30)
-
-print s
-"""
Index: /trunk/anuga_core/source/anuga/structures/test/test_all.py
===================================================================
--- /trunk/anuga_core/source/anuga/structures/test/test_all.py	(revision 9440)
+++ /trunk/anuga_core/source/anuga/structures/test/test_all.py	(revision 9440)
@@ -0,0 +1,83 @@
+"""Regression testing framework
+This module will search for scripts in the same directory named
+test_*.py.  Each such script should be a test suite that tests a
+module through PyUnit. This script will aggregate all
+found test suites into one big test suite and run them all at once.
+"""
+
+# Author: Mark Pilgrim
+# Modified by Ole Nielsen
+
+import unittest
+import os
+
+
+#List files that should be excluded from the testing process.
+#E.g. if they are known to fail and under development
+exclude = [] 
+
+
+def get_test_files(path):
+
+    import sys
+
+    files = os.listdir(path)
+
+    #Check sub directories
+    test_files = []
+    for file in files:
+        if os.path.isdir(file):
+            sys.path.append(file)
+            #print 'Recursing into', file
+            test_files += get_test_files(path + os.sep + file)
+        elif file[:5] == 'test_' and file[-2:] == 'py':
+            #print 'Appending', file
+            test_files.append(file)
+        else:
+            pass
+    return test_files
+
+
+
+def regressionTest():
+    import sys, os, re, unittest
+    path = os.path.split(sys.argv[0])[0] or os.getcwd()
+
+
+    files = get_test_files(path)
+
+
+
+    #test = re.compile('^test_[\w]*.py$', re.IGNORECASE)
+    #files = filter(test.search, files)
+
+
+    try:
+        files.remove(__file__)  #Remove self from list (Ver 2.3. or later)
+    except:
+        files.remove('test_all.py')
+
+    print 'Testing:'
+    for file in files:
+        print '  ' + file
+
+    if globals().has_key('exclude'):
+        for file in exclude:
+            files.remove(file)
+            print 'WARNING: File '+ file + ' excluded from testing'
+
+
+    filenameToModuleName = lambda f: os.path.splitext(f)[0]
+    #print "files",files 
+    moduleNames = map(filenameToModuleName, files)
+    #print "moduleNames",moduleNames
+    modules = map(__import__, moduleNames)
+    load = unittest.defaultTestLoader.loadTestsFromModule
+    return unittest.TestSuite(map(load, modules))
+
+################################################################################
+
+if __name__ == '__main__':   
+    suite = regressionTest()
+    runner = unittest.TextTestRunner() #verbosity=2)
+    runner.run(suite)
Index: /trunk/anuga_core/source/anuga/structures/test/test_boyd_box_operator.py
===================================================================
--- /trunk/anuga_core/source/anuga/structures/test/test_boyd_box_operator.py	(revision 9440)
+++ /trunk/anuga_core/source/anuga/structures/test/test_boyd_box_operator.py	(revision 9440)
@@ -0,0 +1,2623 @@
+#!/usr/bin/env python
+
+
+import unittest
+
+
+from anuga.structures.boyd_box_operator import Boyd_box_operator
+from anuga.structures.boyd_box_operator import boyd_box_function
+
+from anuga.abstract_2d_finite_volumes.mesh_factory import rectangular_cross
+from anuga.shallow_water.shallow_water_domain import Domain
+import numpy
+
+verbose = False
+
+
+class Test_boyd_box_operator(unittest.TestCase):
+    """
+	Test the boyd box operator, in particular the discharge_routine!
+    """
+
+    def setUp(self):
+        pass
+
+    def tearDown(self):
+        pass
+    
+    
+    def _create_domain(self,d_length,
+                            d_width,
+                            dx,
+                            dy,
+                            elevation_0,
+                            elevation_1,
+                            stage_0,
+                            stage_1,
+                            xvelocity_0 = 0.0,
+                            xvelocity_1 = 0.0,
+                            yvelocity_0 = 0.0,
+                            yvelocity_1 = 0.0):
+        
+        points, vertices, boundary = rectangular_cross(int(d_length/dx), int(d_width/dy),
+                                                        len1=d_length, len2=d_width)
+        domain = Domain(points, vertices, boundary)   
+        domain.set_name('Test_Outlet_Inlet')                 # Output name
+        domain.set_store()
+        domain.set_default_order(2)
+        domain.H0 = 0.01
+        domain.tight_slope_limiters = 1
+
+        #print 'Size', len(domain)
+
+        #------------------------------------------------------------------------------
+        # Setup initial conditions
+        #------------------------------------------------------------------------------
+
+        def elevation(x, y):
+            """Set up a elevation
+            """
+            
+            z = numpy.zeros(x.shape,dtype='d')
+            z[:] = elevation_0
+            
+            numpy.putmask(z, x > d_length/2, elevation_1)
+    
+            return z
+            
+        def stage(x,y):
+            """Set up stage
+            """
+            z = numpy.zeros(x.shape,dtype='d')
+            z[:] = stage_0
+            
+            numpy.putmask(z, x > d_length/2, stage_1)
+
+            return z
+        
+        def xmom(x,y):
+            """Set up xmomentum
+            """
+            z = numpy.zeros(x.shape,dtype='d')
+            z[:] = xvelocity_0*(stage_0-elevation_0)
+            
+            numpy.putmask(z, x > d_length/2, xvelocity_1*(stage_1-elevation_1) )
+
+            return z
+        
+        def ymom(x,y):
+            """Set up ymomentum
+            """
+            z = numpy.zeros(x.shape,dtype='d')
+            z[:] = yvelocity_0*(stage_0-elevation_0)
+            
+            numpy.putmask(z, x > d_length/2, yvelocity_1*(stage_1-elevation_1) )
+
+            return z
+            
+        #print 'Setting Quantities....'
+        domain.set_quantity('elevation', elevation)  # Use function for elevation
+        domain.set_quantity('stage',  stage)   # Use function for elevation
+        domain.set_quantity('xmomentum',  xmom) 
+        domain.set_quantity('ymomentum',  ymom) 
+        
+        return domain
+
+    def test_boyd_non_skew(self):
+        """test_boyd_non_skew
+        
+        This tests the Boyd routine with data obtained from culvertw application 1.1 by IceMindserer  BD Parkinson, 
+        calculation code by MJ Boyd 
+        """
+
+        stage_0 = 11.0
+        stage_1 = 10.0
+        elevation_0 = 10.0
+        elevation_1 = 10.0
+
+        domain_length = 200.0
+        domain_width = 200.0
+
+        culvert_length = 20.0
+        culvert_width = 3.66
+        culvert_height = 3.66
+        culvert_losses = {'inlet':0.5, 'outlet':1.0, 'bend':0.0, 'grate':0.0, 'pier': 0.0, 'other': 0.0}
+        culvert_mannings = 0.013
+        
+        culvert_apron = 0.0
+        enquiry_gap = 5.0
+
+        
+        expected_Q = 6.23
+        expected_v = 2.55
+        expected_d = 0.66
+        
+
+        domain = self._create_domain(d_length=domain_length,
+                                     d_width=domain_width,
+                                     dx = 5.0,
+                                     dy = 5.0,
+                                     elevation_0 = elevation_0,
+                                     elevation_1 = elevation_1,
+                                     stage_0 = stage_0,
+                                     stage_1 = stage_1)
+ 
+
+        #print 'Defining Structures'
+        
+        ep0 = numpy.array([domain_length/2-culvert_length/2, 100.0])
+        ep1 = numpy.array([domain_length/2+culvert_length/2, 100.0])
+        
+        
+        culvert = Boyd_box_operator(domain,
+                                    losses=culvert_losses,
+                                    width=culvert_width,
+                                    end_points=[ep0, ep1],
+                                    height=culvert_height,
+                                    apron=culvert_apron,
+                                    enquiry_gap=enquiry_gap,
+                                    use_momentum_jet=False,
+                                    use_velocity_head=False,
+                                    manning=culvert_mannings,
+                                    logging=False,
+                                    label='3.6x3.6RCBC',
+                                    verbose=False)
+
+        #culvert.determine_inflow_outflow()
+        
+        ( Q, v, d ) = culvert.discharge_routine()
+        
+        if verbose:
+            print 'test_boyd_non_skew'
+            print 'Q: ', Q, 'expected_Q: ', expected_Q
+        
+
+        assert numpy.allclose(Q, expected_Q, rtol=1.0e-2) #inflow
+        assert numpy.allclose(v, expected_v, rtol=1.0e-2) #outflow velocity
+        assert numpy.allclose(d, expected_d, rtol=1.0e-2) #depth at outlet used to calc v 
+        
+        
+        
+        
+        
+    
+    def test_boyd_skew(self):
+        """test_boyd_skew
+        
+        This tests the Boyd routine with data obtained from culvertw application 1.1 by IceMindserer  BD Parkinson, 
+        calculation code by MJ Boyd 
+        """
+
+        stage_0 = 11.0
+        stage_1 = 10.0
+        elevation_0 = 10.0
+        elevation_1 = 10.0
+
+        domain_length = 200.0
+        domain_width = 200.0
+
+        culvert_length = 20.0
+        culvert_width = 3.66
+        culvert_height = 3.66
+        culvert_losses = {'inlet':0.5, 'outlet':1.0, 'bend':0.0, 'grate':0.0, 'pier': 0.0, 'other': 0.0}
+        culvert_mannings = 0.013
+        
+        culvert_apron = 0.0
+        enquiry_gap = 5.0
+        
+        expected_Q = 6.23
+        expected_v = 2.55
+        expected_d = 0.66
+        
+
+        domain = self._create_domain(d_length=domain_length,
+                                     d_width=domain_width,
+                                     dx = 5.0,
+                                     dy = 5.0,
+                                     elevation_0 = elevation_0,
+                                     elevation_1 = elevation_1,
+                                     stage_0 = stage_0,
+                                     stage_1 = stage_1)
+
+        #print 'Defining Structures'
+        
+        a = domain_length/2 - culvert_length/2
+        b = domain_length/2 + culvert_length/2
+        
+        el0 = numpy.array([[a, 100.0 - culvert_width/2], [a, 100.0 + culvert_width/2]])
+        el1 = numpy.array([[b, 100.0 - culvert_width/2], [b, 100.0 + culvert_width/2]])
+        
+        culvert = Boyd_box_operator(domain,
+                                    losses=culvert_losses,
+                                    width=culvert_width,
+                                    exchange_lines=[el0, el1],
+                                    height=culvert_height,
+                                    apron=culvert_apron,
+                                    enquiry_gap=enquiry_gap,
+                                    use_momentum_jet=False,
+                                    use_velocity_head=False,
+                                    manning=culvert_mannings,
+                                    label='3.6x3.6RCBC',
+                                    verbose=False)
+
+        #culvert.determine_inflow_outflow()
+        
+        ( Q, v, d ) = culvert.discharge_routine()
+        
+        if verbose:
+            print 'test_boyd_skew'
+            print 'Q: ', Q, 'expected_Q: ', expected_Q
+
+        assert numpy.allclose(Q, expected_Q, rtol=1.0e-2) #inflow
+        assert numpy.allclose(v, expected_v, rtol=1.0e-2) #outflow velocity
+        assert numpy.allclose(d, expected_d, rtol=1.0e-2) #depth at outlet used to calc v         
+
+
+    def test_boyd_non_skew_enquiry_points(self):
+        """test_boyd_skew_enquiry_points
+        
+        This tests the Boyd routine with data obtained from culvertw application 1.1 by IceMindserer  BD Parkinson, 
+        calculation code by MJ Boyd 
+        """
+
+        stage_0 = 11.0
+        stage_1 = 10.0
+        elevation_0 = 10.0
+        elevation_1 = 10.0
+
+        domain_length = 200.0
+        domain_width = 200.0
+
+        culvert_length = 20.0
+        culvert_width = 3.66
+        culvert_height = 3.66
+        culvert_losses = {'inlet':0.5, 'outlet':1.0, 'bend':0.0, 'grate':0.0, 'pier': 0.0, 'other': 0.0}
+        culvert_mannings = 0.013
+        
+        culvert_apron = 0.0
+        enquiry_gap = 5.0
+        
+        expected_Q = 6.23
+        expected_v = 2.55
+        expected_d = 0.66
+        
+
+        # Probably no need to change below here
+        
+        domain = self._create_domain(d_length=domain_length,
+                                     d_width=domain_width,
+                                     dx = 5.0,
+                                     dy = 5.0,
+                                     elevation_0 = elevation_0,
+                                     elevation_1 = elevation_1,
+                                     stage_0 = stage_0,
+                                     stage_1 = stage_1)
+
+
+        #print 'Defining Structures'
+        
+        a = domain_length/2 - culvert_length/2
+        b = domain_length/2 + culvert_length/2
+        
+        el0 = numpy.array([[a, 100.0 - culvert_width/2], [a, 100.0 + culvert_width/2]])
+        el1 = numpy.array([[b, 100.0 - culvert_width/2], [b, 100.0 + culvert_width/2]])
+        
+        enquiry_points = (numpy.array([85, 100]), numpy.array([115, 100]))
+        
+        culvert = Boyd_box_operator(domain,
+                                    losses=culvert_losses,
+                                    width=culvert_width,
+                                    exchange_lines=[el0, el1],
+                                    enquiry_points=enquiry_points,
+                                    height=culvert_height,
+                                    apron=culvert_apron,
+                                    enquiry_gap=enquiry_gap,
+                                    use_momentum_jet=False,
+                                    use_velocity_head=False,
+                                    manning=culvert_mannings,
+                                    label='3.6x3.6RCBC',
+                                    verbose=False)
+
+
+        
+        ( Q, v, d ) = culvert.discharge_routine()
+        
+        if verbose:
+            print 'test_boyd_non_skew_enquiry_points'
+            print 'Q: ', Q, 'expected_Q: ', expected_Q
+            print 'v: ', v, 'expected_v: ', expected_v
+            print 'd: ', d, 'expected_d: ', expected_d
+
+        assert numpy.allclose(Q, expected_Q, rtol=1.0e-2) #inflow
+        assert numpy.allclose(v, expected_v, rtol=1.0e-2) #outflow velocity
+        assert numpy.allclose(d, expected_d, rtol=1.0e-2) #depth at outlet used to calc v         
+
+    def test_boyd_1(self):
+        """test_boyd_1
+        
+        This tests the Boyd routine with data obtained from culvertw application 1.1 by IceMindserer  BD Parkinson, 
+        calculation code by MJ Boyd     
+        """
+
+
+        g=9.81
+
+
+        inlet_depth=0.150
+        outlet_depth=0.15
+        inlet_velocity=1.00
+        outlet_velocity=0.5
+        
+        culvert_length=10.0
+        culvert_width=3.6
+        culvert_height=1.20
+        
+        culvert_type='box'
+        manning=0.013
+        sum_loss=1.5
+
+        inlet_specific_energy=inlet_depth + 0.5*inlet_velocity**2/g 
+        culvert_slope=10.0  # % Downward
+        z_in = 10.0
+        z_out = z_in-culvert_length*culvert_slope/100
+        E_in = z_in+inlet_depth + 0.5*inlet_velocity**2/g
+        E_out = z_out+outlet_depth + 0.5*outlet_velocity**2/g
+        delta_total_energy = E_in-E_out
+        inlet_specific_energy=inlet_depth + 0.5*inlet_velocity**2/g 
+
+
+        if verbose:
+            print 50*'='
+            print 'width ',culvert_width
+            print 'depth ',culvert_height
+            print 'flow_width ',culvert_width
+            print 'length ' ,culvert_length
+            print 'driving_energy ',inlet_specific_energy
+            print 'delta_total_energy ',delta_total_energy
+            print 'outlet_enquiry_depth ',outlet_depth
+            print 'sum_loss ',sum_loss
+            print 'manning ',manning
+
+
+        Q, v, d, flow_area, case= boyd_box_function(culvert_width, 
+                                                    culvert_height, 
+                                                    culvert_width, 
+                                                    culvert_length, 
+                                                    inlet_specific_energy, 
+                                                    delta_total_energy, 
+                                                    outlet_depth, 
+                                                    sum_loss,
+                                                    manning)
+
+
+        if verbose:
+            print ('%s,%.2f,%.2f,%.2f' %('ANUGAcalcsTEST01 Q-v-d',Q,v,d))
+            print('%s,%.2f,%.2f,%.2f' %('Spreadsheet_Boydcalcs', 0.5526, 1.146, 0.1339))
+            
+        assert numpy.allclose(Q, 0.5526, rtol=1.0e-1) #inflow
+        assert numpy.allclose(v, 1.146, rtol=1.0e-1) #outflow velocity
+        assert numpy.allclose(d, 0.1339, rtol=1.0e-1) #depth at outlet used to calc v 
+   
+   
+   
+   
+    def test_boyd_1_operator(self):
+        """test_boyd_non_skew
+        
+        This tests the Boyd routine with data obtained from culvertw application 1.1 by IceMindserer  BD Parkinson, 
+        calculation code by MJ Boyd 
+        """
+
+        g=9.81
+
+
+        inlet_depth=0.150
+        outlet_depth=0.150
+        inlet_velocity=1.00
+        outlet_velocity=0.5
+        
+        culvert_length=10.0
+        culvert_width=3.6
+        culvert_height=1.20
+        
+        culvert_type='box'
+
+        #sum_loss=1.5
+
+        inlet_specific_energy=inlet_depth + 0.5*inlet_velocity**2/g 
+        culvert_slope=10.0  # % Downward
+        z_in = 10.0
+        z_out = z_in-culvert_length*culvert_slope/100
+        E_in = z_in+inlet_depth + 0.5*inlet_velocity**2/g
+        E_out = z_out+outlet_depth + 0.5*outlet_velocity**2/g
+        delta_total_energy = E_in-E_out
+        inlet_specific_energy=inlet_depth + 0.5*inlet_velocity**2/g 
+        
+        
+        elevation_0 = z_in
+        elevation_1 = z_out
+        
+        stage_0 = elevation_0 + inlet_depth
+        stage_1 = elevation_1 + outlet_depth
+ 
+
+        domain_length = 200.0
+        domain_width = 200.0
+
+        #culvert_length = 20.0
+        #culvert_width = 3.66
+        #culvert_height = 3.66
+        culvert_losses = {'inlet':0.5, 'outlet':1.0, 'bend':0.0, 'grate':0.0, 'pier': 0.0, 'other': 0.0}
+        culvert_mannings = 0.013
+        
+        culvert_apron = 0.0
+        enquiry_gap = 5.0
+
+        
+        expected_Q = 0.55
+        expected_v = 1.15
+        expected_d = 0.13
+
+
+        domain = self._create_domain(d_length=domain_length,
+                                     d_width=domain_width,
+                                     dx = 5.0,
+                                     dy = 5.0,
+                                     elevation_0 = elevation_0,
+                                     elevation_1 = elevation_1,
+                                     stage_0 = stage_0,
+                                     stage_1 = stage_1,
+                                     xvelocity_0 = inlet_velocity,
+                                     xvelocity_1 = outlet_velocity)
+ 
+
+        #print 'Defining Structures'
+        
+        ep0 = numpy.array([domain_length/2-culvert_length/2, 100.0])
+        ep1 = numpy.array([domain_length/2+culvert_length/2, 100.0])
+        
+        
+        culvert = Boyd_box_operator(domain,
+                                    losses=culvert_losses,
+                                    width=culvert_width,
+                                    end_points=[ep0, ep1],
+                                    height=culvert_height,
+                                    apron=culvert_apron,
+                                    enquiry_gap=enquiry_gap,
+                                    use_momentum_jet=False,
+                                    use_velocity_head=True,
+                                    manning=culvert_mannings,
+                                    logging=False,
+                                    label='3.6x1.2RCBC',
+                                    verbose=False)
+
+        #culvert.determine_inflow_outflow()
+        
+        ( Q, v, d ) = culvert.discharge_routine()
+        
+        if verbose:
+            print 'test_boyd_operator_1'
+            print 'expected ',expected_Q,expected_v, expected_d
+            print 'calc ',Q,v,d
+        
+
+        assert numpy.allclose(Q, expected_Q, rtol=5.0e-2) #inflow
+        assert numpy.allclose(v, expected_v, rtol=5.0e-2) #outflow velocity
+        assert numpy.allclose(d, expected_d, rtol=5.0e-2) #depth at outlet used to calc v 
+        
+        
+        
+               
+    def test_boyd_2(self):
+        """test_boyd_2
+        
+        This tests the Boyd routine with data obtained from culvertw application 1.1 by IceMindserer  BD Parkinson, 
+        calculation code by MJ Boyd     
+        """
+
+
+        g=9.81
+        culvert_slope=10  # Downward
+
+        inlet_depth=0.500
+        outlet_depth=0.700
+        inlet_velocity=1.0
+        outlet_velocity=0.50
+        
+        culvert_length=10.0
+        culvert_width=3.60
+        culvert_height=1.20
+        
+        culvert_type='box'
+        manning=0.013
+        sum_loss=1.5
+
+        inlet_specific_energy=inlet_depth + 0.5*inlet_velocity**2/g 
+        z_in = 0.0
+        z_out = z_in-culvert_length*culvert_slope/100
+        E_in = z_in+inlet_depth + 0.5*inlet_velocity**2/g
+        E_out = z_out+outlet_depth + 0.5*outlet_velocity**2/g
+        delta_total_energy = E_in-E_out
+        
+        Q_expected = 2.50
+        v_expected = 1.897
+        d_expected = 0.367
+        
+        if verbose:
+            print 50*'='
+            print 'width ',culvert_width
+            print 'depth ',culvert_height
+            print 'flow_width ',culvert_width
+            print 'length ' ,culvert_length
+            print 'driving_energy ',inlet_specific_energy
+            print 'delta_total_energy ',delta_total_energy
+            print 'outlet_enquiry_depth ',outlet_depth
+            print 'sum_loss ',sum_loss
+            print 'manning ',manning
+        
+        Q, v, d, flow_area, case= boyd_box_function(culvert_width, 
+                                                    culvert_height, 
+                                                    culvert_width, 
+                                                    culvert_length, 
+                                                    inlet_specific_energy, 
+                                                    delta_total_energy, 
+                                                    outlet_depth, 
+                                                    sum_loss,
+                                                    manning)
+
+
+
+        if verbose:
+            print ('%s,%.2f,%.2f,%.2f' %('ANUGAcalcsTEST02 Q-v-d',Q,v,d))
+            print ('%s,%.2f,%.2f,%.2f' %('Spreadsheet_Boydcalcs', 2.508, 1.897, 0.367))
+            
+        assert numpy.allclose(Q, Q_expected, rtol=1.0e-1) #inflow
+        assert numpy.allclose(v, v_expected, rtol=1.0e-1) #outflow velocity
+        assert numpy.allclose(d, d_expected, rtol=1.0e-1) #depth at outlet used to calc v  
+
+
+    def test_boyd_2_operator(self):
+        """test_boyd_non_skew
+        
+        This tests the Boyd routine with data obtained from culvertw application 1.1 by IceMindserer  BD Parkinson, 
+        calculation code by MJ Boyd 
+        """
+
+        g=9.81
+        culvert_slope=10  # Downward
+
+        inlet_depth=0.500
+        outlet_depth=0.700
+        inlet_velocity=1.0
+        outlet_velocity=0.50
+        
+        culvert_length=10.0
+        culvert_width=3.60
+        culvert_height=1.20
+        
+        culvert_type='box'
+        manning=0.013
+        sum_loss=1.5
+
+        inlet_specific_energy=inlet_depth + 0.5*inlet_velocity**2/g 
+        z_in = 0.0
+        z_out = z_in-culvert_length*culvert_slope/100
+        E_in = z_in+inlet_depth + 0.5*inlet_velocity**2/g
+        E_out = z_out+outlet_depth + 0.5*outlet_velocity**2/g
+        delta_total_energy = E_in-E_out
+        
+      
+        
+        elevation_0 = z_in
+        elevation_1 = z_out
+        
+        stage_0 = elevation_0 + inlet_depth
+        stage_1 = elevation_1 + outlet_depth
+ 
+
+        domain_length = 200.0
+        domain_width = 200.0
+
+        #culvert_length = 20.0
+        #culvert_width = 3.66
+        #culvert_height = 3.66
+        culvert_losses = {'inlet':0.5, 'outlet':1.0, 'bend':0.0, 'grate':0.0, 'pier': 0.0, 'other': 0.0}
+        culvert_mannings = 0.013
+        
+        culvert_apron = 0.0
+        enquiry_gap = 5.0
+
+        Q_expected = 2.50
+        v_expected = 1.897
+        d_expected = 0.367
+
+
+        domain = self._create_domain(d_length=domain_length,
+                                     d_width=domain_width,
+                                     dx = 5.0,
+                                     dy = 5.0,
+                                     elevation_0 = elevation_0,
+                                     elevation_1 = elevation_1,
+                                     stage_0 = stage_0,
+                                     stage_1 = stage_1,
+                                     xvelocity_0 = inlet_velocity,
+                                     xvelocity_1 = outlet_velocity)
+ 
+
+        #print 'Defining Structures'
+        
+        ep0 = numpy.array([domain_length/2-culvert_length/2, 100.0])
+        ep1 = numpy.array([domain_length/2+culvert_length/2, 100.0])
+        
+        
+        culvert = Boyd_box_operator(domain,
+                                    losses=culvert_losses,
+                                    width=culvert_width,
+                                    end_points=[ep0, ep1],
+                                    height=culvert_height,
+                                    apron=culvert_apron,
+                                    enquiry_gap=enquiry_gap,
+                                    use_momentum_jet=False,
+                                    use_velocity_head=True,
+                                    manning=culvert_mannings,
+                                    logging=False,
+                                    label='3.6x1.2RCBC',
+                                    verbose=False)
+
+        #culvert.determine_inflow_outflow()
+        
+        ( Q, v, d ) = culvert.discharge_routine()
+        
+        if verbose:
+            print 'test_boyd_operator_2'
+            print 'expected ',Q_expected,v_expected, d_expected
+            print 'calc ',Q,v,d
+        
+
+        assert numpy.allclose(Q, Q_expected, rtol=2.0e-2) #inflow
+        assert numpy.allclose(v, v_expected, rtol=2.0e-2) #outflow velocity
+        assert numpy.allclose(d, d_expected, rtol=2.0e-2) #depth at outlet used to calc v 
+        
+        
+
+
+
+    def test_boyd_3(self):
+        """test_boyd_3
+        
+        This tests the Boyd routine with data obtained from culvertw application 1.1 by IceMindserer  BD Parkinson, 
+        calculation code by MJ Boyd     
+        """
+
+
+        g=9.81
+        culvert_slope=10  # Downward
+
+        inlet_depth=1.800
+        outlet_depth=0.80
+        inlet_velocity=1.0
+        outlet_velocity=0.5
+        
+        culvert_length=10.0
+        culvert_width=3.60
+        culvert_height=1.20
+        
+        culvert_type='box'
+        manning=0.013
+        sum_loss=1.5
+
+        inlet_specific_energy=inlet_depth + 0.5*inlet_velocity**2/g 
+        z_in = 0.0
+        z_out = z_in-culvert_length*culvert_slope/100
+        E_in = z_in+inlet_depth + 0.5*inlet_velocity**2/g
+        E_out = z_out+outlet_depth + 0.5*outlet_velocity**2/g
+        delta_total_energy = E_in-E_out
+        
+
+        Q_expected = 13.554
+        v_expected = 3.329
+        d_expected = 1.131
+        
+        if verbose:
+            print 50*'='
+            print 'width ',culvert_width
+            print 'depth ',culvert_height
+            print 'flow_width ',culvert_width
+            print 'length ' ,culvert_length
+            print 'driving_energy ',inlet_specific_energy
+            print 'delta_total_energy ',delta_total_energy
+            print 'outlet_enquiry_depth ',outlet_depth
+            print 'sum_loss ',sum_loss
+            print 'manning ',manning
+        
+        Q, v, d, flow_area, case= boyd_box_function(culvert_width, 
+                                                    culvert_height, 
+                                                    culvert_width, 
+                                                    culvert_length, 
+                                                    inlet_specific_energy, 
+                                                    delta_total_energy, 
+                                                    outlet_depth, 
+                                                    sum_loss,
+                                                    manning)
+
+
+
+
+        if verbose:
+            print ('%s,%.2f'%('SPEC_E = ',inlet_specific_energy))
+            print ('%s,%.2f'%('Delta E = ',delta_total_energy))
+            print ('%s,%.2f,%.2f,%.2f' %('ANUGAcalcsTEST03 Q-v-d',Q,v,d))
+            print ('%s,%.2f,%.2f,%.2f' %('Spreadsheet_Boydcalcs', 13.554, 3.329, 1.131))
+            
+        assert numpy.allclose(Q, Q_expected, rtol=1.0e-2) #inflow
+        assert numpy.allclose(v, v_expected, rtol=1.0e-2) #outflow velocity
+        assert numpy.allclose(d, d_expected, rtol=1.0e-2) #depth at outlet used to calc v 
+
+
+    def test_boyd_3_operator(self):
+        """test_boyd_non_skew
+        
+        This tests the Boyd routine with data obtained from culvertw application 1.1 by IceMindserer  BD Parkinson, 
+        calculation code by MJ Boyd 
+        """
+
+        g=9.81
+        culvert_slope=10  # Downward
+
+        inlet_depth=1.800
+        outlet_depth=0.80
+        inlet_velocity=1.0
+        outlet_velocity=0.5
+        
+        culvert_length=10.0
+        culvert_width=3.60
+        culvert_height=1.20
+        
+        culvert_type='box'
+        manning=0.013
+        sum_loss=1.5
+
+        inlet_specific_energy=inlet_depth + 0.5*inlet_velocity**2/g 
+        z_in = 0.0
+        z_out = z_in-culvert_length*culvert_slope/100
+        E_in = z_in+inlet_depth + 0.5*inlet_velocity**2/g
+        E_out = z_out+outlet_depth + 0.5*outlet_velocity**2/g
+        delta_total_energy = E_in-E_out
+        
+
+        Q_expected = 13.554
+        v_expected = 3.329
+        d_expected = 1.131
+        
+      
+        
+        elevation_0 = z_in
+        elevation_1 = z_out
+        
+        stage_0 = elevation_0 + inlet_depth
+        stage_1 = elevation_1 + outlet_depth
+ 
+
+        domain_length = 200.0
+        domain_width = 200.0
+
+        #culvert_length = 20.0
+        #culvert_width = 3.66
+        #culvert_height = 3.66
+        culvert_losses = {'inlet':0.5, 'outlet':1.0, 'bend':0.0, 'grate':0.0, 'pier': 0.0, 'other': 0.0}
+        culvert_mannings = 0.013
+        
+        culvert_apron = 0.0
+        enquiry_gap = 5.0
+
+
+
+
+        domain = self._create_domain(d_length=domain_length,
+                                     d_width=domain_width,
+                                     dx = 5.0,
+                                     dy = 5.0,
+                                     elevation_0 = elevation_0,
+                                     elevation_1 = elevation_1,
+                                     stage_0 = stage_0,
+                                     stage_1 = stage_1,
+                                     xvelocity_0 = inlet_velocity,
+                                     xvelocity_1 = outlet_velocity)
+ 
+
+        #print 'Defining Structures'
+        
+        ep0 = numpy.array([domain_length/2-culvert_length/2, 100.0])
+        ep1 = numpy.array([domain_length/2+culvert_length/2, 100.0])
+        
+        
+        culvert = Boyd_box_operator(domain,
+                                    losses=culvert_losses,
+                                    width=culvert_width,
+                                    end_points=[ep0, ep1],
+                                    height=culvert_height,
+                                    apron=culvert_apron,
+                                    enquiry_gap=enquiry_gap,
+                                    use_momentum_jet=False,
+                                    use_velocity_head=True,
+                                    manning=culvert_mannings,
+                                    logging=False,
+                                    label='3.6x1.2RCBC',
+                                    verbose=False)
+
+        #culvert.determine_inflow_outflow()
+        
+        ( Q, v, d ) = culvert.discharge_routine()
+        
+        if verbose:
+            print 'test_boyd_operator_1'
+            print 'expected ',Q_expected,v_expected, d_expected
+            print 'calc ',Q,v,d
+        
+
+        assert numpy.allclose(Q, Q_expected, rtol=2.0e-2) #inflow
+        assert numpy.allclose(v, v_expected, rtol=2.0e-2) #outflow velocity
+        assert numpy.allclose(d, d_expected, rtol=2.0e-2) #depth at outlet used to calc v 
+        
+        
+
+
+
+
+#NOTE FROM HERE DOWN THE UNITS TEST HAVE NOT BEEN AMENDED TO ALLOW VELOCITY COMPONENT TO BE USED. ONLY ABOVE 3 TESTS WORK. PM WILL FIX THE ONES BELOW WHEN THE ABOVE 3 ARE WORKING
+    def test_boyd_4(self):
+        """test_boyd_4
+        
+        This tests the Boyd routine with data obtained from culvertw application 1.1 by IceMindserer  BD Parkinson, 
+        calculation code by MJ Boyd    
+        """
+        # FIXME(Ole): This test fails (20 Feb 2009)
+
+        g=9.81
+        culvert_slope=10  # Downward
+
+        inlet_depth=1.00
+        outlet_depth=0.8
+        inlet_velocity=1.0
+        outlet_velocity=0.5 
+        culvert_length=10.0
+        culvert_width=3.60
+        culvert_height=1.20
+       
+        culvert_type='box'
+        manning=0.013
+        sum_loss=1.5
+
+        inlet_specific_energy=inlet_depth + 0.5*inlet_velocity**2/g 
+        z_in = 10.0
+        z_out = 10.0-culvert_length*culvert_slope/100
+        E_in = z_in+inlet_depth + 0.5*inlet_velocity**2/g
+        E_out = z_out+outlet_depth + 0.5*outlet_velocity**2/g
+        delta_total_energy = E_in-E_out
+        
+        
+        
+        Q_expected = 6.609
+        v_expected = 2.621
+        d_expected = 0.70
+        
+        
+        if verbose:
+            print 50*'='
+            print 'width ',culvert_width
+            print 'depth ',culvert_height
+            print 'flow_width ',culvert_width
+            print 'length ' ,culvert_length
+            print 'driving_energy ',inlet_specific_energy
+            print 'delta_total_energy ',delta_total_energy
+            print 'outlet_enquiry_depth ',outlet_depth
+            print 'sum_loss ',sum_loss
+            print 'manning ',manning
+
+        Q, v, d, flow_area, case= boyd_box_function(culvert_width, 
+                                                    culvert_height, 
+                                                    culvert_width, 
+                                                    culvert_length, 
+                                                    inlet_specific_energy, 
+                                                    delta_total_energy, 
+                                                    outlet_depth, 
+                                                    sum_loss,
+                                                    manning)
+
+
+        if verbose:
+            print ('%s,%.2f'%('SPEC_E = ',inlet_specific_energy))
+            print ('%s,%.2f'%('Delta E = ',delta_total_energy))
+            print ('%s,%.2f,%.2f,%.2f' %('ANUGAcalcsTEST04 Q-v-d',Q,v,d))
+            print ('%s,%.2f,%.2f,%.2f' %('Spreadsheet_Boydcalcs', 6.609, 2.621, 0.70))
+            
+        assert numpy.allclose(Q, Q_expected, rtol=2.0e-2) #inflow
+        assert numpy.allclose(v, v_expected, rtol=2.0e-2) #outflow velocity
+        assert numpy.allclose(d, d_expected, rtol=2.0e-2) #depth at outlet used to calc v 
+
+
+    def test_boyd_4_operator(self):
+        """test_boyd_non_skew
+        
+        This tests the Boyd routine with data obtained from culvertw application 1.1 by IceMindserer  BD Parkinson, 
+        calculation code by MJ Boyd 
+        """
+
+        g=9.81
+        culvert_slope=10  # Downward
+
+        inlet_depth=1.00
+        outlet_depth=0.8
+        inlet_velocity=1.0
+        outlet_velocity=0.5 
+        culvert_length=10.0
+        culvert_width=3.60
+        culvert_height=1.20
+       
+        culvert_type='box'
+        manning=0.013
+        sum_loss=1.5
+
+        inlet_specific_energy=inlet_depth + 0.5*inlet_velocity**2/g 
+        z_in = 10.0
+        z_out = 10.0-culvert_length*culvert_slope/100
+        E_in = z_in+inlet_depth + 0.5*inlet_velocity**2/g
+        E_out = z_out+outlet_depth + 0.5*outlet_velocity**2/g
+        delta_total_energy = E_in-E_out
+        
+        
+        
+        Q_expected = 6.609
+        v_expected = 2.621
+        d_expected = 0.70
+        
+      
+        
+        elevation_0 = z_in
+        elevation_1 = z_out
+        
+        stage_0 = elevation_0 + inlet_depth
+        stage_1 = elevation_1 + outlet_depth
+ 
+
+        domain_length = 200.0
+        domain_width = 200.0
+
+        #culvert_length = 20.0
+        #culvert_width = 3.66
+        #culvert_height = 3.66
+        culvert_losses = {'inlet':0.5, 'outlet':1.0, 'bend':0.0, 'grate':0.0, 'pier': 0.0, 'other': 0.0}
+        culvert_mannings = 0.013
+        
+        culvert_apron = 0.0
+        enquiry_gap = 5.0
+
+
+
+
+        domain = self._create_domain(d_length=domain_length,
+                                     d_width=domain_width,
+                                     dx = 5.0,
+                                     dy = 5.0,
+                                     elevation_0 = elevation_0,
+                                     elevation_1 = elevation_1,
+                                     stage_0 = stage_0,
+                                     stage_1 = stage_1,
+                                     xvelocity_0 = inlet_velocity,
+                                     xvelocity_1 = outlet_velocity)
+ 
+
+        #print 'Defining Structures'
+        
+        ep0 = numpy.array([domain_length/2-culvert_length/2, 100.0])
+        ep1 = numpy.array([domain_length/2+culvert_length/2, 100.0])
+        
+        
+        culvert = Boyd_box_operator(domain,
+                                    losses=culvert_losses,
+                                    width=culvert_width,
+                                    end_points=[ep0, ep1],
+                                    height=culvert_height,
+                                    apron=culvert_apron,
+                                    enquiry_gap=enquiry_gap,
+                                    use_momentum_jet=False,
+                                    use_velocity_head=True,
+                                    manning=culvert_mannings,
+                                    logging=False,
+                                    label='3.6x1.2RCBC',
+                                    verbose=False)
+
+        #culvert.determine_inflow_outflow()
+        
+        ( Q, v, d ) = culvert.discharge_routine()
+        
+        if verbose:
+            print 'test_boyd_operator_1'
+            print 'expected ',Q_expected,v_expected, d_expected
+            print 'calc ',Q,v,d
+        
+
+        assert numpy.allclose(Q, Q_expected, rtol=2.0e-2) #inflow
+        assert numpy.allclose(v, v_expected, rtol=2.0e-2) #outflow velocity
+        assert numpy.allclose(d, d_expected, rtol=2.0e-2) #depth at outlet used to calc v 
+
+    def test_boyd_5(self):
+        """test_boyd_5
+        
+        This tests the Boyd routine with data obtained from culvertw application 1.1 by IceMindserer  BD Parkinson, 
+        calculation code by MJ Boyd    
+        """
+        # FIXME(Ole): This test fails (20 Feb 2009)
+
+        g=9.81
+        culvert_slope=10  # Downward
+
+        inlet_depth=1.50
+        inlet_velocity= 1.0
+        outlet_depth=2.5
+        outlet_velocity=0.5
+        culvert_length=10.0
+        culvert_width=3.60
+        culvert_height=1.20
+        
+        culvert_type='box'
+        manning=0.013
+        sum_loss=1.5
+
+        inlet_specific_energy=inlet_depth + 0.5*inlet_velocity**2/g 
+        z_in = 10.0
+        z_out = 10.0-culvert_length*culvert_slope/100
+        E_in = z_in+inlet_depth + 0.5*inlet_velocity**2/g
+        E_out = z_out+outlet_depth + 0.5*outlet_velocity**2/g
+        delta_total_energy = E_in-E_out
+    
+        Q_expected = 2.961
+        v_expected = 0.685
+        d_expected = 1.20
+        
+        if verbose:
+            print 50*'='
+            print 'width ',culvert_width
+            print 'depth ',culvert_height
+            print 'flow_width ',culvert_width
+            print 'length ' ,culvert_length
+            print 'driving_energy ',inlet_specific_energy
+            print 'delta_total_energy ',delta_total_energy
+            print 'outlet_enquiry_depth ',outlet_depth
+            print 'sum_loss ',sum_loss
+            print 'manning ',manning
+
+        Q, v, d, flow_area, case= boyd_box_function(culvert_width, 
+                                                    culvert_height, 
+                                                    culvert_width, 
+                                                    culvert_length, 
+                                                    inlet_specific_energy, 
+                                                    delta_total_energy, 
+                                                    outlet_depth, 
+                                                    sum_loss,
+                                                    manning)
+
+
+ 
+        if verbose:
+            print ('%s,%.3f'%('SPEC_E = ',inlet_specific_energy))
+            print ('%s,%.3f'%('Delta E = ',delta_total_energy))
+             
+            print ('%s,%.3f,%.3f,%.3f' %('ANUGAcalcsTEST05 Q-v-d',Q,v,d))
+            print ('%s,%.3f,%.3f,%.3f' %('Spreadsheet_Boydcalcs',2.961, 0.685, 1.20))
+            
+        assert numpy.allclose(Q, Q_expected, rtol=2.0e-2) #inflow
+        assert numpy.allclose(v, v_expected, rtol=2.0e-2) #outflow velocity
+        assert numpy.allclose(d, d_expected, rtol=2.0e-2) #depth at outlet used to calc v 
+        
+        
+        
+        
+    def test_boyd_5_operator(self):
+        """test_boyd_non_skew
+        
+        This tests the Boyd routine with data obtained from culvertw application 1.1 by IceMindserer  BD Parkinson, 
+        calculation code by MJ Boyd 
+        """
+
+ 
+        g=9.81
+        culvert_slope=10  # Downward
+
+        inlet_depth=1.50
+        inlet_velocity= 1.0
+        outlet_depth=2.5
+        outlet_velocity=0.5
+        culvert_length=10.0
+        culvert_width=3.60
+        culvert_height=1.20
+        
+        culvert_type='box'
+        manning=0.013
+        sum_loss=1.5
+
+        inlet_specific_energy=inlet_depth + 0.5*inlet_velocity**2/g 
+        z_in = 10.0
+        z_out = 10.0-culvert_length*culvert_slope/100
+        E_in = z_in+inlet_depth + 0.5*inlet_velocity**2/g
+        E_out = z_out+outlet_depth + 0.5*outlet_velocity**2/g
+        delta_total_energy = E_in-E_out
+    
+        Q_expected = 2.961
+        v_expected = 0.685
+        d_expected = 1.20
+        
+      
+        
+        elevation_0 = z_in
+        elevation_1 = z_out
+        
+        stage_0 = elevation_0 + inlet_depth
+        stage_1 = elevation_1 + outlet_depth
+ 
+
+        domain_length = 200.0
+        domain_width = 200.0
+
+        #culvert_length = 20.0
+        #culvert_width = 3.66
+        #culvert_height = 3.66
+        culvert_losses = {'inlet':0.5, 'outlet':1.0, 'bend':0.0, 'grate':0.0, 'pier': 0.0, 'other': 0.0}
+        culvert_mannings = 0.013
+        
+        culvert_apron = 0.0
+        enquiry_gap = 5.0
+
+
+
+
+        domain = self._create_domain(d_length=domain_length,
+                                     d_width=domain_width,
+                                     dx = 5.0,
+                                     dy = 5.0,
+                                     elevation_0 = elevation_0,
+                                     elevation_1 = elevation_1,
+                                     stage_0 = stage_0,
+                                     stage_1 = stage_1,
+                                     xvelocity_0 = inlet_velocity,
+                                     xvelocity_1 = outlet_velocity)
+ 
+
+        #print 'Defining Structures'
+        
+        ep0 = numpy.array([domain_length/2-culvert_length/2, 100.0])
+        ep1 = numpy.array([domain_length/2+culvert_length/2, 100.0])
+        
+        
+        culvert = Boyd_box_operator(domain,
+                                    losses=culvert_losses,
+                                    width=culvert_width,
+                                    end_points=[ep0, ep1],
+                                    height=culvert_height,
+                                    apron=culvert_apron,
+                                    enquiry_gap=enquiry_gap,
+                                    use_momentum_jet=False,
+                                    use_velocity_head=True,
+                                    manning=culvert_mannings,
+                                    logging=False,
+                                    label='3.6x1.2RCBC',
+                                    verbose=False)
+
+        #culvert.determine_inflow_outflow()
+        
+        ( Q, v, d ) = culvert.discharge_routine()
+        
+        if verbose:
+            print 'test_boyd_operator_1'
+            print 'expected ',Q_expected,v_expected, d_expected
+            print 'calc ',Q,v,d
+        
+
+        assert numpy.allclose(Q, Q_expected, rtol=2.0e-2) #inflow
+        assert numpy.allclose(v, v_expected, rtol=2.0e-2) #outflow velocity
+        assert numpy.allclose(d, d_expected, rtol=2.0e-2) #depth at outlet used to calc v 
+
+
+    def test_boyd_6(self):
+        """test_boyd_6
+        
+        This tests the Boyd routine with data obtained from culvertw application 1.1 by IceMindserer  BD Parkinson, 
+        calculation code by MJ Boyd     
+        """
+        # FIXME(Ole): This test fails (20 Feb 2009)
+
+        g=9.81
+        culvert_slope=10  # Downward
+
+        inlet_depth=1.50
+        inlet_velocity= 4.0
+        outlet_depth=0.80
+        outlet_velocity=4.0
+        culvert_length=10.0
+        culvert_width=3.60
+        culvert_height=1.20
+        
+        culvert_type='box'
+        manning=0.013
+        sum_loss=1.5
+
+        inlet_specific_energy=inlet_depth + 0.5*inlet_velocity**2/g 
+        z_in = 10.0
+        z_out = 10.0-culvert_length*culvert_slope/100
+        E_in = z_in+inlet_depth + 0.5*inlet_velocity**2/g
+        E_out = z_out+outlet_depth + 0.5*outlet_velocity**2/g
+        delta_total_energy = E_in-E_out
+
+        Q_expected = 15.537
+        v_expected = 3.597
+        d_expected = 1.20
+
+        if verbose:
+            print 50*'='
+            print 'width ',culvert_width
+            print 'depth ',culvert_height
+            print 'flow_width ',culvert_width
+            print 'length ' ,culvert_length
+            print 'driving_energy ',inlet_specific_energy
+            print 'delta_total_energy ',delta_total_energy
+            print 'outlet_enquiry_depth ',outlet_depth
+            print 'sum_loss ',sum_loss
+            print 'manning ',manning
+            
+        Q, v, d, flow_area, case= boyd_box_function(culvert_width, 
+                                                    culvert_height, 
+                                                    culvert_width, 
+                                                    culvert_length, 
+                                                    inlet_specific_energy, 
+                                                    delta_total_energy, 
+                                                    outlet_depth, 
+                                                    sum_loss,
+                                                    manning)
+
+
+
+
+        if verbose:   
+            print ('%s,%.3f'%('SPEC_E = ',inlet_specific_energy))
+            print ('%s,%.3f'%('Delta E = ',delta_total_energy))
+             
+            print ('%s,%.3f,%.3f,%.3f' %('ANUGAcalcsTEST06 Q-v-d',Q,v,d))
+            print ('%s,%.3f,%.3f,%.3f' %('Spreadsheet_Boydcalcs',15.537, 3.597, 1.20))
+
+        assert numpy.allclose(Q, Q_expected, rtol=2.0e-2) #inflow
+        assert numpy.allclose(v, v_expected, rtol=2.0e-2) #outflow velocity
+        assert numpy.allclose(d, d_expected, rtol=2.0e-2) #depth at outlet used to calc v 
+        
+        
+    def test_boyd_6_operator(self):
+        """test_boyd_non_skew
+        
+        This tests the Boyd routine with data obtained from culvertw application 1.1 by IceMindserer  BD Parkinson, 
+        calculation code by MJ Boyd 
+        """
+
+        g=9.81
+        culvert_slope=10  # Downward
+
+        inlet_depth=1.50
+        inlet_velocity= 4.0
+        outlet_depth=0.80
+        outlet_velocity=4.0
+        culvert_length=10.0
+        culvert_width=3.60
+        culvert_height=1.20
+        
+        culvert_type='box'
+        manning=0.013
+        sum_loss=1.5
+
+        inlet_specific_energy=inlet_depth + 0.5*inlet_velocity**2/g 
+        z_in = 10.0
+        z_out = 10.0-culvert_length*culvert_slope/100
+        E_in = z_in+inlet_depth + 0.5*inlet_velocity**2/g
+        E_out = z_out+outlet_depth + 0.5*outlet_velocity**2/g
+        delta_total_energy = E_in-E_out
+
+        Q_expected = 15.537
+        v_expected = 3.597
+        d_expected = 1.20
+        
+      
+        
+        elevation_0 = z_in
+        elevation_1 = z_out
+        
+        stage_0 = elevation_0 + inlet_depth
+        stage_1 = elevation_1 + outlet_depth
+ 
+
+        domain_length = 200.0
+        domain_width = 200.0
+
+        #culvert_length = 20.0
+        #culvert_width = 3.66
+        #culvert_height = 3.66
+        culvert_losses = {'inlet':0.5, 'outlet':1.0, 'bend':0.0, 'grate':0.0, 'pier': 0.0, 'other': 0.0}
+        culvert_mannings = 0.013
+        
+        culvert_apron = 0.0
+        enquiry_gap = 5.0
+
+
+
+
+        domain = self._create_domain(d_length=domain_length,
+                                     d_width=domain_width,
+                                     dx = 5.0,
+                                     dy = 5.0,
+                                     elevation_0 = elevation_0,
+                                     elevation_1 = elevation_1,
+                                     stage_0 = stage_0,
+                                     stage_1 = stage_1,
+                                     xvelocity_0 = inlet_velocity,
+                                     xvelocity_1 = outlet_velocity)
+ 
+
+        #print 'Defining Structures'
+        
+        ep0 = numpy.array([domain_length/2-culvert_length/2, 100.0])
+        ep1 = numpy.array([domain_length/2+culvert_length/2, 100.0])
+        
+        
+        culvert = Boyd_box_operator(domain,
+                                    losses=culvert_losses,
+                                    width=culvert_width,
+                                    end_points=[ep0, ep1],
+                                    height=culvert_height,
+                                    apron=culvert_apron,
+                                    enquiry_gap=enquiry_gap,
+                                    use_momentum_jet=False,
+                                    use_velocity_head=True,
+                                    manning=culvert_mannings,
+                                    logging=False,
+                                    label='3.6x1.2RCBC',
+                                    verbose=False)
+
+        #culvert.determine_inflow_outflow()
+        
+        ( Q, v, d ) = culvert.discharge_routine()
+        
+        if verbose:
+            print 'test_boyd_operator_1'
+            print 'expected ',Q_expected,v_expected, d_expected
+            print 'calc ',Q,v,d
+        
+
+        assert numpy.allclose(Q, Q_expected, rtol=2.0e-2) #inflow
+        assert numpy.allclose(v, v_expected, rtol=2.0e-2) #outflow velocity
+        assert numpy.allclose(d, d_expected, rtol=2.0e-2) #depth at outlet used to calc v 
+
+    def test_boyd_7(self):
+        """test_boyd_7
+        
+        This tests the Boyd routine with data obtained from ??? by Petar Milevski    
+        """
+        # FIXME(Ole): This test fails (20 Feb 2009)
+
+        g=9.81
+
+
+        inlet_depth=0.150
+        outlet_depth=0.15
+        inlet_velocity=1.00
+        outlet_velocity=0.5
+        
+        culvert_length=10.0
+        culvert_width=3.6
+        culvert_height=1.20
+        
+        culvert_type='box'
+        manning=0.013
+        sum_loss=1.5
+
+        inlet_specific_energy=inlet_depth + 0.5*inlet_velocity**2/g 
+        culvert_slope=1  # % Downward
+        z_in = 10.0
+        z_out = z_in-culvert_length*culvert_slope/100
+        E_in = z_in+inlet_depth + 0.5*inlet_velocity**2/g
+        E_out = z_out+outlet_depth + 0.5*outlet_velocity**2/g
+        delta_total_energy = E_in-E_out
+        inlet_specific_energy=inlet_depth + 0.5*inlet_velocity**2/g 
+
+
+        Q_expected = 0.5526
+        v_expected = 1.146
+        d_expected = 0.1339
+        
+        if verbose:
+            print 50*'='
+            print 'width ',culvert_width
+            print 'depth ',culvert_height
+            print 'flow_width ',culvert_width
+            print 'length ' ,culvert_length
+            print 'driving_energy ',inlet_specific_energy
+            print 'delta_total_energy ',delta_total_energy
+            print 'outlet_enquiry_depth ',outlet_depth
+            print 'sum_loss ',sum_loss
+            print 'manning ',manning
+            
+        Q, v, d, flow_area, case= boyd_box_function(culvert_width, 
+                                                    culvert_height, 
+                                                    culvert_width, 
+                                                    culvert_length, 
+                                                    inlet_specific_energy, 
+                                                    delta_total_energy, 
+                                                    outlet_depth, 
+                                                    sum_loss,
+                                                    manning)
+        
+#         Q, v, d = boyd_generalised_culvert_model(inlet_depth,
+#                                                  outlet_depth,
+#                                                  inlet_velocity,
+#                                                  outlet_velocity,
+#                                                  inlet_specific_energy, 
+#                                                  delta_total_energy, 
+#                                                  g,
+#                                                  culvert_length,
+#                                                  culvert_width,
+#                                                  culvert_height,
+#                                                  culvert_type,
+#                                                  manning,
+#                                                  sum_loss)
+        if verbose:
+            print ('%s,%.2f,%.2f,%.2f' %('ANUGAcalcsTEST01 Q-v-d',Q,v,d))
+            print('%s,%.2f,%.2f,%.2f' %('Spreadsheet_Boydcalcs', Q_expected, v_expected, d_expected))
+
+        assert numpy.allclose(Q, Q_expected, rtol=1.0e-1) #inflow
+        assert numpy.allclose(v, v_expected, rtol=1.0e-1) #outflow velocity
+        assert numpy.allclose(d, d_expected, rtol=1.0e-1) #depth at outlet used to calc v 
+
+    def test_boyd_7_operator(self):
+        """test_boyd_non_skew
+        
+        This tests the Boyd routine with data obtained from culvertw application 1.1 by IceMindserer  BD Parkinson, 
+        calculation code by MJ Boyd 
+        """
+
+        g=9.81
+
+
+        inlet_depth=0.150
+        outlet_depth=0.15
+        inlet_velocity=1.00
+        outlet_velocity=0.5
+        
+        culvert_length=10.0
+        culvert_width=3.6
+        culvert_height=1.20
+        
+        culvert_type='box'
+        manning=0.013
+        sum_loss=1.5
+
+        inlet_specific_energy=inlet_depth + 0.5*inlet_velocity**2/g 
+        culvert_slope=1  # % Downward
+        z_in = 10.0
+        z_out = z_in-culvert_length*culvert_slope/100
+        E_in = z_in+inlet_depth + 0.5*inlet_velocity**2/g
+        E_out = z_out+outlet_depth + 0.5*outlet_velocity**2/g
+        delta_total_energy = E_in-E_out
+        inlet_specific_energy=inlet_depth + 0.5*inlet_velocity**2/g 
+
+
+        Q_expected = 0.5526
+        v_expected = 1.146
+        d_expected = 0.1339
+        
+      
+        
+        elevation_0 = z_in
+        elevation_1 = z_out
+        
+        stage_0 = elevation_0 + inlet_depth
+        stage_1 = elevation_1 + outlet_depth
+ 
+
+        domain_length = 200.0
+        domain_width = 200.0
+
+        #culvert_length = 20.0
+        #culvert_width = 3.66
+        #culvert_height = 3.66
+        culvert_losses = {'inlet':0.5, 'outlet':1.0, 'bend':0.0, 'grate':0.0, 'pier': 0.0, 'other': 0.0}
+        culvert_mannings = 0.013
+        
+        culvert_apron = 0.0
+        enquiry_gap = 5.0
+
+
+
+
+        domain = self._create_domain(d_length=domain_length,
+                                     d_width=domain_width,
+                                     dx = 5.0,
+                                     dy = 5.0,
+                                     elevation_0 = elevation_0,
+                                     elevation_1 = elevation_1,
+                                     stage_0 = stage_0,
+                                     stage_1 = stage_1,
+                                     xvelocity_0 = inlet_velocity,
+                                     xvelocity_1 = outlet_velocity)
+ 
+
+        #print 'Defining Structures'
+        
+        ep0 = numpy.array([domain_length/2-culvert_length/2, 100.0])
+        ep1 = numpy.array([domain_length/2+culvert_length/2, 100.0])
+        
+        
+        culvert = Boyd_box_operator(domain,
+                                    losses=culvert_losses,
+                                    width=culvert_width,
+                                    end_points=[ep0, ep1],
+                                    height=culvert_height,
+                                    apron=culvert_apron,
+                                    enquiry_gap=enquiry_gap,
+                                    use_momentum_jet=False,
+                                    use_velocity_head=True,
+                                    manning=culvert_mannings,
+                                    logging=False,
+                                    label='3.6x1.2RCBC',
+                                    verbose=False)
+
+        #culvert.determine_inflow_outflow()
+        
+        ( Q, v, d ) = culvert.discharge_routine()
+        
+        if verbose:
+            print 'test_boyd_operator_1'
+            print 'expected ',Q_expected,v_expected, d_expected
+            print 'calc ',Q,v,d
+        
+
+        assert numpy.allclose(Q, Q_expected, rtol=2.0e-2) #inflow
+        assert numpy.allclose(v, v_expected, rtol=2.0e-2) #outflow velocity
+        assert numpy.allclose(d, d_expected, rtol=2.0e-2) #depth at outlet used to calc v 
+
+
+        
+    def test_boyd_8(self):
+        """test_boyd_8
+        
+        This tests the Boyd routine with data obtained from ??? by Petar Milevski    
+        """
+        # FIXME(Ole): This test fails (20 Feb 2009)
+
+        g=9.81
+        culvert_slope=1  # Downward
+
+        inlet_depth=0.500
+        outlet_depth=0.700
+        inlet_velocity=1.50
+        outlet_velocity=0.50
+        
+        culvert_length=10.0
+        culvert_width=3.60
+        culvert_height=1.20
+        
+        culvert_type='box'
+        manning=0.013
+        sum_loss=1.5
+
+        inlet_specific_energy=inlet_depth + 0.5*inlet_velocity**2/g 
+        z_in = 0.0
+        z_out = z_in-culvert_length*culvert_slope/100
+        E_in = z_in+inlet_depth + 0.5*inlet_velocity**2/g
+        E_out = z_out+outlet_depth + 0.5*outlet_velocity**2/g
+        delta_total_energy = E_in-E_out
+        
+        
+        Q_expected = 0.224
+        v_expected = 0.152
+        d_expected = 0.409
+
+        if verbose:
+            print 50*'='
+            print 'width ',culvert_width
+            print 'depth ',culvert_height
+            print 'flow_width ',culvert_width
+            print 'length ' ,culvert_length
+            print 'driving_energy ',inlet_specific_energy
+            print 'delta_total_energy ',delta_total_energy
+            print 'outlet_enquiry_depth ',outlet_depth
+            print 'sum_loss ',sum_loss
+            print 'manning ',manning
+            
+        Q, v, d, flow_area, case= boyd_box_function(culvert_width, 
+                                                    culvert_height, 
+                                                    culvert_width, 
+                                                    culvert_length, 
+                                                    inlet_specific_energy, 
+                                                    delta_total_energy, 
+                                                    outlet_depth, 
+                                                    sum_loss,
+                                                    manning)
+
+#         Q, v, d = boyd_generalised_culvert_model(inlet_depth,
+#                                                  outlet_depth,
+#                                                  inlet_velocity,
+#                                                  outlet_velocity,
+#                                                  inlet_specific_energy, 
+#                                                  delta_total_energy, 
+#                                                  g,
+#                                                  culvert_length,
+#                                                  culvert_width,
+#                                                  culvert_height,
+#                                                  culvert_type,
+#                                                  manning,
+#                                                  sum_loss)
+        if verbose:
+            print ('%s,%.2f,%.2f,%.2f' %('ANUGAcalcsTEST02 Q-v-d',Q,v,d))
+            print('%s,%.2f,%.2f,%.2f' %('Spreadsheet_Boydcalcs', Q_expected, v_expected, d_expected))
+
+        assert numpy.allclose(Q, Q_expected, rtol=1.0e-1) #inflow
+        assert numpy.allclose(v, v_expected, rtol=1.0e-1) #outflow velocity
+        assert numpy.allclose(d, d_expected, rtol=1.0e-1) #depth at outlet used to calc v 
+
+    def test_boyd_8_operator(self):
+        """test_boyd_non_skew
+        
+        This tests the Boyd routine with data obtained from culvertw application 1.1 by IceMindserer  BD Parkinson, 
+        calculation code by MJ Boyd 
+        """
+
+        g=9.81
+        culvert_slope=1  # Downward
+
+        inlet_depth=0.500
+        outlet_depth=0.700
+        inlet_velocity=1.50
+        outlet_velocity=0.50
+        
+        culvert_length=10.0
+        culvert_width=3.60
+        culvert_height=1.20
+        
+        culvert_type='box'
+        manning=0.013
+        sum_loss=1.5
+
+        inlet_specific_energy=inlet_depth + 0.5*inlet_velocity**2/g 
+        z_in = 0.0
+        z_out = z_in-culvert_length*culvert_slope/100
+        E_in = z_in+inlet_depth + 0.5*inlet_velocity**2/g
+        E_out = z_out+outlet_depth + 0.5*outlet_velocity**2/g
+        delta_total_energy = E_in-E_out
+        
+        
+        Q_expected = 0.224
+        v_expected = 0.152
+        d_expected = 0.409
+        
+        elevation_0 = z_in
+        elevation_1 = z_out
+        
+        stage_0 = elevation_0 + inlet_depth
+        stage_1 = elevation_1 + outlet_depth
+ 
+
+        domain_length = 200.0
+        domain_width = 200.0
+
+        #culvert_length = 20.0
+        #culvert_width = 3.66
+        #culvert_height = 3.66
+        culvert_losses = {'inlet':0.5, 'outlet':1.0, 'bend':0.0, 'grate':0.0, 'pier': 0.0, 'other': 0.0}
+        culvert_mannings = 0.013
+        
+        culvert_apron = 0.0
+        enquiry_gap = 5.0
+
+
+
+
+        domain = self._create_domain(d_length=domain_length,
+                                     d_width=domain_width,
+                                     dx = 5.0,
+                                     dy = 5.0,
+                                     elevation_0 = elevation_0,
+                                     elevation_1 = elevation_1,
+                                     stage_0 = stage_0,
+                                     stage_1 = stage_1,
+                                     xvelocity_0 = inlet_velocity,
+                                     xvelocity_1 = outlet_velocity)
+ 
+
+        #print 'Defining Structures'
+        
+        ep0 = numpy.array([domain_length/2-culvert_length/2, 100.0])
+        ep1 = numpy.array([domain_length/2+culvert_length/2, 100.0])
+        
+        
+        culvert = Boyd_box_operator(domain,
+                                    losses=culvert_losses,
+                                    width=culvert_width,
+                                    end_points=[ep0, ep1],
+                                    height=culvert_height,
+                                    apron=culvert_apron,
+                                    enquiry_gap=enquiry_gap,
+                                    use_momentum_jet=False,
+                                    use_velocity_head=True,
+                                    manning=culvert_mannings,
+                                    logging=False,
+                                    label='3.6x1.2RCBC',
+                                    verbose=False)
+
+        #culvert.determine_inflow_outflow()
+        
+        ( Q, v, d ) = culvert.discharge_routine()
+        
+        if verbose:
+            print 'test_boyd_operator_1'
+            print 'expected ',Q_expected,v_expected, d_expected
+            print 'calc ',Q,v,d
+        
+
+        assert numpy.allclose(Q, Q_expected, rtol=1.0e-1) #inflow
+        assert numpy.allclose(v, v_expected, rtol=1.0e-1) #outflow velocity
+        assert numpy.allclose(d, d_expected, rtol=1.0e-1) #depth at outlet used to calc v 
+
+
+    def test_boyd_9(self):
+        """test_boyd_9
+        
+        This tests the Boyd routine with data obtained from ??? by Petar Milevski    
+        """
+        # FIXME(Ole): This test fails (20 Feb 2009)
+
+        g=9.81
+        culvert_slope=1  # Downward
+
+        inlet_depth=1.800
+        outlet_depth=0.80
+        inlet_velocity=1.0
+        outlet_velocity=0.5
+        
+        culvert_length=10.0
+        culvert_width=3.60
+        culvert_height=1.20
+        
+        culvert_type='box'
+        manning=0.013
+        sum_loss=1.5
+
+        inlet_specific_energy=inlet_depth + 0.5*inlet_velocity**2/g 
+        z_in = 0.0
+        z_out = z_in-culvert_length*culvert_slope/100
+        E_in = z_in+inlet_depth + 0.5*inlet_velocity**2/g
+        E_out = z_out+outlet_depth + 0.5*outlet_velocity**2/g
+        delta_total_energy = E_in-E_out
+
+
+        Q_expected = 13.554
+        v_expected = 3.329
+        d_expected = 1.131
+        
+        if verbose:
+            print 50*'='
+            print 'width ',culvert_width
+            print 'depth ',culvert_height
+            print 'flow_width ',culvert_width
+            print 'length ' ,culvert_length
+            print 'driving_energy ',inlet_specific_energy
+            print 'delta_total_energy ',delta_total_energy
+            print 'outlet_enquiry_depth ',outlet_depth
+            print 'sum_loss ',sum_loss
+            print 'manning ',manning
+            
+        Q, v, d, flow_area, case= boyd_box_function(culvert_width, 
+                                                    culvert_height, 
+                                                    culvert_width, 
+                                                    culvert_length, 
+                                                    inlet_specific_energy, 
+                                                    delta_total_energy, 
+                                                    outlet_depth, 
+                                                    sum_loss,
+                                                    manning)
+
+
+#         Q, v, d = boyd_generalised_culvert_model(inlet_depth,
+#                                                  outlet_depth,
+#                                                  inlet_velocity,
+#                                                  outlet_velocity,
+#                                                  inlet_specific_energy, 
+#                                                  delta_total_energy, 
+#                                                  g,
+#                                                  culvert_length,
+#                                                  culvert_width,
+#                                                  culvert_height,
+#                                                  culvert_type,
+#                                                  manning,
+#                                                  sum_loss)
+
+        if verbose:
+            print ('%s,%.2f'%('SPEC_E = ',inlet_specific_energy))
+            print ('%s,%.2f'%('Delta E = ',delta_total_energy))
+            print ('%s,%.2f,%.2f,%.2f' %('ANUGAcalcsTEST03 Q-v-d',Q,v,d))
+            print('%s,%.2f,%.2f,%.2f' %('Spreadsheet_Boydcalcs', Q_expected, v_expected, d_expected))
+
+        assert numpy.allclose(Q, Q_expected, rtol=1.0e-1) #inflow
+        assert numpy.allclose(v, v_expected, rtol=1.0e-1) #outflow velocity
+        assert numpy.allclose(d, d_expected, rtol=1.0e-1) #depth at outlet used to calc v 
+
+    def test_boyd_9_operator(self):
+        """test_boyd_non_skew
+        
+        This tests the Boyd routine with data obtained from culvertw application 1.1 by IceMindserer  BD Parkinson, 
+        calculation code by MJ Boyd 
+        """
+
+        g=9.81
+        culvert_slope=1  # Downward
+
+        inlet_depth=1.800
+        outlet_depth=0.80
+        inlet_velocity=1.0
+        outlet_velocity=0.5
+        
+        culvert_length=10.0
+        culvert_width=3.60
+        culvert_height=1.20
+        
+        culvert_type='box'
+        manning=0.013
+        sum_loss=1.5
+
+        inlet_specific_energy=inlet_depth + 0.5*inlet_velocity**2/g 
+        z_in = 0.0
+        z_out = z_in-culvert_length*culvert_slope/100
+        E_in = z_in+inlet_depth + 0.5*inlet_velocity**2/g
+        E_out = z_out+outlet_depth + 0.5*outlet_velocity**2/g
+        delta_total_energy = E_in-E_out
+
+
+        Q_expected = 13.554
+        v_expected = 3.329
+        d_expected = 1.131
+      
+        
+        elevation_0 = z_in
+        elevation_1 = z_out
+        
+        stage_0 = elevation_0 + inlet_depth
+        stage_1 = elevation_1 + outlet_depth
+ 
+
+        domain_length = 200.0
+        domain_width = 200.0
+
+        #culvert_length = 20.0
+        #culvert_width = 3.66
+        #culvert_height = 3.66
+        culvert_losses = {'inlet':0.5, 'outlet':1.0, 'bend':0.0, 'grate':0.0, 'pier': 0.0, 'other': 0.0}
+        culvert_mannings = 0.013
+        
+        culvert_apron = 0.0
+        enquiry_gap = 5.0
+
+
+
+
+        domain = self._create_domain(d_length=domain_length,
+                                     d_width=domain_width,
+                                     dx = 5.0,
+                                     dy = 5.0,
+                                     elevation_0 = elevation_0,
+                                     elevation_1 = elevation_1,
+                                     stage_0 = stage_0,
+                                     stage_1 = stage_1,
+                                     xvelocity_0 = inlet_velocity,
+                                     xvelocity_1 = outlet_velocity)
+ 
+
+        #print 'Defining Structures'
+        
+        ep0 = numpy.array([domain_length/2-culvert_length/2, 100.0])
+        ep1 = numpy.array([domain_length/2+culvert_length/2, 100.0])
+        
+        
+        culvert = Boyd_box_operator(domain,
+                                    losses=culvert_losses,
+                                    width=culvert_width,
+                                    end_points=[ep0, ep1],
+                                    height=culvert_height,
+                                    apron=culvert_apron,
+                                    enquiry_gap=enquiry_gap,
+                                    use_momentum_jet=False,
+                                    use_velocity_head=True,
+                                    manning=culvert_mannings,
+                                    logging=False,
+                                    label='3.6x1.2RCBC',
+                                    verbose=False)
+
+        #culvert.determine_inflow_outflow()
+        
+        ( Q, v, d ) = culvert.discharge_routine()
+        
+        if verbose:
+            print 'test_boyd_operator_1'
+            print 'expected ',Q_expected,v_expected, d_expected
+            print 'calc ',Q,v,d
+        
+
+        assert numpy.allclose(Q, Q_expected, rtol=2.0e-2) #inflow
+        assert numpy.allclose(v, v_expected, rtol=2.0e-2) #outflow velocity
+        assert numpy.allclose(d, d_expected, rtol=2.0e-2) #depth at outlet used to calc v 
+
+    def test_boyd_10(self):
+        """test_boyd_10
+        
+        This tests the Boyd routine with data obtained from ??? by Petar Milevski    
+        """
+        # FIXME(Ole): This test fails (20 Feb 2009)
+
+        g=9.81
+        culvert_slope=1  # Downward
+
+        inlet_depth=1.00
+        outlet_depth=0.8
+        inlet_velocity=1.0
+        outlet_velocity=0.5 
+        culvert_length=10.0
+        culvert_width=3.60
+        culvert_height=1.20
+       
+        culvert_type='box'
+        manning=0.013
+        sum_loss=1.5
+
+        inlet_specific_energy=inlet_depth + 0.5*inlet_velocity**2/g 
+        z_in = 10.0
+        z_out = 10.0-culvert_length*culvert_slope/100
+        E_in = z_in+inlet_depth + 0.5*inlet_velocity**2/g
+        E_out = z_out+outlet_depth + 0.5*outlet_velocity**2/g
+        delta_total_energy = E_in-E_out
+
+
+
+        Q_expected = 5.164
+        v_expected = 2.047
+        d_expected = 0.70
+        
+        if verbose:
+            print 50*'='
+            print 'width ',culvert_width
+            print 'depth ',culvert_height
+            print 'flow_width ',culvert_width
+            print 'length ' ,culvert_length
+            print 'driving_energy ',inlet_specific_energy
+            print 'delta_total_energy ',delta_total_energy
+            print 'outlet_enquiry_depth ',outlet_depth
+            print 'sum_loss ',sum_loss
+            print 'manning ',manning
+            
+        Q, v, d, flow_area, case= boyd_box_function(culvert_width, 
+                                                    culvert_height, 
+                                                    culvert_width, 
+                                                    culvert_length, 
+                                                    inlet_specific_energy, 
+                                                    delta_total_energy, 
+                                                    outlet_depth, 
+                                                    sum_loss,
+                                                    manning)
+
+#         Q, v, d = boyd_generalised_culvert_model(inlet_depth,
+#                                                  outlet_depth,
+#                                                  inlet_velocity,
+#                                                  outlet_velocity,
+#                                                  inlet_specific_energy, 
+#                                                  delta_total_energy, 
+#                                                  g,
+#                                                  culvert_length,
+#                                                  culvert_width,
+#                                                  culvert_height,
+#                                                  culvert_type,
+#                                                  manning,
+#                                                  sum_loss)        
+
+        if verbose:
+            print ('%s,%.2f'%('SPEC_E = ',inlet_specific_energy))
+            print ('%s,%.2f'%('Delta E = ',delta_total_energy))
+            print ('%s,%.2f,%.2f,%.2f' %('ANUGAcalcsTEST04 Q-v-d',Q,v,d))
+            print('%s,%.2f,%.2f,%.2f' %('Spreadsheet_Boydcalcs', Q_expected, v_expected, d_expected))
+
+        assert numpy.allclose(Q, Q_expected, rtol=1.0e-1) #inflow
+        assert numpy.allclose(v, v_expected, rtol=1.0e-1) #outflow velocity
+        assert numpy.allclose(d, d_expected, rtol=1.0e-1) #depth at outlet used to calc v 
+
+    def test_boyd_10_operator(self):
+        """test_boyd_non_skew
+        
+        This tests the Boyd routine with data obtained from culvertw application 1.1 by IceMindserer  BD Parkinson, 
+        calculation code by MJ Boyd 
+        """
+
+        g=9.81
+        culvert_slope=1  # Downward
+
+        inlet_depth=1.00
+        outlet_depth=0.8
+        inlet_velocity=1.0
+        outlet_velocity=0.5 
+        culvert_length=10.0
+        culvert_width=3.60
+        culvert_height=1.20
+       
+        culvert_type='box'
+        manning=0.013
+        sum_loss=1.5
+
+        inlet_specific_energy=inlet_depth + 0.5*inlet_velocity**2/g 
+        z_in = 10.0
+        z_out = 10.0-culvert_length*culvert_slope/100
+        E_in = z_in+inlet_depth + 0.5*inlet_velocity**2/g
+        E_out = z_out+outlet_depth + 0.5*outlet_velocity**2/g
+        delta_total_energy = E_in-E_out
+
+
+
+        Q_expected = 5.164
+        v_expected = 2.047
+        d_expected = 0.70
+        
+      
+        
+        elevation_0 = z_in
+        elevation_1 = z_out
+        
+        stage_0 = elevation_0 + inlet_depth
+        stage_1 = elevation_1 + outlet_depth
+ 
+
+        domain_length = 200.0
+        domain_width = 200.0
+
+        #culvert_length = 20.0
+        #culvert_width = 3.66
+        #culvert_height = 3.66
+        culvert_losses = {'inlet':0.5, 'outlet':1.0, 'bend':0.0, 'grate':0.0, 'pier': 0.0, 'other': 0.0}
+        culvert_mannings = 0.013
+        
+        culvert_apron = 0.0
+        enquiry_gap = 5.0
+
+
+
+
+        domain = self._create_domain(d_length=domain_length,
+                                     d_width=domain_width,
+                                     dx = 5.0,
+                                     dy = 5.0,
+                                     elevation_0 = elevation_0,
+                                     elevation_1 = elevation_1,
+                                     stage_0 = stage_0,
+                                     stage_1 = stage_1,
+                                     xvelocity_0 = inlet_velocity,
+                                     xvelocity_1 = outlet_velocity)
+ 
+
+        #print 'Defining Structures'
+        
+        ep0 = numpy.array([domain_length/2-culvert_length/2, 100.0])
+        ep1 = numpy.array([domain_length/2+culvert_length/2, 100.0])
+        
+        
+        culvert = Boyd_box_operator(domain,
+                                    losses=culvert_losses,
+                                    width=culvert_width,
+                                    end_points=[ep0, ep1],
+                                    height=culvert_height,
+                                    apron=culvert_apron,
+                                    enquiry_gap=enquiry_gap,
+                                    use_momentum_jet=False,
+                                    use_velocity_head=True,
+                                    manning=culvert_mannings,
+                                    logging=False,
+                                    label='3.6x1.2RCBC',
+                                    verbose=False)
+
+        #culvert.determine_inflow_outflow()
+        
+        ( Q, v, d ) = culvert.discharge_routine()
+        
+        if verbose:
+            print 'test_boyd_operator_1'
+            print 'expected ',Q_expected,v_expected, d_expected
+            print 'calc ',Q,v,d
+        
+
+        assert numpy.allclose(Q, Q_expected, rtol=2.0e-2) #inflow
+        assert numpy.allclose(v, v_expected, rtol=2.0e-2) #outflow velocity
+        assert numpy.allclose(d, d_expected, rtol=2.0e-2) #depth at outlet used to calc v 
+
+    def test_boyd_11(self):
+        """test_boyd_11
+        
+        This tests the Boyd routine with data obtained from ??? by Petar Milevski    
+        """
+        # FIXME(Ole): This test fails (20 Feb 2009)
+
+        g=9.81
+        culvert_slope=1  # Downward
+
+        inlet_depth=1.50
+        inlet_velocity= 1.0
+        outlet_depth=1.3
+        outlet_velocity=0.5
+        culvert_length=10.0
+        culvert_width=3.60
+        culvert_height=1.20
+        
+        culvert_type='box'
+        manning=0.013
+        sum_loss=1.5
+
+        inlet_specific_energy=inlet_depth + 0.5*inlet_velocity**2/g 
+        z_in = 10.0
+        z_out = 10.0-culvert_length*culvert_slope/100
+        E_in = z_in+inlet_depth + 0.5*inlet_velocity**2/g
+        E_out = z_out+outlet_depth + 0.5*outlet_velocity**2/g
+        delta_total_energy = E_in-E_out
+
+
+        Q_expected = 8.808
+        v_expected = 2.039
+        d_expected = 1.20
+        
+        if verbose:
+            print 50*'='
+            print 'width ',culvert_width
+            print 'depth ',culvert_height
+            print 'flow_width ',culvert_width
+            print 'length ' ,culvert_length
+            print 'driving_energy ',inlet_specific_energy
+            print 'delta_total_energy ',delta_total_energy
+            print 'outlet_enquiry_depth ',outlet_depth
+            print 'sum_loss ',sum_loss
+            print 'manning ',manning
+            
+        Q, v, d, flow_area, case= boyd_box_function(culvert_width, 
+                                                    culvert_height, 
+                                                    culvert_width, 
+                                                    culvert_length, 
+                                                    inlet_specific_energy, 
+                                                    delta_total_energy, 
+                                                    outlet_depth, 
+                                                    sum_loss,
+                                                    manning)
+
+#         Q, v, d = boyd_generalised_culvert_model(inlet_depth,
+#                                                  outlet_depth,
+#                                                  inlet_velocity,
+#                                                  outlet_velocity,
+#                                                  inlet_specific_energy, 
+#                                                  delta_total_energy, 
+#                                                  g,
+#                                                  culvert_length,
+#                                                  culvert_width,
+#                                                  culvert_height,
+#                                                  culvert_type,
+#                                                  manning,
+#                                                  sum_loss)  
+        if verbose:      
+            print ('%s,%.3f'%('SPEC_E = ',inlet_specific_energy))
+            print ('%s,%.3f'%('Delta E = ',delta_total_energy))
+        
+            print ('%s,%.3f,%.3f,%.3f' %('ANUGAcalcsTEST05Q-v-d',Q,v,d))
+            print('%s,%.2f,%.2f,%.2f' %('Spreadsheet_Boydcalcs', Q_expected, v_expected, d_expected))
+
+        assert numpy.allclose(Q, Q_expected, rtol=1.0e-1) #inflow
+        assert numpy.allclose(v, v_expected, rtol=1.0e-1) #outflow velocity
+        assert numpy.allclose(d, d_expected, rtol=1.0e-1) #depth at outlet used to calc v 
+
+    def test_boyd_11_operator(self):
+        """test_boyd_non_skew
+        
+        This tests the Boyd routine with data obtained from culvertw application 1.1 by IceMindserer  BD Parkinson, 
+        calculation code by MJ Boyd 
+        """
+
+        g=9.81
+        culvert_slope=1  # Downward
+
+        inlet_depth=1.50
+        inlet_velocity= 1.0
+        outlet_depth=1.3
+        outlet_velocity=0.5
+        culvert_length=10.0
+        culvert_width=3.60
+        culvert_height=1.20
+        
+        culvert_type='box'
+        manning=0.013
+        sum_loss=1.5
+
+        inlet_specific_energy=inlet_depth + 0.5*inlet_velocity**2/g 
+        z_in = 10.0
+        z_out = 10.0-culvert_length*culvert_slope/100
+        E_in = z_in+inlet_depth + 0.5*inlet_velocity**2/g
+        E_out = z_out+outlet_depth + 0.5*outlet_velocity**2/g
+        delta_total_energy = E_in-E_out
+
+
+        Q_expected = 8.808
+        v_expected = 2.039
+        d_expected = 1.20
+        
+      
+        
+        elevation_0 = z_in
+        elevation_1 = z_out
+        
+        stage_0 = elevation_0 + inlet_depth
+        stage_1 = elevation_1 + outlet_depth
+ 
+
+        domain_length = 200.0
+        domain_width = 200.0
+
+        #culvert_length = 20.0
+        #culvert_width = 3.66
+        #culvert_height = 3.66
+        culvert_losses = {'inlet':0.5, 'outlet':1.0, 'bend':0.0, 'grate':0.0, 'pier': 0.0, 'other': 0.0}
+        culvert_mannings = 0.013
+        
+        culvert_apron = 0.0
+        enquiry_gap = 5.0
+
+
+
+
+        domain = self._create_domain(d_length=domain_length,
+                                     d_width=domain_width,
+                                     dx = 5.0,
+                                     dy = 5.0,
+                                     elevation_0 = elevation_0,
+                                     elevation_1 = elevation_1,
+                                     stage_0 = stage_0,
+                                     stage_1 = stage_1,
+                                     xvelocity_0 = inlet_velocity,
+                                     xvelocity_1 = outlet_velocity)
+ 
+
+        #print 'Defining Structures'
+        
+        ep0 = numpy.array([domain_length/2-culvert_length/2, 100.0])
+        ep1 = numpy.array([domain_length/2+culvert_length/2, 100.0])
+        
+        
+        culvert = Boyd_box_operator(domain,
+                                    losses=culvert_losses,
+                                    width=culvert_width,
+                                    end_points=[ep0, ep1],
+                                    height=culvert_height,
+                                    apron=culvert_apron,
+                                    enquiry_gap=enquiry_gap,
+                                    use_momentum_jet=False,
+                                    use_velocity_head=True,
+                                    manning=culvert_mannings,
+                                    logging=False,
+                                    label='3.6x1.2RCBC',
+                                    verbose=False)
+
+        #culvert.determine_inflow_outflow()
+        
+        ( Q, v, d ) = culvert.discharge_routine()
+        
+        if verbose:
+            print 'test_boyd_operator_1'
+            print 'expected ',Q_expected,v_expected, d_expected
+            print 'calc ',Q,v,d
+        
+
+        assert numpy.allclose(Q, Q_expected, rtol=2.0e-2) #inflow
+        assert numpy.allclose(v, v_expected, rtol=2.0e-2) #outflow velocity
+        assert numpy.allclose(d, d_expected, rtol=2.0e-2) #depth at outlet used to calc v 
+
+
+    def test_boyd_12(self):
+        """test_boyd_12
+        
+        This tests the Boyd routine with data obtained from ??? by Petar Milevski    
+        """
+        # FIXME(Ole): This test fails (20 Feb 2009)
+
+        g=9.81
+        culvert_slope=1  # Downward
+
+        inlet_depth=1.50
+        inlet_velocity= 4.0
+        outlet_depth=0.8
+        outlet_velocity=4.0
+        culvert_length=10.0
+        culvert_width=3.60
+        culvert_height=1.20
+        
+        culvert_type='box'
+        manning=0.013
+        sum_loss=1.5
+
+        inlet_specific_energy=inlet_depth + 0.5*inlet_velocity**2/g 
+        z_in = 10.0
+        z_out = 10.0-culvert_length*culvert_slope/100
+        E_in = z_in+inlet_depth + 0.5*inlet_velocity**2/g
+        E_out = z_out+outlet_depth + 0.5*outlet_velocity**2/g
+        delta_total_energy = E_in-E_out
+
+
+        Q_expected = 13.546
+        v_expected = 3.136
+        d_expected = 1.20
+        
+        if verbose:
+            print 50*'='
+            print 'width ',culvert_width
+            print 'depth ',culvert_height
+            print 'flow_width ',culvert_width
+            print 'length ' ,culvert_length
+            print 'driving_energy ',inlet_specific_energy
+            print 'delta_total_energy ',delta_total_energy
+            print 'outlet_enquiry_depth ',outlet_depth
+            print 'sum_loss ',sum_loss
+            print 'manning ',manning
+            
+        Q, v, d, flow_area, case= boyd_box_function(culvert_width, 
+                                                    culvert_height, 
+                                                    culvert_width, 
+                                                    culvert_length, 
+                                                    inlet_specific_energy, 
+                                                    delta_total_energy, 
+                                                    outlet_depth, 
+                                                    sum_loss,
+                                                    manning)
+
+#         Q, v, d = boyd_generalised_culvert_model(inlet_depth,
+#                                                  outlet_depth,
+#                                                  inlet_velocity,
+#                                                  outlet_velocity,
+#                                                  inlet_specific_energy, 
+#                                                  delta_total_energy, 
+#                                                  g,
+#                                                  culvert_length,
+#                                                  culvert_width,
+#                                                  culvert_height,
+#                                                  culvert_type,
+#                                                  manning,
+#                                                  sum_loss)        
+        if verbose:
+            print ('%s,%.3f'%('SPEC_E = ',inlet_specific_energy))
+            print ('%s,%.3f'%('Delta E = ',delta_total_energy))
+        
+            print ('%s,%.3f,%.3f,%.3f' %('ANUGAcalcsTEST06 Q-v-d',Q,v,d))
+            print('%s,%.2f,%.2f,%.2f' %('Spreadsheet_Boydcalcs', Q_expected, v_expected, d_expected))
+
+        assert numpy.allclose(Q, Q_expected, rtol=1.0e-1) #inflow
+        assert numpy.allclose(v, v_expected, rtol=1.0e-1) #outflow velocity
+        assert numpy.allclose(d, d_expected, rtol=1.0e-1) #depth at outlet used to calc v 
+
+    def test_boyd_12_operator(self):
+        """test_boyd_non_skew
+        
+        This tests the Boyd routine with data obtained from culvertw application 1.1 by IceMindserer  BD Parkinson, 
+        calculation code by MJ Boyd 
+        """
+
+        g=9.81
+        culvert_slope=1  # Downward
+
+        inlet_depth=1.50
+        inlet_velocity= 4.0
+        outlet_depth=0.8
+        outlet_velocity=4.0
+        culvert_length=10.0
+        culvert_width=3.60
+        culvert_height=1.20
+        
+        culvert_type='box'
+        manning=0.013
+        sum_loss=1.5
+
+        inlet_specific_energy=inlet_depth + 0.5*inlet_velocity**2/g 
+        z_in = 10.0
+        z_out = 10.0-culvert_length*culvert_slope/100
+        E_in = z_in+inlet_depth + 0.5*inlet_velocity**2/g
+        E_out = z_out+outlet_depth + 0.5*outlet_velocity**2/g
+        delta_total_energy = E_in-E_out
+
+
+        Q_expected = 13.546
+        v_expected = 3.136
+        d_expected = 1.20
+        
+        elevation_0 = z_in
+        elevation_1 = z_out
+        
+        stage_0 = elevation_0 + inlet_depth
+        stage_1 = elevation_1 + outlet_depth
+ 
+
+        domain_length = 200.0
+        domain_width = 200.0
+
+        #culvert_length = 20.0
+        #culvert_width = 3.66
+        #culvert_height = 3.66
+        culvert_losses = {'inlet':0.5, 'outlet':1.0, 'bend':0.0, 'grate':0.0, 'pier': 0.0, 'other': 0.0}
+        culvert_mannings = 0.013
+        
+        culvert_apron = 0.0
+        enquiry_gap = 5.0
+
+
+
+
+        domain = self._create_domain(d_length=domain_length,
+                                     d_width=domain_width,
+                                     dx = 5.0,
+                                     dy = 5.0,
+                                     elevation_0 = elevation_0,
+                                     elevation_1 = elevation_1,
+                                     stage_0 = stage_0,
+                                     stage_1 = stage_1,
+                                     xvelocity_0 = inlet_velocity,
+                                     xvelocity_1 = outlet_velocity)
+ 
+
+        #print 'Defining Structures'
+        
+        ep0 = numpy.array([domain_length/2-culvert_length/2, 100.0])
+        ep1 = numpy.array([domain_length/2+culvert_length/2, 100.0])
+        
+        
+        culvert = Boyd_box_operator(domain,
+                                    losses=culvert_losses,
+                                    width=culvert_width,
+                                    end_points=[ep0, ep1],
+                                    height=culvert_height,
+                                    apron=culvert_apron,
+                                    enquiry_gap=enquiry_gap,
+                                    use_momentum_jet=False,
+                                    use_velocity_head=True,
+                                    manning=culvert_mannings,
+                                    logging=False,
+                                    label='3.6x1.2RCBC',
+                                    verbose=False)
+
+        #culvert.determine_inflow_outflow()
+        
+        ( Q, v, d ) = culvert.discharge_routine()
+        
+        if verbose:
+            print 'test_boyd_operator_1'
+            print 'expected ',Q_expected,v_expected, d_expected
+            print 'calc ',Q,v,d
+        
+
+        assert numpy.allclose(Q, Q_expected, rtol=2.0e-2) #inflow
+        assert numpy.allclose(v, v_expected, rtol=2.0e-2) #outflow velocity
+        assert numpy.allclose(d, d_expected, rtol=2.0e-2) #depth at outlet used to calc v 
+        
+
+    def test_boyd_12_operator_invert(self):
+        """test_boyd_non_skew
+        
+        This tests the Boyd routine with data obtained from culvertw application 1.1 by IceMindserer  BD Parkinson, 
+        calculation code by MJ Boyd 
+        """
+
+        #verbose = True
+        g=9.81
+        culvert_slope=1  # Downward
+
+        inlet_depth=1.50
+        inlet_velocity= 4.0
+        outlet_depth=0.8
+        outlet_velocity=4.0
+        culvert_length=10.0
+        culvert_width=3.60
+        culvert_height=1.20
+        
+        culvert_type='box'
+        manning=0.013
+        sum_loss=1.5
+
+        inlet_specific_energy=inlet_depth + 0.5*inlet_velocity**2/g 
+        z_in = 10.0
+        z_out = 10.0-culvert_length*culvert_slope/100
+        E_in = z_in+inlet_depth + 0.5*inlet_velocity**2/g
+        E_out = z_out+outlet_depth + 0.5*outlet_velocity**2/g
+        delta_total_energy = E_in-E_out
+
+        invert0 = 20.0
+        invert1 = 30.0
+
+
+        #Q_expected = 13.546
+        #v_expected = 3.136
+        #d_expected = 1.20
+        
+        Q_expected = 0.0
+        v_expected = 0.0
+        d_expected = 0.0
+        
+        elevation_0 = z_in
+        elevation_1 = z_out
+        
+        stage_0 = elevation_0 + inlet_depth
+        stage_1 = elevation_1 + outlet_depth
+ 
+
+        domain_length = 200.0
+        domain_width = 200.0
+
+        #culvert_length = 20.0
+        #culvert_width = 3.66
+        #culvert_height = 3.66
+        culvert_losses = {'inlet':0.5, 'outlet':1.0, 'bend':0.0, 'grate':0.0, 'pier': 0.0, 'other': 0.0}
+        culvert_mannings = 0.013
+        
+        culvert_apron = 0.0
+        enquiry_gap = 5.0
+
+
+
+
+        domain = self._create_domain(d_length=domain_length,
+                                     d_width=domain_width,
+                                     dx = 5.0,
+                                     dy = 5.0,
+                                     elevation_0 = elevation_0,
+                                     elevation_1 = elevation_1,
+                                     stage_0 = stage_0,
+                                     stage_1 = stage_1,
+                                     xvelocity_0 = inlet_velocity,
+                                     xvelocity_1 = outlet_velocity)
+ 
+
+        #print 'Defining Structures'
+        
+        ep0 = numpy.array([domain_length/2-culvert_length/2, 100.0])
+        ep1 = numpy.array([domain_length/2+culvert_length/2, 100.0])
+        
+        
+        culvert = Boyd_box_operator(domain,
+                                    losses=culvert_losses,
+                                    width=culvert_width,
+                                    end_points=[ep0, ep1],
+                                    height=culvert_height,
+                                    apron=culvert_apron,
+                                    #invert_elevations=[elevation_0,elevation_1],
+                                    invert_elevations=[invert0,invert1],
+                                    enquiry_gap=enquiry_gap,
+                                    use_momentum_jet=False,
+                                    use_velocity_head=True,
+                                    manning=culvert_mannings,
+                                    logging=False,
+                                    label='3.6x1.2RCBC',
+                                    verbose=verbose)
+
+        #culvert.determine_inflow_outflow()
+        
+        ( Q, v, d ) = culvert.discharge_routine()
+        
+        if verbose:
+            print 'test_boyd_operator_12_invert'
+            print 'expected ',Q_expected,v_expected, d_expected
+            print 'calc ',Q,v,d
+        
+
+        assert numpy.allclose(Q, Q_expected, rtol=2.0e-2) #inflow
+        assert numpy.allclose(v, v_expected, rtol=2.0e-2) #outflow velocity
+        assert numpy.allclose(d, d_expected, rtol=2.0e-2) #depth at outlet used to calc v 
+        
+       
+# =========================================================================
+if __name__ == "__main__":
+    suite = unittest.makeSuite(Test_boyd_box_operator, 'test')
+    runner = unittest.TextTestRunner()
+    runner.run(suite)
Index: /trunk/anuga_core/source/anuga/structures/test/test_boyd_pipe_operator.py
===================================================================
--- /trunk/anuga_core/source/anuga/structures/test/test_boyd_pipe_operator.py	(revision 9440)
+++ /trunk/anuga_core/source/anuga/structures/test/test_boyd_pipe_operator.py	(revision 9440)
@@ -0,0 +1,482 @@
+#!/usr/bin/env python
+
+
+import unittest
+
+
+from anuga.structures.boyd_pipe_operator import Boyd_pipe_operator
+from anuga.structures.boyd_pipe_operator import boyd_pipe_function
+
+from anuga.abstract_2d_finite_volumes.mesh_factory import rectangular_cross
+from anuga.shallow_water.shallow_water_domain import Domain
+import numpy
+
+verbose = False
+#diameter = width
+
+class Test_boyd_pipe_operator(unittest.TestCase):
+    """
+	Test the boyd box operator, in particular the discharge_routine!
+    """
+
+    def setUp(self):
+        pass
+
+    def tearDown(self):
+        pass
+    
+    
+    def _create_domain(self,d_length,
+                            d_width,
+                            dx,
+                            dy,
+                            elevation_0,
+                            elevation_1,
+                            stage_0,
+                            stage_1,
+                            xvelocity_0 = 0.0,
+                            xvelocity_1 = 0.0,
+                            yvelocity_0 = 0.0,
+                            yvelocity_1 = 0.0):
+        
+        points, vertices, boundary = rectangular_cross(int(d_length/dx), int(d_width/dy),
+                                                        len1=d_length, len2=d_width)
+        domain = Domain(points, vertices, boundary)   
+        domain.set_name('Test_Outlet_Inlet')                 # Output name
+        domain.set_store()
+        domain.set_default_order(2)
+        domain.H0 = 0.01
+        domain.tight_slope_limiters = 1
+
+        #print 'Size', len(domain)
+
+        #------------------------------------------------------------------------------
+        # Setup initial conditions
+        #------------------------------------------------------------------------------
+
+        def elevation(x, y):
+            """Set up a elevation
+            """
+            
+            z = numpy.zeros(x.shape,dtype='d')
+            z[:] = elevation_0
+            
+            numpy.putmask(z, x > d_length/2, elevation_1)
+    
+            return z
+            
+        def stage(x,y):
+            """Set up stage
+            """
+            z = numpy.zeros(x.shape,dtype='d')
+            z[:] = stage_0
+            
+            numpy.putmask(z, x > d_length/2, stage_1)
+
+            return z
+        
+        def xmom(x,y):
+            """Set up xmomentum
+            """
+            z = numpy.zeros(x.shape,dtype='d')
+            z[:] = xvelocity_0*(stage_0-elevation_0)
+            
+            numpy.putmask(z, x > d_length/2, xvelocity_1*(stage_1-elevation_1) )
+
+            return z
+        
+        def ymom(x,y):
+            """Set up ymomentum
+            """
+            z = numpy.zeros(x.shape,dtype='d')
+            z[:] = yvelocity_0*(stage_0-elevation_0)
+            
+            numpy.putmask(z, x > d_length/2, yvelocity_1*(stage_1-elevation_1) )
+
+            return z
+            
+        #print 'Setting Quantities....'
+        domain.set_quantity('elevation', elevation)  # Use function for elevation
+        domain.set_quantity('stage',  stage)   # Use function for elevation
+        domain.set_quantity('xmomentum',  xmom) 
+        domain.set_quantity('ymomentum',  ymom) 
+        
+        return domain
+
+    def test_boyd_non_skew1(self):
+        """test_boyd_non_skew
+        
+        This tests the Boyd routine with data obtained from culvertw application 1.1 by IceMindserer  BD Parkinson, 
+        calculation code by MJ Boyd 
+        """
+
+        stage_0 = 11.5
+        stage_1 = 10.0
+        elevation_0 = 11.0
+        elevation_1 = 10.0
+
+        domain_length = 200.0
+        domain_width = 200.0
+
+        culvert_length = 20.0
+        culvert_width = 1.2
+        ##culvert_height = 3.66
+        culvert_losses = {'inlet':0.5, 'outlet':1.0, 'bend':0.0, 'grate':0.0, 'pier': 0.0, 'other': 0.0}
+        culvert_mannings = 0.013
+        
+        culvert_apron = 0.0
+        enquiry_gap = 5.0
+
+        
+        expected_Q = 0.50
+        expected_v = 0.78
+        expected_d = 0.66
+        
+
+        domain = self._create_domain(d_length=domain_length,
+                                     d_width=domain_width,
+                                     dx = 5.0,
+                                     dy = 5.0,
+                                     elevation_0 = elevation_0,
+                                     elevation_1 = elevation_1,
+                                     stage_0 = stage_0,
+                                     stage_1 = stage_1)
+ 
+
+        #print 'Defining Structures'
+        
+        ep0 = numpy.array([domain_length/2-culvert_length/2, 100.0])
+        ep1 = numpy.array([domain_length/2+culvert_length/2, 100.0])
+        
+        
+        culvert = Boyd_pipe_operator(domain,
+                                    losses=culvert_losses,
+                                    diameter=culvert_width,
+                                    end_points=[ep0, ep1],
+                                    #height=culvert_height,
+                                    apron=culvert_apron,
+                                    enquiry_gap=enquiry_gap,
+                                    use_momentum_jet=False,
+                                    use_velocity_head=False,
+                                    manning=culvert_mannings,
+                                    logging=False,
+                                    label='1.2pipe',
+                                    verbose=False)
+
+        #culvert.determine_inflow_outflow()
+        
+        ( Q, v, d ) = culvert.discharge_routine()
+        
+        if verbose:
+            print 'test_boyd_non_skew'
+            print 'Q: ', Q, 'expected_Q: ', expected_Q
+            print 'v: ', v, 'expected_v: ', expected_v
+            print 'd: ', d, 'expected_d: ', expected_d
+
+        assert numpy.allclose(Q, expected_Q, rtol=1.0e-2) #inflow
+        assert numpy.allclose(v, expected_v, rtol=1.0e-2) #outflow velocity
+        assert numpy.allclose(d, expected_d, rtol=1.0e-2) #depth at outlet used to calc v 
+        
+    def test_boyd_non_skew2(self):
+        """test_boyd_non_skew
+        
+        This tests the Boyd routine with data obtained from culvertw application 1.1 by IceMindserer  BD Parkinson, 
+        calculation code by MJ Boyd 
+        """
+
+        stage_0 = 12.2
+        stage_1 = 10.0
+        elevation_0 = 11.0
+        elevation_1 = 10.0
+
+        domain_length = 200.0
+        domain_width = 200.0
+
+        culvert_length = 20.0
+        culvert_width = 1.2
+        ##culvert_height = 3.66
+        culvert_losses = {'inlet':0.5, 'outlet':1.0, 'bend':0.0, 'grate':0.0, 'pier': 0.0, 'other': 0.0}
+        culvert_mannings = 0.013
+        
+        culvert_apron = 0.0
+        enquiry_gap = 5.0
+
+        
+        expected_Q = 2.08
+        expected_v = 2.13
+        expected_d = 0.96
+        
+
+        domain = self._create_domain(d_length=domain_length,
+                                     d_width=domain_width,
+                                     dx = 5.0,
+                                     dy = 5.0,
+                                     elevation_0 = elevation_0,
+                                     elevation_1 = elevation_1,
+                                     stage_0 = stage_0,
+                                     stage_1 = stage_1)
+ 
+
+        #print 'Defining Structures'
+        
+        ep0 = numpy.array([domain_length/2-culvert_length/2, 100.0])
+        ep1 = numpy.array([domain_length/2+culvert_length/2, 100.0])
+        
+        
+        culvert = Boyd_pipe_operator(domain,
+                                    losses=culvert_losses,
+                                    diameter=culvert_width,
+                                    end_points=[ep0, ep1],
+                                    #height=culvert_height,
+                                    apron=culvert_apron,
+                                    enquiry_gap=enquiry_gap,
+                                    use_momentum_jet=False,
+                                    use_velocity_head=False,
+                                    manning=culvert_mannings,
+                                    logging=False,
+                                    label='1.2pipe',
+                                    verbose=False)
+
+        #culvert.determine_inflow_outflow()
+        
+        ( Q, v, d ) = culvert.discharge_routine()
+        
+        if verbose:
+            print 'test_boyd_non_skew2'
+            print 'Q: ', Q, 'expected_Q: ', expected_Q
+            print 'v: ', v, 'expected_v: ', expected_v
+            print 'd: ', d, 'expected_d: ', expected_d
+
+        assert numpy.allclose(Q, expected_Q, rtol=1.0e-2) #inflow
+        assert numpy.allclose(v, expected_v, rtol=1.0e-2) #outflow velocity
+        assert numpy.allclose(d, expected_d, rtol=1.0e-2) #depth at outlet used to calc v  
+        
+    def test_boyd_non_skew3(self):
+        """test_boyd_non_skew
+        
+        This tests the Boyd routine with data obtained from culvertw application 1.1 by IceMindserer  BD Parkinson, 
+        calculation code by MJ Boyd 
+        """
+
+        stage_0 = 15.0
+        stage_1 = 10.0
+        elevation_0 = 11.0
+        elevation_1 = 10.0
+
+        domain_length = 200.0
+        domain_width = 200.0
+
+        culvert_length = 20.0
+        culvert_width = 1.2
+        ##culvert_height = 3.66
+        culvert_losses = {'inlet':0.5, 'outlet':1.0, 'bend':0.0, 'grate':0.0, 'pier': 0.0, 'other': 0.0}
+        culvert_mannings = 0.013
+        
+        culvert_apron = 0.0
+        enquiry_gap = 5.0
+
+        
+        expected_Q = 5.59
+        expected_v = 4.94
+        expected_d = 1.20
+        
+
+        domain = self._create_domain(d_length=domain_length,
+                                     d_width=domain_width,
+                                     dx = 5.0,
+                                     dy = 5.0,
+                                     elevation_0 = elevation_0,
+                                     elevation_1 = elevation_1,
+                                     stage_0 = stage_0,
+                                     stage_1 = stage_1)
+ 
+
+        #print 'Defining Structures'
+        
+        ep0 = numpy.array([domain_length/2-culvert_length/2, 100.0])
+        ep1 = numpy.array([domain_length/2+culvert_length/2, 100.0])
+        
+        
+        culvert = Boyd_pipe_operator(domain,
+                                    losses=culvert_losses,
+                                    diameter=culvert_width,
+                                    end_points=[ep0, ep1],
+                                    #height=culvert_height,
+                                    apron=culvert_apron,
+                                    enquiry_gap=enquiry_gap,
+                                    use_momentum_jet=False,
+                                    use_velocity_head=False,
+                                    manning=culvert_mannings,
+                                    logging=False,
+                                    label='1.2pipe',
+                                    verbose=False)
+
+        #culvert.determine_inflow_outflow()
+        
+        ( Q, v, d ) = culvert.discharge_routine()
+        
+        if verbose:
+            print 'test_boyd_non_skew3'
+            print 'Q: ', Q, 'expected_Q: ', expected_Q
+            print 'v: ', v, 'expected_v: ', expected_v
+            print 'd: ', d, 'expected_d: ', expected_d
+
+ 
+        assert numpy.allclose(Q, expected_Q, rtol=1.0e-2) #inflow
+        assert numpy.allclose(v, expected_v, rtol=1.0e-2) #outflow velocity
+        assert numpy.allclose(d, expected_d, rtol=1.0e-2) #depth at outlet used to calc v 
+        
+    def test_boyd_non_skew4(self):
+        """test_boyd_non_skew
+        
+        This tests the Boyd routine with data obtained from culvertw application 1.1 by IceMindserer  BD Parkinson, 
+        calculation code by MJ Boyd 
+        """
+
+        stage_0 = 12.2 #change
+        stage_1 = 11.2 #change
+        elevation_0 = 11.0
+        elevation_1 = 10.0
+
+        domain_length = 200.0
+        domain_width = 200.0
+
+        culvert_length = 20.0
+        culvert_width = 1.2
+        ##culvert_height = 3.66
+        culvert_losses = {'inlet':0.5, 'outlet':1.0, 'bend':0.0, 'grate':0.0, 'pier': 0.0, 'other': 0.0}
+        culvert_mannings = 0.013
+        
+        culvert_apron = 0.0
+        enquiry_gap = 5.0
+
+        
+        expected_Q = 2.08
+        expected_v = 2.13
+        expected_d = 0.96
+        
+
+        domain = self._create_domain(d_length=domain_length,
+                                     d_width=domain_width,
+                                     dx = 5.0,
+                                     dy = 5.0,
+                                     elevation_0 = elevation_0,
+                                     elevation_1 = elevation_1,
+                                     stage_0 = stage_0,
+                                     stage_1 = stage_1)
+ 
+
+        #print 'Defining Structures'
+        
+        ep0 = numpy.array([domain_length/2-culvert_length/2, 100.0])
+        ep1 = numpy.array([domain_length/2+culvert_length/2, 100.0])
+        
+        
+        culvert = Boyd_pipe_operator(domain,
+                                    losses=culvert_losses,
+                                    diameter=culvert_width,
+                                    end_points=[ep0, ep1],
+                                    #height=culvert_height,
+                                    apron=culvert_apron,
+                                    enquiry_gap=enquiry_gap,
+                                    use_momentum_jet=False,
+                                    use_velocity_head=False,
+                                    manning=culvert_mannings,
+                                    logging=False,
+                                    label='1.2pipe',
+                                    verbose=False)
+
+        #culvert.determine_inflow_outflow()
+        
+        ( Q, v, d ) = culvert.discharge_routine()
+        
+        if verbose:
+            print 'test_boyd_non_skew4'
+            print 'Q: ', Q, 'expected_Q: ', expected_Q
+            print 'v: ', v, 'expected_v: ', expected_v
+            print 'd: ', d, 'expected_d: ', expected_d
+
+
+        assert numpy.allclose(Q, expected_Q, rtol=1.0e-2) #inflow
+        assert numpy.allclose(v, expected_v, rtol=1.0e-2) #outflow velocity
+        assert numpy.allclose(d, expected_d, rtol=1.0e-2) #depth at outlet used to calc v 
+        
+    def test_boyd_non_skew5(self):
+        """test_boyd_non_skew
+        
+        This tests the Boyd routine with data obtained from culvertw application 1.1 by IceMindserer  BD Parkinson, 
+        calculation code by MJ Boyd 
+        """
+
+        stage_0 = 15.0 #change
+        stage_1 = 14.0 #change
+        elevation_0 = 11.0
+        elevation_1 = 10.0
+
+        domain_length = 200.0
+        domain_width = 200.0
+
+        culvert_length = 20.0
+        culvert_width = 1.2
+        ##culvert_height = 3.66
+        culvert_losses = {'inlet':0.5, 'outlet':1.0, 'bend':0.0, 'grate':0.0, 'pier': 0.0, 'other': 0.0}
+        culvert_mannings = 0.013
+        
+        culvert_apron = 0.0
+        enquiry_gap = 5.0
+
+        
+        expected_Q = 3.70
+        expected_v = 3.27
+        expected_d = 1.20
+        
+
+        domain = self._create_domain(d_length=domain_length,
+                                     d_width=domain_width,
+                                     dx = 5.0,
+                                     dy = 5.0,
+                                     elevation_0 = elevation_0,
+                                     elevation_1 = elevation_1,
+                                     stage_0 = stage_0,
+                                     stage_1 = stage_1)
+ 
+
+        #print 'Defining Structures'
+        
+        ep0 = numpy.array([domain_length/2-culvert_length/2, 100.0])
+        ep1 = numpy.array([domain_length/2+culvert_length/2, 100.0])
+        
+        
+        culvert = Boyd_pipe_operator(domain,
+                                    losses=culvert_losses,
+                                    diameter=culvert_width,
+                                    end_points=[ep0, ep1],
+                                    #height=culvert_height,
+                                    apron=culvert_apron,
+                                    enquiry_gap=enquiry_gap,
+                                    use_momentum_jet=False,
+                                    use_velocity_head=False,
+                                    manning=culvert_mannings,
+                                    logging=False,
+                                    label='1.2pipe',
+                                    verbose=False)
+
+        #culvert.determine_inflow_outflow()
+        
+        ( Q, v, d ) = culvert.discharge_routine()
+        
+        if verbose:
+            print 'test_boyd_non_skew5'
+            print 'Q: ', Q, 'expected_Q: ', expected_Q
+            print 'v: ', v, 'expected_v: ', expected_v
+            print 'd: ', d, 'expected_d: ', expected_d
+
+
+        assert numpy.allclose(Q, expected_Q, rtol=1.0e-2) #inflow
+        assert numpy.allclose(v, expected_v, rtol=1.0e-2) #outflow velocity
+        assert numpy.allclose(d, expected_d, rtol=1.0e-2) #depth at outlet used to calc v  
+# =========================================================================
+if __name__ == "__main__":
+    suite = unittest.makeSuite(Test_boyd_pipe_operator, 'test')
+    runner = unittest.TextTestRunner()
+    runner.run(suite)
Index: /trunk/anuga_core/source/anuga/structures/test/test_inlet_operator.py
===================================================================
--- /trunk/anuga_core/source/anuga/structures/test/test_inlet_operator.py	(revision 9440)
+++ /trunk/anuga_core/source/anuga/structures/test/test_inlet_operator.py	(revision 9440)
@@ -0,0 +1,307 @@
+#!/usr/bin/env python
+
+
+import unittest
+import os.path
+import sys
+
+import numpy
+import anuga
+
+from anuga.abstract_2d_finite_volumes.mesh_factory import rectangular_cross
+from anuga.shallow_water.shallow_water_domain import Domain
+from anuga.abstract_2d_finite_volumes.util import file_function
+
+from anuga.structures.inlet_operator import Inlet_operator
+
+class Test_inlet_operator(unittest.TestCase):
+    """
+	Test the boyd box operator, in particular the discharge_routine!
+    """
+
+    def setUp(self):
+        pass
+
+    def tearDown(self):
+        pass
+    
+    
+    def _create_domain(self,d_length,
+                            d_width,
+                            dx,
+                            dy,
+                            elevation_0,
+                            elevation_1,
+                            stage_0,
+                            stage_1):
+        
+        points, vertices, boundary = rectangular_cross(int(d_length/dx), int(d_width/dy),
+                                                        len1=d_length, len2=d_width)
+        domain = Domain(points, vertices, boundary)   
+        domain.set_name('Test_Outlet_Inlet')                 # Output name
+        domain.set_store()
+        domain.set_default_order(2)
+        domain.H0 = 0.01
+        domain.tight_slope_limiters = 1
+
+        #print 'Size', len(domain)
+
+        #------------------------------------------------------------------------------
+        # Setup initial conditions
+        #------------------------------------------------------------------------------
+
+        def elevation(x, y):
+            """Set up a elevation
+            """
+            
+            z = numpy.zeros(x.shape,dtype='d')
+            z[:] = elevation_0
+            
+            numpy.putmask(z, x > d_length/2, elevation_1)
+    
+            return z
+            
+        def stage(x,y):
+            """Set up stage
+            """
+            z = numpy.zeros(x.shape,dtype='d')
+            z[:] = stage_0
+            
+            numpy.putmask(z, x > d_length/2, stage_1)
+
+            return z
+            
+        #print 'Setting Quantities....'
+        domain.set_quantity('elevation', elevation)  # Use function for elevation
+        domain.set_quantity('stage',  stage)   # Use function for elevation
+
+        Br = anuga.Reflective_boundary(domain)
+        domain.set_boundary({'left': Br, 'right': Br, 'top': Br, 'bottom': Br})
+        
+        return domain
+
+    def test_inlet_constant_Q(self):
+        """test_inlet_Q
+        
+        This tests that the inlet operator adds the correct amount of water
+        """
+
+        stage_0 = 11.0
+        stage_1 = 10.0
+        elevation_0 = 10.0
+        elevation_1 = 10.0
+
+        domain_length = 200.0
+        domain_width = 200.0
+        
+
+        domain = self._create_domain(d_length=domain_length,
+                                     d_width=domain_width,
+                                     dx = 10.0,
+                                     dy = 10.0,
+                                     elevation_0 = elevation_0,
+                                     elevation_1 = elevation_1,
+                                     stage_0 = stage_0,
+                                     stage_1 = stage_1)
+
+        vol0 = domain.compute_total_volume()
+
+        finaltime = 3.0
+        line1 = [[95.0, 10.0], [105.0, 10.0]]
+        Q1 = 5.00
+        
+        line2 = [[10.0, 90.0], [20.0, 90.0]]
+        Q2 = 10.0
+        
+        Inlet_operator(domain, line1, Q1, logging=True)
+        Inlet_operator(domain, line2, Q2)
+
+        for t in domain.evolve(yieldstep = 1.0, finaltime = finaltime):
+            #domain.write_time()
+            #print domain.volumetric_balance_statistics()
+            pass
+ 
+
+        vol1 = domain.compute_total_volume()
+
+        assert numpy.allclose((Q1+Q2)*finaltime, vol1-vol0, rtol=1.0e-8) 
+        assert numpy.allclose((Q1+Q2)*finaltime, domain.fractional_step_volume_integral, rtol=1.0e-8) 
+
+
+
+    def test_inlet_constant_Q_polygon(self):
+        """test_inlet_Q
+
+        This tests that the inlet operator adds the correct amount of water
+        """
+
+        stage_0 = 11.0
+        stage_1 = 10.0
+        elevation_0 = 10.0
+        elevation_1 = 10.0
+
+        domain_length = 200.0
+        domain_width = 200.0
+
+
+        domain = self._create_domain(d_length=domain_length,
+                                     d_width=domain_width,
+                                     dx = 10.0,
+                                     dy = 10.0,
+                                     elevation_0 = elevation_0,
+                                     elevation_1 = elevation_1,
+                                     stage_0 = stage_0,
+                                     stage_1 = stage_1)
+
+        vol0 = domain.compute_total_volume()
+
+        finaltime = 3.0
+        poly1 = [[95.0, 10.0], [105.0, 10.0], [105, 20.0], [95.0, 20.0]]
+        Q1 = 5.00
+
+
+        Inlet_operator(domain, poly1, Q1, logging=True)
+
+
+        for t in domain.evolve(yieldstep = 1.0, finaltime = finaltime):
+            #domain.write_time()
+            #print domain.volumetric_balance_statistics()
+            pass
+
+
+        vol1 = domain.compute_total_volume()
+
+        assert numpy.allclose((Q1)*finaltime, vol1-vol0, rtol=1.0e-8)
+        assert numpy.allclose((Q1)*finaltime, domain.fractional_step_volume_integral, rtol=1.0e-8) 
+
+
+
+    def test_inlet_variable_Q(self):
+        """test_inlet_Q
+        
+        This tests that the inlet operator adds the correct amount of water
+        """
+
+        stage_0 = 11.0
+        stage_1 = 10.0
+        elevation_0 = 10.0
+        elevation_1 = 10.0
+
+        domain_length = 200.0
+        domain_width = 200.0
+        
+
+        domain = self._create_domain(d_length=domain_length,
+                                     d_width=domain_width,
+                                     dx = 10.0,
+                                     dy = 10.0,
+                                     elevation_0 = elevation_0,
+                                     elevation_1 = elevation_1,
+                                     stage_0 = stage_0,
+                                     stage_1 = stage_1)
+
+        vol0 = domain.compute_total_volume()
+
+        finaltime = 3.0
+
+        #Make sure we are inthe right directory to find the
+        #time series data for the inlets
+        import os
+        baseDir = os.getcwd()
+
+        try:
+            os.chdir('structures')
+        except:
+            pass
+
+        line1 = [[95.0, 10.0], [105.0, 10.0]]
+        Q1 = file_function(filename='inlet_operator_test1.tms', quantities=['hydrograph'])
+        
+        line2 = [[10.0, 90.0], [20.0, 90.0]]
+        Q2 = file_function(filename='inlet_operator_test2.tms', quantities=['hydrograph'])
+
+        os.chdir(baseDir)
+        
+        Inlet_operator(domain, line1, Q1)
+        Inlet_operator(domain, line2, Q2)
+
+        for t in domain.evolve(yieldstep = 1.0, finaltime = finaltime):
+            #domain.write_time()
+            #print domain.volumetric_balance_statistics()
+            pass
+ 
+
+        vol1 = domain.compute_total_volume()
+
+        #print vol1-vol0
+        
+        assert numpy.allclose(13.5, vol1-vol0, rtol=1.0e-8) 
+        assert numpy.allclose(vol1-vol0, domain.fractional_step_volume_integral, rtol=1.0e-8) 
+                
+    def test_inlet_variable_Q_default(self):
+        """test_inlet_Q
+
+        This tests that the inlet operator adds the correct amount of water
+        """
+
+        stage_0 = 11.0
+        stage_1 = 10.0
+        elevation_0 = 10.0
+        elevation_1 = 10.0
+
+        domain_length = 200.0
+        domain_width = 200.0
+
+
+        domain = self._create_domain(d_length=domain_length,
+                                     d_width=domain_width,
+                                     dx = 10.0,
+                                     dy = 10.0,
+                                     elevation_0 = elevation_0,
+                                     elevation_1 = elevation_1,
+                                     stage_0 = stage_0,
+                                     stage_1 = stage_1)
+
+        vol0 = domain.compute_total_volume()
+
+        finaltime = 5.0
+
+        #Make sure we are inthe right directory to find the
+        #time series data for the inlets
+        import os
+        baseDir = os.getcwd()
+
+        try:
+            os.chdir('structures')
+        except:
+            pass
+
+        line1 = [[95.0, 10.0], [105.0, 10.0]]
+        Q1 = file_function(filename='inlet_operator_test1.tms', quantities=['hydrograph'])
+
+        line2 = [[10.0, 90.0], [20.0, 90.0]]
+        Q2 = file_function(filename='inlet_operator_test2.tms', quantities=['hydrograph'])
+
+        os.chdir(baseDir)
+
+        Inlet_operator(domain, line1, Q1, default=6)
+        Inlet_operator(domain, line2, Q2, default=3)
+
+        for t in domain.evolve(yieldstep = 1.0, finaltime = finaltime):
+            #domain.write_time()
+            #print domain.volumetric_balance_statistics()
+            pass
+
+
+        vol1 = domain.compute_total_volume()
+
+        #print vol1-vol0
+
+        assert numpy.allclose(31.5, vol1-vol0, rtol=1.0e-8)
+        assert numpy.allclose(vol1-vol0, domain.fractional_step_volume_integral, rtol=1.0e-8) 
+
+# =========================================================================
+if __name__ == "__main__":
+    suite = unittest.makeSuite(Test_inlet_operator, 'test')
+    runner = unittest.TextTestRunner()
+    runner.run(suite)
Index: /trunk/anuga_core/source/anuga/structures/test/test_riverwall_structure.py
===================================================================
--- /trunk/anuga_core/source/anuga/structures/test/test_riverwall_structure.py	(revision 9440)
+++ /trunk/anuga_core/source/anuga/structures/test/test_riverwall_structure.py	(revision 9440)
@@ -0,0 +1,611 @@
+#!/usr/bin/env python
+
+
+import unittest
+
+
+#from anuga.structures.riverwall import Boyd_box_operator
+#from anuga.structures.riverwall import boyd_box_function
+
+#from anuga.abstract_2d_finite_volumes.mesh_factory import rectangular_cross
+import anuga
+import numpy
+from anuga.shallow_water.shallow_water_domain import Domain
+from anuga.utilities import plot_utils as util
+from anuga.config import g
+
+## Generic data for scenario
+
+verbose = False
+boundaryPolygon=[ [0., 0.], [0., 100.], [100.0, 100.0], [100.0, 0.0]]
+wallLoc=50.
+# The boundary polygon + riverwall breaks the mesh into multiple regions
+# Must define the resolution in these areas with an xy point + maximum area
+# Otherwise triangle.c gets confused
+regionPtAreas=[ [99., 99., 20.0*20.0*0.5],
+                [1., 1., 20.0*20.0*0.5]]
+
+class Test_riverwall_structure(unittest.TestCase):
+    """
+	Test the riverwall structure
+    """
+
+    def setUp(self):
+        pass
+
+    def tearDown(self):
+        pass
+    
+    def create_domain_DE0(self, wallHeight, InitialOceanStage, InitialLandStage, riverWall=None, riverWall_Par=None):
+        # Riverwall = list of lists, each with a set of x,y,z (and optional QFactor) values
+
+        if(riverWall is None):
+            riverWall={ 'centralWall':
+                            [ [wallLoc, 0.0, wallHeight],
+                              [wallLoc, 100.0, wallHeight]] 
+                      }
+        if(riverWall_Par is None):
+            riverWall_Par={'centralWall':{'Qfactor':1.0}}
+        # Make the domain
+        anuga.create_mesh_from_regions(boundaryPolygon, 
+                                 boundary_tags={'left': [0],
+                                                'top': [1],
+                                                'right': [2],
+                                                'bottom': [3]},
+                                   maximum_triangle_area = 200.,
+                                   minimum_triangle_angle = 28.0,
+                                   filename = 'testRiverwall.msh',
+                                   interior_regions =[ ], #[ [higherResPolygon, 1.*1.*0.5],
+                                                          #  [midResPolygon, 3.0*3.0*0.5]],
+                                   breaklines=riverWall.values(),
+                                   use_cache=False,
+                                   verbose=verbose,
+                                   regionPtArea=regionPtAreas)
+
+        domain=anuga.create_domain_from_file('testRiverwall.msh')
+
+        # 05/05/2014 -- riverwalls only work with DE0 and DE1
+        domain.set_flow_algorithm('DE0')
+        domain.set_name('test_riverwall')
+
+        domain.set_store_vertices_uniquely()
+       
+        def topography(x,y):
+            return -x/150. 
+
+        def stagefun(x,y):
+            stg=InitialOceanStage*(x>=50.) + InitialLandStage*(x<50.)
+            return stg 
+
+        # NOTE: Setting quantities at centroids is important for exactness of tests
+        domain.set_quantity('elevation',topography,location='centroids')     
+        domain.set_quantity('friction',0.03)             
+        domain.set_quantity('stage', stagefun,location='centroids')            
+        
+        domain.riverwallData.create_riverwalls(riverWall,riverWall_Par,verbose=verbose) 
+
+        # Boundary conditions
+        Br=anuga.Reflective_boundary(domain)
+        domain.set_boundary({'left': Br, 'right': Br, 'top': Br, 'bottom':Br})
+
+        return domain
+ 
+    def create_domain_DE1(self, wallHeight, InitialOceanStage, InitialLandStage):
+        # Riverwall = list of lists, each with a set of x,y,z (and optional QFactor) values
+        riverWall={ 'centralWall':
+                        [ [wallLoc, 0.0, wallHeight],
+                          [wallLoc, 100.0, wallHeight]] 
+                  }
+        riverWall_Par={'centralWall':{'Qfactor':1.0}}
+        # Make the domain
+        anuga.create_mesh_from_regions(boundaryPolygon, 
+                                 boundary_tags={'left': [0],
+                                                'top': [1],
+                                                'right': [2],
+                                                'bottom': [3]},
+                                   maximum_triangle_area = 200.,
+                                   minimum_triangle_angle = 28.0,
+                                   filename = 'testRiverwall.msh',
+                                   interior_regions =[ ], #[ [higherResPolygon, 1.*1.*0.5],
+                                                          #  [midResPolygon, 3.0*3.0*0.5]],
+                                   breaklines=riverWall.values(),
+                                   use_cache=False,
+                                   verbose=verbose,
+                                   regionPtArea=regionPtAreas)
+
+        domain=anuga.create_domain_from_file('testRiverwall.msh')
+
+        # 05/05/2014 -- riverwalls only work with DE0 and DE1
+        domain.set_flow_algorithm('DE1')
+        domain.set_name('test_riverwall')
+
+        domain.set_store_vertices_uniquely()
+       
+        def topography(x,y):
+            return -x/150. 
+
+        def stagefun(x,y):
+            stg=InitialOceanStage*(x>=50.) + InitialLandStage*(x<50.)
+            return stg 
+
+        # NOTE: Setting quantities at centroids is important for exactness of tests
+        domain.set_quantity('elevation',topography,location='centroids')     
+        domain.set_quantity('friction',0.03)             
+        domain.set_quantity('stage', stagefun,location='centroids')            
+        
+        domain.riverwallData.create_riverwalls(riverWall,riverWall_Par,verbose=verbose) 
+
+        # Boundary conditions
+        Br=anuga.Reflective_boundary(domain)
+        domain.set_boundary({'left': Br, 'right': Br, 'top': Br, 'bottom':Br})
+
+        return domain
+           
+    def test_noflux_riverwall_DE1(self):
+        """test_noflux_riverwall
+            
+            Tests that the riverwall blocks water when the stage is < wall height 
+            
+        """
+        wallHeight=-0.2
+        InitialOceanStage=-0.3
+        InitialLandStage=-999999.
+       
+        domain=self.create_domain_DE1(wallHeight,InitialOceanStage, InitialLandStage) 
+
+        # Run the model for a few seconds, and check that no water has flowed past the riverwall 
+        for t in domain.evolve(yieldstep=10.0,finaltime=10.0):
+            if(verbose): 
+                print domain.timestepping_statistics()
+
+        # Indices landward of the riverwall
+        landInds=(domain.centroid_coordinates[:,0]<50.).nonzero()[0]
+        # Compute volume of water landward of riverwall
+        landVol=domain.quantities['height'].centroid_values[landInds]*domain.areas[landInds]            
+        landVol=landVol.sum()
+        
+        if(verbose):
+            print 'Land Vol: ', landVol, 'theoretical vol: ', 0.
+
+        assert numpy.allclose(landVol,0., atol=1.0e-12)
+        
+    def test_simpleflux_riverwall_DE1(self):
+        """test_simpleflux_riverwall
+            
+            Tests that the riverwall flux (when dry on one edge) is
+            2/3*H*sqrt(2/3*g*H)
+            
+        """
+        wallHeight=2.
+        InitialOceanStage=2.50
+        InitialLandStage=-999999.
+       
+        domain=self.create_domain_DE1(wallHeight,InitialOceanStage, InitialLandStage) 
+
+        # Run the model for a few fractions of a second
+        # Any longer, and the evolution of stage starts causing
+        # significant changes to the flow
+        yst=1.0e-04
+        ft=1.0e-03
+        for t in domain.evolve(yieldstep=yst,finaltime=ft):
+            if(verbose):
+                print domain.timestepping_statistics()
+
+        # Compare with theoretical result
+        L= 100. # Length of riverwall
+        H=InitialOceanStage-wallHeight # Upstream head
+        dt=ft
+        theoretical_flux_vol=dt*L*2./3.*H*(2./3.*g*H)**0.5
+
+        # Indices landward of the riverwall
+        landInds=(domain.centroid_coordinates[:,0]<50.).nonzero()[0]
+        # Compute volume of water landward of riverwall
+        landVol=domain.quantities['height'].centroid_values[landInds]*domain.areas[landInds]            
+        landVol=landVol.sum()
+
+        if(verbose):
+            print 'Land Vol: ', landVol, 'theoretical vol: ', theoretical_flux_vol
+
+        assert numpy.allclose(landVol,theoretical_flux_vol, rtol=1.0e-03)
+    
+    def test_simpleflux_riverwall_with_Qfactor_DE1(self):
+        """test_simpleflux_riverwall with Qfactor != 1.0
+            
+            Tests that the riverwall flux (when dry on one edge) is
+            2/3*H*sqrt(2/3*g*H)*Qfactor
+            
+        """
+        wallHeight=2.
+        InitialOceanStage=2.50
+        InitialLandStage=-999999.
+       
+        domain=self.create_domain_DE1(wallHeight,InitialOceanStage, InitialLandStage) 
+        # Redefine the riverwall, with 2x the discharge Qfactor
+        riverWall={ 'centralWall':
+                        [ [wallLoc, 0.0, wallHeight],
+                          [wallLoc, 100.0, wallHeight]] 
+                  }
+        Qmult=2.0
+        riverWall_Par={'centralWall':{'Qfactor':Qmult}}
+        domain.riverwallData.create_riverwalls(riverWall,riverWall_Par,verbose=verbose)
+
+        #import pdb
+        #pdb.set_trace()
+
+        # Run the model for a few fractions of a second
+        # Any longer, and the evolution of stage starts causing
+        # significant changes to the flow
+        yst=1.0e-04
+        ft=1.0e-03
+        for t in domain.evolve(yieldstep=yst,finaltime=ft):
+            if(verbose):
+                print domain.timestepping_statistics()
+
+        # Compare with theoretical result
+        L= 100. # Length of riverwall
+        H=InitialOceanStage-wallHeight # Upstream head
+        dt=ft
+        theoretical_flux_vol=Qmult*dt*L*2./3.*H*(2./3.*g*H)**0.5
+
+        # Indices landward of the riverwall
+        landInds=(domain.centroid_coordinates[:,0]<50.).nonzero()[0]
+        # Compute volume of water landward of riverwall
+        landVol=domain.quantities['height'].centroid_values[landInds]*domain.areas[landInds]            
+        landVol=landVol.sum()
+
+        #import pdb
+        #pdb.set_trace()
+        
+        if(verbose):
+            print 'Land Vol: ', landVol, 'theoretical vol: ', theoretical_flux_vol
+
+        assert numpy.allclose(landVol,theoretical_flux_vol, rtol=1.0e-03)
+
+   
+    def test_submergeflux_riverwall_DE1(self):
+        """test_submergedflux_riverwall
+            
+            Tests that the riverwall flux is
+            Q1*(1-Q2/Q1)**(0.385)
+
+            Where Q1, Q2 =2/3*H*sqrt(2/3*g*H)
+             with H computed from the smallest (Q2) / largest (Q1) head side
+        """
+        wallHeight=20.
+        InitialOceanStage=20.50
+        InitialLandStage=20.44
+       
+        domain=self.create_domain_DE1(wallHeight,InitialOceanStage, InitialLandStage) 
+
+        # Indices landward of the riverwall
+        landInds=(domain.centroid_coordinates[:,0]<50.).nonzero()[0]
+        InitialHeight=(domain.quantities['stage'].centroid_values[landInds]-domain.quantities['elevation'].centroid_values[landInds])
+        InitialLandVol=InitialHeight*(InitialHeight>0.)*domain.areas[landInds]            
+        InitialLandVol=InitialLandVol.sum()
+
+        # Run the model for a few fractions of a second
+        # Any longer, and the evolution of stage starts causing
+        # significant changes to the flow
+        yst=1.0e-04
+        ft=1.0e-03
+        for t in domain.evolve(yieldstep=yst,finaltime=ft):
+            if(verbose):
+                print domain.timestepping_statistics()
+
+        # Compare with theoretical result
+        L= 100. # Length of riverwall
+        dt=ft
+        H1=max(InitialOceanStage-wallHeight,0.) # Upstream head
+        H2=max(InitialLandStage-wallHeight,0.) # Downstream head
+
+        Q1=2./3.*H1*(2./3.*g*H1)**0.5
+        Q2=2./3.*H2*(2./3.*g*H2)**0.5
+
+        theoretical_flux_vol=dt*L*Q1*(1.-Q2/Q1)**0.385
+
+        # Compute volume of water landward of riverwall
+        FinalLandVol=domain.quantities['height'].centroid_values[landInds]*domain.areas[landInds]            
+        FinalLandVol=FinalLandVol.sum()
+
+        landVol=FinalLandVol-InitialLandVol
+
+        #import pdb
+        #pdb.set_trace()
+        
+        if(verbose):
+            print 'Land Vol: ', landVol, 'theoretical vol: ', theoretical_flux_vol
+
+        assert numpy.allclose(landVol,theoretical_flux_vol, rtol=1.0e-03)
+ 
+    def test_noflux_riverwall_DE0(self):
+        """test_noflux_riverwall
+            
+            Tests that the riverwall blocks water when the stage is < wall height 
+            
+        """
+        wallHeight=-0.2
+        InitialOceanStage=-0.3
+        InitialLandStage=-999999.
+       
+        domain=self.create_domain_DE0(wallHeight,InitialOceanStage, InitialLandStage) 
+
+        # Run the model for a few seconds, and check that no water has flowed past the riverwall 
+        for t in domain.evolve(yieldstep=10.0,finaltime=10.0):
+            if(verbose): 
+                print domain.timestepping_statistics()
+
+        # Indices landward of the riverwall
+        landInds=(domain.centroid_coordinates[:,0]<50.).nonzero()[0]
+        # Compute volume of water landward of riverwall
+        landVol=domain.quantities['height'].centroid_values[landInds]*domain.areas[landInds]            
+        landVol=landVol.sum()
+        
+        if(verbose):
+            print 'Land Vol: ', landVol, 'theoretical vol: ', 0.
+
+        assert numpy.allclose(landVol,0., atol=1.0e-12)
+        
+    def test_simpleflux_riverwall_DE0(self):
+        """test_simpleflux_riverwall
+            
+            Tests that the riverwall flux (when dry on one edge) is
+            2/3*H*sqrt(2/3*g*H)
+            
+        """
+        wallHeight=2.
+        InitialOceanStage=2.50
+        InitialLandStage=-999999.
+       
+        domain=self.create_domain_DE0(wallHeight,InitialOceanStage, InitialLandStage) 
+
+        # Run the model for a few fractions of a second
+        # Any longer, and the evolution of stage starts causing
+        # significant changes to the flow
+        yst=1.0e-04
+        ft=1.0e-03
+        for t in domain.evolve(yieldstep=yst,finaltime=ft):
+            if(verbose):
+                print domain.timestepping_statistics()
+
+        # Compare with theoretical result
+        L= 100. # Length of riverwall
+        H=InitialOceanStage-wallHeight # Upstream head
+        dt=ft
+        theoretical_flux_vol=dt*L*2./3.*H*(2./3.*g*H)**0.5
+
+        # Indices landward of the riverwall
+        landInds=(domain.centroid_coordinates[:,0]<50.).nonzero()[0]
+        # Compute volume of water landward of riverwall
+        landVol=domain.quantities['height'].centroid_values[landInds]*domain.areas[landInds]            
+        landVol=landVol.sum()
+
+        if(verbose):
+            print 'Land Vol: ', landVol, 'theoretical vol: ', theoretical_flux_vol
+
+        assert numpy.allclose(landVol,theoretical_flux_vol, rtol=1.0e-03)
+    
+    def test_simpleflux_riverwall_with_Qfactor_DE0(self):
+        """test_simpleflux_riverwall with Qfactor != 1.0
+            
+            Tests that the riverwall flux (when dry on one edge) is
+            2/3*H*sqrt(2/3*g*H)*Qfactor
+            
+        """
+        wallHeight=2.
+        InitialOceanStage=2.50
+        InitialLandStage=-999999.
+       
+        domain=self.create_domain_DE0(wallHeight,InitialOceanStage, InitialLandStage) 
+        # Redefine the riverwall, with 2x the discharge Qfactor
+        riverWall={ 'centralWall':
+                        [ [wallLoc, 0.0, wallHeight],
+                          [wallLoc, 100.0, wallHeight]] 
+                  }
+        Qmult=2.0
+        riverWall_Par={'centralWall':{'Qfactor':Qmult}}
+        domain.riverwallData.create_riverwalls(riverWall,riverWall_Par,verbose=verbose)
+
+        #import pdb
+        #pdb.set_trace()
+
+        # Run the model for a few fractions of a second
+        # Any longer, and the evolution of stage starts causing
+        # significant changes to the flow
+        yst=1.0e-04
+        ft=1.0e-03
+        for t in domain.evolve(yieldstep=yst,finaltime=ft):
+            if(verbose):
+                print domain.timestepping_statistics()
+
+        # Compare with theoretical result
+        L= 100. # Length of riverwall
+        H=InitialOceanStage-wallHeight # Upstream head
+        dt=ft
+        theoretical_flux_vol=Qmult*dt*L*2./3.*H*(2./3.*g*H)**0.5
+
+        # Indices landward of the riverwall
+        landInds=(domain.centroid_coordinates[:,0]<50.).nonzero()[0]
+        # Compute volume of water landward of riverwall
+        landVol=domain.quantities['height'].centroid_values[landInds]*domain.areas[landInds]            
+        landVol=landVol.sum()
+
+        #import pdb
+        #pdb.set_trace()
+        
+        if(verbose):
+            print 'Land Vol: ', landVol, 'theoretical vol: ', theoretical_flux_vol
+
+        assert numpy.allclose(landVol,theoretical_flux_vol, rtol=1.0e-03)
+
+   
+    def test_submergeflux_riverwall_DE0(self):
+        """test_submergedflux_riverwall
+            
+            Tests that the riverwall flux is
+            Q1*(1-Q2/Q1)**(0.385)
+
+            Where Q1, Q2 =2/3*H*sqrt(2/3*g*H)
+             with H computed from the smallest (Q2) / largest (Q1) head side
+        """
+        wallHeight=20.
+        InitialOceanStage=20.50
+        InitialLandStage=20.44
+       
+        domain=self.create_domain_DE0(wallHeight,InitialOceanStage, InitialLandStage) 
+
+        # Indices landward of the riverwall
+        landInds=(domain.centroid_coordinates[:,0]<50.).nonzero()[0]
+        InitialHeight=(domain.quantities['stage'].centroid_values[landInds]-domain.quantities['elevation'].centroid_values[landInds])
+        InitialLandVol=InitialHeight*(InitialHeight>0.)*domain.areas[landInds]            
+        InitialLandVol=InitialLandVol.sum()
+
+        # Run the model for a few fractions of a second
+        # Any longer, and the evolution of stage starts causing
+        # significant changes to the flow
+        yst=1.0e-04
+        ft=1.0e-03
+        for t in domain.evolve(yieldstep=yst,finaltime=ft):
+            if(verbose):
+                print domain.timestepping_statistics()
+
+        # Compare with theoretical result
+        L= 100. # Length of riverwall
+        dt=ft
+        H1=max(InitialOceanStage-wallHeight,0.) # Upstream head
+        H2=max(InitialLandStage-wallHeight,0.) # Downstream head
+
+        Q1=2./3.*H1*(2./3.*g*H1)**0.5
+        Q2=2./3.*H2*(2./3.*g*H2)**0.5
+
+        theoretical_flux_vol=dt*L*Q1*(1.-Q2/Q1)**0.385
+
+        # Compute volume of water landward of riverwall
+        FinalLandVol=domain.quantities['height'].centroid_values[landInds]*domain.areas[landInds]            
+        FinalLandVol=FinalLandVol.sum()
+
+        landVol=FinalLandVol-InitialLandVol
+
+        #import pdb
+        #pdb.set_trace()
+        
+        if(verbose):
+            print 'Land Vol: ', landVol, 'theoretical vol: ', theoretical_flux_vol
+
+        assert numpy.allclose(landVol,theoretical_flux_vol, rtol=1.0e-03)
+    
+    def test_riverwall_includes_specified_points_in_domain(self): 
+        """
+            Check that all domain points that should be on the riverwall
+            actually are, and that there are no 'non-riverwall' points on the riverwall
+        """
+        wallHeight=-0.2
+        InitialOceanStage=-0.3
+        InitialLandStage=-999999.
+       
+        domain=self.create_domain_DE1(wallHeight,InitialOceanStage, InitialLandStage) 
+
+        edgeInds_on_wall=domain.riverwallData.riverwall_edges.tolist()
+
+        riverWall_x_coord=domain.edge_coordinates[edgeInds_on_wall,0]-wallLoc
+
+        assert(numpy.allclose(riverWall_x_coord,0.))
+   
+        # Now check that all the other domain edge coordinates are not on the wall 
+        # Note the threshold requires a sufficiently coarse mesh
+        notriverWall_x_coord=numpy.delete(domain.edge_coordinates[:,0], edgeInds_on_wall) 
+        assert(min(abs(notriverWall_x_coord-wallLoc))>1.0e-01)
+
+    def test_is_vertex_on_boundary(self):
+        """
+            Check that is_vertex_on_boundary is working as expected
+        """
+        wallHeight=-0.2
+        InitialOceanStage=-0.3
+        InitialLandStage=-999999.
+       
+        domain=self.create_domain_DE1(wallHeight,InitialOceanStage, InitialLandStage) 
+
+        allVertices=numpy.array(range(len(domain.vertex_coordinates)))
+        boundaryFlag=domain.riverwallData.is_vertex_on_boundary(allVertices)
+        boundaryVerts=boundaryFlag.nonzero()[0].tolist()
+
+        # Check that all boundary vertices are on the boundary 
+        check2=(domain.vertex_coordinates[boundaryVerts,0]==0.)+\
+               (domain.vertex_coordinates[boundaryVerts,0]==100.)+\
+               (domain.vertex_coordinates[boundaryVerts,1]==100.)+\
+               (domain.vertex_coordinates[boundaryVerts,1]==0.)
+
+        assert(all(check2>0.))
+
+        # Check that all non-boundary vertices are not
+        nonboundaryVerts=(boundaryFlag==0).nonzero()[0].tolist()
+        check2=(domain.vertex_coordinates[nonboundaryVerts,0]==0.)+\
+               (domain.vertex_coordinates[nonboundaryVerts,0]==100.)+\
+               (domain.vertex_coordinates[nonboundaryVerts,1]==100.)+\
+               (domain.vertex_coordinates[nonboundaryVerts,1]==0.)
+
+        assert(all(check2==0))
+
+    def test_multiple_riverwalls(self):
+        """
+            Testcase with multiple riverwalls -- check all is working as required
+
+         Idea -- add other riverwalls with different Qfactor / height.
+                 Set them up to have no hydraulic effect, but
+                 so that we are likely to catch bugs if the code is not right
+        """
+        wallHeight=2.
+        InitialOceanStage=2.50
+        InitialLandStage=-999999.
+        
+       
+        riverWall={ 'awall1':
+                        [ [wallLoc+20., 0.0, -9999.],
+                          [wallLoc+20., 100.0, -9999.]],  
+                    'centralWall':
+                        [ [wallLoc, 0.0, wallHeight],
+                          [wallLoc, 100.0, wallHeight]] ,
+                    'awall2':
+                        [ [wallLoc-20., 0.0, 30.],
+                          [wallLoc-20., 100.0, 30.]],  
+                  }
+
+        newQfac=2.0
+        riverWall_Par={'centralWall':{'Qfactor':newQfac}, 'awall1':{'Qfactor':100.}, 'awall2':{'Qfactor':0.}}
+
+        domain=self.create_domain_DE0(wallHeight,InitialOceanStage, InitialLandStage, riverWall=riverWall,riverWall_Par=riverWall_Par) 
+        
+
+        domain.riverwallData.create_riverwalls(riverWall,riverWall_Par,verbose=verbose) 
+
+        # Run the model for a few fractions of a second
+        # Any longer, and the evolution of stage starts causing
+        # significant changes to the flow
+        yst=1.0e-04
+        ft=1.0e-03
+        for t in domain.evolve(yieldstep=yst,finaltime=ft):
+            if(verbose):
+                print domain.timestepping_statistics()
+
+        # Compare with theoretical result
+        L= 100. # Length of riverwall
+        H=InitialOceanStage-wallHeight # Upstream head
+        dt=ft
+        theoretical_flux_vol=newQfac*dt*L*2./3.*H*(2./3.*g*H)**0.5
+
+        # Indices landward of the riverwall
+        landInds=(domain.centroid_coordinates[:,0]<50.).nonzero()[0]
+        # Compute volume of water landward of riverwall
+        landVol=domain.quantities['height'].centroid_values[landInds]*domain.areas[landInds]            
+        landVol=landVol.sum()
+
+        if(verbose):
+            print 'Land Vol: ', landVol, 'theoretical vol: ', theoretical_flux_vol
+
+        assert numpy.allclose(landVol,theoretical_flux_vol, rtol=1.0e-03)
+
+# =========================================================================
+if __name__ == "__main__":
+    suite = unittest.makeSuite(Test_riverwall_structure, 'test')
+    runner = unittest.TextTestRunner()
+    runner.run(suite)
Index: /trunk/anuga_core/source/anuga/structures/test/test_weir_orifice_trapezoid_operator.py
===================================================================
--- /trunk/anuga_core/source/anuga/structures/test/test_weir_orifice_trapezoid_operator.py	(revision 9440)
+++ /trunk/anuga_core/source/anuga/structures/test/test_weir_orifice_trapezoid_operator.py	(revision 9440)
@@ -0,0 +1,650 @@
+#!/usr/bin/env python
+
+
+import unittest
+
+
+from anuga.structures.weir_orifice_trapezoid_operator import Weir_orifice_trapezoid_operator
+from anuga.structures.weir_orifice_trapezoid_operator import weir_orifice_trapezoid_function
+
+from anuga.abstract_2d_finite_volumes.mesh_factory import rectangular_cross
+from anuga.shallow_water.shallow_water_domain import Domain
+import numpy
+import inspect
+
+
+
+
+verbose = False
+
+
+class Test_weir_orifice_trapezoid_operator(unittest.TestCase):
+    """
+	Test the weir_orifice_trapezoid_operator, in particular the discharge_routine!
+    """
+
+    def setUp(self):
+        pass
+
+    def tearDown(self):
+        pass
+    
+    
+    def _create_domain(self,d_length,
+                            d_width,
+                            dx,
+                            dy,
+                            elevation_0,
+                            elevation_1,
+                            stage_0,
+                            stage_1,
+                            xvelocity_0 = 0.0,
+                            xvelocity_1 = 0.0,
+                            yvelocity_0 = 0.0,
+                            yvelocity_1 = 0.0):
+        
+        points, vertices, boundary = rectangular_cross(int(d_length/dx), int(d_width/dy),
+                                                        len1=d_length, len2=d_width)
+        domain = Domain(points, vertices, boundary)   
+        domain.set_name('Test_Outlet_Inlet')                 # Output name
+        domain.set_store()
+        domain.set_default_order(2)
+        domain.H0 = 0.01
+        domain.tight_slope_limiters = 1
+
+        #print 'Size', len(domain)
+
+        #------------------------------------------------------------------------------
+        # Setup initial conditions
+        #------------------------------------------------------------------------------
+
+        def elevation(x, y):
+            """Set up a elevation
+            """
+            
+            z = numpy.zeros(x.shape,dtype='d')
+            z[:] = elevation_0
+            
+            numpy.putmask(z, x > d_length/2, elevation_1)
+    
+            return z
+            
+        def stage(x,y):
+            """Set up stage
+            """
+            z = numpy.zeros(x.shape,dtype='d')
+            z[:] = stage_0
+            
+            numpy.putmask(z, x > d_length/2, stage_1)
+
+            return z
+        
+        def xmom(x,y):
+            """Set up xmomentum
+            """
+            z = numpy.zeros(x.shape,dtype='d')
+            z[:] = xvelocity_0*(stage_0-elevation_0)
+            
+            numpy.putmask(z, x > d_length/2, xvelocity_1*(stage_1-elevation_1) )
+
+            return z
+        
+        def ymom(x,y):
+            """Set up ymomentum
+            """
+            z = numpy.zeros(x.shape,dtype='d')
+            z[:] = yvelocity_0*(stage_0-elevation_0)
+            
+            numpy.putmask(z, x > d_length/2, yvelocity_1*(stage_1-elevation_1) )
+
+            return z
+            
+        #print 'Setting Quantities....'
+        domain.set_quantity('elevation', elevation)  # Use function for elevation
+        domain.set_quantity('stage',  stage)   # Use function for elevation
+        domain.set_quantity('xmomentum',  xmom) 
+        domain.set_quantity('ymomentum',  ymom) 
+        
+        return domain
+    
+    #def test_weir_orifice_non_skew(self):
+
+        #stage_0 = 11.0
+        #stage_1 = 10.0
+        #elevation_0 = 10.0
+        #elevation_1 = 10.0
+
+        #domain_length = 200.0
+        #domain_width = 200.0
+
+        #culvert_length = 10.0
+        #culvert_width = 10.0
+        #culvert_height = 3.0
+        #culvert_slope=0.1
+        #culvert_z1 = 2
+        #culvert_z2 = 2
+        #culvert_losses = {'inlet':0.5, 'outlet':1.0, 'bend':0.0, 'grate':0.0, 'pier': 0.0, 'other': 0.0}
+        #culvert_mannings = 0.015
+        
+        #culvert_apron = 0.0
+        #enquiry_gap = 5.0
+
+        
+        #expected_Q = 0.52 
+        #expected_v = 1.04
+        #expected_d = 0.50
+                                    
+
+        #domain = self._create_domain(d_length=domain_length,
+                                     #d_width=domain_width,
+                                     #dx = 5.0,
+                                     #dy = 5.0,
+                                     #elevation_0 = elevation_0,
+                                     #elevation_1 = elevation_1,
+                                     #stage_0 = stage_0,
+                                     #stage_1 = stage_1)
+ 
+
+        ##print 'Defining Structures'
+        
+        #ep0 = numpy.array([domain_length/2-culvert_length/2, 100.0])
+        #ep1 = numpy.array([domain_length/2+culvert_length/2, 100.0])
+        
+        
+        #culvert = Weir_orifice_trapezoid_operator(domain,
+                                    #losses=culvert_losses,
+                                    #width=culvert_width,
+                                    #end_points=[ep0, ep1],
+                                    #height=culvert_height,
+                                    #culvert_slope=culvert_slope,
+                                    #z1=culvert_z1,
+                                    #z2=culvert_z2,
+                                    #apron=culvert_apron,
+                                    #enquiry_gap=enquiry_gap,
+                                    #use_momentum_jet=False,
+                                    #use_velocity_head=False,
+                                    #manning=culvert_mannings,
+                                    #logging=False,
+                                    #label='10mwidex3mdeep 1V:2H trapezoid',
+                                    #verbose=False)
+
+        ##culvert.determine_inflow_outflow()
+        
+        #( Q, v, d ) = culvert.discharge_routine()
+        
+        #if verbose:
+            #print 50*'='
+            #print 'UNITTEST ',inspect.stack()[0][3]
+            #print 'Q v d: ', Q, v, d, ' expected_Q v d: ', expected_Q, expected_v, expected_d
+        
+
+        #assert numpy.allclose(Q, expected_Q, rtol=1.0e-1) #inflow
+        #assert numpy.allclose(v, expected_v, rtol=1.0e-1) #outflow velocity
+        #assert numpy.allclose(d, expected_d, rtol=1.0e-1) #depth at outlet used to calc v 
+        
+      
+
+    def test_weir_orifice_1(self):
+        """test_weir_orifice 1
+        
+        This tests the test_weir_orifice routine with data obtained from a spreadsheet to do the weir orfice calcs    
+        """
+
+
+        g=9.81
+        culvert_slope=1  # Downward
+
+        inlet_depth=0.57
+        outlet_depth=0.45
+        inlet_velocity=1.93 # v jut upstream of culvert
+        outlet_velocity=2.03 # v just downstream of culvert
+        
+        culvert_length=10.0
+        culvert_width=10.0
+        culvert_height=3.0
+        culvert_slope=0.1
+        culvert_z1=2
+        culvert_z2=2
+        
+        culvert_type='trapezoid'
+        manning=0.015
+        sum_loss=1.5
+
+        inlet_specific_energy=inlet_depth + 0.5*inlet_velocity**2/g 
+        z_in = 0.0
+        z_out = z_in-culvert_length*culvert_slope/100
+        E_in = z_in+inlet_depth + 0.5*inlet_velocity**2/g
+        E_out = z_out+outlet_depth + 0.5*outlet_velocity**2/g
+        delta_total_energy = E_in-E_out
+        
+
+        Q_expected = 0.52 
+        v_expected = 1.04
+        d_expected = 0.05
+        
+        if verbose:
+            print 50*'='
+            print 'UNITTEST ',inspect.stack()[0][3]
+            print 'width ',culvert_width
+            print 'depth ',culvert_height
+            print 'flow_width ',culvert_width
+            print 'length ' ,culvert_length
+            print 'driving_energy ',inlet_specific_energy
+            print 'delta_total_energy ',delta_total_energy
+            print 'outlet_enquiry_depth ',outlet_depth
+            print 'sum_loss ',sum_loss
+            print 'manning ',manning
+        
+        Q, v, d, flow_area, case= weir_orifice_trapezoid_function(culvert_width, 
+                                                    culvert_height, 
+                                                    culvert_width,
+                                                    culvert_slope,
+                                                    culvert_z1,
+                                                    culvert_z2, 
+                                                    culvert_length, 
+                                                    inlet_specific_energy, 
+                                                    delta_total_energy, 
+                                                    outlet_depth, 
+                                                    sum_loss,
+                                                    manning)
+        
+
+
+
+
+        if verbose:
+            print ('%s %.2f'%('SPEC_E = ',inlet_specific_energy))
+            print ('%s %.2f'%('Delta E = ',delta_total_energy))
+            print ('%s %.2f,%.2f,%.2f' %('   ANUGAcalcsTEST Q-v-d ',Q,v,d))
+            print ('%s %.2f,%.2f,%.2f' %('spreadsheet calculation ', Q_expected, v_expected, d_expected))
+            
+        assert numpy.allclose(Q, Q_expected, rtol=1.0e-1) #inflow
+        assert numpy.allclose(v, v_expected, rtol=1.0e-1) #outflow velocity
+        assert numpy.allclose(d, d_expected, rtol=1.0e-1) #depth at outlet used to calc v 
+        
+    def test_weir_orifice_2(self):
+        """test_weir_orifice 2
+        
+        This tests the test_weir_orifice routine with data obtained from a spreadsheet to do the weir orfice calcs  
+        """
+
+
+        g=9.81
+        culvert_slope=1  # Downward
+
+        inlet_depth=1.99
+        outlet_depth=1.9
+        inlet_velocity=3.59
+        outlet_velocity=3.82
+        
+        culvert_length=10.0
+        culvert_width=10.0
+        culvert_height=3.0
+        culvert_slope=0.01
+        culvert_z1=2
+        culvert_z2=2
+        
+        culvert_type='trapezoid'
+        manning=0.015
+        sum_loss=1.5
+
+        inlet_specific_energy=inlet_depth + 0.5*inlet_velocity**2/g 
+        z_in = 0.0
+        z_out = z_in-culvert_length*culvert_slope/100
+        E_in = z_in+inlet_depth + 0.5*inlet_velocity**2/g
+        E_out = z_out+outlet_depth + 0.5*outlet_velocity**2/g
+        delta_total_energy = E_in-E_out
+        
+
+        Q_expected = 0.09
+        v_expected = 0.20
+        d_expected = 0.04
+        
+        if verbose:
+            print 50*'='
+            print 'UNITTEST ',inspect.stack()[0][3] 
+            print 'width ',culvert_width
+            print 'depth ',culvert_height
+            print 'flow_width ',culvert_width
+            print 'length ' ,culvert_length
+            print 'driving_energy ',inlet_specific_energy
+            print 'delta_total_energy ',delta_total_energy
+            print 'outlet_enquiry_depth ',outlet_depth
+            print 'sum_loss ',sum_loss
+            print 'manning ',manning
+        
+        Q, v, d, flow_area, case= weir_orifice_trapezoid_function(culvert_width, 
+                                                    culvert_height, 
+                                                    culvert_width,
+                                                    culvert_slope,
+                                                    culvert_z1,
+                                                    culvert_z2, 
+                                                    culvert_length, 
+                                                    inlet_specific_energy, 
+                                                    delta_total_energy, 
+                                                    outlet_depth, 
+                                                    sum_loss,
+                                                    manning)
+
+
+
+
+        if verbose:
+            print ('%s %.2f'%('SPEC_E = ',inlet_specific_energy))
+            print ('%s %.2f'%('Delta E = ',delta_total_energy))
+            print ('%s %.2f,%.2f,%.2f' %(   'ANUGAcalcsTEST Q-v-d ',Q,v,d))
+            print ('%s %.2f,%.2f,%.2f' %('spreadsheet calculation ', Q_expected, v_expected, d_expected))
+            
+        assert numpy.allclose(Q, Q_expected, rtol=1.0e-1) #inflow
+        assert numpy.allclose(v, v_expected, rtol=1.0e-1) #outflow velocity
+        assert numpy.allclose(d, d_expected, rtol=1.0e-1) #depth at outlet used to calc v 
+        
+    def test_weir_orifice_3(self):
+        """test_weir_orifice 3
+        
+        This tests the test_weir_orifice routine with data obtained from a spreadsheet to do the weir orfice calcs 
+        """
+
+
+        g=9.81
+        culvert_slope=1  # Downward
+
+        inlet_depth=6.15
+        outlet_depth=2.02
+        inlet_velocity=1.82
+        outlet_velocity=8.82
+        
+        culvert_length=10.0
+        culvert_width=10.0
+        culvert_height=3.0
+        culvert_z1=2
+        culvert_z2=2
+        
+        culvert_type='trapezoid'
+        manning=0.015
+        sum_loss=1.5
+
+        inlet_specific_energy=inlet_depth + 0.5*inlet_velocity**2/g 
+        z_in = 0.0
+        z_out = z_in-culvert_length*culvert_slope/100
+        E_in = z_in+inlet_depth + 0.5*inlet_velocity**2/g
+        E_out = z_out+outlet_depth + 0.5*outlet_velocity**2/g
+        delta_total_energy = E_in-E_out
+        
+
+        Q_expected = 6.44
+        v_expected = 2.33
+        d_expected = 0.24
+        
+        if verbose:
+            print 50*'='
+            print 'UNITTEST ',inspect.stack()[0][3]
+            print 'width ',culvert_width
+            print 'depth ',culvert_height
+            print 'flow_width ',culvert_width
+            print 'length ' ,culvert_length
+            print 'driving_energy ',inlet_specific_energy
+            print 'delta_total_energy ',delta_total_energy
+            print 'outlet_enquiry_depth ',outlet_depth
+            print 'sum_loss ',sum_loss
+            print 'manning ',manning
+        
+        Q, v, d, flow_area, case= weir_orifice_trapezoid_function(culvert_width, 
+                                                    culvert_height, 
+                                                    culvert_width,
+                                                    culvert_slope,
+                                                    culvert_z1,
+                                                    culvert_z2, 
+                                                    culvert_length, 
+                                                    inlet_specific_energy, 
+                                                    delta_total_energy, 
+                                                    outlet_depth, 
+                                                    sum_loss,
+                                                    manning)
+
+
+
+
+        if verbose:
+            print ('%s %.2f'%('SPEC_E = ',inlet_specific_energy))
+            print ('%s %.2f'%('Delta E = ',delta_total_energy))
+            print ('%s %.2f,%.2f,%.2f' %('   ANUGAcalcsTEST Q-v-d ',Q,v,d))
+            print ('%s %.2f,%.2f,%.2f' %('spreadsheet calculation ', Q_expected, v_expected, d_expected))
+            
+        assert numpy.allclose(Q, Q_expected, rtol=1.0e-1) #inflow
+        assert numpy.allclose(v, v_expected, rtol=1.0e-1) #outflow velocity
+        assert numpy.allclose(d, d_expected, rtol=1.0e-1) #depth at outlet used to calc v  
+
+    def test_weir_orifice_4(self):
+        """test_weir_orifice 4
+        
+        This tests the test_weir_orifice routine with data obtained from a spreadsheet to do the weir orfice calcs  
+        """
+
+
+        g=9.81
+        culvert_slope=0.1  # Downward
+
+        inlet_depth=12.0
+        outlet_depth=10.0
+        inlet_velocity=2.0
+        outlet_velocity=2.5
+        
+        culvert_length=100.0
+        culvert_width=10.0
+        culvert_height=3.0
+        culvert_z1=2
+        culvert_z2=2
+        
+        culvert_type='trapezoid'
+        manning=0.015
+        sum_loss=1.5
+
+        inlet_specific_energy=inlet_depth + 0.5*inlet_velocity**2/g 
+        z_in = 0.0
+        z_out = z_in-culvert_length*culvert_slope/100
+        E_in = z_in+inlet_depth + 0.5*inlet_velocity**2/g
+        E_out = z_out+outlet_depth + 0.5*outlet_velocity**2/g
+        delta_total_energy = E_in-E_out
+        
+
+        Q_expected = 383.75
+        v_expected = 5.09
+        d_expected = 3.00
+        
+        if verbose:
+            print 50*'='
+            print 'UNITTEST ',inspect.stack()[0][3]
+            print 'width ',culvert_width
+            print 'depth ',culvert_height
+            print 'flow_width ',culvert_width
+            print 'length ' ,culvert_length
+            print 'driving_energy ',inlet_specific_energy
+            print 'delta_total_energy ',delta_total_energy
+            print 'outlet_enquiry_depth ',outlet_depth
+            print 'sum_loss ',sum_loss
+            print 'manning ',manning
+        
+        Q, v, d, flow_area, case= weir_orifice_trapezoid_function(culvert_width, 
+                                                    culvert_height, 
+                                                    culvert_width,
+                                                    culvert_slope,
+                                                    culvert_z1,
+                                                    culvert_z2, 
+                                                    culvert_length, 
+                                                    inlet_specific_energy, 
+                                                    delta_total_energy, 
+                                                    outlet_depth, 
+                                                    sum_loss,
+                                                    manning)
+
+
+
+
+        if verbose:
+            print ('%s %.2f'%('SPEC_E = ',inlet_specific_energy))
+            print ('%s %.2f'%('Delta E = ',delta_total_energy))
+            print ('%s %.2f,%.2f,%.2f' %('   ANUGAcalcsTEST Q-v-d ',Q,v,d))
+            print ('%s %.2f,%.2f,%.2f' %('spreadsheet calculation ', Q_expected, v_expected, d_expected))
+            
+        assert numpy.allclose(Q, Q_expected, rtol=1.0e-1) #inflow
+        assert numpy.allclose(v, v_expected, rtol=1.0e-1) #outflow velocity
+        assert numpy.allclose(d, d_expected, rtol=1.0e-1) #depth at outlet used to calc v 
+        
+
+    def test_weir_orifice_5(self):
+        """test_weir_orifice 5
+        
+        This tests the test_weir_orifice routine with data obtained from a spreadsheet to do the weir orfice calcs  
+        """
+
+
+        g=9.81
+        culvert_slope=1  # Downward
+
+        inlet_depth=12.0
+        outlet_depth=10.0
+        inlet_velocity=2.0
+        outlet_velocity=2.5
+        
+        culvert_length=100.0
+        culvert_width=10.0
+        culvert_height=3.0
+        culvert_z1=2
+        culvert_z2=2
+        
+        culvert_type='trapezoid'
+        manning=0.015
+        sum_loss=1.5
+
+        inlet_specific_energy=inlet_depth + 0.5*inlet_velocity**2/g 
+        z_in = 0.0
+        z_out = z_in-culvert_length*culvert_slope/100
+        E_in = z_in+inlet_depth + 0.5*inlet_velocity**2/g
+        E_out = z_out+outlet_depth + 0.5*outlet_velocity**2/g
+        delta_total_energy = E_in-E_out
+        
+
+        Q_expected = 487.48
+        v_expected = 6.13
+        d_expected = 3.00
+        
+        if verbose:
+            print 50*'='
+            print 'UNITTEST ',inspect.stack()[0][3]
+            print 'width ',culvert_width
+            print 'depth ',culvert_height
+            print 'flow_width ',culvert_width
+            print 'length ' ,culvert_length
+            print 'driving_energy ',inlet_specific_energy
+            print 'delta_total_energy ',delta_total_energy
+            print 'outlet_enquiry_depth ',outlet_depth
+            print 'sum_loss ',sum_loss
+            print 'manning ',manning
+        
+        Q, v, d, flow_area, case= weir_orifice_trapezoid_function(culvert_width, 
+                                                    culvert_height, 
+                                                    culvert_width,
+                                                    culvert_slope,
+                                                    culvert_z1,
+                                                    culvert_z2, 
+                                                    culvert_length, 
+                                                    inlet_specific_energy, 
+                                                    delta_total_energy, 
+                                                    outlet_depth, 
+                                                    sum_loss,
+                                                    manning)
+
+
+
+
+        if verbose:
+            print ('%s %.2f'%('SPEC_E = ',inlet_specific_energy))
+            print ('%s %.2f'%('Delta E = ',delta_total_energy))
+            print ('%s %.2f,%.2f,%.2f' %('   ANUGAcalcsTEST Q-v-d ',Q,v,d))
+            print ('%s %.2f,%.2f,%.2f' %('spreadsheet calculation ', Q_expected, v_expected, d_expected))
+            
+        assert numpy.allclose(Q, Q_expected, rtol=1.0e-1) #inflow
+        assert numpy.allclose(v, v_expected, rtol=1.0e-1) #outflow velocity
+        assert numpy.allclose(d, d_expected, rtol=1.0e-1) #depth at outlet used to calc v 
+
+    def test_weir_orifice_6(self):
+        """test_weir_orifice 6
+        
+        This tests the test_weir_orifice routine with data obtained from a spreadsheet to do the weir orfice calcs 
+        """
+
+
+        g=9.81
+        culvert_slope=10  # Downward
+
+        inlet_depth=12.0
+        outlet_depth=10.0
+        inlet_velocity=2.0
+        outlet_velocity=2.5
+        
+        culvert_length=100.0
+        culvert_width=10.0
+        culvert_height=3.0
+        culvert_z1=2
+        culvert_z2=2
+        
+        culvert_type='trapezoid'
+        manning=0.015
+        sum_loss=1.5
+
+        inlet_specific_energy=inlet_depth + 0.5*inlet_velocity**2/g 
+        z_in = 0.0
+        z_out = z_in-culvert_length*culvert_slope/100
+        E_in = z_in+inlet_depth + 0.5*inlet_velocity**2/g
+        E_out = z_out+outlet_depth + 0.5*outlet_velocity**2/g
+        delta_total_energy = E_in-E_out
+        
+
+        Q_expected = 1049.86
+        v_expected = 8.75
+        d_expected = 3.00
+        
+        if verbose:
+            print 50*'='
+            print 'UNITTEST ',inspect.stack()[0][3]
+            print 'width ',culvert_width
+            print 'depth ',culvert_height
+            print 'flow_width ',culvert_width
+            print 'length ' ,culvert_length
+            print 'driving_energy ',inlet_specific_energy
+            print 'delta_total_energy ',delta_total_energy
+            print 'outlet_enquiry_depth ',outlet_depth
+            print 'sum_loss ',sum_loss
+            print 'manning ',manning
+        
+        Q, v, d, flow_area, case= weir_orifice_trapezoid_function(culvert_width, 
+                                                    culvert_height, 
+                                                    culvert_width,
+                                                    culvert_slope,
+                                                    culvert_z1,
+                                                    culvert_z2, 
+                                                    culvert_length, 
+                                                    inlet_specific_energy, 
+                                                    delta_total_energy, 
+                                                    outlet_depth, 
+                                                    sum_loss,
+                                                    manning)
+
+
+
+
+        if verbose:
+            print ('%s %.2f'%('SPEC_E = ',inlet_specific_energy))
+            print ('%s %.2f'%('Delta E = ',delta_total_energy))
+            print ('%s %.2f,%.2f,%.2f' %('   ANUGAcalcsTEST Q-v-d ',Q,v,d))
+            print ('%s %.2f,%.2f,%.2f' %('spreadsheet calculation ', Q_expected, v_expected, d_expected))
+            
+        assert numpy.allclose(Q, Q_expected, rtol=1.0e-1) #inflow
+        assert numpy.allclose(v, v_expected, rtol=1.0e-1) #outflow velocity
+        assert numpy.allclose(d, d_expected, rtol=1.0e-1) #depth at outlet used to calc v 
+# =========================================================================
+if __name__ == "__main__":
+    suite = unittest.makeSuite(Test_weir_orifice_trapezoid_operator, 'test')
+    runner = unittest.TextTestRunner()
+    runner.run(suite)
Index: unk/anuga_core/source/anuga/structures/test_all.py
===================================================================
--- /trunk/anuga_core/source/anuga/structures/test_all.py	(revision 9439)
+++ 	(revision )
@@ -1,83 +1,0 @@
-"""Regression testing framework
-This module will search for scripts in the same directory named
-test_*.py.  Each such script should be a test suite that tests a
-module through PyUnit. This script will aggregate all
-found test suites into one big test suite and run them all at once.
-"""
-
-# Author: Mark Pilgrim
-# Modified by Ole Nielsen
-
-import unittest
-import os
-
-
-#List files that should be excluded from the testing process.
-#E.g. if they are known to fail and under development
-exclude = [] 
-
-
-def get_test_files(path):
-
-    import sys
-
-    files = os.listdir(path)
-
-    #Check sub directories
-    test_files = []
-    for file in files:
-        if os.path.isdir(file):
-            sys.path.append(file)
-            #print 'Recursing into', file
-            test_files += get_test_files(path + os.sep + file)
-        elif file[:5] == 'test_' and file[-2:] == 'py':
-            #print 'Appending', file
-            test_files.append(file)
-        else:
-            pass
-    return test_files
-
-
-
-def regressionTest():
-    import sys, os, re, unittest
-    path = os.path.split(sys.argv[0])[0] or os.getcwd()
-
-
-    files = get_test_files(path)
-
-
-
-    #test = re.compile('^test_[\w]*.py$', re.IGNORECASE)
-    #files = filter(test.search, files)
-
-
-    try:
-        files.remove(__file__)  #Remove self from list (Ver 2.3. or later)
-    except:
-        files.remove('test_all.py')
-
-    print 'Testing:'
-    for file in files:
-        print '  ' + file
-
-    if globals().has_key('exclude'):
-        for file in exclude:
-            files.remove(file)
-            print 'WARNING: File '+ file + ' excluded from testing'
-
-
-    filenameToModuleName = lambda f: os.path.splitext(f)[0]
-    #print "files",files 
-    moduleNames = map(filenameToModuleName, files)
-    #print "moduleNames",moduleNames
-    modules = map(__import__, moduleNames)
-    load = unittest.defaultTestLoader.loadTestsFromModule
-    return unittest.TestSuite(map(load, modules))
-
-################################################################################
-
-if __name__ == '__main__':   
-    suite = regressionTest()
-    runner = unittest.TextTestRunner() #verbosity=2)
-    runner.run(suite)
Index: unk/anuga_core/source/anuga/structures/test_boyd_box_operator.py
===================================================================
--- /trunk/anuga_core/source/anuga/structures/test_boyd_box_operator.py	(revision 9439)
+++ 	(revision )
@@ -1,2623 +1,0 @@
-#!/usr/bin/env python
-
-
-import unittest
-
-
-from anuga.structures.boyd_box_operator import Boyd_box_operator
-from anuga.structures.boyd_box_operator import boyd_box_function
-
-from anuga.abstract_2d_finite_volumes.mesh_factory import rectangular_cross
-from anuga.shallow_water.shallow_water_domain import Domain
-import numpy
-
-verbose = False
-
-
-class Test_boyd_box_operator(unittest.TestCase):
-    """
-	Test the boyd box operator, in particular the discharge_routine!
-    """
-
-    def setUp(self):
-        pass
-
-    def tearDown(self):
-        pass
-    
-    
-    def _create_domain(self,d_length,
-                            d_width,
-                            dx,
-                            dy,
-                            elevation_0,
-                            elevation_1,
-                            stage_0,
-                            stage_1,
-                            xvelocity_0 = 0.0,
-                            xvelocity_1 = 0.0,
-                            yvelocity_0 = 0.0,
-                            yvelocity_1 = 0.0):
-        
-        points, vertices, boundary = rectangular_cross(int(d_length/dx), int(d_width/dy),
-                                                        len1=d_length, len2=d_width)
-        domain = Domain(points, vertices, boundary)   
-        domain.set_name('Test_Outlet_Inlet')                 # Output name
-        domain.set_store()
-        domain.set_default_order(2)
-        domain.H0 = 0.01
-        domain.tight_slope_limiters = 1
-
-        #print 'Size', len(domain)
-
-        #------------------------------------------------------------------------------
-        # Setup initial conditions
-        #------------------------------------------------------------------------------
-
-        def elevation(x, y):
-            """Set up a elevation
-            """
-            
-            z = numpy.zeros(x.shape,dtype='d')
-            z[:] = elevation_0
-            
-            numpy.putmask(z, x > d_length/2, elevation_1)
-    
-            return z
-            
-        def stage(x,y):
-            """Set up stage
-            """
-            z = numpy.zeros(x.shape,dtype='d')
-            z[:] = stage_0
-            
-            numpy.putmask(z, x > d_length/2, stage_1)
-
-            return z
-        
-        def xmom(x,y):
-            """Set up xmomentum
-            """
-            z = numpy.zeros(x.shape,dtype='d')
-            z[:] = xvelocity_0*(stage_0-elevation_0)
-            
-            numpy.putmask(z, x > d_length/2, xvelocity_1*(stage_1-elevation_1) )
-
-            return z
-        
-        def ymom(x,y):
-            """Set up ymomentum
-            """
-            z = numpy.zeros(x.shape,dtype='d')
-            z[:] = yvelocity_0*(stage_0-elevation_0)
-            
-            numpy.putmask(z, x > d_length/2, yvelocity_1*(stage_1-elevation_1) )
-
-            return z
-            
-        #print 'Setting Quantities....'
-        domain.set_quantity('elevation', elevation)  # Use function for elevation
-        domain.set_quantity('stage',  stage)   # Use function for elevation
-        domain.set_quantity('xmomentum',  xmom) 
-        domain.set_quantity('ymomentum',  ymom) 
-        
-        return domain
-
-    def test_boyd_non_skew(self):
-        """test_boyd_non_skew
-        
-        This tests the Boyd routine with data obtained from culvertw application 1.1 by IceMindserer  BD Parkinson, 
-        calculation code by MJ Boyd 
-        """
-
-        stage_0 = 11.0
-        stage_1 = 10.0
-        elevation_0 = 10.0
-        elevation_1 = 10.0
-
-        domain_length = 200.0
-        domain_width = 200.0
-
-        culvert_length = 20.0
-        culvert_width = 3.66
-        culvert_height = 3.66
-        culvert_losses = {'inlet':0.5, 'outlet':1.0, 'bend':0.0, 'grate':0.0, 'pier': 0.0, 'other': 0.0}
-        culvert_mannings = 0.013
-        
-        culvert_apron = 0.0
-        enquiry_gap = 5.0
-
-        
-        expected_Q = 6.23
-        expected_v = 2.55
-        expected_d = 0.66
-        
-
-        domain = self._create_domain(d_length=domain_length,
-                                     d_width=domain_width,
-                                     dx = 5.0,
-                                     dy = 5.0,
-                                     elevation_0 = elevation_0,
-                                     elevation_1 = elevation_1,
-                                     stage_0 = stage_0,
-                                     stage_1 = stage_1)
- 
-
-        #print 'Defining Structures'
-        
-        ep0 = numpy.array([domain_length/2-culvert_length/2, 100.0])
-        ep1 = numpy.array([domain_length/2+culvert_length/2, 100.0])
-        
-        
-        culvert = Boyd_box_operator(domain,
-                                    losses=culvert_losses,
-                                    width=culvert_width,
-                                    end_points=[ep0, ep1],
-                                    height=culvert_height,
-                                    apron=culvert_apron,
-                                    enquiry_gap=enquiry_gap,
-                                    use_momentum_jet=False,
-                                    use_velocity_head=False,
-                                    manning=culvert_mannings,
-                                    logging=False,
-                                    label='3.6x3.6RCBC',
-                                    verbose=False)
-
-        #culvert.determine_inflow_outflow()
-        
-        ( Q, v, d ) = culvert.discharge_routine()
-        
-        if verbose:
-            print 'test_boyd_non_skew'
-            print 'Q: ', Q, 'expected_Q: ', expected_Q
-        
-
-        assert numpy.allclose(Q, expected_Q, rtol=1.0e-2) #inflow
-        assert numpy.allclose(v, expected_v, rtol=1.0e-2) #outflow velocity
-        assert numpy.allclose(d, expected_d, rtol=1.0e-2) #depth at outlet used to calc v 
-        
-        
-        
-        
-        
-    
-    def test_boyd_skew(self):
-        """test_boyd_skew
-        
-        This tests the Boyd routine with data obtained from culvertw application 1.1 by IceMindserer  BD Parkinson, 
-        calculation code by MJ Boyd 
-        """
-
-        stage_0 = 11.0
-        stage_1 = 10.0
-        elevation_0 = 10.0
-        elevation_1 = 10.0
-
-        domain_length = 200.0
-        domain_width = 200.0
-
-        culvert_length = 20.0
-        culvert_width = 3.66
-        culvert_height = 3.66
-        culvert_losses = {'inlet':0.5, 'outlet':1.0, 'bend':0.0, 'grate':0.0, 'pier': 0.0, 'other': 0.0}
-        culvert_mannings = 0.013
-        
-        culvert_apron = 0.0
-        enquiry_gap = 5.0
-        
-        expected_Q = 6.23
-        expected_v = 2.55
-        expected_d = 0.66
-        
-
-        domain = self._create_domain(d_length=domain_length,
-                                     d_width=domain_width,
-                                     dx = 5.0,
-                                     dy = 5.0,
-                                     elevation_0 = elevation_0,
-                                     elevation_1 = elevation_1,
-                                     stage_0 = stage_0,
-                                     stage_1 = stage_1)
-
-        #print 'Defining Structures'
-        
-        a = domain_length/2 - culvert_length/2
-        b = domain_length/2 + culvert_length/2
-        
-        el0 = numpy.array([[a, 100.0 - culvert_width/2], [a, 100.0 + culvert_width/2]])
-        el1 = numpy.array([[b, 100.0 - culvert_width/2], [b, 100.0 + culvert_width/2]])
-        
-        culvert = Boyd_box_operator(domain,
-                                    losses=culvert_losses,
-                                    width=culvert_width,
-                                    exchange_lines=[el0, el1],
-                                    height=culvert_height,
-                                    apron=culvert_apron,
-                                    enquiry_gap=enquiry_gap,
-                                    use_momentum_jet=False,
-                                    use_velocity_head=False,
-                                    manning=culvert_mannings,
-                                    label='3.6x3.6RCBC',
-                                    verbose=False)
-
-        #culvert.determine_inflow_outflow()
-        
-        ( Q, v, d ) = culvert.discharge_routine()
-        
-        if verbose:
-            print 'test_boyd_skew'
-            print 'Q: ', Q, 'expected_Q: ', expected_Q
-
-        assert numpy.allclose(Q, expected_Q, rtol=1.0e-2) #inflow
-        assert numpy.allclose(v, expected_v, rtol=1.0e-2) #outflow velocity
-        assert numpy.allclose(d, expected_d, rtol=1.0e-2) #depth at outlet used to calc v         
-
-
-    def test_boyd_non_skew_enquiry_points(self):
-        """test_boyd_skew_enquiry_points
-        
-        This tests the Boyd routine with data obtained from culvertw application 1.1 by IceMindserer  BD Parkinson, 
-        calculation code by MJ Boyd 
-        """
-
-        stage_0 = 11.0
-        stage_1 = 10.0
-        elevation_0 = 10.0
-        elevation_1 = 10.0
-
-        domain_length = 200.0
-        domain_width = 200.0
-
-        culvert_length = 20.0
-        culvert_width = 3.66
-        culvert_height = 3.66
-        culvert_losses = {'inlet':0.5, 'outlet':1.0, 'bend':0.0, 'grate':0.0, 'pier': 0.0, 'other': 0.0}
-        culvert_mannings = 0.013
-        
-        culvert_apron = 0.0
-        enquiry_gap = 5.0
-        
-        expected_Q = 6.23
-        expected_v = 2.55
-        expected_d = 0.66
-        
-
-        # Probably no need to change below here
-        
-        domain = self._create_domain(d_length=domain_length,
-                                     d_width=domain_width,
-                                     dx = 5.0,
-                                     dy = 5.0,
-                                     elevation_0 = elevation_0,
-                                     elevation_1 = elevation_1,
-                                     stage_0 = stage_0,
-                                     stage_1 = stage_1)
-
-
-        #print 'Defining Structures'
-        
-        a = domain_length/2 - culvert_length/2
-        b = domain_length/2 + culvert_length/2
-        
-        el0 = numpy.array([[a, 100.0 - culvert_width/2], [a, 100.0 + culvert_width/2]])
-        el1 = numpy.array([[b, 100.0 - culvert_width/2], [b, 100.0 + culvert_width/2]])
-        
-        enquiry_points = (numpy.array([85, 100]), numpy.array([115, 100]))
-        
-        culvert = Boyd_box_operator(domain,
-                                    losses=culvert_losses,
-                                    width=culvert_width,
-                                    exchange_lines=[el0, el1],
-                                    enquiry_points=enquiry_points,
-                                    height=culvert_height,
-                                    apron=culvert_apron,
-                                    enquiry_gap=enquiry_gap,
-                                    use_momentum_jet=False,
-                                    use_velocity_head=False,
-                                    manning=culvert_mannings,
-                                    label='3.6x3.6RCBC',
-                                    verbose=False)
-
-
-        
-        ( Q, v, d ) = culvert.discharge_routine()
-        
-        if verbose:
-            print 'test_boyd_non_skew_enquiry_points'
-            print 'Q: ', Q, 'expected_Q: ', expected_Q
-            print 'v: ', v, 'expected_v: ', expected_v
-            print 'd: ', d, 'expected_d: ', expected_d
-
-        assert numpy.allclose(Q, expected_Q, rtol=1.0e-2) #inflow
-        assert numpy.allclose(v, expected_v, rtol=1.0e-2) #outflow velocity
-        assert numpy.allclose(d, expected_d, rtol=1.0e-2) #depth at outlet used to calc v         
-
-    def test_boyd_1(self):
-        """test_boyd_1
-        
-        This tests the Boyd routine with data obtained from culvertw application 1.1 by IceMindserer  BD Parkinson, 
-        calculation code by MJ Boyd     
-        """
-
-
-        g=9.81
-
-
-        inlet_depth=0.150
-        outlet_depth=0.15
-        inlet_velocity=1.00
-        outlet_velocity=0.5
-        
-        culvert_length=10.0
-        culvert_width=3.6
-        culvert_height=1.20
-        
-        culvert_type='box'
-        manning=0.013
-        sum_loss=1.5
-
-        inlet_specific_energy=inlet_depth + 0.5*inlet_velocity**2/g 
-        culvert_slope=10.0  # % Downward
-        z_in = 10.0
-        z_out = z_in-culvert_length*culvert_slope/100
-        E_in = z_in+inlet_depth + 0.5*inlet_velocity**2/g
-        E_out = z_out+outlet_depth + 0.5*outlet_velocity**2/g
-        delta_total_energy = E_in-E_out
-        inlet_specific_energy=inlet_depth + 0.5*inlet_velocity**2/g 
-
-
-        if verbose:
-            print 50*'='
-            print 'width ',culvert_width
-            print 'depth ',culvert_height
-            print 'flow_width ',culvert_width
-            print 'length ' ,culvert_length
-            print 'driving_energy ',inlet_specific_energy
-            print 'delta_total_energy ',delta_total_energy
-            print 'outlet_enquiry_depth ',outlet_depth
-            print 'sum_loss ',sum_loss
-            print 'manning ',manning
-
-
-        Q, v, d, flow_area, case= boyd_box_function(culvert_width, 
-                                                    culvert_height, 
-                                                    culvert_width, 
-                                                    culvert_length, 
-                                                    inlet_specific_energy, 
-                                                    delta_total_energy, 
-                                                    outlet_depth, 
-                                                    sum_loss,
-                                                    manning)
-
-
-        if verbose:
-            print ('%s,%.2f,%.2f,%.2f' %('ANUGAcalcsTEST01 Q-v-d',Q,v,d))
-            print('%s,%.2f,%.2f,%.2f' %('Spreadsheet_Boydcalcs', 0.5526, 1.146, 0.1339))
-            
-        assert numpy.allclose(Q, 0.5526, rtol=1.0e-1) #inflow
-        assert numpy.allclose(v, 1.146, rtol=1.0e-1) #outflow velocity
-        assert numpy.allclose(d, 0.1339, rtol=1.0e-1) #depth at outlet used to calc v 
-   
-   
-   
-   
-    def test_boyd_1_operator(self):
-        """test_boyd_non_skew
-        
-        This tests the Boyd routine with data obtained from culvertw application 1.1 by IceMindserer  BD Parkinson, 
-        calculation code by MJ Boyd 
-        """
-
-        g=9.81
-
-
-        inlet_depth=0.150
-        outlet_depth=0.150
-        inlet_velocity=1.00
-        outlet_velocity=0.5
-        
-        culvert_length=10.0
-        culvert_width=3.6
-        culvert_height=1.20
-        
-        culvert_type='box'
-
-        #sum_loss=1.5
-
-        inlet_specific_energy=inlet_depth + 0.5*inlet_velocity**2/g 
-        culvert_slope=10.0  # % Downward
-        z_in = 10.0
-        z_out = z_in-culvert_length*culvert_slope/100
-        E_in = z_in+inlet_depth + 0.5*inlet_velocity**2/g
-        E_out = z_out+outlet_depth + 0.5*outlet_velocity**2/g
-        delta_total_energy = E_in-E_out
-        inlet_specific_energy=inlet_depth + 0.5*inlet_velocity**2/g 
-        
-        
-        elevation_0 = z_in
-        elevation_1 = z_out
-        
-        stage_0 = elevation_0 + inlet_depth
-        stage_1 = elevation_1 + outlet_depth
- 
-
-        domain_length = 200.0
-        domain_width = 200.0
-
-        #culvert_length = 20.0
-        #culvert_width = 3.66
-        #culvert_height = 3.66
-        culvert_losses = {'inlet':0.5, 'outlet':1.0, 'bend':0.0, 'grate':0.0, 'pier': 0.0, 'other': 0.0}
-        culvert_mannings = 0.013
-        
-        culvert_apron = 0.0
-        enquiry_gap = 5.0
-
-        
-        expected_Q = 0.55
-        expected_v = 1.15
-        expected_d = 0.13
-
-
-        domain = self._create_domain(d_length=domain_length,
-                                     d_width=domain_width,
-                                     dx = 5.0,
-                                     dy = 5.0,
-                                     elevation_0 = elevation_0,
-                                     elevation_1 = elevation_1,
-                                     stage_0 = stage_0,
-                                     stage_1 = stage_1,
-                                     xvelocity_0 = inlet_velocity,
-                                     xvelocity_1 = outlet_velocity)
- 
-
-        #print 'Defining Structures'
-        
-        ep0 = numpy.array([domain_length/2-culvert_length/2, 100.0])
-        ep1 = numpy.array([domain_length/2+culvert_length/2, 100.0])
-        
-        
-        culvert = Boyd_box_operator(domain,
-                                    losses=culvert_losses,
-                                    width=culvert_width,
-                                    end_points=[ep0, ep1],
-                                    height=culvert_height,
-                                    apron=culvert_apron,
-                                    enquiry_gap=enquiry_gap,
-                                    use_momentum_jet=False,
-                                    use_velocity_head=True,
-                                    manning=culvert_mannings,
-                                    logging=False,
-                                    label='3.6x1.2RCBC',
-                                    verbose=False)
-
-        #culvert.determine_inflow_outflow()
-        
-        ( Q, v, d ) = culvert.discharge_routine()
-        
-        if verbose:
-            print 'test_boyd_operator_1'
-            print 'expected ',expected_Q,expected_v, expected_d
-            print 'calc ',Q,v,d
-        
-
-        assert numpy.allclose(Q, expected_Q, rtol=5.0e-2) #inflow
-        assert numpy.allclose(v, expected_v, rtol=5.0e-2) #outflow velocity
-        assert numpy.allclose(d, expected_d, rtol=5.0e-2) #depth at outlet used to calc v 
-        
-        
-        
-               
-    def test_boyd_2(self):
-        """test_boyd_2
-        
-        This tests the Boyd routine with data obtained from culvertw application 1.1 by IceMindserer  BD Parkinson, 
-        calculation code by MJ Boyd     
-        """
-
-
-        g=9.81
-        culvert_slope=10  # Downward
-
-        inlet_depth=0.500
-        outlet_depth=0.700
-        inlet_velocity=1.0
-        outlet_velocity=0.50
-        
-        culvert_length=10.0
-        culvert_width=3.60
-        culvert_height=1.20
-        
-        culvert_type='box'
-        manning=0.013
-        sum_loss=1.5
-
-        inlet_specific_energy=inlet_depth + 0.5*inlet_velocity**2/g 
-        z_in = 0.0
-        z_out = z_in-culvert_length*culvert_slope/100
-        E_in = z_in+inlet_depth + 0.5*inlet_velocity**2/g
-        E_out = z_out+outlet_depth + 0.5*outlet_velocity**2/g
-        delta_total_energy = E_in-E_out
-        
-        Q_expected = 2.50
-        v_expected = 1.897
-        d_expected = 0.367
-        
-        if verbose:
-            print 50*'='
-            print 'width ',culvert_width
-            print 'depth ',culvert_height
-            print 'flow_width ',culvert_width
-            print 'length ' ,culvert_length
-            print 'driving_energy ',inlet_specific_energy
-            print 'delta_total_energy ',delta_total_energy
-            print 'outlet_enquiry_depth ',outlet_depth
-            print 'sum_loss ',sum_loss
-            print 'manning ',manning
-        
-        Q, v, d, flow_area, case= boyd_box_function(culvert_width, 
-                                                    culvert_height, 
-                                                    culvert_width, 
-                                                    culvert_length, 
-                                                    inlet_specific_energy, 
-                                                    delta_total_energy, 
-                                                    outlet_depth, 
-                                                    sum_loss,
-                                                    manning)
-
-
-
-        if verbose:
-            print ('%s,%.2f,%.2f,%.2f' %('ANUGAcalcsTEST02 Q-v-d',Q,v,d))
-            print ('%s,%.2f,%.2f,%.2f' %('Spreadsheet_Boydcalcs', 2.508, 1.897, 0.367))
-            
-        assert numpy.allclose(Q, Q_expected, rtol=1.0e-1) #inflow
-        assert numpy.allclose(v, v_expected, rtol=1.0e-1) #outflow velocity
-        assert numpy.allclose(d, d_expected, rtol=1.0e-1) #depth at outlet used to calc v  
-
-
-    def test_boyd_2_operator(self):
-        """test_boyd_non_skew
-        
-        This tests the Boyd routine with data obtained from culvertw application 1.1 by IceMindserer  BD Parkinson, 
-        calculation code by MJ Boyd 
-        """
-
-        g=9.81
-        culvert_slope=10  # Downward
-
-        inlet_depth=0.500
-        outlet_depth=0.700
-        inlet_velocity=1.0
-        outlet_velocity=0.50
-        
-        culvert_length=10.0
-        culvert_width=3.60
-        culvert_height=1.20
-        
-        culvert_type='box'
-        manning=0.013
-        sum_loss=1.5
-
-        inlet_specific_energy=inlet_depth + 0.5*inlet_velocity**2/g 
-        z_in = 0.0
-        z_out = z_in-culvert_length*culvert_slope/100
-        E_in = z_in+inlet_depth + 0.5*inlet_velocity**2/g
-        E_out = z_out+outlet_depth + 0.5*outlet_velocity**2/g
-        delta_total_energy = E_in-E_out
-        
-      
-        
-        elevation_0 = z_in
-        elevation_1 = z_out
-        
-        stage_0 = elevation_0 + inlet_depth
-        stage_1 = elevation_1 + outlet_depth
- 
-
-        domain_length = 200.0
-        domain_width = 200.0
-
-        #culvert_length = 20.0
-        #culvert_width = 3.66
-        #culvert_height = 3.66
-        culvert_losses = {'inlet':0.5, 'outlet':1.0, 'bend':0.0, 'grate':0.0, 'pier': 0.0, 'other': 0.0}
-        culvert_mannings = 0.013
-        
-        culvert_apron = 0.0
-        enquiry_gap = 5.0
-
-        Q_expected = 2.50
-        v_expected = 1.897
-        d_expected = 0.367
-
-
-        domain = self._create_domain(d_length=domain_length,
-                                     d_width=domain_width,
-                                     dx = 5.0,
-                                     dy = 5.0,
-                                     elevation_0 = elevation_0,
-                                     elevation_1 = elevation_1,
-                                     stage_0 = stage_0,
-                                     stage_1 = stage_1,
-                                     xvelocity_0 = inlet_velocity,
-                                     xvelocity_1 = outlet_velocity)
- 
-
-        #print 'Defining Structures'
-        
-        ep0 = numpy.array([domain_length/2-culvert_length/2, 100.0])
-        ep1 = numpy.array([domain_length/2+culvert_length/2, 100.0])
-        
-        
-        culvert = Boyd_box_operator(domain,
-                                    losses=culvert_losses,
-                                    width=culvert_width,
-                                    end_points=[ep0, ep1],
-                                    height=culvert_height,
-                                    apron=culvert_apron,
-                                    enquiry_gap=enquiry_gap,
-                                    use_momentum_jet=False,
-                                    use_velocity_head=True,
-                                    manning=culvert_mannings,
-                                    logging=False,
-                                    label='3.6x1.2RCBC',
-                                    verbose=False)
-
-        #culvert.determine_inflow_outflow()
-        
-        ( Q, v, d ) = culvert.discharge_routine()
-        
-        if verbose:
-            print 'test_boyd_operator_2'
-            print 'expected ',Q_expected,v_expected, d_expected
-            print 'calc ',Q,v,d
-        
-
-        assert numpy.allclose(Q, Q_expected, rtol=2.0e-2) #inflow
-        assert numpy.allclose(v, v_expected, rtol=2.0e-2) #outflow velocity
-        assert numpy.allclose(d, d_expected, rtol=2.0e-2) #depth at outlet used to calc v 
-        
-        
-
-
-
-    def test_boyd_3(self):
-        """test_boyd_3
-        
-        This tests the Boyd routine with data obtained from culvertw application 1.1 by IceMindserer  BD Parkinson, 
-        calculation code by MJ Boyd     
-        """
-
-
-        g=9.81
-        culvert_slope=10  # Downward
-
-        inlet_depth=1.800
-        outlet_depth=0.80
-        inlet_velocity=1.0
-        outlet_velocity=0.5
-        
-        culvert_length=10.0
-        culvert_width=3.60
-        culvert_height=1.20
-        
-        culvert_type='box'
-        manning=0.013
-        sum_loss=1.5
-
-        inlet_specific_energy=inlet_depth + 0.5*inlet_velocity**2/g 
-        z_in = 0.0
-        z_out = z_in-culvert_length*culvert_slope/100
-        E_in = z_in+inlet_depth + 0.5*inlet_velocity**2/g
-        E_out = z_out+outlet_depth + 0.5*outlet_velocity**2/g
-        delta_total_energy = E_in-E_out
-        
-
-        Q_expected = 13.554
-        v_expected = 3.329
-        d_expected = 1.131
-        
-        if verbose:
-            print 50*'='
-            print 'width ',culvert_width
-            print 'depth ',culvert_height
-            print 'flow_width ',culvert_width
-            print 'length ' ,culvert_length
-            print 'driving_energy ',inlet_specific_energy
-            print 'delta_total_energy ',delta_total_energy
-            print 'outlet_enquiry_depth ',outlet_depth
-            print 'sum_loss ',sum_loss
-            print 'manning ',manning
-        
-        Q, v, d, flow_area, case= boyd_box_function(culvert_width, 
-                                                    culvert_height, 
-                                                    culvert_width, 
-                                                    culvert_length, 
-                                                    inlet_specific_energy, 
-                                                    delta_total_energy, 
-                                                    outlet_depth, 
-                                                    sum_loss,
-                                                    manning)
-
-
-
-
-        if verbose:
-            print ('%s,%.2f'%('SPEC_E = ',inlet_specific_energy))
-            print ('%s,%.2f'%('Delta E = ',delta_total_energy))
-            print ('%s,%.2f,%.2f,%.2f' %('ANUGAcalcsTEST03 Q-v-d',Q,v,d))
-            print ('%s,%.2f,%.2f,%.2f' %('Spreadsheet_Boydcalcs', 13.554, 3.329, 1.131))
-            
-        assert numpy.allclose(Q, Q_expected, rtol=1.0e-2) #inflow
-        assert numpy.allclose(v, v_expected, rtol=1.0e-2) #outflow velocity
-        assert numpy.allclose(d, d_expected, rtol=1.0e-2) #depth at outlet used to calc v 
-
-
-    def test_boyd_3_operator(self):
-        """test_boyd_non_skew
-        
-        This tests the Boyd routine with data obtained from culvertw application 1.1 by IceMindserer  BD Parkinson, 
-        calculation code by MJ Boyd 
-        """
-
-        g=9.81
-        culvert_slope=10  # Downward
-
-        inlet_depth=1.800
-        outlet_depth=0.80
-        inlet_velocity=1.0
-        outlet_velocity=0.5
-        
-        culvert_length=10.0
-        culvert_width=3.60
-        culvert_height=1.20
-        
-        culvert_type='box'
-        manning=0.013
-        sum_loss=1.5
-
-        inlet_specific_energy=inlet_depth + 0.5*inlet_velocity**2/g 
-        z_in = 0.0
-        z_out = z_in-culvert_length*culvert_slope/100
-        E_in = z_in+inlet_depth + 0.5*inlet_velocity**2/g
-        E_out = z_out+outlet_depth + 0.5*outlet_velocity**2/g
-        delta_total_energy = E_in-E_out
-        
-
-        Q_expected = 13.554
-        v_expected = 3.329
-        d_expected = 1.131
-        
-      
-        
-        elevation_0 = z_in
-        elevation_1 = z_out
-        
-        stage_0 = elevation_0 + inlet_depth
-        stage_1 = elevation_1 + outlet_depth
- 
-
-        domain_length = 200.0
-        domain_width = 200.0
-
-        #culvert_length = 20.0
-        #culvert_width = 3.66
-        #culvert_height = 3.66
-        culvert_losses = {'inlet':0.5, 'outlet':1.0, 'bend':0.0, 'grate':0.0, 'pier': 0.0, 'other': 0.0}
-        culvert_mannings = 0.013
-        
-        culvert_apron = 0.0
-        enquiry_gap = 5.0
-
-
-
-
-        domain = self._create_domain(d_length=domain_length,
-                                     d_width=domain_width,
-                                     dx = 5.0,
-                                     dy = 5.0,
-                                     elevation_0 = elevation_0,
-                                     elevation_1 = elevation_1,
-                                     stage_0 = stage_0,
-                                     stage_1 = stage_1,
-                                     xvelocity_0 = inlet_velocity,
-                                     xvelocity_1 = outlet_velocity)
- 
-
-        #print 'Defining Structures'
-        
-        ep0 = numpy.array([domain_length/2-culvert_length/2, 100.0])
-        ep1 = numpy.array([domain_length/2+culvert_length/2, 100.0])
-        
-        
-        culvert = Boyd_box_operator(domain,
-                                    losses=culvert_losses,
-                                    width=culvert_width,
-                                    end_points=[ep0, ep1],
-                                    height=culvert_height,
-                                    apron=culvert_apron,
-                                    enquiry_gap=enquiry_gap,
-                                    use_momentum_jet=False,
-                                    use_velocity_head=True,
-                                    manning=culvert_mannings,
-                                    logging=False,
-                                    label='3.6x1.2RCBC',
-                                    verbose=False)
-
-        #culvert.determine_inflow_outflow()
-        
-        ( Q, v, d ) = culvert.discharge_routine()
-        
-        if verbose:
-            print 'test_boyd_operator_1'
-            print 'expected ',Q_expected,v_expected, d_expected
-            print 'calc ',Q,v,d
-        
-
-        assert numpy.allclose(Q, Q_expected, rtol=2.0e-2) #inflow
-        assert numpy.allclose(v, v_expected, rtol=2.0e-2) #outflow velocity
-        assert numpy.allclose(d, d_expected, rtol=2.0e-2) #depth at outlet used to calc v 
-        
-        
-
-
-
-
-#NOTE FROM HERE DOWN THE UNITS TEST HAVE NOT BEEN AMENDED TO ALLOW VELOCITY COMPONENT TO BE USED. ONLY ABOVE 3 TESTS WORK. PM WILL FIX THE ONES BELOW WHEN THE ABOVE 3 ARE WORKING
-    def test_boyd_4(self):
-        """test_boyd_4
-        
-        This tests the Boyd routine with data obtained from culvertw application 1.1 by IceMindserer  BD Parkinson, 
-        calculation code by MJ Boyd    
-        """
-        # FIXME(Ole): This test fails (20 Feb 2009)
-
-        g=9.81
-        culvert_slope=10  # Downward
-
-        inlet_depth=1.00
-        outlet_depth=0.8
-        inlet_velocity=1.0
-        outlet_velocity=0.5 
-        culvert_length=10.0
-        culvert_width=3.60
-        culvert_height=1.20
-       
-        culvert_type='box'
-        manning=0.013
-        sum_loss=1.5
-
-        inlet_specific_energy=inlet_depth + 0.5*inlet_velocity**2/g 
-        z_in = 10.0
-        z_out = 10.0-culvert_length*culvert_slope/100
-        E_in = z_in+inlet_depth + 0.5*inlet_velocity**2/g
-        E_out = z_out+outlet_depth + 0.5*outlet_velocity**2/g
-        delta_total_energy = E_in-E_out
-        
-        
-        
-        Q_expected = 6.609
-        v_expected = 2.621
-        d_expected = 0.70
-        
-        
-        if verbose:
-            print 50*'='
-            print 'width ',culvert_width
-            print 'depth ',culvert_height
-            print 'flow_width ',culvert_width
-            print 'length ' ,culvert_length
-            print 'driving_energy ',inlet_specific_energy
-            print 'delta_total_energy ',delta_total_energy
-            print 'outlet_enquiry_depth ',outlet_depth
-            print 'sum_loss ',sum_loss
-            print 'manning ',manning
-
-        Q, v, d, flow_area, case= boyd_box_function(culvert_width, 
-                                                    culvert_height, 
-                                                    culvert_width, 
-                                                    culvert_length, 
-                                                    inlet_specific_energy, 
-                                                    delta_total_energy, 
-                                                    outlet_depth, 
-                                                    sum_loss,
-                                                    manning)
-
-
-        if verbose:
-            print ('%s,%.2f'%('SPEC_E = ',inlet_specific_energy))
-            print ('%s,%.2f'%('Delta E = ',delta_total_energy))
-            print ('%s,%.2f,%.2f,%.2f' %('ANUGAcalcsTEST04 Q-v-d',Q,v,d))
-            print ('%s,%.2f,%.2f,%.2f' %('Spreadsheet_Boydcalcs', 6.609, 2.621, 0.70))
-            
-        assert numpy.allclose(Q, Q_expected, rtol=2.0e-2) #inflow
-        assert numpy.allclose(v, v_expected, rtol=2.0e-2) #outflow velocity
-        assert numpy.allclose(d, d_expected, rtol=2.0e-2) #depth at outlet used to calc v 
-
-
-    def test_boyd_4_operator(self):
-        """test_boyd_non_skew
-        
-        This tests the Boyd routine with data obtained from culvertw application 1.1 by IceMindserer  BD Parkinson, 
-        calculation code by MJ Boyd 
-        """
-
-        g=9.81
-        culvert_slope=10  # Downward
-
-        inlet_depth=1.00
-        outlet_depth=0.8
-        inlet_velocity=1.0
-        outlet_velocity=0.5 
-        culvert_length=10.0
-        culvert_width=3.60
-        culvert_height=1.20
-       
-        culvert_type='box'
-        manning=0.013
-        sum_loss=1.5
-
-        inlet_specific_energy=inlet_depth + 0.5*inlet_velocity**2/g 
-        z_in = 10.0
-        z_out = 10.0-culvert_length*culvert_slope/100
-        E_in = z_in+inlet_depth + 0.5*inlet_velocity**2/g
-        E_out = z_out+outlet_depth + 0.5*outlet_velocity**2/g
-        delta_total_energy = E_in-E_out
-        
-        
-        
-        Q_expected = 6.609
-        v_expected = 2.621
-        d_expected = 0.70
-        
-      
-        
-        elevation_0 = z_in
-        elevation_1 = z_out
-        
-        stage_0 = elevation_0 + inlet_depth
-        stage_1 = elevation_1 + outlet_depth
- 
-
-        domain_length = 200.0
-        domain_width = 200.0
-
-        #culvert_length = 20.0
-        #culvert_width = 3.66
-        #culvert_height = 3.66
-        culvert_losses = {'inlet':0.5, 'outlet':1.0, 'bend':0.0, 'grate':0.0, 'pier': 0.0, 'other': 0.0}
-        culvert_mannings = 0.013
-        
-        culvert_apron = 0.0
-        enquiry_gap = 5.0
-
-
-
-
-        domain = self._create_domain(d_length=domain_length,
-                                     d_width=domain_width,
-                                     dx = 5.0,
-                                     dy = 5.0,
-                                     elevation_0 = elevation_0,
-                                     elevation_1 = elevation_1,
-                                     stage_0 = stage_0,
-                                     stage_1 = stage_1,
-                                     xvelocity_0 = inlet_velocity,
-                                     xvelocity_1 = outlet_velocity)
- 
-
-        #print 'Defining Structures'
-        
-        ep0 = numpy.array([domain_length/2-culvert_length/2, 100.0])
-        ep1 = numpy.array([domain_length/2+culvert_length/2, 100.0])
-        
-        
-        culvert = Boyd_box_operator(domain,
-                                    losses=culvert_losses,
-                                    width=culvert_width,
-                                    end_points=[ep0, ep1],
-                                    height=culvert_height,
-                                    apron=culvert_apron,
-                                    enquiry_gap=enquiry_gap,
-                                    use_momentum_jet=False,
-                                    use_velocity_head=True,
-                                    manning=culvert_mannings,
-                                    logging=False,
-                                    label='3.6x1.2RCBC',
-                                    verbose=False)
-
-        #culvert.determine_inflow_outflow()
-        
-        ( Q, v, d ) = culvert.discharge_routine()
-        
-        if verbose:
-            print 'test_boyd_operator_1'
-            print 'expected ',Q_expected,v_expected, d_expected
-            print 'calc ',Q,v,d
-        
-
-        assert numpy.allclose(Q, Q_expected, rtol=2.0e-2) #inflow
-        assert numpy.allclose(v, v_expected, rtol=2.0e-2) #outflow velocity
-        assert numpy.allclose(d, d_expected, rtol=2.0e-2) #depth at outlet used to calc v 
-
-    def test_boyd_5(self):
-        """test_boyd_5
-        
-        This tests the Boyd routine with data obtained from culvertw application 1.1 by IceMindserer  BD Parkinson, 
-        calculation code by MJ Boyd    
-        """
-        # FIXME(Ole): This test fails (20 Feb 2009)
-
-        g=9.81
-        culvert_slope=10  # Downward
-
-        inlet_depth=1.50
-        inlet_velocity= 1.0
-        outlet_depth=2.5
-        outlet_velocity=0.5
-        culvert_length=10.0
-        culvert_width=3.60
-        culvert_height=1.20
-        
-        culvert_type='box'
-        manning=0.013
-        sum_loss=1.5
-
-        inlet_specific_energy=inlet_depth + 0.5*inlet_velocity**2/g 
-        z_in = 10.0
-        z_out = 10.0-culvert_length*culvert_slope/100
-        E_in = z_in+inlet_depth + 0.5*inlet_velocity**2/g
-        E_out = z_out+outlet_depth + 0.5*outlet_velocity**2/g
-        delta_total_energy = E_in-E_out
-    
-        Q_expected = 2.961
-        v_expected = 0.685
-        d_expected = 1.20
-        
-        if verbose:
-            print 50*'='
-            print 'width ',culvert_width
-            print 'depth ',culvert_height
-            print 'flow_width ',culvert_width
-            print 'length ' ,culvert_length
-            print 'driving_energy ',inlet_specific_energy
-            print 'delta_total_energy ',delta_total_energy
-            print 'outlet_enquiry_depth ',outlet_depth
-            print 'sum_loss ',sum_loss
-            print 'manning ',manning
-
-        Q, v, d, flow_area, case= boyd_box_function(culvert_width, 
-                                                    culvert_height, 
-                                                    culvert_width, 
-                                                    culvert_length, 
-                                                    inlet_specific_energy, 
-                                                    delta_total_energy, 
-                                                    outlet_depth, 
-                                                    sum_loss,
-                                                    manning)
-
-
- 
-        if verbose:
-            print ('%s,%.3f'%('SPEC_E = ',inlet_specific_energy))
-            print ('%s,%.3f'%('Delta E = ',delta_total_energy))
-             
-            print ('%s,%.3f,%.3f,%.3f' %('ANUGAcalcsTEST05 Q-v-d',Q,v,d))
-            print ('%s,%.3f,%.3f,%.3f' %('Spreadsheet_Boydcalcs',2.961, 0.685, 1.20))
-            
-        assert numpy.allclose(Q, Q_expected, rtol=2.0e-2) #inflow
-        assert numpy.allclose(v, v_expected, rtol=2.0e-2) #outflow velocity
-        assert numpy.allclose(d, d_expected, rtol=2.0e-2) #depth at outlet used to calc v 
-        
-        
-        
-        
-    def test_boyd_5_operator(self):
-        """test_boyd_non_skew
-        
-        This tests the Boyd routine with data obtained from culvertw application 1.1 by IceMindserer  BD Parkinson, 
-        calculation code by MJ Boyd 
-        """
-
- 
-        g=9.81
-        culvert_slope=10  # Downward
-
-        inlet_depth=1.50
-        inlet_velocity= 1.0
-        outlet_depth=2.5
-        outlet_velocity=0.5
-        culvert_length=10.0
-        culvert_width=3.60
-        culvert_height=1.20
-        
-        culvert_type='box'
-        manning=0.013
-        sum_loss=1.5
-
-        inlet_specific_energy=inlet_depth + 0.5*inlet_velocity**2/g 
-        z_in = 10.0
-        z_out = 10.0-culvert_length*culvert_slope/100
-        E_in = z_in+inlet_depth + 0.5*inlet_velocity**2/g
-        E_out = z_out+outlet_depth + 0.5*outlet_velocity**2/g
-        delta_total_energy = E_in-E_out
-    
-        Q_expected = 2.961
-        v_expected = 0.685
-        d_expected = 1.20
-        
-      
-        
-        elevation_0 = z_in
-        elevation_1 = z_out
-        
-        stage_0 = elevation_0 + inlet_depth
-        stage_1 = elevation_1 + outlet_depth
- 
-
-        domain_length = 200.0
-        domain_width = 200.0
-
-        #culvert_length = 20.0
-        #culvert_width = 3.66
-        #culvert_height = 3.66
-        culvert_losses = {'inlet':0.5, 'outlet':1.0, 'bend':0.0, 'grate':0.0, 'pier': 0.0, 'other': 0.0}
-        culvert_mannings = 0.013
-        
-        culvert_apron = 0.0
-        enquiry_gap = 5.0
-
-
-
-
-        domain = self._create_domain(d_length=domain_length,
-                                     d_width=domain_width,
-                                     dx = 5.0,
-                                     dy = 5.0,
-                                     elevation_0 = elevation_0,
-                                     elevation_1 = elevation_1,
-                                     stage_0 = stage_0,
-                                     stage_1 = stage_1,
-                                     xvelocity_0 = inlet_velocity,
-                                     xvelocity_1 = outlet_velocity)
- 
-
-        #print 'Defining Structures'
-        
-        ep0 = numpy.array([domain_length/2-culvert_length/2, 100.0])
-        ep1 = numpy.array([domain_length/2+culvert_length/2, 100.0])
-        
-        
-        culvert = Boyd_box_operator(domain,
-                                    losses=culvert_losses,
-                                    width=culvert_width,
-                                    end_points=[ep0, ep1],
-                                    height=culvert_height,
-                                    apron=culvert_apron,
-                                    enquiry_gap=enquiry_gap,
-                                    use_momentum_jet=False,
-                                    use_velocity_head=True,
-                                    manning=culvert_mannings,
-                                    logging=False,
-                                    label='3.6x1.2RCBC',
-                                    verbose=False)
-
-        #culvert.determine_inflow_outflow()
-        
-        ( Q, v, d ) = culvert.discharge_routine()
-        
-        if verbose:
-            print 'test_boyd_operator_1'
-            print 'expected ',Q_expected,v_expected, d_expected
-            print 'calc ',Q,v,d
-        
-
-        assert numpy.allclose(Q, Q_expected, rtol=2.0e-2) #inflow
-        assert numpy.allclose(v, v_expected, rtol=2.0e-2) #outflow velocity
-        assert numpy.allclose(d, d_expected, rtol=2.0e-2) #depth at outlet used to calc v 
-
-
-    def test_boyd_6(self):
-        """test_boyd_6
-        
-        This tests the Boyd routine with data obtained from culvertw application 1.1 by IceMindserer  BD Parkinson, 
-        calculation code by MJ Boyd     
-        """
-        # FIXME(Ole): This test fails (20 Feb 2009)
-
-        g=9.81
-        culvert_slope=10  # Downward
-
-        inlet_depth=1.50
-        inlet_velocity= 4.0
-        outlet_depth=0.80
-        outlet_velocity=4.0
-        culvert_length=10.0
-        culvert_width=3.60
-        culvert_height=1.20
-        
-        culvert_type='box'
-        manning=0.013
-        sum_loss=1.5
-
-        inlet_specific_energy=inlet_depth + 0.5*inlet_velocity**2/g 
-        z_in = 10.0
-        z_out = 10.0-culvert_length*culvert_slope/100
-        E_in = z_in+inlet_depth + 0.5*inlet_velocity**2/g
-        E_out = z_out+outlet_depth + 0.5*outlet_velocity**2/g
-        delta_total_energy = E_in-E_out
-
-        Q_expected = 15.537
-        v_expected = 3.597
-        d_expected = 1.20
-
-        if verbose:
-            print 50*'='
-            print 'width ',culvert_width
-            print 'depth ',culvert_height
-            print 'flow_width ',culvert_width
-            print 'length ' ,culvert_length
-            print 'driving_energy ',inlet_specific_energy
-            print 'delta_total_energy ',delta_total_energy
-            print 'outlet_enquiry_depth ',outlet_depth
-            print 'sum_loss ',sum_loss
-            print 'manning ',manning
-            
-        Q, v, d, flow_area, case= boyd_box_function(culvert_width, 
-                                                    culvert_height, 
-                                                    culvert_width, 
-                                                    culvert_length, 
-                                                    inlet_specific_energy, 
-                                                    delta_total_energy, 
-                                                    outlet_depth, 
-                                                    sum_loss,
-                                                    manning)
-
-
-
-
-        if verbose:   
-            print ('%s,%.3f'%('SPEC_E = ',inlet_specific_energy))
-            print ('%s,%.3f'%('Delta E = ',delta_total_energy))
-             
-            print ('%s,%.3f,%.3f,%.3f' %('ANUGAcalcsTEST06 Q-v-d',Q,v,d))
-            print ('%s,%.3f,%.3f,%.3f' %('Spreadsheet_Boydcalcs',15.537, 3.597, 1.20))
-
-        assert numpy.allclose(Q, Q_expected, rtol=2.0e-2) #inflow
-        assert numpy.allclose(v, v_expected, rtol=2.0e-2) #outflow velocity
-        assert numpy.allclose(d, d_expected, rtol=2.0e-2) #depth at outlet used to calc v 
-        
-        
-    def test_boyd_6_operator(self):
-        """test_boyd_non_skew
-        
-        This tests the Boyd routine with data obtained from culvertw application 1.1 by IceMindserer  BD Parkinson, 
-        calculation code by MJ Boyd 
-        """
-
-        g=9.81
-        culvert_slope=10  # Downward
-
-        inlet_depth=1.50
-        inlet_velocity= 4.0
-        outlet_depth=0.80
-        outlet_velocity=4.0
-        culvert_length=10.0
-        culvert_width=3.60
-        culvert_height=1.20
-        
-        culvert_type='box'
-        manning=0.013
-        sum_loss=1.5
-
-        inlet_specific_energy=inlet_depth + 0.5*inlet_velocity**2/g 
-        z_in = 10.0
-        z_out = 10.0-culvert_length*culvert_slope/100
-        E_in = z_in+inlet_depth + 0.5*inlet_velocity**2/g
-        E_out = z_out+outlet_depth + 0.5*outlet_velocity**2/g
-        delta_total_energy = E_in-E_out
-
-        Q_expected = 15.537
-        v_expected = 3.597
-        d_expected = 1.20
-        
-      
-        
-        elevation_0 = z_in
-        elevation_1 = z_out
-        
-        stage_0 = elevation_0 + inlet_depth
-        stage_1 = elevation_1 + outlet_depth
- 
-
-        domain_length = 200.0
-        domain_width = 200.0
-
-        #culvert_length = 20.0
-        #culvert_width = 3.66
-        #culvert_height = 3.66
-        culvert_losses = {'inlet':0.5, 'outlet':1.0, 'bend':0.0, 'grate':0.0, 'pier': 0.0, 'other': 0.0}
-        culvert_mannings = 0.013
-        
-        culvert_apron = 0.0
-        enquiry_gap = 5.0
-
-
-
-
-        domain = self._create_domain(d_length=domain_length,
-                                     d_width=domain_width,
-                                     dx = 5.0,
-                                     dy = 5.0,
-                                     elevation_0 = elevation_0,
-                                     elevation_1 = elevation_1,
-                                     stage_0 = stage_0,
-                                     stage_1 = stage_1,
-                                     xvelocity_0 = inlet_velocity,
-                                     xvelocity_1 = outlet_velocity)
- 
-
-        #print 'Defining Structures'
-        
-        ep0 = numpy.array([domain_length/2-culvert_length/2, 100.0])
-        ep1 = numpy.array([domain_length/2+culvert_length/2, 100.0])
-        
-        
-        culvert = Boyd_box_operator(domain,
-                                    losses=culvert_losses,
-                                    width=culvert_width,
-                                    end_points=[ep0, ep1],
-                                    height=culvert_height,
-                                    apron=culvert_apron,
-                                    enquiry_gap=enquiry_gap,
-                                    use_momentum_jet=False,
-                                    use_velocity_head=True,
-                                    manning=culvert_mannings,
-                                    logging=False,
-                                    label='3.6x1.2RCBC',
-                                    verbose=False)
-
-        #culvert.determine_inflow_outflow()
-        
-        ( Q, v, d ) = culvert.discharge_routine()
-        
-        if verbose:
-            print 'test_boyd_operator_1'
-            print 'expected ',Q_expected,v_expected, d_expected
-            print 'calc ',Q,v,d
-        
-
-        assert numpy.allclose(Q, Q_expected, rtol=2.0e-2) #inflow
-        assert numpy.allclose(v, v_expected, rtol=2.0e-2) #outflow velocity
-        assert numpy.allclose(d, d_expected, rtol=2.0e-2) #depth at outlet used to calc v 
-
-    def test_boyd_7(self):
-        """test_boyd_7
-        
-        This tests the Boyd routine with data obtained from ??? by Petar Milevski    
-        """
-        # FIXME(Ole): This test fails (20 Feb 2009)
-
-        g=9.81
-
-
-        inlet_depth=0.150
-        outlet_depth=0.15
-        inlet_velocity=1.00
-        outlet_velocity=0.5
-        
-        culvert_length=10.0
-        culvert_width=3.6
-        culvert_height=1.20
-        
-        culvert_type='box'
-        manning=0.013
-        sum_loss=1.5
-
-        inlet_specific_energy=inlet_depth + 0.5*inlet_velocity**2/g 
-        culvert_slope=1  # % Downward
-        z_in = 10.0
-        z_out = z_in-culvert_length*culvert_slope/100
-        E_in = z_in+inlet_depth + 0.5*inlet_velocity**2/g
-        E_out = z_out+outlet_depth + 0.5*outlet_velocity**2/g
-        delta_total_energy = E_in-E_out
-        inlet_specific_energy=inlet_depth + 0.5*inlet_velocity**2/g 
-
-
-        Q_expected = 0.5526
-        v_expected = 1.146
-        d_expected = 0.1339
-        
-        if verbose:
-            print 50*'='
-            print 'width ',culvert_width
-            print 'depth ',culvert_height
-            print 'flow_width ',culvert_width
-            print 'length ' ,culvert_length
-            print 'driving_energy ',inlet_specific_energy
-            print 'delta_total_energy ',delta_total_energy
-            print 'outlet_enquiry_depth ',outlet_depth
-            print 'sum_loss ',sum_loss
-            print 'manning ',manning
-            
-        Q, v, d, flow_area, case= boyd_box_function(culvert_width, 
-                                                    culvert_height, 
-                                                    culvert_width, 
-                                                    culvert_length, 
-                                                    inlet_specific_energy, 
-                                                    delta_total_energy, 
-                                                    outlet_depth, 
-                                                    sum_loss,
-                                                    manning)
-        
-#         Q, v, d = boyd_generalised_culvert_model(inlet_depth,
-#                                                  outlet_depth,
-#                                                  inlet_velocity,
-#                                                  outlet_velocity,
-#                                                  inlet_specific_energy, 
-#                                                  delta_total_energy, 
-#                                                  g,
-#                                                  culvert_length,
-#                                                  culvert_width,
-#                                                  culvert_height,
-#                                                  culvert_type,
-#                                                  manning,
-#                                                  sum_loss)
-        if verbose:
-            print ('%s,%.2f,%.2f,%.2f' %('ANUGAcalcsTEST01 Q-v-d',Q,v,d))
-            print('%s,%.2f,%.2f,%.2f' %('Spreadsheet_Boydcalcs', Q_expected, v_expected, d_expected))
-
-        assert numpy.allclose(Q, Q_expected, rtol=1.0e-1) #inflow
-        assert numpy.allclose(v, v_expected, rtol=1.0e-1) #outflow velocity
-        assert numpy.allclose(d, d_expected, rtol=1.0e-1) #depth at outlet used to calc v 
-
-    def test_boyd_7_operator(self):
-        """test_boyd_non_skew
-        
-        This tests the Boyd routine with data obtained from culvertw application 1.1 by IceMindserer  BD Parkinson, 
-        calculation code by MJ Boyd 
-        """
-
-        g=9.81
-
-
-        inlet_depth=0.150
-        outlet_depth=0.15
-        inlet_velocity=1.00
-        outlet_velocity=0.5
-        
-        culvert_length=10.0
-        culvert_width=3.6
-        culvert_height=1.20
-        
-        culvert_type='box'
-        manning=0.013
-        sum_loss=1.5
-
-        inlet_specific_energy=inlet_depth + 0.5*inlet_velocity**2/g 
-        culvert_slope=1  # % Downward
-        z_in = 10.0
-        z_out = z_in-culvert_length*culvert_slope/100
-        E_in = z_in+inlet_depth + 0.5*inlet_velocity**2/g
-        E_out = z_out+outlet_depth + 0.5*outlet_velocity**2/g
-        delta_total_energy = E_in-E_out
-        inlet_specific_energy=inlet_depth + 0.5*inlet_velocity**2/g 
-
-
-        Q_expected = 0.5526
-        v_expected = 1.146
-        d_expected = 0.1339
-        
-      
-        
-        elevation_0 = z_in
-        elevation_1 = z_out
-        
-        stage_0 = elevation_0 + inlet_depth
-        stage_1 = elevation_1 + outlet_depth
- 
-
-        domain_length = 200.0
-        domain_width = 200.0
-
-        #culvert_length = 20.0
-        #culvert_width = 3.66
-        #culvert_height = 3.66
-        culvert_losses = {'inlet':0.5, 'outlet':1.0, 'bend':0.0, 'grate':0.0, 'pier': 0.0, 'other': 0.0}
-        culvert_mannings = 0.013
-        
-        culvert_apron = 0.0
-        enquiry_gap = 5.0
-
-
-
-
-        domain = self._create_domain(d_length=domain_length,
-                                     d_width=domain_width,
-                                     dx = 5.0,
-                                     dy = 5.0,
-                                     elevation_0 = elevation_0,
-                                     elevation_1 = elevation_1,
-                                     stage_0 = stage_0,
-                                     stage_1 = stage_1,
-                                     xvelocity_0 = inlet_velocity,
-                                     xvelocity_1 = outlet_velocity)
- 
-
-        #print 'Defining Structures'
-        
-        ep0 = numpy.array([domain_length/2-culvert_length/2, 100.0])
-        ep1 = numpy.array([domain_length/2+culvert_length/2, 100.0])
-        
-        
-        culvert = Boyd_box_operator(domain,
-                                    losses=culvert_losses,
-                                    width=culvert_width,
-                                    end_points=[ep0, ep1],
-                                    height=culvert_height,
-                                    apron=culvert_apron,
-                                    enquiry_gap=enquiry_gap,
-                                    use_momentum_jet=False,
-                                    use_velocity_head=True,
-                                    manning=culvert_mannings,
-                                    logging=False,
-                                    label='3.6x1.2RCBC',
-                                    verbose=False)
-
-        #culvert.determine_inflow_outflow()
-        
-        ( Q, v, d ) = culvert.discharge_routine()
-        
-        if verbose:
-            print 'test_boyd_operator_1'
-            print 'expected ',Q_expected,v_expected, d_expected
-            print 'calc ',Q,v,d
-        
-
-        assert numpy.allclose(Q, Q_expected, rtol=2.0e-2) #inflow
-        assert numpy.allclose(v, v_expected, rtol=2.0e-2) #outflow velocity
-        assert numpy.allclose(d, d_expected, rtol=2.0e-2) #depth at outlet used to calc v 
-
-
-        
-    def test_boyd_8(self):
-        """test_boyd_8
-        
-        This tests the Boyd routine with data obtained from ??? by Petar Milevski    
-        """
-        # FIXME(Ole): This test fails (20 Feb 2009)
-
-        g=9.81
-        culvert_slope=1  # Downward
-
-        inlet_depth=0.500
-        outlet_depth=0.700
-        inlet_velocity=1.50
-        outlet_velocity=0.50
-        
-        culvert_length=10.0
-        culvert_width=3.60
-        culvert_height=1.20
-        
-        culvert_type='box'
-        manning=0.013
-        sum_loss=1.5
-
-        inlet_specific_energy=inlet_depth + 0.5*inlet_velocity**2/g 
-        z_in = 0.0
-        z_out = z_in-culvert_length*culvert_slope/100
-        E_in = z_in+inlet_depth + 0.5*inlet_velocity**2/g
-        E_out = z_out+outlet_depth + 0.5*outlet_velocity**2/g
-        delta_total_energy = E_in-E_out
-        
-        
-        Q_expected = 0.224
-        v_expected = 0.152
-        d_expected = 0.409
-
-        if verbose:
-            print 50*'='
-            print 'width ',culvert_width
-            print 'depth ',culvert_height
-            print 'flow_width ',culvert_width
-            print 'length ' ,culvert_length
-            print 'driving_energy ',inlet_specific_energy
-            print 'delta_total_energy ',delta_total_energy
-            print 'outlet_enquiry_depth ',outlet_depth
-            print 'sum_loss ',sum_loss
-            print 'manning ',manning
-            
-        Q, v, d, flow_area, case= boyd_box_function(culvert_width, 
-                                                    culvert_height, 
-                                                    culvert_width, 
-                                                    culvert_length, 
-                                                    inlet_specific_energy, 
-                                                    delta_total_energy, 
-                                                    outlet_depth, 
-                                                    sum_loss,
-                                                    manning)
-
-#         Q, v, d = boyd_generalised_culvert_model(inlet_depth,
-#                                                  outlet_depth,
-#                                                  inlet_velocity,
-#                                                  outlet_velocity,
-#                                                  inlet_specific_energy, 
-#                                                  delta_total_energy, 
-#                                                  g,
-#                                                  culvert_length,
-#                                                  culvert_width,
-#                                                  culvert_height,
-#                                                  culvert_type,
-#                                                  manning,
-#                                                  sum_loss)
-        if verbose:
-            print ('%s,%.2f,%.2f,%.2f' %('ANUGAcalcsTEST02 Q-v-d',Q,v,d))
-            print('%s,%.2f,%.2f,%.2f' %('Spreadsheet_Boydcalcs', Q_expected, v_expected, d_expected))
-
-        assert numpy.allclose(Q, Q_expected, rtol=1.0e-1) #inflow
-        assert numpy.allclose(v, v_expected, rtol=1.0e-1) #outflow velocity
-        assert numpy.allclose(d, d_expected, rtol=1.0e-1) #depth at outlet used to calc v 
-
-    def test_boyd_8_operator(self):
-        """test_boyd_non_skew
-        
-        This tests the Boyd routine with data obtained from culvertw application 1.1 by IceMindserer  BD Parkinson, 
-        calculation code by MJ Boyd 
-        """
-
-        g=9.81
-        culvert_slope=1  # Downward
-
-        inlet_depth=0.500
-        outlet_depth=0.700
-        inlet_velocity=1.50
-        outlet_velocity=0.50
-        
-        culvert_length=10.0
-        culvert_width=3.60
-        culvert_height=1.20
-        
-        culvert_type='box'
-        manning=0.013
-        sum_loss=1.5
-
-        inlet_specific_energy=inlet_depth + 0.5*inlet_velocity**2/g 
-        z_in = 0.0
-        z_out = z_in-culvert_length*culvert_slope/100
-        E_in = z_in+inlet_depth + 0.5*inlet_velocity**2/g
-        E_out = z_out+outlet_depth + 0.5*outlet_velocity**2/g
-        delta_total_energy = E_in-E_out
-        
-        
-        Q_expected = 0.224
-        v_expected = 0.152
-        d_expected = 0.409
-        
-        elevation_0 = z_in
-        elevation_1 = z_out
-        
-        stage_0 = elevation_0 + inlet_depth
-        stage_1 = elevation_1 + outlet_depth
- 
-
-        domain_length = 200.0
-        domain_width = 200.0
-
-        #culvert_length = 20.0
-        #culvert_width = 3.66
-        #culvert_height = 3.66
-        culvert_losses = {'inlet':0.5, 'outlet':1.0, 'bend':0.0, 'grate':0.0, 'pier': 0.0, 'other': 0.0}
-        culvert_mannings = 0.013
-        
-        culvert_apron = 0.0
-        enquiry_gap = 5.0
-
-
-
-
-        domain = self._create_domain(d_length=domain_length,
-                                     d_width=domain_width,
-                                     dx = 5.0,
-                                     dy = 5.0,
-                                     elevation_0 = elevation_0,
-                                     elevation_1 = elevation_1,
-                                     stage_0 = stage_0,
-                                     stage_1 = stage_1,
-                                     xvelocity_0 = inlet_velocity,
-                                     xvelocity_1 = outlet_velocity)
- 
-
-        #print 'Defining Structures'
-        
-        ep0 = numpy.array([domain_length/2-culvert_length/2, 100.0])
-        ep1 = numpy.array([domain_length/2+culvert_length/2, 100.0])
-        
-        
-        culvert = Boyd_box_operator(domain,
-                                    losses=culvert_losses,
-                                    width=culvert_width,
-                                    end_points=[ep0, ep1],
-                                    height=culvert_height,
-                                    apron=culvert_apron,
-                                    enquiry_gap=enquiry_gap,
-                                    use_momentum_jet=False,
-                                    use_velocity_head=True,
-                                    manning=culvert_mannings,
-                                    logging=False,
-                                    label='3.6x1.2RCBC',
-                                    verbose=False)
-
-        #culvert.determine_inflow_outflow()
-        
-        ( Q, v, d ) = culvert.discharge_routine()
-        
-        if verbose:
-            print 'test_boyd_operator_1'
-            print 'expected ',Q_expected,v_expected, d_expected
-            print 'calc ',Q,v,d
-        
-
-        assert numpy.allclose(Q, Q_expected, rtol=1.0e-1) #inflow
-        assert numpy.allclose(v, v_expected, rtol=1.0e-1) #outflow velocity
-        assert numpy.allclose(d, d_expected, rtol=1.0e-1) #depth at outlet used to calc v 
-
-
-    def test_boyd_9(self):
-        """test_boyd_9
-        
-        This tests the Boyd routine with data obtained from ??? by Petar Milevski    
-        """
-        # FIXME(Ole): This test fails (20 Feb 2009)
-
-        g=9.81
-        culvert_slope=1  # Downward
-
-        inlet_depth=1.800
-        outlet_depth=0.80
-        inlet_velocity=1.0
-        outlet_velocity=0.5
-        
-        culvert_length=10.0
-        culvert_width=3.60
-        culvert_height=1.20
-        
-        culvert_type='box'
-        manning=0.013
-        sum_loss=1.5
-
-        inlet_specific_energy=inlet_depth + 0.5*inlet_velocity**2/g 
-        z_in = 0.0
-        z_out = z_in-culvert_length*culvert_slope/100
-        E_in = z_in+inlet_depth + 0.5*inlet_velocity**2/g
-        E_out = z_out+outlet_depth + 0.5*outlet_velocity**2/g
-        delta_total_energy = E_in-E_out
-
-
-        Q_expected = 13.554
-        v_expected = 3.329
-        d_expected = 1.131
-        
-        if verbose:
-            print 50*'='
-            print 'width ',culvert_width
-            print 'depth ',culvert_height
-            print 'flow_width ',culvert_width
-            print 'length ' ,culvert_length
-            print 'driving_energy ',inlet_specific_energy
-            print 'delta_total_energy ',delta_total_energy
-            print 'outlet_enquiry_depth ',outlet_depth
-            print 'sum_loss ',sum_loss
-            print 'manning ',manning
-            
-        Q, v, d, flow_area, case= boyd_box_function(culvert_width, 
-                                                    culvert_height, 
-                                                    culvert_width, 
-                                                    culvert_length, 
-                                                    inlet_specific_energy, 
-                                                    delta_total_energy, 
-                                                    outlet_depth, 
-                                                    sum_loss,
-                                                    manning)
-
-
-#         Q, v, d = boyd_generalised_culvert_model(inlet_depth,
-#                                                  outlet_depth,
-#                                                  inlet_velocity,
-#                                                  outlet_velocity,
-#                                                  inlet_specific_energy, 
-#                                                  delta_total_energy, 
-#                                                  g,
-#                                                  culvert_length,
-#                                                  culvert_width,
-#                                                  culvert_height,
-#                                                  culvert_type,
-#                                                  manning,
-#                                                  sum_loss)
-
-        if verbose:
-            print ('%s,%.2f'%('SPEC_E = ',inlet_specific_energy))
-            print ('%s,%.2f'%('Delta E = ',delta_total_energy))
-            print ('%s,%.2f,%.2f,%.2f' %('ANUGAcalcsTEST03 Q-v-d',Q,v,d))
-            print('%s,%.2f,%.2f,%.2f' %('Spreadsheet_Boydcalcs', Q_expected, v_expected, d_expected))
-
-        assert numpy.allclose(Q, Q_expected, rtol=1.0e-1) #inflow
-        assert numpy.allclose(v, v_expected, rtol=1.0e-1) #outflow velocity
-        assert numpy.allclose(d, d_expected, rtol=1.0e-1) #depth at outlet used to calc v 
-
-    def test_boyd_9_operator(self):
-        """test_boyd_non_skew
-        
-        This tests the Boyd routine with data obtained from culvertw application 1.1 by IceMindserer  BD Parkinson, 
-        calculation code by MJ Boyd 
-        """
-
-        g=9.81
-        culvert_slope=1  # Downward
-
-        inlet_depth=1.800
-        outlet_depth=0.80
-        inlet_velocity=1.0
-        outlet_velocity=0.5
-        
-        culvert_length=10.0
-        culvert_width=3.60
-        culvert_height=1.20
-        
-        culvert_type='box'
-        manning=0.013
-        sum_loss=1.5
-
-        inlet_specific_energy=inlet_depth + 0.5*inlet_velocity**2/g 
-        z_in = 0.0
-        z_out = z_in-culvert_length*culvert_slope/100
-        E_in = z_in+inlet_depth + 0.5*inlet_velocity**2/g
-        E_out = z_out+outlet_depth + 0.5*outlet_velocity**2/g
-        delta_total_energy = E_in-E_out
-
-
-        Q_expected = 13.554
-        v_expected = 3.329
-        d_expected = 1.131
-      
-        
-        elevation_0 = z_in
-        elevation_1 = z_out
-        
-        stage_0 = elevation_0 + inlet_depth
-        stage_1 = elevation_1 + outlet_depth
- 
-
-        domain_length = 200.0
-        domain_width = 200.0
-
-        #culvert_length = 20.0
-        #culvert_width = 3.66
-        #culvert_height = 3.66
-        culvert_losses = {'inlet':0.5, 'outlet':1.0, 'bend':0.0, 'grate':0.0, 'pier': 0.0, 'other': 0.0}
-        culvert_mannings = 0.013
-        
-        culvert_apron = 0.0
-        enquiry_gap = 5.0
-
-
-
-
-        domain = self._create_domain(d_length=domain_length,
-                                     d_width=domain_width,
-                                     dx = 5.0,
-                                     dy = 5.0,
-                                     elevation_0 = elevation_0,
-                                     elevation_1 = elevation_1,
-                                     stage_0 = stage_0,
-                                     stage_1 = stage_1,
-                                     xvelocity_0 = inlet_velocity,
-                                     xvelocity_1 = outlet_velocity)
- 
-
-        #print 'Defining Structures'
-        
-        ep0 = numpy.array([domain_length/2-culvert_length/2, 100.0])
-        ep1 = numpy.array([domain_length/2+culvert_length/2, 100.0])
-        
-        
-        culvert = Boyd_box_operator(domain,
-                                    losses=culvert_losses,
-                                    width=culvert_width,
-                                    end_points=[ep0, ep1],
-                                    height=culvert_height,
-                                    apron=culvert_apron,
-                                    enquiry_gap=enquiry_gap,
-                                    use_momentum_jet=False,
-                                    use_velocity_head=True,
-                                    manning=culvert_mannings,
-                                    logging=False,
-                                    label='3.6x1.2RCBC',
-                                    verbose=False)
-
-        #culvert.determine_inflow_outflow()
-        
-        ( Q, v, d ) = culvert.discharge_routine()
-        
-        if verbose:
-            print 'test_boyd_operator_1'
-            print 'expected ',Q_expected,v_expected, d_expected
-            print 'calc ',Q,v,d
-        
-
-        assert numpy.allclose(Q, Q_expected, rtol=2.0e-2) #inflow
-        assert numpy.allclose(v, v_expected, rtol=2.0e-2) #outflow velocity
-        assert numpy.allclose(d, d_expected, rtol=2.0e-2) #depth at outlet used to calc v 
-
-    def test_boyd_10(self):
-        """test_boyd_10
-        
-        This tests the Boyd routine with data obtained from ??? by Petar Milevski    
-        """
-        # FIXME(Ole): This test fails (20 Feb 2009)
-
-        g=9.81
-        culvert_slope=1  # Downward
-
-        inlet_depth=1.00
-        outlet_depth=0.8
-        inlet_velocity=1.0
-        outlet_velocity=0.5 
-        culvert_length=10.0
-        culvert_width=3.60
-        culvert_height=1.20
-       
-        culvert_type='box'
-        manning=0.013
-        sum_loss=1.5
-
-        inlet_specific_energy=inlet_depth + 0.5*inlet_velocity**2/g 
-        z_in = 10.0
-        z_out = 10.0-culvert_length*culvert_slope/100
-        E_in = z_in+inlet_depth + 0.5*inlet_velocity**2/g
-        E_out = z_out+outlet_depth + 0.5*outlet_velocity**2/g
-        delta_total_energy = E_in-E_out
-
-
-
-        Q_expected = 5.164
-        v_expected = 2.047
-        d_expected = 0.70
-        
-        if verbose:
-            print 50*'='
-            print 'width ',culvert_width
-            print 'depth ',culvert_height
-            print 'flow_width ',culvert_width
-            print 'length ' ,culvert_length
-            print 'driving_energy ',inlet_specific_energy
-            print 'delta_total_energy ',delta_total_energy
-            print 'outlet_enquiry_depth ',outlet_depth
-            print 'sum_loss ',sum_loss
-            print 'manning ',manning
-            
-        Q, v, d, flow_area, case= boyd_box_function(culvert_width, 
-                                                    culvert_height, 
-                                                    culvert_width, 
-                                                    culvert_length, 
-                                                    inlet_specific_energy, 
-                                                    delta_total_energy, 
-                                                    outlet_depth, 
-                                                    sum_loss,
-                                                    manning)
-
-#         Q, v, d = boyd_generalised_culvert_model(inlet_depth,
-#                                                  outlet_depth,
-#                                                  inlet_velocity,
-#                                                  outlet_velocity,
-#                                                  inlet_specific_energy, 
-#                                                  delta_total_energy, 
-#                                                  g,
-#                                                  culvert_length,
-#                                                  culvert_width,
-#                                                  culvert_height,
-#                                                  culvert_type,
-#                                                  manning,
-#                                                  sum_loss)        
-
-        if verbose:
-            print ('%s,%.2f'%('SPEC_E = ',inlet_specific_energy))
-            print ('%s,%.2f'%('Delta E = ',delta_total_energy))
-            print ('%s,%.2f,%.2f,%.2f' %('ANUGAcalcsTEST04 Q-v-d',Q,v,d))
-            print('%s,%.2f,%.2f,%.2f' %('Spreadsheet_Boydcalcs', Q_expected, v_expected, d_expected))
-
-        assert numpy.allclose(Q, Q_expected, rtol=1.0e-1) #inflow
-        assert numpy.allclose(v, v_expected, rtol=1.0e-1) #outflow velocity
-        assert numpy.allclose(d, d_expected, rtol=1.0e-1) #depth at outlet used to calc v 
-
-    def test_boyd_10_operator(self):
-        """test_boyd_non_skew
-        
-        This tests the Boyd routine with data obtained from culvertw application 1.1 by IceMindserer  BD Parkinson, 
-        calculation code by MJ Boyd 
-        """
-
-        g=9.81
-        culvert_slope=1  # Downward
-
-        inlet_depth=1.00
-        outlet_depth=0.8
-        inlet_velocity=1.0
-        outlet_velocity=0.5 
-        culvert_length=10.0
-        culvert_width=3.60
-        culvert_height=1.20
-       
-        culvert_type='box'
-        manning=0.013
-        sum_loss=1.5
-
-        inlet_specific_energy=inlet_depth + 0.5*inlet_velocity**2/g 
-        z_in = 10.0
-        z_out = 10.0-culvert_length*culvert_slope/100
-        E_in = z_in+inlet_depth + 0.5*inlet_velocity**2/g
-        E_out = z_out+outlet_depth + 0.5*outlet_velocity**2/g
-        delta_total_energy = E_in-E_out
-
-
-
-        Q_expected = 5.164
-        v_expected = 2.047
-        d_expected = 0.70
-        
-      
-        
-        elevation_0 = z_in
-        elevation_1 = z_out
-        
-        stage_0 = elevation_0 + inlet_depth
-        stage_1 = elevation_1 + outlet_depth
- 
-
-        domain_length = 200.0
-        domain_width = 200.0
-
-        #culvert_length = 20.0
-        #culvert_width = 3.66
-        #culvert_height = 3.66
-        culvert_losses = {'inlet':0.5, 'outlet':1.0, 'bend':0.0, 'grate':0.0, 'pier': 0.0, 'other': 0.0}
-        culvert_mannings = 0.013
-        
-        culvert_apron = 0.0
-        enquiry_gap = 5.0
-
-
-
-
-        domain = self._create_domain(d_length=domain_length,
-                                     d_width=domain_width,
-                                     dx = 5.0,
-                                     dy = 5.0,
-                                     elevation_0 = elevation_0,
-                                     elevation_1 = elevation_1,
-                                     stage_0 = stage_0,
-                                     stage_1 = stage_1,
-                                     xvelocity_0 = inlet_velocity,
-                                     xvelocity_1 = outlet_velocity)
- 
-
-        #print 'Defining Structures'
-        
-        ep0 = numpy.array([domain_length/2-culvert_length/2, 100.0])
-        ep1 = numpy.array([domain_length/2+culvert_length/2, 100.0])
-        
-        
-        culvert = Boyd_box_operator(domain,
-                                    losses=culvert_losses,
-                                    width=culvert_width,
-                                    end_points=[ep0, ep1],
-                                    height=culvert_height,
-                                    apron=culvert_apron,
-                                    enquiry_gap=enquiry_gap,
-                                    use_momentum_jet=False,
-                                    use_velocity_head=True,
-                                    manning=culvert_mannings,
-                                    logging=False,
-                                    label='3.6x1.2RCBC',
-                                    verbose=False)
-
-        #culvert.determine_inflow_outflow()
-        
-        ( Q, v, d ) = culvert.discharge_routine()
-        
-        if verbose:
-            print 'test_boyd_operator_1'
-            print 'expected ',Q_expected,v_expected, d_expected
-            print 'calc ',Q,v,d
-        
-
-        assert numpy.allclose(Q, Q_expected, rtol=2.0e-2) #inflow
-        assert numpy.allclose(v, v_expected, rtol=2.0e-2) #outflow velocity
-        assert numpy.allclose(d, d_expected, rtol=2.0e-2) #depth at outlet used to calc v 
-
-    def test_boyd_11(self):
-        """test_boyd_11
-        
-        This tests the Boyd routine with data obtained from ??? by Petar Milevski    
-        """
-        # FIXME(Ole): This test fails (20 Feb 2009)
-
-        g=9.81
-        culvert_slope=1  # Downward
-
-        inlet_depth=1.50
-        inlet_velocity= 1.0
-        outlet_depth=1.3
-        outlet_velocity=0.5
-        culvert_length=10.0
-        culvert_width=3.60
-        culvert_height=1.20
-        
-        culvert_type='box'
-        manning=0.013
-        sum_loss=1.5
-
-        inlet_specific_energy=inlet_depth + 0.5*inlet_velocity**2/g 
-        z_in = 10.0
-        z_out = 10.0-culvert_length*culvert_slope/100
-        E_in = z_in+inlet_depth + 0.5*inlet_velocity**2/g
-        E_out = z_out+outlet_depth + 0.5*outlet_velocity**2/g
-        delta_total_energy = E_in-E_out
-
-
-        Q_expected = 8.808
-        v_expected = 2.039
-        d_expected = 1.20
-        
-        if verbose:
-            print 50*'='
-            print 'width ',culvert_width
-            print 'depth ',culvert_height
-            print 'flow_width ',culvert_width
-            print 'length ' ,culvert_length
-            print 'driving_energy ',inlet_specific_energy
-            print 'delta_total_energy ',delta_total_energy
-            print 'outlet_enquiry_depth ',outlet_depth
-            print 'sum_loss ',sum_loss
-            print 'manning ',manning
-            
-        Q, v, d, flow_area, case= boyd_box_function(culvert_width, 
-                                                    culvert_height, 
-                                                    culvert_width, 
-                                                    culvert_length, 
-                                                    inlet_specific_energy, 
-                                                    delta_total_energy, 
-                                                    outlet_depth, 
-                                                    sum_loss,
-                                                    manning)
-
-#         Q, v, d = boyd_generalised_culvert_model(inlet_depth,
-#                                                  outlet_depth,
-#                                                  inlet_velocity,
-#                                                  outlet_velocity,
-#                                                  inlet_specific_energy, 
-#                                                  delta_total_energy, 
-#                                                  g,
-#                                                  culvert_length,
-#                                                  culvert_width,
-#                                                  culvert_height,
-#                                                  culvert_type,
-#                                                  manning,
-#                                                  sum_loss)  
-        if verbose:      
-            print ('%s,%.3f'%('SPEC_E = ',inlet_specific_energy))
-            print ('%s,%.3f'%('Delta E = ',delta_total_energy))
-        
-            print ('%s,%.3f,%.3f,%.3f' %('ANUGAcalcsTEST05Q-v-d',Q,v,d))
-            print('%s,%.2f,%.2f,%.2f' %('Spreadsheet_Boydcalcs', Q_expected, v_expected, d_expected))
-
-        assert numpy.allclose(Q, Q_expected, rtol=1.0e-1) #inflow
-        assert numpy.allclose(v, v_expected, rtol=1.0e-1) #outflow velocity
-        assert numpy.allclose(d, d_expected, rtol=1.0e-1) #depth at outlet used to calc v 
-
-    def test_boyd_11_operator(self):
-        """test_boyd_non_skew
-        
-        This tests the Boyd routine with data obtained from culvertw application 1.1 by IceMindserer  BD Parkinson, 
-        calculation code by MJ Boyd 
-        """
-
-        g=9.81
-        culvert_slope=1  # Downward
-
-        inlet_depth=1.50
-        inlet_velocity= 1.0
-        outlet_depth=1.3
-        outlet_velocity=0.5
-        culvert_length=10.0
-        culvert_width=3.60
-        culvert_height=1.20
-        
-        culvert_type='box'
-        manning=0.013
-        sum_loss=1.5
-
-        inlet_specific_energy=inlet_depth + 0.5*inlet_velocity**2/g 
-        z_in = 10.0
-        z_out = 10.0-culvert_length*culvert_slope/100
-        E_in = z_in+inlet_depth + 0.5*inlet_velocity**2/g
-        E_out = z_out+outlet_depth + 0.5*outlet_velocity**2/g
-        delta_total_energy = E_in-E_out
-
-
-        Q_expected = 8.808
-        v_expected = 2.039
-        d_expected = 1.20
-        
-      
-        
-        elevation_0 = z_in
-        elevation_1 = z_out
-        
-        stage_0 = elevation_0 + inlet_depth
-        stage_1 = elevation_1 + outlet_depth
- 
-
-        domain_length = 200.0
-        domain_width = 200.0
-
-        #culvert_length = 20.0
-        #culvert_width = 3.66
-        #culvert_height = 3.66
-        culvert_losses = {'inlet':0.5, 'outlet':1.0, 'bend':0.0, 'grate':0.0, 'pier': 0.0, 'other': 0.0}
-        culvert_mannings = 0.013
-        
-        culvert_apron = 0.0
-        enquiry_gap = 5.0
-
-
-
-
-        domain = self._create_domain(d_length=domain_length,
-                                     d_width=domain_width,
-                                     dx = 5.0,
-                                     dy = 5.0,
-                                     elevation_0 = elevation_0,
-                                     elevation_1 = elevation_1,
-                                     stage_0 = stage_0,
-                                     stage_1 = stage_1,
-                                     xvelocity_0 = inlet_velocity,
-                                     xvelocity_1 = outlet_velocity)
- 
-
-        #print 'Defining Structures'
-        
-        ep0 = numpy.array([domain_length/2-culvert_length/2, 100.0])
-        ep1 = numpy.array([domain_length/2+culvert_length/2, 100.0])
-        
-        
-        culvert = Boyd_box_operator(domain,
-                                    losses=culvert_losses,
-                                    width=culvert_width,
-                                    end_points=[ep0, ep1],
-                                    height=culvert_height,
-                                    apron=culvert_apron,
-                                    enquiry_gap=enquiry_gap,
-                                    use_momentum_jet=False,
-                                    use_velocity_head=True,
-                                    manning=culvert_mannings,
-                                    logging=False,
-                                    label='3.6x1.2RCBC',
-                                    verbose=False)
-
-        #culvert.determine_inflow_outflow()
-        
-        ( Q, v, d ) = culvert.discharge_routine()
-        
-        if verbose:
-            print 'test_boyd_operator_1'
-            print 'expected ',Q_expected,v_expected, d_expected
-            print 'calc ',Q,v,d
-        
-
-        assert numpy.allclose(Q, Q_expected, rtol=2.0e-2) #inflow
-        assert numpy.allclose(v, v_expected, rtol=2.0e-2) #outflow velocity
-        assert numpy.allclose(d, d_expected, rtol=2.0e-2) #depth at outlet used to calc v 
-
-
-    def test_boyd_12(self):
-        """test_boyd_12
-        
-        This tests the Boyd routine with data obtained from ??? by Petar Milevski    
-        """
-        # FIXME(Ole): This test fails (20 Feb 2009)
-
-        g=9.81
-        culvert_slope=1  # Downward
-
-        inlet_depth=1.50
-        inlet_velocity= 4.0
-        outlet_depth=0.8
-        outlet_velocity=4.0
-        culvert_length=10.0
-        culvert_width=3.60
-        culvert_height=1.20
-        
-        culvert_type='box'
-        manning=0.013
-        sum_loss=1.5
-
-        inlet_specific_energy=inlet_depth + 0.5*inlet_velocity**2/g 
-        z_in = 10.0
-        z_out = 10.0-culvert_length*culvert_slope/100
-        E_in = z_in+inlet_depth + 0.5*inlet_velocity**2/g
-        E_out = z_out+outlet_depth + 0.5*outlet_velocity**2/g
-        delta_total_energy = E_in-E_out
-
-
-        Q_expected = 13.546
-        v_expected = 3.136
-        d_expected = 1.20
-        
-        if verbose:
-            print 50*'='
-            print 'width ',culvert_width
-            print 'depth ',culvert_height
-            print 'flow_width ',culvert_width
-            print 'length ' ,culvert_length
-            print 'driving_energy ',inlet_specific_energy
-            print 'delta_total_energy ',delta_total_energy
-            print 'outlet_enquiry_depth ',outlet_depth
-            print 'sum_loss ',sum_loss
-            print 'manning ',manning
-            
-        Q, v, d, flow_area, case= boyd_box_function(culvert_width, 
-                                                    culvert_height, 
-                                                    culvert_width, 
-                                                    culvert_length, 
-                                                    inlet_specific_energy, 
-                                                    delta_total_energy, 
-                                                    outlet_depth, 
-                                                    sum_loss,
-                                                    manning)
-
-#         Q, v, d = boyd_generalised_culvert_model(inlet_depth,
-#                                                  outlet_depth,
-#                                                  inlet_velocity,
-#                                                  outlet_velocity,
-#                                                  inlet_specific_energy, 
-#                                                  delta_total_energy, 
-#                                                  g,
-#                                                  culvert_length,
-#                                                  culvert_width,
-#                                                  culvert_height,
-#                                                  culvert_type,
-#                                                  manning,
-#                                                  sum_loss)        
-        if verbose:
-            print ('%s,%.3f'%('SPEC_E = ',inlet_specific_energy))
-            print ('%s,%.3f'%('Delta E = ',delta_total_energy))
-        
-            print ('%s,%.3f,%.3f,%.3f' %('ANUGAcalcsTEST06 Q-v-d',Q,v,d))
-            print('%s,%.2f,%.2f,%.2f' %('Spreadsheet_Boydcalcs', Q_expected, v_expected, d_expected))
-
-        assert numpy.allclose(Q, Q_expected, rtol=1.0e-1) #inflow
-        assert numpy.allclose(v, v_expected, rtol=1.0e-1) #outflow velocity
-        assert numpy.allclose(d, d_expected, rtol=1.0e-1) #depth at outlet used to calc v 
-
-    def test_boyd_12_operator(self):
-        """test_boyd_non_skew
-        
-        This tests the Boyd routine with data obtained from culvertw application 1.1 by IceMindserer  BD Parkinson, 
-        calculation code by MJ Boyd 
-        """
-
-        g=9.81
-        culvert_slope=1  # Downward
-
-        inlet_depth=1.50
-        inlet_velocity= 4.0
-        outlet_depth=0.8
-        outlet_velocity=4.0
-        culvert_length=10.0
-        culvert_width=3.60
-        culvert_height=1.20
-        
-        culvert_type='box'
-        manning=0.013
-        sum_loss=1.5
-
-        inlet_specific_energy=inlet_depth + 0.5*inlet_velocity**2/g 
-        z_in = 10.0
-        z_out = 10.0-culvert_length*culvert_slope/100
-        E_in = z_in+inlet_depth + 0.5*inlet_velocity**2/g
-        E_out = z_out+outlet_depth + 0.5*outlet_velocity**2/g
-        delta_total_energy = E_in-E_out
-
-
-        Q_expected = 13.546
-        v_expected = 3.136
-        d_expected = 1.20
-        
-        elevation_0 = z_in
-        elevation_1 = z_out
-        
-        stage_0 = elevation_0 + inlet_depth
-        stage_1 = elevation_1 + outlet_depth
- 
-
-        domain_length = 200.0
-        domain_width = 200.0
-
-        #culvert_length = 20.0
-        #culvert_width = 3.66
-        #culvert_height = 3.66
-        culvert_losses = {'inlet':0.5, 'outlet':1.0, 'bend':0.0, 'grate':0.0, 'pier': 0.0, 'other': 0.0}
-        culvert_mannings = 0.013
-        
-        culvert_apron = 0.0
-        enquiry_gap = 5.0
-
-
-
-
-        domain = self._create_domain(d_length=domain_length,
-                                     d_width=domain_width,
-                                     dx = 5.0,
-                                     dy = 5.0,
-                                     elevation_0 = elevation_0,
-                                     elevation_1 = elevation_1,
-                                     stage_0 = stage_0,
-                                     stage_1 = stage_1,
-                                     xvelocity_0 = inlet_velocity,
-                                     xvelocity_1 = outlet_velocity)
- 
-
-        #print 'Defining Structures'
-        
-        ep0 = numpy.array([domain_length/2-culvert_length/2, 100.0])
-        ep1 = numpy.array([domain_length/2+culvert_length/2, 100.0])
-        
-        
-        culvert = Boyd_box_operator(domain,
-                                    losses=culvert_losses,
-                                    width=culvert_width,
-                                    end_points=[ep0, ep1],
-                                    height=culvert_height,
-                                    apron=culvert_apron,
-                                    enquiry_gap=enquiry_gap,
-                                    use_momentum_jet=False,
-                                    use_velocity_head=True,
-                                    manning=culvert_mannings,
-                                    logging=False,
-                                    label='3.6x1.2RCBC',
-                                    verbose=False)
-
-        #culvert.determine_inflow_outflow()
-        
-        ( Q, v, d ) = culvert.discharge_routine()
-        
-        if verbose:
-            print 'test_boyd_operator_1'
-            print 'expected ',Q_expected,v_expected, d_expected
-            print 'calc ',Q,v,d
-        
-
-        assert numpy.allclose(Q, Q_expected, rtol=2.0e-2) #inflow
-        assert numpy.allclose(v, v_expected, rtol=2.0e-2) #outflow velocity
-        assert numpy.allclose(d, d_expected, rtol=2.0e-2) #depth at outlet used to calc v 
-        
-
-    def test_boyd_12_operator_invert(self):
-        """test_boyd_non_skew
-        
-        This tests the Boyd routine with data obtained from culvertw application 1.1 by IceMindserer  BD Parkinson, 
-        calculation code by MJ Boyd 
-        """
-
-        #verbose = True
-        g=9.81
-        culvert_slope=1  # Downward
-
-        inlet_depth=1.50
-        inlet_velocity= 4.0
-        outlet_depth=0.8
-        outlet_velocity=4.0
-        culvert_length=10.0
-        culvert_width=3.60
-        culvert_height=1.20
-        
-        culvert_type='box'
-        manning=0.013
-        sum_loss=1.5
-
-        inlet_specific_energy=inlet_depth + 0.5*inlet_velocity**2/g 
-        z_in = 10.0
-        z_out = 10.0-culvert_length*culvert_slope/100
-        E_in = z_in+inlet_depth + 0.5*inlet_velocity**2/g
-        E_out = z_out+outlet_depth + 0.5*outlet_velocity**2/g
-        delta_total_energy = E_in-E_out
-
-        invert0 = 20.0
-        invert1 = 30.0
-
-
-        #Q_expected = 13.546
-        #v_expected = 3.136
-        #d_expected = 1.20
-        
-        Q_expected = 0.0
-        v_expected = 0.0
-        d_expected = 0.0
-        
-        elevation_0 = z_in
-        elevation_1 = z_out
-        
-        stage_0 = elevation_0 + inlet_depth
-        stage_1 = elevation_1 + outlet_depth
- 
-
-        domain_length = 200.0
-        domain_width = 200.0
-
-        #culvert_length = 20.0
-        #culvert_width = 3.66
-        #culvert_height = 3.66
-        culvert_losses = {'inlet':0.5, 'outlet':1.0, 'bend':0.0, 'grate':0.0, 'pier': 0.0, 'other': 0.0}
-        culvert_mannings = 0.013
-        
-        culvert_apron = 0.0
-        enquiry_gap = 5.0
-
-
-
-
-        domain = self._create_domain(d_length=domain_length,
-                                     d_width=domain_width,
-                                     dx = 5.0,
-                                     dy = 5.0,
-                                     elevation_0 = elevation_0,
-                                     elevation_1 = elevation_1,
-                                     stage_0 = stage_0,
-                                     stage_1 = stage_1,
-                                     xvelocity_0 = inlet_velocity,
-                                     xvelocity_1 = outlet_velocity)
- 
-
-        #print 'Defining Structures'
-        
-        ep0 = numpy.array([domain_length/2-culvert_length/2, 100.0])
-        ep1 = numpy.array([domain_length/2+culvert_length/2, 100.0])
-        
-        
-        culvert = Boyd_box_operator(domain,
-                                    losses=culvert_losses,
-                                    width=culvert_width,
-                                    end_points=[ep0, ep1],
-                                    height=culvert_height,
-                                    apron=culvert_apron,
-                                    #invert_elevations=[elevation_0,elevation_1],
-                                    invert_elevations=[invert0,invert1],
-                                    enquiry_gap=enquiry_gap,
-                                    use_momentum_jet=False,
-                                    use_velocity_head=True,
-                                    manning=culvert_mannings,
-                                    logging=False,
-                                    label='3.6x1.2RCBC',
-                                    verbose=verbose)
-
-        #culvert.determine_inflow_outflow()
-        
-        ( Q, v, d ) = culvert.discharge_routine()
-        
-        if verbose:
-            print 'test_boyd_operator_12_invert'
-            print 'expected ',Q_expected,v_expected, d_expected
-            print 'calc ',Q,v,d
-        
-
-        assert numpy.allclose(Q, Q_expected, rtol=2.0e-2) #inflow
-        assert numpy.allclose(v, v_expected, rtol=2.0e-2) #outflow velocity
-        assert numpy.allclose(d, d_expected, rtol=2.0e-2) #depth at outlet used to calc v 
-        
-       
-# =========================================================================
-if __name__ == "__main__":
-    suite = unittest.makeSuite(Test_boyd_box_operator, 'test')
-    runner = unittest.TextTestRunner()
-    runner.run(suite)
Index: unk/anuga_core/source/anuga/structures/test_boyd_pipe_operator.py
===================================================================
--- /trunk/anuga_core/source/anuga/structures/test_boyd_pipe_operator.py	(revision 9439)
+++ 	(revision )
@@ -1,482 +1,0 @@
-#!/usr/bin/env python
-
-
-import unittest
-
-
-from anuga.structures.boyd_pipe_operator import Boyd_pipe_operator
-from anuga.structures.boyd_pipe_operator import boyd_pipe_function
-
-from anuga.abstract_2d_finite_volumes.mesh_factory import rectangular_cross
-from anuga.shallow_water.shallow_water_domain import Domain
-import numpy
-
-verbose = False
-#diameter = width
-
-class Test_boyd_pipe_operator(unittest.TestCase):
-    """
-	Test the boyd box operator, in particular the discharge_routine!
-    """
-
-    def setUp(self):
-        pass
-
-    def tearDown(self):
-        pass
-    
-    
-    def _create_domain(self,d_length,
-                            d_width,
-                            dx,
-                            dy,
-                            elevation_0,
-                            elevation_1,
-                            stage_0,
-                            stage_1,
-                            xvelocity_0 = 0.0,
-                            xvelocity_1 = 0.0,
-                            yvelocity_0 = 0.0,
-                            yvelocity_1 = 0.0):
-        
-        points, vertices, boundary = rectangular_cross(int(d_length/dx), int(d_width/dy),
-                                                        len1=d_length, len2=d_width)
-        domain = Domain(points, vertices, boundary)   
-        domain.set_name('Test_Outlet_Inlet')                 # Output name
-        domain.set_store()
-        domain.set_default_order(2)
-        domain.H0 = 0.01
-        domain.tight_slope_limiters = 1
-
-        #print 'Size', len(domain)
-
-        #------------------------------------------------------------------------------
-        # Setup initial conditions
-        #------------------------------------------------------------------------------
-
-        def elevation(x, y):
-            """Set up a elevation
-            """
-            
-            z = numpy.zeros(x.shape,dtype='d')
-            z[:] = elevation_0
-            
-            numpy.putmask(z, x > d_length/2, elevation_1)
-    
-            return z
-            
-        def stage(x,y):
-            """Set up stage
-            """
-            z = numpy.zeros(x.shape,dtype='d')
-            z[:] = stage_0
-            
-            numpy.putmask(z, x > d_length/2, stage_1)
-
-            return z
-        
-        def xmom(x,y):
-            """Set up xmomentum
-            """
-            z = numpy.zeros(x.shape,dtype='d')
-            z[:] = xvelocity_0*(stage_0-elevation_0)
-            
-            numpy.putmask(z, x > d_length/2, xvelocity_1*(stage_1-elevation_1) )
-
-            return z
-        
-        def ymom(x,y):
-            """Set up ymomentum
-            """
-            z = numpy.zeros(x.shape,dtype='d')
-            z[:] = yvelocity_0*(stage_0-elevation_0)
-            
-            numpy.putmask(z, x > d_length/2, yvelocity_1*(stage_1-elevation_1) )
-
-            return z
-            
-        #print 'Setting Quantities....'
-        domain.set_quantity('elevation', elevation)  # Use function for elevation
-        domain.set_quantity('stage',  stage)   # Use function for elevation
-        domain.set_quantity('xmomentum',  xmom) 
-        domain.set_quantity('ymomentum',  ymom) 
-        
-        return domain
-
-    def test_boyd_non_skew1(self):
-        """test_boyd_non_skew
-        
-        This tests the Boyd routine with data obtained from culvertw application 1.1 by IceMindserer  BD Parkinson, 
-        calculation code by MJ Boyd 
-        """
-
-        stage_0 = 11.5
-        stage_1 = 10.0
-        elevation_0 = 11.0
-        elevation_1 = 10.0
-
-        domain_length = 200.0
-        domain_width = 200.0
-
-        culvert_length = 20.0
-        culvert_width = 1.2
-        ##culvert_height = 3.66
-        culvert_losses = {'inlet':0.5, 'outlet':1.0, 'bend':0.0, 'grate':0.0, 'pier': 0.0, 'other': 0.0}
-        culvert_mannings = 0.013
-        
-        culvert_apron = 0.0
-        enquiry_gap = 5.0
-
-        
-        expected_Q = 0.50
-        expected_v = 0.78
-        expected_d = 0.66
-        
-
-        domain = self._create_domain(d_length=domain_length,
-                                     d_width=domain_width,
-                                     dx = 5.0,
-                                     dy = 5.0,
-                                     elevation_0 = elevation_0,
-                                     elevation_1 = elevation_1,
-                                     stage_0 = stage_0,
-                                     stage_1 = stage_1)
- 
-
-        #print 'Defining Structures'
-        
-        ep0 = numpy.array([domain_length/2-culvert_length/2, 100.0])
-        ep1 = numpy.array([domain_length/2+culvert_length/2, 100.0])
-        
-        
-        culvert = Boyd_pipe_operator(domain,
-                                    losses=culvert_losses,
-                                    diameter=culvert_width,
-                                    end_points=[ep0, ep1],
-                                    #height=culvert_height,
-                                    apron=culvert_apron,
-                                    enquiry_gap=enquiry_gap,
-                                    use_momentum_jet=False,
-                                    use_velocity_head=False,
-                                    manning=culvert_mannings,
-                                    logging=False,
-                                    label='1.2pipe',
-                                    verbose=False)
-
-        #culvert.determine_inflow_outflow()
-        
-        ( Q, v, d ) = culvert.discharge_routine()
-        
-        if verbose:
-            print 'test_boyd_non_skew'
-            print 'Q: ', Q, 'expected_Q: ', expected_Q
-            print 'v: ', v, 'expected_v: ', expected_v
-            print 'd: ', d, 'expected_d: ', expected_d
-
-        assert numpy.allclose(Q, expected_Q, rtol=1.0e-2) #inflow
-        assert numpy.allclose(v, expected_v, rtol=1.0e-2) #outflow velocity
-        assert numpy.allclose(d, expected_d, rtol=1.0e-2) #depth at outlet used to calc v 
-        
-    def test_boyd_non_skew2(self):
-        """test_boyd_non_skew
-        
-        This tests the Boyd routine with data obtained from culvertw application 1.1 by IceMindserer  BD Parkinson, 
-        calculation code by MJ Boyd 
-        """
-
-        stage_0 = 12.2
-        stage_1 = 10.0
-        elevation_0 = 11.0
-        elevation_1 = 10.0
-
-        domain_length = 200.0
-        domain_width = 200.0
-
-        culvert_length = 20.0
-        culvert_width = 1.2
-        ##culvert_height = 3.66
-        culvert_losses = {'inlet':0.5, 'outlet':1.0, 'bend':0.0, 'grate':0.0, 'pier': 0.0, 'other': 0.0}
-        culvert_mannings = 0.013
-        
-        culvert_apron = 0.0
-        enquiry_gap = 5.0
-
-        
-        expected_Q = 2.08
-        expected_v = 2.13
-        expected_d = 0.96
-        
-
-        domain = self._create_domain(d_length=domain_length,
-                                     d_width=domain_width,
-                                     dx = 5.0,
-                                     dy = 5.0,
-                                     elevation_0 = elevation_0,
-                                     elevation_1 = elevation_1,
-                                     stage_0 = stage_0,
-                                     stage_1 = stage_1)
- 
-
-        #print 'Defining Structures'
-        
-        ep0 = numpy.array([domain_length/2-culvert_length/2, 100.0])
-        ep1 = numpy.array([domain_length/2+culvert_length/2, 100.0])
-        
-        
-        culvert = Boyd_pipe_operator(domain,
-                                    losses=culvert_losses,
-                                    diameter=culvert_width,
-                                    end_points=[ep0, ep1],
-                                    #height=culvert_height,
-                                    apron=culvert_apron,
-                                    enquiry_gap=enquiry_gap,
-                                    use_momentum_jet=False,
-                                    use_velocity_head=False,
-                                    manning=culvert_mannings,
-                                    logging=False,
-                                    label='1.2pipe',
-                                    verbose=False)
-
-        #culvert.determine_inflow_outflow()
-        
-        ( Q, v, d ) = culvert.discharge_routine()
-        
-        if verbose:
-            print 'test_boyd_non_skew2'
-            print 'Q: ', Q, 'expected_Q: ', expected_Q
-            print 'v: ', v, 'expected_v: ', expected_v
-            print 'd: ', d, 'expected_d: ', expected_d
-
-        assert numpy.allclose(Q, expected_Q, rtol=1.0e-2) #inflow
-        assert numpy.allclose(v, expected_v, rtol=1.0e-2) #outflow velocity
-        assert numpy.allclose(d, expected_d, rtol=1.0e-2) #depth at outlet used to calc v  
-        
-    def test_boyd_non_skew3(self):
-        """test_boyd_non_skew
-        
-        This tests the Boyd routine with data obtained from culvertw application 1.1 by IceMindserer  BD Parkinson, 
-        calculation code by MJ Boyd 
-        """
-
-        stage_0 = 15.0
-        stage_1 = 10.0
-        elevation_0 = 11.0
-        elevation_1 = 10.0
-
-        domain_length = 200.0
-        domain_width = 200.0
-
-        culvert_length = 20.0
-        culvert_width = 1.2
-        ##culvert_height = 3.66
-        culvert_losses = {'inlet':0.5, 'outlet':1.0, 'bend':0.0, 'grate':0.0, 'pier': 0.0, 'other': 0.0}
-        culvert_mannings = 0.013
-        
-        culvert_apron = 0.0
-        enquiry_gap = 5.0
-
-        
-        expected_Q = 5.59
-        expected_v = 4.94
-        expected_d = 1.20
-        
-
-        domain = self._create_domain(d_length=domain_length,
-                                     d_width=domain_width,
-                                     dx = 5.0,
-                                     dy = 5.0,
-                                     elevation_0 = elevation_0,
-                                     elevation_1 = elevation_1,
-                                     stage_0 = stage_0,
-                                     stage_1 = stage_1)
- 
-
-        #print 'Defining Structures'
-        
-        ep0 = numpy.array([domain_length/2-culvert_length/2, 100.0])
-        ep1 = numpy.array([domain_length/2+culvert_length/2, 100.0])
-        
-        
-        culvert = Boyd_pipe_operator(domain,
-                                    losses=culvert_losses,
-                                    diameter=culvert_width,
-                                    end_points=[ep0, ep1],
-                                    #height=culvert_height,
-                                    apron=culvert_apron,
-                                    enquiry_gap=enquiry_gap,
-                                    use_momentum_jet=False,
-                                    use_velocity_head=False,
-                                    manning=culvert_mannings,
-                                    logging=False,
-                                    label='1.2pipe',
-                                    verbose=False)
-
-        #culvert.determine_inflow_outflow()
-        
-        ( Q, v, d ) = culvert.discharge_routine()
-        
-        if verbose:
-            print 'test_boyd_non_skew3'
-            print 'Q: ', Q, 'expected_Q: ', expected_Q
-            print 'v: ', v, 'expected_v: ', expected_v
-            print 'd: ', d, 'expected_d: ', expected_d
-
- 
-        assert numpy.allclose(Q, expected_Q, rtol=1.0e-2) #inflow
-        assert numpy.allclose(v, expected_v, rtol=1.0e-2) #outflow velocity
-        assert numpy.allclose(d, expected_d, rtol=1.0e-2) #depth at outlet used to calc v 
-        
-    def test_boyd_non_skew4(self):
-        """test_boyd_non_skew
-        
-        This tests the Boyd routine with data obtained from culvertw application 1.1 by IceMindserer  BD Parkinson, 
-        calculation code by MJ Boyd 
-        """
-
-        stage_0 = 12.2 #change
-        stage_1 = 11.2 #change
-        elevation_0 = 11.0
-        elevation_1 = 10.0
-
-        domain_length = 200.0
-        domain_width = 200.0
-
-        culvert_length = 20.0
-        culvert_width = 1.2
-        ##culvert_height = 3.66
-        culvert_losses = {'inlet':0.5, 'outlet':1.0, 'bend':0.0, 'grate':0.0, 'pier': 0.0, 'other': 0.0}
-        culvert_mannings = 0.013
-        
-        culvert_apron = 0.0
-        enquiry_gap = 5.0
-
-        
-        expected_Q = 2.08
-        expected_v = 2.13
-        expected_d = 0.96
-        
-
-        domain = self._create_domain(d_length=domain_length,
-                                     d_width=domain_width,
-                                     dx = 5.0,
-                                     dy = 5.0,
-                                     elevation_0 = elevation_0,
-                                     elevation_1 = elevation_1,
-                                     stage_0 = stage_0,
-                                     stage_1 = stage_1)
- 
-
-        #print 'Defining Structures'
-        
-        ep0 = numpy.array([domain_length/2-culvert_length/2, 100.0])
-        ep1 = numpy.array([domain_length/2+culvert_length/2, 100.0])
-        
-        
-        culvert = Boyd_pipe_operator(domain,
-                                    losses=culvert_losses,
-                                    diameter=culvert_width,
-                                    end_points=[ep0, ep1],
-                                    #height=culvert_height,
-                                    apron=culvert_apron,
-                                    enquiry_gap=enquiry_gap,
-                                    use_momentum_jet=False,
-                                    use_velocity_head=False,
-                                    manning=culvert_mannings,
-                                    logging=False,
-                                    label='1.2pipe',
-                                    verbose=False)
-
-        #culvert.determine_inflow_outflow()
-        
-        ( Q, v, d ) = culvert.discharge_routine()
-        
-        if verbose:
-            print 'test_boyd_non_skew4'
-            print 'Q: ', Q, 'expected_Q: ', expected_Q
-            print 'v: ', v, 'expected_v: ', expected_v
-            print 'd: ', d, 'expected_d: ', expected_d
-
-
-        assert numpy.allclose(Q, expected_Q, rtol=1.0e-2) #inflow
-        assert numpy.allclose(v, expected_v, rtol=1.0e-2) #outflow velocity
-        assert numpy.allclose(d, expected_d, rtol=1.0e-2) #depth at outlet used to calc v 
-        
-    def test_boyd_non_skew5(self):
-        """test_boyd_non_skew
-        
-        This tests the Boyd routine with data obtained from culvertw application 1.1 by IceMindserer  BD Parkinson, 
-        calculation code by MJ Boyd 
-        """
-
-        stage_0 = 15.0 #change
-        stage_1 = 14.0 #change
-        elevation_0 = 11.0
-        elevation_1 = 10.0
-
-        domain_length = 200.0
-        domain_width = 200.0
-
-        culvert_length = 20.0
-        culvert_width = 1.2
-        ##culvert_height = 3.66
-        culvert_losses = {'inlet':0.5, 'outlet':1.0, 'bend':0.0, 'grate':0.0, 'pier': 0.0, 'other': 0.0}
-        culvert_mannings = 0.013
-        
-        culvert_apron = 0.0
-        enquiry_gap = 5.0
-
-        
-        expected_Q = 3.70
-        expected_v = 3.27
-        expected_d = 1.20
-        
-
-        domain = self._create_domain(d_length=domain_length,
-                                     d_width=domain_width,
-                                     dx = 5.0,
-                                     dy = 5.0,
-                                     elevation_0 = elevation_0,
-                                     elevation_1 = elevation_1,
-                                     stage_0 = stage_0,
-                                     stage_1 = stage_1)
- 
-
-        #print 'Defining Structures'
-        
-        ep0 = numpy.array([domain_length/2-culvert_length/2, 100.0])
-        ep1 = numpy.array([domain_length/2+culvert_length/2, 100.0])
-        
-        
-        culvert = Boyd_pipe_operator(domain,
-                                    losses=culvert_losses,
-                                    diameter=culvert_width,
-                                    end_points=[ep0, ep1],
-                                    #height=culvert_height,
-                                    apron=culvert_apron,
-                                    enquiry_gap=enquiry_gap,
-                                    use_momentum_jet=False,
-                                    use_velocity_head=False,
-                                    manning=culvert_mannings,
-                                    logging=False,
-                                    label='1.2pipe',
-                                    verbose=False)
-
-        #culvert.determine_inflow_outflow()
-        
-        ( Q, v, d ) = culvert.discharge_routine()
-        
-        if verbose:
-            print 'test_boyd_non_skew5'
-            print 'Q: ', Q, 'expected_Q: ', expected_Q
-            print 'v: ', v, 'expected_v: ', expected_v
-            print 'd: ', d, 'expected_d: ', expected_d
-
-
-        assert numpy.allclose(Q, expected_Q, rtol=1.0e-2) #inflow
-        assert numpy.allclose(v, expected_v, rtol=1.0e-2) #outflow velocity
-        assert numpy.allclose(d, expected_d, rtol=1.0e-2) #depth at outlet used to calc v  
-# =========================================================================
-if __name__ == "__main__":
-    suite = unittest.makeSuite(Test_boyd_pipe_operator, 'test')
-    runner = unittest.TextTestRunner()
-    runner.run(suite)
Index: unk/anuga_core/source/anuga/structures/test_inlet_operator.py
===================================================================
--- /trunk/anuga_core/source/anuga/structures/test_inlet_operator.py	(revision 9439)
+++ 	(revision )
@@ -1,307 +1,0 @@
-#!/usr/bin/env python
-
-
-import unittest
-import os.path
-import sys
-
-import numpy
-import anuga
-
-from anuga.abstract_2d_finite_volumes.mesh_factory import rectangular_cross
-from anuga.shallow_water.shallow_water_domain import Domain
-from anuga.abstract_2d_finite_volumes.util import file_function
-
-from anuga.structures.inlet_operator import Inlet_operator
-
-class Test_inlet_operator(unittest.TestCase):
-    """
-	Test the boyd box operator, in particular the discharge_routine!
-    """
-
-    def setUp(self):
-        pass
-
-    def tearDown(self):
-        pass
-    
-    
-    def _create_domain(self,d_length,
-                            d_width,
-                            dx,
-                            dy,
-                            elevation_0,
-                            elevation_1,
-                            stage_0,
-                            stage_1):
-        
-        points, vertices, boundary = rectangular_cross(int(d_length/dx), int(d_width/dy),
-                                                        len1=d_length, len2=d_width)
-        domain = Domain(points, vertices, boundary)   
-        domain.set_name('Test_Outlet_Inlet')                 # Output name
-        domain.set_store()
-        domain.set_default_order(2)
-        domain.H0 = 0.01
-        domain.tight_slope_limiters = 1
-
-        #print 'Size', len(domain)
-
-        #------------------------------------------------------------------------------
-        # Setup initial conditions
-        #------------------------------------------------------------------------------
-
-        def elevation(x, y):
-            """Set up a elevation
-            """
-            
-            z = numpy.zeros(x.shape,dtype='d')
-            z[:] = elevation_0
-            
-            numpy.putmask(z, x > d_length/2, elevation_1)
-    
-            return z
-            
-        def stage(x,y):
-            """Set up stage
-            """
-            z = numpy.zeros(x.shape,dtype='d')
-            z[:] = stage_0
-            
-            numpy.putmask(z, x > d_length/2, stage_1)
-
-            return z
-            
-        #print 'Setting Quantities....'
-        domain.set_quantity('elevation', elevation)  # Use function for elevation
-        domain.set_quantity('stage',  stage)   # Use function for elevation
-
-        Br = anuga.Reflective_boundary(domain)
-        domain.set_boundary({'left': Br, 'right': Br, 'top': Br, 'bottom': Br})
-        
-        return domain
-
-    def test_inlet_constant_Q(self):
-        """test_inlet_Q
-        
-        This tests that the inlet operator adds the correct amount of water
-        """
-
-        stage_0 = 11.0
-        stage_1 = 10.0
-        elevation_0 = 10.0
-        elevation_1 = 10.0
-
-        domain_length = 200.0
-        domain_width = 200.0
-        
-
-        domain = self._create_domain(d_length=domain_length,
-                                     d_width=domain_width,
-                                     dx = 10.0,
-                                     dy = 10.0,
-                                     elevation_0 = elevation_0,
-                                     elevation_1 = elevation_1,
-                                     stage_0 = stage_0,
-                                     stage_1 = stage_1)
-
-        vol0 = domain.compute_total_volume()
-
-        finaltime = 3.0
-        line1 = [[95.0, 10.0], [105.0, 10.0]]
-        Q1 = 5.00
-        
-        line2 = [[10.0, 90.0], [20.0, 90.0]]
-        Q2 = 10.0
-        
-        Inlet_operator(domain, line1, Q1, logging=True)
-        Inlet_operator(domain, line2, Q2)
-
-        for t in domain.evolve(yieldstep = 1.0, finaltime = finaltime):
-            #domain.write_time()
-            #print domain.volumetric_balance_statistics()
-            pass
- 
-
-        vol1 = domain.compute_total_volume()
-
-        assert numpy.allclose((Q1+Q2)*finaltime, vol1-vol0, rtol=1.0e-8) 
-        assert numpy.allclose((Q1+Q2)*finaltime, domain.fractional_step_volume_integral, rtol=1.0e-8) 
-
-
-
-    def test_inlet_constant_Q_polygon(self):
-        """test_inlet_Q
-
-        This tests that the inlet operator adds the correct amount of water
-        """
-
-        stage_0 = 11.0
-        stage_1 = 10.0
-        elevation_0 = 10.0
-        elevation_1 = 10.0
-
-        domain_length = 200.0
-        domain_width = 200.0
-
-
-        domain = self._create_domain(d_length=domain_length,
-                                     d_width=domain_width,
-                                     dx = 10.0,
-                                     dy = 10.0,
-                                     elevation_0 = elevation_0,
-                                     elevation_1 = elevation_1,
-                                     stage_0 = stage_0,
-                                     stage_1 = stage_1)
-
-        vol0 = domain.compute_total_volume()
-
-        finaltime = 3.0
-        poly1 = [[95.0, 10.0], [105.0, 10.0], [105, 20.0], [95.0, 20.0]]
-        Q1 = 5.00
-
-
-        Inlet_operator(domain, poly1, Q1, logging=True)
-
-
-        for t in domain.evolve(yieldstep = 1.0, finaltime = finaltime):
-            #domain.write_time()
-            #print domain.volumetric_balance_statistics()
-            pass
-
-
-        vol1 = domain.compute_total_volume()
-
-        assert numpy.allclose((Q1)*finaltime, vol1-vol0, rtol=1.0e-8)
-        assert numpy.allclose((Q1)*finaltime, domain.fractional_step_volume_integral, rtol=1.0e-8) 
-
-
-
-    def test_inlet_variable_Q(self):
-        """test_inlet_Q
-        
-        This tests that the inlet operator adds the correct amount of water
-        """
-
-        stage_0 = 11.0
-        stage_1 = 10.0
-        elevation_0 = 10.0
-        elevation_1 = 10.0
-
-        domain_length = 200.0
-        domain_width = 200.0
-        
-
-        domain = self._create_domain(d_length=domain_length,
-                                     d_width=domain_width,
-                                     dx = 10.0,
-                                     dy = 10.0,
-                                     elevation_0 = elevation_0,
-                                     elevation_1 = elevation_1,
-                                     stage_0 = stage_0,
-                                     stage_1 = stage_1)
-
-        vol0 = domain.compute_total_volume()
-
-        finaltime = 3.0
-
-        #Make sure we are inthe right directory to find the
-        #time series data for the inlets
-        import os
-        baseDir = os.getcwd()
-
-        try:
-            os.chdir('structures')
-        except:
-            pass
-
-        line1 = [[95.0, 10.0], [105.0, 10.0]]
-        Q1 = file_function(filename='inlet_operator_test1.tms', quantities=['hydrograph'])
-        
-        line2 = [[10.0, 90.0], [20.0, 90.0]]
-        Q2 = file_function(filename='inlet_operator_test2.tms', quantities=['hydrograph'])
-
-        os.chdir(baseDir)
-        
-        Inlet_operator(domain, line1, Q1)
-        Inlet_operator(domain, line2, Q2)
-
-        for t in domain.evolve(yieldstep = 1.0, finaltime = finaltime):
-            #domain.write_time()
-            #print domain.volumetric_balance_statistics()
-            pass
- 
-
-        vol1 = domain.compute_total_volume()
-
-        #print vol1-vol0
-        
-        assert numpy.allclose(13.5, vol1-vol0, rtol=1.0e-8) 
-        assert numpy.allclose(vol1-vol0, domain.fractional_step_volume_integral, rtol=1.0e-8) 
-                
-    def test_inlet_variable_Q_default(self):
-        """test_inlet_Q
-
-        This tests that the inlet operator adds the correct amount of water
-        """
-
-        stage_0 = 11.0
-        stage_1 = 10.0
-        elevation_0 = 10.0
-        elevation_1 = 10.0
-
-        domain_length = 200.0
-        domain_width = 200.0
-
-
-        domain = self._create_domain(d_length=domain_length,
-                                     d_width=domain_width,
-                                     dx = 10.0,
-                                     dy = 10.0,
-                                     elevation_0 = elevation_0,
-                                     elevation_1 = elevation_1,
-                                     stage_0 = stage_0,
-                                     stage_1 = stage_1)
-
-        vol0 = domain.compute_total_volume()
-
-        finaltime = 5.0
-
-        #Make sure we are inthe right directory to find the
-        #time series data for the inlets
-        import os
-        baseDir = os.getcwd()
-
-        try:
-            os.chdir('structures')
-        except:
-            pass
-
-        line1 = [[95.0, 10.0], [105.0, 10.0]]
-        Q1 = file_function(filename='inlet_operator_test1.tms', quantities=['hydrograph'])
-
-        line2 = [[10.0, 90.0], [20.0, 90.0]]
-        Q2 = file_function(filename='inlet_operator_test2.tms', quantities=['hydrograph'])
-
-        os.chdir(baseDir)
-
-        Inlet_operator(domain, line1, Q1, default=6)
-        Inlet_operator(domain, line2, Q2, default=3)
-
-        for t in domain.evolve(yieldstep = 1.0, finaltime = finaltime):
-            #domain.write_time()
-            #print domain.volumetric_balance_statistics()
-            pass
-
-
-        vol1 = domain.compute_total_volume()
-
-        #print vol1-vol0
-
-        assert numpy.allclose(31.5, vol1-vol0, rtol=1.0e-8)
-        assert numpy.allclose(vol1-vol0, domain.fractional_step_volume_integral, rtol=1.0e-8) 
-
-# =========================================================================
-if __name__ == "__main__":
-    suite = unittest.makeSuite(Test_inlet_operator, 'test')
-    runner = unittest.TextTestRunner()
-    runner.run(suite)
Index: unk/anuga_core/source/anuga/structures/test_riverwall_structure.py
===================================================================
--- /trunk/anuga_core/source/anuga/structures/test_riverwall_structure.py	(revision 9439)
+++ 	(revision )
@@ -1,611 +1,0 @@
-#!/usr/bin/env python
-
-
-import unittest
-
-
-#from anuga.structures.riverwall import Boyd_box_operator
-#from anuga.structures.riverwall import boyd_box_function
-
-#from anuga.abstract_2d_finite_volumes.mesh_factory import rectangular_cross
-import anuga
-import numpy
-from anuga.shallow_water.shallow_water_domain import Domain
-from anuga.utilities import plot_utils as util
-from anuga.config import g
-
-## Generic data for scenario
-
-verbose = False
-boundaryPolygon=[ [0., 0.], [0., 100.], [100.0, 100.0], [100.0, 0.0]]
-wallLoc=50.
-# The boundary polygon + riverwall breaks the mesh into multiple regions
-# Must define the resolution in these areas with an xy point + maximum area
-# Otherwise triangle.c gets confused
-regionPtAreas=[ [99., 99., 20.0*20.0*0.5],
-                [1., 1., 20.0*20.0*0.5]]
-
-class Test_riverwall_structure(unittest.TestCase):
-    """
-	Test the riverwall structure
-    """
-
-    def setUp(self):
-        pass
-
-    def tearDown(self):
-        pass
-    
-    def create_domain_DE0(self, wallHeight, InitialOceanStage, InitialLandStage, riverWall=None, riverWall_Par=None):
-        # Riverwall = list of lists, each with a set of x,y,z (and optional QFactor) values
-
-        if(riverWall is None):
-            riverWall={ 'centralWall':
-                            [ [wallLoc, 0.0, wallHeight],
-                              [wallLoc, 100.0, wallHeight]] 
-                      }
-        if(riverWall_Par is None):
-            riverWall_Par={'centralWall':{'Qfactor':1.0}}
-        # Make the domain
-        anuga.create_mesh_from_regions(boundaryPolygon, 
-                                 boundary_tags={'left': [0],
-                                                'top': [1],
-                                                'right': [2],
-                                                'bottom': [3]},
-                                   maximum_triangle_area = 200.,
-                                   minimum_triangle_angle = 28.0,
-                                   filename = 'testRiverwall.msh',
-                                   interior_regions =[ ], #[ [higherResPolygon, 1.*1.*0.5],
-                                                          #  [midResPolygon, 3.0*3.0*0.5]],
-                                   breaklines=riverWall.values(),
-                                   use_cache=False,
-                                   verbose=verbose,
-                                   regionPtArea=regionPtAreas)
-
-        domain=anuga.create_domain_from_file('testRiverwall.msh')
-
-        # 05/05/2014 -- riverwalls only work with DE0 and DE1
-        domain.set_flow_algorithm('DE0')
-        domain.set_name('test_riverwall')
-
-        domain.set_store_vertices_uniquely()
-       
-        def topography(x,y):
-            return -x/150. 
-
-        def stagefun(x,y):
-            stg=InitialOceanStage*(x>=50.) + InitialLandStage*(x<50.)
-            return stg 
-
-        # NOTE: Setting quantities at centroids is important for exactness of tests
-        domain.set_quantity('elevation',topography,location='centroids')     
-        domain.set_quantity('friction',0.03)             
-        domain.set_quantity('stage', stagefun,location='centroids')            
-        
-        domain.riverwallData.create_riverwalls(riverWall,riverWall_Par,verbose=verbose) 
-
-        # Boundary conditions
-        Br=anuga.Reflective_boundary(domain)
-        domain.set_boundary({'left': Br, 'right': Br, 'top': Br, 'bottom':Br})
-
-        return domain
- 
-    def create_domain_DE1(self, wallHeight, InitialOceanStage, InitialLandStage):
-        # Riverwall = list of lists, each with a set of x,y,z (and optional QFactor) values
-        riverWall={ 'centralWall':
-                        [ [wallLoc, 0.0, wallHeight],
-                          [wallLoc, 100.0, wallHeight]] 
-                  }
-        riverWall_Par={'centralWall':{'Qfactor':1.0}}
-        # Make the domain
-        anuga.create_mesh_from_regions(boundaryPolygon, 
-                                 boundary_tags={'left': [0],
-                                                'top': [1],
-                                                'right': [2],
-                                                'bottom': [3]},
-                                   maximum_triangle_area = 200.,
-                                   minimum_triangle_angle = 28.0,
-                                   filename = 'testRiverwall.msh',
-                                   interior_regions =[ ], #[ [higherResPolygon, 1.*1.*0.5],
-                                                          #  [midResPolygon, 3.0*3.0*0.5]],
-                                   breaklines=riverWall.values(),
-                                   use_cache=False,
-                                   verbose=verbose,
-                                   regionPtArea=regionPtAreas)
-
-        domain=anuga.create_domain_from_file('testRiverwall.msh')
-
-        # 05/05/2014 -- riverwalls only work with DE0 and DE1
-        domain.set_flow_algorithm('DE1')
-        domain.set_name('test_riverwall')
-
-        domain.set_store_vertices_uniquely()
-       
-        def topography(x,y):
-            return -x/150. 
-
-        def stagefun(x,y):
-            stg=InitialOceanStage*(x>=50.) + InitialLandStage*(x<50.)
-            return stg 
-
-        # NOTE: Setting quantities at centroids is important for exactness of tests
-        domain.set_quantity('elevation',topography,location='centroids')     
-        domain.set_quantity('friction',0.03)             
-        domain.set_quantity('stage', stagefun,location='centroids')            
-        
-        domain.riverwallData.create_riverwalls(riverWall,riverWall_Par,verbose=verbose) 
-
-        # Boundary conditions
-        Br=anuga.Reflective_boundary(domain)
-        domain.set_boundary({'left': Br, 'right': Br, 'top': Br, 'bottom':Br})
-
-        return domain
-           
-    def test_noflux_riverwall_DE1(self):
-        """test_noflux_riverwall
-            
-            Tests that the riverwall blocks water when the stage is < wall height 
-            
-        """
-        wallHeight=-0.2
-        InitialOceanStage=-0.3
-        InitialLandStage=-999999.
-       
-        domain=self.create_domain_DE1(wallHeight,InitialOceanStage, InitialLandStage) 
-
-        # Run the model for a few seconds, and check that no water has flowed past the riverwall 
-        for t in domain.evolve(yieldstep=10.0,finaltime=10.0):
-            if(verbose): 
-                print domain.timestepping_statistics()
-
-        # Indices landward of the riverwall
-        landInds=(domain.centroid_coordinates[:,0]<50.).nonzero()[0]
-        # Compute volume of water landward of riverwall
-        landVol=domain.quantities['height'].centroid_values[landInds]*domain.areas[landInds]            
-        landVol=landVol.sum()
-        
-        if(verbose):
-            print 'Land Vol: ', landVol, 'theoretical vol: ', 0.
-
-        assert numpy.allclose(landVol,0., atol=1.0e-12)
-        
-    def test_simpleflux_riverwall_DE1(self):
-        """test_simpleflux_riverwall
-            
-            Tests that the riverwall flux (when dry on one edge) is
-            2/3*H*sqrt(2/3*g*H)
-            
-        """
-        wallHeight=2.
-        InitialOceanStage=2.50
-        InitialLandStage=-999999.
-       
-        domain=self.create_domain_DE1(wallHeight,InitialOceanStage, InitialLandStage) 
-
-        # Run the model for a few fractions of a second
-        # Any longer, and the evolution of stage starts causing
-        # significant changes to the flow
-        yst=1.0e-04
-        ft=1.0e-03
-        for t in domain.evolve(yieldstep=yst,finaltime=ft):
-            if(verbose):
-                print domain.timestepping_statistics()
-
-        # Compare with theoretical result
-        L= 100. # Length of riverwall
-        H=InitialOceanStage-wallHeight # Upstream head
-        dt=ft
-        theoretical_flux_vol=dt*L*2./3.*H*(2./3.*g*H)**0.5
-
-        # Indices landward of the riverwall
-        landInds=(domain.centroid_coordinates[:,0]<50.).nonzero()[0]
-        # Compute volume of water landward of riverwall
-        landVol=domain.quantities['height'].centroid_values[landInds]*domain.areas[landInds]            
-        landVol=landVol.sum()
-
-        if(verbose):
-            print 'Land Vol: ', landVol, 'theoretical vol: ', theoretical_flux_vol
-
-        assert numpy.allclose(landVol,theoretical_flux_vol, rtol=1.0e-03)
-    
-    def test_simpleflux_riverwall_with_Qfactor_DE1(self):
-        """test_simpleflux_riverwall with Qfactor != 1.0
-            
-            Tests that the riverwall flux (when dry on one edge) is
-            2/3*H*sqrt(2/3*g*H)*Qfactor
-            
-        """
-        wallHeight=2.
-        InitialOceanStage=2.50
-        InitialLandStage=-999999.
-       
-        domain=self.create_domain_DE1(wallHeight,InitialOceanStage, InitialLandStage) 
-        # Redefine the riverwall, with 2x the discharge Qfactor
-        riverWall={ 'centralWall':
-                        [ [wallLoc, 0.0, wallHeight],
-                          [wallLoc, 100.0, wallHeight]] 
-                  }
-        Qmult=2.0
-        riverWall_Par={'centralWall':{'Qfactor':Qmult}}
-        domain.riverwallData.create_riverwalls(riverWall,riverWall_Par,verbose=verbose)
-
-        #import pdb
-        #pdb.set_trace()
-
-        # Run the model for a few fractions of a second
-        # Any longer, and the evolution of stage starts causing
-        # significant changes to the flow
-        yst=1.0e-04
-        ft=1.0e-03
-        for t in domain.evolve(yieldstep=yst,finaltime=ft):
-            if(verbose):
-                print domain.timestepping_statistics()
-
-        # Compare with theoretical result
-        L= 100. # Length of riverwall
-        H=InitialOceanStage-wallHeight # Upstream head
-        dt=ft
-        theoretical_flux_vol=Qmult*dt*L*2./3.*H*(2./3.*g*H)**0.5
-
-        # Indices landward of the riverwall
-        landInds=(domain.centroid_coordinates[:,0]<50.).nonzero()[0]
-        # Compute volume of water landward of riverwall
-        landVol=domain.quantities['height'].centroid_values[landInds]*domain.areas[landInds]            
-        landVol=landVol.sum()
-
-        #import pdb
-        #pdb.set_trace()
-        
-        if(verbose):
-            print 'Land Vol: ', landVol, 'theoretical vol: ', theoretical_flux_vol
-
-        assert numpy.allclose(landVol,theoretical_flux_vol, rtol=1.0e-03)
-
-   
-    def test_submergeflux_riverwall_DE1(self):
-        """test_submergedflux_riverwall
-            
-            Tests that the riverwall flux is
-            Q1*(1-Q2/Q1)**(0.385)
-
-            Where Q1, Q2 =2/3*H*sqrt(2/3*g*H)
-             with H computed from the smallest (Q2) / largest (Q1) head side
-        """
-        wallHeight=20.
-        InitialOceanStage=20.50
-        InitialLandStage=20.44
-       
-        domain=self.create_domain_DE1(wallHeight,InitialOceanStage, InitialLandStage) 
-
-        # Indices landward of the riverwall
-        landInds=(domain.centroid_coordinates[:,0]<50.).nonzero()[0]
-        InitialHeight=(domain.quantities['stage'].centroid_values[landInds]-domain.quantities['elevation'].centroid_values[landInds])
-        InitialLandVol=InitialHeight*(InitialHeight>0.)*domain.areas[landInds]            
-        InitialLandVol=InitialLandVol.sum()
-
-        # Run the model for a few fractions of a second
-        # Any longer, and the evolution of stage starts causing
-        # significant changes to the flow
-        yst=1.0e-04
-        ft=1.0e-03
-        for t in domain.evolve(yieldstep=yst,finaltime=ft):
-            if(verbose):
-                print domain.timestepping_statistics()
-
-        # Compare with theoretical result
-        L= 100. # Length of riverwall
-        dt=ft
-        H1=max(InitialOceanStage-wallHeight,0.) # Upstream head
-        H2=max(InitialLandStage-wallHeight,0.) # Downstream head
-
-        Q1=2./3.*H1*(2./3.*g*H1)**0.5
-        Q2=2./3.*H2*(2./3.*g*H2)**0.5
-
-        theoretical_flux_vol=dt*L*Q1*(1.-Q2/Q1)**0.385
-
-        # Compute volume of water landward of riverwall
-        FinalLandVol=domain.quantities['height'].centroid_values[landInds]*domain.areas[landInds]            
-        FinalLandVol=FinalLandVol.sum()
-
-        landVol=FinalLandVol-InitialLandVol
-
-        #import pdb
-        #pdb.set_trace()
-        
-        if(verbose):
-            print 'Land Vol: ', landVol, 'theoretical vol: ', theoretical_flux_vol
-
-        assert numpy.allclose(landVol,theoretical_flux_vol, rtol=1.0e-03)
- 
-    def test_noflux_riverwall_DE0(self):
-        """test_noflux_riverwall
-            
-            Tests that the riverwall blocks water when the stage is < wall height 
-            
-        """
-        wallHeight=-0.2
-        InitialOceanStage=-0.3
-        InitialLandStage=-999999.
-       
-        domain=self.create_domain_DE0(wallHeight,InitialOceanStage, InitialLandStage) 
-
-        # Run the model for a few seconds, and check that no water has flowed past the riverwall 
-        for t in domain.evolve(yieldstep=10.0,finaltime=10.0):
-            if(verbose): 
-                print domain.timestepping_statistics()
-
-        # Indices landward of the riverwall
-        landInds=(domain.centroid_coordinates[:,0]<50.).nonzero()[0]
-        # Compute volume of water landward of riverwall
-        landVol=domain.quantities['height'].centroid_values[landInds]*domain.areas[landInds]            
-        landVol=landVol.sum()
-        
-        if(verbose):
-            print 'Land Vol: ', landVol, 'theoretical vol: ', 0.
-
-        assert numpy.allclose(landVol,0., atol=1.0e-12)
-        
-    def test_simpleflux_riverwall_DE0(self):
-        """test_simpleflux_riverwall
-            
-            Tests that the riverwall flux (when dry on one edge) is
-            2/3*H*sqrt(2/3*g*H)
-            
-        """
-        wallHeight=2.
-        InitialOceanStage=2.50
-        InitialLandStage=-999999.
-       
-        domain=self.create_domain_DE0(wallHeight,InitialOceanStage, InitialLandStage) 
-
-        # Run the model for a few fractions of a second
-        # Any longer, and the evolution of stage starts causing
-        # significant changes to the flow
-        yst=1.0e-04
-        ft=1.0e-03
-        for t in domain.evolve(yieldstep=yst,finaltime=ft):
-            if(verbose):
-                print domain.timestepping_statistics()
-
-        # Compare with theoretical result
-        L= 100. # Length of riverwall
-        H=InitialOceanStage-wallHeight # Upstream head
-        dt=ft
-        theoretical_flux_vol=dt*L*2./3.*H*(2./3.*g*H)**0.5
-
-        # Indices landward of the riverwall
-        landInds=(domain.centroid_coordinates[:,0]<50.).nonzero()[0]
-        # Compute volume of water landward of riverwall
-        landVol=domain.quantities['height'].centroid_values[landInds]*domain.areas[landInds]            
-        landVol=landVol.sum()
-
-        if(verbose):
-            print 'Land Vol: ', landVol, 'theoretical vol: ', theoretical_flux_vol
-
-        assert numpy.allclose(landVol,theoretical_flux_vol, rtol=1.0e-03)
-    
-    def test_simpleflux_riverwall_with_Qfactor_DE0(self):
-        """test_simpleflux_riverwall with Qfactor != 1.0
-            
-            Tests that the riverwall flux (when dry on one edge) is
-            2/3*H*sqrt(2/3*g*H)*Qfactor
-            
-        """
-        wallHeight=2.
-        InitialOceanStage=2.50
-        InitialLandStage=-999999.
-       
-        domain=self.create_domain_DE0(wallHeight,InitialOceanStage, InitialLandStage) 
-        # Redefine the riverwall, with 2x the discharge Qfactor
-        riverWall={ 'centralWall':
-                        [ [wallLoc, 0.0, wallHeight],
-                          [wallLoc, 100.0, wallHeight]] 
-                  }
-        Qmult=2.0
-        riverWall_Par={'centralWall':{'Qfactor':Qmult}}
-        domain.riverwallData.create_riverwalls(riverWall,riverWall_Par,verbose=verbose)
-
-        #import pdb
-        #pdb.set_trace()
-
-        # Run the model for a few fractions of a second
-        # Any longer, and the evolution of stage starts causing
-        # significant changes to the flow
-        yst=1.0e-04
-        ft=1.0e-03
-        for t in domain.evolve(yieldstep=yst,finaltime=ft):
-            if(verbose):
-                print domain.timestepping_statistics()
-
-        # Compare with theoretical result
-        L= 100. # Length of riverwall
-        H=InitialOceanStage-wallHeight # Upstream head
-        dt=ft
-        theoretical_flux_vol=Qmult*dt*L*2./3.*H*(2./3.*g*H)**0.5
-
-        # Indices landward of the riverwall
-        landInds=(domain.centroid_coordinates[:,0]<50.).nonzero()[0]
-        # Compute volume of water landward of riverwall
-        landVol=domain.quantities['height'].centroid_values[landInds]*domain.areas[landInds]            
-        landVol=landVol.sum()
-
-        #import pdb
-        #pdb.set_trace()
-        
-        if(verbose):
-            print 'Land Vol: ', landVol, 'theoretical vol: ', theoretical_flux_vol
-
-        assert numpy.allclose(landVol,theoretical_flux_vol, rtol=1.0e-03)
-
-   
-    def test_submergeflux_riverwall_DE0(self):
-        """test_submergedflux_riverwall
-            
-            Tests that the riverwall flux is
-            Q1*(1-Q2/Q1)**(0.385)
-
-            Where Q1, Q2 =2/3*H*sqrt(2/3*g*H)
-             with H computed from the smallest (Q2) / largest (Q1) head side
-        """
-        wallHeight=20.
-        InitialOceanStage=20.50
-        InitialLandStage=20.44
-       
-        domain=self.create_domain_DE0(wallHeight,InitialOceanStage, InitialLandStage) 
-
-        # Indices landward of the riverwall
-        landInds=(domain.centroid_coordinates[:,0]<50.).nonzero()[0]
-        InitialHeight=(domain.quantities['stage'].centroid_values[landInds]-domain.quantities['elevation'].centroid_values[landInds])
-        InitialLandVol=InitialHeight*(InitialHeight>0.)*domain.areas[landInds]            
-        InitialLandVol=InitialLandVol.sum()
-
-        # Run the model for a few fractions of a second
-        # Any longer, and the evolution of stage starts causing
-        # significant changes to the flow
-        yst=1.0e-04
-        ft=1.0e-03
-        for t in domain.evolve(yieldstep=yst,finaltime=ft):
-            if(verbose):
-                print domain.timestepping_statistics()
-
-        # Compare with theoretical result
-        L= 100. # Length of riverwall
-        dt=ft
-        H1=max(InitialOceanStage-wallHeight,0.) # Upstream head
-        H2=max(InitialLandStage-wallHeight,0.) # Downstream head
-
-        Q1=2./3.*H1*(2./3.*g*H1)**0.5
-        Q2=2./3.*H2*(2./3.*g*H2)**0.5
-
-        theoretical_flux_vol=dt*L*Q1*(1.-Q2/Q1)**0.385
-
-        # Compute volume of water landward of riverwall
-        FinalLandVol=domain.quantities['height'].centroid_values[landInds]*domain.areas[landInds]            
-        FinalLandVol=FinalLandVol.sum()
-
-        landVol=FinalLandVol-InitialLandVol
-
-        #import pdb
-        #pdb.set_trace()
-        
-        if(verbose):
-            print 'Land Vol: ', landVol, 'theoretical vol: ', theoretical_flux_vol
-
-        assert numpy.allclose(landVol,theoretical_flux_vol, rtol=1.0e-03)
-    
-    def test_riverwall_includes_specified_points_in_domain(self): 
-        """
-            Check that all domain points that should be on the riverwall
-            actually are, and that there are no 'non-riverwall' points on the riverwall
-        """
-        wallHeight=-0.2
-        InitialOceanStage=-0.3
-        InitialLandStage=-999999.
-       
-        domain=self.create_domain_DE1(wallHeight,InitialOceanStage, InitialLandStage) 
-
-        edgeInds_on_wall=domain.riverwallData.riverwall_edges.tolist()
-
-        riverWall_x_coord=domain.edge_coordinates[edgeInds_on_wall,0]-wallLoc
-
-        assert(numpy.allclose(riverWall_x_coord,0.))
-   
-        # Now check that all the other domain edge coordinates are not on the wall 
-        # Note the threshold requires a sufficiently coarse mesh
-        notriverWall_x_coord=numpy.delete(domain.edge_coordinates[:,0], edgeInds_on_wall) 
-        assert(min(abs(notriverWall_x_coord-wallLoc))>1.0e-01)
-
-    def test_is_vertex_on_boundary(self):
-        """
-            Check that is_vertex_on_boundary is working as expected
-        """
-        wallHeight=-0.2
-        InitialOceanStage=-0.3
-        InitialLandStage=-999999.
-       
-        domain=self.create_domain_DE1(wallHeight,InitialOceanStage, InitialLandStage) 
-
-        allVertices=numpy.array(range(len(domain.vertex_coordinates)))
-        boundaryFlag=domain.riverwallData.is_vertex_on_boundary(allVertices)
-        boundaryVerts=boundaryFlag.nonzero()[0].tolist()
-
-        # Check that all boundary vertices are on the boundary 
-        check2=(domain.vertex_coordinates[boundaryVerts,0]==0.)+\
-               (domain.vertex_coordinates[boundaryVerts,0]==100.)+\
-               (domain.vertex_coordinates[boundaryVerts,1]==100.)+\
-               (domain.vertex_coordinates[boundaryVerts,1]==0.)
-
-        assert(all(check2>0.))
-
-        # Check that all non-boundary vertices are not
-        nonboundaryVerts=(boundaryFlag==0).nonzero()[0].tolist()
-        check2=(domain.vertex_coordinates[nonboundaryVerts,0]==0.)+\
-               (domain.vertex_coordinates[nonboundaryVerts,0]==100.)+\
-               (domain.vertex_coordinates[nonboundaryVerts,1]==100.)+\
-               (domain.vertex_coordinates[nonboundaryVerts,1]==0.)
-
-        assert(all(check2==0))
-
-    def test_multiple_riverwalls(self):
-        """
-            Testcase with multiple riverwalls -- check all is working as required
-
-         Idea -- add other riverwalls with different Qfactor / height.
-                 Set them up to have no hydraulic effect, but
-                 so that we are likely to catch bugs if the code is not right
-        """
-        wallHeight=2.
-        InitialOceanStage=2.50
-        InitialLandStage=-999999.
-        
-       
-        riverWall={ 'awall1':
-                        [ [wallLoc+20., 0.0, -9999.],
-                          [wallLoc+20., 100.0, -9999.]],  
-                    'centralWall':
-                        [ [wallLoc, 0.0, wallHeight],
-                          [wallLoc, 100.0, wallHeight]] ,
-                    'awall2':
-                        [ [wallLoc-20., 0.0, 30.],
-                          [wallLoc-20., 100.0, 30.]],  
-                  }
-
-        newQfac=2.0
-        riverWall_Par={'centralWall':{'Qfactor':newQfac}, 'awall1':{'Qfactor':100.}, 'awall2':{'Qfactor':0.}}
-
-        domain=self.create_domain_DE0(wallHeight,InitialOceanStage, InitialLandStage, riverWall=riverWall,riverWall_Par=riverWall_Par) 
-        
-
-        domain.riverwallData.create_riverwalls(riverWall,riverWall_Par,verbose=verbose) 
-
-        # Run the model for a few fractions of a second
-        # Any longer, and the evolution of stage starts causing
-        # significant changes to the flow
-        yst=1.0e-04
-        ft=1.0e-03
-        for t in domain.evolve(yieldstep=yst,finaltime=ft):
-            if(verbose):
-                print domain.timestepping_statistics()
-
-        # Compare with theoretical result
-        L= 100. # Length of riverwall
-        H=InitialOceanStage-wallHeight # Upstream head
-        dt=ft
-        theoretical_flux_vol=newQfac*dt*L*2./3.*H*(2./3.*g*H)**0.5
-
-        # Indices landward of the riverwall
-        landInds=(domain.centroid_coordinates[:,0]<50.).nonzero()[0]
-        # Compute volume of water landward of riverwall
-        landVol=domain.quantities['height'].centroid_values[landInds]*domain.areas[landInds]            
-        landVol=landVol.sum()
-
-        if(verbose):
-            print 'Land Vol: ', landVol, 'theoretical vol: ', theoretical_flux_vol
-
-        assert numpy.allclose(landVol,theoretical_flux_vol, rtol=1.0e-03)
-
-# =========================================================================
-if __name__ == "__main__":
-    suite = unittest.makeSuite(Test_riverwall_structure, 'test')
-    runner = unittest.TextTestRunner()
-    runner.run(suite)
Index: unk/anuga_core/source/anuga/structures/test_weir_orifice_trapezoid_operator.py
===================================================================
--- /trunk/anuga_core/source/anuga/structures/test_weir_orifice_trapezoid_operator.py	(revision 9439)
+++ 	(revision )
@@ -1,650 +1,0 @@
-#!/usr/bin/env python
-
-
-import unittest
-
-
-from anuga.structures.weir_orifice_trapezoid_operator import Weir_orifice_trapezoid_operator
-from anuga.structures.weir_orifice_trapezoid_operator import weir_orifice_trapezoid_function
-
-from anuga.abstract_2d_finite_volumes.mesh_factory import rectangular_cross
-from anuga.shallow_water.shallow_water_domain import Domain
-import numpy
-import inspect
-
-
-
-
-verbose = False
-
-
-class Test_weir_orifice_trapezoid_operator(unittest.TestCase):
-    """
-	Test the weir_orifice_trapezoid_operator, in particular the discharge_routine!
-    """
-
-    def setUp(self):
-        pass
-
-    def tearDown(self):
-        pass
-    
-    
-    def _create_domain(self,d_length,
-                            d_width,
-                            dx,
-                            dy,
-                            elevation_0,
-                            elevation_1,
-                            stage_0,
-                            stage_1,
-                            xvelocity_0 = 0.0,
-                            xvelocity_1 = 0.0,
-                            yvelocity_0 = 0.0,
-                            yvelocity_1 = 0.0):
-        
-        points, vertices, boundary = rectangular_cross(int(d_length/dx), int(d_width/dy),
-                                                        len1=d_length, len2=d_width)
-        domain = Domain(points, vertices, boundary)   
-        domain.set_name('Test_Outlet_Inlet')                 # Output name
-        domain.set_store()
-        domain.set_default_order(2)
-        domain.H0 = 0.01
-        domain.tight_slope_limiters = 1
-
-        #print 'Size', len(domain)
-
-        #------------------------------------------------------------------------------
-        # Setup initial conditions
-        #------------------------------------------------------------------------------
-
-        def elevation(x, y):
-            """Set up a elevation
-            """
-            
-            z = numpy.zeros(x.shape,dtype='d')
-            z[:] = elevation_0
-            
-            numpy.putmask(z, x > d_length/2, elevation_1)
-    
-            return z
-            
-        def stage(x,y):
-            """Set up stage
-            """
-            z = numpy.zeros(x.shape,dtype='d')
-            z[:] = stage_0
-            
-            numpy.putmask(z, x > d_length/2, stage_1)
-
-            return z
-        
-        def xmom(x,y):
-            """Set up xmomentum
-            """
-            z = numpy.zeros(x.shape,dtype='d')
-            z[:] = xvelocity_0*(stage_0-elevation_0)
-            
-            numpy.putmask(z, x > d_length/2, xvelocity_1*(stage_1-elevation_1) )
-
-            return z
-        
-        def ymom(x,y):
-            """Set up ymomentum
-            """
-            z = numpy.zeros(x.shape,dtype='d')
-            z[:] = yvelocity_0*(stage_0-elevation_0)
-            
-            numpy.putmask(z, x > d_length/2, yvelocity_1*(stage_1-elevation_1) )
-
-            return z
-            
-        #print 'Setting Quantities....'
-        domain.set_quantity('elevation', elevation)  # Use function for elevation
-        domain.set_quantity('stage',  stage)   # Use function for elevation
-        domain.set_quantity('xmomentum',  xmom) 
-        domain.set_quantity('ymomentum',  ymom) 
-        
-        return domain
-    
-    #def test_weir_orifice_non_skew(self):
-
-        #stage_0 = 11.0
-        #stage_1 = 10.0
-        #elevation_0 = 10.0
-        #elevation_1 = 10.0
-
-        #domain_length = 200.0
-        #domain_width = 200.0
-
-        #culvert_length = 10.0
-        #culvert_width = 10.0
-        #culvert_height = 3.0
-        #culvert_slope=0.1
-        #culvert_z1 = 2
-        #culvert_z2 = 2
-        #culvert_losses = {'inlet':0.5, 'outlet':1.0, 'bend':0.0, 'grate':0.0, 'pier': 0.0, 'other': 0.0}
-        #culvert_mannings = 0.015
-        
-        #culvert_apron = 0.0
-        #enquiry_gap = 5.0
-
-        
-        #expected_Q = 0.52 
-        #expected_v = 1.04
-        #expected_d = 0.50
-                                    
-
-        #domain = self._create_domain(d_length=domain_length,
-                                     #d_width=domain_width,
-                                     #dx = 5.0,
-                                     #dy = 5.0,
-                                     #elevation_0 = elevation_0,
-                                     #elevation_1 = elevation_1,
-                                     #stage_0 = stage_0,
-                                     #stage_1 = stage_1)
- 
-
-        ##print 'Defining Structures'
-        
-        #ep0 = numpy.array([domain_length/2-culvert_length/2, 100.0])
-        #ep1 = numpy.array([domain_length/2+culvert_length/2, 100.0])
-        
-        
-        #culvert = Weir_orifice_trapezoid_operator(domain,
-                                    #losses=culvert_losses,
-                                    #width=culvert_width,
-                                    #end_points=[ep0, ep1],
-                                    #height=culvert_height,
-                                    #culvert_slope=culvert_slope,
-                                    #z1=culvert_z1,
-                                    #z2=culvert_z2,
-                                    #apron=culvert_apron,
-                                    #enquiry_gap=enquiry_gap,
-                                    #use_momentum_jet=False,
-                                    #use_velocity_head=False,
-                                    #manning=culvert_mannings,
-                                    #logging=False,
-                                    #label='10mwidex3mdeep 1V:2H trapezoid',
-                                    #verbose=False)
-
-        ##culvert.determine_inflow_outflow()
-        
-        #( Q, v, d ) = culvert.discharge_routine()
-        
-        #if verbose:
-            #print 50*'='
-            #print 'UNITTEST ',inspect.stack()[0][3]
-            #print 'Q v d: ', Q, v, d, ' expected_Q v d: ', expected_Q, expected_v, expected_d
-        
-
-        #assert numpy.allclose(Q, expected_Q, rtol=1.0e-1) #inflow
-        #assert numpy.allclose(v, expected_v, rtol=1.0e-1) #outflow velocity
-        #assert numpy.allclose(d, expected_d, rtol=1.0e-1) #depth at outlet used to calc v 
-        
-      
-
-    def test_weir_orifice_1(self):
-        """test_weir_orifice 1
-        
-        This tests the test_weir_orifice routine with data obtained from a spreadsheet to do the weir orfice calcs    
-        """
-
-
-        g=9.81
-        culvert_slope=1  # Downward
-
-        inlet_depth=0.57
-        outlet_depth=0.45
-        inlet_velocity=1.93 # v jut upstream of culvert
-        outlet_velocity=2.03 # v just downstream of culvert
-        
-        culvert_length=10.0
-        culvert_width=10.0
-        culvert_height=3.0
-        culvert_slope=0.1
-        culvert_z1=2
-        culvert_z2=2
-        
-        culvert_type='trapezoid'
-        manning=0.015
-        sum_loss=1.5
-
-        inlet_specific_energy=inlet_depth + 0.5*inlet_velocity**2/g 
-        z_in = 0.0
-        z_out = z_in-culvert_length*culvert_slope/100
-        E_in = z_in+inlet_depth + 0.5*inlet_velocity**2/g
-        E_out = z_out+outlet_depth + 0.5*outlet_velocity**2/g
-        delta_total_energy = E_in-E_out
-        
-
-        Q_expected = 0.52 
-        v_expected = 1.04
-        d_expected = 0.05
-        
-        if verbose:
-            print 50*'='
-            print 'UNITTEST ',inspect.stack()[0][3]
-            print 'width ',culvert_width
-            print 'depth ',culvert_height
-            print 'flow_width ',culvert_width
-            print 'length ' ,culvert_length
-            print 'driving_energy ',inlet_specific_energy
-            print 'delta_total_energy ',delta_total_energy
-            print 'outlet_enquiry_depth ',outlet_depth
-            print 'sum_loss ',sum_loss
-            print 'manning ',manning
-        
-        Q, v, d, flow_area, case= weir_orifice_trapezoid_function(culvert_width, 
-                                                    culvert_height, 
-                                                    culvert_width,
-                                                    culvert_slope,
-                                                    culvert_z1,
-                                                    culvert_z2, 
-                                                    culvert_length, 
-                                                    inlet_specific_energy, 
-                                                    delta_total_energy, 
-                                                    outlet_depth, 
-                                                    sum_loss,
-                                                    manning)
-        
-
-
-
-
-        if verbose:
-            print ('%s %.2f'%('SPEC_E = ',inlet_specific_energy))
-            print ('%s %.2f'%('Delta E = ',delta_total_energy))
-            print ('%s %.2f,%.2f,%.2f' %('   ANUGAcalcsTEST Q-v-d ',Q,v,d))
-            print ('%s %.2f,%.2f,%.2f' %('spreadsheet calculation ', Q_expected, v_expected, d_expected))
-            
-        assert numpy.allclose(Q, Q_expected, rtol=1.0e-1) #inflow
-        assert numpy.allclose(v, v_expected, rtol=1.0e-1) #outflow velocity
-        assert numpy.allclose(d, d_expected, rtol=1.0e-1) #depth at outlet used to calc v 
-        
-    def test_weir_orifice_2(self):
-        """test_weir_orifice 2
-        
-        This tests the test_weir_orifice routine with data obtained from a spreadsheet to do the weir orfice calcs  
-        """
-
-
-        g=9.81
-        culvert_slope=1  # Downward
-
-        inlet_depth=1.99
-        outlet_depth=1.9
-        inlet_velocity=3.59
-        outlet_velocity=3.82
-        
-        culvert_length=10.0
-        culvert_width=10.0
-        culvert_height=3.0
-        culvert_slope=0.01
-        culvert_z1=2
-        culvert_z2=2
-        
-        culvert_type='trapezoid'
-        manning=0.015
-        sum_loss=1.5
-
-        inlet_specific_energy=inlet_depth + 0.5*inlet_velocity**2/g 
-        z_in = 0.0
-        z_out = z_in-culvert_length*culvert_slope/100
-        E_in = z_in+inlet_depth + 0.5*inlet_velocity**2/g
-        E_out = z_out+outlet_depth + 0.5*outlet_velocity**2/g
-        delta_total_energy = E_in-E_out
-        
-
-        Q_expected = 0.09
-        v_expected = 0.20
-        d_expected = 0.04
-        
-        if verbose:
-            print 50*'='
-            print 'UNITTEST ',inspect.stack()[0][3] 
-            print 'width ',culvert_width
-            print 'depth ',culvert_height
-            print 'flow_width ',culvert_width
-            print 'length ' ,culvert_length
-            print 'driving_energy ',inlet_specific_energy
-            print 'delta_total_energy ',delta_total_energy
-            print 'outlet_enquiry_depth ',outlet_depth
-            print 'sum_loss ',sum_loss
-            print 'manning ',manning
-        
-        Q, v, d, flow_area, case= weir_orifice_trapezoid_function(culvert_width, 
-                                                    culvert_height, 
-                                                    culvert_width,
-                                                    culvert_slope,
-                                                    culvert_z1,
-                                                    culvert_z2, 
-                                                    culvert_length, 
-                                                    inlet_specific_energy, 
-                                                    delta_total_energy, 
-                                                    outlet_depth, 
-                                                    sum_loss,
-                                                    manning)
-
-
-
-
-        if verbose:
-            print ('%s %.2f'%('SPEC_E = ',inlet_specific_energy))
-            print ('%s %.2f'%('Delta E = ',delta_total_energy))
-            print ('%s %.2f,%.2f,%.2f' %(   'ANUGAcalcsTEST Q-v-d ',Q,v,d))
-            print ('%s %.2f,%.2f,%.2f' %('spreadsheet calculation ', Q_expected, v_expected, d_expected))
-            
-        assert numpy.allclose(Q, Q_expected, rtol=1.0e-1) #inflow
-        assert numpy.allclose(v, v_expected, rtol=1.0e-1) #outflow velocity
-        assert numpy.allclose(d, d_expected, rtol=1.0e-1) #depth at outlet used to calc v 
-        
-    def test_weir_orifice_3(self):
-        """test_weir_orifice 3
-        
-        This tests the test_weir_orifice routine with data obtained from a spreadsheet to do the weir orfice calcs 
-        """
-
-
-        g=9.81
-        culvert_slope=1  # Downward
-
-        inlet_depth=6.15
-        outlet_depth=2.02
-        inlet_velocity=1.82
-        outlet_velocity=8.82
-        
-        culvert_length=10.0
-        culvert_width=10.0
-        culvert_height=3.0
-        culvert_z1=2
-        culvert_z2=2
-        
-        culvert_type='trapezoid'
-        manning=0.015
-        sum_loss=1.5
-
-        inlet_specific_energy=inlet_depth + 0.5*inlet_velocity**2/g 
-        z_in = 0.0
-        z_out = z_in-culvert_length*culvert_slope/100
-        E_in = z_in+inlet_depth + 0.5*inlet_velocity**2/g
-        E_out = z_out+outlet_depth + 0.5*outlet_velocity**2/g
-        delta_total_energy = E_in-E_out
-        
-
-        Q_expected = 6.44
-        v_expected = 2.33
-        d_expected = 0.24
-        
-        if verbose:
-            print 50*'='
-            print 'UNITTEST ',inspect.stack()[0][3]
-            print 'width ',culvert_width
-            print 'depth ',culvert_height
-            print 'flow_width ',culvert_width
-            print 'length ' ,culvert_length
-            print 'driving_energy ',inlet_specific_energy
-            print 'delta_total_energy ',delta_total_energy
-            print 'outlet_enquiry_depth ',outlet_depth
-            print 'sum_loss ',sum_loss
-            print 'manning ',manning
-        
-        Q, v, d, flow_area, case= weir_orifice_trapezoid_function(culvert_width, 
-                                                    culvert_height, 
-                                                    culvert_width,
-                                                    culvert_slope,
-                                                    culvert_z1,
-                                                    culvert_z2, 
-                                                    culvert_length, 
-                                                    inlet_specific_energy, 
-                                                    delta_total_energy, 
-                                                    outlet_depth, 
-                                                    sum_loss,
-                                                    manning)
-
-
-
-
-        if verbose:
-            print ('%s %.2f'%('SPEC_E = ',inlet_specific_energy))
-            print ('%s %.2f'%('Delta E = ',delta_total_energy))
-            print ('%s %.2f,%.2f,%.2f' %('   ANUGAcalcsTEST Q-v-d ',Q,v,d))
-            print ('%s %.2f,%.2f,%.2f' %('spreadsheet calculation ', Q_expected, v_expected, d_expected))
-            
-        assert numpy.allclose(Q, Q_expected, rtol=1.0e-1) #inflow
-        assert numpy.allclose(v, v_expected, rtol=1.0e-1) #outflow velocity
-        assert numpy.allclose(d, d_expected, rtol=1.0e-1) #depth at outlet used to calc v  
-
-    def test_weir_orifice_4(self):
-        """test_weir_orifice 4
-        
-        This tests the test_weir_orifice routine with data obtained from a spreadsheet to do the weir orfice calcs  
-        """
-
-
-        g=9.81
-        culvert_slope=0.1  # Downward
-
-        inlet_depth=12.0
-        outlet_depth=10.0
-        inlet_velocity=2.0
-        outlet_velocity=2.5
-        
-        culvert_length=100.0
-        culvert_width=10.0
-        culvert_height=3.0
-        culvert_z1=2
-        culvert_z2=2
-        
-        culvert_type='trapezoid'
-        manning=0.015
-        sum_loss=1.5
-
-        inlet_specific_energy=inlet_depth + 0.5*inlet_velocity**2/g 
-        z_in = 0.0
-        z_out = z_in-culvert_length*culvert_slope/100
-        E_in = z_in+inlet_depth + 0.5*inlet_velocity**2/g
-        E_out = z_out+outlet_depth + 0.5*outlet_velocity**2/g
-        delta_total_energy = E_in-E_out
-        
-
-        Q_expected = 383.75
-        v_expected = 5.09
-        d_expected = 3.00
-        
-        if verbose:
-            print 50*'='
-            print 'UNITTEST ',inspect.stack()[0][3]
-            print 'width ',culvert_width
-            print 'depth ',culvert_height
-            print 'flow_width ',culvert_width
-            print 'length ' ,culvert_length
-            print 'driving_energy ',inlet_specific_energy
-            print 'delta_total_energy ',delta_total_energy
-            print 'outlet_enquiry_depth ',outlet_depth
-            print 'sum_loss ',sum_loss
-            print 'manning ',manning
-        
-        Q, v, d, flow_area, case= weir_orifice_trapezoid_function(culvert_width, 
-                                                    culvert_height, 
-                                                    culvert_width,
-                                                    culvert_slope,
-                                                    culvert_z1,
-                                                    culvert_z2, 
-                                                    culvert_length, 
-                                                    inlet_specific_energy, 
-                                                    delta_total_energy, 
-                                                    outlet_depth, 
-                                                    sum_loss,
-                                                    manning)
-
-
-
-
-        if verbose:
-            print ('%s %.2f'%('SPEC_E = ',inlet_specific_energy))
-            print ('%s %.2f'%('Delta E = ',delta_total_energy))
-            print ('%s %.2f,%.2f,%.2f' %('   ANUGAcalcsTEST Q-v-d ',Q,v,d))
-            print ('%s %.2f,%.2f,%.2f' %('spreadsheet calculation ', Q_expected, v_expected, d_expected))
-            
-        assert numpy.allclose(Q, Q_expected, rtol=1.0e-1) #inflow
-        assert numpy.allclose(v, v_expected, rtol=1.0e-1) #outflow velocity
-        assert numpy.allclose(d, d_expected, rtol=1.0e-1) #depth at outlet used to calc v 
-        
-
-    def test_weir_orifice_5(self):
-        """test_weir_orifice 5
-        
-        This tests the test_weir_orifice routine with data obtained from a spreadsheet to do the weir orfice calcs  
-        """
-
-
-        g=9.81
-        culvert_slope=1  # Downward
-
-        inlet_depth=12.0
-        outlet_depth=10.0
-        inlet_velocity=2.0
-        outlet_velocity=2.5
-        
-        culvert_length=100.0
-        culvert_width=10.0
-        culvert_height=3.0
-        culvert_z1=2
-        culvert_z2=2
-        
-        culvert_type='trapezoid'
-        manning=0.015
-        sum_loss=1.5
-
-        inlet_specific_energy=inlet_depth + 0.5*inlet_velocity**2/g 
-        z_in = 0.0
-        z_out = z_in-culvert_length*culvert_slope/100
-        E_in = z_in+inlet_depth + 0.5*inlet_velocity**2/g
-        E_out = z_out+outlet_depth + 0.5*outlet_velocity**2/g
-        delta_total_energy = E_in-E_out
-        
-
-        Q_expected = 487.48
-        v_expected = 6.13
-        d_expected = 3.00
-        
-        if verbose:
-            print 50*'='
-            print 'UNITTEST ',inspect.stack()[0][3]
-            print 'width ',culvert_width
-            print 'depth ',culvert_height
-            print 'flow_width ',culvert_width
-            print 'length ' ,culvert_length
-            print 'driving_energy ',inlet_specific_energy
-            print 'delta_total_energy ',delta_total_energy
-            print 'outlet_enquiry_depth ',outlet_depth
-            print 'sum_loss ',sum_loss
-            print 'manning ',manning
-        
-        Q, v, d, flow_area, case= weir_orifice_trapezoid_function(culvert_width, 
-                                                    culvert_height, 
-                                                    culvert_width,
-                                                    culvert_slope,
-                                                    culvert_z1,
-                                                    culvert_z2, 
-                                                    culvert_length, 
-                                                    inlet_specific_energy, 
-                                                    delta_total_energy, 
-                                                    outlet_depth, 
-                                                    sum_loss,
-                                                    manning)
-
-
-
-
-        if verbose:
-            print ('%s %.2f'%('SPEC_E = ',inlet_specific_energy))
-            print ('%s %.2f'%('Delta E = ',delta_total_energy))
-            print ('%s %.2f,%.2f,%.2f' %('   ANUGAcalcsTEST Q-v-d ',Q,v,d))
-            print ('%s %.2f,%.2f,%.2f' %('spreadsheet calculation ', Q_expected, v_expected, d_expected))
-            
-        assert numpy.allclose(Q, Q_expected, rtol=1.0e-1) #inflow
-        assert numpy.allclose(v, v_expected, rtol=1.0e-1) #outflow velocity
-        assert numpy.allclose(d, d_expected, rtol=1.0e-1) #depth at outlet used to calc v 
-
-    def test_weir_orifice_6(self):
-        """test_weir_orifice 6
-        
-        This tests the test_weir_orifice routine with data obtained from a spreadsheet to do the weir orfice calcs 
-        """
-
-
-        g=9.81
-        culvert_slope=10  # Downward
-
-        inlet_depth=12.0
-        outlet_depth=10.0
-        inlet_velocity=2.0
-        outlet_velocity=2.5
-        
-        culvert_length=100.0
-        culvert_width=10.0
-        culvert_height=3.0
-        culvert_z1=2
-        culvert_z2=2
-        
-        culvert_type='trapezoid'
-        manning=0.015
-        sum_loss=1.5
-
-        inlet_specific_energy=inlet_depth + 0.5*inlet_velocity**2/g 
-        z_in = 0.0
-        z_out = z_in-culvert_length*culvert_slope/100
-        E_in = z_in+inlet_depth + 0.5*inlet_velocity**2/g
-        E_out = z_out+outlet_depth + 0.5*outlet_velocity**2/g
-        delta_total_energy = E_in-E_out
-        
-
-        Q_expected = 1049.86
-        v_expected = 8.75
-        d_expected = 3.00
-        
-        if verbose:
-            print 50*'='
-            print 'UNITTEST ',inspect.stack()[0][3]
-            print 'width ',culvert_width
-            print 'depth ',culvert_height
-            print 'flow_width ',culvert_width
-            print 'length ' ,culvert_length
-            print 'driving_energy ',inlet_specific_energy
-            print 'delta_total_energy ',delta_total_energy
-            print 'outlet_enquiry_depth ',outlet_depth
-            print 'sum_loss ',sum_loss
-            print 'manning ',manning
-        
-        Q, v, d, flow_area, case= weir_orifice_trapezoid_function(culvert_width, 
-                                                    culvert_height, 
-                                                    culvert_width,
-                                                    culvert_slope,
-                                                    culvert_z1,
-                                                    culvert_z2, 
-                                                    culvert_length, 
-                                                    inlet_specific_energy, 
-                                                    delta_total_energy, 
-                                                    outlet_depth, 
-                                                    sum_loss,
-                                                    manning)
-
-
-
-
-        if verbose:
-            print ('%s %.2f'%('SPEC_E = ',inlet_specific_energy))
-            print ('%s %.2f'%('Delta E = ',delta_total_energy))
-            print ('%s %.2f,%.2f,%.2f' %('   ANUGAcalcsTEST Q-v-d ',Q,v,d))
-            print ('%s %.2f,%.2f,%.2f' %('spreadsheet calculation ', Q_expected, v_expected, d_expected))
-            
-        assert numpy.allclose(Q, Q_expected, rtol=1.0e-1) #inflow
-        assert numpy.allclose(v, v_expected, rtol=1.0e-1) #outflow velocity
-        assert numpy.allclose(d, d_expected, rtol=1.0e-1) #depth at outlet used to calc v 
-# =========================================================================
-if __name__ == "__main__":
-    suite = unittest.makeSuite(Test_weir_orifice_trapezoid_operator, 'test')
-    runner = unittest.TextTestRunner()
-    runner.run(suite)
