Changeset 1632 for inundation/ga/storm_surge/pyvolution
- Timestamp:
- Jul 22, 2005, 5:59:19 PM (20 years ago)
- Location:
- inundation/ga/storm_surge/pyvolution
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
inundation/ga/storm_surge/pyvolution/general_mesh.py
r1587 r1632 173 173 174 174 175 def get_vertex_coordinates(self ):175 def get_vertex_coordinates(self, obj = False): 176 176 """Return all vertex coordinates. 177 177 Return all vertex coordinates for all triangles as an Nx6 array 178 178 (ordered as x0, y0, x1, y1, x2, y2 for each triangle) 179 """ 180 return self.vertex_coordinates 179 180 if obj is True, the x/y pairs are returned in a 3*N x 2 array. 181 FIXME, we might make that the default. 182 183 184 """ 185 186 if obj is True: 187 from Numeric import concatenate, reshape 188 V = self.vertex_coordinates 189 #return concatenate( (V[:,0:2], V[:,2:4], V[:,4:6]), axis=0) 190 191 N = V.shape[0] 192 return reshape(V, (3*N, 2)) 193 else: 194 return self.vertex_coordinates 181 195 182 196 … … 193 207 """ 194 208 195 #FIXME : Perhaps they should be ordered as in obj files??209 #FIXME (Ole): Perhaps they should be ordered as in obj files?? 196 210 #See quantity.get_vertex_values 211 #FIXME (Ole) - oh yes they should 197 212 198 213 from Numeric import zeros, Float … … 210 225 return vertex_coordinates 211 226 212 def get_vertices(self, 227 def get_vertices(self, indexes=None): 213 228 """Get connectivity 214 229 indexes is the set of element ids of interest … … 221 236 222 237 return take(self.triangles, indexes) 238 239 #FIXME - merge these two 240 def get_triangles(self, obj = False): 241 """Get connetivity 242 Return triangles (triplets of indices into point coordinates) 243 244 """ 245 246 if obj is True: 247 from Numeric import array, reshape, Int 248 m = len(self) #Number of triangles 249 M = 3*m #Total number of unique vertices 250 T = reshape(array(range(M)).astype(Int), (m,3)) 251 else: 252 T = self.triangles 253 254 return T 255 256 223 257 224 258 def get_unique_vertices(self, indexes=None): -
inundation/ga/storm_surge/pyvolution/interpolate_sww.py
r1396 r1632 84 84 85 85 86 def read_sww(self, file_name, quantity_name):86 def read_sww(self, file_name, quantity_name): 87 87 """ 88 88 Read in an sww file. … … 136 136 The time list is defined 137 137 """ 138 from load_mesh.loadASCII import 138 from load_mesh.loadASCII import export_points_file 139 139 140 141 140 xya_dict = {} 142 141 xya_dict['pointlist'] = self.point_coordinates 143 142 xya_dict['attributelist'] = self.interpolated_quantity 144 143 export_points_file(point_file, xya_dict) 144 145 145 146 146 #------------------------------------------------------------- -
inundation/ga/storm_surge/pyvolution/least_squares.py
r1627 r1632 279 279 vertex_coordinates: List of coordinate pairs [xi, eta] of 280 280 points constituting mesh (or a an m x 2 Numeric array) 281 Points may appear multiple times 282 (e.g. if vertices have discontinuities) 281 283 282 284 triangles: List of 3-tuples (or a Numeric array) of -
inundation/ga/storm_surge/pyvolution/quantity.py
r1626 r1632 538 538 else: 539 539 #Don't smooth 540 #obj machinery moved to general_mesh 540 541 541 542 # Create a V like [[0 1 2], [3 4 5]....[3*m-2 3*m-1 3*m]] 542 543 # These vert_id's will relate to the verts created below 543 m = len(self.domain) #Number of volumes 544 M = 3*m #Total number of unique vertices 545 V = reshape(array(range(M)).astype(Int), (m,3)) 544 #m = len(self.domain) #Number of volumes 545 #M = 3*m #Total number of unique vertices 546 #V = reshape(array(range(M)).astype(Int), (m,3)) 547 548 V = self.domain.get_triangles(obj=True) 549 #FIXME use get_vertices, when ready 546 550 547 551 A = self.vertex_values.flat -
inundation/ga/storm_surge/pyvolution/sparse.py
r605 r1632 115 115 B = array(other) 116 116 except: 117 print 'FIXME: Only Numeric types implemented so far' 117 msg = 'FIXME: Only Numeric types implemented so far' 118 raise msg 119 118 120 119 121 #Assume numeric types from now on -
inundation/ga/storm_surge/pyvolution/test_least_squares.py
r1469 r1632 925 925 926 926 927 def test_interpolation_from_discontinuous_vertex_values(self): 928 """test_interpolation_from_discontinuous_vertex_values. 929 This will test the format used internally in pyvolution and also 930 interpolation from sww files 931 """ 932 933 from mesh import Mesh 934 935 936 #Setup mesh used to represent discontinuous function 937 a = [0.0, 0.0] 938 b = [0.0, 2.0] 939 c = [2.0, 0.0] 940 d = [0.0, 4.0] 941 e = [2.0, 2.0] 942 f = [4.0, 0.0] 943 944 points = [b, a, c, 945 b, c, e, 946 e, c, f, 947 d, b, e] 948 949 #bac, bce, ecf, dbe 950 triangles = [[0,1,2], [3,4,5], [6,7,8], [9,10,11]] 951 952 953 vertex_values = [0.,0.,0.,1.,1.,1.,2.,2.,2.,7.,3.,3.] 954 955 956 957 #New datapoints where interpolated values are sought 958 data_points = [[0.0, 0.0], #T0 959 [0.5, 0.5], #T0 960 [1.5, 1.5], #T1 961 [2.5, 0.5], #T2 962 [0.0, 3.0], #T3 963 [1.0, 2.0], #In between T1 and T3 (T1 is used) FIXME? 964 [2.0, 1.0], #In between T1 and T2 (T1 is used) FIXME? 965 [1.0, 1.0]] #In between T1 and T0 (T0 is used) FIXME? 966 967 968 969 970 #Build interpolation matrix 971 interp = Interpolation(points, triangles, data_points) 972 #, alpha=0.0, precrop = True) 973 974 #print interp.A.todense() 975 #print vertex_values 976 977 #Interpolate using fitted surface 978 z = interp.interpolate(vertex_values) 979 980 #print z 981 982 assert allclose(z, [0,0,1,2,5,1,1,0]) 983 984 985 986 987 988 989 927 990 928 991 def test_fit_and_interpolation_with_different_origins(self): … … 1167 1230 mesh_dic = {} 1168 1231 mesh_dic['vertices'] = [[0.0, 0.0], 1169 1170 1232 [0.0, 5.0], 1233 [5.0, 0.0]] 1171 1234 mesh_dic['triangles'] = [[0, 2, 1]] 1172 1235 mesh_dic['segments'] = [[0, 1], [2, 0], [1, 2]] … … 1210 1273 1211 1274 def test_fit_to_msh_netcdf_fileII(self): 1212 from load_mesh.loadASCII import import_mesh_file, export_mesh_file1275 from load_mesh.loadASCII import import_mesh_file, export_mesh_file 1213 1276 import tempfile 1214 1277 import os … … 1217 1280 mesh_dic = {} 1218 1281 mesh_dic['vertices'] = [[0.0, 0.0], 1219 1220 1282 [0.0, 5.0], 1283 [5.0, 0.0]] 1221 1284 mesh_dic['triangles'] = [[0, 2, 1]] 1222 1285 mesh_dic['segments'] = [[0, 1], [2, 0], [1, 2]] -
inundation/ga/storm_surge/pyvolution/test_mesh.py
r1392 r1632 70 70 V = mesh.get_vertex_coordinates() 71 71 assert allclose(V[0], [0.0, 0.0, 4.0, 0.0, 0.0, 3.0]) 72 73 V = mesh.get_vertex_coordinates(obj=True) 74 assert allclose(V, [ [0.0, 0.0], 75 [4.0, 0.0], 76 [0.0, 3.0] ]) 72 77 73 78 V0 = mesh.get_vertex_coordinate(0, 0)
Note: See TracChangeset
for help on using the changeset viewer.