| | |
| | | using Hydro.Core.Model; |
| | | //using Hydro.HydraulicModel; |
| | | using System; |
| | | using System.Collections.Generic; |
| | | using System.Data; |
| | | using System.Drawing; |
| | | using System.IO; |
| | | using System.IO.Ports; |
| | |
| | | public NetWork() |
| | | { |
| | | } |
| | | public string Title { get; set; } |
| | | |
| | | private List<JunctionModel> Junctions { get; set; } = new List<JunctionModel>(); |
| | | |
| | | private List<TankModel> Tanks { get; set; } = new List<TankModel>(); |
| | | |
| | | private List<PipeModel> Pipes { get; set; } = new List<PipeModel>(); |
| | | |
| | | private List<PumpModel> Pumps { get; set; } = new List<PumpModel>(); |
| | | |
| | | private List<ValveModel> Valves { get; set; } = new List<ValveModel>(); |
| | | |
| | | private List<ReservoisModel> Reservos { get; set; } = new List<ReservoisModel>(); |
| | | |
| | | private List<MeterModel> Meters { get; set; } = new List<MeterModel>(); |
| | | |
| | | private List<NozzleModel> Nozzles { get; set; } = new List<NozzleModel>(); |
| | | |
| | | public void AddJunction(JunctionModel junction) |
| | | public List<JunctionModel> Junctions |
| | | { |
| | | Junctions.Add(junction); |
| | | get |
| | | { |
| | | var js = Nodes.Where(d => d is JunctionModel); |
| | | return js?.Select(d => d as JunctionModel).ToList(); |
| | | } |
| | | |
| | | } |
| | | public List<TankModel> Tanks |
| | | { |
| | | get |
| | | { |
| | | var js = Nodes.Where(d => d is TankModel); |
| | | return js?.Select(d => d as TankModel).ToList(); |
| | | } |
| | | } |
| | | |
| | | public List<PipeModel> Pipes |
| | | { |
| | | get |
| | | { |
| | | var js = Links.Where(d => d is PipeModel); |
| | | return js?.Select(d => d as PipeModel).ToList(); |
| | | } |
| | | } |
| | | |
| | | public List<PumpModel> Pumps |
| | | { |
| | | get |
| | | { |
| | | var js = Links.Where(d => d is PumpModel); |
| | | return js?.Select(d => d as PumpModel).ToList(); |
| | | } |
| | | } |
| | | |
| | | public List<ValveModel> Valves |
| | | { |
| | | get |
| | | { |
| | | var js = Links.Where(d => d is ValveModel); |
| | | return js?.Select(d => d as ValveModel).ToList(); |
| | | } |
| | | } |
| | | |
| | | public List<ReservoisModel> Reservos |
| | | { |
| | | get |
| | | { |
| | | var js = Nodes.Where(d => d is ReservoisModel); |
| | | return js?.Select(d => d as ReservoisModel).ToList(); |
| | | } |
| | | } |
| | | |
| | | public List<MeterModel> Meters |
| | | { |
| | | get |
| | | { |
| | | var js = Nodes.Where(d => d is MeterModel); |
| | | return js?.Select(d => d as MeterModel).ToList(); |
| | | } |
| | | } |
| | | |
| | | public List<NozzleModel> Nozzles |
| | | { |
| | | get |
| | | { |
| | | var js = Nodes.Where(d => d is NozzleModel); |
| | | return js?.Select(d => d as NozzleModel).ToList(); |
| | | } |
| | | } |
| | | |
| | | public virtual void AddJunction(JunctionModel junction) |
| | | { |
| | | CheckNodesExist(junction); |
| | | Nodes.Add(junction); |
| | | } |
| | | |
| | | public void AddTank(TankModel tank) |
| | | public virtual void AddJunctions(List<JunctionModel> junctions) |
| | | { |
| | | Tanks.Add(tank); |
| | | junctions.ForEach(junction => { AddJunction(junction); }); |
| | | } |
| | | |
| | | public virtual void AddTank(TankModel tank) |
| | | { |
| | | CheckNodesExist(tank); |
| | | Nodes.Add(tank); |
| | | } |
| | | |
| | | public void AddPipe(PipeModel pipe) |
| | | public virtual void AddTanks(List<TankModel> tanks) |
| | | { |
| | | Pipes.Add(pipe); |
| | | tanks.ForEach(tank => { AddTank(tank); }); |
| | | } |
| | | |
| | | public virtual void AddPipe(PipeModel pipe) |
| | | { |
| | | CheckLinksExist(pipe); |
| | | Links.Add(pipe); |
| | | } |
| | | |
| | | public void AddPump(PumpModel pump) |
| | | public virtual void AddPipes(List<PipeModel> pipes) |
| | | { |
| | | Pumps.Add(pump); |
| | | pipes.ForEach(pipe => { AddPipe(pipe); }); |
| | | } |
| | | public virtual void AddPump(PumpModel pump) |
| | | { |
| | | CheckLinksExist(pump); |
| | | Links.Add(pump); |
| | | } |
| | | |
| | | public void AddValve(ValveModel valve) |
| | | public virtual void AddPumps(List<PumpModel> pumps) |
| | | { |
| | | Valves.Add(valve); |
| | | pumps.ForEach(pump => { AddPump(pump); }); |
| | | } |
| | | public virtual void AddValve(ValveModel valve) |
| | | { |
| | | CheckLinksExist(valve); |
| | | Links.Add(valve); |
| | | } |
| | | |
| | | public void AddReservos(ReservoisModel reservois) |
| | | public virtual void AddValves(List<ValveModel> valves) |
| | | { |
| | | Reservos.Add(reservois); |
| | | valves.ForEach(valve => { AddValve(valve); }); |
| | | } |
| | | public virtual void AddReservos(ReservoisModel reservois) |
| | | { |
| | | CheckNodesExist(reservois); |
| | | Nodes.Add(reservois); |
| | | } |
| | | |
| | | public void AddMeter(MeterModel meter) |
| | | public virtual void AddReservoss(List<ReservoisModel> reservoiss) |
| | | { |
| | | Meters.Add(meter); |
| | | reservoiss.ForEach(reservois => { AddReservos(reservois); }); |
| | | } |
| | | public virtual void AddMeter(MeterModel meter) |
| | | { |
| | | CheckNodesExist(meter); |
| | | Nodes.Add(meter); |
| | | Junctions.Add(meter.ToJunction()); |
| | | } |
| | | |
| | | public void AddNozzle(NozzleModel nozzle) |
| | | public virtual void AddMeters(List<MeterModel> meters) |
| | | { |
| | | Nozzles.Add(nozzle); |
| | | meters.ForEach(meter => { AddMeter(meter); }); |
| | | } |
| | | public virtual void AddNozzle(NozzleModel nozzle) |
| | | { |
| | | CheckNodesExist(nozzle); |
| | | Nodes.Add(nozzle); |
| | | Junctions.Add(nozzle.ToJunction()); |
| | | } |
| | | public virtual void AddNozzles(List<NozzleModel> nozzles) |
| | | { |
| | | nozzles.ForEach(nozzle => { AddNozzle(nozzle); }); |
| | | } |
| | | |
| | | public List<NodeModel> Nodes { get; set; } = new List<NodeModel>(); |
| | | public List<LinkModel> Links { get; set; } = new List<LinkModel>(); |
| | | private void CheckNodesExist(NodeCalcModel node) |
| | | { |
| | | if (Nodes.Any(d => d.ID == node.ID)) |
| | | throw new Exception("已存在重复的对象"); |
| | | } |
| | | |
| | | private void CheckLinksExist(LinkCalcModel link) |
| | | { |
| | | if (Links.Any(d => d.ID == link.ID)) |
| | | throw new Exception("已存在重复的对象"); |
| | | } |
| | | |
| | | public List<NodeCalcModel> Nodes { get; set; } = new List<NodeCalcModel>(); |
| | | public List<LinkCalcModel> Links { get; set; } = new List<LinkCalcModel>(); |
| | | |
| | | /// <summary> |
| | | /// 根据INP文件生成 |
| | |
| | | Elev = Elev, |
| | | Demand = Demand, |
| | | PatternID = PatternID, |
| | | Level = Level |
| | | }); |
| | | } |
| | | else if (parts[5] == "Nozzle") |
| | |
| | | Elev = Elev, |
| | | Demand = Demand, |
| | | PatternID = PatternID, |
| | | Level = Level |
| | | }); |
| | | } |
| | | else |
| | |
| | | Elev = Elev, |
| | | Demand = Demand, |
| | | PatternID = PatternID, |
| | | Level = Level |
| | | }); |
| | | } |
| | | |
| | |
| | | r.Head = head; |
| | | r.PatternID = parts.Length > 2 ? parts[2] : ""; |
| | | int level; |
| | | if (int.TryParse(parts[3], out level)) |
| | | r.Level = level; |
| | | //if (int.TryParse(parts[3], out level)) |
| | | // r.Level = level; |
| | | AddReservos(r); |
| | | } |
| | | break; |
| | |
| | | VolCurve = "", |
| | | IsOverFlow = true |
| | | }; |
| | | int level; |
| | | if (int.TryParse(parts[9], out level)) |
| | | tank.Level = level; |
| | | //int level; |
| | | //if (int.TryParse(parts[9], out level)) |
| | | // tank.Level = level; |
| | | AddTank(tank); |
| | | } |
| | | break; |
| | |
| | | if (float.TryParse(parts[6], out minorLoss)) |
| | | p.MinorLoss = minorLoss; |
| | | p.Status = parts.Length > 7 ? StatusType.CLOSED : StatusType.DEFAULT; |
| | | int level; |
| | | if (int.TryParse(parts[8], out level)) |
| | | p.Level = level; |
| | | //int level; |
| | | //if (int.TryParse(parts[8], out level)) |
| | | // p.Level = level; |
| | | AddPipe(p); |
| | | } |
| | | break; |
| | |
| | | float minorLoss; |
| | | if (float.TryParse(parts[6], out minorLoss)) |
| | | valve.MinorLoss = minorLoss; |
| | | int level; |
| | | if (int.TryParse(parts[7], out level)) |
| | | valve.Level = level; |
| | | //int level; |
| | | //if (int.TryParse(parts[7], out level)) |
| | | // valve.Level = level; |
| | | AddValve(valve); |
| | | } |
| | | break; |
| | |
| | | } |
| | | sr.Close(); |
| | | |
| | | //读取坐标 |
| | | Junctions.ForEach(o => |
| | | { |
| | | var p = points.Where(d => d.ID == o.ID).FirstOrDefault(); |
| | | if (p != null) |
| | | { |
| | | o.X = p.Position.X; |
| | | o.Y = p.Position.Y; |
| | | } |
| | | }); |
| | | #region 坐标匹配方法 |
| | | #endregion |
| | | |
| | | Reservos.ForEach(o => |
| | | { |
| | | var p = points.Where(d => d.ID == o.ID).FirstOrDefault(); |
| | | if (p != null) |
| | | { |
| | | o.X = p.Position.X; |
| | | o.Y = p.Position.Y; |
| | | } |
| | | }); |
| | | #region 删除 |
| | | //[Cloudflight修改]2023-11-27 二重循环匹配坐标速度太慢 |
| | | ////读取坐标 |
| | | //Junctions.ForEach(o => |
| | | //{ |
| | | // var p = points.Where(d => d.ID == o.ID).FirstOrDefault(); |
| | | // if (p != null) |
| | | // { |
| | | // o.X = p.Position.X; |
| | | // o.Y = p.Position.Y; |
| | | // } |
| | | //}); |
| | | |
| | | Tanks.ForEach(o => |
| | | { |
| | | var p = points.Where(d => d.ID == o.ID).FirstOrDefault(); |
| | | if (p != null) |
| | | { |
| | | o.X = p.Position.X; |
| | | o.Y = p.Position.Y; |
| | | } |
| | | }); |
| | | //Reservos.ForEach(o => |
| | | //{ |
| | | // var p = points.Where(d => d.ID == o.ID).FirstOrDefault(); |
| | | // if (p != null) |
| | | // { |
| | | // o.X = p.Position.X; |
| | | // o.Y = p.Position.Y; |
| | | // } |
| | | //}); |
| | | |
| | | Meters.ForEach(o => |
| | | { |
| | | var p = points.Where(d => d.ID == o.ID).FirstOrDefault(); |
| | | if (p != null) |
| | | { |
| | | o.X = p.Position.X; |
| | | o.Y = p.Position.Y; |
| | | } |
| | | }); |
| | | //Tanks.ForEach(o => |
| | | //{ |
| | | // var p = points.Where(d => d.ID == o.ID).FirstOrDefault(); |
| | | // if (p != null) |
| | | // { |
| | | // o.X = p.Position.X; |
| | | // o.Y = p.Position.Y; |
| | | // } |
| | | //}); |
| | | |
| | | Nozzles.ForEach(o => |
| | | { |
| | | var p = points.Where(d => d.ID == o.ID).FirstOrDefault(); |
| | | if (p != null) |
| | | { |
| | | o.X = p.Position.X; |
| | | o.Y = p.Position.Y; |
| | | } |
| | | }); |
| | | //Meters.ForEach(o => |
| | | //{ |
| | | // var p = points.Where(d => d.ID == o.ID).FirstOrDefault(); |
| | | // if (p != null) |
| | | // { |
| | | // o.X = p.Position.X; |
| | | // o.Y = p.Position.Y; |
| | | // } |
| | | //}); |
| | | |
| | | //Nozzles.ForEach(o => |
| | | //{ |
| | | // var p = points.Where(d => d.ID == o.ID).FirstOrDefault(); |
| | | // if (p != null) |
| | | // { |
| | | // o.X = p.Position.X; |
| | | // o.Y = p.Position.Y; |
| | | // } |
| | | //}); |
| | | #endregion |
| | | |
| | | #region 优化方案 |
| | | int k1 = 0; |
| | | int k2 = 0; |
| | | #region delete |
| | | |
| | | //Nodes.Sort((a, b) => string.Compare(a.ID, b.ID)); |
| | | //points.Sort((a, b) => string.Compare(a.ID, b.ID)); |
| | | //k1 = 0; |
| | | //k2 = 0; |
| | | //while (k1 < Nodes.Count) |
| | | //{ |
| | | // var J = Nodes[k1]; |
| | | // var coor = points[k2]; |
| | | |
| | | // while (J.ID != coor.ID && k2 < points.Count) |
| | | // { |
| | | // k2++; |
| | | // if (k2 < points.Count) coor = points[k2]; |
| | | Nodes.Sort((a, b) => string.Compare(a.ID, b.ID)); |
| | | points.Sort((a, b) => string.Compare(a.ID, b.ID)); |
| | | k1 = 0; |
| | | k2 = 0; |
| | | while (k1 < Nodes.Count) |
| | | { |
| | | var J = Nodes[k1]; |
| | | var coor = points[k2]; |
| | | |
| | | // } |
| | | // if (k2 == points.Count) |
| | | // { |
| | | // throw new Exception($"未找到Node[{J.ID}]的坐标"); |
| | | // } |
| | | // J.X = coor.Position.X; |
| | | // J.Y = coor.Position.Y; |
| | | while (J.ID != coor.ID && k2 < points.Count) |
| | | { |
| | | k2++; |
| | | if (k2 < points.Count) coor = points[k2]; |
| | | |
| | | // k1++; |
| | | //} |
| | | } |
| | | if (k2 == points.Count) |
| | | { |
| | | throw new Exception($"未找到Node[{J.ID}]的坐标"); |
| | | } |
| | | J.X = coor.Position.X; |
| | | J.Y = coor.Position.Y; |
| | | |
| | | k1++; |
| | | } |
| | | #endregion |
| | | |
| | | |
| | | |
| | | //建立点线关系链表StartNode,先将管线以Node1(节点1的ID)排序,再将Nodes按ID排序,建立两个游标k1、k2,正向一次循环,建立链表关系 |
| | |
| | | //if (J.MaxDiameter < p.Diameter) J.MaxDiameter = p.Diameter; |
| | | //J.Links.Add(p); |
| | | k2++; |
| | | |
| | | } |
| | | return true; |
| | | } |
| | |
| | | /// <param name="InpPath">Inp文件路径</param> |
| | | /// <param name="TemplateInpFullPath">Inp模板文件绝对路径,如果为空就用系统默认模板文件</param> |
| | | /// <exception cref="Exception"></exception> |
| | | public virtual void BuildToInp(string InpPath, string TemplateInpFullPath = "") |
| | | public virtual void BuildToInp(string InpPath, string TemplateInpFullPath = "", string sourcePath = null, bool isReplace = false) |
| | | { |
| | | |
| | | string tempString = ""; |
| | |
| | | } |
| | | if (!File.Exists(tempPath)) |
| | | { |
| | | throw new Exception("模板文件不存在"); |
| | | throw new Exception("模板文件不存在," + tempPath); |
| | | } |
| | | if (!File.Exists(InpPath)) |
| | | File.Create(InpPath).Close(); |
| | |
| | | |
| | | Junctions.ForEach(j => |
| | | { |
| | | junctionStringBuilder.AppendLine(j.ToString() + $"{j.Level}\tJunction"); |
| | | junctionStringBuilder.AppendLine(j.ToString() + $"0\tJunction"); |
| | | coorStringBuilder.AppendLine(j.ToCoorString()); |
| | | |
| | | }); |
| | | Meters.ForEach(m => |
| | | { |
| | | junctionStringBuilder.AppendLine(m.ToString() + $"{m.Level}\tMeter"); |
| | | junctionStringBuilder.AppendLine(m.ToString() + $"0\tMeters"); |
| | | coorStringBuilder.AppendLine(m.ToCoorString()); |
| | | }); |
| | | Nozzles.ForEach(no => |
| | | { |
| | | junctionStringBuilder.AppendLine(no.ToString() + $"{no.Level}\tNozzle\t{no.FlowCoefficient}"); |
| | | junctionStringBuilder.AppendLine(no.ToString() + $"0\tNozzle\t{no.FlowCoefficient}"); |
| | | emitterStringBuilder.Append(no.ToEmitterString()); |
| | | coorStringBuilder.AppendLine(no.ToCoorString()); |
| | | }); |
| | |
| | | |
| | | Reservos.ForEach(o => |
| | | { |
| | | reservoirStringBuilder.AppendLine(o.ToString() + $"{o.Level}\t{o.Elev}"); |
| | | reservoirStringBuilder.AppendLine(o.ToString() + $"0\t{o.Elev}"); |
| | | coorStringBuilder.AppendLine(o.ToCoorString()); |
| | | }); |
| | | string reserverString = reservoirStringBuilder.ToString(); |
| | |
| | | |
| | | Tanks.ForEach(o => |
| | | { |
| | | tankStringBuilder.AppendLine(o.ToString() + $"{o.Level}"); |
| | | tankStringBuilder.AppendLine(o.ToString());// + $"0"); |
| | | coorStringBuilder.AppendLine(o.ToCoorString()); |
| | | }); |
| | | string tankString = tankStringBuilder.ToString(); |
| | |
| | | |
| | | Pipes.ForEach(p => |
| | | { |
| | | pipeStringBuilder.AppendLine(p.ToString() + $"{p.Level}"); |
| | | pipeStringBuilder.AppendLine(p.ToString());// + $"{p.Level}"); |
| | | statusStringBuilder.Append(p.ToStatusString()); |
| | | }); |
| | | |
| | |
| | | |
| | | Valves.ForEach(o => |
| | | { |
| | | valveStringBuilder.AppendLine(o.ToString() + $"{o.Level}"); |
| | | valveStringBuilder.AppendLine(o.ToString());// + $"0"); |
| | | statusStringBuilder.Append(o.ToStatusString()); |
| | | }); |
| | | string valveString = valveStringBuilder.ToString(); |
| | |
| | | |
| | | Pumps.ForEach(o => |
| | | { |
| | | pumpStringBuilder.AppendLine(o.ToString() + $"{o.Level}"); |
| | | pumpStringBuilder.AppendLine(o.ToString());// + $"0"); |
| | | statusStringBuilder.Append(o.ToStatusString()); |
| | | }); |
| | | string pumpString = pumpStringBuilder.ToString(); |
| | |
| | | //Global.ClearFileReadOnly(InpPath); |
| | | File.WriteAllText(InpPath, output); |
| | | } |
| | | //public void BuildToInp(string filePath, string userCoorString = null, string sourcePath = null, bool isReplace = false) |
| | | //{ |
| | | |
| | | // if (sourcePath == null) sourcePath = filePath; |
| | | |
| | | // string tempString = ""; |
| | | // if (!isReplace) |
| | | // { |
| | | // var tempPath = Path.Combine(Directory.GetCurrentDirectory(), @"template\inp\导出模板.inp"); |
| | | // if (!File.Exists(tempPath)) |
| | | // { |
| | | // //MessageBox.Show($"模板文件不存在[{tempPath}]"); |
| | | // return; |
| | | // } |
| | | // tempString = File.ReadAllText(tempPath); |
| | | // } |
| | | // else |
| | | // { |
| | | // tempString = File.ReadAllText(sourcePath); |
| | | // } |
| | | |
| | | |
| | | // Dictionary<string, string> dictExchange = new Dictionary<string, string>() { |
| | | // {"{junctions}","{0}" }, |
| | | // {"{reservoirs}","{1}" }, |
| | | // {"{tanks}","{2}" }, |
| | | // {"{pipes}","{3}" }, |
| | | // {"{valves}","{4}" }, |
| | | // {"{pumps}","{5}" }, |
| | | |
| | | // {"{coor}","{6}" }, |
| | | // {"{curve}","{7}" }, |
| | | // }; |
| | | // dictExchange.ToList().ForEach(m => tempString = tempString.Replace(m.Key, m.Value)); |
| | | |
| | | // StringBuilder junctionStringBuilder = new StringBuilder(); |
| | | |
| | | // junctionStringBuilder.AppendLine(";ID Elev Demand Pattern Type"); |
| | | |
| | | // Nodes.ForEach(o => |
| | | // { |
| | | // //if (!o.Visible) return; |
| | | // if (o is JunctionModel j) |
| | | // junctionStringBuilder.AppendLine(j.ToString() + $"0\tJunction"); |
| | | // else if (o is MeterModel m) |
| | | // junctionStringBuilder.AppendLine(m.ToString() + $"0\tMeter"); |
| | | // else if (o is NozzleModel no) |
| | | // junctionStringBuilder.AppendLine(no.ToString() + $"0\tNozzle\t{no.FlowCoefficient}"); |
| | | // }); |
| | | // string junctionString = junctionStringBuilder.ToString(); |
| | | |
| | | // StringBuilder reservoirStringBuilder = new StringBuilder(); |
| | | |
| | | // reservoirStringBuilder.AppendLine(";ID Head Pattern "); |
| | | |
| | | // Reservos.ForEach(o => |
| | | // { |
| | | // //if (!o.Visible) return; |
| | | // reservoirStringBuilder.AppendLine(o.ToString() + $"0\t{o.Elev}"); |
| | | // }); |
| | | // string reserverString = reservoirStringBuilder.ToString(); |
| | | |
| | | // StringBuilder tankStringBuilder = new StringBuilder(); |
| | | |
| | | // tankStringBuilder.AppendLine(";ID Elevation InitLevel MinLevel MaxLevel Diameter MinVol VolCurve Overflow"); |
| | | |
| | | // Tanks.ForEach(o => |
| | | // { |
| | | // //if (!o.Visible) return; |
| | | // tankStringBuilder.AppendLine(o.ToString() + $"0"); |
| | | // }); |
| | | // string tankString = tankStringBuilder.ToString(); |
| | | |
| | | // StringBuilder pipeStringBuilder = new StringBuilder(); |
| | | |
| | | // pipeStringBuilder.AppendLine(";ID Node1 Node2 Length Diameter Roughness MinorLoss Status"); |
| | | |
| | | // Links.ForEach(o => |
| | | // { |
| | | // //if (!o.Visible) return; |
| | | // if (o is PipeModel p) |
| | | // pipeStringBuilder.AppendLine(p.ToString() + $"0"); |
| | | // //else if (o is RepeaterViewModel r) |
| | | // // pipeStringBuilder.AppendLine(r.ToString()); |
| | | // }); |
| | | // string pipeString = pipeStringBuilder.ToString(); |
| | | |
| | | // StringBuilder valveStringBuilder = new StringBuilder(); |
| | | |
| | | // valveStringBuilder.AppendLine(";ID Node1 Node2 Diameter Type Setting MinorLoss "); |
| | | |
| | | // Valves.ForEach(o => |
| | | // { |
| | | // //if (!o.Visible) return; |
| | | // valveStringBuilder.AppendLine(o.ToString() + $"0"); |
| | | // }); |
| | | // string valveString = valveStringBuilder.ToString(); |
| | | |
| | | // StringBuilder pumpStringBuilder = new StringBuilder(); |
| | | |
| | | // pumpStringBuilder.AppendLine(";ID Node1 Node2 Diameter Type Setting MinorLoss "); |
| | | |
| | | // Pumps.ForEach(o => |
| | | // { |
| | | // //if (!o.Visible) return; |
| | | // pumpStringBuilder.AppendLine(o.ToString() + $"0"); |
| | | // }); |
| | | // string pumpString = pumpStringBuilder.ToString(); |
| | | |
| | | |
| | | // StringBuilder curveStringBuilder = new StringBuilder(); |
| | | |
| | | |
| | | |
| | | // //pumps.ForEach(o => |
| | | // //{ |
| | | // // if (!o.Visible || !o.Datasets.ContainsKey("流量扬程曲线")) return; |
| | | // // curveStringBuilder.AppendLine(o.Datasets["流量扬程曲线"].ToString()); |
| | | // //}); |
| | | // if (dict_dataset != null) |
| | | // foreach (var kp in dict_dataset) |
| | | // { |
| | | // curveStringBuilder.AppendLine(kp.Value.ToString()); |
| | | // } |
| | | // string curveString = curveStringBuilder.ToString(); |
| | | |
| | | |
| | | // StringBuilder coorStringBuilder = new StringBuilder(); |
| | | // if (userCoorString == null) |
| | | // { |
| | | |
| | | // coorStringBuilder.AppendLine(";Node X-Coord Y-Coord"); |
| | | // Nodes.ForEach(o => coorStringBuilder.AppendLine(o.ToCoorString())); |
| | | // } |
| | | // else |
| | | // { |
| | | // coorStringBuilder.Append(userCoorString); |
| | | // } |
| | | |
| | | |
| | | |
| | | // string coorString = coorStringBuilder.ToString(); |
| | | // string output = ""; |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | // StringBuilder emitterStringBuilder = new StringBuilder(); |
| | | // emitterStringBuilder.AppendLine(";Junction \tCoefficient"); |
| | | // Nodes.ForEach(o => emitterStringBuilder.Append(o.ToEmitterString())); |
| | | |
| | | |
| | | |
| | | // string emitterString = emitterStringBuilder.ToString(); |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | // StringBuilder statusStringBuilder = new StringBuilder(); |
| | | // statusStringBuilder.AppendLine(";ID \tStatus/Setting\r\n"); |
| | | // Links.ForEach(o => statusStringBuilder.Append(o.ToStatusString())); |
| | | |
| | | |
| | | |
| | | // string statusString = statusStringBuilder.ToString(); |
| | | |
| | | |
| | | |
| | | // output = tempString; |
| | | |
| | | // output = ReplaceContent(output, "JUNCTIONS", junctionString); |
| | | // output = ReplaceContent(output, "RESERVOIRS", reserverString); |
| | | // output = ReplaceContent(output, "TANKS", tankString); |
| | | // output = ReplaceContent(output, "PIPES", pipeString); |
| | | // output = ReplaceContent(output, "VALVES", valveString); |
| | | // output = ReplaceContent(output, "PUMPS", pumpString); |
| | | // output = ReplaceContent(output, "CURVES", curveString); |
| | | |
| | | |
| | | // output = ReplaceContent(output, "COORDINATES", coorString); |
| | | // output = ReplaceContent(output, "EMITTERS", emitterString); |
| | | // output = ReplaceContent(output, "STATUS", statusString); |
| | | // string backupFolderPath = Path.Combine(Path.GetDirectoryName(filePath), "bk"); |
| | | // if (!Directory.Exists(backupFolderPath)) |
| | | // { |
| | | // Directory.CreateDirectory(backupFolderPath); |
| | | // } |
| | | |
| | | // string backupFileName = $"{Path.GetFileNameWithoutExtension(filePath)}_{DateTime.Now:yyyyMMddHHmmss}{Path.GetExtension(filePath)}"; |
| | | // string backupFilePath = Path.Combine(backupFolderPath, backupFileName); |
| | | // if (File.Exists(filePath)) File.Copy(filePath, backupFilePath, true); |
| | | |
| | | |
| | | // // 检查文件是否存在 |
| | | // try |
| | | // { |
| | | // Global.ClearFileReadOnly(filePath); |
| | | |
| | | // File.WriteAllText(filePath, output); |
| | | // } |
| | | // catch (Exception ex) |
| | | // { |
| | | // MessageBox.Show(ex.Message); |
| | | // } |
| | | |
| | | // //MessageBox.Show($"保存成功!"); |
| | | //} |
| | | /// <summary> |
| | | /// 根据Inp文件计算 |
| | | /// </summary> |
| | | /// <returns></returns> |
| | | public virtual List<TimePoint> Calc(string InpPath) |
| | | { |
| | | Epanet epanet = new Epanet(); |
| | | HydraulicModel.Epanet epanet = new HydraulicModel.Epanet(); |
| | | var result = new List<TimePoint>(); |
| | | var err = epanet.open(InpPath, "d:\\5.log", ""); |
| | | |
| | | 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); |
| | | epanet.getcount((int)CountType.Link, ref linkCount); |
| | | var sb = new StringBuilder(EpaHelper.MAXID); |
| | | const int MAXID = 31; |
| | | |
| | | var sb = new StringBuilder(MAXID); |
| | | |
| | | for (int i = 1; i < nodeCount; i++) |
| | | { |
| | | epanet.getnodeid(i, sb); |
| | | var arr = System.Enum.GetValues(typeof(NodeValueType)); |
| | | var arr = System.Enum.GetValues(typeof(HydraulicModel.NodeValueType)); |
| | | for (var j = 0; j < arr.Length; j++) |
| | | { |
| | | float v = 0; |
| | | var t = (NodeValueType)j; |
| | | var t = (HydraulicModel.NodeValueType)j; |
| | | epanet.getnodevalue(i, (int)t, ref v); |
| | | result.Add(new TimePoint() |
| | | { |
| | |
| | | for (int i = 1; i < linkCount; i++) |
| | | { |
| | | epanet.getlinkid(i, sb); |
| | | var arr = System.Enum.GetValues(typeof(LinkValueType)); |
| | | var arr = System.Enum.GetValues(typeof(HydraulicModel.LinkValueType)); |
| | | for (var j = 0; j < arr.Length; j++) |
| | | { |
| | | float v = 0; |
| | | var t = (LinkValueType)j; |
| | | var t = (HydraulicModel.LinkValueType)j; |
| | | epanet.getlinkvalue(i, (int)t, ref v); |
| | | result.Add(new TimePoint() |
| | | { |
| | |
| | | /// <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); |
| | | } |
| | |
| | | |
| | | private string ReplaceContent(string text, string content, string replaceString) |
| | | { |
| | | |
| | | |
| | | string str = replaceString; |
| | | |
| | | string replacedText = ReplaceCoordinatesSection(text, content, str); |
| | | |
| | | return replacedText; |
| | | //Console.WriteLine(replacedText); |
| | | } |
| | | |
| | | private string ReplaceCoordinatesSection(string text, string content, string str) |
| | | public static string ReplaceCoordinatesSection(string text, string content, string str) |
| | | { |
| | | string pattern = $@"(\[{content}\]).*?(\[|$)"; |
| | | |
| | | string replacedText = Regex.Replace(text, pattern, match => |
| | | { |
| | | string section = match.Groups[2].Value.Trim(); |
| | | |
| | | if (!string.IsNullOrEmpty(section)) |
| | | { |
| | | return $"{match.Groups[1].Value}\n{str}\n["; |
| | |
| | | return $"{match.Groups[1].Value}\n{str}\n["; |
| | | } |
| | | }, RegexOptions.Singleline); |
| | | |
| | | return replacedText; |
| | | } |
| | | |
| | | } |
| | | } |