Changeset 209
- Timestamp:
- Aug 24, 2004, 12:10:48 PM (21 years ago)
- Location:
- inundation/ga/storm_surge/pyvolution
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
inundation/ga/storm_surge/pyvolution/domain.py
r205 r209 133 133 return q 134 134 135 def set_quantity(self, name, values, location='vertices'):135 def set_quantity(self, name, X, location='vertices'): 136 136 """Set values for named quantity 137 137 138 138 name: Name of quantity 139 values: Compatible list or Numeric array(see below)139 X: Compatible list, Numeric array, const or function (see below) 140 140 location: Where values are to be stored. 141 141 Permissible options are: vertices, edges, centroid … … 149 149 """ 150 150 151 self.quantities[name].set_values( values, location)151 self.quantities[name].set_values(X, location) 152 152 153 153 … … 461 461 Q = self.quantities[name] 462 462 if self.order == 1: 463 Q. first_order_extrapolator()463 Q.extrapolate_first_order() 464 464 elif self.order == 2: 465 Q. second_order_extrapolator()466 Q.limit er()465 Q.extrapolate_second_order() 466 Q.limit() 467 467 else: 468 468 raise 'Unknown order' -
inundation/ga/storm_surge/pyvolution/quantity.py
r206 r209 84 84 self.edge_values[i, 2] = 0.5*(v0 + v1) 85 85 86 86 87 def update(self, timestep): 87 88 """Update centroid values based on values stored in … … 185 186 186 187 187 def limit er(self):188 def limit(self): 188 189 """Limit slopes for each volume to eliminate artificial variance 189 190 introduced by e.g. second order extrapolator … … 245 246 246 247 247 def first_order_extrapolator(self):248 def extrapolate_first_order(self): 248 249 """Extrapolate conserved quantities from centroid to 249 250 vertices for each volume using … … 258 259 259 260 260 def second_order_extrapolator(self):261 def extrapolate_second_order(self): 261 262 """Extrapolate conserved quantities from centroid to 262 263 vertices for each volume using … … 322 323 323 324 324 #FIXME: Should do location erro check here only 325 326 325 #FIXME: Should do location error check here only 326 327 if location not in ['vertices', 'centroids', 'edges']: 328 msg = 'Invalid location: %s' %location 329 raise msg 330 327 331 import types 328 332 … … 331 335 self.set_function_values(X, location) 332 336 elif type(X) in [types.FloatType, types.IntType, types.LongType]: 333 if location == ' vertices':334 self. vertex_values[:] = X337 if location == 'centroids': 338 self.centroid_values[:] = X 335 339 elif location == 'edges': 336 340 self.edge_values[:] = X 337 elif location == 'centroids':338 self.centroid_values[:] = X339 341 else: 340 raise 'Invalid location: %s' %location 342 self.vertex_values[:] = X 343 341 344 else: 342 345 #Use array specific method 343 346 self.set_array_values(X, location) 347 348 if location == 'vertices': 349 #Intialise centroid and edge_values 350 self.interpolate() 351 344 352 345 353 … … 353 361 """ 354 362 355 356 if location == 'vertices': 357 V = self.domain.get_vertex_coordinates() 358 363 if location == 'centroids': 364 P = self.domain.centroids 365 self.set_values(f(P[:,0], P[:,1]), location) 366 elif location == 'edges': 367 raise 'Not yet implemented: %s' %location 368 else: 369 #Vertices 370 P = self.domain.get_vertex_coordinates() 359 371 for i in range(3): 360 self.set_values(f(V[:,2*i], V[:,2*i+1]), location) 361 elif location == 'edges': 362 raise 'Not yet implemented' 363 elif location == 'centroids': 364 V = self.domain.centroids 365 self.set_values(f(V[:,0], V[:,1]), location) 366 else: 367 raise 'Invalid location: %s' %location 372 self.vertex_values[:,i] = f(P[:,2*i], P[:,2*i+1]) 368 373 369 374 … … 398 403 assert values.shape[0] == N, msg 399 404 400 if location == 'vertices': 401 assert len(values.shape) == 2, 'Values array must be 2d' 402 msg = 'Array must be N x 3' 403 assert values.shape[1] == 3, msg 404 405 self.vertex_values = values 406 407 #Intialise centroid and edge_values 408 self.interpolate() 405 if location == 'centroids': 406 assert len(values.shape) == 1, 'Values array must be 1d' 407 self.centroid_values = values 409 408 elif location == 'edges': 410 409 assert len(values.shape) == 2, 'Values array must be 2d' … … 413 412 414 413 self.edge_values = values 415 416 elif location == 'centroids':417 assert len(values.shape) == 1, 'Values array must be 1d'418 self.centroid_values = values419 414 else: 420 raise 'Invalid location: %s' %location 415 assert len(values.shape) == 2, 'Values array must be 2d' 416 msg = 'Array must be N x 3' 417 assert values.shape[1] == 3, msg 418 419 self.vertex_values = values 420 -
inundation/ga/storm_surge/pyvolution/shallow_water.py
r205 r209 274 274 protect_against_infinitesimal_heights_centroid(domain) 275 275 if domain.order == 1: 276 first_order_extrapolator(domain)276 extrapolate_first_order(domain) 277 277 elif domain.order == 2: 278 second_order_extrapolator(domain)278 extrapolate_second_order(domain) 279 279 else: 280 280 raise 'Unknown order' … … 312 312 313 313 314 def first_order_extrapolator(domain):314 def extrapolate_first_order(domain): 315 315 """First order extrapolator function, specific 316 316 to the shallow water wave equation. … … 332 332 for name in domain.conserved_quantities: 333 333 Q = domain.quantities[name] 334 Q. first_order_extrapolator()334 Q.extrapolate_first_order() 335 335 Q.interpolate_from_vertices_to_edges() 336 336 … … 396 396 397 397 398 def second_order_extrapolator(domain):398 def extrapolate_second_order(domain): 399 399 """Second order limiter function, specific to the shallow water wave 400 400 equation. … … 427 427 Q = domain.quantities[name] 428 428 429 Q. second_order_extrapolator()429 Q.extrapolate_second_order() 430 430 Q.limiter() 431 431 Q.interpolate_from_vertices_to_edges() -
inundation/ga/storm_surge/pyvolution/test_quantity.py
r205 r209 145 145 146 146 147 def test_set_values_const(self): 148 quantity = Quantity(self.mesh4) 149 150 quantity.set_values(1.0, location = 'vertices') 151 assert allclose(quantity.vertex_values, 152 [[1,1,1], [1,1,1], [1,1,1], [1, 1, 1]]) 153 assert allclose(quantity.centroid_values, [1, 1, 1, 1]) #Centroid 154 assert allclose(quantity.edge_values, [[1, 1, 1], 155 [1, 1, 1], 156 [1, 1, 1], 157 [1, 1, 1]]) 158 159 160 quantity.set_values(2.0, location = 'centroids') 161 assert allclose(quantity.centroid_values, [2, 2, 2, 2]) 162 163 quantity.set_values(3.0, location = 'edges') 164 assert allclose(quantity.edge_values, [[3, 3, 3], 165 [3, 3, 3], 166 [3, 3, 3], 167 [3, 3, 3]]) 168 169 170 def test_set_values_func(self): 171 quantity = Quantity(self.mesh4) 172 173 def f(x, y): 174 return x+y 175 176 quantity.set_values(f, location = 'vertices') 177 assert allclose(quantity.vertex_values, 178 [[2,0,2], [2,2,4], [4,2,4], [4,2,4]]) 179 assert allclose(quantity.centroid_values, 180 [4.0/3, 8.0/3, 10.0/3, 10.0/3]) 181 assert allclose(quantity.edge_values, 182 [[1,2,1], [3,3,2], [3,4,3], [3,4,3]]) 183 184 185 quantity.set_values(f, location = 'centroids') 186 assert allclose(quantity.centroid_values, 187 [4.0/3, 8.0/3, 10.0/3, 10.0/3]) 188 189 147 190 def test_gradient(self): 148 191 quantity = Quantity(self.mesh4) … … 165 208 166 209 167 quantity. second_order_extrapolator()210 quantity.extrapolate_second_order() 168 211 169 212 assert allclose(quantity.vertex_values, [[2., 2., 2.], … … 359 402 360 403 #Extrapolate 361 quantity. first_order_extrapolator()404 quantity.extrapolate_first_order() 362 405 363 406 #Check vertices but not edge values … … 375 418 376 419 377 quantity. second_order_extrapolator()378 quantity.limit er()420 quantity.extrapolate_second_order() 421 quantity.limit() 379 422 380 423 … … 408 451 409 452 #Limit 410 quantity.limit er()453 quantity.limit() 411 454 412 455 #Assert that central triangle is limited by neighbours … … 439 482 440 483 #Extrapolate 441 quantity. first_order_extrapolator()484 quantity.extrapolate_first_order() 442 485 443 486 #Interpolate
Note: See TracChangeset
for help on using the changeset viewer.