def dx(u, FST, axis=0): """Compute integral of u over domain for channel solvers""" sx = list(range(3)) sx.pop(axis) uu = np.sum(u, axis=tuple(sx)) sl = FST.local_slice(False)[axis] M = FST.shape()[axis] c = np.zeros(M) cc = np.zeros(M) cc[sl] = uu FST.comm.Reduce(cc, c, op=MPI.SUM, root=0) quad = FST.bases[axis].quad if FST.comm.Get_rank() == 0: if quad == 'GL': ak = np.zeros_like(c) ak = dct(c, ak, 1, axis=0) ak /= (M-1) w = np.arange(0, M, 1, dtype=float) w[2:] = 2./(1-w[2:]**2) w[0] = 1 w[1::2] = 0 return sum(ak*w)*np.prod(np.take(config.params.L/config.params.N, sx)) assert quad == 'GC' d = np.zeros(M) k = 2*(1 + np.arange((M-1)//2)) d[::2] = (2./M)/np.hstack((1., 1.-k*k)) w = np.zeros_like(d) w = dct(d, w, type=3, axis=0) return np.sum(c*w)*np.prod(np.take(config.params.L/config.params.N, sx)) return 0
def dx(u, FST): """Compute integral of u over domain""" uu = sum(u, axis=(1, 2)) sl = FST.local_slice(False)[0] M = FST.shape()[0] c = zeros(M) cc = zeros(M) cc[sl] = uu FST.comm.Reduce(cc, c, op=MPI.SUM, root=0) quad = FST.bases[0].quad if FST.comm.Get_rank() == 0: if quad == 'GL': ak = zeros_like(c) ak = dct(c, ak, 1, axis=0) ak /= (M - 1) w = arange(0, M, 1, dtype=float) w[2:] = 2. / (1 - w[2:]**2) w[0] = 1 w[1::2] = 0 return sum(ak * w) * config.params.L[1] * config.params.L[ 2] / config.params.N[1] / config.params.N[2] assert quad == 'GC' d = zeros(M) k = 2 * (1 + arange((M - 1) // 2)) d[::2] = (2. / M) / hstack((1., 1. - k * k)) w = zeros_like(d) w = dct(d, w, type=3, axis=0) return sum(c * w) * config.params.L[1] * config.params.L[ 2] / config.params.N[1] / config.params.N[2] return 0
def dx(self, u, quad): """Compute integral of u over domain""" uu = sum(u, axis=(1, 2)) c = zeros(self.N[0]) self.comm.Gather(uu, c) if self.rank == 0: if quad == 'GL': ak = zeros_like(c) ak = dct(c, ak, 1, axis=0) ak /= (self.N[0] - 1) w = arange(0, self.N[0], 1, dtype=self.float) w[2:] = 2. / (1 - w[2:]**2) w[0] = 1 w[1::2] = 0 return sum( ak * w) * self.L[1] * self.L[2] / self.N[1] / self.N[2] assert quad == 'GC' d = zeros(self.N[0]) k = 2 * (1 + arange((self.N[0] - 1) // 2)) d[::2] = (2. / self.N[0]) / hstack((1., 1. - k * k)) w = zeros_like(d) w = dct(d, w, type=3, axis=0) return sum(c * w) * self.L[1] * self.L[2] / self.N[1] / self.N[2] return 0
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 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 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 ifct(self, fk, cj): """Inverse fast Chebyshev transform.""" if self.quad == "GC": cj = dct(fk, cj, type=3, axis=0) cj *= 0.5 cj += fk[0]/2 elif self.quad == "GL": cj = dct(fk, cj, type=1, axis=0) cj *= 0.5 cj += fk[0]/2 cj[::2] += fk[-1]/2 cj[1::2] -= fk[-1]/2 return cj
def fastChebScalar(self, fj, fk): """Fast Chebyshev scalar product.""" N = fj.shape[0] if self.fast_transform: if self.quad == "GC": fk = dct(fj, fk, type=2, axis=0) fk *= (pi/(2*N)) elif self.quad == "GL": fk = dct(fj, fk, type=1, axis=0) fk *= (pi/(2*(N-1))) else: if not self.points.shape == (N,): self.init(N) 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
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
def Q(u, rank, comm, N): """Integrate u over entire computational domain """ L = config.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