仿真在线:有限元分析咨询与培训中心——Ansys|Fluent|Abaqus|HFSS|SolidWorks|课程培训

Udf全局變量-外部變量External Variables,可在不同文件間共享

2022-03-25  by:CAE仿真在線  來源:互聯網

Udf全局變量-外部變量External Variables,可在不同文件間共享,如果要累計不同時間步的數據,就可以考慮這個方式。


A.5.2. External Variables


If you have a global variable that is declared in one source code file, but a function in another source file needs to use it, then it must be defined in the other source fi1e as an external variable. To do this, simp1y precede the variable declaration by the word extern as in

extern real volume; 
If there are several files referring to that variable then it is convenient to include the extern definition in a header (.h) file, and include the header file in all of the .c files that want to use the external variable. Only one .c file should have the declaration of the variable without the extern keyword. Below is an example that demonstrates the use of a header file.

Important:   extern can be used only in compiled UDFs.

 
A.5.2.1. Example
Suppose that there is a global variable named volume that is declared in a C source file named file1.c

#include "udf.h"
 real volume;  /* real variable named volume is declared globally */
 
 DEFINE_ADJUST(compute_volume, domain)
 {
 /* code that computes volume of some zone */
 volume = ....
 } 
If multiple sourc files want to use volume in the1r computations, then volume can be declared as an external variab1e in a header file (for example, extfile.h)

/* extfile.h
 Header file that contains the external variable declaration for
 volume */
 
 extern real volume; /*聲明udf全局變量,這樣在h文件聲明就可以了*/
Now another file named file2.c can declare volume as an external variable by simply including extfile.h.

/* file2.c
 
 #include "udf.h"
 #include "extfile.h" /* header file containing extern declaration
       is included */
 
 DEFINE_SOURCE(heat_source,c,t,ds,eqn)
 {
 /* code that computes the per unit volume source using the total
   volume computed in the compute_volume function from file1.c  */
 real tota1_source = ...;
 real source;
 source = total_source/volume;
 return source;

 } 


但如果用static 靜態變量呢?這個不行

因為靜態變量只在定義他的文件范圍內有效,即時把static定義成external都不行。這點要注意。

但如果累計的變量一直在同一個文件內部,則就有用了。

如果static變量在一個function內定義,則在文件內一直保留,包括他的值也保留。如果在頭部定義,則對整個文件一直保留其值。

The static operator has different effects depending on whether it is applied to local or global variables. When a local variable is declared as static the variable is prevented from being destroyed when a function returns from a call. In other words, the value of the variable is preserved. When a global variable is declared as static the variable is "file global." It can be used by any function within the source file in which it is declared, but is prevented from being used outside the file, even if is declared as external. Functions can also be declared as static. A static function is visible only to the source file in which it is defined.

Important:   static variables and functions can be declared only in compiled UDF source files.

 
A.5.3.1. Example - Static Global Variable
/* mysource.c /*
 
 #include "udf.h"
 
 static real abs_coeff = 1.0; /* static global variable */
  /* used by both functions in this source file but is
   not visible to the outside */
 
 DEFINE_SOURCE(energy_source, c, t, dS, eqn)
 {
   real source; /* local variable
   int P1 = ....; /* local variable
        value is not preserved when function returns */
   dS[eqn] = -16.* abs_coeff * SIGMA_SBC * pow(C_T(c,t),3.);
   source =-abs_coeff *(4.* SIGMA_SBC * pow(C_T(c,t),4.) - C_UDSI(c,t,P1));
   return source;
 }
 
 DEFINE_SOURCE(p1_source, c, t, dS, eqn)
 {
   real source;
   int P1 = ...;
   dS[eqn] = -abs_coeff;
   source = abs_coeff *(4.* SIGMA_SBC * pow(C_T(c,t),4.) - C_UDSI(c,t,P1));
   return source;
 } 



開放分享:優質有限元技術文章,助你自學成才

相關標簽搜索:Udf全局變量-外部變量External Variables,可在不同文件間共享 fluent-udf Fluent培訓 Fluent流體培訓 Fluent軟件培訓 fluent技術教程 fluent在線視頻教程 fluent資料下載 fluent分析理論 fluent化學反應 fluent軟件下載 UDF編程代做 Fluent、CFX流體分析 

編輯
在線報名:
  • 客服在線請直接聯系我們的客服,您也可以通過下面的方式進行在線報名,我們會及時給您回復電話,謝謝!
驗證碼

全國服務熱線

1358-032-9919

廣州公司:
廣州市環市中路306號金鷹大廈3800
電話:13580329919
          135-8032-9919
培訓QQ咨詢:點擊咨詢 點擊咨詢
項目QQ咨詢:點擊咨詢
email:kf@1cae.com




