Python Manual Pages 3
Python Manual Pages 3
PyPost: Plotting
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.
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
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
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.
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’
}
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
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
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.
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.
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
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
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
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
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:
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
Introduction
Using the Python Modules 3
Variable Types 3
3 Marc Python Reference
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
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
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
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
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