Beispiel #1
0
    def test_upwind_2d_simplex_surf_discharge_negative(self):
        g = simplex.StructuredTriangleGrid([2, 1], [1, 1])
        R = cg.rot(-np.pi / 5., [1, 1, -1])
        g.nodes = np.dot(R, g.nodes)
        g.compute_geometry(is_embedded=True)

        solver = upwind.Upwind()
        param = Parameters(g)
        dis = solver.discharge(g, np.dot(R, [-1, 0, 0]))

        bf = g.tags['domain_boundary_faces'].nonzero()[0]
        bc = BoundaryCondition(g, bf, bf.size * ['neu'])
        param.set_bc(solver, bc)

        data = {'param': param, 'discharge': dis}
        M = solver.matrix_rhs(g, data)[0].todense()
        deltaT = solver.cfl(g, data)

        M_known = np.array([[1, 0, 0, -1],
                            [-1, 0, 0, 0],
                            [0, 0, 1, 0],
                            [0, 0, -1, 1]])
        deltaT_known = 1 / 6

        rtol = 1e-15
        atol = rtol
        assert np.allclose(M, M_known, rtol, atol)
        assert np.allclose(deltaT, deltaT_known, rtol, atol)
def anisotropy(gb, deg, yfactor):
    """
    Set anisotropic permeability in the 2d matrix.
    """
    for g, d in gb:
        # Get rotational tensor R
        perm_x = 1
        perm_y = 1 / yfactor
        perm_z = 1
        rad = deg * np.pi / 180
        v = np.array([0, 0, 1])
        R = cg.rot(rad, v)
        # Set up orthogonal tensor and rotate it
        k_orth = np.array([[perm_x, 0, 0], [0, perm_y, 0], [0, 0, perm_z]])
        k = np.dot(np.dot(R, k_orth), R.T)
        kf = np.ones(g.num_cells)
        kxx = kf * k[0, 0]
        kyy = kf * k[1, 1]
        kxy = kf * k[0, 1]
        kxz = kf * k[0, 2]
        kyz = kf * k[1, 2]
        kzz = kf * k[2, 2]

        k_frac = 1e4
        kxx[fracture_cells] = k_frac
        kyy[fracture_cells] = k_frac
        kzz[fracture_cells] = k_frac
        kxy[fracture_cells] = 0
        kxz[fracture_cells] = 0
        kyz[fracture_cells] = 0
        perm = tensor.SecondOrderTensor(
            3, kxx=kxx, kyy=kyy, kzz=kzz, kxy=kxy, kxz=kxz, kyz=kyz
        )
        d["param"].set_tensor("flow", perm)
Beispiel #3
0
def anisotropy(gb, deg, yfactor):
    """
    Set anisotropic permeability in the 2d matrix.
    """
    for g, d in gb:
        if g.dim == 2:
            # Get rotational tensor R
            perm_x = 1
            perm_y = 1 / yfactor
            perm_z = 1
            rad = deg * np.pi / 180
            v = np.array([0, 0, 1])
            R = cg.rot(rad, v)
            # Set up orthogonal tensor and rotate it
            k_orth = np.array([[perm_x, 0, 0], [0, perm_y, 0], [0, 0, perm_z]])
            k = np.dot(np.dot(R, k_orth), R.T)

            kf = np.ones(g.num_cells)
            kxx = kf * k[0, 0]
            kyy = kf * k[1, 1]
            kxy = kf * k[0, 1]
            kxz = kf * k[0, 2]
            kyz = kf * k[1, 2]
            kzz = kf * k[2, 2]
            perm = tensor.SecondOrder(3, kxx=kxx, kyy=kyy,
                                      kzz=kzz, kxy=kxy, kxz=kxz, kyz=kyz)

            d['param'].set_tensor('flow', perm)
            d['hybrid_correction'] = True
def main(N):
    Nx = Ny = N
    #g = structured.CartGrid([Nx, Ny], [1, 1])
    g = simplex.StructuredTriangleGrid([Nx, Ny], [1, 1])
    R = cg.rot(np.pi / 4., [1, 0, 0])
    g.nodes = np.dot(R, g.nodes)
    g.compute_geometry(is_embedded=True)
    #co.coarsen(g, 'by_volume')

    # Assign parameters
    data = add_data(g)

    # Choose and define the solvers
    solver_flow = vem_dual.DualVEM('flow')
    A_flow, b_flow = solver_flow.matrix_rhs(g, data)

    solver_source = vem_source.Integral('flow')
    A_source, b_source = solver_source.matrix_rhs(g, data)

    up = sps.linalg.spsolve(A_flow + A_source, b_flow + b_source)

    u = solver_flow.extract_u(g, up)
    p = solver_flow.extract_p(g, up)
    P0u = solver_flow.project_u(g, u, data)

    diam = np.amax(g.cell_diameters())
    return diam, error_p(g, p)
Beispiel #5
0
def anisotropy(g, deg, yfactor):
    """
    Set anisotropic permeability in the 2d matrix.
    """
    # Get rotational tensor R
    k = 1e3
    perm_x = k
    perm_y = k / yfactor
    perm_z = k
    rad = deg * np.pi / 180
    v = np.array([0, 0, 1])
    R = cg.rot(rad, v)
    # Set up orthogonal permeability tensor and rotate it
    k_orth = np.array([[perm_x, 0, 0], [0, perm_y, 0], [0, 0, perm_z]])
    k = np.dot(np.dot(R, k_orth), R.T)

    kf = np.ones(g.num_cells)
    kxx = kf * k[0, 0]
    kyy = kf * k[1, 1]
    kxy = kf * k[0, 1]
    kxz = kf * k[0, 2]
    kyz = kf * k[1, 2]
    kzz = kf * k[2, 2]
    perm = tensor.SecondOrderTensor(3,
                                    kxx=kxx,
                                    kyy=kyy,
                                    kzz=kzz,
                                    kxy=kxy,
                                    kxz=kxz,
                                    kyz=kyz)
    return perm
Beispiel #6
0
    def test_upwind_2d_simplex_surf_discharge_positive(self):
        g = simplex.StructuredTriangleGrid([2, 1], [1, 1])
        R = cg.rot(np.pi / 2., [1, 1, 0])
        g.nodes = np.dot(R, g.nodes)
        g.compute_geometry()

        solver = upwind.Upwind()
        param = Parameters(g)
        dis = solver.discharge(g, np.dot(R, [1, 0, 0]))

        bf = g.tags["domain_boundary_faces"].nonzero()[0]
        bc = BoundaryCondition(g, bf, bf.size * ["neu"])
        param.set_bc(solver, bc)

        data = {"param": param, "discharge": dis}
        M = solver.matrix_rhs(g, data)[0].todense()
        deltaT = solver.cfl(g, data)

        M_known = np.array([[1, -1, 0, 0], [0, 1, 0, 0], [0, 0, 0, -1],
                            [-1, 0, 0, 1]])
        deltaT_known = 1 / 6

        rtol = 1e-15
        atol = rtol
        self.assertTrue(np.allclose(M, M_known, rtol, atol))
        self.assertTrue(np.allclose(deltaT, deltaT_known, rtol, atol))
Beispiel #7
0
def rotate_fracture(frac, vec, angle, exposure):
    """ Rotate a fracture along a specified strike vector, and centered on a
    given point on the fracture surface.

    Modification of the fracture coordinates is done in place.

    TODO: Move this to the fracture itself?

    Parameters:
        frac (Fracture): To be rotated. Points are modified in-place.
        vec (np.array-like): Rotation will be around this vector.
        ang (double). Rotation angle. Measured in radians.
        exposure (np.array-like): Point on the strike vector, rotation will be
            centered around the line running through this point.

    """
    vec = np.asarray(vec)
    exposure = np.asarray(exposure)

    if vec.size == 2:
        vec = np.append(vec, 0)
    if exposure.size == 2:
        exposure = np.append(exposure, 0)
    exposure = exposure.reshape((3, 1))

    rot = cg.rot(angle, vec)
    p = frac.p
    frac.p = exposure + rot.dot(p - exposure)

    frac.points_2_ccw()
    frac.compute_centroid()
    frac.compute_normal()
