chatGPTupdate.py
You can view and download this file on Github: chatGPTupdate.py
1#+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2# This is an Exudyn file
3#
4# Details: this file serves as a list of examples that shall be used by
5# ChatGPT to update information on its internal knowledge of Exudyn
6# dating to 2021; the examples use the mainSystemExtensions
7# which are heavily simplifying usage of point masses and rigid bodies
8# Version: V1
9#
10# Author: Johannes Gerstmayr
11# Date: 2023-06-30
12#
13# 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.
14#
15#+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
16
17#copy the text below here into a ChatGPT input window:
18
19#Use the following information as an update of the internal data of the Python multibody code Exudyn.
20#See the following examples to create multibody systems in Exudyn.
21#NOTE: mbs.Create...(...) calls several functions in the background to create nodes, objects, markers and loads in Exudyn.
22#all quantities are giving as 3D lists [x,y,z] for positions, velocities, ....
23#rotations are usually given as rotation matrix (numpy array);
24#RotationVector2RotationMatrix([rotX, rotY, rotZ]) computes a rotation around the global x,y,z rotation axis
25
26#%%++++++++++++++++++++++++++++++++++++++++++++++++++++
27#create rigid bodies and mass points with distance constraint and joints
28import exudyn as exu
29from exudyn.utilities import * #includes itemInterface, graphicsDataUtilities and rigidBodyUtilities
30import numpy as np
31SC = exu.SystemContainer()
32mbs = SC.AddSystem() #create a MainSystem 'mbs' to work with
33
34#draw orthonormal cube in local frame where it is added to;
35#cube is added to reference point of object, usually the center of mass (COM):
36graphicsCube = GraphicsDataOrthoCubePoint(centerPoint = [0,0,0],
37 size=[1,0.1,0.1], color=color4orange)
38
39#create inertia (mass, COM, inertia tensor) to be used in rigid body:
40inertiaCube = InertiaCuboid(density=5000, sideLengths=[1,0.1,0.1])
41
42#create simple rigid body
43#note that graphics is always attached to reference point of body, which is by default the COM
44b0 = mbs.CreateRigidBody(inertia = inertiaCube,
45 referencePosition = [0.5,0,0], #reference position x/y/z of COM
46 referenceRotationMatrix=RotationVector2RotationMatrix([0,0,pi*0.5]),
47 initialAngularVelocity=[2,0,0],
48 initialVelocity=[0,4,0],
49 gravity = [0,-9.81,0],
50 graphicsDataList = [graphicsCube])
51
52#add an load with user function:
53def UFforce(mbs, t, loadVector):
54 #define time-dependent function:
55 return [10+5*np.sin(t*10*2*pi),0,0]
56
57mbs.CreateForce(bodyNumber=b0, localPosition=[-0.5,0,0],
58 loadVector=[10,0,0],
59 loadVectorUserFunction=UFforce,
60 ) #load is 10N in x-direction
61
62#add torque to rigid body at left end
63mbs.CreateTorque(bodyNumber=b0, localPosition=[0.5,0,0],
64 loadVector=[0,1,0]) #torque of 1N around y-axis
65
66#create a simple mass point at [1,-1,0] with initial velocity
67m1 = mbs.CreateMassPoint(referencePosition=[1,-1,0],
68 initialVelocity = [2,5,0], #initial velocities for mass point
69 physicsMass=1, drawSize = 0.2)
70#we can obtain the node number from the mass point:
71n1 = mbs.GetObject(m1)['nodeNumber']
72
73#add a ground object:
74#graphics data for sphere:
75gGround0 = GraphicsDataSphere(point=[3,1,0], radius = 0.1, color=color4red, nTiles=16)
76#graphics for checkerboard background:
77gGround1 = GraphicsDataCheckerBoard(point=[3,0,-2], normal=[0,0,1], size=10)
78oGround = mbs.CreateGround(graphicsDataList=[gGround0,gGround1])
79
80#create a rigid distance between bodies (using local position) or between nodes
81mbs.CreateDistanceConstraint(bodyOrNodeList=[oGround, b0],
82 localPosition0 = [ 0. ,0,0],
83 localPosition1 = [-0.5,0,0],
84 distance=None, #automatically computed
85 drawSize=0.06)
86
87#distance constraint between body b0 and mass m1
88mbs.CreateDistanceConstraint(bodyOrNodeList=[b0, m1],
89 localPosition0 = [0.5,0,0],
90 localPosition1 = [0.,0.,0.], #must be [0,0,0] for Node
91 distance=None, #automatically computed
92 drawSize=0.06)
93
94#add further rigid body, which will be connected with joints
95b1 = mbs.CreateRigidBody(inertia = InertiaCuboid(density=5000, sideLengths=[1,0.1,0.1]),
96 referencePosition = [2.5,0,0], #reference position x/y/z
97 gravity = [0,-9.81,0],
98 graphicsDataList = [graphicsCube])
99
100b2 = mbs.CreateRigidBody(inertia = InertiaCuboid(density=5000, sideLengths=[1,0.1,0.1]),
101 referencePosition = [3.5,0,0], #reference position x/y/z
102 gravity = [0,-9.81,0],
103 graphicsDataList = [graphicsCube])
104
105#create revolute joint with following args:
106 # name: name string for joint; markers get Marker0:name and Marker1:name
107 # bodyNumbers: a list of object numbers for body0 and body1; must be rigid body or ground object
108 # position: a 3D vector as list or np.array: if useGlobalFrame=True it describes the global position of the joint in reference configuration; else: local position in body0
109 # axis: a 3D vector as list or np.array: if useGlobalFrame=True it describes the global rotation axis of the joint in reference configuration; else: local axis in body0
110 # useGlobalFrame: if False, the point and axis vectors are defined in the local coordinate system of body0
111 # show: if True, connector visualization is drawn
112 # axisRadius: radius of axis for connector graphical representation
113 # axisLength: length of axis for connector graphical representation
114 # color: color of connector
115#returns list [oJoint, mBody0, mBody1], containing the joint object number, and the two rigid body markers on body0/1 for the joint
116mbs.CreateRevoluteJoint(bodyNumbers=[b1, b2], position=[3,0,0], axis=[0,0,1], #rotation along global z-axis
117 useGlobalFrame=True, axisRadius=0.02, axisLength=0.14)
118
119
120#create prismatic joint with following args:
121 # name: name string for joint; markers get Marker0:name and Marker1:name
122 # bodyNumbers: a list of object numbers for body0 and body1; must be rigid body or ground object
123 # position: a 3D vector as list or np.array: if useGlobalFrame=True it describes the global position of the joint in reference configuration; else: local position in body0
124 # axis: a 3D vector as list or np.array containing the global translation axis of the joint in reference configuration
125 # useGlobalFrame: if False, the point and axis vectors are defined in the local coordinate system of body0
126 # show: if True, connector visualization is drawn
127 # axisRadius: radius of axis for connector graphical representation
128 # axisLength: length of axis for connector graphical representation
129 # color: color of connector
130#returns list [oJoint, mBody0, mBody1], containing the joint object number, and the two rigid body markers on body0/1 for the joint
131mbs.CreatePrismaticJoint(bodyNumbers=[oGround, b1], position=[2,0,0], axis=[1,0,0], #can move in global x-direction
132 useGlobalFrame=True, axisRadius=0.02, axisLength=1)
133
134# #instead of the prismatic joint, we could add another revolute joint to b1 to get a double-pendulum:
135# mbs.CreateRevoluteJoint(bodyNumbers=[oGround, b1], position=[2,0,0], axis=[0,0,1],
136# useGlobalFrame=True, axisRadius=0.02, axisLength=0.14)
137
138
139#create simple mass point, connected with ground
140m2 = mbs.CreateMassPoint(referencePosition = [7,2,0],
141 physicsMass = 10, gravity = [0,-9.81,0],
142 drawSize = 0.5, color=color4blue)
143
144#create spring damper between bodies (using local position) or between nodes
145#spring-damper may not have size 0; spring reference length is computed from reference configuration
146oSD = mbs.CreateSpringDamper(bodyOrNodeList=[oGround, m2],
147 localPosition0=[6,0,0],
148 localPosition1=[0,0,0],
149 stiffness=1e3, damping=1e1,
150 drawSize=0.2)
151
152#alternatively, we can use a CartesianSpringDamper; has spring and damper coefficients as list of x/y/z components
153#it has no reference length and acts on the coordinates of both objects:
154oCSD = mbs.CreateCartesianSpringDamper(bodyOrNodeList=[oGround, m2],
155 localPosition0=[7,2,0],
156 localPosition1=[0,0,0],
157 stiffness=[20,0,1e4], #stiffness in x/y/z direction
158 damping=[0.1,0,10],
159 drawSize=0.2)
160
161#prepare mbs for simulation:
162mbs.Assemble()
163#some simulation parameters:
164simulationSettings = exu.SimulationSettings() #takes currently set values or default values
165simulationSettings.timeIntegration.numberOfSteps = 1000
166simulationSettings.timeIntegration.endTime = 5
167
168#for redundant constraints, the following two settings:
169simulationSettings.linearSolverSettings.ignoreSingularJacobian=True
170simulationSettings.linearSolverType = exu.LinearSolverType.EigenDense
171
172mbs.SolveDynamic(simulationSettings = simulationSettings,
173 solverType=exu.DynamicSolverType.GeneralizedAlpha)
174SC.visualizationSettings.nodes.drawNodesAsPoint=False #draw nodes as spheres; better graphics for nodes
175
176#visualize results:
177mbs.SolutionViewer()