def build_FFF(N, dealias, dtype): c = d3.CartesianCoordinates('x', 'y', 'z') d = d3.Distributor(c, dtype=dtype) if dtype == np.complex128: xb = d3.ComplexFourier(c.coords[0], size=N, bounds=(0, Lx), dealias=dealias) yb = d3.ComplexFourier(c.coords[1], size=N, bounds=(0, Ly), dealias=dealias) zb = d3.ComplexFourier(c.coords[2], size=N, bounds=(0, Lz), dealias=dealias) elif dtype == np.float64: xb = d3.RealFourier(c.coords[0], size=N, bounds=(0, Lx), dealias=dealias) yb = d3.RealFourier(c.coords[1], size=N, bounds=(0, Ly), dealias=dealias) zb = d3.RealFourier(c.coords[2], size=N, bounds=(0, Lz), dealias=dealias) b = (xb, yb, zb) x = xb.local_grid(dealias) y = yb.local_grid(dealias) z = zb.local_grid(dealias) r = (x, y, z) return c, d, b, r
def test_poisson_1d_fourier(Nx, dtype, matrix_coupling): # Bases coord = d3.Coordinate('x') dist = d3.Distributor(coord, dtype=dtype) if dtype == np.complex128: basis = d3.ComplexFourier(coord, size=Nx, bounds=(0, 2 * np.pi)) elif dtype == np.float64: basis = d3.RealFourier(coord, size=Nx, bounds=(0, 2 * np.pi)) x = basis.local_grid(1) # Fields u = dist.Field(name='u', bases=basis) g = dist.Field(name='c') # Substitutions dx = lambda A: d3.Differentiate(A, coord) integ = lambda A: d3.Integrate(A, coord) F = dist.Field(bases=basis) F['g'] = -np.sin(x) # Problem problem = d3.LBVP([u, g], namespace=locals()) problem.add_equation("dx(dx(u)) + g = F") problem.add_equation("integ(u) = 0") # Solver solver = problem.build_solver(matrix_coupling=[matrix_coupling]) solver.solve() # Check solution u_true = np.sin(x) assert np.allclose(u['g'], u_true)