コード例 #1
0
def CheckSolverInfoStatistics(solverName, infoStat, numberOfEvaluations):
    import numpy as np

    stat = np.array(exudyn.InfoStat(False)) - np.array(infoStat)

    newCnt = max(stat[0], stat[2], stat[4])  #array, vector, matrix new counts

    if newCnt > solverCheckMemoryAllocationsThreshold and newCnt >= numberOfEvaluations:
        exudyn.Print(
            "WARNING: " + solverName + " detected large amount (" +
            str(newCnt) +
            ") of memory allocations, which seem to occur in every time step; solver may be slow"
        )
コード例 #2
0
def TestExudyn(x):

    #create an environment for mini example
    SC = exu.SystemContainer()
    mbs = SC.AddSystem()

    oGround = mbs.AddObject(ObjectGround(referencePosition=[0, 0, 0]))
    nGround = mbs.AddNode(NodePointGround(referenceCoordinates=[0, 0, 0]))

    testError = 1  #set default error, if failed
    exu.Print("start mini example for class ObjectMass1D")

    node = mbs.AddNode(
        Node1D(referenceCoordinates=[0],
               initialCoordinates=[0.],
               initialVelocities=[1 * x]))
    mass = mbs.AddObject(Mass1D(nodeNumber=node, physicsMass=1))

    #assemble and solve system for default parameters
    mbs.Assemble()
    #exu.SolveDynamic(mbs, exu.SimulationSettings())

    h = 1e-6
    tEnd = 10
    simulationSettings = exu.SimulationSettings()
    simulationSettings.timeIntegration.numberOfSteps = int(tEnd / h)
    simulationSettings.timeIntegration.endTime = tEnd
    simulationSettings.solutionSettings.coordinatesSolutionFileName = "coordinatesSolution" + str(
        int(x)) + ".txt"
    simulationSettings.solutionSettings.writeSolutionToFile = True  #no concurrent writing to files ...!
    #exu.StartRenderer() #don't do this in parallelization: will crash
    exu.SolveDynamic(mbs, simulationSettings)
    #exu.StopRenderer() #don't do this in parallelization: will crash

    #check result, get current mass position at local position [0,0,0]
    result = mbs.GetObjectOutputBody(mass, exu.OutputVariableType.Position,
                                     [0, 0, 0])[0]
    print("result ", x, "=", result)
    return result
コード例 #3
0
    #simulationSettings.timeIntegration.newton.numericalDifferentiation.doSystemWideDifferentiation = True

    simulationSettings.timeIntegration.generalizedAlpha.useNewmark = True
    simulationSettings.timeIntegration.generalizedAlpha.useIndex2Constraints = simulationSettings.timeIntegration.generalizedAlpha.useNewmark
    simulationSettings.timeIntegration.newton.useModifiedNewton = False
    simulationSettings.timeIntegration.newton.numericalDifferentiation.minimumCoordinateSize = 1
    simulationSettings.timeIntegration.generalizedAlpha.spectralRadius = 0.8
    simulationSettings.timeIntegration.adaptiveStep = False  #disable adaptive step reduction
    ##############################################################
    # IMPORTANT!!!!!!!!!
    simulationSettings.linearSolverType = exu.LinearSolverType.EigenSparse  #sparse solver !!!!!!!!!!!!!!!
    ##############################################################
    simulationSettings.displayStatistics = True

    SC.TimeIntegrationSolve(mbs, 'GeneralizedAlpha', simulationSettings)

if exudynTestGlobals.useGraphics:  #only start graphics once, but after background is set
    if displaySimulation:
        SC.WaitForRenderEngineStopFlag()

    exu.StopRenderer()  #safely close rendering window!

nLast = mbs.systemData.NumberOfNodes(
) - 1  #just take last node-1 (last node is ground)

uy = mbs.GetNodeOutput(
    nLast - 1, exu.OutputVariableType.Position)[1]  #y-coordinate of last node
exu.Print("uy=", uy)
exudynTestGlobals.testError = uy - (0.44656762760262225
                                    )  #2020-01-16: 0.44656762760262225
コード例 #4
0
import exudyn as exu
from exudyn.itemInterface import *
from exudyn.utilities import *

from modelUnitTests import ExudynTestStructure, exudynTestGlobals
import numpy as np

#create an environment for mini example
SC = exu.SystemContainer()
mbs = SC.AddSystem()

oGround = mbs.AddObject(ObjectGround(referencePosition=[0, 0, 0]))
nGround = mbs.AddNode(NodePointGround(referenceCoordinates=[0, 0, 0]))

testError = 1  #set default error, if failed
exu.Print("start mini example for class ObjectGenericODE2")
try:  #puts example in safe environment
    #set up a mechanical system with two nodes; it has the structure: |~~M0~~M1
    nMass0 = mbs.AddNode(NodePoint(referenceCoordinates=[0, 0, 0]))
    nMass1 = mbs.AddNode(NodePoint(referenceCoordinates=[1, 0, 0]))

    mass = 0.5 * np.eye(3)  #mass of nodes
    stif = 5000 * np.eye(3)  #stiffness of nodes
    damp = 50 * np.eye(3)  #damping of nodes
    Z = 0. * np.eye(3)  #matrix with zeros
    #build mass, stiffness and damping matrices (:
    M = np.block([[mass, 0. * np.eye(3)], [0. * np.eye(3), mass]])
    K = np.block([[2 * stif, -stif], [-stif, stif]])
    D = np.block([[2 * damp, -damp], [-damp, damp]])

    oGenericODE2 = mbs.AddObject(
コード例 #5
0
nodes = fem.ImportFromAbaqusInputFile(inputFileName + '.inp',
                                      typeName='Instance',
                                      name='rotor-1')
elements = np.array(fem.elements[0]['Hex8'])

fem.ReadMassMatrixFromAbaqus(inputFileName + 'MASS1.mtx')
fem.ReadStiffnessMatrixFromAbaqus(inputFileName + 'STIF1.mtx')
fem.ScaleStiffnessMatrix(
    1e-2)  #for larger deformations, stiffness is reduced to 1%

massMatrix = fem.GetMassMatrix(sparse=False)
stiffnessMatrix = fem.GetStiffnessMatrix(sparse=False)

#+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

exu.Print("nodes size=", nodes.shape)
exu.Print("elements size=", elements.shape)

minZ = min(nodes[:, 2])
maxZ = max(nodes[:, 2])
midZ = 0.5 * (minZ + maxZ)

#+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

#nLeft = (78-1)
#nRight = (77-1)
#nMid = (43-1)
nLeft = -1
nRight = -1
nMid = -1
nForce = -1  #40; node where fore is attached
コード例 #6
0
objectList=[]
for case in range(2):
    nRB=-1
    if case == 0:
        com=[0,0,0]
    else:
        #com=[0.4,0.6,1.3]
        com=[0.4,0.22,-0.35]
    zOff = 0.5*case*0

    RBinertia = RigidBodyInertia(mass=m, inertiaTensor=inertia)
    #exu.Print("RBinertia orig =", RBinertia)
    RBinertia = RBinertia.Translated(com) #this includes the correct terms in inertia

    if NormL2(RBinertia.com) != 0 and i==1:
        exu.Print("AddRigidBody COM=", RBinertia.com)
        exu.Print("inertia6D=", RBinertia.GetInertia6D())
    #exu.Print("RBinertia trans=", RBinertia)
    #exu.Print("inertia6D=", RBinertia.GetInertia6D())
    #exu.Print("inertia.com=", RBinertia.com)
    mPosLast = mbs.AddMarker(MarkerBodyRigid(bodyNumber = oGround, 
                                                localPosition=[0,0,zOff]))

    #create a chain of bodies:
    for i in range(nBodies):
        omega0 = [0,0,0] #arbitrary initial angular velocity
        ep0 = eulerParameters0 #no rotation
        ep_t0 = AngularVelocity2EulerParameters_t(omega0, ep0)
        
        #Rotxyz:
        #ep0 = [0,0,0]
コード例 #7
0
import exudyn as exu
from exudyn.itemInterface import *
from exudyn.utilities import *

from modelUnitTests import ExudynTestStructure, exudynTestGlobals
import numpy as np

#create an environment for mini example
SC = exu.SystemContainer()
mbs = SC.AddSystem()

oGround = mbs.AddObject(ObjectGround(referencePosition=[0, 0, 0]))
nGround = mbs.AddNode(NodePointGround(referenceCoordinates=[0, 0, 0]))

testError = 1  #set default error, if failed
exu.Print("start mini example for class ObjectRotationalMass1D")
try:  #puts example in safe environment
    node = mbs.AddNode(
        Node1D(
            referenceCoordinates=[1],  #\psi_0ref
            initialCoordinates=[0.5],  #\psi_0ini
            initialVelocities=[0.5]))  #\psi_t0ini
    rotor = mbs.AddObject(Rotor1D(nodeNumber=node, physicsInertia=1))

    #assemble and solve system for default parameters
    mbs.Assemble()
    SC.TimeIntegrationSolve(mbs, 'GeneralizedAlpha', exu.SimulationSettings())

    #check result
    #check result, get current rotor z-rotation at local position [0,0,0]
    testError = mbs.GetObjectOutputBody(rotor, exu.OutputVariableType.Rotation,
コード例 #8
0
mbs.AddObject(CoordinateConstraint(markerNumbers=[mNCground, mC2]))

#+++++++++++++++++++++++++++++++++++++++++++++++++++++++++
#add tip load
tipNodeMarker = mbs.AddMarker(MarkerNodeRigid(nodeNumber=nodeList[-1]))
mbs.AddLoad(
    Force(markerNumber=tipNodeMarker,
          loadVector=[1 * fEnd * sin(phi), -1 * fEnd * cos(phi), 0]))
mbs.AddLoad(Torque(markerNumber=tipNodeMarker, loadVector=[0, 0, -5e8]))

#exu.Print(mbs)
mbs.Assemble()
n0 = mbs.GetNodeOutput(0,
                       variableType=exu.OutputVariableType.Position,
                       configuration=exu.ConfigurationType.Reference)
exu.Print("n0=", n0)
p = mbs.GetObjectOutputBody(0,
                            variableType=exu.OutputVariableType.Position,
                            localPosition=[0, 0, 0],
                            configuration=exu.ConfigurationType.Reference)
exu.Print("p=", p)

simulationSettings = exu.SimulationSettings()

tEnd = 1
steps = 2000
simulationSettings.timeIntegration.numberOfSteps = steps
simulationSettings.timeIntegration.endTime = tEnd
simulationSettings.solutionSettings.solutionWritePeriod = tEnd / steps
#simulationSettings.timeIntegration.verboseMode = 1
simulationSettings.solutionSettings.writeSolutionToFile = False
コード例 #9
0
#+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
#cable:
mypi = 3.141592653589793

L = 2.  # length of ANCF element in m
#L=mypi                 # length of ANCF element in m
E = 2.07e11  # Young's modulus of ANCF element in N/m^2
rho = 7800  # density of ANCF element in kg/m^3
b = 0.01  # width of rectangular ANCF element in m
h = 0.01  # height of rectangular ANCF element in m
A = b * h  # cross sectional area of ANCF element in m^2
I = b * h**3 / 12  # second moment of area of ANCF element in m^4
EI = E * I
rhoA = rho * A

exu.Print("EI=" + str(EI))
exu.Print("rhoA=" + str(rhoA))

nGround = mbs.AddNode(NodePointGround(
    referenceCoordinates=[0, 0, 0]))  #ground node for coordinate constraint
mGround = mbs.AddMarker(MarkerNodeCoordinate(
    nodeNumber=nGround, coordinate=0))  #Ground node ==> no action

cableList = []

nc0 = mbs.AddNode(Point2DS1(referenceCoordinates=[0, 0, 1, 0]))
nElements = 32  #32
lElem = L / nElements
for i in range(nElements):
    nLast = mbs.AddNode(
        Point2DS1(referenceCoordinates=[lElem * (i + 1), 0, 1, 0]))
コード例 #10
0
import exudyn as exu
from exudyn.itemInterface import *
from exudyn.utilities import *

from modelUnitTests import ExudynTestStructure, exudynTestGlobals
import numpy as np

#create an environment for mini example
SC = exu.SystemContainer()
mbs = SC.AddSystem()

oGround = mbs.AddObject(ObjectGround(referencePosition=[0, 0, 0]))
nGround = mbs.AddNode(NodePointGround(referenceCoordinates=[0, 0, 0]))

testError = 1  #set default error, if failed
exu.Print("start mini example for class MarkerSuperElementPosition")
try:  #puts example in safe environment
    #set up a mechanical system with two nodes; it has the structure: |~~M0~~M1
    #==>further examples see objectGenericODE2Test.py, objectFFRFTest2.py, etc.
    nMass0 = mbs.AddNode(NodePoint(referenceCoordinates=[0, 0, 0]))
    nMass1 = mbs.AddNode(NodePoint(referenceCoordinates=[1, 0, 0]))
    mGround = mbs.AddMarker(
        MarkerBodyPosition(bodyNumber=oGround, localPosition=[1, 0, 0]))

    mass = 0.5 * np.eye(3)  #mass of nodes
    stif = 5000 * np.eye(3)  #stiffness of nodes
    damp = 50 * np.eye(3)  #damping of nodes
    Z = 0. * np.eye(3)  #matrix with zeros
    #build mass, stiffness and damping matrices (:
    M = np.block([[mass, 0. * np.eye(3)], [0. * np.eye(3), mass]])
    K = np.block([[2 * stif, -stif], [-stif, stif]])
コード例 #11
0
#+++++++++++ add elastic supports to fem ==> compute correct eigen frequencies
pLeft = [0,0,0]
pRight = [0,0,0.5]
nLeft = fem.GetNodeAtPoint(pLeft)
nRight = fem.GetNodeAtPoint(pRight)
kJoint = 2e8     #joint stiffness
dJoint = kJoint*0.01  #joint damping

fem.AddElasticSupportAtNode(nLeft, springStiffness=[kJoint,kJoint,kJoint])
fem.AddElasticSupportAtNode(nRight, springStiffness=[kJoint,kJoint,kJoint])

#+++++++++++ compute eigenmodes for comparison
nModes = 8
fem.ComputeEigenmodes(nModes, excludeRigidBodyModes = 6, useSparseSolver = False)
exu.Print("eigen freq.=", fem.GetEigenFrequenciesHz()[0:6+nModes].round(4)) #mode 0 is rigid body mode (free rotation)!
exu.Print("eigen freq. first mode =", fem.GetEigenFrequenciesHz()[1])       #mode1 with supports: 57.6317863976366Hz;  free-free mode6: sparse: 104.63701326020315, dense: 104.63701326063597
accumulatedError += 1e-2*(fem.GetEigenFrequenciesHz()[1]/57.63178639764625 - 1.)   #check mode (with supports); this is subject to small variations between 32 and 64bit! ==>*1e-2

#+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
#create generic object for rotor:
forwardWhirl = True    #test: True; switch this flag to turn on rotordynamics effects
backwardWhirl = False   #test: False; switch this flag to turn on rotordynamics effects
excitationSign = 1
if backwardWhirl: excitationSign = -1

forceVector = [0,-1.,0]*nNodes  #static force vector, optional; add some force in y-direction; could also use node mass to compute force due to weight
fUnbalance = 2000               #fictive force, not depending on frequency

nForce = fem.GetNodeAtPoint([0,0,0.15])#position where unbalance (excitation) force acts
exu.Print("excitation node=", nForce)
コード例 #12
0
SC.visualizationSettings.markers.show = False
#SC.visualizationSettings.nodes.defaultSize = 0.05

simulationSettings.staticSolver.newton.numericalDifferentiation.relativeEpsilon = 1e-5 * 0.01
#simulationSettings.staticSolver.newton.relativeTolerance = 1e-6#*1e5
#simulationSettings.staticSolver.newton.absoluteTolerance = 1e-1
#simulationSettings.staticSolver.numberOfLoadSteps = 10
#simulationSettings.staticSolver.loadStepGeometric = True
simulationSettings.staticSolver.verboseMode = 2

#dense solver:
simulationSettings.linearSolverType = exu.LinearSolverType.EXUdense
exu.SolveStatic(mbs, simulationSettings)

u = mbs.GetNodeOutput(nBodies - 2, exu.OutputVariableType.Position)  #tip node
exu.Print('static tip displacement (y)=', u[1])
exudynTestGlobals.testError = u[1] - (
    -6.779862983765133)  #72 x 6 bodies; CPUtime surface: 0.55 seconds
exudynTestGlobals.testResult = u[1]

#sparse solver:
simulationSettings.linearSolverType = exu.LinearSolverType.EigenSparse
exu.SolveStatic(mbs, simulationSettings)

u = mbs.GetNodeOutput(nBodies - 2, exu.OutputVariableType.Position)  #tip node
exu.Print('static tip displacement (y)=', u[1])

#factor 1e-2: 32bit version shows 2.1e-12 error
exudynTestGlobals.testError = 1e-2 * (
    u[1] -
    (-6.779862983766792))  #72 x 6 bodies; CPUtime surface: 0.029 seconds
コード例 #13
0
simulationSettings.timeIntegration.generalizedAlpha.spectralRadius = 0.5

#SC.visualizationSettings.nodes.showNumbers = True
SC.visualizationSettings.bodies.showNumbers = True
#SC.visualizationSettings.connectors.showNumbers = True
SC.visualizationSettings.nodes.defaultSize = 0.05

simulationSettings.solutionSettings.solutionInformation = "Planar four-bar-mechanism with initial angular velocity and gravity"

#exudynTestGlobals.useGraphics = True #uncomment this line to visualize the example!
if exudynTestGlobals.useGraphics:
    exu.StartRenderer()
    #mbs.WaitForUserToContinue()

exu.SolveDynamic(mbs, simulationSettings)

if exudynTestGlobals.useGraphics:
    SC.WaitForRenderEngineStopFlag()
    exu.StopRenderer()  #safely close rendering window!

#compute error for test suite:
sol = mbs.systemData.GetODE2Coordinates()
u = sol[1]
#y-displacement of first node of four bar mechanism
exu.Print('solution of fourbar mechanism =', u)

exudynTestGlobals.testError = u - (
    -2.354666317492353
)  #2020-01-09: -2.354666317492353; 2019-12-15: (-2.3546596670554125); 2019-11-22:(-2.354659593986869);  previous: (-2.354659593986899)
exudynTestGlobals.testResult = u
コード例 #14
0
if exudynTestGlobals.useGraphics:
    SC.WaitForRenderEngineStopFlag()
    exu.StopRenderer() #safely close rendering window!

sol = mbs.systemData.GetODE2Coordinates(); 
solref = mbs.systemData.GetODE2Coordinates(configuration=exu.ConfigurationType.Reference); 
#exu.Print('sol=',sol)
u = 0
for i in range(4):
    u += abs(sol[3+i]+solref[3+i]); #Euler parameters

for i in range(3):
    u += abs(sol[7+3+i]+solref[7+3+i]); #Euler angles Rxyz

exu.Print('solution of heavy top =',u)
# EP ref solution MATLAB: at t=0.2
#  gen alpha (sigma=0.98, h=1e-4): -0.70813,0.43881,0.54593,0.089251 ==> abs sum=1.782121
#  RK4:                            -0.70828,0.43878,0.54573,0.0894   ==> abs sum=1.78219
#Exudyn: (index2)                  -1.70824157  0.43878143  0.54578152   0.08937154

#RotXYZ solution EXUDYN:           29.86975964,-0.7683481513,-1.002841906

exudynTestGlobals.testError = u - (33.423125751773306) #2020-02-04 added RigidRxyz: (33.423125751773306) 2020-02-03: (1.7821760506326125)



#+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
#compute exact solution:

if exudynTestGlobals.useGraphics:
コード例 #15
0
simulationSettings.timeIntegration.generalizedAlpha.spectralRadius = 0.6  #0.6 works well

simulationSettings.solutionSettings.solutionInformation = "rigid body tests"
SC.visualizationSettings.nodes.defaultSize = 0.05
#simulationSettings.displayComputationTime = True
#simulationSettings.displayStatistics = True

if exudynTestGlobals.useGraphics:
    exu.StartRenderer()
    mbs.WaitForUserToContinue()

SC.TimeIntegrationSolve(mbs, 'GeneralizedAlpha', simulationSettings)

#+++++++++++++++++++++++++++++++++++++++++++++
sol = mbs.systemData.GetODE2Coordinates()
solref = mbs.systemData.GetODE2Coordinates(
    configuration=exu.ConfigurationType.Reference)
#exu.Print('sol=',sol)
u = 0
for i in range(14):  #take coordinates of first two bodies
    u += abs(sol[i] + solref[i])

exu.Print('solution of sphericalJointTest=', u)

exudynTestGlobals.testError = u - (4.409004179180698
                                   )  #2020-04-04: 4.409004179180698

if exudynTestGlobals.useGraphics:
    #SC.WaitForRenderEngineStopFlag()
    exu.StopRenderer()  #safely close rendering window!
コード例 #16
0
simulationSettings.solutionSettings.solutionInformation = "rigid body tests"
SC.visualizationSettings.nodes.defaultSize = 0.05
simulationSettings.displayComputationTime = False
#simulationSettings.displayStatistics = True

if exudynTestGlobals.useGraphics:
    exu.StartRenderer()
    mbs.WaitForUserToContinue()

exu.SolveDynamic(mbs, simulationSettings)  #, experimentalNewSolver=True)

#+++++++++++++++++++++++++++++++++++++++++++++
#compute TestModel error for EulerParameters and index2 solver
pos = mbs.GetObjectOutputBody(oRB,
                              exu.OutputVariableType.Position,
                              localPosition=[0, 0, 0])
exu.Print('pos=', pos)
u = 0
for i in range(3):  #take sum of all coordinates
    u += abs(pos[i])

exu.Print('solution of GenericJointTest=', u)

exudynTestGlobals.testError = u - (1.1878327690760586
                                   )  #2020-04-22: 1.1878327690760586
exudynTestGlobals.testResult = u

if exudynTestGlobals.useGraphics:
    #SC.WaitForRenderEngineStopFlag()
    exu.StopRenderer()  #safely close rendering window!
コード例 #17
0
import exudyn as exu
from exudyn.itemInterface import *
from exudyn.utilities import *

from modelUnitTests import ExudynTestStructure, exudynTestGlobals
import numpy as np

#create an environment for mini example
SC = exu.SystemContainer()
mbs = SC.AddSystem()

oGround = mbs.AddObject(ObjectGround(referencePosition=[0, 0, 0]))
nGround = mbs.AddNode(NodePointGround(referenceCoordinates=[0, 0, 0]))

testError = 1  #set default error, if failed
exu.Print("start mini example for class ObjectConnectorRigidBodySpringDamper")
try:  #puts example in safe environment
    #example with rigid body at [0,0,0], 1kg under initial velocity
    k = 500
    nBody = mbs.AddNode(RigidRxyz(initialVelocities=[0, 1e3, 0, 0, 0, 0]))
    oBody = mbs.AddObject(
        RigidBody(physicsMass=1,
                  physicsInertia=[1, 1, 1, 0, 0, 0],
                  nodeNumber=nBody))

    mBody = mbs.AddMarker(MarkerNodeRigid(nodeNumber=nBody))
    mGround = mbs.AddMarker(
        MarkerBodyRigid(bodyNumber=oGround, localPosition=[0, 0, 0]))
    mbs.AddObject(
        RigidBodySpringDamper(markerNumbers=[mGround, mBody],
                              stiffness=np.diag([k, k, k, 0, 0, 0]),
コード例 #18
0
ファイル: pendulumFriction.py プロジェクト: eapcivil/EXUDYN
        referencePosition=[0, 0, 0],
        visualization=VObjectGround(graphicsData=[graphicsBackground])))

graphicsSphere = GraphicsDataSphere(point=[L / 2, 0, 0],
                                    radius=r,
                                    color=[1., 0.2, 0.2, 1],
                                    nTiles=16)
graphicsSphere2 = GraphicsDataSphere(point=[0, 0, 0],
                                     radius=r,
                                     color=color4steelblue,
                                     nTiles=16)
graphicsLink = GraphicsDataOrthoCube(-L / 2, -d / 2, -d / 2, L / 2, d / 2,
                                     d / 2, [0.5, 0.5, 0.5, 0.5])

inertia = InertiaCuboid(density=mass / (L * d * d), sideLengths=[L, d, d])
exu.Print("mass=", inertia.mass)

nR0 = mbs.AddNode(Rigid2D(
    referenceCoordinates=[L / 2, 0, 0]))  #body goes from [0,0,0] to [L,0,0]
oR0 = mbs.AddObject(
    RigidBody2D(nodeNumber=nR0,
                physicsMass=inertia.mass,
                physicsInertia=inertia.inertiaTensor[2][2],
                visualization=VObjectRigidBody2D(
                    graphicsData=[graphicsLink, graphicsSphere])))
mGround0 = mbs.AddMarker(
    MarkerBodyPosition(bodyNumber=oGround, localPosition=[0, 0, 0]))
mR0 = mbs.AddMarker(
    MarkerBodyPosition(bodyNumber=oR0, localPosition=[-L / 2, 0, 0]))
mTip0 = mbs.AddMarker(
    MarkerBodyPosition(bodyNumber=oR0, localPosition=[L / 2, 0, 0]))
コード例 #19
0
simulationSettings = exu.SimulationSettings()
simulationSettings.timeIntegration.numberOfSteps = int(tEnd / h)
simulationSettings.timeIntegration.endTime = tEnd
simulationSettings.solutionSettings.writeSolutionToFile = False

simulationSettings.timeIntegration.generalizedAlpha.spectralRadius = 1  #no numerical damping

simulationSettings.displayStatistics = True
simulationSettings.timeIntegration.verboseMode = 1

if exudynTestGlobals.useGraphics:
    exu.StartRenderer()  #start graphics visualization
    mbs.WaitForUserToContinue()  #wait for pressing SPACE bar to continue

#start solver:
exu.SolveDynamic(mbs, simulationSettings)

if exudynTestGlobals.useGraphics:
    SC.WaitForRenderEngineStopFlag()  #wait for pressing 'Q' to quit
    exu.StopRenderer()  #safely close rendering window!

p0 = mbs.GetObjectOutputBody(oBody,
                             localPosition=[0.1, 0.1, 0.1],
                             variableType=exu.OutputVariableType.Position)
result = p0[0] + p0[1]
exu.Print('solution of connectorRigidBodySpringDamperTest=',
          result)  #use x-coordinate

exudynTestGlobals.testError = result - (0.18276224743714353)  #2021-01-07:
exudynTestGlobals.testResult = result
コード例 #20
0
        },  #parameters provide search range
        numberOfGenerations=2,
        populationSize=10,
        elitistRatio=0.1,
        crossoverProbability=0.1,
        rangeReductionFactor=0.7,
        addComputationIndex=True,
        randomizerInitialization=0,  #for reproducible results
        distanceFactor=0.1,  #for this example only one significant minimum
        debugMode=False,
        useMultiProcessing=False,  #may be problematic for test
        showProgress=False,
    )
    #exu.Print("--- %s seconds ---" % (time.time() - start_time))

    exu.Print("[pOpt, vOpt]=", [pOpt, vOpt])
    u = vOpt
    exu.Print("optimum=", u)
    exudynTestGlobals.testError = u - (
        0.0030262381385228617
    )  #2020-12-18: (nElements=32) -2.7613614363986017e-05
    exudynTestGlobals.testResult = u

    if exudynTestGlobals.useGraphics and False:
        # from mpl_toolkits.mplot3d import Axes3D  # noqa: F401 unused import
        import matplotlib.pyplot as plt

        plt.close('all')
        [figList, axList] = PlotOptimizationResults2D(pList,
                                                      values,
                                                      yLogScale=True)
