def update_vertices( self ): self.all_vertices = nm.zeros( (0,), nm.int32 ) self.vertices = {} for ig, group in self.domain.iter_groups( self.igs ): rcells = self.cells[ig] conn = group.conn nods = conn[rcells,:].ravel() aux = la.unique1d( nods ) self.vertices[ig] = aux self.all_vertices = nm.unique1d( nm.r_[self.all_vertices, aux] )
def _region_leaf( level, op ): token, details = op['token'], op['orig'] if token != 'KW_Region': parse_def = token + '<' + ' '.join( details ) + '>' ## conns = [group.conn for group in domain.groups.itervalues()] ## vertex_groups = [group.vertices ## for group in domain.groups.itervalues()] region = Region( 'leaf', rdef, domain, parse_def ) if token == 'KW_Region': details = details[1][2:] aux = regions.find( details ) if not aux: raise ValueError, 'region %s does not exist' % details else: if rdef[:4] == 'copy': region = aux.copy() else: region = aux elif token == 'KW_All': region.set_vertices( nm.arange( domain.mesh.nod0.shape[0], dtype = nm.int32 ) ) elif token == 'E_NIR': where = details[2] if where[0] == '[': out = nm.array( eval( where ), dtype = nm.int32 ) assert_( nm.amin( out ) >= 0 ) assert_( nm.amax( out ) < domain.mesh.nod0.shape[0] ) else: x = domain.mesh.nod0[:,0] y = domain.mesh.nod0[:,1] if domain.mesh.dim == 3: z = domain.mesh.nod0[:,2] else: z = None coor_dict = {'x' : x, 'y' : y, 'z': z} out = nm.where( eval( where, {}, coor_dict ) )[0] region.set_vertices( out ) elif token == 'E_NOS': if domain.fa: # 3D. fa, nfa = domain.fa, domain.nfa else: fa, nfa = domain.ed, domain.ned flag = dm_mark_surface_faces( fa, nfa ) ii = nm.where( flag > 0 )[0] aux = la.unique1d( fa.data[ii,3:].ravel() ) if aux[0] == -1: # Triangular faces have -1 as 4. point. aux = aux[1:] region.can_cells = False region.set_vertices( aux ) elif token == 'E_NBF': where = details[2] x = domain.mesh.nod0[:,0] if domain.shape.dim > 1: y = domain.mesh.nod0[:,1] if domain.shape.dim > 2: z = domain.mesh.nod0[:,2] else: z = None else: y = None aux = {'x' : x, 'y' : y, 'z': z} fun = 'funmod.' + where # print fun out = nm.where( eval( fun, {'funmod' : funmod}, aux ) )[0] region.set_vertices( out ) elif token == 'E_EBF': where = details[2] aux = {'domain' : domain} fun = 'funmod.' + where # print fun out = eval( fun, {'funmod' : funmod}, aux ) print out region.set_cells( out ) elif token == 'E_EOG': group = int( details[3] ) ig = domain.mat_ids_to_i_gs[group] group = domain.groups[ig] region.set_from_group( ig, group.vertices, group.shape.n_el ) elif token == 'E_ONIR': aux = regions[details[3][2:]] region.set_vertices( aux.all_vertices[0:1] ) elif token == 'E_NI': region.set_vertices( nm.array( [int( details[1] )], dtype = nm.int32 ) ) else: output( 'token "%s" unkown - check regions!' % token ) raise NotImplementedError return region