def detect_orientation(self, orientation): # Limit dry and wet types to these that are actually used in the simulation. uniq_types = set(np.unique(self._type_map.base)) dry_types = list(set(nt.get_dry_node_type_ids()) & uniq_types) orient_types = list( set(nt.get_orientation_node_type_ids()) & uniq_types) # Convert to a numpy array. dry_types = self._type_map.dtype.type(dry_types) orient_types = self._type_map.dtype.type(orient_types) orient_map = util.in_anyd_fast(self._type_map, orient_types) l = len(list(self.subdomain.grid.basis[0])) - 1 for vec in self.subdomain.grid.basis: # FIXME: we currently only process the primary directions if vec.dot(vec) != 1: continue shifted_map = self._type_map for j, shift in enumerate(vec): if shift == 0: continue shifted_map = np.roll(shifted_map, int(-shift), axis=l - j) # Only set orientation where it's not already defined (=0). idx = orient_map & (shifted_map == 0) & (orientation == 0) orientation[idx] = self.subdomain.grid.vec_to_dir(list(vec))
def detect_orientation(self, use_tags): # Limit dry and wet types to these that are actually used in the simulation. uniq_types = set(np.unique(self._type_map.base)) dry_types = list(set(nt.get_dry_node_type_ids()) & uniq_types) orient_types = list( (set(nt.get_orientation_node_type_ids()) - set(nt.get_link_tag_node_type_ids() if use_tags else [])) & uniq_types) if not orient_types: return # Convert to a numpy array. dry_types = self._type_map.dtype.type(dry_types) orient_types = self._type_map.dtype.type(orient_types) orient_map = util.in_anyd_fast(self._type_map_base, orient_types) l = self.grid.dim - 1 for vec in self.grid.basis: # Orientaion only handles the primary directions. More complex # setups need link tagging. if vec.dot(vec) != 1: continue shifted_map = self._type_map_base for j, shift in enumerate(vec): if shift == 0: continue shifted_map = np.roll(shifted_map, int(-shift), axis=l - j) # Only set orientation where it's not already defined (=0). idx = orient_map & (shifted_map == 0) & (self._orientation_base == 0) self._orientation_base[idx] = self.grid.vec_to_dir(list(vec))
def detect_orientation(self, use_tags): # Limit dry and wet types to these that are actually used in the simulation. uniq_types = set(np.unique(self._type_map.base)) dry_types = list(set(nt.get_dry_node_type_ids()) & uniq_types) orient_types = list((set(nt.get_orientation_node_type_ids()) - set(nt.get_link_tag_node_type_ids() if use_tags else [])) & uniq_types) if not orient_types: return # Convert to a numpy array. dry_types = self._type_map.dtype.type(dry_types) orient_types = self._type_map.dtype.type(orient_types) orient_map = util.in_anyd_fast(self._type_map_base, orient_types) l = self.grid.dim - 1 for vec in self.grid.basis: # Orientaion only handles the primary directions. More complex # setups need link tagging. if vec.dot(vec) != 1: continue shifted_map = self._type_map_base for j, shift in enumerate(vec): if shift == 0: continue shifted_map = np.roll(shifted_map, int(-shift), axis=l-j) # Only set orientation where it's not already defined (=0). idx = orient_map & (shifted_map == 0) & (self._orientation_base == 0) self._orientation_base[idx] = self.grid.vec_to_dir(list(vec))
def encode(self): assert self._type_map is not None orientation = np.zeros_like(self._type_map) cnt = np.zeros_like(self._type_map) # Limit dry and wet types to these that are actually used in the simulation. uniq_types = set(np.unique(self._type_map.base)) dry_types = list(set(nt.get_dry_node_type_ids()) & uniq_types) wet_types = list(set(nt.get_wet_node_type_ids()) & uniq_types) orient_types = list(set(nt.get_orientation_node_type_ids()) & uniq_types) # Convert to a numpy array. dry_types = self._type_map.dtype.type(dry_types) wet_types = self._type_map.dtype.type(wet_types) orient_types = self._type_map.dtype.type(orient_types) # Check if there are any node types that need the orientation vector. needs_orientation = False for nt_code in uniq_types: if nt._NODE_TYPES[nt_code].needs_orientation: needs_orientation = True break if needs_orientation: for i, vec in enumerate(self.subdomain.grid.basis): l = len(list(vec)) - 1 shifted_map = self._type_map for j, shift in enumerate(vec): shifted_map = np.roll(shifted_map, int(-shift), axis=l-j) cnt[util.in_anyd_fast(shifted_map, dry_types)] += 1 # FIXME: we're currently only processing the primary directions # here if vec.dot(vec) == 1: idx = np.logical_and( util.in_anyd_fast(self._type_map, orient_types), shifted_map == 0) orientation[idx] = self.subdomain.grid.vec_to_dir(list(vec)) # Remap type IDs. max_type_code = max(self._type_id_remap.keys()) type_choice_map = np.zeros(max_type_code + 1, dtype=np.uint32) for orig_code, new_code in self._type_id_remap.iteritems(): type_choice_map[orig_code] = new_code self._type_map[:] = self._encode_node(orientation, self._encoded_param_map, np.choose(np.int32(self._type_map), type_choice_map), self._scratch_map) # Drop the reference to the map array. self._type_map = None
def detect_orientation(self, orientation): # Limit dry and wet types to these that are actually used in the simulation. uniq_types = set(np.unique(self._type_map.base)) dry_types = list(set(nt.get_dry_node_type_ids()) & uniq_types) orient_types = list(set(nt.get_orientation_node_type_ids()) & uniq_types) # Convert to a numpy array. dry_types = self._type_map.dtype.type(dry_types) orient_types = self._type_map.dtype.type(orient_types) orient_map = util.in_anyd_fast(self._type_map, orient_types) l = len(list(self.subdomain.grid.basis[0])) - 1 for vec in self.subdomain.grid.basis: # FIXME: we currently only process the primary directions if vec.dot(vec) != 1: continue shifted_map = self._type_map for j, shift in enumerate(vec): if shift == 0: continue shifted_map = np.roll(shifted_map, int(-shift), axis=l-j) # Only set orientation where it's not already defined (=0). idx = orient_map & (shifted_map == 0) & (orientation == 0) orientation[idx] = self.subdomain.grid.vec_to_dir(list(vec))