rollingCoinPenaltyTest.py

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

  1#+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  2# This is an EXUDYN example
  3#
  4# Details:  Rolling coin example;
  5#           examine example of Rill, Schaeffer, Grundlagen und Methodik der Mehrkörpersimulation, 2010, page 59
  6#           Note that in comparison to the literature, we use the local x-axis for the local axis of the coin, z is the normal to the plane
  7#           mass and inertia do not influence the results, as long as mass and inertia of a infinitely small ring are used
  8#           gravity is set to [0,0,-9.81m/s^2] and the radius is 0.01m;
  9#           In this example, the penalty formulation is used, which additionally treats friction
 10#
 11# Author:   Johannes Gerstmayr
 12# Date:     2020-06-19
 13#
 14# 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.
 15#
 16#+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 17
 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
 22import numpy as np
 23
 24useGraphics = True #without test
 25#+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 26#you can erase the following lines and all exudynTestGlobals related operations if this is not intended to be used as TestModel:
 27try: #only if called from test suite
 28    from modelUnitTests import exudynTestGlobals #for globally storing test results
 29    useGraphics = exudynTestGlobals.useGraphics
 30except:
 31    class ExudynTestGlobals:
 32        pass
 33    exudynTestGlobals = ExudynTestGlobals()
 34#+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 35
 36SC = exu.SystemContainer()
 37mbs = SC.AddSystem()
 38
 39phi0 = 5./180.*np.pi#initial nick angle of disc, 1 degree
 40g = [0,0,-9.81]     #gravity in m/s^2
 41m = 1               #mass in kg
 42r = 0.01            #radius of disc in m
 43w = 0.001           #width of disc in m, just for drawing
 44p0 = [r*np.sin(phi0),0,r*np.cos(phi0)+0.01] #origin of disc center point at reference, such that initial contact point is at [0,0,0]
 45initialRotation = RotationMatrixY(phi0)
 46
 47omega0 = [40,0,0*1800/180*np.pi]                   #initial angular velocity around z-axis
 48v0 = Skew(omega0) @ initialRotation @ [0,0,r]   #initial angular velocity of center point
 49#v0 = [0,0,0]                                   #initial translational velocity
 50#exu.Print("v0=",v0)#," = ", [0,10*np.pi*r*np.sin(phi0),0])
 51
 52#inertia for infinitely small ring:
 53inertiaRing = RigidBodyInertia(mass=1, inertiaTensor= np.diag([0.5*m*r**2, 0.25*m*r**2, 0.25*m*r**2]))
 54#print(inertiaRing)
 55
 56#additional graphics for visualization of rotation:
 57graphicsBody = graphics.Brick(centerPoint=[0,0,0],size=[w*1.1,0.7*r,0.7*r], color=graphics.color.lightred)
 58
 59[n0,b0]=AddRigidBody(mainSys = mbs,
 60                     inertia = inertiaRing,
 61                     nodeType = str(exu.NodeType.RotationEulerParameters),
 62                     position = p0,
 63                     rotationMatrix = initialRotation, #np.diag([1,1,1]),
 64                     angularVelocity = omega0,
 65                     velocity=v0,
 66                     gravity = g,
 67                     graphicsDataList = [graphicsBody])
 68
 69#ground body and marker
 70gGround = graphics.Brick(centerPoint=[0,0,-0.001],size=[0.3,0.3,0.002], color=graphics.color.lightgrey)
 71oGround = mbs.AddObject(ObjectGround(visualization=VObjectGround(graphicsData=[gGround])))
 72markerGround = mbs.AddMarker(MarkerBodyRigid(bodyNumber=oGround, localPosition=[0,0,0]))
 73
 74#markers for rigid body:
 75markerBody0J0 = mbs.AddMarker(MarkerBodyRigid(bodyNumber=b0, localPosition=[0,0,0]))
 76
 77#rolling disc:
 78nGeneric = mbs.AddNode(NodeGenericData(initialCoordinates=[0,0,0], numberOfDataCoordinates=3))
 79oRolling=mbs.AddObject(ObjectConnectorRollingDiscPenalty(markerNumbers=[markerGround, markerBody0J0], nodeNumber = nGeneric,
 80                                              discRadius=r, dryFriction=[0.8,0.8], dryFrictionProportionalZone=1e-2,
 81                                              rollingFrictionViscous=0.2,
 82                                              contactStiffness=1e5, contactDamping=1e4,
 83                                              visualization=VObjectConnectorRollingDiscPenalty(discWidth=w, color=graphics.color.blue)))
 84
 85
 86#sensor for trace of contact point:
 87if useGraphics:
 88    sTrail=mbs.AddSensor(SensorObject(objectNumber=oRolling, storeInternal=True,#fileName='solution/rollingDiscTrail.txt',
 89                               outputVariableType = exu.OutputVariableType.Position))
 90
 91    sTrailVel=mbs.AddSensor(SensorObject(objectNumber=oRolling, storeInternal=True,#fileName='solution/rollingDiscTrailVel.txt',
 92                               outputVariableType = exu.OutputVariableType.Velocity))
 93
 94
 95    sAngVel=mbs.AddSensor(SensorBody(bodyNumber=b0, storeInternal=True,#fileName='solution/rollingDiscAngVel.txt',
 96                               outputVariableType = exu.OutputVariableType.AngularVelocity))
 97
 98    sPos=mbs.AddSensor(SensorBody(bodyNumber=b0, storeInternal=True,#fileName='solution/rollingDiscPos.txt',
 99                               outputVariableType = exu.OutputVariableType.Position))
