Changeset 4588


Ignore:
Timestamp:
Jul 4, 2007, 6:09:12 PM (17 years ago)
Author:
ole
Message:

Added exception and helpful diagnostics if a boundary condition tries
to access file_boundary outside its area defined by the underlying
sww file.

Location:
anuga_core/source/anuga
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • anuga_core/source/anuga/abstract_2d_finite_volumes/generic_boundary_conditions.py

    r4312 r4588  
    11"""boundary.py - Classes for implementing boundary conditions
    22"""
     3
     4from anuga.utilities.numerical_tools import NAN   
    35
    46
     
    271273        if vol_id is not None and edge_id is not None:
    272274            i = self.boundary_indices[ vol_id, edge_id ]
    273             return self.F(t, point_id = i)
     275            res = self.F(t, point_id = i)
     276
     277            if res == NAN:
     278                x,y=self.midpoint_coordinates[i,:]
     279                msg = 'NAN value found in file_boundary at '
     280                msg += 'point id #%d: (%.2f, %.2f)' %(i, x, y)
     281                #print msg
     282                raise Exception, msg
     283           
     284            return res
    274285        else:
    275286            #raise 'Boundary call without point_id not implemented'
  • anuga_core/source/anuga/abstract_2d_finite_volumes/test_util.py

    r4490 r4588  
    689689
    690690
    691     def xtest_spatio_temporal_file_function_time(self):
     691    def NOtest_spatio_temporal_file_function_time(self):
     692        # FIXME: This passes but needs some TLC
    692693        # Test that File function interpolates correctly
    693694        # When some points are outside the mesh
  • anuga_core/source/anuga/fit_interpolate/interpolate.py

    r4548 r4588  
    548548                                                  point_coordinates=\
    549549                                                  self.interpolation_points)
     550
     551                    #assert len(result), len(interpolation_points)
    550552                    self.precomputed_values[name][i, :] = result
    551553
     
    645647                    if ratio > 0:
    646648                        Q1 = Q[self.index+1, point_id]
    647            
     649
    648650            #Linear temporal interpolation   
    649651            if ratio > 0:
  • anuga_core/source/anuga/fit_interpolate/test_interpolate.py

    r4522 r4588  
    1414
    1515from Scientific.IO.NetCDF import NetCDFFile
    16 from Numeric import allclose, array, transpose, zeros, Float
     16from Numeric import allclose, array, transpose, zeros, Float, sometrue, alltrue, take, where
    1717
    1818
     
    13361336                                   verbose = False)
    13371337
     1338       
     1339        assert alltrue(I.precomputed_values['Attribute'][:,4] != NAN)
     1340        assert sometrue(I.precomputed_values['Attribute'][:,5] == NAN)
     1341
     1342        #X = I.precomputed_values['Attribute'][1,:]
     1343        #print X
     1344        #print take(X, X == NAN)
     1345        #print where(X == NAN, range(len(X)), 0)       
     1346       
    13381347        answer = linear_function(interpolation_points)
    13391348         
  • anuga_core/source/anuga/shallow_water/test_shallow_water_domain.py

    r4554 r4588  
    42744274        #from domain 1. Call it domain2
    42754275
    4276         points = [ [0,0], [1.0/3,0], [1.0/3,1.0/3],
     4276        points = [ [0,0],
     4277                   [1.0/3,0], [1.0/3,1.0/3],
    42774278                   [2.0/3,0], [2.0/3,1.0/3], [2.0/3,2.0/3],
    4278                    [1,0], [1,1.0/3], [1,2.0/3], [1,1]]
    4279 
     4279                   [1,0],     [1,1.0/3],     [1,2.0/3],     [1,1]] 
     4280                   
    42804281        vertices = [ [1,2,0],
    42814282                     [3,4,1], [2,1,4], [4,5,2],
     
    43864387        R0 = Bf.evaluate(8,0)
    43874388        assert allclose(R0[0], ((s1[10] + s1[15])/2 + 2.0*(s2[10] + s2[15])/2)/3 + mean_stage)
     4389
     4390
     4391        #Cleanup
     4392        os.remove(domain1.get_name() + '.' + domain1.format)
     4393
     4394
     4395    def test_spatio_temporal_boundary_outside(self):
     4396        """Test that field_boundary catches if a point is outside the sww that defines it
     4397        """
     4398
     4399        import time
     4400        #Create sww file of simple propagation from left to right
     4401        #through rectangular domain
     4402
     4403        from mesh_factory import rectangular
     4404
     4405        #Create basic mesh
     4406        points, vertices, boundary = rectangular(3, 3)
     4407
     4408        #Create shallow water domain
     4409        domain1 = Domain(points, vertices, boundary)
     4410
     4411        domain1.reduction = mean
     4412        domain1.smooth = True #To mimic MOST output
     4413
     4414        domain1.default_order = 2
     4415        domain1.store = True
     4416        domain1.set_datadir('.')
     4417        domain1.set_name('spatio_temporal_boundary_source' + str(time.time()))
     4418
     4419        #FIXME: This is extremely important!
     4420        #How can we test if they weren't stored?
     4421        domain1.quantities_to_be_stored = ['stage', 'xmomentum', 'ymomentum']
     4422
     4423
     4424        #Bed-slope and friction at vertices (and interpolated elsewhere)
     4425        domain1.set_quantity('elevation', 0)
     4426        domain1.set_quantity('friction', 0)
     4427
     4428        # Boundary conditions
     4429        Br = Reflective_boundary(domain1)
     4430        Bd = Dirichlet_boundary([0.3,0,0])
     4431        domain1.set_boundary({'left': Bd, 'top': Bd, 'right': Br, 'bottom': Br})
     4432        #Initial condition
     4433        domain1.set_quantity('stage', 0)
     4434        domain1.check_integrity()
     4435
     4436        finaltime = 5
     4437        #Evolution  (full domain - large steps)
     4438        for t in domain1.evolve(yieldstep = 1, finaltime = finaltime):
     4439            pass
     4440            #domain1.write_time()
     4441
     4442
     4443        #Create an triangle shaped domain (coinciding with some
     4444        #coordinates from domain 1, but one edge outside!),
     4445        #formed from the lower and right hand  boundaries and
     4446        #the sw-ne diagonal as in the previous test but scaled
     4447        #in the x direction by a factor of 2
     4448
     4449        points = [ [0,0],
     4450                   [2.0/3,0], [2.0/3,1.0/3],
     4451                   [4.0/3,0], [4.0/3,1.0/3], [4.0/3,2.0/3],
     4452                   [2,0],     [2,1.0/3],     [2,2.0/3],     [2,1] 
     4453                   ]
     4454
     4455        vertices = [ [1,2,0],
     4456                     [3,4,1], [2,1,4], [4,5,2],
     4457                     [6,7,3], [4,3,7], [7,8,4], [5,4,8], [8,9,5]]
     4458
     4459        boundary = { (0,1):'bottom', (1,1):'bottom', (4,1): 'bottom',
     4460                     (4,2):'right', (6,2):'right', (8,2):'right',
     4461                     (0,0):'diagonal', (3,0):'diagonal', (8,0):'diagonal'}
     4462
     4463        domain2 = Domain(points, vertices, boundary)
     4464
     4465        domain2.reduction = domain1.reduction
     4466        domain2.smooth = False
     4467        domain2.default_order = 2
     4468
     4469        #Bed-slope and friction at vertices (and interpolated elsewhere)
     4470        domain2.set_quantity('elevation', 0)
     4471        domain2.set_quantity('friction', 0)
     4472        domain2.set_quantity('stage', 0)
     4473
     4474
     4475        #Read results for specific timesteps t=1 and t=2
     4476        from Scientific.IO.NetCDF import NetCDFFile
     4477        fid = NetCDFFile(domain1.get_name() + '.' + domain1.format)
     4478
     4479        x = fid.variables['x'][:]
     4480        y = fid.variables['y'][:]
     4481        s1 = fid.variables['stage'][1,:]
     4482        s2 = fid.variables['stage'][2,:]
     4483        fid.close()
     4484
     4485        from Numeric import take, reshape, concatenate
     4486        shp = (len(x), 1)
     4487        points = concatenate( (reshape(x, shp), reshape(y, shp)), axis=1)
     4488        #The diagonal points of domain 1 are 0, 5, 10, 15
     4489
     4490        #print points[0], points[5], points[10], points[15]
     4491        assert allclose( take(points, [0,5,10,15]),
     4492                         [[0,0], [1.0/3, 1.0/3], [2.0/3, 2.0/3], [1,1]])
     4493
     4494
     4495        # Boundary conditions
     4496        Br = Reflective_boundary(domain2)
     4497        #Bf = Spatio_temporal_boundary(domain1.get_name() + '.' + domain1.format,
     4498        #                              domain2)
     4499        Bf = Field_boundary(domain1.get_name() + '.' + domain1.format,
     4500                            domain2, mean_stage=1)
     4501       
     4502        domain2.set_boundary({'right':Br, 'bottom':Br, 'diagonal':Bf})
     4503        domain2.check_integrity()
     4504
     4505        try:
     4506            for t in domain2.evolve(yieldstep = 1, finaltime = finaltime):
     4507                pass
     4508        except:
     4509            pass
     4510        else:
     4511            msg = 'This should have caught NAN at boundary'
     4512            raise Exception, msg
    43884513
    43894514
     
    46194744       
    46204745if __name__ == "__main__":
    4621     suite = unittest.makeSuite(Test_Shallow_Water,'test')
     4746    suite = unittest.makeSuite(Test_Shallow_Water,'test')   
     4747    #suite = unittest.makeSuite(Test_Shallow_Water,'test_spatio_temporal_boundary_outside')
    46224748    #suite = unittest.makeSuite(Test_Shallow_Water,'test_get_maximum_inundation_from_sww')
    46234749    #suite = unittest.makeSuite(Test_Shallow_Water,'test_temp')   
Note: See TracChangeset for help on using the changeset viewer.