zoukankan      html  css  js  c++  java
  • .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  解决方案一览



  • 相关阅读:
    LR--用栈实现移进--归约分析(demo)
    阿里云ECS服务器socket无法连接的问题
    select客户端模型封装——回调方式快速建立客户端
    select服务器端模型封装——回调方式快速建立服务端
    python实现的ocr接口
    汉字字典树
    linux下简易端口扫描器
    Linux下cs简单通讯(socket)
    POj 1321 棋盘问题 DFS 回溯
    HDU 1097 快速幂
  • 原文地址:https://www.cnblogs.com/silyvin/p/9106921.html
Copyright © 2011-2022 走看看