-
Notifications
You must be signed in to change notification settings - Fork 3
/
getElemCent.py
60 lines (45 loc) · 1.68 KB
/
getElemCent.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#USE THIS ONE - ayushi
def getElemCent():
import numpy as np
import datetime
from dictionary import thisdict
###############################
###### USER INPUTS #########
###############################
# input deck name without .inp (i.e., the output of this script)
deckName = thisdict["deckName"]
###############################
###### LOAD FILES #########
###############################
#abaqus output files
elcentFile = deckName + '-ElemCent.inp'
fileOutput = open(elcentFile ,'w')
# node file name (from getElsetNode getElsetNodesElems.py, getNlNodesElems.py)
nodeFile = 'nlNodes.inp'
# element file name
elementFile = 'nlElements.inp'
## Open input files
nodes = np.loadtxt(nodeFile,delimiter=',')
elements = np.loadtxt(elementFile,delimiter=',',dtype=int)
numNodes = nodes.shape[0]
print ('Number of Nodes: ' + str(numNodes))
numElements = elements.shape[0]
nodesPerElem = elements.shape[1] - 1
print ('Number of Elements: ' + str(numElements))
print ('Number of Nodes per Elements: ' + str(nodesPerElem))
for e in range(numElements):
ind = elements[e,1:10]
nodesInElem = nodes[ind-1,1:4]
xCent = 0.0
yCent = 0.0
zCent = 0.0
for i in range(nodesPerElem):
xyz = nodesInElem[i]
xCent = xCent + xyz[0]
yCent = yCent + xyz[1]
zCent = zCent + xyz[2]
xCent = xCent/nodesPerElem
yCent = yCent/nodesPerElem
zCent = zCent/nodesPerElem
fileOutput.write(str(e+1) + ', ' + str(xCent) + ', ' + str(yCent) + ', ' + str(zCent) + '\n')
fileOutput.close()