コード例 #21
0
import exudyn as exu
from exudyn.itemInterface import *
from exudyn.utilities import *

from modelUnitTests import ExudynTestStructure, exudynTestGlobals
import numpy as np

#create an environment for mini example
SC = exu.SystemContainer()
mbs = SC.AddSystem()

oGround = mbs.AddObject(ObjectGround(referencePosition=[0, 0, 0]))
nGround = mbs.AddNode(NodePointGround(referenceCoordinates=[0, 0, 0]))

testError = 1  #set default error, if failed
exu.Print("start mini example for class ObjectANCFCable2D")
try:  #puts example in safe environment
    node = mbs.AddNode(NodePoint(referenceCoordinates=[1.05, 0, 0]))
    oMassPoint = mbs.AddObject(MassPoint(nodeNumber=node, physicsMass=1))

    m0 = mbs.AddMarker(
        MarkerBodyPosition(bodyNumber=oGround, localPosition=[0, 0, 0]))
    m1 = mbs.AddMarker(
        MarkerBodyPosition(bodyNumber=oMassPoint, localPosition=[0, 0, 0]))

    mbs.AddObject(
        ObjectConnectorSpringDamper(
            markerNumbers=[m0, m1],
            referenceLength=1,  #shorter than initial distance
            stiffness=100,
            damping=1))
