Exemplo n.º 1
0
def explore_mesh(mesh, name):
    print("Nb vertices:", mesh.nb_vertices)
    print("Nb cells:", mesh.nb_cells)
    print("Nb faces:", mesh.nb_faces)
    print("Vertices")
    print_collection(mesh.vertices)
    print("Cell nodes")
    print_collection(mesh.connectivity.cells.nodes)
    print("Cell face")
    print_collection(mesh.connectivity.cells.faces)
    print("Face nodes")
    print_collection(mesh.connectivity.faces.nodes)
    print("Boundary faces:", mesh.boundary_faces())
    fcenters = MT.as_coordinate_array(mesh.face_centers())
    print("All face centers: (with shape", fcenters.shape, ")")
    print(fcenters)
    ccenters = MT.as_coordinate_array(mesh.cell_centers())
    print("All cell centers: (with shape", ccenters.shape, ")")
    print(ccenters)
    vertices = MT.as_coordinate_array(mesh.vertices)
    cellnodes = np.array(
        [np.array(cell) for cell in mesh.connectivity.cells.nodes])
    print(cellnodes)
    vtkw.write_vtu(vtkw.vtu_doc(vertices, cellnodes), name + ".vtu")
    vtkw.write_vtu(
        vtkw.vtu_doc(fcenters, np.reshape(np.arange(fcenters.shape[0]),
                                          (-1, 1))),
        name + "_face_centers.vtu",
    )
Exemplo n.º 2
0
def dump_mesh(basename, vertices, cells, pointdata, facedata, celldata, fractures=None):
    assert all(np.asarray(a).shape == (vertices.shape[0],) for a in pointdata.values())
    assert all(np.asarray(a).shape == (cells.shape[0],) for a in celldata.values())
    vtkw.write_vtu(
        vtkw.vtu_doc(
            vertices, cells, pointdata=pointdata, celldata=celldata, ofmt="ascii"
        ),
        "mesh" + basename,
    )
    if facedata:
        assert "facecenters" in facedata
        face_centers = facedata["facecenters"]
        assert all(
            np.asarray(a).shape == (face_centers.shape[0],)
            for key, a in facedata.items()
            if key is not "facecenters"
        )
        vtkw.write_vtu(
            vtkw.points_as_vtu_doc(
                face_centers,
                pointdata={
                    name: value
                    for name, value in facedata.items()
                    if name != "facecenters"
                },
            ),
            "facedata" + basename + ".vtu",
        )
    if fractures is not None:
        vtkw.write_vtu(
            vtkw.vtu_doc(vertices, fractures), "frac_mesh" + basename + ".vtu",
        )
Exemplo n.º 3
0
Arquivo: mesh.py Projeto: BRGM/ComPASS
def dump_model(model, filename):
    mesh_arrays = [S.as_arrays() for S in model.surfaces()]
    nodes_offset = np.cumsum([0,] + [a[0].shape[0] for a in mesh_arrays])
    faces_offset = np.cumsum([0,] + [a[1].shape[0] for a in mesh_arrays])
    all_vertices = np.vstack([a[0] for a in mesh_arrays])
    all_faces = np.vstack(
        [a[1] + offset for a, offset in zip(mesh_arrays, nodes_offset[:-1])]
    )
    fault_id = np.zeros(all_faces.shape[0])
    for fi, t in enumerate(zip(faces_offset[:-1], faces_offset[1:])):
        fault_id[t[0] : t[1]] = fi
    vtkw.write_vtu(
        vtkw.vtu_doc(all_vertices, all_faces, celldata={"id": fault_id}), filename
    )
Exemplo n.º 4
0
def test_hexmesh():

    vertices, cells = GT.grid2hexs(shape=(3, 2, 4))

    cells = np.ascontiguousarray(cells, dtype=MT.idtype())

    mesh = MT.HexMesh.make(vertices, cells)

    vertices = MT.as_coordinate_array(mesh.vertices)
    cellnodes = np.array(
        [np.array(nodes) for nodes in mesh.connectivity.cells.nodes])

    vtkw.write_vtu(vtkw.vtu_doc(vertices, cellnodes), "hexs.vtu")

    try:
        import meshio

        meshio.read("hexs.vtu")
    except ModuleNotFoundError:
        pass
