def helmholtz(self, u, v, w): ''' break a vector into solenoidal & dilatational parts ''' Nx = self.para.Nx Ny = self.para.Ny Nz = self.para.Nz dx = self.para.dx dz = self.para.dz.reshape([-1,1]) dy = self.para.dy.reshape([-1,1,1]) hx = self.para.hx hz = self.para.hz.reshape([-1,1]) hy = self.para.hy.reshape([-1,1,1]) dy = self.para.dy.reshape([-1,1,1]) hy = self.para.hy.reshape([-1,1,1]) opt = Operators(self.para) # compute divergence and rotation of the vector field phi = opt.divergence(u,v,w) xi1, xi2, xi3 = opt.rotation(u,v,w) # implement homogeneous BC phi[[0,-1]] = 0 xi1[[0,-1]] = 0 xi2[[0,-1]] = 0 xi3[[0,-1]] = 0 # solve poisson equations with Dirichlet BC for xi2 and Neumann BC for others phi = self.poisson(phi) xi1 = self.poisson(-xi1) xi2 = self.poisson(-xi2, bcoef=1) xi3 = self.poisson(-xi3) # interpolate xi to staggered grids xi1[:,:,1:] = .5/hx[1:] * (xi1[:,:,1:]*dx[:-1] + xi1[:,:,:-1]*dx[1:]) xi3[:,1:] = .5/hz[1:] * (xi3[:,1:] *dz[:-1] + xi3[:,:-1] *dz[1:]) xi2[1:] = .5/hy[1:] * (xi2[1:] *dy[:-1] + xi2[:-1] *dy[1:]) xi1[:,:,0] = 0 xi3[:,0] = 0 xi2[0] = 0 # return Us (centered), Ud (staggered), xi (staggered), phi (centered) return opt.rotation(xi1,xi2,xi3), opt.gradient(phi), (xi1,xi2,xi3), phi