(testmodels-initialaccelerationstest)= # initialAccelerationsTest.py You can view and download this file on Github: [initialAccelerationsTest.py](https://github.com/jgerstmayr/EXUDYN/tree/master/python/TestModels/initialAccelerationsTest.py) ```{code-block} python :linenos: #+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ # This is an EXUDYN example # # Details: The initial accelerations of the generalized-alpha method, timeIntegration.generalizedAlpha. # computeInitialAccelerations (#2235): a pendulum - a mass point on a distance constraint of length # L - starts horizontally with velocity v perpendicular to the rod. Its initial acceleration is the # centripetal v^2/L towards the pivot plus gravity; the term of the initial velocity comes from the # derivative of the constraint Jacobian, and the multiplier is the rod force m v^2/L. Without # computeInitialAccelerations the accelerations are zero. # # Author: Johannes Gerstmayr # Date: 2026-10-05 # # 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. # #+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ import exudyn as exu from exudyn.utilities import * #includes itemInterface and rigidBodyUtilities import numpy as np testIsActive = exu.sys.get('testIsActive', False) L = 0.8 v = 1.5 g = 9.81 def InitialAccelerations(computeInitialAccelerations, linearSolverType=exu.LinearSolverType.EXUdense): SC = exu.SystemContainer() mbs = SC.AddSystem() oGround = mbs.CreateGround() oMass = mbs.CreateMassPoint(referencePosition=[L,0,0], initialVelocity=[0,v,0], mass=2, gravity=[0,-g,0]) mbs.CreateDistanceConstraint(itemNumbers=[oGround, oMass]) mbs.Assemble() settings = exu.SimulationSettings() settings.linearSolver.solverType = linearSolverType settings.solution.file.write = False settings.timeIntegration.verboseMode = 0 settings.timeIntegration.generalizedAlpha.computeInitialAccelerations = computeInitialAccelerations solver = exu.MainSolverImplicitSecondOrder() solver.InitializeSolver(mbs, settings) return (mbs.systemData.GetODE2Coordinates_tt(), mbs.systemData.GetAECoordinates()) expected = np.array([-v**2/L, -g, 0]) u = 0 for linearSolverType in [exu.LinearSolverType.EXUdense, exu.LinearSolverType.EigenSparse]: (a, multipliers) = InitialAccelerations(True, linearSolverType) exu.Print(linearSolverType, ': initial accelerations', a, ', expected', expected, ', multiplier', multipliers) u += int(np.linalg.norm(a - expected) < 1e-8) + int(abs(abs(multipliers[0]) - 2*v**2/L) < 1e-8) + a[0] + 0.1*a[1] (a, multipliers) = InitialAccelerations(False) exu.Print('without computeInitialAccelerations:', a) u += int(np.linalg.norm(a) == 0) exu.Print('solution of initialAccelerationsTest=', u) exu.sys['testResult'] = u ```