msc培训chapter第十四章PCL语言简介_第1页
msc培训chapter第十四章PCL语言简介_第2页
msc培训chapter第十四章PCL语言简介_第3页
msc培训chapter第十四章PCL语言简介_第4页
msc培训chapter第十四章PCL语言简介_第5页
已阅读5页,还剩10页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1、第十四章 PCL 语言简介14.1 PCL 概述14.1.1PCL?PCL 是一种全功能的计算机编程语言,是 MSC.Patrand Language 的缩写;在安装 MSC.Patran 时,PCL 语言的开发环境可以一起装好;PCL 语言为你提供了大量的函数(几万个),尤其适合于 CAE 应用程序的开发;PCL 语言的语法类似 C 语言,对会用 C 的用户,可以很快读懂 PCL 程序,并开始编制自己的简单的 PCL 程序,扩展 MSC.Patran 的功能;14.1.2PCL 能干什么?PCL 语言允许你方便地编制 MSC.Patran 的应用小程序,扩展 MSC.Patran 的功能。在

2、使用 MSC.Patran 时,PCL 可帮你轻松地完成本来是很繁人的,但重复性程度高的操作。PCL 语言允许你把自己的分析程序集成到MSC.Patran的环境中去,利用 MSC.Patran为你做前后置处理,就象 MSC.Nastran,ABAQUS,DYNA3D 等一样。PCL 语言允许你对 MSC.Patran 的模型作参数化的一的参数化模型。,针对特殊的工程问题,建立统PCL 语言允许你方便地编制“傻瓜”形的界面,供设计工程师和新手使用。14.1.3 PCL 的函数结构PCL 的函数结构如下所示:FUNCTION 函数名称(变量列表)RETURNEND FUNCTION下面是一个最简单

3、的 PCL 程序:FUNCTION simple_function()/*/This is a simple function which write : “$# My favorite number is 1”he history window.EGER numNum = 1Write_line(“My favorite number is ”, num)END FUNCTION14.1PCL 的语法作为一种全功能的语言,PCL 有类似 C 的语则。关于 PCL 的常数,PCL 变量的定义,PCL 的数组,PCL 的分叉控制,循环控制等,这里不作详细介绍,请参考MSC.PatranUsers

4、 Manual第四卷第九部分“PCL and Customization”,那里有详细的说明和例子。14.2PCL 的函数库PCL 强大的功能是通过其丰富的函数库来实现的。一般来说,PCL 的函数库可分成三大类,下面分别介绍:14.3.1 PCL 的基本函数库基本函数库中的函数与一般 C 语言所提供的函数库一致。其中包括:数学函数,数据流、文件输入输出函数,字符串处理函数,系统调用函数,图形绘制函数等等。关于具体每个函数的名称及用法,请查阅MSC.Patran Users Manual第四卷第九部分 2-27 页2-174 页,或查该书最后的索引。下面给出的是一个用这些函数所编制的一个例子。F

5、UNCTION write_number( max_number, leading_text)/*Pure:This function opens an external filehe currentworking directory called records.out and writesmax_number records of a format as follows:*this this this thisthisis is is isisrecord record record recordrecordnumber number number numbernumber12345(if

6、 leading_text isthis is record number and max_number = 5)Input: max_number Ileading_text Smax_number of recordsprefix on each recordOutput: noneSide Effects:The file records.out is either created or the ver and the above described records are written to it.incrementedErrors:Return 0, no errorOtherwi

7、se it is a file utility error*/STRING leading_text, filename80, outstr720EGER max_number, sus, rec, channel/*Build a filename with verexternal file*/numberand open thesus= file_build_fname(,records,out, NV,filename)IF(sus != 0 ) THEN RETURNsussus= text_open( filename,NRW, 0,0, channel )IF(sus != 0 )

