ANCFcantileverTest.py
You can view and download this file on Github: ANCFcantileverTest.py
1#+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2# This is an EXUDYN example
3#
4# Details: ANCF Cable2D cantilever test
5#
6# Model: Cantilever beam with cable elements
7#
8# Author: Johannes Gerstmayr
9# Date: 2019-11-15
10# Update: 2022-03-16: get to run static example again, compared to paper!
11#
12# 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.
13#
14# *clean example*
15#+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
16
17## import exudyn and utilities
18import exudyn as exu
19from exudyn.utilities import *
20
21## create container and main system to work with
22SC = exu.SystemContainer()
23mbs = SC.AddSystem()
24
25
26## create graphics background
27rect = [-0.5,-2,2.5,0.5] #xmin,ymin,xmax,ymax
28background = {'type':'Line', 'color':[0.1,0.1,0.8,1], 'data':[rect[0],rect[1],0, rect[2],rect[1],0, rect[2],rect[3],0, rect[0],rect[3],0, rect[0],rect[1],0]} #background
29oGround=mbs.AddObject(ObjectGround(referencePosition= [0,0,0], visualization=VObjectGround(graphicsData= [background])))
30
31#+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
32## define beam dimensions and tip load
33L=2 # length of ANCF element in m
34E=2.07e11 # Young's modulus of ANCF element in N/m^2
35rho=7800 # density of ANCF element in kg/m^3
36b=0.1 # width of rectangular ANCF element in m
37h=0.1 # height of rectangular ANCF element in m
38A=b*h # cross sectional area of ANCF element in m^2
39I=b*h**3/12 # second moment of area of ANCF element in m^4
40f=3*E*I/L**2 # tip load applied to ANCF element in N
41
42print("load f="+str(f))
43
44#%%+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
45## generate ANCFCable2D template containing beam parameters
46cableTemplate = Cable2D(#physicsLength = L / nElements, #set in GenerateStraightLineANCFCable2D(...)
47 physicsMassPerLength = rho*A,
48 physicsBendingStiffness = E*I,
49 physicsAxialStiffness = E*A,
50 useReducedOrderIntegration = 0,
51 #nodeNumbers = [0, 0], #will be filled in GenerateStraightLineANCFCable2D(...)
52 )
53
54## define nodal positions of beam (3D vectors, while cable element is only 2D)
55positionOfNode0 = [0, 0, 0] # starting point of line
56positionOfNode1 = [L, 0, 0] # end point of line
57
58## number of cable elements for discretization
59numberOfElements = 64
60
61## use utility function to create set of straight cable elements between two positions with options for constraints at supports
62#alternative to mbs.AddObject(Cable2D(...)) with nodes:
63ancf=GenerateStraightLineANCFCable2D(mbs,
64 positionOfNode0, positionOfNode1,
65 numberOfElements,
66 cableTemplate, #this defines the beam element properties
67 massProportionalLoad = [0,-9.81*0,0], #optionally add gravity
68 fixedConstraintsNode0 = [1,1,0,1], #add constraints for pos and rot (r'_y)
69 fixedConstraintsNode1 = [0,0,0,0])
70
71## add load vector on last node in y-direction
72mANCFLast = mbs.AddMarker(MarkerNodePosition(nodeNumber=ancf[0][-1])) #ancf[0][-1] = last node
73mbs.AddLoad(Force(markerNumber = mANCFLast, loadVector = [0, -f, 0])) #will be changed in load steps
74
75
76#%%+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
77## assemble system and create simulation settings
78mbs.Assemble()
79
80simulationSettings = exu.SimulationSettings() #takes currently set values or default values
81
82tEnd = 0.1
83h = 1e-4
84simulationSettings.timeIntegration.numberOfSteps = int(tEnd/h)
85simulationSettings.timeIntegration.endTime = tEnd
86simulationSettings.solutionSettings.writeSolutionToFile = True
87simulationSettings.solutionSettings.solutionWritePeriod = simulationSettings.timeIntegration.endTime/1000
88simulationSettings.displayComputationTime = False
89simulationSettings.timeIntegration.verboseMode = 1
90
91simulationSettings.timeIntegration.newton.useModifiedNewton = True
92
93simulationSettings.displayStatistics = True
94simulationSettings.displayComputationTime = True
95
96SC.visualizationSettings.nodes.defaultSize = 0.01
97simulationSettings.solutionSettings.solutionInformation = "ANCF cantilever beam"
98simulationSettings.linearSolverType = exu.LinearSolverType.EigenSparse
99
100doDynamicSimulation = True #switch between static and dynamic simulation
101
102
103if doDynamicSimulation:
104 ## do dynamic simulation
105 exu.StartRenderer()
106 mbs.SolveDynamic(simulationSettings)
107 SC.WaitForRenderEngineStopFlag()
108 exu.StopRenderer() #safely close rendering window!
109 ##
110else:
111 ## perform static simulation with manual load stepping
112 simulationSettings.staticSolver.verboseMode = 0
113
114 simulationSettings.staticSolver.newton.relativeTolerance = 1e-8
115 simulationSettings.staticSolver.newton.absoluteTolerance = 1e-3 #1 for 256 elements; needs to be larger for larger number of load steps
116 #simulationSettings.staticSolver.numberOfLoadSteps = 1
117
118 nLoadSteps = 1;
119 for loadSteps in range(nLoadSteps):
120 nLoad = 0
121 loadValue = f**((loadSteps+1)/nLoadSteps) #geometric increment of loads
122 print('load='+str(loadValue))
123
124 mbs.SetLoadParameter(nLoad, 'loadVector', [0, -loadValue,0])
125 print('load vector=' + str(mbs.GetLoadParameter(nLoad, 'loadVector')) )
126
127 mbs.SolveStatic(simulationSettings, updateInitialValues=True)
128
129 sol = mbs.systemData.GetODE2Coordinates()
130
131 n = len(sol)
132 print('nEL=',numberOfElements, ', tip displacement: x='+str(sol[n-4])+', y='+str(sol[n-3]))
133 #MATLAB 1 element: x=0.3622447298905063, y=0.9941447587249748 = paper "on the correct ..."
134 #2022-03-16:
135 # nEL= 1 , tip displacement: x=-0.36224472989050654,y=-0.9941447587249747
136 # nEL= 2 , tip displacement: x=-0.4889263085609102, y=-1.1752228652637502
137 # nEL= 4 , tip displacement: x=-0.5074287154557922, y=-1.2055337025602493
138 # nEL= 8 , tip displacement: x=-0.5085092365729895, y=-1.207197756093103
139 # nEL= 16 , tip displacement: x=-0.5085365799149556, y=-1.207238895003594
140 # nEL= 32 , tip displacement: x=-0.508537277761696, y=-1.2072398264650905
141 # nEL= 64 , tip displacement: x=-0.5085373030408489, y=-1.207239853404364
142 # nEL= 128, tip displacement: x=-0.5085373043168473, y=-1.2072398545511795
143 # nEL= 256, tip displacement: x=-0.5085373043916903, y=-1.207239854614031
144
145 #with second SolveStatic:
146 #nEL= 256 , tip displacement: x=-0.5085373043209366, y=-1.2072398545457574
147 #converged: x=-0.508537304326, y=-1.207239854550
148
149 #here (OLD):
150 #1: x=-0.36224472989050543, y=-0.994144758724973
151 #2: x=-0.4889263083414858, y=-1.1752228650551666
152 #4: x=-0.5074287151188892, y=-1.2055337022335404
153 #8: x=-0.5085092364970802, y=-1.2071977560198281
154 #64: x=-0.5085373029700947, y=-1.2072398533360738
155 #256:x=-0.5085373043209689, y=-1.2072398545457785
156
157
158
159
160 #sol = mbs.systemData.GetODE2Coordinates(exu.ConfigurationType.Initial)
161 #print('initial values='+str(sol))