Exemplo n.º 1
0
def test_cross_product(Nphi, Ntheta, Nr, dealias, basis):
    c, d, b, phi, theta, r, x, y, z = basis(Nphi, Ntheta, Nr, dealias,
                                            np.complex128)
    f = field.Field(dist=d, bases=(b, ), dtype=np.complex128)
    f['g'] = z
    ez = operators.Gradient(f, c).evaluate()
    u = field.Field(dist=d, bases=(b, ), tensorsig=(c, ), dtype=np.complex128)
    u['g'][2] = (6 * x**2 + 4 * y * z) / r
    u['g'][1] = -2 * (y**3 + x**2 *
                      (y - 3 * z) - y * z**2) / (r**2 * np.sin(theta))
    u['g'][0] = 2 * x * (-3 * y + z) / (r * np.sin(theta))
    h = arithmetic.CrossProduct(ez, u).evaluate()
    hg = np.zeros(h['g'].shape, dtype=h['g'].dtype)
    hg[0] = -ez['g'][1] * u['g'][2] + ez['g'][2] * u['g'][1]
    hg[1] = -ez['g'][2] * u['g'][0] + ez['g'][0] * u['g'][2]
    hg[2] = -ez['g'][0] * u['g'][1] + ez['g'][1] * u['g'][0]
    assert np.allclose(h['g'], hg)
Exemplo n.º 2
0
# Boundary conditions
u_BC = field.Field(dist=d, bases=(b_S2, ), tensorsig=(c, ), dtype=dtype)
u_BC['g'][2] = 0.  # u_r = 0
u_BC['g'][1] = -u0 * np.cos(theta) * np.cos(phi)
u_BC['g'][0] = u0 * np.sin(phi)

# 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)
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([p, u, tau])
# Equations for ell != 0
problem.add_equation(eq_eval("div(u) = 0"), condition="ntheta != 0")
problem.add_equation(eq_eval(
    "ddt(u) - nu*lap(u) + grad(p) + LiftTau(tau) = - dot(u,grad(u)) - Om*cross(ez, u)"
),