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
 17from exudyn.FEM import *
 18
 19testIsActive = exu.sys.get('testIsActive', False)
 20
 21testIsActive = True
 22
 23import numpy as np
 24import time
 25import sys
 26
 27#%%+++++++++++++++++++++++++++++++++++++++++++++++++++++
 28#Use FEMinterface to import FEM model and create FFRFreducedOrder object
 29fileDir = 'testData/abaqus/block'
 30result = 0
 31
 32elements = ['C3D4','C3D10','C3D8','C3D20','C3D20R']
 33#elements = ['C3D8']
 34
 35for element in elements:
 36    SC = exu.SystemContainer()
 37    mbs = SC.AddSystem()
 38
 39    fem = FEMinterface()
 40    inputFileName = fileDir+element
 41    nodes=fem.ImportFromAbaqusInputFile(inputFileName+'.inp', typeName='Instance', name='rotor-1')
 42    
 43    fem.ReadMassMatrixFromAbaqus(inputFileName+'_MASS1.mtx')
 44    fem.ReadStiffnessMatrixFromAbaqus(inputFileName+'_STIF1.mtx')
 45    if True:
 46        from exudyn.basicUtilities import OutputFilePath
 47        fn = OutputFilePath('solution/testFEM', 'abaqusImportTest') #output of the test (#2418)
 48        #test save and import
 49        if np.__version__ <= '2.0': #load save does not work yet!
 50            fem.SaveToFile(fn)
 51            fem = FEMinterface()
 52            fem.LoadFromFile(fn)
 53        else: #for newer numpy version, use pickle (PKL) or HDF5
 54            fem.SaveToFile(fn,mode='PKL')
 55            fem = FEMinterface()
 56            fem.LoadFromFile(fn,mode='PKL')
 57            
 58
 59        if False:
 60            exu.Print('size of nodes:', sys.getsizeof(np.array(fem.nodes['Position'])) )
 61            exu.Print('size of elements:', sys.getsizeof(fem.elements[0]) )
 62            exu.Print('size of massMatrix:', sys.getsizeof(fem.massMatrix) )
 63            exu.Print('size of stiffnessMatrix:', sys.getsizeof(fem.stiffnessMatrix) )
 64            exu.Print('size of modeBasis:', sys.getsizeof(fem.modeBasis) )
 65            #print('size of postProcessingModes:', sys.getsizeof(fem.postProcessingModes['matrix']) )
 66            exu.Print('===================')
 67    
 68    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 
 69
 70    pLeft = [0,0,0]
 71    pLeftMid = [0,0.5,0.5]
 72    pRight = [4,0,0]
 73    nTip = fem.GetNodeAtPoint(pRight) #tip node (do not use midpoint, as this may not be a mesh node ...)
 74
 75    nodesLeftPlane = fem.GetNodesInPlane(pLeft, [-1,0,0])
 76    weightsLeftPlane = fem.GetNodeWeightsFromSurfaceAreas(nodesLeftPlane)
 77
 78    nodesRightPlane = fem.GetNodesInPlane(pRight, [-1,0,0])
 79    weightsRightPlane = fem.GetNodeWeightsFromSurfaceAreas(nodesRightPlane)
 80
 81    boundaryList = [nodesLeftPlane] 
 82
 83    if not testIsActive:
 84        exu.Print("nNodes=",fem.NumberOfNodes())
 85        exu.Print("compute HCB modes... ")
 86    start_time = time.time()
 87    fem.ComputeHurtyCraigBamptonModes(boundaryNodesList=boundaryList, 
 88                                  nEigenModes=nModes, 
 89                                  useSparseSolver=False, #sparse solver gives non-repeatable results ...
 90                                  computationMode = HCBstaticModeSelection.RBE2)
 91
 92    if not testIsActive:
 93        exu.Print("HCB modes needed %.3f seconds" % (time.time() - start_time))
 94    
 95    cms = ObjectFFRFreducedOrderInterface(fem)
 96    if True: #try save/load
 97        fn = OutputFilePath('solution/testCMS', 'abaqusImportTest') #output of the test (#2418)
 98        cms.SaveToFile(fn)
 99        cms = ObjectFFRFreducedOrderInterface()
