Ignore:
Timestamp:
Sep 28, 2007, 5:15:52 PM (17 years ago)
Author:
duncan
Message:

ticket#196

File:
1 edited

Legend:

Unmodified
Added
Removed
  • anuga_core/source/anuga/damage_modelling/test_inundation_damage.py

    r4503 r4742  
    204204        #Create a csv file
    205205        self.csv_fileII = tempfile.mktemp(".csv")
    206         fd = open(self.csv_file,'wb')
     206        fd = open(self.csv_fileII,'wb')
    207207        writer = csv.writer(fd)
    208208        writer.writerow(['LONGITUDE','LATITUDE',STR_VALUE_LABEL,CONT_VALUE_LABEL,'ROOF_TYPE',WALL_TYPE_LABEL, SHORE_DIST_LABEL])
     
    210210        writer.writerow(['151','-34.5','150000','76000','Metal','Double Brick',200.])
    211211        writer.writerow(['151','-34.25','150000','76000','Metal','Brick Veneer',200.])
    212         writer.writerow(['151.5','-35.5','199770','130000','Metal','Timber',20.])
    213212        fd.close()
    214213       
     
    226225            pass
    227226        os.remove(self.csv_file)
     227        os.remove(self.csv_fileII)
    228228
    229229   
     
    237237
    238238   
     239    def test_inundation_damage_list_as_input(self):
     240
     241        # Note, this isn't testing the results,
     242        # just that is all runs
     243        sww_file = self.domain.get_name() + "." + self.domain.format
     244        #print "sww_file",sww_file
     245        inundation_damage(sww_file,
     246                          [self.csv_file, self.csv_fileII], verbose=False)
     247
    239248    def test_inundation_damage2(self):
    240249
     
    309318        os.remove(sww.filename)
    310319        os.remove(csv_file)
     320         
     321    def test_inundation_damage_list(self):
     322
     323        # create mesh
     324        mesh_file = tempfile.mktemp(".tsh")   
     325        points = [[0.0,0.0],[6.0,0.0],[6.0,6.0],[0.0,6.0]]
     326        m = Mesh()
     327        m.add_vertices(points)
     328        m.auto_segment()
     329        m.generate_mesh(verbose=False)
     330        m.export_mesh_file(mesh_file)
     331       
     332        #Create shallow water domain
     333        domain = Domain(mesh_file)
     334        os.remove(mesh_file)
     335       
     336        domain.default_order=2
     337        domain.beta_h = 0
     338
     339        #Set some field values
     340        domain.set_quantity('elevation', elevation_function)
     341        domain.set_quantity('friction', 0.03)
     342        domain.set_quantity('xmomentum', 22.0)
     343        domain.set_quantity('ymomentum', 55.0)
     344
     345        ######################
     346        # Boundary conditions
     347        B = Transmissive_boundary(domain)
     348        domain.set_boundary( {'exterior': B})
     349
     350        # This call mangles the stage values.
     351        domain.distribute_to_vertices_and_edges()
     352        domain.set_quantity('stage', 0.3)
     353
     354        #sww_file = tempfile.mktemp("")
     355        domain.set_name('datatest' + str(time.time()))
     356        domain.format = 'sww'
     357        domain.smooth = True
     358        domain.reduction = mean
     359
     360        sww = get_dataobject(domain)
     361        sww.store_connectivity()
     362        sww.store_timestep(['stage', 'xmomentum', 'ymomentum'])
     363        domain.set_quantity('stage', -0.3)
     364        domain.time = 2.
     365        sww.store_timestep(['stage', 'xmomentum', 'ymomentum'])
     366       
     367        #Create a csv file
     368        csv_file = tempfile.mktemp(".csv")
     369        fd = open(csv_file,'wb')
     370        writer = csv.writer(fd)
     371        writer.writerow(['x','y',STR_VALUE_LABEL,CONT_VALUE_LABEL,'ROOF_TYPE',WALL_TYPE_LABEL, SHORE_DIST_LABEL])
     372        writer.writerow([5.5,0.5,'10','130000','Metal','Timber',20])
     373        writer.writerow([4.5,1.0,'150','76000','Metal','Double Brick',20])
     374        writer.writerow([0.1,1.5,'100','76000','Metal','Brick Veneer',300])
     375        writer.writerow([6.1,1.5,'100','76000','Metal','Brick Veneer',300])
     376        fd.close()
     377       
     378        extension = ".csv"
     379        csv_fileII = tempfile.mktemp(extension)
     380        fd = open(csv_fileII,'wb')
     381        writer = csv.writer(fd)
     382        writer.writerow(['x','y',STR_VALUE_LABEL,CONT_VALUE_LABEL,'ROOF_TYPE',WALL_TYPE_LABEL, SHORE_DIST_LABEL])
     383        writer.writerow([5.5,0.5,'10','130000','Metal','Timber',20])
     384        writer.writerow([4.5,1.0,'150','76000','Metal','Double Brick',20])
     385        writer.writerow([0.1,1.5,'100','76000','Metal','Brick Veneer',300])
     386        writer.writerow([6.1,1.5,'100','76000','Metal','Brick Veneer',300])
     387        fd.close()
     388       
     389        sww_file = domain.get_name() + "." + domain.format
     390        #print "sww_file",sww_file
     391        marker='_gosh'
     392        inundation_damage(sww_file, [csv_file, csv_fileII],
     393                          exposure_file_out_marker=marker,
     394                          verbose=False)
     395
     396        # Test one file
     397        csv_handle = Exposure_csv(csv_file[:-4]+marker+extension)
     398        struct_loss = csv_handle.get_column(EventDamageModel.STRUCT_LOSS_TITLE)
     399        #print "struct_loss",struct_loss
     400        struct_loss = [float(x) for x in struct_loss]
     401        assert allclose(struct_loss,[10,150,16.9,0])       
     402        depth = csv_handle.get_column(EventDamageModel.MAX_DEPTH_TITLE)
     403        #print "depth",depth
     404        depth = [float(x) for x in depth]
     405        assert allclose(depth,[5.5,4.5,0.1,-0.3])
     406       
     407        # Test another file
     408        csv_handle = Exposure_csv(csv_fileII[:-4]+marker+extension)
     409        struct_loss = csv_handle.get_column(EventDamageModel.STRUCT_LOSS_TITLE)
     410        #print "struct_loss",struct_loss
     411        struct_loss = [float(x) for x in struct_loss]
     412        assert allclose(struct_loss,[10,150,16.9,0])       
     413        depth = csv_handle.get_column(EventDamageModel.MAX_DEPTH_TITLE)
     414        #print "depth",depth
     415        depth = [float(x) for x in depth]
     416        assert allclose(depth,[5.5,4.5,0.1,-0.3])
     417        os.remove(sww.filename)
     418        os.remove(csv_file)
     419        os.remove(csv_fileII)
    311420       
    312421    def ztest_add_depth_and_momentum2csv(self):
     
    491600    else:
    492601        pass
    493     #suite = unittest.makeSuite(Test_inundation_damage,'test_calc_max_depth_and_momentum')
    494602    suite = unittest.makeSuite(Test_inundation_damage,'test')
     603    #suite = unittest.makeSuite(Test_inundation_damage,'test_inundation_damage_list_as_input')
    495604    runner = unittest.TextTestRunner()
    496605    runner.run(suite)
Note: See TracChangeset for help on using the changeset viewer.