diff --git a/fealpy/boundarycondition/BoundaryCondition.py b/fealpy/boundarycondition/BoundaryCondition.py index 42b38235d..2e67fd3fb 100644 --- a/fealpy/boundarycondition/BoundaryCondition.py +++ b/fealpy/boundarycondition/BoundaryCondition.py @@ -30,7 +30,7 @@ def apply(self, A, F, uh=None, threshold=None): F = F.T.flat x = uh.T.flat # 把 uh 按列展平 F -= A@x - bdIdx = np.zeros(A.shape[0], dtype=np.int) + bdIdx = np.zeros(A.shape[0], dtype=np.int_) bdIdx[isDDof] = 1 Tbd = spdiags(bdIdx, 0, A.shape[0], A.shape[0]) T = spdiags(1-bdIdx, 0, A.shape[0], A.shape[0]) diff --git a/fealpy/functionspace/LagrangeFiniteElementSpace.py b/fealpy/functionspace/LagrangeFiniteElementSpace.py index b458e1bd4..84d236314 100644 --- a/fealpy/functionspace/LagrangeFiniteElementSpace.py +++ b/fealpy/functionspace/LagrangeFiniteElementSpace.py @@ -366,7 +366,7 @@ def face_basis(self, bc): TD = bc.shape[1] - 1 multiIndex = self.multi_index_matrix[TD](p) - c = np.arange(1, p+1, dtype=np.int) + c = np.arange(1, p+1, dtype=np.int_) P = 1.0/np.multiply.accumulate(c) t = np.arange(0, p) shape = bc.shape[:-1]+(p+1, TD+1) @@ -412,7 +412,7 @@ def basis(self, bc, index=np.s_[:], p=None): TD = bc.shape[-1] - 1 multiIndex = self.multi_index_matrix[TD](p) - c = np.arange(1, p+1, dtype=np.int) + c = np.arange(1, p+1, dtype=np.int_) P = 1.0/np.multiply.accumulate(c) t = np.arange(0, p) shape = bc.shape[:-1]+(p+1, TD+1) diff --git a/fealpy/functionspace/SimplexSetSpace.py b/fealpy/functionspace/SimplexSetSpace.py index 837281339..2b44380c9 100644 --- a/fealpy/functionspace/SimplexSetSpace.py +++ b/fealpy/functionspace/SimplexSetSpace.py @@ -3,7 +3,7 @@ from .femdof import multi_index_matrix2d class SimplexSetSpace(): - def __init__(self, TD, ftype=np.float, itype=np.int): + def __init__(self, TD, ftype=np.float64, itype=np.int_): self.TD = TD self.multi_index_matrix = multi_index_matrix2d self.ftype = ftype diff --git a/fealpy/functionspace/femdof.py b/fealpy/functionspace/femdof.py index cad5a9fad..130ddc259 100644 --- a/fealpy/functionspace/femdof.py +++ b/fealpy/functionspace/femdof.py @@ -8,7 +8,7 @@ def multi_index_matrix0d(p): def multi_index_matrix1d(p): ldof = p+1 - multiIndex = np.zeros((ldof, 2), dtype=np.int) + multiIndex = np.zeros((ldof, 2), dtype=np.int_) multiIndex[:, 0] = np.arange(p, -1, -1) multiIndex[:, 1] = p - multiIndex[:, 0] return multiIndex @@ -17,7 +17,7 @@ def multi_index_matrix2d(p): ldof = (p+1)*(p+2)//2 idx = np.arange(0, ldof) idx0 = np.floor((-1 + np.sqrt(1 + 8*idx))/2) - multiIndex = np.zeros((ldof, 3), dtype=np.int) + multiIndex = np.zeros((ldof, 3), dtype=np.int_) multiIndex[:,2] = idx - idx0*(idx0 + 1)/2 multiIndex[:,1] = idx0 - multiIndex[:,2] multiIndex[:,0] = p - multiIndex[:, 1] - multiIndex[:, 2] @@ -30,7 +30,7 @@ def multi_index_matrix3d(p): idx0 = np.floor(idx0 + 1/idx0/3 - 1 + 1e-4) # a+b+c idx1 = idx - idx0*(idx0 + 1)*(idx0 + 2)/6 idx2 = np.floor((-1 + np.sqrt(1 + 8*idx1))/2) # b+c - multiIndex = np.zeros((ldof, 4), dtype=np.int) + multiIndex = np.zeros((ldof, 4), dtype=np.int_) multiIndex[1:, 3] = idx1 - idx2*(idx2 + 1)/2 multiIndex[1:, 2] = idx2 - multiIndex[1:, 3] multiIndex[1:, 1] = idx0 - idx2 @@ -58,7 +58,7 @@ def boundary_dof(self, threshold=None): index = index[flag] gdof = self.number_of_global_dofs() - isBdDof = np.zeros(gdof, dtype=np.bool) + isBdDof = np.zeros(gdof, dtype=np.bool_) isBdDof[index] = True return isBdDof @@ -73,7 +73,7 @@ def is_boundary_dof(self, threshold=None): index = index[flag] gdof = self.number_of_global_dofs() - isBdDof = np.zeros(gdof, dtype=np.bool) + isBdDof = np.zeros(gdof, dtype=np.bool_) isBdDof[index] = True return isBdDof @@ -127,11 +127,11 @@ def interpolation_points(self): NN = mesh.number_of_nodes() gdof = self.number_of_global_dofs() shape = (gdof,) + node.shape[1:] - ipoint = np.zeros(shape, dtype=np.float) + ipoint = np.zeros(shape, dtype=np.float64) ipoint[:NN] = node NC = mesh.number_of_cells() cell = mesh.ds.cell - w = np.zeros((p-1,2), dtype=np.float) + w = np.zeros((p-1,2), dtype=np.float64) w[:,0] = np.arange(p-1, 0, -1)/p w[:,1] = w[-1::-1, 0] GD = mesh.geo_dimension() @@ -172,7 +172,7 @@ def boundary_dof(self, threshold=None): gdof = self.number_of_global_dofs() edge2dof = self.edge_to_dof() - isBdDof = np.zeros(gdof, dtype=np.bool) + isBdDof = np.zeros(gdof, dtype=np.bool_) isBdDof[edge2dof[index]] = True return isBdDof @@ -189,7 +189,7 @@ def is_boundary_dof(self, threshold=None): gdof = self.number_of_global_dofs() edge2dof = self.edge_to_dof() - isBdDof = np.zeros(gdof, dtype=np.bool) + isBdDof = np.zeros(gdof, dtype=np.bool_) isBdDof[edge2dof[index]] = True return isBdDof @@ -213,7 +213,7 @@ def edge_to_dof(self): NN = mesh.number_of_nodes() edge = mesh.ds.edge - edge2dof = np.zeros((NE, p+1), dtype=np.int) + edge2dof = np.zeros((NE, p+1), dtype=np.int_) edge2dof[:, [0, -1]] = edge if p > 1: edge2dof[:, 1:-1] = NN + np.arange(NE*(p-1)).reshape(NE, p-1) @@ -234,7 +234,7 @@ def cell_to_dof(self): cell2dof = cell if p > 1: - cell2dof = np.zeros((NC, ldof), dtype=np.int) + cell2dof = np.zeros((NC, ldof), dtype=np.int_) isEdgeDof = self.is_on_edge_local_dof() edge2dof = self.edge_to_dof() @@ -275,11 +275,11 @@ def interpolation_points(self): N = node.shape[0] dim = node.shape[-1] gdof = self.number_of_global_dofs() - ipoint = np.zeros((gdof, dim), dtype=np.float) + ipoint = np.zeros((gdof, dim), dtype=np.float64) ipoint[:N, :] = node NE = mesh.number_of_edges() edge = mesh.ds.edge - w = np.zeros((p-1,2), dtype=np.float) + w = np.zeros((p-1,2), dtype=np.float64) w[:,0] = np.arange(p-1, 0, -1)/p w[:,1] = w[-1::-1, 0] ipoint[N:N+(p-1)*NE, :] = np.einsum('ij, ...jm->...im', w, @@ -333,7 +333,7 @@ def is_on_edge_local_dof(self): p =self.p ldof = self.number_of_local_dofs() localEdge = self.mesh.ds.localEdge - isEdgeDof = np.zeros((ldof, 6), dtype=np.bool) + isEdgeDof = np.zeros((ldof, 6), dtype=np.bool_) for i in range(6): isEdgeDof[:, i] = (self.multiIndex[:, localEdge[-(i+1), 0]] == 0) & (self.multiIndex[:, localEdge[-(i+1), 1]] == 0 ) return isEdgeDof @@ -365,7 +365,7 @@ def edge_to_dof(self): base = N edge = mesh.ds.edge - edge2dof = np.zeros((NE, p+1), dtype=np.int) + edge2dof = np.zeros((NE, p+1), dtype=np.int_) edge2dof[:, [0, -1]] = edge if p > 1: edge2dof[:,1:-1] = base + np.arange(NE*(p-1)).reshape(NE, p-1) @@ -375,7 +375,7 @@ def face_to_dof(self): p = self.p fdof = (p+1)*(p+2)//2 - edgeIdx = np.zeros((2, p+1), dtype=np.int) + edgeIdx = np.zeros((2, p+1), dtype=np.int_) edgeIdx[0, :] = range(p+1) edgeIdx[1, :] = edgeIdx[0, -1::-1] @@ -391,13 +391,13 @@ def face_to_dof(self): edge2dof = self.edge_to_dof() - face2dof = np.zeros((NF, fdof), dtype=np.int) + face2dof = np.zeros((NF, fdof), dtype=np.int_) faceIdx = self.multiIndex2d isEdgeDof = (faceIdx == 0) fe = np.array([1, 0, 0]) for i in range(3): - I = np.ones(NF, dtype=np.int) + I = np.ones(NF, dtype=np.int_) sign = (face[:, fe[i]] == edge[face2edge[:, i], 0]) I[sign] = 0 face2dof[:, isEdgeDof[:, i]] = edge2dof[face2edge[:, [i]], edgeIdx[I]] @@ -423,7 +423,7 @@ def boundary_dof(self, threshold=None): face2dof = self.face_to_dof() gdof = self.number_of_global_dofs() - isBdDof = np.zeros(gdof, dtype=np.bool) + isBdDof = np.zeros(gdof, dtype=np.bool_) isBdDof[face2dof[index]] = True return isBdDof @@ -440,7 +440,7 @@ def is_boundary_dof(self, threshold=None): face2dof = self.face_to_dof() gdof = self.number_of_global_dofs() - isBdDof = np.zeros(gdof, dtype=np.bool) + isBdDof = np.zeros(gdof, dtype=np.bool_) isBdDof[face2dof[index]] = True return isBdDof @@ -463,7 +463,7 @@ def cell_to_dof(self): cell2face = mesh.ds.cell_to_face() - cell2dof = np.zeros((NC, ldof), dtype=np.int) + cell2dof = np.zeros((NC, ldof), dtype=np.int_) face2dof = self.face_to_dof() isFaceDof = self.is_on_face_local_dof() @@ -500,13 +500,13 @@ def cell_to_dof_1(self): NN = mesh.number_of_nodes() NC = mesh.number_of_cells() ldof = self.number_of_local_dofs() - cell2dof = np.zeros((NC, ldof), dtype=np.int) + cell2dof = np.zeros((NC, ldof), dtype=np.int_) idx = np.array([ 0, ldof - (p+1)*(p+2)//2 - 1, ldof - p -1, - ldof - 1], dtype=np.int) + ldof - 1], dtype=np.int_) cell2dof[:, idx] = cell @@ -514,7 +514,7 @@ def cell_to_dof_1(self): return cell2dof if p == 2: cell2edge = mesh.ds.cell_to_edge() - idx = np.array([1, 2, 3, 5, 6, 8], dtype=np.int) + idx = np.array([1, 2, 3, 5, 6, 8], dtype=np.int_) cel2dof[:, idx] = cell2edge + NN return cell2dof else: @@ -550,13 +550,13 @@ def cell_to_dof_2(self): NN = mesh.number_of_nodes() NC = mesh.number_of_cells() ldof = self.number_of_local_dofs() - cell2dof = np.zeros((NC, ldof), dtype=np.int) + cell2dof = np.zeros((NC, ldof), dtype=np.int_) idx = np.array([ 0, ldof - (p+1)*(p+2)//2 - 1, ldof - p -1, - ldof - 1], dtype=np.int) + ldof - 1], dtype=np.int_) cell2dof[:, idx] = cell @@ -564,7 +564,7 @@ def cell_to_dof_2(self): return cell2dof if p == 2: cell2edge = mesh.ds.cell_to_edge() - idx = np.array([1, 2, 3, 5, 6, 8], dtype=np.int) + idx = np.array([1, 2, 3, 5, 6, 8], dtype=np.int_) cel2dof[:, idx] = cell2edge + NN return cell2dof else: @@ -642,12 +642,12 @@ def interpolation_points(self): ldof = self.number_of_local_dofs() gdof = self.number_of_global_dofs() - ipoint = np.zeros((gdof, dim), dtype=np.float) + ipoint = np.zeros((gdof, dim), dtype=np.float64) ipoint[:N, :] = node if p > 1: NE = mesh.number_of_edges() edge = mesh.ds.edge - w = np.zeros((p-1,2), dtype=np.float) + w = np.zeros((p-1,2), dtype=np.float64) w[:,0] = np.arange(p-1, 0, -1)/p w[:,1] = w[-1::-1, 0] ipoint[N:N+(p-1)*NE, :] = np.einsum('ij, kj...->ki...', w, node[edge,:]).reshape(-1, dim) @@ -727,7 +727,7 @@ def __init__(self, mesh, p): def multi_index_matrix(self): p = self.p ldof = self.number_of_local_dofs() - multiIndex = np.zeros((ldof, 2), dtype=np.int) + multiIndex = np.zeros((ldof, 2), dtype=np.int_) multiIndex[:, 0] = np.arange(p, -1, -1) multiIndex[:, 1] = p - multiIndex[:, 0] return multiIndex @@ -743,11 +743,11 @@ def __init__(self, mesh, p): def multi_index_matrix(self): p = self.p if p == 0: - return np.array([[0, 0, 0]], dtype=np.int) + return np.array([[0, 0, 0]], dtype=np.int_) ldof = self.number_of_local_dofs() idx = np.arange(0, ldof) idx0 = np.floor((-1 + np.sqrt(1 + 8*idx))/2) - multiIndex = np.zeros((ldof, 3), dtype=np.int) + multiIndex = np.zeros((ldof, 3), dtype=np.int_) multiIndex[:, 2] = idx - idx0*(idx0 + 1)/2 multiIndex[:, 1] = idx0 - multiIndex[:, 2] multiIndex[:, 0] = p - multiIndex[:, 1] - multiIndex[:, 2] @@ -769,7 +769,7 @@ def multi_index_matrix(self): idx0 = np.floor(idx0 + 1/idx0/3 - 1 + 1e-4)# a+b+c idx1 = idx - idx0*(idx0 + 1)*(idx0 + 2)/6 idx2 = np.floor((-1 + np.sqrt(1 + 8*idx1))/2)# b+c - multiIndex = np.zeros((ldof, 4), dtype=np.int) + multiIndex = np.zeros((ldof, 4), dtype=np.int_) multiIndex[1:, 3] = idx1 - idx2*(idx2 + 1)/2 multiIndex[1:, 2] = idx2 - multiIndex[1:, 3] multiIndex[1:, 1] = idx0 - idx2 @@ -808,7 +808,7 @@ def local_face_to_dof(self): qdof = (p+1)*(p+1) - idx = np.r_['0', [0, 3], 2*np.ones(p-1, dtype=np.int)] + idx = np.r_['0', [0, 3], 2*np.ones(p-1, dtype=np.int_)] f0 = np.repeat(np.cumsum(np.cumsum(idx)), range(1, p+2)) - np.arange(tdof) f1 = np.arange(tdof*p, ldof) f2 = np.repeat( @@ -872,7 +872,7 @@ def boundary_dof(self, threshold=None): gdof = self.number_of_global_dofs() face2dof = self.face_to_dof() - isBdDof = np.zeros(gdof, dtype=np.bool) + isBdDof = np.zeros(gdof, dtype=np.bool_) isBdDof[np.concatenate(face2dof[index])] = True return isBdDof @@ -958,14 +958,14 @@ def cell_to_dof_2(self): NN = mesh.number_of_nodes() NC = mesh.number_of_cells() ldof = self.number_of_local_dofs() - cell2dof = np.zeros((NC, ldof), dtype=np.int) + cell2dof = np.zeros((NC, ldof), dtype=np.int_) idx = np.array([ 0, p*(p+1)//2, (p+1)*(p+2)//2-1, ldof - (p+1)*(p+2)//2, ldof - p - 1, - ldof - 1], dtype=np.int) + ldof - 1], dtype=np.int_) cell2dof[:, idx] = cell if p == 1: @@ -1043,7 +1043,7 @@ def interpolation_points_1(self): w1 = self.multi_index_matrix(1)/p w2 = self.multi_index_matrix(2)/p w3 = np.einsum('ij, km->ijkm', w1, w2) - w = np.zeros((ldof, 6), dtype=np.float) + w = np.zeros((ldof, 6), dtype=np.float64) w[:, 0:3] = w3[:, 0, :, :].reshape(-1, 3) w[:, 3:] = w3[:, 1, :, :].reshape(-1, 3) ps = np.einsum('km, imd->ikd', w, node[cell]).reshape(-1, GD) diff --git a/fealpy/mesh/Mesh2d.py b/fealpy/mesh/Mesh2d.py index c43838083..12e2313bb 100644 --- a/fealpy/mesh/Mesh2d.py +++ b/fealpy/mesh/Mesh2d.py @@ -336,10 +336,10 @@ def cell_to_edge_sign(self, return_sparse=False): edge2cell = self.edge2cell if return_sparse == False: - cell2edgeSign = np.zeros((NC, NEC), dtype=np.bool) + cell2edgeSign = np.zeros((NC, NEC), dtype=np.bool_) cell2edgeSign[edge2cell[:, 0], edge2cell[:, 2]] = True else: - val = np.ones(NE, dtype=np.bool) + val = np.ones(NE, dtype=np.bool_) cell2edgeSign = csr_matrix( (val, (edge2cell[:, 0], range(NE))), shape=(NC, NE), dtype=np.bool_) @@ -398,7 +398,7 @@ def cell_to_cell(self, return_sparse=False, return_boundary=True, return_array=F isInEdge = (edge2cell[:, 0] != edge2cell[:, 1]) cell2cell = coo_matrix( (val[isInEdge], (edge2cell[isInEdge, 0], edge2cell[isInEdge, 1])), - shape=(NC, NC), dtype=np.bool) + shape=(NC, NC), dtype=np.bool_) cell2cell += coo_matrix( (val[isInEdge], (edge2cell[isInEdge, 1], edge2cell[isInEdge, 0])), shape=(NC, NC), dtype=np.bool_) @@ -484,7 +484,7 @@ def node_to_node_in_edge(self, NN, edge): I = edge.flatten() J = edge[:, [1, 0]].flatten() val = np.ones(2*edge.shape[0], dtype=np.bool_) - node2node = csr_matrix((val, (I, J)), shape=(NN, NN), dtype=np.bool) + node2node = csr_matrix((val, (I, J)), shape=(NN, NN), dtype=np.bool_) return node2node def node_to_edge(self): @@ -536,7 +536,7 @@ def boundary_node_flag(self): NN = self.NN edge = self.edge isBdEdge = self.boundary_edge_flag() - isBdNode = np.zeros((NN,), dtype=np.bool) + isBdNode = np.zeros((NN,), dtype=np.bool_) isBdNode[edge[isBdEdge,:]] = True return isBdNode @@ -559,7 +559,7 @@ def boundary_face(self): def boundary_cell_flag(self): NC = self.NC edge2cell = self.edge2cell - isBdCell = np.zeros((NC,), dtype=np.bool) + isBdCell = np.zeros((NC,), dtype=np.bool_) isBdEdge = self.boundary_edge_flag() isBdCell[edge2cell[isBdEdge,0]] = True return isBdCell diff --git a/fealpy/mesh/Mesh3d.py b/fealpy/mesh/Mesh3d.py index e35ec137a..52d2a6d71 100644 --- a/fealpy/mesh/Mesh3d.py +++ b/fealpy/mesh/Mesh3d.py @@ -292,7 +292,7 @@ def cell_to_edge(self, return_sparse=False): else: NC = self.NC NE = self.NE - cell2edge = coo_matrix((NC, NE), dtype=np.bool) + cell2edge = coo_matrix((NC, NE), dtype=np.bool_) NEC = self.NEC cell2edge = csr_matrix( ( @@ -396,12 +396,12 @@ def face_to_node(self, return_sparse=False): NF = self.NF face2node = csr_matrix( ( - np.ones(FE*NF, dtype=np.bool), + np.ones(FE*NF, dtype=np.bool_), ( np.repeat(range(NF), FE), face.flat ) - ), shape=(NF, NN), dtype=np.bool) + ), shape=(NF, NN), dtype=np.bool_) return face2node def face_to_edge(self, return_sparse=False): @@ -440,12 +440,12 @@ def face_to_cell(self, return_sparse=False): NF = self.NF face2cell = csr_matrix( ( - np.ones(2*NF, dtype=np.bool), + np.ones(2*NF, dtype=np.bool_), ( np.repeat(range(NF), 2), self.face2cell[:, [0, 1]].flat ) - ), shape=(NF, NC), dtype=np.bool) + ), shape=(NF, NC), dtype=np.bool_) return face2cell def edge_to_node(self, return_sparse=False): @@ -458,12 +458,12 @@ def edge_to_node(self, return_sparse=False): edge = self.edge edge2node = csr_matrix( ( - np.ones(2*NE, dtype=np.bool), + np.ones(2*NE, dtype=np.bool_), ( np.repeat(range(NE), 2), edge.flat ) - ), shape=(NE, NN), dtype=np.bool) + ), shape=(NE, NN), dtype=np.bool_) return edge2node def edge_to_edge(self): @@ -513,12 +513,12 @@ def node_to_node(self): edge = self.edge node2node = csr_matrix( ( - np.ones((2*NE,), dtype=np.bool), + np.ones((2*NE,), dtype=np.bool_), ( edge.flat, edge[:, [1, 0]].flat ) - ), shape=(NN, NN), dtype=np.bool) + ), shape=(NN, NN), dtype=np.bool_) return node2node def node_to_edge(self): @@ -584,7 +584,7 @@ def boundary_node_flag(self): NN = self.NN face = self.face isBdFace = self.boundary_face_flag() - isBdPoint = np.zeros((NN,), dtype=np.bool) + isBdPoint = np.zeros((NN,), dtype=np.bool_) isBdPoint[face[isBdFace, :]] = True return isBdPoint @@ -592,7 +592,7 @@ def boundary_edge_flag(self): NE = self.NE face2edge = self.face_to_edge() isBdFace = self.boundary_face_flag() - isBdEdge = np.zeros((NE,), dtype=np.bool) + isBdEdge = np.zeros((NE,), dtype=np.bool_) isBdEdge[face2edge[isBdFace, :]] = True return isBdEdge @@ -604,7 +604,7 @@ def boundary_cell_flag(self): NC = self.NC face2cell = self.face_to_cell() isBdFace = self.boundary_face_flag() - isBdCell = np.zeros((NC,), dtype=np.bool) + isBdCell = np.zeros((NC,), dtype=np.bool_) isBdCell[face2cell[isBdFace, 0]] = True return isBdCell diff --git a/fealpy/mesh/Octree.py b/fealpy/mesh/Octree.py index 7f0e146dc..a3e0f8789 100644 --- a/fealpy/mesh/Octree.py +++ b/fealpy/mesh/Octree.py @@ -9,18 +9,19 @@ class Octree(HexahedronMesh): localFace2childCell = np.array([ (0, 2), (4, 6), (0, 7), (1, 6), - (0, 5), (2, 7)], dtype=np.int) + (0, 5), (2, 7)], dtype=np.int_) localEdge2childCell = np.array([ (0, 1), (1, 2), (2, 3), (3, 0), (4, 0), (5, 1), (6, 2), (7, 3), - (4, 5), (5, 6), (6, 7), (7, 4)], dtype=np.int) + (4, 5), (5, 6), (6, 7), (7, 4)], dtype=np.int_) - def __init__(self, node, cell, dtype=np.float): - super(Octree, self).__init__(node, cell, dtype=dtype) - self.dtype = dtype + def __init__(self, node, cell, itype=np.int_, ftype=np.float64): + super(Octree, self).__init__(node, cell, ftype=ftype) + self.itype = itype + self.ftype = ftype NC = self.number_of_cells() - self.parent = -np.ones((NC, 2), dtype=np.int) - self.child = -np.ones((NC, 8), dtype=np.int) + self.parent = -np.ones((NC, 2), dtype=itype) + self.child = -np.ones((NC, 8), dtype=itype) def leaf_cell_index(self): child = self.child @@ -84,11 +85,11 @@ def refine(self, marker=None): isNeedCutEdge = ~isCuttedEdge & isCutEdge - edge2center = np.zeros(NE, dtype=np.int) + edge2center = np.zeros(NE, dtype=self.itype) I, J = np.nonzero(isCuttedEdge[cell2edge]) - cellIdx = np.zeros(NE, dtype=np.int) - localIdx = np.zeros(NE, dtype=np.int) + cellIdx = np.zeros(NE, dtype=self.itype) + localIdx = np.zeros(NE, dtype=self.itype) I1 = I[~isLeafCell[I]] J1 = J[~isLeafCell[I]] cellIdx[cell2edge[I1, J1]] = I1 @@ -116,11 +117,11 @@ def refine(self, marker=None): isNeedCutFace = ~isCuttedFace & isCutFace - face2center = np.zeros(NF, dtype=np.int) + face2center = np.zeros(NF, dtype=self.itype) I, J = np.nonzero(isCuttedFace[cell2face]) - cellIdx = np.zeros(NF, dtype=np.int) - localIdx = np.zeros(NF, dtype=np.int) + cellIdx = np.zeros(NF, dtype=self.itype) + localIdx = np.zeros(NF, dtype=self.itype) I1 = I[~isLeafCell[I]] J1 = J[~isLeafCell[I]] cellIdx[cell2face[I1, J1]] = I1 @@ -149,12 +150,12 @@ def refine(self, marker=None): cc = np.arange(N+NEC+NFC, N+NEC+NFC+NCC).reshape(-1, 1) - newParent = np.zeros((8*NCC, 2), dtype=np.int) + newParent = np.zeros((8*NCC, 2), dtype=self.itype) newParent[:, 0] = np.repeat(idx, 8) - newParent[:, 1] = ranges(8*np.ones(NCC, dtype=np.int)) - newChild = -np.ones((8*NCC, 8), dtype=np.int) + newParent[:, 1] = ranges(8*np.ones(NCC, dtype=self.itype)) + newChild = -np.ones((8*NCC, 8), dtype=self.itype) - newCell = np.zeros((8*NCC, 8), dtype=np.int) + newCell = np.zeros((8*NCC, 8), dtype=self.itype) newCell[0::8, :] = np.concatenate( (cp[0], ep[0], fp[0], ep[3], ep[4], fp[4], cc, fp[2]), axis=1) newCell[1::8, :] = np.concatenate( @@ -226,7 +227,7 @@ def coarsen(self, marker): isNewLeafCell = np.sum(isRemainCell[child[childIdx, :]], axis=1) == 0 child[childIdx[isNewLeafCell], :] = -1 - cellIdxMap = np.zeros(NC, dtype=np.int) + cellIdxMap = np.zeros(NC, dtype=self.itype) NNC = isRemainCell.sum() cellIdxMap[isRemainCell] = np.arange(NNC) child[child > -1] = cellIdxMap[child[child > -1]] @@ -234,7 +235,7 @@ def coarsen(self, marker): self.child = child self.parent = parent - nodeIdxMap = np.zeros(N, dtype=np.int) + nodeIdxMap = np.zeros(N, dtype=self.itype) NN = isRemainNode.sum() nodeIdxMap[isRemainNode] = np.arange(NN) cell = nodeIdxMap[cell] @@ -326,7 +327,7 @@ def to_pmesh(self): NC = self.number_of_cells() PNC = isLeafCell.sum() - cellIdxMap = np.zeros(NC, dtype=np.int) + cellIdxMap = np.zeros(NC, dtype=self.itype) cellIdxMap[isLeafCell] = np.arange(PNC) pface2cell[:, 0:2] = cellIdxMap[pface2cell[:, 0:2]] @@ -339,7 +340,7 @@ def to_pmesh(self): pface2edge = face2edge[isLeafFace] isLeafEdge[pface2edge] = True pedge = edge[isLeafEdge] - idxMap = -np.ones(NE, dtype=np.int) + idxMap = -np.ones(NE, dtype=self.itype) idxMap[isLeafEdge] = range(np.sum(isLeafEdge)) pface2edge = idxMap[pface2edge] @@ -351,7 +352,7 @@ def to_pmesh(self): val[:, 1] = 2 p2e = csr_matrix((val.flatten(), (I, J)), shape=(N, NE), dtype=np.int8) - NV = np.zeros(PNF, dtype=np.int) + NV = np.zeros(PNF, dtype=self.itype) node = self.node mp = (node[pedge[:, 0]] + node[pedge[:, 1]])/2 l2 = np.sqrt(np.sum((node[pedge[:, 0]] - node[pedge[:, 1]])**2, axis=1)) @@ -403,9 +404,9 @@ def to_pmesh(self): fp = pedge[pe, lidx%2] NV[fidx] += 1 - pfaceLocation = np.zeros(PNF+1, dtype=np.int) + pfaceLocation = np.zeros(PNF+1, dtype=self.itype) pfaceLocation[1:] = np.cumsum(NV) - pface0 = np.zeros(pfaceLocation[-1], dtype=np.int) + pface0 = np.zeros(pfaceLocation[-1], dtype=self.itype) currentLocation = pfaceLocation[:-1].copy() for i in range(4): print("Current ", i) diff --git a/fealpy/mesh/PolygonMesh.py b/fealpy/mesh/PolygonMesh.py index f757d02c2..fb86588e8 100644 --- a/fealpy/mesh/PolygonMesh.py +++ b/fealpy/mesh/PolygonMesh.py @@ -43,7 +43,7 @@ def to_vtk(self): cell = self.ds.cell cellLocation = self.ds.cellLocation NV = self.ds.number_of_vertices_of_cells() - cells = np.zeros(len(cell) + NC, dtype=np.int) + cells = np.zeros(len(cell) + NC, dtype=self.itype) isIdx = np.ones(len(cell) + NC, dtype=np.bool) isIdx[0] = False isIdx[np.add.accumulate(NV+1)[:-1]] = False @@ -108,8 +108,8 @@ def angle(self): cell = self.ds.cell cellLocation = self.ds.cellLocation - idx1 = np.zeros(cell.shape[0], dtype=np.int) - idx2 = np.zeros(cell.shape[0], dtype=np.int) + idx1 = np.zeros(cell.shape[0], dtype=np.int_) + idx2 = np.zeros(cell.shape[0], dtype=np.int_) idx1[0:-1] = cell[1:] idx1[cellLocation[1:]-1] = cell[cellLocation[:-1]] diff --git a/fealpy/mesh/PolyhedronMesh.py b/fealpy/mesh/PolyhedronMesh.py index 572baee4f..434be1bdb 100644 --- a/fealpy/mesh/PolyhedronMesh.py +++ b/fealpy/mesh/PolyhedronMesh.py @@ -5,11 +5,14 @@ class PolyhedronMesh(): - def __init__(self, node, face, faceLocation, face2cell, NC=None, dtype=np.float): + def __init__(self, node, face, faceLocation, face2cell, NC=None, + itype=np.int_, + ftype=np.float64): self.node = node self.ds = PolyhedronMeshDataStructure(node.shape[0], face, faceLocation, face2cell, NC=NC) self.meshtype = 'polyhedron' - self.dtype= dtype + self.itype = itype + self.ftype = ftype def to_vtk(self): NF = self.number_of_faces() @@ -18,7 +21,7 @@ def to_vtk(self): faceLocation = self.ds.faceLocation NV = self.ds.number_of_vertices_of_faces() - faces = np.zeros(len(face) + NF, dtype=np.int) + faces = np.zeros(len(face) + NF, dtype=self.itype) isIdx = np.ones(len(face) + NF, dtype=np.bool) isIdx[0] = False isIdx[np.add.accumulate(NV+1)[:-1]] = False @@ -35,9 +38,9 @@ def check(self): isIntFace = (face2cell[:, 0] != face2cell[:, 1]) cell2node = self.ds.cell_to_node() - V = cell2node@np.ones(N, dtype=np.int) - E = np.zeros(NC, dtype=np.int) - F = np.zeros(NC, dtype=np.int) + V = cell2node@np.ones(N, dtype=self.itype) + E = np.zeros(NC, dtype=self.itype) + F = np.zeros(NC, dtype=self.itype) np.add.at(E, face2cell[:, 0], NFE) np.add.at(E, face2cell[isIntFace, 1], NFE[isIntFace]) @@ -70,8 +73,8 @@ def face_angle(self): face = self.ds.face faceLocation = self.ds.faceLocation - idx1 = np.zeros(face.shape[0], dtype=np.int) - idx2 = np.zeros(face.shape[0], dtype=np.int) + idx1 = np.zeros(face.shape[0], dtype=self.itype) + idx2 = np.zeros(face.shape[0], dtype=self.itype) idx1[0:-1] = face[1:] idx1[faceLocation[1:]-1] = face[faceLocation[:-1]] @@ -140,7 +143,7 @@ def total_edge(self): face = self.face faceLocation = self.faceLocation - totalEdge = np.zeros((len(face), 2), dtype=np.int) + totalEdge = np.zeros((len(face), 2), dtype=self.itype) totalEdge[:, 0] = face totalEdge[:-1, 1] = face[1:] totalEdge[faceLocation[1:] - 1, 1] = face[faceLocation[:-1]] diff --git a/fealpy/mesh/QuadrangleMesh.py b/fealpy/mesh/QuadrangleMesh.py index b3f9606a1..a0ebc714b 100644 --- a/fealpy/mesh/QuadrangleMesh.py +++ b/fealpy/mesh/QuadrangleMesh.py @@ -94,7 +94,7 @@ def uniform_refine(self, n=1): ep = [edge2center[cell2edge[:, i]].reshape(-1, 1) for i in range(4)] cc = np.arange(N + NE, N + NE + NC).reshape(-1, 1) - cell = np.zeros((4*NC, 4), dtype=np.int) + cell = np.zeros((4*NC, 4), dtype=np.int_) cell[0::4, :] = np.r_['1', cp[0], ep[0], cc, ep[3]] cell[1::4, :] = np.r_['1', ep[0], cp[1], ep[1], cc] cell[2::4, :] = np.r_['1', cc, ep[1], cp[2], ep[2]] @@ -109,12 +109,12 @@ def refine_RB(self, markedCell): hashR = np.array([ [1, 1, 1, 1], [1, 1, 0, 0], - [0, 0, 1, 1]], dtype=np.int) + [0, 0, 1, 1]], dtype=np.int_) mR, vR = hash2map(np.arange(16), hashR) print(mR, vR) cell2edge = self.ds.cell_to_edge() NE = self.number_of_edges() - edge2flag = np.zeros(NE, dtype=np.bool) + edge2flag = np.zeros(NE, dtype=np.bool_) edge2flag[cell2edge[markedCell]] = True print(edge2flag) print(edge2flag[cell2edge]) diff --git a/fealpy/mesh/Quadtree.py b/fealpy/mesh/Quadtree.py index a21b0b86b..e014a4234 100644 --- a/fealpy/mesh/Quadtree.py +++ b/fealpy/mesh/Quadtree.py @@ -8,7 +8,7 @@ class Quadtree(QuadrangleMesh): localEdge2childCell = np.array([ - (0, 1), (1, 2), (2, 3), (3, 0)], dtype=np.int) + (0, 1), (1, 2), (2, 3), (3, 0)], dtype=np.int_) def __init__(self, node, cell): super(Quadtree, self).__init__(node, cell) @@ -77,7 +77,7 @@ def uniform_refine(self, n=1): def adaptive(self, eta, options): if options['HB'] is True: - HB = np.zeros((len(eta), 2), dtype=np.int) + HB = np.zeros((len(eta), 2), dtype=np.int_) HB[:, 0] = np.arange(len(eta)) HB[:, 1] = np.arange(len(eta)) options['HB'] = HB @@ -219,7 +219,7 @@ def refine_1(self, isMarkedCell=None, options={'disp': True}): NHB0 = flag0.sum() NHB1 = flag1.sum() NHB = NHB0 + 4*NHB1 - HB = np.zeros((NHB, 2), dtype=np.int) + HB = np.zeros((NHB, 2), dtype=np.int_) HB[:, 0] = range(NHB) HB[0:NHB0, 1] = options['HB'][flag0, 1] HB[NHB0:, 1] = np.repeat(options['HB'][flag1, 1], 4) diff --git a/fealpy/mesh/StructureQuadMesh.py b/fealpy/mesh/StructureQuadMesh.py index 9a937be77..10bb18a76 100644 --- a/fealpy/mesh/StructureQuadMesh.py +++ b/fealpy/mesh/StructureQuadMesh.py @@ -5,7 +5,7 @@ from .Mesh2d import Mesh2d class StructureQuadMesh(Mesh2d): - def __init__(self, box, nx, ny, itype=np.int32, ftype=np.float): + def __init__(self, box, nx, ny, itype=np.int_, ftype=np.float64): self.box = box self.ds = StructureQuadMeshDataStructure(nx, ny, itype) self.meshtype="quad" @@ -104,13 +104,13 @@ def laplace_operator(self): hx = 1/(self.hx**2) hy = 1/(self.hy**2) - d0 = (2*hy)*np.ones(n0, dtype=np.float) - d1 = -hy*np.ones(n0-1, dtype=np.float) + d0 = (2*hy)*np.ones(n0, dtype=self.ftype) + d1 = -hy*np.ones(n0-1, dtype=self.ftype) T0 = diags([d0, d1, d1], [0, -1, 1]) I0 = eye(n0) - d0 = (2*hx)*np.ones(n1, dtype=np.float) - d1 = -hx*np.ones(n1-1, dtype=np.float) + d0 = (2*hx)*np.ones(n1, dtype=self.ftype) + d1 = -hx*np.ones(n1-1, dtype=self.ftype) T1 = diags([d0, d1, d1], [0, -1, 1]) I1 = eye(n1) diff --git a/fealpy/mesh/core.py b/fealpy/mesh/core.py index 0e330a4bc..ddabf2f38 100644 --- a/fealpy/mesh/core.py +++ b/fealpy/mesh/core.py @@ -106,7 +106,7 @@ def multi_index_matrix0d(p): def multi_index_matrix1d(p): ldof = p+1 - multiIndex = np.zeros((ldof, 2), dtype=np.int) + multiIndex = np.zeros((ldof, 2), dtype=np.int_) multiIndex[:, 0] = np.arange(p, -1, -1) multiIndex[:, 1] = p - multiIndex[:, 0] return multiIndex @@ -115,7 +115,7 @@ def multi_index_matrix2d(p): ldof = (p+1)*(p+2)//2 idx = np.arange(0, ldof) idx0 = np.floor((-1 + np.sqrt(1 + 8*idx))/2) - multiIndex = np.zeros((ldof, 3), dtype=np.int) + multiIndex = np.zeros((ldof, 3), dtype=np.int_) multiIndex[:,2] = idx - idx0*(idx0 + 1)/2 multiIndex[:,1] = idx0 - multiIndex[:,2] multiIndex[:,0] = p - multiIndex[:, 1] - multiIndex[:, 2] @@ -128,7 +128,7 @@ def multi_index_matrix3d(p): idx0 = np.floor(idx0 + 1/idx0/3 - 1 + 1e-4) # a+b+c idx1 = idx - idx0*(idx0 + 1)*(idx0 + 2)/6 idx2 = np.floor((-1 + np.sqrt(1 + 8*idx1))/2) # b+c - multiIndex = np.zeros((ldof, 4), dtype=np.int) + multiIndex = np.zeros((ldof, 4), dtype=np.int_) multiIndex[1:, 3] = idx1 - idx2*(idx2 + 1)/2 multiIndex[1:, 2] = idx2 - multiIndex[1:, 3] multiIndex[1:, 1] = idx0 - idx2 @@ -154,7 +154,7 @@ def lagrange_shape_function(bc, p, n=0): multiIndex = multi_index_matrix[TD](p) ldof = multiIndex.shape[0] # p 次 Lagrange 形函数的个数 - c = np.arange(1, p+1, dtype=np.int) + c = np.arange(1, p+1, dtype=np.int_) P = 1.0/np.multiply.accumulate(c) t = np.arange(0, p) shape = bc.shape[:-1]+(p+1, TD+1) # (NQ, p+1, TD+1) diff --git a/fealpy/mesh/simple_mesh_generator.py b/fealpy/mesh/simple_mesh_generator.py index 17d4e6c85..87f251e27 100644 --- a/fealpy/mesh/simple_mesh_generator.py +++ b/fealpy/mesh/simple_mesh_generator.py @@ -81,9 +81,9 @@ def tri_to_polygonmesh(mesh, n): -def squaremesh(x0, x1, y0, y1, r=3, dtype=np.float): - node = np.array([[x0, y0], [x1, y0], [x1, y1], [x0, y1]], dtype=dtype) - cell = np.array([[1, 2, 0], [3, 0, 2]], dtype=np.int) +def squaremesh(x0, x1, y0, y1, r=3, ftype=np.float64): + node = np.array([[x0, y0], [x1, y0], [x1, y1], [x0, y1]], dtype=ftype) + cell = np.array([[1, 2, 0], [3, 0, 2]], dtype=np.int_) mesh = TriangleMesh(node, cell) mesh.uniform_refine(r) return mesh @@ -163,7 +163,7 @@ def distmesh2d(fd, h0, bbox, pfix, meshtype='tri'): pnode, pcell, pcellLocation = mesh.to_polygonmesh() return PolygonMesh(pnode, pcell, pcellLocation) -def unitcircledomainmesh(h0, meshtype='tri', dtype=np.float): +def unitcircledomainmesh(h0, meshtype='tri', ftype=np.float64): fd = lambda p: dcircle(p, (0,0), 1) fh = huniform bbox = [-1.2, 1.2, -1.2, 1.2] diff --git a/fealpy/pde/poisson_2d.py b/fealpy/pde/poisson_2d.py index dcc01aec5..b6a30b317 100644 --- a/fealpy/pde/poisson_2d.py +++ b/fealpy/pde/poisson_2d.py @@ -13,8 +13,8 @@ class CosCosData: """ - -\Delta u = f - u = cos(pi*x)*cos(pi*y) + -\\Delta u = f + u = cos(pi*x)*cos(pi*y) """ def __init__(self): pass @@ -166,7 +166,7 @@ def is_robin_boundary(self, p): class X2Y2Data: """ - -\Delta u = f + -\\Delta u = f u = cos(pi*x)*cos(pi*y) """ def __init__(self):