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

Python Manual Pages 3

Chapter 12 discusses the PyPost module for plotting in Python, detailing the creation of Gnuplot objects, setting plot parameters, and generating plots from data. It also introduces the PyOpenGL module for rendering 3-D graphics, including classes for managing displacement data and window properties. The chapter provides code examples for plotting nodes, drawing elements, and creating a graphical user interface for visualizing deformed and undeformed shapes.

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

Python Manual Pages 3

Chapter 12 discusses the PyPost module for plotting in Python, detailing the creation of Gnuplot objects, setting plot parameters, and generating plots from data. It also introduces the PyOpenGL module for rendering 3-D graphics, including classes for managing displacement data and window properties. The chapter provides code examples for plotting nodes, drawing elements, and creating a graphical user interface for visualizing deformed and undeformed shapes.

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

CHAPTER 12 91

PyPost: Plotting

Line 12 Create the Gnuplot object.


Lines 14-15 Set the title, the linestyle, and the size of the plot.
Line 16 Create an array to store the Gnuplot Data objects.
Line 18-19 Loop through each node in the ccheck_nodes list and create a title containing the node number
and set the line color to a different color for each line.
Lines 20-21 Set the x and y axis labels.
Line 22 Call the plot routine to generate the plot. When the plot routine is called, the data is sent to the gnuplot
program and the plot is displayed.
Line 23-26 If the platform is Microsoft Windows, pause the display. Otherwise wait for five seconds and then
exit.
Line 28 Create the postscript file.
Line 30 Sleep (or pause) the program. If this is not done, a file is not generated.
Lines 33-66 The main routine is similar to that of the chap12a.py example.

When the script completes, a plot as shown in Figure 12-2 is displayed in the Gnuplot program, and is saved as a
PostScript plot in the file chap12b.ps.

Figure 12-2 Resulting PostScript File from chap12b.py


92 Marc Python Tutorial

The PyOpenGL Module


The OpenGL module is an interface to the PyOpenGL API that can be used by Python scripts to draw 3-D graphics.
It is useful to create 3-D graphs, plots, or to display the model itself which will be shown in this example. The original
model and the final displaced model will be displayed.
The post file model is a 2-D model from the Chapter 9: PyPost: Obtaining Element Data example. It requires the
PyOpenGL module and the Numeric extensions from LLNL.
1. from py_post import *
2. from Numeric import *
3. from OpenGL.GL import *
4. from OpenGL.Tk import *
5. from OpenGL.GLUT import *
6.
7. # list of the nodes to label
8. check_nodes = [1,4,7,45]
9.
10. class Displ:
11. def __init__(self, i, xv, yv, dxv, dyv):
12. self.Id = i
13. self.X = xv
14. self.Y = yv
15. self.dX = dxv
16. self.dY = dyv
17. def x(self):
18. return self.X
19. def y(self):
20. return self.Y
21. def dx(self):
22. return self.dX
23. def dy(self):
24. return self.dY
25. def id(self):
26. return self.Id
27.
CHAPTER 12 93
PyPost: Plotting

28. class Win:


29. def __init__(self, left, right, bottom, top, w, h):
30. self.Left = left
31. self.Right = right
32. self.Bottom = bottom
33. self.Top = top
34. self.Width = w
35. self.Height = h
36. def left(self):
37. return self.Left
38. def right(self):
39. return self.Right
40. def bottom(self):
41. return self.Bottom
42. def top(self):
43. return self.Top
44. def width(self):
45. return self.Width
46. def height(self):
47. return self.Height
48.
49. def width():
50. return 400
51.
52. def height():
53. return 400
54.
55. def mode_3d():
56. global win
57. glMatrixMode(GL_PROJECTION)
58. glLoadIdentity()
59. glOrtho(win.left(), win.right(), win.bottom(),win.top(), -1.0,1.0)
60. glMatrixMode(GL_MODELVIEW)
61.
94 Marc Python Tutorial

62. BMfonts = ( "glut9by15", "glut8by13",


63. "glutTimesRoman10", "glutTimesRoman24",
64. "glutHelvetica10", "glutHelvetica12", "glutHelvetica18" )
65.
66. # draw a symbol for the node
67. def draw_dot(x,y):
68. dot = array([0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,0xFFFFFFFF,
69. 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,0xFFFFFFFF])
70. glPixelStorei(GL_UNPACK_ALIGNMENT, 1)
71.
72. wid = 3
73. hei = 3
74. glRasterPos3f(x,y,0.0)
75. t=dot.tostring()
76. glDrawPixels(wid, hei, GL_RGBA, GL_UNSIGNED_BYTE, t)
77. return
78.
79. def draw_string(str,x,y):
80. glRasterPos3f(x,y,0.0)
81. for i in range(len(str)):
82. glutBitmapCharacter("glut9by15", ord(str[i]));
83. return
84.
85. def draw_element(i):
86. # draw the original shape
87. glColor3f(1,0,0)
88. glBegin(GL_LINE_STRIP)
89. glVertex2f(nodex[i], nodey[i])
90. glVertex2f(nodex[i+1], nodey[i+1])
91. glVertex2f(nodex[i+2], nodey[i+2])
92. glEnd()
93. # draw the deformed shape
94. glColor3f(0,1.0,0.0)
95. glBegin(GL_LINE_STRIP)
CHAPTER 12 95
PyPost: Plotting

96. glVertex2f(nodedx[i], nodedy[i])


97. glVertex2f(nodedx[i+1], nodedy[i+1])
98. glVertex2f(nodedx[i+2], nodedy[i+2])
99. glEnd()
100. return
101.
102. def plot_nodes(lst):
103. global p
104. glColor3f(1,1,1)
105. for i in range(len(lst)):
106. j = p.node_sequence(lst[i])
107. k=lst[i]
108. draw_string(`k`,nod[j].x(), nod[j].y())
109. draw_dot(nod[j].x(), nod[j].y())
110. dx = nod[j].x()+nod[j].dx()
111. dy = nod[j].y()+nod[j].dy()
112. draw_string(`k`,dx, dy)
113. draw_dot(dx,dy)
114. return
115.
116. def draw_legend():
117. global win
118. glColor3f(1,0,0)
119. glBegin(GL_LINE_STRIP)
120. x1 = win.left() + .1
121. x2 = x1 + (win.right()-win.left())/5.0
122. y = win.bottom() +.15
123. glVertex2f(x1, y)
124. glVertex2f(x2, y)
125. glEnd()
126. draw_string("undeformed", x2+.05, y)
127. glColor3f(0,1.0,0.0)
128. glBegin(GL_LINE_STRIP)
129. glVertex2f(x1, y-.1)
96 Marc Python Tutorial

