Changeset 476
- Timestamp:
- Nov 1, 2004, 3:49:47 PM (20 years ago)
- Location:
- inundation/ga/storm_surge/pyvolution
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
inundation/ga/storm_surge/pyvolution/domain.py
r469 r476 45 45 self.quantities[name] = Quantity(self) 46 46 47 48 #FIXME: Move these explanations elsewhere49 50 47 #Create an empty list for explicit forcing terms 51 #52 # Explicit terms must have the form53 #54 # G(q, t)55 #56 # and explicit scheme is57 #58 # q^{(n+1}) = q^{(n)} + delta_t G(q^{n}, n delta_t)59 #60 #61 # FIXME: How to call and how function should look62 63 48 self.forcing_terms = [] 64 49 65 66 #Create an empty list for semi implicit forcing terms if any67 #68 # Semi implicit forcing terms are assumed to have the form69 #70 # G(q, t) = H(q, t) q71 #72 # and the semi implicit scheme will then be73 #74 # q^{(n+1}) = q^{(n)} + delta_t H(q^{n}, n delta_t) q^{(n+1})75 76 ###self.semi_implicit_forcing_terms = []77 50 78 51 -
inundation/ga/storm_surge/pyvolution/quantity.py
r461 r476 472 472 """Update centroid values based on values stored in 473 473 explicit_update and semi_implicit_update as well as given timestep 474 475 Function implementing forcing terms must take on argument 476 which is the domain and they must update either explicit 477 or implicit updates, e,g,: 478 479 def gravity(domain): 480 .... 481 domain.quantities['xmomentum'].explicit_update = ... 482 domain.quantities['ymomentum'].explicit_update = ... 483 484 485 486 Explicit terms must have the form 487 488 G(q, t) 489 490 and explicit scheme is 491 492 q^{(n+1}) = q^{(n)} + delta_t G(q^{n}, n delta_t) 493 494 495 Semi implicit forcing terms are assumed to have the form 496 497 G(q, t) = H(q, t) q 498 499 and the semi implicit scheme will then be 500 501 q^{(n+1}) = q^{(n)} + delta_t H(q^{n}, n delta_t) q^{(n+1}) 502 503 474 504 """ 475 505 … … 479 509 480 510 481 #Divide by semi_implicit update by conserved quantity511 #Divide H by conserved quantity to obtain G (see docstring above) 482 512 for k in range(N): 483 513 x = quantity.centroid_values[k] … … 487 517 quantity.semi_implicit_update[k] /= x 488 518 489 490 519 491 520 #Explicit updates -
inundation/ga/storm_surge/pyvolution/test_quantity.py
r461 r476 7 7 from quantity import * 8 8 from config import epsilon 9 from Numeric import allclose, array 9 from Numeric import allclose, array, ones, Float 10 10 11 11 … … 412 412 assert allclose( quantity.centroid_values, x) 413 413 414 #FIXME: Update these tests once I understand the semi_implicit scheme 415 # def test_update_semi_implicit(self): 416 # quantity = Conserved_quantity(self.mesh4) 417 418 # #Test centroids 419 # quantity.set_values([1.,2.,3.,4.], location = 'centroids') 420 # assert allclose(quantity.centroid_values, [1, 2, 3, 4]) #Centroid 421 422 # #Set semi implicit update 423 # quantity.semi_implicit_update = array( [1.,1.,1.,1.] ) 424 425 # #Update with given timestep 426 # quantity.update(0.1) 427 428 # x = array([1, 2, 3, 4])/array( [.9,.9,.9,.9] ) 429 # assert allclose( quantity.centroid_values, x) 430 431 # def test_both_updates(self): 432 # quantity = Conserved_quantity(self.mesh4) 433 434 # #Test centroids 435 # quantity.set_values([1.,2.,3.,4.], location = 'centroids') 436 # assert allclose(quantity.centroid_values, [1, 2, 3, 4]) #Centroid 437 438 # #Set explicit_update 439 # quantity.explicit_update = array( [4.,3.,2.,1.] ) 440 441 # #Set semi implicit update 442 # quantity.semi_implicit_update = array( [1.,1.,1.,1.] ) 443 444 # #Update with given timestep 445 # quantity.update(0.1) 446 447 # x = array([1, 2, 3, 4]) + array( [.4,.3,.2,.1] ) 448 # x /= array( [.9,.9,.9,.9] ) 449 # assert allclose( quantity.centroid_values, x) 414 def test_update_semi_implicit(self): 415 quantity = Conserved_quantity(self.mesh4) 416 417 #Test centroids 418 quantity.set_values([1.,2.,3.,4.], location = 'centroids') 419 assert allclose(quantity.centroid_values, [1, 2, 3, 4]) #Centroid 420 421 #Set semi implicit update 422 quantity.semi_implicit_update = array([1.,1.,1.,1.]) 423 424 #Update with given timestep 425 timestep = 0.1 426 quantity.update(timestep) 427 428 sem = array([1.,1.,1.,1.])/array([1, 2, 3, 4]) 429 denom = ones(4, Float)-timestep*sem 430 431 x = array([1, 2, 3, 4])/denom 432 assert allclose( quantity.centroid_values, x) 433 434 435 def test_both_updates(self): 436 quantity = Conserved_quantity(self.mesh4) 437 438 #Test centroids 439 quantity.set_values([1.,2.,3.,4.], location = 'centroids') 440 assert allclose(quantity.centroid_values, [1, 2, 3, 4]) #Centroid 441 442 #Set explicit_update 443 quantity.explicit_update = array( [4.,3.,2.,1.] ) 444 445 #Set semi implicit update 446 quantity.semi_implicit_update = array( [1.,1.,1.,1.] ) 447 448 #Update with given timestep 449 timestep = 0.1 450 quantity.update(0.1) 451 452 sem = array([1.,1.,1.,1.])/array([1, 2, 3, 4]) 453 denom = ones(4, Float)-timestep*sem 454 455 x = array([1, 2, 3, 4]) + array( [.4,.3,.2,.1] ) 456 x /= denom 457 assert allclose( quantity.centroid_values, x) 450 458 451 459
Note: See TracChangeset
for help on using the changeset viewer.