简体   繁体   English

如何通过Python脚本告诉Abaqus在错误后继续?

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

At the moment I´m programming a Python-script that I start in Abaqus CAE. 目前,我正在编程一个从Abaqus CAE开始的Python脚本。 It´s purpose is to generate a dataset for a neural network. 目的是为神经网络生成数据集。 Therefore the script picks a random node out of a before defined nodeset and applies a displacement and a rotation on that node. 因此,脚本从预先定义的节点集中选取一个随机节点,并对该节点施加位移和旋转。 Then it tells abaqus to solve that simulation and reads the odb-file after the simulation is complete. 然后,它告诉abaqus解决该模拟问题,并在模拟完成后读取odb文件。 After that the script is continuing with the next random chosen node for a before chosen amount of iterations. 之后,脚本将继续使用下一个随机选择的节点进行之前选定的迭代次数。 The script works fine code-wise, but now and then the random chosen inputs for the displacement and the rotation are too difficult for abaqus to solve, so it crashes with a "Increment-Error" ( Too many increments made for this increment....). 该脚本可以很好地在代码上正常运行,但是对于abaqus而言,它有时难于解决位移和旋转的随机选择输入,因此它会崩溃,并显示“ Increment-Error”(对此增量进行了太多的增量。 ..)。 And because of that there is a .lck file in the directory that prevents the Python-script to get access to read the odb-File and therefore also the Python-script crashes. 因此,目录中存在一个.lck文件,该文件阻止Python脚本访问读取odb-File,因此Python脚本也会崩溃。 I already tried to fix this error by editing the Increment size and the maximum number of increments, but both ideas have not worked. 我已经尝试通过编辑“增量”大小和最大增量数来解决此错误,但两种方法均无效。 My latest idea was to implement a "if"-condition that tells abaqus to delete all "Job_1.*"-files and to continue with the next node and other random chosen input variables, if there exists a .lck file directly after the job is done. 我的最新想法是实现一个“ if”条件,该条件告诉abaqus删除所有“ Job_1。*”文件,并继续下一个节点和其他随机选择的输入变量(如果在作业之后直接存在一个.lck文件)。已经完成了。 But also this idea has not worked. 但是这个想法也没有奏效。 Because of that i ask you guys, if any of you has an idea how i can solve this problem. 因此,我问你们,如果你们有一个想法我可以解决这个问题。 Is there any way to tell Abaqus it should continue with another node after such an error accured? 有没有办法告诉Abaqus,在发生此类错误后应继续使用另一个节点? Here is the Code: 这是代码:

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)

Here is the errror in Abaqus CAE: 这是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

And after that outprinting the Python-error-Window tells me that there is no .sta file. 之后,Python错误窗口的输出告诉我没有.sta文件。

Use try and except clause: 使用try和except子句:

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

I'd suggest using try-except from https://docs.python.org/2/tutorial/errors.html 我建议使用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!"

in your edited version you still open and attempt to process the odb after detecting a failure. 在已编辑的版本中,您仍然会打开并在检测到故障后尝试处理odb。

You should have (note the affirmative) 您应该有(请注意)

   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"

i don't see why you need to do anything besides print an error message, the main loop will just continue and create a new case will it not? 我看不到为什么除了打印错误消息外,您还需要做什么,主循环将继续并创建新的情况,不是吗?

I would also for good measure do os.remove("Job-1.sta") before submitting the job. 在提交作业之前,我也要做好os.remove("Job-1.sta")

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM