Ignore:
Timestamp:
Jun 30, 2005, 5:41:44 PM (19 years ago)
Author:
steve
Message:
 
File:
1 edited

Legend:

Unmodified
Added
Removed
  • inundation/ga/storm_surge/parallel/parallel_shallow_water.py

    r1558 r1563  
    3333
    3434    def __init__(self, coordinates, vertices, boundary = None,
    35                  full_send_dict = None, ghost_recv_dict = None,
    36                  velocity = None):
     35                 full_send_dict = None, ghost_recv_dict = None):
    3736
    3837        self.processor = pypar.rank()
    3938        self.numproc   = pypar.size()
    40         #print 'Processor %d'%self.processor
    41         #velocity = [(self.processor+1),0.0]
    42 
    43         #print 'velocity',velocity
    44 
    45         Advection_Domain.__init__(self, coordinates, vertices, boundary,
    46                                   velocity = velocity)
     39
     40        Shallow_Water_Domain.__init__(self, coordinates, vertices, boundary)
    4741
    4842        N = self.number_of_elements
     
    5145        self.numproc   = pypar.size()
    5246
     47        # Setup Communication Buffers
     48        self.nsys = 3
     49        for key in full_send_dict:
     50            buffer_shape = full_send_dict[key][0].shape[0]
     51            full_send_dict[key].append(zeros( (buffer_shape,self.nsys) ,Float))
     52
     53
     54        for key in ghost_recv_dict:
     55            buffer_shape = ghost_recv_dict[key][0].shape[0]
     56            ghost_recv_dict[key].append(zeros( (buffer_shape,self.nsys) ,Float))
     57
    5358        self.full_send_dict  = full_send_dict
    54 #        for key in self.full_send_dict:
    55 #            self.full_send_dict[key][0] = array(self.full_send_dict[key][0],Int)
    56 #            self.full_send_dict[key][2] = array(self.full_send_dict[key][2],Float)
    57 
    58 
    5959        self.ghost_recv_dict = ghost_recv_dict
    60 #        for key in self.ghost_recv_dict:
    61 #            self.ghost_recv_dict[key][0] = array(self.ghost_recv_dict[key][0],Int)
    62 #            self.ghost_recv_dict[key][2] = array(self.ghost_recv_dict[key][2],Float)
     60
    6361
    6462        self.communication_time = 0.0
    6563        self.communication_reduce_time = 0.0
    6664
    67         #print self.full_send_dict
    68         #print self.ghost_recv_dict
     65
    6966
    7067    def check_integrity(self):
    71         Advection_Domain.check_integrity(self)
     68        Shallow_Water_Domain.check_integrity(self)
    7269
    7370        msg = 'Will need to check global and local numbering'
    7471        assert self.conserved_quantities[0] == 'stage', msg
     72        assert self.conserved_quantities[1] == 'xmomentum', msg
     73        assert self.conserved_quantities[2] == 'ymomentum', msg
    7574
    7675
     
    7978
    8079        # Calculate local timestep
    81         Advection_Domain.update_timestep(self, yieldstep, finaltime)
     80        Shallow_Water_Domain.update_timestep(self, yieldstep, finaltime)
    8281
    8382        import time
     
    101100        self.communication_reduce_time += time.time()-t0
    102101
     102
    103103    def update_ghosts(self):
    104 
    105         self.update_ghosts_second()
    106 
    107 
    108     def update_ghosts_second(self):
    109104
    110105        # We must send the information from the full cells and
     
    119114        t0 = time.time()
    120115
    121         stage_cv = self.quantities['stage'].centroid_values
     116        stage_cv     = self.quantities['stage'].centroid_values
     117        xmomentum_cv = self.quantities['xmomentum'].centroid_values
     118        ymomentum_cv = self.quantities['ymomentum'].centroid_values
    122119
    123120        # update of non-local ghost cells
     
    127124                for send_proc in self.full_send_dict:
    128125                    if send_proc != iproc:
    129                         # LINDA:
    130                         # now store full as local id, global_id, value
    131126
    132127                        Idf  = self.full_send_dict[send_proc][0]
    133128                        Xout = self.full_send_dict[send_proc][2]
    134129
    135                         N = len(Xout)
    136 
    137 
    138                         #==============================
    139                         # Original python Code
     130                        N = len(Idf)
     131
    140132                        for i in range(N):
    141                             Xout[i] = stage_cv[Idf[i]]
    142                         #==============================
    143 
    144 
    145                         #LINDA:
    146                         #could not get the code below to work, kept on complaining about error: no match for call to `(py::list) (int&)'
    147 
    148                         code1 = """
    149                         for (int i=0; i<N ; i++){
    150                             Xout(i) = stage_cv(Idf(i));
    151                         }
    152                         """
    153                         #weave.inline(code1, ['stage_cv','Idf','Xout','N'],
    154                         #             type_converters = converters.blitz, compiler='gcc');
     133                            Xout[i,0] = stage_cv[Idf[i]]
     134                            Xout[i,1] = xmomentum_cv[Idf[i]]
     135                            Xout[i,2] = ymomentum_cv[Idf[i]]
     136
    155137
    156138                        pypar.send(Xout,send_proc)
     
    161143                if  self.ghost_recv_dict.has_key(iproc):
    162144
    163                     # LINDA:
    164                     # now store ghost as local id, global id, value
    165145                    Idg = self.ghost_recv_dict[iproc][0]
    166146                    X = self.ghost_recv_dict[iproc][2]
    167147
    168148                    X = pypar.receive(iproc,X)
    169                     N = len(X)
    170 
    171                     #LINDA: had problems getting C code to work
    172 
    173 
    174                     #===========================
    175                     # Origin Python Code
     149                    N = len(Idg)
     150
    176151                    for i in range(N):
    177                         stage_cv[Idg[i]] = X[i]
    178                     #===========================
    179 
    180 
    181                     code2 = """
    182                     for (int i=0; i<N; i++){
    183                         stage_cv(Idg(i)) = X(i);
    184                     }
    185                     """
    186 #                    weave.inline(code2, ['stage_cv','Idg','X','N'],
    187 #                                 type_converters = converters.blitz, compiler='gcc');
     152                        stage_cv[Idg[i]]     = X[i,0]
     153                        xmomentum_cv[Idg[i]] = X[i,1]
     154                        ymomentum_cv[Idg[i]] = X[i,2]
     155
    188156
    189157        #local update of ghost cells
     
    201169            N = len(Idg)
    202170
    203 
    204             #======================================
    205             # Original python loop
    206171            for i in range(N):
    207                 #print i,Idg[i],Idf[i]
    208                 stage_cv[Idg[i]] = stage_cv[Idf[i]]
    209             #======================================
    210 
    211 
    212             code3 = """
    213             for (int i=0; i<N; i++){
    214                 stage_cv(Idg(i)) = stage_cv(Idf(i));
    215             }
    216             """
    217             #weave.inline(code3, ['stage_cv','Idg','Idf','N'],
    218             #                     type_converters = converters.blitz, compiler='gcc');
    219 
    220         self.communication_time += time.time()-t0
    221 
    222 
    223 #        if self.ghosts is not None:
    224 #            stage_cv = self.quantities['stage'].centroid_values
    225 #            for triangle in self.ghosts:
    226 #                stage_cv[triangle] = stage_cv[self.ghosts[triangle]]
    227 
    228     def update_ghosts_first(self):
    229 
    230         # We must send the information from the full cells and
    231         # receive the information for the ghost cells
    232         # We have a dictionary of lists with ghosts expecting updates from
    233         # the separate processors
    234 
    235         import weave
    236         from weave import converters
    237 
    238         import time
    239         t0 = time.time()
    240 
    241 
    242         stage_cv = self.quantities['stage'].centroid_values
    243 
    244         for send_proc in self.full_send_dict:
    245             if send_proc != self.processor:
    246                 Idf  = self.full_send_dict[send_proc][0]
    247                 Xout = self.full_send_dict[send_proc][1]
    248                 N = len(Xout)
    249 
    250 
    251                 #==============================
    252                 # Original python Code
    253                 for i in range(N):
    254                     Xout[i] = stage_cv[Idf[i]]
    255                 #==============================
    256 
    257 
    258 #                code1 = """
    259 #                for (int i=0; i<N ; i++){
    260 #                     Xout(i) = stage_cv(Idf(i));
    261 #                }
    262 #                """
    263 #                weave.inline(code1, ['stage_cv','Idf','Xout','N'],
    264 #                             type_converters = converters.blitz, compiler='gcc');
    265 
    266                 pypar.send(Xout,send_proc)
    267 
    268 
    269         #Receive data from the iproc processor
    270         for recv_proc in self.ghost_recv_dict:
    271             if recv_proc != self.processor:
    272                 Idg = self.ghost_recv_dict[recv_proc][0]
    273                 X   = self.ghost_recv_dict[recv_proc][1]
    274 
    275                 X = pypar.receive(recv_proc,X)
    276                 N = len(X)
    277 
    278 
    279                 #===========================
    280                 # Origin Python Code
    281                 for i in range(N):
    282                     stage_cv[Idg[i]] = X[i]
    283                 #===========================
    284 
    285 
    286 #                code2 = """
    287 #                for (int i=0; i<N; i++){
    288 #                    stage_cv(Idg(i)) = X(i);
    289 #                }
    290 #                """
    291 #                weave.inline(code2, ['stage_cv','Idg','X','N'],
    292 #                             type_converters = converters.blitz, compiler='gcc');
    293 
    294 
    295         #local update of ghost cells
    296         iproc = self.processor
    297         if self.full_send_dict.has_key(iproc):
    298             Idf  = self.full_send_dict[iproc][0]
    299             #print Idf
    300             Idg  = self.ghost_recv_dict[iproc][0]
    301             N = len(Idg)
    302             #print Idg
    303 
    304 
    305             #======================================
    306             # Original python loop
    307             for i in range(N):
    308                 #print i,Idg[i],Idf[i]
    309                 stage_cv[Idg[i]] = stage_cv[Idf[i]]
    310             #======================================
    311 
    312 
    313 #            code3 = """
    314 #            for (int i=0; i<N; i++){
    315 #                stage_cv(Idg(i)) = stage_cv(Idf(i));
    316 #            }
    317 #            """
    318 #            weave.inline(code3, ['stage_cv','Idg','Idf','N'],
    319 #                                 type_converters = converters.blitz, compiler='gcc');
    320 
     172                stage_cv[Idg[i]]     = stage_cv[Idf[i]]
     173                xmomentum_cv[Idg[i]] = xmomentum_cv[Idf[i]]
     174                ymomentum_cv[Idg[i]] = ymomentum_cv[Idf[i]]
    321175
    322176        self.communication_time += time.time()-t0
     
    339193
    340194
    341 
    342195    def evolve(self, yieldstep = None, finaltime = None):
    343196        """Specialisation of basic evolve method from parent class
     
    349202
    350203        #Call basic machinery from parent class
    351         for t in Advection_Domain.evolve(self, yieldstep, finaltime):
     204        for t in Shallow_Water_Domain.evolve(self, yieldstep, finaltime):
    352205
    353206            #Pass control on to outer loop for more specific actions
     
    355208
    356209
    357 
Note: See TracChangeset for help on using the changeset viewer.