主站蜘蛛池模板: 济南货架|济南仓储货架|济南仓库货架|山东蕴达金属制品有限公司 济南海纳特科技有限公司 | 四合扣-工字扣-帽钉(831,200,警用,大拉力四合扣)-永嘉县鑫达钮扣有限公司 | 手板机箱_亚克力机箱_医疗机箱_美容机箱_医疗设备外壳厂家_鸿堪医疗器械有限公司 | 精密齿轮,同步带轮,蜗轮,蜗杆,减速机齿轮,行星齿轮-和兴齿轮 | 深圳办公室装修_高端写字楼设计费用_企业装修报价公司-深圳长红装饰 | 智齿科技-智齿客服 | 在线客服_呼叫中心_客户联络中心方案 | 热门网页游戏平台_页游排行榜_新开网页游戏开服表_599游戏 | 贴片磁胶电感_一体成型电感_贴片共模电感_广东精密龙电子科技有限公司 | 企业微信服务商-企业微信crm营销|认证-[朝阳企客通]一款企微管家服务型产品 | 西藏旅游-西藏中旅-西藏中旅国际旅行社| 润东方环保空调厂家-水冷式空调价格-润东方水冷空调-东莞市科骏机电设备有限公司 | 全不锈钢拉钉|铁开口拉钉|全铝封闭拉钉厂家-凯仕特官网 | 塑胶模具定制,提供注塑加工服务,塑料模具制造厂_博腾纳公司 | 金属剪切机,金属打包机,废钢剪切机,废铁压块机,金属压块机,废纸打包机,重废龙门剪,废钢龙门剪,箱式剪,液压剪切机-瑞顿机械装备制造江阴有限公司 | 南开大学在职研究生招生信息网| 混凝土修补-清水混凝土保护剂-仿清水混凝土-混凝土装修-混凝土色差处理-混凝土色差修复剂-德州唐荣建筑装饰工程有限公司 | 真空系统,真空泵租赁技术服务-兆德机械(上海)有限公司 | 永磁变频空压机_青岛空压机_螺杆空压机_口罩专用空压机-青岛凯瑞特机电设备有限公司 | 品牌T恤零售/批发厂商/供应商_男女式T恤生产/设计-圣达信T恤 | 专业护工_医院护工_护工陪护_住家护工- 心陪护 | 上海新航道学校官网_20年专注雅思_托福_SAT_ACT等出国语言培训机构. | 人仁康集团 -- 10A抗菌舱研发生产厂家 | 汽车标签|医疗标签|电子标签|手机电池标签|电脑电池标签|电源标签|耐高温标签|防静电标签|手机出厂膜|手机全裹膜|手机包裹膜|手机卖点膜|热转印标签|遮阳板标签|天势科技|-标签印制专家! | 惠声电子、广州市惠声电子科技有限公司、VBS、VBS惠声电子、VBS公共广播生产厂家、VBS广播功放生产厂家、VBS会议系统设备批发、VBSIP网络对讲系统厂家、VBS会议系统厂家、VBS智能中控厂家、VBS专业扩声厂家 | 郑州离婚律师|婚姻律师在线咨询-河南锦盾律师事务所 | 双合金螺杆|注塑机螺杆|挤出机螺杆|双合金料管—东莞市精耐螺杆机械有限公司 | 浙江福茂德汽车滤清器有限公司| 饮料制造机械设备-罐体设备报价-CIP清洗设备-饮料生产线交钥匙工程-上海哲苏轻工机械有限公司 | 西安网站建设,西安网站设计制作,西安短视频拍摄_短视频运营就选动力无限网络推广公司 | 呼吸家官网|肺功能检测仪生产厂家|国产肺功能仪知名品牌|肺功能检测仪|肺功能测试仪|婴幼儿肺功能仪|弥散残气肺功能仪|肺功能测试系统|广州红象医疗科技有限公司|便携式肺功能仪|大肺功能仪|呼吸康复一体机|儿童肺功能仪|肺活量计|医用简易肺功能仪|呼吸康复系统|肺功能仪|弥散肺功能仪(大肺)|便携式肺功能检测仪|肺康复|呼吸肌力测定肺功能仪|肺功能测定仪|呼吸神经肌肉刺激仪|便携式肺功能 | 消防车厂家_东风水罐泡沫消防车价格图片吨位-湖北新东日专用汽车有限公司 | 乌兰察布市集宁牧田饲料科技有限公司-乌兰察布奶牛饲料|饲料原料加工|精品羊料 | 推台锯_多片锯_圆木推台锯_方木多片锯_圆木多片锯-河北茂业机械有限公司 | 快速卷帘门-电动卷帘门-快速堆积门-快速门厂家-任丘市康速机电设备有限公司 | 深圳-广州-惠州-东莞-重型货架-悬臂-轻中型货架-深圳市诺普泰仓储设备有限公司 | 山东贝州集团有限公司| 双合金_注塑机_螺杆|炮筒|料管|料筒-广东海驰德塑胶机械有限公司 | 深圳市翔洲宏科技有限公司 | 浙江微龙科技-微通道工艺结合设备一站式解决方案-致力于连续流技术开发与产业化应用-助力传统医药化工行业转型升级 | 社会百态,七仙女思春完整版免费高清电影引发的思考 | 螺旋输送机_无轴螺旋输送机_绞龙螺旋输送机- 河北品丞环保机械有限公司 |