Changeset 1697 for inundation/ga/storm_surge/pyvolution
- Timestamp:
- Aug 9, 2005, 5:44:21 PM (20 years ago)
- Location:
- inundation/ga/storm_surge/pyvolution
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
inundation/ga/storm_surge/pyvolution/config.py
r1690 r1697 87 87 if sys.platform == 'win32': 88 88 #default_datadir = 'C:\grohm_output' 89 default_datadir = '.' 89 default_datadir = '.' 90 90 else: 91 91 #default_datadir = os.path.expanduser('~'+os.sep+'grohm_output') 92 default_datadir = '.' 92 default_datadir = '.' 93 93 94 94 -
inundation/ga/storm_surge/pyvolution/domain.py
r1681 r1697 545 545 from config import min_timestep 546 546 547 timestep = self.timestep 547 # self.timestep is calculated from speed of characteristics 548 # Apply CFL condition here 549 timestep = self.CFL*self.timestep 548 550 549 551 #Record maximal and minimal values of timestep for reporting … … 635 637 def update_ghosts(self): 636 638 pass 637 638 639 639 640 def distribute_to_vertices_and_edges(self): -
inundation/ga/storm_surge/pyvolution/generic_boundary_conditions.py
r1657 r1697 10 10 A boundary object has one neighbour; the one it 11 11 serves. 12 """ 12 """ 13 13 14 14 def __init__(self): 15 15 pass 16 16 17 17 def evaluate(self, vol_id=None, edge_id=None): 18 18 msg = 'Generic class Boundary must be subclassed' … … 26 26 Underlying domain must be specified when boundary is instantiated 27 27 """ 28 28 29 29 def __init__(self, domain = None): 30 30 Boundary.__init__(self) … … 33 33 msg = 'Domain must be specified for transmissive boundary' 34 34 raise msg 35 36 self.domain = domain 37 35 36 self.domain = domain 37 38 38 def __repr__(self): 39 39 return 'Transmissive_boundary(%s)' %self.domain … … 43 43 of the volume they serve. 44 44 """ 45 45 46 46 q = self.domain.get_conserved_quantities(vol_id, edge = edge_id) 47 return q 47 return q 48 48 49 49 … … 66 66 def __repr__(self): 67 67 return 'Dirichlet boundary (%s)' %self.conserved_quantities 68 68 69 69 def evaluate(self, vol_id=None, edge_id=None): 70 70 return self.conserved_quantities … … 88 88 msg = 'Function for time boundary could not be executed:\n%s' %e 89 89 raise msg 90 91 92 from Numeric import array, Float 90 91 92 from Numeric import array, Float 93 93 try: 94 94 q = array(q).astype(Float) … … 96 96 msg = 'Return value from time boundary function could ' 97 97 msg += 'not be converted into a Numeric array of floats.\n' 98 msg += 'Specified function should return either list or array.' 98 msg += 'Specified function should return either list or array.' 99 99 raise msg 100 100 101 101 msg = 'ERROR: Time boundary function must return a 1d list or array ' 102 102 assert len(q.shape) == 1, msg 103 103 104 104 d = len(domain.conserved_quantities) 105 105 msg = 'Return value for f must be a list or an array of length %d' %d … … 132 132 from config import time_format 133 133 from util import File_function 134 134 135 135 Boundary.__init__(self) 136 136 … … 145 145 assert len(q) == d, msg 146 146 147 147 148 148 def __repr__(self): 149 149 return 'File boundary' … … 174 174 File boundary must read and interpolate from *smoothed* version 175 175 as stored in sww and cannot work with the discontinuos triangles. 176 176 177 177 """ 178 178 … … 182 182 from config import time_format 183 183 from util import file_function 184 184 185 185 Boundary.__init__(self) 186 186 187 187 #Get x,y vertex coordinates for all triangles 188 188 V = domain.vertex_coordinates 189 189 190 190 #Compute midpoint coordinates for all boundary elements 191 192 #we don't know which ones at this stage since this object can be attached to 193 191 #Only a subset may be invoked when boundary is evaluated but 192 #we don't know which ones at this stage since this object can be attached to 193 #any tagged boundary later on. 194 194 195 195 if verbose: print 'Find midpoint coordinates of entire boundary' 196 196 self.midpoint_coordinates = zeros( (len(domain.boundary), 2), Float) 197 198 199 200 self.boundary_indices = {} 201 197 boundary_keys = domain.boundary.keys() 198 199 #Record ordering #FIXME: should this happen in domain.py 200 self.boundary_indices = {} 201 202 202 for i, (vol_id, edge_id) in enumerate(boundary_keys): 203 203 204 204 x0 = V[vol_id, 0]; y0 = V[vol_id, 1] 205 205 x1 = V[vol_id, 2]; y1 = V[vol_id, 3] 206 x2 = V[vol_id, 4]; y2 = V[vol_id, 5] 207 208 #Midpoints 206 x2 = V[vol_id, 4]; y2 = V[vol_id, 5] 207 208 #Midpoints 209 209 if edge_id == 0: m = array([(x1 + x2)/2, (y1 + y2)/2]) 210 210 if edge_id == 1: m = array([(x0 + x2)/2, (y0 + y2)/2]) 211 if edge_id == 2: m = array([(x1 + x0)/2, (y1 + y0)/2]) 211 if edge_id == 2: m = array([(x1 + x0)/2, (y1 + y0)/2]) 212 212 self.midpoint_coordinates[i,:] = m 213 214 215 216 217 218 self.F = file_function(filename, domain, 213 214 self.boundary_indices[(vol_id, edge_id)] = i 215 216 217 if verbose: print 'Initialise file_function' 218 self.F = file_function(filename, domain, 219 219 interpolation_points=self.midpoint_coordinates, 220 220 verbose = verbose) … … 225 225 226 226 d = len(domain.conserved_quantities) 227 msg = 'Values specified in file %s must be ' %filename 228 227 msg = 'Values specified in file %s must be ' %filename 228 msg += ' a list or an array of length %d' %d 229 229 assert len(q) == d, msg 230 230 231 231 232 232 def __repr__(self): 233 233 return 'File boundary' … … 247 247 else: 248 248 #raise 'Boundary call without point_id not implemented' 249 #FIXME: What should the semantics be? 249 #FIXME: What should the semantics be? 250 250 return self.F(t) 251 251 … … 262 262 conserved quantities from a volume as defined by a connection table 263 263 mapping between tuples of (volume id, face id) for volumes that 264 have their boundaries connected. 264 have their boundaries connected. 265 265 266 266 FIXME: Perhaps include possibility of mapping between … … 274 274 def __init__(self, table): 275 275 from domain import Volume 276 276 277 277 Boundary.__init__(self) 278 278 … … 281 281 282 282 def __repr__(self): 283 return 'Connective boundary' 283 return 'Connective boundary' 284 284 285 285 #FIXME: IF we ever need to get field_values from connected volume, … … 287 287 #get_conserved_quantities 288 288 #def get_field_values() 289 289 290 290 def get_conserved_quantities(self, volume, face=0): 291 291 292 292 id = volume.id 293 293 if self.connection_table.has_key((id, face)): 294 other_id, other_face = self.connection_table[(id, face)] 295 294 other_id, other_face = self.connection_table[(id, face)] 295 296 296 other_volume = self.Volume.instances[other_id] 297 297 cmd = 'q = other_volume.conserved_quantities_face%d' %face; 298 exec(cmd) 298 exec(cmd) 299 299 return q 300 300 else: … … 302 302 %(id, face) 303 303 raise msg 304 305 306 307 308 309 #FIXME: Add a boundary with a general function of x,y, and t 304 305 306 307 308 309 #FIXME: Add a boundary with a general function of x,y, and t 310 310 311 311 #FIXME: Add periodic boundaries e.g.: … … 317 317 # 318 318 # print i,k 319 # 319 # 320 320 # domain[i].faces[2].neighbour = domain[k].faces[1] 321 # domain[k].faces[1].neighbour = domain[i].faces[2] 322 321 # domain[k].faces[1].neighbour = domain[i].faces[2] 322 323 323 324 324 … … 329 329 Must specify initial conserved quantities, 330 330 neighbour, 331 domain to get access to model time 331 domain to get access to model time 332 332 a function f(q_old, neighbours_q, t) which must return 333 333 new conserved quantities q as a function time … … 366 366 from Numeric import array 367 367 from config import time_format 368 368 369 369 Boundary.__init__(self) 370 370 … … 385 385 try: 386 386 starttime = time.mktime(time.strptime(fields[0], time_format)) 387 except ValueError: 387 except ValueError: 388 388 msg = 'First field in file %s must be' %filename 389 389 msg += ' date-time with format %s.\n' %time_format 390 msg += 'I got %s instead.' %fields[0] 390 msg += 'I got %s instead.' %fields[0] 391 391 raise msg 392 392 … … 397 397 398 398 q = array(values) 399 399 400 400 msg = 'ERROR: File boundary function must return a 1d list or array ' 401 401 assert len(q.shape) == 1, msg 402 402 403 403 d = len(domain.conserved_quantities) 404 404 msg = 'Values specified in file must be a list or an array of length %d' %d … … 414 414 msg = 'Start time as specified in domain (%s) is earlier ' 415 415 'than the starttime of file %s: %s'\ 416 %(domain.starttime, self.filename, self.starttime) 416 %(domain.starttime, self.filename, self.starttime) 417 417 if self.starttime > domain.starttime: 418 418 raise msg 419 419 420 420 self.read_time_boundary() #Now read all times in. 421 422 421 422 423 423 def read_time_boundary(self): 424 424 from Numeric import zeros, Float, alltrue 425 425 from config import time_format 426 426 import time 427 428 fid = open(self.filename) 427 428 fid = open(self.filename) 429 429 lines = fid.readlines() 430 430 fid.close() 431 431 432 432 N = len(lines) 433 433 d = len(self.domain.conserved_quantities) … … 436 436 Q = zeros((N, d), Float) 437 437 438 438 439 439 for i, line in enumerate(lines): 440 440 fields = line.split(',') … … 443 443 T[i] = real_time - self.starttime 444 444 445 445 446 446 for j, value in enumerate(fields[1].split()): 447 447 Q[i, j] = float(value) … … 449 449 msg = 'Time boundary must list time as a monotonuosly ' 450 450 msg += 'increasing sequence' 451 451 452 452 assert alltrue( T[1:] - T[:-1] > 0 ), msg 453 453 … … 456 456 self.index = 0 #Initial index 457 457 458 458 459 459 def __repr__(self): 460 460 return 'File boundary' … … 465 465 466 466 t = self.domain.time 467 467 468 468 msg = 'Time given in File boundary does not match model time' 469 469 if t < self.T[0]: raise msg 470 if t > self.T[-1]: raise msg 470 if t > self.T[-1]: raise msg 471 471 472 472 oldindex = self.index … … 478 478 #if oldindex != self.index: 479 479 # print 'Changing from %d to %d' %(oldindex, self.index) 480 481 480 481 482 482 #t is now between index and index+1 483 483 ratio = (t - self.T[self.index])/\ … … 485 485 486 486 return self.Q[self.index,:] +\ 487 ratio*(self.Q[self.index+1,:] - self.Q[self.index,:]) 488 489 490 491 492 487 ratio*(self.Q[self.index+1,:] - self.Q[self.index,:]) 488 489 490 491 -
inundation/ga/storm_surge/pyvolution/netherlands.py
r1688 r1697 83 83 N = 130 #size = 33800 84 84 N = 600 #Size = 720000 85 N = 10085 N = 50 86 86 87 87 … … 154 154 # 155 155 print 'Initial condition' 156 domain.set_quantity('stage', Constant_height(Z, 0.0))157 #domain.set_quantity('stage', Constant_stage(-1.0))156 #domain.set_quantity('stage', Constant_height(Z, 0.0)) 157 domain.set_quantity('stage', Constant_stage(inflow_stage/2.0)) 158 158 159 159 #Evolve … … 169 169 for t in domain.evolve(yieldstep = 0.02, finaltime = 15.0): 170 170 domain.write_time() 171 print domain.quantities['stage'].get_values(location='centroids',indexes=[0]) 171 172 #V.update_quantity('stage') 172 173 #rpdb.set_active() -
inundation/ga/storm_surge/pyvolution/quantity.py
r1681 r1697 182 182 self.set_values_from_file(X) #FIXME: More parameters 183 183 184 184 185 185 if location == 'vertices' or location == 'unique vertices': 186 186 #Intialise centroid and edge_values … … 199 199 Default is "vertices" 200 200 201 In case of location == 'centroid ' the dimension values must201 In case of location == 'centroids' the dimension values must 202 202 be a list of a Numerical array of length N, N being the number 203 203 of elements. Otherwise it must be of dimension Nx3 … … 266 266 #FIXME: Should check that function returns something sensible and 267 267 #raise a meaningfol exception if it returns None for example 268 268 269 269 from Numeric import take 270 270 … … 404 404 #FIXME location, indices 405 405 406 406 407 407 import util, least_squares 408 408 … … 413 413 attribute_name = names[0] 414 414 415 415 416 416 if verbose: 417 417 print 'Using attribute %s from file %s' %(attribute_name, filename) 418 print 'Available attributes: %s' %(names) 419 418 print 'Available attributes: %s' %(names) 419 420 420 421 421 try: … … 425 425 %(attribute_name, filename) 426 426 raise msg 427 427 428 428 429 429 #Fit attributes to mesh … … 438 438 #Recursively set value using fitted array 439 439 print 'shape', X.shape 440 self.set_values(X, location='vertices') #FIXME, indexes = None): 441 440 self.set_values(X, location='vertices') #FIXME, indexes = None): 441 442 442 443 443 … … 470 470 assert A.shape[0] == len(indexes) 471 471 vertex_list = indexes 472 472 473 473 #Go through list of unique vertices 474 474 for i_index, unique_vert_id in enumerate(vertex_list): … … 606 606 #M = 3*m #Total number of unique vertices 607 607 #V = reshape(array(range(M)).astype(Int), (m,3)) 608 608 609 609 V = self.domain.get_triangles(obj=True) 610 610 #FIXME use get_vertices, when ready … … 861 861 862 862 #Gradient 863 a[k], b[k] = gradient2(x0, y0, x1, y1, q0, q1) 863 a[k], b[k] = gradient2(x0, y0, x1, y1, q0, q1) 864 864 else: 865 865 #No true neighbours - -
inundation/ga/storm_surge/pyvolution/realtime_visualisation_new.py
r1688 r1697 206 206 #print 'update bed image' 207 207 if qname=='elevation': 208 self.vpython_z_models[qname].pos = self.pos+1.0e-3 209 else: 210 self.vpython_z_models[qname].pos = self.pos 211 208 self.pos[:,2] = self.pos[:,2]+1.0e-3 209 210 self.vpython_z_models[qname].pos = self.pos 212 211 self.vpython_z_models[qname].color = self.colour 213 212 self.vpython_z_models[qname].normal = self.normals -
inundation/ga/storm_surge/pyvolution/shallow_water.py
r1688 r1697 113 113 from realtime_visualisation_new import Visualiser 114 114 self.visualiser = Visualiser(self,scale_z,rect) 115 self.visualiser. updating['elevation']=True115 self.visualiser.setup['elevation']=True 116 116 self.visualise = True 117 117 … … 181 181 182 182 # #self.quantities['stage'].interpolate() 183 184 183 185 184 … … 964 963 965 964 965 966 class Transmissive_Momentum_Set_Stage_boundary(Boundary): 967 """Returns same momentum conserved quantities as 968 those present in its neighbour volume. Sets stage 969 970 Underlying domain must be specified when boundary is instantiated 971 """ 972 973 def __init__(self, domain = None, function=None): 974 Boundary.__init__(self) 975 976 if domain is None: 977 msg = 'Domain must be specified for this type boundary' 978 raise msg 979 980 if function is None: 981 msg = 'Function must be specified for this type boundary' 982 raise msg 983 984 self.domain = domain 985 self.function = function 986 987 def __repr__(self): 988 return 'Transmissive_Momentum_Set_Stage_boundary(%s)' %self.domain 989 990 def evaluate(self, vol_id, edge_id): 991 """Transmissive Momentum Set Stage boundaries return the edge momentum 992 values of the volume they serve. 993 """ 994 995 q = self.domain.get_conserved_quantities(vol_id, edge = edge_id) 996 value = self.function(self.domain.time) 997 q[0] = value[0] 998 return q 999 1000 1001 1002 1003 966 1004 #class Spatio_temporal_boundary(Boundary): 967 1005 # """The spatio-temporal boundary, reads values for the conserved
Note: See TracChangeset
for help on using the changeset viewer.