Code: Select all
├── meshes
│ └── 1
│ ├── nodes
│ │ ├── zoneTopology
│ │ │ ├── id (1)
│ │ │ ├── dimension (1)
│ │ │ ├── maxId (1)
│ │ │ ├── minId (1)
│ │ │ ├── name (1)
│ │ │ ├── zoneType (1)
│ │ │ └── fields (1)
│ │ └── coords
│ │ └── 1 (418030)
│ ├── faces
│ │ ├── zoneTopology
│ │ │ ├── id (5)
│ │ │ ├── dimension (5)
│ │ │ ├── maxId (5)
│ │ │ ├── minId (5)
│ │ │ ├── name (1)
│ │ │ ├── childZoneId (5)
│ │ │ ├── faceType (5)
│ │ │ ├── shadowZoneId (5)
│ │ │ ├── zoneType (5)
│ │ │ └── fields (1)
│ │ ├── nodes
│ │ │ ├── 1
│ │ │ │ ├── nnodes (12193)
│ │ │ │ └── nodes (24386)
│ │ │ ├── 2
│ │ │ │ ├── nnodes (36)
│ │ │ │ └── nodes (72)
│ │ │ ├── 3
│ │ │ │ ├── nnodes (20)
│ │ │ │ └── nodes (40)
│ │ │ ├── 4
│ │ │ │ ├── nnodes (19)
│ │ │ │ └── nodes (38)
│ │ │ └── 5
│ │ │ ├── nnodes (985700)
│ │ │ └── nodes (1971400)
│ │ ├── c1
│ │ │ ├── 1 (12193)
│ │ │ ├── 2 (36)
│ │ │ ├── 3 (20)
│ │ │ ├── 4 (19)
│ │ │ └── 5 (985700)
│ │ └── c0
│ │ ├── 1 (12193)
│ │ ├── 2 (36)
│ │ ├── 3 (20)
│ │ ├── 4 (19)
│ │ └── 5 (985700)
│ └── cells
│ ├── zoneTopology
│ │ ├── id (1)
│ │ ├── dimension (1)
│ │ ├── maxId (1)
│ │ ├── minId (1)
│ │ ├── name (1)
│ │ ├── cellType (1)
│ │ ├── childZoneId (1)
│ │ └── fields (1)
│ └── ctype
│ └── 1
│ └── cell-types (579936)
└── settings
├── Cortex Variables (1)
├── Origin (1)
├── Solver (1)
├── Thread Variables (1)
└── Version (1)
Code: Select all
mesh_filepath = r'...'
with h5py.File(mesh_filepath, 'r') as h5file:
node_coordinates = np.array(h5file['meshes/1/nodes/coords/1'])
< /code>
Ich erstelle dann ein Numpy -Array, um die Verbindungen zwischen jedem Knoten basierend auf ihren Indizes im Netz zu speichern: < /p>
faces_nodes_group = h5file['meshes/1/faces/nodes']
nodes_connectivity = []
for key in faces_nodes_group.keys():
nodes = faces_nodes_group[key]['nodes'][:]
nodes = nodes.reshape(-1, 2)
nodes_connectivity.append(nodes)
nodes_connectivity = np.vstack(nodes_connectivity)
Code: Select all
num_mesh_nodes = nodes_connectivity.max() + 1
row, col = nodes_connectivity[:, 0] - 1, nodes_connectivity[:, 1] - 1
adjacency_matrix = sp.coo_matrix((np.ones(len(row)), (row, col)), shape=(num_mesh_nodes, num_mesh_nodes))
adjacency_matrix += adjacency_matrix.T
< /code>
Schließlich zeichne ich ein Networkx -Diagramm, um das Ergebnis zu visualisieren: < /p>
G = nx.Graph()
row, col = adjacency_matrix.nonzero()
edges = list(zip(row, col))
G.add_edges_from(edges)
pos = {i: coord for i, coord in enumerate(node_coordinates)}
nx.draw(G, pos, node_size=5)
plt.show()
< /code>
Dies funktioniert völlig in Ordnung und zeigt den Diagramm genau, wie das Netz aussehen soll. Ich muss jedoch aufgrund von Komplikationen bei einem anderen Projekt eine Reihe von Knoten aus dem Netzwerk entfernen, aber ich konnte es nicht zum Laufen bringen. Immer wenn ich versuche, Verbindungen in nodes_connektivität zu entfernen
Code: Select all
# Removing nodes that are too close or far from some boundary coordinates
tree = scipy.spatial.KDTree(boundary_coordinates)
distances, _ = tree.query(node_coordinates)
indices_to_keep = np.where(
np.logical_and(min_dist