Changeset 389 for inundation/ga


Ignore:
Timestamp:
Oct 12, 2004, 2:45:24 PM (20 years ago)
Author:
duncan
Message:

add vert atts to pmesh2domain/pyvolution

Location:
inundation/ga/storm_surge/pyvolution
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • inundation/ga/storm_surge/pyvolution/domain.py

    r278 r389  
    125125        return q
    126126
     127
     128    def set_quantity_vertices_dict(self, quantity_dict):
     129        """Set values for named quantities.
     130        The index is the quantity
     131       
     132        name: Name of quantity
     133        X: Compatible list, Numeric array, const or function (see below)
     134       
     135        The values will be stored in elements following their
     136        internal ordering.
     137
     138        """
     139        for key in quantity_dict.keys():
     140            self.set_quantity(key,quantity_dict[key], location='vertices')
     141       
    127142    def set_quantity(self, name, X, location='vertices'):
    128143        """Set values for named quantity
  • inundation/ga/storm_surge/pyvolution/interpolate_sww.py

    r374 r389  
    116116        volumes = fid.variables['volumes'][:]
    117117        time = fid.variables['time'][:]
    118         stage = fid.variables['stage'][:,:]   # 2D  
     118        stage = fid.variables['stage'][:,:]   # 2D
    119119       
    120120        fid.close()
  • inundation/ga/storm_surge/pyvolution/least_squares.py

    r374 r389  
    6262    point_dict = load_xya_file(point_file)
    6363    point_coordinates = point_dict['pointlist']
    64     point_attributes = point_dict['pointattributelist']
    6564    point_attributes = point_dict['pointattributelist']
    6665    title_string = point_dict['title']
  • inundation/ga/storm_surge/pyvolution/pmesh2domain.py

    r374 r389  
    88
    99
    10 def pmesh_to_domain(fileName, tags = None, setting_function = None):
     10def pmesh_to_domain_instance(fileName, DomainClass,tags = None, setting_function = None):
    1111    """
    1212    """
    13     #FIXME:  The current design doesn't seem to accomadate tags and
    14     # setting_functions being passed into the domain at this point.
     13    #FIXME:  The current design doesn't seem to accomadate tags
     14    # being passed into the domain at this point.
    1515
    16     #FIXME: Plus the names of the functions are no longer appropriate,
    17     #since domain objects aren't being returned.
    18    
    1916    import sys
    20     from config import pmesh_filename
    21     sys.path.append(pmesh_filename)
    22     from load_mesh.loadASCII import import_trianglulation
     17    from domain import Domain
    2318
    24     try:
    25         meshdic = import_trianglulation(fileName)
    26     except IOError, e:       
    27         msg = 'Could not open file %s ' %fileName
    28         raise IOError, msg
     19    vertex_coordinates, volumes, marker_dict, vertex_quantity_dict = \
     20                        pmesh_to_domain(fileName,
     21                                                   setting_function=setting_function)
     22       
     23    assert issubclass(DomainClass, Domain), "DomainClass is not a subclass of Domain."
     24    domain = DomainClass(vertex_coordinates, volumes, marker_dict)
    2925
    30        
    31     return pmesh_dictionary_to_domain(meshdic,
    32                                       setting_function = setting_function)
     26    # set the water level to be the elevation
     27    if vertex_quantity_dict.has_key('elevation') and not vertex_quantity_dict.has_key('level'):
     28        vertex_quantity_dict['level'] = vertex_quantity_dict['elevation']
     29    domain.set_quantity_vertices_dict(vertex_quantity_dict)
     30    #print "vertex_quantity_dict",vertex_quantity_dict
     31    return domain
    3332
    3433
    3534
    36 def pmesh_dictionary_to_domain(meshdic, setting_function = None):
     35def pmesh_to_domain(fileName, setting_function = None):
    3736    """
    3837    convert a pmesh dictionary to a list of Volumes.
    3938    Also, return a list of triangles which have boundary tags
    40     meshdic structure;
     39    mesh_dict structure;
    4140    generated point list: [(x1,y1),(x2,y2),...] (Tuples of doubles) 
    4241    generated point attribute list:[(P1att1,P1attt2, ...),(P2att1,P2attt2,...),...]
     
    4746    triangle attribute list: [T1att, T2att, ...] (list of floats)
    4847    """
    49 
    50     vertex_coordinates = meshdic['generatedpointlist']
    51     volumes = meshdic['generatedtrianglelist']
     48   
     49    from Numeric import transpose
     50    from load_mesh.loadASCII import mesh_file_to_mesh_dictionary
     51   
     52    mesh_dict = mesh_file_to_mesh_dictionary(fileName)
     53    #print "mesh_dict",mesh_dict
     54    vertex_coordinates = mesh_dict['generatedpointlist']
     55    volumes = mesh_dict['generatedtrianglelist']
    5256
    5357    #if setting_function:
     
    5559    #        setting_function = [setting_function]
    5660    #    for funct in setting_function:
    57     #        meshdic = funct(meshdic, vertices = mesh_vertices,
     61    #        mesh_dict = funct(mesh_dict, vertices = mesh_vertices,
    5862    #                        volumes = volumes)
    59        
    60     marker_dict = pmesh_dict_to_marker_dict(volumes, meshdic,
     63
     64
     65    vertex_quantity_dict = {}
     66    point_atts = transpose(mesh_dict['generatedpointattributelist'])
     67    point_titles  = mesh_dict['generatedpointattributetitlelist']
     68    #print "point_titles",point_titles
     69    for quantity, value_vector in map (None, point_titles, point_atts):
     70        vertex_quantity_dict[quantity] = value_vector
     71    marker_dict = pmesh_dict_to_marker_dict(volumes, mesh_dict,
    6172                                            vertex_coordinates)
    62 
    63     return vertex_coordinates, volumes, marker_dict
     73   
     74    return vertex_coordinates, volumes, marker_dict, vertex_quantity_dict
    6475
    6576
     
    7586
    7687   
    77 def pmesh_dict_to_marker_dict(triangles,meshdic,Vertices):
    78     """ Convert the pmesh dictionary (meshdic) description of boundary tags
     88def pmesh_dict_to_marker_dict(triangles,mesh_dict,Vertices):
     89    """ Convert the pmesh dictionary (mesh_dict) description of boundary tags
    7990    to a dictionary of markers, indexed with volume id and face number.
    8091    """
    8192    sides = calc_sides(triangles)
    8293    marker_dict = {}
    83     for seg, marker in map(None,meshdic['generatedsegmentlist'],
    84                            meshdic['generatedsegmentmarkerlist']):
     94    for seg, marker in map(None,mesh_dict['generatedsegmentlist'],
     95                           mesh_dict['generatedsegmentmarkerlist']):
    8596        v1 = seg[0]
    8697        v2 = seg[1]
  • inundation/ga/storm_surge/pyvolution/quantity.py

    r344 r389  
    5656    def __len__(self):
    5757        return self.centroid_values.shape[0]
    58        
     58   
    5959    def interpolate(self):
    6060        """Compute interpolated values at edges and centroid
     
    201201            if len(values.shape) == 1:
    202202                #Values are being specified once for each unique vertex
    203                 msg = 'Number of values must mact number of vertices'
     203                msg = 'Number of values must match number of vertices'
    204204                assert values.shape[0] == self.domain.coordinates.shape[0], msg
    205205
     
    218218               
    219219
    220 
     220    # FIXME have a get_vertex_values as well, so the 'level' quantity can be
     221    # set, based on the elevation   
    221222    def set_vertex_values(self, A):
    222223        """Set vertex values for all triangles based on input array A
  • inundation/ga/storm_surge/pyvolution/run_tsh.py

    r309 r389  
    1616
    1717from mesh_factory import rectangular
    18 from pmesh2domain import pmesh_to_domain
     18from pmesh2domain import pmesh_to_domain, pmesh_to_domain_instance
    1919
    2020from Numeric import array
     
    3030
    3131print 'Creating domain from', filename
    32 points, vertices, boundary = pmesh_to_domain(filename)
    33 domain = Domain(points, vertices, boundary)
     32domain = pmesh_to_domain_instance(filename, Domain)
    3433print "Number of triangles = ", len(domain)
    3534
     
    4847print 'Field values'
    4948
    50 domain.set_quantity('elevation', W)
     49#domain.set_quantity('elevation', W)
    5150domain.set_quantity('friction', manning)
    5251
     
    7372
    7473#Set boundary conditions
    75 domain.set_boundary({'left': Bw, '0': Br})
     74domain.set_boundary({'left': Bw, '0': Br, '1':Bw, 'external':Br})
    7675
     76
     77print domain.quantities['elevation'].vertex_values
     78#print domain.quantities['level'].vertex_values
     79         
    7780######################
    7881#Initial condition
    7982print 'Initial condition'
    80 domain.set_quantity('level', Constant_height(W, 0.))
     83#domain.set_quantity('level', Constant_height(W, 0.))
    8184domain.check_integrity()
    8285
Note: See TracChangeset for help on using the changeset viewer.