Esempio n. 1
0
def main(id_problem, is_coarse=False, tol=1e-5, if_export=False):

    gb = example_1_create_grid.create(0.5 / float(id_problem), tol)

    if is_coarse:
        co.coarsen(gb, 'by_tpfa')
        folder_export = "example_1_vem_coarse/"
    else:
        folder_export = "example_1_vem/"

    file_name_error = folder_export + "vem_error.txt"

    if if_export:
        save = Exporter(gb, "vem", folder_export)

    example_1_data.assign_frac_id(gb)

    # Assign parameters
    example_1_data.add_data(gb, tol)

    # Choose and define the solvers and coupler
    solver_flow = vem_dual.DualVEMDFN(gb.dim_max(), 'flow')
    A_flow, b_flow = solver_flow.matrix_rhs(gb)

    solver_source = vem_source.DualSourceDFN(gb.dim_max(), 'flow')
    A_source, b_source = solver_source.matrix_rhs(gb)

    up = sps.linalg.spsolve(A_flow + A_source, b_flow + b_source)
    solver_flow.split(gb, "up", up)

    gb.add_node_props(["discharge", 'pressure', "P0u", "err"])
    solver_flow.extract_u(gb, "up", "discharge")
    solver_flow.extract_p(gb, "up", 'pressure')
    solver_flow.project_u(gb, "discharge", "P0u")

    only_max_dim = lambda g: g.dim == gb.dim_max()
    diam = gb.diameter(only_max_dim)
    error_pressure = example_1_data.error_pressure(gb, "p")
    error_discharge = example_1_data.error_discharge(gb, "P0u")
    print("h=", diam, "- err(p)=", error_pressure, "- err(P0u)=",
          error_discharge)
    error_pressure = example_1_data.error_pressure(gb, 'pressure')

    with open(file_name_error, 'a') as f:
        info = str(gb.num_cells(only_max_dim)) + " " +\
               str(gb.num_cells(only_max_dim)) + " " +\
               str(error_pressure) + " " +\
               str(error_discharge) + " " +\
               str(gb.num_faces(only_max_dim))  + "\n"
        f.write(info)

    if if_export:
        save.write_vtk(['pressure', "err", "P0u"])
def main(id_problem, tol=1e-5, N_pts=1000, if_export=False):

    mesh_size = 0.15
    folder_export = 'example_2_1_vem_coarse_' + str(mesh_size) + '/' + str(
        id_problem) + "/"
    file_export = 'vem'

    gb = example_2_1_create_grid.create(id_problem,
                                        is_coarse=True,
                                        mesh_size=mesh_size,
                                        tol=tol)

    internal_flag = FaceTag.FRACTURE
    [g.remove_face_tag_if_tag(FaceTag.BOUNDARY, internal_flag) for g, _ in gb]

    # Assign parameters
    example_2_1_data.add_data(gb, tol)

    # Choose and define the solvers and coupler
    solver_flow = vem_dual.DualVEMDFN(gb.dim_max(), 'flow')
    A_flow, b_flow = solver_flow.matrix_rhs(gb)

    solver_source = vem_source.DualSourceDFN(gb.dim_max(), 'flow')
    A_source, b_source = solver_source.matrix_rhs(gb)

    up = sps.linalg.spsolve(A_flow + A_source, b_flow + b_source)
    solver_flow.split(gb, "up", up)

    gb.add_node_props(["discharge", 'pressure', "P0u"])
    solver_flow.extract_u(gb, "up", "discharge")
    solver_flow.extract_p(gb, "up", 'pressure')
    solver_flow.project_u(gb, "discharge", "P0u")

    if if_export:
        save = Exporter(gb, file_export, folder_export)
        save.write_vtk(['pressure', "P0u"])

    b_box = gb.bounding_box()
    z_range = np.linspace(b_box[0][2] + tol, b_box[1][2] - tol, N_pts)
    pts = np.stack((0.5 * np.ones(N_pts), 0.5 * np.ones(N_pts), z_range))
    values = example_2_1_data.plot_over_line(gb, pts, 'pressure', tol)

    arc_length = z_range - b_box[0][2]
    np.savetxt(folder_export + "plot_over_line.txt", (arc_length, values))

    # compute the flow rate
    diam, flow_rate = example_2_1_data.compute_flow_rate_vem(gb, tol)
    np.savetxt(folder_export + "flow_rate.txt", (diam, flow_rate))
Esempio n. 3
0
def main(id_problem, is_coarse=False, tol=1e-5, N_pts=1000, if_export=False):

    folder_export = "example_2_2_vem/" + str(id_problem) + "/"
    file_export = "vem"

    gb = example_2_2_create_grid.create(id_problem,
                                        is_coarse=is_coarse,
                                        tol=tol)

    # Assign parameters
    example_2_2_data.add_data(gb, tol)

    # Choose and define the solvers and coupler
    solver_flow = vem_dual.DualVEMDFN(gb.dim_max(), "flow")
    A_flow, b_flow = solver_flow.matrix_rhs(gb)

    solver_source = vem_source.DualSourceDFN(gb.dim_max(), "flow")
    A_source, b_source = solver_source.matrix_rhs(gb)

    up = sps.linalg.spsolve(A_flow + A_source, b_flow + b_source)
    solver_flow.split(gb, "up", up)

    gb.add_node_props(["discharge", "pressure", "P0u"])
    solver_flow.extract_u(gb, "up", "discharge")
    solver_flow.extract_p(gb, "up", "pressure")
    solver_flow.project_u(gb, "discharge", "P0u")

    if if_export:
        save = Exporter(gb, file_export, folder_export)
        save.write_vtk(["pressure", "P0u"])

    b_box = gb.bounding_box()
    y_range = np.linspace(b_box[0][1] + tol, b_box[1][1] - tol, N_pts)
    pts = np.stack((1.5 * np.ones(N_pts), y_range, 0.5 * np.ones(N_pts)))
    values = example_2_2_data.plot_over_line(gb, pts, "pressure", tol)

    arc_length = y_range - b_box[0][1]
    np.savetxt(folder_export + "plot_over_line.txt", (arc_length, values))

    # compute the flow rate
    diam, flow_rate = example_2_2_data.compute_flow_rate_vem(gb, tol)
    np.savetxt(folder_export + "flow_rate.txt", (diam, flow_rate))