久久精品草-久久精品成人-久久精品成人免费网站-久久精品成人欧美大片免费-香港三级大全-香港三级日本三级a视频

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

2022-03-25  by:CAE仿真在線  來源:互聯(lián)網(wǎng)

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


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 靜態(tài)變量呢?這個(gè)不行

因?yàn)殪o態(tài)變量只在定義他的文件范圍內(nèi)有效,即時(shí)把static定義成external都不行。這點(diǎn)要注意。

但如果累計(jì)的變量一直在同一個(gè)文件內(nèi)部,則就有用了。

如果static變量在一個(gè)function內(nèi)定義,則在文件內(nèi)一直保留,包括他的值也保留。如果在頭部定義,則對(duì)整個(gè)文件一直保留其值。

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;
 } 



開放分享:優(yōu)質(zhì)有限元技術(shù)文章,助你自學(xué)成才

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

編輯
在線報(bào)名:
  • 客服在線請(qǐng)直接聯(lián)系我們的客服,您也可以通過下面的方式進(jìn)行在線報(bào)名,我們會(huì)及時(shí)給您回復(fù)電話,謝謝!
驗(yàn)證碼

全國(guó)服務(wù)熱線

1358-032-9919

廣州公司:
廣州市環(huán)市中路306號(hào)金鷹大廈3800
電話:13580329919
          135-8032-9919
培訓(xùn)QQ咨詢:點(diǎn)擊咨詢 點(diǎn)擊咨詢
項(xiàng)目QQ咨詢:點(diǎn)擊咨詢
email:kf@1cae.com




主站蜘蛛池模板: 91精品国产高清91久久久久久 | 99热这里只有精品在在 | 成年午夜性漫画免费看 | 精品免费久久久久国产一区 | 日韩成人在线观看视频 | 国产精品久久久久久免费播放 | 中文字幕日本精品一区二区三区 | 一二三四在线视频社区8 | 永久黄网站色视频免费网站 | 最近最新中文字幕6页 | 五月天男人天堂 | 久久综合香蕉久久久久久久 | 四虎永久免费 | 亚洲另类天天更新影院在线观看 | 欧美一进一出 | 久草视频网址 | 真正全免费视频a毛片 | 色视频免费观看高清完整 | 97国产成人精品视频 | 麻豆影视视频高清在线观看 | 好爽毛片一区二区三区四区 | 精品九九在线 | eeuss天堂影院| 婷婷五月天.com | 在线看片a免费人成漫画 | 色网址在线观看 | 久久国产精品女 | 视频久久久 | 国产精品午夜久久久久久99热 | 国产一二三区精品 | 嫩草影院在线观看网站成人 | 日本不卡在线观看 | 欧美性一区 | 99久久久久久久 | 毛片免费永久不卡视频观看 | 香蕉蕉亚亚洲aav综合 | 麻豆国内精品久久久久久 | 黄色日韩视频 | 亚洲视频在线观看免费 | 精品久草| 99热热久久|