def fastChebScalar(self, fj, fk): """Fast Chebyshev scalar product.""" N = fj.shape[0] if self.quad == "GC": fk[:] = dct(fj, type=2, axis=0)*np.pi/(2*N) elif self.quad == "GL": fk[:] = dct(fj, type=1, axis=0)*np.pi/(2*(N-1)) return fk
def ifct(self, fk, cj): """Inverse fast Chebyshev transform.""" if self.quad == "GC": cj[:] = 0.5*dct(fk, type=3, axis=0) cj += 0.5*fk[0] elif self.quad == "GL": cj[:] = 0.5*dct(fk, type=1, axis=0) cj += 0.5*fk[0] cj[::2] += 0.5*fk[-1] cj[1::2] -= 0.5*fk[-1] return cj
def fct(self, fj, cj): """Fast Chebyshev transform.""" N = fj.shape[0] if self.quad == "GC": cj[:] = dct(fj, type=2, axis=0) cj /= N cj[0] /= 2 elif self.quad == "GL": cj[:] = dct(fj, type=1, axis=0)/(N-1) cj[0] /= 2 cj[-1] /= 2 return cj
def fastChebScalar(self, fj, fk): """Fast Chebyshev scalar product.""" if self.fast_transform: N = fj.shape[0] if self.quad == "GC": fk[:] = dct(fj, type=2, axis=0)*pi/(2*N) elif self.quad == "GL": fk[:] = dct(fj, type=1, axis=0)*pi/(2*(N-1)) else: if self.points is None: self.init(fj.shape[0]) fk[:] = np.dot(self.V, fj*self.weights) return fk
def energy(u, N, comm, rank, L): uu = sum(u, axis=(1,2)) c = zeros(N[0]) comm.Gather(uu, c) if rank == 0: ak = 1./(N[0]-1)*dct(c, 1, axis=0) w = arange(0, N[0], 1, dtype=float) w[2:] = 2./(1-w[2:]**2) w[0] = 1 w[1::2] = 0 return sum(ak*w)*L[1]*L[2]/N[1]/N[2] else: return 0