Ignore:
Timestamp:
Sep 8, 2010, 5:12:10 PM (14 years ago)
Author:
steve
Message:

Slight conflict with init.py due to addition of hole_tags

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/anuga_core/source/anuga/abstract_2d_finite_volumes/mesh_factory.py

    r7317 r8009  
    202202
    203203    return points, elements, boundary
     204
     205
     206
     207def rectangular_cross_slit(m, n, len1=1.0, len2=1.0, origin = (0.0, 0.0)):
     208
     209    """Setup a rectangular grid of triangles
     210    with m+1 by n+1 grid points
     211    and side lengths len1, len2. If side lengths are omitted
     212    the mesh defaults to the unit square.
     213
     214    len1: x direction (left to right)
     215    len2: y direction (bottom to top)
     216
     217    Return to lists: points and elements suitable for creating a Mesh or
     218    FVMesh object, e.g. Mesh(points, elements)
     219    """
     220
     221    from anuga.config import epsilon
     222
     223    delta1 = float(len1)/m
     224    delta2 = float(len2)/n
     225
     226    #Dictionary of vertex objects
     227    vertices = {}
     228    points = []
     229
     230    for i in range(m+1):
     231        for j in range(n+1):
     232            vertices[i,j] = len(points)
     233            points.append([delta1*i + origin[0], delta2*j  + origin[1]])
     234
     235    # Construct 4 triangles per element
     236    elements = []
     237    boundary = {}
     238    for i in range(m):
     239        for j in range(n):
     240            v1 = vertices[i,j+1]
     241            v2 = vertices[i,j]
     242            v3 = vertices[i+1,j+1]
     243            v4 = vertices[i+1,j]
     244            x = (points[v1][0]+points[v2][0]+points[v3][0]+points[v4][0])*0.25
     245            y = (points[v1][1]+points[v2][1]+points[v3][1]+points[v4][1])*0.25
     246
     247            # Create centre point
     248            v5 = len(points)
     249            points.append([x, y])
     250
     251            #Create left triangle
     252            if i == 0:
     253                boundary[(len(elements), 1)] = 'left'
     254            elements.append([v2,v5,v1])
     255
     256            #Create bottom triangle
     257            if j == 0:
     258                boundary[(len(elements), 1)] = 'bottom'
     259            elements.append([v4,v5,v2])
     260
     261            #Create right triangle
     262            if i == m-1:
     263                boundary[(len(elements), 1)] = 'right'
     264            elements.append([v3,v5,v4])
     265
     266            #Create top triangle
     267            if j == n-1:
     268                boundary[(len(elements), 1)] = 'top'
     269            elements.append([v1,v5,v3])
     270
     271
     272    return points, elements, boundary
     273
    204274
    205275
Note: See TracChangeset for help on using the changeset viewer.