第二节 桁架结构基本信息录入与保存
此节之后会结合一个算例。结构如图,EA = 300000 kN
杆件编号、节点编号、坐标系:
2.1 文本信息
bars.txt
1,1,3,300000
2,2,3,300000
3,4,3,300000
4,2,4,300000
nodes.txt
1,0,3,1,1,0,0
2,0,0,1,1,0,0
3,4,3,0,0,0,-20
4,4,0,0,0,30,0
2.2 静态类 ClassBasicInfo 存放基本结构数据
新建类库,命名为 Business,添加对 PlaceUsingTxt.dll 的引用,新建类,命名为 ClassBasicInfo,贴入以下代码:
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace Business { public static class ClassBasicInfo { public static int[,] BarsNodes;//杆件节点编号 public static Single[] LinearStiffness;//杆件刚度 public static Single[,] Coordinate;//节点坐标 public static bool[,] Restraint;//节点约束 public static Single[,] Loads;//节点荷载 public static Single[,] TatalStiffnessMatrix;//总刚度矩阵 public static Single[] TatalDisplacement;//总位移列阵 public static Single[] TatalLoads;//总荷载列阵 public static bool[] TatalRestraint;//总边界条件 } }
新建类,命名为 ClassGetBasicInfo,贴入以下代码:
using System; using System.Collections.Generic; using System.Linq; using System.Text; using PlaceUsingTxt; namespace Business { public class ClassGetBasicInfo { public int NumBars;//杆件数 public int NumNodes;//节点数 public void InitBars(string StrBars) { //初始化杆件信息 ClassReadTxt crt = new ClassReadTxt(StrBars); string[,] tempstr = crt.OutStr2D(); crt.close(); //取得杆件数 NumBars = tempstr.GetLength(0); ClassBasicInfo.BarsNodes = new int[NumBars, 2]; ClassBasicInfo.LinearStiffness = new Single[NumBars]; for (int i = 0; i < NumBars; i++) { ClassBasicInfo.BarsNodes[i, 0] = Convert.ToInt32(tempstr[i, 1]);//杆件起点编号 ClassBasicInfo.BarsNodes[i, 1] = Convert.ToInt32(tempstr[i, 2]);//杆件终点编号 ClassBasicInfo.LinearStiffness[i] = Convert.ToSingle(tempstr[i, 3]);//杆件刚度 } } public void InitNodes(string StrNodes) { //初始化节点信息 ClassReadTxt crt2 = new ClassReadTxt(StrNodes); string[,] temps = crt2.OutStr2D(); crt2.close(); //取得节点数 NumNodes = temps.GetLength(0); ClassBasicInfo.Coordinate = new Single[NumNodes, 2]; ClassBasicInfo.Restraint = new bool[NumNodes, 2]; ClassBasicInfo.Loads = new Single[NumNodes, 2]; for (int i = 0; i < NumNodes; i++) { ClassBasicInfo.Coordinate[i, 0] = Convert.ToSingle(temps[i, 1]);//节点x坐标 ClassBasicInfo.Coordinate[i, 1] = Convert.ToSingle(temps[i, 2]);//节点y坐标 ClassBasicInfo.Restraint[i, 0] = Convert.ToBoolean(Convert.ToInt32(temps[i, 3]));//节点x方向约束 ClassBasicInfo.Restraint[i, 1] = Convert.ToBoolean(Convert.ToInt32(temps[i, 4]));//节点y方向约束 ClassBasicInfo.Loads[i, 0] = Convert.ToSingle(temps[i, 5]);//节点x方向荷载 ClassBasicInfo.Loads[i, 1] = Convert.ToSingle(temps[i, 6]);//节点y方向荷载 } } //初始化有限元法基本方程矩阵 public void InitMatrix() { ClassBasicInfo.TatalStiffnessMatrix = new Single[NumNodes * 2,NumNodes * 2];//总刚度矩阵 ClassBasicInfo.TatalDisplacement = new Single[NumNodes * 2];//总位移列阵 ClassBasicInfo.TatalLoads = new Single[NumNodes * 2];//总荷载列阵 ClassBasicInfo.TatalRestraint = new bool[NumNodes * 2];//总边界条件 } //接口 public void Initialize(string StrBars,string StrNodes) { this.InitBars(StrBars); this.InitNodes(StrNodes); this.InitMatrix(); } } }
至此,完成基本信息的存放,以静态数组的方式储存,方便全局范围的访问。
其中,PlaceUsingTxt.dll 的源码参见:http://blog.csdn.net/silyvin/article/details/6758196