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  解决方案一览



  • 相关阅读:
    FindWindowEx
    c# 基础知识
    propertychange 属性说明
    Python3-2020-测试开发-22- 异常
    Python3-2020-测试开发-21- 面向对象之封装,继承,多态
    Python3-2020-测试开发-20- Python中装饰器@property
    Python3-2020-测试开发-19- Python中私有属性和私有方法
    Python3-2020-测试开发-18- Python中方法没有重载
    Python3-2020-测试开发-17- 类编程
    Python3-2020-测试开发-16- 嵌套函数(内部函数 )&nonlacal声明外部函数的局部变量&LEGB规则
  • 原文地址:https://www.cnblogs.com/silyvin/p/9106921.html
Copyright © 2011-2022 走看看