130. glVertex2f(x2, y-.1)


131. glEnd()
132. draw_string("deformed",x2+.05, y-.1)
133. return
134.
135. def redraw(o):
136. glClearColor(0.1, 0.1, 0.1, 0)
137. glColor3f(1,0,0)
138. glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
139. mode_3d()
140.
141. glDisable(GL_LIGHTING)
142. for i in range(0,len(nodex),3):
143. draw_element(i)
144. plot_nodes(check_nodes)
145. draw_legend()
146. glEnable(GL_LIGHTING)
147. return
148.
149. def find_node(n,nod):
150. for i in range(0,len(nod)):
151. if nod[i].id() == n:
152. return i
153. return -1
154.
155. def find_maxmin(x, y):
156. global maxx, maxy, minx, miny
157. if maxx < x : maxx = x
158. if maxy < y : maxy = y
159. if minx > x : minx = x
160. if miny > y : miny = y
161.
162. def main(fname):
163. global nodex, nodey, nodedx, nodedy
CHAPTER 12 97
PyPost: Plotting

164. global maxx, maxy, minx, miny


165. global nod # List of Displ objects
166. global win
167. global o, p
168.
169. p = post_open(fname)
170. p.moveto(1)
171. nns = p.node_scalars()
172.
173. ninc = p.increments()
174. print " Increments = ",ninc
175.
176. # find the index ih the scalar label list for the displacements
177. for i in range(0,nns):
178. s = p.node_scalar_label(i)
179. if s == "Displacement X" :
180. nlocx = i
181. if s == "Displacement Y" :
182. nlocy = i
183.
184. # go to the last increment
185. p.moveto(p.increments()-1)
186. k = 0
187.
188. # get nodes
189. nod = [Displ] * p.nodes()
190. while k < n:
191. j = p.node_id(k)
192. i = k
193. np = p.node(k)
194. dx = p.node_scalar(k,nlocx)
195. dy = p.node_scalar(k,nlocy)
196. nod[k] = Displ(j,np.x, np.y,dx,dy)
197. k = k + 1
98 Marc Python Tutorial

198.
199. k = 0
200. n = p.elements()
201.
202. # Create the x and y coordinate arrays for plotting.
203. # We should check the element list to find out how many
204. # nodes are in each element.
205. # We know for this model all elements have 3 nodes.
206. nodex = [0.0]*(n*3)
207. nodey = [0.0]*(n*3)
208. nodedx = [0.0]*(n*3)
209. nodedy = [0.0]*(n*3)
210. maxx = maxy = -10000.0
211. minx = miny = 10000.0
212.
213. cnt=0
214. # build the x and y coordinate arrays
215. while k < p.elements():
216. el = p.element(k)
217. for m in range(0,el.len):
218. id=find_node(el.items[m],nod)
219. if id >=0 :
220. nodex[cnt] = nod[id].x()
221. nodey[cnt] = nod[id].y()
222. nodedx[cnt] = nod[id].x() + nod[id].dx()
223. nodedy[cnt] = nod[id].y() + nod[id].dy()
224. find_maxmin(nodex[cnt], nodey[cnt])
225. find_maxmin(nodedx[cnt], nodedy[cnt])
226. cnt = cnt+1
227. k = k +1
228.
229. # Generate the Win object containing the viewport info
230. minx = minx - .25*(maxx-minx)
231. maxx = maxx + .25*(maxx-minx)
CHAPTER 12 99
PyPost: Plotting

232. miny = miny - .25*(maxy-miny)


233. maxy = maxy + .25*(maxy-miny)
234. win = Win(minx, maxx,miny, maxy, width(), height())
235.
236. f = Frame()
237. f.pack(side='top',expand=1)
238. quit=Button(f,text = 'Quit',command =sys.exit).grid(row = 0,
column = 0, sticky =W)
239.
240. t = "Increments " + `p.increments()`
241. lbl = Label(f, text=" ").grid(row=0, col=2, sticky=W)
242. lbl = Label(f, text=t).grid(row=0, col=3, sticky=W)
243. o = Opengl(width = width(), height = height(), double = 1)
244. o.redraw = redraw
245. o.pack(side = 'top', expand = 1, fill = 'both')
246. o.focus_set()
247. o.mainloop()
248.
249. if __name__ == '__main__':
250. main("../c09/chap9.t16")

Line 2 Import the Numeric (NumPy) extension.


Lines 3-5 Import the OpenGL, OpenGL toolkit (Tkinter), and the OpenGL GLUT modules.
Lines 10-26 Create a class for storing the displacement data.
Lines 28-47 Create a class for storing information about the window.
Lines 49-53 The width and height function to return the desired size. Change the values here to change the size
of the window.
Lines 55-60 The mode_3d routine sets the OpenGL parameters for a 3-D window.
Lines 62-64 The BMfonts list contains the available fonts for displaying in the 3-D window.
Lines 66-77 The drawdot routine draws a 3x3 block of pixels. This is used to identify the nodes we wish to see
labelled.
Lines 79-83 The draw_string routine draws a string of characters at the specified position in the 3-D window
Lines 85-100 The draw_element routine draws both the deformed and the undeformed elements.
Lines 102-114 The plot_nodes routine draws the "dot" to represent the node location and will label the node for
both the deformed and undeformed elements.
100 Marc Python Tutorial

Lines 116-133 The draw_legend routine draws a legend in the lower left corner reflecting the color of the lines
used for the deformed and undeformed shape.
Lines 135-147 The redraw routine is called by the Tkinter toolkit (which is registered at line 247) to redraw the
window. It calls the mode_3d routine to setup the 3-D window, and then draws the elements, plots
the nodes, and draws the legend. If the window is resized or receives an expose event, the toolkit
will call this routine.
Lines 149-153 The find_node routine finds the index of a node id in the nod array.
Lines 155-160 The find_maxmin routine finds the maximum and minimum x and y values in the model. This is
used to determine the values to specify when creating the 3-D window.
Lines 163-167 Declare some global variables.
Lines 176-182 Determine the index of the X and Y displacements in the post file.
Lines 188-197 Create an array of Displ objects to store the displacement data. Loop over all of the nodes and
create an object.
Lines 206-209 Create the arrays to store the actual x and y coordinates to plot.
Line 215 Loop through all the elements.
Lines 217-226 For each node in the element, get the index of the node in the nod array and store the data in the
undeformed x and y arrays (nodex and nodey), and also in the deformed x and y arrays (nodedx
and nodedy). The find_maxmin routine is called to find the maximum and minimum values so that
the window may be scaled appropriately.
Lines 229-234 Find the minimum and maximum values for the data so that the window can be created with the
proper limits.
Lines 236-237 Create the window frame using the Tkinter toolkit.
Lines 238-242 Create a quit button and a label that specifies the number of increments.
Lines 243-247 Create the OpenGL object and specify the width, height and whether double buffering is needed.
Specify the redraw routine (line 244) and get the window focus. Then start the main loop event
processing (line 247).
CHAPTER 12 101
PyPost: Plotting

Figure 12-3 The Resulting Plot from chap12c.py


Chapter 13: PyMentat: Menu System Lookup Functions

PyMentat: Menu System Lookup


13 Functions

Chapter Overview 103
 Menu System Lookup Functions 103

Integer Function 104

Double Function 104
 String Function 104

Boolean Function 105

State Function 106
CHAPTER 13 103
PyMentat: Menu System Lookup Functions

Chapter Overview
In this chapter the basics of obtaining database values using the menu system lookup functions will be demonstrated.
Upon completion of this chapter, you should have a clearer understanding of the following areas:
• The fundamentals of the menu system lookup functions.
• How to use the lookup functions in a Python script to obtain database values.

Menu System Lookup Functions


This chapter describes how to obtain database value by accessing them using the menuing system lookup functions
supported by Mentat. Each function has two arguments: the first argument is the name of the database (menu) item,
the second argument is the index of the item (base 0). The index value is non-zero where lists of items are used, such
as obtaining values of post time on a post file for each increment or a list of contact body names, otherwise the index
will be zero.
The lookup functions supported are:

Integer py_ms_int
Double py_ms_double
String py_ms_string
Boolean py_ms_bool
State py_ms_state

The list of possible database item names are quite long and are not listed here - the name of the item should be obtained
via the menu file. To obtain the name of a database item, run Mentat, and when viewing the required item on a menu
screen, place the cursor over the desired menu item and press the F2 function key to view/edit the menu file. On a Unix
system, the cursor goes directly to the menu item; however, on Microsoft Windows, you need to do a search to get to
the proper location. For example, open a model file or a post file and go to the UTILS->SIZES menu. Place the cursor
over the COUNT item in the ELEMENTS row and press the F2 button. On a Unix system, the cursor is brought to the
proper location which displays an integer database item displaying db_count_elements. For this case, the
function call uses the py_ms_int function to retrieve the value:
nelems = py_ms_int(‘db_count_elements’,0)
For Microsoft Windows users that are using the default editor, you need to do a search of “COUNT” (that is, search
for part of the table’s title) to get to the proper menu text. If you have a ‘vi’ editor for Microsoft Windows, you can use
that instead by modifying the bin\edit_window.bat script.
The names of some items may require spaces to be used in the text; however, this is not allowed in the Python text
strings. Substitute a ‘&’ or a ‘@’ symbol for any embedded spaces.
104 Marc Python Tutorial

Integer Function
The database values for integer items may be obtained using the py_ms_int function. The first argument is the name
of the database item, the second argument is the index of the item. Any item in a menu file that is represented as an
integer may be obtained, such as:
integer {
position +10 =
size 10 4
display ‘db_count_nodes’
}
The Python code for this example would be:
nnodes = py_ms_int(‘db_count_nodes’,0)
The index value is nonzero where lists of items are used, such as the values on a post file for each increment. An
example would be post_size: The following obtains the post file size data for the 6th increment on the post file:
n = py_ms_int(‘post_size’,5)

Double Function
The database values for floating point (float or double) items may be obtained using the py_ms_double function.
The database may store items either as a double or a float; hence, for float items, the value is cast as a double and
returned. The first argument is the name of the database item, the second argument is the index of the item. Any item
in a menu file that is represented as a float may be obtained, for example:
float {
position +26 =
size 12 4
display lcase_time_step
}
The Python code for this example would be:
tstep = py_ms_double(‘lcase_time_step’,0)
An example of a menu item that uses a non-zero index would be post_time: The following obtains the post file time
value for the 6th increment on the post file:
n = py_ms_double(‘post_time’,5)

String Function
The database values for string or text items may be obtained using the py_ms_string function. The first argument
is the name of the database item, the second argument is the index of the item. Any item in a menu file that is
represented as a text item (character string) may be obtained, for example:
text {
position +1 +4
CHAPTER 13 105
PyMentat: Menu System Lookup Functions

size 30 4
display post_file
command ‘*post_open’
}
The Python code for this example would be:
tstep = py_ms_string(‘post_file’,0)
In some cases a text value of an integer or floating point value are displayed. In these cases the string will appear as
display d_gmodel_data_defmag
display i_geomdist_grid_div
The first character denotes the data type, such as i for integer or d for double (float).
The index value is non-zero where lists of items are used, such as the values on a post file for each increment. An
example would be post_time: The following obtains the name of the second contact body in a model file:
str = py_ms_string(‘cbody_list_name’, 1)

Boolean Function
The database values for boolean items may be obtained using the py_ms_bool function. The first argument is the
name of the database item, the second argument is the index of the item. Any item in a menu file that is represented as
a toggle or a oneonly may be obtained, for example:
toggle {
position +15 =
size 8 4
text ‘GRID’
true_command ‘*set_grid on’
false_command ‘*set_grid off’
toggle set_grid
}
oneonly {
position 1 +4
size 10 4
text ‘FOLLOWER FORCE’
commands ‘*job_option follow:on’
oneonly ‘*job_option follow:on’
}
The Python code for the examples shown above would be:
bGrid = py_ms_bool(‘set_grid’,0)
bFollow = py_ms_bool(‘*job_option&follow:on’,0)
The grid example returns 1 if the grid is on; false if it is off. The job_option example returns true if the follower
force option is on; false if not. If an option has multiple states, then the State function is used. The job_option of
follower force actually has four states, so the state function should be used to get the active state.
106 Marc Python Tutorial

State Function
The database values for state items may be obtained using the py_ms_state function. State items are similar to
boolean items, except that in most cases they have multiple conditions, but not in all cases (such as
acis_file_check). The first argument is the name of the database item, the second argument is the index of the
item.
There are much fewer state items than integer, double, string or booleans, and the return values may not be clear, hence
they are listed in the following table. A state item is generally represented in a menu file that is defined as a roller item,
however it may also appear as a oneonly. Note that in some cases the name will include the preceding asterisk, simliar
to that of the actual command. A menu example for a roller button is as follows:
roller {
position 1 1
size 36 4
nvalues 4
texts ‘NO FOLLOWER FORCE’
‘FOLLOWER FORCE’
‘FOLLOWER FORCE/STIFFNESS’
‘FOLLOWER FORCE/(BEGIN INC)’
commands ‘*job_option follow:off’
‘*job_option follow:on’
‘*job_option follow:stiffness’
‘*job_option follow:begin_inc’
roller ‘job_option follow’
}

The Python code for this example would be:


bType = py_ms_state(‘job_option&follow’,0)
The state values will generally (but not always) begin at 0 for the first item listed and increment by one for each item
in the texts list. Note that functions that end with option or param have a space after the name and are followed by
the name of the option. The possible arguments for the option or param types are numerous - when the item you require
is found in a menu file, view the file to obtain the required argument. For an example, consider job_option. The best
way to verify the correct state value is to use py_send to send the command and then obtain the state value:
py_send(‘*job_option style:single’)
bOpt = py_ms_state(‘job_option&style’,0)
print ‘ job style single has state ’, bOpt

Table 13-1 State Functions


Function Description
acis_file_type *set_acis_formatted command state: returns 0 if Acis file type is
formatted, 1 if binary.
acis_file_check *set_acis_entity_check command state: returns 0 if entity check
is off, 1 if on.
adapg_option
CHAPTER 13 107
PyMentat: Menu System Lookup Functions

Table 13-1 State Functions


Function Description
adapg_param
apply_option
bsect_grid_type Returns 0 for rectangular, 1 for cylindrical
bsect_option
carea_option
cavity_option
connect_option
coord_system Coordinate system type: 0 for rectalngular, 1 for cylindrical, 2 for
sphereical.
crdsyst_option
crdsyst_type Coordinate system type: 0 for rectalngular, 1 for cylindrical, 2 for
sphereical.

ctable_bodies_option
ctable_entry
curve_div_applyrest_state *set_curve_div_applyrest_<cvs|lps> command state:
0 = individual cuirves (cvs), 1 = detected loops (lps).
curve_div_tol_state State of *set_curve_div_tol_(rel, abs) commands:
0 = relative, 1 = absolute.
geometry_option
job_option
job_post_eq_layers Post layers: 0 for default, 1 for All, 2 for out&mid, 3 for list.
match_mesh_dir *set_match_mesh_dir state: 0 = from side a to b, 1 = from side b to a.
mesh_parameter_ SuperForm mesh parameter settings.
mesh_split_method_1d Match split method 1D: 0=element base, 1 = plane
mesh_split_method_2d Match split method 2D: 0=element base, 1 = plane, 3 = smooth
mesh_split_method_3d Match split method 3D: 0=element base, 1 = plane
numerics_format Numerics format: 0 for automatic, 1 for exponential, 2 for floating, 3 for
integer
save_file_type Formatted file type returns 0, binary type returns 1
select_filter 0 = none, 1 = outline, 2 = surface, 3 = top, 4 = bottom
select_method 0 = single, 1 = path, 2 = box, 3 = user_box, 4 = plane, 5 = flood,
6 = associate, 7 = point_dist, 8 = curve_dist, 9 =s urface_dist
108 Marc Python Tutorial

Table 13-1 State Functions


Function Description
select_mode 0 = and, 1 = except, 2 = invert, 3 = intersect
servo_match_rtype 0 = side a, 1 = side b, 2 = external, 3 = create new
servo_match_ttype 0 = side a, 1 = side b
set_curve_type Curve type: 0 = line, 1 = circle_cr, 2 = bezier, 3 = nurb, 4 = arc_craa,
5 = polyline, 6 = cubic_spline, 7 = circle_cp, 8 = arc_cpp, 9 = arc_cpa,
10 = arc_ppp, 11 = arc_tra, 12 = composite, 13 = interpolate, 14 = tangent,
15 = fillet, 16 = sampled, 17 = circle_ppp
set_element_class Element class: 0 = line2, 1 = line3, 2 = tria3, 3 = tria6, 4 = quad4, 5 = quad6,
6 = quad8, 7 = quad9, 8 = hex8, 9 = hex12, 10 = hex20, 11 = hex27,
12 = tetra4, 13 = tetra10, 14 = penta6, 15 =p enta16
set_solid_type Solid type: 0 = block, 1 = cylinder, 2 = prism, 3 = sphere, 4 = torus
set_surface_type Surface type: 0 = quad, 1 = sphere, 2 = bezier, 3 = nurb, 4 = ruled,
5 = driven, 6 = cylinder, 7 = swept, 8 = interpolate, 9 = coons, 10 = skin,
11 = sampled
set_insert_embedded_type 0 for elements, 1 for nodes.
set_insert_host_type 0 for elements, 1 for contact bodies‘
set_insert_create Flag for insert generation during rebar remeshing: 0 is off, 1 is on.
set_view_repeat Flag for *set_view_repeat command: 0 is off, 1 is on.
set_xy_draw_type_histplot 0 = curve, 1 = bar, 2 = scatter
set_xy_draw_type_pathplot 0 = curve, 1 = bar, 2 = scatter
set_xy_draw_type_table 0 = curve, 1 = bar, 2 =s catter
set_xy_draw_type_xcurve 0 = curve, 2 = scatter
set_xy_draw_type_xy_plot 0 = curve, 1 = bar, 2 =s catter
set_import_space State of DXF file import for model/paper space: 0 is model, 1 is paper, 2 is
both.
srfprop_option
strline_option
table_indep_vars State of current table’s number of independent variables. Returns : 0 is 1
indep var, 1 is 2 indep var, 2 is3 indep var, 3 is4 indep var,
table_xvar State of current table x axis variables (V1-V4): Returns: 0 is V1, 1 is V2, 2
is V3, 3 is V4.
table_yvar State of current table y axis variables (V1-V4): Returns: 0 is V1, 1 is V2, 2
is V3, 3 is V4.
tform_option
weldpath_option
CHAPTER 13 109
PyMentat: Menu System Lookup Functions

