ANSYS 12.0 官方培訓手冊-Introduction to CFX-PART E_第1頁
ANSYS 12.0 官方培訓手冊-Introduction to CFX-PART E_第2頁
ANSYS 12.0 官方培訓手冊-Introduction to CFX-PART E_第3頁
ANSYS 12.0 官方培訓手冊-Introduction to CFX-PART E_第4頁
ANSYS 12.0 官方培訓手冊-Introduction to CFX-PART E_第5頁
已閱讀5頁,還剩99頁未讀, 繼續(xù)免費閱讀

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進行舉報或認領(lǐng)

文檔簡介

1、A-1ANSYS, Inc. Proprietary 2009 ANSYS, Inc. All rights reserved.April 28, 2009Inventory #002598ANSYS 12.0 Training ManualCFX 12.0Introduction to CFXPart E Appendix A-E, 104 PagesA-2ANSYS, Inc. Proprietary 2009 ANSYS, Inc. All rights reserved.April 28, 2009Inventory #002598Appendix AScripting and Aut

2、omationIntroduction to CFX Scripting and AutomationA-3ANSYS, Inc. Proprietary 2009 ANSYS, Inc. All rights reserved.April 28, 2009Inventory #002598Training Manual Introduction CFX User Environment (CUE) architecture State and Session Files Introduction to Perl CCL and Perl “Power Syntax” Perl subrout

3、ines MacrosOverviewScripting and AutomationA-4ANSYS, Inc. Proprietary 2009 ANSYS, Inc. All rights reserved.April 28, 2009Inventory #002598Training Manual Need for scripting and automation Increase productivity by simplifying repetitive tasks Standardize practices Save and re-use data IntroductionScr

4、ipting and AutomationA-5ANSYS, Inc. Proprietary 2009 ANSYS, Inc. All rights reserved.April 28, 2009Inventory #002598Training Manual CUE is the common development environment for all CFX products CUE applications employ a client-server architecture The user interfaces with the “client”, while the “se

5、rver” processes the data The most common client is a graphical user interface, but line and batch interfaces also existServerClientUser InputCCLCFX User EnvironmentScripting and AutomationA-6ANSYS, Inc. Proprietary 2009 ANSYS, Inc. All rights reserved.April 28, 2009Inventory #002598Training Manual D

6、efault mode of operation Graphical client driven by user input User loads results, states, runs sessions and macrosEngineGUIUserCCLGUI ModeScripting and AutomationA-7ANSYS, Inc. Proprietary 2009 ANSYS, Inc. All rights reserved.April 28, 2009Inventory #002598Training Manual Open session launched from

7、 command line or within a script by specifying -line flag e.g. cfx5post line Client includes viewer and a command line input CCL objects and commands are input one line at a time Allows interactive scripts with control outside of script Line input modes exist for TurboGrid, Pre, Post, Solver (solver

8、 uses ccl flag)EngineLine Input / ViewerUser/ScriptCCLLine Input ModeScripting and AutomationA-8ANSYS, Inc. Proprietary 2009 ANSYS, Inc. All rights reserved.April 28, 2009Inventory #002598Training Manual Closed session (not interactive) launched from command line or script Direct to engine No viewer

9、 Session file specified at run time Session file may include interactive commands, load states, results, etc. Must end with a quit statementEngineScriptCCLBatch ModeScripting and AutomationA-9ANSYS, Inc. Proprietary 2009 ANSYS, Inc. All rights reserved.April 28, 2009Inventory #002598Training Manual

10、Session files contain a list of commands and CCL objects Can record the commands executed during a session to a file and then play back the file at a later date or in batch mode Can write/modify session files in a text editor Produced in Pre, Post, TurboGrid Session files can perform actions, for ex

11、ample Input / OutputSession FilesScripting and AutomationA-10ANSYS, Inc. Proprietary 2009 ANSYS, Inc. All rights reserved.April 28, 2009Inventory #002598Training Manual State files are a snap-shot of the current state of all objects Can be created to save or load a number of objects Contain CCL obje

