SystemData
This is the data structure of a system which contains Objects (bodies/constraints/…), Nodes, Markers and Loads. The SystemData structure allows advanced access to this data, which HAS TO BE USED WITH CARE, as unexpected results and system crash might happen.
1import exudyn as exu #EXUDYN package including C++ core part
2from exudyn.itemInterface import * #conversion of data to exudyn dictionaries
3SC = exu.SystemContainer() #container of systems
4mbs = SC.AddSystem() #add a new system to work with
5nMP = mbs.AddNode(NodePoint(referenceCoordinates=[0,0,0]))
6mbs.AddObject(ObjectMassPoint(physicsMass=10, nodeNumber=nMP ))
7mMP = mbs.AddMarker(MarkerNodePosition(nodeNumber = nMP))
8mbs.AddLoad(Force(markerNumber = mMP, loadVector=[2,0,5]))
9mbs.Assemble()
10exu.SolveDynamic(mbs, exu.SimulationSettings())
11
12#obtain current ODE2 system vector (e.g. after static simulation finished):
13u = mbs.systemData.GetODE2Coordinates()
14#set initial ODE2 vector for next simulation:
15mbs.systemData.SetODE2Coordinates(coordinates=u,
16 configuration=exu.ConfigurationType.Initial)
17#print detailed information on items:
18mbs.systemData.Info()
19#print LTG lists for objects and loads:
20mbs.systemData.InfoLTG()
The class MainSystemData has the following functions and structures:
- NumberOfLoads():return number of loads in systemExample:
print(mbs.systemData.NumberOfLoads())
- NumberOfMarkers():return number of markers in systemExample:
print(mbs.systemData.NumberOfMarkers())
- NumberOfNodes():return number of nodes in systemExample:
print(mbs.systemData.NumberOfNodes())
- NumberOfObjects():return number of objects in systemExample:
print(mbs.systemData.NumberOfObjects())
- NumberOfSensors():return number of sensors in systemExample:
print(mbs.systemData.NumberOfSensors())
- ODE2Size(configurationType = exu.ConfigurationType.Current):get size of ODE2 coordinate vector for given configuration (only works correctly after mbs.Assemble() )Example:
print('ODE2 size=',mbs.systemData.ODE2Size())
- ODE1Size(configurationType = exu.ConfigurationType.Current):get size of ODE1 coordinate vector for given configuration (only works correctly after mbs.Assemble() )Example:
print('ODE1 size=',mbs.systemData.ODE1Size())
- AEsize(configurationType = exu.ConfigurationType.Current):get size of AE coordinate vector for given configuration (only works correctly after mbs.Assemble() )Example:
print('AE size=',mbs.systemData.AEsize())
- DataSize(configurationType = exu.ConfigurationType.Current):get size of Data coordinate vector for given configuration (only works correctly after mbs.Assemble() )Example:
print('Data size=',mbs.systemData.DataSize())
- SystemSize(configurationType = exu.ConfigurationType.Current):get size of System coordinate vector for given configuration (only works correctly after mbs.Assemble() )Example:
print('System size=',mbs.systemData.SystemSize())
- GetTime(configurationType = exu.ConfigurationType.Current):get configuration dependent time.Example:
mbs.systemData.GetTime(exu.ConfigurationType.Initial)
- SetTime(newTime, configurationType = exu.ConfigurationType.Current):set configuration dependent time; use this access with care, e.g. in user-defined solvers.Example:
mbs.systemData.SetTime(10., exu.ConfigurationType.Initial)
- AddODE2LoadDependencies(loadNumber, globalODE2coordinates):advanced function for adding special dependencies of loads onto ODE2 coordinates, taking a list / numpy array of global ODE2 coordinates; this function needs to be called after Assemble() and needs to contain global ODE2 coordinate indices; this list only affects implicit or static solvers if timeIntegration.computeLoadsJacobian or staticSolver.computeLoadsJacobian is set to 1 (ODE2) or 2 (ODE2 and ODE2_t dependencies); if set, it may greatly improve convergence if loads with user functions depend on some system states, such as in a load with feedback control loop; the additional dependencies are not required, if doSystemWideDifferentiation=True, however the latter option being much less efficient. For more details, consider the file doublePendulum2DControl.py in the examples directory.Example:
mbs.systemData.AddODE2LoadDependencies(0,[0,1,2]) #add dependency of load 5 onto node 2 coordinates: nodeLTG2 = mbs.systemData.GetNodeLTGODE2(2) mbs.systemData.AddODE2LoadDependencies(5,nodeLTG2)
- Info():print detailed information on every item; for short information use print(mbs)Example:
mbs.systemData.Info()
- InfoLTG():print LTG information of objects and load dependenciesExample:
mbs.systemData.InfoLTG()
SystemData: Access coordinates
This section provides access functions to global coordinate vectors. Assigning invalid values or using wrong vector size might lead to system crash and unexpected results.
The class MainSystemData has the following functions and structures regarding coordinate access:
- GetODE2Coordinates(configuration = exu.ConfigurationType.Current):get ODE2 system coordinates (displacements) for given configuration (default: exu.Configuration.Current)Example:
uCurrent = mbs.systemData.GetODE2Coordinates()
- SetODE2Coordinates(coordinates, configuration = exu.ConfigurationType.Current):set ODE2 system coordinates (displacements) for given configuration (default: exu.Configuration.Current); invalid vector size may lead to system crash!Example:
mbs.systemData.SetODE2Coordinates(uCurrent)
- GetODE2Coordinates_t(configuration = exu.ConfigurationType.Current):get ODE2 system coordinates (velocities) for given configuration (default: exu.Configuration.Current)Example:
vCurrent = mbs.systemData.GetODE2Coordinates_t()
- SetODE2Coordinates_t(coordinates, configuration = exu.ConfigurationType.Current):set ODE2 system coordinates (velocities) for given configuration (default: exu.Configuration.Current); invalid vector size may lead to system crash!Example:
mbs.systemData.SetODE2Coordinates_t(vCurrent)
- GetODE2Coordinates_tt(configuration = exu.ConfigurationType.Current):get ODE2 system coordinates (accelerations) for given configuration (default: exu.Configuration.Current)Example:
vCurrent = mbs.systemData.GetODE2Coordinates_tt()
- SetODE2Coordinates_tt(coordinates, configuration = exu.ConfigurationType.Current):set ODE2 system coordinates (accelerations) for given configuration (default: exu.Configuration.Current); invalid vector size may lead to system crash!Example:
mbs.systemData.SetODE2Coordinates_tt(aCurrent)
- GetODE1Coordinates(configuration = exu.ConfigurationType.Current):get ODE1 system coordinates (displacements) for given configuration (default: exu.Configuration.Current)Example:
qCurrent = mbs.systemData.GetODE1Coordinates()
- SetODE1Coordinates(coordinates, configuration = exu.ConfigurationType.Current):set ODE1 system coordinates (velocities) for given configuration (default: exu.Configuration.Current); invalid vector size may lead to system crash!Example:
mbs.systemData.SetODE1Coordinates_t(qCurrent)
- GetODE1Coordinates_t(configuration = exu.ConfigurationType.Current):get ODE1 system coordinates (velocities) for given configuration (default: exu.Configuration.Current)Example:
qCurrent = mbs.systemData.GetODE1Coordinates_t()
- SetODE1Coordinates_t(coordinates, configuration = exu.ConfigurationType.Current):set ODE1 system coordinates (displacements) for given configuration (default: exu.Configuration.Current); invalid vector size may lead to system crash!Example:
mbs.systemData.SetODE1Coordinates(qCurrent)
- GetAECoordinates(configuration = exu.ConfigurationType.Current):get algebraic equations (AE) system coordinates for given configuration (default: exu.Configuration.Current)Example:
lambdaCurrent = mbs.systemData.GetAECoordinates()
- SetAECoordinates(coordinates, configuration = exu.ConfigurationType.Current):set algebraic equations (AE) system coordinates for given configuration (default: exu.Configuration.Current); invalid vector size may lead to system crash!Example:
mbs.systemData.SetAECoordinates(lambdaCurrent)
- GetDataCoordinates(configuration = exu.ConfigurationType.Current):get system data coordinates for given configuration (default: exu.Configuration.Current)Example:
dataCurrent = mbs.systemData.GetDataCoordinates()
- SetDataCoordinates(coordinates, configuration = exu.ConfigurationType.Current):set system data coordinates for given configuration (default: exu.Configuration.Current); invalid vector size may lead to system crash!Example:
mbs.systemData.SetDataCoordinates(dataCurrent)
- GetSystemState(configuration = exu.ConfigurationType.Current):get system state for given configuration (default: exu.Configuration.Current); state vectors do not include the non-state derivatives ODE1_t and ODE2_tt and the time; function is copying data - not highly efficient; format of pyList: [ODE2Coords, ODE2Coords_t, ODE1Coords, AEcoords, dataCoords]Example:
sysStateList = mbs.systemData.GetSystemState()
- SetSystemState(systemStateList, configuration = exu.ConfigurationType.Current):set system data coordinates for given configuration (default: exu.Configuration.Current); invalid list of vectors / vector size may lead to system crash; write access to state vectors (but not the non-state derivatives ODE1_t and ODE2_tt and the time); function is copying data - not highly efficient; format of pyList: [ODE2Coords, ODE2Coords_t, ODE1Coords, AEcoords, dataCoords]Example:
mbs.systemData.SetSystemState(sysStateList, configuration = exu.ConfigurationType.Initial)
SystemData: Get object LTG coordinate mappings
This section provides access functions the LTG-lists for every object (body, constraint, …) in the system. For details on the LTG mapping, see Section Mapping between local and global coordinate indices.
The class MainSystemData has the following functions and structures regarding object LTG coordinate mappings:
- GetObjectLTGODE2(objectNumber):get object local-to-global coordinate mapping (list of global coordinate indices) for ODE2 coordinates; only available after Assemble()Example:
ltgObject4 = mbs.systemData.GetObjectLTGODE2(4)
- GetObjectLTGODE1(objectNumber):get object local-to-global coordinate mapping (list of global coordinate indices) for ODE1 coordinates; only available after Assemble()Example:
ltgObject4 = mbs.systemData.GetObjectLTGODE1(4)
- GetObjectLTGAE(objectNumber):get object local-to-global coordinate mapping (list of global coordinate indices) for algebraic equations (AE) coordinates; only available after Assemble()Example:
ltgObject4 = mbs.systemData.GetObjectLTGAE(4)
- GetObjectLTGData(objectNumber):get object local-to-global coordinate mapping (list of global coordinate indices) for data coordinates; only available after Assemble()Example:
ltgObject4 = mbs.systemData.GetObjectLTGData(4)
- GetNodeLTGODE2(nodeNumber):get node local-to-global coordinate mapping (list of global coordinate indices) for ODE2 coordinates; only available after Assemble()Example:
ltgNode4 = mbs.systemData.GetNodeLTGODE2(4)
- GetNodeLTGODE1(nodeNumber):get node local-to-global coordinate mapping (list of global coordinate indices) for ODE1 coordinates; only available after Assemble()Example:
ltgNode4 = mbs.systemData.GetNodeLTGODE1(4)
- GetNodeLTGAE(nodeNumber):get node local-to-global coordinate mapping (list of global coordinate indices) for AE coordinates; only available after Assemble()Example:
ltgNode4 = mbs.systemData.GetNodeLTGAE(4)
- GetNodeLTGData(nodeNumber):get node local-to-global coordinate mapping (list of global coordinate indices) for Data coordinates; only available after Assemble()Example:
ltgNode4 = mbs.systemData.GetNodeLTGData(4)