def optimizationFunction(vals, args): # Parse the constant variables jobName = args[0] workingDirectory = args[1] batFileName = args[2] experimentalResults = args[3] # Change the material properties in the Abaqus simulation updateSimulationVariable(vals, workingDirectory) # Run the simulation SimulationTools.runSimulation(jobName, workingDirectory, abaqusBatFile=batFileName) # Get the results from the simulation, and save them using cPickle odbFileName = '{}\\{}.odb'.format(workingDirectory, jobName) # Create the path to the odb file. SimulationTools.getResults(workingDirectory, odbFileName, abaqusBatFile=batFileName) # The specific results have been written to the working directory, so we can now open them as the variable that we saved. saveResultsFileName = workingDirectory + '\\specificResults.dat' # Define the saved results file name. This needs to be the same result file name that was saved in ExtractResults.py with open(saveResultsFileName, mode='r') as file: simResults = cPickle.load(file) # Load the saved results. This will be the same variable that we saved in ExtractResults.py error = (simResults - experimentalResults)**2 # Define the error error = np.sum(error) # Sum the error to return a constant value. This may be an array, depending on the choice of optimization. return error
def runEmbedSim(self, jobName, workingDirectory, genericInputFile): _checkIfDirExists(workingDirectory) #: Check if workingDirectory exists, if not, make one. springs.writeGeometry(workingDirectory, self.pointsPerSide, self.pointsPerLength, self.sideLength, self.sideLength, self.ligamentLength, self.stiffness, self.matrixStiffness, self.offset, self.damping, self.mass, twist=self.twist, phi=self.phi, rMl=self.rMl, rAp=self.rAp, embeded=True) copyfile(genericInputFile, workingDirectory+'/'+jobName+'.inp') SimulationTools.runSimulation(jobName, workingDirectory) return
def _test(): pointsPerSide = 5 # Nodes per edge of insertion area. femSideLength = 14 # Width and height of femoral Insertion area. tibSideLength = 18 # Width and height of tibial Insertion area. ligamentLength = 30 # Length of the ligament. twist = 0 # Twist between the femoral insertion and the tibial insertion phi = 0 # The angle between the planes that define the femoral insertion and the tibial insertion pointsPerLength = 5 stiffness = 1000 # N/mm offset = -0.0 # mm matrixStiffness = 1000 # N/mm damping = 0.1 # damping value mass = 0.00001 workingDirectory = "../Simulations/Test03" writeGeometry( workingDirectory, pointsPerSide, pointsPerLength, tibSideLength, femSideLength, ligamentLength, stiffness, matrixStiffness, offset, damping, mass, twist=twist, phi=phi, ) from shutil import copyfile genericInputFile = "../Simulations/InputFiles/GenericInputExplicit.inp" jobName = "test03.inp" copyfile(genericInputFile, workingDirectory + "/" + jobName) # Run the simulation SimulationTools.runSimulation(jobName, workingDirectory) # mesh = springsMesh(name='SpringMesh') # mesh.getNodes(pointsPerSide, pointsPerLength, tibSideLength, femSideLength, ligamentLength, twist=twist, phi=phi) # mesh.getElements(pointsPerSide, pointsPerLength) # mesh.setFibers(pointsPerSide, pointsPerLength) # mesh.setFiberProperties(stiffness, offset) # mesh.setMatrixMaterialProperties(matrixStiffness) # mesh.getElementsText() return