Ansys Workbench Scripting

download Ansys Workbench Scripting

of 29

Transcript of Ansys Workbench Scripting

  • 8/12/2019 Ansys Workbench Scripting

    1/29

    Introduction toIntroduction toANSYS Workbench

    Scripting in

    ANSYS Workbench

    Scripting in ..

    November 2009November 2009

    2009 ANSYS, Inc. All rights reserved. 1 ANSYS, Inc. Proprietary

    2009 ANSYS, Inc. All rights reserved. 1 ANSYS, Inc. Proprietary

  • 8/12/2019 Ansys Workbench Scripting

    2/29

    Agenda

    Recording & Replaying Journals

    Scripting Basics

    Scripting with Data-Integrated Applications

    ere o e e p

    Examples

    2009 ANSYS, Inc. All rights reserved. 2 ANSYS, Inc. Proprietary

  • 8/12/2019 Ansys Workbench Scripting

    3/29

    Scripting Overview

    scripting

    Project concepts & operations

    arame er managemen

    Native applications , ,

    File management and data models

    Python-based scripting language Object-oriented

    Platform-independent

    Full documented & su orted

    Works hand-in-hand with application-level scripting

    DesignModeler, Meshing,

    2009 ANSYS, Inc. All rights reserved. 3 ANSYS, Inc. Proprietary

    ec an ca , ec an ca ,FLUENT, CFX, etc.

  • 8/12/2019 Ansys Workbench Scripting

    4/29

    Journaling

    journal file n y opera ons w c mo y a a mo e

    Files have *.wbjn extension

    Each session creates a new journal file

    Journals should not be confused with log files

    og es recor spec c or enc even s

    Log files cannot be replayed

    2009 ANSYS, Inc. All rights reserved. 4 ANSYS, Inc. Proprietary

  • 8/12/2019 Ansys Workbench Scripting

    5/29

    Journaling

    Automatically recorded session journals

    Restore work from a complete session

    NOT designed to archive simulation projects

    Manually recorded journals Starting points for creating custom Workbench scripts

    Communicate sequential Workbench steps to

    colleagues or ANSYS Customer Support

    2009 ANSYS, Inc. All rights reserved. 5 ANSYS, Inc. Proprietary

  • 8/12/2019 Ansys Workbench Scripting

    6/29

    Journaling Options (Preferences)

    - -

    2009 ANSYS, Inc. All rights reserved. 6 ANSYS, Inc. Proprietary

  • 8/12/2019 Ansys Workbench Scripting

    7/29

    Manually Recorded Journals

    recording

    Stop a journal recording

    2009 ANSYS, Inc. All rights reserved. 7 ANSYS, Inc. Proprietary

  • 8/12/2019 Ansys Workbench Scripting

    8/29

    Replaying Journals

    interactive session e cr p ng un cr p e

    2009 ANSYS, Inc. All rights reserved. 8 ANSYS, Inc. Proprietary

  • 8/12/2019 Ansys Workbench Scripting

    9/29

    Replaying Journals

    command line < ename.w n>

    Add I for interactive mode or B for batch

    2009 ANSYS, Inc. All rights reserved. 9 ANSYS, Inc. Proprietary

  • 8/12/2019 Ansys Workbench Scripting

    10/29

    Workbench Command Line

    Argument Operation

    -B Run Workbench in batch mode. The user interface is not

    displayed and a console window is opened. The functionality of

    the console window is the same as the Workbench Command

    Window.

    -R

    Replay the specified Workbench script file on start-up. If

    specified in conjunction with B, Workbench will start in batch

    mode, execute the specified script, and shut down at the

    .

    -I Run Workbench in interactive mode. This is typically the default,

    but if specified in conjunction with B, both the user interface and

    .

    -X Run Workbench interactively and then exit upon completion of

    script execution. Typically used in conjunction with R.

    - or enc

    project file>

    oa e spec e or enc pro ec e on s ar -up.

    -E Execute the specified Workbench scripting command on start-up.

    2009 ANSYS, Inc. All rights reserved. 10 ANSYS, Inc. Proprietary

    , ,

    or specify this argument multiple times and the commands will beexecuted in order.

  • 8/12/2019 Ansys Workbench Scripting

    11/29

    Command Window

    in Command Window

    2009 ANSYS, Inc. All rights reserved. 11 ANSYS, Inc. Proprietary

  • 8/12/2019 Ansys Workbench Scripting

    12/29

    Command Window

    Command completion

    Command history

    Ke board shortcuts for cursor navi ation and

    editing

    2009 ANSYS, Inc. All rights reserved. 12 ANSYS, Inc. Proprietary

  • 8/12/2019 Ansys Workbench Scripting

    13/29

    Scripting Basics

    Workbench an e a mo e ourna or a comp e e y new

    set of instructions written directly

    Scripts and journals use the same programminglanguagePython

    Use scripts for:

    Performing Workbench operations in batch

    2009 ANSYS, Inc. All rights reserved. 13 ANSYS, Inc. Proprietary

  • 8/12/2019 Ansys Workbench Scripting

    14/29

    Objects and Properties

    act on the data

    roper y:

    Data belonging to an object

    , ,

    Property types: Boolean, String, Integer, Real, etc.

    Properties are accessed via dot operatorparameter1.Expression = 10

    parameter1 is an object of type Parameter

    2009 ANSYS, Inc. All rights reserved. 14 ANSYS, Inc. Proprietary

    Value of Expression is set to 10

  • 8/12/2019 Ansys Workbench Scripting

    15/29

    Methods

    Can change property values, create or deleteproper es, or nvo e comp ex ca cu a ons an

    operations

    Like properties, methods are accessed via dot

    operator

    parameter1.SetQuantityUnits("m") parameter1 is an object of type Parameter

    SetQuantityUnits is a method called to set the

    2009 ANSYS, Inc. All rights reserved. 15 ANSYS, Inc. Proprietary

    objects units to meters

  • 8/12/2019 Ansys Workbench Scripting

    16/29

    Object-Based Scripting Approach

    Query methods return object references that are

    assigned to variables Parameter = EMo e . etParameter Name= P

    2. Interrogate/modify object properties

    Parameter.Nature = "NatureUsability"3. Call methods to operate on objects internal data

    e o s requ re comma-separa e argumen swithin parentheses

    Parameter.AddLevels(Levels=["65","70","75","80"])

    Note: Python is a loosely-typed language; you do not

    2009 ANSYS, Inc. All rights reserved. 16 ANSYS, Inc. Proprietary

    need to declare variables.

  • 8/12/2019 Ansys Workbench Scripting

    17/29

    Project & Data Model Concepts

    2009 ANSYS, Inc. All rights reserved. 17 ANSYS, Inc. Proprietary

  • 8/12/2019 Ansys Workbench Scripting

    18/29

    Project & Data Model Concepts

    System:

    A collection of components thattogether provide a workflow to

    achieve an engineering

    simulation goal.

    Systems are created from

    System Templates.

    2009 ANSYS, Inc. All rights reserved. 18 ANSYS, Inc. Proprietary

  • 8/12/2019 Ansys Workbench Scripting

    19/29

    Project & Data Model Concepts

    Component:

    A collection of data and a dataeditor that work together to

    achieve a CAE-related task.

    A Component is represented

    by a Cell in the Workbench

    Project Schematic.

    2009 ANSYS, Inc. All rights reserved. 19 ANSYS, Inc. Proprietary

  • 8/12/2019 Ansys Workbench Scripting

    20/29

    Project & Data Model Concepts

    Component Data Container:

    Data unique to an individualcomponen , an e serv ces o

    manage and manipulate it.

    2009 ANSYS, Inc. All rights reserved. 20 ANSYS, Inc. Proprietary

  • 8/12/2019 Ansys Workbench Scripting

    21/29

    Project & Data Model Concepts

    Data Entity:

    A data structure defined within aata conta ner. ata

    container often has several data

    entities.

    2009 ANSYS, Inc. All rights reserved. 21 ANSYS, Inc. Proprietary

  • 8/12/2019 Ansys Workbench Scripting

    22/29

    Example:

    # Query for the static structural analysis template

    ss_template = GetTemplate(TemplateName="Static Structural",

    Solver="ANSYS")

    # Create an analysis system from the template

    ss_system = ss_template.CreateSystem()

    # Query for the Engineering Data container

    ed_container = ss_system.GetContainer(ComponentName="Engineering Data")

    uery or e ma er a a a en y n e a a con a ner

    steel = ed_container.GetMaterial(Name="Structural Steel")

    elasticity = steel.GetProperty(Name="Elasticity")

    2009 ANSYS, Inc. All rights reserved. 22 ANSYS, Inc. Proprietary

    elasticity.SetData(Variables="Young's Modulus", Values=2E+11)

  • 8/12/2019 Ansys Workbench Scripting

    23/29

    Data-Integrated Applications

    Native applications Built entirely on new Workbench Framework

    Fully supported by Workbench scripting

    E.g., Project Schematic, Design Exploration,Engineering Data

    Data-integrated applications Share data and parameters with Workbench,

    na ve app ca ons, an o er a a- n egra e

    applications

    Created inde endentl from new WorkbenchFramework

    Often have their own scripting languages

    2009 ANSYS, Inc. All rights reserved. 23 ANSYS, Inc. Proprietary

    .g., ec an ca , ec an ca ,

    CFX, FLUENT, DesignModeler

  • 8/12/2019 Ansys Workbench Scripting

    24/29

    Data-Integrated Applications

    -

    Workbench script

    , , , , .

    Some data-integrated applications record their

    operations in the Workbench journal CFX, FLUENT

    2009 ANSYS, Inc. All rights reserved. 24 ANSYS, Inc. Proprietary

  • 8/12/2019 Ansys Workbench Scripting

    25/29

    Example:

    curve in DesignModeler:

    # create a geometry system

    system = GetSystem(Name="Geom")

    # query the data container of the geometry system

    geometry = system.GetContainer(ComponentName="Geometry")

    # send a JScript command to DM to create an ellipse

    geometry.SendCommand(Command = """var ps1 = new Object();

    ps1.Plane = agb.GetActivePlane();

    ps1.Origin = ps1.Plane.GetOrigin();

    ps1.XAxis = ps1.Plane.GetXAxis();

    ps1.YAxis = ps1.Plane.GetYAxis();ps . = ps . ane. ew e c ;

    ps1.Sk1.Name = "Sketch1";

    with (ps1.Sk1) { ps1.El7 = Ellipse( 8.0, 10.0, 9.0,

    2009 ANSYS, Inc. All rights reserved. 25 ANSYS, Inc. Proprietary

    . , . , .

    agb.Regen();""")

  • 8/12/2019 Ansys Workbench Scripting

    26/29

    Documentation

    Overview

    How-to Complete command reference

    Many examples

    2009 ANSYS, Inc. All rights reserved. 26 ANSYS, Inc. Proprietary

    PDF version available on ANSYS Customer Portal

  • 8/12/2019 Ansys Workbench Scripting

    27/29

    Example & Demo:

    2009 ANSYS, Inc. All rights reserved. 27 ANSYS, Inc. Proprietary

  • 8/12/2019 Ansys Workbench Scripting

    28/29

    Example & Demo:

    2009 ANSYS, Inc. All rights reserved. 28 ANSYS, Inc. Proprietary

  • 8/12/2019 Ansys Workbench Scripting

    29/29

    Example & Demo:

    2009 ANSYS, Inc. All rights reserved. 29 ANSYS, Inc. Proprietary