Example #1
0
 def InitializeSolver(self):
     if self.doTimeIntegration:
         self.mbs.sys['solver'] = exudyn.MainSolverImplicitSecondOrder()
         self.mbs.sys['solver'].InitializeSolver(self.mbs,
                                                 self.simulationSettings)
Example #2
0
simulationSettings.timeIntegration.adaptiveStep = False
#simulationSettings.linearSolverType = exu.LinearSolverType.EigenSparse

simulationSettings.timeIntegration.generalizedAlpha.computeInitialAccelerations = True
simulationSettings.solutionSettings.coordinatesSolutionFileName = "coordinatesSolution.txt"

simulationSettings.displayComputationTime = False
simulationSettings.displayStatistics = True

#start 3D visualization
exu.StartRenderer()

#+++++++++++++++++++++++++++++++++++
#solve
exu.InfoStat()
solver = exu.MainSolverImplicitSecondOrder()
solver.SolveSystem(mbs, simulationSettings)
print(solver.conv)
print(solver.it)
exu.InfoStat()

#alternative solver command
#exu.SolveDynamic(mbs, simulationSettings)

#+++++++++++++++++++++++++++++++++++
#wait for closing window (press 'Q')
SC.WaitForRenderEngineStopFlag()
#stop 3D visualization
exu.StopRenderer()  #safely close rendering window!

#+++++++++++++++++++++++++++++++++++
Example #3
0
def SolveDynamic(
    mbs,
    simulationSettings=exudyn.SimulationSettings(),
    solverType=exudyn.DynamicSolverType.GeneralizedAlpha,
    updateInitialValues=False,
    storeSolver=True,
    showHints=False,
    showCausingItems=True,
):
    success = False
    if (solverType == exudyn.DynamicSolverType.TrapezoidalIndex2
            or solverType == exudyn.DynamicSolverType.GeneralizedAlpha):

        dynamicSolver = exudyn.MainSolverImplicitSecondOrder()
        if storeSolver:
            mbs.sys[
                'dynamicSolver'] = dynamicSolver  #copy solver structure to sys variable
            mbs.sys[
                'simulationSettings'] = simulationSettings  #link to last simulation settings
        #if (experimentalNewSolver or #solver flag
        #    ('experimentalNewSolver' in exudyn.sys)): #flag set in test suite
        #    dynamicSolver.experimentalUseSolverNew = True #must be set at the very beginning when MainSolverImplicitSecondOrder() is initialized

        #store old settings:
        newmarkOld = simulationSettings.timeIntegration.generalizedAlpha.useNewmark
        index2Old = simulationSettings.timeIntegration.generalizedAlpha.useIndex2Constraints

        if solverType == exudyn.DynamicSolverType.TrapezoidalIndex2:
            #manually override settings for integrator
            simulationSettings.timeIntegration.generalizedAlpha.useNewmark = True
            simulationSettings.timeIntegration.generalizedAlpha.useIndex2Constraints = True

        stat = exudyn.InfoStat(False)
        success = False
        try:
            success = dynamicSolver.SolveSystem(mbs, simulationSettings)
        except:
            pass
            # print(SolverErrorMessage(dynamicSolver, mbs, isStatic=False, showCausingObjects=showCausingItems,
            #                          showCausingNodes=showCausingItems, showHints=showHints))
            #print(dynamicSolver.conv)
            # import sys
            # sys.exit() #produce no further error messages
            #raise ValueError("SolveDynamic terminated due to errors, see messages above")

        if not success:
            print(
                SolverErrorMessage(dynamicSolver,
                                   mbs,
                                   isStatic=False,
                                   showCausingObjects=showCausingItems,
                                   showCausingNodes=showCausingItems,
                                   showHints=showHints))
            raise ValueError("SolveDynamic terminated")

        CheckSolverInfoStatistics(dynamicSolver.GetSolverName(), stat,
                                  dynamicSolver.it.newtonStepsCount
                                  )  #now check if these statistics are ok

        #restore old settings:
        simulationSettings.timeIntegration.generalizedAlpha.useNewmark = newmarkOld
        simulationSettings.timeIntegration.generalizedAlpha.useIndex2Constraints = index2Old
    elif (solverType == exudyn.DynamicSolverType.ExplicitEuler
          or solverType == exudyn.DynamicSolverType.ExplicitMidpoint
          or solverType == exudyn.DynamicSolverType.RK33
          or solverType == exudyn.DynamicSolverType.RK44
          or solverType == exudyn.DynamicSolverType.RK67
          or solverType == exudyn.DynamicSolverType.ODE23
          or solverType == exudyn.DynamicSolverType.DOPRI5):
        simulationSettings.timeIntegration.explicitIntegration.dynamicSolverType = solverType
        dynamicSolver = exudyn.MainSolverExplicit()
        if storeSolver:
            mbs.sys[
                'dynamicSolver'] = dynamicSolver  #copy solver structure to sys variable
            mbs.sys[
                'simulationSettings'] = simulationSettings  #link to last simulation settings

        stat = exudyn.InfoStat(False)
        success = dynamicSolver.SolveSystem(mbs, simulationSettings)
        CheckSolverInfoStatistics(dynamicSolver.GetSolverName(), stat,
                                  dynamicSolver.it.currentStepIndex *
                                  dynamicSolver.GetNumberOfStages()
                                  )  #now check if these statistics are ok
    else:
        raise ValueError("SolveDynamic: solver type not implemented: ",
                         solverType)

    if updateInitialValues:
        currentState = mbs.systemData.GetSystemState()  #get current values
        mbs.systemData.SetSystemState(
            systemStateList=currentState,
            configuration=exudyn.ConfigurationType.Initial)
        mbs.systemData.SetODE2Coordinates_tt(
            coordinates=mbs.systemData.GetODE2Coordinates_tt(),
            configuration=exudyn.ConfigurationType.Initial)

    return success