source: anuga_work/development/river2d_integration/River2DMesh_ANUGAMesh.py @ 6077

Last change on this file since 6077 was 6077, checked in by ole, 16 years ago

Some work on River2D integration - not working yet, mesh bungled.

File size: 1.8 KB
Line 
1""" This script takes a River2D msh file of format:
2
3 node no.,x,y,z,roughness
4 no more nodes.
5 Vert1,Vert2,Vert3,Tag,TagValue
6 no more boundary segments.
7 
8 
9and converts it to a format where it can be used to creat a domain from Points and Vertices.
10
11All you need to do is specify the data file name and output file name
12
13
14"""
15import string
16
17infid = open('Riv2dMesh.msh') # input file
18outfid1 = open('ANUGA_MeshPts.csv', 'w') # output filename
19outfid2 = open('ANUGA_MeshVertices.csv', 'w') # output filename
20print "\nFILES are open ready for conversion....\n"
21
22reading_points = True
23reading_vertices = False
24last_point_index = 0
25for line in infid.readlines():
26    print 'line', line.strip()
27   
28    if line.strip() == '':
29        continue
30
31    if line.lower().startswith('no more nodes'):
32        reading_vertices = True
33        reading_points = False
34        continue
35
36    if line.lower().startswith('no more boundary segments'):
37        break
38
39    if reading_points is True:   # Read Points
40
41        # Check that point indices are consecutive       
42        s = line[:5]
43        index = int(s.strip())
44        assert index-1 == last_point_index
45        last_point_index = index
46
47        # Get points
48        s = line[9:38]
49        fields = s.split(' ')
50        x=float(fields[0])
51        y=float(fields[1])
52        #z=float(fields[3]) # TODO: Get elevation data a separate list
53        outfid1.write('%.3f, %.3f\n' % (x, y))
54
55    elif reading_vertices is True:    # Read Vertices
56        fields = line.split(' ')
57
58        # Create indices and make them start from 0
59        pt1=int(line[1:6]) - 1
60        pt2=int(line[10:16]) - 1
61        pt3=int(line[20:26]) - 1
62        outfid2.write('%d, %d, %d\n' % (pt1, pt2,pt3)) 
63
64   
65outfid1.close()
66outfid2.close()
67print "\nConversion complete.\n"
68
Note: See TracBrowser for help on using the repository browser.