abaqusImportTest.py
You can view and download this file on Github: abaqusImportTest.py
1#+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2# This is an EXUDYN example
3#
4# Details: Test for FEMinterface with different ABAQUS files;
5# also test if store/load for FEMinterface and ObjectFFRFreducedOrderInterface works
6#
7# Author: Johannes Gerstmayr
8# Date: 2020-05-13
9#
10# Copyright:This file is part of Exudyn. Exudyn is free software. You can redistribute it and/or modify it under the terms of the Exudyn license. See 'LICENSE.txt' for more details.
11#
12#+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
13
14import exudyn as exu
15from exudyn.utilities import * #includes itemInterface and rigidBodyUtilities
16import exudyn.graphics as graphics #only import if it does not conflict
17from exudyn.FEM import *
18
19useGraphics = True #without test
20#+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
21#you can erase the following lines and all exudynTestGlobals related operations if this is not intended to be used as TestModel:
22try: #only if called from test suite
23 from modelUnitTests import exudynTestGlobals #for globally storing test results
24 useGraphics = exudynTestGlobals.useGraphics
25except:
26 class ExudynTestGlobals:
27 pass
28 exudynTestGlobals = ExudynTestGlobals()
29#+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
30
31useGraphics=False
32
33import numpy as np
34import time
35import sys
36
37#%%+++++++++++++++++++++++++++++++++++++++++++++++++++++
38#Use FEMinterface to import FEM model and create FFRFreducedOrder object
39fileDir = 'testData/abaqus/block'
40result = 0
41
42elements = ['C3D4','C3D10','C3D8','C3D20','C3D20R']
43#elements = ['C3D8']
44
45for element in elements:
46 SC = exu.SystemContainer()
47 mbs = SC.AddSystem()
48
49 fem = FEMinterface()
50 inputFileName = fileDir+element
51 nodes=fem.ImportFromAbaqusInputFile(inputFileName+'.inp', typeName='Instance', name='rotor-1')
52
53 fem.ReadMassMatrixFromAbaqus(inputFileName+'_MASS1.mtx')
54 fem.ReadStiffnessMatrixFromAbaqus(inputFileName+'_STIF1.mtx')
55 if True:
56 fn = 'solution/testFEM'
57 fem.SaveToFile(fn)
58 fem = FEMinterface()
59 fem.LoadFromFile(fn)
60
61 if False:
62 exu.Print('size of nodes:', sys.getsizeof(np.array(fem.nodes['Position'])) )
63 exu.Print('size of elements:', sys.getsizeof(fem.elements[0]) )
64 exu.Print('size of massMatrix:', sys.getsizeof(fem.massMatrix) )
65 exu.Print('size of stiffnessMatrix:', sys.getsizeof(fem.stiffnessMatrix) )
66 exu.Print('size of modeBasis:', sys.getsizeof(fem.modeBasis) )
67 #print('size of postProcessingModes:', sys.getsizeof(fem.postProcessingModes['matrix']) )
68 exu.Print('===================')
69
70 nModes = 5 #use 2,5,6,7 or 9 but not 8, as in case that symmetric modes are swapped (in Hex case), solution is completely different
71
72 pLeft = [0,0,0]
73 pLeftMid = [0,0.5,0.5]
74 pRight = [4,0,0]
75 nTip = fem.GetNodeAtPoint(pRight) #tip node (do not use midpoint, as this may not be a mesh node ...)
76
77 nodesLeftPlane = fem.GetNodesInPlane(pLeft, [-1,0,0])
78 weightsLeftPlane = fem.GetNodeWeightsFromSurfaceAreas(nodesLeftPlane)
79
80 nodesRightPlane = fem.GetNodesInPlane(pRight, [-1,0,0])
81 weightsRightPlane = fem.GetNodeWeightsFromSurfaceAreas(nodesRightPlane)
82
83 boundaryList = [nodesLeftPlane]
84
85 if useGraphics:
86 exu.Print("nNodes=",fem.NumberOfNodes())
87 exu.Print("compute HCB modes... ")
88 start_time = time.time()
89 fem.ComputeHurtyCraigBamptonModes(boundaryNodesList=boundaryList,
90 nEigenModes=nModes,
91 useSparseSolver=False, #sparse solver gives non-repeatable results ...
92 computationMode = HCBstaticModeSelection.RBE2)
93
94 if useGraphics:
95 exu.Print("HCB modes needed %.3f seconds" % (time.time() - start_time))
96
97 cms = ObjectFFRFreducedOrderInterface(fem)
98 if True: #try save/load
99 fn = 'solution/testCMS'
100 cms.SaveToFile(fn)
101 cms = ObjectFFRFreducedOrderInterface()
102 cms.LoadFromFile(fn)
103
104 if False: #check size of objects
105 for key in cms.__dict__:
106 exu.Print('size of ', key, ':', sys.getsizeof(cms.__dict__[key]) )
107
108 objFFRF = cms.AddObjectFFRFreducedOrder(mbs, positionRef=[0,0,0],
109 initialVelocity=[0,0,0],
110 initialAngularVelocity=[0,0,0],
111 gravity=[0,-9.81,0],
112 color=[0.1,0.9,0.1,1.])
113
114 #%%+++++++++++++++++++++++++++++++++++++++++++++++++++++
115 #add markers and joints
116 nodeDrawSize = 0.0025 #for joint drawing
117
118 mRB = mbs.AddMarker(MarkerNodeRigid(nodeNumber=objFFRF['nRigidBody']))
119 oGround = mbs.AddObject(ObjectGround(referencePosition= [0,0,0]))
120
121 mGroundPosLeft = mbs.AddMarker(MarkerBodyRigid(bodyNumber=oGround, localPosition=pLeftMid))
122 mLeft = mbs.AddMarker(MarkerSuperElementRigid(bodyNumber=objFFRF['oFFRFreducedOrder'],
123 meshNodeNumbers=np.array(nodesLeftPlane), #these are the meshNodeNumbers
124 weightingFactors=weightsLeftPlane))
125
126
127
128 mbs.AddObject(GenericJoint(markerNumbers=[mGroundPosLeft, mLeft], constrainedAxes=[1,1,1, 1,1,1]))
129
130 #%%+++++++++++++++++++++++++++++++++++++++++++++++++++++
131 sDisp=mbs.AddSensor(SensorSuperElement(bodyNumber=objFFRF['oFFRFreducedOrder'], meshNodeNumber=nTip, #meshnode number!
132 storeInternal=True,
133 outputVariableType = exu.OutputVariableType.DisplacementLocal))
134
135 mbs.Assemble()
136
137 simulationSettings = exu.SimulationSettings()
138
139 # SC.visualizationSettings.nodes.defaultSize = nodeDrawSize
140 SC.visualizationSettings.nodes.drawNodesAsPoint = False
141 SC.visualizationSettings.bodies.deformationScaleFactor = 1e4 #use this factor to scale the deformation of modes
142
143 SC.visualizationSettings.loads.drawSimplified = False
144
145 SC.visualizationSettings.contour.outputVariable = exu.OutputVariableType.DisplacementLocal
146 SC.visualizationSettings.contour.outputVariableComponent = 1 #y-component
147
148 # simulationSettings.solutionSettings.solutionInformation = "ObjectFFRFreducedOrder test"
149
150 h=1e-4
151 tEnd = 5e-3 #at almost max. of deflection under gravity
152
153 simulationSettings.timeIntegration.numberOfSteps = int(tEnd/h)
154 simulationSettings.timeIntegration.endTime = tEnd
155 simulationSettings.solutionSettings.solutionWritePeriod = h
156 simulationSettings.timeIntegration.verboseMode = useGraphics
157 #simulationSettings.timeIntegration.verboseModeFile = 3
158 simulationSettings.timeIntegration.newton.useModifiedNewton = True
159
160 simulationSettings.solutionSettings.sensorsWritePeriod = h
161 simulationSettings.solutionSettings.coordinatesSolutionFileName = "solution/coordinatesSolutionCMStest.txt"
162 simulationSettings.solutionSettings.writeSolutionToFile=False
163
164 simulationSettings.timeIntegration.generalizedAlpha.spectralRadius = 0.5 #SHOULD work with 0.9 as well
165
166 if useGraphics:
167 exu.StartRenderer()
168 if 'renderState' in exu.sys: SC.SetRenderState(exu.sys['renderState']) #load last model view
169
170 mbs.WaitForUserToContinue() #press space to continue
171
172 mbs.SolveDynamic(simulationSettings)
173
174 # data = np.loadtxt(fileDir+'nMidDisplacementCMS'+str(nModes)+'Test.txt', comments='#', delimiter=',')
175 data = mbs.GetSensorStoredData(sDisp)
176 exu.Print('u-tip for '+element+' = ', data[-1,1:], ', nNodes=',fem.NumberOfNodes())
177 result += abs(data[-1,1:]).sum()
178
179 if useGraphics:
180 SC.WaitForRenderEngineStopFlag()
181 exu.StopRenderer() #safely close rendering window!
182 lastRenderState = SC.GetRenderState() #store model view for next simulation
183
184exu.Print('solution of abaqusImportTest=',result)
185
186exudynTestGlobals.testError = (result - (0.0005885208722206333))
187exudynTestGlobals.testResult = result
188
189#for small meshes in TestModels:
190# u-tip for C3D4 = [-1.39753280e-05 -8.83250776e-05 9.86454888e-07] , nNodes= 214
191# u-tip for C3D10 = [-1.73664007e-05 -1.04237155e-04 1.86678663e-10] , nNodes= 257
192# u-tip for C3D8 = [-1.70545446e-05 -1.03215074e-04 6.31348275e-08] , nNodes= 176
193# u-tip for C3D20 = [-1.72124324e-05 -1.04326514e-04 -9.10211089e-11] , nNodes= 171
194# u-tip for C3D20R = [-1.72278715e-05 -1.04863540e-04 5.83371018e-08] , nNodes= 171
195
196#for larger files (see Experimental folder):
197# u-tip for C3D4 = [-1.39753280e-05 -8.83250776e-05 9.86454888e-07] , nNodes= 214
198# u-tip for C3D10 = [-1.74686596e-05 -1.05689104e-04 5.05186882e-08] , nNodes= 1332
199# u-tip for C3D8 = [-1.72150782e-05 -1.03377335e-04 4.39361119e-08] , nNodes= 176
200# u-tip for C3D20 = [-1.74978842e-05 -1.05476601e-04 -1.35045610e-08] , nNodes= 600
201# u-tip for C3D20R = [-1.72957461e-05 -1.05412212e-04 5.01834245e-08] , nNodes= 600