Вы находитесь на странице: 1из 29

WS-2: Develop a custom post processing

extension

1 © 2011 ANSYS, Inc. December 3, 2012


Objective
• Getting velocity vector plot in 3D Modal Analysis on a selected face of the body

Need to multiply deformation in X, Y


and Z direction by 2*Pi*Frequency

In Mechanical, one can get


Displacement vector plot but not the
velocity vector plot

• Create an ACT extension to get the velocity vector plot

2 © 2011 ANSYS, Inc. December 3, 2012


The command snippet way!

User
Inputs

• Insert a command snippet


• Define the user inputs in the top
• Remaining code is to display vector plot as a image in Mechanical
Element/Node selection possible only via NamedSelection
Can not visualize the entity graphically like other Mechanical result objects, where we can zoom, pan, rotate, etc.
Potential for user errors
E.g. if spelling of component “face” is not correct, then post processing will fail
Output result is based on solver units
! Inputs are hardcoded
Reading of result set
Selection of component
3 © 2011 ANSYS, Inc. December 3, 2012
The ACT way!

Benefits of ACT:
• Get a plot which can be view as 3D like other graphical
results. User can zoom, pan, and rotate etc.
• User can select the geometry and set the mode number
interactively, can also scope to geometry/named selection
• Min and Max results are available for parameterization
• Results are available in the selected unit system

4 © 2011 ANSYS, Inc. December 3, 2012


Two ways to get the results via ACT:
1. Using APDL commands
Similar to the custom ACT load example (covered in Session 3)
– Collect the input (mode number, selected face nodes)
– Generate APDL commands and start a MAPDL session with the RST file
• Get the velocities on nodes and write them to a file
– Read this file and plot the velocity vectors
2. Using Native Python APIs
– Collect the input (mode number, selected face nodes)
– Get the displacements and compute velocities on nodes using native Python APIs
– Plot the velocity vectors
The 2nd option is more efficient as we get the results directly
Both the methods will have
• Same xml file
• But the Python function will be different
5 © 2011 ANSYS, Inc. December 3, 2012
Prerequisites
This workshop assumes that you
• Understand XML and Python
• Have reviewed Session-1, Session-2 and Session-3 of ACT training materials

Start with
• WB project file velocity_vector_plot_ACT.wbpz
– It has all the settings done (material, loads, analysis settings etc.)

6 © 2011 ANSYS, Inc. December 3, 2012


Planning the ‘velocity plot’ extension

XML
• Need a button in toolbar for the
‘velocity plot’
• Details of the result object:
– Scope to Geometry or Named
Selection
Python
• Create the result object under Solution
• Collect the user inputs
1st Method: Use APDL commands
• Convert the user inputs to APDL
commands
• Start MAPDL in background and
use the APDL commands to
generate a file with the velocity
components on nodes
• Read the above file and plot the
velocity vector plot
nd
2 Method: Use Native Python APIs
Comes by default for a • Get the velocity components on
nodes
result object • Plot the velocity vector plot
7 © 2011 ANSYS, Inc. December 3, 2012
8 © 2011 ANSYS, Inc. December 3, 2012
Developing the GUI

The <extension> element contains the version


and name attributes for this extension

The <script> element contains the src attribute.


Defines the path to the iron python script file.
<interface> is the parent element for custom UI
controls It contains the application’s context
attribute.
<simdata> is the parent node for encapsulating
the definition for the result object. It contains the
application’s context attribute.

9 © 2011 ANSYS, Inc. December 3, 2012


Developing the GUI (2)
<interface> is the parent element for custom UI
controls It contains the application’s context
attribute.

The <images> node value defines the location of


icon files used for UI customizations

The <toolbar> node defines a toolbar and its


properties

The <entry> node defines a toolbar button and


its properties

The <callbacks> node defines the callbacks


associated with the <entry>

10 © 2011 ANSYS, Inc. December 3, 2012


Developing the GUI (3)
<simdata> is the parent node for encapsulating
the definition for the result. It contains the
application’s context attribute.
<result> provide the name,
version, caption, icon, and
color that apply to this load

The result <callbacks> tag encapsulates callbacks (Python functions).


1. When the evaluation for the result starts (<onstarteval>)
2. When the result is plotted (<getvalue>)

The <details> tag encapsulates the properties that will be applied to the actual
definition of the result. These properties will be displayed in the "Details" pane
11 © 2011 ANSYS, Inc. December 3, 2012
Developing the GUI (4)

The <details> tag encapsulates the properties that


will be applied to the actual definition of the result.
These properties will be displayed in the "Details"
pane

Comes by default for a


The <property> element and its children provide the
result object means to define the properties that are required for
this result. Through this definition, these properties
will appear in the “Details” pane

! Refer to the “Developers Guide” document for the various options for any element

12 © 2011 ANSYS, Inc. December 3, 2012


An example from the Developers Guide

13 © 2011 ANSYS, Inc. December 3, 2012


More information on Units
The ‘unit’ information is
available at the
Workbench Project level

14 © 2011 ANSYS, Inc. December 3, 2012


