Patran二次开发工具PCL系列教程之8
基于MSC_Patran界面的PCL二次开发

《现代电子技术》2010 年第 16 期总第 327 期
计算机应用技术
基于 MSC. Patran 界面的 PCL 二次开发
张军彦 , 李昌华 , 李晓辉
(西安建筑科技大学 信息与控制工程学院 , 陕西 西安 710055)
摘 要 :在对 MSC. Pat ran 进行二次开发时 ,通常需要编写自定义的图形界面 ,以实现开发者所需的一些特殊功能 。由 于 Pat ran 软件读取部分格式文件功能比较繁琐 ,要通过手动输入一些参数才能进行数据的读入 。针对这些不足 ,特进行 Pat ran 界面的二次开发 ,使得预先设置好的参数 ,通过界面函数与系统调用 ,可以直接进行数据读取 ,大大提高了效率 。最 后给出开发后的界面实例进行验证 。
Keywords : MSC Pat ran ; PCL redevelop ment ; user interface ; read data
0 引 言
随着造船技术的发展 ,船舶建造向大型化和经济化 方向发展 。MSC. Pat ran 是 MSC 公司开发的大型有限 元通用软件 ,广泛地应用于航空 、航天 、船舶 、建筑 、桥梁 等行业的工程设 、工程分析中 。Pat ran 可以用来对 建筑物进行各种分析 ,例如 :混凝土实体结构有限元分 析以及超高层建筑物的气压波动分析等 。MSC. Pat ran 具有齐全的前 、后处理功能 ,以 MSC. Pant ran 为平台 , 应用 PCL 语言并结合会话文件对 MSC. Pat ran 进行 二次开发 ,实现结构建模与分析的参数化 。PCL ( Pat2 ran Co mmand Language) 是一个高级 、模块化结构编程 语言和用户自定义工具 ,类似于 C 语言和 Fort ran 语 言 ,可用于生成应用程序或特定的用户界面 ,显示自定 义图形 、读写 Pat ran 数据库 ,建立新的功能或增强功 能 。同时通过 PCL 的二次开发 ,其他商品化的或自编 分析程序可被集成到 Pat ran 中 。
Patran基础教程08_场

