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
Exemple #2
0
def runBatch(experimentObject, batchDirectory, genericInputFile, baseJobName, rMl, springs=True):
    for param in rMl:
        jobName = '{}_{}'.format(baseJobName, int(param))
        workingDirectory = '{}/{}'.format(batchDirectory, jobName)
        experimentObject.rMl = param
        if springs is True:
            experimentObject.runSpringSim(jobName, workingDirectory, genericInputFile)
        else:
            experimentObject.runEmbedSim(jobName, workingDirectory, genericInputFile)
        odbFileName = '{}/{}.odb'.format(workingDirectory, jobName)
        SimulationTools.getResults(workingDirectory, odbFileName)

    return