Exemplo n.º 1
0
def build_CF_CF(Nx, Ny, dealias_x, dealias_y):
    c = coords.CartesianCoordinates('x', 'y')
    d = distributor.Distributor((c, ))
    xb = basis.ComplexFourier(c.coords[0],
                              size=Nx,
                              bounds=(0, np.pi),
                              dealias=dealias_x)
    yb = basis.ComplexFourier(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
Exemplo n.º 2
0
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
Exemplo n.º 3
0
def test_heat_1d_periodic(x_basis_class, Nx, timestepper, dtype):
    # Bases
    c = coords.Coordinate('x')
    d = distributor.Distributor((c, ))
    xb = basis.ComplexFourier(c, size=Nx, bounds=(0, 2 * np.pi))
    x = xb.local_grid(1)
    # Fields
    u = field.Field(name='u', dist=d, bases=(xb, ), dtype=dtype)
    F = field.Field(name='F', dist=d, bases=(xb, ), dtype=dtype)
    F['g'] = -np.sin(x)
    # Problem
    dx = lambda A: operators.Differentiate(A, c)
    dt = operators.TimeDerivative
    problem = problems.IVP([u])
    problem.add_equation((-dt(u) + dx(dx(u)), F))
    # Solver
    solver = solvers.InitialValueSolver(problem, timestepper)
    dt = 1e-5
    iter = 10
    for i in range(iter):
        solver.step(dt)
    # Check solution
    amp = 1 - np.exp(-solver.sim_time)
    u_true = amp * np.sin(x)
    assert np.allclose(u['g'], u_true)
Exemplo n.º 4
0
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'])
Exemplo n.º 5
0
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])
Exemplo n.º 6
0
def test_CF_scalar_roundtrip(N, dealias):
    if comm.size == 1:
        c = coords.Coordinate('x')
        d = distributor.Distributor([c])
        xb = basis.ComplexFourier(c, size=N, bounds=(0, 1), dealias=dealias)
        x = xb.local_grid(dealias)
        # Scalar transforms
        u = field.Field(dist=d, bases=(xb, ), dtype=np.complex128)
        u.preset_scales(dealias)
        u['g'] = ug = np.exp(2 * np.pi * 1j * x)
        u['c']
        assert np.allclose(u['g'], ug)
    else:
        pytest.skip("Can only test 1D transform in serial")
Exemplo n.º 7
0
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)
Exemplo n.º 8
0
from dedalus.core import coords, distributor, basis, field, operators, problems, solvers
from dedalus.tools import logging
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
Exemplo n.º 9
0
import logging
logger = logging.getLogger(__name__)

# Parameters
Lx, Ly, Lz = (4, 4, 1)
Nx, Ny, Nz = 8, 8, 16
Prandtl = 1
Rayleigh = 3000
timestep = 0.01
stop_iteration = 10

# Bases
c = coords.CartesianCoordinates('x', 'y', 'z')
d = distributor.Distributor((c, ))
xb = basis.ComplexFourier(c.coords[0], size=Nx, bounds=(0, Lx))
yb = basis.ComplexFourier(c.coords[1], size=Ny, bounds=(0, Ly))
zb = basis.ChebyshevT(c.coords[2], size=Nz, bounds=(0, Lz))

# Fields
p = field.Field(name='p', dist=d, bases=(xb, yb, zb), dtype=np.complex128)
b = field.Field(name='b', dist=d, bases=(xb, yb, zb), dtype=np.complex128)
u = field.Field(name='u',
                dist=d,
                bases=(xb, yb, zb),
                dtype=np.complex128,
                tensorsig=(c, ))

# Taus
zb2 = basis.ChebyshevV(c.coords[2], size=Nz, bounds=(0, Lz), alpha0=0)
t1 = field.Field(name='t4', dist=d, bases=(xb, yb), dtype=np.complex128)
Exemplo n.º 10
0
import numpy as np
from dedalus.core import coords, distributor, basis, field, operators
from mpi4py import MPI

comm = MPI.COMM_WORLD

results = []

## 2D Fourier * Chebyshev
c = coords.CartesianCoordinates('x', 'y')
d = distributor.Distributor((c, ))
xb = basis.ComplexFourier(c.coords[0], size=16, bounds=(0, 2 * np.pi))
yb = basis.ChebyshevT(c.coords[1], size=16, bounds=(0, 1))
x = xb.local_grid(1)
y = yb.local_grid(1)

# Gradient of a scalar
f = field.Field(dist=d, bases=(xb, yb), dtype=np.complex128)
f.name = 'f'
f['g'] = np.sin(x) * y**5
u = operators.Gradient(f, c)
u = u.evaluate()
u.name = 'u'
ug = np.array([np.cos(x) * y**5, np.sin(x) * 5 * y**4])
result = np.allclose(u['g'], ug)
results.append(result)
print(len(results), ':', result, '(gradient of a scalar)')

# Gradient of a vector
T = operators.Gradient(u, c)
T = T.evaluate()