.Net ( c# ) 与 Fortran 混合编程实例(二):杆系结构有限元法——平面桁架解答(4):测试

4.1  编写主程序

新建控制台程序,命名为 Main,添加对 Business.dll 的引用,新建类,命名为 ClassPrint,贴入:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using Business;

namespace Main
{
    class ClassPrint
    {
        string StrBarsPath;
        string StrNodesPath;

        //取得、构造初始文本路径
        public void GetInitPath()
        {
            Console.WriteLine("Please press down the path of Bars Information:");
            Console.Write(Environment.CurrentDirectory + "/");
            StrBarsPath = Environment.CurrentDirectory + "/" + Console.ReadLine();

            Console.WriteLine("Please press down the path of Nodes Information:");
            Console.Write(Environment.CurrentDirectory + "/");
            StrNodesPath = Environment.CurrentDirectory + "/" + Console.ReadLine();
        }

        public void PrintEquation()
        {
            //赋初值
            ClassGetBasicInfo c = new ClassGetBasicInfo();
            c.Initialize(StrBarsPath, StrNodesPath);

            //取得总刚度矩阵,总荷载列阵,总边界条件
            ClassCalculation cc = new ClassCalculation();
            cc.GetAll();

            //打印有限元法基本方程
            for (int i = 0; i < ClassBasicInfo.TatalRestraint.GetLength(0); i++)
            {
                for (int j = 0; j < ClassBasicInfo.TatalRestraint.GetLength(0); j++)
                {
                    Console.Write(ClassBasicInfo.TatalStiffnessMatrix[i, j].ToString() + "   ");
                }
                Console.Write(ClassBasicInfo.TatalRestraint[i].ToString() + "   ");
                Console.Write(ClassBasicInfo.TatalLoads[i].ToString() + "\n");
            }
        }

        public void PrintSolution()
        {
            //引入边界条件,求得并整合总位移列阵
            ClassBoundaryIn ccc = new ClassBoundaryIn();
            ccc.GetAll();

            //打印总位移列阵
            for (int i = 0; i < ClassBasicInfo.TatalDisplacement.GetLength(0); i++)
            {
                Console.WriteLine(ClassBasicInfo.TatalDisplacement[i].ToString() + "    " + ClassBasicInfo.TatalLoads[i].ToString());
            }
        }
    }
}

在 Program 入口中贴入:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using Business;

namespace Main
{
    class Program
    {
        static void Main(string[] args)
        {
            ClassPrint c = new ClassPrint();
            Console.WriteLine();
            c.GetInitPath();
            c.PrintEquation();
            Console.WriteLine();
            c.PrintSolution();
            Console.WriteLine();

            Console.ReadLine();
        }
    }
}

4.2  测试

运行程序,显示

键入 bars.txt ,显示

键入 nodes.txt,显示:


下面一块左列为总位移列阵,右列为总荷载列阵,分别代表节点 x、y 两方向的位移、荷载。


4.3  解决方案一览



你可能感兴趣的:(编程,.net,String,C#,Class,fortran)