亚洲精品美女久久_91国内精品久久_亚洲九九在线_91精品国产高潮抽搐_国产一区二区三区在线免费观看_91com在线观看

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:[email protected]




主站蜘蛛池模板: 久久婷婷五月综合色一区二区 | 无码精品人妻一区二区三区人妻斩 | 亚洲大片免费观看 | 大伊香蕉在线精品视频人碰人 | 国产亚州精品女人久久久久久 | 国产 麻豆 日韩 欧美 久久 | 亚洲福利在线视频 | 成人爽a毛片在线视频网站 成人丝袜激情一区二区 | 野花社区在线观看视频 | 国产免费一级精品视频 | 毛片不卡一区二区三区 | 国产免费一区二区三区最新 | 精品一区二区免费视频 | 国产激情久久久久久熟女老人av | 侵犯人妻教师波多野吉衣 | 日本一级毛片无遮挡 | 中文字幕人妻高清乱码 | 强伦人妻一区二区三区视频18 | 日本免费黄色大片 | 久久久久无码精品国产app | 久久99热狠狠色精品一区 | 亚洲成亚洲成网 | 99热久久只有精品6国产32 | 中文字幕成熟丰满人妻 | 国产伦精品一区二区三区免.费 | 久久青青成人亚洲精品 | 亚洲av中文无码乱人伦在线咪咕 | 免费看a视频 | 日本国内一区二区三区 | 日韩中文字幕在线观看 | 又粗又硬又黄又爽的免费视频 | 国产 麻豆 日韩 欧美 久久 | 国产91极品福利手机观看 | 毛片在线高清免费观看 | 婷婷五月色综合香五月 | 亚洲精品久久久久久久蜜桃 | 国产美女精品一区二区三区 | 午夜免费观看福利片一区二区三区 | 欧美毛片在线播放观看 | 蜜桃久久 | 男人扒开添女人下部免费视频 |