コード例 #22
0
    #SC.TimeIntegrationSolve(mbs, 'SecondOrderImplicit', simulationSettings)
        
    if exudynTestGlobals.useGraphics: 
        #+++++++++++++++++++++++++++++++++++++
        #animate solution
#        mbs.WaitForUserToContinue
#        fileName = 'coordinatesSolution.txt'
#        solution = LoadSolutionFile('coordinatesSolution.txt')
#        AnimateSolution(exu, SC, mbs, solution, 10, 0.025, True)
        #+++++++++++++++++++++++++++++++++++++

        SC.WaitForRenderEngineStopFlag()
        exu.StopRenderer() #safely close rendering window!
    
    u = mbs.GetNodeOutput(nMass, exu.OutputVariableType.Position) #tip node
    exu.Print('sol =', abs(u[0]))
    solutionSliderCrankIndex2 += abs(u[0]) #x-position of slider


exu.Print('solutionSliderCrankIndex2=',solutionSliderCrankIndex2)
exudynTestGlobals.testError = solutionSliderCrankIndex2 - 0.5916491633788333 #2020-01-15: 0.5916491633788333(corrected PrismaticJoint); 2019-12-26: 0.5916499441339551; 2019-12-15: 0.591689710999802 (absTol: 1e-8 now; 1e-2 before); before 2019-12-15: 0.5896009710727431


