-
Notifications
You must be signed in to change notification settings - Fork 2
/
Visualization.py
146 lines (117 loc) · 5.66 KB
/
Visualization.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
from abaqus import *
from abaqusConstants import *
import displayGroupOdbToolset as dgo
import os
import numpy as np
class main_tools(object):
def __init__(self, jobName, partName, instanceName, modelName, mdb, session, viewportObj1 = 'Viewport: 1'):
self.jobName = jobName
self.odbName = jobName + '.odb'
self.partName = partName
self.modelName = modelName
self.instanceName = instanceName
self.mdb = mdb
self.session = session
self.viewportObj1 = self.session.viewports[viewportObj1]
def job_submit(self, jobName):
FirstJob = self.mdb.jobs[jobName]
FirstJob.submit(consistencyChecking=OFF)
FirstJob.waitForCompletion()
def open_odb(self, odbName, readOnly = True):
try:
return self.session.openOdb(name = odbName, readOnly = readOnly)
except:
import time; time.sleep(5)
print 'open_odb() did not work.'
return self.session.openOdb(name = odbName, readOnly = readOnly)
def close_odb(self, odbName = ''):
if odbName == '': odbName = self.odbName
try:
self.session.odbs[odbName].close()
except:
print 'close_odb did not work.'
def save_and_close_odb(self, odbObj):
odbObj.save()
odbObj.close()
def output_values(self, odb, stepName = 'Main', frameNum = -1, parameterName = 'SDV3'):
return odb.steps[stepName].frames[frameNum].fieldOutputs[parameterName].values
def edit_node_by_offset(self ,offsetPars):
self.mdb.meshEditOptions.setValues(enableUndo=True, maxUndoCacheElements=0.5)
partObj = self.mdb.models[self.modelName].parts[self.partName]
nodeObj = partObj.nodes
num = 0
for i in offsetPars:
num += 1
if num % 3 == 1:
nodes = i - 1
elif num % 3 == 2:
u1 = i
elif num % 3 == 0:
u2 = i
partObj.editNode(nodes=nodeObj[nodes], offset1=-u1, offset2=-u2, projectToGeometry=OFF)
def extract_coords_values(self, frameNum = -1, stepName = 'Main', odb = ''):
if odb == '': odb = self.open_odb(self.odbName)
temp = []
dispVal = self.output_values(odb, stepName, frameNum, 'COORD')
for s in dispVal:
temp.append(s.nodeLabel)
temp.append(s.dataDouble[0])
temp.append(s.dataDouble[1])
return temp
def extract_nodal_values(self, frameNum = -1, stepName = 'Main', odb = ''):
if odb == '': odb = self.open_odb(self.odbName)
temp = []
dispVal = self.output_values(odb, stepName, frameNum, 'COORD')
for s in dispVal:
temp.append(s.nodeLabel)
temp.append(s.dataDouble[0])
temp.append(s.dataDouble[1])
return temp
def integration_points_values(self, parameters = ['LE22'], frameNum = -1, stepName = 'UC', odb = ''):
if odb == '': odb = self.open_odb(self.odbName)
temp = []
for sdv in parameters:
temp.append([])
outputValues = self.output_values(odb, stepName, frameNum, sdv)
for outputVal in outputValues:
temp[-1].append([outputVal.data, outputVal.elementLabel, outputVal.integrationPoint])
return temp
os.chdir(r"C:\temp\HybridML")
FileName = 'Open_knee_native'
openMdb(pathName = FileName + '.cae')
jobName, partName, instanceName, modelName = 'Job-1', 'femur_cartilage', 'femur_cartilage-1', 'OpenKnee_model'
modelObj = mdb.models[modelName]
mt = main_tools(jobName, partName, instanceName, modelName, mdb, session) # main tools of Abaqus
odb = mt.open_odb(mt.odbName, readOnly = False)
viewportObj = session.viewports['Viewport: 1']
viewportObj.setValues(displayedObject=odb)
viewportObj.makeCurrent()
viewportObj.viewportAnnotationOptions.setValues(triad=OFF, legend=OFF, title=OFF, state=OFF, annotations=OFF, compass=OFF)
# START OF AUTOMATICALLY GENERATED PYTHON CODE
path = "temp_temp"
# END OF AUTOMATICALLY GENERATED PYTHON CODE
data = np.loadtxt(path, delimiter=",", dtype='float32').reshape(-1,1)
odbInstance = odb.rootAssembly.instances['PART-1-1']
region = odbInstance.nodeSets['TIBIA_CARTILAGE_MED-1__PICKEDSET26']
Sarrays = odb.steps['LOAD'].frames[-1].fieldOutputs['S'].getSubset(region = region, position = ELEMENT_NODAL).values
region = [i.nodeLabel for i in Sarrays]
name = 'temp_%s'%(np.random.random())
newFieldOutput = odb.steps['LOAD'].frames[0].FieldOutput(name=name, description='', type=SCALAR)
newFieldOutput.addData(position=NODAL, instance=odbInstance, labels=region, data=data)
mt.save_and_close_odb(odb)
odb = mt.open_odb(mt.odbName)
viewportObj = session.viewports['Viewport: 1']
viewportObj.setValues(displayedObject=odb)
viewportObj.odbDisplay.display.setValues(plotState=(CONTOURS_ON_DEF, ))
leaf = dgo.LeafFromElementSets(elementSets=('PART-1-1.TIBIA_CARTILAGE_MED-1__PICKEDSET26', ))
viewportObj.odbDisplay.displayGroup.replace(leaf=leaf)
viewportObj.view.setValues(cameraPosition=(85.8183, 423.226, 45.6801), cameraUpVector=(0, 0, 1))
viewportObj.odbDisplay.contourOptions.setValues(maxAutoCompute=OFF, maxValue=2, minAutoCompute=OFF, minValue=0)
viewportObj.view.fitView()
viewportObj.odbDisplay.contourOptions.setValues(outsideLimitsMode=SPECTRUM)
viewportObj.odbDisplay.setFrame(step=0, frame=0)
viewportObj.setValues(displayedObject=odb)
viewportObj.odbDisplay.setPrimaryVariable(variableLabel=name, outputPosition=NODAL)
session.pngOptions.setValues(imageSize=(4000, 2536))
session.printOptions.setValues(reduceColors=False)
session.printToFile(fileName='%s'%(path), format=PNG, canvasObjects=(viewportObj, ))