簡體   English   中英

如何通過Python腳本告訴Abaqus在錯誤后繼續?

[英]How to tell Abaqus to continue after Error with Python-Script?

目前,我正在編程一個從Abaqus CAE開始的Python腳本。 目的是為神經網絡生成數據集。 因此,腳本從預先定義的節點集中選取一個隨機節點,並對該節點施加位移和旋轉。 然后,它告訴abaqus解決該模擬問題,並在模擬完成后讀取odb文件。 之后,腳本將繼續使用下一個隨機選擇的節點進行之前選定的迭代次數。 該腳本可以很好地在代碼上正常運行,但是對於abaqus而言,它有時難於解決位移和旋轉的隨機選擇輸入,因此它會崩潰,並顯示“ Increment-Error”(對此增量進行了太多的增量。 ..)。 因此,目錄中存在一個.lck文件,該文件阻止Python腳本訪問讀取odb-File,因此Python腳本也會崩潰。 我已經嘗試通過編輯“增量”大小和最大增量數來解決此錯誤,但兩種方法均無效。 我的最新想法是實現一個“ if”條件,該條件告訴abaqus刪除所有“ Job_1。*”文件,並繼續下一個節點和其他隨機選擇的輸入變量(如果在作業之后直接存在一個.lck文件)。已經完成了。 但是這個想法也沒有奏效。 因此,我問你們,如果你們有一個想法我可以解決這個問題。 有沒有辦法告訴Abaqus,在發生此類錯誤后應繼續使用另一個節點? 這是代碼:

import assembly  
import step  
import interaction  
import load  
import mesh
import optimization
import job
import sketch
import visualization
import xyPlot
import displayGroupOdbToolset as dgo
import connectorBehavior
from time import *
import datetime
import string
import odbAccess
from abaqus import getInput
from random import choice
from random import random
from math import pi
from math import sqrt
import os
import glob

def create_dataset(dataset_length):
    print "Start"
    global dataset
    a = mdb.models['Model-1'].rootAssembly
    n1 = a.instances['PART-1-1'].nodes 
    session.journalOptions.setValues(replayGeometry=COORDINATE, recoverGeometry=COORDINATE) 
    nodes1 =n1[157:159]+n1[190:194]+n1[198:200]+n1[201:209]+n1[239:247]+.... #Abaqus Node-Set for random pick
    nodesetlen=len(nodes1)
    i=0
    while i < dataset_length:  # while-Loop with the length of the requested dataset-length
        print "%i. Loop begins" %(i+1)
        k = choice(range(nodesetlen)) #random-index
        x = nodes1[k:k+1]  # random node out of the nodeset
        region = a.Set(nodes=x, name='BC_RH')  # Abaqus region definition (because the new node-position )
        datum = mdb.models['Model-1'].rootAssembly.datums[49] 
        mdb.models['Model-1'].DisplacementBC(name='BC_RH', createStepName='Step-1',
                                             region=region, u1=(random()*30),
                                             u2=(random()*30), u3=(random()*30),
                                             ur1=(random()*pi/4),
                                             ur2=(random()*pi/4), ur3=(random()*pi/4),
                                             amplitude=UNSET, fixed=OFF, distributionType=UNIFORM, fieldName='',
                                             localCsys=datum)  # Sets the inputs for the abaqus-Job_1
        mdb.jobs['Job_1'].submit(consistencyChecking=OFF) # submits the Job
        print "Job ist submitted"
        mdb.jobs['Job_1'].waitForCompletion() #Python waits for Abaqus until the Job is done
        print "Job is done"
        my_file = "U:/Job_1.lck"
        with open("Job_1.sta") as rfile:
            line = rfile.readlines()[-1]
        if line == " THE ANALYSIS HAS NOT BEEN COMPLETED\n":
            print "Increment Error next Loop will start"
            sleep(30) #just to be sure that Abaqus closed all files
        else:
             odb = openOdb(path='Job_1.odb') # Opens ODB-File
             # HERE ARE A LOT OF OUTPUT-CALCULATIONS IN THE REAL FILE
             # DOESNT INFLUENCE THE PROBLEM
             odb.close()
             i += 1
    print "Erfolgreich beendet"
    return dataset

dataset_length = 500
create_dataset(dataset_length)

這是Abaqus CAE中的錯誤:

1. Loop begins
Recent Node-Label:  22432
Job ist submitted
Job Job_1: Analysis Input File Processor completed successfully.
Error in job Job_1: Too many attempts made for this increment
Error in job Job_1: THE ANALYSIS HAS BEEN TERMINATED DUE TO PREVIOUS ERRORS. ALL OUTPUT REQUESTS HAVE BEEN WRITTEN FOR THE LAST CONVERGED INCREMENT.
Job Job_1: Abaqus/Standard aborted due to errors.
Job is done
Increment Error, next Loop will start
1. Loop begins
Recent Node-Label:  20996
Job ist submitted
Error in job Job_1: Abaqus/Standard Analysis exited with an error - Please see the  message file for possible error messages if the file exists.
Error in job Job_1: Abaqus/Standard Analysis exited with an error - Please see the  message file for possible error messages if the file exists.
Job Job_1 aborted due to errors.
Job Job_1 aborted due to errors.
Job is done

之后,Python錯誤窗口的輸出告訴我沒有.sta文件。

使用try和except子句:

try:
   code goes here
except IncrementError:
   log error and continue

我建議使用https://docs.python.org/2/tutorial/errors.html中的 try-except

try: 
   # do what needs to be done here
except Increment-Error:
    print "Oh no, and Incremental Error has happened!"

在已編輯的版本中,您仍然會打開並在檢測到故障后嘗試處理odb。

您應該有(請注意)

   if line == " THE ANALYSIS HAS COMPLETED\n":
     odb = openOdb(path='Job_1.odb') # Opens ODB-File
      # HERE ARE A LOT OF OUTPUT-CALCULATIONS IN THE REAL FILE
      # DOESNT INFLUENCE THE PROBLEM
     odb.close()
   else:
     print "some error message"

我看不到為什么除了打印錯誤消息外,您還需要做什么,主循環將繼續並創建新的情況,不是嗎?

在提交作業之前,我也要做好os.remove("Job-1.sta")

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM