emptySystemTest.py
You can view and download this file on Github: emptySystemTest.py
1#+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2# This is an EXUDYN example
3#
4# Details: A system without coordinates - only a ground, a sensor and a user function - is solved by every solver
5# (#2790): the time advances, the PreStepUserFunction is called in every step and the sensor records it;
6# with the dense and with the sparse linear solver. Such a system is a starting point that grows (items
7# added later), or a model whose motion is prescribed and only measured.
8#
9# Author: Johannes Gerstmayr
10# Date: 2026-10-02
11#
12# 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.
13#
14#+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
15
16import exudyn as exu
17from exudyn.utilities import * #includes itemInterface and rigidBodyUtilities
18import numpy as np
19
20testIsActive = exu.sys.get('testIsActive', False)
21
22DST = exu.DynamicSolverType
23testResult = 0
24for linearSolverType in [exu.LinearSolverType.EXUdense, exu.LinearSolverType.EigenSparse]:
25 for solver in [DST.ExplicitEuler, DST.RK44, DST.ODE23, DST.GeneralizedAlpha, DST.TrapezoidalIndex2, 'static']:
26 SC = exu.SystemContainer()
27 mbs = SC.AddSystem()
28 mbs.AddObject(ObjectGround())
29 mbs.variables['steps'] = 0
30 def PreStepUserFunction(mbs, t):
31 mbs.variables['steps'] += 1
32 return True
33 mbs.SetPreStepUserFunction(PreStepUserFunction)
34 sensor = mbs.AddSensor(SensorUserFunction(sensorUserFunction=lambda mbs, t, sensorNumbers, factors, configuration: [np.sin(t)],
35 storeInternal=True))
36 mbs.Assemble()
37 assert len(mbs.systemData.GetODE2Coordinates()) == 0
38
39 simulationSettings = exu.SimulationSettings()
40 simulationSettings.timeIntegration.numberOfSteps = 10
41 simulationSettings.timeIntegration.endTime = 1
42 simulationSettings.solution.file.write = False
43 simulationSettings.linearSolver.solverType = linearSolverType
44 if solver == 'static':
45 mbs.SolveStatic(simulationSettings)
46 else:
47 mbs.SolveDynamic(simulationSettings, solverType=solver)
48
49 data = mbs.GetSensorStoredData(sensor)
50 exu.Print(str(linearSolverType).split('.')[-1], str(solver).split('.')[-1], ': steps', mbs.variables['steps'],
51 ', last time', data[-1, 0], ', rows', len(data))
52 testResult += data[-1, 0] + data[-1, 1] + mbs.variables['steps']
53
54exu.Print('solution of emptySystemTest=', testResult)
55exu.sys['testResult'] = testResult