Changeset 281


Ignore:
Timestamp:
Sep 7, 2004, 10:29:42 PM (21 years ago)
Author:
ole
Message:

Got datamanager for sww smooth to work.
Non-smooth does not work yet and tests are unfinished

Location:
inundation/ga/storm_surge/pyvolution
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • inundation/ga/storm_surge/pyvolution/HUSK.txt

    r272 r281  
    11
    2        
     2Do datamanager for non-smooth data + tests. Smooth is OK (7/9)
     3               
    34       
    45Perhaps control old/new style with minimum_allowed height
  • inundation/ga/storm_surge/pyvolution/data_manager.py

    r280 r281  
    286286   
    287287
    288     def store_all(self):
     288    def store_connectivity(self):
    289289        """Writes x,y,z coordinates of triangles constituting
    290290        the bed elevation.
     
    294294        raise msg
    295295
    296    
    297296    def store_timestep(self, t, V0, V1, V2):
    298297        """Store time, water heights (and momentums) to file
     
    364363        fid.close()               
    365364
    366     def store_all(self):
    367         """Specialisation of store all for net CDF format
     365
     366    def store_connectivity(self):
     367        """Specialisation of store_connectivity for net CDF format
    368368
    369369        Writes x,y,z coordinates of triangles constituting
     
    387387        volumes = fid.variables['volumes']
    388388
    389         # Get X, Y and bed elevation (index=0)
    390         X,Y,A,V = domain.get_vertex_values(xy=True,
    391                                            value_array='field_values',
    392                                            indices = (0,),
    393                                            precision = self.precision)
    394 
    395 
    396         x[:] = X
    397         y[:] = Y
    398         z[:] = A[:,0]
     389        # Get X, Y and bed elevation Z
     390        Q = domain.quantities['elevation']
     391        X,Y,Z,V = Q.get_vertex_values(xy=True,
     392                                      precision = self.precision)
     393                                     
     394
     395
     396        x[:] = X.astype(self.precision)
     397        y[:] = Y.astype(self.precision)
     398        z[:] = Z.astype(self.precision)
    399399
    400400        volumes[:] = V
     
    404404
    405405
    406     def store_timestep(self):
    407         """Store time, water heights (and momentums) to file
     406    def store_timestep(self, name):
     407        """Store time and named quantity to file
    408408        """
    409409        from Scientific.IO.NetCDF import NetCDFFile
     
    443443        time[i] = self.domain.time
    444444
    445         # Get stage (index = 0)
    446         A,V = domain.get_vertex_values(xy=False,
    447                                        value_array='conserved_quantities',
    448                                        indices = (0,),
    449                                        precision = self.precision)
    450 
    451        
    452         stage[i,:] = A[:,0]  #Only store stage
     445        # Get quantity
     446        Q = domain.quantities[name]
     447        A,V = Q.get_vertex_values(xy=False,
     448                                  precision = self.precision)
     449       
     450        stage[i,:] = A.astype(self.precision)
    453451
    454452        #Flush and close
  • inundation/ga/storm_surge/pyvolution/quantity.py

    r275 r281  
    300300
    301301            if xy is True:
    302                 X = self.domain.coordinates[:,0]
    303                 Y = self.domain.coordinates[:,1]
     302                X = self.domain.coordinates[:,0].astype(precision)
     303                Y = self.domain.coordinates[:,1].astype(precision)
     304               
    304305                return X, Y, A, V
    305306            else:
     
    311312            M = 3*m        #Total number of unique vertices
    312313
    313             A = self.vertex_values[:]
     314            A = self.vertex_values.flat
    314315
    315316            #Create connectivity
     
    321322                C = self.domain.get_vertex_coordinates()
    322323
    323                 X = C[:,0:6:2].copy()
    324                 Y = C[:,1:6:2].copy()               
    325 
     324                #X = C[:,0:6:2].copy()
     325                #Y = C[:,1:6:2].copy()               
     326
     327                X = concatenate((C[:,0], C[:,2], C[:,4]),
     328                                axis=0).astype(precision)
     329                Y = concatenate((C[:,1], C[:,3], C[:,5]),
     330                                axis=0).astype(precision)
     331               
     332               
    326333               
    327334                return X.flat, Y.flat, A, V           
  • inundation/ga/storm_surge/pyvolution/shallow_water.py

    r280 r281  
    4242        #Stored output
    4343        self.store=False
    44         self.format = 'dat'   
     44        self.format = 'sww'   
    4545        self.smooth = True
    4646
     
    110110        #Store model data, e.g. for visualisation   
    111111        if self.store is True and self.time == 0.0:
    112             #FIXME: Could be wrapped into local store_bathymetry and store_timestep
    113             self.intialise_storage()
    114             self.store_quantity('elevation')       
     112            self.initialise_storage()   
     113           
    115114
    116115        #Call basic machinery from parent class
     
    122121            #Store model data, e.g. for subsequent visualisation   
    123122            if self.store is True:
    124                 self.store_timestep() #FIXME: An idea               
    125                 self.store_quantity('level')
     123                self.writer.store_timestep('level')
     124                #FIXME: Could maybe be taken from specified list
     125                #of 'store every step' quantities       
    126126
    127127
     
    130130       
    131131
     132    def initialise_storage(self):       
     133        """Save x,y and bed elevation
     134        """
     135
     136        import data_manager
     137       
     138        #Initialise writer
     139        self.writer = data_manager.get_dataobject(self, mode = 'w')
     140
     141        #Store vertices and connectivity
     142        self.writer.store_connectivity()                   
     143       
     144       
    132145
    133146    def store_quantity(self, name):
    134         """Store named quantity to file using foormat and filename
     147        """Store named quantity to file using format and filename
    135148        """
    136149
     150        #FIXME: NOT IN USE
     151       
    137152        Q = self.quantities[name]
    138153        Q.store(self.filename, self.format)
  • inundation/ga/storm_surge/pyvolution/show_balanced_limiters.py

    r272 r281  
    3535domain = Domain(points, vertices, boundary)
    3636domain.smooth = False
    37 domain.visualise = False
     37#domain.visualise = False
    3838domain.visualise = True
    3939domain.default_order = 2
    4040
     41#domain.store = True
    4142
    4243#Set bed-slope and friction
  • inundation/ga/storm_surge/pyvolution/test_data_manager.py

    r276 r281  
    128128
    129129
    130 #     def test_sww_constant(self):
    131 #         """Test that constant sww information can be written correctly
    132 #         (non smooth)
    133 #         """
    134 
    135 #         import time, os
    136 #         from Numeric import array, zeros, allclose, Float, concatenate
    137 #         from Scientific.IO.NetCDF import NetCDFFile       
    138 
    139 #         self.domain.filename = 'datatest' + str(time.time())
    140 #         self.domain.format = 'sww'
    141 #         self.domain.smooth = False
    142        
    143 #         sww = get_dataobject(self.domain)
    144 #         sww.store_all()
    145 
    146 #         #Check contents
    147 #         #Get NetCDF
    148 #         fid = NetCDFFile(sww.filename, 'r')  #Open existing file for append
    149        
    150 #         # Get the variables
    151 #         x = fid.variables['x']
    152 #         y = fid.variables['y']
    153 #         z = fid.variables['z']
    154 
    155 #         volumes = fid.variables['volumes']       
    156 
    157 #         assert allclose (x[:], concatenate( (self.X0, self.X1, self.X2) ))
    158 #         assert allclose (y[:], concatenate( (self.Y0, self.Y1, self.Y2) ))
    159 #         assert allclose (z[:], concatenate( (self.F0[:,0],
    160 #                                              self.F1[:,0],
    161 #                                              self.F2[:,0]) ))
    162 
    163 #         V = volumes
    164 
    165 #         P = len(self.domain)
    166 #         for k in range(P):
    167 #              assert V[k,0] == V[k,1] - P
    168 #              assert V[k,1] == V[k,2] - P
    169        
    170 
    171 
    172        
    173 #         fid.close()
    174        
    175 #         #Cleanup
    176 #         os.remove(sww.filename)
    177 
    178 
    179 #     def test_sww_constant_smooth(self):
    180 #         """Test that constant sww information can be written correctly
    181 #         (non smooth)
    182 #         """
    183 
    184 
    185 #         import time, os
    186 #         from Numeric import array, zeros, allclose, Float, concatenate
    187 #         from Scientific.IO.NetCDF import NetCDFFile       
    188 
    189 #         self.domain.filename = 'datatest' + str(time.time())
    190 #         self.domain.format = 'sww'
    191 #         self.domain.smooth = True
    192        
    193 #         sww = get_dataobject(self.domain)
    194 #         sww.store_all()
    195 
    196 #         #Check contents
    197 #         #Get NetCDF
    198 #         fid = NetCDFFile(sww.filename, 'r')  #Open existing file for append
    199        
    200 #         # Get the variables
    201 #         x = fid.variables['x']
    202 #         y = fid.variables['y']
    203 #         z = fid.variables['z']
    204 
    205 #         volumes = fid.variables['volumes']       
    206 
    207 #         X = x[:]
    208 #         Y = y[:]
    209        
    210 #         assert allclose([X[0], Y[0]], array([0.0, 0.0]))
    211 #         assert allclose([X[1], Y[1]], array([0.0, 0.5]))
    212 #         assert allclose([X[2], Y[2]], array([0.0, 1.0]))
    213 
    214 #         assert allclose([X[4], Y[4]], array([0.5, 0.5]))
    215 
    216 #         assert allclose([X[7], Y[7]], array([1.0, 0.5]))       
    217 
    218 #         Z = z[:]
    219 #         assert Z[4] == -0.5
    220 
    221 
    222 
    223 #         V = volumes
    224 #         assert V[2,0] == 4
    225 #         assert V[2,1] == 5
    226 #         assert V[2,2] == 1
    227 
    228 #         assert V[4,0] == 6
    229 #         assert V[4,1] == 7
    230 #         assert V[4,2] == 3                     
    231        
    232        
    233 
    234 
    235        
    236 #         fid.close()
    237        
    238 #         #Cleanup
    239 #         os.remove(sww.filename)
    240 
    241 
    242 
    243 #     def test_sww_variable(self):
    244 #         """Test that sww information can be written correctly
    245 #         """
    246 
    247 #         import time, os
    248 #         from Numeric import array, zeros, allclose, Float, concatenate
    249 #         from Scientific.IO.NetCDF import NetCDFFile       
    250 
    251 #         self.domain.filename = 'datatest' + str(time.time())
    252 #         self.domain.format = 'sww'
    253 #         self.domain.smooth = True
    254 #         self.domain.reduction = mean             
    255        
    256 #         sww = get_dataobject(self.domain)
    257 #         sww.store_all()
    258 #         sww.store_timestep()
    259 
    260 #         #Check contents
    261 #         #Get NetCDF
    262 #         fid = NetCDFFile(sww.filename, 'r')  #Open existing file for append
    263        
    264 
    265 #         # Get the variables
    266 #         x = fid.variables['x']
    267 #         y = fid.variables['y']
    268 #         z = fid.variables['z']       
    269 #         time = fid.variables['time']
    270 #         stage = fid.variables['stage']
    271 
    272 
    273 #         Q0 = self.domain.volume_class.conserved_quantities_vertex0
    274 #         Q1 = self.domain.volume_class.conserved_quantities_vertex1
    275 #         Q2 = self.domain.volume_class.conserved_quantities_vertex2       
    276 
    277 #         A = stage[0,:]
    278 #         #print A[0], (Q2[0,0] + Q1[1,0])/2
    279 #         assert allclose(A[0], (Q2[0,0] + Q1[1,0])/2) 
    280 #         assert allclose(A[1], (Q0[1,0] + Q1[3,0] + Q2[2,0])/3)
    281 #         assert allclose(A[2], Q0[3,0])
    282 #         assert allclose(A[3], (Q0[0,0] + Q1[5,0] + Q2[4,0])/3)
    283 
    284 #         #Center point
    285 #         assert allclose(A[4], (Q1[0,0] + Q2[1,0] + Q0[2,0] +\
    286 #                                  Q0[5,0] + Q2[6,0] + Q1[7,0])/6)
    287                                  
    288        
    289        
    290 #         fid.close()
    291        
    292 #         #Cleanup
    293 #         os.remove(sww.filename)
     130    def test_sww_constant(self):
     131        """Test that constant sww information can be written correctly
     132        (non smooth)
     133        """
     134
     135        import time, os
     136        from Numeric import array, zeros, allclose, Float, concatenate
     137        from Scientific.IO.NetCDF import NetCDFFile       
     138
     139        self.domain.filename = 'datatest' + str(time.time())
     140        self.domain.format = 'sww'
     141        self.domain.smooth = False
     142     
     143        sww = get_dataobject(self.domain)
     144        sww.store_connectivity()
     145
     146        #Check contents
     147        #Get NetCDF
     148        fid = NetCDFFile(sww.filename, 'r')  #Open existing file for append
     149     
     150        # Get the variables
     151        x = fid.variables['x']
     152        y = fid.variables['y']
     153        z = fid.variables['z']
     154
     155        volumes = fid.variables['volumes']       
     156
     157        #print z[:]
     158        #print self.F.flat
     159        #print concatenate( (self.X0, self.X1, self.X2))
     160                       
     161        assert allclose (x[:], concatenate( (self.X0, self.X1, self.X2) ))
     162        assert allclose (y[:], concatenate( (self.Y0, self.Y1, self.Y2) ))
     163        assert allclose (z[:], self.F.flat)
     164
     165        V = volumes
     166
     167        P = len(self.domain)
     168        for k in range(P):
     169             assert V[k,0] == V[k,1] - P
     170             assert V[k,1] == V[k,2] - P
     171     
     172
     173
     174     
     175        fid.close()
     176     
     177        #Cleanup
     178        os.remove(sww.filename)
     179
     180
     181    def test_sww_constant_smooth(self):
     182        """Test that constant sww information can be written correctly
     183        (non smooth)
     184        """
     185
     186
     187        import time, os
     188        from Numeric import array, zeros, allclose, Float, concatenate
     189        from Scientific.IO.NetCDF import NetCDFFile       
     190
     191        self.domain.filename = 'datatest' + str(time.time())
     192        self.domain.format = 'sww'
     193        self.domain.smooth = True
     194     
     195        sww = get_dataobject(self.domain)
     196        sww.store_connectivity()       
     197
     198        #Check contents
     199        #Get NetCDF
     200        fid = NetCDFFile(sww.filename, 'r')  #Open existing file for append
     201     
     202        # Get the variables
     203        x = fid.variables['x']
     204        y = fid.variables['y']
     205        z = fid.variables['z']
     206
     207        volumes = fid.variables['volumes']       
     208
     209        X = x[:]
     210        Y = y[:]
     211     
     212        assert allclose([X[0], Y[0]], array([0.0, 0.0]))
     213        assert allclose([X[1], Y[1]], array([0.0, 0.5]))
     214        assert allclose([X[2], Y[2]], array([0.0, 1.0]))
     215
     216        assert allclose([X[4], Y[4]], array([0.5, 0.5]))
     217
     218        assert allclose([X[7], Y[7]], array([1.0, 0.5]))       
     219
     220        Z = z[:]
     221        assert Z[4] == -0.5
     222
     223        V = volumes
     224        assert V[2,0] == 4
     225        assert V[2,1] == 5
     226        assert V[2,2] == 1
     227
     228        assert V[4,0] == 6
     229        assert V[4,1] == 7
     230        assert V[4,2] == 3                     
     231     
     232     
     233
     234
     235     
     236        fid.close()
     237     
     238        #Cleanup
     239        os.remove(sww.filename)
     240
     241
     242
     243    def test_sww_variable(self):
     244        """Test that sww information can be written correctly
     245        """
     246
     247        import time, os
     248        from Numeric import array, zeros, allclose, Float, concatenate
     249        from Scientific.IO.NetCDF import NetCDFFile       
     250
     251        self.domain.filename = 'datatest' + str(time.time())
     252        self.domain.format = 'sww'
     253        self.domain.smooth = True
     254        self.domain.reduction = mean             
     255     
     256        sww = get_dataobject(self.domain)
     257        sww.store_connectivity()
     258        sww.store_timestep('level')
     259
     260        #Check contents
     261        #Get NetCDF
     262        fid = NetCDFFile(sww.filename, 'r')  #Open existing file for append
     263     
     264
     265        # Get the variables
     266        x = fid.variables['x']
     267        y = fid.variables['y']
     268        z = fid.variables['z']       
     269        time = fid.variables['time']
     270        stage = fid.variables['stage']
     271
     272
     273        Q = self.domain.quantities['level']     
     274        Q0 = Q.vertex_values[:,0]
     275        Q1 = Q.vertex_values[:,1]
     276        Q2 = Q.vertex_values[:,2]
     277
     278        A = stage[0,:]
     279        #print A[0], (Q2[0,0] + Q1[1,0])/2
     280        assert allclose(A[0], (Q2[0] + Q1[1])/2) 
     281        assert allclose(A[1], (Q0[1] + Q1[3] + Q2[2])/3)
     282        assert allclose(A[2], Q0[3])
     283        assert allclose(A[3], (Q0[0] + Q1[5] + Q2[4])/3)
     284
     285        #Center point
     286        assert allclose(A[4], (Q1[0] + Q2[1] + Q0[2] +\
     287                                 Q0[5] + Q2[6] + Q1[7])/6)
     288                               
     289     
     290     
     291        fid.close()
     292     
     293        #Cleanup
     294        os.remove(sww.filename)
    294295       
    295296       
     
    421422#-------------------------------------------------------------
    422423if __name__ == "__main__":
    423     #suite = unittest.makeSuite(dataTestCase,'test_sww_constant')
    424     suite = unittest.makeSuite(dataTestCase,'test_dummy')
     424    suite = unittest.makeSuite(dataTestCase,'test')
    425425    runner = unittest.TextTestRunner()
    426426    runner.run(suite)
  • inundation/ga/storm_surge/pyvolution/test_quantity.py

    r275 r281  
    458458        Q = level.vertex_values
    459459
     460        assert A.shape[0] == 9 
     461        assert V.shape[0] == 8 
     462        assert V.shape[1] == 3                 
     463       
    460464        #First four points
    461465        assert allclose(A[0], (Q[0,2] + Q[1,1])/2) 
     
    531535
    532536        #Check XY
    533         assert allclose(X[1], 0.5)
    534         assert allclose(Y[1], 0.5)
    535        
    536         assert allclose(X[4], 0.0)
    537         assert allclose(Y[4], 0.0)
    538 
    539         assert allclose(X[12], 1.0)
    540         assert allclose(Y[12], 0.0)               
     537       
     538        #FIXME: Do this test
     539        print X
     540       
     541        #assert allclose(X[1], 0.5)
     542        #assert allclose(Y[1], 0.5)
     543        #assert allclose(X[4], 0.0)
     544        #assert allclose(Y[4], 0.0)
     545        #assert allclose(X[12], 1.0)
     546        #assert allclose(Y[12], 0.0)               
    541547       
    542548       
Note: See TracChangeset for help on using the changeset viewer.