Python Manual Pages 4
Python Manual Pages 4
Synopsis
Integer py_get_int(String name)
Arguments
name A string representing the expression to be evaluated.
Description
This routine evaluates the expression specified in name and returns an integer result. Only Database functions may be
used in the expression since the Arithmetic functions are floating point routines.
Note: The variables created and used in the Python script are not stored by Mentat and are not available to be
used directly in the expression. Mentat parameters may be defined and used for this purpose.
Example
str = ‘npoints()’
i = py_get_int(‘npoints()’)
j = py_get_int(‘node_id(i)’) # is invalid
str = ‘node_id(%d)’” % i
j = py_get_int(str) # is correct
CHAPTER 1 12
PyMentat References
Synopsis
String py_get_string(String name)
Arguments
name A string representing the function or parameter to be returned.
Description
This routine evaluates the function or parameter specified in name and returns a string result. Any database function
that returns a string may be used in the expression, such as set_name() or job_title(). If name is a string that
begins with ‘$’, then it is interpreted as being the name of a PARAMETER that is currently defined and its expression
is returned.
Note: The variables created and used in the Python script are not stored by Mentat and are not available to be
used directly in the name argument. Mentat PARAMETERS may be defined and used for this purpose.
Example
id = py_get_int(‘set_id(1)‘)
nam = py_get_string(‘set_name(%d)’ % id)
typ = py_get_string(‘set_type(%d)’ % id)
print ‘Set ‘,nam, ‘ is type ‘,typ
py_send(‘*define filename myfile.mfd’)
s = py_get_string(‘$filename’)
print ‘Filename: ‘,s
13 Marc Python Reference
Synopsis
py_prompt(String name)
Arguments
name The string to print in the dialogue area.
Description
This routine prints the string name in the Mentat dialogue area.
Example
py_prompt(”Evaluating Mesh”)
CHAPTER 1 14
PyMentat References
Synopsis
py_send(String command)
Arguments
command A string that contains the Mentat command(s) to be executed.
Description
This routine sends the string command to Mentat for execution. The string may contain multiple Mentat commands
(which must be separated by blanks) and can be constructed using standard Python string operations. The command(s)
will be executed just as if they were typed in the Mentat dialog area.
Graphics windows will not be updated automatically after the string has been executed. They will be updated only after
the Python script has finished executing. The special command *py_update can be sent to Mentat to force a refresh
of the graphics windows during execution of the Python script. This command must be used if one wants to create a
snapshot of the graphics window from the Python script. For example, the following two Python commands save a
snapshot of the current graphics window into the file image.png:
py_send(“*py_update”)
py_send(“*image_save_current image.png yes”)
Example
py_send(“*add_nodes %f %f %f” % (x, y, z)) # creates a node at
# position (x,y,z)
Chapter 2: PyPost References
2 PyPost References
PyPost 21
close 25
cbody 26
cbody_angle 28
cbody_displacement 29
cbody_force 30
cbody_moment 31
cbody_name 32
cbody_rotation 33
cbody_transform 34
cbody_velocity 35
cbody_volume 36
cbodies 37
domain 38
element 39
elements 40
element_id 41
element_scalar 42
element_scalars 43
element_scalar_label 44
element_sequence 45
CHAPTER 2 20
PyPost References
element_tensor 46
element_tensors 47
element_tensor_label 48
element_vector 49
element_vectors 50
element_vector_label 51
extrapolation 52
global_value 53
global_values 54
global_value_label 55
increments 56
moveto 57
node 58
nodes 59
node_displacement 60
node_displacements 61
node_id 62
node_scalar 63
node_scalars 64
node_scalar_label 65
node_sequence 66
node_vector 67
node_vectors 68
node_vector_label 69
post_open 70
set 71
sets 72
title 73
version 74
21 Marc Python Reference
PyPost
This chapter describes the PyPost routines and methods.
The PyPost module is used by a Python script to read data from a Marc post file.
All Python scripts that need access to the PyPost module must import the module as:
from py_post import *
The PyPost object contains attributes that are accessible after opening a post file. For example:
from py_post import *
p = post_open(‘chap19.t16’)
p.moveto(11)
print ‘increment number ‘,p.increment
The PyPost object contains the following attributes:
General Description
cutback The total number of cutbacks
cycles The number of recycles for this increment
extrapolate The current extrapolation method
filename The postfile name associated with this object
increment The current increment
position The current position (as supplied to moveto())
revision The post file revision
separation The total number of separation recycles
split The total number of increment splittings
soltype The dynamic response flag: 0=Normal, 1=Modal, 2=Buckle, 3=Harmonic, 4=Complex.
subinc The current sub-increment. Non-zero for dynamic analysis.
Energy Description (from block 5180n)
creepenergy The total creep strain energy
dampenergy The total damping energy
elasticenergy The total elastic strain energy
energy The total energy
kineticenergy The total kinetic energy
plasticenergy The total plastic strain energy
thermalenergy The total thermal energy
strainenergy The total strain energy
CHAPTER 2 22
PyPost References
Variables
buckle The buckling factor (for a buckling analysis)
frequency The frequency (for a modal or harmonic analysis). This value is zero for the static increments of the
analysis and non-zero for the dynamic increments. The following code segment will search all
increments to find the first dynamic increment.
firstdyn = 0
for i in range(1,ninc):
p.moveto(i)
if p.frequency != 0:
firstdyn = i
Note that soltype can also be check for being non-zero.
machangle The machine angle (SuperForm only)
pressure The process pressure
time The transient time
mass The total mass
volume The total volume
Work Description (from block 5180n)
appliedwork The total work done by applied force or displacement
contactwork The total work done by contact or external forces
foundwork The total work done by foundations
frictionwork The total work due to friction
springwork The total work done by springs
work The total work
close Closes a currently open post file and frees any allocated memory
Synopsis
close( )
Arguments
None
Description
This method closes the post file associated with the PyPost object.
Example
p = post_open(‘c08_job1.t19’)
p.close( )
CHAPTER 2 26
PyPost References
Synopsis
PyContactBody cbody(Integer index)
Arguments
index Contact body index number
Description
Return a PyContactBody object for contact body index. The cbodies method should be called prior to calling the
cbody method to obtain the total number of contact bodies that are available. The PyContactBody object contains the
geometry for the contact body if the revision of the post file is 8 or higher (member revision of the PyPost object).
This method returns a PyContactBody object.
• PyContactBody Members
id - contact body ID
name - name of the contact body (string)
type - contact body type
0 - deformable
1 - 2-D line elements (line type 9)
2 - 3-D patch elements (elem type 18)
3 - 2-D curves
4 - 3-D surfaces
bodytype - physical type of contact body
1 - rigid
2 - deformable structure
3 - symmetry
4 - deformable heat-rigid
5 - workpiece (SuperForm only)
6 - deformable acoustic
Prior to post revision 8, only rigid contact bodies have the following set:
Also See
cbodies, cbody_name
Example
p = post_open(‘ch03_job1.t16’)
p.moveto(0)
n = p.cbodies()
for i in range(0,n):
d = p.cbody(i)
print ‘contact body id ‘,d.id,’ name ‘,d.name,’
Type ‘,d.type
print ‘Physical type ‘,d.bodytype
CHAPTER 2 28
PyPost References
Synopsis
Float cbody_angle(Integer index)
Arguments
index cbody index number
Description
Return the value of the contact body angle at contact body index if available. The cbodies method should be called
prior to calling the cbody_angle method to obtain the total number of cbodies that are available.
This method returns a float.
Also See
cbodies, cbody_name
Example
p = post_open(‘ch03_job1.t16’)
p.moveto(0)
n = p.cbodies()
for i in range(0,p.increments())
p.moveto(i)
for j in range(0,n):
a = p.cbody_angle(i)
29 Marc Python Reference
Synopsis
Float, Float, Float cbody_displacement(Integer index)
Arguments
index Contact body index number
Description
Return the values of the contact body displacement at contact body index. The cbodies method should be called prior
to calling the cbody_displacement method to obtain the total number of contact bodies that are available.
This method returns three floats.
Also See
cbodies, cbody_name
Example
p = post_open(‘ch03_job1.t16’)
p.moveto(0)
n = p.cbodies()
for i in range(0,p.increments())
p.moveto(i)
for j in range(0,n):
x,y,z = p.cbody_displacement(i)
CHAPTER 2 30
PyPost References
Synopsis
Float, Float, Float cbody_force(Integer index)
Arguments
index Contact body index number
Description
Return the values of the contact body force at contact body index. The cbodies method should be called prior to
calling the cbody_force method to obtain the total number of contact bodies that are available.
This method returns three floats.
Also See
cbodies, cbody_name
Example
p = post_open(‘ch03_job1.t16’)
p.moveto(0)
n=p.cbodies()
n = p.cbodies()
for i in range(0,p.increments())
p.moveto(i)
for j in range(0,n):
x,y,z = p.cbody_force(i)
31 Marc Python Reference
Synopsis
Float, Float, Float cbody_moment(Integer index)
Arguments
index Contact body index number
Description
Return the values of the moment for contact body index. The cbodies method should be called prior to calling the
cbody_moment method to obtain the total number of contact bodies that are available.
This method returns three floats.
Also See
cbodies, cbody_name
Example
p = post_open(‘ch03_job1.t16’)
p.moveto(0)
n = p.cbodies()
for i in range(0,p.increments())
p.moveto(i)
for j in range(0,n):
x,y,z = p.cbody_moment(i)
CHAPTER 2 32
PyPost References
Synopsis
String cbody_name(Integer index)
Arguments
index Contact body index number
Description
Return the name contact body index. The cbodies method should be called prior to calling the cbody_name
method to obtain the total number of contact bodies that are available.
This method returns a string.
Also See
cbodies
Example
p = post_open(‘ch03_job1.t16’)
p.moveto(0)
n = p.cbodies()
for i in range(0,n):
print ‘ contact body ‘,p.cbody_id(), ‘ is named ‘,
p.cbody_name(i)
33 Marc Python Reference
Synopsis
Float cbody_rotation(Integer index)
Arguments
index Contact body index number
Description
Return the value of the contact body rotation for contact body index. The cbodies method should be called prior to
calling the cbody_rotation method to obtain the total number of contact bodies that are available.
This method returns a float.
Also See
cbodies, cbody_name
Example
p = post_open(‘ch03_job1.t16’)
p.moveto(1)
n = p.cbodies()
for i in range(0,p.increments())
p.moveto(i)
for j in range(0,n):
r = p.cbody_rotation(i)
CHAPTER 2 34
PyPost References
Synopsis
List Float cbody_transform(Integer index)
Arguments
index Contact body index number
Description
Return the values of the transform for contact body index. The cbodies method should be called prior to calling the
cbody_transform method to obtain the total number of contact bodies that are available.
A transform is actually a 4x4 array of floats, however this method returns an array of 16 floats. They are arranged as
follows:
Also See
cbodies, cbody_name
Example
p = post_open(‘ch03_job1.t16’)
p.moveto(1)
print cbody_transform(p.cbodies()-1)
35 Marc Python Reference
Synopsis
Float cbody_velocity(Integer index)
Arguments
index Contact body index number
Description
Return the value for the velocity of the contact body index. The cbodies method should be called prior to calling the
cbody_velocity method to obtain the total number of contact bodies that are available.
This method returns a float.
Also See
cbodies, cbody_name
Example
p = post_open(‘ch03_job1.t16’)
p.moveto(0)
n = p.cbodies()
for i in range(0,p.increments())
p.moveto(i)
for j in range(0,n):
v = p.cbody_velocity(i)
CHAPTER 2 36
PyPost References
Synopsis
Float cbody_volume(Integer index)
Arguments
index Contact body index number
Description
Return the value for the volume of the contact body index. The cbodies method should be called prior to calling the
cbody_displacement method to obtain the total number of cbodies that are available.
This method returns a float.
Also See
cbodies, cbody_name
Example
p = post_open(‘ch03_job1.t16’)
p.moveto(0)
n = p.cbodies()
for i in range(0,p.increments())
p.moveto(i)
for j in range(0,n):
v = p.cbody_volume(i)
37 Marc Python Reference
Synopsis
Integer cbodies()
Arguments
None
Description
Returns the number of contact bodies.
Example
p = post_open(‘c07_job1.t19’)
p.moveto(0)
n = p.cbodies()
CHAPTER 2 38
PyPost References
Synopsis
Integer domains()
Arguments
None
Description
Returns the number of domains in the post file.
Example
p = post_open(‘c07_job1.t19’)
n = p.domains()
39 Marc Python Reference
Synopsis
PyElement element(int nelem)
Arguments
nelem The element index number
Description
Returns a PyElement object containing the element data for element nelem in the current increment. This data may
change for each increment due to rezoning.
PyElement Members
type - element type
len - number of nodes in the element
items - list of node IDs that comprise the element
Example
p = post_open(‘c08_job1.t19’)
p.moveto(0)
n = p.elements()
for i in range(0,n):
el = p.element(i)
print el
CHAPTER 2 40
PyPost References
Synopsis
Integer elements()
Arguments
None
Description
Returns the number of elements in the current increment. This may change for each increment due to rezoning.
Example
p = post_open(‘c08_job1.t19’)
p.moveto(0)
n = p.elements()
41 Marc Python Reference
Synopsis
Integer element_id(Integer nelem)
Arguments
nelem The element index number
Description
Returns ID of element at index number nelem.
Example
p = post_open(‘c08_job1.t19’)
# print the id’s of each element
p.moveto(0)
n = p.elements()
for i in range(0,n):
print ‘Element ‘,i,’ has id ‘, p.element_id(i)
CHAPTER 2 42
PyPost References
Synopsis
List PyScalar element_scalar(Integer nelem, Integer ns)
Arguments
nelem Element index number
ns Scalar index number
Description
Returns a PyScalar list for element scalar nscalar for element at index nelem. A scala is returned for each node in the
element.
This PyScalar list contains the node id and the scalar value. The list returned is read-only, meaning that the values in
the list cannot be changed.
Example
P = post_open(‘c08_job1.t19’)
p.moveto(1)
ne = p.element_scalars()
n = p.elements()
for i in range(0,ne):
for j in range(0,n):
slist = p.element_scalar(j,i)
print ‘Element ‘,j
for k in range(0,len(slist)):
print ‘ Node ‘,slist[k].id, ‘Scalar ‘,
,slist[k].value
slist[k].value = -slist[k].value # Causes Error
43 Marc Python Reference
Synopsis
Integer element_scalars()
Arguments
None
Description
Returns the number of element scalars available. This method returns an integer.
Example
P = post_open(‘c08_job1.t19’)
# print the element scalar labels
p.moveto(1)
n = p.element_scalars()
for i in range(0,n):
print p.element_scalar_label(i)
CHAPTER 2 44
PyPost References
Synopsis
String element_scalar_label(Integer nscalar)
Arguments
nscalar Scalar index number
Description
Return the name of element scalar nscalar.
This method returns a string.
Example
p = post_open(‘c08_job1.t19’)
# print the element scalar labels
p.moveto(1)
n = p.element_scalars()
for i in range(0,n):
print p.element_scalar_label(i)
45 Marc Python Reference
Synopsis
Integer element_sequence(Integer nelem)
Arguments
nelem The element ID
Description
Returns the index number of element with ID nelem. This is the inverse of the element_id method.
Example
p = post_open(‘c08_job1.t19’)
# print the id’s of each element
p.moveto(0)
n = p.elements()
for i in range(0,n):
print ‘Element Id ‘,i,’ index ‘,p.element_sequence(i)
CHAPTER 2 46
PyPost References
Synopsis
List PyTensor element_tensor(Integer nelem, Integer ntens)
Arguments
nelem Element index number
ntens Tensor index number
Description
Returns a list of nodes and nodal tensor values for element tensor ntens for element an index nelem. A scalar is returned
for each node in the element.
This PyTensor list contains the node ID and the tensor values. The list returned is read-only, meaning that the values
in the list cannot be changed. This method returns a Python list of PyTensor values.
Example
P = post_open(‘c08_job1.t19’)
p.moveto(1)
ne = p.element_tensors()
n = p.elements()
for i in range(0,ne):
for j in range(0,n):
tlist = p.element_tensor(j,i)
print ‘Element ‘,j
for k in range(0,len(tlist)):
print ‘ Tensor ‘,tlist[k]
47 Marc Python Reference
Synopsis
Integer element_tensors()
Arguments
None
Description
Returns the number of element tensors available. This method returns an integer.
Example
P = post_open(‘c08_job1.t19’)
# print the element tensor labels
p.moveto(1)
n = p.element_tensors()
for i in range(0,n):
print p.element_tensor_label(i)
CHAPTER 2 48
PyPost References
Synopsis
String element_tensor_label(Integer ntens)
Arguments
ntens Tensor index number
Description
Return the name of element tensor ntens.
This method returns a string.
Example
p = post_open(‘c08_job1.t19’)
# print the element tensor labels
p.moveto(1)
n = p.element_tensors()
for i in range(0,n):
print p.element_tensor_label(i)
49 Marc Python Reference
Synopsis
List PyVector element_vector(Integer nelem, Integer nv)
Arguments
nelem Element index number
nv Vector index number
Description
Returns a list of nodes and values for element vector nv for element at index nelem. A scalar is returned for each node
in the element.
This PyVector list contains the node id and the vector values. The list returned is read-only, meaning that the values in
the list cannot be changed.
This method returns a Python list of PyVector values.
Example
P = post_open(‘c08_job1.t19’)
p.moveto(1)
ne = p.element_vectors()
n = p.elements()
for i in range(0,ne):
for j in range(0,n):
vlist = p.element_vector(j,i)
print ‘Element ‘,j
for k in range(0,len(vlist)):
print ‘ Vector ‘,vlist[k]
CHAPTER 2 50
PyPost References
Synopsis
Integer element_vectors()
Arguments
None
Description
Returns the number of element vectors available. This method returns an integer.
Example
P = post_open(‘c08_job1.t19’)
# print the element vector labels
p.moveto(1)
n = p.element_vectors()
for i in range(0,n):
print p.element_vector_label(i)
51 Marc Python Reference
Synopsis
String element_vector_label(Integer nscalar)
Arguments
nvec Vector index number
Description
Return the name of element vector nvec. This method returns a string.
Example
p = post_open(‘c08_job1.t19’)
# print the element vector labels
p.moveto(1)
n = p.element_vectors()
for i in range(0,n):
print p.element_vector_label(i)
CHAPTER 2 52
PyPost References
Synopsis
extrapolation(String type)
Arguments
type A string representing the integration method to use
Description
This method controls the manner in which element integration point data is extrapolated to the nodes of an element. In
addition, they control the inter-element averaging of the nodal data after it has been extrapolated. The available
methods are:
linear Extrapolate by averaging the integration points to the centroid of the element and then doing a
linear extrapolation from the centroid through the integration point to the node.
translate Do not extrapolate, but rather copy the data at each integration point to its corresponding node. In
those cases where there are fewer integration points than nodes, some averaging of neighboring
integration points may be done.
average The average of all the integration points is computed and assigned to the nodes. Therefore, all
nodes have an equal value assigned to them.
Example
P = post_open(‘c08_job1.t19’)
p.extrapolation(‘linear’)
print ‘Extrapolation method is ‘, p.extrapolate
53 Marc Python Reference
Synopsis
Float global_value(Integer index)
Arguments
index Global value index number
Description
Return the value of a particular global value index.
This method returns a float.
Example
# Post file from Userguide Example 3.5
p = post_open(‘airspring_axito3d_wcav_job1.t16’)
ninc = p.increments()
p.moveto(ninc-1)
n = p.global_values()
for i in range(0,n):
print p.global_value_label(i), ‘: ‘, p.global_value(i)
Resulting Output:
Volume Cavity 1 : 0.00172809232026
Pressure Cavity 1 : 1904785.625
Mass Cavity 1 : 0.0363396443427
Temperature Cavity 1 : 300.0
Loadcase Percentage Completion : 0.0
CHAPTER 2 54
PyPost References
Synopsis
Integer global_values()
Arguments
None
Description
Returns the number of global values available. This method returns an integer.
Example
P = post_open(‘airspring_axito3d_wcav_job1.t16’)
# print the global value labels
n = p.global_values()
for i in range(0,n):
print p.global_value_label(i)
55 Marc Python Reference
Synopsis
String global_value_label(Integer index)
Arguments
index Global value index number
Description
Return the name of global value index.
This method returns a string.
Example
p = post_open(‘airspring_axito3d_wcav_job1.t16’)
# print the global value labels
n = p.global_values()
for i in range(0,n):
print p.global_value_label(i)
CHAPTER 2 56
PyPost References
Synopsis
Integer increments()
Arguments
None
Description
The number of increments on the post file plus one is returned. Note that a post file starts with a header, which contains
the model data, but no results. This header is included in the increments method. So if a post file only contains
increment 0, the increments method returns two. If a post file contains increment 0 and sub-increments 0:1 and 0:2,
then the increments method returns four. The increments method is often combined with the moveto method
(see moveto) to skip to a particular increment.
Example
p = post_open(‘c08_job1.t19’)
n = p.increments()
57 Marc Python Reference
Synopsis
moveto(Integer i)
Arguments
i increment number
Description
Moves to the specified increment in the post file. Increment number 0 only contains the model itself. There is no scalar
data for increment 0. The first increment with data is increment 1.
When the moveto method is called, the following members of the PyPost object are available:
Example
p = post_open(‘c07_job1.t19’)
p.moveto(4)
print ‘increment ‘,p.increment,’ Time ‘,p.time
print ‘Frequency ‘,p.frequency
CHAPTER 2 58
PyPost References
Synopsis
PyNode node(int nnode)
Arguments
nnode The node index number
Description
Returns a PyNode object containing the nodal data for node at index nnode in the current increment. This data may
change for each increment due to rezoning.
PyNode Members
id - node ID
x - x coordinate
y - y coordinate
z - z coordinate
Example
p = post_open(‘c08_job1.t19’)
p.moveto(0)
n = p.nodes()
for i in range(0,n):
nod = p.node(i)
print "Node index number ",i, " Id ",nod.id
print " x = ",nod.x, " y = ",nod.y," z = ",p.z
59 Marc Python Reference
Synopsis
Integer nodes()
Arguments
None
Description
Returns the number of nodes in the current increment. This may change for each increment due to rezoning.
Example
p = post_open(‘c07_job1.t19’)
p.moveto(0)
n = p.nodes()