def calc_Vsh(self, n, sqrt_r): """Generates m.H(V[n][s]) for a given n, used for generating B[n][s] This is described on p. 14 of arXiv:1103.0936v2 [cond-mat.str-el] for left gauge fixing. Here, we are using right gauge fixing. Array slicing and reshaping is used to manipulate the indices as necessary. Each V[n] directly depends only on A[n] and r[n]. We return the conjugate m.H(V) because we use it in more places than V. """ R = sp.zeros((self.D[n], self.q[n], self.D[n-1]), dtype=self.typ, order='C') for s in xrange(self.q[n]): R[:,s,:] = m.mmul(sqrt_r, m.H(self.A[n][s])) R = R.reshape((self.q[n] * self.D[n], self.D[n-1])) V = m.H(ns.nullspace(m.H(R))) #print (q[n]*D[n] - D[n-1], q[n]*D[n]) #print V.shape #print sp.allclose(mat(V) * mat(V).H, sp.eye(q[n]*D[n] - D[n-1])) #print sp.allclose(mat(V) * mat(Rh).H, 0) V = V.reshape((self.q[n] * self.D[n] - self.D[n - 1], self.D[n], self.q[n])) #this works with the above form for R #prepare for using V[s] and already take the adjoint, since we use it more often Vsh = sp.empty((self.q[n], self.D[n], self.q[n] * self.D[n] - self.D[n - 1]), dtype=self.typ, order=self.odr) for s in xrange(self.q[n]): Vsh[s] = m.H(V[:,:,s]) return Vsh
def computeRigidity(self): """returns a k-by-n-by-2 basis of velocity vectors satisfying the constraints of this""" m = 2 * len(self.fixed) + len(self.edges) + len(self.angles) if m == 0: m = 1 # still no constraint, but want a nonempty matrix n = len(self.vertices) rigidity = numpy.zeros((m, 2 * n)) row = 0 # 2 constraints per fixed point i, # to make vx_i=0 and vy_i=0, # i.e. constrain i to have zero velocity: for i in self.fixed: rigidity[row, 2 * i] = 1 rigidity[row + 1, 2 * i + 1] = 1 row += 2 # 1 constraint per edge (i,j), # to make (p_i-p_j).v_i=(p_i-p_j).v_j, # i.e. constrain velocities of i and j # to agree along their common edge: for (i, j) in self.edges: u = self.vertices[i] v = self.vertices[j] dx = u[0] - v[0] dy = u[1] - v[1] rigidity[row, 2 * i] = dx rigidity[row, 2 * i + 1] = dy rigidity[row, 2 * j] = -dx rigidity[row, 2 * j + 1] = -dy row += 1 # 1 constraint per fixed angle: for (i, j, k) in self.angles: u = self.vertices[i] v = self.vertices[j] w = self.vertices[k] dxj = u[0] - v[0] dyj = u[1] - v[1] dxk = u[0] - w[0] dyk = u[1] - w[1] rigidity[row, 2 * i] = dxj + dxk rigidity[row, 2 * i + 1] = dyj + dyk rigidity[row, 2 * j] = -dxk rigidity[row, 2 * j + 1] = -dyk rigidity[row, 2 * k] = -dxj rigidity[row, 2 * k + 1] = -dyj row += 1 # find basis of velocities satisfying constraints: null = nullspace.nullspace(rigidity) # reshape to list of 2D vectors: velocities = [] for v in null: velocities.append(v.reshape((n, 2))) return velocities
def computeRigidity(self): """returns a k-by-n-by-2 basis of velocity vectors satisfying the constraints of this""" m = 2*len(self.fixed) + len(self.edges) + len(self.angles) if m==0: m=1 # still no constraint, but want a nonempty matrix n = len(self.vertices) rigidity = numpy.zeros((m, 2*n)) row = 0 # 2 constraints per fixed point i, # to make vx_i=0 and vy_i=0, # i.e. constrain i to have zero velocity: for i in self.fixed: rigidity[row, 2*i] = 1 rigidity[row+1, 2*i+1] = 1 row+=2 # 1 constraint per edge (i,j), # to make (p_i-p_j).v_i=(p_i-p_j).v_j, # i.e. constrain velocities of i and j # to agree along their common edge: for (i,j) in self.edges: u = self.vertices[i] v = self.vertices[j] dx = u[0]-v[0] dy = u[1]-v[1] rigidity[row, 2*i] = dx rigidity[row, 2*i+1] = dy rigidity[row, 2*j] = -dx rigidity[row, 2*j+1] = -dy row+=1 # 1 constraint per fixed angle: for (i,j,k) in self.angles: u = self.vertices[i] v = self.vertices[j] w = self.vertices[k] dxj = u[0]-v[0] dyj = u[1]-v[1] dxk = u[0]-w[0] dyk = u[1]-w[1] rigidity[row, 2*i] = dxj+dxk rigidity[row, 2*i+1] = dyj+dyk rigidity[row, 2*j] = -dxk rigidity[row, 2*j+1] = -dyk rigidity[row, 2*k] = -dxj rigidity[row, 2*k+1] = -dyj row+=1 # find basis of velocities satisfying constraints: null = nullspace.nullspace(rigidity) # reshape to list of 2D vectors: velocities = [] for v in null: velocities.append(v.reshape((n,2))) return velocities
def FindIndependentK(permutation, reference, InteractionPairs): # kList=[(random.randint(0, Nmax), random.randint(0,Nmax)) for i in range(len(InteractionPairs)+1)] N=len(InteractionPairs) Matrix=np.zeros((2*N,3*N)) for i in range(2*N): interaction=int(i/2)+2*N sign=i%2 Matrix[i,interaction]=-(-1)**sign Matrix[i, i]=-1 Matrix[i, permutation.index(i)]=1 # print Matrix vectors = nullspace(Matrix) # print len(vectors) # print vectors freedoms=vectors.shape[1] if freedoms!=N+1: print "Warning! Rank is wrong for {0} with \n{1}".format(permutation, vectors) return vectors