Exemple #1
0
def darcy_dual_hybridVEM_example3(**kwargs):
    #######################
    # Simple 3d Darcy problem with known exact solution
    #######################
    Nx = Ny = Nz = 7
    g = structured.CartGrid([Nx, Ny, Nz], [1, 1, 1])
    g.compute_geometry()

    kxx = np.ones(g.num_cells)
    perm = tensor.SecondOrder(g.dim, kxx)

    def funP_ex(pt):
        return np.sin(2*np.pi*pt[0])*np.sin(2*np.pi*pt[1])\
            * np.sin(2*np.pi*pt[2])

    def funU_ex(pt):
        return [-2*np.pi*np.cos(2*np.pi*pt[0])\
                * np.sin(2*np.pi*pt[1])*np.sin(2*np.pi*pt[2]),
                -2*np.pi*np.sin(2*np.pi*pt[0])\
                * np.cos(2*np.pi*pt[1])*np.sin(2*np.pi*pt[2]),
                -2*np.pi*np.sin(2*np.pi*pt[0])\
                * np.sin(2*np.pi*pt[1])*np.cos(2*np.pi*pt[2])]

    def fun(pt):
        return 12 * np.pi**2 * funP_ex(pt)

    f = np.array([fun(pt) for pt in g.cell_centers.T])

    b_faces = g.get_boundary_faces()
    bnd = bc.BoundaryCondition(g, b_faces, ['dir'] * b_faces.size)
    bnd_val = np.zeros(g.num_faces)
    bnd_val[b_faces] = funP_ex(g.face_centers[:, b_faces])

    solver = hybrid.HybridDualVEM()
    data = {'perm': perm, 'source': f, 'bc': bnd, 'bc_val': bnd_val}
    H, rhs = solver.matrix_rhs(g, data)

    l = sps.linalg.spsolve(H, rhs)
    u, p = solver.compute_up(g, l, data)
    P0u = dual.DualVEM().project_u(g, u)

    if kwargs['visualize']:
        plot_grid(g, p, P0u)

    p_ex = error.interpolate(g, funP_ex)
    u_ex = error.interpolate(g, funU_ex)

    np.set_printoptions(linewidth=999999)
    np.set_printoptions(precision=16)

    errors = np.array(
        [error.error_L2(g, p, p_ex),
         error.error_L2(g, P0u, u_ex)])
    errors_known = np.array([0.1010936831876412, 0.0680593765009036])
    assert np.allclose(errors, errors_known)
Exemple #2
0
def darcy_dual_hybridVEM_example2(**kwargs):
    #######################
    # Simple 2d Darcy problem on a surface with known exact solution
    #######################
    Nx = Ny = 25
    g = simplex.StructuredTriangleGrid([Nx, Ny], [1, 1])
    R = cg.rot(np.pi / 6., [0, 1, 1])
    g.nodes = np.dot(R, g.nodes)
    g.compute_geometry(is_embedded=True)

    T = cg.tangent_matrix(g.nodes)

    kxx = np.ones(g.num_cells)
    perm = tensor.SecondOrder(g.dim, kxx)

    def funP_ex(pt):
        return np.pi * pt[0] - 6 * pt[1] + np.exp(1) * pt[2] - 4

    def funU_ex(pt):
        return np.dot(T, [-np.pi, 6, -np.exp(1)])

    def fun(pt):
        return 0

    f = np.array([fun(pt) for pt in g.cell_centers.T])

    b_faces = g.get_boundary_faces()
    bnd = bc.BoundaryCondition(g, b_faces, ['dir'] * b_faces.size)
    bnd_val = np.zeros(g.num_faces)
    bnd_val[b_faces] = funP_ex(g.face_centers[:, b_faces])

    solver = hybrid.HybridDualVEM()
    data = {'perm': perm, 'source': f, 'bc': bnd, 'bc_val': bnd_val}
    H, rhs = solver.matrix_rhs(g, data)

    l = sps.linalg.spsolve(H, rhs)
    u, p = solver.compute_up(g, l, data)
    P0u = dual.DualVEM().project_u(g, u)

    if kwargs['visualize']:
        plot_grid(g, p, P0u)

    p_ex = error.interpolate(g, funP_ex)
    u_ex = error.interpolate(g, funU_ex)

    errors = np.array(
        [error.error_L2(g, p, p_ex),
         error.error_L2(g, P0u, u_ex)])
    errors_known = np.array([0, 0])
    assert np.allclose(errors, errors_known)
Exemple #3
0
def darcy_dualVEM_example1(**kwargs):
    #######################
    # Simple 2d Darcy problem with known exact solution
    #######################
    Nx = Ny = 25
    g = structured.CartGrid([Nx, Ny], [1, 1])
    g.compute_geometry()

    kxx = np.ones(g.num_cells)
    perm = tensor.SecondOrder(g.dim, kxx)

    def funP_ex(pt):
        return np.sin(2 * np.pi * pt[0]) * np.sin(2 * np.pi * pt[1])

    def funU_ex(pt):
        return [
            -2 * np.pi * np.cos(2 * np.pi * pt[0]) * np.sin(2 * np.pi * pt[1]),
            -2 * np.pi * np.sin(2 * np.pi * pt[0]) * np.cos(2 * np.pi * pt[1]),
            0
        ]

    def fun(pt):
        return 8 * np.pi**2 * funP_ex(pt)

    f = np.array([fun(pt) for pt in g.cell_centers.T])

    b_faces = g.get_boundary_faces()
    bnd = bc.BoundaryCondition(g, b_faces, ['dir'] * b_faces.size)
    bnd_val = np.zeros(g.num_faces)
    bnd_val[b_faces] = funP_ex(g.face_centers[:, b_faces])

    solver = dual.DualVEM()
    data = {'perm': perm, 'source': f, 'bc': bnd, 'bc_val': bnd_val}
    D, rhs = solver.matrix_rhs(g, data)

    up = sps.linalg.spsolve(D, rhs)
    u, p = solver.extract_u(g, up), solver.extract_p(g, up)
    P0u = solver.project_u(g, u)

    if kwargs['visualize']:
        plot_grid(g, p, P0u)

    p_ex = error.interpolate(g, funP_ex)
    u_ex = error.interpolate(g, funU_ex)

    errors = np.array(
        [error.error_L2(g, p, p_ex),
         error.error_L2(g, P0u, u_ex)])
    errors_known = np.array([0.0210718223032, 0.00526933885613])
    assert np.allclose(errors, errors_known)