0% found this document useful (0 votes)
6 views

Python Manual Pages 4

The document provides a reference for various Python routines used in the Mentat software, detailing functions such as py_get_int, py_get_string, py_prompt, and py_send, which allow users to evaluate expressions, print messages, and send commands to Mentat. It also introduces the PyPost module for reading data from Marc post files, explaining its attributes and methods for accessing contact body data and other elements. Examples are provided for each function to illustrate their usage within Python scripts.

Uploaded by

qq2109235237
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views

Python Manual Pages 4

The document provides a reference for various Python routines used in the Mentat software, detailing functions such as py_get_int, py_get_string, py_prompt, and py_send, which allow users to evaluate expressions, print messages, and send commands to Mentat. It also introduces the PyPost module for reading data from Marc post files, explaining its attributes and methods for accessing contact body data and other elements. Examples are provided for each function to illustrate their usage within Python scripts.

Uploaded by

qq2109235237
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 45

11 Marc Python Reference

py_get_int Evaluates an expression and returns an integer value

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

py_get_string Evaluates a function or parameter and returns a string

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

py_prompt Prints a string in the Mentat dialogue area

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

py_send Sends commands to Mentat for execution

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

The PyPost module uses the following special types:

PyNode Nodal Data


id The node ID
x, y, z The x, y, z coordinates of the node
PyElement Element Data
type The element type
len The number of nodes in the element
items The list of node IDs for the element
PySet Set Data
name The string representing the set name
type The set type, either “node” or “element”
len The number of items in the ‘items’ list
items The list of nodes or elements
23 Marc Python Reference

PyTensor Tensor Data


id The node ID of the tensor, if applicable
t11, t12, t13 First row of tensor matrix. These values in matrix notation would be t(1,1), t(1,2), and t(1,3),
respectively.
t22, t23 Second row of tensor matrix. Since the tensor matrix is symmetric, only the “top right” values
of the matrix are returned. These values in matrix notation would be t(2,2) and t(2,3),
respectively.
t33 Third row of tensor matrix. This value in matrix notation would be t(3,3).
intensity The tensor intensity
PyVector Vector Data
id The node id of the vector, if applicable
x,y,z The x, y, z vector values
PyCurve Curve Data
npoints Number of points
norder Order of curve
points List of points that describe the curve (PyNode)
knots Knot vector. The number of items is npoints+norder.
w Weight values. The number of items is npoints.
PySurface Surface Data
npoints_u Number of points in “u” direction.
npoints_v Number of points in “v” direction.
norder_u Order of surface in “u” direction.
norder_v Order of surface in “v” direction.
points List of points that describe the surface (PyNode). There are npoints_u*npoints_v
number of points. They are arranged in “v” major order, such that:
for i in range(0,npoints_v):
for j in range(0,npoints_u):
print ‘point[%i][%j].x=%12g‘ %
(point[i*npoints_u+j].x)
w List of weight values (floats). They are arranged in “v” major order similar to the points array.
knots_u List of knot values (floats) in “u” direction. There are npoints_u+order_u items.
knots_v List of knot values (floats) in “v” direction. There are npoints_v+order_v items.
ntrim Number of trimming curves
trim List of trimming curves (PyCurve).
PyContactBody Contact Body Data
id The ID of the contact body
name The name of the contact body
CHAPTER 2 24
PyPost References

type The type of the contact body:


