Changeset 4899


Ignore:
Timestamp:
Dec 31, 2007, 7:53:02 AM (17 years ago)
Author:
duncan
Message:

Using the numeric arrays from mesh engine, but still have the old output.

Location:
anuga_core/source/anuga
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • anuga_core/source/anuga/load_mesh/loadASCII.py

    r4663 r4899  
    623623    """
    624624 
    625     # FIXME(Ole and John): We ran into a problem on Bogong (64 bit) where integers appeared as arrays.
    626     # This may be similar to problem seen by Steve in changeset:2778 where he had to wrap them in int.
    627     # Now we are trying with the native Integer format (Int == 'l' == Int64). However, that caused casting errors, when 64bit arrays
    628     # are to be assigned to their NetCDF counterparts. It seems that the NetCDF arrays are 32bit even though they are created with
    629     # the type Int64. Need to look at the NetCDF library in more detail.
     625    # FIXME(Ole and John): We ran into a problem on Bogong (64 bit)
     626    # where integers appeared as arrays.  This may be similar to
     627    # problem seen by Steve in changeset:2778 where he had to wrap
     628    # them in int.  Now we are trying with the native Integer format
     629    # (Int == 'l' == Int64). However, that caused casting errors, when
     630    # 64bit arrays are to be assigned to their NetCDF counterparts. It
     631    # seems that the NetCDF arrays are 32bit even though they are
     632    # created with the type Int64. Need to look at the NetCDF library
     633    # in more detail.
    630634   
    631635    IntType = Int32
     
    732736        outfile.variables['triangles'][:] = mesh['triangles']
    733737        outfile.variables['triangle_neighbors'][:] = mesh['triangle_neighbors']
    734         if (mesh['triangle_tags'].shape[1] > 0):
     738        if mesh['triangle_tags'] is not None and \
     739               (mesh['triangle_tags'].shape[1] > 0):
    735740            outfile.createDimension('num_of_triangle_tag_chars',
    736741                                    mesh['triangle_tags'].shape[1])
  • anuga_core/source/anuga/load_mesh/test_loadASCII.py

    r4165 r4899  
    275275        export_mesh_file(fileName,dict)
    276276        loaded_dict = import_mesh_file(fileName)
    277         dict = self.tri_dict   
     277        dict = self.tri_dict
    278278        self.check_mesh_dicts(loaded_dict,dict, 'test_read_write_msh_file6') 
    279279        os.remove(fileName)
     
    545545
    546546    suite = unittest.makeSuite(loadASCIITestCase,'test')
    547     #suite = unittest.makeSuite(loadASCIITestCase,'test_writepts')
    548     runner = unittest.TextTestRunner() #verbosity=0)
     547    #suite = unittest.makeSuite(loadASCIITestCase,'test_rs')
     548    runner = unittest.TextTestRunner() #verbosity=2)
    549549    runner.run(suite)
    550550   
  • anuga_core/source/anuga/mesh_engine/mesh_engine.py

    r4898 r4899  
    55from types import ListType, TupleType
    66
     7import exceptions
     8
     9class NoTrianglesError(exceptions.Exception): pass
    710import anuga.mesh_engine.mesh_engine_c_layer as triang
    811#import anuga.mesh_engine.list_dic as triang
     
    130133                          pointatts,segatts, mode, segments.flat)
    131134    # the values as arrays
    132     mesh_dict['trianglelist'] = trianglelist
    133     mesh_dict['pointlist'] = pointlist
     135    mesh_dict['generatedtrianglelist'] = trianglelist
     136    mesh_dict['generatedpointlist'] = pointlist
     137    #print "mesh engine mesh_dict['generatedpointlist']", mesh_dict['generatedpointlist']
     138    # WARNING - generatedpointmarkerlist IS UNTESTED
     139    mesh_dict['generatedpointmarkerlist'] = pointmarkerlist
     140    mesh_dict['generatedpointattributelist'] = pointattributelist
     141    mesh_dict['generatedsegmentlist'] = segmentlist
     142    mesh_dict['generatedsegmentmarkerlist'] =  segmentmarkerlist
     143    mesh_dict['generatedtriangleneighborlist'] = neighborlist
     144    mesh_dict['qaz'] = 1 #debugging
    134145
    135     # WARNING - pointmarkerlist IS UNTESTED
    136     mesh_dict['pointmarkerlist'] = pointmarkerlist
    137     mesh_dict['pointattributelist'] = pointattributelist
    138     mesh_dict['triangleattributelist'] = triangleattributelist
    139     mesh_dict['segmentlist'] = segmentlist
    140     mesh_dict['segmentmarkerlist'] =  segmentmarkerlist
    141     mesh_dict['triangleneighborlist'] = neighborlist
    142     mesh_dict['qaz'] = 1 #debugging
    143     ##print "r_test", r_test
     146    mesh_dict['triangleattributelist'] = triangleattributelist
     147    #print "mesh eng generatedtrianglelist", trianglelist
     148    #print "mesh eng mesh_dict['triangleattributelist'] ",mesh_dict['triangleattributelist']
     149    #print "mesh eng mesh_dict['generatedtriangleattributelist'] ", mesh_dict['generatedtriangleattributelist']   
     150   
     151    if True:
     152        mesh_dict['generatedtriangleattributelist'] = triangleattributelist
     153
     154        if mesh_dict['generatedtriangleattributelist'].shape[1] == 0:
     155            mesh_dict['generatedtriangleattributelist'] = None
     156        if trianglelist.shape[0] == 0:
     157            # There are no triangles.
     158            # this is used by urs_ungridded2sww
     159            raise NoTrianglesError
     160    #print "mesh eng mesh_dict['generatedtriangleattributelist'] ", mesh_dict['generatedtriangleattributelist']   
    144161   
    145162    return mesh_dict
  • anuga_core/source/anuga/mesh_engine/test_generate_mesh.py

    r4898 r4899  
    527527
    528528
    529     def test_transition_to_arrays(self):
    530         # segattlist = []
    531         points = []
    532         seglist = []
    533         holelist = []
    534         regionlist = []
    535 
     529    def dont_test_transition_to_arrays(self):
     530        points = []
     531        seglist = []
     532        holelist = []
     533        regionlist = []
    536534        points = [(0.0,0.0),(0.0,10.0),(3.0,0.0),(3.0,10.0)]
    537535        pointattlist = []
    538536        # 5.0 is the region tag, 99.0 is the max area
    539         # REgion tag isn't working though
    540537        regionlist.append( [0.2,0.2,5.0,99.0] )
    541538        seglist = [(0,1),(1,3),(3,2),(2,0)]
     
    550547        self.failUnless(data['generatedtrianglelist'] ==[(1, 0, 2), (2, 3, 1)],
    551548                        'trianglelist is wrong!')
    552         #print "data['generatedtrianglelist']",data['generatedtrianglelist']
    553         #print "data['trianglelist']", data['trianglelist']
    554549        self.failUnless(data['generatedtrianglelist'] ==data['trianglelist'],
    555550                        'trianglelist is wrong!')
     
    585580                        data['triangleneighborlist'],
    586581                        ' is wrong!')
    587                        
     582       
     583    def test_numeric_arrays(self):
     584        points = []
     585        seglist = []
     586        holelist = []
     587        regionlist = []
     588        points = [(0.0,0.0),(0.0,10.0),(3.0,0.0),(3.0,10.0)]
     589        pointattlist = []
     590        # 5.0 is the region tag, 99.0 is the max area
     591        tri_tag = 123456.0
     592        regionlist.append( [0.2,0.2, tri_tag,99.0] )
     593        seglist = [(0,1),(1,3),(3,2),(2,0)]
     594        segattlist = [21,22,23,24]
     595         #The 'A' has to be there to get the region marker stuff working
     596        mode = "QzpnA"
     597        #mode = "jQpznAa2000.1a"
     598        data = generate_mesh(points,seglist,holelist,regionlist,
     599                              pointattlist,segattlist, mode, points)
     600        #print "data", data
     601
     602        self.failUnless(data['generatedtrianglelist'] ==[(1, 0, 2), (2, 3, 1)],
     603                        'trianglelist is wrong!')
     604        self.failUnless(data['generatedsegmentlist'] ==[(0, 1), (1, 3),
     605                                                        (3, 2), (2, 0)],
     606                        'segmentlist is wrong!')
     607        self.failUnless(data['generatedpointlist'] ==[(0.0, 0.0), (0.0, 10.0),
     608                                                      (3.0, 0.0), (3.0, 10.0)],
     609                        ' is wrong!')
     610        self.failUnless(data['generatedtriangleattributelist'] == [[tri_tag],
     611                                                                   [tri_tag]],
     612                        ' is wrong!')
     613       
     614        self.failUnless(data['generatedsegmentlist'] == seglist,
     615                        ' is wrong!')
     616        self.failUnless(data['generatedsegmentmarkerlist'] == segattlist,
     617                        ' is wrong!')
     618        # I copied these answers from the output, so bad test..
     619        self.failUnless(data['generatedtriangleneighborlist'] == \
     620                        [(-1, 1, -1), (-1, 0, -1)],
     621                        ' is wrong!')
     622       
    588623    def test_pointattlist(self):
    589624        # segattlist = []
     
    604639                                                                [10],[10]],
    605640                        ' is wrong!')
     641       
     642       
     643        pointattlist = [[0.],[0.],[10.],[10.]]
     644        mode = "Qzp"       
     645        data = generate_mesh(points,seglist,holelist,regionlist,
     646                              pointattlist,segattlist, mode, points)
     647        self.failUnless(data['generatedpointattributelist'] == [[0.0],[0.0],
     648                                                                [10],[10]],
     649                        ' is wrong!')
     650        pointattlist = [[0.,1],[0.,1],[10.,20],[10.,20]]
     651        mode = "Qzp"       
     652        data = generate_mesh(points,seglist,holelist,regionlist,
     653                              pointattlist,segattlist, mode, points)
     654        #print "data", data
     655        self.failUnless(data['generatedpointattributelist'] == pointattlist,
     656                        ' is wrong!')
     657           
     658    def dont_test_transition_pointattlist(self):
     659        # segattlist = []
     660        points = []
     661        seglist = []
     662        holelist = []
     663        regionlist = []
     664
     665        points = [(0.0,0.0),(0.0,4.0),(4.0,2.0),(2.0,0.0)]
     666        pointattlist = [0.,0.,10.,10.]
     667        regionlist.append( [0.2,0.2,2.1, 99.] )
     668        seglist = [(0,1),(1,2),(2,3),(3,0)]
     669        segattlist = [11,12,13,14]
     670        mode = "Qzp"
     671        data = generate_mesh(points,seglist,holelist,regionlist,
     672                              pointattlist,segattlist, mode, points)
     673        self.failUnless(data['generatedpointattributelist'] == [[0.0],[0.0],
     674                                                                [10],[10]],
     675                        ' is wrong!')
    606676        self.failUnless(data['generatedpointattributelist'] == \
    607677                        data['pointattributelist'],
  • anuga_core/source/anuga/pmesh/mesh.py

    r4898 r4899  
    2525
    2626
    27 class NoTrianglesError(exceptions.Exception): pass
     27#class NoTrianglesError(exceptions.Exception): pass
    2828 
    2929#import load_mesh
     
    11901190        #print "%%%%%%%%%%%%%%%%%%%%%%%%%%%generated",generatedMesh
    11911191        generatedMesh['qaa'] = 1
    1192         generatedMesh['generatedsegmentmarkerlist'] = \
    1193              segment_ints2strings(generatedMesh['generatedsegmentmarkerlist'],
    1194                                   segconverter)
     1192        if generatedMesh['generatedsegmentmarkerlist'] is not None:
     1193            generatedMesh['generatedsegmentmarkerlist'] = \
     1194              segment_ints2strings(generatedMesh['generatedsegmentmarkerlist'],
     1195                                   segconverter)
    11951196        #print "processed gen",generatedMesh['generatedsegmentmarkerlist']
    1196         generatedMesh['generatedtriangleattributelist'] = \
    1197          region_ints2strings(generatedMesh['generatedtriangleattributelist'],
     1197        #print "pmesh mesh generatedMesh['generatedtriangleattributelist']", generatedMesh['generatedtriangleattributelist']
     1198        if generatedMesh['generatedtriangleattributelist'] is not None:
     1199            generatedMesh['generatedtriangleattributelist'] = \
     1200            region_ints2strings(generatedMesh['generatedtriangleattributelist'],
    11981201                                  regionconverter)
    11991202
     1203        #print "pmesh mesh generatedMesh['generatedtriangleattributelist']", generatedMesh['generatedtriangleattributelist']
    12001204        #FIXME (DSG-DSG)  move above section into generate_mesh.py
    1201 
    1202         if len(generatedMesh['generatedpointattributelist'][0])==0:
     1205       
     1206        if generatedMesh['generatedpointattributelist'].shape[1] ==0:
    12031207            self.attributeTitles = []
    12041208        generatedMesh['generatedpointattributetitlelist']= \
     
    15541558            self.meshTriangles.append(tObject)
    15551559
    1556         index = 0
    1557         for att in genDict['generatedtriangleattributelist']:
    1558             if att == []:
    1559                 self.meshTriangles[index].setAttribute("")
    1560             else:
    1561                 self.meshTriangles[index].setAttribute(att[0])
    1562             index += 1
     1560        if genDict['generatedtriangleattributelist'] is not None:
     1561            index = 0
     1562            for att in genDict['generatedtriangleattributelist']:
     1563                if att == []:
     1564                    self.meshTriangles[index].setAttribute("")
     1565                else:
     1566                    self.meshTriangles[index].setAttribute(att[0])
     1567                index += 1
    15631568           
    15641569        index = 0
     
    31523157    """Reverses the transformation of region_strings2ints
    31533158    """
    3154     if region_list == []:
    3155         raise NoTrianglesError
    3156     if region_list[0] != []:
     3159    #print 'region_ints2strings region_list', region_list
     3160   
     3161    returned_region_list = []
     3162    # may not need (not region_list[0] == [])
     3163    # or region_list[0] == [0.0]
     3164    if (not region_list[0] == []): # or region_list[0] == [0.0]:
     3165        #print "in loop"
    31573166        for i in xrange(len(region_list)):
    3158             region_list[i] = [convertint2string[int(region_list[i][0])]]
    3159     return region_list
     3167            temp = region_list[i]
     3168            returned_region_list.append([convertint2string[int(temp[0])]])
     3169    return returned_region_list
    31603170
    31613171def segment_ints2strings(intlist, convertint2string):
  • anuga_core/source/anuga/pmesh/test_mesh.py

    r4888 r4899  
    418418        m = Mesh(userVertices=[a,b,c,d,e,f,g], userSegments=[s1,s2,s3,s4,s5,s6,s7,s8,s9,s10], regions=[r1,r2,r3] )
    419419        m.generateMesh("Q", maxArea = 2.1 )
    420         #print m
     420       
    421421        Triangulation =  m.getTriangulation()
    422422        #print Triangulation[0].attribute
     
    16531653        self.failUnless( dict['triangle_neighbors'][0] == [-1,2,3],
    16541654                        'test_Mesh2IODict failed. test 6')
     1655        #print "dict['triangle_tags'][0]", dict['triangle_tags'][0]
    16551656        self.failUnless( dict['triangle_tags'][0] == "1.3",
    16561657                         'test_Mesh2IODict failed. test 7')
     
    23562357    suite = unittest.makeSuite(meshTestCase,'test')
    23572358    #suite = unittest.makeSuite(meshTestCase,'mode_string_float_problems')
    2358     #suite = unittest.makeSuite(meshTestCase,'test_exportPointsFile')
     2359    #suite = unittest.makeSuite(meshTestCase,'test_import_mesh')
     2360    #suite = unittest.makeSuite(meshTestCase,'test_Mesh2IODict')
    23592361    runner = unittest.TextTestRunner() # verbosity=2)
    23602362    runner.run(suite)
  • anuga_core/source/anuga/pmesh/test_mesh_interface.py

    r3872 r4899  
    746746if __name__ == "__main__":
    747747    suite = unittest.makeSuite(TestCase,'test')
    748 #    suite = unittest.makeSuite(TestCase,'test_create_mesh_from_regions_interior_regions')
     748    #suite = unittest.makeSuite(TestCase,'test_create_mesh_from_regions4')
    749749    runner = unittest.TextTestRunner() #verbosity=2)
    750750    runner.run(suite)
  • anuga_core/source/anuga/shallow_water/data_manager.py

    r4868 r4899  
    46494649      +ve value in grid A and a -ve value in grid B.
    46504650    """
    4651     from anuga.pmesh.mesh import Mesh, NoTrianglesError
     4651    from anuga.mesh_engine.mesh_engine import NoTrianglesError
     4652    from anuga.pmesh.mesh import Mesh
    46524653
    46534654    files_in = [basename_in + WAVEHEIGHT_MUX_LABEL,
     
    47204721           
    47214722    points_utm=ensure_numeric(points_utm)
    4722     #print "mesh_dic['generatedpointlist']", mesh_dic['generatedpointlist']
    4723     #print "points_utm", points_utm
    47244723    assert ensure_numeric(mesh_dic['generatedpointlist']) == \
    47254724           ensure_numeric(points_utm)
  • anuga_core/source/anuga/shallow_water/test_data_manager.py

    r4868 r4899  
    73687368    suite = unittest.makeSuite(Test_Data_Manager,'test')
    73697369    #suite = unittest.makeSuite(Test_Data_Manager,'test_urs_ungridded_holeII')
    7370     #suite = unittest.makeSuite(Test_Data_Manager,'test_sww_range')
     7370    #suite = unittest.makeSuite(Test_Data_Manager,'test_urs_ungridded_holeII')
    73717371
    73727372   
     
    73797379    else:
    73807380        pass
    7381     runner = unittest.TextTestRunner() #verbosity=2)
     7381    runner = unittest.TextTestRunner() # verbosity=2)
    73827382    runner.run(suite)
    73837383
Note: See TracChangeset for help on using the changeset viewer.