source: anuga_work/development/momentum_sink/scripts/building_generator.py @ 5587

Last change on this file since 5587 was 3535, checked in by duncan, 18 years ago

change imports so reflect the new structure

File size: 2.2 KB
Line 
1
2
3
4# add inundation dir to your pythonpath
5from anuga.pmesh.mesh import Mesh
6from anuga.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],[WidtH,0],[WidtH,WidtH],[0,WidtH]]
24    m.add_region_from_polygon(outer_polygon, tags={'wall':[0,1,2], 'wave':[3]})
25
26    # inner polygons => building boundaries
27    width = 15
28    wh = width/2
29    length = 15
30    lh = length/2
31    Wm = [12.5,37.5,62.5,87.5]
32    Lm = [12.5,37.5,62.5,87.5]
33
34    for W in Wm:
35        polygon = [[W-wh,L-lh],[W+wh,L-lh],[W+wh,L+lh],[W-wh,L+lh]]
36        m.add_hole_from_polygon(polygon, tags={'wall':[0,1,2,3]})# Adds holes with reflective boundaries.       
37
38        for L in Lm:
39            polygon1 = [[W-wh,L-lh],[W+wh,L-lh],[W+wh,L+lh],[W-wh,L+lh]]
40            m.add_hole_from_polygon(polygon1, tags={'wall':[0,1,2,3]})# Adds holes with reflective boundaries.       
41
42
43    #polygon = [[10,10],[20,10],[20,20],[10,20]]
44    #m.add_hole_from_polygon(polygon, tags={'wall':[0,1,2,3]})
45
46    #polygon = [[40,40],[50,40],[50,50],[40,50]]
47    #m.add_hole_from_polygon(polygon, tags={'wall':[0,1,2,3]})
48
49    #m.add_circle([20,70], 5, hole=True, tag='wall')
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.