12、cts-parameter definitions Can write / modify state files using a text editor Produced in Pre, Post, TurboGrid State files cannot perform actionsState FilesA-11ANSYS, Inc. Proprietary 2009 ANSYS, Inc. All rights reserved.April 28, 2009Inventory #002598Introduction to PerlScripting and AutomationA-12A

13、NSYS, Inc. Proprietary 2009 ANSYS, Inc. All rights reserved.April 28, 2009Inventory #002598Training Manual Perl is a public domain scripting language that combines the features and purposes of many command languages and tools It is a fully featured programming language (even supports Object Oriented

14、 programming) Has replaced shell scripting, awk, sed, regexp, grep, etc. inside of CFX Good text handling and parsing capabilitiesWhat is Perl?Scripting and AutomationA-13ANSYS, Inc. Proprietary 2009 ANSYS, Inc. All rights reserved.April 28, 2009Inventory #002598Training Manual Advantages Powerful,

15、consistent, fully-featured programming language System interoperability (Windows/Unix) Strong user base & public support Many useful Perl modules (subroutine/object libraries) freely available Disadvantages It is an interpreted language Cant hide code (sort of) Slow for computationally intensive

16、 processes Many ways to do the same thing Easy to write obfuscated PerlWhy use Perl?Scripting and AutomationA-14ANSYS, Inc. Proprietary 2009 ANSYS, Inc. All rights reserved.April 28, 2009Inventory #002598Training Manual Books: Introductory Randal L. Schwartz, Learning Perl, 1993, OReilly and Associa

17、tes, Inc., ISBN 1-56592-042-2. The Llama Book. Hoffman, Perl 5 For Dummies, 408 pages, IDG Books, ISBN 0-7645-0460-6 The Perl Bible Larry Wall, Tom Christiansen & Randall L. Schwartz, Programming Perl, 2nd Edition September 1996, OReilly and Associates, Inc., ISBN 1-56592-149-6. The Camel Book.

18、Advanced Use S. Srivivasan, Advanced Perl Programming, 1997, OReilly and Associates, Inc., ISBN 1-56592-220-4 Web: , , newsgroupsPerl ReferencesScripting and AutomationA-15ANSYS, Inc. Proprietary 2009 ANSYS, Inc. All rights reserved.April 28, 2009Inventory #002598Training Manual#!/usr/bi

19、n/perlprint “What is your name? “;$name = ;chomp($name);if ($name eq “Steve”) print “Hi Steve! Good to see you again!n”; #friendly greeting else print “Hello, $name. Nice to meet you.n”; #ordinary greetingPerl ExampleScripting and AutomationA-16ANSYS, Inc. Proprietary 2009 ANSYS, Inc. All rights res

20、erved.April 28, 2009Inventory #002598Training Manual Perl statements are terminated by a semicolon (;) Whitespace and indentation do not matter Except for making the code readable. Everything is case sensitive Comments are preceded by a pound sign (#) There are no multi-line comments (e.g. /* . */ i

21、n C+)Syntax BasicsScripting and AutomationA-17ANSYS, Inc. Proprietary 2009 ANSYS, Inc. All rights reserved.April 28, 2009Inventory #002598Training Manual Variable type is implied, not declared Leading character determines return type Scalars: $ Denotes a single value Can be a number, character strin

22、g, pointer, array element, etc. Linear Arrays: Elements reference by position Elements may be any type (scalar, array, hash) Hash (associative array): % Elements referenced by lookup (associative) Elements may be any type Very useful for nested dataPerl VariablesScripting and AutomationA-18ANSYS, In

23、c. Proprietary 2009 ANSYS, Inc. All rights reserved.April 28, 2009Inventory #002598Training Manual Scalars are single valued numbers or strings Scalar variable names are of the form $varName The first character in varName must be a letter All numbers are treated internally as double-precision floats

24、. Format is flexible: 1.25, -5.34e34, 12, -2001, 3.14E-5 Variable assignment uses the equal sign (=) $pi = 22/7.0 #close enoughScalar Variables $Scripting and AutomationA-19ANSYS, Inc. Proprietary 2009 ANSYS, Inc. All rights reserved.April 28, 2009Inventory #002598Training Manual Strings are a quote

