Changeset 8576
- Timestamp:
- Sep 13, 2012, 11:49:08 PM (13 years ago)
- Location:
- trunk/anuga_core/source/anuga/operators
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/anuga_core/source/anuga/operators/set_elevation_operators.py
r8483 r8576 141 141 142 142 elevation = self.get_elevation() 143 144 if elevation is None: 145 return False 143 146 144 147 updated = True … … 186 189 187 190 188 if elevation is None: 189 msg = ('Attribute elevation must be specified in '+self.__name__+ 190 ' before attempting to call it') 191 raise Exception(msg) 191 # if elevation is None: 192 # msg = 'Attribute elevation must be specified' 193 # raise Exception(msg) 192 194 193 195 return elevation -
trunk/anuga_core/source/anuga/operators/set_stage_operators.py
r8506 r8576 62 62 """ 63 63 64 64 65 if self.indices is []: 65 66 return 66 67 67 68 stage = self.get_stage() 69 70 if stage is None: 71 return 68 72 69 73 if self.verbose is True: -
trunk/anuga_core/source/anuga/operators/test_erosion_operators.py
r8575 r8576 13 13 from anuga.config import time_format 14 14 15 from erosion_operators import *15 from anuga.operators.erosion_operators import Erosion_operator 16 16 17 17 import numpy as num … … 30 30 31 31 32 def test_ set_erosion_operator_simple(self):32 def test_erosion_operator_simple(self): 33 33 from anuga.config import rho_a, rho_w, eta_w 34 34 from math import pi, cos, sin -
trunk/anuga_core/source/anuga/operators/test_set_operators.py
r8575 r8576 132 132 stage_ex = [ -5., -5., 1., -5.] 133 133 134 print domain.quantities['elevation'].centroid_values135 print domain.quantities['stage'].centroid_values136 print domain.quantities['xmomentum'].centroid_values137 print domain.quantities['ymomentum'].centroid_values134 #print domain.quantities['elevation'].centroid_values 135 #print domain.quantities['stage'].centroid_values 136 #print domain.quantities['xmomentum'].centroid_values 137 #print domain.quantities['ymomentum'].centroid_values 138 138 139 139 assert num.allclose(domain.quantities['stage'].centroid_values, stage_ex) … … 143 143 144 144 145 def test_set_erosion_operator_simple(self):146 from anuga.config import rho_a, rho_w, eta_w147 from math import pi, cos, sin148 149 a = [0.0, 0.0]150 b = [0.0, 2.0]151 c = [2.0, 0.0]152 d = [0.0, 4.0]153 e = [2.0, 2.0]154 f = [4.0, 0.0]155 156 points = [a, b, c, d, e, f]157 # bac, bce, ecf, dbe158 vertices = [[1,0,2], [1,2,4], [4,2,5], [3,1,4]]159 160 domain = Domain(points, vertices)161 162 #Flat surface with 1m of water163 domain.set_quantity('elevation', 0)164 domain.set_quantity('stage', 1.0)165 domain.set_quantity('friction', 0)166 domain.set_quantity('xmomentum',2.0)167 domain.set_quantity('ymomentum',3.0)168 169 Br = Reflective_boundary(domain)170 domain.set_boundary({'exterior': Br})171 172 173 # print domain.quantities['stage'].centroid_values174 # print domain.quantities['xmomentum'].centroid_values175 # print domain.quantities['ymomentum'].centroid_values176 177 # Apply operator to these triangles178 indices = [0,1,3]179 180 181 operator = Erosion_operator(domain, indices=indices)182 183 # Apply Operator184 domain.timestep = 2.0185 operator()186 187 stage_ex = [ 3., 3., 1., 3.]188 189 print domain.quantities['elevation'].centroid_values190 print domain.quantities['stage'].centroid_values191 print domain.quantities['xmomentum'].centroid_values192 print domain.quantities['ymomentum'].centroid_values193 194 assert num.allclose(domain.quantities['stage'].centroid_values, stage_ex)195 assert num.allclose(domain.quantities['xmomentum'].centroid_values, 0.0)196 assert num.allclose(domain.quantities['ymomentum'].centroid_values, 0.0)197 198 199 200 # def test_rate_operator_rate_from_file(self):201 # from anuga.config import rho_a, rho_w, eta_w202 # from math import pi, cos, sin203 #204 # a = [0.0, 0.0]205 # b = [0.0, 2.0]206 # c = [2.0, 0.0]207 # d = [0.0, 4.0]208 # e = [2.0, 2.0]209 # f = [4.0, 0.0]210 #211 # points = [a, b, c, d, e, f]212 # # bac, bce, ecf, dbe213 # vertices = [[1,0,2], [1,2,4], [4,2,5], [3,1,4]]214 #215 #216 # #---------------------------------217 # #Typical ASCII file218 # #---------------------------------219 # finaltime = 1200220 # filename = 'test_file_function'221 # fid = open(filename + '.txt', 'w')222 # start = time.mktime(time.strptime('2000', '%Y'))223 # dt = 60 #One minute intervals224 # t = 0.0225 # while t <= finaltime:226 # t_string = time.strftime(time_format, time.gmtime(t+start))227 # fid.write('%s, %f %f %f\n' %(t_string, 2*t, t**2, sin(t*pi/600)))228 # t += dt229 #230 # fid.close()231 #232 # #Convert ASCII file to NetCDF (Which is what we really like!)233 # timefile2netcdf(filename+'.txt')234 #235 #236 # #Create file function from time series237 # F = file_function(filename + '.tms',238 # quantities = ['Attribute0',239 # 'Attribute1',240 # 'Attribute2'])241 #242 # #Now try interpolation243 # for i in range(20):244 # t = i*10245 # q = F(t)246 #247 # #Exact linear intpolation248 # assert num.allclose(q[0], 2*t)249 # if i%6 == 0:250 # assert num.allclose(q[1], t**2)251 # assert num.allclose(q[2], sin(t*pi/600))252 #253 # #Check non-exact254 #255 # t = 90 #Halfway between 60 and 120256 # q = F(t)257 # assert num.allclose( (120**2 + 60**2)/2, q[1] )258 # assert num.allclose( (sin(120*pi/600) + sin(60*pi/600))/2, q[2] )259 #260 #261 # t = 100 #Two thirds of the way between between 60 and 120262 # q = F(t)263 # assert num.allclose( 2*120**2/3 + 60**2/3, q[1] )264 # assert num.allclose( 2*sin(120*pi/600)/3 + sin(60*pi/600)/3, q[2] )265 #266 # #os.remove(filename + '.txt')267 # #os.remove(filename + '.tms')268 #269 #270 # domain = Domain(points, vertices)271 #272 # #Flat surface with 1m of water273 # domain.set_quantity('elevation', 0)274 # domain.set_quantity('stage', 1.0)275 # domain.set_quantity('friction', 0)276 #277 # Br = Reflective_boundary(domain)278 # domain.set_boundary({'exterior': Br})279 #280 ## print domain.quantities['elevation'].centroid_values281 ## print domain.quantities['stage'].centroid_values282 ## print domain.quantities['xmomentum'].centroid_values283 ## print domain.quantities['ymomentum'].centroid_values284 #285 # # Apply operator to these triangles286 # indices = [0,1,3]287 #288 #289 # rate = file_function('test_file_function.tms', quantities=['Attribute1'])290 #291 # factor = 1000.0292 # default_rate= 17.7293 #294 # operator = Rate_operator(domain, rate=rate, factor=factor, \295 # indices=indices, default_rate = default_rate)296 #297 #298 # # Apply Operator299 # domain.set_starttime(360.0)300 # domain.timestep = 1.0301 #302 # operator()303 #304 #305 # d = domain.get_time()**2 * factor + 1.0306 # stage_ex0 = [ d, d, 1., d]307 #308 ## print d, domain.get_time(), F(360.0)309 #310 ## print domain.quantities['elevation'].centroid_values311 ## print domain.quantities['stage'].centroid_values312 ## print domain.quantities['xmomentum'].centroid_values313 ## print domain.quantities['ymomentum'].centroid_values314 #315 # assert num.allclose(domain.quantities['stage'].centroid_values, stage_ex0)316 # assert num.allclose(domain.quantities['xmomentum'].centroid_values, 0.0)317 # assert num.allclose(domain.quantities['ymomentum'].centroid_values, 0.0)318 #319 #320 # domain.set_starttime(-10.0)321 # domain.timestep = 1.0322 #323 # try:324 # operator()325 # except:326 # pass327 # else:328 # raise Exception('Should have raised an exception, time too early')329 #330 #331 # domain.set_starttime(1300.0)332 # domain.timestep = 1.0333 #334 # operator()335 #336 # d = default_rate*factor + d337 # stage_ex1 = [ d, d, 1., d]338 #339 ## print domain.quantities['elevation'].centroid_values340 ## print domain.quantities['stage'].centroid_values341 ## print domain.quantities['xmomentum'].centroid_values342 ## print domain.quantities['ymomentum'].centroid_values343 #344 # assert num.allclose(domain.quantities['stage'].centroid_values, stage_ex1)345 # assert num.allclose(domain.quantities['xmomentum'].centroid_values, 0.0)346 # assert num.allclose(domain.quantities['ymomentum'].centroid_values, 0.0)347 348 349 # def test_rate_operator_functions_rate_default_rate(self):350 # from anuga.config import rho_a, rho_w, eta_w351 # from math import pi, cos, sin352 #353 # a = [0.0, 0.0]354 # b = [0.0, 2.0]355 # c = [2.0, 0.0]356 # d = [0.0, 4.0]357 # e = [2.0, 2.0]358 # f = [4.0, 0.0]359 #360 # points = [a, b, c, d, e, f]361 # # bac, bce, ecf, dbe362 # vertices = [[1,0,2], [1,2,4], [4,2,5], [3,1,4]]363 #364 # domain = Domain(points, vertices)365 #366 # #Flat surface with 1m of water367 # domain.set_quantity('elevation', 0)368 # domain.set_quantity('stage', 1.0)369 # domain.set_quantity('friction', 0)370 #371 # Br = Reflective_boundary(domain)372 # domain.set_boundary({'exterior': Br})373 #374 # verbose = False375 #376 # if verbose:377 # print domain.quantities['elevation'].centroid_values378 # print domain.quantities['stage'].centroid_values379 # print domain.quantities['xmomentum'].centroid_values380 # print domain.quantities['ymomentum'].centroid_values381 #382 # # Apply operator to these triangles383 # indices = [0,1,3]384 # factor = 10.0385 #386 #387 # def main_rate(t):388 # if t > 20:389 # msg = 'Model time exceeded.'390 # raise Modeltime_too_late, msg391 # else:392 # return 3.0 * t + 7.0393 #394 # default_rate = lambda t: 3*t + 7395 #396 #397 # operator = Rate_operator(domain, rate=main_rate, factor=factor, \398 # indices=indices, default_rate = default_rate)399 #400 #401 # # Apply Operator402 # domain.timestep = 2.0403 # operator()404 #405 # t = operator.get_time()406 # d = operator.get_timestep()*main_rate(t)*factor + 1407 # stage_ex = [ d, d, 1., d]408 #409 # if verbose:410 # print domain.quantities['elevation'].centroid_values411 # print domain.quantities['stage'].centroid_values412 # print domain.quantities['xmomentum'].centroid_values413 # print domain.quantities['ymomentum'].centroid_values414 #415 # assert num.allclose(domain.quantities['stage'].centroid_values, stage_ex)416 # assert num.allclose(domain.quantities['xmomentum'].centroid_values, 0.0)417 # assert num.allclose(domain.quantities['ymomentum'].centroid_values, 0.0)418 #419 # domain.set_starttime(30.0)420 # domain.timestep = 1.0421 # operator()422 #423 # t = operator.get_time()424 # d = operator.get_timestep()*default_rate(t)*factor + d425 # stage_ex = [ d, d, 1., d]426 #427 # if verbose:428 # print domain.quantities['elevation'].centroid_values429 # print domain.quantities['stage'].centroid_values430 # print domain.quantities['xmomentum'].centroid_values431 # print domain.quantities['ymomentum'].centroid_values432 #433 # assert num.allclose(domain.quantities['stage'].centroid_values, stage_ex)434 # assert num.allclose(domain.quantities['xmomentum'].centroid_values, 0.0)435 # assert num.allclose(domain.quantities['ymomentum'].centroid_values, 0.0)436 145 437 146
Note: See TracChangeset
for help on using the changeset viewer.