Table 13-1 State Functions


Function Description
xcv_discontinuous State of *xcv_discontinuous command: 0 is off; 1 is on.
xcv_err_abs State of *xcv_err_abs command: 0 is off; 1 is on.
xcv_hyp_tc State of *xcv_hyp_tc command: 0 is tensile; 1 is compressive.
Chapter 14: MentatDCOM: Connecting to Mentat using a .NET Module

MentatDCOM: Connecting to
14 Mentat using a .NET Module

Chapter Overview 111
 MentatDCOM Basics 111

Running the Program 114

MentatDCOM and PyMentat 115
CHAPTER 14 111
MentatDCOM: Connecting to Mentat using a .NET Module

Chapter Overview
In this chapter it will be demonstrated the basics of using the MentatDCOM module to connect to Mentat using
programs created with Microsoft Visual Studio 2005 or later. An example will be shown which uses code similar to
that of the example discussed in Chapter 2.
Upon completion of this chapter, you should have a clearer understanding of the following areas:
• The basics of using MentatDCOM
• How to use MentatDCOM to send data to Mentat

MentatDCOM Basics
In Chapter 2, it was shown how to use PyMentat to connect to Mentat and build a simple model. The MentatDCOM
module is a .NET assembly module built with Microsoft Visual Studio 2005 to provide an API simliar to that of
PyMentat to send and receive data from Mentat. As a .NET assembly module, it allows any .NET module to access the
members functions, using languages such as VB.NET, C#, J#, etc. It connects to Mentat using a DCOM interface which
must be registered in the Microsoft Windows registry before it can be used. This is done by running the *dcom_reg
command in Mentat. This command has to be run only once. The interface remains registered if Mentat is closed.
The DCOM interface is initiated in a Mentat session using the *dcom_init command. The MentatDCOM module
contains a class named MentatData which must be instantiated by the client. This MentatData object contains the
methods that are used to send commands and retrieve various data items. The first method that must be called is used
to start the connection, connect and returns either 0 for a successfull connection or non-zero if there was an error.
Note that the MentatDCOM module (DLL) must be in the same directory as your executable, otherwise it will not be
found.
When using the MentatDCOM module, you will import the module in a similar way as importing the PyMentat
module, using the appropriate language syntax:
C++/CLI
using namespace MentatDCOM;
C#
using MentatDCOM;
VB.Net
Imports MentatDCOM
In the main program, the MentatData object is created which provides acces to the member functions:
C++/CLI
MentatData p = gcnew MentatData();
C#
MentatData p = new MentatData();
112 Marc Python Tutorial

VB.Net
Dim p as New MentatData()
The program example discussed in this chapter will be a C# program performing the same functions as shown in
Chapter 2.
1. using System;
2. using MentatDCOM;
3. namespace MentatTest
4. {
5. class Chap14
6. {
7. static MentatData p;
8. static void make_nodes(int s, int t, double xs, double ys)
9. {
10. int i, j;
11. double x, y, z, delx, dely;
12. y = ys;
13. z = 0.0;
14. delx = 1.0/(double)s;
15. dely = 1.0/(double)t;
16. string str;
17. for(i = 0; i < t; i++)
18. {
19. x = xs;
20. for(j = 0; j < s; j++)
21. {
22. str = "*add_nodes " + x.ToString()
23. + " " + y.ToString() + " " + z.ToString();
24.
25. p.send(str);
26. x = x + delx;
27. }
28. y = y + dely;
29. }
30. return;
CHAPTER 14 113
MentatDCOM: Connecting to Mentat using a .NET Module

31. }
32.
33. static void make_elements(int n, int m)
34. {
35. int i, j, n1, n2, n3, n4;
36. string str;
37. for(i = 1; i < m; i++) // the "y" dir
38. {
39. n1 = (i-1) * (n) + 1;
40. n2 = n1 + 1;
41. n4 = n1 + (n);
42. n3 = n2 + (n);
43. for(j = 1; j < n; j++ ) // the "x" dir
44. {
45. str = "*add_elements "+n1.ToString()+" " +
46. n2.ToString() + " " + n3.ToString() + " " + n4.ToString();
47. p.send(str);
48. n1++;
49. n2++;
50. n3++;
51. n4++;
52. }
53. }
54. return;
55. }
56.
57. static void Main(string[] args)
58. {
59. string host = "local";
60. if (args.Length > 0){
61. host = args[0];
62. }
63. Console.WriteLine("chap14 {0}", host);
64. p = new MentatData();
114 Marc Python Tutorial

65. if (p.connect(host) > 0)


66. {
67. Console.WriteLine("Failed to connect to {0}", host);
68. return;
69. }
70. int n = 6;
71. int m = 8;
72. double xs = -1.0;
73. double ys = -1.0;
74. make_nodes(n, m, xs, ys);
75. make_elements(n, m);
76. p.disconnect();
77. return;
78. } // end Main
79. } // end class
80. }

Lines 1-2 Import the modules to be used. The System module is required for using the WriteLine method, the
MentatDCOM module provides access to the MentatData class.
Lines 7 Declare the MentatData object member.he argument list passed to the main function is checked for
the post file name.
Lines 8-55 This code is similar to the Python code of Chapter 2.
Lines 60-62 The argument list passed to the main function is checked for the host name.
Line 64 The MentatData Object class is initialized. It creates the MentatData object and is stored in the
variable p. All subsequent MentatDCOM methods called will be members of this object.
Lines 65-69 The connect method is called with the hostname of the computer.
Lines 70-75 This code is similar to the Python code of Chapter 2.
Line 76 The disconnect method is called to close the connection.

Running the Program


This script is intended to be run outside of Mentat. In a Microsoft Windows command prompt window, change your
directory to the Mentat directory examples/python/tutorial/c14. Compile and run the C# program chap14.cs as:
csc /r:MentatDCOM.dll chap14.cs /out:chap14_cs.exe
CHAPTER 14 115
MentatDCOM: Connecting to Mentat using a .NET Module

