前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >5.2.3 二维导热算例-整体架构

5.2.3 二维导热算例-整体架构

作者头像
周星星9527
发布2018-08-08 15:55:10
4970
发布2018-08-08 15:55:10
举报

首先给出代码:

代码语言:javascript
复制
1. packageSoong.Solver
2. {
3.  import flash.net.FileReference;
4.  public classTSolverMgr
5.    {
6.  public var xDim:Number = 20;//Dimension inX Direction
7.  public var yDim:Number = 20;//Dimension inX Direction
8.  
9.  public var dx:Number = 1;//Grid Size in XDirection
10.  public var dy:Number = 1;//Grid Size in YDirection
11.  
12.  public var IDsteel:uint = Math.pow(2,1);//ID of material Steel
13.  public var IDair:uint = Math.pow(2,2);//ID of material Air
14.  
15.  public var steel:Material= null;//MaterialSteel
16.  public varair:Material = null;//MaterialAir
17.  
18.  public var Tambient:Number = 30;//Temperatureof Ambient Space (Eg: Air)
19.  public varConvectionCoeff:Number = 100;//
20.  
21.  private var xGridNum:uint = 0;//Number of GridAllocated in X Direction
22.  private var yGridNum:uint = 0;//Number of GridAllocated in X Direction
23.  
24.  private vartotalGridNum:uint = 0;//TotalNumber of Grid Allocated in 2D Plane
25.  
26.  private varkeyGridNum:uint = 0;//Numberof Key Grid
27.  
28.  private varxKeyGridNum:uint = 0;//Numberof Key Grid in X Direction
29.  private varyKeyGridNum:uint = 0;//Numberof Key Grid in Y Direction
30.  
31.  private varsolver:TSolver = null;
32.  private var nodeList:Vector.<Node> =null;
33.  private var flowTime:Number=0;
34.  
35.  public functionTSolverMgr()
36.       {
37.  
38.       }
39.  
40.  public functionSetDim(xDim:Number=20,yDim:Number=20,dx:Number=1,dy:Number=1):void
41.       {
42.  this.xDim = xDim;
43.  this.yDim = yDim;
44.  
45.  this.dx = dx;
46.  this.dy = dy;
47.  
48.          xKeyGridNum= uint(xDim / dx) + 1;
49.          xGridNum= xKeyGridNum + 2 + 2;
50.  
51.          yKeyGridNum= uint(yDim / dy) + 1;
52.          yGridNum= yKeyGridNum + 2 + 2;
53.  
54.          totalGridNum= xGridNum * yGridNum;
55.          keyGridNum=xKeyGridNum*yKeyGridNum;
56.  
57.          solver= new TSolver(xGridNum,yGridNum,dx,dy);
58.          solver.Tlist= new Vector.<Node>(totalGridNum, true);
59.  
60.          nodeList= solver.Tlist;
61.  
62.  for(var i:uint=0;i<totalGridNum;i++)
63.          {
64.             nodeList[i]=new Node();
65.          }
66.       }
67.  
68.  public functionApplyMaterial(steel:Material,air:Material):void
69.       {
70.  this.steel = steel;
71.  
72.  this.air = air;
73.       }
74.  
75.  public functionSetMaterial():void
76.       {
77.          steel= new Material(IDsteel,1550);
78.  
79.          steel.Cp= 680;
80.          steel.lmd= 34;
81.          steel.Rho= 7200;
82.          steel.LatentHeat= 270000;
83.          steel.Tsol= 1504;
84.          steel.Tliq= 1531;
85.  
86.          air= new Material(IDair, Tambient);
87.          air.Cp= 1008;
88.          air.lmd= 0.02;
89.          air.Rho= 1.29;
90.          air.LatentHeat= 0;
91.  
92.  var col:uint = 0;
93.  var row:uint = 0;
94.  var node:Node=null;
95.  
96.  //Apply the Steel Region
97.  for (col = 2; col < xGridNum - 2; col++ )
98.          {
99.  for (row = 2; row < yGridNum-2; row++ )
100.            {
101.               node= nodeList[Index(col, row)] as Node;
102. 
103.               node.ApplyMaterial(steel);
104.            }
105.         }
106. 
107. //Apply the Upper Air Region 
108. for (col = 0; col < xGridNum; col++ )
109.         {
110. for (row = yGridNum-2; row < yGridNum; row++ )
111.            {
112.               node= nodeList[Index(col, row)] as Node;
113. 
114.               node.ApplyMaterial(air);
115.            }
116.         }
117. 
118. //Apply the Right Air Region
119. for (col = xGridNum - 2; col < xGridNum; col++ )
120.         {
121. for (row = 0; row < yGridNum; row++ )
122.            {
123.               node= nodeList[Index(col, row)] as Node;
124. 
125.               node.ApplyMaterial(air);
126.            }
127.         }
128.      }
129. 
130. public functionUpdateHeatExchangeFactor():void
131.      {
132. var col:uint = 0;
133. var row:uint = 0;
134. var xDir:Boolean =true;
135. var node:Node = null;
136. 
137. //Update Heat Exchange Factor in Steel Region
138. for (col = 2; col < xGridNum - 2; col++ )
139.         {
140. for (row = 2; row < yGridNum-2; row++ )
141.            {
142. var node_Adj:Node=null;
143. 
144.               node= nodeList[Index(col, row)] as Node;
145. 
146.               node_Adj=nodeList[Index(col+1,row)] as Node;
147.               node.eHeatExchangeFactor= HeatExchangeFactor(node.materialIndex, node_Adj.materialIndex,true);
148. 
149.               node_Adj=nodeList[Index(col-1,row)] as Node;
150.               node.wHeatExchangeFactor= HeatExchangeFactor(node.materialIndex, node_Adj.materialIndex,true);
151. 
152.               node_Adj=nodeList[Index(col,row+1)] as Node;
153.               node.nHeatExchangeFactor= HeatExchangeFactor(node.materialIndex, node_Adj.materialIndex,false);
154. 
155.               node_Adj=nodeList[Index(col,row-1)] as Node;
156.               node.sHeatExchangeFactor= HeatExchangeFactor(node.materialIndex, node_Adj.materialIndex,false);
157.            }
158.         }
159.      }
160. 
161. public functionHeatExchangeFactor(mtlA:uint,mtlB:uint,xDir:Boolean=true):Number
162.      {
163. /* Interface Index
164.           *1 for Insulation, 2 for Steel, 4 For Air
165.           *AB 1 2 4
166.           *----------
167.           *1| 2 3 5
168.           *2| 3 4 6
169.           *4| 5 6 8
170.           */
171. var interfaceAB:uint= mtlA + mtlB;
172. 
173. var gridSize:Number =xDir?dx:dy;
174. 
175. switch (interfaceAB)
176.         {
177. case Material.HeatInsulation*2://Interface Between Insulation: 2
178. return 0;
179. break;
180. 
181. case Material.HeatInsulation+steel.ID://Interface Between Insulation and Steel: 3
182. return 0;
183. break;
184. 
185. case steel.ID*2://InterfaceBetween Steel: 4
186. return steel.lmd / gridSize;
187. break;
188. 
189. case Material.HeatInsulation+air.ID://Interface Between Insulation and Air: 5
190. return 0
191. break;
192. 
193. case steel.ID+air.ID://InterfaceBetween Steel and Air: 6
194. return ConvectionCoeff;
195. break;
196. 
197. case air.ID*2://InterfaceBetween Air: 8
198. return air.lmd / gridSize;
199. break;
200. 
201. default:
202. break;
203.         }
204. 
205. return 0;
206.      }
207. 
208. public functionStep(timeStep:Number):void
209.      {
210.         flowTime+=timeStep;
211. 
212.         solver.Step(timeStep);
213.      }
214. 
215. public functionExport2Tecplot(fileName:String="Tdata.dat",precision:uint=5):void
216.      {
217. var file:FileReference= new FileReference();
218. 
219. var exData:String = new String("Title=\"Data Simulated By SoongSoftStudio\"\n");
220. 
221.         exData+="Variables=\"X\",\"Y\",\"T\",\"LiquidFraction\"\n";
222. 
223.         exData+="Zone T=\"Billet\" I="+xKeyGridNum+",J="+yKeyGridNum+",K=1\n";
224. 
225.         exData+="SOLUTIONTIME="+flowTime.toFixed(precision)+"\n";
226. 
227. var col:uint = 0;
228. var row:uint = 0;
229. 
230. var Tsol:Number=steel.Tsol;
231. var dT:Number=steel.Tliq-Tsol;
232. 
233. //Update Heat Exchange Factor in Steel Region
234. for (col = 2; col < xGridNum - 2; col++ )
235.         {
236. for (row = 2; row < yGridNum-2; row++ )
237.            {
238. var x:Number=(col-2)*dx;
239. var y:Number=(row-2)*dy;
240. 
241. var T:Number=nodeList[Index(col,row)].T;
242. var lf:Number=(T-Tsol)/dT;
243. 
244. if (lf>1) lf=1;
245. if(lf<0) lf=0;
246. 
247.               exData+=x.toFixed(precision)+""+y.toFixed(precision)+""+T.toFixed(precision)+""+lf.toFixed(precision)+"\n";
248.            }
249.         }
250. 
251.         file.save(exData,fileName);
252.      }
253. 
254. public functionGetCurrentT():Vector.<Number>
255.      {
256. var result:Vector.<Number>=new Vector.<Number>();
257. 
258. var col:uint = 0;
259. var row:uint = 0;
260. 
261. //Update Heat Exchange Factor in Steel Region
262. for (col = 2; col < xGridNum - 2; col++ )
263.         {
264. for (row = 2; row < yGridNum-2; row++ )
265.            {
266. var T:Number=nodeList[Index(col,row)].T;
267. 
268.               result.push(T);
269.            }
270.         }
271. 
272. return result;
273.      }
274. 
275. private functionIndex(col:uint=0,row:uint=0):uint
276.      {
277. return row * xGridNum + col;
278.      }
279. 
280. public function ExportSetting(fileName:String="Setting.ini",precision:uint=1):void
281.      {
282. var file:FileReference= new FileReference();
283. 
284. var exData:String = new String("Title=\"Data Simulated By SoongSoftStudio\"\n");
285. 
286.         exData+="Variables=\"X\",\"Y\",\"T\",\"e\",\"s\",\"w\",\"n\"\n";
287. 
288.         exData+="Zone T=\"Billet\" I="+xGridNum+",J="+yGridNum+",K=1\n";
289. 
290.         exData+="SOLUTIONTIME="+flowTime.toFixed(precision)+"\n";
291. 
292. var col:uint = 0;
293. var row:uint = 0;
294. 
295. var Tsol:Number=steel.Tsol;
296. var dT:Number=steel.Tliq-Tsol;
297. 
298. //Update Heat Exchange Factor in Steel Region
299. for (col = 0; col < xGridNum ; col++ )
300.         {
301. for (row = 0; row < yGridNum; row++ )
302.            {
303. var idx:uint=Index(col,row);
304. 
305. var x:Number=col*dx;
306. var y:Number=row*dy;
307. 
308. var node:Node=nodeList[idx];
309. 
310. var Tini:Number=node.T0;
311. 
312. var eHEF:Number=node.eHeatExchangeFactor;
313. var sHEF:Number=node.sHeatExchangeFactor;
314. var wHEF:Number=node.wHeatExchangeFactor;
315. var nHEF:Number=node.nHeatExchangeFactor;
316. 
317.               exData+=x.toFixed(precision)+""+y.toFixed(precision)+""+Tini.toFixed(precision)+""+eHEF.toFixed(precision)+""+sHEF.toFixed(precision)+""+wHEF.toFixed(precision)+""+nHEF.toFixed(precision)+"\n";
318.            }
319.         }
320. 
321.         file.save(exData,fileName);
322.      }
323.   }
324.}

导出后处理数据的函数,到处设置的函数。

网格剖分及节点数组定义。

注意边界条件的处理,这个是重点。

本文参与 腾讯云自媒体分享计划,分享自微信公众号。
原始发表:2018-07-27,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 传输过程数值模拟学习笔记 微信公众号,前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档