solutionViewerMultipleSimulations.py

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

  1#+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  2# This is an EXUDYN example
  3#
  4# Details:  Test for multiple static solutions merged into one solution file
  5#
  6# Author:   Johannes Gerstmayr
  7# Date:     2022-12-20
  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
 13import exudyn as exu
 14from exudyn.itemInterface import *
 15from exudyn.utilities import * #includes itemInterface and rigidBodyUtilities
 16from exudyn.beams import GenerateBeamElementsAlongLine
 17import exudyn.graphics as graphics
 18
 19SC = exu.SystemContainer()
 20mbs = SC.AddSystem()
 21
 22#+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 23#set up simple ANCF model
 24#background
 25rect = [-0.5,-2,2.5,0.5] #xmin,ymin,xmax,ymax
 26background = {'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
 27oGround=mbs.AddObject(ObjectGround(referencePosition= [0,0,0], visualization=VObjectGround(graphicsData= [background])))
 28
 29#cable:
 30
 31L=2                    # length of ANCF element in m
 32E=2.07e11             # Young's modulus of ANCF element in N/m^2
 33rho=7800               # density of ANCF element in kg/m^3
 34b=0.1                  # width of rectangular ANCF element in m
 35h=0.1                  # height of rectangular ANCF element in m
 36A=b*h                  # cross sectional area of ANCF element in m^2
 37I=b*h**3/12            # second moment of area of ANCF element in m^4
 38f=2*3*E*I/L**2           # tip load applied to ANCF element in N
 39
 40nGround = mbs.AddNode(NodePointGround(referenceCoordinates=[0,0,0])) #ground node for coordinate constraint
 41mGround = mbs.AddMarker(MarkerNodeCoordinate(nodeNumber = nGround, coordinate=0)) #Ground node ==> no action
 42
 43#%%+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 44#generate ANCF beams with utilities function
 45cableTemplate = Cable2D(#length = L / nElements, #set in GenerateBeamElementsAlongLine(...)
 46                        massPerLength = rho*A,
 47                        bendingStiffness = E*I,
 48                        axialStiffness = E*A,
 49                        useReducedOrderIntegration = 1,
 50                        #nodeNumbers = [0, 0], #will be filled in GenerateBeamElementsAlongLine(...)
 51                        )
 52
 53positionOfNode0 = [0, 0, 0] # starting point of line
 54positionOfNode1 = [L, 0, 0] # end point of line
 55numberOfElements = 16
 56
 57#alternative to mbs.AddObject(Cable2D(...)) with nodes:
 58ancf=GenerateBeamElementsAlongLine(mbs,
 59                positionOfNode0, positionOfNode1,
 60                numberOfElements,
 61                beamTemplate=cableTemplate, #this defines the beam element properties
 62                gravity = [0,-9.81*0,0], #optionally add gravity
 63                groundConstraintsStart = [1,1,0,1], #add constraints for pos and rot (r'_y)
 64                groundConstraintsEnd = [0,0,0,0])
 65mANCFLast = mbs.AddMarker(MarkerNodePosition(nodeNumber=ancf['nodes'][-1])) #ancf['nodes'][-1] = last node
 66nLoad = mbs.AddLoad(Force(markerNumber = mANCFLast, loadVector = [f*0, -f, 0])) #will be changed in load steps
 67
 68
 69#%%+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 70mbs.Assemble()
 71# print(mbs)
 72simulationSettings = exu.SimulationSettings() #takes currently set values or default values
 73
 74simulationSettings.solution.file.name = 'solution/coordinatesSolution.txt'
 75simulationSettings.solution.file.write = True
 76simulationSettings.solution.file.writePeriod = simulationSettings.timeIntegration.endTime/1000
 77simulationSettings.show.computationTime = False
 78#simulationSettings.show.statistics = True
 79#simulationSettings.show.computationTime = True
 80
 81SC.visualizationSettings.nodes.defaultSize = 0.01
 82
 83simulationSettings.solution.file.information = "Cantilever"
 84simulationSettings.linearSolver.solverType = exu.LinearSolverType.EigenSparse
 85
 86simulationSettings.staticSolver.verboseMode = 0
 87simulationSettings.staticSolver.newton.residualMode = 1 
 88
 89#adapt these settings for better solution file with multiple simulations:
 90#**************************************************
 91simulationSettings.solution.file.append = False
 92simulationSettings.solution.file.writeFooter = False #never write footer as it would be seen between the solution steps
 93#**************************************************
 94
 95useGraphics=False
 96if useGraphics:
 97    SC.renderer.Start()
 98    SC.renderer.DoIdleTasks()
 99
100nLoadSteps = 25 #this is the number of individual computations; could also be done with staticSolver.numberOfLoadSteps
101                #  but here, we want to show how to do multiple steps merged into one solution file
102for loadSteps in range(nLoadSteps):
103    #loadValue = f**((loadSteps+1)/nLoadSteps) #geometric increment of loads
104    loadValue = 2*f*(loadSteps+1)/(nLoadSteps)
105    
106    mbs.SetLoadParameter(nLoad, 'loadVector', [0, -loadValue,0])
107    #print('load vector=' + str(mbs.GetLoadParameter(nLoad, 'loadVector')) )
108
109    simulationSettings.staticSolver.loadStepStart = loadSteps
110    # simulationSettings.staticSolver.numberOfLoadSteps = 5
111    mbs.SolveStatic(simulationSettings, updateInitialValues=True)
112
113    #**************************************************
114    #after first STEP, add this:
115    simulationSettings.solution.file.writeInitialValues = False #to avoid duplication of output times (start/end)
116    simulationSettings.solution.file.writeHeader = False
117    simulationSettings.solution.file.append = True
118    #**************************************************
119
120    sol = mbs.systemData.GetODE2Coordinates()
121    
122    n = len(sol)
123    print('load=',loadValue, ', tip: x='+str(sol[n-4])+', y='+str(sol[n-3])) 
124
125if useGraphics:
126    SC.renderer.DoIdleTasks()
127    SC.renderer.Stop() #safely close rendering window!
128
129if True:
130    #%%
131    
132    t=LoadSolutionFile(OutputFilePath('solution/coordinatesSolution.txt'), verbose=False, safeMode=True)
133    mbs.SolutionViewer(solution=t)