Changeset 6085


Ignore:
Timestamp:
Dec 16, 2008, 5:04:35 PM (15 years ago)
Author:
ole
Message:

Got River2D runfile reader and associated ANUGA domain to work

Location:
anuga_work/development/river2d_integration
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • anuga_work/development/river2d_integration/Create_Domain_From_Pts_Vert.py

    r6077 r6085  
    7474#------------------------------------------------------------------------------
    7575
     76domain.set_quantity('stage', 1.0)
    7677
    7778
  • anuga_work/development/river2d_integration/River2Dcdg_ANUGAMesh.py

    r6083 r6085  
    2020print "\nFILES are open ready for conversion....\n"
    2121
     22lines = infid.readlines()
    2223
    23 linecounter =0
     24# Ignore all metadata prior to node information
     25for i, line in enumerate(lines):
     26    if line.strip().startswith('Node #'):
     27        # Found node information
     28        break
     29
     30
    2431reading_points = True
    2532reading_vertices = False
    2633last_point_index = 0
    2734
    28 for line in infid.readlines():
    29     linecounter=linecounter+1
    30     print 'line ',linecounter,reading_points, line.strip()
     35for L in lines[i+1:]:
     36    line = L.strip()
    3137
    32     raw_input("Press ENTER to exit.\n")
    33     if linecounter < 35:
    34         reading_vertices = False
    35         reading_points = False
     38    print line
     39   
     40    if line == '':
    3641        continue
    3742
    38     if line.strip() == '':
     43    if line.startswith('Element Information'):
    3944        continue
    40 
    41     if line.lower().startswith(' node #, coordinates'):
    42         raw_input("Press ENTER to exit.\n")
    43         reading_vertices = True
    44         reading_points = True
    45         continue
    46 
    47     if line.lower().startswith(' element #, vtype, gtype, nodes'):
     45       
     46    if line.startswith('Element #'):
    4847        reading_vertices = True
    4948        reading_points = False
    5049        continue
    5150
    52     if line.lower().startswith(' boundary element #, vtype, gtype, nodes, boundary condition codes'):
     51    if line.startswith('Boundary Element #'):
     52        print 'Reached boundary info, not processing yet'
    5353        break
    5454
    5555    if reading_points is True:   # Read Points
    56         fields = line.split(' ')
     56        fields = line.split()
     57
     58        #print fields, len(fields)
     59
     60        if len(fields) == 9:
     61            # No single character flag
     62            x_index = 1
     63        elif len(fields) == 10:
     64            # Single character flag used in in second column
     65            x_index = 2
     66        else:
     67            print fields, len(fields)
     68            raise Exception, 'Bad file format'
     69           
    5770        # Check that point indices are consecutive       
    5871        s = fields[0]
    59         print s
    6072        index = int(s)
    6173        assert index-1 == last_point_index
     
    6375
    6476        # Get points
    65         s = line[11:39]
    66         fields = s.split(' ')
    67         x=float(fields[0])
    68         y=float(fields[1])
    69         #z=float(fields[3]) # TODO: Get elevation data a separate list
     77        x=float(fields[x_index])
     78        y=float(fields[x_index + 1])
     79        #z=float(fields[x_index + 2]) # TODO: Get elevation data a separate list
    7080        outfid1.write('%.3f, %.3f\n' % (x, y))
    7181
    7282    elif reading_vertices is True:    # Read Vertices
    73         fields = line.split(' ')
     83        fields = line.split()
    7484
    7585        # Create indices and make them start from 0
    76         pt1=int(line[1:6]) - 1
    77         pt2=int(line[10:16]) - 1
    78         pt3=int(line[20:26]) - 1
     86        pt1=int(fields[3]) - 1
     87        pt2=int(fields[4]) - 1
     88        pt3=int(fields[5]) - 1
    7989        outfid2.write('%d, %d, %d\n' % (pt1, pt2,pt3))
    8090
Note: See TracChangeset for help on using the changeset viewer.