#plotResults = True#constrainGroundBody #comparison only works in case of fixed ground
plotResults = exudynTestGlobals.useGraphics#constrainGroundBody #comparison only works in case of fixed ground
if plotResults:
    dataIndex2 = np.loadtxt('coordinatesSolution.txt', comments='#', delimiter=',')
    #dataMatlab = np.loadtxt('slidercrankRefSolM0.1_tol1e-4.txt', comments='#', delimiter=',') #this is quite inaccurate
    dataMatlab2 = np.loadtxt('slidercrankRefSolM0.1_tol1e-6.txt', comments='#', delimiter=',')
                            
    vODE2=mbs.systemData.GetODE2Coordinates()
コード例 #23
0
# 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 sys
sys.path.append('../TestModels')            #for modelUnitTest as this example may be used also as a unit test

import exudyn as exu
from exudyn.itemInterface import *

from modelUnitTests import ExudynTestStructure, exudynTestGlobals

SC = exu.SystemContainer()
mbs = SC.AddSystem()


exu.Print("\n\n++++++++++++++++++++++++++\nStart EXUDYN version "+exu.GetVersionString()+"\n")

#background
rect = [-2,-2,2,2] #xmin,ymin,xmax,ymax
background0 = {'type':'Line', 'color':[0.1,0.1,0.8,1], 'data':[rect[0],rect[1],0, rect[2],rect[1],0, rect[2],rect[3],0, rect[0],rect[3],0, rect[0],rect[1],0]} #background
background1 = {'type':'Circle', 'radius': 0.1, 'position': [-1.5,0,0]} 
background2 = {'type':'Text', 'position': [-1,-1,0], 'text':'Example with text\nin two lines:.=!'} #background
oGround=mbs.AddObject(ObjectGround(referencePosition= [0,0,0], visualization=VObjectGround(graphicsData= [background0, background1, background2])))

