def allComponents(self, N): result = 0 # First term for K in range(N - 1, self.collapse + 1): Cd = self.diff(self.Cs[0], order=K) Md = spatial_diff(self.M, order=K - N + 1) tmp = np.tensordot(Cd, Md, axes=(tuple(range(1, K - N + 2)) + (0, ), tuple(range(0, K - N + 2)))) tmp = symmetrize(tmp, list(range(len(tmp.shape)))) result = result + 2 * binomial(K, N - 1) * tmp # Second summand for K in range(N, self.collapse + 1): for J in range(N + 1, K + 2): Cd = self.diff(self.Cs[0], order=K) Md = spatial_diff(self.M, order=K - J + 1) tmp = np.tensordot(Cd, Md, axes=(tuple(range(1, K - J + 2)) + (0, ), tuple(range(0, K - J + 2)))) tmp = symmetrize(tmp, list(range(len(tmp.shape)))) tmp = spatial_diff(tmp, order=J - N) for i in range(J - N + 1): tmp = tmp.trace(0, len(tmp.shape) - 1) result = result + (-1)**J * binomial(K, J - 1) * binomial( J, N) * tmp return result
def allComponents(self, N): V = np.tensordot(self.E, self.p, axes=(1, 1)) - np.tensordot( self.F, spatial_diff(self.p, order=1), axes=((2, 0), (1, 1))) result = (N + 2) * (self.degP - 1) * np.tensordot( self.Cs[N + 2], V, axes=(0, 0)) # First M term tmp = np.tensordot(self.Cs[N + 1], self.diff(self.M, order=0).swapaxes(1, 2), axes=(0, 0)) result -= (N + 1) * symmetrize(tmp, list(range(N + 1))) # The other M terms tmp = self.sumCoefficientDerivativeContraction(self.M, N=N + 1, freeIndices=0) if tmp is not None: result -= tmp # Multiply everything we have so far by (N+1) result = (N + 1) * result # The sum with the index swapping Cd = self.diff(self.Cs[N], order=1) for K in range(0, N + 1): result -= Cd.swapaxes(K, len(self.Cs.shape) - 2) # Last term result += 2 * spatial_diff(self.diff(self.Cs[N], order=2), order=1).trace(0, N + 2) return result
def coefficientDerivativeTrace(self, N=0, derivOrder=0, freeIndices=0): Cd = self.diff(expr=self.Cs[N], order=derivOrder + freeIndices) result = spatial_diff(expr=Cd, order=derivOrder) if derivOrder > 0 else Cd for i in range(derivOrder): result = np.trace(result, axis1=0, axis2=len(result.shape) - 1) return result
def allComponents(self): # First term V = np.tensordot(self.p, self.E, axes=(1, 1)) - np.tensordot( spatial_diff(expr=self.p, order=1), self.F, axes=((0, 2), (2, 1))) result = 6 * (self.degP - 1) * np.tensordot(self.Cs[3], V, axes=(0, 1)) # Second term. In the M_: term we swap B2 and mu result -= 4 * symmetrize( np.tensordot(self.Cs[2], self.diff(expr=self.M, order=0).swapaxes(1, 2), axes=(0, 0)), [0, 1]) # Third to fifth term tmp = self.sumCoefficientDerivativeContraction(self.M, N=2) if tmp is not None: result -= 2 * tmp # Sixth summand. Need to swap the first and second axes to get into the B1 B2 order result -= self.diff(expr=self.Cs[1], order=1).swapaxes(0, 1) # Last summand tmp = self.sumCoefficientDerivativeTrace(N=1, freeIndices=1, combinatorial='K+1', alternatingSign=True) if tmp is not None: result -= tmp return result
def allComponents(self): V = np.tensordot(self.p, self.E, axes=(1, 1)) - np.tensordot( spatial_diff(self.p, order=1), self.F, axes=((0, 2), (2, 1))) # First summand. It is transposed into the shape (B,nu) result = 2 * (self.degP - 1) * np.tensordot(self.Cs[2], V, axes=(0, 1)) # Second summand result -= np.tensordot(self.Cs[1], self.diff(self.M, order=0), axes=(0, 0)).transpose() # Third summand tmp = self.sumCoefficientDerivativeContraction(self.M, N=1) if tmp is not None: result -= tmp # Fourth summand tmp = self.sumCoefficientDerivativeTrace(N=1, freeIndices=1, combinatorial='K+1', alternatingSign=True) if tmp is not None: result -= tmp return result
def allComponents(self): result = 0 # Third summand for K in range(2, self.collapse + 1): for J in range(2, K + 1): Cd = self.diff(self.Cs[0], order=K) Md = spatial_diff(self.M, order=K - J) tmp = np.tensordot(Cd, Md, axes=(tuple(range(1, K - J + 1)) + (0, ), tuple(range(0, K - J + 1)))) tmp = symmetrize(tmp, list(range(len(tmp.shape)))) tmp = spatial_diff(tmp, order=J + 1) for i in range(J + 1): tmp = tmp.trace(0, len(tmp.shape) - 1) result = result + (-1)**J * binomial(K, J) * (J - 1) * tmp return result
def coefficientDerivativeContraction(self, coeff, N=0, derivOrder=0, Aposition=0, freeIndices=0): Cshape = self.Cs[N].shape Cd = self.diff(expr=self.Cs[N], order=derivOrder + freeIndices) coeffd = spatial_diff(expr=coeff, order=derivOrder) if derivOrder == 0 else coeff # Calculate the index positions for the contraction Caxes = (len(Cshape), ) + tuple( range(len(Cd.shape) - derivOrder, len(Cd.shape))) caxes = (Aposition + derivOrder, ) + tuple(range(derivOrder)) result = np.tensordot(Cd, coeffd, axes=(Caxes, caxes)) return result