Example #1
0
def test_curl_implicit_FFF(basis, N, dealias, dtype):
    c, d, b, r = basis(N, dealias, dtype)
    Lz = b[2].bounds[1]
    integ = lambda A: d3.Integrate(
        d3.Integrate(d3.Integrate(A, c.coords[0]), c.coords[1]), c.coords[2])
    tau1 = d.VectorField(c, name='tau1')
    tau2 = d.Field(name='tau2')
    # ABC vector field
    k = 2 * np.pi * np.array([1 / Lx, 1 / Ly, 1 / Lz])
    f = d.VectorField(c, bases=b)
    f.preset_scales(dealias)
    f['g'][0] = np.sin(k[2] * r[2]) + np.cos(k[1] * r[1])
    f['g'][1] = np.sin(k[0] * r[0]) + np.cos(k[2] * r[2])
    f['g'][2] = np.sin(k[1] * r[1]) + np.cos(k[0] * r[0])
    g = d.VectorField(c, bases=b)
    g.preset_scales(dealias)
    g['g'][0] = k[2] * np.sin(k[2] * r[2]) + k[1] * np.cos(k[1] * r[1])
    g['g'][1] = k[0] * np.sin(k[0] * r[0]) + k[2] * np.cos(k[2] * r[2])
    g['g'][2] = k[1] * np.sin(k[1] * r[1]) + k[0] * np.cos(k[0] * r[0])
    # Skew LBVP
    u = d.VectorField(c, name='u', bases=b)
    phi = d.Field(name='phi', bases=b)
    problem = d3.LBVP([u, phi, tau1, tau2], namespace=locals())
    problem.add_equation("curl(u) + grad(phi) + tau1 = g")
    problem.add_equation("div(u) + tau2 = 0")
    problem.add_equation("integ(phi) = 0")
    problem.add_equation("integ(comp(u,index=0,coord=c['x'])) = 0")
    problem.add_equation("integ(comp(u,index=0,coord=c['y'])) = 0")
    problem.add_equation("integ(comp(u,index=0,coord=c['z'])) = 0")
    solver = problem.build_solver()
    solver.print_subproblem_ranks()
    solver.solve()
    assert np.allclose(u['c'], f['c'])
Example #2
0
def test_curl_implicit_FFC(basis, N, dealias, dtype):
    c, d, b, r = basis(N, dealias, dtype)
    Lz = b[2].bounds[1]
    lift_basis = b[2].clone_with(a=1 / 2, b=1 / 2)  # First derivative basis
    lift = lambda A, n: d3.Lift(A, lift_basis, n)
    integ = lambda A: d3.Integrate(
        d3.Integrate(d3.Integrate(A, c.coords[0]), c.coords[1]), c.coords[2])
    tau1 = d.VectorField(c, name='tau1', bases=b[0:2])
    tau2 = d.Field(name='tau2', bases=b[0:2])
    # ABC vector field
    k = 2 * np.pi * np.array([1 / Lx, 1 / Ly, 1 / Lz])
    f = d.VectorField(c, bases=b)
    f.preset_scales(dealias)
    f['g'][0] = np.sin(k[2] * r[2]) + np.cos(k[1] * r[1])
    f['g'][1] = np.sin(k[0] * r[0]) + np.cos(k[2] * r[2])
    f['g'][2] = np.sin(k[1] * r[1]) + np.cos(k[0] * r[0])
    g = d.VectorField(c, bases=b)
    g.preset_scales(dealias)
    g['g'][0] = k[2] * np.sin(k[2] * r[2]) + k[1] * np.cos(k[1] * r[1])
    g['g'][1] = k[0] * np.sin(k[0] * r[0]) + k[2] * np.cos(k[2] * r[2])
    g['g'][2] = k[1] * np.sin(k[1] * r[1]) + k[0] * np.cos(k[0] * r[0])
    # Skew LBVP
    u = d.VectorField(c, name='u', bases=b)
    phi = d.Field(name='phi', bases=b)
    problem = d3.LBVP([u, phi, tau1, tau2], namespace=locals())
    problem.add_equation("curl(u) + grad(phi) + lift(tau1,-1) = g")
    problem.add_equation("div(u) + lift(tau2,-1) = 0")
    problem.add_equation("u(z=0) = f(z=0)")
    problem.add_equation("phi(z=0) = 0")
    solver = problem.build_solver()
    solver.solve()
    assert np.allclose(u['c'], f['c'])
