source: development/momentum_sink/friction_block.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.2 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 = 202 # 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    #m.add_region_from_polygon(outer_polygon, tags={'wall':[0,1,2], 'wave':[3]})
25
26    #domain.set_region(Set_region('mound', 'elevation', 100, location='unique vertices'))
27
28    #Boundary
29    dict = {}
30    dict['points'] = [[0,0],[0.5*WidtH,0],[1.5*WidtH,0],[2*WidtH,0],[2*WidtH,WidtH] \
31                      ,[1.5*WidtH,WidtH],[0.5*WidtH,WidtH],[0,WidtH]]
32   
33    dict['segments'] = [[0,1], [1,2], [2,3], [3,4],
34                        [4,5], [5,6], [6,7], [7,0],[1,6],[2,5]] # the outer border
35    dict['segment_tags'] = ['wall',
36                            'wall',
37                            'wall',                           
38                            'wall',
39                            'wall',
40                            'wall',
41                            'wall',
42                            'wave',
43                            '',                           
44                            '']
45    m.addVertsSegs(dict)
46
47    medium = m.add_region(0.51*WidtH,0.1)
48    medium.setTag('mound')
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.