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

WS-1: Develop a custom load extension

(reuse APDL)

1 © 2011 ANSYS, Inc. December 3, 2012


Objective
• Apply a convective boundary condition to the blade surface in a 2D axi-symmetric
analysis

Need to apply a ‘convective boundary


condition’ to this surface body

Since the model is 2D, Mechanical


allows convective boundary condition
only on the edges!

Using a command snippet we can


apply the convection load to the
surface!

• Create an ACT extension to apply this load


– In an user-friendly way
– Avoid possible user errors!
2 © 2011 ANSYS, Inc. December 3, 2012
The command snippet way!

User
Inputs

• Insert a command snippet


• Define the user inputs in the top
• Put the remaining code to apply the convection load
Element/Node selection possible only via NamedSelection
Can not visualize the entity graphically
Potential for user errors
! E.g. if ‘component’ is for a ‘face’  CMSEL will select the nodes and the analysis will fail
Inputs are hardcoded based on current unit system
3 © 2011 Doesn’t
ANSYS, Inc.updateDecember
on changing
3, 2012 the unit system [unlike standard load objects]
The ACT way!
! APDL_script_for_convection.inp

/prep7
thickness = 0.001
film_coefficient = 200.
temperature = 120
cmsel,s,component

*GET,n_el,ELEM,0,num,max
*GET,mat1, ELEM,n_el,ATTR,MAT

et,100,152 User Inputs will be


keyop,100,8,2. generated from the
et,1001,131
keyo,1001,3,2 custom (ACT) load
sectype,1001,shell
secdata,thickness,mat1
secoff,mid Other APDL
emodif,all,type,1001 commands will be
emodif,all,secnum,1001
type,100 reused as it is
esurf
fini
alls
/solu
esel,s,type,,100
nsle
sf,all,conv,film_coefficient,temperature
allsel, all
4 © 2011 ANSYS, Inc. December 3, 2012
Prerequisites
This workshop assumes that you ! APDL_script_for_convection.inp

• Understand XML and Python /prep7


thickness = 0.001
• Have reviewed Session-1 and Session-2 of ACT film_coefficient = 200.
temperature = 120
training materials cmsel,s,component

*GET,n_el,ELEM,0,num,max
*GET,mat1, ELEM,n_el,ATTR,MAT

Start with et,100,152


keyop,100,8,2.
• WB project file blade-model-145.wbpz et,1001,131
keyo,1001,3,2
– It has all the settings done (material, loads, sectype,1001,shell
secdata,thickness,mat1
analysis settings etc.) secoff,mid
– Review the command snippet emodif,all,type,1001
– Save the command snippet to a separate file emodif,all,secnum,1001
type,100
(e.g. APDL_script_for_convection.inp) esurf
fini
• Only keep the part where the user inputs alls
/solu
are used to apply the load esel,s,type,,100
• Don’t keep the user inputs as those will nsle
sf,all,conv,film_coefficient,temperature
come from the load allsel, all

5 © 2011 ANSYS, Inc. December 3, 2012


Planning the ‘bladeLoad’ extension

XML
• Need a button in toolbar for
the ‘bladeLoad’
• Details of the load:
– Scope to Geometry or
Named Selection
• Only allow body selection
– Other inputs with
appropriate units

Python
• Create the load under analysis
• Insert the desired APDL
commands to ‘ds.dat’ during
runtime
1. Collect the user inputs
2. Convert the user inputs to
APDL commands
3. Reuse the APDL commands
for applying the load using
the user inputs
6 © 2011 ANSYS, Inc. December 3, 2012
7 © 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 load. It contains the
application’s context attribute.

8 © 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>

9 © 2011 ANSYS, Inc. December 3, 2012


Developing the GUI (3)
<simdata> is the parent node for encapsulating
the definition for the load. It contains the
application’s context attribute.

<load> provide the name, version, caption, icon,


and color that apply to this load

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


1. when the solver input file is being generated by the application
(<getsolvecommands>)

The <details> tag encapsulates the properties that will be applied to


the actual definition of the load. These properties will be displayed
in the "Details" pane
10 © 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 load. These properties will be displayed
in the "Details" pane

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

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

11 © 2011 ANSYS, Inc. December 3, 2012


An example from the Developers Guide

Look at the file "controltemplates.xml" in


folder "templates" for more details on each
template. E.g. the “scoping” control

12 © 2011 ANSYS, Inc. December 3, 2012


More information on Controls

The value of the control attribute specifies the type of UI control to use
in the details view for this property.
• The text control activates a text area in which the user defines input
data.
• The select control activates a drop-down menu that contains a list of
available definitions.
• Static list using attributes
• Dynamic list using onactivate callback to manage the refresh
• The applycancel control activates an Apply/Cancel button based
on one user-defined selection. This control is the most generic
control type that can be used with callbacks to integrate a variety of
scenarios.

All pre-defined templates can be used as control type.


The following templates are available: scoping, component_selection,
geometry_selection, fileopen, entity_selection and
coordinatesystem_selection. Look at the file
"controltemplates.xml" in folder "templates" for more details on
each of these controls.
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 Solver is launched

15 © 2011 ANSYS, Inc. December 3, 2012


Developing the Python callbacks (2)

Arguments to the function: currentAnalysis


Creates the “bladeLoad” in the selected analysis
Details of the load is in the XML file

For any function, ExtAPI is available and represents the main entry point for all the
services provided by the Application Customization Toolkit.
[we have seen examples of this in the Session-2]

16 © 2011 ANSYS, Inc. December 3, 2012


Developing the Python callbacks (3)

Arguments to the function: load & stream

stream refers to the ANSYS DAT (ds.dat) file generated when the Solver is launched

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

The desired APDL commands are written to the stream


17 © 2011 ANSYS, Inc. December 3, 2012
1. 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

18 © 2011 ANSYS, Inc. December 3, 2012


2. Convert the user inputs to APDL commands

Convert the user inputs


to APDL commands

Using an external module (myUtils) to


generate an ElementComponent from the
selected bodies

The desired APDL


thickness = 0.001
film_coefficient = 200. commands are written to
temperature = 120 the stream [ds.dat file]
/prep7
cmsel,s,component

19 © 2011 ANSYS, Inc. December 3, 2012


3. Reuse the APDL commands
Read the APDL
commands [from the
input file] and write to
the stream [ds.dat file]

*GET,n_el,ELEM,0,num,max
*GET,mat1, ELEM,n_el,ATTR,MAT

et,100,152
keyop,100,8,2.
et,1001,131
keyo,1001,3,2
sectype,1001,shell
secdata,thickness,mat1
secoff,mid

emodif,all,type,1001
emodif,all,secnum,1001
type,100
esurf
fini
alls
/solu
esel,s,type,,100
nsle
sf,all,conv,film_coefficient,temperature
allsel, all
20 © 2011 ANSYS, Inc. December 3, 2012
Demo the extension

21 © 2011 ANSYS, Inc. December 3, 2012


Q/A

22 © 2011 ANSYS, Inc. December 3, 2012

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