Changeset 8623
- Timestamp:
- Nov 15, 2012, 3:27:45 PM (12 years ago)
- Location:
- trunk/anuga_core/source
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/anuga_core/source/anuga/structures/inlet.py
r8616 r8623 56 56 raise Exception, msg 57 57 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]) 61 63 62 64 msg = 'Inlet exchange area has area = %f' % self.area … … 224 226 areas = self.get_areas() 225 227 stages = self.get_stages() 228 depths = self.get_depths() 226 229 227 230 stages_order = stages.argsort() … … 235 238 236 239 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 263 248 264 249 self.set_stages(stages) 265 250 266 251 267 268 269 def set_stages_evenly_new(self,volume):270 """ Distribute volume of water over271 inlet exchange region so that stage is level272 """273 # WARNING: requires synchronization, must be called by all procs associated274 # with this inlet275 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 procedure283 284 total_stages = len(stages)285 286 287 s_areas = areas288 s_stages = stages289 s_stages_order = stages_order290 291 292 pos = 0293 summed_volume = 0.294 summed_areas = 0.295 prev_stage = 0.296 num_stages = 0.297 first = True298 299 for i in self.procs:300 pos[i] = 0301 302 while num_stages < total_stages:303 # Determine current minimum stage of all the processors in s_stages304 num_stages = num_stages + 1305 current_stage = num.finfo(num.float32).max306 index = -1307 308 309 if pos >= len(s_stages):310 continue311 312 if s_stages[s_stages_order[pos]] < current_stage:313 current_stage = s_stages[i][s_stages_order[i][pos[i]]]314 index = i315 316 # If first iteration, then only update summed_areas, position, and prev|current stage317 318 if first:319 first = False320 summed_areas = s_areas[index][s_stages_order[index][pos[index]]]321 pos[index] = pos[index] + 1322 prev_stage = current_stage323 continue324 325 assert index >= 0, "Index out of bounds"326 327 # Update summed volume and summed areas328 tmp_volume = summed_volume + (summed_areas * (current_stage - prev_stage))329 330 # Terminate if volume exceeded331 if tmp_volume >= volume:332 break333 334 summed_areas = summed_areas + s_areas[index][s_stages_order[index][pos[index]]]335 pos[index] = pos[index] + 1336 summed_volume = tmp_volume337 338 # Update position of index processor and current stage339 prev_stage = current_stage340 341 # Calculate new stage342 new_stage = prev_stage + (volume - summed_volume) / summed_areas343 344 345 # Update own depth346 stages[stages_order[0:pos]] = new_stage347 348 349 350 self.set_stages(stages)351 352 stages = self.get_stages()353 stages_order = stages.argsort()354 252 355 253 -
trunk/anuga_core/source/anuga/structures/inlet_operator.py
r8616 r8623 20 20 line, 21 21 Q = 0.0, 22 velocity = None, 22 23 default = None, 23 24 description = None, … … 42 43 self.inlet = inlet.Inlet(self.domain, self.line, verbose= verbose) 43 44 45 46 self.velocity = velocity 47 44 48 self.applied_Q = 0.0 45 49 … … 57 61 # Need to run global command on all processors 58 62 current_volume = self.inlet.get_total_water_volume() 63 total_area = self.inlet.get_area() 64 65 assert current_volume >= 0.0 59 66 60 67 Q1 = self.update_Q(t) … … 73 80 self.applied_Q = Q 74 81 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 91 105 92 106 -
trunk/anuga_core/source/anuga_parallel/parallel_inlet_operator.py
r8617 r8623 35 35 line, 36 36 Q = 0.0, 37 velocity = None, 37 38 default = None, 38 39 description = None, … … 88 89 self.set_default(default) 89 90 91 self.velocity = velocity 90 92 91 93 def __call__(self): … … 95 97 # Need to run global command on all processors 96 98 current_volume = self.inlet.get_global_total_water_volume() 99 total_area = self.inlet.get_global_area() 97 100 98 101 # Only the master proc calculates the update … … 106 109 volume = 0.5*(Q1+Q2)*timestep 107 110 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 114 144 115 145 … … 174 204 message += 'Parallel Inlet report for %s:\n' % self.label 175 205 message += '--------------------------------------------\n' 176 message += 'Q [m^3/s]: %.2f\n' % self. Q206 message += 'Q [m^3/s]: %.2f\n' % self.applied_Q 177 207 178 208 print message -
trunk/anuga_core/source/anuga_parallel/parallel_operator_factory.py
r8507 r8623 39 39 line, 40 40 Q, 41 velocity = None, 41 42 default = None, 42 43 description = None, … … 53 54 line, 54 55 Q, 56 velocity = velocity, 55 57 default = default, 56 58 description = description, … … 83 85 line, 84 86 Q, 87 velocity = velocity, 85 88 default = default, 86 89 description = description,
Note: See TracChangeset
for help on using the changeset viewer.