The buildit.bat script will compile the program for you. Start Mentat (from either the shortcut on the desktop or
another command prompt window) and enter the command:
*dcom_init
Run the DCOM program as:
chap14_cs
When the script completes, a mesh will be created as shown in Figure 14-1.

Figure 14-1 Resulting Mentat from chap14.cs

MentatDCOM and PyMentat


The MentatDCOM module methods are very similar to those in PyMentat; howeve,r thre are some minor changes.

connect(String ^host) This method is called py_connect in PyMentat. It initializes the connection to
Mentat. Note that the port number has been removed. It returns zero on success,
non-zero on failure. The host string is currently ignored.
int ret = p.connect(‘localhost’); // C# syntax
int ret = p->connect(‘localhost’); // C++ syntax
ret = p.connect(‘localhost’); ‘ VB syntax
116 Marc Python Tutorial

disconnect() This method is called py_disconnect in PyMentat and closes the DCOM
connection.
p.disconnect();
send() This method is called py_send in PyMentat and sends a command string:
p.send(‘*set_grid on’);
get_string() This method is called py_get_string in PyMentat and returns a string:
String ^nm = p.get_string(‘model_name()’);
Console::WriteLine(‘{0}’, nm);
get_double() This method is called py_get_float in PyMentat. It returns a type of double.
string s = ‘element_mass(-1)’;
double f = p.get_double(s);
Console::WriteLine(‘Mass {0}’, f);
get_int() This method is called py_get_int in PyMentat. It returns a type of integer.
string s = ‘nnodes()’;
int n = p.get_int(s);
Console::WriteLine(‘Node count {0}’, n);
update() This method is called py_update in PyMentat. It forces a graphics update to
allow the image_save routines to function properly.
p.send(‘*image_save_rgb 1 test.rgb yes’);
p.update();
Note that graphics updates will not function properly when running the OpenGL
version of Mentat. The OopenGL graphics engine reports a ‘ERROR_BUSY’
error for the OpenGL calls when a separate process accesses Mentat via DCOM.

Note: The Mentat DCOM module (MentatDCOM.dll) must be in the same directory as your executable,
otherwise it will not be found.
Chapter 15: MarcPost: Reading a Post File using a .NET Module

MarcPost: Reading a Post File


15 using a .NET Module

Chapter Overview 118
 MarcPost Basics 118

Running the Program 121

MarcPost and PyPost 122
118 Marc Python Tutorial

Chapter Overview
In this chapter, it will be demonstrated the basics of using the MarcPost module to read a Marc post file using programs
created with Microsoft Visual Studio 2005 or later. This example will use the post file of the example used in Chapter
6: PyMentat: Processing a Post File.

Upon completion of this chapter, you should have a clearer understanding of the following areas:
• The basics of using MarcPost
• How to use MarcPost to read nodal data

MarcPost Basics
In Chapter 8: PyPost: Reading a Post File, it was shown how to use PyPost to post process a Marc post file. The
MarcPost module is a .NET assembly module built with Microsoft Visual Studio 2005 to provide an API similar to that
of PyPost to obtain the results from a Marc post file. As a .NET assembly module, it allows any .NET module to access
the members functions, using languages such as VB.NET, C#, J#, etc. The MarcPost module contains a method that is
used to open a post file, open (or post_open) and return a PostData object. This PostData object contains the
methods that are used to access various data items in the post file. Note that the MarcPost module (MarcPost.dll)
must be in the same directory as your executable, otherwise it will not be found.
When using the MarcPost module, you will import the module in a similar way as importing the PyPost module, using
the appropriate language syntax:
C++/CLI
using namespace MarcPost;
C#
using MarcPost;
VB.Net
Imports MarcPost
In the main program the PostData object is created which provides acces to the member functions:
C++/CLI
PostData p = gcnew PostData();
C#
PostData p = new PostData();
VB.Net
Dim p as New PostData()
CHAPTER 15 119
MarcPost: Reading a Post File using a .NET Module

The program example discussed in this chapter will be a C# program performing the same functions as shown in
Chapter 8: PyPost: Reading a Post File.

1. using System;
2. using MarcPost;
3. namespace MarcTest
4. {
5. class Chap15
6. {
7. static void Main(string[] args)
8. {
9. if (args.Length < 1){
10. Console.WriteLine("CSPost requires filename");
11. return 1;
12. }
13. Console.WriteLine("CPost {0}", args[0]);
14. PostData p = new PostData();
15. if (p.open(args[0]) > 0)
16. {
17. Console.WriteLine("Failed to open {0}", args[0]);
18. return;
19. }
20. p.moveto(1);
21. int nns = p.node_scalars();
22. Console.WriteLine("Found {0} node scalars", nns);
23. double[] max_scalars = new double[nns];
24. int[] max_nodes = new int[nns];
25. int j, k, numnodes;
26. double d;
27. for(j=0;j<nns;j++) max_scalars[j] = -1.0e20;
28. for(j=0;j<nns;j++)
29. {
30. numnodes = p.nodes();
120 Marc Python Tutorial

31. for(k=0;k<numnodes;k++)
32. {
33. d = p.node_scalar(k,j);
34. if(d < 0.0) d = -d;
35. if(d > max_scalars[j])
36. {
37. max_scalars[j] = d;
38. max_nodes[j] = p.node_id(k);
39. }
40. }
41. }
42. Console.WriteLine(" Label node scalar");
43. Console.WriteLine(" ---------------------------------------------");
44. for(j=0;j<nns;j++)
45. {
46. Console.WriteLine(" {0,20} {1,10:d} {2,-24:g}",
p.node_scalar_label(j),
47. max_nodes[j], max_scalars[j]);
48. }
49. } // end Main
50. } // end class
51. }

Lines 1-2 Import the modules to be used. The System module is required for using the WriteLine method, the
MarcPost module provides access to the PostData class.
Lines 9-12 The argument list passed to the main function is checked for the post file name.
Line 14 The PostData class is initialized. It created the PostData object and is stored in the variable p. All
subsequent MarcPost methods called will be members of this object
Lines 15-19 The open method is called with the post file name chap5_job1.t16.
Line 20 Call the moveto method to go to the first increment. When the post file is opened, it is at increment 0
which contains only the model data. We need to explicitly go to the first increment even though there
is only one increment of data in the post file.
Lines 23-25 The max_scalars and max_nodes variables are declared as arrays. The index of the list will be
each of the scalars in the post file. The maximum scalar value will be stored in the max_scalars
list. The node associated with the max_scalar value will be stored in the max_nodes list.
Line 27 The max_scalars array is initialized.
CHAPTER 15 121
MarcPost: Reading a Post File using a .NET Module

