Changeset 1761


Ignore:
Timestamp:
Aug 25, 2005, 10:06:22 AM (19 years ago)
Author:
steve
Message:

Added a more symmetric rectangle_cross procedure. Can be used in place of rectangle from mesh_factory

Location:
inundation
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • inundation/pyvolution/mesh_factory.py

    r1638 r1761  
    2020    from config import epsilon
    2121
    22     #E = m*n*2        #Number of triangular elements
    23     #P = (m+1)*(n+1)  #Number of initial vertices
    24 
    25     delta1 = float(len1)/m
    26     delta2 = float(len2)/n
     22    deltax = float(len1)/m
     23    deltay = float(len2)/n
    2724
    2825    #Dictionary of vertex objects
     
    3431            vertices[i,j] = len(points)
    3532            points.append([i*delta1 + origin[0], j*delta2 + origin[1]])
    36 
    3733
    3834
     
    120116            i4 = index(i+1,j)
    121117
     118            x = (points[v1][0]+points[v2][0]+points[v3][0]+points[v4][0])*0.25
     119            y = (points[v1][1]+points[v2][1]+points[v3][1]+points[v4][1])*0.25
     120            v5 = len(points)
     121            points.append([x, y])
     122
     123            #Create left triangle
     124            if i == 0:
     125                boundary[(len(elements), 1)] = 'left'
     126            elements.append([v2,v5,v1])
     127
     128            #Create bottom triangle
     129            if j == 0:
     130                boundary[(len(elements), 1)] = 'bottom'
     131            elements.append([v4,v5,v2])
     132
     133            #Create right triangle
     134            if i == m-1:
     135                boundary[(len(elements), 1)] = 'right'
     136            elements.append([v3,v5,v4])
     137
     138            #Create top triangle
     139            if j == n-1:
     140                boundary[(len(elements), 1)] = 'top'
     141            elements.append([v1,v5,v3])
     142
    122143            #Update boundary dictionary and create elements
    123144            if i == m-1:
     
    133154                boundary[nt, 1] = 'top'
    134155            elements[nt,:] = [i1,i2,i3] #Upper element
     156
     157    return points, elements, boundary
     158
     159
     160def rectangular_cross(m, n, len1=1.0, len2=1.0, origin = (0.0, 0.0)):
     161
     162    """Setup a rectangular grid of triangles
     163    with m+1 by n+1 grid points
     164    and side lengths len1, len2. If side lengths are omitted
     165    the mesh defaults to the unit square.
     166
     167    len1: x direction (left to right)
     168    len2: y direction (bottom to top)
     169
     170    Return to lists: points and elements suitable for creating a Mesh or
     171    FVMesh object, e.g. Mesh(points, elements)
     172    """
     173
     174    from config import epsilon
     175    from Numeric import zeros, Float, Int
     176
     177    delta1 = float(len1)/m
     178    delta2 = float(len2)/n
     179
     180    #Dictionary of vertex objects
     181    vertices = {}
     182    points = []
     183
     184    for i in range(m+1):
     185        for j in range(n+1):
     186            vertices[i,j] = len(points)
     187            points.append([delta1*i + origin[0], delta2*j  + origin[1]])
     188
     189    # Construct 4 triangles per element
     190    elements = []
     191    boundary = {}
     192    for i in range(m):
     193        for j in range(n):
     194            v1 = vertices[i,j+1]
     195            v2 = vertices[i,j]
     196            v3 = vertices[i+1,j+1]
     197            v4 = vertices[i+1,j]
     198            x = (points[v1][0]+points[v2][0]+points[v3][0]+points[v4][0])*0.25
     199            y = (points[v1][1]+points[v2][1]+points[v3][1]+points[v4][1])*0.25
     200
     201            # Create centre point
     202            v5 = len(points)
     203            points.append([x, y])
     204
     205            #Create left triangle
     206            if i == 0:
     207                boundary[(len(elements), 1)] = 'left'
     208            elements.append([v2,v5,v1])
     209
     210            #Create bottom triangle
     211            if j == 0:
     212                boundary[(len(elements), 1)] = 'bottom'
     213            elements.append([v4,v5,v2])
     214
     215            #Create right triangle
     216            if i == m-1:
     217                boundary[(len(elements), 1)] = 'right'
     218            elements.append([v3,v5,v4])
     219
     220            #Create top triangle
     221            if j == n-1:
     222                boundary[(len(elements), 1)] = 'top'
     223            elements.append([v1,v5,v3])
     224
    135225
    136226    return points, elements, boundary
  • inundation/validation/LWRU2/lwru2.py

    r1753 r1761  
    7474from pyvolution.shallow_water import Domain, Reflective_boundary,\
    7575            File_boundary, Transmissive_Momentum_Set_Stage_boundary
    76 from pyvolution.mesh_factory import rectangular
     76from pyvolution.mesh_factory import rectangular_cross
    7777from pyvolution.pmesh2domain import pmesh_to_domain_instance
    7878from Numeric import array, zeros, Float, allclose
     
    9191#######################
    9292# Domain
    93    
     93
    9494if read_mesh is True:
    9595    print 'Creating domain from', filenames.mesh_filename
     
    101101
    102102
    103    
    104 else:   
     103
     104else:
    105105    print 'Creating regular mesh'
    106106    N = 100
    107     points, vertices, boundary = rectangular(N, N/5*3,
     107    points, vertices, boundary = rectangular_cross(N, N/5*3,
    108108                                             len1=5.448, len2=3.402)
    109109    print 'Creating domain'
    110    
     110
    111111    #domain = Domain(points, vertices, boundary)
    112112    domain = cache(Domain, (points, vertices, boundary))
     
    135135                    verbose = True,
    136136                    use_cache = True)
    137                    
     137
    138138domain.set_quantity('friction', 0.0)
    139139domain.set_quantity('stage', 0.0)
     
    157157#Set boundary conditions
    158158if read_mesh is True:
    159     domain.set_boundary({'wave': Bts, 'wall': Br})     
    160 else:   
     159    domain.set_boundary({'wave': Bts, 'wall': Br})
     160else:
    161161    domain.set_boundary({'left': Bts, 'right': Br, 'bottom': Br, 'top': Br})
    162162
Note: See TracChangeset for help on using the changeset viewer.