Changeset 1402


Ignore:
Timestamp:
May 16, 2005, 5:25:56 PM (20 years ago)
Author:
steve
Message:

Periodic boundary working via ghosts

Location:
inundation/ga/storm_surge
Files:
4 edited

Legend:

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

    r1393 r1402  
    1616from advection import *
    1717Advection_Domain = Domain
    18 from Numeric import zeros, Float, Int
     18from Numeric import zeros, Float, Int, ones
    1919
    2020class Parallel_Domain(Advection_Domain):
    2121
    22     def __init__(self, coordinates, vertices, boundary = None, velocity = None,
    23                  processor = 0, global_ids = None):
     22    def __init__(self, coordinates, vertices, boundary = None, ghosts = None, velocity = None):
    2423
    2524        Advection_Domain.__init__(self, coordinates, vertices, boundary, velocity)
    2625
    27         self.processor = processor
    28 
    2926        N = self.number_of_elements
    3027
    31         if  global_ids == None:
    32             self.global_ids = global_ids
     28        if  ghosts == None:
     29            self.ghosts = None
     30            self.full = ones( N, Float)
    3331        else:
    34             self.global_ids = zeros(N, Int)
    35 
     32            self.ghosts = ghosts
     33            self.full = ones( N, Int)
     34            keys = self.ghosts.keys()
     35            for key in keys:
     36                self.full[key] = -1
    3637
    3738    def check_integrity(self):
     
    4243
    4344
    44 
     45    def update_ghosts(self):
     46        if self.ghosts is not None:
     47            stage_cv = self.quantities['stage'].centroid_values
     48            for triangle in self.ghosts:
     49                stage_cv[triangle] = stage_cv[self.ghosts[triangle]]
    4550
    4651    def evolve(self, yieldstep = None, finaltime = None):
     
    6469
    6570
    66 def rectangular_with_ghosts(m, n, len1=1.0, len2=1.0, origin = (0.0, 0.0)):
     71def rectangular_periodic(m, n, len1=1.0, len2=1.0, origin = (0.0, 0.0)):
    6772
    6873
     
    141146                ghosts[nt] = E(m-2,j)
    142147
     148            if j == n-1:
     149                ghosts[nt] = E(i,1)
     150
     151            if j == 0:
     152                ghosts[nt] = E(i,n-2)
     153
    143154            if i == m-1:
    144155                boundary[nt, 2] = 'right'
     
    154165                ghosts[nt] = E(m-2,j)+1
    155166
     167            if j == n-1:
     168                ghosts[nt] = E(i,1)+1
     169
     170            if j == 0:
     171                ghosts[nt] = E(i,n-2)+1
     172
    156173            if i == 0:
    157174                boundary[nt, 2] = 'left'
     
    160177            elements[nt,:] = [i1,i2,i3]
    161178
     179    #bottom left
     180    nt = E(0,0)
     181    nf = E(m-2,n-2)
     182    ghosts[nt]   = nf
     183    ghosts[nt+1] = nf+1
     184
     185    #bottom right
     186    nt = E(m-1,0)
     187    nf = E(1,n-2)
     188    ghosts[nt]   = nf
     189    ghosts[nt+1] = nf+1
     190
     191    #top left
     192    nt = E(0,n-1)
     193    nf = E(m-2,1)
     194    ghosts[nt]   = nf
     195    ghosts[nt+1] = nf+1
     196
     197    #top right
     198    nt = E(m-1,n-1)
     199    nf = E(1,1)
     200    ghosts[nt]   = nf
     201    ghosts[nt+1] = nf+1
     202
    162203    return points, elements, boundary, ghosts
    163204
     205def rectangular_periodic_lr(m, n, len1=1.0, len2=1.0, origin = (0.0, 0.0)):
     206
     207
     208    """Setup a rectangular grid of triangles
     209    with m+1 by n+1 grid points
     210    and side lengths len1, len2. If side lengths are omitted
     211    the mesh defaults to the unit square.
     212
     213    len1: x direction (left to right)
     214    len2: y direction (bottom to top)
     215
     216    Return to lists: points and elements suitable for creating a Mesh or
     217    FVMesh object, e.g. Mesh(points, elements)
     218    """
     219
     220    from config import epsilon
     221    from Numeric import zeros, Float, Int
     222
     223    delta1 = float(len1)/m
     224    delta2 = float(len2)/n
     225
     226    #Calculate number of points
     227    Np = (m+1)*(n+1)
     228
     229    class VIndex:
     230
     231        def __init__(self, n,m):
     232            self.n = n
     233            self.m = m
     234
     235        def __call__(self, i,j):
     236            return j+i*(self.n+1)
     237
     238    class EIndex:
     239
     240        def __init__(self, n,m):
     241            self.n = n
     242            self.m = m
     243
     244        def __call__(self, i,j):
     245            return 2*(j+i*self.n)
     246
     247
     248    I = VIndex(n,m)
     249    E = EIndex(n,m)
     250
     251    points = zeros( (Np,2), Float)
     252
     253    for i in range(m+1):
     254        for j in range(n+1):
     255
     256            points[I(i,j),:] = [i*delta1 + origin[0], j*delta2 + origin[1]]
     257
     258    #Construct 2 triangles per rectangular element and assign tags to boundary
     259    #Calculate number of triangles
     260    Nt = 2*m*n
     261
     262
     263    elements = zeros( (Nt,3), Int)
     264    boundary = {}
     265    ghosts = {}
     266    nt = -1
     267    for i in range(m):
     268        for j in range(n):
     269
     270            i1 = I(i,j+1)
     271            i2 = I(i,j)
     272            i3 = I(i+1,j+1)
     273            i4 = I(i+1,j)
     274
     275            #Lower Element
     276            nt = E(i,j)
     277            if i == m-1:
     278                ghosts[nt] = E(1,j)
     279            if i == 0:
     280                ghosts[nt] = E(m-2,j)
     281
     282            if i == m-1:
     283                boundary[nt, 2] = 'right'
     284            if j == 0:
     285                boundary[nt, 1] = 'bottom'
     286            elements[nt,:] = [i4,i3,i2]
     287
     288            #Upper Element
     289            nt = E(i,j)+1
     290            if i == m-1:
     291                ghosts[nt] = E(1,j)+1
     292            if i == 0:
     293                ghosts[nt] = E(m-2,j)+1
     294
     295            if i == 0:
     296                boundary[nt, 2] = 'left'
     297            if j == n-1:
     298                boundary[nt, 1] = 'top'
     299            elements[nt,:] = [i1,i2,i3]
     300
     301
     302    return points, elements, boundary, ghosts
  • inundation/ga/storm_surge/parallel/run_parallel_advection.py

    r1393 r1402  
    99from Numeric import array
    1010
    11 from mesh_factory import rectangular
     11N = 40
     12M = 40
    1213
    13 N = 4
    14 M = 4
    15 
    16 points, vertices, boundary, ghosts = rectangular_with_ghosts(N, M)
    17 
    18 
    19 print ghosts
     14points, vertices, boundary, ghosts = rectangular_periodic_lr(N, M)
    2015
    2116#Create advection domain with direction (1,-1)
    22 domain = Parallel_Domain(points, vertices, boundary, velocity=[1.0, 0.0])
     17domain = Parallel_Domain(points, vertices, boundary, ghosts, velocity=[1.0, 0.0])
    2318
    2419# Initial condition is zero by default
     
    5348
    5449#Check that the boundary value gets propagated to all elements
    55 for t in domain.evolve(yieldstep = 0.01, finaltime = 0.01):
     50for t in domain.evolve(yieldstep = 0.01, finaltime = 1.0):
    5651    domain.write_time()
  • inundation/ga/storm_surge/pyvolution/domain.py

    r1387 r1402  
    431431        self.distribute_to_vertices_and_edges()
    432432
     433        #Initial update boundary values
     434        self.update_boundary()
    433435
    434436        #Or maybe restore from latest checkpoint
     
    436438            self.goto_latest_checkpoint()
    437439
    438 
    439440        yield(self.time)  #Yield initial values
    440441
    441442        while True:
     443
     444            #Compute fluxes across each element edge
     445            self.compute_fluxes()
     446
     447            #Update timestep to fit yieldstep and finaltime
     448            self.update_timestep(yieldstep, finaltime)
     449
     450            #Update conserved quantities
     451            self.update_conserved_quantities()
     452
     453            #update ghosts
     454            self.update_ghosts()
     455
     456            #Update vertex and edge values
     457            self.distribute_to_vertices_and_edges()
     458
    442459            #Update boundary values
    443460            self.update_boundary()
    444 
    445             #Compute fluxes across each element edge
    446             self.compute_fluxes()
    447 
    448             #Update timestep to fit yieldstep and finaltime
    449             self.update_timestep(yieldstep, finaltime)
    450 
    451             #Update conserved quantities
    452             self.update_conserved_quantities()
    453 
    454             #Update vertex and edge values
    455             self.distribute_to_vertices_and_edges()
    456461
    457462            #Update time
     
    604609            Q.semi_implicit_update[:] = 0.0
    605610
     611    def update_ghosts(self):
     612        pass
    606613
    607614
Note: See TracChangeset for help on using the changeset viewer.