Ignore:
Timestamp:
Nov 17, 2005, 4:16:50 PM (19 years ago)
Author:
steve
Message:

Adding ways to create cut out regions

File:
1 edited

Legend:

Unmodified
Added
Removed
  • inundation/analytical solutions/Non_symmetrical_dam_break.py

    r2034 r2036  
    44   Christopher Zoppou, Stephen Roberts
    55   Australian National University
    6    
     6
    77"""
    88
     
    1515from shallow_water import Domain, Transmissive_boundary, Reflective_boundary,\
    1616     Dirichlet_boundary
    17 from pmesh2domain import pmesh_to_domain_instance
     17#from pmesh2domain import pmesh_to_domain_instance
    1818from util import Polygon_function
    1919from mesh_factory import rectangular_cross
     20
     21
     22def cut_out_region(domain):
     23    """
     24    To do: make better comments!
     25    Deal with passing the boundary info as well
     26    """
     27
     28    points = domain.coordinates
     29    elements = domain.triangles
     30    boundary = domain.boundary
     31    centroid_coordinates = domain.centroid_coordinates
     32    N = domain.number_of_elements
     33
     34    elements_in  = []
     35    elements_out = []
     36    for i in range(N):
     37        element = elements[i]
     38        #print element
     39        [x,y] = centroid_coordinates[i]
     40        #print x,y
     41        if x>10 and y>10:
     42            #print i,'Out region'
     43            elements_out.append(i)
     44        else:
     45            #print i,'In region'
     46            elements_in.append(i)
     47
     48    #print elements_in
     49    #print elements_out
     50
     51    points_in = {}
     52    for i in elements_in:
     53        #print i
     54        [v0,v1,v2] = elements[i]
     55        #print v0,v1,v2
     56        points_in[v0] = v0
     57        points_in[v1] = v1
     58        points_in[v2] = v2
     59
     60
     61    new_index = []
     62    for i,value in enumerate(points_in):
     63        #print i , value
     64        points_in[value] = i
     65
     66
     67    #print points_in
     68    new_elements  = []
     69    for i in elements_in:
     70        #print i
     71        [v0,v1,v2] = elements[i]
     72        #print v0,v1,v2
     73
     74        nv0 = points_in[v0]
     75        nv1 = points_in[v1]
     76        nv2 = points_in[v2]
     77
     78        new_elements.append([nv0,nv1,nv2])
     79
     80    new_points = []
     81    for key,value in points_in.iteritems():
     82        [x,y] = points[key]
     83        new_points.append([x,y])
     84
     85    #print new_points
     86
     87    return new_points, new_elements
     88
     89
     90
     91
     92
    2093
    2194
     
    28101#---------------------------------------
    29102# Domain
    30 n = 19
    31 m = 40
    32 delta_x = 5.
    33 delta_y = 5.
     103n = 60
     104m = 60
     105delta_x = .5
     106delta_y = .5
    34107lenx = delta_x*n
    35108leny = delta_y*m
     
    38111points, elements, boundary = rectangular_cross(m, n, lenx, leny, origin)
    39112domain = Domain(points, elements, boundary)
     113
     114new_points, new_elements = cut_out_region(domain)
     115domain = Domain(new_points, new_elements)
     116
     117
    40118R = Reflective_boundary(domain)
    41119T = Transmissive_boundary(domain)
    42120D = Dirichlet_boundary([h1, 0.0, 0.0])
    43 domain.set_boundary({'left': R, 'right': T, 'top': R, 'bottom': R})
    44 
    45 n = 2
    46 m = 15
    47 delta_x = 5.
    48 delta_y = 5.
    49 lenx = delta_x*n
    50 leny = delta_y*m
    51 origin = (90.0, 90.0)
    52 
    53 points, elements, boundary = rectangular_cross(m, n, lenx, leny, origin)
    54 domain = Domain(points, elements, boundary)
    55 R = Reflective_boundary(domain)
    56 T = Transmissive_boundary(domain)
    57 D = Dirichlet_boundary([h1, 0.0, 0.0])
    58 domain.set_boundary({'left': T, 'right': T, 'top': R, 'bottom': R})
     121domain.set_boundary({'exterior': R})
    59122
    60123
    61 n = 19
    62 m = 40
    63 delta_x = 5.
    64 delta_y = 5.
    65 lenx = delta_x*n
    66 leny = delta_y*m
    67 origin = (100.0, 0.0)
    68124
    69 points, elements, boundary = rectangular_cross(m, n, lenx, leny, origin)
    70 domain = Domain(points, elements, boundary)
    71 R = Reflective_boundary(domain)
    72 T = Transmissive_boundary(domain)
    73 D = Dirichlet_boundary([h1, 0.0, 0.0])
    74 domain.set_boundary({'left': T, 'right': R, 'top': R, 'bottom': R})
     125
     126
     127
    75128
    76129print "Number of triangles = ", len(domain)
     
    79132#---------------------------------------
    80133#Initial condition
    81 domain.set_quantity('stage', h0)
    82 p0 = [[0.0, 0.0], [100.0, 0.0], [100.0, 200.0], [0.0, 200.0]]
    83 domain.set_quantity('stage',Polygon_function([(p0,h1)]))
     134p0 = [[0.0, 0.0], [10.0, 0.0], [10.0, 20.0], [0.0, 20.0]]
     135domain.set_quantity('stage',Polygon_function([(p0,h1)],default = h0))
    84136
    85137
     
    90142domain.filename = 'Non_symetrical_Dam_Break_second_order'
    91143
     144
     145# Visualization smoothing
     146domain.smooth=False
     147domain.visualise=True
    92148
    93149#---------------------------------------
     
    108164# Friction
    109165domain.set_quantity('friction', 0.0)
    110        
    111  
     166
     167
    112168#--------------------------------------
    113169# Evolution
    114170
    115171yieldstep = 0.1
    116 finaltime = 5.0
    117    
     172finaltime = 15.0
     173
    118174domain.default_order = 2
    119175domain.smooth = True
     
    123179for t in domain.evolve(yieldstep = yieldstep, finaltime = finaltime):
    124180    domain.write_time()
    125    
     181
    126182print 'That took %.2f seconds' %(time.time()-t0)
    127183
    128    
Note: See TracChangeset for help on using the changeset viewer.