Python processing Abaqus inp files

Python modifying Abaqus inp files

In the process of scientific research, have you ever encountered the need for batch calculation? The model of each calculation is not different, and only specific parameters are changed. In batch calculation, repeated operations are often done. Can you use program batch for modeling, analysis and calculation?

There are two ways of batch processing: 1. Modify the key parameters of inp file to obtain the correct inp model file, and then submit the task in batch with Python script file for calculation; 2. Batch calculation is realized by editing Abaqus script file in Python. These two methods have different applications. In this paper, Python is used to process inp files to reduce the workload of human operation.

inp file records the operation results in Abaqus and can represent the whole process of finite element analysis. As a text file, inp file is very convenient in data transmission and avoids the trouble of transferring model and result data to each other.

There are two ways to change the inp file: 1. Manually modify the inp file directly. Therefore, when there are many tasks to be calculated, it requires a lot of workload; 2. To generate the inp file required for calculation by program, you need to have a certain understanding of Abaqus inp file and programming skills.

example

Abaqus can calculate fatigue damage in many ways: 1. Abaqus has its own Direct cycle command; 2. Add fatigue load by Abaqus step; 3. The fatigue load is added through the amplification provided in Abaqus step, but it needs to be recorded when writing subroutines. This paper uses step to record back and forth, changes the inp file through python, establishes multiple load steps, and realizes the addition of cyclic load. The following is an example of program code for adding multiple cyclic load steps in Python:

try:
    fin=open('F:\python\input.txt','r')
except:
    print('something went wrong')
try:
    fout=open('F:\python\output.txt','w')
except:
    print('something went wrong in output file')
file=fin.readlines()
n=1
while n<1000:
    changdu=43
    print(changdu)
    k=0
    while k<2:
        fout.write(file[k])
        k+=1
    fout.write("** STEP: Step-%d\n"%(n))
    k+=1
    while k<4:
        fout.write(file[k])
        k+=1
    fout.write("*Step, name=Step-%d, nlgeom=YES\n"%(n))
    k+=1
    while k<10:
        fout.write(file[k])
        k+=1
    fout.write("** Name: move%d Type: Displacement/Rotation\n"%(n))
    k+=1
    while k<13:
        fout.write(file[k])
        k+=1
    if n%2==1:
        fout.write("DOWNRIGHT, 2, 2, -0.2\n")
    else:
        fout.write("DOWNRIGHT, 2, 2, -0.2\n")
    k+=1
    while k<changdu:
        fout.write(file[k])
        k+=1
    n+=1
    while k<2+changdu:

        fout.write(file[k])
        k+=1
    fout.write("** STEP: Step-%d\n"%(n))
    k+=1
    while k<4+changdu:
        fout.write(file[k])
        k+=1
    fout.write("*Step, name=Step-%d, nlgeom=YES\n"%(n))
    k+=1
    while k<10+changdu:
        fout.write(file[k])
        k+=1
    fout.write("** Name: move%d Type: Displacement/Rotation\n"%(n))
    k+=1
    while k<13+changdu:
        fout.write(file[k])
        k+=1
    if n%2==1:
        fout.write("DOWNRIGHT, 2, 2, 0.2\n")
    else:
        fout.write("DOWNRIGHT, 2, 2, 0.2\n")
    k+=1
    while k<changdu+changdu:
        fout.write(file[k])
        k+=1
    n+=1
    while k<(2+2*changdu):
        fout.write(file[k])
        k+=1
    fout.write("** STEP: Step-%d\n"%(n))
    k+=1
    while k<(4+2*changdu):
        fout.write(file[k])
        k+=1
    fout.write("*Step, name=Step-%d, nlgeom=YES\n"%(n))
    k+=1
    while k<(10+2*changdu):
        fout.write(file[k])
        k+=1
    fout.write("** Name: move%d Type: Displacement/Rotation\n"%(n))
    k+=1
    while k<(13+2*changdu):
        fout.write(file[k])
        k+=1
    if n%2==1:
        fout.write("DOWNRIGHT, 2, 2, -0.2\n")
    else:
        fout.write("DOWNRIGHT, 2, 2, -0.2\n")
    k+=1
    while k<(changdu+2*changdu):
        fout.write(file[k])
        k+=1
    n+=1
    while k<2+3*changdu:
        fout.write(file[k])
        k+=1
    fout.write("** STEP: Step-%d\n"%(n))
    k+=1
    while k<4+3*changdu:
        fout.write(file[k])
        k+=1
    fout.write("*Step, name=Step-%d, nlgeom=YES\n"%(n))
    k+=1
    while k<10+3*changdu:
        fout.write(file[k])
        k+=1
    fout.write("** Name: move%d Type: Displacement/Rotation\n"%(n))
    k+=1
    while k<13+3*changdu:
        fout.write(file[k])
        k+=1
    if n%2==1:
        fout.write("DOWNRIGHT, 2, 2, 0.2\n")
    else:
        fout.write("DOWNRIGHT, 2, 2, 0.2\n")
    k+=1
    while k<changdu+3*changdu:
        fout.write(file[k])
        k+=1
    n+=1

Added by dyip on Thu, 20 Jan 2022 12:23:46 +0200