Exemplo n.º 5
0
def _dump_wells(simulation,
                well_type,
                outputdir=None,
                tag=None,
                verbose=False):
    if outputdir is None:
        outputdir = Path(".")
    else:
        outputdir = Path(outputdir)
    assert outputdir.exists() and outputdir.is_dir()
    info = _wells_info(simulation, well_type)
    if not _any_wells(info):
        return
    wells = info.information
    nb_own_wells = _check_own_wells(wells, info)
    if verbose:
        print(f"Dumping {info.nb_own} {info.type} wells out of {info.nb}.")
    wells_data = [data for data, _ in zip(info.data, range(nb_own_wells))]
    vertices = simulation.vertices()
    node_states = simulation.node_states()
    if len(set([data.id for data in wells_data])) != nb_own_wells:
        print("!!!")
        print(
            "!!! WARNING: you must use unique well id to discriminate output files"
        )
        print("!!!")
    for wk, well in enumerate(wells):
        if wk >= nb_own_wells:
            break
        # We want to keep only well vertices not all revervoir vertices
        well_vertices = well.vertices
        assert well_vertices.shape == np.unique(well_vertices).shape
        remap = np.zeros(vertices.shape[0], dtype=well_vertices.dtype)
        remap[well_vertices] = 1
        remap = np.cumsum(remap) - 1
        # FIXME: well.pressure has no real meaning for multiple phases (reference pressure ?)
        welldata = {
            name: np.ascontiguousarray(a)
            for name, a in [
                ("reservoir vertices id", well_vertices),
                ("well pressure", well.pressure),
                ("well temperature", K2degC(well.temperature)),
                ("well pressure drop", well.pressure_drop),
                ("well density", well.density),
                ("Darcy WI", well.well_index_Darcy),
                ("Fourier WI", well.well_index_Fourier),
                ("reservoir pressure", node_states.p[well_vertices]),
                ("reservoir temperature",
                 K2degC(node_states.T[well_vertices])),
                (
                    "inflow",
                    np.where(
                        well.pressure < node_states.p[well_vertices],
                        well.well_index_Darcy *
                        (node_states.p[well_vertices] - well.pressure),
                        0,
                    ),
                ),
            ]
        }
        try:
            welldata["well saturation pressure"] = np.ascontiguousarray(
                simulation.Psat(well.temperature))
        except AttributeError:
            pass
        try:
            welldata["well saturation temperature"] = np.ascontiguousarray(
                simulation.Tsat(well.pressure))
        except AttributeError:
            pass
        vtkw.write_vtu(
            vtkw.vtu_doc(
                vertices[well_vertices],
                np.hstack([
                    np.reshape(remap[well_vertices[:-1]], (-1, 1)),
                    np.reshape(remap[well.parent_vertex], (-1, 1)),
                ]),
                pointdata=welldata,
            ),
            str(outputdir / _well_vtu_filename(wells_data[wk].id, tag)),
        )
Exemplo n.º 6
0

def retrieve(filename, dtype):
    return np.loadtxt(os.path.join(dirname, filename), dtype=dtype)


vertices = retrieve("vertices", np.double)
cells = retrieve("cells", MT.idtype())
faces = retrieve("faces", MT.idtype())
fault_faces = retrieve("faces_fault", MT.idtype())
fault_faces_nodes = faces[fault_faces]

mesh = MT.tetmesh(vertices, cells)
fault_faces_id = mesh.faces_ids(fault_faces_nodes)

vtkw.write_vtu(vtkw.vtu_doc(vertices, cells), os.path.join(dirname, "mesh.vtu"))

ffcenters = mesh.face_centers(fault_faces_id)

vtkw.write_vtu(
    vtkw.vtu_doc(ffcenters, np.reshape(np.arange(ffcenters.shape[0]), (-1, 1))),
    os.path.join(dirname, "fault_faces_centers.vtu"),
)

fcenters = mesh.face_centers(mesh.faces_ids(faces))
patches = retrieve("patches", np.int)
assert fcenters.shape[0] == patches.shape[0]

vtkw.write_vtu(
    vtkw.vtu_doc(
        fcenters,