Esempio 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",
    )
Esempio n. 2
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(
Esempio n. 3
0
import numpy as np
import MeshTools as MT
import GridTools as GT
import vtkwriters as vtkw

vertices, cells = GT.grid2hexs((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")
Esempio n. 4
0
    vertices[j * nr:(j + 1) * nr, 1] = y[0]
for k, yk in enumerate(y[1:]):
    vertices[(k + 1) * (nr * ntheta):(k + 2) *
             (nr * ntheta)] = vertices[k * (nr * ntheta):(k + 1) *
                                       (nr * ntheta)]
    vertices[(k + 1) * (nr * ntheta):(k + 2) * (nr * ntheta), 1] = yk

ncr, ncth, ncy = nr - 1, nsectors, nslices
ncells = ncr * ncth * ncy
cells = np.zeros((ncells, 8), dtype=MT.idtype())

tmp = np.arange(ncr)
cells[:ncr, 0] = tmp
cells[:ncr, 1] = tmp + 1
cells[:ncr, 2] = tmp + 1 + nr
cells[:ncr, 3] = tmp + nr
for j in range(1, ncth - 1):
    cells[j * ncr:(j + 1) * ncr, :4] = cells[(j - 1) * ncr:j * ncr, :4] + nr
cells[(ncth - 1) * ncr:ncth * ncr, :2] = cells[(ncth - 2) * ncr:(ncth - 1) *
                                               ncr, 3:1:-1]
cells[(ncth - 1) * ncr:ncth * ncr, 2:4] = cells[:ncr, 1::-1]
cells[:(ncr * ncth), 4:] = cells[:(ncr * ncth), :4] + nr * ntheta
for k in range(1, ncy):
    cells[k * (ncr * ncth):(k + 1) *
          (ncr * ncth), :] = (cells[(k - 1) * (ncr * ncth):k *
                                    (ncr * ncth), :] + nr * ntheta)

mesh = MT.hexmesh(vertices, cells)

vtkw.write_vtu(vtkw.vtu_doc(mesh.vertices, mesh.cellnodes), "andra.vtu")
Esempio n. 5
0
mesh = MT.TetMesh.make(vertices, MT.idarray(tets))

print("Nb vertices:", mesh.nb_vertices)
print("Nb cells:", mesh.nb_cells)
print("Nb faces:", mesh.nb_faces)


def print_collection(iterable):
    for item in iterable:
        print(item)


print("Vertices")
print_collection(mesh.vertices)
print("Cell face")
print_collection(mesh.connectivity.cells.faces)
print("Cell nodes")
print_collection(mesh.connectivity.cells.nodes)
print("Face nodes")
print_collection(mesh.connectivity.faces.nodes)

print("All cell centers:")
print_collection(mesh.cell_centers())

vtkw.write_vtu(
    vtkw.vtu_doc(vertices,
                 tets,
                 celldata={"id": np.arange(1, tets.shape[0] + 1)}),
    "cubes.vtu",
)
Esempio n. 6
0
import numpy as np
import vtkwriters as vtkw

vertices = np.array([
    [0, 0, 0],
    [1, 0, 0],
    [1, 1, 0],
    [0, 1, 0],
], dtype="d")
triangles = np.array([
    [0, 1, 2],
    [0, 2, 3],
], dtype="i")

vtkw.write_vtu(
    vtkw.vtu_doc(
        vertices,
        triangles,
        celldata={"cell property": np.arange(2)},
        fielddata={"color": (0, 255, 0)},  # green
    ),
    "two_triangles",
)
Esempio n. 7
0
import vtkwriters as vtkw
import gmsh_reader

filename = "case-tests/andra/andra_gallery.msh"

nodes, elements = gmsh_reader.retrieve_mesh_elements(filename)

# select heaxedra only
hexaedra = [elt for elt, tags in elements if type(elt) is MT.Hexahedron]
mesh = MT.HexMesh.create(nodes, hexaedra)

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), filename.replace(".msh", "_hexaedra_only.vtu")
)

# filter out 2D elements
elements_3D = [
    (elt, tags)
    for elt, tags in elements
    if type(elt) in (MT.Tetrahedron, MT.Wedge, MT.Hexahedron)
]

mesh = MT.HybridMesh.create(nodes, [elt for elt, tags in elements_3D])
physical = np.array([tags[0] for elt, tags in elements_3D])

offsets, cellnodes = mesh.cells_nodes_as_COC()

vtkw.write_vtu(