def FastForce(X, Y, Xss, Yss, LinkIndices, LinkData, LinkCurL, TetherIndex, TetherData): Nb = len(X) tx = X[LinkIndices[:, 1]] - X[LinkIndices[:, 0]] ty = Y[LinkIndices[:, 1]] - Y[LinkIndices[:, 0]] LinkCurL[:] = (tx**2 + ty**2)**.5 txl = tx / LinkCurL tyl = ty / LinkCurL for i in range(Nb): if LinkCurL[i] == 0: txl[i] = tyl[i] = 0. Xss[:], Yss[:] = 0. * Xss, 0. * Yss calc = LinkData[:, 0] * (tx - LinkData[:, 1] * txl) IB_c.CollapseSum(Xss, LinkIndices[:, 0], calc) IB_c.CollapseSum(Xss, LinkIndices[:, 1], -calc) calc = LinkData[:, 0] * (ty - LinkData[:, 1] * tyl) IB_c.CollapseSum(Yss, LinkIndices[:, 0], calc) IB_c.CollapseSum(Yss, LinkIndices[:, 1], -calc) Xss[TetherIndex] += TetherData[:, 0] * (TetherData[:, 1] - X[TetherIndex]) Yss[TetherIndex] += TetherData[:, 0] * (TetherData[:, 2] - Y[TetherIndex])
def FastJacobian2(z, D, args, LinkIndices, LinkData, LinkCurL, TetherIndex, TetherData): tx = z[LinkIndices[:, 1]] - z[LinkIndices[:, 0]] ty = z[LinkIndices[:, 1] + Nb] - z[LinkIndices[:, 0] + Nb] l3 = LinkCurL**3 l1 = 1. / LinkCurL dxdx = (-1. + LinkData[:, 1] * (l1 - tx**2 / l3)) dydy = (-1. + LinkData[:, 1] * (l1 - ty**2 / l3)) dxdy = -LinkData[:, 1] * tx * ty / l3 for i in range(Nb): if LinkCurL[i] == 0: dxdx[i] = -1. dydy[i] = -1. dxdy[i] = 0. print i, LinkCurL[i], dxdx[i], dxdy[i], dydy[i] data = 0. * D.data n = len(dxdx) data[:n] -= dxdx data[n:2 * n] -= dxdx data[2 * n:3 * n] -= dydy data[3 * n:4 * n] -= dydy data[4 * n:5 * n] -= dxdy data[5 * n:6 * n] -= dxdy data[6 * n:7 * n] -= dxdy data[7 * n:8 * n] -= dxdy Diag = zeros(Nb, float64) IB_c.CollapseSum(Diag, LinkIndices[:, 0], dxdx) IB_c.CollapseSum(Diag, LinkIndices[:, 1], dxdx) Diag[TetherIndex] -= 1. #TetherData[:,0] data[8 * n:8 * n + Nb] = 1. * Diag Diag = zeros(Nb, float64) IB_c.CollapseSum(Diag, LinkIndices[:, 0], dydy) IB_c.CollapseSum(Diag, LinkIndices[:, 1], dydy) Diag[TetherIndex] -= 1. #TetherData[:,0] data[8 * n + Nb:8 * n + 2 * Nb] = 1. * Diag Diag = zeros(Nb, float64) IB_c.CollapseSum(Diag, LinkIndices[:, 0], dxdy) IB_c.CollapseSum(Diag, LinkIndices[:, 1], dxdy) data[8 * n + 2 * Nb:8 * n + 3 * Nb] = 1. * Diag Diag = zeros(Nb, float64) IB_c.CollapseSum(Diag, LinkIndices[:, 1], dxdy) IB_c.CollapseSum(Diag, LinkIndices[:, 0], dxdy) data[8 * n + 3 * Nb:8 * n + 4 * Nb] = 1. * Diag D.data[args] = data