25、d group of characters double-quoted (“) and single-quoted () strings are handled slightly differently. Double quoted strings act a lot like strings in C Can include backslash escapes to represent special characters. $greeting = “hello worldn”; # hello world, newlineStrings “”, Scripting and Automati

26、onA-20ANSYS, Inc. Proprietary 2009 ANSYS, Inc. All rights reserved.April 28, 2009Inventory #002598Training Manual An array is an ordered list of scalar data Arrays can have any number of elements Perl deals with all memory management issues Arrays are zero indexed The sign denotes an array variable

27、evens=(2,4,6,8); numbers = (1.5); # (1,2,3,4,5) Access a array elements using $listNameindices; $four = $evens1; ($four,$five) = $numbers3,4;Arrays (lists)Scripting and AutomationA-21ANSYS, Inc. Proprietary 2009 ANSYS, Inc. All rights reserved.April 28, 2009Inventory #002598Training Manual To determ

28、ine the size of an array, use scalar(listName) Useful array functions: push, pop: To add and remove elements from the high end of a list push(list,$newValue) or push(list,moreElements) $oldValue=pop(list) shift, unshift: To add and remove elements from the low end of a list reverse: reverses the ord

29、er of the elements in a new list backwardList=reverse(forwardList) sort: sorts the elements in ASCII order into a new list ordered=sort(unordered)Arrays (lists)Scripting and AutomationA-22ANSYS, Inc. Proprietary 2009 ANSYS, Inc. All rights reserved.April 28, 2009Inventory #002598Training Manual Perl

30、 uses standard math operators addition (+), subtraction (-), multiply (*), divide (/), exponentiation (*), modulus (%) increment (+) and decrement (-) binary assignment supported (+=,*=, etc.)$a = $a + 1;#$a += 1;# All are equivalent$a+# String operators concatenation (. or .=)“hello” . “world” #giv

31、es “helloworld”“fred” . “ “ . “wilma” #gives “fred wilma” string repetition (x) “l(fā)a” x 3 #gives “l(fā)alala”“foo” x (4 + 1)#gives “foofoofoofoofoo”Scalar Variable OperatorsScripting and AutomationA-23ANSYS, Inc. Proprietary 2009 ANSYS, Inc. All rights reserved.April 28, 2009Inventory #002598Training Man

32、ual Perl has many, many built in functions Functions for: Text processing, numeric functions, process control, list processing, file IO, data processing, etc. No real distinction between built-in functions and user-defined subroutines They all: Have a name Return a value or list of values Can accept

33、 arguments$res = log(123);$angle = atan2(.5,-.5);push(myList,2,4,7);$value = pop(myList);$textBit = substr($myString,3,2);Perl FunctionsScripting and AutomationA-24ANSYS, Inc. Proprietary 2009 ANSYS, Inc. All rights reserved.April 28, 2009Inventory #002598Training Manual Perl contains a number of co

34、ntrol structures (if, else, etc.) based on logic expressions The following is true: Any string except for “” and “0”. Any number except 0. Any reference is true Anything else is false Tests in control structures can contain any expression or operators and the result is evaluated using the above rule

35、sLogic in PerlScripting and AutomationA-25ANSYS, Inc. Proprietary 2009 ANSYS, Inc. All rights reserved.April 28, 2009Inventory #002598Training Manual Comparison operators come in numeric and string varieties Make sure you use the right one e.g. (30 le 7) is true. Its evaluated using ascii precedence

36、ComparisonNumericStringEqual=eqNot equal!=neLess thangtLess than or equal to=geScalar Comparison OperatorsScripting and AutomationA-26ANSYS, Inc. Proprietary 2009 ANSYS, Inc. All rights reserved.April 28, 2009Inventory #002598Training Manual if:if (some expression) statement 1;statement 2; . elsif (