#+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
#cable:
mypi = 3.141592653589793

L=2.                   # length of ANCF element in m
#L=mypi                 # length of ANCF element in m
E=2.07e11*1e-5              # Young's modulus of ANCF element in N/m^2
コード例 #24
0
graphics2 = {'type':'Line', 'color':[0.1,0.1,0.8,1], 'data':[-a,-b,0, a,-b,0, a,b,0, -a,b,0, -a,-b,0]} #background
omega0 = 5*0 #inconsistent initial conditions lead to integration problems!
nRigid = mbs.AddNode(Rigid2D(referenceCoordinates=[a,0,0], initialVelocities=[0,omega0*a,omega0]));
oRigid = mbs.AddObject(RigidBody2D(physicsMass=massRigid, physicsInertia=inertiaRigid,nodeNumber=nRigid,visualization=VObjectRigidBody2D(graphicsData= [graphics2])))

mR1 = mbs.AddMarker(MarkerBodyPosition(bodyNumber=oRigid, localPosition=[-a,0.,0.])) #support point
mR2 = mbs.AddMarker(MarkerBodyPosition(bodyNumber=oRigid, localPosition=[ a,0.,0.])) #end point

mG0 = mbs.AddMarker(MarkerBodyPosition(bodyNumber=oGround, localPosition=[0,0,0.]))
mbs.AddObject(RevoluteJoint2D(markerNumbers=[mG0,mR1]))

