def _region_leaf(level, op): token, details = op['token'], op['orig'] if token != 'KW_Region': parse_def = token + '<' + ' '.join(details) + '>' region = Region('leaf', rdef, domain, parse_def=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.vertices = nm.arange(n_coor, dtype=nm.uint32) elif token == 'E_VIR': where = details[2] if where[0] == '[': vertices = nm.array(eval(where), dtype=nm.uint32) assert_(nm.amin(vertices) >= 0) assert_(nm.amax(vertices) < n_coor) else: coors = domain.cmesh.coors y = z = None x = coors[:, 0] if dim > 1: y = coors[:, 1] if dim > 2: z = coors[:, 2] coor_dict = {'x': x, 'y': y, 'z': z} vertices = nm.where(eval(where, {}, coor_dict))[0] region.vertices = vertices elif token == 'E_VOS': facets = domain.cmesh.get_surface_facets() region.set_kind('facet') region.facets = facets elif token == 'E_VBF': where = details[2] coors = domain.cmesh.coors fun = functions[where] vertices = fun(coors, domain=domain) region.vertices = vertices elif token == 'E_CBF': where = details[2] coors = domain.get_centroids(dim) fun = functions[where] cells = fun(coors, domain=domain) region.cells = cells elif token == 'E_COG': group = int(details[3]) region.cells = nm.where(domain.cmesh.cell_groups == group)[0] elif token == 'E_COSET': raise NotImplementedError('element sets not implemented!') elif token == 'E_VOG': group = int(details[3]) region.vertices = nm.where(domain.cmesh.vertex_groups == group)[0] elif token == 'E_VOSET': try: vertices = domain.vertex_set_bcs[details[3]] except KeyError: msg = 'undefined vertex set! (%s)' % details[3] raise ValueError(msg) region.vertices = vertices elif token == 'E_OVIR': aux = regions[details[3][2:]] region.vertices = aux.vertices[0:1] elif token == 'E_VI': region.vertices = nm.array([int(ii) for ii in details[1:]], dtype=nm.uint32) elif token == 'E_CI': region.cells = nm.array([int(ii) for ii in details[1:]], dtype=nm.uint32) else: output('token "%s" unkown - check regions!' % token) raise NotImplementedError return region
def _region_leaf(level, op): token, details = op['token'], op['orig'] if token != 'KW_Region': parse_def = token + '<' + ' '.join(details) + '>' region = Region('leaf', rdef, domain, parse_def=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.vertices = nm.arange(n_coor, dtype=nm.uint32) elif token == 'E_VIR': where = details[2] if where[0] == '[': vertices = nm.array(eval(where), dtype=nm.uint32) assert_(nm.amin(vertices) >= 0) assert_(nm.amax(vertices) < n_coor) else: coors = domain.cmesh.coors y = z = None x = coors[:,0] if dim > 1: y = coors[:,1] if dim > 2: z = coors[:,2] coor_dict = {'x' : x, 'y' : y, 'z': z} vertices = nm.where(eval(where, {}, coor_dict))[0] region.vertices = vertices elif token == 'E_VOS': facets = domain.cmesh.get_surface_facets() region.set_kind('facet') region.facets = facets elif token == 'E_VBF': where = details[2] coors = domain.cmesh.coors fun = functions[where] vertices = fun(coors, domain=domain) region.vertices = vertices elif token == 'E_CBF': where = details[2] coors = domain.get_centroids(dim) fun = functions[where] cells = fun(coors, domain=domain) region.cells = cells elif token == 'E_COG': group = int(details[3]) region.cells = nm.where(domain.cmesh.cell_groups == group)[0] elif token == 'E_COSET': raise NotImplementedError('element sets not implemented!') elif token == 'E_VOG': group = int(details[3]) region.vertices = nm.where(domain.cmesh.vertex_groups == group)[0] elif token == 'E_VOSET': try: vertices = domain.vertex_set_bcs[details[3]] except KeyError: msg = 'undefined vertex set! (%s)' % details[3] raise ValueError(msg) region.vertices = vertices elif token == 'E_OVIR': aux = regions[details[3][2:]] region.vertices = aux.vertices[0:1] elif token == 'E_VI': region.vertices = nm.array([int(ii) for ii in details[1:]], dtype=nm.uint32) elif token == 'E_CI': region.cells = nm.array([int(ii) for ii in details[1:]], dtype=nm.uint32) else: output('token "%s" unkown - check regions!' % token) raise NotImplementedError return region
def _region_leaf(level, op): token, details = op['token'], op['orig'] if token != 'KW_Region': parse_def = token + '<' + ' '.join(details) + '>' region = Region('leaf', rdef, domain, parse_def=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.vertices = nm.arange(domain.mesh.n_nod, dtype=nm.uint32) elif token == 'E_VIR': where = details[2] if where[0] == '[': vertices = nm.array(eval(where), dtype=nm.uint32) assert_(nm.amin(vertices) >= 0) assert_(nm.amax(vertices) < domain.mesh.n_nod) else: coors = domain.get_mesh_coors() x = coors[:,0] y = coors[:,1] if domain.mesh.dim == 3: z = coors[:,2] else: z = None coor_dict = {'x' : x, 'y' : y, 'z': z} vertices = nm.where(eval(where, {}, coor_dict))[0] region.vertices = vertices elif token == 'E_VOS': facets = domain.cmesh.get_surface_facets() region.set_kind('facet') region.facets = facets elif token == 'E_VBF': where = details[2] coors = domain.get_mesh_coors() fun = functions[where] vertices = fun(coors, domain=domain) region.vertices = vertices elif token == 'E_CBF': where = details[2] coors = domain.get_centroids(domain.mesh.dim) fun = functions[where] cells = fun(coors, domain=domain) region.cells = cells elif token == 'E_COG': group = int(details[3]) ig = domain.mat_ids_to_i_gs[group] group = domain.groups[ig] off = domain.mesh.el_offsets[ig] region.cells = off + nm.arange(group.shape.n_el, dtype=nm.uint32) elif token == 'E_COSET': raise NotImplementedError('element sets not implemented!') elif token == 'E_VOG': group = int(details[3]) vertices = nm.where(domain.mesh.ngroups == group)[0] region.vertices = vertices elif token == 'E_VOSET': try: vertices = domain.mesh.nodal_bcs[details[3]] except KeyError: msg = 'undefined vertex set! (%s)' % details[3] raise ValueError(msg) region.vertices = vertices elif token == 'E_OVIR': aux = regions[details[3][2:]] region.vertices = aux.vertices[0:1] elif token == 'E_VI': region.vertices = nm.array([int(ii) for ii in details[1:]], dtype=nm.uint32) elif token == 'E_CI1': region.cells = nm.array([int(ii) for ii in details[1:]], dtype=nm.uint32) elif token == 'E_CI2': num = len(details[1:]) / 2 cells = [] for ii in range(num): ig, iel = int(details[1+2*ii]), int(details[2+2*ii]) cells.append(iel + domain.mesh.el_offsets[ig]) region.cells = cells else: output('token "%s" unkown - check regions!' % token) raise NotImplementedError return region