Beispiel #8
0
    def test_upwind_2d_cart_surf_discharge_negative(self):
        g = structured.CartGrid([3, 2], [1, 1])
        R = cg.rot(np.pi/6., [1,1,0])
        g.nodes = np.dot(R, g.nodes)
        g.compute_geometry(is_embedded=True)

        solver = upwind.Upwind()
        param = Parameters(g)
        dis = solver.discharge(g, np.dot(R, [-1, 0, 0]))

        bf = g.get_boundary_faces()
        bc = BoundaryCondition(g, bf, bf.size * ['neu'])
        param.set_bc(solver, bc)

        data = {'param': param, 'discharge': dis}
        M = solver.matrix_rhs(g, data)[0].todense()
        deltaT = solver.cfl(g, data)

        M_known = 0.5 * np.array([[ 0,-1, 0, 0, 0, 0],
                                  [ 0, 1,-1, 0, 0, 0],
                                  [ 0, 0, 1, 0, 0, 0],
                                  [ 0, 0, 0, 0,-1, 0],
                                  [ 0, 0, 0, 0, 1,-1],
                                  [ 0, 0, 0, 0, 0, 1]])

        deltaT_known = 1/6

        rtol = 1e-15
        atol = rtol
        assert np.allclose(M, M_known, rtol, atol)
        assert np.allclose(deltaT, deltaT_known, rtol, atol)
Beispiel #9
0
def darcy_dualVEM_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()

    T = cg.tangent_matrix(g.nodes)

    kxx = np.ones(g.num_cells)
    perm = tensor.SecondOrderTensor(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_all_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, 0])
    assert np.allclose(errors, errors_known)
Beispiel #10
0
def main(N):
    Nx = Ny = N
    #g = structured.CartGrid([Nx, Ny], [1, 1])
    g = simplex.StructuredTriangleGrid([Nx, Ny], [1, 1])
    R = cg.rot(np.pi / 2., [1, 0, 0])
    g.nodes = np.dot(R, g.nodes)
    g.compute_geometry(is_embedded=True)

    # Assign parameters
    data = add_data(g)

    # Choose and define the solvers
    solver = mpfa.Mpfa('flow')
    A, b_flux = solver.matrix_rhs(g, data)
    _, b_source = source.Integral('flow').matrix_rhs(g, data)
    p = sps.linalg.spsolve(A, b_flux + b_source)

    diam = np.amax(g.cell_diameters())
    return diam, error_p(g, p)
# ------------------------------------------------------------------------------#


def error_p(g, p):

    sol = np.array([solution(*pt) for pt in g.cell_centers.T])
    return np.sqrt(np.sum(np.power(np.abs(p - sol), 2) * g.cell_volumes))


# ------------------------------------------------------------------------------#

Nx = Ny = 20
# g = structured.CartGrid([Nx, Ny], [1, 1])
g = simplex.StructuredTriangleGrid([Nx, Ny], [1, 1])
R = cg.rot(np.pi / 4.0, [1, 0, 0])
g.nodes = np.dot(R, g.nodes)
g.compute_geometry()
# co.coarsen(g, 'by_volume')

# Assign parameters
data = add_data(g)

# Choose and define the solvers
solver = dual.DualVEM("flow")
A, b = solver.matrix_rhs(g, data)
up = sps.linalg.spsolve(A, b)

u = solver.extract_u(g, up)
p = solver.extract_p(g, up)
P0u = solver.project_u(g, u, data)