source: development/momentum_sink/create_buildings.py @ 2378

Last change on this file since 2378 was 2341, checked in by nicholas, 19 years ago

Added friction comparision for building, Fiddled with loops fro create buildings

File size: 2.1 KB
Line 
1
2
3
4# add inundation dir to your pythonpath
5from pmesh.mesh import Mesh
6from coordinate_transforms.geo_reference import Geo_reference
7
8
9def create_mesh(maximum_triangle_area,
10                mesh_file=None,
11                triangles_in_name = False):
12    """
13    triangles_in_name, if True is used to append the number of
14    triangles in the mesh to the mesh file name.
15    """
16    # create a mesh instance of class Mesh
17    m = Mesh()
18
19    # Boundary of problem
20    WidtH = 200 # width of boudary in metres
21    #W = WidtH/8
22    #L = W
23    outer_polygon = [[0,0],[2*WidtH,0],[2*WidtH,WidtH],[0,WidtH]]
24    print outer_polygon
25    m.add_region_from_polygon(outer_polygon, tags={'wall':[0,1,2], 'wave':[3]})
26
27    # inner polygons => building boundaries
28    depth = 15 # depth of building side to oncoming wave
29    wh = depth/2 
30    breadth = 15 # breadth of building
31    lh = breadth/2 
32    print "building footprint"
33    print depth * breadth , "m^2"
34    block = 625
35    BL = block**0.5
36    print BL
37    #[12.5,37.5,62.5,87.5,112.5,137.5,162.5,187.5]
38    D = WidtH/2 + BL/2
39    B = BL/2
40    for D in [112.5,137.5,162.5,187.5]:
41        for B in [12.5,37.5,62.5,87.5,112.5,137.5,162.5,187.5]:
42            polygon = [[D-wh,B-lh],[D+wh,B-lh],[D+wh,B+lh],[D-wh,B+lh]]
43            m.add_hole_from_polygon(polygon, tags={'wall':[0,1,2,3]})# Adds holes with reflective boundaries.       
44            #print polygon
45           
46            print B
47
48        print D
49
50    m.generate_mesh(maximum_triangle_area=maximum_triangle_area)
51    triangle_count = m.get_triangle_count()
52   
53    if mesh_file is None:   
54        return m, triangle_count
55    else:
56        if triangles_in_name is True:
57            mesh_file = mesh_file[:-4] + '_' + str(triangle_count) \
58                        + mesh_file[-4:]
59        m.export_mesh_file(mesh_file)
60        return mesh_file, triangle_count
61
62#-------------------------------------------------------------
63if __name__ == "__main__":
64    _, triangle_count = create_mesh(10,mesh_file="test.tsh")
65    print "triangle_count",triangle_count
Note: See TracBrowser for help on using the repository browser.