ANCFcable2DuserFunction.py

You can view and download this file on Github: ANCFcable2DuserFunction.py

  1#+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  2# This is an EXUDYN example
  3#
  4# Details:  Test model for ANCFCable2D test user functions
  5#
  6# Author:   Johannes Gerstmayr
  7# Date:     2023-12-13
  8#
  9# 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.
 10#
 11#+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 12
 13
 14import exudyn as exu
 15from exudyn.utilities import *
 16
 17import numpy as np
 18
 19useGraphics = True #without test
 20#+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 21#you can erase the following lines and all exudynTestGlobals related operations if this is not intended to be used as TestModel:
 22try: #only if called from test suite
 23    from modelUnitTests import exudynTestGlobals #for globally storing test results
 24    useGraphics = exudynTestGlobals.useGraphics
 25except:
 26    class ExudynTestGlobals:
 27        pass
 28    exudynTestGlobals = ExudynTestGlobals()
 29#+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 30
 31from exudyn.beams import *
 32from math import atan
 33
 34#create an environment for mini example
 35SC = exu.SystemContainer()
 36mbs = SC.AddSystem()
 37
 38oGround=mbs.AddObject(ObjectGround(referencePosition= [0,0,0]))
 39nGround = mbs.AddNode(NodePointGround(referenceCoordinates=[0,0,0]))
 40
 41rhoA = 78.
 42EA = 100000.
 43EI = 2000
 44
 45#example of bending moment user function
 46#limit bending moment with atan function
 47def bendingMomentUserFunction(mbs, t, itemNumber, axialPositionNormalized, curvature, curvature_t, curvatureRef, physicsBendingStiffness, physicsBendingDamping,
 48                                    axialStrain, axialStrain_t, axialStrainRef):
 49    #m = physicsBendingStiffness*(curvature-curvatureRef) + physicsBendingDamping*curvature_t #this is the linear, conventional case
 50    kappa=(curvature-curvatureRef)
 51    kappa = 0.1*atan(10*kappa) #nonlinear behavior, somehow like elasto-plastic
 52    return physicsBendingStiffness*(kappa) + physicsBendingDamping*curvature_t
 53
 54#example of axial force user function
 55#reduce stiffness over time
 56def axialForceUserFunction(mbs, t, itemNumber, axialPositionNormalized, axialStrain, axialStrain_t, axialStrainRef, physicsAxialStiffness, physicsAxialDamping,
 57            curvature, curvature_t, curvatureRef):
 58    fact = max(0.02,(2-t**0.5)) #make axial stiffness it softer over time
 59    return fact*physicsAxialStiffness*(axialStrain-axialStrainRef) + physicsAxialDamping*axialStrain_t
 60
 61#create ANCF cable object:
 62cable = ObjectANCFCable2D(physicsMassPerLength=rhoA,
 63                physicsBendingStiffness=EI,
 64                physicsBendingDamping = EI*0.1,
 65                physicsAxialStiffness=EA,
 66                physicsAxialDamping=EA*0.05,
 67                bendingMomentUserFunction=bendingMomentUserFunction,
 68                axialForceUserFunction=axialForceUserFunction,
 69                )
 70
 71#create several cable elements
 72ancf=GenerateStraightLineANCFCable(mbs=mbs,
 73                positionOfNode0=[0,0,0], positionOfNode1=[2,0,0],
 74                numberOfElements=16, #converged to 4 digits
 75                cableTemplate=cable, #this defines the beam element properties
 76                massProportionalLoad = [0,-9.81,0],
 77                fixedConstraintsNode0 = [1,1, 0,1],
 78                )
 79
 80#assemble and solve system for default parameters
 81mbs.Assemble()
 82
 83endTime = 0.5
 84stepSize = 5e-3
 85
 86simulationSettings = exu.SimulationSettings()
 87
 88simulationSettings.solutionSettings.writeSolutionToFile = False
 89simulationSettings.timeIntegration.verboseMode = 1 #turn off, because of lots of output
 90simulationSettings.linearSolverType = exu.LinearSolverType.EigenSparse
 91# simulationSettings.displayComputationTime = True
 92# simulationSettings.displayStatistics = True
 93
 94simulationSettings.timeIntegration.numberOfSteps = int(endTime/stepSize)
 95simulationSettings.timeIntegration.endTime = endTime
 96simulationSettings.timeIntegration.newton.useModifiedNewton = True
 97
 98SC.visualizationSettings.window.renderWindowSize=[1200,1024]
 99#+++++++++++++++++++++++++++++++++++++++++++++++++++++++
100
101
102if useGraphics:
103    exu.StartRenderer()              #start graphics visualization
104    mbs.WaitForUserToContinue()    #wait for pressing SPACE bar to continue
105
106mbs.SolveDynamic(simulationSettings)
107
108if useGraphics:
109    SC.WaitForRenderEngineStopFlag()#wait for pressing 'Q' to quit
110    exu.StopRenderer()               #safely close rendering window!
111
112#evaluate final (=current) output values
113node = ancf[0][-1]
114p = mbs.GetNodeOutput(node, exu.OutputVariableType.Position)
115exu.Print('ANCFcable2DuserFunction test tip pos=',p)
116
117u=sum(p)
118exu.Print('solution of ANCFcable2DuserFunction test =',u)
119
120exudynTestGlobals.testError = u - (0.6015588367721232)
121exudynTestGlobals.testResult = u