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