Changeset 8576


Ignore:
Timestamp:
Sep 13, 2012, 11:49:08 PM (13 years ago)
Author:
steve
Message:

Few changes to operators

Location:
trunk/anuga_core/source/anuga/operators
Files:
4 edited

Legend:

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

    r8483 r8576  
    141141
    142142        elevation = self.get_elevation()
     143
     144        if elevation is None:
     145            return False
    143146
    144147        updated = True
     
    186189
    187190
    188         if elevation is None:
    189             msg = ('Attribute elevation must be specified in '+self.__name__+
    190                    ' before attempting to call it')
    191             raise Exception(msg)
     191#        if elevation is None:
     192#            msg  = 'Attribute elevation must be specified'
     193#            raise Exception(msg)
    192194
    193195        return elevation
  • trunk/anuga_core/source/anuga/operators/set_stage_operators.py

    r8506 r8576  
    6262        """
    6363
     64
    6465        if self.indices is []:
    6566            return
    6667
    6768        stage = self.get_stage()
     69
     70        if stage is None:
     71            return
    6872
    6973        if self.verbose is True:
  • trunk/anuga_core/source/anuga/operators/test_erosion_operators.py

    r8575 r8576  
    1313from anuga.config import time_format
    1414
    15 from erosion_operators import *
     15from anuga.operators.erosion_operators import Erosion_operator
    1616
    1717import numpy as num
     
    3030
    3131
    32     def test_set_erosion_operator_simple(self):
     32    def test_erosion_operator_simple(self):
    3333        from anuga.config import rho_a, rho_w, eta_w
    3434        from math import pi, cos, sin
  • trunk/anuga_core/source/anuga/operators/test_set_operators.py

    r8575 r8576  
    132132        stage_ex = [ -5.,  -5.,   1.,  -5.]
    133133
    134         print domain.quantities['elevation'].centroid_values
    135         print domain.quantities['stage'].centroid_values
    136         print domain.quantities['xmomentum'].centroid_values
    137         print domain.quantities['ymomentum'].centroid_values
     134        #print domain.quantities['elevation'].centroid_values
     135        #print domain.quantities['stage'].centroid_values
     136        #print domain.quantities['xmomentum'].centroid_values
     137        #print domain.quantities['ymomentum'].centroid_values
    138138
    139139        assert num.allclose(domain.quantities['stage'].centroid_values, stage_ex)
     
    143143
    144144
    145     def test_set_erosion_operator_simple(self):
    146         from anuga.config import rho_a, rho_w, eta_w
    147         from math import pi, cos, sin
    148 
    149         a = [0.0, 0.0]
    150         b = [0.0, 2.0]
    151         c = [2.0, 0.0]
    152         d = [0.0, 4.0]
    153         e = [2.0, 2.0]
    154         f = [4.0, 0.0]
    155 
    156         points = [a, b, c, d, e, f]
    157         #             bac,     bce,     ecf,     dbe
    158         vertices = [[1,0,2], [1,2,4], [4,2,5], [3,1,4]]
    159 
    160         domain = Domain(points, vertices)
    161 
    162         #Flat surface with 1m of water
    163         domain.set_quantity('elevation', 0)
    164         domain.set_quantity('stage', 1.0)
    165         domain.set_quantity('friction', 0)
    166         domain.set_quantity('xmomentum',2.0)
    167         domain.set_quantity('ymomentum',3.0)
    168 
    169         Br = Reflective_boundary(domain)
    170         domain.set_boundary({'exterior': Br})
    171 
    172 
    173 #        print domain.quantities['stage'].centroid_values
    174 #        print domain.quantities['xmomentum'].centroid_values
    175 #        print domain.quantities['ymomentum'].centroid_values
    176 
    177         # Apply operator to these triangles
    178         indices = [0,1,3]
    179 
    180 
    181         operator = Erosion_operator(domain, indices=indices)
    182 
    183         # Apply Operator
    184         domain.timestep = 2.0
    185         operator()
    186 
    187         stage_ex = [ 3.,  3.,   1.,  3.]
    188 
    189         print domain.quantities['elevation'].centroid_values
    190         print domain.quantities['stage'].centroid_values
    191         print domain.quantities['xmomentum'].centroid_values
    192         print domain.quantities['ymomentum'].centroid_values
    193 
    194         assert num.allclose(domain.quantities['stage'].centroid_values, stage_ex)
    195         assert num.allclose(domain.quantities['xmomentum'].centroid_values, 0.0)
    196         assert num.allclose(domain.quantities['ymomentum'].centroid_values, 0.0)
    197 
    198 
    199 
    200 #    def test_rate_operator_rate_from_file(self):
    201 #        from anuga.config import rho_a, rho_w, eta_w
    202 #        from math import pi, cos, sin
    203 #
    204 #        a = [0.0, 0.0]
    205 #        b = [0.0, 2.0]
    206 #        c = [2.0, 0.0]
    207 #        d = [0.0, 4.0]
    208 #        e = [2.0, 2.0]
    209 #        f = [4.0, 0.0]
    210 #
    211 #        points = [a, b, c, d, e, f]
    212 #        #             bac,     bce,     ecf,     dbe
    213 #        vertices = [[1,0,2], [1,2,4], [4,2,5], [3,1,4]]
    214 #
    215 #
    216 #        #---------------------------------
    217 #        #Typical ASCII file
    218 #        #---------------------------------
    219 #        finaltime = 1200
    220 #        filename = 'test_file_function'
    221 #        fid = open(filename + '.txt', 'w')
    222 #        start = time.mktime(time.strptime('2000', '%Y'))
    223 #        dt = 60  #One minute intervals
    224 #        t = 0.0
    225 #        while t <= finaltime:
    226 #            t_string = time.strftime(time_format, time.gmtime(t+start))
    227 #            fid.write('%s, %f %f %f\n' %(t_string, 2*t, t**2, sin(t*pi/600)))
    228 #            t += dt
    229 #
    230 #        fid.close()
    231 #
    232 #        #Convert ASCII file to NetCDF (Which is what we really like!)
    233 #        timefile2netcdf(filename+'.txt')
    234 #
    235 #
    236 #        #Create file function from time series
    237 #        F = file_function(filename + '.tms',
    238 #                          quantities = ['Attribute0',
    239 #                                        'Attribute1',
    240 #                                        'Attribute2'])
    241 #
    242 #        #Now try interpolation
    243 #        for i in range(20):
    244 #            t = i*10
    245 #            q = F(t)
    246 #
    247 #            #Exact linear intpolation
    248 #            assert num.allclose(q[0], 2*t)
    249 #            if i%6 == 0:
    250 #                assert num.allclose(q[1], t**2)
    251 #                assert num.allclose(q[2], sin(t*pi/600))
    252 #
    253 #        #Check non-exact
    254 #
    255 #        t = 90 #Halfway between 60 and 120
    256 #        q = F(t)
    257 #        assert num.allclose( (120**2 + 60**2)/2, q[1] )
    258 #        assert num.allclose( (sin(120*pi/600) + sin(60*pi/600))/2, q[2] )
    259 #
    260 #
    261 #        t = 100 #Two thirds of the way between between 60 and 120
    262 #        q = F(t)
    263 #        assert num.allclose( 2*120**2/3 + 60**2/3, q[1] )
    264 #        assert num.allclose( 2*sin(120*pi/600)/3 + sin(60*pi/600)/3, q[2] )
    265 #
    266 #        #os.remove(filename + '.txt')
    267 #        #os.remove(filename + '.tms')
    268 #
    269 #
    270 #        domain = Domain(points, vertices)
    271 #
    272 #        #Flat surface with 1m of water
    273 #        domain.set_quantity('elevation', 0)
    274 #        domain.set_quantity('stage', 1.0)
    275 #        domain.set_quantity('friction', 0)
    276 #
    277 #        Br = Reflective_boundary(domain)
    278 #        domain.set_boundary({'exterior': Br})
    279 #
    280 ##        print domain.quantities['elevation'].centroid_values
    281 ##        print domain.quantities['stage'].centroid_values
    282 ##        print domain.quantities['xmomentum'].centroid_values
    283 ##        print domain.quantities['ymomentum'].centroid_values
    284 #
    285 #        # Apply operator to these triangles
    286 #        indices = [0,1,3]
    287 #
    288 #
    289 #        rate = file_function('test_file_function.tms', quantities=['Attribute1'])
    290 #
    291 #        factor = 1000.0
    292 #        default_rate= 17.7
    293 #
    294 #        operator = Rate_operator(domain, rate=rate, factor=factor, \
    295 #                      indices=indices, default_rate = default_rate)
    296 #
    297 #
    298 #        # Apply Operator
    299 #        domain.set_starttime(360.0)
    300 #        domain.timestep = 1.0
    301 #
    302 #        operator()
    303 #
    304 #
    305 #        d = domain.get_time()**2 * factor + 1.0
    306 #        stage_ex0 = [ d,  d,   1.,  d]
    307 #
    308 ##        print d, domain.get_time(), F(360.0)
    309 #
    310 ##        print domain.quantities['elevation'].centroid_values
    311 ##        print domain.quantities['stage'].centroid_values
    312 ##        print domain.quantities['xmomentum'].centroid_values
    313 ##        print domain.quantities['ymomentum'].centroid_values
    314 #
    315 #        assert num.allclose(domain.quantities['stage'].centroid_values, stage_ex0)
    316 #        assert num.allclose(domain.quantities['xmomentum'].centroid_values, 0.0)
    317 #        assert num.allclose(domain.quantities['ymomentum'].centroid_values, 0.0)
    318 #
    319 #
    320 #        domain.set_starttime(-10.0)
    321 #        domain.timestep = 1.0
    322 #
    323 #        try:
    324 #            operator()
    325 #        except:
    326 #            pass
    327 #        else:
    328 #            raise Exception('Should have raised an exception, time too early')
    329 #
    330 #
    331 #        domain.set_starttime(1300.0)
    332 #        domain.timestep = 1.0
    333 #
    334 #        operator()
    335 #
    336 #        d = default_rate*factor + d
    337 #        stage_ex1 = [ d,  d,   1.,  d]
    338 #
    339 ##        print domain.quantities['elevation'].centroid_values
    340 ##        print domain.quantities['stage'].centroid_values
    341 ##        print domain.quantities['xmomentum'].centroid_values
    342 ##        print domain.quantities['ymomentum'].centroid_values
    343 #
    344 #        assert num.allclose(domain.quantities['stage'].centroid_values, stage_ex1)
    345 #        assert num.allclose(domain.quantities['xmomentum'].centroid_values, 0.0)
    346 #        assert num.allclose(domain.quantities['ymomentum'].centroid_values, 0.0)
    347 
    348 
    349 #    def test_rate_operator_functions_rate_default_rate(self):
    350 #        from anuga.config import rho_a, rho_w, eta_w
    351 #        from math import pi, cos, sin
    352 #
    353 #        a = [0.0, 0.0]
    354 #        b = [0.0, 2.0]
    355 #        c = [2.0, 0.0]
    356 #        d = [0.0, 4.0]
    357 #        e = [2.0, 2.0]
    358 #        f = [4.0, 0.0]
    359 #
    360 #        points = [a, b, c, d, e, f]
    361 #        #             bac,     bce,     ecf,     dbe
    362 #        vertices = [[1,0,2], [1,2,4], [4,2,5], [3,1,4]]
    363 #
    364 #        domain = Domain(points, vertices)
    365 #
    366 #        #Flat surface with 1m of water
    367 #        domain.set_quantity('elevation', 0)
    368 #        domain.set_quantity('stage', 1.0)
    369 #        domain.set_quantity('friction', 0)
    370 #
    371 #        Br = Reflective_boundary(domain)
    372 #        domain.set_boundary({'exterior': Br})
    373 #
    374 #        verbose = False
    375 #
    376 #        if verbose:
    377 #            print domain.quantities['elevation'].centroid_values
    378 #            print domain.quantities['stage'].centroid_values
    379 #            print domain.quantities['xmomentum'].centroid_values
    380 #            print domain.quantities['ymomentum'].centroid_values
    381 #
    382 #        # Apply operator to these triangles
    383 #        indices = [0,1,3]
    384 #        factor = 10.0
    385 #
    386 #
    387 #        def main_rate(t):
    388 #            if t > 20:
    389 #                msg = 'Model time exceeded.'
    390 #                raise Modeltime_too_late, msg
    391 #            else:
    392 #                return 3.0 * t + 7.0
    393 #
    394 #        default_rate = lambda t: 3*t + 7
    395 #
    396 #
    397 #        operator = Rate_operator(domain, rate=main_rate, factor=factor, \
    398 #                      indices=indices, default_rate = default_rate)
    399 #
    400 #
    401 #        # Apply Operator
    402 #        domain.timestep = 2.0
    403 #        operator()
    404 #
    405 #        t = operator.get_time()
    406 #        d = operator.get_timestep()*main_rate(t)*factor + 1
    407 #        stage_ex = [ d,  d,   1.,  d]
    408 #
    409 #        if verbose:
    410 #            print domain.quantities['elevation'].centroid_values
    411 #            print domain.quantities['stage'].centroid_values
    412 #            print domain.quantities['xmomentum'].centroid_values
    413 #            print domain.quantities['ymomentum'].centroid_values
    414 #
    415 #        assert num.allclose(domain.quantities['stage'].centroid_values, stage_ex)
    416 #        assert num.allclose(domain.quantities['xmomentum'].centroid_values, 0.0)
    417 #        assert num.allclose(domain.quantities['ymomentum'].centroid_values, 0.0)
    418 #
    419 #        domain.set_starttime(30.0)
    420 #        domain.timestep = 1.0
    421 #        operator()
    422 #
    423 #        t = operator.get_time()
    424 #        d = operator.get_timestep()*default_rate(t)*factor + d
    425 #        stage_ex = [ d,  d,   1.,  d]
    426 #
    427 #        if verbose:
    428 #            print domain.quantities['elevation'].centroid_values
    429 #            print domain.quantities['stage'].centroid_values
    430 #            print domain.quantities['xmomentum'].centroid_values
    431 #            print domain.quantities['ymomentum'].centroid_values
    432 #
    433 #        assert num.allclose(domain.quantities['stage'].centroid_values, stage_ex)
    434 #        assert num.allclose(domain.quantities['xmomentum'].centroid_values, 0.0)
    435 #        assert num.allclose(domain.quantities['ymomentum'].centroid_values, 0.0)
    436145
    437146           
Note: See TracChangeset for help on using the changeset viewer.