rigidPendulum.py

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

 1#+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 2# This is an EXUDYN example
 3#
 4# Details:  Example 2D rigid pendulum
 5#
 6# Author:   Johannes Gerstmayr
 7# Date:     2019-08-15
 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#+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
12
13import exudyn as exu
14from exudyn.utilities import * #includes itemInterface and rigidBodyUtilities
15import exudyn.graphics as graphics #only import if it does not conflict
16
17SC = exu.SystemContainer()
18mbs = SC.AddSystem()
19
20
21#+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
22#rigid pendulum:
23L = 1    #x-dim of pendulum
24b = 0.1  #y-dim of pendulum
25background = graphics.CheckerBoard(point=[-1,0.5,0],size=2)
26oGround=mbs.AddObject(ObjectGround(referencePosition= [0,0,0], visualization=VObjectGround(graphicsData= [background])))
27massRigid = 12
28inertiaRigid = massRigid/12*(L)**2
29g = 9.81    # gravity
30
31graphicsCube = graphics.Brick(size= [L,b,b], color= graphics.color.dodgerblue, addEdges=True)
32graphicsJoint = graphics.Cylinder(pAxis=[-0.5*L,0,-0.6*b], vAxis= [0,0,1.2*b], radius = 0.55*b, color=graphics.color.darkgrey, addEdges=True)
33nRigid = mbs.AddNode(Rigid2D(referenceCoordinates=[-0.5*L,L,0], initialVelocities=[0,0,2]));
34oRigid = mbs.AddObject(RigidBody2D(physicsMass=massRigid, physicsInertia=inertiaRigid,nodeNumber=nRigid,
35                                   visualization=VObjectRigidBody2D(graphicsData= [graphicsCube, graphicsJoint])))
36
37mR1 = mbs.AddMarker(MarkerBodyPosition(bodyNumber=oRigid, localPosition=[-0.5*L,0.,0.])) #support point
38mR2 = mbs.AddMarker(MarkerBodyPosition(bodyNumber=oRigid, localPosition=[ 0.,0.,0.])) #end point
39
40mG0 = mbs.AddMarker(MarkerBodyPosition(bodyNumber=oGround, localPosition=[-L,L,0.]))
41mbs.AddObject(RevoluteJoint2D(markerNumbers=[mG0,mR1]))
42
43mbs.AddLoad(Force(markerNumber = mR2, loadVector = [0, -massRigid*g, 0]))
44
45mbs.Assemble()
46print(mbs)
47
48simulationSettings = exu.SimulationSettings() #takes currently set values or default values
49
50simulationSettings.timeIntegration.numberOfSteps = 1000000
51simulationSettings.timeIntegration.endTime = 2000
52simulationSettings.timeIntegration.startTime = 0
53simulationSettings.timeIntegration.newton.relativeTolerance = 1e-8*100 #10000
54simulationSettings.timeIntegration.newton.absoluteTolerance = 1e-10
55simulationSettings.timeIntegration.verboseMode = 1
56
57simulationSettings.timeIntegration.newton.useModifiedNewton = False
58simulationSettings.timeIntegration.newton.numericalDifferentiation.minimumCoordinateSize = 1
59simulationSettings.timeIntegration.generalizedAlpha.spectralRadius = 0.5
60simulationSettings.displayStatistics = True
61
62#SC.visualizationSettings.nodes.defaultSize = 0.05
63
64simulationSettings.solutionSettings.solutionInformation = "Rigid pendulum"
65SC.visualizationSettings.openGL.multiSampling = 4
66SC.visualizationSettings.openGL.lineWidth = 2
67
68exu.StartRenderer()
69
70
71mbs.SolveDynamic(simulationSettings)
72
73SC.WaitForRenderEngineStopFlag()
74exu.StopRenderer() #safely close rendering window!