Ignore:
Timestamp:
Jul 20, 2014, 10:32:49 PM (11 years ago)
Author:
steve
Message:

Cleaning up auto validation tests

Location:
trunk/anuga_core/validation_tests/analytical_exact
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/anuga_core/validation_tests/analytical_exact/avalanche_dry/validate_avalanche_dry.py

    r9241 r9273  
    2626        pass
    2727
    28     def test_simulation(self):
     28    def test_avalanche_dry(self):
    2929   
    3030
     
    8787
    8888
    89         if verbose:
    90             print indent+'Errors in stage: ',eh10, eh30
     89        print
     90        print indent+'Errors in stage: ',eh10, eh30
    9191
    92         assert eh10 < 0.01,  'L^1 error %g greater than 1 percent'% eh10
    93         assert eh30 < 0.01,  'L^1 error %g greater than 1 percent'% eh30
    9492
    9593
     
    9896        euh10 = numpy.sum(numpy.abs(uh10_n-u10*h10))/numpy.sum(numpy.abs(u10*h10))
    9997        euh30 = numpy.sum(numpy.abs(uh30_n-u30*h30))/numpy.sum(numpy.abs(u30*h30))
    100        
     98   
    10199
    102         if verbose:
    103             print indent+'Errors in xmomentum: ',euh10, euh30
    104 
    105 
    106         assert euh10 < 0.025,  'L^1 error %g greater than 2.5 percent'% euh10
    107         assert euh30 < 0.025,  'L^1 error %g greater than 2.5 percent'% euh30
    108 
    109 
     100        print indent+'Errors in xmomentum: ',euh10, euh30
    110101
    111102        #Test xvelocity
     
    114105        eu30 = numpy.sum(numpy.abs(u30_n-u30))/numpy.sum(numpy.abs(u30))
    115106
    116         if verbose:
    117             print indent+'Errors in xvelocity: ', eu10, eu30
     107
     108        print indent+'Errors in xvelocity: ', eu10, eu30
     109
     110
     111        assert eh10 < 0.01,  'L^1 error %g greater than 1 percent'% eh10
     112        assert eh30 < 0.01,  'L^1 error %g greater than 1 percent'% eh30
     113
     114        assert euh10 < 0.025,  'L^1 error %g greater than 2.5 percent'% euh10
     115        assert euh30 < 0.025,  'L^1 error %g greater than 2.5 percent'% euh30
     116
    118117
    119118        assert eu10 < 0.2,  'L^1 error %g greater than 20 percent'% eu10
  • trunk/anuga_core/validation_tests/analytical_exact/avalanche_wet/numerical_avalanche_wet.py

    r9241 r9273  
    77# Import necessary modules
    88#------------------------------------------------------------------------------
    9 import sys
    109import anuga
    11 from anuga import Domain as Domain
    12 from math import cos
     10from anuga import Domain
     11from anuga import Operator
     12
    1313from numpy import zeros
    14 from time import localtime, strftime, gmtime
    15 from numpy import sin, cos, tan, arctan
     14from time import localtime, strftime
     15from numpy import cos, arctan
    1616from anuga import myid, finalize, distribute
    1717
     
    4545verbose = args.verbose
    4646
    47 class Coulomb_friction:
    48    
    49     def __init__(self,
     47
     48
     49
     50class Coulomb_friction(object):
     51   
     52    def __init__(self,                 
    5053                 friction_slope=0.05,
    5154                 bed_slope=0.1):
     
    5760        self.F = g*cos(thet)*cos(thet)*friction_slope
    5861        self.m = -1.0*g*bed_slope + self.F
    59        
    60     def __call__(self, domain):       
    61 
    62         w = domain.quantities['stage'].centroid_values
    63         z = domain.quantities['elevation'].centroid_values
    64         h = w-z
    65 
    66         xmom_update = domain.quantities['xmomentum'].explicit_update
    67         #ymom_update = domain.quantities['ymomentum'].explicit_update
    68 
    69         xmom_update[:] = xmom_update + self.F*h
     62   
     63
     64class Friction_operator(Operator):
     65   
     66    def __init__(self,
     67                 domain,
     68                 friction=None,
     69                 description = None,
     70                 label = None,
     71                 logging = False,
     72                 verbose = False):
     73
     74        Operator.__init__(self, domain, description, label, logging, verbose)
     75
     76       
     77        self.friction = friction
     78        self.F = self.friction.F
     79        self.m = self.friction.m
     80       
     81    def __call__(self):       
     82
     83        timestep = self.domain.get_timestep()
     84       
     85        h = self.stage_c - self.elev_c
     86
     87        self.xmom_c[:] = self.xmom_c + timestep* self.F*h
     88
     89    def parallel_safe(self):
     90        """Operator is applied independently on each cell and
     91        so is parallel safe.
     92        """
     93        return True
     94
     95
     96
    7097
    7198
    7299bed_slope = 0.1
    73100friction_slope = 0.05
    74 Coulomb_forcing_term = Coulomb_friction(friction_slope, bed_slope)
     101coulomb_friction = Coulomb_friction(friction_slope, bed_slope)
     102#coulomb_forcing_term = Coulomb_friction(friction_slope, bed_slope)
    75103
    76104def stage(X,Y):
     
    95123    h_r = h_0 #+ bed_slope*cell_len
    96124    w_r = z_r + h_r
    97     u_r = Coulomb_forcing_term.m*t
     125    u_r = coulomb_friction.m*t
    98126    #['stage', 'xmomentum', 'ymomentum']
    99127    return [w_r,  u_r*h_r,  0.0]
     
    103131    h_l = h_1 #+ bed_slope*cell_len
    104132    w_l = z_l + h_l
    105     u_l = Coulomb_forcing_term.m*t
     133    u_l = coulomb_friction.m*t
    106134    #['stage', 'xmomentum', 'ymomentum']
    107135    return [w_l,  u_l*h_l,  0.0]
     
    132160    domain.set_quantity('friction', 0.0)
    133161   
    134     domain.forcing_terms.append(Coulomb_forcing_term)
    135162   
    136163    domain.set_quantity('stage', stage)
     
    146173#===============================================================================
    147174domain = distribute(domain)
     175
     176
     177#------------------------------------------------------------------------------
     178# Setup Operators
     179#------------------------------------------------------------------------------
     180Friction_operator(domain, friction=coulomb_friction)
    148181
    149182#-----------------------------------------------------------------------------
  • trunk/anuga_core/validation_tests/analytical_exact/avalanche_wet/validate_avalanche_wet.py

    r9241 r9273  
    2626        pass
    2727
    28     def test_simulation(self):
     28    def test_avalanche_wet(self):
    2929   
    3030
     
    8484
    8585
    86         if verbose:
    87             print indent+'Errors in stage: ',eh20, eh40
     86        print
     87        print indent+'Errors in stage: ',eh20, eh40
    8888
    89         assert eh20 < 0.01,  'L^1 error %g greater than 1 percent'% eh20
    90         assert eh40 < 0.01,  'L^1 error %g greater than 1 percent'% eh40
     89
    9190
    9291
     
    9796
    9897
    99         if verbose:
    100             print indent+'Errors in xmomentum: ',euh20, euh40
    101 
    102 
    103         assert euh20 < 0.025,  'L^1 error %g greater than 2.5 percent'% euh20
    104         assert euh40 < 0.025,  'L^1 error %g greater than 2.5 percent'% euh40
    105 
    106 
     98        print indent+'Errors in xmomentum: ',euh20, euh40
    10799
    108100        #Test xvelocity
     
    111103        eu40 = numpy.sum(numpy.abs(u40_n-u40))/numpy.sum(numpy.abs(u40))
    112104
    113         if verbose:
    114             print indent+'Errors in xvelocity: ', eu20, eu40
     105        print indent+'Errors in xvelocity: ', eu20, eu40
    115106
     107        assert eh20 < 0.01,  'L^1 error %g greater than 1 percent'% eh20
     108        assert eh40 < 0.01,  'L^1 error %g greater than 1 percent'% eh40
     109       
     110        assert euh20 < 0.025,  'L^1 error %g greater than 2.5 percent'% euh20
     111        assert euh40 < 0.025,  'L^1 error %g greater than 2.5 percent'% euh40
     112       
    116113        assert eu20 < 0.02,  'L^1 error %g greater than 2 percent'% eu20
    117114        assert eu40 < 0.01,  'L^1 error %g greater than 2 percent'% eu40
  • trunk/anuga_core/validation_tests/analytical_exact/carrier_greenspan_periodic/numerical_carrier_greenspan.py

    r9179 r9273  
    173173#------------------------------------------------------------------------------
    174174for t in domain.evolve(yieldstep = Tp/48., finaltime = 7000.):
    175     if myid == 0: print domain.timestepping_statistics()
     175    if myid == 0 and verbose: print domain.timestepping_statistics()
    176176
    177177
  • trunk/anuga_core/validation_tests/analytical_exact/carrier_greenspan_periodic/validate_carrier_greenspan_periodic.py

    r9241 r9273  
    2626        pass
    2727
    28     def test_simulation(self):
     28    def test_carrier_greenspan_periodic(self):
    2929   
    3030
     
    8989            ew[i] = numpy.sum(numpy.abs(W_n[i]-W[i]))/numpy.sum(numpy.abs(W[i]))
    9090 
    91         if verbose:
    92             print indent+'L^1 Errors in stage: ', ew
    9391
    94         for i, id in enumerate(ids):
    95             assert ew[i] < 0.01,  'L^1 error %g greater than 1 percent'% ew[i]
    96 
     92        print
     93        print indent+'L^1 Errors in stage: ', ew
    9794
    9895        #Test xmomenta
     
    106103
    107104       
    108 
    109         if verbose:
    110             print indent+'L^1 Errors in xmomentum: ',euh
    111 
    112         for i, id in enumerate(ids):
    113             assert euh[i] < 0.02,  'L^1 error %g greater than 2 percent'% euh[i]
    114            
     105        print indent+'L^1 Errors in xmomentum: ',euh   
    115106
    116107        #Test xvelocity
     
    124115                eu[i] = numpy.sum(numpy.abs(U_n[i]-U[i]))/numpy.sum(numpy.abs(U[i]))
    125116
    126         if verbose:
    127             print indent+'L^1 Errors in xvelocity: ', eu
     117        print indent+'L^1 Errors in xvelocity: ', eu
    128118
     119        for i, id in enumerate(ids):
     120            assert ew[i] < 0.01,  'L^1 error %g greater than 1 percent'% ew[i]
     121
     122        for i, id in enumerate(ids):
     123            assert euh[i] < 0.02,  'L^1 error %g greater than 2 percent'% euh[i]
     124 
    129125        for i, id in enumerate(ids):
    130126            assert eu[i] < 0.1,  'L^1 error %g greater than 10 percent'% eu[i]
  • trunk/anuga_core/validation_tests/analytical_exact/carrier_greenspan_transient/validate_carrier_greenspan_transient.py

    r9155 r9273  
    1515indent = anuga.indent
    1616
    17 verbose = True
     17args = anuga.get_args()
     18verbose = args.verbose
    1819
    1920class Test_results(unittest.TestCase):
     
    3031        pass
    3132
    32     def test_simulation(self):
     33    def test_carrier_greenspan_transient(self):
    3334   
    3435
     
    3839
    3940        s = 'numerical_cg_transient.py'
    40         res = os.system('python %s > validate_output.stdout' %s)
    41 
     41        res = anuga.run_anuga_script(s,args=args)
     42       
    4243        # Test that script runs ok
    4344        assert res == 0
     
    103104            ew[i] = numpy.sum(numpy.abs(W_n[i]-W[i]))/numpy.sum(numpy.abs(W[i]))
    104105 
    105         if verbose:
    106             print indent+'L^1 Errors in stage: ', ew
     106        print
     107        print indent+'L^1 Errors in stage: ', ew
    107108
    108         for i, id in enumerate(ids):
    109             assert ew[i] < 0.01,  'L^1 error %g greater than 1 percent'% ew[i]
    110109
    111110
     
    117116
    118117       
    119 
    120         if verbose:
    121             print indent+'L^1 Errors in xmomentum: ',euh
    122 
    123         for i, id in enumerate(ids):
    124             assert euh[i] < 0.025,  'L^1 error %g greater than 2 percent'% euh[i]
    125            
     118        print indent+'L^1 Errors in xmomentum: ',euh   
    126119
    127120        #Test xvelocity
     
    135128                eu[i] = numpy.sum(numpy.abs(U_n[i]-U[i]))/numpy.sum(numpy.abs(U[i]))
    136129
    137         if verbose:
    138             print indent+'L^1 Errors in xvelocity: ', eu
     130        print indent+'L^1 Errors in xvelocity: ', eu
    139131
    140132        for i, id in enumerate(ids):
    141             assert eu[i] < 0.02,  'L^1 error %g greater than 2 percent'% eu[i]
     133            assert ew[i] < 0.01,  'L^1 error %g greater than 1 percent'% ew[i]
     134
     135        for i, id in enumerate(ids):
     136            assert euh[i] < 0.025,  'L^1 error %g greater than 2.5 percent'% euh[i]
     137
     138        for i, id in enumerate(ids):
     139            assert eu[i] < 0.025,  'L^1 error %g greater than 2.5 percent'% eu[i]
    142140
    143141
  • trunk/anuga_core/validation_tests/analytical_exact/dam_break_dry/validate_dam_break_dry.py

    r9174 r9273  
    2828        pass
    2929
    30     def test_simulation(self):
     30    def test_dam_break_dry(self):
    3131   
    3232
     
    7070        eh100 = numpy.sum(numpy.abs(p2_st.stage[100,v2]-h100))/numpy.sum(numpy.abs(h100))
    7171
    72         if verbose:
    73             print indent+'Errors in stage: ',eh10, eh50, eh100
    74 
    75         assert eh10 < 0.1,  'Relative L^1 error %g greater than 0.1'% eh10
    76         assert eh50 < 0.1,  'Relative L^1 error %g greater than 0.1'% eh50
    77         assert eh100 < 0.15, 'Relative L^1 error %g greater than 0.15'% eh100
     72        print
     73        print indent+'Errors in stage: ',eh10, eh50, eh100
    7874
    7975
     
    8480        euh100 = numpy.sum(numpy.abs(p2_st.xmom[100,v2]-u100*h100))/numpy.sum(numpy.abs(u100*h100))
    8581
    86         if verbose:
    87             print indent+'Errors in xmomentum: ',euh10, euh50, euh100
    88 
    89 
    90         assert euh10 < 0.25,  'Relative L^1 error %g greater than 0.25'% euh10
    91         assert euh50 < 0.25,  'Relative L^1 error %g greater than 0.25'% euh50
    92         assert euh100 < 0.25, 'Relative L^1 error %g greater than 0.25'% euh100
    93 
     82        print indent+'Errors in xmomentum: ',euh10, euh50, euh100
    9483
    9584        #Test xvelocity
     
    9988        eu100 = numpy.sum(numpy.abs(p2_st.xvel[100,v2]-u100))/numpy.sum(numpy.abs(u100))
    10089
    101         if verbose:
    102             print indent+'Errors in xvelocity: ', eu10, eu50, eu100
     90        print indent+'Errors in xvelocity: ', eu10, eu50, eu100
     91
     92
     93        assert eh10 < 0.1,  'Relative L^1 error %g greater than 0.1'% eh10
     94        assert eh50 < 0.1,  'Relative L^1 error %g greater than 0.1'% eh50
     95        assert eh100 < 0.15, 'Relative L^1 error %g greater than 0.15'% eh100
     96
     97        assert euh10 < 0.25,  'Relative L^1 error %g greater than 0.25'% euh10
     98        assert euh50 < 0.25,  'Relative L^1 error %g greater than 0.25'% euh50
     99        assert euh100 < 0.25, 'Relative L^1 error %g greater than 0.25'% euh100
    103100
    104101        assert eu10 < 2.0,  'Relative L^1 error %g greater than 2.0'% eu10
  • trunk/anuga_core/validation_tests/analytical_exact/dam_break_wet/validate_dam_break_wet.py

    r9174 r9273  
    2727        pass
    2828
    29     def test_simulation(self):
     29    def test_dam_break_wet(self):
    3030   
    3131
     
    6969        eh100 = numpy.sum(numpy.abs(p2_st.stage[100,v2]-h100))/numpy.sum(numpy.abs(h100))
    7070
    71         if verbose:
    72             print indent+'Errors in stage: ',eh10, eh50, eh100
    73 
    74         assert eh10 < 0.01,  'L^1 error %g greater than 1\%'% eh10
    75         assert eh50 < 0.01,  'L^1 error %g greater than 1\%'% eh50
    76         assert eh100 < 0.01, 'L^1 error %g greater than 1\%'% eh100
    77 
     71        print
     72        print indent+'Errors in stage: ',eh10, eh50, eh100
    7873
    7974        #Test xmomenta
     
    8378        euh100 = numpy.sum(numpy.abs(p2_st.xmom[100,v2]-u100*h100))/numpy.sum(numpy.abs(u100*h100))
    8479
    85         if verbose:
    86             print indent+'Errors in xmomentum: ',euh10, euh50, euh100
    87 
    88 
    89         assert euh10 < 0.02,  'L^1 error %g greater than 2\%'% euh10
    90         assert euh50 < 0.01,  'L^1 error %g greater than 1\%'% euh50
    91         assert euh100 < 0.01, 'L^1 error %g greater than 1\%'% euh100
    92 
     80        print indent+'Errors in xmomentum: ',euh10, euh50, euh100
    9381
    9482        #Test xvelocity
     
    9886        eu100 = numpy.sum(numpy.abs(p2_st.xvel[100,v2]-u100))/numpy.sum(numpy.abs(u100))
    9987
    100         if verbose:
    101             print indent+'Errors in xvelocity: ', eu10, eu50, eu100
     88        print indent+'Errors in xvelocity: ', eu10, eu50, eu100
     89
     90        assert eh10 < 0.01,  'L^1 error %g greater than 1\%'% eh10
     91        assert eh50 < 0.01,  'L^1 error %g greater than 1\%'% eh50
     92        assert eh100 < 0.01, 'L^1 error %g greater than 1\%'% eh100
     93
     94        assert euh10 < 0.02,  'L^1 error %g greater than 2\%'% euh10
     95        assert euh50 < 0.01,  'L^1 error %g greater than 1\%'% euh50
     96        assert euh100 < 0.01, 'L^1 error %g greater than 1\%'% euh100
    10297
    10398        assert eu10 < 0.02,  'L^1 error %g greater than 2\%'% eu10
Note: See TracChangeset for help on using the changeset viewer.