Search code examples
pythonabaqus

How to change model names in Abaqus wrt an array list?


I am trying to change Model names in Abaqus with respect to the values in an array list. At first, I created two array lists and divided them but it is not a good idea as I will have 100 values later on in Beam_h and Beam_w and the values will repeat.. What can I do if I want to have my model names be: model20-10, model30-10, model50-10? Also, the loop I used so far gives me model0, model1, model2. What to write in the loop to get desired model names?

#Here is the code,

Beam_h = [20, 30, 50] #Beam Height mm
Beam_w = [10, 10, 10] #Beam width mm 
divide_list = [x/y for x, y in zip(Beam_h, Beam_w)]  ##I do not want to divide.It's wrong

for values in divide_list:                                               ##looping not right
    mdb.Model(name='model'+str(values))
    BeamModel = mdb.Model(name='model'+str(values))

Solution

  • I think, you just need to figure out string concatenation.

    You need to check for duplicate model names as well. Because Abaqus replaces the already existing model if you create a model with duplicate name.
    To address this issue, you can use dictionary object in following way:

    dup_Models = dict()  # To store the model names and repeating count
    for x,y in zip(Beam_h,Beam_w):
        modelName = 'model%d-%d'%(x,y) # String concatenation - You can use other ways also!
        if modelName not in dup_Models:
            dup_Models[modelName] = 1
            umodelName = modelName      # Unique model name (No Duplication)
        else:
            dup_Models[modelName] += 1
            umodelName = '%s_%d'%(modelName,dup_Models[modelName])
    
        BeamModel = mdb.Model(name=umodelName)
    

    One last thing, you cannot use .(dot) in model name(Abaqus throws an error). So, if Beam_h and Beam_w has values other than integers, then you have to name the model some other way, for ex. w=10.5 and w=20.5 --> model10pt5-20pt5.