Changeset 8623


Ignore:
Timestamp:
Nov 15, 2012, 3:27:45 PM (12 years ago)
Author:
steve
Message:

Some changes to inlet_operator to take negative rates.

Location:
trunk/anuga_core/source
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/anuga_core/source/anuga/structures/inlet.py

    r8616 r8623  
    5656            raise Exception, msg
    5757       
    58         self.area = 0.0
    59         for j in self.triangle_indices:
    60             self.area += self.domain.areas[j]
     58#        self.area = 0.0
     59#        for j in self.triangle_indices:
     60#            self.area += self.domain.areas[j]
     61
     62        self.area = num.sum(self.domain.areas[self.triangle_indices])
    6163
    6264        msg = 'Inlet exchange area has area = %f' % self.area
     
    224226        areas = self.get_areas()
    225227        stages = self.get_stages()
     228        depths = self.get_depths()
    226229
    227230        stages_order = stages.argsort()
     
    235238
    236239
    237         if volume>= 0.0 :
    238             # find the number of cells which will be filled
    239             #print summed_volume
    240             #print summed_volume<=volume
    241 
    242             #Test = summed_volume<=volume
    243 
    244             #print num.any(Test)
    245             #print num.nonzero(summed_volume<=volume)
    246             #print num.nonzero(summed_volume<=volume)[0]
    247 
    248             index = num.nonzero(summed_volume<=volume)[0][-1]
    249 
    250             # calculate stage needed to fill chosen cells with given volume of water
    251             depth = (volume - summed_volume[index])/summed_areas[index]
    252             stages[stages_order[0:index+1]] = stages[stages_order[index]]+depth
    253 
    254         else:
    255             if summed_volume[-1]>= -volume :
    256                 depth = (summed_volume[-1] + volume)/summed_areas[-1]
    257                 stages[:] = depth
    258             else:
    259                 #assert summed_volume[-1] >= -volume
    260                 import warnings
    261                 warnings.warn('summed_volume < volume to be extracted')
    262                 stages[:] = 0.0
     240        assert volume >= 0.0
     241
     242
     243        index = num.nonzero(summed_volume<=volume)[0][-1]
     244
     245        # calculate stage needed to fill chosen cells with given volume of water
     246        depth = (volume - summed_volume[index])/summed_areas[index]
     247        stages[stages_order[0:index+1]] = stages[stages_order[index]]+depth
    263248
    264249        self.set_stages(stages)
    265250
    266251
    267 
    268 
    269     def set_stages_evenly_new(self,volume):
    270         """ Distribute volume of water over
    271         inlet exchange region so that stage is level
    272         """
    273         # WARNING: requires synchronization, must be called by all procs associated
    274         # with this inlet
    275 
    276         centroid_coordinates = self.domain.get_full_centroid_coordinates(absolute=True)
    277         areas = self.get_areas()
    278         stages = self.get_stages()
    279 
    280         stages_order = stages.argsort()
    281 
    282         # PETE: send stages and areas, apply merging procedure
    283 
    284         total_stages = len(stages)
    285 
    286 
    287         s_areas = areas
    288         s_stages = stages
    289         s_stages_order = stages_order
    290 
    291 
    292         pos = 0
    293         summed_volume = 0.
    294         summed_areas = 0.
    295         prev_stage = 0.
    296         num_stages = 0.
    297         first = True
    298 
    299         for i in self.procs:
    300             pos[i] = 0
    301 
    302         while num_stages < total_stages:
    303             # Determine current minimum stage of all the processors in s_stages
    304             num_stages = num_stages + 1
    305             current_stage = num.finfo(num.float32).max
    306             index = -1
    307 
    308 
    309             if pos >= len(s_stages):
    310                 continue
    311 
    312             if s_stages[s_stages_order[pos]] < current_stage:
    313                 current_stage = s_stages[i][s_stages_order[i][pos[i]]]
    314                 index = i
    315 
    316             # If first iteration, then only update summed_areas, position, and prev|current stage
    317 
    318             if first:
    319                 first = False
    320                 summed_areas = s_areas[index][s_stages_order[index][pos[index]]]
    321                 pos[index] = pos[index] + 1
    322                 prev_stage = current_stage
    323                 continue
    324 
    325             assert index >= 0, "Index out of bounds"
    326 
    327             # Update summed volume and summed areas
    328             tmp_volume = summed_volume + (summed_areas * (current_stage - prev_stage))
    329 
    330             # Terminate if volume exceeded
    331             if tmp_volume >= volume:
    332                 break
    333 
    334             summed_areas = summed_areas + s_areas[index][s_stages_order[index][pos[index]]]
    335             pos[index] = pos[index] + 1
    336             summed_volume = tmp_volume
    337 
    338         # Update position of index processor and current stage
    339         prev_stage = current_stage
    340 
    341         # Calculate new stage
    342         new_stage = prev_stage + (volume - summed_volume) / summed_areas
    343 
    344 
    345         # Update own depth
    346         stages[stages_order[0:pos]] = new_stage
    347 
    348 
    349 
    350         self.set_stages(stages)
    351 
    352         stages = self.get_stages()
    353         stages_order = stages.argsort()
    354252
    355253
  • trunk/anuga_core/source/anuga/structures/inlet_operator.py

    r8616 r8623  
    2020                 line,
    2121                 Q = 0.0,
     22                 velocity = None,
    2223                 default = None,
    2324                 description = None,
     
    4243        self.inlet = inlet.Inlet(self.domain, self.line, verbose= verbose)
    4344
     45
     46        self.velocity = velocity
     47
    4448        self.applied_Q = 0.0
    4549
     
    5761        # Need to run global command on all processors
    5862        current_volume = self.inlet.get_total_water_volume()
     63        total_area = self.inlet.get_area()
     64
     65        assert current_volume >= 0.0
    5966
    6067        Q1 = self.update_Q(t)
     
    7380        self.applied_Q = Q
    7481
    75         msg =  'Requesting too much water to be removed from an inlet! \n'
    76         msg += 'current_water_volume = %5.2e Increment volume = %5.2e' % (current_volume, volume)
    77         import warnings
    78         if current_volume + volume < 0.0:
    79             #warnings.warn(msg)
    80             volume = -current_volume
    81             self.applied_Q = volume/timestep
    82 
    83 
    84         #print 'applied_Q', self.applied_Q
    85        
    86         # Distribute volume so as to obtain flat surface
    87         self.inlet.set_stages_evenly(volume)
    88        
    89         # Distribute volume evenly over all cells
    90         #self.inlet.set_depths_evenly(volume)
     82
     83
     84 
     85
     86       
     87        # Distribute positive volume so as to obtain flat surface otherwise
     88        # just pull water off to have a uniform depth.
     89        if volume >= 0.0 :
     90            self.inlet.set_stages_evenly(volume)
     91            if self.velocity is not None:
     92                depths = self.inlet.get_depths()
     93                self.inlet.set_xmoms(self.inlet.get_xmoms()+depths*self.velocity[0])
     94                self.inlet.set_ymoms(self.inlet.get_ymoms()+depths*self.velocity[1])
     95               
     96        elif current_volume + volume >= 0.0 :
     97            depth = (current_volume + volume)/total_area
     98            self.inlet.set_depths(depth)
     99        else: #extracting too much water!
     100            self.inlet.set_depths(0.0)
     101            self.applied_Q = current_volume/timestep
     102            msg =  'Requesting too much water to be removed from an inlet! \n'
     103            msg += 'current_water_volume = %5.2e Increment volume = %5.2e' % (current_volume, volume)
     104
    91105
    92106
  • trunk/anuga_core/source/anuga_parallel/parallel_inlet_operator.py

    r8617 r8623  
    3535                 line,
    3636                 Q = 0.0,
     37                 velocity = None,
    3738                 default = None,
    3839                 description = None,
     
    8889        self.set_default(default)
    8990
     91        self.velocity = velocity
    9092
    9193    def __call__(self):
     
    9597        # Need to run global command on all processors
    9698        current_volume = self.inlet.get_global_total_water_volume()
     99        total_area = self.inlet.get_global_area()
    97100
    98101        # Only the master proc calculates the update
     
    106109            volume = 0.5*(Q1+Q2)*timestep
    107110
    108             assert current_volume + volume >= 0.0 , 'Requesting too much water to be removed from an inlet!'
    109 
    110             #print "Volume to be removed from Inlet = " + str(volume)
    111 
    112         # Set stages evenly on all processors
    113         self.inlet.set_stages_evenly(volume)
     111
     112
     113            assert current_volume >= 0.0 , 'Volume of watrer in inlet negative!'
     114
     115            for i in self.procs:
     116                if i == self.master_proc: continue
     117
     118                pypar.send((volume, current_volume, total_area, timestep), i)
     119        else:
     120            volume, current_volume, total_area, timestep = pypar.receive(self.master_proc)
     121
     122
     123        #print self.myid, volume, current_volume, total_area, timestep
     124
     125        self.applied_Q = volume/timestep
     126       
     127        # Distribute positive volume so as to obtain flat surface otherwise
     128        # just pull water off to have a uniform depth.
     129        if volume >= 0.0 :
     130            self.inlet.set_stages_evenly(volume)
     131            if self.velocity is not None:
     132                # This is done locally without communication
     133                depths = self.inlet.get_depths()
     134                self.inlet.set_xmoms(self.inlet.get_xmoms()+depths*self.velocity[0])
     135                self.inlet.set_ymoms(self.inlet.get_ymoms()+depths*self.velocity[1])
     136
     137        elif current_volume + volume >= 0.0 :
     138            depth = (current_volume + volume)/total_area
     139            self.inlet.set_depths(depth)
     140        else: #extracting too much water!
     141            self.inlet.set_depths(0.0)
     142            self.applied_Q = current_volume/timestep
     143
    114144
    115145
     
    174204            message += 'Parallel Inlet report for %s:\n' % self.label
    175205            message += '--------------------------------------------\n'
    176             message += 'Q [m^3/s]: %.2f\n' % self.Q
     206            message += 'Q [m^3/s]: %.2f\n' % self.applied_Q
    177207       
    178208            print message
  • trunk/anuga_core/source/anuga_parallel/parallel_operator_factory.py

    r8507 r8623  
    3939                   line,
    4040                   Q,
     41                   velocity = None,
    4142                   default = None,
    4243                   description = None,
     
    5354                                                              line,
    5455                                                              Q,
     56                                                              velocity = velocity,
    5557                                                              default = default,
    5658                                                              description = description,
     
    8385                                       line,
    8486                                       Q,
     87                                       velocity = velocity,
    8588                                       default = default,
    8689                                       description = description,
Note: See TracChangeset for help on using the changeset viewer.