Example #3
0
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)
τs2 = d.Field(name='τs2', bases=xb)
τu1 = d.VectorField(c, name='τu1', bases=(xb, ))
τu2 = d.VectorField(c, name='τu2', bases=(xb, ))

# Parameters and operators
div = lambda A: de.Divergence(A, index=0)
lap = lambda A: de.Laplacian(A, c)
grad = lambda A: de.Gradient(A, c)
#curl = lambda A: de.operators.Curl(A)
dot = lambda A, B: de.DotProduct(A, B)
cross = lambda A, B: de.CrossProduct(A, B)
trace = lambda A: de.Trace(A)
trans = lambda A: de.TransposeComponents(A)
dt = lambda A: de.TimeDerivative(A)

integ = lambda A: de.Integrate(de.Integrate(A, 'x'), 'z')
avg = lambda A: integ(A) / (Lx * Lz)
#x_avg = lambda A: de.Integrate(A, 'x')/(Lx)
x_avg = lambda A: de.Integrate(A, 'x') / (Lx)

from dedalus.core.operators import Skew
skew = lambda A: Skew(A)

ex = d.VectorField(c, name='ex', bases=zb)
ez = d.VectorField(c, name='ez', bases=zb)
ex['g'][0] = 1
ez['g'][1] = 1
ez2 = d.VectorField(c, name='ez2', bases=zb2)
ez2['g'][1] = 1

h0 = d.Field(name='h0', bases=zb)
τ_s1 = d.Field(name='τ_s1')
τ_s2 = d.Field(name='τ_s2')
τ_u1 = d.VectorField(c, name='τ_u1')
τ_u2 = d.VectorField(c, name='τ_u2')

# Parameters and operators
div = lambda A: de.Divergence(A, index=0)
lap = lambda A: de.Laplacian(A, c)
grad = lambda A: de.Gradient(A, c)
#curl = lambda A: de.operators.Curl(A)
cross = lambda A, B: de.CrossProduct(A, B)
trace = lambda A: de.Trace(A)
trans = lambda A: de.TransposeComponents(A)
dt = lambda A: de.TimeDerivative(A)

integ = lambda A: de.Integrate(A, 'z')

print(c.unit_vector_fields(d))
ez, = c.unit_vector_fields(d)

# stress-free bcs
e = grad(u) + trans(grad(u))
e.store_last = True

viscous_terms = div(e) - 2 / 3 * grad(div(u))
trace_e = trace(e)
trace_e.store_last = True
Phi = 0.5 * trace(e @ e) - 1 / 3 * (trace_e * trace_e)

structure = heated_polytrope(nz, γ, ε, n_h)
h0 = d.Field(name='h0', bases=zb)
Example #6
0
# Parameters and operators
div = lambda A: de.Divergence(A, index=0)
lap = lambda A: de.Laplacian(A, c)
grad = lambda A: de.Gradient(A, c)
curl = lambda A: de.Curl(A)
dot = lambda A, B: de.DotProduct(A, B)
cross = lambda A, B: de.CrossProduct(A, B)
ddt = lambda A: de.TimeDerivative(A)
trans = lambda A: de.TransposeComponents(A)
radial = lambda A: de.RadialComponent(A)
angular = lambda A: de.AngularComponent(A, index=1)
trace = lambda A: de.Trace(A)
power = lambda A, B: de.Power(A, B)
lift_basis = b.clone_with(k=2)
lift = lambda A, n: de.LiftTau(A, lift_basis, n)
integ = lambda A: de.Integrate(A, c)
azavg = lambda A: de.Average(A, c.coords[0])
shellavg = lambda A: de.Average(A, c.S2coordsys)
avg = lambda A: de.Integrate(A, c) / (4 / 3 * np.pi * radius**3)

# NCCs and variables of the problem
ez = d.VectorField(c, name='ez', bases=b)
ez['g'][1] = -np.sin(theta)
ez['g'][2] = np.cos(theta)
ez_g = de.Grid(ez).evaluate()
ez_g.name = 'ez_g'

r_cyl = d.VectorField(c, name='r_cyl', bases=b)
r_cyl['g'][2] = r * np.sin(theta)
r_cyl['g'][1] = -r * np.cos(theta)