100
101    sForce=mbs.AddSensor(SensorObject(objectNumber=oRolling, storeInternal=True,#fileName='solution/rollingDiscForceLocal.txt',
102                               outputVariableType = exu.OutputVariableType.ForceLocal))
103
104mbs.Assemble()
105
106simulationSettings = exu.SimulationSettings() #takes currently set values or default values
107
108tEnd = 0.5
109if useGraphics:
110    tEnd = 0.5
111
112h=0.0001
113
114simulationSettings.timeIntegration.numberOfSteps = int(tEnd/h)
115simulationSettings.timeIntegration.endTime = tEnd
116#simulationSettings.solutionSettings.solutionWritePeriod = 0.01
117simulationSettings.solutionSettings.sensorsWritePeriod = 0.0005
118#simulationSettings.timeIntegration.verboseMode = 1
119simulationSettings.solutionSettings.writeSolutionToFile = False
120
121simulationSettings.timeIntegration.generalizedAlpha.useIndex2Constraints = True
122simulationSettings.timeIntegration.generalizedAlpha.useNewmark = True
123simulationSettings.timeIntegration.generalizedAlpha.spectralRadius = 0.5
124simulationSettings.timeIntegration.generalizedAlpha.computeInitialAccelerations=True
125
126
127SC.visualizationSettings.nodes.show = True
128SC.visualizationSettings.nodes.drawNodesAsPoint  = False
129SC.visualizationSettings.nodes.showBasis = True
130SC.visualizationSettings.nodes.basisSize = 0.015
131
132if useGraphics:
133    exu.StartRenderer()
134    mbs.WaitForUserToContinue()
135
136mbs.SolveDynamic(simulationSettings)
137
138p0=mbs.GetObjectOutput(oRolling, exu.OutputVariableType.Position)
139exu.Print('solution of rollingCoinPenaltyTest=',p0[0]) #use x-coordinate
140
141exudynTestGlobals.testError = p0[0] - (0.03489603106769764) #2020-06-20: 0.03489603106769764
142exudynTestGlobals.testResult = p0[0]
143
144
145if useGraphics:
146    SC.WaitForRenderEngineStopFlag()
147    exu.StopRenderer() #safely close rendering window!
148
149    ##++++++++++++++++++++++++++++++++++++++++++++++q+++++++
150    #plot results
151    if True:
152
153
154        mbs.PlotSensor(sTrail, componentsX=[0],components=[1], closeAll=True, title='wheel trail')
155
156        mbs.PlotSensor(sPos, components=[0,1,2], title='wheel position')
157        mbs.PlotSensor(sForce, components=[0,1,2], title='wheel force')
158
159        mbs.PlotSensor(sAngVel, components=[0], title='wheel local angular velocity')