Changeset 1565


Ignore:
Timestamp:
Jul 1, 2005, 5:08:10 PM (19 years ago)
Author:
steve
Message:

Working on passing quantities from serial to parallel domains

Location:
inundation/ga/storm_surge
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • inundation/ga/storm_surge/parallel/pmesh_divide.py

    r1559 r1565  
    1818#########################################################
    1919
     20from pmesh2domain import pmesh_to_domain_instance
    2021from math import floor
    21 from pmesh2domain import pmesh_to_domain_instance
    22 
    23 #########################################################
    24 #
    25 # Find the minimum x coordinate
    26 #
    27 # *) t1 and t2 are two node coordinates
    28 #
    29 # -------------------------------------------------------
    30 #
    31 # *) The node with the minimum x coordinate is returned
    32 #
    33 #########################################################
    34 
    35 def min_x(t1, t2):
    36     if t1[0] < t2[0]:
    37         return t1
    38     else:
    39         return t2
    40 
    41 #########################################################
    42 #
    43 # Find the maximum x coordinate
    44 #
    45 # *) t1 and t2 are two node coordinates
    46 #
    47 # -------------------------------------------------------
    48 #
    49 # *) The node with the maximum x coordinate is returned
    50 #
    51 #########################################################
    52 
    53 def max_x(t1, t2):
    54     if t1[0] > t2[0]:
    55         return t1
    56     else:
    57         return t2
    58 
    59 #########################################################
    60 #
    61 # Find the minimum y coordinate
    62 #
    63 # *) t1 and t2 are two node coordinates
    64 #
    65 # -------------------------------------------------------
    66 #
    67 # *) The node with the minimum y coordinate is returned
    68 #
    69 #########################################################
    70 def min_y(t1, t2):
    71     if t1[1] < t2[1]:
    72         return t1
    73     else:
    74         return t2
    75 
    76 #########################################################
    77 #
    78 # Find the maximum y coordinate
    79 #
    80 # *) t1 and t2 are two node coordinates
    81 #
    82 # -------------------------------------------------------
    83 #
    84 # *) The node with the maximum y coordinate is returned
    85 #
    86 #########################################################
    87 def max_y(t1, t2):
    88     if t1[1] > t2[1]:
    89         return t1
    90     else:
    91         return t2
    9222
    9323#########################################################
     
    11343    # read in the pmesh
    11444
    115     domain = pmesh_to_domain_instance(f, Domain)#
     45    domain = pmesh_to_domain_instance(f, Domain)
    11646
    11747    # find the bounding box
    118 
    119     x_coord_min = reduce(min_x, domain.coordinates)[0]
    120     x_coord_max = reduce(max_x, domain.coordinates)[0]
    121     y_coord_min = reduce(min_y, domain.coordinates)[1]
    122     y_coord_max = reduce(max_y, domain.coordinates)[1]
    123 
    124 
    125     rect = [x_coord_min, y_coord_min, x_coord_max, y_coord_max]
     48    x_coord_min = domain.xy_extent[0]
     49    x_coord_max = domain.xy_extent[2]
     50    y_coord_min = domain.xy_extent[1]
     51    y_coord_max = domain.xy_extent[3]
     52
     53    rect = domain.xy_extent
    12654
    12755    # find the size of each sub-box
     
    197125
    198126    return nodes, triangles, boundary,  triangles_per_proc, rect
     127
     128
     129
     130def pmesh_divide_steve(f, Domain, n_x = 1, n_y = 1):
     131
     132    # read in the pmesh
     133
     134    domain = pmesh_to_domain_instance(f, Domain)
     135
     136
     137#    for key, Quantity in domain.quantities.iteritems():
     138#        print key
     139#        for n in range(10):
     140#            print Quantity.centroid_values[n]
     141
     142    # find the bounding box
     143    x_coord_min = domain.xy_extent[0]
     144    x_coord_max = domain.xy_extent[2]
     145    y_coord_min = domain.xy_extent[1]
     146    y_coord_max = domain.xy_extent[3]
     147
     148    rect = domain.xy_extent
     149
     150    # find the size of each sub-box
     151
     152    x_div = (x_coord_max-x_coord_min)/n_x
     153    y_div = (y_coord_max-y_coord_min)/n_y
     154
     155
     156    # initialise the lists
     157    tri_list = []
     158    triangles_per_proc = []
     159    proc_sum = []
     160    for i in range(n_x*n_y):
     161        tri_list.append([])
     162        triangles_per_proc.append([])
     163        proc_sum.append([])
     164        tri_list[i] = []
     165
     166    # subdivide the triangles depending on which sub-box they sit
     167    # in (a triangle sits in the sub-box if its first vectex sits
     168    # in that sub-box)
     169
     170    tri_index = {}
     171    N = domain.number_of_elements
     172    for i in range(N):
     173        t = domain.triangles[i]
     174
     175        x_coord = domain.centroid_coordinates[i][0]
     176        bin_x = int(floor((x_coord-x_coord_min)/x_div))
     177        if (bin_x == n_x):
     178            bin_x = n_x-1
     179
     180        y_coord = domain.centroid_coordinates[i][1]
     181        bin_y = int(floor((y_coord-y_coord_min)/y_div))
     182        if (bin_y == n_y):
     183            bin_y = n_y-1
     184
     185        bin = bin_y*n_x + bin_x
     186        tri_list[bin].append(t)
     187        tri_index[i] = ([bin, len(tri_list[bin])-1])
     188
     189    # find the number of triangles per processor and order the
     190    # triangle list so that all of the triangles belonging to
     191    # processor i are listed before those belonging to processor
     192    # i+1
     193
     194    triangles = []
     195    for i in range(n_x*n_y):
     196        triangles_per_proc[i] = len(tri_list[i])
     197        for t in tri_list[i]:
     198            triangles.append(t)
     199
     200    # the boundary labels have to changed in accoradance with the
     201    # new triangle ordering, proc_sum and tri_index help with this
     202
     203    proc_sum[0] = 0
     204    for i in range(n_x*n_y-1):
     205        proc_sum[i+1]=proc_sum[i]+triangles_per_proc[i]
     206
     207    # relabel the boundary elements to fit in with the new triangle
     208    # ordering
     209
     210    boundary = {}
     211    for b in domain.boundary:
     212        t =  tri_index[b[0]]
     213        boundary[proc_sum[t[0]]+t[1], b[1]] = domain.boundary[b]
     214
     215    # extract the node list
     216    nodes = domain.coordinates.copy()
     217
     218    return nodes, triangles, boundary,  triangles_per_proc, rect
     219
     220
     221
  • inundation/ga/storm_surge/parallel/run_parallel_sw_merimbula.py

    r1563 r1565  
    5959# mesh partition routines
    6060
    61 from pmesh_divide import pmesh_divide
     61from pmesh_divide import pmesh_divide, pmesh_divide_steve
    6262from build_submesh import *
    6363from build_local import *
     
    7979
    8080    #filename = 'test-100.tsh'
    81     filename = 'merimbula_10785.tsh'
    82     nx = 2
     81    filename = 'merimbula_10785_1.tsh'
     82    nx = numprocs
    8383    ny = 1
    8484    if nx*ny != numprocs:
     
    8686
    8787    [nodes, triangles, boundary, triangles_per_proc, rect] =\
    88             pmesh_divide(filename, Shallow_Water_Domain, nx, ny)
     88            pmesh_divide_steve(filename, Shallow_Water_Domain, nx, ny)
    8989
    9090    # subdivide the mesh
    9191
    92     print rect
     92    #print rect
    9393
    9494    rect = array(rect, Float)
     
    123123
    124124pypar.broadcast(rect,0)
    125 print rect
     125#print rect
    126126
    127127domain = Parallel_Shallow_Water_Domain(points, vertices, boundary,
  • inundation/ga/storm_surge/pyvolution/general_mesh.py

    r1387 r1565  
    8484        #Register number of elements (N)
    8585        self.number_of_elements = N = self.triangles.shape[0]
     86
     87        self.xy_extent = [ min(self.coordinates[:,0]), min(self.coordinates[:,1]) ,
     88                           max(self.coordinates[:,0]), max(self.coordinates[:,1]) ]
     89
    8690
    8791        #Allocate space for geometric quantities
     
    275279    def get_area(self):
    276280        """Return total area of mesh
    277         """
    278 
    279         return sum(self.areas)
     281        """
     282
     283        return sum(self.areas)
  • inundation/ga/storm_surge/pyvolution/realtime_visualisation_new.py

    r1510 r1565  
    2121
    2222        # models for each quantity
    23         self.z_models = {}
    24         keys = self.domain.quantities.keys()
     23        self.vpython_z_models = {}
    2524        #print keys
    26         for key in keys:
    27             self.z_models[key] = faces(frame= self.frame)
     25        for key in self.domain.quantities:
     26            self.vpython_z_models[key] = faces(frame= self.frame)
    2827
    2928        #print self.z_models
     
    161160
    162161            #print 'update bed image'
    163             self.z_models[qname].pos    = self.pos
    164             self.z_models[qname].color  = self.colour
    165             self.z_models[qname].normal = self.normals
     162            self.vpython_z_models[qname].pos    = self.pos
     163            self.vpython_z_models[qname].color  = self.colour
     164            self.vpython_z_models[qname].normal = self.normals
    166165        except:
    167166            print 'Visualisation: Could not update quantity '+qname
     
    189188
    190189            #print 'update bed image'
    191         self.z_models[qname].pos    = self.pos
    192         self.z_models[qname].color  = self.colour
    193         self.z_models[qname].normal = self.normals
     190        self.vpython_z_models[qname].pos    = self.pos
     191        self.vpython_z_models[qname].color  = self.colour
     192        self.vpython_z_models[qname].normal = self.normals
    194193        #except:
    195194        #    print 'Visualisation: Could not update quantity '+qname
Note: See TracChangeset for help on using the changeset viewer.