-
Notifications
You must be signed in to change notification settings - Fork 25
/
Copy pathmyPluginFunctions.py
254 lines (199 loc) · 10.3 KB
/
myPluginFunctions.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
from abaqusConstants import *
from abaqus import mdb, session
import odb, odbAccess, xyPlot, visualization
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
def showColor(myColor):
# Just for test
# Outputs a selection from a color wheel
a = myColor
print 'The color is: '
print a
return a
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
def showPickedNode(myNode):
# Just for test
# Outputs the node label of a selected node
print myNode.label
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
def getCombineOfNode(pickedNode):
# Creates a combine of logarithmic strain and Mises stress
# of a picked node in the Viewport
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
### Delete all created XYData
for i in session.xyDataObjects.keys():
del session.xyDataObjects[i]
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
### What are we looking at?
# Get the displayed ODB in current Viewport (must be in Visualisation):
vpName = session.currentViewportName
myViewport = session.viewports[vpName]
myODB = myViewport.displayedObject
# Get active nodes labels:
visibleNodes = myViewport.getActiveNodeLabels()
visibleElement = myViewport.getActiveElementLabels()
visiblePart = visibleNodes.keys()[0]
visibleElementIndex = visibleElement.values()[0][0] - 1 # Because index starts at 0
# Take only the one of the nodes:
#chosenNode = int(getInput('Which Node to take? \n ' + str(visibleNodes.values()[0])))
chosenNode = pickedNode.label
# Take the chosen node:
nodeTuples = ((visiblePart, tuple([chosenNode]) ), )
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
### Get Field Data
# Get section categories (if section integration points exist) for that specific element/node:
# Works only if other elements are hidden
visibleElementObject = myODB.rootAssembly.instances[visiblePart].elements[visibleElementIndex]
# If there are section points, choose the first section point:
if visibleElementObject.sectionCategory.sectionPoints:
mySection = {visibleElementObject.sectionCategory.name : visibleElementObject.sectionCategory.sectionPoints[0].description , }
else:
mySection = {}
fieldVar = (('S', INTEGRATION_POINT, ((INVARIANT, 'Mises' ), ), mySection), )
varField_stress = session.xyDataListFromField(odb=myODB, outputPosition=NODAL, variable=fieldVar, nodeLabels=nodeTuples )
fieldVar = (('LE', INTEGRATION_POINT, ((INVARIANT, 'Max. Principal (Abs)' ), ), mySection), )
varField_strain = session.xyDataListFromField(odb=myODB, outputPosition=NODAL, variable=fieldVar, nodeLabels=nodeTuples )
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
### Combine
# Arrange the data:
myCombine = []
for i in range(len(varField_strain[0])):
myCombine.append( (-varField_strain[0][i][1], varField_stress[0][i][1]) )
# Make the Combine:
session.XYData(data=myCombine, name='Combine-Stress-Strain-'+str(chosenNode), xValuesLabel='STRAIN', yValuesLabel='STRESS')
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
def getMinMaxViewport():
# Make an XYData of the shown Variables MAX and MIN in the Viewport
# Deformed state with the wanted variable must be activated!
###
from abaqusConstants import *
import odb
import odbAccess
import xyPlot
import visualization
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
### Delete all created XYData:
for i in session.xyDataObjects.keys():
del session.xyDataObjects[i]
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
### What are we looking at
# Get the displayed ODB in current Viewport (must be in Visualisation):
vpName = session.currentViewportName
myViewport = session.viewports[vpName]
myODB = myViewport.displayedObject # ! Can be an XYPLot!!!
shownVar = myViewport.odbDisplay.primaryVariable[0]
shownComponent = myViewport.odbDisplay.primaryVariable[5]
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
### Get the times (cumulative)
# Get a list of lists with times from 0 to end for each step:
times = [list(thisstep[8]) for thisstep in myViewport.odbDisplay.fieldSteps]
# Make an array that contains the nr of frames for each step:
framesInSteps = map(len,times)
# For steps>0 add the end time of the previous step to the times of the subsequent steps:
for stepnr in range(len(times)):
if stepnr>0:
times[stepnr] = [thisframe+times[stepnr-1][-1] for thisframe in times[stepnr]]
# Make everything to only one list:
times = [k for i in times for k in i]
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
### Go through each frame and extract the MIN and MAX
maxes = []
mins = []
for stepnr in range(len(framesInSteps)):
for framenr in range(framesInSteps[stepnr]): # Much faster if range is used instead of frame objects
myViewport.odbDisplay.setFrame(step=stepnr,frame=framenr)
maxes.append(myViewport.getPrimVarMinMaxLoc()['maxValue'])
mins.append(myViewport.getPrimVarMinMaxLoc()['minValue'])
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
### Make a XY Data of the extracted
# Zip the data together to tuples:
maxesData = zip(times,maxes)
minsData = zip(times,mins)
# Make the XY data for the Envelope:
session.XYData(data=maxesData,
name='Maximums-' + shownVar + '-' + shownComponent,
xValuesLabel='TIME')
#yValuesLabel='STRESS'
session.XYData(data=minsData,
name='Minimums-' + shownVar + '-' + shownComponent,
xValuesLabel='TIME')
#yValuesLabel='STRESS'
# Getting quantity types seems unbelievably hard in this programme...
# Could make a xyPlot of the current variable and then just extract the quantity type:
#print session.xyPlots['XYPlot-1'].curves['Minimums-S-S33'].data.axis1QuantityType.type
# Then I could copy that to the new XY Plots
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
def getMinMaxEnvelopeViewport():
# Takes the shown variables in the Viewport and creates envelopes
# of the MINs and MAXes at NODAL locations acros sall steps and frames
#
# Deformed state with the wanted variable must be activated!
# Only the visible elements are regarded!
# CPRESS and other variables that depend on parts cannot be ragarded!
###
from abaqusConstants import *
import odb
import odbAccess
import xyPlot
import visualization
from abaqus import maxEnvelope
from abaqus import minEnvelope
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
### Delete all created XYData
for i in session.xyDataObjects.keys():
del session.xyDataObjects[i]
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
### What are we looking at
# Get the displayed ODB in current Viewport (must be in Visualisation):
vpName = session.currentViewportName
myViewport = session.viewports[vpName]
myODB = myViewport.displayedObject # ! Can be an XYPLot!!!
shownVar = myViewport.odbDisplay.primaryVariable[0]
shownComponent = myViewport.odbDisplay.primaryVariable[5]
allowedComponents = myODB.steps.values()[0].frames[0].fieldOutputs[shownVar].componentLabels
allowedPosition = myODB.steps.values()[0].frames[0].fieldOutputs[shownVar].values[0].position
# Alternative:
#allowedPosition = myODB.steps.values()[0].frames[0].fieldOutputs[shownVar].locations[0].position
# But how do we get CENTROID etc?
# Get active nodes labels:
visibleNodes = myViewport.getActiveNodeLabels()
# Format nodes to a tuple to pass to function
nodeTuples = tuple([(part, tuple(visibleNodes[part])) for part in visibleNodes])
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
### Prepare the Field Data Format
# Set the wanted field Variable to component or invariant:
if shownComponent in allowedComponents:
fieldVar = ((shownVar,allowedPosition, ( (COMPONENT, shownComponent ), ), ), )
elif shownComponent=='':
fieldVar = ((shownVar,allowedPosition, ), )
else:
fieldVar = ((shownVar,allowedPosition, ( (INVARIANT, shownComponent ), ), ), )
varField = session.xyDataListFromField(odb=myODB, outputPosition=NODAL, variable=fieldVar, nodeLabels=nodeTuples )
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
### Output the data
# Get the Envelope:
myMaxEnveloppe = maxEnvelope(varField)
myMinEnveloppe = minEnvelope(varField)
# Make the XY data for the Envelope:
session.XYData(data=myMaxEnveloppe.data, name='MaxEnvelope-' + shownVar + '-' + shownComponent)
session.XYData(data=myMinEnveloppe.data, name='MinEnvelope-' + shownVar + '-' + shownComponent)
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
def getCombineUserInput(firstVar, secondVar):
# TODO!
# User chooses variables (depending on which exists)
# Then make a combine of it
return 0
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
def getMinMaxEnvelopeUserInnput(firstVar, secondVar):
# TODO!
# User chooses variables (depending on which exists)
# Then make min max envelopes of it
return 0
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~