Developing the Python callbacks

Invoked when the toolbar button in “Clicked”

Invoked when the result is evaluated


• onstarteval called once at the start of the
result evaluation process
• getvalue called at each node to get the
result at that node when it is being plotted

15 © 2011 ANSYS, Inc. December 3, 2012


Developing the Python callbacks (2)

Arguments to the function: analysis


Creates the “velplot” in the selected
analysis
Details of the result is in the XML file

16 © 2011 ANSYS, Inc. December 3, 2012


Developing the Python callbacks (3)

Arguments to the function: result & step

result refers to the ACT result object. The user inputs can be accessed using this reference

step refers to the result set number for which results need to be evaluated.
The step value is passed from the substep/time selector in the details of the result object

17 © 2011 ANSYS, Inc. December 3, 2012


Collect the user inputs

Collect the user inputs

In the Session-2, we have seen how to access a load via the IronPyton Console for
! debugging purpose. The result object can be accessed in the same way.

18 © 2011 ANSYS, Inc. December 3, 2012


Strategy: 1st Method: Use APDL commands
/batch
/post1
• Get into Post Processing FILE,'D:\Temp\t1_files\dp0\SYS\MECH\file'
• Read result file from the Mech directory SET,,,velo,,,,1
CMBLOCK,velapdl1,NODE,21
• Read result set from the result object
(8i10)
• Create and select a nodal component of selected 58 78 98 146 147 186 187 188
nodes 189 402 403 404 444 484 558
This portion of the APDL commands will generated 559
according to the user inputs 560 618 619 620 621
CMSEL, S, velapdl1

*GET, ncount, NODE, 0, count


*dim,varray,array,ncount,4
nnum = ndnext(0)
• Looping over the nodes *do,_nn,1,ncount
• Get velocity components in array varray(_nn,1) = nnum
• Write an array (node & velocity components) to varray(_nn,2) = ux(nnum)
the file varray(_nn,3) = uy(nnum)
varray(_nn,4) = uz(nnum)
This portion of the APDL commands will remain nnum = ndnext(nnum)
*enddo
constant for any selected APDL components alls
*cfopen,results,txt
These commands are saved as a file (e.g. *vwrite,varray(1,1),varray(1,2),varray(1,3),varray(1,4)
‘apdl_macro.inp’) that we can read and use as it is (F10.0,' ',E10.4,' ',E10.4,' ',E10.4)
[similar to custom load example in Session-3] *cfclose
fini
/exit
19 © 2011 ANSYS, Inc. December 3, 2012
1st Method: Use APDL commands
User inputs to APDL commands

Get the already solved


result file and use APDL
commands for
generating the results

Using an external module (myUtils) to


generate an nodal component from
the selected geometry

The APDL commands are Merging the commands from


written to the RunMapdlFile the ‘apdl_macro.inp’ file
20 © 2011 ANSYS, Inc. December 3, 2012
1st Method: Use APDL commands
Run MAPDL in background to get results

Read the file in Python and


store nodes and its velocities
in dictionaries

Run MAPDL in background with the RunMapdlFile

Note the usage of RunANSYS method from the


external ansys module [from libraries]

21 © 2011 ANSYS, Inc. December 3, 2012


2nd Method: Use Native Python APIs to get results

Use Native Python APIs to


get to evaluate the velocity
components

Velocities at the Nodes then


stored in dictionaries

Although the 1st method [Use of APDL commands] and 2nd method [Use of Native Python APIs] used
different approaches, at the end they both update a few dictionaries with node velocities
22 © 2011 ANSYS, Inc. December 3, 2012
Callback function to plot results (for both the
options)

• Display results at node, this information comes from the xml file at location = “node”

• This function is called for each node [based on use selection of scoping]
• A node ID is passed and it returns the velocity x , y and z components from the dictionary
[already stored in the onstarteval callback] to draw the velocity vector

For a contour, it would be type=“scalar” in XML and val = [vx_values[nodeId]] in Python


23 © 2011 ANSYS, Inc. December 3, 2012
Demo the extension

24 © 2011 ANSYS, Inc. December 3, 2012


Q/A

25 © 2011 ANSYS, Inc. December 3, 2012


Appendix

26 © 2011 ANSYS, Inc. December 3, 2012


Compare the XML files for Custom Load and Custom
post-processing extensions (1)

Custom Post-processing Custom Load

So, far they are identical!

27 © 2011 ANSYS, Inc. December 3, 2012


Compare the XML files for Custom Load and Custom
post-processing extensions (2)
Custom Post-processing

Custom Load

The Load and Result object have identical structure.


The details have some differences, for example
• Result object can have result of type nodal, elemental or elemental nodal, in details this can be specified
using location = “node” or “elem” or “elemnode” , where in load object no such requirement
28 © 2011 ANSYS, Inc. December 3, 2012
Compare the XML files for Custom Load and Custom
post-processing extensions (3)

Custom Post-processing

The <property> element for a


Custom Load result and load are the same

29 © 2011 ANSYS, Inc. December 3, 2012

Вам также может понравиться