Changeset 835
- Timestamp:
- Feb 7, 2005, 10:02:41 AM (20 years ago)
- Location:
- inundation/ga/storm_surge/pyvolution
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
inundation/ga/storm_surge/pyvolution/generic_boundary_conditions.py
r623 r835 116 116 117 117 118 class File_boundary (Boundary):118 class File_boundary_time(Boundary): 119 119 """Boundary values obtained from file and interpolated. 120 120 conserved quantities as a function of time. … … 123 123 124 124 No spatial info assumed. 125 FIXME: Soon to be Obsolete 125 126 """ 126 127 … … 156 157 t = self.domain.time 157 158 return self.F(t) 159 160 161 162 163 class File_boundary(Boundary): 164 """Boundary values obtained from file and interpolated. 165 conserved quantities as a function of time. 166 167 Assumes that file contains a time series and possibly 168 also spatial info. 169 See docstring for File_function in util.py for details about 170 admissible file formats 171 """ 172 173 174 def __init__(self, filename, domain): 175 import time 176 from Numeric import array 177 from config import time_format 178 from util import File_function 179 180 Boundary.__init__(self) 181 182 self.F = File_function(filename, domain) 183 self.domain = domain 184 185 #Get x,y vertex coordinates for all triangles 186 V = domain.vertex_coordinates 187 188 #Compute midpoint coordinates for all boundary elements 189 midpoint_coordinates = {} 190 for vol_id, edge_id in domain.boundary.keys(): 191 192 x0 = V[vol_id, 0]; y0 = V[vol_id, 1] 193 x1 = V[vol_id, 2]; y1 = V[vol_id, 3] 194 x2 = V[vol_id, 4]; y2 = V[vol_id, 5] 195 196 #Midpoints 197 if edge_id == 0: m = array([(x1 + x2)/2, (y1 + y2)/2]) 198 if edge_id == 1: m = array([(x0 + x2)/2, (y0 + y2)/2]) 199 if edge_id == 2: m = array([(x1 + x0)/2, (y1 + y0)/2]) 200 midpoint_coordinates[(vol_id, edge_id)] = m 201 202 self.midpoint_coordinates = midpoint_coordinates 203 204 #Test 205 q = self.F(0, 0, 0) 206 207 d = len(domain.conserved_quantities) 208 msg = 'Values specified in file must be a list or an array of length %d' %d 209 assert len(q) == d, msg 210 211 212 def __repr__(self): 213 return 'File boundary' 214 215 def evaluate(self, vol_id=None, edge_id=None): 216 """Return linearly interpolated values based on domain.time 217 218 vol_id and edge_id are ignored 219 """ 220 221 t = self.domain.time 222 223 if vol_id is not None and edge_id is not None: 224 x, y = self.midpoint_coordinates[ vol_id, edge_id ] 225 return self.F(t, x, y) 226 else: 227 return self.F(t) 228 229 230 231 158 232 159 233 -
inundation/ga/storm_surge/pyvolution/test_data_manager.py
r834 r835 560 560 fid.close() 561 561 562 os.remove(filename) 563 os.remove(root + '.xya') 564 562 563 os.remove(root + '.xya') 564 os.remove(root + '.dem') 565 os.remove(root + '.asc') 565 566 566 567 -
inundation/ga/storm_surge/pyvolution/test_generic_boundary_conditions.py
r773 r835 101 101 102 102 103 def test_fileboundary (self):103 def test_fileboundary_time_only(self): 104 104 """Test that boundary values can be read from file and interpolated 105 105 """ … … 113 113 a = [0.0, 0.0] 114 114 b = [0.0, 2.0] 115 c = [2.0, 0.0]115 c = [2.0, 0.0] 116 116 d = [0.0, 4.0] 117 117 e = [2.0, 2.0] 118 f = [4.0, 0.0]118 f = [4.0, 0.0] 119 119 120 120 points = [a, b, c, d, e, f] … … 135 135 domain.check_integrity() 136 136 137 domain.check_integrity()138 137 139 138 #Write file … … 151 150 152 151 F = File_boundary(filename, domain) 153 os.remove(filename) 154 152 os.remove(filename) 153 154 155 #Check that midpoint coordinates at boundary are correctly computed 156 #print domain.boundary 157 #print F.midpoint_coordinates 158 assert allclose(F.midpoint_coordinates[(3,2)], [0.0, 3.0]) 159 assert allclose(F.midpoint_coordinates[(3,1)], [1.0, 3.0]) 160 assert allclose(F.midpoint_coordinates[(0,2)], [0.0, 1.0]) 161 assert allclose(F.midpoint_coordinates[(0,0)], [1.0, 0.0]) 162 assert allclose(F.midpoint_coordinates[(2,0)], [3.0, 0.0]) 163 assert allclose(F.midpoint_coordinates[(2,1)], [3.0, 1.0]) 164 165 166 #Check time interpolation 155 167 from config import default_boundary_tag 156 168 domain.set_boundary( {default_boundary_tag: F} ) … … 167 179 168 180 169 181 def test_fileboundary_time_and_space(self): 182 """Test that boundary values can be read from file and interpolated 183 Include both time and space 184 """ 185 186 from domain import Domain 187 from quantity import Quantity 188 189 raise 'Not yet implemented' 170 190 171 191 def test_fileboundary_exception(self): -
inundation/ga/storm_surge/pyvolution/test_least_squares.py
r834 r835 512 512 assert allclose(attributes, ref) 513 513 514 514 os.remove(FN) 515 515 516 516 -
inundation/ga/storm_surge/pyvolution/test_util.py
r834 r835 192 192 assert allclose( 2*sin(120*pi/600)/3 + sin(60*pi/600)/3, q[2] ) 193 193 194 194 os.remove(filename) 195 195 196 196 … … 268 268 assert allclose( 2*sin(120*pi/600)/3 + sin(60*pi/600)/3, q[2] ) 269 269 270 270 os.remove(filename) 271 271 272 272 273 def test_file_function_time_with_domain_different_start(self): … … 336 337 assert allclose( 2*sin(120*pi/600)/3 + sin(60*pi/600)/3, q[2] ) 337 338 339 os.remove(filename) 338 340 339 341 def test_xya_ascii(self): -
inundation/ga/storm_surge/pyvolution/util.py
r834 r835 109 109 NOTE: At this stage the function is assumed to depend on 110 110 time only, i.e no spatial dependency!!!!! 111 When that is need we can use the least_squares interpolation.111 When that is needed we can use the least_squares interpolation. 112 112 """ 113 113 … … 189 189 self.read_times() #Now read all times in. 190 190 else: 191 raise 'x,y depende cy not yet implemented'191 raise 'x,y dependency not yet implemented' 192 192 193 193 … … 237 237 FIXME: x, y dependency not yet implemented except that 238 238 result is a vector of same length as x and y 239 FIXME: Naaaa 239 240 """ 240 241 … … 275 276 return q 276 277 else: 277 from Numeric import ones, Float 278 #Create one constant column for each value 279 N = len(x) 280 assert len(y) == N, 'x and y must have same length' 281 282 res = [] 283 for col in q: 284 res.append(col*ones(N, Float)) 278 try: 279 N = len(x) 280 except: 281 return q 282 else: 283 from Numeric import ones, Float 284 #x is a vector - Create one constant column for each value 285 N = len(x) 286 assert len(y) == N, 'x and y must have same length' 287 288 res = [] 289 for col in q: 290 res.append(col*ones(N, Float)) 285 291 286 return res 292 return res 293 287 294 288 295 def read_xya(filename, format = 'netcdf'):
Note: See TracChangeset
for help on using the changeset viewer.