Ignore:
Timestamp:
Aug 14, 2008, 10:26:06 AM (16 years ago)
Author:
ole
Message:

Implemented default_boundary option in File_boundary and Field_boundary as
per ticket:293 and added a note in the user manual.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • anuga_core/source/anuga/shallow_water/test_data_manager.py

    r5627 r5657  
    76437643        """
    76447644       
     7645        # FIXME (Ole): These tests should really move to
     7646        # test_generic_boundaries.py
     7647       
    76457648        from anuga.shallow_water import Domain
    76467649        from anuga.shallow_water import Reflective_boundary
     
    77747777        os.remove(sts_file+'.sts')
    77757778        os.remove(meshname)
     7779       
     7780       
     7781       
     7782               
     7783       
     7784    def test_file_boundary_stsI_beyond_model_time(self):
     7785        """test_file_boundary_stsI(self):
     7786       
     7787        Test that file_boundary can work when model time
     7788        exceeds available data.
     7789        This is optional and requires the user to specify a default
     7790        boundary object.
     7791        """
     7792       
     7793        # Don't do warnings in unit test
     7794        import warnings
     7795        warnings.simplefilter('ignore')
     7796       
     7797        from anuga.shallow_water import Domain
     7798        from anuga.shallow_water import Reflective_boundary
     7799        from anuga.shallow_water import Dirichlet_boundary
     7800        from anuga.shallow_water import File_boundary
     7801        from anuga.pmesh.mesh_interface import create_mesh_from_regions
     7802
     7803        bounding_polygon=[[6.0,97.0],[6.01,97.0],[6.02,97.0],[6.02,97.02],[6.00,97.02]]
     7804        tide = 0.37
     7805        time_step_count = 5
     7806        time_step = 2
     7807        lat_long_points =bounding_polygon[0:3]
     7808        n=len(lat_long_points)
     7809        first_tstep=ones(n,Int)
     7810        last_tstep=(time_step_count)*ones(n,Int)
     7811
     7812        h = 20       
     7813        w = 2
     7814        u = 10
     7815        v = -10
     7816        gauge_depth=h*ones(n,Float)
     7817        ha=w*ones((n,time_step_count),Float)
     7818        ua=u*ones((n,time_step_count),Float)
     7819        va=v*ones((n,time_step_count),Float)
     7820        base_name, files = self.write_mux2(lat_long_points,
     7821                                           time_step_count, time_step,
     7822                                           first_tstep, last_tstep,
     7823                                           depth=gauge_depth,
     7824                                           ha=ha,
     7825                                           ua=ua,
     7826                                           va=va)
     7827
     7828        sts_file=base_name
     7829        urs2sts(base_name,
     7830                sts_file,
     7831                mean_stage=tide,
     7832                verbose=False)
     7833        self.delete_mux(files)
     7834
     7835        #print 'start create mesh from regions'
     7836        for i in range(len(bounding_polygon)):
     7837            zone,\
     7838            bounding_polygon[i][0],\
     7839            bounding_polygon[i][1]=redfearn(bounding_polygon[i][0],
     7840                                            bounding_polygon[i][1])
     7841                                           
     7842        extent_res=1000000
     7843        meshname = 'urs_test_mesh' + '.tsh'
     7844        interior_regions=None
     7845        boundary_tags={'ocean': [0,1], 'otherocean': [2,3,4]}
     7846        create_mesh_from_regions(bounding_polygon,
     7847                                 boundary_tags=boundary_tags,
     7848                                 maximum_triangle_area=extent_res,
     7849                                 filename=meshname,
     7850                                 interior_regions=interior_regions,
     7851                                 verbose=False)
     7852       
     7853        domain_fbound = Domain(meshname)
     7854        domain_fbound.set_quantity('stage', tide)
     7855       
     7856        Br = Reflective_boundary(domain_fbound)
     7857        Bd = Dirichlet_boundary([w+tide, u*(w+h+tide), v*(w+h+tide)])       
     7858        Bf = File_boundary(sts_file+'.sts',
     7859                           domain_fbound,
     7860                           boundary_polygon=bounding_polygon,
     7861                           default_boundary=Bd) # Condition to be used
     7862                                                # if model time exceeds
     7863                                                # available data
     7864
     7865        domain_fbound.set_boundary({'ocean': Bf,'otherocean': Br})
     7866       
     7867        # Check boundary object evaluates as it should
     7868        for i, ((vol_id, edge_id), B) in enumerate(domain_fbound.boundary_objects):
     7869            if B is Bf:
     7870           
     7871                qf = B.evaluate(vol_id, edge_id)  # File boundary
     7872                qd = Bd.evaluate(vol_id, edge_id) # Dirichlet boundary
     7873
     7874                assert allclose(qf, qd)
     7875               
     7876       
     7877        # Evolve
     7878        data_finaltime = time_step*(time_step_count-1)
     7879        finaltime = data_finaltime + 10 # Let model time exceed available data
     7880        yieldstep = time_step
     7881        temp_fbound=zeros(int(finaltime/yieldstep)+1, Float)
     7882
     7883        for i, t in enumerate(domain_fbound.evolve(yieldstep=yieldstep,
     7884                                                   finaltime=finaltime,
     7885                                                   skip_initial_step=False)):
     7886                                                   
     7887            D = domain_fbound
     7888            temp_fbound[i]=D.quantities['stage'].centroid_values[2]
     7889
     7890            # Check that file boundary object has populated
     7891            # boundary array correctly 
     7892            # FIXME (Ole): Do this for the other tests too!
     7893            for j, val in enumerate(D.get_quantity('stage').boundary_values):
     7894           
     7895                (vol_id, edge_id), B = D.boundary_objects[j]
     7896                if isinstance(B, File_boundary):
     7897                    #print j, val
     7898                    assert allclose(val, w + tide)
     7899
     7900
     7901
     7902       
     7903       
     7904       
     7905           
     7906
     7907       
     7908        domain_drchlt = Domain(meshname)
     7909        domain_drchlt.set_quantity('stage', tide)
     7910        Br = Reflective_boundary(domain_drchlt)
     7911
     7912        domain_drchlt.set_boundary({'ocean': Bd,'otherocean': Br})
     7913        temp_drchlt=zeros(int(finaltime/yieldstep)+1,Float)
     7914
     7915        for i, t in enumerate(domain_drchlt.evolve(yieldstep=yieldstep,
     7916                                                   finaltime=finaltime,
     7917                                                   skip_initial_step=False)):
     7918            temp_drchlt[i]=domain_drchlt.quantities['stage'].centroid_values[2]
     7919
     7920        #print domain_fbound.quantities['stage'].vertex_values
     7921        #print domain_drchlt.quantities['stage'].vertex_values
     7922                   
     7923        assert allclose(temp_fbound,temp_drchlt)
     7924       
     7925        assert allclose(domain_fbound.quantities['stage'].vertex_values,
     7926                        domain_drchlt.quantities['stage'].vertex_values)
     7927                       
     7928        assert allclose(domain_fbound.quantities['xmomentum'].vertex_values,
     7929                        domain_drchlt.quantities['xmomentum'].vertex_values)                       
     7930                       
     7931        assert allclose(domain_fbound.quantities['ymomentum'].vertex_values,
     7932                        domain_drchlt.quantities['ymomentum'].vertex_values)                                               
     7933       
     7934       
     7935        os.remove(sts_file+'.sts')
     7936        os.remove(meshname)
     7937
     7938       
    77767939
    77777940    def test_file_boundary_stsII(self):
     
    1010510268
    1010610269    suite = unittest.makeSuite(Test_Data_Manager,'test')
    10107     #suite = unittest.makeSuite(Test_Data_Manager,'test_file_boundary_stsI')
     10270    #suite = unittest.makeSuite(Test_Data_Manager,'test_file_boundary_stsI_beyond_model_time')
    1010810271    #suite = unittest.makeSuite(Test_Data_Manager,'test_file_boundary_stsIV_sinewave_ordering')
    1010910272    #suite = unittest.makeSuite(Test_Data_Manager,'test_get_flow_through_cross_section_with_geo')
Note: See TracChangeset for help on using the changeset viewer.