Changeset 7539


Ignore:
Timestamp:
Sep 30, 2009, 12:33:22 PM (15 years ago)
Author:
ole
Message:

Added better error message when simulation time excedds available forcing function timeseries (and no default_rate was set).

Location:
anuga_core/source/anuga/shallow_water
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • anuga_core/source/anuga/shallow_water/shallow_water_domain.py

    r7519 r7539  
    23572357        except Modeltime_too_late, e:
    23582358            if self.default_rate is None:
    2359                 raise Exception, e    # Reraise exception
     2359                msg = '%s: ANUGA is trying to run longer than specified data.\n' %str(e)
     2360                msg += 'You can specify keyword argument default_rate in the '
     2361                msg += 'forcing function to tell it what to do in the absence of time data.'
     2362                raise Modeltime_too_late, msg   
    23602363            else:
    23612364                # Pass control to default rate function
  • anuga_core/source/anuga/shallow_water/test_shallow_water_domain.py

    r7519 r7539  
    29422942            # receives updates from the flux calculation.
    29432943
     2944
     2945    def test_rainfall_forcing_with_evolve_1(self):
     2946        """test_rainfall_forcing_with_evolve
     2947
     2948        Test how forcing terms are called within evolve.
     2949        This test checks that proper exception is thrown when no default_rate is set
     2950        """
     2951
     2952
     2953        a = [0.0, 0.0]
     2954        b = [0.0, 2.0]
     2955        c = [2.0, 0.0]
     2956        d = [0.0, 4.0]
     2957        e = [2.0, 2.0]
     2958        f = [4.0, 0.0]
     2959
     2960        points = [a, b, c, d, e, f]
     2961        #             bac,     bce,     ecf,     dbe
     2962        vertices = [[1,0,2], [1,2,4], [4,2,5], [3,1,4]]
     2963
     2964        domain = Domain(points, vertices)
     2965
     2966        # Flat surface with 1m of water
     2967        domain.set_quantity('elevation', 0)
     2968        domain.set_quantity('stage', 1.0)
     2969        domain.set_quantity('friction', 0)
     2970
     2971        Br = Reflective_boundary(domain)
     2972        domain.set_boundary({'exterior': Br})
     2973
     2974        # Setup only one forcing term, time dependent rainfall
     2975        # that expires at t==20
     2976        from anuga.fit_interpolate.interpolate import Modeltime_too_late
     2977
     2978        def main_rate(t):
     2979            if t > 20:
     2980                msg = 'Model time exceeded.'
     2981                raise Modeltime_too_late, msg
     2982            else:
     2983                return 3*t + 7
     2984
     2985        domain.forcing_terms = []
     2986        R = Rainfall(domain,
     2987                     rate=main_rate,
     2988                     polygon=[[1,1], [2,1], [2,2], [1,2]])
     2989
     2990
     2991        assert num.allclose(R.exchange_area, 2)
     2992       
     2993        domain.forcing_terms.append(R)
     2994        #for t in domain.evolve(yieldstep=1, finaltime=25):
     2995        #    pass
     2996               
     2997        try:
     2998            for t in domain.evolve(yieldstep=1, finaltime=25):
     2999                pass
     3000        except Modeltime_too_late, e:
     3001            # Test that error message is as expected
     3002            assert 'can specify keyword argument default_rate in the forcing function' in str(e)
     3003        else:
     3004            raise Exception, 'Should have raised exception'
     3005
     3006           
     3007           
    29443008    def test_inflow_using_circle(self):
    29453009        from math import pi, cos, sin
     
    74917555
    74927556if __name__ == "__main__":
    7493     #suite = unittest.makeSuite(Test_Shallow_Water, 'test_volumetric_balance')
     7557    #suite = unittest.makeSuite(Test_Shallow_Water, 'test_rainfall_forcing_with_evolve')
    74947558    suite = unittest.makeSuite(Test_Shallow_Water, 'test')
    74957559    runner = unittest.TextTestRunner(verbosity=1)
Note: See TracChangeset for help on using the changeset viewer.