Changeset 476


Ignore:
Timestamp:
Nov 1, 2004, 3:49:47 PM (20 years ago)
Author:
ole
Message:

Reimplemented unit tests for semi implicit updates and fixed comments.

Location:
inundation/ga/storm_surge/pyvolution
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • inundation/ga/storm_surge/pyvolution/domain.py

    r469 r476  
    4545            self.quantities[name] = Quantity(self)
    4646
    47 
    48         #FIXME: Move these explanations elsewhere   
    49            
    5047        #Create an empty list for explicit forcing terms
    51         #
    52         # Explicit terms must have the form
    53         #
    54         #    G(q, t)
    55         #
    56         # and explicit scheme is
    57         #
    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 look
    62 
    6348        self.forcing_terms = []
    6449
    65 
    66         #Create an empty list for semi implicit forcing terms if any
    67         #
    68         # Semi implicit forcing terms are assumed to have the form
    69         #
    70         #    G(q, t) = H(q, t) q
    71         #
    72         # and the semi implicit scheme will then be
    73         #
    74         #   q^{(n+1}) = q^{(n)} + delta_t H(q^{n}, n delta_t) q^{(n+1})
    75        
    76         ###self.semi_implicit_forcing_terms = []
    7750
    7851
  • inundation/ga/storm_surge/pyvolution/quantity.py

    r461 r476  
    472472    """Update centroid values based on values stored in
    473473    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   
    474504    """
    475505   
     
    479509
    480510
    481     #Divide by semi_implicit update by conserved quantity
     511    #Divide H by conserved quantity to obtain G (see docstring above)
    482512    for k in range(N):
    483513        x = quantity.centroid_values[k]
     
    487517            quantity.semi_implicit_update[k] /= x             
    488518           
    489 
    490519       
    491520    #Explicit updates
  • inundation/ga/storm_surge/pyvolution/test_quantity.py

    r461 r476  
    77from quantity import *
    88from config import epsilon
    9 from Numeric import allclose, array
     9from Numeric import allclose, array, ones, Float
    1010
    1111       
     
    412412        assert allclose( quantity.centroid_values, x)
    413413
    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)       
    450458
    451459       
Note: See TracChangeset for help on using the changeset viewer.