Professional Documents
Culture Documents
Abaqus二次开发专题
Abaqus二次开发专题
L4.2
L4.4
>>> odb = openOdb('cantilever.odb') >>> odb.__members__ ['analysisTitle', 'closed', 'description', 'diagnosticData', 'isReadOnly', 'jobData', 'name', 'parts', 'path', 'rootAssembly', 'sectionCategories', 'sectorDefinition', 'steps', 'userData'] >>> odb.__methods__ ['Part', 'SectionCategory', 'Step', 'UserXYData', 'close', 'getFrame', 'save', 'update']
L4.5
prettyPrint
>>> from textRepr import * >>> prettyPrint(odb) ({'analysisTitle': 'Cantilever beam model', 'closed': FALSE, 'description': 'DDB object', 'diagnosticData': 'OdbDiagnosticData object', 'isReadOnly': FALSE, 'jobData': 'JobData object', 'name': 'cantilever.odb', 'parts': 'Repository object', 'path': 'd:\temp\cantilever.odb ', 'rootAssembly': 'OdbAssembly object', 'sectionCategories': 'Repository object', 'sectorDefinition': None, 'steps': 'Repository object', 'userData': 'UserData object'})
1 2 prettyPrint.py.
>>> prettyPrint(odb, maxRecursionDepth=2)
textRepr Abaqus .
>>> session.textReprOptions.setValues(maxRecursionDepth=3)
Introduction to Python and Scripting in Abaqus
Dassault Systmes, 2008
L4.6
textRepr textRepr :
getIndentedRepr, getPaths, getTypes, prettyPrint, prettyPrintToFile, prettyPrintToFileName, prettyPrintToTerm, printPaths, printPathsToFile, printPathsToFileName, printPathsToTerm, printTypes
:
prettyPrint(object <, maxRecursionDepth, maxElementsInSequence, significantDigits, _internalMembersMethods>) printPaths(object <, maxRecursionDepth, maxElementsInSequence, pathRoot, _internalMembersMethods>) printTypes(object <, maxRecursionDepth, maxElementsInSequence, pathRoot, _internalMembersMethods>) printPathsToFileName(fileName, object <, maxRecursionDepth, maxElementsInSequence, pathRoot, _internalMembersMethods >)
<...> __doc__
L4.7
>>> from odbAccess import * >>> from textRepr import * >>> odb = openOdb('cantilever.odb') >>> printPaths(odb, pathRoot='odb') odb.analysisTitle odb.closed odb.description odb.diagnosticData odb.isReadOnly odb.jobData odb.name odb.parts odb.path odb.rootAssembly odb.sectionCategories odb.sectorDefinition odb.steps odb.userData
>>> printPaths(odb, 2, pathRoot='odb')
. . .
>>> printPaths(odb.steps['Step-1'], 2, pathRoot='step')
Introduction to Python and Scripting in Abaqus
Dassault Systmes, 2008
L4.8
getPaths
>>> x = getPaths(odb.steps['Step-1'].frames[87].fieldOutputs, pathRoot='fieldOutputs') >>> print x fieldOutputs['S'] fieldOutputs['PE'] fieldOutputs['RF'] fieldOutputs['PEEQ'] fieldOutputs['LE'] fieldOutputs['PEMAG'] fieldOutputs['AC YIELD'] fieldOutputs['CF'] fieldOutputs['U'] >>> y = x.splitlines() >>> print y[3] fieldOutputs['PEEQ']
L4.9
printTypes member
>>> stress = odb.steps['Step-1'].frames[87].fieldOutputs['S'] >>> printTypes(stress, pathRoot='stress') tuple stress.componentLabels string stress.description FieldLocationArray stress.locations string stress.name SymbolicConstant stress.type tuple stress.validInvariants FieldValueArray stress.values
getPaths() eval(path)
for path in getPaths(obj).splitlines(): print '%-20s %s' % (eval(path), path)
Abaqus
L4.11
Abaqus
Abaqus kernelGUI Update messages
Commands
Abaqus Abaqus GUI GUI Command Command line line interpreter interpreter Python Python interpreter interpreter
Input file
L4.12
Abaqus
GUI Abaqus API GUI Abaqus GUI Python GUI
L4.14
monitorManager callback
L4.15
from abaqus import * from jobMessage import ANY_JOB, ANY_MESSAGE_TYPE
# define a callback function
def printMessages(jobName, mType, data, userData): print 'Job name: %s, Message type: %s'%(jobName, mType) print 'data members:' members = dir(data) format = ' %-18s %s' print format%('member', 'value') for member in members: memberValue = getattr(data, member) print format%(member, memberValue)
# call the function for all jobs, and all message types
L4.16
myJob1 myJob2
myJob1 = mdb.Job(name='Job-1', model='Model-1') myJob2 = mdb.Job(name='Job-2', model='Model-2') myJob1.submit() myJob1.waitForCompletion() myJob2.submit() myJob2.waitForCompletion()
L4.18
>>> mdb.customData.myDict = {}
L4.19
L4.20
L4.22
Abaqus/CAE GUI ( GUI ) plugin.py Abaqus/CAE abaqus/abaqus_plugins, abaqus Abaqus home/abaqus_plugins, home current/abaqus_plugins, current abaqus_v6.env plugin_central_dir
plugin_central_dir = r'\\fileServer\sharedDirectory'
Abaqus/CAE Plug-ins
L4.23
myUtils.py def printTime(): import time t = time.localtime() print 'The time is: %d:%d' %d/%d/%d' % \ (t[3], t[4], t[1], t[2], t[0]) time_plugin.py from abaqusGui import getAFXApp toolset = getAFXApp().getAFXMainWindow().getPluginToolset() toolset.registerKernelMenuButton(moduleName='myUtils', functionName='printTime()', buttonText='Print Time')
abaqus_plugins
L4.24
L4.25
GUI GUI Abaqus GUI Abaqus GUI RSG RSG: Abaqus GUI GUI 4.2 RSG
L4.27
L4.28
Python
File "testTraceback.py", line 3, in ? a() File ".\aTest.py", line 4, in a b() File ".\bTest.py", line 2, in b 1/0 ZeroDivisionError: integer division or modulo by zero
if not myDict.has_key(key): raise KeyError, 'myDict does not have key: %s' % key
Introduction to Python and Scripting in Abaqus
Dassault Systmes, 2008
L4.29
strategic points
def myFunc(a, b): print 'arg a:', a, 'arg b:', b ...
Abaqus
print session.viewport['Viewport: 1'] ... 'border': ON, 'titleBar': ON, 'name': 'Viewport: 1' ...
L4.30
(Pdb) ? EOF break cont enable list quit tbreak whatis a c continue h n r u where alias cl d help next return unalias args clear disable ignore p s up b condition down l q step w
Pdb Python
Introduction to Python and Scripting in Abaqus
Dassault Systmes, 2008
L4.31
L4.32
(IDE) PythonWin, WingIDE, IDLE, Komodo Abaqus Python IDE Abaqus Abaqus IDE Internet Idle PythonWin IDE Python IDEAbaqus PDE
L4.33
Abaqus PythonPDE
L4.35
L4.36
Abaqus Python
Abaqus PDE
Abaqus/CAE PDE
Abaqus/CAE
L4.37
Abaqus Python
Abaqus PDE
L4.38
Abaqus Python
GUI (CLI) GUI GUI API (GUI)
GUI CLI
Introduction to Python and Scripting in Abaqus
Dassault Systmes, 2008
L4.39
Abaqus Python
(CLI)
L4.40
Abaqus Python
Abaqus/CAE PDE odb API PDE GUI abq pde script local.py
Local
GUI CLI
Introduction to Python and Scripting in Abaqus
Dassault Systmes, 2008
L4.42
L4.43
Python Python C
L4.44
()
.
(: Python )
Erich
Gamma, Richard Helm, Ralph Johnson, John Vlissides, Addison-Wesley, 1995
L4.45
square
class Square: def __init__(self, size): self.size = size self.color = 'Red' # Set the default color to 'Red' def setColor(self, color): self.color = color def draw(self): s = self.size * 0.5 drawLine(-s, -s, s, -s) drawLine( s, -s, s, s) drawLine( s, s, -s, s) drawLine(-s, s, -s, -s) >>> sq = Square(5) >>> sq.size 5.0 >>> sq.color 'Red' >>> sq.setColor('Blue') >>> sq.draw()
drawline
L4.46
IsA IsA
Abaqus
L4.47
L4.48
()
L4.49
class DrawingPrimitive: def __init__(self): self.color = 'Red' # Set the default color to 'Red' def setColor(self, color): self.color = color # color is set using base class method def draw(self): # abstract base class - cannot draw raise RuntimeError, 'draw method not implemented' class Square(DrawingPrimitive): def __init__(self, size): DrawingPrimitive.__init__(self) # init base class self.size = float(size) def draw(self): # override base class draw method s = self.size * 0.5 drawLine(-s, -s, s, -s) drawLine( s, -s, s, s) drawLine( s, s, -s, s) drawLine(-s, s, -s, -s)
L4.50
square
>>> sq = Square(5) >>> sq.size 5.0 >>> sq.color 'Red' >>> sq.setColor('Blue') >>> sq.color 'Blue' >>> sq.draw()
Python
L4.52
Python
class
>>> class Plain: # define a class ... pass ...
>>> a = Plain() # create an instance of class Plain
>>> a.x = 1.0 # add members to the instance >>> a.y = 2.0 >>> a.description = 'First Point'
-
>>> print a # print the string value of the instance <__main__.Plain instance at 00896A7C>
L4.53
Python
Magic methods . . . Python
>>> class Simple: ... def __init__(self, arg): ... self.arg = arg # preferred way of adding members ... def __str__(self): # called by print or str(x) ... return self.arg ...
__init__
>>> b = Simple('Point X')
Python +, -, /, *,
L4.54
Python
>>> dir(sq) # list the attributes of sq (incl class attrs) ['__doc__', '__init__', '__module__', 'color', 'draw', 'setColor', 'size'] >>> sq.__dict__ # attribute values are stored in __dict__ {'size': 5.0, 'color': 'Blue'}
>>> dir(sq.__class__) ['__doc__', '__init__', '__module__', 'draw', 'setColor']
.
>>> type(sq) # all instances have type 'instance' <type 'instance'>
__class__
>>> sq.__class__ # __class__ contains the class object <class __main__.Square at 008C6534> >>> sq.__class__.__name__ # get the class name 'Square'
L4.55
Python
The __repr__ and __setattr__ methods
>>> class Spam(Simple): ... locked = 0 ... def __init__(self, arg): ... self.description = arg ... self.locked = 1 ... def __repr__(self): # used to re-create the object ... s = "Spam('%s')"%self.description ... return s ... def __setattr__(self, arg, value): ... if self.locked: ... raise TypeError, 'object is read-only' ... self.__dict__[arg] = value ... >>> c = Spam('Point 1') >>> c Spam('Point 1') >>> c.x = 2.1 Traceback (most recent call last): File "<stdin>", line 1, in ? File "spam.py", line 11, in __setattr__ raise TypeError, 'object is read-only' TypeError: object is read-only
Introduction to Python and Scripting in Abaqus
Dassault Systmes, 2008
L4.56
Python
__getattr__ __setattr__ __getitem__ __setitem__ __len__ __nonzero__ __cmp__ __call__ __add__ __sub__ __mul__ __div__ (__iadd__ etc) __lt__ __le__ __eq__ __ne__ __ge__ __gt__
L4.57
Python Abaqus :
__init __ SIMULIA 2483
L4.59
from part import THREE_D, DEFORMABLE_BODY class Extrusion: """abstract base class Extrusion. Objects are centered at origin""" def __init__(self, model, name, depth): if self.__class__.__name__ == 'Extrusion': raise TypeError, "Extrusion is abstract base class" self.model = model self.name = name self.depth = depth self.sketch = self.model.ConstrainedSketch(name=name, sheetSize=200.0) def createPartUsingSketch(self): self.part = self.model.Part(name=self.name, dimensionality=THREE_D, type=DEFORMABLE_BODY) self.part.BaseSolidExtrude(sketch=self.sketch, depth=self.depth) session.viewports[session.currentViewportName].\ setValues(displayedObject=self.part) def getVolume(self): raise TypeError, "getVolume not implemented" def printSummary(self): raise TypeError, "printSummary not implemented"
L4.60
class Block(Extrusion): """Block(model, name, width, height, depth)""" def __init__(self, model, name, width, height, depth): Extrusion.__init__(self, model, name, depth) self.width = width self.height = height self.sketch.rectangle(point1=(-width/2,-height/2), point2=(width/2,height/2)) self.createPartUsingSketch() def getVolume(self): return self.width * self.height * self.depth def printSummary(self): print 'Block object:' print 'width=%d, height=%d, depth=%d'%\ (self.width, self.height, self.depth)
L4.61
class Cylinder(Extrusion): """Cylinder(model, name, radius, depth)""" def __init__(self, model, name, radius, depth): Extrusion.__init__(self, model, name, depth) self.radius = radius self.sketch.CircleByCenterPerimeter(center=(0.0, 0.0), point1=(0.0, radius)) self.createPartUsingSketch() def getVolume(self): import math return math.pi * self.radius ** 2 * self.depth def printSummary(self): print 'Cylinder object:' print 'radius=%d'%(self.radius)
L4.62
>>> execfile('extrusionDemo.py') Part module loaded >>> m = mdb.models['Model-1'] >>> b = Block(m, 20, 30, 100) #* exceptions.TypeError: not enough arguments; expected 6, got 5 >>> Block.__doc__ 'Block(model, name, width, height, depth)' >>> b = Block(m, 'BLK', 20, 30, 100) >>> c = Cylinder(m, 'CYL', 30, 100) >>> c.printSummary() Cylinder object: radius=30 >>> b.printSummary() Block object: width=20, height=30, depth=100 >>> b.getVolume() 60000 >>> c.getVolume() 282743.338823
L4.64
4.1:
INPUT rubberDome.inp 52 U2 rubberDome MONITOR_DATA monitorDataValue 52 -2.0
L4.65
4.2: GUI
rpy RSG