Changeset 8092


Ignore:
Timestamp:
Dec 7, 2010, 5:03:30 PM (9 years ago)
Author:
habili
Message:

Updated the inlet operator to deal with variable discharge rates.
inlet_operator_test1.tms and inlet_operator_test1.tms are unit tests to test the variable
discharge rate code.

Location:
trunk/anuga_core/source/anuga/structures
Files:
2 added
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/anuga_core/source/anuga/structures/inlet.py

    r8081 r8092  
    235235       
    236236        # find the number of cells which will be filled
    237         index = num.nonzero(summed_volume<volume)[0][-1]
     237        index = num.nonzero(summed_volume<=volume)[0][-1]
    238238
    239239        # calculate stage needed to fill chosen cells with given volume of water
  • trunk/anuga_core/source/anuga/structures/inlet_operator.py

    r8080 r8092  
    3535        self.Q = Q
    3636
    37 
    3837        if description == None:
    3938            self.description = ' '
     
    5049        self.verbose = verbose
    5150
    52        
    5351        # Keep count of inlet operator
    5452        Inlet_operator.counter += 1
    5553
    56         import pdb
    57         #pdb.set_trace()
    58        
    5954        self.enquiry_point = 0.5*(self.line[0] + self.line[1])
    6055        self.outward_vector = self.line
     
    6661
    6762        timestep = self.domain.get_timestep()
     63
     64        t = self.domain.get_time()
     65        Q1 = self.update_Q(t)
     66        Q2 = self.update_Q(t + timestep)
    6867       
    69         Q = self.Q
    70 
    71         volume = Q*timestep
    72 
    73         assert Q >= 0.0, 'Q < 0: Water to be removed from an inlet!'
    74 
    75 
     68        volume = 0.5*(Q1+Q2)*timestep
     69       
     70        assert 0.5*(Q1+Q2) >= 0.0, 'Q < 0: Water to be removed from an inlet!'
     71       
    7672        # Distribute volume so as to obtain flat surface
    7773        self.inlet.set_stages_evenly(volume)
     
    7975        # Distribute volume evenly over all cells
    8076        #self.inlet.set_depths_evenly(volume)
     77       
     78    def update_Q(self, t):
     79        """Virtual method allowing local modifications by writing an
     80        overriding version in descendant
     81        """
     82       
     83        if callable(self.Q):
     84            Q = self.Q(t)[0]
     85        else:
     86            Q = self.Q
     87
     88        return Q   
    8189 
    82 
    8390    def statistics(self):
    8491
  • trunk/anuga_core/source/anuga/structures/test_inlet_operator.py

    r8079 r8092  
    99import anuga
    1010
    11 from anuga.utilities.system_tools import get_pathname_from_package
    12 from anuga.structures.boyd_box_operator import Boyd_box_operator
    1311from anuga.abstract_2d_finite_volumes.mesh_factory import rectangular_cross
    1412from anuga.shallow_water.shallow_water_domain import Domain
    15 from anuga.shallow_water.forcing import Rainfall, Inflow
     13from anuga.abstract_2d_finite_volumes.util import file_function
    1614
    1715from anuga.structures.inlet_operator import Inlet_operator
     
    8381        return domain
    8482
    85     def test_inlet_Q(self):
     83    def test_inlet_constant_Q(self):
    8684        """test_inlet_Q
    8785       
     
    129127        assert numpy.allclose((Q1+Q2)*finaltime, vol1-vol0, rtol=1.0e-8)
    130128       
     129    def test_inlet_variable_Q(self):
     130        """test_inlet_Q
    131131       
     132        This tests that the inlet operator adds the correct amount of water
     133        """
     134
     135        stage_0 = 11.0
     136        stage_1 = 10.0
     137        elevation_0 = 10.0
     138        elevation_1 = 10.0
     139
     140        domain_length = 200.0
     141        domain_width = 200.0
     142       
     143
     144        domain = self._create_domain(d_length=domain_length,
     145                                     d_width=domain_width,
     146                                     dx = 10.0,
     147                                     dy = 10.0,
     148                                     elevation_0 = elevation_0,
     149                                     elevation_1 = elevation_1,
     150                                     stage_0 = stage_0,
     151                                     stage_1 = stage_1)
     152
     153        vol0 = domain.compute_total_volume()
     154
     155        finaltime = 3.0
     156        line1 = [[95.0, 10.0], [105.0, 10.0]]
     157        Q1 = file_function('inlet_operator_test1.tms', quantities=['hydrograph'])
     158       
     159        line2 = [[10.0, 90.0], [20.0, 90.0]]
     160        Q2 = file_function('inlet_operator_test2.tms', quantities=['hydrograph'])
     161       
     162        Inlet_operator(domain, line1, Q1)
     163        Inlet_operator(domain, line2, Q2)
     164
     165        for t in domain.evolve(yieldstep = 1.0, finaltime = finaltime):
     166            #domain.write_time()
     167            #print domain.volumetric_balance_statistics()
     168            pass
     169 
     170
     171        vol1 = domain.compute_total_volume()
     172       
     173        print vol1 - vol0
     174       
     175        assert numpy.allclose(13.5, vol1-vol0, rtol=1.0e-8)
     176               
    132177
    133178
Note: See TracChangeset for help on using the changeset viewer.