Line 28 This begins the main loop for the scalars.


Line 22 Obtain the number of nodes. If we were processing multiple increments, we would have to call the
nodes method every increment, since rezoning will change the number of nodes.
Line 28 Loop through all the nodes.
Line 33 Get the scalar value for this scalar (k) and node (j).
Lines 25-26 Ignore the sign of the values and only work with magnitudes.
Lines 35-39 Check the current value against the current maximum value. Convert the node sequence number to
the node id using the node_id method.
Lines 44-48 Print out the results for each scalar.

Running the Program


This script is intended to be run outside of Mentat. In a Microsoft Windows command prompt window, change your
directory to the Mentat directory examples/python/tutorial/c15. Compile and run the C# program chap15.cs as:
csc /r:..\..\..\..\shlib\win64\MarcPost.dll chap15.cs \
/out:chap15_cs.exe
on 64-bit Windows.
The buildit.bat script will compile the program for you. Run the program as:
chap15_cs ..\c06\chap5_job1.16
When the program completes, the output will printed as shown in Figure 15-1.

Found 6
node scalars
Label node scalar
-------------------------------------------
Displacement X 53 0.00128282303921878
Displacement Y 49 0.00565143441781402
External Force X 1 0
External Force Y 50 187.5
Reaction Force X 82 2866.59521484375
Reaction Force Y 81 921.813659667969

Figure 15-1 Resulting Output from chap15.cs


122 Marc Python Tutorial

MarcPost and PyPost


The MarcPost module is very similar to the PyPost module, but there are some differences.
The MarcPost object contains the following attributes:

General Description
cutback The total number of cutbacks
cycles The number of recycles for this increment
increment The current increment
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
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
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
CHAPTER 15 123
MarcPost: Reading a Post File using a .NET Module

frictionwork The total work due to friction


springwork The total work done by springs
work The total work

The MarcPost module uses the following special types:


Node Nodal Data
id The node ID
x, y, z The x, y, z coordinates of the node
Element Element Data
type The element type
id The element ID
nnode The number of nodes of the element
nodes The list of nodes for the element

The MarcPost module offers the following methods.

int post_open(String ^filename) Opens the specified post file and returns 0 on success and 1 otherwise.
int close() Closes a currently open post file. Returns 0.
String ^title() Returns the title of the post file.
int increments() Returns the number of increments on the post file.
int domains() Returns the number of domains.
void moveto(int i) Moves to the i-th increment on the post file.
position() Returns the current increment on the post file, that is, the increment moved to
by the moveto method. In PyPost, position is an attribute; however, in
MarcPost position is a member function. This change is necessary since it
could be changed by the user; however, the position in the file will not be
updated (use the moveto method instead). Example use:
int pos = p.position();
int nodes() Returns the number of nodes in the model for the current increment. The
number of nodes may change for each increment due to remeshing.
int node_id(int i) Returns the id of the i-th node.
int node_sequence(int id) Returns the index number of a particular node id or -1 if the id does not exist.
Node ^node(int i) Returns the nodal data for the i-th node.
int node_displacements() Returns 1 if displacements are available on the post file and 0 otherwise.
int node_displacement(int i, Returns the x-, y- and z-displacements of the i-th node. The return value if the
double *x, double *y, double* z) method is 0 on success and 1 on failure.
int node_scalars() Returns the number of nodal scalar quantities available.
124 Marc Python Tutorial

double node_scalar(int i, int j) Returns the value of the j-th nodal scalar quantity at the i-th node.
String^ node_scalar_label(int i) Returns the name of the i-th nodal scalar quantity.
int node_vectors() Returns the number of nodal vectors available.
String^ node_vector_label(int i) Returns the name of the i-th nodal vector.
int node_vector(int i, int j, Returns the x-, y-, and z-components of the j-th nodal vector at the i-th node.
double *x, double *y, double *z) The return value of the method is 0.
int elements() Returns the number of elements in the model for the current increment. The
number of elements may change for each increment due to remeshing.
int element_id(int i) Returns the id of the i-th element.
element_sequence(int id) Returns the index number of a particular element id or -1 if the id does not
exist.
Element^ element(int i) Returns the element data for the i-th element.
int element_scalars() Returns the number of element scalars available.
String^ element_scalar_label(int i) Returns the name of the i-th element scalar.
int element_vectors() Returns the number of element vectors available.
String^ elelment_vector_label(int i) Returns the name of the i-th element vector.
int element_tensors() Returns the number of element tensor available.
String^ element_tensor_label(int i) Returns the name of the i-th element vector.
int extrapolation(String^ type) Sets the integration point extrapolation method for element data. The
argument is a string specifying the extrapolation method to use:

• “linear”- Integration point values are interpolated linearly from the


element integration points to the nodes of the element.
• “translate” - Integration point values are copied to the corresponding nodes
of the element.
• “average” - The average of all integration point values are assigned to the
nodes of the element.
Returns 0 on success and 1 otherwise.
int global_values() Returns the number of global quantities available.
String^ global_value_label(int i) Returns the name of the i-th global quantity.
double global_value(int i) Returns the value of the i-th global quantity.
int cbodies() Returns the number of contact bodies.
int cbody_id(int i) Returns the id of the i-th contact body.
String^ cbody_name(int i) Returns the name of the i-th contact body.
double cbody_angle(int i) Returns the angle for the i-th contact body.
double cbody_volume(int i) Returns the volume of the i-th contact body.
CHAPTER 15 125
MarcPost: Reading a Post File using a .NET Module

double cbody_rotation(int i) Returns the rotation for the i-th contact body.
int cbody_displacement(int i, Returns the x-, y-, and z-displacements of the i-th contact body. The return
double* x, double *y, double *z) value of the method is 0 if the body exists and 1 otherwise.
int cbody_force(int i, double* x, Returns the forces in x-, y-, and z-directions for the i-th contact body. The
double *y, double *z) return value of the method is 0 if the body exists and 1 otherwise.
int cbody_moment(int i, Returns the moments about the x-, y-, and z-axes for the i-th contact body. The
double *x, double *y, double *z) return value of the method is 0 if the body exists and 1 otherwise.
int cbody_velocity(int i, Returns the velocities in x-, y-, and z-directions of the i-th contact body. The
double *x, double *y, double *z) return value of the method is 0 if the body exists and 1 otherwise.
int sets() Returns the number of sets on the post file.
String ^version() This method returns the MarcPost module version information:
String ^ver = p.version();
Console::WriteLine(‘{0}’,ver);
Example output Assembly name MarcPost, Version=1.0.0.0,
Culture=neutral, PublicKeyToken=null
Marc Python Reference