37、another_expression) statement 3; . else statement 4;statement 5; .print “How old are you?”;$a = ;chomp($a);if ($a 18) print “Sorry, youre too young.n”;die; else print “Welcomen”;if.Scripting and AutomationA-27ANSYS, Inc. Proprietary 2009 ANSYS, Inc. All rights reserved.April 28, 2009Inventory #00259

38、8Training Manual for:for (initial_exp; test_exp; increment_exp) statement 1;statement 2; . for ($I = 1; $I 10; $I+) print “$In”; while:while (some expression) statement 1;statement 2; .print “How old are you?”;$a = ;chomp($a);while ($a 0) print “At one time, you were $a years old.n”;$a-;for & wh

39、ileScripting and AutomationA-28ANSYS, Inc. Proprietary 2009 ANSYS, Inc. All rights reserved.April 28, 2009Inventory #002598Training Manual foreach is a useful for walking through the elements of a listforeach $var (some_list) statement 1;statement 2; .a = (3,5,7,9);foreach $number (a) $number += 2;

40、# a is now (5,7,9,11); Any changes to the scalar variable affect the list ! will negate any logical expression (i.e. not) & is a logical and | is a logical orforeach, not, and, orScripting and AutomationA-29ANSYS, Inc. Proprietary 2009 ANSYS, Inc. All rights reserved.April 28, 2009Inventory #002

41、598Training Manual The connection to an input or output location is called a handle Filehandles are created using open() open for read: open(MYFILE,”infile.dat”); open for write: open(MYFILE,”outfile.dat”); Will fail if file exists open for append: open(MYFILE,”logfile.dat”); open() returns true/fal

42、se for success/failureopen(IN,”infile.dat”) | print “Error: couldnt open filen”;Basic I/OScripting and AutomationA-30ANSYS, Inc. Proprietary 2009 ANSYS, Inc. All rights reserved.April 28, 2009Inventory #002598Training Manual You write to a filehandle by printing to itprint LOGFILE “Done current task

43、.n”; Read from a filehandle by putting it inside Returns the next line in the file if assigned to a scalar. An empty string is returned at the end of the file Returns all lines if assigned to an arrayopen(INFILE,”myfile.dat”);while($line = ) print “Just read: $linen”;open(INFILE,”myfile.dat”);allLin

44、es = ;foreach $line (allLines) print “The file contained: $linen”;Basic I/OScripting and AutomationA-31ANSYS, Inc. Proprietary 2009 ANSYS, Inc. All rights reserved.April 28, 2009Inventory #002598Training Manual close(FILEHANDLE) when done with a file STDIN, STDOUT, STDERR are automatically managed f

45、ilehandles. he chomp($a) function removes the last character from a string if it is a newline (n)print “How old are you?”;$a = ;chomp($a);if ($a errors.dat”);open(SOLVER,|cfx5solve -def $myRun);close(SOLVER); #waits until done to continueExternal ProcessesScripting and AutomationA-33ANSYS, Inc. Prop

46、rietary 2009 ANSYS, Inc. All rights reserved.April 28, 2009Inventory #002598Training Manual Perl can use regular expressions for general text pattern matching and replacement Complex and ugly, but powerfulprint “Any last requests? ”;chomp($a = );if ($a = /y/i) # does the input begin with yprint “Wha

47、t is it?”; ; print “Sorry, I cant do that.n”;print “Ready, aim, Fire !n”;$string = “foot fool buffoon”;$string = s/foo/bar/g; # string is now “bart barl bufbarn”$line = “X,Y,Z,1,1.234,34”;fields = split(/,/, $line); # fields is (“X”,”Y”,”Z”,”1”,”,”1.234”,”34”)Regular ExpressionsScripting and Automat

48、ionA-34ANSYS, Inc. Proprietary 2009 ANSYS, Inc. All rights reserved.April 28, 2009Inventory #002598Training Manual Subroutines are just user defined functions. Declared with sub Subroutines return one or more values from a return statement or the value of the last statement if no explicit return. In

