Changeset 1290


Ignore:
Timestamp:
May 6, 2005, 6:24:03 PM (19 years ago)
Author:
steve
Message:

visualisation stuff

Location:
inundation/ga/storm_surge
Files:
1 added
58 deleted
11 edited

Legend:

Unmodified
Added
Removed
  • inundation/ga/storm_surge/analytical solutions/Hobart.py

    r774 r1290  
    4242domain.default_order = 1
    4343domain.smooth = True
     44domain.visualise = True
    4445
    4546
  • inundation/ga/storm_surge/pyvolution/domain.py

    r1280 r1290  
    141141        X: Compatible list, Numeric array, const or function (see below)
    142142        location: Where values are to be stored.
    143                   Permissible options are: vertices, edges, centroid
    144 
    145         In case of location == 'centroid' the dimension values must
     143                  Permissible options are: vertices, edges, centroids
     144
     145        In case of location == 'centroids' the dimension values must
    146146        be a list of a Numerical array of length N, N being the number
    147147        of elements. Otherwise it must be of dimension Nx3.
     
    152152        internal ordering.
    153153
    154         #FIXME (Ole): I suggest the following interface
    155         set_quantity(name, X, location, region)
    156         where
     154        #FIXME (Ole): I suggest the following interface
     155        set_quantity(name, X, location, region)
     156        where
    157157            name: Name of quantity
    158158            X:
     
    194194        name: Name of quantity
    195195
    196         In case of location == 'centroid' the dimension values must
     196        In case of location == 'centroids' the dimension values must
    197197        be a list of a Numerical array of length N, N being the number
    198198        of elements. Otherwise it must be of dimension Nx3.
  • inundation/ga/storm_surge/pyvolution/mesh.py

    r1193 r1290  
    6767        """
    6868
    69        
     69
    7070
    7171        from Numeric import array, zeros, Int, Float, maximum, sqrt, sum
     
    113113                #a triangle to the midpoint of the side of the triangle
    114114                #closest to the centroid
    115                 d0 = sqrt(sum( (centroid-m0)**2 ))
     115                d0 = sqrt(sum( (centroid-m0)**2 ))
    116116                d1 = sqrt(sum( (centroid-m1)**2 ))
    117117                d2 = sqrt(sum( (centroid-m2)**2 ))
     
    129129
    130130                self.radii[i]=self.areas[i]/(2*(a+b+c))
    131                
     131
    132132
    133133            #Initialise Neighbours (-1 means that it is a boundary neighbour)
     
    446446            #Note: Could be arbitrary, but nice to have
    447447            #a unique way of selecting
    448             dist_A = sqrt(sum( (A-pmin)**2 ))
    449             dist_B = sqrt(sum( (B-pmin)**2 ))
     448            dist_A = sqrt(sum( (A-pmin)**2 ))
     449            dist_B = sqrt(sum( (B-pmin)**2 ))
    450450
    451451            #Find minimal point
  • inundation/ga/storm_surge/pyvolution/netherlands.py

    r1280 r1290  
    151151t0 = time.time()
    152152
    153 for t in domain.evolve(yieldstep = 0.01, finaltime = 10.0):
     153for t in domain.evolve(yieldstep = 0.2, finaltime = 10.0):
    154154    domain.write_time()
    155155
  • inundation/ga/storm_surge/pyvolution/quantity.py

    r1011 r1290  
    66
    77   domain: Associated domain structure. Required.
    8    
     8
    99   vertex_values: N x 3 array of values at each vertex for each element.
    1010                  Default None
     
    2828
    2929        if vertex_values is None:
    30             N = domain.number_of_elements           
     30            N = domain.number_of_elements
    3131            self.vertex_values = zeros((N, 3), Float)
    32         else:   
     32        else:
    3333            self.vertex_values = array(vertex_values).astype(Float)
    3434
     
    3636            assert V == 3,\
    3737                   'Three vertex values per element must be specified'
    38            
     38
    3939
    4040            msg = 'Number of vertex values (%d) must be consistent with'\
     
    4242            msg += 'number of elements in specified domain (%d).'\
    4343                   %domain.number_of_elements
    44            
     44
    4545            assert N == domain.number_of_elements, msg
    4646
    47         self.domain = domain   
     47        self.domain = domain
    4848
    4949        #Allocate space for other quantities
    5050        self.centroid_values = zeros(N, Float)
    51         self.edge_values = zeros((N, 3), Float)       
     51        self.edge_values = zeros((N, 3), Float)
    5252
    5353        #Intialise centroid and edge_values
     
    5656    def __len__(self):
    5757        return self.centroid_values.shape[0]
    58    
     58
    5959    def interpolate(self):
    6060        """Compute interpolated values at edges and centroid
     
    6262        """
    6363
    64         N = self.vertex_values.shape[0]       
     64        N = self.vertex_values.shape[0]
    6565        for i in range(N):
    6666            v0 = self.vertex_values[i, 0]
    6767            v1 = self.vertex_values[i, 1]
    6868            v2 = self.vertex_values[i, 2]
    69            
     69
    7070            self.centroid_values[i] = (v0 + v1 + v2)/3
    7171
     
    7777        #(either from this module or C-extension)
    7878        interpolate_from_vertices_to_edges(self)
    79            
    80            
     79
     80
    8181    def set_values(self, X, location='vertices', indexes = None):
    8282        """Set values for quantity
     
    8484        X: Compatible list, Numeric array (see below), constant or function
    8585        location: Where values are to be stored.
    86                   Permissible options are: vertices, edges, centroid
     86                  Permissible options are: vertices, edges, centroids
    8787                  Default is "vertices"
    8888
    89         In case of location == 'centroid' the dimension values must
     89        In case of location == 'centroids' the dimension values must
    9090        be a list of a Numerical array of length N, N being the number
    9191        of elements. Otherwise it must be of dimension Nx3
     
    9696        If values are described a function, it will be evaluated at
    9797        specified points
    98        
     98
    9999        If indexex is not 'unique vertices' Indexes is the set of element ids
    100100        that the operation applies to.
    101101        If indexex is 'unique vertices' Indexes is the set of vertex ids
    102102        that the operation applies to.
    103        
    104        
     103
     104
    105105        If selected location is vertices, values for centroid and edges
    106106        will be assigned interpolated values.
     
    115115        if X is None:
    116116            msg = 'Given values are None'
    117             raise msg           
     117            raise msg
    118118
    119119        import types, Numeric
     
    122122                                 'Indices must be a list or None'
    123123
    124        
     124
    125125        if callable(X):
    126126            #Use function specific method
    127             self.set_function_values(X, location, indexes = indexes)       
     127            self.set_function_values(X, location, indexes = indexes)
    128128        elif type(X) in [types.FloatType, types.IntType, types.LongType]:
    129129            if location == 'centroids':
     
    134134                    for i in indexes:
    135135                        self.centroid_values[i,:] = X
    136                        
     136
    137137            elif location == 'edges':
    138138                if (indexes ==  None):
     
    142142                    for i in indexes:
    143143                        self.edge_values[i,:] = X
    144                        
     144
    145145            elif location == 'unique vertices':
    146146                if (indexes ==  None):
     
    151151                    for unique_vert_id in indexes:
    152152                        triangles = self.domain.vertexlist[unique_vert_id]
    153                        
     153
    154154                        #In case there are unused points
    155                         if triangles is None: continue 
     155                        if triangles is None: continue
    156156
    157157                        #Go through all triangle, vertex pairs
     
    159159                        for triangle_id, vertex_id in triangles:
    160160                            self.vertex_values[triangle_id, vertex_id] = X
    161                
     161
    162162                        #Intialise centroid and edge_values
    163163                        self.interpolate()
     
    168168                    #Brute force
    169169                    for i_vertex in indexes:
    170                         self.vertex_values[i_vertex,:] = X     
     170                        self.vertex_values[i_vertex,:] = X
    171171
    172172        else:
     
    177177            #Intialise centroid and edge_values
    178178            self.interpolate()
    179            
     179
    180180        if location == 'centroids':
    181181            #Extrapolate 1st order - to capture notion of area being specified
    182             self.extrapolate_first_order()           
    183          
     182            self.extrapolate_first_order()
     183
    184184    def get_values(self, location='vertices', indexes = None):
    185185        """get values for quantity
     
    197197        (N if indexes = None).  Each value will be a list of the three
    198198        vertex values for this quantity.
    199        
     199
    200200        Indexes is the set of element ids that the operation applies to.
    201        
     201
    202202        """
    203203        from Numeric import take
     
    205205        if location not in ['vertices', 'centroids', 'edges', 'unique vertices']:
    206206            msg = 'Invalid location: %s' %location
    207             raise msg         
    208        
     207            raise msg
     208
    209209        import types, Numeric
    210210        assert type(indexes) in [types.ListType, types.NoneType,
    211211                                 Numeric.ArrayType],\
    212212                                 'Indices must be a list or None'
    213            
     213
    214214        if location == 'centroids':
    215215            if (indexes ==  None):
    216216                indexes = range(len(self))
    217             return take(self.centroid_values,indexes)                       
     217            return take(self.centroid_values,indexes)
    218218        elif location == 'edges':
    219219            if (indexes ==  None):
    220220                indexes = range(len(self))
    221             return take(self.edge_values,indexes)                     
     221            return take(self.edge_values,indexes)
    222222        elif location == 'unique vertices':
    223223            if (indexes ==  None):
     
    227227            for unique_vert_id in indexes:
    228228                triangles = self.domain.vertexlist[unique_vert_id]
    229                        
     229
    230230                #In case there are unused points
    231                 if triangles is None: 
    232                     msg = 'Unique vertex not associated with triangles' 
    233                     raise msg 
     231                if triangles is None:
     232                    msg = 'Unique vertex not associated with triangles'
     233                    raise msg
    234234
    235235                # Go through all triangle, vertex pairs
     
    280280            raise 'Not implemented: %s' %location
    281281
    282            
     282
    283283    def set_array_values(self, values, location='vertices', indexes = None):
    284284        """Set values for quantity
     
    288288        Permissible options are: vertices, edges, centroid, unique vertices
    289289        Default is "vertices"
    290        
     290
    291291        indexes - if this action is carried out on a subset of
    292292        elements or unique vertices
    293293        The element/unique vertex indexes are specified here.
    294        
     294
    295295        In case of location == 'centroid' the dimension values must
    296296        be a list of a Numerical array of length N, N being the number
     
    315315            indexes = array(indexes).astype(Int)
    316316            msg = 'Number of values must match number of indexes'
    317             assert values.shape[0] == indexes.shape[0], msg 
    318            
     317            assert values.shape[0] == indexes.shape[0], msg
     318
    319319        N = self.centroid_values.shape[0]
    320        
     320
    321321        if location == 'centroids':
    322322            assert len(values.shape) == 1, 'Values array must be 1d'
     
    325325                msg = 'Number of values must match number of elements'
    326326                assert values.shape[0] == N, msg
    327            
     327
    328328                self.centroid_values = values
    329329            else:
    330330                msg = 'Number of values must match number of indexes'
    331331                assert values.shape[0] == indexes.shape[0], msg
    332                
     332
    333333                #Brute force
    334334                for i in range(len(indexes)):
    335335                    self.centroid_values[indexes[i]] = values[i]
    336                    
     336
    337337        elif location == 'edges':
    338338            assert len(values.shape) == 2, 'Values array must be 2d'
     
    340340            msg = 'Number of values must match number of elements'
    341341            assert values.shape[0] == N, msg
    342            
    343             msg = 'Array must be N x 3'           
     342
     343            msg = 'Array must be N x 3'
    344344            assert values.shape[1] == 3, msg
    345            
     345
    346346            self.edge_values = values
    347            
     347
    348348        elif location == 'unique vertices':
    349349            assert len(values.shape) == 1 or allclose(values.shape[1:], 1),\
     
    360360                 #   self.set_vertex_values(values)
    361361                #else:
    362                 #    for element_index, value in map(None, indexes, values): 
     362                #    for element_index, value in map(None, indexes, values):
    363363                #        self.vertex_values[element_index, :] = value
    364                        
     364
    365365            elif len(values.shape) == 2:
    366366                #Vertex values are given as a triplet for each triangle
    367                
    368                 msg = 'Array must be N x 3'           
     367
     368                msg = 'Array must be N x 3'
    369369                assert values.shape[1] == 3, msg
    370                
     370
    371371                if indexes == None:
    372372                    self.vertex_values = values
    373373                else:
    374                     for element_index, value in map(None, indexes, values): 
     374                    for element_index, value in map(None, indexes, values):
    375375                        self.vertex_values[element_index] = value
    376             else:   
     376            else:
    377377                msg = 'Values array must be 1d or 2d'
    378378                raise msg
    379            
     379
    380380
    381381    # FIXME have a get_vertex_values as well, so the 'stage' quantity can be
     
    387387        one value for each row in vertexlist.
    388388
    389         indexes is the list of vertex_id's that will be set. 
     389        indexes is the list of vertex_id's that will be set.
    390390
    391391        Note: Functions not allowed
     
    409409        for i_index,unique_vert_id in enumerate(vertex_list):
    410410            triangles = self.domain.vertexlist[unique_vert_id]
    411                
     411
    412412            if triangles is None: continue #In case there are unused points
    413413
     
    416416            for triangle_id, vertex_id in triangles:
    417417                self.vertex_values[triangle_id, vertex_id] = A[i_index]
    418                
     418
    419419        #Intialise centroid and edge_values
    420420        self.interpolate()
    421  
     421
    422422    def smooth_vertex_values(self, value_array='field_values',
    423423                             precision = None):
     
    432432        from Numeric import concatenate, zeros, Float, Int, array, reshape
    433433
    434        
     434
    435435        A,V = self.get_vertex_values(xy=False,
    436436                                     value_array=value_array,
     
    450450        elif value_array == 'conserved_quantities':
    451451            Volume.interpolate_conserved_quantities()
    452        
    453    
     452
     453
    454454    #Method for outputting model results
    455455    #FIXME: Split up into geometric and numeric stuff.
     
    457457    #FIXME: STill remember to move XY to mesh
    458458    def get_vertex_values(self,
    459                           xy=True, 
     459                          xy=True,
    460460                          smooth = None,
    461461                          precision = None,
     
    465465        The vertex values are returned as one sequence in the 1D float array A.
    466466        If requested the coordinates will be returned in 1D arrays X and Y.
    467        
     467
    468468        The connectivity is represented as an integer array, V, of dimension
    469469        M x 3, where M is the number of volumes. Each row has three indices
     
    474474        reduction operator. In this case vertex coordinates will be
    475475        de-duplicated.
    476        
     476
    477477        If no smoothings is required, vertex coordinates and values will
    478478        be aggregated as a concatenation of values at
    479479        vertices 0, vertices 1 and vertices 2
    480480
    481        
     481
    482482        Calling convention
    483483        if xy is True:
    484484           X,Y,A,V = get_vertex_values
    485485        else:
    486            A,V = get_vertex_values         
    487            
     486           A,V = get_vertex_values
     487
    488488        """
    489489
     
    499499        if reduction is None:
    500500            reduction = self.domain.reduction
    501            
     501
    502502        #Create connectivity
    503                        
     503
    504504        if smooth == True:
    505505
     
    511511            for k in range(N):
    512512                L = self.domain.vertexlist[k]
    513                
     513
    514514                #Go through all triangle, vertex pairs
    515515                #contributing to vertex k and register vertex value
    516516
    517517                if L is None: continue #In case there are unused points
    518                
     518
    519519                contributions = []
    520520                for volume_id, vertex_id in L:
     
    522522                    contributions.append(v)
    523523
    524                 A[k] = reduction(contributions)   
     524                A[k] = reduction(contributions)
    525525
    526526
     
    528528                X = self.domain.coordinates[:,0].astype(precision)
    529529                Y = self.domain.coordinates[:,1].astype(precision)
    530                
     530
    531531                return X, Y, A, V
    532532            else:
     
    540540            M = 3*m        #Total number of unique vertices
    541541            V = reshape(array(range(M)).astype(Int), (m,3))
    542            
     542
    543543            A = self.vertex_values.flat
    544544
    545             #Do vertex coordinates   
    546             if xy is True:               
     545            #Do vertex coordinates
     546            if xy is True:
    547547                C = self.domain.get_vertex_coordinates()
    548548
    549549                X = C[:,0:6:2].copy()
    550                 Y = C[:,1:6:2].copy()               
    551 
    552                 return X.flat, Y.flat, A, V           
     550                Y = C[:,1:6:2].copy()
     551
     552                return X.flat, Y.flat, A, V
    553553            else:
    554554                return A, V
    555555
    556            
     556
    557557    def extrapolate_first_order(self):
    558558        """Extrapolate conserved quantities from centroid to
     
    560560        first order scheme.
    561561        """
    562        
     562
    563563        qc = self.centroid_values
    564564        qv = self.vertex_values
     
    566566        for i in range(3):
    567567            qv[:,i] = qc
    568            
     568
    569569
    570570    def get_integral(self):
     
    574574        for k in range(self.domain.number_of_elements):
    575575            area = self.domain.areas[k]
    576             qc = self.centroid_values[k]     
     576            qc = self.centroid_values[k]
    577577            integral += qc*area
    578            
    579         return integral   
    580        
     578
     579        return integral
     580
    581581
    582582class Conserved_quantity(Quantity):
     
    590590    def __init__(self, domain, vertex_values=None):
    591591        Quantity.__init__(self, domain, vertex_values)
    592        
     592
    593593        from Numeric import zeros, Float
    594594
     
    603603        self.explicit_update = zeros(N, Float )
    604604        self.semi_implicit_update = zeros(N, Float )
    605                
     605
    606606
    607607    def update(self, timestep):
     
    615615        #(either from this module or C-extension)
    616616        return compute_gradients(self)
    617            
     617
    618618
    619619    def limit(self):
     
    621621        #(either from this module or C-extension)
    622622        limit(self)
    623        
    624        
     623
     624
    625625    def extrapolate_second_order(self):
    626626        #Call correct module function
     
    629629
    630630
    631 def update(quantity, timestep):   
     631def update(quantity, timestep):
    632632    """Update centroid values based on values stored in
    633633    explicit_update and semi_implicit_update as well as given timestep
     
    642642        domain.quantities['ymomentum'].explicit_update = ...
    643643
    644        
     644
    645645
    646646    Explicit terms must have the form
    647    
     647
    648648        G(q, t)
    649    
     649
    650650    and explicit scheme is
    651    
     651
    652652       q^{(n+1}) = q^{(n)} + delta_t G(q^{n}, n delta_t)
    653653
    654654
    655655    Semi implicit forcing terms are assumed to have the form
    656    
     656
    657657       G(q, t) = H(q, t) q
    658    
     658
    659659    and the semi implicit scheme will then be
    660    
     660
    661661      q^{(n+1}) = q^{(n)} + delta_t H(q^{n}, n delta_t) q^{(n+1})
    662662
    663    
     663
    664664    """
    665    
     665
    666666    from Numeric import sum, equal, ones, Float
    667        
     667
    668668    N = quantity.centroid_values.shape[0]
    669669
     
    673673
    674674    for k in range(N):
    675         x = quantity.centroid_values[k] 
     675        x = quantity.centroid_values[k]
    676676        if x == 0.0:
    677677            #FIXME: Is this right
    678             quantity.semi_implicit_update[k] = 0.0           
    679         else:
    680             quantity.semi_implicit_update[k] /= x             
    681            
     678            quantity.semi_implicit_update[k] = 0.0
     679        else:
     680            quantity.semi_implicit_update[k] /= x
     681
    682682    #Explicit updates
    683683    quantity.centroid_values += timestep*quantity.explicit_update
    684            
     684
    685685    #Semi implicit updates
    686686    denominator = ones(N, Float)-timestep*quantity.semi_implicit_update
     
    702702        q1 = quantity.vertex_values[k, 1]
    703703        q2 = quantity.vertex_values[k, 2]
    704            
     704
    705705        quantity.edge_values[k, 0] = 0.5*(q1+q2)
    706         quantity.edge_values[k, 1] = 0.5*(q0+q2) 
     706        quantity.edge_values[k, 1] = 0.5*(q0+q2)
    707707        quantity.edge_values[k, 2] = 0.5*(q0+q1)
    708708
    709709
    710710
    711 def extrapolate_second_order(quantity):       
     711def extrapolate_second_order(quantity):
    712712    """Extrapolate conserved quantities from centroid to
    713713    vertices for each volume using
    714714    second order scheme.
    715715    """
    716        
     716
    717717    a, b = quantity.compute_gradients()
    718718
     
    720720    qc = quantity.centroid_values
    721721    qv = quantity.vertex_values
    722    
     722
    723723    #Check each triangle
    724724    for k in range(quantity.domain.number_of_elements):
    725         #Centroid coordinates           
     725        #Centroid coordinates
    726726        x, y = quantity.domain.centroid_coordinates[k]
    727        
     727
    728728        #vertex coordinates
    729729        x0, y0, x1, y1, x2, y2 = X[k,:]
    730        
     730
    731731        #Extrapolate
    732732        qv[k,0] = qc[k] + a[k]*(x0-x) + b[k]*(y0-y)
    733733        qv[k,1] = qc[k] + a[k]*(x1-x) + b[k]*(y1-y)
    734         qv[k,2] = qc[k] + a[k]*(x2-x) + b[k]*(y2-y)           
    735 
    736 
    737 def compute_gradients(quantity):                   
     734        qv[k,2] = qc[k] + a[k]*(x2-x) + b[k]*(y2-y)
     735
     736
     737def compute_gradients(quantity):
    738738    """Compute gradients of triangle surfaces defined by centroids of
    739739    neighbouring volumes.
     
    744744    from Numeric import zeros, Float
    745745    from util import gradient
    746    
     746
    747747    centroid_coordinates = quantity.domain.centroid_coordinates
    748     surrogate_neighbours = quantity.domain.surrogate_neighbours   
    749     centroid_values = quantity.centroid_values   
    750     number_of_boundaries = quantity.domain.number_of_boundaries     
    751    
     748    surrogate_neighbours = quantity.domain.surrogate_neighbours
     749    centroid_values = quantity.centroid_values
     750    number_of_boundaries = quantity.domain.number_of_boundaries
     751
    752752    N = centroid_values.shape[0]
    753753
    754754    a = zeros(N, Float)
    755755    b = zeros(N, Float)
    756    
     756
    757757    for k in range(N):
    758758        if number_of_boundaries[k] < 2:
    759759            #Two or three true neighbours
    760760
    761             #Get indices of neighbours (or self when used as surrogate)     
     761            #Get indices of neighbours (or self when used as surrogate)
    762762            k0, k1, k2 = surrogate_neighbours[k,:]
    763763
    764             #Get data       
     764            #Get data
    765765            q0 = centroid_values[k0]
    766766            q1 = centroid_values[k1]
    767             q2 = centroid_values[k2]                   
     767            q2 = centroid_values[k2]
    768768
    769769            x0, y0 = centroid_coordinates[k0] #V0 centroid
     
    773773            #Gradient
    774774            a[k], b[k] = gradient(x0, y0, x1, y1, x2, y2, q0, q1, q2)
    775        
     775
    776776        elif number_of_boundaries[k] == 2:
    777777            #One true neighbour
     
    789789
    790790            x0, y0 = centroid_coordinates[k0] #V0 centroid
    791             x1, y1 = centroid_coordinates[k1] #V1 centroid       
     791            x1, y1 = centroid_coordinates[k1] #V1 centroid
    792792
    793793            #Gradient
     
    798798
    799799        else:
    800             #No true neighbours -       
     800            #No true neighbours -
    801801            #Fall back to first order scheme
    802802            pass
    803        
    804    
     803
     804
    805805    return a, b
    806        
    807                    
    808 
    809 def limit(quantity):       
     806
     807
     808
     809def limit(quantity):
    810810    """Limit slopes for each volume to eliminate artificial variance
    811811    introduced by e.g. second order extrapolator
    812    
     812
    813813    This is an unsophisticated limiter as it does not take into
    814814    account dependencies among quantities.
    815    
     815
    816816    precondition:
    817817    vertex values are estimated from gradient
     
    823823
    824824    N = quantity.domain.number_of_elements
    825    
     825
    826826    beta_w = quantity.domain.beta_w
    827        
     827
    828828    qc = quantity.centroid_values
    829829    qv = quantity.vertex_values
    830        
     830
    831831    #Find min and max of this and neighbour's centroid values
    832832    qmax = zeros(qc.shape, Float)
    833     qmin = zeros(qc.shape, Float)       
    834    
     833    qmin = zeros(qc.shape, Float)
     834
    835835    for k in range(N):
    836836        qmax[k] = qmin[k] = qc[k]
     
    839839            if n >= 0:
    840840                qn = qc[n] #Neighbour's centroid value
    841                
     841
    842842                qmin[k] = min(qmin[k], qn)
    843843                qmax[k] = max(qmax[k], qn)
    844      
    845    
     844
     845
    846846    #Diffences between centroids and maxima/minima
    847     dqmax = qmax - qc 
     847    dqmax = qmax - qc
    848848    dqmin = qmin - qc
    849        
     849
    850850    #Deltas between vertex and centroid values
    851851    dq = zeros(qv.shape, Float)
     
    853853        dq[:,i] = qv[:,i] - qc
    854854
    855     #Phi limiter   
     855    #Phi limiter
    856856    for k in range(N):
    857        
     857
    858858        #Find the gradient limiter (phi) across vertices
    859859        phi = 1.0
     
    862862            if (dq[k,i] > 0): r = dqmax[k]/dq[k,i]
    863863            if (dq[k,i] < 0): r = dqmin[k]/dq[k,i]
    864            
    865             phi = min( min(r*beta_w, 1), phi )   
     864
     865            phi = min( min(r*beta_w, 1), phi )
    866866
    867867        #Then update using phi limiter
    868         for i in range(3):           
     868        for i in range(3):
    869869            qv[k,i] = qc[k] + phi*dq[k,i]
    870870
     
    874874if compile.can_use_C_extension('quantity_ext.c'):
    875875    #Replace python version with c implementations
    876        
     876
    877877    from quantity_ext import limit, compute_gradients,\
    878     extrapolate_second_order, interpolate_from_vertices_to_edges, update
    879 
     878    extrapolate_second_order, interpolate_from_vertices_to_edges, update
  • inundation/ga/storm_surge/pyvolution/realtime_visualisation_new.py

    r1281 r1290  
    11from visual import *
     2
     3elevation_color = (0.3,0.4,0.5)
     4stage_color = (0.1,0.4,0.99)
    25
    36class Surface:
     
    811        self.frame  = frame()
    912
    10         self.bed_model   = faces(frame=self.frame)
    11         self.stage_model = faces(frame=self.frame)
    1213        self.domain = domain
    1314        self.scale_z  = scale_z
    14 
    1515        self.vertices = domain.vertex_coordinates
    1616
    17         self.stage = domain.quantities['stage'].vertex_values
    18 
    19         try:
    20             self.bed   = domain.quantities['elevation'].vertex_values
    21             self.xmomentum = domain.quantities['xmomentum'].vertex_values
    22             self.ymomentum = domain.quantities['ymomentum'].vertex_values
    23         except:
    24             self.bed = None
    25             self.xmomentum = None
    26             self.ymomentum = None
    27 
    28 
    29         self.max_x = max(max(self.vertices[:,0],self.vertices[:,2],self.vertices[:,4]))
    30         self.min_x = min(min(self.vertices[:,0],self.vertices[:,2],self.vertices[:,4]))
    31         self.max_y = max(max(self.vertices[:,1],self.vertices[:,3],self.vertices[:,5]))
    32         self.min_y = min(min(self.vertices[:,1],self.vertices[:,3],self.vertices[:,5]))
     17        # models for each quantity
     18        self.z_models = {}
     19        keys = self.domain.quantities.keys()
     20        #print keys
     21        for key in keys:
     22            self.z_models[key] = faces(frame= self.frame)
     23
     24
     25
     26        self.max_x = max(max(self.vertices[:,0]),max(self.vertices[:,2]),max(self.vertices[:,4]))
     27        self.min_x = min(min(self.vertices[:,0]),min(self.vertices[:,2]),min(self.vertices[:,4]))
     28        self.max_y = max(max(self.vertices[:,1]),max(self.vertices[:,3]),max(self.vertices[:,5]))
     29        self.min_y = min(min(self.vertices[:,1]),min(self.vertices[:,3]),min(self.vertices[:,5]))
    3330        self.range_x = self.max_x - self.min_x
    3431        self.range_y = self.max_y - self.min_y
    35 
    3632        self.range_xy = max(self.range_x, self.range_y)
    3733
    38         if self.bed != None and range_z == None:
    39             self.max_z = max(max(self.bed))
    40             self.min_z = min(min(self.bed))
    41             self.range_z = max(self.max_z - self.min_z, 1.0e-10)
    42 
    43             print 'min_bed=',self.min_z
    44             print 'max_bed=',self.max_z
    45             print 'range_z=',self.range_z
    46         else:
    47             self.max_z = range_z/2.0
    48             self.min_z = -range_z/2.0
    49             self.range_z = max(self.max_z - self.min_z, 1.0e-10)
     34#        print 'min_x=',self.min_x
     35#        print 'max_x=',self.max_x
     36#        print 'range_x=',self.range_x
     37#        print 'min_y=',self.min_y
     38#        print 'max_y=',self.max_y
     39#        print 'range_y',self.range_y
     40
     41        self.range_z = 1.0
     42        self.max_z = self.range_z/2.0
     43        self.min_z = -self.range_z/2.0
     44        self.range_z = max(self.max_z - self.min_z, 1.0e-10)
    5045
    5146
     
    6863        #scene.autoscale=0
    6964        #self.update_all()
     65        #scene.uniform=0
     66        self.setup_range_z()
     67
     68    def setup_range_z(self,qname1='elevation',qname2='stage'):
     69
     70        #print qname1
     71        #print qname2
     72        self.range_z = 1.0e-10
     73        try:
     74            q1 = self.domain.quantities[qname1].vertex_values
     75            max_z = max(max(q1))
     76            min_z = min(min(q1))
     77            print max_z, min_z
     78            self.range_z = max(self.range_z, max_z - min_z)
     79        except:
     80            print 'could not find range of '+qname1
     81            pass
     82
     83        try:
     84            q2 = self.domain.quantities[qname2].vertex_values
     85            max_z = max(max(q2))
     86            min_z = min(min(q2))
     87            print max_z, min_z
     88            self.range_z = max(self.range_z, max_z - min_z)
     89        except:
     90            print 'Visualisation: could not find range of '+qname2
     91            pass
    7092
    7193    def update_all(self):
    7294
    73         self.update_bed()
    74         self.update_stage()
     95        self.update_quantity('elevation',elevation_color)
     96        self.update_quantity('stage',stage_color)
    7597
    7698    def update_timer(self):
    7799        self.timer.text='Time=%10.5e'%self.domain.time
    78100
    79     def update_bed(self):
    80 
    81         #print 'update bed arrays'
    82         c0 = 0.3
    83         c1 = 0.3
    84         c2 = 0.3
    85         if self.bed != None:
    86             self.update_arrays(self.bed,  (c0,c1,c2) )
     101
     102    def update_quantity(self,qname,qcolor=None):
     103
     104        #print 'update '+qname+' arrays'
     105
     106        if qcolor is None:
     107            if qname=='elevation':
     108                qcolor = elevation_color
     109
     110            if qname=='stage':
     111                qcolor = stage_color
     112
     113
     114        try:
     115            self.update_arrays(self.domain.quantities[qname].vertex_values, qcolor)
    87116
    88117            #print 'update bed image'
    89             self.bed_model.pos    = self.pos
    90             self.bed_model.color  = self.colour
    91             self.bed_model.normal = self.normals
    92 
    93 
    94     def update_stage(self):
    95         c0 = 0.1
    96         c1 = 0.4
    97         c2 = 0.99
    98         #print 'update stage arrays'
    99         if self.stage != None:
    100             self.update_arrays(self.stage, (c0,c1,c2) )
    101             #print 'update stage image'
    102             self.stage_model.pos    = self.pos
    103             self.stage_model.color  = self.colour
    104             self.stage_model.normal = self.normals
    105 
    106     def update_xmomentum(self):
    107         c0 = 0.1
    108         c1 = 0.4
    109         c2 = 0.99
    110         #print 'update stage arrays'
    111         self.update_arrays(self.xmomentum, (c0,c1,c2) )
    112         #print 'update stage image'
    113         self.stage_model.pos    = self.pos
    114         self.stage_model.color  = self.colour
    115         self.stage_model.normal = self.normals
    116 
    117     def update_ymomentum(self):
    118         c0 = 0.1
    119         c1 = 0.4
    120         c2 = 0.99
    121         #print 'update stage arrays'
    122         self.update_arrays(self.ymomentum, (c0,c1,c2) )
    123         #print 'update stage image'
    124         self.stage_model.pos    = self.pos
    125         self.stage_model.color  = self.colour
    126         self.stage_model.normal = self.normals
     118            self.z_models[qname].pos    = self.pos
     119            self.z_models[qname].color  = self.colour
     120            self.z_models[qname].normal = self.normals
     121        except:
     122            print 'Visualisation: Could not update quantity '+qname
     123            pass
     124
     125    def update_quantity_color(self,qname,qcolor=None):
     126
     127        #print 'update '+qname+' arrays'
     128
     129        if qcolor is None:
     130            if qname=='elevation':
     131                qcolor = elevation_color
     132
     133            if qname=='stage':
     134                qcolor = stage_color
     135
     136
     137        try:
     138            self.update_arrays_color(self.domain.quantities[qname].vertex_values, qcolor)
     139
     140            #print 'update bed image'
     141            self.z_models[qname].pos    = self.pos
     142            self.z_models[qname].color  = self.colour
     143            self.z_models[qname].normal = self.normals
     144        except:
     145            print 'Visualisation: Could not update quantity '+qname
     146            pass
     147
    127148
    128149    def update_arrays(self,quantity,qcolor):
     
    151172
    152173
     174    def update_arrays_color(self,quantity,qcolor):
     175
     176        col = asarray(qcolor)
     177
     178        N = len(self.domain)
     179
     180        scale_z = self.scale_z
     181        min_x = self.min_x
     182        min_y = self.min_y
     183        range_xy = self.range_xy
     184        range_z = self.range_z
     185
     186        vertices = self.vertices
     187        pos      = self.pos
     188        normals  = self.normals
     189        colour   = self.colour
     190
     191        try:
     192            update_arrays_color_weave(vertices,quantity,col,pos,normals,colour,N,
     193                                min_x,min_y,range_xy,range_z,scale_z)
     194        except:
     195            update_arrays_color_python(vertices,quantity,col,pos,normals,colour,N,
     196                                 min_x,min_y,range_xy,range_z,scale_z)
     197
     198
     199#==================================================================================
    153200
    154201def  update_arrays_python(vertices,quantity,col,pos,normals,colour,N,
     
    277324                 type_converters = converters.blitz, compiler='gcc');
    278325
     326def  update_arrays_color_python(vertices,quantity,col,pos,normals,colour,N,
     327                          min_x,min_y,range_xy,range_z,scale_z):
     328
     329    from math import sqrt
     330    normal = zeros( 3, Float)
     331    v = zeros( (3,3), Float)
     332    s = 1.0
     333
     334    for i in range( N ):
     335
     336        for j in range(3):
     337            v[j,0] = (vertices[i,2*j  ]-min_x)/range_xy
     338            v[j,1] = (vertices[i,2*j+1]-min_y)/range_xy
     339            v[j,2] = quantity[i,j]/range_z*scale_z*0.5
     340
     341        v10 = v[1,:]-v[0,:]
     342        v20 = v[2,:]-v[0,:]
     343
     344        normal[0] = v10[1]*v20[2] - v20[1]*v10[2]
     345        normal[1] = v10[2]*v20[0] - v20[2]*v10[0]
     346        normal[2] = v10[0]*v20[1] - v20[0]*v10[1]
     347
     348        norm = sqrt( normal[0]**2 + normal[1]**2 + normal[2]**2)
     349
     350        normal[0] = normal[0]/norm
     351        normal[1] = normal[1]/norm
     352        normal[2] = normal[2]/norm
     353
     354        pos[6*i  ,:] = v[0,:]
     355        pos[6*i+1,:] = v[1,:]
     356        pos[6*i+2,:] = v[2,:]
     357        pos[6*i+3,:] = v[0,:]
     358        pos[6*i+4,:] = v[2,:]
     359        pos[6*i+5,:] = v[1,:]
     360
     361        s = abs(v(2,j))
     362
     363        colour[6*i  ,:] = s*col
     364        colour[6*i+1,:] = s*col
     365        colour[6*i+2,:] = s*col
     366        colour[6*i+3,:] = s*col
     367        colour[6*i+4,:] = s*col
     368        colour[6*i+5,:] = s*col
     369
     370        s =  15.0/8.0 - s
     371
     372        normals[6*i  ,:] = normal
     373        normals[6*i+1,:] = normal
     374        normals[6*i+2,:] = normal
     375        normals[6*i+3,:] = -normal
     376        normals[6*i+4,:] = -normal
     377        normals[6*i+5,:] = -normal
     378
     379
     380
     381def  update_arrays_color_weave(vertices,quantity,col,pos,normals,colour,
     382                         N,min_x,min_y,range_xy,range_z,scale_z):
     383
     384    import weave
     385    from weave import converters
     386
     387    from math import sqrt
     388    normal = zeros( 3, Float)
     389    v = zeros( (3,3), Float)
     390    v10 = zeros( 3, Float)
     391    v20 = zeros( 3, Float)
     392
     393    code1 = """
     394        double s = 1.0;
     395
     396        for (int i=0; i<N ; i++ ) {
     397            for (int j=0; j<3 ; j++) {
     398                v(j,0) = (vertices(i,2*j  )-min_x)/range_xy;
     399                v(j,1) = (vertices(i,2*j+1)-min_y)/range_xy;
     400                v(j,2) = quantity(i,j)/range_z*scale_z*0.5;
     401            }
     402
     403
     404            for (int j=0; j<3; j++) {
     405                v10(j) = v(1,j)-v(0,j);
     406                v20(j) = v(2,j)-v(0,j);
     407            }
     408
     409            normal(0) = v10(1)*v20(2) - v20(1)*v10(2);
     410            normal(1) = v10(2)*v20(0) - v20(2)*v10(0);
     411            normal(2) = v10(0)*v20(1) - v20(0)*v10(1);
     412
     413            double norm =  sqrt(normal(0)*normal(0) + normal(1)*normal(1) + normal(2)*normal(2));
     414
     415            normal(0) = normal(0)/norm;
     416            normal(1) = normal(1)/norm;
     417            normal(2) = normal(2)/norm;
     418
     419            s = 0.2+fabs((v(0,2)+v(1,2)+v(2,2))/3.0);
     420
     421            for (int j=0; j<3; j++) {
     422                pos(6*i  ,j) = v(0,j);
     423                pos(6*i+1,j) = v(1,j);
     424                pos(6*i+2,j) = v(2,j);
     425                pos(6*i+3,j) = v(0,j);
     426                pos(6*i+4,j) = v(2,j);
     427                pos(6*i+5,j) = v(1,j);
     428
     429
     430
     431
     432                colour(6*i  ,j) = s*col(j);
     433                colour(6*i+1,j) = s*col(j);
     434                colour(6*i+2,j) = s*col(j);
     435                colour(6*i+3,j) = s*col(j);
     436                colour(6*i+4,j) = s*col(j);
     437                colour(6*i+5,j) = s*col(j);
     438
     439                normals(6*i  ,j) = normal(j);
     440                normals(6*i+1,j) = normal(j);
     441                normals(6*i+2,j) = normal(j);
     442                normals(6*i+3,j) = -normal(j);
     443                normals(6*i+4,j) = -normal(j);
     444                normals(6*i+5,j) = -normal(j);
     445                }
     446
     447            s =  15.0/8.0 - s;
     448        }
     449
     450        """
     451
     452    weave.inline(code1, ['vertices','quantity','col','pos','normals','colour','N',
     453                         'min_x','min_y','range_xy','range_z','scale_z','v','normal','v10','v20'],
     454                 type_converters = converters.blitz, compiler='gcc');
    279455
    280456scene.width = 1000
     
    282458
    283459#Original
    284 scene.center = (0.5,0.5,0)
     460scene.center = (0.5,0.5,0.0)
    285461scene.forward = vector(-0.1, 0.5, -0.5)
    286462
     
    304480
    305481
    306 def create_surface(domain,range_z=None):
    307 
    308     surface = Surface(domain,range_z=range_z)
     482def create_surface(domain,scale_z=0.5,range_z=None):
     483
     484    surface = Surface(domain,scale_z=0.5,range_z=range_z)
    309485    domain.surface = surface
    310486
    311     surface.update_bed()
    312     surface.update_stage()
    313     #surface.update_xmomentum()
    314     #surface.update_ymomentum
     487    surface.update_quantity('elevation')
     488    surface.update_quantity('stage')
    315489    surface.update_timer()
    316490
    317491def update(domain):
    318492
    319     #print 'start visual update'
    320493    surface = domain.surface
    321     surface.update_stage()
    322     #surface.update_xmomentum()
    323     #surface.update_ymomentum()
     494    surface.update_quantity('stage')
    324495    surface.update_timer()
    325     #print 'end visual update'
  • inundation/ga/storm_surge/pyvolution/view_tsh.py

    r1278 r1290  
    4040
    4141    surface =  Surface(domain, scale_z = scale_z)
    42     surface.update_bed()
    43 
    44 
     42    surface.update_quantity('elevation')
  • inundation/ga/storm_surge/steve/run_merimbula_lake.py

    r1271 r1290  
    2929#-------
    3030# Domain
    31 filename = 'merimbula_interpolated.tsh' 
     31filename = 'merimbula_interpolated.tsh'
     32filename = 'merimbula_10785_1.tsh'
    3233print 'Creating domain from', filename
    3334domain = pmesh_to_domain_instance(filename, Domain)
     
    162163#   All other boundaries are reflective
    163164Br = Reflective_boundary(domain)
    164 domain.set_boundary({'external': Br, 'open': Bf})
     165domain.set_boundary({'exterior': Br, 'open': Bf})
    165166
    166167#-----------
     
    174175#--------------------------------
    175176# Initial water surface elevation
    176 domain.set_quantity('stage', 1.0)
     177domain.set_quantity('stage', 0.0)
    177178   
    178179#----------------------------------------------------------
  • inundation/ga/storm_surge/zeus/anuga-workspace.zwi

    r1280 r1290  
    22<workspace name="anuga-workspace">
    33    <mode>Debug</mode>
    4     <active>parallel</active>
     4    <active>pyvolution</active>
     5    <project name="Merimbula">Merimbula.zpi</project>
    56    <project name="parallel">parallel.zpi</project>
    67    <project name="pyvolution">pyvolution.zpi</project>
  • inundation/ga/storm_surge/zeus/steve.zpi

    r1271 r1290  
    7575    <file>..\steve\get_triangle_data.py</file>
    7676    <file>..\steve\get_triangle_data_new.py</file>
    77     <file>..\steve\run_least_squares_merimbula.py</file>
    7877    <file>..\pyvolution-parallel\vtk-pylab.py</file>
    7978    <folder name="Header Files" />
Note: See TracChangeset for help on using the changeset viewer.