mbs.AddLoad(Force(markerNumber = mR2, loadVector = [0, -massRigid*g, 0]))

mbs.Assemble()
exu.Print(mbs)

simulationSettings = exu.SimulationSettings() #takes currently set values or default values

simulationSettings.timeIntegration.numberOfSteps = 100
simulationSettings.timeIntegration.endTime = 2
simulationSettings.timeIntegration.newton.relativeTolerance = 1e-8 #10000
simulationSettings.timeIntegration.newton.absoluteTolerance = 1e-4
simulationSettings.timeIntegration.verboseMode = 1

simulationSettings.timeIntegration.newton.useNumericalDifferentiation = False
simulationSettings.timeIntegration.newton.numericalDifferentiation.minimumCoordinateSize = 1
#simulationSettings.timeIntegration.generalizedAlpha.useNewmark = True
#simulationSettings.timeIntegration.generalizedAlpha.useIndex2Constraints = True
simulationSettings.timeIntegration.generalizedAlpha.spectralRadius = 0.5
simulationSettings.displayStatistics = True
コード例 #25
0
#SC.visualizationSettings.exportImages.saveImageFileName = "animation/frame"

if exudynTestGlobals.useGraphics:
    exu.StartRenderer()
    if 'lastRenderState' in vars():
        SC.SetRenderState(lastRenderState) #load last model view

    mbs.WaitForUserToContinue() #press space to continue

SC.TimeIntegrationSolve(mbs, 'GeneralizedAlpha', simulationSettings)
    

data = np.loadtxt(fileDir+'nMidDisplacementCMS'+str(nModes)+'Test.txt', comments='#', delimiter=',')
result = abs(data).sum()
#pos = mbs.GetObjectOutputBody(objFFRF['oFFRFreducedOrder'],exu.OutputVariableType.Position, localPosition=[0,0,0])
exu.Print('solution of ObjectFFRFreducedOrder=',result)

exudynTestGlobals.testError = result - (0.5354530110580623) #2020-05-26(added EP-constraint): 0.5354530110580623; 2020-05-17 (tEnd=0.01, h=1e-4): 0.535452257303538 
exudynTestGlobals.testError *=0.1 #make error smaller, as there are small changes for different runs (because of scipy sparse eigenvalue solver!)

if exudynTestGlobals.useGraphics:
    SC.WaitForRenderEngineStopFlag()
    exu.StopRenderer() #safely close rendering window!
    lastRenderState = SC.GetRenderState() #store model view for next simulation

##++++++++++++++++++++++++++++++++++++++++++++++q+++++++
#plot results
if exudynTestGlobals.useGraphics:
    import matplotlib.pyplot as plt
    import matplotlib.ticker as ticker
    cList=['r-','g-','b-','k-','c-','r:','g:','b:','k:','c:']
コード例 #26
0
#+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
#cable:
mypi = 3.141592653589793

L=2                     # length of ANCF element in m
#L=mypi                 # length of ANCF element in m
E=2.07e11               # Young's modulus of ANCF element in N/m^2
rho=7800                # density of ANCF element in kg/m^3
b=0.001*10                 # width of rectangular ANCF element in m
h=0.001*10                 # height of rectangular ANCF element in m
A=b*h                   # cross sectional area of ANCF element in m^2
I=b*h**3/12             # second moment of area of ANCF element in m^4
f=3*E*I/L**2            # tip load applied to ANCF element in N

exu.Print("load f="+str(f))
exu.Print("EI="+str(E*I))

nGround = mbs.AddNode(NodePointGround(referenceCoordinates=[0,0,0])) #ground node for coordinate constraint
mGround = mbs.AddMarker(MarkerNodeCoordinate(nodeNumber = nGround, coordinate=0)) #Ground node ==> no action

