Skip to content

Instantly share code, notes, and snippets.

@jkfurtney
Created May 5, 2022 14:00
Show Gist options
  • Save jkfurtney/5744c6d6815dd190831beb9c3b60efc7 to your computer and use it in GitHub Desktop.
Save jkfurtney/5744c6d6815dd190831beb9c3b60efc7 to your computer and use it in GitHub Desktop.
import itasca as it
it.command("python-reset-state false")
import numpy as np
from itasca import zonearray as za
zid = za.ids()
zz_faces = set()
for i, neighbors in enumerate(za.neighbors()):
this_zone_id = zid[i]
for n in neighbors:
if n != -1:
neighbor_id = zid[n]
zz_faces.add((min(this_zone_id, neighbor_id), max(this_zone_id, neighbor_id)))
attach_connections = set()
for a in it.attach.list():
gp = a.follower()
follower_zones = set(map(lambda x: x.id(), gp.zones()))
master_zones = set()
for mgp in a.leader():
if mgp is not None:
for z in mgp.zones():
master_zones.add(z.id())
for fz in follower_zones:
for mz in master_zones:
attach_connections.add((min(fz, mz), max(fz, mz)))
ca = np.array(list(zz_faces)+list(attach_connections))
np.save("zzcon3.npy", ca)
import numpy as np
import networkx as nx
connections = np.load('zzcon3.npy')
cc = list(nx.connected_components(nx.from_edgelist(connections)))
for c in cc:
print("this FLAC3D model has", len(c), "connected components")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment