cloudflight
2023-12-26 5fa6947054206e2e781eadd4effdcdf52eda28c4
Hydro.Inp/NetWork.cs
@@ -2,6 +2,7 @@
//using Hydro.HydraulicModel;
using System;
using System.Collections.Generic;
using System.Data;
using System.Drawing;
using System.IO;
using System.IO.Ports;
@@ -16,6 +17,7 @@
namespace Hydro.Inp
{
    [Serializable]
    public class NetWork //: INetWork
    {
        public NetWork()
@@ -174,20 +176,20 @@
            nozzles.ForEach(nozzle => { AddNozzle(nozzle); });
        }
        private void CheckNodesExist(NodeModel node)
        private void CheckNodesExist(NodeCalcModel node)
        {
            if (Nodes.Any(d => d.ID == node.ID))
                throw new Exception("已存在重复的对象");
        }
        private void CheckLinksExist(LinkModel link)
        private void CheckLinksExist(LinkCalcModel link)
        {
            if (Links.Any(d => d.ID == link.ID))
                throw new Exception("已存在重复的对象");
        }
        public List<NodeModel> Nodes { get; set; } = new List<NodeModel>();
        public List<LinkModel> Links { get; set; } = new List<LinkModel>();
        public List<NodeCalcModel> Nodes { get; set; } = new List<NodeCalcModel>();
        public List<LinkCalcModel> Links { get; set; } = new List<LinkCalcModel>();
        /// <summary>
        /// 根据INP文件生成
@@ -465,7 +467,7 @@
                #region 优化方案
                int k1 = 0;
                int k2 = 0;
                Nodes.Sort((a, b) => string.Compare(a.ID, b.ID));
                points.Sort((a, b) => string.Compare(a.ID, b.ID));
@@ -493,7 +495,7 @@
                }
                #endregion
                //建立点线关系链表StartNode,先将管线以Node1(节点1的ID)排序,再将Nodes按ID排序,建立两个游标k1、k2,正向一次循环,建立链表关系
                //时间复杂度 O(n)
@@ -566,8 +568,15 @@
            {
                throw new Exception("模板文件不存在," + tempPath);
            }
            if (!File.Exists(InpPath))
            {
                FileInfo fi=new FileInfo(InpPath);
                if (!Directory.Exists(fi.DirectoryName))
                Directory.CreateDirectory(fi.DirectoryName);
                File.Create(InpPath).Close();
            }
            tempString = File.ReadAllText(tempPath);
            StringBuilder statusStringBuilder = new StringBuilder();
            statusStringBuilder.AppendLine(";ID              \tStatus/Setting\r\n");
@@ -951,12 +960,18 @@
        /// <returns></returns>
        public virtual List<TimePoint> Calc(string InpPath)
        {
            HydraulicModel.Epanet epanet = new HydraulicModel.Epanet();
            HydraulicModel.HydraulicCore epanet = new HydraulicModel.HydraulicCore();
            var result = new List<TimePoint>();
            var err = epanet.open(InpPath, "d:\\5.log", "");
            var err = epanet.open(InpPath, "", "");
            if (err != 0)
            {
                throw new Exception($"计算失败:{err}");
                throw new Exception($"打开计算文件失败:{err}");
            }
            var errCal = epanet.solveH();
            if (errCal != 0)
            {
                throw new Exception($"计算失败:{errCal}");
            }
            int nodeCount = 0, linkCount = 0;
            epanet.getcount((int)CountType.Node, ref nodeCount);
@@ -1007,7 +1022,8 @@
        /// <returns></returns>
        public virtual List<TimePoint> Calc()
        {
            var inpPath = Path.Combine(Directory.GetCurrentDirectory(), @"data\inp\calc.inp");
            var inpPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, @"data\inp\calc.inp");
            BuildToInp(inpPath);
            return Calc(inpPath);
        }
@@ -1057,4 +1073,8 @@
        }
    }
}