Esempio n. 1
0
def test_ball_diffusion(Lmax, Nmax, Leig, radius, bc, dtype):
    # Bases
    c = coords.SphericalCoordinates('phi', 'theta', 'r')
    d = distributor.Distributor((c, ))
    b = basis.BallBasis(c, (2 * (Lmax + 1), Lmax + 1, Nmax + 1),
                        radius=radius,
                        dtype=dtype)
    b_S2 = b.S2_basis()
    phi, theta, r = b.local_grids((1, 1, 1))
    # Fields
    A = field.Field(dist=d, bases=(b, ), tensorsig=(c, ), dtype=dtype)
    φ = field.Field(dist=d, bases=(b, ), dtype=dtype)
    τ_A = field.Field(dist=d, bases=(b_S2, ), tensorsig=(c, ), dtype=dtype)
    λ = field.Field(name='λ', dist=d, dtype=dtype)
    # Parameters and operators
    div = lambda A: operators.Divergence(A)
    grad = lambda A: operators.Gradient(A, c)
    curl = lambda A: operators.Curl(A)
    lap = lambda A: operators.Laplacian(A, c)
    trans = lambda A: operators.TransposeComponents(A)
    radial = lambda A, index: operators.RadialComponent(A, index=index)
    angular = lambda A, index: operators.AngularComponent(A, index=index)
    Lift = lambda A: operators.Lift(A, b, -1)
    # Problem
    problem = problems.EVP([φ, A, τ_A], λ)
    problem.add_equation((div(A), 0))
    problem.add_equation((-λ * A + grad(φ) - lap(A) + Lift(τ_A), 0))
    if bc == 'no-slip':
        problem.add_equation((A(r=radius), 0))
    elif bc == 'stress-free':
        E = 1 / 2 * (grad(A) + trans(grad(A)))
        problem.add_equation((radial(A(r=radius), 0), 0))
        problem.add_equation((radial(angular(E(r=radius), 0), 1), 0))
    elif bc == 'potential':
        ell_func = lambda ell: ell + 1
        ell_1 = lambda A: operators.SphericalEllProduct(A, c, ell_func)
        problem.add_equation(
            (radial(grad(A)(r=radius), 0) + ell_1(A)(r=radius) / radius, 0))
    elif bc == 'conducting':
        problem.add_equation((φ(r=radius), 0))
        problem.add_equation((angular(A(r=radius), 0), 0))
    elif bc == 'pseudo':
        problem.add_equation((radial(A(r=radius), 0), 0))
        problem.add_equation((angular(curl(A)(r=radius), 0), 0))
    # Solver
    solver = solvers.EigenvalueSolver(problem)
    if not solver.subproblems[Leig].group[1] == Leig:
        raise ValueError("subproblems indexed in a strange way")
    solver.solve_dense(solver.subproblems[Leig])
    i_sort = np.argsort(solver.eigenvalues)
    solver.eigenvalues = solver.eigenvalues[i_sort]
    λ_analytic = analytic_eigenvalues(Leig, Nmax + 1, bc, r0=radius)
    if (bc == 'stress-free' and Leig == 1):
        # add null space solution
        λ_analytic = np.append(0, λ_analytic)
    assert np.allclose(solver.eigenvalues[:Nmax // 4], λ_analytic[:Nmax // 4])
Esempio n. 2
0
def test_curl_vector(Nphi, Nr, dealias, basis, dtype):
    c, d, b, phi, r, x, y = basis(Nphi, Nr, dealias, dtype)
    v = field.Field(dist=d, bases=(b, ), tensorsig=(c, ), dtype=dtype)
    v.preset_scales(b.domain.dealias)
    ex = np.array([-np.sin(phi) + 0. * r, np.cos(phi) + 0. * r])
    ey = np.array([np.cos(phi) + 0. * r, np.sin(phi) + 0. * r])
    v['g'] = 4 * x**3 * ey + 3 * y**2 * ey
    u = operators.Curl(v).evaluate()
    ug = 12 * x**2
    assert np.allclose(u['g'], ug)
def test_curl_vector(Nphi, Ntheta, Nr, dealias, basis, dtype):
    c, d, b, phi, theta, r, x, y, z = basis(Nphi, Ntheta, Nr, dealias, dtype)
    u = field.Field(dist=d, bases=(b,), tensorsig=(c,), dtype=dtype)
    u.preset_scales(b.domain.dealias)
    ct, st, cp, sp = np.cos(theta), np.sin(theta), np.cos(phi), np.sin(phi)
    u['g'][2] = r**2*st*(2*ct**2*cp-r*ct**3*sp+r**3*cp**3*st**5*sp**3+r*ct*st**2*(cp**3+sp**3))
    u['g'][1] = r**2*(2*ct**3*cp-r*cp**3*st**4+r**3*ct*cp**3*st**5*sp**3-1/16*r*np.sin(2*theta)**2*(-7*sp+np.sin(3*phi)))
    u['g'][0] = r**2*sp*(-2*ct**2+r*ct*cp*st**2*sp-r**3*cp**2*st**5*sp**3)
    v = operators.Curl(u).evaluate()
    vg = 0 * v['g']
    vg[2] = -r*st*(r*ct**2*cp+r*cp*st**2*sp*(3*cp+sp)+ct*sp*(-4+3*r**3*cp**2*st**3*sp))
    vg[1] = r*(-r*ct**3*cp+4*ct**2*sp+3*r**3*cp**2*st**5*sp**2-r*ct*cp*st**2*sp*(3*cp+sp))
    vg[0] = r*(4*ct*cp+r*ct**2*sp+r*st**2*(-3*cp**3+sp**3))
    assert np.allclose(v['g'], vg)
Esempio n. 4
0
tau_T = field.Field(dist=d, bases=(cb,), dtype=dtype)

# parameters
S = field.Field(dist=d, bases=(b,), dtype=dtype)
g = field.Field(dist=d, bases=(b,), tensorsig=(c,), dtype=dtype)

# constant heating rate
# radially dependent gravity
S['g'] = 2.
g['g'][1] = -r

# Parameters and operators
lap = lambda A: operators.Laplacian(A, c)
div = lambda A: operators.Divergence(A)
grad = lambda A: operators.Gradient(A, c)
curl = lambda A: operators.Curl(A)
dot = lambda A,B: arithmetic.DotProduct(A, B)
cross = lambda A,B: arithmetic.CrossProduct(A, B)
dt = lambda A: operators.TimeDerivative(A)
LiftTau = lambda A: operators.LiftTau(A, b, -1)

# Problem
def eq_eval(eq_str):
    return [eval(expr) for expr in split_equation(eq_str)]
problem = problems.IVP([u, T, p, tau_u, tau_T])
#problem.add_equation(eq_eval("dt(u) - nu*lap(u) - grad(p) = -cross(u, curl(u)) - g*T"), condition='nphi != 0')
problem.add_equation(eq_eval("dt(u) - nu*lap(u) - grad(p) + LiftTau(tau_u) = -dot(u, grad(u)) - g*T"), condition='nphi != 0')
problem.add_equation(eq_eval("u = 0"), condition='nphi == 0')
problem.add_equation(eq_eval("dt(T) - kappa*lap(T) + LiftTau(tau_T) = -dot(u, grad(T)) + S"))
problem.add_equation(eq_eval("div(u) = 0"), condition='nphi != 0')
problem.add_equation(eq_eval("p = 0"), condition='nphi == 0')
Esempio n. 5
0
A_potential_bc = operators.RadialComponent(
    operators.interpolate(operators.Gradient(
        A, c), r=1)) + operators.interpolate(
            operators.SphericalEllProduct(A, c, ell_func), r=1) / r_out

# Parameters and operators
ez = field.Field(dist=d, bases=(b, ), tensorsig=(c, ), dtype=dtype)
ez['g'][1] = -np.sin(theta)
ez['g'][2] = np.cos(theta)
div = lambda A: operators.Divergence(A, index=0)
lap = lambda A: operators.Laplacian(A, c)
grad = lambda A: operators.Gradient(A, c)
dot = lambda A, B: arithmetic.DotProduct(A, B)
cross = lambda A, B: arithmetic.CrossProduct(A, B)
ddt = lambda A: operators.TimeDerivative(A)
curl = lambda A: operators.Curl(A)
LiftTau = lambda A: operators.LiftTau(A, b, -1)


def eq_eval(eq_str):
    return [eval(expr) for expr in split_equation(eq_str)]


A_analytic_2 = (
    3 / 2 * r**2 * (1 - 4 * r**2 + 6 * r**4 - 3 * r**6) * np.sin(theta) *
    (np.sin(phi) - np.cos(phi)) + 3 / 8 * r**3 *
    (2 - 7 * r**2 + 9 * r**4 - 4 * r**6) * (3 * np.cos(theta)**2 - 1) +
    9 / 160 * r**2 *
    (-200 / 21 * r + 980 / 27 * r**3 - 540 / 11 * r**5 + 880 / 39 * r**7) *
    (3 * np.cos(theta)**2 - 1) + 9 / 80 * r *
    (1 - 100 / 21 * r**2 + 245 / 27 * r**4 - 90 / 11 * r**6 + 110 / 39 * r**8)
Esempio n. 6
0
#B['g'][2] = 5/8*(8*r_outer -6*r -2*r_inner**4/r**3)*np.cos(theta)

B['g'][0] = -3 / 4 * r * (r**2 - 1) * np.cos(theta) * (
    3 * r * (2 - 5 * r**2 + 4 * r**4) * np.sin(theta) + 2 *
    (1 - 3 * r**2 + 3 * r**4) * (np.cos(phi) - np.sin(phi)))
B['g'][1] = -3 / 2 * r * (-1 + 4 * r**2 - 6 * r**4 + 3 * r**6) * (np.cos(phi) +
                                                                  np.sin(phi))

# Parameters and operators
div = lambda A: operators.Divergence(A, index=0)
lap = lambda A: operators.Laplacian(A, c)
grad = lambda A: operators.Gradient(A, c)
dot = lambda A, B: arithmetic.DotProduct(A, B)
cross = lambda A, B: operators.CrossProduct(A, B)
ddt = lambda A: operators.TimeDerivative(A)
curl = lambda A: operators.Curl(A)

# Potential BC on A
r_out = 1
ell_func = lambda ell: ell + 1
radial = lambda A: operators.RadialComponent(A)
ell_op = lambda A: operators.SphericalEllProduct(A, c, ell_func)

A_bc_outer = radial(grad(A)(r=r_outer)) + ell_op(A)(r=r_outer) / r_outer
A_bc_inner = radial(grad(A)(r=r_inner)) + ell_op(A)(r=r_inner) / r_inner


def eq_eval(eq_str):
    return [eval(expr) for expr in split_equation(eq_str)]