温度场有限容积法程序入门之四:网格剖分.边界条件设置.迭代.导
发布时间:2020-12-15 18:10:56 所属栏目:百科 来源:网络整理
导读:首先给出代码: ? package Soong.Solver{import flash.net.FileReference;public class TSolverMgr{public var xDim:Number = 20;//Dimension in X Directionpublic var yDim:Number = 20;//Dimension in X Directionpublic var dx:Number = 1;//Grid Size i
首先给出代码: ? package Soong.Solver { import flash.net.FileReference; public class TSolverMgr { public var xDim:Number = 20;//Dimension in X Direction public var yDim:Number = 20;//Dimension in X Direction public var dx:Number = 1;//Grid Size in X Direction public var dy:Number = 1;//Grid Size in Y Direction public var IDsteel:uint = Math.pow(2,1);//ID of material Steel public var IDair:uint = Math.pow(2,2);//ID of material Air public var steel:Material = null;//Material Steel public var air:Material = null;//Material Air public var Tambient:Number = 30;//Temperature of Ambient Space (Eg: Air) public var ConvectionCoeff:Number = 100;// private var xGridNum:uint = 0;//Number of Grid Allocated in X Direction private var yGridNum:uint = 0;//Number of Grid Allocated in X Direction private var totalGridNum:uint = 0;//Total Number of Grid Allocated in 2D Plane private var keyGridNum:uint = 0;//Number of Key Grid private var xKeyGridNum:uint = 0;//Number of Key Grid in X Direction private var yKeyGridNum:uint = 0;//Number of Key Grid in Y Direction private var solver:TSolver = null; private var nodeList:Vector.<Node> = null; private var flowTime:Number=0; public function TSolverMgr() { } public function SetDim(xDim:Number=20,yDim:Number=20,dx:Number=1,dy:Number=1):void { this.xDim = xDim; this.yDim = yDim; this.dx = dx; this.dy = dy; xKeyGridNum = uint(xDim / dx) + 1; xGridNum = xKeyGridNum + 2 + 2; yKeyGridNum = uint(yDim / dy) + 1; yGridNum = yKeyGridNum + 2 + 2; totalGridNum = xGridNum * yGridNum; keyGridNum=xKeyGridNum*yKeyGridNum; solver = new TSolver(xGridNum,yGridNum,dx,dy); solver.Tlist = new Vector.<Node>(totalGridNum,true); nodeList = solver.Tlist; for(var i:uint=0;i<totalGridNum;i++) { nodeList[i]=new Node(); } } public function ApplyMaterial(steel:Material,air:Material):void { this.steel = steel; this.air = air; } public function SetMaterial():void { steel = new Material(IDsteel,1550); steel.Cp = 680; steel.lmd = 34; steel.Rho = 7200; steel.LatentHeat = 270000; steel.Tsol = 1504; steel.Tliq = 1531; air = new Material(IDair,Tambient); air.Cp = 1008; air.lmd = 0.02; air.Rho = 1.29; air.LatentHeat = 0; var col:uint = 0; var row:uint = 0; var node:Node=null; //Apply the Steel Region for (col = 2; col < xGridNum - 2; col++ ) { for (row = 2; row < yGridNum-2; row++ ) { node = nodeList[Index(col,row)] as Node; node.ApplyMaterial(steel); } } //Apply the Upper Air Region for (col = 0; col < xGridNum; col++ ) { for (row = yGridNum-2; row < yGridNum; row++ ) { node = nodeList[Index(col,row)] as Node; node.ApplyMaterial(air); } } //Apply the Right Air Region for (col = xGridNum - 2; col < xGridNum; col++ ) { for (row = 0; row < yGridNum; row++ ) { node = nodeList[Index(col,row)] as Node; node.ApplyMaterial(air); } } } public function UpdateHeatExchangeFactor():void { var col:uint = 0; var row:uint = 0; var xDir:Boolean = true; var node:Node = null; //Update Heat Exchange Factor in Steel Region for (col = 2; col < xGridNum - 2; col++ ) { for (row = 2; row < yGridNum-2; row++ ) { var node_Adj:Node=null; node = nodeList[Index(col,row)] as Node; node_Adj=nodeList[Index(col+1,row)] as Node; node.eHeatExchangeFactor = HeatExchangeFactor(node.materialIndex,node_Adj.materialIndex,true); node_Adj=nodeList[Index(col-1,row)] as Node; node.wHeatExchangeFactor = HeatExchangeFactor(node.materialIndex,true); node_Adj=nodeList[Index(col,row+1)] as Node; node.nHeatExchangeFactor = HeatExchangeFactor(node.materialIndex,false); node_Adj=nodeList[Index(col,row-1)] as Node; node.sHeatExchangeFactor = HeatExchangeFactor(node.materialIndex,false); } } } public function HeatExchangeFactor(mtlA:uint,mtlB:uint,xDir:Boolean=true):Number { /* Interface Index * 1 for Insulation,2 for Steel,4 For Air * AB 1 2 4 * ---------- * 1| 2 3 5 * 2| 3 4 6 * 4| 5 6 8 */ var interfaceAB:uint = mtlA + mtlB; var gridSize:Number = xDir?dx:dy; switch (interfaceAB) { case Material.HeatInsulation*2://Interface Between Insulation: 2 return 0; break; case Material.HeatInsulation+steel.ID://Interface Between Insulation and Steel: 3 return 0; break; case steel.ID*2://Interface Between Steel: 4 return steel.lmd / gridSize; break; case Material.HeatInsulation+air.ID://Interface Between Insulation and Air: 5 return 0 break; case steel.ID+air.ID://Interface Between Steel and Air: 6 return ConvectionCoeff; break; case air.ID*2://Interface Between Air: 8 return air.lmd / gridSize; break; default: break; } return 0; } public function Step(timeStep:Number):void { flowTime+=timeStep; solver.Step(timeStep); } public function Export2Tecplot(fileName:String="Tdata.dat",precision:uint=5):void { var file:FileReference = new FileReference(); var exData:String = new String("Title="Data Simulated By SoongSoftStudio"n"); exData+="Variables="X","Y","T","Liquid Fraction"n"; exData+="Zone T="Billet" I="+xKeyGridNum+",J="+yKeyGridNum+",K=1n"; exData+="SOLUTIONTIME="+flowTime.toFixed(precision)+"n"; var col:uint = 0; var row:uint = 0; var Tsol:Number=steel.Tsol; var dT:Number=steel.Tliq-Tsol; //Update Heat Exchange Factor in Steel Region for (col = 2; col < xGridNum - 2; col++ ) { for (row = 2; row < yGridNum-2; row++ ) { var x:Number=(col-2)*dx; var y:Number=(row-2)*dy; var T:Number=nodeList[Index(col,row)].T; var lf:Number=(T-Tsol)/dT; if (lf>1) lf=1; if(lf<0) lf=0; exData+=x.toFixed(precision)+" "+y.toFixed(precision)+" "+T.toFixed(precision)+" "+lf.toFixed(precision)+"n"; } } file.save(exData,fileName); } public function GetCurrentT():Vector.<Number> { var result:Vector.<Number>=new Vector.<Number>(); var col:uint = 0; var row:uint = 0; //Update Heat Exchange Factor in Steel Region for (col = 2; col < xGridNum - 2; col++ ) { for (row = 2; row < yGridNum-2; row++ ) { var T:Number=nodeList[Index(col,row)].T; result.push(T); } } return result; } private function Index(col:uint=0,row:uint=0):uint { return row * xGridNum + col; } public function ExportSetting(fileName:String="Setting.ini",precision:uint=1):void { var file:FileReference = new FileReference(); var exData:String = new String("Title="Data Simulated By SoongSoftStudio"n"); exData+="Variables="X","e","s","w","n"n"; exData+="Zone T="Billet" I="+xGridNum+",J="+yGridNum+",K=1n"; exData+="SOLUTIONTIME="+flowTime.toFixed(precision)+"n"; var col:uint = 0; var row:uint = 0; var Tsol:Number=steel.Tsol; var dT:Number=steel.Tliq-Tsol; //Update Heat Exchange Factor in Steel Region for (col = 0; col < xGridNum ; col++ ) { for (row = 0; row < yGridNum; row++ ) { var idx:uint=Index(col,row); var x:Number=col*dx; var y:Number=row*dy; var node:Node=nodeList[idx]; var Tini:Number=node.T0; var eHEF:Number=node.eHeatExchangeFactor; var sHEF:Number=node.sHeatExchangeFactor; var wHEF:Number=node.wHeatExchangeFactor; var nHEF:Number=node.nHeatExchangeFactor; exData+=x.toFixed(precision)+" "+y.toFixed(precision)+" "+Tini.toFixed(precision)+" "+eHEF.toFixed(precision)+" "+sHEF.toFixed(precision)+" "+wHEF.toFixed(precision)+" "+nHEF.toFixed(precision)+"n"; } } file.save(exData,fileName); } } }
网格剖分及节点数组定义。 注意边界条件的处理,这个是重点。 ? 说到这里,就近乎尾声了。 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |