Changeset 1393


Ignore:
Timestamp:
May 15, 2005, 10:25:56 PM (19 years ago)
Author:
steve
Message:

Added ghosts to rectangle

Location:
inundation/ga/storm_surge
Files:
1 added
10 edited

Legend:

Unmodified
Added
Removed
  • inundation/ga/storm_surge/Merimbula/run_merimbula_lake.py

    r1363 r1393  
    7979domain.store = True     #Store for visualisation purposes
    8080domain.format = 'sww'   #Native netcdf visualisation format
    81 domain.filename = 'Merimbula_2003_4days_dry'
     81from normalDate import ND
     82domain.filename = 'Merimbula_2003_4days_dry_%s'%ND()
     83
     84print domain.filename
    8285
    8386#----------------------
  • inundation/ga/storm_surge/parallel/parallel_advection.py

    r1387 r1393  
    6666def rectangular_with_ghosts(m, n, len1=1.0, len2=1.0, origin = (0.0, 0.0)):
    6767
     68
    6869    """Setup a rectangular grid of triangles
    6970    with m+1 by n+1 grid points
     
    7475    len2: y direction (bottom to top)
    7576
    76     Also returns a list of
    77 
    7877    Return to lists: points and elements suitable for creating a Mesh or
    7978    FVMesh object, e.g. Mesh(points, elements)
     
    8180
    8281    from config import epsilon
    83 
    84     #E = m*n*2        #Number of triangular elements
    85     #P = (m+1)*(n+1)  #Number of initial vertices
     82    from Numeric import zeros, Float, Int
    8683
    8784    delta1 = float(len1)/m
    8885    delta2 = float(len2)/n
    8986
    90     #Dictionary of vertex objects
    91     vertices = {}
    92     points = []
     87    #Calculate number of points
     88    Np = (m+1)*(n+1)
     89
     90    class VIndex:
     91
     92        def __init__(self, n,m):
     93            self.n = n
     94            self.m = m
     95
     96        def __call__(self, i,j):
     97            return j+i*(self.n+1)
     98
     99    class EIndex:
     100
     101        def __init__(self, n,m):
     102            self.n = n
     103            self.m = m
     104
     105        def __call__(self, i,j):
     106            return 2*(j+i*self.n)
     107
     108
     109    I = VIndex(n,m)
     110    E = EIndex(n,m)
     111
     112    points = zeros( (Np,2), Float)
    93113
    94114    for i in range(m+1):
    95115        for j in range(n+1):
    96             vertices[i,j] = len(points)
    97             points.append([i*delta1 + origin[0], j*delta2 + origin[1]])
     116
     117            points[I(i,j),:] = [i*delta1 + origin[0], j*delta2 + origin[1]]
     118
     119    #Construct 2 triangles per rectangular element and assign tags to boundary
     120    #Calculate number of triangles
     121    Nt = 2*m*n
    98122
    99123
    100 
    101     #Construct 2 triangles per rectangular element and assign tags to boundary
    102     elements = []
     124    elements = zeros( (Nt,3), Int)
    103125    boundary = {}
     126    ghosts = {}
     127    nt = -1
    104128    for i in range(m):
    105129        for j in range(n):
    106             v1 = vertices[i,j+1]
    107             v2 = vertices[i,j]
    108             v3 = vertices[i+1,j+1]
    109             v4 = vertices[i+1,j]
    110130
    111             #Update boundary dictionary and create elements
     131            i1 = I(i,j+1)
     132            i2 = I(i,j)
     133            i3 = I(i+1,j+1)
     134            i4 = I(i+1,j)
     135
     136            #Lower Element
     137            nt = E(i,j)
    112138            if i == m-1:
    113                 boundary[(len(elements), 2)] = 'right'
     139                ghosts[nt] = E(1,j)
     140            if i == 0:
     141                ghosts[nt] = E(m-2,j)
     142
     143            if i == m-1:
     144                boundary[nt, 2] = 'right'
    114145            if j == 0:
    115                 boundary[(len(elements), 1)] = 'bottom'
    116             elements.append([v4,v3,v2]) #Lower element
     146                boundary[nt, 1] = 'bottom'
     147            elements[nt,:] = [i4,i3,i2]
     148
     149            #Upper Element
     150            nt = E(i,j)+1
     151            if i == m-1:
     152                ghosts[nt] = E(1,j)+1
     153            if i == 0:
     154                ghosts[nt] = E(m-2,j)+1
    117155
    118156            if i == 0:
    119                 boundary[(len(elements), 2)] = 'left'
     157                boundary[nt, 2] = 'left'
    120158            if j == n-1:
    121                 boundary[(len(elements), 1)] = 'top'
    122             elements.append([v1,v2,v3]) #Upper element
     159                boundary[nt, 1] = 'top'
     160            elements[nt,:] = [i1,i2,i3]
    123161
    124     ghosts = {}
    125     i=0
    126     for j in range(n):
    127         v1 = vertices[i,j+1]
    128         v2 = vertices[i,j]
    129         v3 = vertices[i+1,j+1]
    130         v4 = vertices[i+1,j]
    131         ghosts.append(elements.index([
     162    return points, elements, boundary, ghosts
    132163
    133     return points, elements, boundary
  • inundation/ga/storm_surge/parallel/run_parallel_advection.py

    r1387 r1393  
    1111from mesh_factory import rectangular
    1212
    13 points, vertices, boundary = rectangular(30, 30)
     13N = 4
     14M = 4
     15
     16points, vertices, boundary, ghosts = rectangular_with_ghosts(N, M)
     17
     18
     19print ghosts
    1420
    1521#Create advection domain with direction (1,-1)
     
    4753
    4854#Check that the boundary value gets propagated to all elements
    49 for t in domain.evolve(yieldstep = 0.01, finaltime = 1.5):
     55for t in domain.evolve(yieldstep = 0.01, finaltime = 0.01):
    5056    domain.write_time()
  • inundation/ga/storm_surge/pyvolution/data_manager.py

    r1363 r1393  
    342342        from Scientific.IO.NetCDF import NetCDFFile
    343343        import types
    344         from time import sleep
     344        from time import sleep
    345345        from os import stat
    346346
    347347
    348348        #Get NetCDF
    349         retries = 0
    350         file_open = False
    351         while not file_open and retries < 10:
    352             try:
     349        retries = 0
     350        file_open = False
     351        while not file_open and retries < 10:
     352            try:
    353353                fid = NetCDFFile(self.filename, 'a') #Open existing file
    354             except IOError:
    355                 #This could happen if someone was reading the file.
    356                 #In that case, wait a while and try again
    357                 msg = 'Warning (store_timestep): File %s could not be opened'\
    358                 %self.filename
    359                 msg += ' - trying again'
    360                 print msg
    361                 retries += 1
    362                 sleep(1)
    363             else:
    364                file_open = True
    365 
    366         if not file_open:
    367             msg = 'File %s could not be opened for append' %self.filename
    368             raise msg
     354            except IOError:
     355                #This could happen if someone was reading the file.
     356                #In that case, wait a while and try again
     357                msg = 'Warning (store_timestep): File %s could not be opened'\
     358                      %self.filename
     359                msg += ' - trying again'
     360                print msg
     361                retries += 1
     362                sleep(1)
     363            else:
     364                file_open = True
     365
     366        if not file_open:
     367            msg = 'File %s could not be opened for append' %self.filename
     368            raise msg
    369369
    370370
     
    19951995        q = (1-ratio)*Q[index]+ ratio*Q[index+1]
    19961996    else:
    1997          q = Q[index]
     1997        q = Q[index]
    19981998    #Return vector of interpolated values
    19991999    return q
  • inundation/ga/storm_surge/pyvolution/netherlands.py

    r1392 r1393  
    6565
    6666            #Wall
    67             #if x[i] > 0.995:
    68             #    z[i] = -x[i]/20+0.3
     67            if x[i] > 0.995:
     68                z[i] = -x[i]/20+0.3
    6969
    7070        return z/2
     
    103103
    104104#Set bed-slope and friction
    105 inflow_stage = 0.2
    106 manning = 0.00
     105inflow_stage = 0.1
     106manning = 0.03
    107107Z = Weir(inflow_stage)
    108108
     
    156156t0 = time.time()
    157157
    158 for t in domain.evolve(yieldstep = 1.0, finaltime = 100.0):
     158from visual import *
     159
     160for t in domain.evolve(yieldstep = 0.1, finaltime = 15.0):
    159161    domain.write_time()
    160162    #domain.visualiser.scale_z = 1.0
    161     domain.visualiser.update_quantity_color('xmomentum',scale_z = 4.0)
     163    #domain.visualiser.update_quantity_color('xmomentum',scale_z = 4.0)
     164    #integral_label.text='Integral=%10.5e'%domain.quantities['stage'].get_integral()
    162165
    163166
  • inundation/ga/storm_surge/pyvolution/quantity.py

    r1290 r1393  
    536536
    537537            # Create a V like [[0 1 2], [3 4 5]....[3*m-2 3*m-1 3*m]]
    538             # These vert_id's will relate to the verts created bellow
     538            # These vert_id's will relate to the verts created below
    539539            m = len(self.domain)  #Number of volumes
    540540            M = 3*m        #Total number of unique vertices
  • inundation/ga/storm_surge/pyvolution/test_quantity.py

    r1018 r1393  
    201201        quantity = Quantity(self.mesh4)
    202202
    203         #Try constants first
    204         const = 5
     203        #Try constants first
     204        const = 5
    205205        quantity.set_values(const, location = 'vertices')
    206         #print 'Q', quantity.get_integral()
    207 
    208         assert allclose(quantity.get_integral(),
    209                         self.mesh4.get_area() * const)
    210 
    211         #Try with a linear function
     206        #print 'Q', quantity.get_integral()
     207
     208        assert allclose(quantity.get_integral(), self.mesh4.get_area() * const)
     209
     210        #Try with a linear function
    212211        def f(x, y):
    213212            return x+y
     
    216215
    217216
    218         ref_integral = (4.0/3 + 8.0/3 + 10.0/3 + 10.0/3) * 2
    219 
    220         assert allclose (quantity.get_integral(), ref_integral)
     217        ref_integral = (4.0/3 + 8.0/3 + 10.0/3 + 10.0/3) * 2
     218
     219        assert allclose (quantity.get_integral(), ref_integral)
    221220
    222221
     
    929928    runner = unittest.TextTestRunner()
    930929    runner.run(suite)
    931 
  • inundation/ga/storm_surge/zeus/anuga-workspace.zwi

    r1387 r1393  
    22<workspace name="anuga-workspace">
    33    <mode>Debug</mode>
    4     <active>steve</active>
     4    <active>pyvolution</active>
    55    <project name="Merimbula">Merimbula.zpi</project>
    66    <project name="parallel">parallel.zpi</project>
  • inundation/ga/storm_surge/zeus/pyvolution.zpi

    r1271 r1393  
    9999    <file>..\pyvolution\netherlands.py</file>
    100100    <file>..\pyvolution\netherlands-chris.py</file>
     101    <file>..\pyvolution\normalDate.py</file>
    101102    <file>..\pyvolution\pmesh2domain.py</file>
    102103    <file>..\pyvolution\pressure_force.py</file>
Note: See TracChangeset for help on using the changeset viewer.