100        cms.LoadFromFile(fn)
101        
102        if False: #check size of objects
103            for key in cms.__dict__:
104                exu.Print('size of ', key, ':', sys.getsizeof(cms.__dict__[key]) )
105    
106    objFFRF = cms.AddObjectFFRFreducedOrder(mbs, positionRef=[0,0,0], 
107                                            initialVelocity=[0,0,0], 
108                                            initialAngularVelocity=[0,0,0],
109                                            gravity=[0,-9.81,0],
110                                            color=[0.1,0.9,0.1,1.])
111    
112    #%%+++++++++++++++++++++++++++++++++++++++++++++++++++++
113    #add markers and joints
114    nodeDrawSize = 0.0025 #for joint drawing
115    
116    mRB = mbs.AddMarker(MarkerNodeRigid(nodeNumber=objFFRF['nRigidBody']))
117    oGround = mbs.AddObject(ObjectGround(referencePosition= [0,0,0]))
118    
119    mGroundPosLeft = mbs.AddMarker(MarkerBodyRigid(bodyNumber=oGround, localPosition=pLeftMid))
120    mLeft = mbs.AddMarker(MarkerSuperElementRigid(bodyNumber=objFFRF['oFFRFreducedOrder'], 
121                                                  meshNodeNumbers=np.array(nodesLeftPlane), #these are the meshNodeNumbers
122                                                  weightingFactors=weightsLeftPlane))
123
124
125    
126    mbs.AddObject(GenericJoint(markerNumbers=[mGroundPosLeft, mLeft], constrainedAxes=[1,1,1, 1,1,1]))
127        
128    #%%+++++++++++++++++++++++++++++++++++++++++++++++++++++
129    sDisp=mbs.AddSensor(SensorSuperElement(bodyNumber=objFFRF['oFFRFreducedOrder'], meshNodeNumber=nTip, #meshnode number!
130                             storeInternal=True,
131                             outputVariableType = exu.OutputVariableType.DisplacementLocal))
132    
133    mbs.Assemble()
134    
135    simulationSettings = exu.SimulationSettings()
136    
137    # SC.visualizationSettings.nodes.defaultSize = nodeDrawSize
138    SC.visualizationSettings.nodes.drawNodesAsPoint = False
139    SC.visualizationSettings.bodies.deformationScaleFactor = 1e4 #use this factor to scale the deformation of modes
140    
141    SC.visualizationSettings.loads.drawSimplified = False
142    
143    SC.visualizationSettings.contour.outputVariable = exu.OutputVariableType.DisplacementLocal
144    SC.visualizationSettings.contour.outputVariableComponent = 1 #y-component
145    
146    # simulationSettings.solution.file.information = "ObjectFFRFreducedOrder test"
147    
148    h=1e-4
149    tEnd = 5e-3 #at almost max. of deflection under gravity
150    
151    simulationSettings.timeIntegration.numberOfSteps = int(tEnd/h)
152    simulationSettings.timeIntegration.endTime = tEnd
153    simulationSettings.solution.file.writePeriod = h
154    simulationSettings.timeIntegration.verboseMode = (not testIsActive)
155    #simulationSettings.timeIntegration.verboseModeFile = 3
156    simulationSettings.timeIntegration.newton.useModifiedNewton = True
157    
158    simulationSettings.solution.sensors.writePeriod = h
159    simulationSettings.solution.file.name = "solution/coordinatesSolutionCMStest.txt"
160    simulationSettings.solution.file.write=False
161    
162    simulationSettings.timeIntegration.generalizedAlpha.spectralRadius = 0.5 #SHOULD work with 0.9 as well
163    
164    if not testIsActive:
165        SC.renderer.Start()
166        SC.renderer.RestoreSavedState() #load last model view
167    
168        SC.renderer.DoIdleTasks() #press space to continue
169    
170    mbs.SolveDynamic(simulationSettings)
171        
172    # data = np.loadtxt(fileDir+'nMidDisplacementCMS'+str(nModes)+'Test.txt', comments='#', delimiter=',')
173    data = mbs.GetSensorStoredData(sDisp)
174    exu.Print('u-tip for '+element+' = ', data[-1,1:], ', nNodes=',fem.NumberOfNodes())
175    result += abs(data[-1,1:]).sum()
176    
177    if not testIsActive:
178        SC.renderer.DoIdleTasks()
179        SC.renderer.Stop() #safely close rendering window!
180        lastRenderState = SC.renderer.GetState() #store model view for next simulation
181
182exu.Print('solution of abaqusImportTest=',result)
183
184exu.sys['testResult'] = result
185
186#for small meshes in TestModels:
187# u-tip for C3D4 =  [-1.39753280e-05 -8.83250776e-05  9.86454888e-07] , nNodes= 214
188# u-tip for C3D10 =  [-1.73664007e-05 -1.04237155e-04  1.86678663e-10] , nNodes= 257
189# u-tip for C3D8 =  [-1.70545446e-05 -1.03215074e-04  6.31348275e-08] , nNodes= 176
190# u-tip for C3D20 =  [-1.72124324e-05 -1.04326514e-04 -9.10211089e-11] , nNodes= 171
191# u-tip for C3D20R =  [-1.72278715e-05 -1.04863540e-04  5.83371018e-08] , nNodes= 171
192
193#for larger files (see Experimental folder):
194# u-tip for C3D4 =  [-1.39753280e-05 -8.83250776e-05  9.86454888e-07] , nNodes= 214
195# u-tip for C3D10 =  [-1.74686596e-05 -1.05689104e-04  5.05186882e-08] , nNodes= 1332
196# u-tip for C3D8 =  [-1.72150782e-05 -1.03377335e-04  4.39361119e-08] , nNodes= 176
197# u-tip for C3D20 =  [-1.74978842e-05 -1.05476601e-04 -1.35045610e-08] , nNodes= 600
198# u-tip for C3D20R =  [-1.72957461e-05 -1.05412212e-04  5.01834245e-08] , nNodes= 600