ANCFBeamTest.py

You can view and download this file on Github: ANCFBeamTest.py

  1#+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  2# This is an EXUDYN example
  3#
  4# Details:  Test models for ANCFBeam (2-node 3D shear deformable ANCF beam element 
  5#           with 2 cross section slope vectors); 
  6#           test models: cantilever beam with tip force and torque
  7#
  8# Author:   Johannes Gerstmayr
  9# Date:     2023-04-05
 10#
 11# 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.
 12#
 13#+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 14
 15import exudyn as exu
 16from exudyn.utilities import * #includes itemInterface and rigidBodyUtilities
 17from math import sin, cos
 18import exudyn.graphics as graphics
 19
 20import numpy as np
 21
 22testIsActive = exu.sys.get('testIsActive', False)
 23
 24SC = exu.SystemContainer()
 25mbs = SC.AddSystem()
 26
 27compute2D = False
 28compute3D = True
 29
 30#test examples
 31#2011 MUBO, Nachbagauer Pechstein Irschik Gerstmayr (2D)
 32#2013 CND, Nachbagauer Gruber Gerstmayr (static, 3D); "Structural and Continuum Mechanics Approaches for a 3D Shear Deformable ANCF Beam Finite Element: Application to Static and Linearized Dynamic Examples"
 33### not yet: 2013 CND, Nachbagauer Gerstmayr (dynamic, 3D)
 34cases = ['CantileverLinear2011', 'Cantilever2011', 'GeneralBending2013', 'PrincetonBeamF2', 'PrincetonBeamF3', 'Eigenmodes2013']
 35nElementsList = [1,2,4,8,16,32,64,128,256,512,1024]
 36# nElementsList = [8,32, 128]
 37nElements = 8
 38
 39betaList = [0,15,30,45,60,75,90]
 40betaDegree = 45
 41
 42caseList = [0,1,2,3,4]
 43case=4
 44
 45testIsActive = True
 46verbose = False
 47
 48bodyFixedLoad = False
 49testErrorSum = 0
 50printCase = True
 51
 52#for nElements in nElementsList:
 53#for betaDegree in betaList:
 54for case in caseList:
 55    if printCase:
 56        printCase=False
 57        exu.Print('case=', case, cases[case])
 58    mbs.Reset()
 59    
 60    computeEigenmodes = False
 61    csFact = 1
 62    sectionData = exu.BeamSection()
 63    fTip = 0
 64    MxTip = 0
 65    MyTip = 0
 66
 67    ks1=1 #shear correction, torsion
 68    ks2=1 #shear correction, bending
 69    ks3=1 #shear correction, bending
 70    ff=1 #drawing factor
 71
 72    #define beam parameters and loads for different cases
 73    if case == 0 or case == 1:
 74        caseName = cases[case]
 75
 76        L = 2 #length of beam
 77        w = 0.1 #width of beam
 78        h = 0.5 #height Y
 79
 80        fTip = 5e5*h**3
 81        if case == 1:
 82            fTip *= 1000
 83
 84        Em = 2.07e11
 85        rho = 1e2
 86    
 87        A=h*w
 88        nu = 0.3              # Poisson ratio
 89        ks2= 10*(1+nu)/(12+11*nu)
 90        ks3=ks2
 91
 92    elif case == 2:
 93        L = 2 #length of beam
 94        h = 0.2 #height Y
 95        w = 0.4 #width Z of beam
 96        Em = 2.07e11
 97        rho = 1e2
 98
 99        A=h*w
