(testmodels-cartesianspringdampertest)= # CartesianSpringDamperTest.py You can view and download this file on Github: [CartesianSpringDamperTest.py](https://github.com/jgerstmayr/EXUDYN/tree/master/python/TestModels/CartesianSpringDamperTest.py) ```{code-block} python :linenos: #+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ # This is an EXUDYN example # # Details: A mass point held by a `CartesianSpringDamper` against a constant force, integrated over # 1 s in 1000 steps: the x-displacement at the end, which agrees with the analytical # solution to about 3e-6. # The model compares against a reference value written into it, so its # result is that difference and its reference solution is 0 (#2632). # # Author: Johannes Gerstmayr # Date: 2019-11-01, reworked 2026-09-24 # # 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 exudyn.graphics as graphics testIsActive = exu.sys.get('testIsActive', False) exu.sys['testTolerance'] = 4e-13 #the tolerance RunAllModelUnitTests used for these ten SC = exu.SystemContainer() mbs = SC.AddSystem() L=0.5 mass = 1.6 k = 4000 omega0 = 50 # sqrt(4000/1.6) dRel = 0.05 d = dRel * 2 * 80 #80=sqrt(1.6*4000) u0=-0.08 v0=1 f = 80 x0 = f/k #node for mass point: n1=mbs.AddNode(Point(referenceCoordinates = [L,0,0], initialCoordinates = [u0,0,0], initialVelocities= [v0,0,0])) #add mass points and ground object: objectGround = mbs.AddObject(ObjectGround(referencePosition = [0,0,0])) massPoint = mbs.AddObject(MassPoint(mass = mass, nodeNumber = n1)) #marker for constraint / springDamper groundMarker = mbs.AddMarker(MarkerBodyPosition(bodyNumber = objectGround, localPosition= [0, 0, 0])) bodyMarker = mbs.AddMarker(MarkerBodyPosition(bodyNumber = massPoint, localPosition= [0, 0, 0])) mbs.AddObject(CartesianSpringDamper(markerNumbers = [groundMarker, bodyMarker], stiffness = [k,k,k], damping = [d,0,0], offset = [L,0,0])) #add loads: mbs.AddLoad({'loadType': 'ForceVector', 'markerNumber': bodyMarker, 'loadVector': [f, 0, 0]}) #exu.Print(mbs) mbs.Assemble() simulationSettings = exu.SimulationSettings() simulationSettings.solution.file.write=False tEnd = 1 steps = 1000 simulationSettings.timeIntegration.numberOfSteps = steps simulationSettings.timeIntegration.endTime = tEnd simulationSettings.timeIntegration.generalizedAlpha.spectralRadius = 1 #SHOULD work with 0.9 as well simulationSettings.show.statistics = False mbs.SolveDynamic(simulationSettings) u = mbs.GetNodeOutput(n1, exu.OutputVariableType.Position) uCartesianSpringDamper= u[0] - L if True: errorCartesianSpringDamper = uCartesianSpringDamper - 0.011834933407061654 #until 2022-01-25 (changed jacobians): 0.011834933406052683 #2021-09-27: new JacobianODE2RHS #errorCartesianSpringDamper = uCartesianSpringDamper -0.011834933407364412 #2021-02-04: 0.011834933407364412 else: errorCartesianSpringDamper = uCartesianSpringDamper - 0.011834933407594783 #15.12.2019: 0.011834933407594783; beofre 15.12.2019: 0.011834933407038783 #for 1000 steps, endtime=1; accurate up to 3e-6 to exact solution exu.Print('solution cartesianSpringDamper=',uCartesianSpringDamper) testResult = abs(errorCartesianSpringDamper) exu.Print('solution of CartesianSpringDamperTest=', testResult) exu.sys['testResult'] = testResult ```