49、voked by calling subName(args)sub subName statement 1; statement 2; .$result = doSomething($a,$b);SubroutinesScripting and AutomationA-35ANSYS, Inc. Proprietary 2009 ANSYS, Inc. All rights reserved.April 28, 2009Inventory #002598Training Manual Arguments are passed to a subroutine using the _ list M

50、ust pass lists and arrays by referencesub addThreeNumbers ($a, $b, $c) = _; $result = $a + $b + $c; return $result;SubroutinesScripting and AutomationA-36ANSYS, Inc. Proprietary 2009 ANSYS, Inc. All rights reserved.April 28, 2009Inventory #002598Training Manual Use in front of a variable to create a

51、 scalar reference (pointer) $listRef = myList; De-reference by using a variable reference type ($, or %) push($listRef,”new Value”); Directly access elements in a reference using - notation For arrays: $listRef-$index For hashes: $hashRef-$keyReferencessub printHash ($hashRef) = _; foreach $key (key

52、s(%$hashRef) print “Key: $key, Value: “ . $hashRef-$key . “n”; %myHash = (“a” = “b”, “c” = “d”);printHash(%myHash);Scripting and AutomationA-37ANSYS, Inc. Proprietary 2009 ANSYS, Inc. All rights reserved.April 28, 2009Inventory #002598Training Manual By default, all variables have global scope. Can

53、create private variables using my specification. Put use strict; in a script to force explicit scoping of all variables All variables must be declared using my or local Catches mis-typed variable namessub addThreeNumbers my ($a, $b, $c) = _; my $result = $a + $b + $c; return $result;Variable ScopeSc

54、ripting and AutomationA-38ANSYS, Inc. Proprietary 2009 ANSYS, Inc. All rights reserved.April 28, 2009Inventory #002598Training Manual Significant benefit of Perl is the ability to re-use other peoples work You can include a set of subroutines from another file with require filename.pl A wide range o

55、f modules are publicly available e.g. matrix algebra, HTML parsing, database manipulation, graphing, GUIs, 3rd party interfacesLibraries and ModulesScripting and AutomationA-39ANSYS, Inc. Proprietary 2009 ANSYS, Inc. All rights reserved.April 28, 2009Inventory #002598Training Manual Ext

56、ernal Perl scripts can be used to drive the CFX-Solver for multiple runs, optimisation loops, etc The CFX-Solver can be sent CCL through the command line to over-ride local settings cfx5solve -ccl - means read from stdin cfx5solve -def duct.def -ccl special.cclExternal Perl ScriptingScripting and Au

57、tomationA-40ANSYS, Inc. Proprietary 2009 ANSYS, Inc. All rights reserved.April 28, 2009Inventory #002598Training Manual CFX-Pre, CFD-Post and TurboGrid can also be launched from within a Perl script and automatically run a session file to perform quantitative or graphical post-processing in batch mo

58、desystem(“cfx5post -batch mysession.cse results.res”);Oropen(CFDPOST, |cfx5post line);print CFDPOST CCL COMMANDSclose(CFDPOST);External Perl ScriptingScripting and AutomationA-41ANSYS, Inc. Proprietary 2009 ANSYS, Inc. All rights reserved.April 28, 2009Inventory #002598Training Manual CCL also inclu

59、des Power Syntax as a programming language within CCL Indicated by a “!” at the start of the line Power Syntax is the Perl programming language CCL includes Perl Full support for loops, if/then/else, subroutines and much more! $speed = 2.0;! if ($speed gt 1.5) ! $turbulence = on;! .BOUNDARY: inlet1

60、Normal speed in = $speed m/s ! if ($turbulence = on) Eddy length scale = 0.001 m ! END! $numSteps = 20;! for (my $i=0; $i=$numSteps; $i+) ! $transparency = $i/$numSteps;BOUNDARY:Default Transparency = $transparencyEND!CCL & PerlScripting and AutomationA-42ANSYS, Inc. Proprietary 2009 ANSYS, Inc. All rights reserv

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負責。
  • 6. 下載文件中如有侵權(quán)或不適當內(nèi)容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

評論

0/150

提交評論