Changeset 700


Ignore:
Timestamp:
Dec 13, 2004, 5:45:14 PM (20 years ago)
Author:
ole
Message:

Added error message if indices is not a list, array or None. Also fixed up Hobart examples.

Location:
inundation/ga/storm_surge
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • inundation/ga/storm_surge/analytical solutions/Hobart.py

    r699 r700  
    3636print 'Creating domain from', filename
    3737domain = pmesh_to_domain_instance(filename, Domain)
    38 print "Number of triangles = ", len(domain)
     38print 'Number of triangles = ', len(domain)
     39print 'Extent = ', domain.get_extent()
     40
    3941
    4042domain.default_order = 1
    4143domain.smooth = True
     44
    4245
    4346#------------------------------
     
    6063X = domain.get_centroid_coordinates()
    6164#        Find triangle indices which are within polygon boundary only
    62 indicies = inside_polygon(X,p0)
     65indices = inside_polygon(X, p0)
    6366#        Get the bed elevation at the centroid of every triangle in polygon region
    64 zp = domain.get_quantity('elevation',location='centroids',indexes='indicies')
    65 #        Set the level to bed elevation plus depth for all triangle centroids in the polygon region
    66 domain.set_quantity('level',zp+depth,location='centroids',indexes='indicies')
     67
     68zp = domain.get_quantity('elevation', location='centroids', indexes=indices)
     69#        Set the level to bed elevation plus depth for all triangle vertices in the polygon region
     70
     71domain.set_quantity('level', zp+depth, location='centroids', indexes=indices)
     72
     73
     74#Alternative way which also works (I used it for testing - OMN)
     75#
     76
     77#z = domain.get_quantity('elevation')
     78#from copy import copy
     79#w = copy(z)
     80#for i in indices:
     81#    w[i, :] = z[i, :] + depth
     82#domain.set_quantity('level', w)
     83
    6784
    6885#-------------------------------------
  • inundation/ga/storm_surge/pyvolution/quantity.py

    r659 r700  
    110110            msg = 'Given values are None'
    111111            raise msg           
    112        
    113         import types
     112
     113        import types, Numeric
     114        assert type(indexes) in [types.ListType, types.NoneType,
     115                                 Numeric.ArrayType],\
     116                                 'Indices must be a list or None'
     117
    114118       
    115119        if callable(X):
     
    177181            raise msg         
    178182       
     183        import types, Numeric
     184        assert type(indexes) in [types.ListType, types.NoneType,
     185                                 Numeric.ArrayType],\
     186                                 'Indices must be a list or None'
     187
    179188        if (indexes ==  None):
    180189            indexes = range(len(self))
     190       
    181191           
    182192        if location == 'centroids':
  • inundation/ga/storm_surge/pyvolution/test_domain.py

    r648 r700  
    399399        domain.set_region([set_bottom_friction, set_top_friction])
    400400        #print domain.quantities['friction'].get_values()
    401         assert allclose(domain.quantities['friction'].get_values(), [[ 0.09,  0.09,  0.09],
    402 [ 0.09,  0.09,  0.09],
    403 [ 0.07,  0.07,  0.07],
    404 [ 0.07,  0.07,  0.07],
    405 [ 1.0,  1.0,  1.0],
    406 [ 1.0,  1.0,  1.0]])
     401        assert allclose(domain.quantities['friction'].get_values(),\
     402                        [[ 0.09,  0.09,  0.09],
     403                         [ 0.09,  0.09,  0.09],
     404                         [ 0.07,  0.07,  0.07],
     405                         [ 0.07,  0.07,  0.07],
     406                         [ 1.0,  1.0,  1.0],
     407                         [ 1.0,  1.0,  1.0]])
    407408       
    408409        domain.set_region([set_all_friction])
  • inundation/ga/storm_surge/pyvolution/test_region.py

    r592 r700  
    4848        domain.set_region([a, b])
    4949        #print domain.quantities['friction'].get_values()
    50         assert allclose(domain.quantities['friction'].get_values(), [[ 0.09,  0.09,  0.09],
    51 [ 0.09,  0.09,  0.09],
    52 [ 0.07,  0.07,  0.07],
    53 [ 0.07,  0.07,  0.07],
    54 [ 1.0,  1.0,  1.0],
    55 [ 1.0,  1.0,  1.0]])
     50        assert allclose(domain.quantities['friction'].get_values(),\
     51                        [[ 0.09,  0.09,  0.09],
     52                         [ 0.09,  0.09,  0.09],
     53                         [ 0.07,  0.07,  0.07],
     54                         [ 0.07,  0.07,  0.07],
     55                         [ 1.0,  1.0,  1.0],
     56                         [ 1.0,  1.0,  1.0]])
    5657
    5758        #c = Add_Value_To_Region('all', 'friction', 10.0)
Note: See TracChangeset for help on using the changeset viewer.