cableList=[]        #for cable elements
nodeList=[]  #for nodes of cable
markerList=[]       #for nodes
nc0 = mbs.AddNode(Point2DS1(referenceCoordinates=[0,0,1,0]))
nodeList+=[nc0]
nElements = 8 #32*4
lElem = L / nElements
for i in range(nElements):
    nLast = mbs.AddNode(Point2DS1(referenceCoordinates=[lElem*(i+1),0,1,0]))
    nodeList+=[nLast]
コード例 #27
0
ファイル: rollingCoinTest.py プロジェクト: eapcivil/EXUDYN
simulationSettings.timeIntegration.generalizedAlpha.spectralRadius = 0.5
simulationSettings.timeIntegration.generalizedAlpha.computeInitialAccelerations = True

SC.visualizationSettings.nodes.show = True
SC.visualizationSettings.nodes.drawNodesAsPoint = False
SC.visualizationSettings.nodes.showBasis = True
SC.visualizationSettings.nodes.basisSize = 0.015

if exudynTestGlobals.useGraphics:
    exu.StartRenderer()
    mbs.WaitForUserToContinue()

SC.TimeIntegrationSolve(mbs, 'GeneralizedAlpha', simulationSettings)

p0 = mbs.GetObjectOutput(oRolling, exu.OutputVariableType.Position)
exu.Print('solution of rollingCoinTest=', p0[0])  #use x-coordinate

exudynTestGlobals.testError = p0[0] - (
    0.002004099927340136
)  #2020-06-20: 0.002004099927340136; 2020-06-19: 0.002004099760845168 #4s looks visually similar to Rill, but not exactly ...

if exudynTestGlobals.useGraphics:
    SC.WaitForRenderEngineStopFlag()
    exu.StopRenderer()  #safely close rendering window!

    ##++++++++++++++++++++++++++++++++++++++++++++++q+++++++
    #plot results
    if True:
        import matplotlib.pyplot as plt
        import matplotlib.ticker as ticker
コード例 #28
0
SC.visualizationSettings.nodes.show = True
SC.visualizationSettings.nodes.drawNodesAsPoint = False
SC.visualizationSettings.nodes.showBasis = True
SC.visualizationSettings.nodes.basisSize = 0.015

exu.SolveDynamic(mbs,
                 simulationSettings,
                 solverType=exu.DynamicSolverType.TrapezoidalIndex2)

if exudynTestGlobals.useGraphics:
    SC.WaitForRenderEngineStopFlag()
    exu.StopRenderer()  #safely close rendering window!

c = mbs.GetNodeOutput(n0, variableType=exu.OutputVariableType.Coordinates)
u = sum(c)
exu.Print("carRollingDiscTest u=", u)

exudynTestGlobals.testError = u - (-0.23940048717113419
                                   )  #2020-12-18: -0.23940048717113419
exudynTestGlobals.testResult = u

##++++++++++++++++++++++++++++++++++++++++++++++q+++++++
#plot results
if exudynTestGlobals.useGraphics:
    import matplotlib.pyplot as plt
    import matplotlib.ticker as ticker

    symStr = ['r-', 'g-', 'b-', 'k-']
    symStr2 = ['r--', 'g--', 'b--', 'k--']
    for i in range(4):
        s = str(i)
コード例 #29
0
if exudynTestGlobals.useGraphics:
    exu.StartRenderer()

#get initial velocities
vInit = mbs.systemData.GetODE2Coordinates_t(
    configuration=exu.ConfigurationType.Initial)

#start static calculation
exu.SolveStatic(mbs, simulationSettings)

#++++++++++++++++++++++++++++++++++++++++
#compute error for test suite:
ltgCable = mbs.systemData.GetObjectLTGODE2(cable1ObjectList[int(
    len(cable1ObjectList) / 2)])
nc = ltgCable[1]  #vertical displacement
exu.Print("select cable coordinate", nc)
sol = mbs.systemData.GetODE2Coordinates()
uStatic = sol[nc]
#y-displacement of first node of four bar mechanism
exu.Print('static solution of cable1 =', uStatic)
exudynTestGlobals.testError = uStatic - (
    -2.197321886974786
)  #2020-03-05(corrected Cable2DshapeMarker): -2.197321886974786 #2019-12-26:  2.1973218859908146
exudynTestGlobals.testResult = uStatic

#++++++++++++++++++++++++++++++++++++++++
#store solution for next computation
u = mbs.systemData.GetODE2Coordinates()
data = mbs.systemData.GetDataCoordinates()

コード例 #30
0
ファイル: genericODE2test.py プロジェクト: eapcivil/EXUDYN
steps = 2000
simulationSettings.timeIntegration.numberOfSteps = steps
simulationSettings.timeIntegration.endTime = tEnd
simulationSettings.solutionSettings.solutionWritePeriod = tEnd/steps
simulationSettings.timeIntegration.verboseMode = 1
#simulationSettings.solutionSettings.solutionWritePeriod = tEnd/steps

simulationSettings.timeIntegration.generalizedAlpha.spectralRadius = 1 #SHOULD work with 0.9 as well

SC.TimeIntegrationSolve(mbs, 'GeneralizedAlpha', simulationSettings)

u1 = mbs.GetNodeOutput(n1, exu.OutputVariableType.Coordinates)
#exu.Print("u1 =", u1)
u2 = mbs.GetNodeOutput(n2, exu.OutputVariableType.Coordinates)
#exu.Print("u2 =", u2)

u=NormL2(u1) + NormL2(u2)
exu.Print('solution of genericODE2test=',u)

exudynTestGlobals.testError = u - (0.03604546349898683) #2020-04-22: 0.03604546349898683