def test_get_skin(): mb = core.Core() rs = mb.get_root_set() coords = np.array([[0,0,0], [1,0,0], [2,0,0], [0,1,0], [1,1,0], [2,1,0], [0,2,0], [1,2,0], [2,2,0]],dtype='float64') verts = mb.create_vertices(coords) verts = np.array((verts[0:8]),dtype='uint64') connect = np.array([[1, 2, 5, 4], [2, 3, 6, 5], [4, 5, 8, 7], [5, 6, 9, 8]],dtype='uint64') quads = mb.create_elements(types.MBQUAD,connect) nelems = mb.get_entities_by_dimension(rs, 2) CHECK_EQ(len(nelems), 4) mb.write_file('quads_test.vtk') mskn = skinner.Skinner(mb) skin_verts = mskn.find_skin(rs, quads, True, False) CHECK_EQ(len(skin_verts), 8) skin_edges = mskn.find_skin(rs, quads, False, False) CHECK_EQ(len(skin_edges), 8)
def skinner_operation(self): skin = sk.Skinner(self.mb) print("Entering skinner test") if self.dimension == 3: faces_on_skin_handles = skin.find_skin(self.root_set, self.all_volumes[:]) # pdb.set_trace() edges_on_skin_handles = self.access_handle(faces_on_skin_handles) nodes_on_skin_handles = self.access_handle(edges_on_skin_handles) nodes_in_volumes = ([self.mb.get_adjacencies(el_handle,0) for el_handle in self.all_volumes]) check_volumes = np.asarray([rng.intersect(el_handle,nodes_on_skin_handles) for el_handle in nodes_in_volumes]) external_volumes_index = np.array([el_handle.empty() for el_handle in check_volumes]).astype(bool) volumes_on_skin_handles = self.range_index(np.bitwise_not(external_volumes_index),self.all_volumes) elif self.dimension == 2: edges_on_skin_handles = skin.find_skin(self.root_set, self.all_faces[:]) nodes_on_skin_handles = self.access_handle(edges_on_skin_handles) nodes_in_faces = ([self.mb.get_adjacencies(el_handle,0) for el_handle in self.all_faces]) check_faces= np.asarray([rng.intersect(el_handle,nodes_on_skin_handles) for el_handle in nodes_in_faces]) external_faces_index = np.array([el_handle.empty() for el_handle in check_faces]).astype(bool) faces_on_skin_handles = self.range_index(np.bitwise_not(external_faces_index),self.all_faces) volumes_on_skin_handles = rng.Range() print("Skinning Operation Successful") return [nodes_on_skin_handles, edges_on_skin_handles, faces_on_skin_handles, volumes_on_skin_handles]
def __init__(self, inputname_dict, inputname_h5m): global kkeys self.__verif = False self.kkeys = kkeys os.chdir('configs') with open(inputname_dict, 'r') as stream: self.info = yaml.load(stream) os.chdir('..') self.Ltot = self.info[self.kkeys[0]]['L'] self.mb = core.Core() self.mb.load_file(inputname_h5m) self.mtu = topo_util.MeshTopoUtil(self.mb) self.sk = skinner.Skinner(self.mb) self.root_set = self.mb.get_root_set() self.all_volumes = self.mb.get_entities_by_dimension(self.root_set, 3) # e_tags = self.mb.tag_get_tags_on_entity(self.all_volumes[0]) # print(e_tags) # import pdb; pdb.set_trace() self.all_nodes = self.mb.get_entities_by_dimension(0, 0) self.mtu.construct_aentities(self.all_nodes) self.all_faces = self.mb.get_entities_by_dimension(self.root_set, 2) self.all_edges = self.mb.get_entities_by_dimension(self.root_set, 1) self.vols_centroids = np.array( [self.mtu.get_average_position([v]) for v in self.all_volumes]) self.ns = (len(self.all_volumes)) self.gravity = self.info[key_gravity] self.DefineLenghtNv0() self.__verif = True
def skinner_operation(self): self.skin = sk.Skinner(self.mb) print("Entering skinner test") if self.all_volumes.empty() and self.dimension == 3: raise ValueError("Empty volumes range for a tridimensional mesh.") if self.dimension == 3: faces_on_skin_handles = self.skin.find_skin( self.root_set, self.all_volumes) edges_on_skin_handles = self.mtu.get_bridge_adjacencies( faces_on_skin_handles, 2, 1) nodes_on_skin_handles = self.mtu.get_bridge_adjacencies( faces_on_skin_handles, 2, 0) volumes_on_skin_handles = self.mtu.get_bridge_adjacencies( faces_on_skin_handles, 0, 3) elif self.dimension == 2: edges_on_skin_handles = self.skin.find_skin( self.root_set, self.all_faces) nodes_on_skin_handles = self.mtu.get_bridge_adjacencies( edges_on_skin_handles, 1, 0) faces_on_skin_handles = self.mtu.get_bridge_adjacencies( edges_on_skin_handles, 0, 2) volumes_on_skin_handles = self.mtu.get_bridge_adjacencies( edges_on_skin_handles, 0, 3) #empty print("Skinning Operation Successful") return [ nodes_on_skin_handles, edges_on_skin_handles, faces_on_skin_handles, volumes_on_skin_handles ]
def persistent_load(self, pid): type_tag = pid[0] if type_tag == "core": if self.mb is None: mb = core.Core() mb.load_file(f'{self.file_name}.h5m') self.mb = mb return self.mb elif type_tag == "mtu": if self.mb is None: raise pickle.UnpicklingError("core is missing") if self.mtu is None: mtu = topo_util.MeshTopoUtil(self.mb) return self.mtu elif type_tag == "skinner": if self.mb is None: raise pickle.UnpicklingError("core is missing") if self.skinner is None: self.skinner = skinner.Skinner(self.mb) return self.skinner elif type_tag == "range": r = rng.Range(pid[1]) return r elif type_tag == "tag": if self.mb is None: raise pickle.UnpicklingError("core is missing") return self.mb.tag_get_handle(pid[1]) else: print() raise pickle.UnpicklingError( f'unsupported persistent object {pid}')
def __init__(self, coords, elements, neighbors, center): self.mb = core.Core() self.mtu = topo_util.MeshTopoUtil(self.mb) skin = sk.Skinner(self.mb) verts = self.mb.create_vertices(coords) import pdb; pdb.set_trace() rs = self.mb.get_root_set() #import pdb; pdb.set_trace() #import pdb; pdb.set_trace() import pdb; pdb.set_trace() elements = elements + np.ones(elements.shape) tag_handle = self.mb.tag_get_handle("Teste", 1, types.MB_TYPE_INTEGER, types.MB_TAG_DENSE, create_if_missing = True) for el in elements: tetra = self.mb.create_element(types.MBTET, el.ravel().astype("uint64")) #self.mtu.construct_aentities(verts) elements = self.mb.get_entities_by_dimension(0, 3) for index,el in enumerate(elements): self.mb.tag_set_data(tag_handle,el,index) self.mb.write_file("delaunayVIEW.vtk")
def test_get_geometric_skin(): mb = core.Core() coords = np.array([[0,0,0], [1,0,0], [2,0,0], [0,1,0], [1,1,0], [2,1,0], [0,2,0], [1,2,0], [2,2,0]],dtype='float64') verts = mb.create_vertices(coords) verts = np.array((verts[0:8]),dtype='uint64') connect = np.array([[1, 2, 5, 4], [2, 3, 6, 5], [4, 5, 8, 7], [5, 6, 9, 8]],dtype='uint64') quads = mb.create_elements(types.MBQUAD,connect) # create a geometric set for the quads surf_set = mb.create_meshset() geom_tag = mb.tag_get_handle(types.GEOM_DIMENSION_TAG_NAME, 1, types.MB_TYPE_INTEGER, types.MB_TAG_SPARSE, create_if_missing = True) mb.tag_set_data(geom_tag, surf_set, 2) # place 2-D entities in this set mb.add_entities(surf_set, verts) mb.add_entities(surf_set, quads) # create a dummy volume set vol_set = mb.create_meshset() mb.tag_set_data(geom_tag, vol_set, 3) # set surface to volume parent-child relationship mb.add_parent_meshset(surf_set, vol_set) mskn = skinner.Skinner(mb) rs = mb.get_root_set() skin = mskn.find_geometric_skin(rs) CHECK_EQ(skin.num_of_type(types.MBVERTEX), 8) CHECK_EQ(skin.num_of_type(types.MBQUAD), 4)
def test_get_geometric_skin(): mb = core.Core() coords = np.array([[0,0,0], [1,0,0], [2,0,0], [0,1,0], [1,1,0], [2,1,0], [0,2,0], [1,2,0], [2,2,0]],dtype='float64') verts = mb.create_vertices(coords) verts = np.array((verts[0:8]),dtype='uint64') connect = np.array([[1, 2, 5, 4], [2, 3, 6, 5], [4, 5, 8, 7], [5, 6, 9, 8]],dtype='uint64') quads = mb.create_elements(types.MBQUAD,connect) mskn = skinner.Skinner(mb) rs = mb.get_root_set() skin_verts = mskn.find_geometric_skin(rs) CHECK_EQ(len(skin_verts), 8)
def skinner_operation(self): self.skin = sk.Skinner(self.mb) if self.dimension == 3: faces_on_skin_handles = self.skin.find_skin(0, self.all_volumes) edges_on_skin_handles = self.mtu.get_bridge_adjacencies( faces_on_skin_handles, 2, 1) nodes_on_skin_handles = self.mtu.get_bridge_adjacencies( faces_on_skin_handles, 2, 0) volumes_on_skin_handles = rng.intersect( self.mtu.get_bridge_adjacencies(faces_on_skin_handles, 0, 3), self.all_volumes) elif self.dimension == 2: edges_on_skin_handles = self.skin.find_skin(0, self.all_faces) nodes_on_skin_handles = self.mtu.get_bridge_adjacencies( edges_on_skin_handles, 1, 0) faces_on_skin_handles = rng.intersect( self.mtu.get_bridge_adjacencies(edges_on_skin_handles, 0, 2), self.all_faces) volumes_on_skin_handles = self.mtu.get_bridge_adjacencies( edges_on_skin_handles, 0, 3) return [ nodes_on_skin_handles, edges_on_skin_handles, faces_on_skin_handles, volumes_on_skin_handles ]
[0,1,0], [1,1,0], [2,1,0], [0,2,0], [1,2,0], [2,2,0]],dtype='float64') verts = mb.create_vertices(coords) verts = np.array((verts[0:8]),dtype='uint64') connect = np.array([[1, 2, 5, 4], [2, 3, 6, 5], [4, 5, 8, 7], [5, 6, 9, 8]],dtype='uint64') quads = mb.create_elements(types.MBQUAD,connect) nelems = mb.get_entities_by_dimension(rs, 2) # CHECK_EQ(len(nelems), 4) mb.write_file('quads_test.vtk') mskn = skinner.Skinner(mb) # skin_verts = mskn.find_skin(rs, quads, True, False) pdb.set_trace() #skin_verts2 = mskn.find_geometric_skin(rs) # CHECK_EQ(len(skin_verts), 8) # skin_edges = mskn.find_skin(rs, quads, False, False) CHECK_EQ(len(skin_edges), 8) # if __name__ == "__main__": # tests = [
def __init__(self, coords, elements, neighbors, center): #super(DelaunayView, self).__init__() self.mb = core.Core() self.mtu = topo_util.MeshTopoUtil(self.mb) skin = sk.Skinner(self.mb) verts = self.mb.create_vertices(coords) rs = self.mb.get_root_set() #import pdb; pdb.set_trace() #import pdb; pdb.set_trace() elements = elements + np.ones(elements.shape) tag_handle = self.mb.tag_get_handle("Teste", 1, types.MB_TYPE_INTEGER, types.MB_TAG_DENSE, create_if_missing = True) for el in elements: tetra = self.mb.create_element(types.MBTET, el.ravel().astype("uint64")) #self.mtu.construct_aentities(verts) elements = self.mb.get_entities_by_dimension(0, 3) for index,el in enumerate(elements): self.mb.tag_set_data(tag_handle,el,index) #import pdb; pdb.set_trace() bfaces = skin.find_skin(0, elements) print(bfaces) adj = np.array([(self.mb.get_connectivity(bface)) for bface in bfaces]) adj = adj.reshape((len(adj), 3)).astype(int) - np.ones(adj.shape) missing = np.setdiff1d(np.where(~np.isin(neighbors,adj)), center) import pdb; pdb.set_trace() # finding boundary tetrahedron self.mb.write_file("delaunay01.vtk") emp = rng.Range() boundary_tetrahedron = rng.Range() for el in elements: boundary_intersect = rng.intersect(bfaces, self.mb.get_adjacencies(el, 2)) if boundary_intersect is not emp: boundary_tetrahedron = rng.unite(boundary_tetrahedron, rng.Range(el)) # for el in elements: # #import pdb; pdb.set_trace() # local = rng.Range(el) # boundary_intersect = rng.intersect(bfaces, self.mb.get_adjacencies(local, 2)) # if boundary_intersect is not emp: # # import pdb; pdb.set_trace() # face_con = self.mb.get_adjacencies(boundary_intersect,0) # el_con = self.mb.get_adjacencies(local, 0) # #import pdb; pdb.set_trace() # inside_node = int(rng.subtract(el_con, face_con)[0] - 1) # # #inside_node = int(np.setdiff1d(el_con, face_con)[0] - 1) # #import pdb; pdb.set_trace() # #check if inside node is missing # is_missing = bool(np.isin(inside_node, missing)) # if is_missing is True: # boundary_tetrahedron = rng.unite(boundary_tetrahedron, local) #import pdb; pdb.set_trace() for el in boundary_tetrahedron: self.mb.tag_set_data(tag_handle,el,2) print(self.mb.get_connectivity(el)) #print(boundary_tetrahedron) import pdb; pdb.set_trace() #self.mb.delete_entity(boundary_tetrahedron) print(boundary_tetrahedron) self.mb.write_file("delaunay02.vtk")
def skinner(self, range): skin = sk.Skinner(self.mb) return skin.find_skin(self.rs,range)
def laplacian_smooth(mb, maxiter): """Generates a uniform grid in a moab instance (mb) meshset which is representative of the yt grid dataset (ds)""" #create a meshset for this grid rs = mb.get_root_set() ldim = 3 for idim in [3, 2, 1]: if len(mb.get_entities_by_dimension(rs, idim)) > 0: ldim = idim melems = mb.get_entities_by_dimension(rs, 2) break mverts = mb.get_entities_by_dimension(rs, 0) print("The " + str(ldim) + "-d mesh contains " + str(mverts.size()) + " vertices and " + str(melems.size()) + " elements!") # Compute the skin and fix the boundary vertices - these should not be moved sknr = skinner.Skinner(mb) skin_verts = sknr.find_skin(rs, melems, True, False) print("Found " + str(skin_verts.size()) + " boundary vertices in the mesh") # Now let us set the new "smoothed" coordinate to the vertex oldvtxcoords = mb.get_coords(mverts) # size of coords: (3 * mverts.size()) newvtxcoords = np.copy(oldvtxcoords) mtu = topo_util.MeshTopoUtil(mb) iter = 0 while iter < maxiter: ivtx = 0 print('Laplacian smoothing iteration: ' + str(iter)) for vtx in mverts: if vtx in skin_verts: ivtx += 1 continue # Not a fixed node - lets apply our smoothing algorithm adjs = mtu.get_bridge_adjacencies(vtx, bridge_dim=ldim, to_dim=0) vtxcoords = mb.get_coords(adjs) avgcoords = np.zeros(3) i = 0 while i < len(adjs): avgcoords[0] += vtxcoords[i * 3 + 0] avgcoords[1] += vtxcoords[i * 3 + 1] avgcoords[2] += vtxcoords[i * 3 + 2] i += 1 avgcoords /= i newvtxcoords[ivtx * 3 + 0] = avgcoords[0] newvtxcoords[ivtx * 3 + 1] = avgcoords[1] newvtxcoords[ivtx * 3 + 2] = avgcoords[2] ivtx += 1 # Now let us set the new "smoothed" coordinate to the vertex mb.set_coords(mverts, newvtxcoords) coorderr = np.linalg.norm(newvtxcoords - oldvtxcoords) print("\t L_2 Error in iterate = %.6e" % coorderr) oldvtxcoords = np.copy(newvtxcoords) iter += 1 #return the grid meshset return rs