8、 THENwrite(Unable to open file/filename)RETURN sEND IFus/* Loop to max_number and write concatenated string*/FOR (rec = 1 TO max_number)outstr s us IF( sEND FOR= leading_text/ /STR_FROM_EGER( rec)= text_write_string( channel, outstr )us != 0 ) THEN RETURN sus/* Close*/the external filetext_close( ch

9、annel, )/*/l user completeui_write(Write_number completed.)ui_write( STR_FROM_filename )RETURN 0EGER(rec-1)/ recordswrittento/END FUNCTION14.3.2读写 MSC.Patran 数据库的 PCL 函数库这是 PCL 所特有的函数库,也是函数最多的一个函数库。通过这些函数,你可以读写 MSC.Patran 数据库中的任何信息,也就是说,通过这些函数,MSC.Patran 完全向你开放了。关于这部分函数的名称及用法,请查阅PCL Reference Manual

10、和MSC.Patran Users Manual第四卷第九部分。下面给出一个例子。FUNCTION lug_create( )/*Pure:Create a 2-dimenal mparametric cubic patches.of a lug withINPUT:GLOBALVARIABLES:radius widthlengthR WRRadius of pin holeWidth of structure around pin hole Length from support to pin center*ERROR:return != 0, error sus from applica

11、tion callSide effects:A 2D lug is created from the specified dimens*/STRING STRING STRING STRING STRING STRINGSTRINGasm_create_grid_xyz_created_idsVIRTUALasm_sp_line_arc_created_idsVIRTUALasm_create_cord_3po_created_idsVIRTUAL asm_transform_line created_idsVIRTUAL asm_create_patch_xy_created_idsVIRT

12、UAL asm_patch_2curve_created_idsVIRTUALasm_transform_patch_created_idsVIRTUALEGER sus/* Create the constructions grid*/sus = asm_const_grid_xyz( 1, radiusasm_create_grid_xyz_created_ids )0 0,Coord0, IF( sus != 0 ) THEN RETURN sus/* Create the line describing the*/inner radius of the lugsus= asm_sp_l

