Index: anuga_core/source/anuga/culvert_flows/culvert_class.py
===================================================================
--- anuga_core/source/anuga/culvert_flows/culvert_class.py	(revision 5566)
+++ anuga_core/source/anuga/culvert_flows/culvert_class.py	(revision 5570)
@@ -2,4 +2,7 @@
 from anuga.culvert_flows.culvert_polygons import create_culvert_polygons
 from anuga.utilities.system_tools import log_to_file
+from anuga.utilities.polygon import inside_polygon
+from anuga.utilities.polygon import is_inside_polygon
+
 
 class Culvert_flow:
@@ -125,5 +128,20 @@
             #               P['enquiry_polygon1']],
             #              figname='culvert_polygon_output')
-        
+
+
+        # Check that all polygons lie within the mesh.
+        bounding_polygon = domain.get_boundary_polygon()
+        for key in P.keys():
+            print 'Key', key
+            for point in P[key]:
+
+                print 'Passing in:', point
+                msg = 'Point %s in polygon %s for culvert %s did not'\
+                      %(str(point), key, self.label)
+                msg += 'fall within the domain boundary.'
+                assert is_inside_polygon(point, bounding_polygon), msg
+        
+
+        # Create inflow object at each end of the culvert. 
         self.openings = []
         self.openings.append(Inflow(domain,
@@ -188,5 +206,5 @@
     def __call__(self, domain):
         from anuga.utilities.numerical_tools import mean
-        from anuga.utilities.polygon import inside_polygon
+        
         from anuga.config import g, epsilon
         from Numeric import take, sqrt
@@ -209,12 +227,15 @@
         openings = self.openings   # There are two Opening [0] and [1]
         for i, opening in enumerate(openings):
-            stage = domain.quantities['stage'].get_values(location='centroids',
-                                                          indices=opening.exchange_indices)
-            elevation = domain.quantities['elevation'].get_values(location='centroids',
-                                                                  indices=opening.exchange_indices)
+            dq = domain.quantities
+            
+            stage = dq['stage'].get_values(location='centroids',
+                                           indices=opening.exchange_indices)
+            elevation = dq['elevation'].get_values(location='centroids',
+                                                   indices=opening.exchange_indices)
 
             # Indices corresponding to energy enquiry field for this opening
             coordinates = domain.get_centroid_coordinates(absolute=True) # Get all centroid points (x,y)
-            enquiry_indices = inside_polygon(coordinates, self.enquiry_polygons[i]) 
+            enquiry_indices = inside_polygon(coordinates,
+                                             self.enquiry_polygons[i]) 
 
             if len(enquiry_indices) == 0:
@@ -223,9 +244,12 @@
             
             # Get model values for points in enquiry polygon for this opening
-            dq = domain.quantities
-            stage = dq['stage'].get_values(location='centroids', indices=enquiry_indices)
-            xmomentum = dq['xmomentum'].get_values(location='centroids', indices=enquiry_indices)
-            ymomentum = dq['ymomentum'].get_values(location='centroids', indices=enquiry_indices)                        
-            elevation = dq['elevation'].get_values(location='centroids', indices=enquiry_indices)
+            stage = dq['stage'].get_values(location='centroids',
+                                           indices=enquiry_indices)
+            xmomentum = dq['xmomentum'].get_values(location='centroids',
+                                                   indices=enquiry_indices)
+            ymomentum = dq['ymomentum'].get_values(location='centroids',
+                                                   indices=enquiry_indices)
+            elevation = dq['elevation'].get_values(location='centroids',
+                                                   indices=enquiry_indices)
             depth = stage - elevation
 
@@ -234,4 +258,5 @@
             ux = xmomentum/(depth+velocity_protection/depth)   # Velocity (x-direction)
             uy = ymomentum/(depth+velocity_protection/depth)   # Velocity (y-direction)
+            print 'Velocity in culvert:', ux, uy, depth, xmomentum, ymomentum
             v = mean(sqrt(ux**2+uy**2))      # Average velocity
             w = mean(stage)                  # Average stage
Index: anuga_core/source/anuga/shallow_water/shallow_water_domain.py
===================================================================
--- anuga_core/source/anuga/shallow_water/shallow_water_domain.py	(revision 5566)
+++ anuga_core/source/anuga/shallow_water/shallow_water_domain.py	(revision 5570)
@@ -108,5 +108,5 @@
 
 
-from anuga.utilities.polygon import inside_polygon, polygon_area        
+from anuga.utilities.polygon import inside_polygon, polygon_area, is_inside_polygon
 
 
@@ -1501,5 +1501,5 @@
             
                      
-        from math import pi
+        from math import pi, cos, sin
 
         self.domain = domain
@@ -1513,4 +1513,8 @@
                          # previous timestep in order to obtain rate
 
+                         
+        bounding_polygon = domain.get_boundary_polygon()
+
+
         # Update area if applicable
         self.exchange_area = None        
@@ -1521,7 +1525,41 @@
 
             self.exchange_area = radius**2*pi
+
+            # Check that circle center lies within the mesh.
+            msg = 'Center %s specified for forcing term did not' %(str(center))
+            msg += 'fall within the domain boundary.'
+            assert is_inside_polygon(center, bounding_polygon), msg
+
+            # Check that circle periphery lies within the mesh.
+            N = 100
+            periphery_points = []
+            for i in range(N):
+
+                theta = 2*pi*i/100
+                
+                x = center[0] + radius*cos(theta)
+                y = center[1] + radius*sin(theta)
+
+                periphery_points.append([x,y])
+
+
+            for point in periphery_points:
+                msg = 'Point %s on periphery for forcing term did not' %(str(point))
+                msg += ' fall within the domain boundary.'
+                assert is_inside_polygon(point, bounding_polygon), msg
+
 	
         if polygon is not None:
             self.exchange_area = polygon_area(self.polygon)
+
+            # Check that polygon lies within the mesh.
+            for point in self.polygon:
+                msg = 'Point %s in polygon for forcing term did not' %(str(point))
+                msg += 'fall within the domain boundary.'
+                assert is_inside_polygon(point, bounding_polygon), msg
+        
+
+
+            
 
 
Index: anuga_core/source/anuga/utilities/polygon.py
===================================================================
--- anuga_core/source/anuga/utilities/polygon.py	(revision 5566)
+++ anuga_core/source/anuga/utilities/polygon.py	(revision 5570)
@@ -457,17 +457,33 @@
 	raise msg
 
-    #if verbose: print 'check'
-
-    assert len(polygon.shape) == 2,\
-       'Polygon array must be a 2d array of vertices'
-
-    assert polygon.shape[1] == 2,\
-       'Polygon array must have two columns'
-
-    assert len(points.shape) == 2,\
-       'Points array must be a 2d array'
-
-    assert points.shape[1] == 2,\
-       'Points array must have two columns'
+    msg = 'Polygon array must be a 2d array of vertices'
+    assert len(polygon.shape) == 2, msg
+
+    msg = 'Polygon array must have two columns' 
+    assert polygon.shape[1] == 2, msg
+
+
+    msg = 'Points array must be 1 or 2 dimensional.'
+    msg += ' I got %d dimensions' %len(points.shape)
+    assert 0 < len(points.shape) < 3, msg
+
+
+    if len(points.shape) == 1:
+        # Only one point was passed in.
+        # Convert to array of points
+        points = reshape(points, (1,2))
+
+    
+    msg = 'Point array must have two columns (x,y), '
+    msg += 'I got points.shape[1] == %d' %points.shape[0]
+    assert points.shape[1] == 2, msg
+
+       
+    msg = 'Points array must be a 2d array. I got %s' %str(points[:30])
+    assert len(points.shape) == 2, msg
+
+    msg = 'Points array must have two columns'
+    assert points.shape[1] == 2, msg
+
 
     N = polygon.shape[0] #Number of vertices in polygon
Index: anuga_core/source/anuga/utilities/polygon_ext.c
===================================================================
--- anuga_core/source/anuga/utilities/polygon_ext.c	(revision 5566)
+++ anuga_core/source/anuga/utilities/polygon_ext.c	(revision 5570)
@@ -199,4 +199,6 @@
   //Find min and max of poly used for optimisation when points
   //are far away from polygon
+  
+  //FIXME(Ole): Pass in rtol and atol from Python
 
   minpx = polygon[0]; maxpx = minpx;
