rigidRotor3Dnutation.py
You can view and download this file on Github: rigidRotor3Dnutation.py
1#+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2# This is an EXUDYN example
3#
4# Details: Example with 3D rotor, test nutation with point force
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
26m = 2 #mass in kg
27r = 0.5 #radius for disc mass distribution
28lRotor = 0.2 #length of rotor disk
29k = 8000 #stiffness of (all/both) springs in rotor in N/m
30Jxx = 0.5*m*r**2 #polar moment of inertia
31Jyyzz = 0.25*m*r**2 + 1/12.*m*lRotor**2 #moment of inertia for y and z axes
32
33omega0=np.sqrt(2*k/m) #linear system
34
35D0 = 0.002 #dimensionless damping
36d = 2*omega0*D0*m #damping constant in N/(m/s)
37
38omegaInitial = 0.1*omega0 #initial rotation speed in rad/s
39
40print('resonance frequency (rad/s)= '+str(omega0))
41
42tEnd = 50 #end time of simulation
43steps = 20000 #number of steps
44
45
46#user function for load
47def userLoad(mbs, t, load):
48 #time.sleep(0.005) #make simulation slower
49 if t<0.01: print(load)
50 if t>10 and t<10.05:
51 return load
52 else:
53 return [0,0,0]
54
55
56#draw RGB-frame at origin
57p=[0,0,0]
58lFrame = 0.8
59tFrame = 0.01
60backgroundX = GraphicsDataCylinder(p,[lFrame,0,0],tFrame,[0.9,0.3,0.3,1],12)
61backgroundY = GraphicsDataCylinder(p,[0,lFrame,0],tFrame,[0.3,0.9,0.3,1],12)
62backgroundZ = GraphicsDataCylinder(p,[0,0,lFrame],tFrame,[0.3,0.3,0.9,1],12)
63#mbs.AddObject(ObjectGround(referencePosition= [0,0,0], visualization=VObjectGround(graphicsData= [backgroundX, backgroundY, backgroundZ])))
64
65#rotor is rotating around x-axis
66ep0 = eulerParameters0 #no rotation
67ep_t0 = AngularVelocity2EulerParameters_t([omegaInitial,0,0], ep0)
68print(ep_t0)
69
70p0 = [0,0,0] #reference position
71v0 = [0.,0.,0.] #initial translational velocity
72
73#node for Rigid2D body: px, py, phi:
74n1=mbs.AddNode(NodeRigidBodyEP(referenceCoordinates = p0+ep0, initialVelocities=v0+list(ep_t0)))
75
76#ground nodes
77nGround0=mbs.AddNode(NodePointGround(referenceCoordinates = [0,0,0]))
78
79#add mass point (this is a 3D object with 3 coordinates):
80gRotor = GraphicsDataCylinder([-lRotor*0.5,0,0],[lRotor*0.5,0,0],r,[0.3,0.3,0.9,1],32)
81gRotor3 = [backgroundX, backgroundY, backgroundZ]
82rigid = mbs.AddObject(RigidBody(physicsMass=m, physicsInertia=[Jxx,Jyyzz,Jyyzz,0,0,0], nodeNumber = n1,
83 visualization=VObjectRigidBody2D(graphicsData=[gRotor]+gRotor3)))
84
85#marker for ground (=fixed):
86groundMarker0=mbs.AddMarker(MarkerNodePosition(nodeNumber= nGround0))
87
88#marker for rotor axis and support:
89rotorAxisMarker0 =mbs.AddMarker(MarkerBodyPosition(bodyNumber=rigid, localPosition=[0,0,0]))
90
91
92#++++++++++++++++++++++++++++++++++++
93mbs.AddObject(CartesianSpringDamper(markerNumbers=[groundMarker0, rotorAxisMarker0],
94 stiffness=[k,k,k], damping=[d, d, d]))
95
96#add force/torque:
97rotorRigidMarker =mbs.AddMarker(MarkerBodyRigid(bodyNumber=rigid, localPosition=[0,r,0]))
98mbs.AddLoad(Force(markerNumber=rotorRigidMarker, loadVector=[0.3,0.2,0.1], loadVectorUserFunction = userLoad))
99#mbs.AddLoad(Torque(markerNumber=rotorRigidMarker, loadVector=[torque,0,0]))
100
101#print(mbs)
102mbs.Assemble()
103#mbs.systemData.Info()
104
105simulationSettings = exu.SimulationSettings()
106simulationSettings.solutionSettings.solutionWritePeriod = 1e-2 #output interval
107simulationSettings.timeIntegration.numberOfSteps = steps
108simulationSettings.timeIntegration.endTime = tEnd
109simulationSettings.timeIntegration.generalizedAlpha.useIndex2Constraints = True
110simulationSettings.timeIntegration.generalizedAlpha.useNewmark = True
111
112simulationSettings.timeIntegration.generalizedAlpha.spectralRadius = 1
113
114
115#start solver:
116mbs.SolveDynamic(simulationSettings)
117
118exu.StartRenderer() #start graphics visualization
119mbs.WaitForUserToContinue() #wait for pressing SPACE bar to continue
120
121fileName = 'coordinatesSolution.txt'
122solution = LoadSolutionFile('coordinatesSolution.txt')
123AnimateSolution(mbs, solution, 5, 0.02)
124
125#SC.WaitForRenderEngineStopFlag()#wait for pressing 'Q' to quit
126exu.StopRenderer() #safely close rendering window!
127
128
129###+++++++++++++++++++++++++++++++++++++++++++++++++++++
130#import matplotlib.pyplot as plt
131#import matplotlib.ticker as ticker
132#
133#if True:
134# data = np.loadtxt('coordinatesSolution.txt', comments='#', delimiter=',')
135# n=steps
136# #plt.plot(data[:,2], data[:,3], 'r-') #numerical solution
137# #plt.plot(data[:,0], data[:,2], 'b-') #numerical solution
138# plt.plot(data[:,0], data[:,3], 'g-') #numerical solution
139# #plt.plot(data[n-500:n-1,1], data[n-500:n-1,2], 'r-') #numerical solution
140#
141# ax=plt.gca() # get current axes
142# ax.grid(True, 'major', 'both')
143# ax.xaxis.set_major_locator(ticker.MaxNLocator(10))
144# ax.yaxis.set_major_locator(ticker.MaxNLocator(10))
145# plt.tight_layout()
146# plt.show()