av久久久-av九九九-av九九-av激情网-欧美三级在线-欧美三级一区二区三区

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




主站蜘蛛池模板: 老江湖| 高登眼镜| 按摩私处| 《水中花》日本电影| 尹雪喜演的电影在线观看| 李子京| 爱妃直播| 林峰电影| 第一财经今日股市直播间在线直播| 我们的快乐人生 电视剧| 海洋之歌免费观看完整中文版| 中央电视台科教频道| 屈原话剧| 性视频网站在线| 耄耋老太国产| raz分级阅读绘本| 鼻子上长痘痘是什么原因引起的| 爱欲1990未删减版播放| 朱丽安·摩尔| 大秧歌演员表全部| 项目负责人任命书| 烽火硝烟里的青春演员表| 黑暗森林 电影| 黄色网址视频| 女公安毛片免费观看| 肖央演过的电影| 小牛加速器安卓版| 西安今天出大事| 爱奴记| 北京卫视今晚节目表| 新红楼梦电影| 抗日电影完整版| 大尺度床戏韩国| 四 电影| 柏欣彤12点以后跳的广场舞| 20岁电影免费完整观看| 辩论赛作文| 成人在线免费播放视频| 180天在线观看电视剧| 音乐僵尸演员表| 电影白上之黑|