示例#1
0
def test_refine():
    assert comm.Get_size() < 7
    N = (8, 9, 10)
    F0 = Basis(8, 'F', dtype='D')
    F1 = Basis(9, 'F', dtype='D')
    F2 = Basis(10, 'F', dtype='d')
    T = TensorProductSpace(comm, (F0, F1, F2), slab=True, collapse_fourier=True)
    u_hat = Function(T)
    u = Array(T)
    u[:] = np.random.random(u.shape)
    u_hat = u.forward(u_hat)
    Tp = T.get_dealiased(padding_factor=(2, 2, 2))
    u_ = Array(Tp)
    up_hat = Function(Tp)
    assert up_hat.commsizes == u_hat.commsizes
    u2 = u_hat.refine(2*np.array(N))
    V = VectorTensorProductSpace(T)
    u_hat = Function(V)
    u = Array(V)
    u[:] = np.random.random(u.shape)
    u_hat = u.forward(u_hat)
    Vp = V.get_dealiased(padding_factor=(2, 2, 2))
    u_ = Array(Vp)
    up_hat = Function(Vp)
    assert up_hat.commsizes == u_hat.commsizes
    u3 = u_hat.refine(2*np.array(N))
示例#2
0
def test_Mult_CTD_3D(quad):
    SD = FunctionSpace(N, 'C', bc=(0, 0))
    F0 = FunctionSpace(4, 'F', dtype='D')
    F1 = FunctionSpace(4, 'F', dtype='d')
    T = TensorProductSpace(comm, (SD, F0, F1))

    TO = T.get_orthogonal()
    CT = TO.bases[0]

    C = inner_product((CT, 0), (SD, 1))
    B = inner_product((CT, 0), (CT, 0))

    vk = Array(T)
    wk = Array(T)
    vk[:] = np.random.random(vk.shape)
    wk[:] = np.random.random(vk.shape)

    bv = Function(T)
    bw = Function(T)

    vk0 = vk.forward()
    vk = vk0.backward()
    wk0 = wk.forward()
    wk = wk0.backward()

    LUsolve.Mult_CTD_3D_ptr(N, vk0, wk0, bv, bw, 0)

    cv = np.zeros_like(vk0)
    cw = np.zeros_like(wk0)
    cv = C.matvec(vk0, cv)
    cw = C.matvec(wk0, cw)
    cv /= B[0].repeat(np.array(bv.shape[1:]).prod()).reshape(bv.shape)
    cw /= B[0].repeat(np.array(bv.shape[1:]).prod()).reshape(bv.shape)

    assert np.allclose(cv, bv)
    assert np.allclose(cw, bw)
示例#3
0
uu = TrialFunction(TV)

# Declare solution arrays and work arrays
UV = Array(TV, buffer=(u0, v0))
UVp = Array(TVp)
U, V = UV  # views into vector components
UV_hat = Function(TV)
w0 = Function(TV)  # Work array spectral space
w1 = Array(TVp)  # Work array physical space

e1 = 0.00002
e2 = 0.00001
b0 = 0.03

#initialize
UV_hat = UV.forward(UV_hat)


def LinearRHS(self, alpha1, alpha2, **params):
    L = inner(vv, (e1, e2) * div(grad(uu)))
    L = np.array([-(-L[0].scale)**(alpha1 / 2), -(-L[1].scale)**(alpha2 / 2)])
    return L


def NonlinearRHS(self, uv, uv_hat, rhs, kappa, **params):
    global b0, UVp, w0, w1, TVp
    rhs.fill(0)
    UVp = TVp.backward(uv_hat, UVp)  # 3/2-rule dealiasing for nonlinear term
    w1[0] = b0 * (1 - UVp[0]) - UVp[0] * UVp[1]**2
    w1[1] = -(b0 + kappa) * UVp[1] + UVp[0] * UVp[1]**2
    w0 = TVp.forward(w1, w0)
示例#4
0
if SD.has_nonhomogeneous_bcs:
    bc_mats = extract_bc_matrices([matrices])

    # Add boundary terms to the known right hand side
    SD.bc.set_boundary_dofs(u_hat, final=True)  # Fixes boundary dofs in u_hat
    w0 = np.zeros_like(u_hat)
    for m in bc_mats:
        f_hat -= m.matvec(u_hat, w0)

# Create linear algebra solver
H = Solver(*matrices)
u_hat = H(u_hat, f_hat)

uj = Array(SD)
uj = SD.backward(u_hat, uj)
uh = uj.forward()

# Compare with analytical solution
uq = Array(SD, buffer=ue)
print("Error=%2.16e" % (np.linalg.norm(uj - uq)))
assert np.linalg.norm(uj - uq) < 1e-8

if 'pytest' not in os.environ:
    import matplotlib.pyplot as plt
    plt.figure()
    plt.plot(X, uq)

    plt.figure()
    plt.plot(X, uj)

    plt.figure()