- Timestamp:
- Jan 14, 2009, 5:47:17 PM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
anuga_core/source/anuga/shallow_water/test_data_manager.py
r6157 r6173 8244 8244 8245 8245 8246 8247 8248 8249 8250 8251 8252 8246 8253 8247 domain_drchlt = Domain(meshname) … … 8845 8839 This one uses a sine wave and compares to time boundary 8846 8840 """ 8847 #FIXME (Ole): Under construction8848 8841 8849 8842 from anuga.shallow_water import Domain … … 8994 8987 domain_time.set_quantity('stage', tide) 8995 8988 Br = Reflective_boundary(domain_time) 8996 Bw =Time_boundary(domain=domain_time,8989 Bw = Time_boundary(domain=domain_time, 8997 8990 f=lambda t: [num.sin(t)+tide,3.*(20.+num.sin(t)+tide),2.*(20.+num.sin(t)+tide)]) 8998 8991 domain_time.set_boundary({'ocean': Bw,'otherocean': Br}) … … 9032 9025 9033 9026 9034 9027 9028 9029 9030 def test_file_boundary_sts_time_limit(self): 9031 """test_file_boundary_stsIV_sinewave_ordering(self): 9032 Read correct points from ordering file and apply sts to boundary 9033 This one uses a sine wave and compares to time boundary 9034 9035 This one tests that times used can be limited by upper limit 9036 """ 9037 9038 from anuga.shallow_water import Domain 9039 from anuga.shallow_water import Reflective_boundary 9040 from anuga.shallow_water import Dirichlet_boundary 9041 from anuga.shallow_water import File_boundary 9042 from anuga.pmesh.mesh_interface import create_mesh_from_regions 9043 9044 lat_long_points=[[6.01,97.0],[6.02,97.0],[6.05,96.9],[6.0,97.0]] 9045 bounding_polygon=[[6.0,97.0],[6.01,97.0],[6.02,97.0],[6.02,97.02],[6.00,97.02]] 9046 tide = 0.35 9047 time_step_count = 50 9048 time_step = 0.1 9049 times_ref = num.arange(0, time_step_count*time_step, time_step) 9050 9051 n=len(lat_long_points) 9052 first_tstep=num.ones(n,num.Int) 9053 last_tstep=(time_step_count)*num.ones(n,num.Int) 9054 9055 gauge_depth=20*num.ones(n,num.Float) 9056 9057 ha1=num.ones((n,time_step_count),num.Float) 9058 ua1=3.*num.ones((n,time_step_count),num.Float) 9059 va1=2.*num.ones((n,time_step_count),num.Float) 9060 for i in range(n): 9061 ha1[i]=num.sin(times_ref) 9062 9063 9064 base_name, files = self.write_mux2(lat_long_points, 9065 time_step_count, time_step, 9066 first_tstep, last_tstep, 9067 depth=gauge_depth, 9068 ha=ha1, 9069 ua=ua1, 9070 va=va1) 9071 9072 # Write order file 9073 file_handle, order_base_name = tempfile.mkstemp("") 9074 os.close(file_handle) 9075 os.remove(order_base_name) 9076 d="," 9077 order_file=order_base_name+'order.txt' 9078 fid=open(order_file,'w') 9079 9080 # Write Header 9081 header='index, longitude, latitude\n' 9082 fid.write(header) 9083 indices=[3,0,1] 9084 for i in indices: 9085 line=str(i)+d+str(lat_long_points[i][1])+d+\ 9086 str(lat_long_points[i][0])+"\n" 9087 fid.write(line) 9088 fid.close() 9089 9090 sts_file=base_name 9091 urs2sts(base_name, basename_out=sts_file, 9092 ordering_filename=order_file, 9093 mean_stage=tide, 9094 verbose=False) 9095 self.delete_mux(files) 9096 9097 9098 9099 # Now read the sts file and check that values have been stored correctly. 9100 fid = NetCDFFile(sts_file + '.sts') 9101 9102 # Check the time vector 9103 times = fid.variables['time'][:] 9104 9105 #print times 9106 9107 # Check sts quantities 9108 stage = fid.variables['stage'][:] 9109 xmomentum = fid.variables['xmomentum'][:] 9110 ymomentum = fid.variables['ymomentum'][:] 9111 elevation = fid.variables['elevation'][:] 9112 9113 9114 9115 # Create beginnings of boundary polygon based on sts_boundary 9116 boundary_polygon = create_sts_boundary(base_name) 9117 9118 os.remove(order_file) 9119 9120 # Append the remaining part of the boundary polygon to be defined by 9121 # the user 9122 bounding_polygon_utm=[] 9123 for point in bounding_polygon: 9124 zone,easting,northing=redfearn(point[0],point[1]) 9125 bounding_polygon_utm.append([easting,northing]) 9126 9127 boundary_polygon.append(bounding_polygon_utm[3]) 9128 boundary_polygon.append(bounding_polygon_utm[4]) 9129 9130 #print 'boundary_polygon', boundary_polygon 9131 9132 9133 assert num.allclose(bounding_polygon_utm,boundary_polygon) 9134 9135 9136 extent_res=1000000 9137 meshname = 'urs_test_mesh' + '.tsh' 9138 interior_regions=None 9139 boundary_tags={'ocean': [0,1], 'otherocean': [2,3,4]} 9140 9141 # have to change boundary tags from last example because now bounding 9142 # polygon starts in different place. 9143 create_mesh_from_regions(boundary_polygon, 9144 boundary_tags=boundary_tags, 9145 maximum_triangle_area=extent_res, 9146 filename=meshname, 9147 interior_regions=interior_regions, 9148 verbose=False) 9149 9150 domain_fbound = Domain(meshname) 9151 domain_fbound.set_quantity('stage', tide) 9152 9153 9154 Bf = File_boundary(sts_file+'.sts', 9155 domain_fbound, 9156 boundary_polygon=boundary_polygon) 9157 time_vec = Bf.F.get_time() 9158 assert num.allclose(time_vec, times_ref) 9159 9160 for time_limit in [0.1, 0.2, 0.5, 1.0, 2.2, 3.0, 4.3, 6.0, 10.0]: 9161 Bf = File_boundary(sts_file+'.sts', 9162 domain_fbound, 9163 time_limit=time_limit, 9164 boundary_polygon=boundary_polygon) 9165 9166 time_vec = Bf.F.get_time() 9167 assert num.alltrue(time_vec < time_limit) 9168 9169 9170 try: 9171 Bf = File_boundary(sts_file+'.sts', 9172 domain_fbound, 9173 time_limit=-1, 9174 boundary_polygon=boundary_polygon) 9175 time_vec = Bf.F.get_time() 9176 print time_vec 9177 except AssertionError: 9178 pass 9179 else: 9180 raise Exception, 'Should have raised Exception here' 9035 9181 9036 9182 def test_lon_lat2grid(self): … … 11103 11249 11104 11250 suite = unittest.makeSuite(Test_Data_Manager,'test') 11105 #suite = unittest.makeSuite(Test_Data_Manager,'test_file_boundary_sts IV_sinewave_ordering')11251 #suite = unittest.makeSuite(Test_Data_Manager,'test_file_boundary_sts_time_limit') 11106 11252 #suite = unittest.makeSuite(Test_Data_Manager,'test_get_flow_through_cross_section_with_geo') 11107 11253 #suite = unittest.makeSuite(Test_Data_Manager,'covered_')
Note: See TracChangeset
for help on using the changeset viewer.