def release_elements(self, time_step, model_time): """ Called at the end of a time step This calls release_elements on all of the contained spills, and adds the elements to the data arrays """ for spill in self.spills: if spill.on: num_released = spill.num_elements_to_release(model_time, time_step) if num_released > 0: # update 'spill_num' ArrayType's initial_value so it # corresponds with spill number for this set of released # particles - just another way to set value of spill_num # correctly self._array_types["spill_num"].initial_value = self.spills.index(spill.id, renumber=False) if len(self["spill_num"]) > 0: # unique identifier for each new element released # this adjusts the _array_types initial_value since the # initialize function just calls: # range(initial_value, num_released + initial_value) self._array_types["id"].initial_value = self["id"][-1] + 1 # else: # self._array_types['id'].initial_value = 0 # append to data arrays self._append_data_arrays(num_released) spill.set_newparticle_values(num_released, model_time, time_step, self._data_arrays)
def release_elements(self, time_step, model_time): """ Called at the end of a time step This calls release_elements on all of the contained spills, and adds the elements to the data arrays :returns: total number of particles released todo: may need to update the 'mass' array to use a default of 1.0 but will need to define it in particle units or something along those lines """ total_released = 0 # substance index - used label elements from same substance # used internally only by SpillContainer - could be a strided array. # Simpler to define it only in SpillContainer as opposed to ArrayTypes # 'substance': ((), np.uint8, 0) for ix, spills in enumerate(self.iterspillsbysubstance()): num_rel_by_substance = 0 for spill in spills: # only spills that are included here - no need to check # spill.on flag num_rel = spill.num_elements_to_release(model_time, time_step) if num_rel > 0: # update 'spill_num' ArrayType's initial_value so it # corresponds with spill number for this set of released # particles - just another way to set value of spill_num # correctly self._array_types['spill_num'].initial_value = \ self.spills.index(spill) if len(self['spill_num']) > 0: # unique identifier for each new element released # this adjusts the _array_types initial_value since the # initialize function just calls: # range(initial_value, num_released + initial_value) self._array_types['id'].initial_value = \ self['id'][-1] + 1 else: # always reset value of first particle released to 0! # The array_types are shared globally. To initialize # uncertain spills correctly, reset this to 0. # To be safe, always reset to 0 when no # particles are released self._array_types['id'].initial_value = 0 # append to data arrays - number of oil components is # currently the same for all spills self._append_data_arrays(num_rel) spill.set_newparticle_values(num_rel, model_time, time_step, self._data_arrays) num_rel_by_substance += num_rel # always reset data arrays else the changing arrays are stale self._set_substance_array(ix, num_rel_by_substance) # reset fate_dataview at each step - do it after release elements self.reset_fate_dataview() # update total elements released for substance total_released += num_rel_by_substance return total_released