Changeset 1424


Ignore:
Timestamp:
May 18, 2005, 5:36:32 PM (20 years ago)
Author:
steve
Message:
 
Location:
inundation/ga/storm_surge
Files:
4 edited

Legend:

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

    r1407 r1424  
    3333
    3434
    35         Generic_domain.__init__(self, coordinates, vertices, boundary,
    36                                 ['stage'])
     35        Generic_domain.__init__(self, coordinates, vertices, boundary,['stage'])
    3736
    3837        if velocity is None:
  • inundation/ga/storm_surge/parallel/parallel_advection.py

    r1414 r1424  
    1616from advection import *
    1717Advection_Domain = Domain
    18 from Numeric import zeros, Float, Int, ones, allclose,  array
     18from Numeric import zeros, Float, Int, ones, allclose, array
    1919import pypar
    2020
     
    2222class Parallel_Domain(Advection_Domain):
    2323
    24     def __init__(self, coordinates, vertices, boundary = None, ghosts = None,
     24    def __init__(self, coordinates, vertices, boundary = None,
     25                 full_send_dict = None, ghost_recv_dict = None,
    2526                 velocity = None):
    26 
    27         Advection_Domain.__init__(self, coordinates, vertices, boundary, velocity)
    28 
    29         N = self.number_of_elements
    3027
    3128        self.processor = pypar.rank()
    3229        self.numproc   = pypar.size()
    33 
    34         if  ghosts == None:
    35             self.ghosts = None
    36             self.full = ones( N, Float)
    37         else:
    38             self.ghosts = ghosts
    39             self.full = ones( N, Int)
    40             keys = self.ghosts.keys()
    41             for key in keys:
    42                 self.full[key] = -1
    43 
    44 
    45 
     30        print 'Processor %d'%self.processor
     31        velocity = [(self.processor+1),0.0]
     32
     33        print 'velocity',velocity
     34
     35        Advection_Domain.__init__(self, coordinates, vertices, boundary, velocity)
     36
     37        N = self.number_of_elements
     38
     39        self.processor = pypar.rank()
     40        self.numproc   = pypar.size()
     41
     42        self.full_send_dict  = full_send_dict
     43        self.ghost_recv_dict = ghost_recv_dict
     44
     45        #print self.full_send_dict
     46        #print self.ghost_recv_dict
    4647
    4748    def check_integrity(self):
     
    6768        pypar.raw_reduce(ltimestep, gtimestep, pypar.MIN, 0)
    6869        pypar.broadcast(gtimestep,0)
    69         pypar.Barrier()
     70        #pypar.Barrier()
    7071
    7172        self.timestep = gtimestep[0]
     
    8283        stage_cv = self.quantities['stage'].centroid_values
    8384
    84 #        for iproc in full_send_dict:
    85 #            Ids = full_send_dict[iproc][0]
    86 #            X   = full_send_dict[iproc][1]
    87 #            for i _ in enumerate(X):
    88 #                X[i] = stage_cv[Ids[i]]
    89 #            pypar.send(X,iproc)
     85        # update of non-local ghost cells
     86#        for iproc in range(self.numproc):
    9087#
    91 #        for iproc in ghost_recv_dict:
    92 #            Ids = ghost_recv_dict[iproc][0]
    93 #            X   = ghost_recv_dict[iproc][1]
    94 #            X = pypar.receive(iproc,X)
    95 #            for i _ in enumerate(X):
    96 #                stage_cv[Ids[i]] = X[i]
    97 
    98 
    99         if self.ghosts is not None:
    100             stage_cv = self.quantities['stage'].centroid_values
    101             for triangle in self.ghosts:
    102                 stage_cv[triangle] = stage_cv[self.ghosts[triangle]]
     88#            if iproc == self.processor:
     89#                #Send data from iproc processor to other processors
     90#                for send_proc in full_send_dict:
     91#                    if send_proc != iproc:
     92#                        Idf  = full_send_dict[iproc][0]
     93#                        Xout = full_send_dict[iproc][1]
     94#                        for i _ in enumerate(X):
     95#                            Xout[i] = stage_cv[Idf[i]]
     96#                        pypar.send(Xout,send_proc)
     97#            else:
     98#                #Receive data from the iproc processor
     99#                if  ghost_recv_dict.has_key(iproc):
     100#                    Idg = ghost_recv_dict[iproc][0]
     101#                    X   = ghost_recv_dict[iproc][1]
     102#                    X = pypar.receive(iproc,X)
     103#                    for i _ in enumerate(X):
     104#                        stage_cv[Idg[i]] = X[i]
     105
     106        #local update of ghost cells
     107        iproc = self.processor
     108        if self.full_send_dict.has_key(iproc):
     109            Idf  = self.full_send_dict[iproc][0]
     110            #print Idf
     111            Idg  = self.ghost_recv_dict[iproc][0]
     112            #print Idg
     113            for i, _ in enumerate(Idf):
     114                #print i,Idg[i],Idf[i]
     115                stage_cv[Idg[i]] = stage_cv[Idf[i]]
     116
     117
     118#        if self.ghosts is not None:
     119#            stage_cv = self.quantities['stage'].centroid_values
     120#            for triangle in self.ghosts:
     121#                stage_cv[triangle] = stage_cv[self.ghosts[triangle]]
    103122
    104123
     
    137156
    138157
    139 def Parallel_rectangular(m, n, len1=1.0, len2=1.0, origin = (0.0, 0.0)):
     158def parallel_rectangular(m, n, len1=1.0, len2=1.0, origin = (0.0, 0.0)):
    140159
    141160
     
    149168    len2: y direction (bottom to top)
    150169
     170    """
     171
     172    from config import epsilon
     173    from Numeric import zeros, Float, Int
     174
     175    processor = pypar.rank()
     176    numproc   = pypar.size()
     177
     178
     179
     180    delta1 = float(len1)/m
     181    delta2 = float(len2)/n
     182
     183    #Calculate number of points
     184    Np = (m+1)*(n+1)
     185
     186    class VIndex:
     187
     188        def __init__(self, n,m):
     189            self.n = n
     190            self.m = m
     191
     192        def __call__(self, i,j):
     193            return j+i*(self.n+1)
     194
     195    class EIndex:
     196
     197        def __init__(self, n,m):
     198            self.n = n
     199            self.m = m
     200
     201        def __call__(self, i,j):
     202            return 2*(j+i*self.n)
     203
     204
     205    I = VIndex(n,m)
     206    E = EIndex(n,m)
     207
     208    points = zeros( (Np,2), Float)
     209
     210    for i in range(m+1):
     211        for j in range(n+1):
     212
     213            points[I(i,j),:] = [i*delta1 + origin[0], j*delta2 + origin[1]]
     214
     215    #Construct 2 triangles per rectangular element and assign tags to boundary
     216    #Calculate number of triangles
     217    Nt = 2*m*n
     218
     219
     220    elements = zeros( (Nt,3), Int)
     221    boundary = {}
     222    Idg = []
     223    Xg  = []
     224    Idf = []
     225    Xf  = []
     226
     227    full_send_dict = {}
     228    ghost_recv_dict = {}
     229    nt = -1
     230    for i in range(m):
     231        for j in range(n):
     232
     233            i1 = I(i,j+1)
     234            i2 = I(i,j)
     235            i3 = I(i+1,j+1)
     236            i4 = I(i+1,j)
     237
     238            #Lower Element
     239            nt = E(i,j)
     240            if i == m-1:
     241                #print 'nt =',nt
     242                Idg.append(nt)
     243                Idf.append(E(1,j))
     244            if i == 0:
     245                Idg.append(nt)
     246                Idf.append(E(m-2,j))
     247
     248            if i == m-1:
     249                boundary[nt, 2] = 'right'
     250            if j == 0:
     251                boundary[nt, 1] = 'bottom'
     252            elements[nt,:] = [i4,i3,i2]
     253
     254            #Upper Element
     255            nt = E(i,j)+1
     256            if i == m-1:
     257                Idg.append(nt)
     258                Idf.append(E(1,j)+1)
     259            if i == 0:
     260                Idg.append(nt)
     261                Idf.append(E(m-2,j)+1)
     262
     263            if i == 0:
     264                boundary[nt, 2] = 'left'
     265            if j == n-1:
     266                boundary[nt, 1] = 'top'
     267            elements[nt,:] = [i1,i2,i3]
     268
     269    Idf = array(Idf,Int)
     270    Idg = array(Idg,Int)
     271    Xf  = zeros(Idf.shape,Float)
     272    Xg  = zeros(Idg.shape,Float)
     273
     274    #print Idf
     275    #print Idg
     276    full_send_dict[processor]  = [Idf, Xf]
     277    ghost_recv_dict[processor] = [Idg, Xg]
     278
     279    return  points, elements, boundary, full_send_dict, ghost_recv_dict
     280
     281
     282
     283def rectangular_periodic(m, n, len1=1.0, len2=1.0, origin = (0.0, 0.0)):
     284
     285
     286    """Setup a rectangular grid of triangles
     287    with m+1 by n+1 grid points
     288    and side lengths len1, len2. If side lengths are omitted
     289    the mesh defaults to the unit square.
     290
     291    len1: x direction (left to right)
     292    len2: y direction (bottom to top)
     293
     294    Return to lists: points and elements suitable for creating a Mesh or
     295    FVMesh object, e.g. Mesh(points, elements)
    151296    """
    152297
     
    213358                ghosts[nt] = E(m-2,j)
    214359
     360            if j == n-1:
     361                ghosts[nt] = E(i,1)
     362
     363            if j == 0:
     364                ghosts[nt] = E(i,n-2)
     365
    215366            if i == m-1:
    216367                boundary[nt, 2] = 'right'
     
    226377                ghosts[nt] = E(m-2,j)+1
    227378
     379            if j == n-1:
     380                ghosts[nt] = E(i,1)+1
     381
     382            if j == 0:
     383                ghosts[nt] = E(i,n-2)+1
     384
    228385            if i == 0:
    229386                boundary[nt, 2] = 'left'
     
    232389            elements[nt,:] = [i1,i2,i3]
    233390
     391    #bottom left
     392    nt = E(0,0)
     393    nf = E(m-2,n-2)
     394    ghosts[nt]   = nf
     395    ghosts[nt+1] = nf+1
     396
     397    #bottom right
     398    nt = E(m-1,0)
     399    nf = E(1,n-2)
     400    ghosts[nt]   = nf
     401    ghosts[nt+1] = nf+1
     402
     403    #top left
     404    nt = E(0,n-1)
     405    nf = E(m-2,1)
     406    ghosts[nt]   = nf
     407    ghosts[nt+1] = nf+1
     408
     409    #top right
     410    nt = E(m-1,n-1)
     411    nf = E(1,1)
     412    ghosts[nt]   = nf
     413    ghosts[nt+1] = nf+1
    234414
    235415    return points, elements, boundary, ghosts
    236416
    237 def rectangular_periodic(m, n, len1=1.0, len2=1.0, origin = (0.0, 0.0)):
     417def rectangular_periodic_lr(m, n, len1=1.0, len2=1.0, origin = (0.0, 0.0)):
    238418
    239419
     
    247427
    248428    Return to lists: points and elements suitable for creating a Mesh or
    249     FVMesh object, e.g. Mesh(points, elements)
     429    Domain object, e.g. Mesh(points, elements)
    250430    """
    251431
     
    312492                ghosts[nt] = E(m-2,j)
    313493
    314             if j == n-1:
    315                 ghosts[nt] = E(i,1)
    316 
    317             if j == 0:
    318                 ghosts[nt] = E(i,n-2)
    319 
    320494            if i == m-1:
    321495                boundary[nt, 2] = 'right'
     
    331505                ghosts[nt] = E(m-2,j)+1
    332506
    333             if j == n-1:
    334                 ghosts[nt] = E(i,1)+1
    335 
    336             if j == 0:
    337                 ghosts[nt] = E(i,n-2)+1
    338 
    339507            if i == 0:
    340508                boundary[nt, 2] = 'left'
     
    343511            elements[nt,:] = [i1,i2,i3]
    344512
    345     #bottom left
    346     nt = E(0,0)
    347     nf = E(m-2,n-2)
    348     ghosts[nt]   = nf
    349     ghosts[nt+1] = nf+1
    350 
    351     #bottom right
    352     nt = E(m-1,0)
    353     nf = E(1,n-2)
    354     ghosts[nt]   = nf
    355     ghosts[nt+1] = nf+1
    356 
    357     #top left
    358     nt = E(0,n-1)
    359     nf = E(m-2,1)
    360     ghosts[nt]   = nf
    361     ghosts[nt+1] = nf+1
    362 
    363     #top right
    364     nt = E(m-1,n-1)
    365     nf = E(1,1)
    366     ghosts[nt]   = nf
    367     ghosts[nt+1] = nf+1
    368513
    369514    return points, elements, boundary, ghosts
    370 
    371 def rectangular_periodic_lr(m, n, len1=1.0, len2=1.0, origin = (0.0, 0.0)):
    372 
    373 
    374     """Setup a rectangular grid of triangles
    375     with m+1 by n+1 grid points
    376     and side lengths len1, len2. If side lengths are omitted
    377     the mesh defaults to the unit square.
    378 
    379     len1: x direction (left to right)
    380     len2: y direction (bottom to top)
    381 
    382     Return to lists: points and elements suitable for creating a Mesh or
    383     Domain object, e.g. Mesh(points, elements)
    384     """
    385 
    386     from config import epsilon
    387     from Numeric import zeros, Float, Int
    388 
    389     delta1 = float(len1)/m
    390     delta2 = float(len2)/n
    391 
    392     #Calculate number of points
    393     Np = (m+1)*(n+1)
    394 
    395     class VIndex:
    396 
    397         def __init__(self, n,m):
    398             self.n = n
    399             self.m = m
    400 
    401         def __call__(self, i,j):
    402             return j+i*(self.n+1)
    403 
    404     class EIndex:
    405 
    406         def __init__(self, n,m):
    407             self.n = n
    408             self.m = m
    409 
    410         def __call__(self, i,j):
    411             return 2*(j+i*self.n)
    412 
    413 
    414     I = VIndex(n,m)
    415     E = EIndex(n,m)
    416 
    417     points = zeros( (Np,2), Float)
    418 
    419     for i in range(m+1):
    420         for j in range(n+1):
    421 
    422             points[I(i,j),:] = [i*delta1 + origin[0], j*delta2 + origin[1]]
    423 
    424     #Construct 2 triangles per rectangular element and assign tags to boundary
    425     #Calculate number of triangles
    426     Nt = 2*m*n
    427 
    428 
    429     elements = zeros( (Nt,3), Int)
    430     boundary = {}
    431     ghosts = {}
    432     nt = -1
    433     for i in range(m):
    434         for j in range(n):
    435 
    436             i1 = I(i,j+1)
    437             i2 = I(i,j)
    438             i3 = I(i+1,j+1)
    439             i4 = I(i+1,j)
    440 
    441             #Lower Element
    442             nt = E(i,j)
    443             if i == m-1:
    444                 ghosts[nt] = E(1,j)
    445             if i == 0:
    446                 ghosts[nt] = E(m-2,j)
    447 
    448             if i == m-1:
    449                 boundary[nt, 2] = 'right'
    450             if j == 0:
    451                 boundary[nt, 1] = 'bottom'
    452             elements[nt,:] = [i4,i3,i2]
    453 
    454             #Upper Element
    455             nt = E(i,j)+1
    456             if i == m-1:
    457                 ghosts[nt] = E(1,j)+1
    458             if i == 0:
    459                 ghosts[nt] = E(m-2,j)+1
    460 
    461             if i == 0:
    462                 boundary[nt, 2] = 'left'
    463             if j == n-1:
    464                 boundary[nt, 1] = 'top'
    465             elements[nt,:] = [i1,i2,i3]
    466 
    467 
    468     return points, elements, boundary, ghosts
  • inundation/ga/storm_surge/parallel/run_parallel_advection.py

    r1414 r1424  
    2020M = 30
    2121
    22 points, vertices, boundary, ghosts = rectangular_periodic(N, M)
     22points, vertices, boundary, full_send_dict, ghost_recv_dict = parallel_rectangular(N, M)
    2323
    2424#Create advection domain with direction (1,-1)
    25 domain = Parallel_Domain(points, vertices, boundary, ghosts, velocity=[1.0, 0.0])
     25domain = Parallel_Domain(points, vertices, boundary,
     26                         full_send_dict, ghost_recv_dict, velocity=[1.0, 0.0])
    2627
    2728# Initial condition is zero by default
Note: See TracChangeset for help on using the changeset viewer.