Changeset 488
- Timestamp:
- Nov 5, 2004, 4:42:19 PM (20 years ago)
- Location:
- inundation/ga/storm_surge/pyvolution
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
inundation/ga/storm_surge/pyvolution/cornell_room.py
r320 r488 12 12 Transmissive_boundary, Time_boundary, Constant_height 13 13 14 from mesh_factory import from_polyfile 14 from mesh_factory import from_polyfile, rectangular 15 15 from Numeric import array 16 from math import sqrt 17 from least_squares import Interpolation 16 18 17 19 18 20 print 'Creating domain' 19 #points, triangles, values = from_polyfile('cornell_room_medres') 20 points, triangles, values = from_polyfile('hires2') 21 #data_points, _, data_values = from_polyfile('cornell_room_medres') 22 #points, triangles, values = from_polyfile('hires2') 23 data_points, _, data_values = from_polyfile('hires2') 21 24 22 25 26 #Regrid onto numerically stable mesh 27 # 28 #Compute regular mesh based on resolution and extent of data 29 data_points = array(data_points) 30 pmax = max(data_points) 31 pmin = min(data_points) 32 33 M = len(data_points) 34 35 N = int(0.8*sqrt(M)) 36 37 #print N 38 39 mesh_points, vertices, boundary = rectangular(N, N, 40 len1=pmax[0]-pmin[0], 41 len2=pmax[1]-pmin[1], 42 origin = pmin) 43 44 45 #Compute smooth surface on new mesh based on values from old (regrid) 46 print 'Interp' 47 interp = Interpolation(mesh_points, vertices, data_points, alpha=0.1) 48 mesh_values = interp.fit(data_values) 49 print 'Len mesh values', len(mesh_values) 50 print 'Len mesh points', len(mesh_points) 51 52 23 53 #Create shallow water domain 24 domain = Domain(points, triangles) 25 54 print 'Creating domain' 55 domain = Domain(mesh_points, vertices) #, boundary) 56 26 57 domain.check_integrity() 27 58 domain.default_order = 2 … … 47 78 48 79 print 'Field values' 49 domain.set_quantity('elevation', values)80 domain.set_quantity('elevation', mesh_values) 50 81 domain.set_quantity('friction', manning) 51 82 -
inundation/ga/storm_surge/pyvolution/least_squares.py
r485 r488 3 3 Implements a penalised least-squares fit and associated interpolations. 4 4 5 The p analty term (or smoothing term) is controlled by the smoothing5 The penalty term (or smoothing term) is controlled by the smoothing 6 6 parameter alpha. 7 7 With a value of alpha=0, the fit function will attempt … … 20 20 21 21 #FIXME (Ole): Currently datapoints outside the triangular mesh are ignored. 22 # Is there a clean way of in lcuding them?22 # Is there a clean way of including them? 23 23 24 24 … … 152 152 Inputs: 153 153 154 vertex_coordinates: List of coordinate pairs [xi, eta] of points155 154 vertex_coordinates: List of coordinate pairs [xi, eta] of 155 points constituting mesh (or a an m x 2 Numeric array) 156 156 157 157 triangles: List of 3-tuples (or a Numeric array) of 158 158 integers representing indices of all vertices in the mesh. 159 159 160 point_coordinates: List of coordinate pairs [x, y] of data points 161 (or an nx2 Numeric array) 160 point_coordinates: List of coordinate pairs [x, y] of 161 data points (or an nx2 Numeric array) 162 If point_coordinates is absent, only smoothing matrix will 163 be built 162 164 163 165 alpha: Smoothing parameter … … 504 506 def fit_points(self, z): 505 507 """Like fit, but more robust when each point has two or more attributes 506 FIXME (Ole): The name fit_points doesn't carry any meaning for me.507 How about something like fit_multiple or fit_columns?508 FIXME (Ole): The name fit_points doesn't carry any meaning 509 for me. How about something like fit_multiple or fit_columns? 508 510 """ 509 511 … … 529 531 530 532 def interpolate(self, f): 531 """ Compute predicted valuesat data points implied in self.A.533 """Evaluate smooth surface f at data points implied in self.A. 532 534 533 535 The mesh values representing a smooth surface are … … 546 548 547 549 548 549 #FIXME: We will need a method 'evaluate(self):' that will interpolate550 #a computed surface living on the mesh onto a collection of551 #arbitrary data points552 #553 #Precondition: self.fit(z) has stored its result in self.f.554 #555 #Input: data_points556 #Algorithm:557 # 1 Build a new temporary A matrix based on mesh and new data points558 # 2 Apply it to self.f (return A*self.f)559 #560 # ON561 562 563 564 550 #------------------------------------------------------------- 565 551 if __name__ == "__main__": -
inundation/ga/storm_surge/pyvolution/mesh_factory.py
r486 r488 86 86 points = [] #x, y 87 87 values = [] #z 88 vertex_values = [] #Repeated z88 ##vertex_values = [] #Repeated z 89 89 triangles = [] #v0, v1, v2 90 90 … … 172 172 173 173 triangles.append([j0, j1, j2]) 174 vertex_values.append([values[j0], values[j1], values[j2]])174 ##vertex_values.append([values[j0], values[j1], values[j2]]) 175 175 else: 176 176 offending +=1 177 177 178 178 print 'Removed %d offending triangles out of %d' %(offending, len(lines)) 179 return points, triangles, v ertex_values179 return points, triangles, values
Note: See TracChangeset
for help on using the changeset viewer.