def match_coors(coors1, coors2, get_saved=True): """ Match coordinates `coors1` with `coors2`. """ if coors1.shape != coors2.shape: raise ValueError('incompatible shapes: %s == %s'\ % (coors1.shape, coors2.shape)) key = coors1.shape + ('coors',) if key in periodic_cache and get_saved: return periodic_cache[key] else: i1, i2 = find_map(coors1, coors2, join=False) if i1.shape[0] != coors1.shape[0]: print(coors1[i1]) print(coors2[i2]) print(nm.abs(coors1[i1] - coors2[i2]).max(0)) ii = nm.setdiff1d(nm.arange(coors1.shape[0]), i1) print(coors1[ii]) print(coors2[ii]) raise ValueError('cannot match nodes!') periodic_cache[key] = (i1, i2) return i1, i2
def match_grid_plane(coors1, coors2, which, get_saved=True): """ Match coordinates `coors1` with `coors2` along the plane with normal axis `which`. """ if coors1.shape != coors2.shape: raise ValueError('incompatible shapes: %s == %s'\ % (coors1.shape, coors2.shape)) key = coors1.shape + ('plane', which) if key in periodic_cache and get_saved: return periodic_cache[key] else: offset = coors1[0,which] - coors2[0,which] aux = coors2.copy() aux[:,which] += offset i1, i2 = find_map(coors1, aux, join = False) if i1.shape[0] != coors1.shape[0]: print(coors1[i1]) print(coors2[i2]) print(nm.abs(coors1[i1] - coors2[i2]).max(0)) ii = nm.setdiff1d(nm.arange(coors1.shape[0]), i1) print(coors1[ii]) print(coors2[ii]) raise ValueError('cannot match nodes!') periodic_cache[key] = (i1, i2) return i1, i2
def match_plane_by_dir(coors1, coors2, direction, get_saved=True): """ Match coordinates `coors1` with `coors2` in a given direction. """ if coors1.shape != coors2.shape: raise ValueError('incompatible shapes: %s == %s'\ % (coors1.shape, coors2.shape)) key_dir = None if direction is None else tuple(direction) key = coors1.shape + ('dir', key_dir) if key in periodic_cache and get_saved: return periodic_cache[key] else: aux = coors2.copy() if direction is not None: direction = nm.asarray(direction, dtype=nm.float).reshape((3, 1)) direction = direction[:coors1.shape[1]] direction /= nm.linalg.norm(direction) x0p = coors1[0] - coors2 dist = nm.linalg.norm(x0p - nm.dot(x0p, direction) * direction.T, axis=1) idx = nm.where(dist < eps)[0] if len(idx) < 1: print(direction) print(dist) raise ValueError('cannot match nodes!') aux += coors1[0] - coors2[idx[0]] i1, i2 = find_map(coors1, aux, eps=eps, join=False) if i1.shape[0] != coors1.shape[0]: print(direction) print(coors1[i1]) print(coors2[i2]) print(nm.abs(coors1[i1] - coors2[i2]).max(0)) ii = nm.setdiff1d(nm.arange(coors1.shape[0]), i1) print(coors1[ii]) print(coors2[ii]) raise ValueError('cannot match nodes!') periodic_cache[key] = (i1, i2) return i1, i2
def match_coors(coors1, coors2): """ Match coordinates `coors1` with `coors2`. """ if coors1.shape != coors2.shape: raise ValueError('incompatible shapes: %s == %s' % (coors1.shape, coors2.shape)) i1, i2 = find_map(coors1, coors2, join=False) if i1.shape[0] != coors1.shape[0]: print(coors1[i1]) print(coors2[i2]) print(nm.abs(coors1[i1] - coors2[i2]).max(0)) ii = nm.setdiff1d(nm.arange(coors1.shape[0]), i1) print(coors1[ii]) print(coors2[ii]) raise ValueError('cannot match nodes!') return i1, i2
def match_grid_plane( coor1, coor2, which ): """ Match coordinates `coor1` with `coor2` along the plane with normal axis `which`. """ if coor1.shape != coor2.shape: raise ValueError('incompatible shapes: %s == %s'\ % ( coor1.shape, coor2.shape)) offset = coor1[0,which] - coor2[0,which] aux = coor2.copy() aux[:,which] += offset i1, i2 = find_map( coor1, aux, join = False ) if i1.shape[0] != coor1.shape[0]: print(coor1[i1]) print(coor2[i2]) print(nm.abs(coor1[i1] - coor2[i2]).max(0)) ii = nm.setdiff1d(nm.arange(coor1.shape[0]), i1) print(coor1[ii]) print(coor2[ii]) raise ValueError('cannot match nodes!') return i1, i2
def setup_mirror_region(self, mirror_name=None, ret_name=False): """ Find the corresponding mirror region, set up element mapping. """ from sfepy.discrete.fem.mesh import find_map regions = self.domain.regions eopts = self.extra_options if (mirror_name is None) and (eopts is not None)\ and ('mirror_region' in eopts): mirror_name = eopts['mirror_region'] if mirror_name is not None: if mirror_name in self.mirror_regions: return mreg = regions[mirror_name] if self.vertices.shape[0] != mreg.vertices.shape[0]: raise ValueError('%s: incompatible mirror region! (%s)' % (self.name, mreg.name)) coors = self.domain.cmesh.coors coors1 = coors[self.vertices, :] coors2 = coors[mreg.vertices, :] shift = ((nm.sum(coors2, axis=0) - nm.sum(coors1, axis=0)) / coors1.shape[0]) vmap1, vmap2 = find_map(coors1, coors2 - shift, join=False) if vmap1.shape[0] != coors1.shape[0]: print(coors1[vmap1]) print(coors2[vmap2]) raise ValueError('cannot match vertices!') fconn = self.domain.cmesh.get_conn_as_graph(self.dim - 1, 0) cc = self.domain.cmesh.get_centroids(self.dim - 1) fmap1, fmap2 = find_map(cc[self.facets], cc[mreg.facets] - shift, join=False) if fmap1.shape[0] != self.facets.shape[0]: print(cc[self.facets][fmap1]) print(cc[mreg.facets][fmap2]) raise ValueError('cannot match facets!') mirror_map_i = nm.zeros_like(fmap1) mirror_map_i[fmap1] = fmap2 mirror_map = nm.zeros_like(fmap1) mirror_map[fmap2] = fmap1 else: for reg in regions: mirror_parent = regions.find(reg.parent) if mirror_parent is None: continue if ((reg is not self) and nm.all(self.vertices == reg.vertices)): mreg = reg mirror_map = mirror_map_i = None break else: raise ValueError('cannot find mirror region! (%s)' % self.name) self.mirror_regions[mreg.name] = mreg self.mirror_maps[mreg.name] = mirror_map mreg.mirror_regions[self.name] = self mreg.mirror_maps[self.name] = mirror_map_i if ret_name: return mreg.name