100    
101        nu = 0.3              # Poisson ratio
102        ks1= 0.5768 #torsion correction factor if J=Jyy+Jzz
103        ks2= 0.8331
104        ks3= 0.7961
105    
106        MxTip = 0.5e6
107        MyTip = 2e6
108
109        csFact = 10
110    elif case == 3 or case == 4: #Princeton beam example
111        L = 0.508       #length of beam
112        h = 12.3777e-3  #height Y; 12.3777e-3 with Obrezkov's paper
113        w = 3.2024e-3   #width Z of beam
114        Em = 71.7e9
115        ks1=0.198
116        nu = 0.31
117
118        ks2=1
119        ks3=1
120        # ks2=0.9
121        # ks3=0.9
122
123
124        rho = 1e2       #unused
125        A=h*w
126    
127        MxTip = 0
128        MyTip = 0
129        if case == 3:
130            fTip = 8.896    #F2
131        elif case == 4:
132            fTip = 13.345 #F3
133        #if kk==0: exu.Print('load=', fTip)
134        
135        beta = betaDegree/180*pi #beta=0 => negative y-axis
136        bodyFixedLoad = False
137
138        csFact = 10
139    
140    Gm = Em/(2*(1+nu))      # Shear modulus
141
142    #compute sectionData
143    
144    # Cross-section properties
145    Iyy = h*w**3/12 # Second moment of area of the beam cross-section
146    Izz = w*h**3/12 # Second moment of area of the beam cross-section
147    J = (Iyy+Izz)   # approximation; Polar moment of area of the beam cross-section
148
149    sectionData.stiffnessMatrix = np.diag([Em*A, Gm*A*ks2, Gm*A*ks3, Gm*J*ks1, Em*Iyy, Em*Izz])
150
151
152    rhoA = rho*A
153
154    if False:
155        #linear solution:
156        uzTip = fTip*L**3/(3*Em*Iyy)
157        exu.Print('uz linear=',uzTip)
158        uyTip = fTip*L**3/(3*Em*Izz)
159        exu.Print('uy linear=',uyTip)
160
161    sectionData.inertia= rho*J*np.eye(3)
162    sectionData.massPerLength = rhoA
163
164    sectionGeometry = exu.BeamSectionGeometry()
165
166    #points, in positive rotation sense viewing in x-direction, points in [Y,Z]-plane
167    #points do not need to be closed!
168    lp = exu.Vector2DList()
169    if True:
170        lp.Append([h*ff,-w*ff])
171        lp.Append([h*ff,w*ff])
172        lp.Append([-h*ff,w*ff])
173        lp.Append([-h*ff,-w*ff])
174
175    sectionGeometry.polygonalPoints = lp
176    #exu.Print('HERE\n',sectionGeometry.polygonalPoints)
177    nGround = mbs.AddNode(NodePointGround(referenceCoordinates=[0,0,0])) #ground node for coordinate constraint
178    mnGround = mbs.AddMarker(MarkerNodeCoordinate(nodeNumber=nGround, coordinate=0))
179 
180
181    eY=[0,1,0]
182    eZ=[0,0,1]
183    lElem = L/nElements
184    if compute3D:
185        initialRotations = eY+eZ
186        #create beam nodes and elements
187        n0 = mbs.AddNode(NodePointSlope23(referenceCoordinates=[0,0,0]+initialRotations))
188        nInit = n0
189        for k in range(nElements):
190            n1 = mbs.AddNode(NodePointSlope23(referenceCoordinates=[lElem*(k+1),0,0]+initialRotations))
191
192            oBeam = mbs.AddObject(ObjectANCFBeam(nodeNumbers=[n0,n1], length = lElem, 
193                                                   sectionData = sectionData,
194                                                   crossSectionPenaltyFactor = [csFact,csFact,csFact],
195                                                   visualization=VANCFBeam(sectionGeometry=sectionGeometry)))
196            n0 = n1
197
198
199        mTip = mbs.AddMarker(MarkerNodeRigid(nodeNumber = n1))
200        if fTip != 0:
201            if case < 3:
202                mbs.AddLoad(Force(markerNumber=mTip, loadVector = [0,fTip,0], bodyFixed = bodyFixedLoad))
203            elif case >= 3:
204                mbs.AddLoad(Force(markerNumber=mTip, loadVector = [0,-fTip*cos(beta),fTip*sin(beta)], bodyFixed = bodyFixedLoad))
205
206        if MxTip != 0 or MyTip != 0:
207            mbs.AddLoad(Torque(markerNumber=mTip, loadVector = [MxTip, MyTip,0]))#, bodyFixed = True ))
208
209        for i in range(9):
210            #if i != 4 and i != 8: #exclude constraining the slope lengths
211            if True:
212                nm0 = mbs.AddMarker(MarkerNodeCoordinate(nodeNumber=nInit, coordinate=i))
213                mbs.AddObject(CoordinateConstraint(markerNumbers=[mnGround, nm0]))
214
215
216    # exu.Print(mbs)
217    mbs.Assemble()
218
219    tEnd = 100     #end time of simulation
220    stepSize = 0.5*0.01*0.1    #step size; leads to 1000 steps
221
222    simulationSettings = exu.SimulationSettings()
223    simulationSettings.solution.file.writePeriod = 2e-2  #output interval general
224    simulationSettings.solution.sensors.writePeriod = 1e-1  #output interval of sensors
225    simulationSettings.timeIntegration.numberOfSteps = int(tEnd/stepSize) #must be integer
226    simulationSettings.timeIntegration.endTime = tEnd
227    #simulationSettings.solution.file.information = "This is the info\nNew line\n and another new line \n"
228    simulationSettings.timeIntegration.generalizedAlpha.spectralRadius = 0.5
229    #simulationSettings.timeIntegration.realtime.active=True
230    #simulationSettings.timeIntegration.realtime.factor=0.1
231
232    simulationSettings.timeIntegration.verboseMode = verbose
233    simulationSettings.staticSolver.verboseMode = verbose
234
235    simulationSettings.timeIntegration.newton.useModifiedNewton = True
236
237    simulationSettings.timeIntegration.newton.numericalDifferentiation.relativeEpsilon = 1e-4
238    simulationSettings.timeIntegration.newton.relativeTolerance = 1e-6
239
240    simulationSettings.linearSolver.solverType = exu.LinearSolverType.EigenSparse
241
242    if nElements > 32 and case==0: #change tolerance, because otherwise no convergence
243        simulationSettings.staticSolver.newton.relativeTolerance = 1e-6
244    if case == 1: #tolerance changed from 1e-8 to 5e-10 to achieve values of paper (1024 has difference at last digit in paper)
245        simulationSettings.staticSolver.newton.relativeTolerance = 0.5e-9
246
247
248    simulationSettings.staticSolver.numberOfLoadSteps = 5
249
250
251    #add some drawing parameters for this example
252    SC.visualizationSettings.nodes.drawNodesAsPoint=False
253    SC.visualizationSettings.nodes.defaultSize=0.01
254
255    SC.visualizationSettings.bodies.beams.axialTiling = 50
256    SC.visualizationSettings.view0.scene.drawWorldBasis = True
257    SC.visualizationSettings.view0.scene.worldBasisSize = 0.1
258    SC.visualizationSettings.openGL.multiSampling = 4
259
260
261    # [M, K, D] = exu.solver.ComputeLinearizedSystem(mbs, simulationSettings, useSparseSolver=True)
262    # exu.Print('M=',M.round(1))
263
264    if not testIsActive:
265        SC.renderer.Start()
266        SC.renderer.DoIdleTasks()
267
268    # else:
269    mbs.SolveStatic(simulationSettings)
270    # mbs.SolveDynamic(simulationSettings)
271    #mbs.SolveDynamic(simulationSettings, solverType = exu.DynamicSolverType.RK44)
272    
273
274    if not testIsActive:
275        SC.renderer.DoIdleTasks()
276        SC.renderer.Stop() #safely close rendering window!
277    
278    ##evaluate final (=current) output values
279    uTip = mbs.GetNodeOutput(n1, exu.OutputVariableType.Displacement)
280    
281    errorFact = 1
282    if case != 1:
283        errorFact *= 100
284
285    testErrorSum += np.linalg.norm(uTip)
286
287    
288    
289    if case < 2:
290        pTip = mbs.GetNodeOutput(n1, exu.OutputVariableType.Position)
291        exu.Print('ne=',nElements, ', ux=',L-pTip[0], ', uy=',pTip[1])
292    elif case == 2:
293        rotTip = mbs.GetNodeOutput(n1, exu.OutputVariableType.Rotation)
294        exu.Print('ne=',nElements, ', u=',list(uTip))
295        # exu.Print('ne=',nElements, ', rot=',rotTip)
296    elif case == 3 or case == 4:
297        exu.Print('ne=', nElements, ', beta=', round(beta*180/pi,1), ', u=',uTip.round(7))
298
299
300exu.Print('Solution of ANCFBeam3Dtest=', testErrorSum)
301exu.sys['testResult'] = testErrorSum
302
303
304
305# case= 0/CantileverLinear2011 
306#NachbagauerPechsteinIrschikGerstmayrMUBO2011 (2D):
307# ne=1,   9.12273046e–8, 6.16666566e–4, 0.000193
308# ne=2,   1.61293091e–7, 7.61594059e–4, 4.831e–5
309# ne=4,   1.81763233e–7, 7.97825954e–4, 1.208e–5
310# ne=256, 1.88847418e–7, 8.09900305e–4, 2.945e–9
311#Exudyn: ksFact=1
312# ne= 1 , ux= 9.122730637578513e-08 , uy= 0.0006166665660910789 
313# ne= 2 , ux= 1.612930911054633e-07 , uy= 0.0007615940599560586 
314# ne= 4 , ux= 1.8176323512975046e-07 , uy= 0.0007978259537503566 
315# ne= 8 , ux= 1.8706537496804287e-07 , uy= 0.0008068839288072378 
316# ne= 16 , ux= 1.8840244964124508e-07 , uy= 0.0008091484226773518 
317# ne= 32 , ux= 1.887374359021976e-07 , uy= 0.0008097145461515286 
318# ne= 64 , ux= 1.888212299849812e-07 , uy= 0.0008098560770202866 
319# ne= 128 , ux= 1.8884218011550047e-07 , uy= 0.000809891459736643 
320# ne= 256 , ux= 1.8884741770364144e-07 , uy= 0.0008099003054122335
321
322
323# case= 1/Cantilever2011 
324#NachbagauerPechsteinIrschikGerstmayrMUBO2011 (2D):
325# ne=1,    0.07140274, 0.54225823, 0.168310
326# ne=2,    0.12379212, 0.65687111, 0.053697
327# ne=4,    0.14346767, 0.69593561, 0.014633
328# ne=1024, 0.15097103, 0.71056837, 2.280e–7
329
330#Exudyn: ksFact=1
331# ne= 1 , ux= 0.07140273975041422 , uy= 0.5422582285449739 
332# ne= 2 , ux= 0.12379212054619537 , uy= 0.6568711099777776 
333# ne= 4 , ux= 0.14346766617229956 , uy= 0.695935613449867 
334# ne= 8 , ux= 0.14904162148449163 , uy= 0.7068152604035266 
335# ne= 16 , ux= 0.15048521526298897 , uy= 0.709623891842095 
336# ne= 32 , ux= 0.15084943688011565 , uy= 0.7103320154655514 
337# ne= 64 , ux= 0.15094070328691145 , uy= 0.7105094267817303 
338# ne= 128 , ux= 0.15096353326024237 , uy= 0.7105538037895819 
339# ne= 256 , ux= 0.15096924149743085 , uy= 0.7105648993600513 
340# ne= 512 , ux= 0.15097066651939461 , uy= 0.7105676689547459 
341# ne= 1024 , ux= 0.15097102364723924 , uy= 0.7105683631862169 
342
343# case = 2:
344#2013 CND, Nachbagauer Gruber Gerstmayr (static, 3D); "Structural and Continuum Mechanics Approaches for a 3D Shear Deformable ANCF Beam Finite Element: Application to Static and Linearized Dynamic Examples"
345#Table 4:
346# SMF
347# 8,  1.0943e-4, 1.8638e-4, 1.8117e-2
348# 32, 1.0943e-4, 1.8625e-4, 1.8117e-2
349# ANSYS
350# 40, 1.0939e-4, 1.8646e-4, 1.8117e-2    
351#Exudyn, ksFact=10:
352# ne= 8 , u= [-0.00010900977088157404, -0.0001902100873246334, -0.01811732779800177] 
353# ne= 32 , u= [-0.00010941122286522997, -0.00018667435478355072, -0.01811739809277171] 
354# ne= 128 , u= [-0.00010943631319815239, -0.000186451835025629, -0.018117402461210096] 
355#==> in 2013 paper, element performed slightly better, especially in ux and uy terms
356
357# case = 3:
358#Princeton beam with ANSYS (Leonid Obrezkov / Aki Mikkola / Marko Matikainen et al.,
359#       Performance review of locking alleviation methods for continuum ANCF beam elements,
360#       Nonlinear Dynamics, Vol. 109, pp. 31–546, May 2022
361# beta=[0 15 30 45 60 75 90];
362if (case==3 or case == 4) and False:
363    # F2=8.896
364    # % ANSYS beam (10-199 el)
365    ANSYSF2y=np.array([1.071417630E-002,  1.061328706E-002, 1.011169630E-002,  8.837226265E-003, 6.604665004E-003, 3.538889001E-003, 0])
366    ANSYSF2z=np.array([0, 4.208232124E-002, 7.939482948E-002, 0.108987937,  0.129887616, 0.142194370, 0.146245978])
367    exu.Print('refsol ANSYS F2=8.896:\n',ANSYSF2y.round(6), '\n', ANSYSF2z.round(6),sep='')
368    # % ANSYS solid (el) (4x12x500) - finer mesh doesn't have much influence see in Size effect file
369    # ANSYS_solid_y=[1.069752828E-002 1.057180106E-002 9.938278402E-003 8.686786771E-003 6.500006282E-003 3.481999513E-003 0];
370    # ANSYS_solid_z=[0 4.101165651E-002 7.696749069E-002 0.105976311 0.127251299 0.139594740 0.143848652];
371    
372    # F3=13.345 
373    # % ANSYS beam (10-199 el)
374    ANSYSF3y=np.array([1.606423724E-002, 1.645825752E-002, 1.665873206E-002, 1.518618440E-002, 1.157837500E-002, 6.248967384E-003, 0])
375    ANSYSF3z=np.array([0,                6.435812858E-002, 0.117735994,      0.156467239,      0.181861627,      0.196097131,      0.200677707])
376    # % ANSYS solid (el) (4x12x500) - finer mesh see in Size effect file
377    #ANSYS_solid_y=[1.603700622E-002 1.637026068E-002 1.640440775E-002 1.485055210E-002 1.127173264E-002 6.062461977E-003  0])
378    #ANSYS_solid_z=[0 6.270699533E-002 0.113752002 0.153554457 0.179978534  0.192972233 0.197669499])
379    exu.Print('refsol ANSYS F3=13.345:\n',ANSYSF3y.round(6), '\n', ANSYSF3z.round(6),sep='')
380#Exudyn results for Princeton beam:
381#not exactly the same, but around the previous values with HOTINT
382#using 16 elements, csFact=10 (no influence)
383# F2=8.896
384# case= 3, PrincetonBeam
385# ne= 16 , beta= 0.0 , u= [-0.0001352 -0.0107023  0.       ]
386# ne= 16 , beta= 15.0 , u= [-0.0022414 -0.0106295  0.0421374]
387# ne= 16 , beta= 30.0 , u= [-0.0076567 -0.0101861  0.0794434]
388# ne= 16 , beta= 45.0 , u= [-0.0143664 -0.0089529  0.1089703]
389# ne= 16 , beta= 60.0 , u= [-0.0204225 -0.0067182  0.1297877]
390# ne= 16 , beta= 75.0 , u= [-0.0245093 -0.0036079  0.1420319]
391# ne= 16 , beta= 90.0 , u= [-0.0259403 -0.         0.1460608]
392
393# F3=13.345
394# case= 4, PrincetonBeam
395# ne= 16 , beta= 0.0 , u= [-0.0003039 -0.0160454  0.       ]
396# ne= 16 , beta= 15.0 , u= [-0.005319  -0.0165469  0.064622 ]
397# ne= 16 , beta= 30.0 , u= [-0.0171901 -0.0169316  0.1179818]
398# ne= 16 , beta= 45.0 , u= [-0.0303357 -0.0155488  0.1565214]
399# ne= 16 , beta= 60.0 , u= [-0.0411035 -0.0118996  0.1817173]
400# ne= 16 , beta= 75.0 , u= [-0.0479101 -0.0064334  0.1958343]
401# ne= 16 , beta= 90.0 , u= [-0.0502184 -0.         0.2003738]