13、ine_arc( 1,0 0 001, asm_s us0 1, 90.,p_line_arc_created_ids0., Coord 0, 1, Pous != 0 ) THEN RETURN s)IF(ssus= asm_sp_line_arc( 2,0 0 002, asm_s us0 1, 90.,p_line_arc_created_ids0., Coord 0, 2, Pous != 0 ) THEN RETURN s)IF(ssus= asm_const_coord_3po( 1, Coord 0, 2, 0 0 0,0 0 1, 1 0 0, asm_create_cord_

14、3po_created_ids ) us != 0 ) THEN RETURN susIF(s/* Construct the outer diameter of the lug*/sus = asm_transform_line_translate( 4, , Coord 1 , 1, TRUE, FALSE, Curve 1 ,asm_transform_line created_ids )IF( sus != 0 ) THEN RETURN sus/* Construct the patches*/sus= asm_const_patch_xyz( 1, , -length 0 0, C

15、oord 0, asm_create_patch_xy_created_ids )IF(sus != 0 ) THEN RETURN sussus= asm_const_patch_2curve_v1( 2, Curve 1 , Curve 4 ,0, , TRUE, asm_patch_2curve_created_ids )IF(sus != 0 ) THEN RETURN sussus= asm_const_patch_2curve_v1( 3, Curve 2 ,Construct 2PoCurve(Evaluate Geometry(Po6 )(Eval /uate Geometry

16、(Po9 ), 0, , TRUE, asm_patch_2curve_created_ids )IF(sus != 0 ) THEN RETURN sussus= asm_const_patch_2curve_v1( 4, Curve 3 , Surface 1.3 ,0, , TRUE, asm_patch_2curve_created_ids )IF(sus != 0 ) THEN RETURN sussus= asm_transform_patch_mirror( 5, Coord 0.2 , 0., TRUE,FALSE, Surface 1:4 , asm_transform_pa

17、tch_created_ids )RETURNsusEND FUNCTION14.3.3 编制 MSC.Patran 风格 Motif 界面的函数库关于这部分函数的名称及用法,也请查阅MSC.Patran Users Manual第四卷第九部分3-1 页4-154 页。有 Motif 界面的 PCL 程序结构比本章 14.1.3 所介绍的要复杂,如下所示:CLASS claameCLASSIWIDE declarations /* Widget ids used to retrieve data */FUNCTION init()END FUNCTION/* called only once

18、: create definition ofand forms*/FUNCTION display()/* display the forms 、theEND FUNCTIONand */FUNCTION refresh()END FUNCTION/*optional,refresh the display*/* other usrovided function */END CLASS应用例子请见本章 14.5。14.4PCL 程序的编译和连接一般把 PCL 程序的后缀取作“.pcl”。PCL 程序在 MSC.Patran 中可通过三种方法来进行编译和连接,即:(1)MSC.Patran 命令

19、行;(2)p;(3)make 。14.4.1“MSC.Patran 命令行”和“p 命令”在“MSC.Patran 命令行”和“下面一起介绍:p 命令”环境下,编译和连接令完全一样,!input.pclMSC.Patran,编 译 和 连 接 filename.pcl , 并 将 函 数 调 入接着直接运行文件中的函数名即执行了该程序。pile .pclo.plb编译 filename.pcl,并将它存放到.plb 库中。!library.plb将库.plb 调入 MSC.Patran。调入 MSC.Patran 后即可执行该库中的函数了。如果你的程序在编制 Motif 界面时首先要作如下的预

20、编译:了宏定义,那么在用上述命令进行编译和连接前,%cpp I/customization function_name.pcl output_file.cpp例如,MSC.Patran 安装在“/msc/patran75”目录下,预编译命令为:要编译和连接 abc.pcl 文件,则%cpp-I/msc/patran75/customization abc.pcl abp然后再用p 命令来预编译“abp”文件,如下所示:敲“%/msc/pat用“!input abp”,进入环境;p”完成编译和连接。14.4.2 Make在你创建或修改完程序后,只要打入“make”,MSC.Patran 便自动完

21、成编译并存放到库中去。但在你第一次做“make”前,必须先编辑如下所给的 Makefile 文件。注意:下面文件中加深显示的三处是要根据你的文件来修改的地方。Makefile 文件:# Name of thepcl libraryPclLibrary = ./exercise.plb# List of .pob filest goo the library# Each of these files should have a corresponding .pcl file PclObjects = exercise.pob platehole2.pob plateform.pob# MSC.P

22、atran 3 home directoryP3_HOME = /disk4/msc/patran75# Location of include files.IPATH = -I$(P3_HOME)/customization -I. -I./include# Script for invoking thestandalone pclcompilerpP=$(P3_HOME)/cu#COMPILEd=for compiling asingle preprosed pcl source file$(P) $(PCFLAGS) -pob $*.CPP#sible locations for fin

23、ding the executable for cppCPPLIST = /usr/lang/cpp /usr/ccs/lib/cpp /lib/cpp /usr/lib/cpp# cpp arguments for preprosing a single pcl source fileCPPARGS = $(IPATH) -C $*.pcl $*.CPP# Define thesible file suffixes.SUFFIXES: .pcl .pob .plb#SMake suret the bourne sis used toinvokemands= /bin/sh# # # # #D

24、efine a rule for converting a .pcl sourcefile to atempts to.pob object. elligentlyon the defaultThis rule is somewhat ugly because1) it it surelocate thesearch pacpp executable given nd 2) we need to makethe compilation fails!often is nott the .pob filegetsdeletedclutterifWe usecarefullysoastonotthe

25、 screen while make is running.pcl.pob: rm-f $*.ERROR CPP= ; for i in $(CPPLIST) ; do if -f $i ; then CPP=$i ; fi ; done ; echo $CPP $(CPPARGS)$CPP $(CPPARGS)echo $(COMPILE);-$(COMPILE) ; if $? -ne 0 ; then rm -rf $*.pob ; touch $*.ERROR ; else exit 0 ; fi-f $*.CPP echorm if -f $*.ERROR ; then rm -f

26、$*.ERROR ; exit 1 ; else exit 0 ; fi# Merge all .pobso the$(PclLibrary): $(PclObjects)$(P) -m $ $(PclObjects)# Finally, define a clean rule clean:rm -f $(PclObjects)14.5 一个例子下面给出一个比较有实用意义的例子,供参考。有空的话,不妨上机一试。1Exercise.pcl 文件:CLASS exerciseFUNCTION init()WIDGETbar,item1,item2,item3bar=uil_primary.get_

27、bar_id()=ui_create(bar,exercise_,Hang Qi)item1=ui_item_create(,EX_1,Plate wiHole,FALSE)item2=ui_item_create( item3=ui_item_create(END FUNCTION,EX_2,Crossing Pipes,FALSE),EX_3,Slot,FALSE)FUNCTION exercise_(item_name) STRING item_nameSWITCH (item_name)CASE(EX_1)write(Plate wi plateForm.init() plateFor

28、m.display()CASE(EX_2)Hole Creating Funtion)write(Cross Pipes Creating Function)CASE(EX_3)write(slot M END SWITCHEND FUNCTIONEND CLASSing Funtion)2Plateform.pcl 文件:#include appforms.p CLASS plateFormCLASSWIDE WIDGET form_id,dataBox1,dataBox2,dataBox3,apply_button,cancel_buttonFUNCTIONreal* Create*/in

29、it()x_loc,y_loc the formform_id=ui_form_create( /*callback */FORM_X_LOC, FORM_Y_LOC, UL,/*/*/*/*/*/*/*x yition width height labeliconname*/*/*/*/*/*/*/FORM_WID_SML,FORM_HGT_FULL,Plate wi )Hole, /* Create the icon*/x_loc=FRAME_WID_SINGLE/2.-200*PIXEL_WID/2.+FORM_L_MARGINy_loc=FORM_T_MARGIN+ui_labelic

30、on_create(ER_WIDGET_SPACE/*/*/*/*/*parant lab_namexy icon*/*/*/*/*/form_id, x_loc,y_loc,platehole.icon)y_loc +=200.*PIXEL_HGT+ DBOX_HGT_NO_LABOVE +ER_WIDGET_SPACE/* Create the input value databox*/dataBox1 = ui_databox_create(/*/*/*/*/*/*/*/*/*Parant callbackxy*/*/*/*/form_id,FRAME_L_MARGIN, y_loc,l

31、abel_length */SINGLE_SPACE*5.0,DBOX_WID_SINGLE*0.6, box_length label valuelabel_above*/*/*/*/r=2., FALSE,/* daype*/REAL,1/* num_values */)ER_WIDGET_SPACEy_loc += DBOX_HGT_NO_LABOVE +dataBox2 = ui_databox_create( form_id, ,FRAME_L_MARGIN,y_loc,/*/*/*/*/*/*/*/*/*/*/*Parant callbackxy*/*/*/*/ label_len

32、gth */SINGLE_SPACE*5.0,DBOX_WID_SINGLE*0.6,box_length label valuelabel_above*/*/*/*/*/*/w=5., FALSE, REAL,1, )daypenum_valuesy_loc += DBOX_HGT_NO_LABOVE+ER_WIDGET_SPACEdataBox3 = ui_databox_create( form_id, ,FRAME_L_MARGIN,y_loc,/*/*/*/*/*/*/*/*/*/*/*Parant callbackxy*/*/*/*/ label_length */SINGLE_S

33、PACE*5.0,DBOX_WID_SINGLE*0.6,box_length label valuelabel_above*/*/*/*/*/*/h=10., FALSE, REAL, 1, )daypenum_valuesy_loc += DBOX_HGT_NO_LABOVE+ER_WIDGET_SPACE*2./* Create the*/apply buttonapply_button=ui_button_create(/*/*/*/*/*/*/*/*parant callbackx ywidthheight label*/*/*/*/*/*/*/form_id, apply_cb,

34、BUTTON_HALF_X_LOC1, y_loc,BUTTON_WID_HALF,0.0,Apply,TRUE,label_inside*/* highlight*/TRUE)/* Create the Cancel button*/cancel_button=ui_button_create( /*/*/*/*/*/*/*/*/*parant callbackx ywidthheight label*/*/*/*/*/*/*/form_id,cancel_cb,BUTTON_HALF_X_LOC2,y_loc,BUTTON_WID_HALF,0.0,Cancel, TRUE, label_

35、inside*/highlight*/FALSE)y_loc += BUTTON_DEFAULT_HGT+FORM_B_MARGIN+ui_wid_set(form_id,HEIGHT,y_loc) END FUNCTIONER_WIDGET_SPACEFUNCTION display() ui_form_display(plateForm)END FUNCTIONFUNCTION apply_cb()real r,w,hui_wid_get( ui_wid_get(ui_wid_get(dataBox1 dataBox2dataBox3,VALUE VALUEVALUE,r wh)ui_fo

36、rm_hide(plateForm) platehole(r,w,h)END FUNCTIONFUNCTION cancel_cb() ui_form_hide(plateForm)END FUNCTIONEND CLASS3Platehole.pcl 文件:FUNCTION platehole(r,w,h) real r,w,hSTRING coord_str32,vector_str32ui_override_message(38000217,YES)STRING sgm_sp_curve_rev_created_idsVIRTUALcoord_str=/str_from_real(r)/

37、 0 0sgm_const_curve_revolve( 1, Coord 0.3, 90., 0., Coord 0, coord_str,sgm_sp_curve_rev_created_ids )$# 1 Curve Created: Curve 1STRING sgm_curve_break_par_created_idsVIRTUAL sgm_edit_curve_break_parametric( 2, 0.5, Curve 1 , TRUE, sgm_curve_break_par_created_ids )STRING asm_create_line_xyz_created_i

38、dsVIRTUAL coord_str=/str_from_real(w)/ 0 0vector_str=asm_const_line_xyz( 4, vector_str, asm_create_line_xyz_created_ids )$# 1 Line created: Line 4 vector_str=Po5 , Coord0, STRING sgm_surface_2curve_created_idsVIRTUAL sgm_const_surface_2curve( 1, Curve 2 , Curve 4 sgm_surface_2curve_created_ids )$# 1

39、 Surface Created: Surface 1sgm_const_surface_2curve( 2, Curve 3 , Curve 5 sgm_surface_2curve_created_ids )$# 1 Surface Created: Surface 2STRING sgm_sp_surface_e_created_idsVIRTUAL vector_str=sgm_const_surface_extrude( 3, vector_str, 1., 0.,00 0,Coord0,Curve 5 , sgm_sp_surface_e_created_ids )$# 1 Sur

40、face Created: Surface 3ui_exec_function( mesh_seed_display_mgr, init ) mesh_seed_create( Surface 1.1 , 3, 10, 3., 0., 0.)ga_viewport_location_set( default_viewport, -0.066622, 1.443467, 1 )ga_viewport_location_set( default_viewport, -0.066622, 1.443467, 1 )mesh_seed_create( mesh_seed_create( mesh_se

41、ed_create(mesh_seed_create(Surface Curve 2Curve 3Surface1.1 , 3, 1, 10, 1, 10,3.1 , 1,10,0.,0.,10,3.,0.,0.,0.,0., 0.0. )0. )0., 0.)EGER fem_create_mesh_surfa_num_nodes EGER fem_create_mesh_surfa_num_elemsSTRING fem_create_mesh_s_nodes_createdVIRTUALSTRING fem_create_mesh_s_elems_createdVIRTUAL fem_create_mesh_surf_2( IsoMesh, 0, Surface 1 ,1, 0.1, Quad4, 1,1, Coord 0, Coord 0, fem_create_mesh_surfa_num_nodes, fem_create_mesh_surfa_num_elems, fem_create_mesh_s_nodes_created, fem_create_mesh_s_elems_creat

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论