Ignore:
Timestamp:
Jan 28, 2008, 6:14:47 PM (16 years ago)
Author:
steve
Message:

Added a C extension for the advection directory (gave up on using f2py!)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • anuga_core/source/anuga/advection/advection.py

    r4975 r4978  
    6666                                numproc=numproc)
    6767
    68 
     68        import Numeric
    6969        if velocity is None:
    70             self.velocity = [1,0]
     70            self.velocity = Numeric.array([1,0],'d')
    7171        else:
    72             self.velocity = velocity
     72            self.velocity = Numeric.array(velocity,'d')
    7373
    7474        #Only first is implemented for advection
     
    108108        return flux, max_speed
    109109
     110
     111
    110112    def compute_fluxes(self):
    111 
    112        
    113         self.compute_fluxes_ext()
    114 ##         try:
    115 ##             self.compute_fluxes_ext()
    116 ##         except:
    117 ##             self.compute_fluxes_python()
    118  
     113        """Compute all fluxes and the timestep suitable for all volumes
     114        in domain.
     115
     116        Compute total flux for each conserved quantity using "flux_function"
     117
     118        Fluxes across each edge are scaled by edgelengths and summed up
     119        Resulting flux is then scaled by area and stored in
     120        domain.explicit_update
     121
     122        The maximal allowable speed computed by the flux_function
     123        for each volume
     124        is converted to a timestep that must not be exceeded. The minimum of
     125        those is computed as the next overall timestep.
     126
     127        Post conditions:
     128        domain.explicit_update is reset to computed flux values
     129        domain.timestep is set to the largest step satisfying all volumes.
     130        """
     131
     132        import sys
     133        from Numeric import zeros, Float
     134        from anuga.config import max_timestep
     135
     136
     137        huge_timestep = float(sys.maxint)
     138        Stage = self.quantities['stage']
     139
     140        """
     141        print "======================================"
     142        print "BEFORE compute_fluxes"
     143        print "stage_update",Stage.explicit_update
     144        print "stage_edge",Stage.edge_values
     145        print "stage_bdry",Stage.boundary_values
     146        print "neighbours",self.neighbours
     147        print "neighbour_edges",self.neighbour_edges
     148        print "normals",self.normals
     149        print "areas",self.areas
     150        print "radii",self.radii
     151        print "edgelengths",self.edgelengths
     152        print "tri_full_flag",self.tri_full_flag
     153        print "huge_timestep",huge_timestep
     154        print "max_timestep",max_timestep
     155        print "velocity",self.velocity
     156        """
     157
     158        import advection_ext           
     159        self.timestep = advection_ext.compute_fluxes(self, Stage, huge_timestep, max_timestep)
     160
     161
     162
     163    def evolve(self,
     164               yieldstep = None,
     165               finaltime = None,
     166               duration = None,
     167               skip_initial_step = False):
     168
     169        """Specialisation of basic evolve method from parent class
     170        """
     171
     172        #Call basic machinery from parent class
     173        for t in Generic_domain.evolve(self,
     174                                       yieldstep=yieldstep,
     175                                       finaltime=finaltime,
     176                                       duration=duration,
     177                                       skip_initial_step=skip_initial_step):
     178
     179            #Pass control on to outer loop for more specific actions
     180            yield(t)
     181
     182
    119183
    120184
     
    207271        self.timestep = timestep
    208272
    209 
    210     def compute_fluxes_ext(self):
    211         """Compute all fluxes and the timestep suitable for all volumes
    212         in domain.
    213 
    214         Compute total flux for each conserved quantity using "flux_function"
    215 
    216         Fluxes across each edge are scaled by edgelengths and summed up
    217         Resulting flux is then scaled by area and stored in
    218         domain.explicit_update
    219 
    220         The maximal allowable speed computed by the flux_function
    221         for each volume
    222         is converted to a timestep that must not be exceeded. The minimum of
    223         those is computed as the next overall timestep.
    224 
    225         Post conditions:
    226         domain.explicit_update is reset to computed flux values
    227         domain.timestep is set to the largest step satisfying all volumes.
    228         """
    229 
    230         import sys
    231         from Numeric import zeros, Float
    232         from anuga.config import max_timestep
    233 
    234         ntri = len(self)
    235 
    236         timestep = max_timestep
    237 
    238         #Shortcuts
    239         Stage = self.quantities['stage']
    240 
    241         #Arrays
    242         neighbours      = self.neighbours
    243         neighbour_edges = self.neighbour_edges
    244         normals         = self.normals
    245         areas           = self.areas
    246         radii           = self.radii
    247         edgelengths     = self.edgelengths
    248         tri_full_flag   = self.tri_full_flag
    249 
    250         stage_edge      = Stage.edge_values
    251         stage_bdry      = Stage.boundary_values
    252         stage_update    = Stage.explicit_update
    253 
    254         huge_timestep = float(sys.maxint)
    255 
    256         v = self.velocity
    257 
    258         nbdry = len(stage_bdry)
    259 
    260         from advection_ext import compute_fluxes
    261 
    262         print "stage_update",stage_update
    263         print "stage_edge",stage_edge
    264         print "stage_bdry",stage_bdry
    265         print "neighbours",neighbours
    266         print "neighbour_edges",neighbour_edges
    267         print "normals",normals
    268         print "areas",areas
    269         print "radii",radii
    270         print "edgelengths",edgelengths
    271         print "tri_full_flag",tri_full_flag
    272         print "huge_timestep",huge_timestep
    273         print "max_timestep",max_timestep
    274         print "v",v
    275         print "ntri",ntri
    276         print "nbdry",nbdry
    277 
    278 
    279                
    280         timestep = compute_fluxes(stage_update,stage_edge,stage_bdry,
    281                                   neighbours,neighbour_edges,normals,
    282                                   areas,radii,edgelengths,
    283                                   tri_full_flag,
    284                                   huge_timestep,max_timestep,v,ntri,nbdry)
    285 
    286         print "stage_update",stage_update       
    287        
    288         #print 'timestep out2 =',timestep
    289 
    290         self.timestep = timestep
    291 
    292 
    293     def evolve(self,
    294                yieldstep = None,
    295                finaltime = None,
    296                duration = None,
    297                skip_initial_step = False):
    298 
    299         """Specialisation of basic evolve method from parent class
    300         """
    301 
    302         #Call basic machinery from parent class
    303         for t in Generic_domain.evolve(self,
    304                                        yieldstep=yieldstep,
    305                                        finaltime=finaltime,
    306                                        duration=duration,
    307                                        skip_initial_step=skip_initial_step):
    308 
    309             #Pass control on to outer loop for more specific actions
    310             yield(t)
Note: See TracChangeset for help on using the changeset viewer.