Changeset 9287


Ignore:
Timestamp:
Aug 6, 2014, 9:14:12 AM (11 years ago)
Author:
steve
Message:

Fixed bug in volume reporting with negative rate operators

Location:
trunk/anuga_core
Files:
4 edited
1 moved

Legend:

Unmodified
Added
Removed
  • trunk/anuga_core/source/anuga/operators/rate_operators.py

    r9282 r9287  
    117117        if self.verbose is True:
    118118            log.critical('Rate of %s at time = %.2f = %f'
    119                          % (self.quantity_name, domain.get_time(), rate))
     119                         % (self.quantity_name, self.domain.get_time(), rate))
    120120
    121121        fid = self.full_indices
     
    123123            # Record the local flux for mass conservation tracking
    124124            if indices is None:
    125                 self.local_influx=factor*timestep*(rate*self.areas)[fid].sum()
    126                 self.stage_c[:] = self.stage_c[:]  \
    127                        + factor*rate*timestep
    128             else:
    129                 self.local_influx=factor*timestep*(rate*self.areas)[fid].sum()
     125                local_rates=factor*timestep*rate
     126                self.local_influx = (local_rates*self.areas)[fid].sum()
     127                self.stage_c[:] = self.stage_c[:] + local_rates
     128            else:
     129                local_rates = factor*timestep*rate
     130                self.local_influx=(local_rates*self.areas[fid]).sum()
    130131                self.stage_c[indices] = self.stage_c[indices] \
    131                        + factor*rate*timestep
     132                       + local_rates
    132133        else: # Be more careful if rate < 0
    133134            if indices is None:
    134                 self.local_influx=(num.minimum(factor*timestep*rate, self.stage_c[:]-self.elev_c[:])*self.areas)[fid].sum()
    135                 self.stage_c[:] = num.maximum(self.stage_c  \
    136                        + factor*rate*timestep, self.elev_c )
    137             else:
    138                 self.local_influx=(num.minimum(factor*timestep*rate, self.stage_c[indices]-self.elev_c[indices])*self.areas)[fid].sum()
    139                 self.stage_c[indices] = num.maximum(self.stage_c[indices] \
    140                        + factor*rate*timestep, self.elev_c[indices])
     135                #self.local_influx=(num.minimum(factor*timestep*rate, self.stage_c[:]-self.elev_c[:])*self.areas)[fid].sum()
     136                #self.stage_c[:] = num.maximum(self.stage_c  \
     137                #       + factor*rate*timestep, self.elev_c )
     138                local_rates = num.maximum(factor*timestep*rate, self.elev_c[:]-self.stage_c[:])
     139                self.local_influx = (local_rates*self.areas)[fid].sum()
     140                self.stage_c[:] = self.stage_c + local_rates
     141            else:
     142                #self.local_influx=(num.minimum(factor*timestep*rate, self.stage_c[indices]-self.elev_c[indices])*self.areas)[fid].sum()
     143                #self.stage_c[indices] = num.maximum(self.stage_c[indices] \
     144                #       + factor*rate*timestep, self.elev_c[indices])
     145               
     146                local_rates = num.maximum(factor*timestep*rate, self.elev_c[indices]-self.stage_c[indices])
     147                self.local_influx=(local_rates*self.areas)[fid].sum()
     148                self.stage_c[indices] = self.stage_c[indices] + local_rates
    141149        # Update mass inflows from fractional steps
    142150        self.domain.fractional_step_volume_integral+=self.local_influx
  • trunk/anuga_core/source/anuga/operators/test_rate_operators.py

    r9283 r9287  
    2525
    2626
     27warnings.simplefilter("ignore")
     28
    2729
    2830class Test_rate_operators(unittest.TestCase):
     
    140142
    141143        stage_ex = [ 0.,  0.,   1.,  0.]
     144        step_integral = -6.0
     145
     146        #print domain.quantities['elevation'].centroid_values
     147        #print domain.quantities['stage'].centroid_values
     148        #print domain.quantities['xmomentum'].centroid_values
     149        #print domain.quantities['ymomentum'].centroid_values
     150        #print domain.fractional_step_volume_integral
     151        #print factor*domain.timestep*(rate*domain.areas[indices]).sum()
     152       
     153        #increment = factor*domain.timestep*rate*domain.areas
     154       
     155       
     156
     157        assert num.allclose(domain.quantities['stage'].centroid_values, stage_ex)
     158        assert num.allclose(domain.quantities['xmomentum'].centroid_values, 0.0)
     159        assert num.allclose(domain.quantities['ymomentum'].centroid_values, 0.0)
     160        assert num.allclose(domain.fractional_step_volume_integral, step_integral)
     161
     162    def test_rate_operator_negative_rate_full(self):
     163        from anuga.config import rho_a, rho_w, eta_w
     164        from math import pi, cos, sin
     165
     166        a = [0.0, 0.0]
     167        b = [0.0, 2.0]
     168        c = [2.0, 0.0]
     169        d = [0.0, 4.0]
     170        e = [2.0, 2.0]
     171        f = [4.0, 0.0]
     172
     173        points = [a, b, c, d, e, f]
     174        #             bac,     bce,     ecf,     dbe
     175        vertices = [[1,0,2], [1,2,4], [4,2,5], [3,1,4]]
     176
     177        domain = Domain(points, vertices)
     178
     179        #Flat surface with 1m of water
     180        domain.set_quantity('elevation', 0)
     181        domain.set_quantity('stage', 10.0)
     182        domain.set_quantity('friction', 0)
     183
     184        Br = Reflective_boundary(domain)
     185        domain.set_boundary({'exterior': Br})
    142186
    143187#        print domain.quantities['elevation'].centroid_values
     
    146190#        print domain.quantities['ymomentum'].centroid_values
    147191
    148         assert num.allclose(domain.quantities['stage'].centroid_values, stage_ex)
    149         assert num.allclose(domain.quantities['xmomentum'].centroid_values, 0.0)
    150         assert num.allclose(domain.quantities['ymomentum'].centroid_values, 0.0)
    151         assert num.allclose(domain.fractional_step_volume_integral, factor*domain.timestep*(rate*domain.areas[indices]).sum())
    152 
    153 
     192        # Apply operator to these triangles
     193        indices = [0,1,3]
     194
     195
     196
     197        #Catchment_Rain_Polygon = read_polygon(join('CatchmentBdy.csv'))
     198        #rainfall = file_function(join('1y120m.tms'), quantities=['rainfall'])
     199        rate = -1.0
     200        factor = 10.0
     201        default_rate= 0.0
     202
     203        operator = Rate_operator(domain, rate=rate, factor=factor, \
     204                      indices=None, default_rate = default_rate)
     205
     206
     207        # Apply Operator
     208        domain.timestep = 2.0
     209        operator()
     210
     211        stage_ex = [ 0.,  0.,   0.,  0.]
     212        step_integral = -80.0
     213
     214        #print domain.quantities['elevation'].centroid_values
     215        #print domain.quantities['stage'].centroid_values
     216        #print domain.quantities['xmomentum'].centroid_values
     217        #print domain.quantities['ymomentum'].centroid_values
     218        #print domain.fractional_step_volume_integral
     219
     220
     221        assert num.allclose(domain.quantities['stage'].centroid_values, stage_ex)
     222        assert num.allclose(domain.quantities['xmomentum'].centroid_values, 0.0)
     223        assert num.allclose(domain.quantities['ymomentum'].centroid_values, 0.0)
     224        assert num.allclose(domain.fractional_step_volume_integral, step_integral)
     225       
    154226    def test_rate_operator_rate_from_file(self):
    155227        from anuga.config import rho_a, rho_w, eta_w
  • trunk/anuga_core/validation_tests/case_studies/towradgi/simulation.py

    r9276 r9287  
    2727
    2828#from project import *
    29 
    3029
    3130
  • trunk/anuga_core/validation_tests/reports/all_tests_report.tex

    r9241 r9287  
    122122%%======================
    123123\inputresults{../experimental_data/dam_break_yeh_petroff}
     124\inputresults{../experimental_data/okushiri}
     125
    124126\inputresults{../behaviour_only/lid_driven_cavity}
    125127\inputresults{../behaviour_only/weir_1}
     128\inputresults{../behaviour_only/bridge_hecras}
     129\inputresults{../behaviour_only/lateral_weir_hecras}
     130\inputresults{../behaviour_only/tides_hecras}
    126131
    127132\inputresults{../other_references/radial_dam_break_dry}
    128133\inputresults{../other_references/radial_dam_break_wet}
    129 
    130 \inputresults{../case_studies/okushiri}
    131134
    132135
     
    139142
    140143
    141 To setup a new validation test, create a test directory under the
    142 \textsc{Tests} directory. In that directory there should be the test code, a
     144To setup a new validation test, create a test directory under one of
     145the validation directories. In that directory there should be the test code, a
    143146\TeX{} file \texttt{results.tex} and a python script
    144147\texttt{produce\_results.py}, which runs the simulation and produces the
    145 outputs. Copy the format from the other test directory.
     148outputs. Copy the format from one of the other test directories.
    146149
    147150In this \TeX{} file, \texttt{report.tex}, add a line
    148151\begin{verbatim}
    149 \inputresults{Tests/Directory/Name}
     152\inputresults{../Directory/Name}
    150153\end{verbatim}
    151154
     
    175178
    176179\begin{verbatim}
    177 from anuga.validation_utilities.fabricate import *
    178 from anuga.validation_utilities import run_validation_script
     180import anuga
     181from anuga.validation_utilities import produce_report
    179182
    180 # Setup the python scripts which produce the output for this
    181 # validation test
    182 def build():
    183     run_validation_script('run_problem.py')
    184     run_validation_script('plot_problem.py')
    185     run('python','typeset_report.py')
    186     pass
     183args = anuga.get_args()
    187184
    188 def clean():
    189     autoclean()
    190 
    191 main()
     185produce_report('run_simulation.py', args=args)
    192186\end{verbatim}
    193 This script uses \texttt{fabricate} which automatically determines dependences
    194 and only runs the command if the parameters alg and cfl have changed,
    195 or input/output or source files have changed. (\texttt{fabricate} is a replacement for
    196 standard \texttt{make})
    197187
    198188
Note: See TracChangeset for help on using the changeset viewer.