-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathUdetermineVolume.py
57 lines (51 loc) · 1.71 KB
/
UdetermineVolume.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
# -*- coding: utf-8 -*-
from abaqus import *
import time
def determineVolume(model_name, part_name, macro_model_dimension, nSG):
part = mdb.models[model_name].parts[part_name]
nodes = part.nodes
WstartTime = time.clock()
geo_info = part.queryGeometry()
if geo_info['category'] == 'OrphanMesh':
nodeX = []
nodeY = []
nodeZ = []
for n in range(0, len(nodes)):
nodeX.append(nodes[n].coordinates[0])
nodeY.append(nodes[n].coordinates[1])
nodeZ.append(nodes[n].coordinates[2])
if max(nodeZ) == 0:
raise ValueError('Please mesh the part!')
LX = max(nodeX) - min(nodeX)
LY = max(nodeY) - min(nodeY)
LZ = max(nodeZ) - min(nodeZ)
elif geo_info['category'] == 'Geometry':
boundbox = geo_info['boundingBox']
LX = boundbox[1][0] - boundbox[0][0]
LY = boundbox[1][1] - boundbox[0][1]
LZ = boundbox[1][2] - boundbox[0][2]
if macro_model_dimension == '3D':
if nSG == 1:
volume = LZ
elif nSG == 2:
volume = LY * LZ
elif nSG == 3:
volume = LX * LY * LZ
elif macro_model_dimension == '2D':
if nSG == 3:
volume = LX * LY
elif nSG == 2:
volume = LY
elif nSG == 1:
volume = 1
elif macro_model_dimension == '1D':
if nSG == 3:
volume = LX
elif nSG == 2:
volume = 1
elif nSG == 1:
raise TypeError (' Wire model cannot be used for beam analysis! ')
WendTime = time.clock()
WTime = WendTime - WstartTime
#print 'Time for calculate w: %s' % str(WTime)
return volume