3SpringsDistance.py

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

  1#+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  2# This is an EXUDYN example
  3#
  4# Details:  File to test ConnectorDistance and ConnectorSpringDamper with point mass
  5#           NOTE: this is a very old example, still using dictionaries! check other examples, which use itemInterface!
  6#
  7# Author:   Johannes Gerstmayr
  8# Date:     2019-07-15
  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# Remark: check, why generalized alpha does work so badly for this example
 13#+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 14
 15import exudyn as exu
 16
 17SC = exu.SystemContainer()
 18mbs = SC.AddSystem()
 19
 20nBodies = 4
 21
 22L = 0.1 #distance
 23L2 = 1.414213562373095*L
 24
 25#add nodes:
 26#n0=mbs.AddNode({'nodeType': 'Point','referenceCoordinates': [0,0,0]})
 27#n1=mbs.AddNode({'nodeType': 'Point','referenceCoordinates': [L,L,0]})
 28#n2=mbs.AddNode({'nodeType': 'Point','referenceCoordinates': [0,L,L]})
 29n3=mbs.AddNode({'nodeType': 'Point','referenceCoordinates': [0,L,0]})
 30
 31#node2=mbs.GetNode(n3)
 32#print(node2)
 33
 34graphics1 = {'type':'Line', 'color':[0.1,0.1,0.8,1], 'data':[-2*L,-2*L,0, 2*L,-2*L,0, 2*L,2*L,0, -2*L,2*L,0, -2*L,-2*L, 0]}
 35
 36#add mass points and ground object:
 37mbs.AddObject({'objectType': 'Ground', 'referencePosition': [0,0,0], 'graphicsData': [graphics1]})
 38mbs.AddObject({'objectType': 'Ground', 'referencePosition': [L,L,0]})
 39mbs.AddObject({'objectType': 'Ground', 'referencePosition': [0,L,L]})
 40mbs.AddObject({'objectType': 'MassPoint', 'physicsMass': 2.5, 'nodeNumber': n3}) #, 'graphicsData': [graphics1]})
 41
 42#add markers (needed for connectors and loads):
 43for i in range(nBodies): mbs.AddMarker({'markerType': 'BodyPosition',  'bodyNumber': i,  'localPosition': [0.0, 0.0, 0.0], 'bodyFixed': False})
 44
 45k = 4000 #spring stiffness
 46d = 200*0.1  #damping coefficient
 47
 48useConstraint = True
 49if useConstraint:
 50    mbs.AddObject({'objectType': 'ConnectorDistance',
 51                   'distance': L,
 52                   'markerNumbers': [0,3],
 53                   'drawSize': 0.01,
 54                   'color': [1,0,0,1]})
 55else:
 56    mbs.AddObject({'objectType': 'ConnectorSpringDamper',
 57                   'stiffness': k,
 58                   'damping': d,
 59                   'force': 0,
 60                   'referenceLength':L,
 61                   'markerNumbers': [0,3],
 62                   'drawSize': 0.01})
 63mbs.AddObject({'objectType': 'ConnectorSpringDamper',
 64               'stiffness': k,
 65               'damping': d,
 66               'force': 0,
 67               'referenceLength':L,
 68               'markerNumbers': [1,3],
 69               'drawSize': 0.01})
 70mbs.AddObject({'objectType': 'ConnectorSpringDamper',
 71               'stiffness': k,
 72               'damping': d,
 73               'force': 0,
 74               'referenceLength':L,
 75               'markerNumbers': [2,3],
 76               'drawSize': 0.01})
 77
 78#add loads:
 79#mbs.AddLoad({'loadType': 'ForceVector',  'markerNumber': nBodies-1,  'loadVector': [0, 20, 0]}) #gives 20N tension in Distance constraint
 80mbs.AddLoad({'loadType': 'ForceVector',  'markerNumber': nBodies-1,  'loadVector': [10, 0, 0]}) #gives approx. 0.001 deformation in x-direction
 81
 82print(mbs)
 83
 84mbs.Assemble()
 85exu.StartRenderer()
 86
 87simulationSettings = exu.SimulationSettings()
 88
 89SC.visualizationSettings.nodes.showNumbers = True
 90SC.visualizationSettings.bodies.showNumbers = True
 91SC.visualizationSettings.connectors.showNumbers = True
 92SC.visualizationSettings.nodes.defaultSize = 0.05
 93
 94
 95computeDynamic = True
 96if computeDynamic:
 97    simulationSettings.timeIntegration.numberOfSteps = 100000000
 98    simulationSettings.timeIntegration.endTime = 500000
 99    simulationSettings.solutionSettings.writeSolutionToFile = True
100    simulationSettings.solutionSettings.solutionWritePeriod = simulationSettings.timeIntegration.endTime/2000
101    simulationSettings.displayComputationTime = True
102    simulationSettings.timeIntegration.verboseMode = 1
103
104    simulationSettings.timeIntegration.newton.relativeTolerance = 1e-8
105    simulationSettings.timeIntegration.newton.absoluteTolerance = 1e-2
106    simulationSettings.timeIntegration.newton.useModifiedNewton = True
107    simulationSettings.timeIntegration.generalizedAlpha.useNewmark = True #example only works with Newmark
108    simulationSettings.timeIntegration.generalizedAlpha.useIndex2Constraints = True
109    simulationSettings.displayStatistics = True
110
111    mbs.SolveDynamic(simulationSettings)
112
113else:
114    simulationSettings.solutionSettings.coordinatesSolutionFileName = "staticSolution.txt"
115    simulationSettings.solutionSettings.appendToFile = False
116    simulationSettings.staticSolver.newton.numericalDifferentiation.relativeEpsilon = 1e-4
117    #simulationSettings.staticSolver.newton.relativeTolerance = 1e-6
118    simulationSettings.staticSolver.newton.absoluteTolerance = 1e-1
119    simulationSettings.staticSolver.verboseMode = 2
120
121    mbs.SolveStatic(simulationSettings)
122
123SC.WaitForRenderEngineStopFlag()
124exu.StopRenderer() #safely close rendering window!