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)
logger.info(args) logger.info("saving data in: {}".format(data_dir)) # this assumes h_bot=1, grad_φ = (γ-1)/γ (or L=Hρ) h_bot = 1 h_slope = -1 / (1 + m) grad_φ = (γ - 1) / γ n_h = float(args['--n_h']) Lz = -1 / h_slope * (1 - np.exp(-n_h)) Lx = float(args['--aspect']) * Lz dealias = 2 c = de.CartesianCoordinates('x', 'z') d = de.Distributor(c, dtype=np.float64) xb = de.RealFourier(c.coords[0], size=nx, bounds=(0, Lx), dealias=dealias) zb = de.ChebyshevT(c.coords[1], size=nz, bounds=(0, Lz), dealias=dealias) b = (xb, zb) x = xb.local_grid(1) z = zb.local_grid(1) # Fields T = d.Field(name='T', bases=b) Υ = d.Field(name='Υ', bases=b) s = d.Field(name='s', bases=b) u = d.VectorField(c, name='u', bases=b) # Taus zb1 = zb.clone_with(a=zb.a + 1, b=zb.b + 1) zb2 = zb.clone_with(a=zb.a + 2, b=zb.b + 2) lift_basis = zb.clone_with(a=1 / 2, b=1 / 2) # First derivative basis
# Parameters Lx, Lz = 4, 1 Nx, Nz = 256, 64 Rayleigh = 2e6 Prandtl = 1 dealias = 3 / 2 stop_sim_time = 50 timestepper = d3.RK222 max_timestep = 0.125 dtype = np.float64 # Bases coords = d3.CartesianCoordinates('x', 'z') dist = d3.Distributor(coords, dtype=dtype) xbasis = d3.RealFourier(coords['x'], size=Nx, bounds=(0, Lx), dealias=dealias) zbasis = d3.ChebyshevT(coords['z'], size=Nz, bounds=(0, Lz), dealias=dealias) # Fields p = dist.Field(name='p', bases=(xbasis, zbasis)) b = dist.Field(name='b', bases=(xbasis, zbasis)) u = dist.VectorField(coords, name='u', bases=(xbasis, zbasis)) tau_p = dist.Field(name='tau_p') tau_b1 = dist.Field(name='tau_b1', bases=xbasis) tau_b2 = dist.Field(name='tau_b2', bases=xbasis) tau_u1 = dist.VectorField(coords, name='tau_u1', bases=xbasis) tau_u2 = dist.VectorField(coords, name='tau_u2', bases=xbasis) # Substitutions kappa = (Rayleigh * Prandtl)**(-1 / 2) nu = (Rayleigh / Prandtl)**(-1 / 2)
# Parameters Lx = 10 Nx = 1024 a = 1e-4 b = 2e-4 dealias = 3/2 stop_sim_time = 10 timestepper = d3.SBDF2 timestep = 2e-3 dtype = np.float64 # Bases xcoord = d3.Coordinate('x') dist = d3.Distributor(xcoord, dtype=dtype) xbasis = d3.RealFourier(xcoord, size=Nx, bounds=(0, Lx), dealias=dealias) # Fields u = dist.Field(name='u', bases=xbasis) # Substitutions dx = lambda A: d3.Differentiate(A, xcoord) # Problem problem = d3.IVP([u], namespace=locals()) problem.add_equation("dt(u) - a*dx(dx(u)) - b*dx(dx(dx(u))) = - u*dx(u)") # Initial conditions x = dist.local_grid(xbasis) n = 20 u['g'] = np.log(1 + np.cosh(n)**2/np.cosh(n*(x-0.2*Lx))**2) / (2*n)
# Parameters Lx, Lz = 1, 2 Nx, Nz = 128, 256 Reynolds = 5e4 Schmidt = 1 dealias = 3 / 2 stop_sim_time = 20 timestepper = d3.RK222 max_timestep = 1e-2 dtype = np.float64 # Bases coords = d3.CartesianCoordinates('x', 'z') dist = d3.Distributor(coords, dtype=dtype) xbasis = d3.RealFourier(coords['x'], size=Nx, bounds=(0, Lx), dealias=dealias) zbasis = d3.RealFourier(coords['z'], size=Nz, bounds=(-Lz / 2, Lz / 2), dealias=dealias) # Fields p = dist.Field(name='p', bases=(xbasis, zbasis)) s = dist.Field(name='s', bases=(xbasis, zbasis)) u = dist.VectorField(coords, name='u', bases=(xbasis, zbasis)) tau_p = dist.Field(name='tau_p') # Substitutions nu = 1 / Reynolds D = nu / Schmidt x, z = dist.local_grids(xbasis, zbasis)
import dedalus.public as d3 import dedalus from dedalus.tools.parallel import RotateProcesses scales = 1 coords = d3.CartesianCoordinates('x', 'y') dist = d3.Distributor(coords, dtype=float) xb = d3.RealFourier(coords['x'], 32, (0, 1)) yb = d3.Chebyshev(coords['y'], 64, (0, 1)) domain = dedalus.core.domain.Domain(dist, (xb, yb)) for layout in dist.layouts: with RotateProcesses(): print("Rank:", dist.comm.rank) print("Grid space:", layout.grid_space, " Local:", layout.local) print("Global shape:", layout.global_shape(domain, scales), " Chunk shape:", layout.chunk_shape(domain)) print(layout.local_groups(domain, scales)) print()