Changeset 309 for inundation/ga/storm_surge/pyvolution/least_squares.py
- Timestamp:
- Sep 16, 2004, 12:01:21 PM (21 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
inundation/ga/storm_surge/pyvolution/least_squares.py
r305 r309 12 12 class Interpolation(Mesh): 13 13 14 def __init__(self, vertex_coordinates, triangles, data ):14 def __init__(self, vertex_coordinates, triangles, data_coordinates): 15 15 """ Build interpolation matrix mapping from 16 16 function values at vertices to function values at data points … … 24 24 integers representing indices of all vertices in the mesh. 25 25 26 data : List of coordinate pairs [x, y] of data points26 data_coordinates: List of coordinate pairs [x, y] of data points 27 27 (or an nx2 Numeric array) 28 28 … … 33 33 34 34 #Convert input to Numeric arrays 35 data = array(data).astype(Float)35 data_coordinates = array(data_coordinates).astype(Float) 36 36 vertex_coordinates = array(vertex_coordinates).astype(Float) 37 37 triangles = array(triangles).astype(Int) … … 43 43 #Build n x m interpolation matrix 44 44 m = vertex_coordinates.shape[0] #Number of basis functions (1/vertex) 45 n = data .shape[0] #Number of data points45 n = data_coordinates.shape[0] #Number of data points 46 46 47 self. matrix= zeros((n,m), Float)47 self.A_m = zeros((n,m), Float) 48 48 49 49 #Compute matrix elements 50 50 for i in range(n): 51 #For each data point51 #For each data_coordinate point 52 52 53 x = data [i]53 x = data_coordinates[i] 54 54 for k in range(len(self)): 55 55 #For each triangle (brute force) … … 78 78 if sigma0 >= 0 and sigma1 >= 0 and sigma2 >= 0: 79 79 80 #Assign values to matrix80 #Assign values to A_m 81 81 j = self.triangles[k,0] #Global vertex id 82 self. matrix[i, j] = sigma082 self.A_m[i, j] = sigma0 83 83 84 84 j = self.triangles[k,1] #Global vertex id 85 self. matrix[i, j] = sigma185 self.A_m[i, j] = sigma1 86 86 87 87 j = self.triangles[k,2] #Global vertex id 88 self. matrix[i, j] = sigma288 self.A_m[i, j] = sigma2 89 89 90 91 92 93 94 95 96 90 def smooth_to_mesh(self, z): 91 from Numeric import zeros, array, Float,transpose,dot 92 from LinearAlgebra import solve_linear_equations 93 #Convert input to Numeric arrays 94 z = array(z).astype(Float) 95 At_m = transpose(self.A_m) 96 #print "z", z 97 #print "At_m",At_m 98 self.AtA_m = dot(At_m, self.A_m) 99 Atz_m = dot(At_m, z) 100 f = solve_linear_equations(self.AtA_m,Atz_m) 101 return f
Note: See TracChangeset
for help on using the changeset viewer.