(*)
60 50 40 30 20 10 0 0
-----
xy1
1
2
3
● 可以输入Excel的电子表格或者把Patran中的列
PAT301, Section 8, September 2010 Copyright 2010 MSC.Software Corporation
表输出成 Excel的电子表格 S8-10
等等一些教育学习办公写作商业经营实用性极强的文档您若觉得对您日常学习商业经营社交沟通办公写作有所帮助的话就关注我吧
第 8 部分 场
PAT301, Section 8, September 2010 Copyright 2010 MSC.Software Corporation
S8-1
FIELDS
S8-18
显示场数据
● Fields 可以 X-Y 图
表显示 ● 必须选择一个自变 量
LEGEND
model
120
100
80
60
40
20
PAT301, Section 8, September 2010 Copyright 2010 MSC.Software Corporation
0
S8-19
0
0.6
T) Thickness = 0.2 + 0.4*SINR(’
T=1.57 T Z R T=0 0.2
S8-6
PAT301, Section 8, September 2010 Copyright 2010 MSC.Software Corporation
空间场, PCL 函数输入
● PCL 表达式最多可用 3 个空间变量来定义
用MSC_Patran的PCL二次开发用户界面

文章编号:167127953(2002)03220203收稿日期:2002203228作者简介:唐友宏(19802),男,硕士在读用MSC.Patran 的PC L 二次开发用户界面唐友宏 陈宾康(武汉理工大学交通学院,武汉430063)摘 要:在对MSC.Patran 进行二次开发时,通常要自己编写自定义的图形界面,以实现开发者所需的一些特殊功能,结合某些用户界面,说明利用PC L 语言进行二次开发用户界面的过程和应注意的问题。
关键词:MSC.Patran ;PC L 语言;用户界面;二次开发中图分类号:U662.9 文献标识码:AAbstract :When y ou use MSC.Patran to ,y ou usually need to com pile self -defined graphical inter faces ,in order to achieve s ome special function needed by developer.This paper shows the process of using PC L language to develop user in 2ter face and the problems needed to be attention by using the exam ple of s ome user inter face.K ey w ords :MSC.Patran ;Patran C ommand Language ;User inter face ;Redevelopment1 引言MSC.Patran 是世界公认最佳的集几何访问、有限元建模、分析求解及数据可视化于一体的新一代框架式软件系统,通过其全新的“并行工程概念”和无与伦比的工程应用模块,将世界所有著名的C AD/C AE/C AM/C AT (测试)软件系统及用户自编程序自然地融为一体。
Patran二次开发步骤

1.******在Patran下挂下拉菜单******通常我们不修改init.pcl文件,启动init.pcl时而会执行附带的启动文件p3prolog.pcl 和p3epilog.pcl。
如果这些文件存在,就会在init.pcl启动前后装载p3prolog.pcl(启动前)和p3epilog.pcl(启动后),所以这两个文件是我们插入自定义命令的好地方。
!!PATH!!LIBRARY!!INPUT在Patran安装目录下修改p3prolog.pcl,加入如下命令,例如:!!input mymenu.pcl #装载菜单文件ui_exec_function("mymenu","init") #当且仅初始化一次!!input plateform.pcl #装载对话框文件2.******** 下拉菜单程序编写*********CLASS exerciseFUNCTION init() /*初始化菜单*/WIDGET menubar,menu,item1,item2,item3 /*定义控件变量*/menu = uil_primary.get_menubar_id() /*获取主菜单ID*/menubar=ui_menu_create(menu,"exercise_menu","有限元分析") /*添加菜单*/ item1=ui_item_create(menubar,"ex_1","计算",FALSE) /*添加子菜单*/ item2=ui_item_create(menubar,"ex_2","导入文件",FALSE) /*添加子菜单*/ item3=ui_item_create(menubar,"ex_3","结束",FALSE) /*添加子菜单*/ END FUNCTIONFUNCTION exercise_menu(item_name) /*菜单各项的响应函数*/STRING item_name[]SWITCH(item_name)CASE("EX_1")write("Plate with a hole creating function")ui_exec_function("plateform","init")plateform.display()CASE("EX_2")write("cross pipes creating function")CASE("EX_3")write("slot modeling function")END SWITCHEND FUNCTIONEND CLASS3.*******弹出对话框程序编写*******#include "appforms.p"CLASS plateForm/*定义控件变量*/CLASSWIDE WIDGET form_id,dataBox1,dataBox2,dataBox3,@apply_button,cancel_button,delete_button/*初始化对话框,必要的函数*/FUNCTION init()real x_loc,y_loc/*创建对话框窗体ui_form_create(callback,x,y,position,width,height,label,[unused])*/form_id=ui_form_create("",FORM_X_LOC,FORM_Y_LOC,"UL",FORM_WID_SML,FOR M_HGT_FULL,"PLATE WITH A HOLE","")/*创建图标*/x_loc=FRAME_WID_SINGLE/2.-200*PIXEL_WID/2.+FORM_L_MARGINy_loc=FRAME_T_MARGIN+INTER_WIDGET_SPACE/*ui_labelicon_create(parent,callback,x,y,label)*/ui_labelicon_create(form_id,"",x_loc,y_loc,"platehole.icon")y_loc+=200.*PIXEL_HGT+DBOX_HGT_NO_LABOVE+INTER_WIDGET_SPACE/*创建输入文本框ui_databox_create(parent,callback,x,y,label_length,box_length,width,height,label,value,label_abo ve,datatype,num_vars)*/dataBox1=ui_databox_create(form_id,"",FRAME_L_MARGIN,y_loc,SINGLE_SPACE*5.0, DBOX_WID_SINGLE*0.6,"r=",2.,FALSE,"REAL",1)y_loc+=DBOX_HGT_NO_LABOVE+INTER_WIDGET_SPACEdataBox2=ui_databox_create(form_id,"",FRAME_L_MARGIN,y_loc,SINGLE_SPACE*5.0, DBOX_WID_SINGLE*0.6,"w=",5.,FALSE,"REAL",1)y_loc+=DBOX_HGT_NO_LABOVE+INTER_WIDGET_SPACEdataBox3=ui_databox_create(form_id,"",FRAME_L_MARGIN,y_loc,SINGLE_SPACE*5.0, DBOX_WID_SINGLE*0.6,"h=",5.,FALSE,"REAL",1)y_loc+=DBOX_HGT_NO_LABOVE+INTER_WIDGET_SPACE*2/*创建“应用”按钮ui_button_create(parent, callback, x, y, width, height, label, [unused], highlight)*/apply_button=ui_button_create(form_id,"apply_cb",BUTTON_HALF_X_LOC1,y_loc,BUT TON_WID_HALF,0,"应用",TRUE,TRUE)/*创建“取消”按钮*/cancel_button=ui_button_create(form_id,"cancel_cb",BUTTON_HALF_X_LOC2,y_loc,BU TTON_WID_HALF,0,"取消",TRUE,FALSE)y_loc+=DBOX_HGT_NO_LABOVE+INTER_WIDGET_SPACE/*创建“删除”按钮*/delete_button=ui_button_create(form_id,"delete_cb",BUTTON_HALF_X_LOC1,y_loc,BUT TON_WID_HALF,0,"Delete",TRUE,FALSE)y_loc+=BUTTON_DEFAULT_HGT+FORM_B_MARGIN+INTER_WIDGET_SPACE ui_wid_set(form_id,"HEIGHT",y_loc)END FUNCTION/*窗体显示,必要的函数*/FUNCTION display()ui_form_display("plateForm")END FUNCTION/*“应用”按钮响应处理函数*/FUNCTION apply_cb()real r,w,hui_wid_get(databox1,"V ALUE",r)ui_wid_get(databox2,"V ALUE",w)ui_wid_get(databox3,"V ALUE",h)ui_form_hide("plateform")ui_writec("r =%f,w=%f,h=%f",r,w,h)END FUNCTIONFUNCTION cancel_cb()ui_form_hide("plateform")END FUNCTIONFUNCTION delete_cb()ui_form_delete("plateform")END FUNCTIONEND CLASS4.C++文件编译处理例如:d:\msc\patran2001r2\bin\cpp -id:/msc/patran2001r2/customization c:/uillist.pcl c:/uillist.cpp 5.编程格式介绍转行继续符:@分号分隔符:同C++:“;”注释多行:/*……*/注释单行:“#”或者“$”计算表达式说明:用“`”(数字1键左边的那个键)例如:Angle:`360/5`,或者用WRITE(10+20)变量和常量Integer(整型),Real(实数),Logical(TRUE和FALSE),String,Widget(控件,有个常量WIDGET_NULL)变量的生命周期Global 全局Local 在函数内,本地Static 静态,patran退出就消失ClassWide 对一组函数可见,patran退出就消失6.指令文件管理!! input file.pcl #编译连接file.pcl,并将函数调入patran!!compile file.pcl into xxx.plb #编译file.pcl,并存入plb库中!!library xxx.plb #将plb文件调入patran!!path Directory #指定打开文件的目录!!Trace option pcl #执行确认!!Debug option #保存注释!!options option #pcl环境设置!!size code newsize #为编译代码区设置大小!!clear global name #删除全局变量定义!!clear function name #删除函数定义。
patran建模步骤 -回复

patran建模步骤-回复Patran建模步骤Patran是一款常用的有限元前后处理软件,用于建立有限元模型、进行前处理工作、对有限元计算结果进行后处理分析。
在进行Patran建模过程中,一般可以分为以下几个步骤。
步骤一:准备工作在进行Patran建模之前,需要准备相关的几何模型和材料数据。
对于复杂的几何模型,可以使用CAD软件绘制,并导入到Patran中;对于简单的几何模型,也可以在Patran中直接建立几何模型。
此外,还需要准备材料的物理性质数据,例如弹性模量、泊松比等。
步骤二:创建几何模型在Patran中创建几何模型的方法有多种,可以通过导入CAD文件、绘制几何形状等方式来实现。
如果是导入CAD文件,可以选择几何模型文件的格式(例如IGES、STEP等),然后按照相关提示导入CAD文件。
如果是在Patran中直接绘制几何模型,可以使用构建几何体的命令(例如点、线、平面、体等)来创建几何形状,并按照设计要求对几何模型进行编辑和变形。
步骤三:创建网格模型在Patran中创建网格模型是进行有限元分析的关键步骤。
网格模型的生成可以通过网格剖分来实现,可以选择不同的网格剖分算法和参数,以获得满足分析要求的网格模型。
在Patran中,可以使用自动剖分命令,也可以使用手动剖分命令来创建网格模型。
自动剖分命令一般适用于简单几何形状,而手动剖分命令适用于复杂几何形状。
在进行网格剖分时,还需要设置网格尺寸、单元类型、局部剖分等参数。
步骤四:定义边界条件在进行有限元分析之前,需要定义边界条件。
边界条件包括加载边界条件和约束边界条件。
加载边界条件是指施加在模型上的外部荷载,例如力、压力、温度等。
约束边界条件是指模型的约束条件,例如支撑、固定、禁止位移等。
在Patran中,可以通过加载定义命令和约束定义命令来分别定义加载边界条件和约束边界条件。
例如,可以选择加载的单元或节点,然后定义加载类型和大小;对于约束条件,可以选择需要约束的节点或边等,然后定义约束类型和大小。
精典材料Patran的PCL用户手册V20

MSC.Patran PCL HandbookIn a Nutshell (7)What is PCL? (7)What can PCL be used for? (8)How does PCL work? (9)All you really need to know is on this page! (10)Documentation (10)PCL for Everyone (11)Entering Equations (11)Entering Data (12)Session Files (13)Rebuilding Models (14)PCL for the More Adventurous (17)Parametric Modeling (17)Adding a Graphical User Interface, GUI (21)Exercise 1: Session Files (22)PCL Programming Basics (24)Overview (24)PCL Expressions (26)Expressions, Comments, Syntax Tips (26)Identifiers (28)Naming Conventions (28)Variable / Function Scope (29)Structure of a PCL Function (30)Function Basics (30)Simple PCL function Example (31)Exercise 2: Hello World! (33)Exercise 3: Effective PCL (34)PCL Operators (35)String comparisons (35)PCL Variables and Constants (36)Datatypes (36)Variable Scope (37)Directly Allocated Arrays (38)Virtual arrays (39)Virtual strings (41)Loop Control Statements (42)For Loop (42)While Loop (42)Repeat Loop (43)BREAK (44)CONTINUE (45)Exercise 4: Writing Files (46)Exercise 5: Reading Files (48)Conditional Control Statements (49)IF Statement (49)SWITCH Statement (50)Structure of a PCL Function (51)Compiling and Linking PCL Functions (54)Primary PCL Directives (55)Compiling PCL outside of MSC.Patran (59)Linking Compiled Libraries (60)Other PCL Directives (61)Start Up Files (62)Exercise 6: p3epilog.pcl (63)Debugging (64)Debugging Compile Errors (64)Debugging Runtime Errors (65)Accessing PCL Functions (67)From The Command Line (67)From Any MSC.Patran Form (68)PCL Functions with Field Variables (69)MSC.Patran Built-In Functions (70)Naming Conventions for Applications (71)Naming Conventions for Other Operations (72)Exercise 7: Group Elements By Shape (74)Graphical User Interface (75)The PCL Class Statement (76)PCL Widgets (77)Required Functions for Building/Displaying a Form (78)The init() Function (78)The display() Function (79)Widget Callbacks (82)What Are They? (82)What Are They Used For? (83)Callback Arguments (Widget Function Data) (83)Widget Placement (85)Widget Variables (87)Modifying Widgets (88)Getting Data from Widgets (89)Putting it all Together (Example) (90)Exercise 8: Simple Form (92)The C-Preprocessor and Include Files (93)Make Files (94)Exercise 9: Callbacks (96)Handling Errors and Messaging (98)Errors from Built-In Functions (98)Custom Error Messages (99)Using User Messages Database (99)Without a Messages Database (100)Taking Advantage of the UNDO Feature (102)Select Mechanism (103)Select Mechanism GUI Mechanics (103)Select Databoxes, Select Frames, and Select Menus (103)GUI PCL Example (105)List Processor (106)List Processor Mechanics (106)All You Really Need to Know (107)Exercise 10: Form to Group Elms By Shape (110)Executing Programs Outside of MSC.Patran (112)Spawning Remote Processes (112)Locking a database (114)Using C and Fortran executables to access a MSC.Patran database directly. (115)External Access of an MSC.Patran Database (116)Special Widgets (118)File Widget (118)Spreadsheet Widget (121)Exercise 11: File Widget (122)Adding Help/Description to your PCL (123)Percent Complete (124)Functions (124)Example (124)Event Manager (125)General (125)Functions (126)Example (126)Primitive Graphics (127)Graphic Objects (127)Graphic Segments (128)Example (129)Another Example (130)Exercise 12: Primitive Graphics (131)MSC.Patran Customization (132)Adding Utility Programs to the Main Menu (132)Example (133)Example: p3_user_menu.my_menu.def (134)Customizing the MSC.Patran Toolbar (135)Exercise 13: Pulldown Menu (138)Exercise 14: Toolbar (139)Some Final Thoughts (141)Appendix A (144)Built-in Function Examples (144)Documentation for a typical MSC.Patran built-in function. (145)To get all the nodes and their global coordinates (146)To get the topology of every element (147)To get the shape of every element (148)To get all the element connectivity for all elements (149)To get the elements associated to a particular element property set (150)To get an element property value (shell thickness) for a specific element (151)To get a material property value (153)To get a list of all groups (154)To get the nodes and elements associated to the current group (154)To get result values for specified elements (155)Appendix B (164)Strings & String Functions (164)Declaration (165)Initialization (165)String Comparisons (165)Functions (166)Appendix C (174)Noteworthy Functions (174)sys_mov e_raw(...) (175)mth_array_search(...). (176)mth_sort(...) . (177)mth_sort_row(...).. (178)mth_sort_column(...) . (178)fem_geom_edge_length(...) .. (179)fem_geom_face_area(...). (179)fem_geom_elem_volume(...). (179)fem_geom_elem_location(...) .. (180)Appendix D (181)Form Spacing Parameters (appforms.p) (181)* SPACING (182)Appendix E (205)MSC.Patran Architecture (205)Appendix F (207)Shareware Compiling Functions (207)Appendix G (210)Parametric Patran (210)Appendix H (216)Additional List Processor Notes (216)List Processor Mechanics (217)List Processor Functions (217)List Processor Sublist Functions (219)List Processor Attribute Functions (220)Miscellaneous List Processor Functions (220)List Processor Examples (222)Easy to Use List Processor Functions (226)Appendix I (227)Key Mapping (227)Appendix J (230)Widget Classification (230)Appendix K (233)User Defined AOM (233)In a NutshellWhat is PCL?❑PCL stands for Patran Command Language❑Comprehensive, fully functional computer programming language❑Specifically and uniquely suited for MCAE applications ❑Delivered as a part of MSC.Patran❑Versatile and easy to useWhat can PCL be used for?❑Integrate application or site-specific programs with the MSC.Patran user interface and database❑Generate parametric/variational models for design/optimization ❑Integrate commercial and/or in-house analysis codes with MSC.Patran❑Display custom graphics❑Access the MSC.Patran database❑Create new and/or enhanced MSC.Patran functionality❑Database management for analysis files❑Eliminate tedious, repetitive proceduresHow does PCL work?❑All MSC.Patran commands are first interpreted by the PCL command interpreter❑PCL expressions are interpreted by a C program❑PCL functions can be compiled into libraries (more efficient binary representation) and “linked” with a MSC.Patran session❑“Built-in” PCL functions are written in C or FORTRAN❑MSC.Patran forms and menus can be created via PCL calls to Xlib, the X-window function library❑FORTRAN and C functions can be “linked” with MSC.Patran through PCLAll you really need to know is on this page! Documentation❑PCL and Customization - General programming guide for PCL.How to build forms, compile, manage libraries, access thedatabase, read/write files, etc.❑PCL Reference – Description of functions written to the session file.❑Develop: The MSC.Patran Toolkit – Documentation of additional functions for database access, etc.PCL for Everyone Entering EquationsUse of PCL when creating spatial fields:‘X + ‘X**2 –sinr(‘X)The PCL interpreter interprets anythingimmediately following a ‘ symbo l as afield variable as opposed to a PCLfunction, such as, sinr().Entering DataUse of PCL when entering geometric coordinates: [ `5./16.` 0 0 ]The PCL interpreter “evaluates” expressions enclosed in back tics, “`”.Other examples:[ `radius/length` 0 0 ]< `cosr(theta)` 1 1 >[ `MyFunction(radius)` 0 1 ]Session FilesSession and journal files are comprised entirely of PCL commands. Model changes (dimensions, mesh density, etc.) can be made quickly by editing and then replaying the session or journal files.$# Session file patran.ses.01 started recording at 16-Aug-01 14:33:54$# Recorded by: MSC.Patran 2001STRING asm_create_patch_xy_created_ids[VIRTUAL]asm_const_patch_xyz( "1", "<10 10 0>", "[0 0 0]", "Coord 0", @asm_create_patch_xy_created_ids )$# 1 Patch created: Patch 1STRING sgm_edit_surface_add_h_edit_ids[VIRTUAL]sgm_edit_surface_add_hole( 1, 1., TRUE, "", "[5 5 0]", "", "Surface 1", @sgm_edit_surface_add_h_edit_ids )$# 1 Surface Edited: Surface 1$# Session file patran.ses.01 stopped recording at 16-Aug-01 14:34:52Rebuilding ModelsThe following session file creates a trimmed surface, 10” x10”with a 1” diameter hole at the center. Note that the parameter that controls the diameter of the hole is indicated below.$# Session file patran.ses.01 started recording at 16-Aug-01 14:33:54$# Recorded by: MSC.Patran 2001STRING asm_create_patch_xy_created_ids[VIRTUAL]asm_const_patch_xyz( "1", "<10 10 0>", "[0 0 0]", "Coord 0", @asm_create_patch_xy_created_ids )$# 1 Patch created: Patch 1STRING sgm_edit_surface_add_h_edit_ids[VIRTUAL]sgm_edit_surface_add_hole( 1, 1., TRUE, "", "[5 5 0]", "", "Surface 1", @ sgm_edit_surface_add_h_edit_ids )$# 1 Surface Edited: Surface 1$# Session file patran.ses.01 stopped recording at 16-Aug-01 14:34:52In the session file below, the previous session file is edited to change the hole diameter from 1” to 4”$# Session file patran.ses.01 started recording at 16-Aug-01 14:33:54$# Recorded by: MSC.Patran 2001STRING asm_create_patch_xy_created_ids[VIRTUAL]asm_const_patch_xyz( "1", "<10 10 0>", "[0 0 0]", "Coord 0", @asm_create_patch_xy_created_ids )$# 1 Patch created: Patch 1STRING sgm_edit_surface_add_h_edit_ids[VIRTUAL]sgm_edit_surface_add_hole( 1, 4., TRUE, "", "[5 5 0]", "", "Surface 1", @ sgm_edit_surface_add_h_edit_ids )$# 1 Surface Edited: Surface 1$# Session file patran.ses.01 stopped recording at 16-Aug-01 14:34:52Session files can be executed or “played” by selecting File/Session/Play … from the top menu.PCL for the More Adventurous Parametric Modeling❑Session files can be parameterized by defining and using variables during the MSC.Patran session❑First, variables are declared and initialized via the MSC.Patran command lineSecond, the variables are used as input into the appropriate MSC.Patran forms (note the use of ` `, back tics)Upon application, the PCL interpreter evaluates `radius` (i.e., sets it equal to 1.0 in this example) and creates the curve. Note that the variable is passed to the session file in its unevaluatedBy using variables as parameters during MSC.Patran input, it is very easy to edit and change dimensions, mesh parameters, etc. in the session file.PCL for the more Adventurous Adding a Graphical User Interface, GUIThe next step might be to create a user interface to run the plate session file!Exercise 1: Session FilesUse MSC.Patran to create a parameterized session file that createsa rectangular surface with an arbitrarily located hole.1) Create variables for the dimensions shown below.2) Steps:a) Create variables using MSC.Patran’s command lineb) Create/Surface/XYZ (use variables length and width)c) Edit/Surface/Add Hole (use x_center, y_center, and diameter) Extra credit: Include error checking, i.e., it doesn’t make sensefor the hole to be outside the surface boundary.IF (x_center + diameter/2.0 > length) THEN RETURNExtra credit: Include meshing, boundary conditions, elementproperties, etc.Extra credit: Use ui_read_real(prompt) to enter the variablevalues interactivelyExtra credit: Turn your session file into a PCL FUNCTION.Exercise 1 Below is an image showing an MSC.Patran form allowing the interactive creation of the model for this exercise.NB – See Appendix G for notes about Parametric Patran.1) Variables and macros are defined interactively via a GUI2) Variables and macros are persistent3) Plus, more. See Appendix G for the detailsPCL Programming Basics Overview❑PCL is a full-featured programming language.❑Operators for arithmetic, relational, and string expressions.Examples include:❑Variables with type, scope, and dimension attributes INTEGER i, j, status, NodeIds(1000)LOGICAL flagREAL xyz(1000, 3), pressure(100), timeGLOBAL STRING my_group[32], all_groups[32](100)❑Dynamically allocated virtual strings and arraysINTEGER node_ids(VIRTUAL)STRING groups[32](VIRTUAL), MyString[VIRTUAL]❑Intrinsic functions for math, string manipulation, etc.sinr(angle)cosd(angle)mth_abs(MyVal)mth_sort(MyArray, CompactDuplicates, NumLeft)mth_array_search(MyArray, Look4, Sorted)str_length(MyString)str_substr(MyString, Position, SubStringLength)str_index(StringToSearchIn, StringToSearchFor)str_token(MyString, Delimiter, TokenNumber, [Compress])PCL Programming Basics ❑Loop control features, such as, WHILE, FOR, REPEAT, and LIST❑Conditional control structure, such as, IF-THEN-ELSE and SWITCH-CASE❑Subroutine (procedure) and function (command) calls❑Class grouping of related functions❑Read/write access to external ASCII and/or binary filestext_open(FileName, Options, 0, 0, FileId)text_read_string(FileId, InString, InStringLength)text_write_string(FileId, OutString)text_read(FileId, Format, MyIntegers, MyReals, MyChar)text_write(FileId, Format, MyIntegers, MyReals, MyChar)text_close(FileId, Options)file_exists(FileSpec, Options)file_delete(FileSpec)❑Access to MSC.Patran “built-in” functions that allow for direct access to the MSC.Patran database, geometry creation,drawing graphic primitives,db_count_nodes(NumNodes)db_get_node_ids(NumNodes, NodeIds)asm_const_grid_xyz(output_ids, coordinates_list, coord_frame, @created_ids)PCL Expressions Expressions, Comments, Syntax Tips❑Sample PCL expressions include:theta = 360.0 – MTH_ASIND(MyAngle)IF (radius >= 20.0) THEN radius = 20.0length = str_length(MyString)build_gear_geometry(30., 56., 3)❑PCL comments begin with a “/*” and end with a “*/”/*This is a comment.Look Ma, I’m making comments in PCL!Has anyone seen or heard from Elvis lately?*/a = 2 /* set mysterious factor equal to 2 */❑Alternatively, single line comments may begin with “$”$ Don’t you just hate to comment your programs?❑More than one PCL expression can co-exist on a line using a semi-colon, “;”alpha = 30.0; beta = 120.0❑PCL expressions can be continued on subsequent lines by using the “@” symbolui_wid_set(main_form, @“HEIGHT”, @NewHeight)ui_wid_set( /* widget_id */ main_form, @/* parameter */ “HEIGHT”, @/* value */ NewHeight)PCL Expressions ❑Don’t break expressions in the middle of a keyword, constant, or identifier❑Multiple blanks are the same as a single blank space❑Lines beginning with “!” (bang operator) are echoed to the xterm (UNIX) or command window (NT), but are not executedIn MSC.Patran type: !`i` nodes createdIn the xterm you see: %27 nodes created❑PCL expressions beginning with “>” are echoed to the session file❑PCL expressions can be typed directly into MSC.Patran at the command line❑PCL expressions may also be created with an editor in a text file and directed into MSC.Patran as a session file or by using the PCL directive !!INPUTIdentifiersNaming Conventions❑Function names and/or variable names are called identifiers ❑Can be up to 32 characters long❑Must begin with a non-digit❑Case insensitive (as is all of PCL)❑Cannot be a reserved keyword, i.e., FOR, IF, etc.❑Valid identifierscurrent_groupCurrentGroupMyString❑Invalid identifiersa_very_very_very_very_very_very_very_very_long_name 95abclistIdentifiers Variable / Function Scope❑Global variable names and functions share the same name space❑When two function names or two variable names conflict, the most recent addition supercedes the previous❑When function names and variable names conflict, the variable name takes precedence❑When compiling functions, PCL will indicate if a function name is superceded by writing “Cleared memory function” to thehistory window❑Hint: Use a unique prefix to keep function definitions separate,i.e au_do_this_and_that.pclStructure of a PCL Function Function Basics❑PCL functions begin with a FUNCTION statement and end with an END FUNCTION statement.❑The FUNCTION statement may contain an argument list to be passed in or out of the function.❑An optional RETURN statement can be used to return a calculated value from the function to the calling statement.❑Processing of the function terminates at either the END FUNCTION statement or a RETURN statement.❑There may be multiple RETURN statements within a single function.Simple PCL function Exampleanother_simple_function(29)$#My favorite number is 29$#My least favorite number is 13Sample output. The ui_write functions writetext to the history window, the session file(patran.ses.##), and the journal file(model.db.jou)Exercise 2: Hello World!Write and execute a PCL function that accepts a single real number argument and echoesHello World, my favorite number is ….to the MSC.Patran session file and history window.Your function will use either the ui_write(…),ui_writef(…), or ui_writec(…) functions.If you use the ui_writef(…) and ui_writec(…) functions, refer to the documentation for the correct format specifiers.Extra credit: How would this function change if you wanted to echo your favorite 10 numbers to the session file? Extra credit: How would this function change if you wanted to echo your favorite color to the session file?Exercise 3: Effective PCLWrite an essay on how the effective use of PCL could:a) Help create a lasting world peaceb) Eliminate world hungerc) Conquer the common coldd) Stop global warmingExtra credit: How could PCL be used to find Elvis?PCL OperatorsExamplesDist = mth_sqrt((x2-x1)**2 + (y2-y1)**2 + (z2-z1)**2) MyString3 = MyString2//”hijk”IF (a == b) THEN c = dIF (a == b && a == c) THEN ui_write(“Equilibrium”)x += 1 (this is equivalent to x = x +1)String comparisons❑The string comparison operators are special in that they ignore trailing blanks and uppercase and lowercase. Therefore, all of the following expressions are TRUE“ABC” == “ABC ““ABC” == “abc”❑Leading blanks are compared, i.e., “TEST” != “ TEST”❑To perform case sensitive comparisons use the str_equal() function, i.e.,IF (str_equal(GroupName1, GroupName2)) THEN RETURN 0PCL Variables and Constants Datatypes❑LOGICAL Boolean value: TRUE or FALSELOGICAL done, created31-1)❑INTEGER Value between +/- (2INTEGER i, num_nodes, node_id❑REAL Single precision floating value between 1.0E-30 and1.0E+30 (positive or negative)REAL x, y, z, force, pressure❑STRING Character string surrounded by double quotes, “Have you seen Elvis?”. Size or string length is defined with brackets, [ ]STRING FileName[80], GroupName[32]❑WIDGET Value is assigned by calls toUI_WIDGET_NAME_CREATE(…), used to create andmanipulate forms, etc.WIDGET main_form, MyButton, group_lboxVariable Scope❑GLOBAL Available to all functions during the MSC.Patransession❑LOCAL Default, only visible within the defining function ❑STATIC Same as LOCAL, but retains its value betweencalls❑CLASSWIDE Available to all functions in the CLASS andretains its value during the MSC.Patran sessionDirectly Allocated Arrays❑Directly allocated arrays can have any number of subscripts (dimensions), defined within parentheses ()❑Assigned upper and lower bounds, ArrayName(Lower:Upper)INTEGER MyArray(2:10)❑ Default lower bound is 1 (not 0) ❑ Available for all datatypes❑Row major (unlike Fortran which is column major)INTEGER MyArray(2, 3) = 1, 2, 3, 4, 5, 6❑Array dimensions are inherited from the argument list, i.e., PCL passes by reference❑Declaration ExamplesREAL displacements(6, 200) STRING group_names[32](20) INTEGER ids(0:2, 0:4, 0:10) LOGICAL exists(12)Virtual arrays❑Any variable can be defined as a VIRTUAL array instead of a directly allocated array. Virtual arrays do not have storagelocations assigned to them at program initialization. The size and amount of storage is allocated as requested and can bereused for other virtual arrays.❑To declare a virtual array, use the keyword VIRTUAL in place of the subscripts for the declaration, i.e.,REAL MyVals(VIRTUAL)INTEGER NodeIds(VIRTUAL)❑Storage is allocated using the function, sys_allocate_array(), or sys_allocate_array(MyVals, 1, 300)sys_allocate_array(MyVals, 1, 300, 1, 3)sys_allocate_array(MyVals, 1, 300, 1, 3, 0, 5)etc.❑Storage may be reallocated using the function,sys_reallocate_array(),sys_reallocate_array(MyVals, 1, 300, 1, 3)❑Storage may be freed using the function, sys_free_array(), sys_free_array(MyVals)Virtual array examplePCL Variables and Constants Virtual strings❑Any string variable can be defined as a VIRTUAL length string instead of a fixed length string. Virtual length strings do nothave storage locations assigned to them at programinitialization. The string length is allocated as requested and can be reused.❑To declare a virtual length string, use the keyword in place of the subscripts for the declaration, i.e.,STRING picklist[VIRTUAL]❑The string length is allocated using the sys_allocate_string() functionsys_allocate_string(picklist, 1000)❑The string length may be modified using thesys_reallocate_string() functionsys_reallocate_string(picklist, 2000)❑The string storage may be freed using the sys_free_string() functionsys_free_string(picklist)❑ A virtual length string can also be a virtual array, i.e., STRING picklists[VIRTUAL](VIRTUAL)Loop Control StatementsFor Loop❑SyntaxFOR (var=numeric_expr TO numeric_exprnumeric_expr label statements … END FOR❑ExampleAvgTemp = 0.0FOR (i = 1 TO NumNodes) AvgTemp += NodalTemp(i) END FORAvgTemp = AvgTemp/NumNodesWhile Loop❑SyntaxWHILE (logical_expression ) [label ] statements … END WHILE❑ExampleAvgTemp = 0.0 i = 1WHILE (i <= NumNodes)AvgTemp += NodalTemp(i) i += 1 END WHILEAvgTemp = AvgTemp/NumNodesRepeat LoopThis is similar to a WHILE Loop except that it will always be executed at least once. Only use REPEAT loops if you want to ALWAYS execute the loop at least once, otherwise us a WHILE loop.❑SyntaxREPEAT [label]statements …UNTIL (logical_expression)❑ExampleAvgTemp = 0.0i = 1REPEATAvgTemp += NodalTemp(i)i += 1UNTIL (i > NumNodes)AvgTemp = AvgTemp/NumNodesBREAKThe BREAK statement is used to exit a loop prior to its normal termination. It can be used in any of the loop statements.BREAK [❑END WHILE…❑Example 2 (nested loops, using labels)WHILE (i <= NumNodes) MainLoopWHILE (j <= 100) AnotherLoopWHILE (k <= 200) InnerLoopIF (status != 0) THEN BREAK MainLoopIF (status != 0) THEN BREAK AnotherLoopIF (status != 0) THEN BREAKIF (status != 0) THEN BREAK InnerLoopEND WHILEEND WHILEEND WHILECONTINUEThe CONTINUE statement is used to skip to the end of the loop ❑SyntaxCONTINUE [label]❑Example 1 (reading a text file)INTEGER file_id, lengthSTRING read_str[80]/* read grid information */WHILE (text_read_string(file_id, read_str, length) == 0)END WHILE❑Example 2 (nested loop, using labels)WHILE (i <= NumNodes) MainLoopREPEAT InnerLoopCONTINUE MainLoopBREAK InnerLoopCONTINUECONTINUE InnerLoopUNTIL (j > 1000)END WHILEstatements …Exercise 4: Writing FilesCreate a PCL function to write nodal data to a user-defined file. 1) The function should have a single argument, the filename to becreated, i.e., FUNCTION write_nodes_to_file(FileName)2) The data should be written to the file as a table, i.e.,Node Id x-coordinate y-coordinate z-coordinate3) Use virtual arrays4) Use the following built-in functions:db_count_nodes(NumNodes)db_get_node_ids(NumNodes, NodeIds)db_get_nodes(NumNodes, NodeIds, rcids, acids, NodeXYZ)text_open(FileName, Options, idum, idum, FileId)text_close(FileId, Options)text_write(FileId, Format, Ints, Reals, Chars)text_write_string(FileId, OutString)5) Use the documentation if you have questions about thearguments to the built-in functions.6) Think about your choice for the format argument in thetext_write(…) function. Will your file be comma or spacedelimited? Will it be fixed or free format?7) Sample code outline:a) Declare variablesb) Count nodes in the databasec) Allocate arraysd) Get node Idse) Get node coordinatesf) Open fileg) Write data to the file with a looph) Close filei) Be sure to include a message that the file output is completeWriting Files Extra credit: Include a header line at the top of the file thatincludes the filename and the total number of nodeswritten to the file.Exercise 5: Reading FilesWrite a function to read the file created in Exercise 4.1) The function should accept a single argument, i.e., the filenameto be read.FUNCTION ReadFile(FileName)2) Use the data in the file to create nodes with the following built-in function from the PCL Reference Manual:fem_create_nodes_1(RefCIDList, AnalysisCIDList, GeomFlag, @NodeIDList, XYZList, NodesCreatedList)3) Use the following built-in functions:text_open(FileName, Options, idum, idum, FileId)text_close(FileId, Options)text_read(FileId, Format, Ints, Reals, Chars)4) Sample code outline:a) Declare variablesb) Open the filec) Read the file within a loopd) Create new nodes as the file is read within the loope) Close the fileExtra credit: What if a node ID to be created already exists in the database?Extra credit: What if the file to be read doesn’t exist? Whatfunction can be used to determine if a file exists? Extra credit: Searching the documentation reveals anotherfunction that can be used to create nodes, i.e.,db_create_nodes(num_nodes, rcids, acids, xyz, group_id,node_ids, node_exists). Why might you use thisfunction versus fem_create_nodes_1(…)?Conditional Control Statements IF Statement❑SyntaxIF (logical_expression) THENstatements …ELSE IF (logical_expression) THENstatements …ELSEstatements …END IF❑ExampleIF (MyKeyWord == “CBAR” || MyKeyWord == “CBEAM”) THEN statements …ELSE IF (MyKeyWord == “CTRIA” || MyKeyWord == “CQUAD”) THEN statements …ELSE IF (MyKeyWord == “GRID”) THENstatements …ELSEstatements …END IF。
Patran二次开发工具PCL系列教程之9

PAT304 Course Notes – Release 9.5 Copyright 2001 MSC.Software Corporation
9-7
PATRAN 2.5 Results Files
There are three formats of PATRAN 2.5 results files that can be imported into MSC.Patran • • • Element Results File (.els) Nodal Results File (.nod) Displacement Results File (.dis)
PAT304 Course Notes – Release 9.5 Copyright 2001 MSC.Software Corporation
9-5
Results Retrieval
Main way to access results in PCL is with res_utl_extract_[type]_results res_utl_extract_nodal_results() requires an integer array of 5 values to define the desired results: • Loadcase ID – res_utl_get_loadcases() • Subcase ID – res_utl_get_subcases() • Primary Result Case ID – res_utl_get_result_ids() • Secondary Result Case ID – res_utl_get_result_ids() • Layer ID – res_utl_get_layers()
patran二次开发语言

3. PCL函数库 函数库 4. PCL编译和连接 编译和连接
方式: 命令行; 方式 1)Patran命令行;2) p3cplcomp; 3)make 命令行 Patran命令行和 p3pclcomp方式 命令行和 方式 !!input <filename>.pcl 编译、连接 编译、连接filename.pcl,并将函数调入 ,并将函数调入Patran 直接运行文件中的函数 !!Compile <filename>. pcl !!Library xxx.plb Make 创建完程序后,键入 自动编译并存入库中, 创建完程序后,键入Make, Patran自动编译并存入库中,但第一次 自动编译并存入库中 用make须给出 须给出Makefile 文件 须给出 编译filename.pcl,并将其存入xxx.plb中 ,并将其存入 编译 中 将库调入Patran, 调入后可执行该函数 将库调入
PCL功能 功能
用小程序, ◆编制Patran用小程序,扩展 编制 用小程序 扩展Patran功能 功能 ◆把自己的分析程序集成到Patran统一环境中,用Patran做前后处理,象NASTRAN, 把自己的分析程序集成到 统一环境中, 做前后处理, , 统一环境中 做前后处理 ABAQUS,DYNA3D一样 , 一样 的模型作参数化研究, ◆对Patran的模型作参数化研究,针对特殊工程问题,建立统一参数化模型 的模型作参数化研究 针对特殊工程问题, ◆方便地编制“傻瓜”界面,供设计工程师和新手使用 方便地编制“傻瓜”界面,
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
The default NT toolbars contain 32 icons
PAT304 Course Notes – Release 9.5 Copyright 2001 MSC.Software Corporation
8-3
PATRAN Default Toolbar Icons
PAT304 Course Notes – Release 9.5 Copyright 2001 MSC.Software Corporation
PAT304 Course Notes – Release 9.5 Copyright 2001 MSC.Software Corporation
8-8
PATRAN Toolbar Functions
*CLASS and *FUNCTION specify the function that is to be used by the Icon in the Toolbar. CLASS and FUNCTION definitions can be specified by creating relatively simple PCL functions. PCL functions that reside within a user defined class are made available by referencing the library in the user’s p3epilog.pcl file.
Lecture 8 Customizing: Toolbar, p3printers.def, Keymapping, Creating an Analysis Preference
PAT304 Course Notes – Release 9.5 Copyright 2001 MSC.Software Corporation
$
= 100 %
Image Size = Fit on Page, As Is Scale Factor = No Show; 1.0 Center = No Show; Yes Draw Borders $ Note use of “No Show” and a default
= Yes, No
8-10
p3printers.def (cont.)
The driver is also displayed in the p3printers.def file An example is shown below:
..........Driver Specific Options.................. Format Black to White, White to Black, Color Background White, Black, Actual Lines & Text = White, Black, Actual; Black Line Weight = 0.5 pts Text Scale $ Note use of default = $ another option is “Grayscale” =
The printers available on NT need to be set up through starndard Windows configuration. An example of the format is shown below: $This is the Default Postscript Printer Printer
End Toolbar
PAT304 Course Notes – Release 9.5 Copyright 2001 MSC.Software Corporation
8-6
PATRAN Toolbar Control File (cont.)
The icons can be found in Patran_install_dir/icons directory. • • *CLASS indicates where to find the function for the icon. *FUNCTION indicates which function will be executed when the icon is selected. *HELP indicates the help bubble that will be displayed when the mouse moves over the icon.
•
There is also an option for whether or not to load the icon into the toolbar when PATRAN is executed. – In order for the icon to load into MSC.Patran, – *LOAD ITEM must be added after the *HELP call.
8-7
PATRAN Toolbar Icons
*ICON specifies the icon that is to be used in the Toolbar form.
The icons are restricted to a 40x40 bitmap format (typically 28x28 for UNIX or 16x16 for NT). Icons can be created using various UNIX bitmap utilities or Paint for NT. A toolbar icon template (UNIX) is supplied with MSC.Patran and can be used to create user-defined icons. • tbblank.28.icon
8-4
PATRAN Default Toolbar Icons (cont.)
PAT304 Course Notes – Release 9.5 Copyright 2001 MSC.Software Corporation
8-5
PATRAN Toolbar Control File
The Toolbar on the main form is configured by the p3toolbar.def file. p3toolbar.def is located in the MSC.Patran installation directory. The file is read in sequential order when the p3toolbar is displayed. • i.e., top to bottom in the file refers to the icons left to right on the toolbar
The user defined icons must be referenced in the p3toolbar.def file and must be in MSC.Patran’s path p3toolbar.def must be in either the Patran_install_dir or the users home directory
= Postscript Default
Print Orientation = Portrait, Landscape; Landscape $ Note use of default
PAT304 Course Notes – Release 9.5 Copyright 2001 MSC.Software Corporation
p3toolbar.def file example: Start Toolbar = Transform *ICON= tbrotatexy.bmp *CLASS= uil_toolbar *FUNCTION= rotate_xy *HELP= Mouse Rotate XY *LOAD ITEM
Quality = No Show; Normal Color Model = No Show; RGB GCR = No Show; 75 %
PAT304 Course Notes – Release 9.5 Copyright 2001 MSC.Software Corporation
8-11
Device Driver Destination Paper Size Width Height Left Margin Right Margin Top Margin Bottom Margin Default Units Number of Copies = Unknown = Postscript = Unknown = Letter, Custom = 0.0 = 0.0 = 0.5 in = 0.5 in = 0.5 in = 0.5 in = Inches, Points, cm = 1 $ Other units are Picas and mm $ See the documentation for additional sizes $ Default width for Custom paper size $ Default height for Custom paper size
The Start/End Toolbar Lines (NT only) define the boundaries of the dockable toolbars
PAT304 Course Notes – Release 9.5 Copyright 2001 MSC.Software Corporf (UNIX only)