rigidRotor3Drunup.py

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

  1#+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  2# This is an EXUDYN example
  3#
  4# Details:  Example with 3D rotor, showing runup
  5#
  6# Author:   Johannes Gerstmayr
  7# Date:     2019-12-05
  8#
  9# 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.
 10#
 11#+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 12import sys
 13sys.path.append('../TestModels')            #for modelUnitTest as this example may be used also as a unit test
 14
 15import exudyn as exu
 16from exudyn.itemInterface import *
 17from exudyn.utilities import *
 18
 19import time
 20import numpy as np
 21
 22SC = exu.SystemContainer()
 23mbs = SC.AddSystem()
 24print('EXUDYN version='+exu.GetVersionString())
 25
 26L=1                     #rotor axis length
 27isSymmetric = True
 28if isSymmetric:
 29    L0 = 0.5            #0.5 (symmetric rotor); position of rotor on x-axis
 30else :
 31    L0 = 0.9            #default: 0.9m; position of rotor on x-axis
 32L1 = L-L0               #
 33m = 2                   #mass in kg
 34r = 0.5*1.5             #radius for disc mass distribution
 35lRotor = 0.2            #length of rotor disk
 36k = 800                 #stiffness of (all/both) springs in rotor in N/m
 37Jxx = 0.5*m*r**2        #polar moment of inertia
 38Jyyzz = 0.25*m*r**2 + 1/12.*m*lRotor**2      #moment of inertia for y and z axes
 39
 40omega0=np.sqrt(2*k/m) #linear system
 41
 42D0 = 0.002              #dimensionless damping
 43d = 2*omega0*D0*m       #damping constant in N/(m/s)
 44
 45f0 = 0*omega0/(2*np.pi) #frequency start (Hz)
 46f1 = 2.*omega0/(2*np.pi) #frequency end (Hz)
 47
 48torque = 0.2            #driving torque; Nm ; 0.1Nm does not surpass critical speed; 0.2Nm works
 49eps = 2e-3*0.74         # excentricity of mass in y-direction
 50                        #symmetric rotor: 2e-3 gives large oscillations;
 51                        #symmetric rotor: 0.74*2e-3 shows kink in runup curve
 52
 53omegaInitial = 0*4*omega0 #initial rotation speed in rad/s
 54
 55tEnd = 200              #end time of simulation
 56steps = 40000           #number of steps
 57
 58fRes = omega0/(2*np.pi)
 59print('symmetric rotor resonance frequency (Hz)= '+str(fRes))
 60#print('runup over '+str(tEnd)+' seconds, fStart='+str(f0)+'Hz, fEnd='+str(f1)+'Hz')
 61
 62#linear frequency sweep evaluated at time t, for time interval [0, t1] and frequency interval [f0,f1];
 63def Sweep(t, t1, f0, f1):
 64    k = (f1-f0)/t1
 65    return np.sin(2*np.pi*(f0+k*0.5*t)*t) #take care of factor 0.5 in k*0.5*t, in order to obtain correct frequencies!!!
 66def SweepCos(t, t1, f0, f1):
 67    k = (f1-f0)/t1
 68    return np.cos(2*np.pi*(f0+k*0.5*t)*t) #take care of factor 0.5 in k*0.5*t, in order to obtain correct frequencies!!!
 69
 70# #user function for load
 71# def userLoad(t, load):
 72#     #return load*np.sin(0.5*omega0*t) #gives resonance
 73#     if t>40: time.sleep(0.02) #make simulation slower
 74#     return load*Sweep(t, tEnd, f0, f1)
 75#     #return load*Sweep(t, tEnd, f1, f0) #backward sweep
 76
 77# #backward whirl excitation:
 78# amp = 0.10  #in resonance: *0.01
 79# def userLoadBWy(t, load):
 80#     return load*SweepCos(t, tEnd, f0, f1) #negative sign: BW, positive sign: FW
 81# def userLoadBWz(t, load):
 82#     return load*Sweep(t, tEnd, f0, f1)
 83#def userLoadBWx(t, load):
 84#    return load*np.sin(omegaInitial*t)
 85#def userLoadBWy(t, load):
 86#    return -load*np.cos(omegaInitial*t) #negative sign: FW, positive sign: BW
 87
 88#background1 = GraphicsDataOrthoCube(0,0,0,.5,0.5,0.5,[0.3,0.3,0.9,1])
 89
 90#draw RGB-frame at origin
 91p=[0,0,0]
 92lFrame = 0.8
 93tFrame = 0.01
 94backgroundX = GraphicsDataCylinder(p,[lFrame,0,0],tFrame,[0.9,0.3,0.3,1],12)
 95backgroundY = GraphicsDataCylinder(p,[0,lFrame,0],tFrame,[0.3,0.9,0.3,1],12)
 96backgroundZ = GraphicsDataCylinder(p,[0,0,lFrame],tFrame,[0.3,0.3,0.9,1],12)
 97#mbs.AddObject(ObjectGround(referencePosition= [0,0,0], visualization=VObjectGround(graphicsData= [backgroundX, backgroundY, backgroundZ])))
 98
 99#rotor is rotating around x-axis
100ep0 = eulerParameters0 #no rotation
101ep_t0 = AngularVelocity2EulerParameters_t([omegaInitial,0,0], ep0)
102print(ep_t0)
103
104p0 = [L0-0.5*L,eps,0] #reference position
105v0 = [0.,0.,0.] #initial translational velocity
106
107#node for Rigid2D body: px, py, phi:
108n1=mbs.AddNode(NodeRigidBodyEP(referenceCoordinates = p0+ep0, initialVelocities=v0+list(ep_t0)))
109
110#ground nodes
111nGround0=mbs.AddNode(NodePointGround(referenceCoordinates = [-L/2,0,0]))
112nGround1=mbs.AddNode(NodePointGround(referenceCoordinates = [ L/2,0,0]))
113
114#add mass point (this is a 3D object with 3 coordinates):
115gRotor = GraphicsDataCylinder([-lRotor*0.5,0,0],[lRotor,0,0],r,[0.3,0.3,0.9,1],128)
116gRotor2 = GraphicsDataCylinder([-L0,0,0],[L,0,0],r*0.05,[0.3,0.3,0.9,1],16)
117gRotor3 = [backgroundX, backgroundY, backgroundZ]
118rigid = mbs.AddObject(RigidBody(physicsMass=m, physicsInertia=[Jxx,Jyyzz,Jyyzz,0,0,0], nodeNumber = n1, visualization=VObjectRigidBody2D(graphicsData=[gRotor, gRotor2]+gRotor3)))
119
120mbs.AddSensor(SensorBody(bodyNumber=rigid,
121                         fileName='solution/runupDisplacement.txt',
122                         outputVariableType=exu.OutputVariableType.Displacement))
123mbs.AddSensor(SensorBody(bodyNumber=rigid,
124                         fileName='solution/runupAngularVelocity.txt',
125                         outputVariableType=exu.OutputVariableType.AngularVelocity))
126
127#marker for ground (=fixed):
128groundMarker0=mbs.AddMarker(MarkerNodePosition(nodeNumber= nGround0))
129groundMarker1=mbs.AddMarker(MarkerNodePosition(nodeNumber= nGround1))
130
131#marker for rotor axis and support:
132rotorAxisMarker0 =mbs.AddMarker(MarkerBodyPosition(bodyNumber=rigid, localPosition=[-L0,-eps,0]))
133rotorAxisMarker1 =mbs.AddMarker(MarkerBodyPosition(bodyNumber=rigid, localPosition=[ L1,-eps,0]))
134
135
136#++++++++++++++++++++++++++++++++++++
137mbs.AddObject(CartesianSpringDamper(markerNumbers=[groundMarker0, rotorAxisMarker0],
138                                    stiffness=[k,k,k], damping=[d, d, d]))
139mbs.AddObject(CartesianSpringDamper(markerNumbers=[groundMarker1, rotorAxisMarker1],
140                                   stiffness=[0,k,k], damping=[0, d, d])) #do not constrain x-axis twice
141
142#coordinate markers for loads:
143rotorMarkerUy=mbs.AddMarker(MarkerNodeCoordinate(nodeNumber= n1, coordinate=1))
144rotorMarkerUz=mbs.AddMarker(MarkerNodeCoordinate(nodeNumber= n1, coordinate=2))
145
146#add torque:
147rotorRigidMarker =mbs.AddMarker(MarkerBodyRigid(bodyNumber=rigid, localPosition=[0,0,0]))
148mbs.AddLoad(Torque(markerNumber=rotorRigidMarker, loadVector=[torque,0,0]))
149
150#print(mbs)
151mbs.Assemble()
152#mbs.systemData.Info()
153
154simulationSettings = exu.SimulationSettings()
155simulationSettings.solutionSettings.solutionWritePeriod = 1e-5  #output interval
156simulationSettings.solutionSettings.sensorsWritePeriod = 1e-5  #output interval
157
158if isSymmetric:
159    simulationSettings.solutionSettings.solutionInformation = "Runup of Laval rotor, resonance="+str(round(fRes,3))+"Hz at 80-90 seconds"
160else:
161    simulationSettings.solutionSettings.solutionInformation = "Runup of unsymmetric rotor"
162
163simulationSettings.timeIntegration.numberOfSteps = steps
164simulationSettings.timeIntegration.endTime = tEnd
165simulationSettings.timeIntegration.generalizedAlpha.useIndex2Constraints = True
166simulationSettings.timeIntegration.generalizedAlpha.useNewmark = True
167
168simulationSettings.timeIntegration.generalizedAlpha.spectralRadius = 1
169
170#create animations (causes slow simulation):
171createAnimation=True
172if createAnimation:
173    simulationSettings.solutionSettings.recordImagesInterval = 0.2
174    SC.visualizationSettings.exportImages.saveImageFileName = "images/frame"
175    SC.visualizationSettings.window.renderWindowSize = [1600,1080]
176
177
178exu.StartRenderer()              #start graphics visualization
179mbs.WaitForUserToContinue()    #wait for pressing SPACE bar to continue
180
181#start solver:
182mbs.SolveDynamic(simulationSettings)
183
184#SC.WaitForRenderEngineStopFlag()#wait for pressing 'Q' to quit
185exu.StopRenderer()               #safely close rendering window!
186
187#evaluate final (=current) output values
188u = mbs.GetNodeOutput(n1, exu.OutputVariableType.AngularVelocity)
189print('omega=',u)
190#print('displacement=',u[0])
191
192#+++++++++++++++++++++++++++++++++++++++++++++++++++++
193import matplotlib.pyplot as plt
194import matplotlib.ticker as ticker
195
196if False:
197    plt.close('all') #close all plots
198
199    dataDisp = np.loadtxt('solution/runupDisplacement.txt', comments='#', delimiter=',')
200    dataOmega = np.loadtxt('solution/runupAngularVelocity.txt', comments='#', delimiter=',')
201
202    plt.plot(dataDisp[:,0], dataDisp[:,3], 'b-') #numerical solution
203    plt.xlabel("time (s)")
204    plt.ylabel("z-displacement (m)")
205
206    plt.figure()
207    plt.plot((1/(2*np.pi))*dataOmega[:,1], dataDisp[:,3], 'b-') #numerical solution
208    plt.xlabel("angular velocity (1/s)")
209    plt.ylabel("z-displacement (m)")
210
211    plt.figure()
212    plt.plot(dataOmega[:,0], (1/(2*np.pi))*dataOmega[:,1], 'b-') #numerical solution
213    plt.xlabel("time (s)")
214    plt.ylabel("angular velocity (1/s)")
215
216    plt.figure()
217    plt.plot(dataDisp[:,2], dataDisp[:,3], 'r-') #numerical solution
218    plt.xlabel("y-displacement (m)")
219    plt.ylabel("z-displacement (m)")
220
221    #plt.plot(data[n-500:n-1,1], data[n-500:n-1,2], 'r-') #numerical solution
222
223    ax=plt.gca() # get current axes
224    ax.grid(True, 'major', 'both')
225    ax.xaxis.set_major_locator(ticker.MaxNLocator(10))
226    ax.yaxis.set_major_locator(ticker.MaxNLocator(10))
227    plt.tight_layout()
228    plt.show()