0 - deformable
1 - 2-D line elements (type 9)
2 - 3-D patch elements (type 18)
3 - 2-D curves
4 - 3-D surfaces
bodytype The physical type of the contact body:
1 - rigid
2 - deformable structural
3 - symmetry
4 - deformable heat-rigid
5 - workpiece (AutoForge)
6 - deformable acoustic
center_x The center of the contact body
center_y
center_z
axis_x The axis of the contact body
axis_y
axis_z
npoints The number of points in the point array that describe the contact body. This value is nonzero if
the contact body type is 1 or 2.
points Array of PyNode’s that describe the contact body
nelements Number of items in the elements array. This is set if the contact body type is 0. This value may
also be obtained by using len(cb.elements) where cb is the PyContactBody object.
elements List of element IDs that describe the contact body.
npatches Number of items in the patches array. This is set if the contact body type is 2. This value may
also be obtained by using len(cb.patches) where cb is the PyContactBody object.
patches List of PyPatch’s that describe the contact body.
ncurves The number of curves that describe the contact body. This is nonzero if the contact body is type
3. This value may also be obtained by using len(cb.curves) where cb is the
PyContactBody object.
curves List of PyCurve’s that describe the contact body.
nsurfaces The number of surfaces that describe the contact body. This is nonzero if the contact body is
type 4. This value may also be obtained by using len(cb.surfaces) where cb is the
PyContactBody object.
surfaces List of PySurface’s that describe the contact body.
25 Marc Python Reference

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

cbody Returns a PyContactBody object for a particular contact body

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

If the contact body type is 0 the following are set:

nelements - number of element items


elements - array of element IDs that comprise the contact body.
27 Marc Python Reference

If the contact body type is 1 the following are set:

nlines - number of lines that comprise the contact body


lines - array of lines (PyPatch’s) that comprise the contact body. The point1 and point2 members of
PyPatch are indices into the points array.

If the contact body type is 2 the following are set:

npatches - number of patches that comprise the contact body


patches - array of patches (PyPatch’s) that comprise the contact body. The point1, point2, point3 and
point4 members of PyPatch are indices into the points array.

If the contact body type is 1 or 2 the following are set:

npoints - number of point items


points - array of points (PyNode’s) that comprise the contact body.

If the contact body type is 3 the following are set:

ncurves - number of curve items


curves - array of curves (PyCurve’s) that comprise the contact body.

If the contact body type is 4 the following are set:

nsurfaces - number of surface items


surfaces - array of surfaces (PySurface’s) that comprise the contact body.

Prior to post revision 8, only rigid contact bodies have the following set:

center_x, center_y, center_z - center of the contact body


axis_x, axis_y, axis_z - axis of the contact body

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

cbody_angle Returns the angle for a particular contact body

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

cbody_displacement Returns the displacement for a particular contact body

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

cbody_force Returns the x, y, and z force for a particular contact body

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

cbody_moment Returns the moment for a particular contact body

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

cbody_name Returns the name of a particular contact body

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

cbody_rotation Returns the rotation for a particular contact body

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

cbody_transform Returns the transform for a particular contact body

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:

t0 t1 t2 t3


T = t4 t5 t6 t7
t8 t9 t  10  t  11 
t  12  t  13  t  14  t  15 

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

cbody_velocity Returns the velocity of a particular contact body

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

cbody_volume Returns the volume of a particular contact body

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

cbodies Returns the number of contact bodies

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

domain Returns the number of domains in the post file

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

element Returns the element data for a particular element

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

elements Returns the number of elements in the current increment

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

element_id Returns ID of a particular element

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

element_scalar Get a list of a particular element scalar for a particular element

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

element_scalars Returns the number of element scalars available

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

element_scalar_label Returns the name of a particular element scalar

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

element_sequence Returns the index number of a particular element ID

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

element_tensor Get a list of a particular element tensors for a particular element

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

element_tensors Returns the number of element tensors available

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

element_tensor_label Returns the name of a particular element tensor

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

element_vector Get a list of a particular element vector for a particular element

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

element_vectors Returns the number of element vectors available

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

element_vector_label Returns the name of a particular element vector

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

extrapolation Sets the integration point extrapolation method

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

global_value Returns the value of a particular global value

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

global_values Returns the number of global values available

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

global_value_label Returns the name of a particular global value

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

increments Returns the number of increments plus one

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

moveto Moves to the specified increment in the post file

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:

increment increment number


time time of this increment
frequency frequency value of this increment

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

node Returns the nodal data for a particular node

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

nodes Returns the number of nodes in the current increment

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()

You might also like