lavalRotor2Dtest.py

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

  1#+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  2# This is an EXUDYN example
  3#
  4# Details:  Example with 2D laval rotor; shows backward and forward whirl effects using
  5#           Includes user load and Sweep
  6#
  7# Author:   Johannes Gerstmayr
  8# Date:     2019-12-03
  9#
 10# 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.
 11#
 12#+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 13import sys
 14sys.path.append('../TestModels')            #for modelUnitTest as this example may be used also as a unit test
 15
 16import exudyn as exu
 17from exudyn.itemInterface import *
 18from exudyn.utilities import * #includes itemInterface and rigidBodyUtilities
 19import exudyn.graphics as graphics #only import if it does not conflict
 20
 21import time
 22import numpy as np
 23
 24SC = exu.SystemContainer()
 25mbs = SC.AddSystem()
 26print('EXUDYN version='+exu.GetVersionString())
 27
 28L=1                     #rotor length
 29mass = 1.6              #mass in kg
 30r = 0.5                 #radius for disc mass distribution
 31spring = 4000           #stiffness of (all/both) springs in rotor in N/m
 32omega0=np.sqrt(spring/mass) #linear system
 33
 34zeta = 0.001*5
 35damper = 2*omega0*zeta*mass  #damping constant in N/(m/s)
 36
 37f0 = 0.*omega0/(2*np.pi)
 38f1 = 1.*omega0/(2*np.pi)
 39
 40torque = 0*1 #Nm
 41eps = 1e-2 #excentricity in y-direction
 42omegaInitial = 0.5*omega0
 43
 44print('resonance frequency = '+str(omega0/2/np.pi)+'Hz')
 45tEnd = 50     #end time of simulation
 46steps = 10000  #number of steps
 47
 48
 49#linear frequency sweep in time interval [0, t1] and frequency interval [f0,f1];
 50def Sweep(t, t1, f0, f1):
 51    k = (f1-f0)/t1
 52    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!!!
 53
 54#user function for load
 55def userLoad(mbs, t, load):
 56    #return load*np.sin(0.5*omega0*t) #gives resonance
 57    if t>40: time.sleep(0.02) #make simulation slower
 58    return load*Sweep(t, tEnd, f0, f1)
 59    #return load*Sweep(t, tEnd, f1, f0) #backward sweep
 60
 61#backward whirl excitation:
 62amp = 0*10  #in resonance: *0.01
 63def userLoadBWx(mbs, t, load):
 64    return load*np.sin(omegaInitial*t)
 65def userLoadBWy(mbs, t, load):
 66    return -load*np.cos(omegaInitial*t) #negative sign: FW, positive sign: BW
 67
 68#node for Rigid2D body: px, py, phi:
 69n1=mbs.AddNode(Rigid2D(referenceCoordinates = [0,eps,0],
 70                       initialCoordinates=[0,0,0],
 71                       initialVelocities=[0,0,omegaInitial]))
 72
 73#ground node
 74nGround=mbs.AddNode(NodePointGround(referenceCoordinates = [0,0,0]))
 75
 76#add mass point (this is a 3D object with 3 coordinates):
 77gRotor = GraphicsDataRectangle(-r*0.5,-r*0.5,r*0.5,r*0.5,[1,0,0,1])
 78rigid2D = mbs.AddObject(RigidBody2D(physicsMass=mass, physicsInertia=mass*r**2, nodeNumber = n1, visualization=VObjectRigidBody2D(graphicsData=[gRotor])))
 79
 80#marker for ground (=fixed):
 81groundMarker=mbs.AddMarker(MarkerNodeCoordinate(nodeNumber= nGround, coordinate = 0))
 82
 83#marker for rotor axis and support:
 84rotorAxisMarker =mbs.AddMarker(MarkerBodyPosition(bodyNumber=rigid2D, localPosition=[0,-eps,0]))
 85groundBody= mbs.AddObject(ObjectGround(referencePosition=[0,0,0]))
 86rotorSupportMarker=mbs.AddMarker(MarkerBodyPosition(bodyNumber=groundBody, localPosition=[0,0,0]))
 87
 88#marker for springDamper for first (x-)coordinate:
 89coordXMarker = mbs.AddMarker(MarkerNodeCoordinate(nodeNumber= n1, coordinate = 0))
 90coordYMarker = mbs.AddMarker(MarkerNodeCoordinate(nodeNumber= n1, coordinate = 1))
 91coordPhiMarker = mbs.AddMarker(MarkerNodeCoordinate(nodeNumber= n1, coordinate = 2))
 92
 93mbs.AddObject(CartesianSpringDamper(markerNumbers=[rotorSupportMarker, rotorAxisMarker], stiffness=[spring,spring,0], damping=[damper, damper,0]))
 94
 95#add load:
 96mbs.AddLoad(LoadCoordinate(markerNumber = coordYMarker, load = 0, loadUserFunction=userLoad))
 97mbs.AddLoad(LoadCoordinate(markerNumber = coordPhiMarker, load = torque))#, loadUserFunction=userLoad))
 98
 99mbs.AddLoad(LoadCoordinate(markerNumber = coordXMarker, load = amp, loadUserFunction=userLoadBWx))
100mbs.AddLoad(LoadCoordinate(markerNumber = coordYMarker, load = amp, loadUserFunction=userLoadBWy))
101
102print(mbs)
103mbs.Assemble()
104
105simulationSettings = exu.SimulationSettings()
106simulationSettings.solutionSettings.solutionWritePeriod = 1e-5  #output interval
107simulationSettings.timeIntegration.numberOfSteps = steps
108simulationSettings.timeIntegration.endTime = tEnd
109
110simulationSettings.timeIntegration.generalizedAlpha.spectralRadius = 1
111
112exu.StartRenderer()              #start graphics visualization
113mbs.WaitForUserToContinue()    #wait for pressing SPACE bar to continue
114
115#start solver:
116mbs.SolveDynamic(simulationSettings)
117
118exu.StopRenderer()               #safely close rendering window!
119
120#evaluate final (=current) output values
121u = mbs.GetNodeOutput(n1, exu.OutputVariableType.Position)
122print('displacement=',u[0])
123
124#+++++++++++++++++++++++++++++++++++++++++++++++++++++
125import matplotlib.pyplot as plt
126import matplotlib.ticker as ticker
127
128if True:
129    data = np.loadtxt('coordinatesSolution.txt', comments='#', delimiter=',')
130    n=steps
131    #plt.plot(data[:,0], data[:,6], 'r-') #numerical solution
132    plt.plot(data[n-500:n-1,1], data[n-500:n-1,2], 'r-') #numerical solution
133
134    ax=plt.gca() # get current axes
135    ax.grid(True, 'major', 'both')
136    ax.xaxis.set_major_locator(ticker.MaxNLocator(10))
137    ax.yaxis.set_major_locator(ticker.MaxNLocator(10))
138    plt.tight_layout()
139    plt.show()