def test_range_methods(): mb = core.Core() coord = np.array((1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 4, 5, 5, 5, 6, 6, 6), dtype='float64') range_a = mb.create_vertices(coord) coord = np.array((2, 2, 2, 3, 3, 3, 4, 4, 4, 5, 5, 5, 6, 6, 6, 7, 7, 7), dtype='float64') range_b = mb.create_vertices(coord) CHECK_EQ(range_a.all_of_dimension(0), True) CHECK_EQ(range_b.all_of_dimension(0), True) CHECK_EQ(range_a.all_of_dimension(1), False) CHECK_EQ(range_b.all_of_dimension(1), False) CHECK_EQ(range_a.num_of_dimension(0), range_a.size()) CHECK_EQ(range_b.num_of_dimension(0), range_b.size()) CHECK_EQ(range_a.num_of_dimension(1), 0) CHECK_EQ(range_b.num_of_dimension(1), 0) CHECK_EQ(range_a.num_of_type(types.MBVERTEX), range_a.size()) CHECK_EQ(range_b.num_of_type(types.MBVERTEX), range_b.size()) range_intersect = intersect(range_a, range_b) CHECK_EQ(range_intersect.size(), 0) range_unite = unite(range_a, range_b) CHECK_EQ(range_unite.size(), 12) range_subtract = subtract(range_a, range_b) CHECK_EQ(range_subtract.size(), range_a.size()) range_a.erase(range_a[0]) CHECK_EQ(range_a.size(), 5) all_verts = mb.get_entities_by_type(0, types.MBVERTEX) CHECK_EQ(all_verts.size(), 12) range_intersect = intersect(all_verts, range_a) CHECK_EQ(range_intersect.size(), 5) range_intersect = intersect(all_verts, range_b) CHECK_EQ(range_intersect.size(), 6) range_unite = unite(all_verts, range_a) CHECK_EQ(range_unite.size(), 12) range_unite = unite(all_verts, range_b) CHECK_EQ(range_unite.size(), 12) range_subtract = subtract(all_verts, range_a) CHECK_EQ(range_subtract.size(), 7) range_subtract = subtract(all_verts, range_b) CHECK_EQ(range_subtract.size(), 6) range_a.merge(range_b) CHECK_EQ(range_a.size(), 11)
def __init__(self, mesh_file, dim=3): self.dimension = dim self.mb = core.Core() self.root_set = self.mb.get_root_set() self.mtu = topo_util.MeshTopoUtil(self.mb) self.mb.load_file(mesh_file) self.all_volumes = self.mb.get_entities_by_dimension(0, 3) 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(0, 2) self.all_edges = self.mb.get_entities_by_dimension(0, 1) self.handleDic = {} [self.boundary_nodes, self.boundary_edges, self.boundary_faces, self.boundary_volumes] = self.skinner_operation() self.internal_nodes = rng.subtract(self.all_nodes, self.boundary_nodes) self.internal_edges = rng.subtract(self.all_edges, self.boundary_edges) self.internal_faces = rng.subtract(self.all_faces, self.boundary_faces) self.internal_volumes = rng.subtract(self.all_volumes, self.boundary_volumes) self.init_id() self.check_integrity() self.create_id_visualization() # self.flag_dic = {} [self.flag_list, self.flag_dic] = self.read_flags() self.create_flag_visualization() # swtich on/off self.parallel_meshset = self.create_parallel_meshset() self.create_parallel_visualization()
def get_pyramid_adjacencies(vertices, edges): # Creating used ranges aux1 = rng.Range() aux2 = rng.Range() base_node = rng.Range() top_node = rng.Range() # Discovering the top node of the pyramid for e in vertex_handles: adj = mesh_topo_util.get_bridge_adjacencies(e, 1, 0) if len(adj) == 4: top_node.insert(e) # Defines the base nodes base_nodes = rng.subtract(vertex_handles, top_node) # Getting the base adjacencies of the point of reference aux = mesh_topo_util.get_bridge_adjacencies(base_nodes[0], 1, 0) aux = rng.subtract(top_node, aux) aux1.insert(aux[0]) aux2.insert(aux[1]) base_node.insert(base_nodes[0]) coord1 = mbcore.get_coords(base_node) coord2 = mbcore.get_coords(aux1) coord3 = mbcore.get_coords(aux2) coord4 = mbcore.get_coords(top_node) order = ([coord1, coord2, coord3, coord4]) return order
def run(self): self.root_set = self.mb.get_root_set() self.father_root_set = self.root_set self.level = 0 self.all_volumes = self.mb.get_entities_by_dimension(0, 3) 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(0, 2) self.all_edges = self.mb.get_entities_by_dimension(0, 1) self.handleDic = {} [ self.boundary_nodes, self.boundary_edges, self.boundary_faces, self.boundary_volumes ] = self.skinner_operation() self.internal_nodes = rng.subtract(self.all_nodes, self.boundary_nodes) self.internal_edges = rng.subtract(self.all_edges, self.boundary_edges) self.internal_faces = rng.subtract(self.all_faces, self.boundary_faces) self.internal_volumes = rng.subtract(self.all_volumes, self.boundary_volumes) self.id_name = "GLOBAL_ID" self.father_id_name = self.id_name self.init_id() [self.flag_list, self.flag_dic] = self.read_flags() self.parallel_meshset = self.create_parallel_meshset() self.create_parallel_tag()
def __init__(self, father_core, num, coarse_vec): self.father_core = father_core self.dimension = father_core.dimension self.mb = father_core.mb self.level = father_core.level + 1 self.coarse_num = num self.father_root_set = father_core.root_set self.root_set = self.mb.create_meshset(types.MESHSET_TRACK_OWNER) self.mtu = father_core.mtu self.handleDic = father_core.handleDic if self.dimension == 3: self.all_volumes = father_core.all_volumes[coarse_vec] self.all_faces = self.mb.get_adjacencies(self.all_volumes, 2, False, op_type=types.UNION) self.all_edges = self.mb.get_adjacencies(self.all_volumes, 1, False, op_type=types.UNION) self.all_nodes = self.mb.get_adjacencies(self.all_volumes, 0, False, op_type=types.UNION) elif self.dimension == 2: self.all_volumes = rng.Range() self.all_faces = father_core.all_faces[coarse_vec] self.all_edges = self.access_handle(self.all_faces) self.all_nodes = rng.Range(self.mb.get_connectivity( self.all_faces)) self.mb.add_entities(self.root_set, self.all_volumes) self.mb.add_entities(self.root_set, self.all_faces) self.mb.add_entities(self.root_set, self.all_edges) self.mb.add_entities(self.root_set, self.all_nodes) all_entities = self.mb.get_entities_by_handle(self.root_set) [ self.boundary_nodes, self.boundary_edges, self.boundary_faces, self.boundary_volumes ] = self.skinner_operation() self.internal_nodes = rng.subtract(self.all_nodes, self.boundary_nodes) self.internal_edges = rng.subtract(self.all_edges, self.boundary_edges) self.internal_faces = rng.subtract(self.all_faces, self.boundary_faces) self.internal_volumes = rng.subtract(self.all_volumes, self.boundary_volumes) if self.level == 1: self.id_name = "LOCAL_ID_L" + str(self.level) + "-" + str( self.coarse_num) self.father_id_name = self.father_core.id_name else: self.father_id_name = self.father_core.id_name self.id_name = self.father_id_name + str("L") + str( self.level) + "-" + str(self.coarse_num) self.init_id() self.flag_dic = { key: [rng.intersect(all_entities, el) for el in value] for (key, value) in father_core.flag_dic.items() }
def fine_transmissibility_structured(mb, mtu, map_global, faces_in=None): """ """ # mtu = topo_util.MeshTopoUtil(mb) keq_tag = mb.tag_get_handle(OtherUtils.name_keq_tag) s_grav_tag = mb.tag_get_handle(OtherUtils.name_s_grav) perm_tag = mb.tag_get_handle(OtherUtils.name_perm_tag) area_tag = mb.tag_get_handle(OtherUtils.name_area_tag) elements = rng.Range(np.array(list(map_global.keys()))) n = len(elements) all_keqs = [] all_s_gravs = [] if faces_in == None: all_faces = utpy.get_faces(mb, rng.Range(elements)) # bound_faces = utpy.get_boundary_of_volumes(mb, elements) # faces = rng.subtract(all_faces, bound_faces) faces = rng.subtract(all_faces, utpy.get_boundary_of_volumes(mb, elements)) else: faces = faces_in all_faces = utpy.get_faces(mb, rng.Range(elements)) T = sp.lil_matrix((n, n)) s = np.zeros(n) # cont = 0 for face in faces: #1 keq, s_grav, elems = OtherUtils.get_kequiv_by_face_quad( mb, mtu, face, perm_tag, area_tag) T[map_global[elems[0]], map_global[elems[1]]] = -keq T[map_global[elems[1]], map_global[elems[0]]] = -keq T[map_global[elems[0]], map_global[elems[0]]] += keq T[map_global[elems[1]], map_global[elems[1]]] += keq s_grav *= -1 s[map_global[elems[0]]] += s_grav s[map_global[elems[1]]] -= s_grav all_keqs.append(keq) all_s_gravs.append(s_grav) bound_faces = rng.subtract(all_faces, faces) mb.tag_set_data(keq_tag, bound_faces, np.repeat(0.0, len(bound_faces))) mb.tag_set_data(s_grav_tag, bound_faces, np.repeat(0.0, len(bound_faces))) mb.tag_set_data(keq_tag, faces, all_keqs) mb.tag_set_data(s_grav_tag, faces, all_s_gravs) if OtherUtils.gravity == True: return T, s else: return T, np.zeros(n)
def calculate_pcorr(self, elements, vertex_elem, pcorr_tag, pms_tag, keq_tag, faces, boundary_faces, volumes_d, volumes_n): map_local = dict(zip(elems, range(len(elems)))) n = len(elems) T = sp.lil_matrix((n, n)) b = np.zeros(n) for i, face in enumerate(faces): elems = self.mb.get_adjacencies(face, 3) keq, s_grav, elems = self.get_mobi_by_face_quad_bif(face, keq_tag) if face in boundary_faces: p = self.mb.tag_get_data(pms_tag, elems, flat=True) flux = (p[1] - p[0]) * keq if self.gravity == True: flux += s_grav b[map_local[elems[0]]] += flux b[map_local[elems[1]]] -= flux continue T[map_local[elems[0]], map_local[elems[1]]] = -keq T[map_local[elems[1]], map_local[elems[0]]] = -keq T[map_local[elems[0]], map_local[elems[0]]] += keq T[map_local[elems[1]], map_local[elems[1]]] += keq T[map_local[vertex], map_local[vertex]] = 1 p = self.mb.tag_get_data(pms_tag, vertex, flat=True)[0] b[map_local[vertex]] = p bound1 = rng.intersect(elems, volumes_d) bound1 = rng.subtract(bound1, vertex) if len(bound1) > 0: ids = np.array([map_local[v] for v in bound1]) T[ids] = sp.lil_matrix((len(ids), n)) T[ids, ids] = np.ones(len(ids)) ps = self.mb.tag_get_data(pms_tag, bound1, flat=True) b[ids] = ps bound2 = rng.intersect(elems, volumes_n) bound2 = rng.subtract(bound2, vertex) if len(bound2) > 0: ids = np.array([map_local[v] for v in bound2]) qs = self.mb.tag_get_data(self.list_tags[3], bound2, flat=True) b[ids] += qs x = linalg.spsolve(T, b) self.mb.tag_set_data(pcorr_tag, elements, x)
def all_coarse_neighbors(self): trange = rng.Range() for el in self.coarse_neighbors_dic.values(): trange = rng.unite(trange, el) if self.is_on_father_boundary: trange = rng.subtract(trange, self.coarse_neighbors_dic[max(self.coarse_neighbors_dic.keys())]) return self.read(trange)
def remove_vol(self, element): tetra_remove = rng.intersect(self.all_elements, element) tetra_remaining = rng.subtract(self.all_elements, tetra_remove) #import pdb; pdb.set_trace() faces = rng.subtract(self.adjs(tetra_remove, 2), self.adjs(tetra_remaining,2)) edges = rng.subtract(self.adjs(tetra_remove, 1), self.adjs(tetra_remaining,1)) nodes = rng.subtract(self.adjs(tetra_remove, 0), self.adjs(tetra_remaining,0)) self.mb.delete_entity(tetra_remove) self.mb.delete_entity(faces) self.mb.delete_entity(edges) self.mb.delete_entity(nodes) self.all_elements = self.mb.get_entities_by_dimension(0, 3) self.nodes = self.mb.get_entities_by_dimension(0, 0) self.faces = self.skinner(self.all_elements) self.boundary_nodes = self.find_boundary_nodes() self.boundary_elements = self.find_boundary_elements()
def get_vizinhos_de_face(self): n_levels = self.n_levels # n_levels = 1 # colocar vizinhos de face apenas no nivel grosso 1 name_vizinhos_tag = 'VIZINHOS_FACE_LV_' for i in range(n_levels): meshsets_vistos = set() meshsets = self.mesh.entities['coarse_volumes_lv' + str(i + 1)] fine_to_primal_tag = self.mesh.tags['FINE_TO_PRIMAL_CLASSIC_' + str(i + 1)] primal_id_tag = self.mesh.tags['PRIMAL_ID_' + str(i + 1)] todos_elementos_vizinhos = dict() for m in meshsets: elems_in_meshset = self.mesh.mb.get_entities_by_handle(m) elems_fora = self.mesh.mtu.get_bridge_adjacencies( elems_in_meshset, 2, 3) elems_fora = rng.subtract(elems_fora, elems_in_meshset) ids_meshsets_vizinhos = np.unique( self.mesh.mb.tag_get_data(fine_to_primal_tag, elems_fora, flat=True)) meshsets_vizinhos1 = todos_elementos_vizinhos.setdefault( m, list()) for j in ids_meshsets_vizinhos: m2 = self.mesh.mb.get_entities_by_type_and_tag( 0, types.MBENTITYSET, np.array([primal_id_tag]), np.array([j]))[0] elems_in_m2 = self.mesh.mb.get_entities_by_handle(m2) if set([m2]) & meshsets_vistos: continue meshsets_vizinhos1.append(m2) meshsets_vizinhos2 = todos_elementos_vizinhos.setdefault( m2, list()) meshsets_vizinhos2.append(m) meshsets_vistos.add(m) name = name_vizinhos_tag + str(i + 1) n = 6 tipo = 'array' entitie = 'coarse_volumes_lv' + str(i + 1) t1 = types.MB_TYPE_HANDLE t2 = types.MB_TAG_SPARSE getting_tag(self.mesh.mb, name, n, t1, t2, True, entitie, tipo, self.mesh.tags, self.mesh.tags_to_infos, self.mesh.entities_to_tags) tag_vizinhos = self.mesh.tags[name] for m, vizinhos in todos_elementos_vizinhos.items(): n2 = len(vizinhos) if n2 < 6: for i in range(6 - n2): m3 = self.mesh.mb.create_meshset() vizinhos.append(m3) self.mesh.mb.tag_set_data(tag_vizinhos, m, vizinhos)
def set_faces_in_boundary_by_meshsets(mb, mtu, meshsets, faces_boundary_meshset_tag, M): all_faces_on_boundary = mb.create_meshset() meshsets = list(meshsets) n = len(meshsets) ms0 = set() # for m1 in meshsets: # ms0.add(m1) # cont = 0 # elems1 = mb.get_entities_by_handle(m1) # faces1 = mtu.get_bridge_adjacencies(elems1, 2, 2) # for m2 in meshsets: # if m2 in ms0: # continue # elems2 = mb.get_entities_by_handle(m2) # faces2 = mtu.get_bridge_adjacencies(elems2, 2, 2) # intersect = rng.intersect(faces1, faces2) # if len(intersect) < 1: # continue # cont+=1 # mb.add_entities(all_faces_on_boundary, intersect) # print(cont) # if cont > 3: # print(i) # print(cont) # import pdb; pdb.set_trace() # import pdb; pdb.set_trace() for m1 in meshsets: cont = 0 elems1 = mb.get_entities_by_handle(m1) faces1 = mtu.get_bridge_adjacencies(elems1, 3, 2) # for face in faces1: # elems = mb.get_adjacencies(face, 3) # if len(elems) < 2: # continue # if elems[0] in elems1 and elems[1] in elems1: # continue # mb.add_entities(all_faces_on_boundary, rng.Range(face)) elems2 = mtu.get_bridge_adjacencies(elems1, 2, 3) elems3 = rng.subtract(elems2, elems1) try: faces3 = mtu.get_bridge_adjacencies(elems3, 3, 2) faces_cont = rng.intersect(faces3, faces1) except Exception as e: faces_cont = faces1 mb.add_entities(all_faces_on_boundary, faces_cont) mb.tag_set_data(faces_boundary_meshset_tag, M.core.root_set, all_faces_on_boundary)
def set_k1_test(mb, perm_tag, all_volumes, all_centroids): k01 = 1.0 k02 = 100.0 k1 = [k01, 0.0, 0.0, 0.0, k01, 0.0, 0.0, 0.0, k01] k2 = [k02, 0.0, 0.0, 0.0, k02, 0.0, 0.0, 0.0, k02] b1 = np.array([np.array([200, 0, 0]), np.array([220, 200, 90])]) b2 = np.array([np.array([400, 100, 0]), np.array([420, 300, 90])]) inds0 = np.where(all_centroids[:,0] > b1[0,0])[0] inds1 = np.where(all_centroids[:,1] > b1[0,1])[0] inds2 = np.where(all_centroids[:,2] > b1[0,2])[0] c1 = set(inds0) & set(inds1) & set(inds2) inds0 = np.where(all_centroids[:,0] < b1[1,0])[0] inds1 = np.where(all_centroids[:,1] < b1[1,1])[0] inds2 = np.where(all_centroids[:,2] < b1[1,2])[0] c2 = set(inds0) & set(inds1) & set(inds2) inds_vols1 = np.array(list(c1 & c2)) inds0 = np.where(all_centroids[:,0] > b2[0,0])[0] inds1 = np.where(all_centroids[:,1] > b2[0,1])[0] inds2 = np.where(all_centroids[:,2] > b2[0,2])[0] c1 = set(inds0) & set(inds1) & set(inds2) inds0 = np.where(all_centroids[:,0] < b2[1,0])[0] inds1 = np.where(all_centroids[:,1] < b2[1,1])[0] inds2 = np.where(all_centroids[:,2] < b2[1,2])[0] c2 = set(inds0) & set(inds1) & set(inds2) inds_vols2 = np.array(list(c1 & c2)) volsk1 = rng.Range(np.array(all_volumes)[inds_vols1]) volsk2 = rng.Range(np.array(all_volumes)[inds_vols2]) volsk1 = rng.Range(set(volsk1) | set(volsk2)) volsk2 = rng.subtract(all_volumes, volsk1) for v in volsk1: mb.tag_set_data(perm_tag, v, k1) for v in volsk2: mb.tag_set_data(perm_tag, v , k2) testk1_tag = mb.tag_get_handle('testk1', 1, types.MB_TYPE_DOUBLE, types.MB_TAG_SPARSE, True) testk2_tag = mb.tag_get_handle('testk2', 1, types.MB_TYPE_DOUBLE, types.MB_TAG_SPARSE, True) mb.tag_set_data(testk1_tag, volsk1, np.repeat(k01, len(volsk1))) mb.tag_set_data(testk2_tag, volsk2, np.repeat(k02, len(volsk2)))
def get_adjs_volumes(self, MM): MM.all_intern_faces = rng.subtract(MM.all_faces, MM.all_faces_boundary) MM.all_intern_adjacencies = np.array([ np.array(MM.mb.get_adjacencies(face, 3)) for face in MM.all_intern_faces ]) MM.all_adjacent_volumes = [] MM.all_adjacent_volumes.append( MM.mb.tag_get_data(MM.ID_reordenado_tag, np.array(MM.all_intern_adjacencies[:, 0]), flat=True)) MM.all_adjacent_volumes.append( MM.mb.tag_get_data(MM.ID_reordenado_tag, np.array(MM.all_intern_adjacencies[:, 1]), flat=True))
def calculate_total_flux(self, ids0, ids1, mobi_in_faces, s_grav_f, Pf, fw_in_faces, volumes, gravity): t1 = time.time() tags_1 = self.tags mb = self.mb meshset_vertices = self.mv meshset_vertices_nv2 = self.mv2 mtu = self.mtu boundary_faces = self.all_boundary_faces elems_nv0 = mb.get_entities_by_type_and_tag( 0, types.MBHEX, np.array([tags_1['l3_ID']]), np.array([1])) vertices_nv1 = mb.get_entities_by_type_and_tag( meshset_vertices, types.MBHEX, np.array([tags_1['l3_ID']]), np.array([2])) vertices_nv2 = mb.get_entities_by_type_and_tag( meshset_vertices_nv2, types.MBHEX, np.array([tags_1['l3_ID']]), np.array([3])) k = 0 self.calc_pcorr_nv(vertices_nv1, k, tags_1['FINE_TO_PRIMAL1_CLASSIC']) k = 1 self.calc_pcorr_nv(vertices_nv2, k, tags_1['FINE_TO_PRIMAL2_CLASSIC']) faces = mtu.get_bridge_adjacencies(elems_nv0, 3, 2) faces = rng.subtract(faces, boundary_faces) self.set_flux_pms_elems_nv0(elems_nv0, faces, tags_1['PMS2']) t2 = time.time() dt = t2 - t1 print('correcao: ', dt) volumes = self.wirebasket_elems_nv0 fluxos = self.mb.tag_get_data(self.tags['TOTAL_FLUX'], volumes, flat=True) fluxos_w = self.mb.tag_get_data(self.tags['FLUX_W'], volumes, flat=True) flux_in_faces = self.mb.tag_get_data(self.tags['FLUX_IN_FACES'], self.all_faces_in, flat=True) fw_in_faces = self.mb.tag_get_data(self.tags['FW_IN_FACES'], self.all_faces_in, flat=True) flux_w_in_faces = flux_in_faces * fw_in_faces return fluxos, fluxos_w, flux_in_faces, flux_w_in_faces
def run_2_v2(t): print('entrou run2') t0 = time.time() elems_nv0 = mb.get_entities_by_type_and_tag(0, types.MBHEX, np.array([tags_1['l3_ID']]), np.array([1])) vertices_nv1 = mb.get_entities_by_type_and_tag(meshset_vertices, types.MBHEX, np.array([tags_1['l3_ID']]), np.array([0])) vertices_nv1 = rng.subtract(mb.get_entities_by_handle(meshset_vertices), vertices_nv1) bif_utils.calculate_pcorr_v3(mb, bound_faces_nv[0], tags_1['PMS2'], tags_1['PCORR2'], vertices_nv1, tags_1, all_volumes) mb.write_file('exemplo.vtk', [vv]) pdb.set_trace()
def get_boundary_faces(self): all_boundary_faces = self.mb.create_meshset() intern_faces_set = self.mb.create_meshset() for face in self.all_faces: elems = self.mtu.get_bridge_adjacencies(face, 2, 3) if len(elems) < 2: self.mb.add_entities(all_boundary_faces, [face]) self.mb.tag_set_data(self.tags['BOUNDARY_FACES'], 0, all_boundary_faces) self.all_boundary_faces = self.mb.get_entities_by_handle( all_boundary_faces) self.intern_faces = rng.subtract(self.all_faces, self.all_boundary_faces) self.mb.add_entities(intern_faces_set, self.intern_faces) self.mb.tag_set_data(self.tags['INTERN_FACES'], 0, intern_faces_set) self.mb.tag_set_data(self.tags['GIDS_INTERN_FACES'], self.intern_faces, np.arange(len(self.intern_faces)))
def fine_transmissibility_structured_bif(self, map_global, mobi_tag, faces_in=None): """ """ # mtu = topo_util.MeshTopoUtil(mb) s_grav_tag = self.mb.tag_get_handle(OtherUtils.name_s_grav) elements = rng.Range(np.array(list(map_global.keys()))) n = len(elements) all_s_gravs = [] if faces_in == None: all_faces = utpy.get_faces(mb, rng.Range(elements)) # bound_faces = utpy.get_boundary_of_volumes(mb, elements) # faces = rng.subtract(all_faces, bound_faces) faces = rng.subtract(all_faces, utpy.get_boundary_of_volumes(mb, elements)) else: faces = faces_in all_faces = utpy.get_faces(mb, rng.Range(elements)) T = sp.lil_matrix((n, n)) s = np.zeros(n) # cont = 0 for face in faces: #1 keq, s_grav, elems = self.get_mobi_by_face_quad_bif(face, mobi_tag) T[map_global[elems[0]], map_global[elems[1]]] = -keq T[map_global[elems[1]], map_global[elems[0]]] = -keq T[map_global[elems[0]], map_global[elems[0]]] += keq T[map_global[elems[1]], map_global[elems[1]]] += keq s[map_global[elems[0]]] += s_grav s[map_global[elems[1]]] -= s_grav all_s_gravs.append(s_grav) self.mb.tag_set_data(s_grav_tag, faces, all_s_gravs) if OtherUtils.gravity == True: return T, s else: return T, np.zeros(n)
def get_OP_adm_nv1(mb, all_volumes, OP_AMS, ID_reord_tag, L1_ID_tag, L3_ID_tag, d1_tag, fine_to_primal1_classic_tag): elems_nv0 = mb.get_entities_by_type_and_tag(0, types.MBHEX, np.array([L3_ID_tag]), np.array([1])) elems_nv1 = rng.subtract(all_volumes, elems_nv0) gids_nv1_elems_nv1 = np.unique(mb.tag_get_data(L1_ID_tag, elems_nv1, flat=True)) gids_elems_nv0 = mb.tag_get_data(ID_reord_tag, elems_nv0, flat=True) gids_adm_nv1_elems_nv0 = mb.tag_get_data(L1_ID_tag, elems_nv0, flat=True) all_ids_nv1 = np.unique(mb.tag_get_data(L1_ID_tag, all_volumes, flat=True)) OP_adm_nv1 = sp.lil_matrix((len(all_volumes), len(all_ids_nv1))) vertex_elems = mb.get_entities_by_type_and_tag(0, types.MBHEX, np.array([d1_tag]), np.array([3])) id_nv1_op_classic_vertex_elems = mb.tag_get_data(fine_to_primal1_classic_tag, vertex_elems, flat=True) id_adm_nv1_vertex_elems = mb.tag_get_data(L1_ID_tag, vertex_elems, flat=True) OP_adm_nv1[:, id_adm_nv1_vertex_elems] = OP_AMS[:, id_nv1_op_classic_vertex_elems] # for id_adm, id_classic in zip(id_adm_nv1_vertex_elems, id_nv1_op_classic_vertex_elems): # OP_adm_nv1[:,id_adm] = OP_AMS[:,id_classic] OP_adm_nv1[gids_elems_nv0] = sp.lil_matrix((len(gids_elems_nv0), len(all_ids_nv1))) OP_adm_nv1[gids_elems_nv0, gids_adm_nv1_elems_nv0] = np.ones(len(gids_elems_nv0)) return OP_adm_nv1
def get_OR_adm_nv1(mb, all_volumes, ID_reord_tag, L1_ID_tag, L3_ID_tag): elems_nv0 = mb.get_entities_by_type_and_tag(0, types.MBHEX, np.array([L3_ID_tag]), np.array([1])) elems_nv1 = rng.subtract(all_volumes, elems_nv0) gids_nv1_elems_nv1 = np.unique( mb.tag_get_data(L1_ID_tag, elems_nv1, flat=True)) gids_elems_nv0 = mb.tag_get_data(ID_reord_tag, elems_nv0, flat=True) gids_nv1_elems_nv0 = mb.tag_get_data(L1_ID_tag, elems_nv0, flat=True) all_ids_nv1 = np.unique(mb.tag_get_data(L1_ID_tag, all_volumes, flat=True)) OR = sp.lil_matrix((len(all_ids_nv1), len(all_volumes))) OR[gids_nv1_elems_nv0, gids_elems_nv0] = np.ones(len(elems_nv0)) ms1 = set() for id in gids_nv1_elems_nv1: elems = mb.get_entities_by_type_and_tag(0, types.MBHEX, np.array([L1_ID_tag]), np.array([id])) gids_nv0_elems = mb.tag_get_data(ID_reord_tag, elems, flat=True) OR[np.repeat(id, len(elems)), gids_nv0_elems] = np.ones(len(elems)) return OR
def set_keq_structured(self): v0 = self.all_volumes[0] nodes = self.mtu.get_bridge_adjacencies(v0, 3, 0) coords_nodes = self.mb.get_coords(nodes).reshape([len(nodes), 3]) xmin = coords_nodes[:, 0].min() xmax = coords_nodes[:, 0].max() ymin = coords_nodes[:, 1].min() ymax = coords_nodes[:, 1].max() zmin = coords_nodes[:, 2].min() zmax = coords_nodes[:, 2].max() hs = np.array([xmax - xmin, ymax - ymin, zmax - zmin]) faces_in = rng.subtract(self.all_faces, self.all_boundary_faces) all_ks = self.mb.tag_get_data(self.perm_tag, self.all_volumes) all_keqs = np.zeros(len(faces_in)) map_volumes = dict(zip(self.all_volumes, range(len(self.all_volumes)))) areas = self.mb.tag_get_data(self.area_tag, faces_in, flat=True) for i, face in enumerate(faces_in): elems = self.mb.get_adjacencies(face, 3) if len(elems) < 2: continue k0 = all_ks[map_volumes[elems[0]]].reshape([3, 3]) k1 = all_ks[map_volumes[elems[1]]].reshape([3, 3]) c0 = self.all_centroids[map_volumes[elems[0]]] c1 = self.all_centroids[map_volumes[elems[1]]] direction = c1 - c0 h = np.linalg.norm(direction) uni = np.absolute(direction / h) k0 = np.dot(np.dot(k0, uni), uni) k1 = np.dot(np.dot(k1, uni), uni) area = areas[i] keq = area * (2 * k1 * k0) / (h * (k1 + k0) * self.mi) all_keqs[i] = keq self.mb.tag_set_data(self.keq_tag, self.all_faces, np.repeat(0.0, len(self.all_faces))) self.mb.tag_set_data(self.keq_tag, faces_in, all_keqs)
def calc_pcorr_nv(self, vertices_nv, k, tag_primal_classic): tags_1 = self.tags mb = self.mb mtu = self.mtu boundary_faces = self.all_boundary_faces bound_faces_nv = self.bound_faces_nv for vert in vertices_nv: t00 = time.time() primal_id = mb.tag_get_data(tag_primal_classic, vert, flat=True)[0] elems_in_meshset = mb.get_entities_by_type_and_tag( 0, types.MBHEX, np.array([tag_primal_classic]), np.array([primal_id])) faces = mtu.get_bridge_adjacencies(elems_in_meshset, 3, 2) faces = rng.subtract(faces, boundary_faces) faces_boundary = rng.intersect(faces, bound_faces_nv[k]) if len(faces_boundary) < 1: import pdb pdb.set_trace() t01 = time.time() t02 = time.time() self.calculate_pcorr(elems_in_meshset, vert, faces_boundary, faces, k) self.set_flux_pms_meshsets(elems_in_meshset, faces, faces_boundary)
def find_coarse_neighbours(self): self.connectivities = np.zeros( (self.num_coarse, self.num_coarse + 1, 3)).astype('bool') self.nodes_neighbors = np.zeros((self.num_coarse, self.num_coarse + 1), dtype=object) self.edges_neighbors = np.zeros((self.num_coarse, self.num_coarse + 1), dtype=object) self.faces_neighbors = np.zeros((self.num_coarse, self.num_coarse + 1), dtype=object) self.nodes_neighbors[:], self.edges_neighbors[:], self.faces_neighbors[:] = None, None, None self._nodes = list() self._faces = list() self._edges = list() self.all_nodes_neighbors = rng.Range() self.all_edges_neighbors = rng.Range() self.all_faces_neighbors = rng.Range() self.all_volumes_neighbors = rng.Range() #print(self.all_nodes_neighbors, self.all_edges_neighbors, self.all_faces_neighbors) # import pdb; pdb.set_trace() node_count, edge_count, face_count = 0, 0, 0 for x in range(self.num_coarse): for y in range(x + 1, self.num_coarse): node_intersect = rng.intersect( self.elements[x].core.boundary_nodes, self.elements[y].core.boundary_nodes) if not node_intersect.empty(): self._nodes.append(node_intersect) #self._nodes = np.append(self._nodes,node_intersect) self.nodes_neighbors[x, y], self.nodes_neighbors[ y, x], = node_count, node_count self.connectivities[x, y, 0], self.connectivities[y, x, 0] = True, True node_count += 1 [ self.all_nodes_neighbors.insert(e) for e in node_intersect ] edges_intersect = rng.intersect( self.elements[x].core.boundary_edges, self.elements[y].core.boundary_edges) if not edges_intersect.empty(): self._edges.append(edges_intersect) # self._edges = np.append(self._edges,edges_intersect) self.edges_neighbors[x, y], self.edges_neighbors[ y, x] = edge_count, edge_count self.connectivities[x, y, 1], self.connectivities[y, x, 1] = True, True edge_count += 1 [ self.all_edges_neighbors.insert(e) for e in edges_intersect ] faces_intersect = rng.intersect( self.elements[x].core.boundary_faces, self.elements[y].core.boundary_faces) if not faces_intersect.empty(): self._faces.append(faces_intersect) #self._faces = np.append(self._faces,faces_intersect) self.faces_neighbors[x, y], self.faces_neighbors[ y, x] = face_count, face_count self.connectivities[x, y, 2], self.connectivities[y, x, 2] = True, True face_count += 1 [ self.all_faces_neighbors.insert(e) for e in faces_intersect ] self.num_internal_nodes = node_count self.num_internal_edges = edge_count self.num_internal_faces = face_count for x in range(self.num_coarse): # fix the interesection - second variable poorly choosen node_intersect = rng.subtract(self.elements[x].core.boundary_nodes, self.all_nodes_neighbors) if not node_intersect.empty(): self._nodes.append(node_intersect) self.nodes_neighbors[x, -1] = node_count self.connectivities[x, -1, 0] = True node_count += 1 edge_intersect = rng.subtract(self.elements[x].core.boundary_edges, self.all_edges_neighbors) if not edge_intersect.empty(): self._edges.append(edge_intersect) self.edges_neighbors[x, -1] = edge_count self.connectivities[x, -1, 1] = True edge_count += 1 face_intersect = rng.subtract(self.elements[x].core.boundary_faces, self.all_faces_neighbors) if not face_intersect.empty(): self._faces.append(face_intersect) self.faces_neighbors[x, -1] = face_count self.connectivities[x, -1, 2] = True face_count += 1
def __init__(self): global input_dir global flying_dir global bifasico_sol_direta_dir global bifasico_sol_multiescala_dir os.chdir(input_dir) with open("inputs.yaml", 'r') as stream: data_loaded = yaml.load(stream) # data_loaded = yaml.load(stream, Loader=yaml.FullLoader) # data_loaded = yaml.full_load(stream) input_file = data_loaded['input_file'] self.input_file = input_file ext_h5m_adm = input_file + '_malha_adm.h5m' self.mb = core.Core() self.mtu = topo_util.MeshTopoUtil(self.mb) self.data_loaded = data_loaded converter_unidades = data_loaded['converter_unidades'] ADM = data_loaded['ADM'] ler_anterior = np.load('ler_anterior.npy')[0] self.ler_anterior = ler_anterior if ler_anterior == False: os.chdir(flying_dir) self.mb.load_file(ext_h5m_adm) self.ultimo_loop = 0 self.vpi = 0.0 self.t = 0.0 else: os.chdir(input_dir) ultimo_loop = np.load('ultimo_loop.npy')[0] self.ultimo_loop = ultimo_loop if ADM == False: ext_h5m = input_file + 'sol_direta_' + str( ultimo_loop) + '.h5m' os.chdir(bifasico_sol_direta_dir) self.mb.load_file(ext_h5m) else: ext_h5m = input_file + 'sol_direta_' + str( ultimo_loop) + '.h5m' os.chdir(bifasico_sol_direta_dir) self.mb.load_file(ext_h5m) hist = np.load('historico_' + str(ultimo_loop) + '.npy') self.vpi = hist[0] self.t = hist[1] self.all_volumes = self.mb.get_entities_by_dimension(0, 3) 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(0, 2) self.all_edges = self.mb.get_entities_by_dimension(0, 1) self.tags = LoadADMMesh.load_tags(self.mb) self.tags.update( LoadADMMesh.create_tags_bifasico(self.mb, ADM, self.all_nodes)) self.volumes_d = self.mb.get_entities_by_type_and_tag( 0, types.MBHEX, np.array([self.tags['P']]), np.array([None])) self.volumes_n = self.mb.get_entities_by_type_and_tag( 0, types.MBHEX, np.array([self.tags['Q']]), np.array([None])) self.mi_w = float(data_loaded['dados_bifasico']['mi_w']) self.mi_o = float(data_loaded['dados_bifasico']['mi_o']) self.gama_w = float(data_loaded['dados_bifasico']['gama_w']) self.gama_o = float(data_loaded['dados_bifasico']['gama_o']) self.Sor = float(data_loaded['dados_bifasico']['Sor']) self.Swc = float(data_loaded['dados_bifasico']['Swc']) self.nw = float(data_loaded['dados_bifasico']['nwater']) self.no = float(data_loaded['dados_bifasico']['noil']) self.loops = int(data_loaded['dados_bifasico']['loops']) self.total_time = float(data_loaded['dados_bifasico']['total_time']) self.gravity = data_loaded['gravity'] if not ler_anterior and converter_unidades: setinfo.convert_to_SI(self.mb, self.tags, self.all_volumes, self.all_faces, self.all_nodes, self.volumes_d, self.volumes_n) if ADM: self.internos, self.faces, self.arestas, self.vertices, \ self.wirebasket_elems, self.mv, self.bound_faces_nv, \ self.wirebasket_numbers, self.meshsets_levels, self.finos0, self.intermediarios, \ self.L2_meshset, self.faces_adjs_by_dual, self.intern_adjs_by_dual = LoadADMMesh.load_elems_adm(self.mb, self.tags) self.wirebasket_elems_nv1 = LoadADMMesh.load_wirebasket_elems_nv1( self.mb, self.tags) if len(self.volumes_n) == 0: self.wells_injector, self.wells_producer = setinfo.injector_producer_press( self.mb, self.gama_w, self.gama_o, self.gravity, self.all_nodes, self.volumes_d, self.tags) else: self.wells_injector, self.wells_producer = setinfo.injector_producer( self.mb, self.gama_w, self.gama_o, self.gravity, self.all_nodes, self.volumes_d, self.volumes_n, self.tags) self.all_boundary_faces = self.mb.get_entities_by_handle( self.mb.tag_get_data(self.tags['FACES_BOUNDARY'], 0, flat=True)[0]) self.all_faces_in = rng.subtract(self.all_faces, self.all_boundary_faces) self.Adjs = np.array([ np.array(self.mb.get_adjacencies(f, 3)) for f in self.all_faces_in ]) self.all_centroids = self.mb.tag_get_data(self.tags['CENT'], self.all_volumes) self.all_kharm = self.mb.tag_get_data(self.tags['KHARM'], self.all_faces_in, flat=True) self.ADM = ADM self.vv = self.mb.create_meshset() self.mb.add_entities(self.vv, self.all_volumes) if not ler_anterior: LoadADMMesh.set_sat_in(self.mb, self.wells_injector, self.all_volumes, self.tags, self.all_centroids)
# fazendo os ids comecarem de 0 em todos os niveis tags = [L1_ID_tag, L2_ID_tag] for tag in tags: all_gids = mb.tag_get_data(tag, all_volumes, flat=True) minim = min(all_gids) all_gids -= minim mb.tag_set_data(tag, all_volumes, all_gids) ###preprocessamento1 ########################################################## boundary_faces_tag = mb.tag_get_handle("FACES_BOUNDARY") faces_boundary = mb.tag_get_data(boundary_faces_tag, 0, flat=True)[0] faces_boundary = mb.get_entities_by_handle(faces_boundary) faces_in = rng.subtract(all_faces, faces_boundary) all_keqs = mb.tag_get_data(k_eq_tag, faces_in, flat=True) Adjs = np.array([np.array(mb.get_adjacencies(face, 3)) for face in faces_in]) all_ids_reord = mb.tag_get_data(ID_reordenado_tag, all_volumes, flat=True) map_volumes = dict(zip(all_volumes, range(len(all_volumes)))) tempo0_ADM=time.time() lines_tf = [] cols_tf = [] data_tf = [] b2 = np.zeros(len(all_volumes)) s_grav_faces = np.zeros(len(faces_in))
# index = list_names_tags.index('S_GRAV') # s_grav_tag = tags_1[index] area_tag = get_tag('AREA') perm_tag = get_tag('PERM') boundary_faces = mb.get_entities_by_handle( mb.tag_get_data(get_tag('FACES_BOUNDARY'), 0, flat=True)[0]) gids2 = mb.tag_get_data(ID_reordenado_tag, all_volumes, flat=True) map_global = dict(zip(all_volumes, gids2)) s = np.zeros(len(all_volumes)) print("def As") ty = time.time() for f in rng.subtract(all_faces, boundary_faces): keq, s_grav, adjs = oth.get_kequiv_by_face_quad(mb, mtu, f, perm_tag, area_tag) keq = 1 Gid_1 = map_global[adjs[0]] Gid_2 = map_global[adjs[1]] if Gid_1 < ni and Gid_2 < ni: lii.append(Gid_1) cii.append(Gid_2) dii.append(keq) lii.append(Gid_2) cii.append(Gid_1) dii.append(keq)
def get_op_adm_nv2(mb, OP2, wirebasket_ord_1, wirebasket_numbers_1, map_nc_in_wirebasket_id_1, all_volumes): nc_primal_tag_1 = mb.tag_get_handle('NC_PRIMAL_1') nc_primal_tag_2 = mb.tag_get_handle('NC_PRIMAL_2') d2_tag = mb.tag_get_handle(ProlongationTPFA3D.name_d2_tag) map_wirebasket_id_in_nc_1 = {} for i, j in map_nc_in_wirebasket_id_1.items(): map_wirebasket_id_in_nc_1[j] = i meshsets_nv2 = np.array( mb.get_entities_by_type_and_tag(mb.get_root_set(), types.MBENTITYSET, np.array([nc_primal_tag_2]), np.array([None]))) lv1_id_tag = mb.tag_get_handle(ProlongationTPFA3D.name_l1_id) lv2_id_tag = mb.tag_get_handle(ProlongationTPFA3D.name_l2_id) level_tag = mb.tag_get_handle(ProlongationTPFA3D.name_l3_id) all_ids_nv1 = np.unique( mb.tag_get_data(lv1_id_tag, all_volumes, flat=True)) all_ids_nv2 = np.unique( mb.tag_get_data(lv2_id_tag, all_volumes, flat=True)) OP_adm_nv2 = sp.lil_matrix((len(all_ids_nv1), len(all_ids_nv2))) meshsets_nv1_que_estao_no_nv2 = [] id_adm_lv2_dos_meshsets_nv1_que_estao_no_nv2 = [] id_adm_lv1_dos_meshsets_nv1_que_estao_no_nv2 = [] todos_meshsets_que_estao_no_nivel_1 = [] ids_adm_nv1_de_todos_meshsets_que_estao_no_nivel_1 = [] for m2 in meshsets_nv2: childs = mb.get_child_meshsets(m2) for m in childs: mb.add_parent_meshset(m, m2) elems = mb.get_entities_by_handle(m) id_adm_nv1 = np.unique( mb.tag_get_data(lv1_id_tag, elems, flat=True)) if len(id_adm_nv1) > 1: continue todos_meshsets_que_estao_no_nivel_1.append(m) ids_adm_nv1_de_todos_meshsets_que_estao_no_nivel_1.append( id_adm_nv1[0]) elems = mb.get_entities_by_handle(m2) id_lv2 = np.unique(mb.tag_get_data(lv2_id_tag, elems, flat=True)) if len(id_lv2) > 1: continue meshsets_nv1_que_estao_no_nv2.append(childs) id_adm_lv2_dos_meshsets_nv1_que_estao_no_nv2.append(id_lv2[0]) ids_adm_lv1 = [] for m in childs: elems_1 = mb.get_entities_by_handle(m) id_adm_lv1 = np.unique( mb.tag_get_data(lv1_id_tag, elems_1, flat=True)) ids_adm_lv1.append(id_adm_lv1) id_adm_lv1_dos_meshsets_nv1_que_estao_no_nv2.append(ids_adm_lv1[:]) ncs_de_todos_meshsets_que_estao_no_nivel_1 = mb.tag_get_data( nc_primal_tag_1, todos_meshsets_que_estao_no_nivel_1, flat=True) map_ncs_de_todos_meshsets_que_estao_no_nivel_1_in_id_adm_1 = dict( zip(ncs_de_todos_meshsets_que_estao_no_nivel_1, ids_adm_nv1_de_todos_meshsets_que_estao_no_nivel_1)) map_todos_meshsets_que_estao_no_nivel_1_in_id_adm_1 = dict( zip(todos_meshsets_que_estao_no_nivel_1, ids_adm_nv1_de_todos_meshsets_que_estao_no_nivel_1)) # import pdb; pdb.set_trace() # print(meshsets_nv1_que_estao_no_nv2) # print(id_adm_lv1_dos_meshsets_nv1_que_estao_no_nv2) # print(id_adm_lv2_dos_meshsets_nv1_que_estao_no_nv2) # print(todos_meshsets_que_estao_no_nivel_1) # print(ids_adm_nv1_de_todos_meshsets_que_estao_no_nivel_1) # import pdb; pdb.set_trace() nni = wirebasket_numbers_1[0] nnf = nni + wirebasket_numbers_1[1] nne = nnf + wirebasket_numbers_1[2] nnv = nne + wirebasket_numbers_1[3] nc_vertex_elems = np.array(wirebasket_ord_1[nne:nnv], dtype=np.uint64) meshsets_vertex_elems_nv1 = [ mb.get_entities_by_type_and_tag(mb.get_root_set(), types.MBENTITYSET, np.array([nc_primal_tag_1]), np.array([i]))[0] for i in nc_vertex_elems ] cont = 0 vertices_pi_chapeu = [] ids_lv2_vertices_pi_chapeu = [] for m in meshsets_vertex_elems_nv1: if m in todos_meshsets_que_estao_no_nivel_1: vertices_pi_chapeu.append(m) elems = mb.get_entities_by_handle(m) id_lv2_adm = np.unique( mb.tag_get_data(lv2_id_tag, elems, flat=True)) ids_lv2_vertices_pi_chapeu.append(id_lv2_adm) # meshsets_vertex_elems_nv1 = rng.Range(meshsets_vertex_elems_nv1) # nc_vertex_elems = mb.tag_get_data(nc_primal_tag_1, meshsets_vertex_elems_nv1, flat=True) for i, m in enumerate(vertices_pi_chapeu): id_adm_lv2_vertice = ids_lv2_vertices_pi_chapeu[i] parent_meshset = mb.get_parent_meshsets(m) nc2 = mb.tag_get_data(nc_primal_tag_2, parent_meshset, flat=True)[0] col_op2 = OP2[:, nc2] indices = sp.find(col_op2) lines = [] vals = [] for j, ind in enumerate(indices[0]): nc_1 = map_wirebasket_id_in_nc_1[ind] if nc_1 not in ncs_de_todos_meshsets_que_estao_no_nivel_1: continue id_adm_nv1 = map_ncs_de_todos_meshsets_que_estao_no_nivel_1_in_id_adm_1[ nc_1] lines.append(id_adm_nv1) vals.append(indices[2][j]) col = np.repeat(id_adm_lv2_vertice, len(vals)).astype(np.int32) lines = np.array(lines).astype(np.int32) vals = np.array(vals) OP_adm_nv2[lines, col] = vals todos = rng.Range(todos_meshsets_que_estao_no_nivel_1) for meshsets in meshsets_nv1_que_estao_no_nv2: todos = rng.subtract(todos, meshsets) for m in todos: elems = mb.get_entities_by_handle(m) id_adm_2 = np.unique(mb.tag_get_data(lv2_id_tag, elems, flat=True))[0] id_adm_1 = map_todos_meshsets_que_estao_no_nivel_1_in_id_adm_1[m] OP_adm_nv2[id_adm_1] = np.zeros(len(all_ids_nv2)) OP_adm_nv2[id_adm_1, id_adm_2] = 1.0 elems_nv0 = mb.get_entities_by_type_and_tag(mb.get_root_set(), types.MBHEX, np.array([level_tag]), np.array([1])) ids_adm_lv2_elems_nv0 = mb.tag_get_data(lv2_id_tag, elems_nv0, flat=True) ids_adm_lv1_elems_nv0 = mb.tag_get_data(lv1_id_tag, elems_nv0, flat=True) OP_adm_nv2[ids_adm_lv1_elems_nv0, ids_adm_lv2_elems_nv0] = np.ones(len(elems_nv0)) return OP_adm_nv2
else: raise NameError("type_prescription == 'neumann' or 'dirichlet'") if bifasico == True and w['type_well'] == 'injector': M1.mb.add_entities(wells_injector, volumes) if bifasico == True: loader = importlib.machinery.SourceFileLoader('bif_utils', utils_dir + '/bif_utils.py') bif_utils = loader.load_module('bif_utils').bifasico( M1.mb, M1.mtu, M1.all_volumes) bif_utils.set_sat_in(M1.all_volumes) bif_utils.set_lamb(M1.all_volumes) bif_utils.set_mobi_faces_ini( M1.all_volumes, rng.subtract(M1.all_faces, M1.all_boundary_faces)) # mb, all_volumes, all_faces_in, wells_inj, k_eq_tag, mobi_in_faces_tag, mobi_w_in_faces_tag # Ci = n: Ci -> Razão de engrossamento ni nível i (em relação ao nível i-1), # n -> número de blocos em cada uma das 3 direções (mesmo número em todas) l1 = 3 l2 = 9 la = [3, 3, 3] lb = [9, 9, 9] # Posição aproximada de cada completação Cent_weels = all_centroids[inds_wells] # Distância, em relação ao poço, até onde se usa malha fina r0 = float(data_loaded['rs']['r0']) M1.mb.tag_set_data(M1.r0_tag, 0, r0) # Distância, em relação ao poço, até onde se usa malha intermediária
def run_2(t): print('entrou run2') tini = time.time() elems_nv0 = mb.get_entities_by_type_and_tag(0, types.MBHEX, np.array([tags_1['l3_ID']]), np.array([1])) # vertices_nv1 = rng.subtract(sol_adm.vertices, elems_nv0) vertices_nv1 = mb.get_entities_by_type_and_tag(meshset_vertices, types.MBHEX, np.array([tags_1['l3_ID']]), np.array([2])) k = 0 cont = 0 for vert in vertices_nv1: t00 = time.time() primal_id = mb.tag_get_data(tags_1['FINE_TO_PRIMAL1_CLASSIC'], vert, flat=True)[0] elems_in_meshset = mb.get_entities_by_type_and_tag( 0, types.MBHEX, np.array([tags_1['FINE_TO_PRIMAL1_CLASSIC']]), np.array([primal_id])) faces = mtu.get_bridge_adjacencies(elems_in_meshset, 3, 2) faces = rng.subtract(faces, boundary_faces) faces_boundary = rng.intersect(faces, bound_faces_nv[k]) t01 = time.time() t02 = time.time() bif_utils.calculate_pcorr(mb, elems_in_meshset, vert, faces_boundary, faces, tags_1['PCORR2'], tags_1['PMS2'], sol_adm.volumes_d, sol_adm.volumes_n, tags_1) # bif_utils.calculate_pcorr_v4(elems_in_meshset, tags_1['PCORR2'], tags_1) t03 = time.time() bif_utils.set_flux_pms_meshsets(elems_in_meshset, faces, faces_boundary, tags_1['PMS2'], tags_1['PCORR2']) t04 = time.time() dt0 = t01 - t00 dt1 = t03 - t02 dt2 = t04 - t03 dtt = t04 - t01 # print(f'tempo total {dtt}') # print(f'tempo hd {dt0}') # print(f'tempo pcorr {dt1}') # print(f'tempo fluxo_ms {dt2} \n') vertices_nv2 = mb.get_entities_by_type_and_tag(meshset_vertices_nv2, types.MBHEX, np.array([tags_1['l3_ID']]), np.array([3])) t0 = time.time() k = 1 for vert in vertices_nv2: primal_id = mb.tag_get_data(tags_1['FINE_TO_PRIMAL2_CLASSIC'], vert, flat=True)[0] elems_in_meshset = mb.get_entities_by_type_and_tag( 0, types.MBHEX, np.array([tags_1['FINE_TO_PRIMAL2_CLASSIC']]), np.array([primal_id])) faces = mtu.get_bridge_adjacencies(elems_in_meshset, 3, 2) faces = rng.subtract(faces, boundary_faces) faces_boundary = rng.intersect(faces, bound_faces_nv[k]) bif_utils.calculate_pcorr(mb, elems_in_meshset, vert, faces_boundary, faces, tags_1['PCORR2'], tags_1['PMS2'], sol_adm.volumes_d, sol_adm.volumes_n, tags_1) # bif_utils.calculate_pcorr_v4(elems_in_meshset, tags_1['PCORR2'], tags_1) bif_utils.set_flux_pms_meshsets(elems_in_meshset, faces, faces_boundary, tags_1['PMS2'], tags_1['PCORR2']) t1 = time.time() dt = t1 - t0 # print(f'tempo nv2 fluxo {dt}\n') faces = mtu.get_bridge_adjacencies(elems_nv0, 3, 2) faces = rng.subtract(faces, boundary_faces) # bif_utils.set_flux_pms_elems_nv0(elems_nv0, faces, tags_1['PMS1']) t0 = time.time() bif_utils.set_flux_pms_elems_nv0(elems_nv0, faces, tags_1['PMS2']) t1 = time.time() dt = t1 - t0 tend = time.time() dtt = tend - tini # print(f'tempo nv0 fluxo {dt}\n') bif_utils.calc_cfl(faces_in) bif_utils.verificar_cfl(all_volumes, loop) print(f'tempo total: {dtt}') print('saiu run2')
# tags_1['l3_ID'] = mb.tag_get_handle('NIVEL_ID') # tags_1['l3_ID'] = mb.tag_get_handle('l3_ID') vv = mb.create_meshset() mb.add_entities(vv, all_volumes) os.chdir(bifasico_sol_multiescala_dir) # loader = importlib.machinery.SourceFileLoader('bif_utils', utils_dir + '/bif_utils.py') # bif_utils = loader.load_module('bif_utils').bifasico(mb, mtu, all_volumes) bif_utils.k_pe_m = k_pe_m all_ids_reord = mb.tag_get_data(tags_1['ID_reord_tag'], all_volumes, flat=True) map_global = dict(zip(all_volumes, all_ids_reord)) boundary_faces = mb.tag_get_data(tags_1['FACES_BOUNDARY'], 0, flat=True)[0] boundary_faces = mb.get_entities_by_handle(boundary_faces) faces_in = rng.subtract(all_faces, boundary_faces) bif_utils.all_faces_in = faces_in bif_utils.Adjs = [mb.get_adjacencies(face, 3) for face in faces_in] name_tag_faces_boundary_meshsets = 'FACES_BOUNDARY_MESHSETS_LEVEL_' boundary_faces_nv2 = mb.get_entities_by_handle( mb.tag_get_data(mb.tag_get_handle(name_tag_faces_boundary_meshsets + str(2)), 0, flat=True)[0]) boundary_faces_nv3 = mb.get_entities_by_handle( mb.tag_get_data(mb.tag_get_handle(name_tag_faces_boundary_meshsets + str(3)), 0, flat=True)[0]) bound_faces_nv = [boundary_faces_nv2, boundary_faces_nv3] wirebasket_numbers = [sol_adm.ni, sol_adm.nf, sol_adm.na, sol_adm.nv]
def set_contraste(mesh): mesh.perm_tag = mesh.tags['PERM'] meshset_by_L2 = mesh.mb.get_child_meshsets(mesh.L2_meshset) max1 = 0 for m2 in meshset_by_L2: meshset_by_L1 = mesh.mb.get_child_meshsets(m2) for m1 in meshset_by_L1: ver_1 = mesh.mb.get_entities_by_type_and_tag( m1, types.MBHEX, np.array([D1_tag]), np.array([3])) viz_vert = mesh.mtu.get_bridge_adjacencies(ver_1, 1, 3) k_vert = mesh.mb.tag_get_data(mesh.perm_tag, ver_1)[:, 0] facs_ver1 = mesh.mtu.get_bridge_adjacencies(ver_1, 2, 2) max_r = 0 vers = [] # somak=0 for f in facs_ver1: viz_facs = mesh.mtu.get_bridge_adjacencies(f, 2, 3) ares_m = mesh.mb.create_meshset() mesh.mb.add_entities(ares_m, viz_facs) ares = mesh.mb.get_entities_by_type_and_tag( ares_m, types.MBHEX, np.array([D1_tag]), np.array([2])) if len(ares) > 0: viz_ares = mesh.mtu.get_bridge_adjacencies(ares, 2, 3) ares_m = mesh.mb.create_meshset() mesh.mb.add_entities(ares_m, viz_ares) ares_com_novas = mesh.mb.get_entities_by_type_and_tag( ares_m, types.MBHEX, np.array([D1_tag]), np.array([2])) novas_ares = rng.subtract(ares_com_novas, ares) ares = rng.unite(ares, novas_ares) for i in range(20): viz_ares = mesh.mtu.get_bridge_adjacencies( novas_ares, 2, 3) ares_m = mesh.mb.create_meshset() mesh.mb.add_entities(ares_m, viz_ares) ares_com_novas = mesh.mb.get_entities_by_type_and_tag( ares_m, types.MBHEX, np.array([D1_tag]), np.array([2])) novas_ares = rng.subtract(ares_com_novas, ares) ares = rng.unite(ares, novas_ares) if len(novas_ares) == 0: break a1 = ares gids_ares = mesh.mb.tag_get_data(mesh.tags['ID_reord_tag'], a1, flat=True) facs_ares = mesh.mtu.get_bridge_adjacencies(a1, 2, 2) # somak+= sum(mesh.mb.tag_get_data(mesh.k_eq_tag,facs_ares,flat=True))/k_vert ares = mesh.mtu.get_bridge_adjacencies(ares, 2, 3) ares_m = mesh.mb.create_meshset() mesh.mb.add_entities(ares_m, ares) verts = mesh.mb.get_entities_by_type_and_tag( ares_m, types.MBHEX, np.array([D1_tag]), np.array([3])) ares_ares = verts = mesh.mb.get_entities_by_type_and_tag( ares_m, types.MBHEX, np.array([D1_tag]), np.array([2])) v_verts = mesh.mtu.get_bridge_adjacencies(verts, 2, 3) ares_ares = rng.unite(ares_ares, verts) ares = rng.unite(ares, v_verts) k_ares_max = mesh.mb.tag_get_data(mesh.perm_tag, ares)[:, 0].max() k_ares_min = mesh.mb.tag_get_data(mesh.perm_tag, ares)[:, 0].min() # k_ares_med=sum(mesh.mb.tag_get_data(mesh.perm_tag,a1)[:,0])/len(ares) ver_2 = np.uint64(rng.subtract(verts, ver_1)) k_ver2 = mesh.mb.tag_get_data(mesh.perm_tag, ver_2)[0][0] vers.append(ver_2) perm_ares = mesh.mb.tag_get_data(mesh.perm_tag, ares)[:, 0] try: r_ver = mesh.mb.tag_get_data(ares2_tag, ver_1) r_k_are_ver = float( max((k_ares_max - k_ares_min) / min(k_vert, k_ver2), r_ver)) except: r_k_are_ver = float( (k_ares_max - k_ares_min) / min(k_vert, k_ver2)) r_k_are_ver = max(r_k_are_ver, max(k_vert, k_ver2) / perm_ares.min()) r_k_are_ver = max(r_k_are_ver, perm_ares.max() / min(k_vert, k_ver2)) if r_k_are_ver > max_r: max_r = r_k_are_ver #mesh.mb.tag_set_data(ares2_tag, ares, np.repeat(float((k_ares_max-k_ares_min)/k_vert),len(ares))) mesh.mb.tag_set_data(ares2_tag, ver_1, r_k_are_ver) perm_viz = mesh.mb.tag_get_data(mesh.tags['PERM'], viz_vert)[:, 0] # raz=float(k_vert/perm_viz.min()) # mesh.mb.tag_set_data(raz_tag, ver_1,raz) # mesh.mb.tag_set_data(var_tag, ver_1,var) # mesh.mb.tag_set_data(var2_tag, ver_1,somak) if max_r > 200: for v in vers: try: r_ver = mesh.mb.tag_get_data(ares2_tag, v) except: r_ver = 0 #mesh.mb.tag_set_data(ares2_tag, v,float(max(max_r/4,r_ver))) #k_ver2=mesh.mb.tag_get_data(mesh.perm_tag,ver_2)[:,0] #try: # r_ver=mesh.mb.tag_get_data(ares2_tag,ver_2) # r_k_are_ver=float(max((k_ares_max-k_ares_min)/k_ver2,r_ver)) #except: # r_k_are_ver=float((k_ares_max-k_ares_min)/k_ver2) #mesh.mb.tag_set_data(ares2_tag, ver_2,r_k_are_ver) del mesh.perm_tag