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
59 if np.__version__ <= '2.0': #load save does not work yet!
60 fem = FEMinterface()
61 fem.LoadFromFile(fn)
62
63 if False:
64 exu.Print('size of nodes:', sys.getsizeof(np.array(fem.nodes['Position'])) )
65 exu.Print('size of elements:', sys.getsizeof(fem.elements[0]) )
66 exu.Print('size of massMatrix:', sys.getsizeof(fem.massMatrix) )
67 exu.Print('size of stiffnessMatrix:', sys.getsizeof(fem.stiffnessMatrix) )
68 exu.Print('size of modeBasis:', sys.getsizeof(fem.modeBasis) )
69 #print('size of postProcessingModes:', sys.getsizeof(fem.postProcessingModes['matrix']) )
70 exu.Print('===================')
71
72 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
73
74 pLeft = [0,0,0]
75 pLeftMid = [0,0.5,0.5]
76 pRight = [4,0,0]
77 nTip = fem.GetNodeAtPoint(pRight) #tip node (do not use midpoint, as this may not be a mesh node ...)
78
79 nodesLeftPlane = fem.GetNodesInPlane(pLeft, [-1,0,0])
80 weightsLeftPlane = fem.GetNodeWeightsFromSurfaceAreas(nodesLeftPlane)
81
82 nodesRightPlane = fem.GetNodesInPlane(pRight, [-1,0,0])
83 weightsRightPlane = fem.GetNodeWeightsFromSurfaceAreas(nodesRightPlane)
84
85 boundaryList = [nodesLeftPlane]
86
87 if useGraphics:
88 exu.Print("nNodes=",fem.NumberOfNodes())
89 exu.Print("compute HCB modes... ")
90 start_time = time.time()
91 fem.ComputeHurtyCraigBamptonModes(boundaryNodesList=boundaryList,
92 nEigenModes=nModes,
93 useSparseSolver=False, #sparse solver gives non-repeatable results ...
94 computationMode = HCBstaticModeSelection.RBE2)
95
96 if useGraphics:
97 exu.Print("HCB modes needed %.3f seconds" % (time.time() - start_time))
98
99 cms = ObjectFFRFreducedOrderInterface(fem)
100 if True: #try save/load
101 fn = 'solution/testCMS'
102 cms.SaveToFile(fn)
103 cms = ObjectFFRFreducedOrderInterface()
104 cms.LoadFromFile(fn)
105
106 if False: #check size of objects
107 for key in cms.__dict__:
108 exu.Print('size of ', key, ':', sys.getsizeof(cms.__dict__[key]) )
109
110 objFFRF = cms.AddObjectFFRFreducedOrder(mbs, positionRef=[0,0,0],
111 initialVelocity=[0,0,0],
112 initialAngularVelocity=[0,0,0],
113 gravity=[0,-9.81,0],
114 color=[0.1,0.9,0.1,1.])
115
116 #%%+++++++++++++++++++++++++++++++++++++++++++++++++++++
117 #add markers and joints
118 nodeDrawSize = 0.0025 #for joint drawing
119
120 mRB = mbs.AddMarker(MarkerNodeRigid(nodeNumber=objFFRF['nRigidBody']))
121 oGround = mbs.AddObject(ObjectGround(referencePosition= [0,0,0]))
122
123 mGroundPosLeft = mbs.AddMarker(MarkerBodyRigid(bodyNumber=oGround, localPosition=pLeftMid))
124 mLeft = mbs.AddMarker(MarkerSuperElementRigid(bodyNumber=objFFRF['oFFRFreducedOrder'],
125 meshNodeNumbers=np.array(nodesLeftPlane), #these are the meshNodeNumbers
126 weightingFactors=weightsLeftPlane))
127
128
129
130 mbs.AddObject(GenericJoint(markerNumbers=[mGroundPosLeft, mLeft], constrainedAxes=[1,1,1, 1,1,1]))
131
132 #%%+++++++++++++++++++++++++++++++++++++++++++++++++++++
133 sDisp=mbs.AddSensor(SensorSuperElement(bodyNumber=objFFRF['oFFRFreducedOrder'], meshNodeNumber=nTip, #meshnode number!
134 storeInternal=True,
135 outputVariableType = exu.OutputVariableType.DisplacementLocal))
136
137 mbs.Assemble()
138
139 simulationSettings = exu.SimulationSettings()
140
141 # SC.visualizationSettings.nodes.defaultSize = nodeDrawSize
142 SC.visualizationSettings.nodes.drawNodesAsPoint = False
143 SC.visualizationSettings.bodies.deformationScaleFactor = 1e4 #use this factor to scale the deformation of modes
144
145 SC.visualizationSettings.loads.drawSimplified = False
146
147 SC.visualizationSettings.contour.outputVariable = exu.OutputVariableType.DisplacementLocal
148 SC.visualizationSettings.contour.outputVariableComponent = 1 #y-component
149
150 # simulationSettings.solutionSettings.solutionInformation = "ObjectFFRFreducedOrder test"
151
152 h=1e-4
153 tEnd = 5e-3 #at almost max. of deflection under gravity
154
155 simulationSettings.timeIntegration.numberOfSteps = int(tEnd/h)
156 simulationSettings.timeIntegration.endTime = tEnd
157 simulationSettings.solutionSettings.solutionWritePeriod = h
158 simulationSettings.timeIntegration.verboseMode = useGraphics
159 #simulationSettings.timeIntegration.verboseModeFile = 3
160 simulationSettings.timeIntegration.newton.useModifiedNewton = True
161
162 simulationSettings.solutionSettings.sensorsWritePeriod = h
163 simulationSettings.solutionSettings.coordinatesSolutionFileName = "solution/coordinatesSolutionCMStest.txt"
164 simulationSettings.solutionSettings.writeSolutionToFile=False
165
166 simulationSettings.timeIntegration.generalizedAlpha.spectralRadius = 0.5 #SHOULD work with 0.9 as well
167
168 if useGraphics:
169 exu.StartRenderer()
170 if 'renderState' in exu.sys: SC.SetRenderState(exu.sys['renderState']) #load last model view
171
172 mbs.WaitForUserToContinue() #press space to continue
173
174 mbs.SolveDynamic(simulationSettings)
175
176 # data = np.loadtxt(fileDir+'nMidDisplacementCMS'+str(nModes)+'Test.txt', comments='#', delimiter=',')
177 data = mbs.GetSensorStoredData(sDisp)
178 exu.Print('u-tip for '+element+' = ', data[-1,1:], ', nNodes=',fem.NumberOfNodes())
179 result += abs(data[-1,1:]).sum()
180
181 if useGraphics:
182 SC.WaitForRenderEngineStopFlag()
183 exu.StopRenderer() #safely close rendering window!
184 lastRenderState = SC.GetRenderState() #store model view for next simulation
185
186exu.Print('solution of abaqusImportTest=',result)
187
188exudynTestGlobals.testError = (result - (0.0005885208722206333))
189exudynTestGlobals.testResult = result
190
191#for small meshes in TestModels:
192# u-tip for C3D4 = [-1.39753280e-05 -8.83250776e-05 9.86454888e-07] , nNodes= 214
193# u-tip for C3D10 = [-1.73664007e-05 -1.04237155e-04 1.86678663e-10] , nNodes= 257
194# u-tip for C3D8 = [-1.70545446e-05 -1.03215074e-04 6.31348275e-08] , nNodes= 176
195# u-tip for C3D20 = [-1.72124324e-05 -1.04326514e-04 -9.10211089e-11] , nNodes= 171
196# u-tip for C3D20R = [-1.72278715e-05 -1.04863540e-04 5.83371018e-08] , nNodes= 171
197
198#for larger files (see Experimental folder):
199# u-tip for C3D4 = [-1.39753280e-05 -8.83250776e-05 9.86454888e-07] , nNodes= 214
200# u-tip for C3D10 = [-1.74686596e-05 -1.05689104e-04 5.05186882e-08] , nNodes= 1332
201# u-tip for C3D8 = [-1.72150782e-05 -1.03377335e-04 4.39361119e-08] , nNodes= 176
202# u-tip for C3D20 = [-1.74978842e-05 -1.05476601e-04 -1.35045610e-08] , nNodes= 600
203# u-tip for C3D20R = [-1.72957461e-05 -1.05412212e-04 5.01834245e-08] , nNodes= 600