Marc Python Reference


Introduction

Introduction

Using the Python Modules 3

Variable Types 3
3 Marc Python Reference

Using the Python Modules


This document describes the routines available to Python scripts that use PyMentat or PyPost interface modules.
PyMentat is the interface module for Python scripts to communicate to Mentat and 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 PyMentat module must import the module as:
from py_mentat import *
Similarly, all Python scripts that need access to the PyPost module must import the module as:
from py_post import *
These modules are shared libraries, and hence the exact names of the PyMentat and PyPost modules are platform
dependent. The PyMentat module on most Unix machines is named py_mentat.so, and it is named
py_mentat.pyd on Microsoft Windows, and the PyPost module on most Unix machines is named py_post.so,
and it is named py_post.pyd on Microsoft Windows.
These modules are located in the Marc Mentat bin directory, and the Python interpreter finds these modules via the
environment variable PYTHONPATH. This environment variable is set in the run_python (run_python.bat on
Microsoft Windows) script located in the Marc Mentat bin directory. You should use this script when running a
Python script, however as long as you set PYTHONPATH to the correct location, you may simply run the Python
interpreter (python) directly. It is also located in the Marc Mentat bin directory.
The definition of each routine is listed in alphabetical order.
See the Marc Python Tutorial, Chapter 2: PyMentat: A Simple Example for examples on the use of these modules.

Variable Types
The type definitions for functions and methods used in this manual are as follows:

String A character string. This type is similar to the C type of char, and the FORTRAN type of character*(*)”. A
string may be specified by using either single quotes or double quotes.
Float A floating point value. This is similar to the C type of double and the FORTRAN type of real*8.
Integer An integer (or fixed point) value. This is similar to the C type of long int and the FORTRAN type of
integer*8.
List A Python List object. A Python list is essentially a linked list that can be accessed as an array.
Chapter 1: PyMentat References

1 PyMentat References

PyMentat 5

py_connect 6
 py_disconnect 7

py_echo 8

py_get_data 9
 py_get_float 10

py_get_int 11

py_get_string 12
 py_prompt 13

py_send 14
5 Marc Python Reference

PyMentat
This chapter describes the PyMentat routines.
PyMentat is the interface module for Python scripts to communicate to Mentat. Mentat must be running prior to
invoking any PyMentat routine.
A Python script using PyMentat can be run either in “embedded” mode or as a separate process. If invoked as a separate
process, the py_port/py_connect routines must be the first PyMentat routines called.
All Python scripts that need access to the PyMentat module must import the module as:
from py_mentat import *
CHAPTER 1 6
PyMentat References

py_connect Establishes a socket connection with Mentat

Synopsis
py_connect(String hostname, Integer nPort)

Arguments
hostname Hostname of system to make connection with
nPort Port number

Description
This routine attempts to establish a socket connect with Mentat on the host specified by hostname, using port number
nPort. The hostname can be an IP address or a DNS name. If hostname is an empty string (“”), then the local host is
used.
A Python script executed as a separate process would use this routine to enable it to communicate with Mentat. It must
be the first PyMentat function called. In addition, Mentat should be waiting for a connection (the Mentat command
*py_connect should have been issued).

Example
if __name__ == ”__main__”:
py_connect(”127.0.0.1”, 40007)
main()
7 Marc Python Reference

py_disconnect Terminates a socket connection with Mentat

Synopsis
py_disconnect()

Arguments
None

Description
This routine terminates a socket connect with Mentat after a successful connection with the py_connect routine.

Example
if __name__ == ”__main__”:
py_connect(”127.0.0.1”, 40007)
...
py_disconnect()
main()
CHAPTER 1 8
PyMentat References

py_echo Enables/disables commands to be printed in Mentat’s dialogue area using py_send

Synopsis
py_echo(int flag)

Arguments
flag An integer used to enable/disable echo.

Description
This routine affects command echoing in Mentat’s dialogue area. If flag is set to true (a nonzero value), then the
commands are echoed. If flag is set to false (zero), then commands sent to Mentat are not echoed. This routine is most
helpful in debugging Python scripts. The default setting is on. Note that enabling echo slightly affects performance.
Mentat command echoing for Python scripts may also be enabled in Mentat using the button:
UTILS->PYTHON->SCRIPT ECHO

Example
py_echo(0)# disables echo
py_echo(1) # enables echo
9 Marc Python Reference

py_get_data Returns a floating point value from the database from the current data class

Synopsis
Float py_get_data(String name)

Arguments
name A string representing the database value to be returned.

Description
This routine parses the string specified in name and returns a floating point result. It has the form:
Dataclass:param_name
where Dataclass is one of:
adapg, adaptg, apply, contact_body, contact_table, geometry, icond, job,
loadcase, material
The Dataclass used is the currently selected item. The naming convention for param_name is consistent with that used
in the menu files for displaying floating point values.

Examples
a = py_get_data(‘material:isotropic:young_modulue’)
b = py_get_data(‘job:singularity_thresh’)
c = py_get_data(‘geometry:cont_radius’)
d = py_get_data(‘icond:base_vec1_x’)
e = py_get_data(‘apply:apply_dof_value_x’)
f = py_get_data(‘contact_body:friction’)
f = py_get_data(‘contact_table:ctable1:ctable2:friction’)
CHAPTER 1 10
PyMentat References

py_get_float Evaluates an expression and returns a floating point value

Synopsis
Float py_get_float(String name)

Arguments
name A string representing the expression to be evaluated.

Description
This routine evaluates the expression specified in name and returns a floating point result. Any Arithmetic or Database
function combination may be used in the expression.

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
s = py_get_float(‘point_u1(npoints())’)
str = ‘curve_length(0)/curve_ndiv(0)’
d = py_get_float(str)
f = py_get_float(‘node_x(0)*d’) # is invalid
str = ‘node_x(0)*%g’ % d
f = py_get_float(str) # is correct

You might also like