def Pxx(xEdge, yEdge): # no | node | e1 | e2 # 00 | i ,j | i ,j | i ,j # 10 | i+1,j | i ,j | i+1,j # 01 | i ,j+1 | i ,j+1 | i ,j # 11 | i+1,j+1 | i ,j+1 | i+1,j posX = 0 if xEdge == 'eX0' else 1 posY = 0 if yEdge == 'eY0' else 1 ind1 = sub2ind(M.vnEx, np.c_[ii, jj + posX]) ind2 = sub2ind(M.vnEy, np.c_[ii + posY, jj]) + M.nEx IND = np.r_[ind1, ind2].flatten() PXX = sp.coo_matrix((np.ones(2 * M.nC), (range(2 * M.nC), IND)), shape=(2 * M.nC, M.nE)).tocsr() if M._meshType == 'Curv': I2x2 = inv2X2BlockDiagonal(getSubArray(eT1[0], [i, j + posX]), getSubArray(eT1[1], [i, j + posX]), getSubArray(eT2[0], [i + posY, j]), getSubArray(eT2[1], [i + posY, j])) PXX = I2x2 * PXX return PXX
def Pxx(xFace, yFace): """ xFace is 'fXp' or 'fXm' yFace is 'fYp' or 'fYm' """ # no | node | f1 | f2 # 00 | i ,j | i , j | i, j # 10 | i+1,j | i+1, j | i, j # 01 | i ,j+1 | i , j | i, j+1 # 11 | i+1,j+1 | i+1, j | i, j+1 posFx = 0 if xFace == 'fXm' else 1 posFy = 0 if yFace == 'fYm' else 1 ind1 = sub2ind(M.vnFx, np.c_[ii + posFx, jj]) ind2 = sub2ind(M.vnFy, np.c_[ii, jj + posFy]) + M.nFx IND = np.r_[ind1, ind2].flatten() PXX = sp.csr_matrix((np.ones(2 * M.nC), (range(2 * M.nC), IND)), shape=(2 * M.nC, M.nF)) if M._meshType == 'Curv': I2x2 = inv2X2BlockDiagonal(getSubArray(fN1[0], [i + posFx, j]), getSubArray(fN1[1], [i + posFx, j]), getSubArray(fN2[0], [i, j + posFy]), getSubArray(fN2[1], [i, j + posFy])) PXX = I2x2 * PXX return PXX
def Pxxx(xEdge, yEdge, zEdge): # no | node | e1 | e2 | e3 # 000 | i ,j ,k | i ,j ,k | i ,j ,k | i ,j ,k # 100 | i+1,j ,k | i ,j ,k | i+1,j ,k | i+1,j ,k # 010 | i ,j+1,k | i ,j+1,k | i ,j ,k | i ,j+1,k # 110 | i+1,j+1,k | i ,j+1,k | i+1,j ,k | i+1,j+1,k # 001 | i ,j ,k+1 | i ,j ,k+1 | i ,j ,k+1 | i ,j ,k # 101 | i+1,j ,k+1 | i ,j ,k+1 | i+1,j ,k+1 | i+1,j ,k # 011 | i ,j+1,k+1 | i ,j+1,k+1 | i ,j ,k+1 | i ,j+1,k # 111 | i+1,j+1,k+1 | i ,j+1,k+1 | i+1,j ,k+1 | i+1,j+1,k posX = [0, 0] if xEdge == 'eX0' else [ 1, 0 ] if xEdge == 'eX1' else [0, 1] if xEdge == 'eX2' else [1, 1] posY = [0, 0] if yEdge == 'eY0' else [ 1, 0 ] if yEdge == 'eY1' else [0, 1] if yEdge == 'eY2' else [1, 1] posZ = [0, 0] if zEdge == 'eZ0' else [ 1, 0 ] if zEdge == 'eZ1' else [0, 1] if zEdge == 'eZ2' else [1, 1] ind1 = sub2ind(M.vnEx, np.c_[ii, jj + posX[0], kk + posX[1]]) ind2 = sub2ind(M.vnEy, np.c_[ii + posY[0], jj, kk + posY[1]]) + M.nEx ind3 = sub2ind(M.vnEz, np.c_[ii + posZ[0], jj + posZ[1], kk]) + M.nEx + M.nEy IND = np.r_[ind1, ind2, ind3].flatten() PXXX = sp.coo_matrix((np.ones(3 * M.nC), (range(3 * M.nC), IND)), shape=(3 * M.nC, M.nE)).tocsr() if M._meshType == 'Curv': I3x3 = inv3X3BlockDiagonal( getSubArray(eT1[0], [i, j + posX[0], k + posX[1]]), getSubArray(eT1[1], [i, j + posX[0], k + posX[1]]), getSubArray(eT1[2], [i, j + posX[0], k + posX[1]]), getSubArray(eT2[0], [i + posY[0], j, k + posY[1]]), getSubArray(eT2[1], [i + posY[0], j, k + posY[1]]), getSubArray(eT2[2], [i + posY[0], j, k + posY[1]]), getSubArray(eT3[0], [i + posZ[0], j + posZ[1], k]), getSubArray(eT3[1], [i + posZ[0], j + posZ[1], k]), getSubArray(eT3[2], [i + posZ[0], j + posZ[1], k])) PXXX = I3x3 * PXXX return PXXX
def Pxxx(xFace, yFace, zFace): """ xFace is 'fXp' or 'fXm' yFace is 'fYp' or 'fYm' zFace is 'fZp' or 'fZm' """ # no | node | f1 | f2 | f3 # 000 | i ,j ,k | i , j, k | i, j , k | i, j, k # 100 | i+1,j ,k | i+1, j, k | i, j , k | i, j, k # 010 | i ,j+1,k | i , j, k | i, j+1, k | i, j, k # 110 | i+1,j+1,k | i+1, j, k | i, j+1, k | i, j, k # 001 | i ,j ,k+1 | i , j, k | i, j , k | i, j, k+1 # 101 | i+1,j ,k+1 | i+1, j, k | i, j , k | i, j, k+1 # 011 | i ,j+1,k+1 | i , j, k | i, j+1, k | i, j, k+1 # 111 | i+1,j+1,k+1 | i+1, j, k | i, j+1, k | i, j, k+1 posX = 0 if xFace == 'fXm' else 1 posY = 0 if yFace == 'fYm' else 1 posZ = 0 if zFace == 'fZm' else 1 ind1 = sub2ind(M.vnFx, np.c_[ii + posX, jj, kk]) ind2 = sub2ind(M.vnFy, np.c_[ii, jj + posY, kk]) + M.nFx ind3 = sub2ind(M.vnFz, np.c_[ii, jj, kk + posZ]) + M.nFx + M.nFy IND = np.r_[ind1, ind2, ind3].flatten() PXXX = sp.coo_matrix((np.ones(3 * M.nC), (range(3 * M.nC), IND)), shape=(3 * M.nC, M.nF)).tocsr() if M._meshType == 'Curv': I3x3 = inv3X3BlockDiagonal( getSubArray(fN1[0], [i + posX, j, k]), getSubArray(fN1[1], [i + posX, j, k]), getSubArray(fN1[2], [i + posX, j, k]), getSubArray(fN2[0], [i, j + posY, k]), getSubArray(fN2[1], [i, j + posY, k]), getSubArray(fN2[2], [i, j + posY, k]), getSubArray(fN3[0], [i, j, k + posZ]), getSubArray(fN3[1], [i, j, k + posZ]), getSubArray(fN3[2], [i, j, k + posZ])) PXXX = I3x3 * PXXX return PXXX
def NMOstack(data, xorig, time, v): if np.isscalar(v): v = np.ones_like(time) * v Time = (time.reshape([1, -1])).repeat(data.shape[0], axis=0) singletrace = np.zeros(data.shape[1]) for i in range(time.size): toffset = np.sqrt(xorig**2 / v[i]**2 + time[i]**2) Time = (time.reshape([1, -1])).repeat(data.shape[0], axis=0) Toffset = (toffset.reshape([-1, 1])).repeat(data.shape[1], axis=1) indmin = np.argmin(abs(Time - Toffset), axis=1) singletrace[i] = (mkvc(data)[sub2ind( data.shape, np.c_[np.arange(data.shape[0]), indmin])]).sum() return singletrace
def test_sub2ind(self): x = np.ones((5,2)) self.assertTrue(np.all(sub2ind(x.shape, [0,0]) == [0])) self.assertTrue(np.all(sub2ind(x.shape, [4,0]) == [4])) self.assertTrue(np.all(sub2ind(x.shape, [0,1]) == [5])) self.assertTrue(np.all(sub2ind(x.shape, [4,1]) == [9])) self.assertTrue(np.all(sub2ind(x.shape, [[4,1]]) == [9])) self.assertTrue(np.all(sub2ind(x.shape, [[0,0],[4,0],[0,1],[4,1]]) == [0,4,5,9]))
def test_sub2ind(self): x = np.ones((5, 2)) self.assertTrue(np.all(sub2ind(x.shape, [0, 0]) == [0])) self.assertTrue(np.all(sub2ind(x.shape, [4, 0]) == [4])) self.assertTrue(np.all(sub2ind(x.shape, [0, 1]) == [5])) self.assertTrue(np.all(sub2ind(x.shape, [4, 1]) == [9])) self.assertTrue(np.all(sub2ind(x.shape, [[4, 1]]) == [9])) self.assertTrue( np.all( sub2ind(x.shape, [[0, 0], [4, 0], [0, 1], [4, 1]]) == [0, 4, 5, 9]))