Changeset 4820
- Timestamp:
- Nov 16, 2007, 2:23:00 PM (17 years ago)
- Files:
-
- 5 edited
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
anuga_core/source/anuga/abstract_2d_finite_volumes/generic_boundary_conditions.py
r4809 r4820 198 198 Boundary.__init__(self) 199 199 200 # Get x,y vertex coordinates for all triangles200 # Get x,y vertex coordinates for all triangles 201 201 V = domain.vertex_coordinates 202 202 203 # Compute midpoint coordinates for all boundary elements204 # Only a subset may be invoked when boundary is evaluated but205 # we don't know which ones at this stage since this object can206 # be attached to207 # any tagged boundary later on.203 # Compute midpoint coordinates for all boundary elements 204 # Only a subset may be invoked when boundary is evaluated but 205 # we don't know which ones at this stage since this object can 206 # be attached to 207 # any tagged boundary later on. 208 208 209 209 if verbose: print 'Find midpoint coordinates of entire boundary' … … 216 216 217 217 218 # Make ordering unique #FIXME: should this happen in domain.py?218 # Make ordering unique #FIXME: should this happen in domain.py? 219 219 boundary_keys.sort() 220 220 221 # Record ordering #FIXME: should this also happen in domain.py?221 # Record ordering #FIXME: should this also happen in domain.py? 222 222 self.boundary_indices = {} 223 223 for i, (vol_id, edge_id) in enumerate(boundary_keys): … … 228 228 x2, y2 = V[base_index+2, :] 229 229 230 # Compute midpoints230 # Compute midpoints 231 231 if edge_id == 0: m = array([(x1 + x2)/2, (y1 + y2)/2]) 232 232 if edge_id == 1: m = array([(x0 + x2)/2, (y0 + y2)/2]) 233 233 if edge_id == 2: m = array([(x1 + x0)/2, (y1 + y0)/2]) 234 234 235 # Convert to absolute UTM coordinates235 # Convert to absolute UTM coordinates 236 236 m[0] += xllcorner 237 237 m[1] += yllcorner 238 238 239 # Register point and index239 # Register point and index 240 240 self.midpoint_coordinates[i,:] = m 241 241 242 # Register index of this boundary edge for use with evaluate242 # Register index of this boundary edge for use with evaluate 243 243 self.boundary_indices[(vol_id, edge_id)] = i 244 244 … … 252 252 self.domain = domain 253 253 254 #Test 254 # Test 255 256 # Here we'll flag indices outside the mesh as a warning 257 # as suggested by Joaquim Luis in sourceforge posting 258 # November 2007 259 # We won't make it an error as it is conceivable that 260 # only part of mesh boundary is actually used with a given 261 # file boundary sww file. 262 if hasattr(self.F, 'indices_outside_mesh') and\ 263 len(self.F.indices_outside_mesh) > 0: 264 msg = 'WARNING: File_boundary has points outside the mesh ' 265 msg += 'given in %s. ' %filename 266 msg += 'See warning message issued by Interpolation_function ' 267 msg += 'for details (should appear above somewhere if ' 268 msg += 'verbose is True).\n' 269 msg += 'This is perfectly OK as long as the points that are ' 270 msg += 'outside aren\'t used on the actual boundary segment.' 271 if verbose is True: 272 print msg 273 #raise Exception(msg) 274 275 255 276 q = self.F(0, point_id=0) 256 277 … … 279 300 x,y=self.midpoint_coordinates[i,:] 280 301 msg = 'NAN value found in file_boundary at ' 281 msg += 'point id #%d: (%.2f, %.2f)' %(i, x, y) 282 #print msg 302 msg += 'point id #%d: (%.2f, %.2f).\n' %(i, x, y) 303 304 if hasattr(self.F, 'indices_outside_mesh') and\ 305 len(self.F.indices_outside_mesh) > 0: 306 # Check if NAN point is due it being outside 307 # boundary defined in sww file. 308 309 if i in self.F.indices_outside_mesh: 310 msg += 'This point refers to one outside the ' 311 msg += 'mesh defined by the file %s.\n'\ 312 %self.F.filename 313 msg += 'Make sure that the file covers ' 314 msg += 'the boundary segment it is assigned to ' 315 msg += 'in set_boundary.' 316 else: 317 msg += 'This point is inside the mesh defined ' 318 msg += 'the file %s.\n' %self.F.filename 319 msg += 'Check this file for NANs.' 283 320 raise Exception, msg 284 321 285 322 return res 286 323 else: 287 # raise 'Boundary call without point_id not implemented'288 # FIXME: What should the semantics be?324 # raise 'Boundary call without point_id not implemented' 325 # FIXME: What should the semantics be? 289 326 return self.F(t) 290 327 -
anuga_core/source/anuga/abstract_2d_finite_volumes/util.py
r4787 r4820 75 75 76 76 77 # FIXME (OLE): Should check origin of domain against that of file78 # In fact, this is where origin should be converted to that of domain79 # Also, check that file covers domain fully.80 81 # Take into account:82 # - domain's georef83 # - sww file's georef84 # - interpolation points as absolute UTM coordinates77 # FIXME (OLE): Should check origin of domain against that of file 78 # In fact, this is where origin should be converted to that of domain 79 # Also, check that file covers domain fully. 80 81 # Take into account: 82 # - domain's georef 83 # - sww file's georef 84 # - interpolation points as absolute UTM coordinates 85 85 86 86 … … 136 136 137 137 f.starttime = starttime 138 f.filename = filename 138 139 139 140 if domain is not None: … … 213 214 214 215 215 # FIXME: Check that model origin is the same as file's origin216 # (both in UTM coordinates)217 # If not - modify those from file to match domain218 # (origin should be passed in)219 # Take this code from e.g. dem2pts in data_manager.py220 # FIXME: Use geo_reference to read and write xllcorner...216 # FIXME: Check that model origin is the same as file's origin 217 # (both in UTM coordinates) 218 # If not - modify those from file to match domain 219 # (origin should be passed in) 220 # Take this code from e.g. dem2pts in data_manager.py 221 # FIXME: Use geo_reference to read and write xllcorner... 221 222 222 223 … … 226 227 from Numeric import array, zeros, Float, alltrue, concatenate, reshape 227 228 228 # Open NetCDF file229 # Open NetCDF file 229 230 if verbose: print 'Reading', filename 230 231 fid = NetCDFFile(filename, 'r') … … 234 235 235 236 if quantity_names is None or len(quantity_names) < 1: 236 # If no quantities are specified get quantities from file237 # x, y, time are assumed as the independent variables so238 # they are excluded as potentiol quantities237 # If no quantities are specified get quantities from file 238 # x, y, time are assumed as the independent variables so 239 # they are excluded as potentiol quantities 239 240 quantity_names = [] 240 241 for name in fid.variables.keys(): … … 253 254 254 255 255 # Now assert that requested quantitites (and the independent ones)256 # are present in file256 # Now assert that requested quantitites (and the independent ones) 257 # are present in file 257 258 missing = [] 258 259 for quantity in ['time'] + quantity_names: … … 266 267 raise Exception, msg 267 268 268 # Decide whether this data has a spatial dimension269 # Decide whether this data has a spatial dimension 269 270 spatial = True 270 271 for quantity in ['x', 'y']: … … 280 281 raise msg 281 282 282 # Get first timestep283 # Get first timestep 283 284 try: 284 285 starttime = fid.starttime[0] … … 287 288 raise msg 288 289 289 # Get variables290 # if verbose: print 'Get variables'290 # Get variables 291 # if verbose: print 'Get variables' 291 292 time = fid.variables['time'][:] 292 293 293 294 # Get time independent stuff 294 295 if spatial: 295 # Get origin296 # Get origin 296 297 xllcorner = fid.xllcorner[0] 297 298 yllcorner = fid.yllcorner[0] … … 307 308 308 309 if interpolation_points is not None: 309 # Adjust for georef310 # Adjust for georef 310 311 interpolation_points[:,0] -= xllcorner 311 312 interpolation_points[:,1] -= yllcorner … … 316 317 if domain_starttime is not None: 317 318 318 # If domain_startime is *later* than starttime,319 # move time back - relative to domain's time319 # If domain_startime is *later* than starttime, 320 # move time back - relative to domain's time 320 321 if domain_starttime > starttime: 321 322 time = time - domain_starttime + starttime 322 323 323 # FIXME Use method in geo to reconcile324 # if spatial:325 # assert domain.geo_reference.xllcorner == xllcorner326 # assert domain.geo_reference.yllcorner == yllcorner327 # assert domain.geo_reference.zone == zone324 # FIXME Use method in geo to reconcile 325 # if spatial: 326 # assert domain.geo_reference.xllcorner == xllcorner 327 # assert domain.geo_reference.yllcorner == yllcorner 328 # assert domain.geo_reference.zone == zone 328 329 329 330 if verbose: … … 345 346 346 347 347 #from least_squares import Interpolation_function348 348 from anuga.fit_interpolate.interpolate import Interpolation_function 349 349 -
anuga_core/source/anuga/fit_interpolate/interpolate.py
r4779 r4820 521 521 522 522 523 # Check that all interpolation points fall within 524 # mesh boundary as defined by triangles and vertex_coordinates. 525 from anuga.abstract_2d_finite_volumes.neighbour_mesh import Mesh 526 from anuga.utilities.polygon import outside_polygon 527 528 mesh = Mesh(vertex_coordinates, triangles) 529 530 indices = outside_polygon(interpolation_points, 531 mesh.get_boundary_polygon()) 532 533 534 # Record result 535 self.indices_outside_mesh = indices 536 537 # Report 538 if len(indices) > 0: 539 msg = 'Interpolation points in Interpolation function fall ' 540 msg += 'outside specified mesh. ' 541 msg += 'Offending points:\n' 542 for i in indices: 543 msg += '%d: %s\n' %(i, interpolation_points[i]) 544 545 # Joaquim Luis suggested this as an Exception, so 546 # that the user can now what the problem is rather than 547 # looking for NaN's. However, NANs are handy as they can 548 # be ignored leaving good points for continued processing. 549 if verbose: 550 print msg 551 #raise Exception(msg) 552 553 554 555 523 556 m = len(self.interpolation_points) 524 557 p = len(self.time) … … 626 659 oldindex = self.index #Time index 627 660 628 # Find current time slot661 # Find current time slot 629 662 while t > self.time[self.index]: self.index += 1 630 663 while t < self.time[self.index]: self.index -= 1 631 664 632 665 if t == self.time[self.index]: 633 # Protect against case where t == T[-1] (last time)634 # - also works in general when t == T[i]666 # Protect against case where t == T[-1] (last time) 667 # - also works in general when t == T[i] 635 668 ratio = 0 636 669 else: 637 # t is now between index and index+1670 # t is now between index and index+1 638 671 ratio = (t - self.time[self.index])/\ 639 672 (self.time[self.index+1] - self.time[self.index]) 640 673 641 # Compute interpolated values674 # Compute interpolated values 642 675 q = zeros(len(self.quantity_names), Float) 643 # print "self.precomputed_values", self.precomputed_values676 # print "self.precomputed_values", self.precomputed_values 644 677 for i, name in enumerate(self.quantity_names): 645 678 Q = self.precomputed_values[name] 646 679 647 680 if self.spatial is False: 648 # If there is no spatial info681 # If there is no spatial info 649 682 assert len(Q.shape) == 1 650 683 … … 654 687 else: 655 688 if x is not None and y is not None: 656 # Interpolate to x, y689 # Interpolate to x, y 657 690 658 691 raise 'x,y interpolation not yet implemented' 659 692 else: 660 # Use precomputed point693 # Use precomputed point 661 694 Q0 = Q[self.index, point_id] 662 695 if ratio > 0: 663 696 Q1 = Q[self.index+1, point_id] 664 697 665 # Linear temporal interpolation698 # Linear temporal interpolation 666 699 if ratio > 0: 667 700 if Q0 == NAN and Q1 == NAN: … … 673 706 674 707 675 # Return vector of interpolated values676 # if len(q) == 1:677 # return q[0]678 # else:679 # return q680 681 682 # Return vector of interpolated values683 # FIXME:708 # Return vector of interpolated values 709 # if len(q) == 1: 710 # return q[0] 711 # else: 712 # return q 713 714 715 # Return vector of interpolated values 716 # FIXME: 684 717 if self.spatial is True: 685 718 return q 686 719 else: 687 # Replicate q according to x and y688 # This is e.g used for Wind_stress720 # Replicate q according to x and y 721 # This is e.g used for Wind_stress 689 722 if x is None or y is None: 690 723 return q … … 696 729 else: 697 730 from Numeric import ones, Float 698 # x is a vector - Create one constant column for each value731 # x is a vector - Create one constant column for each value 699 732 N = len(x) 700 733 assert len(y) == N, 'x and y must have same length' -
anuga_core/source/anuga/fit_interpolate/test_interpolate.py
r4779 r4820 1299 1299 # interpolations in both time and space 1300 1300 1301 # Three timesteps1301 # Three timesteps 1302 1302 time = [1.0, 5.0, 6.0] 1303 1303 1304 # Setup mesh used to represent fitted function1304 # Setup mesh used to represent fitted function 1305 1305 a = [0.0, 0.0] 1306 1306 b = [0.0, 2.0] … … 1315 1315 1316 1316 1317 # New datapoints where interpolated values are sought1317 # New datapoints where interpolated values are sought 1318 1318 interpolation_points = [[ 0.0, 0.0], 1319 1319 [ 0.5, 0.5], … … 1323 1323 [ 545354534, 4354354353]] # outside the mesh 1324 1324 1325 # One quantity1325 # One quantity 1326 1326 Q = zeros( (3,6), Float ) 1327 1327 1328 # Linear in time and space1328 # Linear in time and space 1329 1329 for i, t in enumerate(time): 1330 1330 Q[i, :] = t*linear_function(points) 1331 1331 1332 #Check interpolation of one quantity using interpolaton points) 1332 # Check interpolation of one quantity using interpolaton points) 1333 1333 1334 I = Interpolation_function(time, Q, 1334 1335 vertex_coordinates = points, … … 1336 1337 interpolation_points = interpolation_points, 1337 1338 verbose = False) 1338 1339 1339 1340 1340 1341 assert alltrue(I.precomputed_values['Attribute'][:,4] != NAN) -
anuga_validation/automated_validation_tests/pixel_registration/README.txt
r4810 r4820 8 8 the boundary condition. 9 9 10 After Joaquim's fix (November 2007), this passed. 10 -- 11 It turned out that this test didn't reveal the registration problem after all 12 (see sourceforge postings Nov 2007), but rather that ANUGA didn't 13 give a proper error if the domain exceeds the boundary defined in Field_boundary. 11 14 12 The file layer01.png shows the polygons constituting this example. 15 We don't want to raise an Exception, but the code now has appropriate warnings. 16 This directory is therefore not really part of the validation suite after all. 17
Note: See TracChangeset
for help on using the changeset viewer.