def build_RF_RF(Nx, Ny, dealias_x, dealias_y): c = coords.CartesianCoordinates('x', 'y') d = distributor.Distributor((c, )) xb = basis.RealFourier(c.coords[0], size=Nx, bounds=(0, np.pi), dealias=dealias_x) yb = basis.RealFourier(c.coords[1], size=Ny, bounds=(0, np.pi), dealias=dealias_y) x = xb.local_grid(dealias_x) y = yb.local_grid(dealias_y) return c, d, xb, yb, x, y
def build_3d_box(Nx, Ny, Nz, dealias, dtype, k=0): c = coords.CartesianCoordinates('x', 'y', 'z') d = distributor.Distributor((c,)) if dtype == np.complex128: xb = basis.ComplexFourier(c.coords[0], size=Nx, bounds=(0, Lx)) yb = basis.ComplexFourier(c.coords[1], size=Ny, bounds=(0, Ly)) elif dtype == np.float64: xb = basis.RealFourier(c.coords[0], size=Nx, bounds=(0, Lx)) yb = basis.RealFourier(c.coords[1], size=Ny, bounds=(0, Ly)) zb = basis.ChebyshevT(c.coords[2], size=Nz, bounds=(0, Lz)) b = (xb, yb, zb) x = xb.local_grid(1) y = yb.local_grid(1) z = zb.local_grid(1) return c, d, b, x, y, z
def test_fourier_convert_constant(N, bounds, dtype, layout): c = coords.Coordinate('x') d = distributor.Distributor((c, )) if dtype == np.float64: b = basis.RealFourier(c, size=N, bounds=bounds) elif dtype == np.complex128: b = basis.ComplexFourier(c, size=N, bounds=bounds) fc = field.Field(dist=d, dtype=dtype) fc['g'] = 1 fc[layout] f = operators.convert(fc, (b, )).evaluate() assert np.allclose(fc['g'], f['g'])
def test_fourier_integrate(N, bounds, dtype): c = coords.Coordinate('x') d = distributor.Distributor((c, )) if dtype == np.float64: b = basis.RealFourier(c, size=N, bounds=bounds) elif dtype == np.complex128: b = basis.ComplexFourier(c, size=N, bounds=bounds) x = b.local_grid(1) f = field.Field(dist=d, bases=(b, ), dtype=dtype) k = 4 * np.pi / (bounds[1] - bounds[0]) f['g'] = 1 + np.sin(k * x + 0.1) fi = operators.Integrate(f, c).evaluate() assert np.allclose(fi['g'], bounds[1] - bounds[0])
def test_RF_scalar_roundtrip(N, dealias): if comm.size == 1: c = coords.Coordinate('x') d = distributor.Distributor([c]) xb = basis.RealFourier(c, size=N, bounds=(0, 1), dealias=dealias) x = xb.local_grid(dealias) # Scalar transforms u = field.Field(dist=d, bases=(xb, ), dtype=np.float64) u.preset_scales(dealias) u['g'] = ug = np.cos(2 * np.pi * x + np.pi / 4) u['c'] assert np.allclose(u['g'], ug) else: pytest.skip("Can only test 1D transform in serial")
def test_real_fourier_libraries_forward(N, dealias, dtype, library): """Tests that fast real Fourier transforms match matrix transforms.""" c = coords.Coordinate('x') d = distributor.Distributor([c]) # Matrix b_mat = basis.RealFourier(c, size=N, bounds=(0, 2 * np.pi), dealias=dealias, library='matrix') u_mat = field.Field(dist=d, bases=(b_mat, ), dtype=dtype) u_mat.preset_scales(dealias) u_mat['g'] = np.random.randn(int(np.ceil(dealias * N))) # Library b_lib = basis.RealFourier(c, size=N, bounds=(0, 2 * np.pi), dealias=dealias, library=library) u_lib = field.Field(dist=d, bases=(b_lib, ), dtype=dtype) u_lib.preset_scales(dealias) u_lib['g'] = u_mat['g'] assert np.allclose(u_mat['c'], u_lib['c'])
def test_fourier_interpolate(N, bounds, dtype): c = coords.Coordinate('x') d = distributor.Distributor((c, )) if dtype == np.float64: b = basis.RealFourier(c, size=N, bounds=bounds) elif dtype == np.complex128: b = basis.ComplexFourier(c, size=N, bounds=bounds) x = b.local_grid(1) f = field.Field(dist=d, bases=(b, ), dtype=dtype) k = 4 * np.pi / (bounds[1] - bounds[0]) f['g'] = 1 + np.sin(k * x + 0.1) results = [] for p in [ bounds[0], bounds[1], bounds[0] + (bounds[1] - bounds[0]) * np.random.rand() ]: fp = operators.Interpolate(f, c, p).evaluate() results.append(np.allclose(fp['g'], 1 + np.sin(k * p + 0.1))) assert all(results)
from mpi4py import MPI rank = MPI.COMM_WORLD.rank import logging logger = logging.getLogger(__name__) dtype = np.complex128 #np.float64 Nx = 64 Nz = 32 Lz = 2*np.pi # Bases c = coords.CartesianCoordinates('x', 'z') d = distributor.Distributor((c,)) if dtype == np.complex128: xb = basis.ComplexFourier(c.coords[0], size=Nx, bounds=(0, 2*np.pi), dealias=3/2) elif dtype == np.float64: xb = basis.RealFourier(c.coords[0], size=Nx, bounds=(0, 2*np.pi), dealias=3/2) zb = basis.ChebyshevT(c.coords[1], size=Nz, bounds=(0, Lz),dealias=3/2) x = xb.local_grid(1) z = zb.local_grid(1) zb1 = basis.ChebyshevU(c.coords[1], size=Nz, bounds=(0, Lz), alpha0=0) t1 = field.Field(name='t1', dist=d, bases=(xb,), dtype=dtype) t2 = field.Field(name='t2', dist=d, bases=(xb,), dtype=dtype) P1 = field.Field(name='P1', dist=d, bases=(zb1,), dtype=dtype) if rank == 0: P1['c'][0,-1] = 1 dz = lambda A: operators.Differentiate(A, c.coords[1]) P2 = dz(P1).evaluate() # Fields u = field.Field(name='u', dist=d, bases=(xb,zb), dtype=dtype) F = field.Field(name='F', dist=d, bases=(xb,zb), dtype=dtype)
radius = 1 Mmax = 31 Nmax = 31 nz = 32 Ampl = 1e-6 Re = 3162. nu = 1./Re zmin = 0 zmax = 16*np.pi*2*radius # Bases zc = coords.Coordinate('z') c = coords.PolarCoordinates('phi', 'r') d = distributor.Distributor((zc,c)) b = basis.DiskBasis(c, (Mmax+1, Nmax+1), radius=radius, dtype=dtype) zb = basis.RealFourier(zc, nz, bounds=(zmin, zmax)) cb = b.S1_basis(radius=radius) phi, r = b.local_grids((1, 1)) z = zb.local_grids((1,)) # Fields u = field.Field(dist=d, bases=(zb, b), tensorsig=(c,),dtype=dtype) w = field.Field(dist=d, bases=(zb, b), dtype=dtype) p = field.Field(dist=d, bases=(zb, b), dtype=dtype) tau_u = field.Field(dist=d, bases=(cb,), tensorsig=(c,), dtype=dtype) tau_w = field.Field(dist=d, bases=(cb,), dtype=dtype) # Parameters and operators lap = lambda A: operators.Laplacian(A, c) div = lambda A: operators.Divergence(A)
# Parameters Lx, Lz = (4, 1) Nx, Nz = 64, 32 Prandtl = 1 Rayleigh = 1e6 timestep = 0.05 stop_iteration = 150 dtype = np.complex128 print_condition_numbers = True plot_subproblem_matrices = False # Bases c = coords.CartesianCoordinates('x', 'z') d = distributor.Distributor((c, )) if dtype == np.float64: xb = basis.RealFourier(c.coords[0], size=Nx, bounds=(0, Lx)) elif dtype == np.complex128: xb = basis.ComplexFourier(c.coords[0], size=Nx, bounds=(0, Lx)) zb = basis.ChebyshevT(c.coords[1], size=Nz, bounds=(0, Lz)) x = xb.local_grid(1) z = zb.local_grid(1) # Fields p = field.Field(name='p', dist=d, bases=(xb, zb), dtype=dtype) b = field.Field(name='b', dist=d, bases=(xb, zb), dtype=dtype) u = field.Field(name='u', dist=d, bases=(xb, zb), dtype=dtype, tensorsig=(c, )) # Taus zb1 = basis.ChebyshevU(c.coords[1], size=Nz, bounds=(0, Lz), alpha0=0) t1 = field.Field(name='t1', dist=d, bases=(xb, ), dtype=dtype) t2 = field.Field(name='t2', dist=d, bases=(xb, ), dtype=dtype)