springsDeactivateConnectors.py
You can view and download this file on Github: springsDeactivateConnectors.py
1#+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2# This is an EXUDYN example
3#
4# Details: Test with spring dampers and 'activeConnector';
5# short-time simulations are performed and herafter, springs are deactivated
6# based on the size of the spring-damper force
7#
8# Author: Johannes Gerstmayr
9# Date: 2019-11-22
10#
11# 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.
12#
13#+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
14
15import exudyn as exu
16from exudyn.itemInterface import *
17from exudyn.utilities import * #includes itemInterface and rigidBodyUtilities
18import exudyn.graphics as graphics #only import if it does not conflict
19
20SC = exu.SystemContainer()
21mbs = SC.AddSystem()
22
23useGraphics = False
24
25nBodies = 8
26nBodies2 = 4#3
27
28bodyMarkerList=[]
29for j in range(nBodies2):
30 body = mbs.AddObject({'objectType': 'Ground', 'referencePosition': [0,j,0]})
31 mbs.AddMarker({'markerType': 'BodyPosition', 'bodyNumber': body, 'localPosition': [0.0, 0.0, 0.0], 'bodyFixed': False})
32 for i in range(nBodies-1):
33 node = mbs.AddNode({'nodeType': 'Point','referenceCoordinates': [i+1, j, 0.0],'initialCoordinates': [(i+1)*0.05*0, 0.0, 0.0], 'initialVelocities': [0., 0., 0.],})
34 body = mbs.AddObject({'objectType': 'MassPoint', 'physicsMass': 10, 'nodeNumber': node})
35 mBody = mbs.AddMarker({'markerType': 'BodyPosition', 'bodyNumber': body, 'localPosition': [0.0, 0.0, 0.0], 'bodyFixed': False})
36 bodyMarkerList += [mBody]
37
38#add spring-dampers:
39springList=[]
40for j in range(nBodies2-1):
41 for i in range(nBodies-1):
42 nSpring = mbs.AddObject({'objectType': 'ConnectorSpringDamper', 'stiffness': 4000, 'damping': 10, 'force': 0,
43 'referenceLength':1, 'markerNumbers': [j*nBodies + i,j*nBodies + i+1]})
44 springList += [nSpring]
45 nSpring = mbs.AddObject({'objectType': 'ConnectorSpringDamper', 'stiffness': 4000, 'damping': 10, 'force': 0,
46 'referenceLength':1, 'markerNumbers': [j*nBodies + i,(j+1)*nBodies + i]})
47 springList += [nSpring]
48 #diagonal spring: l*sqrt(2)
49 nSpring = mbs.AddObject({'objectType': 'ConnectorSpringDamper', 'stiffness': 4000, 'damping': 10, 'force': 0,
50 'referenceLength':sqrt2, 'markerNumbers': [j*nBodies + i,(j+1)*nBodies + i+1]})
51 springList += [nSpring]
52
53for i in range(nBodies-1):
54 j = nBodies2-1
55 nSpring = mbs.AddObject({'objectType': 'ConnectorSpringDamper', 'stiffness': 4000, 'damping': 10, 'force': 0,
56 'referenceLength':1, 'markerNumbers': [j*nBodies + i,j*nBodies + i+1]})
57 springList += [nSpring]
58for j in range(nBodies2-1):
59 i = nBodies-1
60 nSpring = mbs.AddObject({'objectType': 'ConnectorSpringDamper', 'stiffness': 4000, 'damping': 10, 'force': 0,
61 'referenceLength':1, 'markerNumbers': [j*nBodies + i,(j+1)*nBodies + i]})
62 springList += [nSpring]
63
64#add loads:
65#mbs.AddLoad({'loadType': 'ForceVector', 'markerNumber': nBodies*nBodies2-1, 'loadVector': [0, -50*2, 0]})
66for marker in bodyMarkerList:
67 mbs.AddLoad({'loadType': 'ForceVector', 'markerNumber': marker, 'loadVector': [0, -16, 0]})
68
69#add constraints for testing:
70nGround = mbs.AddNode(NodePointGround(referenceCoordinates=[-0.5,0,0])) #ground node for coordinate constraint
71mGround = mbs.AddMarker(MarkerNodeCoordinate(nodeNumber = nGround, coordinate=0)) #Ground node ==> no action
72
73
74mbs.Assemble()
75
76if useGraphics:
77 exu.StartRenderer()
78
79simulationSettings = exu.SimulationSettings()
80simulationSettings.timeIntegration.numberOfSteps = 20
81simulationSettings.timeIntegration.endTime = 0.005
82simulationSettings.timeIntegration.verboseMode = 0
83simulationSettings.timeIntegration.newton.useModifiedNewton = True
84
85simulationSettings.timeIntegration.generalizedAlpha.useNewmark = True
86simulationSettings.timeIntegration.generalizedAlpha.useIndex2Constraints = True
87
88SC.visualizationSettings.nodes.defaultSize = 0.05
89SC.visualizationSettings.openGL.multiSampling = 4
90
91nSteps = 10
92if useGraphics:
93 nSteps = 800
94
95for i in range(nSteps): #1000
96 # print('iteration '+str(i)+':')
97 mbs.SolveDynamic(simulationSettings, solverType = exudyn.DynamicSolverType.DOPRI5)
98
99 for spring in springList:
100 dist = mbs.GetObjectOutput(spring, exu.OutputVariableType.Distance)
101 force = NormL2(mbs.GetObjectOutput(spring, exu.OutputVariableType.Force))
102
103 dist0= mbs.GetObjectParameter(spring, 'referenceLength')
104 #print('spring '+str(spring)+' length = ' + str(dist) + ', elongation = ' + str(dist-dist0))
105 #print('spring '+str(spring)+' force = ' + str(force))
106
107 if force > 400:
108 # if mbs.GetObjectParameter(spring, 'activeConnector'):
109 # print('BREAK spring '+str(spring))
110 mbs.SetObjectParameter(spring, 'activeConnector', False)
111 mbs.SetObjectParameter(spring, 'Vshow', False)
112
113 u = mbs.systemData.GetODE2Coordinates()
114 v = mbs.systemData.GetODE2Coordinates_t()
115 mbs.systemData.SetODE2Coordinates(u,configuration = exu.ConfigurationType.Initial)
116 mbs.systemData.SetODE2Coordinates_t(v,configuration = exu.ConfigurationType.Initial)
117
118u = mbs.GetNodeOutput(nBodies-2, exu.OutputVariableType.Position) #tip node
119print('dynamic tip displacement (y)=', u[1])
120
121if useGraphics:
122 SC.WaitForRenderEngineStopFlag()
123 exu.StopRenderer()