Skip to content

Instantly share code, notes, and snippets.

@mhogg
Created March 17, 2015 05:42
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mhogg/b0481d842253d12bb41d to your computer and use it in GitHub Desktop.
Save mhogg/b0481d842253d12bb41d to your computer and use it in GitHub Desktop.
Getting ABAQUS element connectivities
from abaqus import *
from abaqusConstants import *
from odbAccess import *
odb = session.viewports[session.currentViewportName].displayedObject
instName = 'MALE'
elements = odb.rootAssembly.instances[instName].elements
foutName = 'elementConnectivity.txt'
# 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
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]:
elemNbr[e][ec] = 1
# Delete element label from its keys of neighbours and convert to a list
for k in elemNbr.keys():
del elemNbr[k][k]
elemNbr[k] = elemNbr[k].keys()
# Print to a file
fout = open(foutName,'w')
for k,v in sorted(elemNbr.items()):
fout.write('%10d%s\n' % (k, "".join(['%10d' % (i) for i in v])))
fout.close()
@Sechnarr
Copy link

Hi, i have a question, what is there in elemConn?
I thought element number as a key and the connected nodes as a values, is this correct?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment