Created
March 18, 2015 10:44
-
-
Save mhogg/5b0c0eb014a9eb3dfe61 to your computer and use it in GitHub Desktop.
Gets element face connectivity
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
root = r'D:\temp' | |
m = mdb.models['Model-1'] | |
a = m.rootAssembly | |
p = m.parts['Part-1'] | |
elements = p.elements | |
foutName = 'eConn2.txt' | |
npFace = 3 # Number of nodes per face. If using C3D4 elems, this will be 3 | |
# Get element connectivity (elements connect to nodes) | |
elemConn = {} | |
for elem in elements: | |
e = elem.label | |
nconn = elem.connectivity | |
for n in nconn: | |
if not elemConn.has_key(n): | |
elemConn[n] = [] | |
elemConn[n].append(e) | |
# Now get list of all neighbouring elements for each element | |
# Use the dictionary value to tally how many nodes are shared. If this | |
# number is equal to the number of nodes per face, then faces must also | |
# be shared | |
elemNbr = {} | |
for elem in elements: | |
e = elem.label | |
nconn = elem.connectivity | |
if not elemNbr.has_key(e): | |
elemNbr[e] = {} | |
for n in nconn: | |
for ec in elemConn[n]: | |
if not elemNbr[e].has_key(ec): | |
elemNbr[e][ec] = 1 | |
else: | |
elemNbr[e][ec] += 1 | |
# Delete element label from its own list of neighbours. Also delete key if | |
# number of nodes is not equal to npFace | |
for k1 in elemNbr.keys(): | |
del elemNbr[k1][k1] | |
for k2,v2 in elemNbr[k1].items(): | |
if v2!=npFace: | |
del elemNbr[k1][k2] | |
elemNbr[k1] = elemNbr[k1].keys() | |
# Print to a file | |
fout = open(os.path.join(root,foutName),'w') | |
for k,v in sorted(elemNbr.items()): | |
fout.write('%10d%s\n' % (k, "".join(['%10d' % (i) for i in v]))) | |
fout.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment