| | |
| | | emitterSb.AppendLine(";Junction \tCoefficient"); |
| | | |
| | | //坐标 |
| | | var coorSb = new StringBuilder(); |
| | | coorSb.AppendLine(";Node X-Coord Y-Coord"); |
| | | var coorStringBuilder = new StringBuilder(); |
| | | coorStringBuilder.AppendLine(";Node X-Coord Y-Coord"); |
| | | |
| | | Dictionary<string, string> dictExchange = new Dictionary<string, string>() { |
| | | {"{junctions}","{0}" }, |
| | |
| | | dictExchange.ToList().ForEach(m => templateString = templateString.Replace(m.Key, m.Value)); |
| | | |
| | | //连接节点 |
| | | var junctionSb = new StringBuilder(); |
| | | junctionSb.AppendLine(";ID Elev Demand Pattern Type"); |
| | | var junctionStringBuilder = new StringBuilder(); |
| | | junctionStringBuilder.AppendLine(";ID Elev Demand Pattern Type"); |
| | | //连接节点处理 |
| | | network.Junctions?.ForEach(x => |
| | | { |
| | | var demandPattern = x.DemandPattern; |
| | | if (string.IsNullOrEmpty(demandPattern) || demandPattern == ";" || demandPattern == "_") |
| | | { |
| | | demandPattern = ""; |
| | | demandPattern = string.Empty; |
| | | } |
| | | junctionSb.AppendLine($"{x.Id}\t{x.Elev}\t{x.Demand}\t{demandPattern}\t;\t" + $"0\tJunction"); |
| | | coorSb.AppendLine(x.Id + " " + x.Position.X + " " + x.Position.Y); |
| | | junctionStringBuilder.AppendLine($"{x.Id}\t{x.Elev}\t{x.Demand}\t{demandPattern}\t;\t" + $"0\tJunction"); |
| | | coorStringBuilder.AppendLine(x.Id + " " + x.Position.X + " " + x.Position.Y); |
| | | }); |
| | | |
| | | network.GetAllCouplings()?.ForEach(x => |
| | | { |
| | | var demandPattern = x.DemandPattern; |
| | | if (string.IsNullOrEmpty(demandPattern) || demandPattern == ";" || demandPattern == "_") |
| | | { |
| | | demandPattern = string.Empty; |
| | | } |
| | | junctionStringBuilder.AppendLine($"{x.Id}\t{x.Elev}\t{x.Demand}\t{demandPattern}\t;\t" + $"0\tCoupling"); |
| | | coorStringBuilder.AppendLine(x.Id + " " + x.Position.X + " " + x.Position.Y); |
| | | }); |
| | | |
| | | network.GetAllInstruments()?.ForEach(x => |
| | | { |
| | | var demandPattern = x.DemandPattern; |
| | | if (string.IsNullOrEmpty(demandPattern) || demandPattern == ";" || demandPattern == "_") |
| | | { |
| | | demandPattern = string.Empty; |
| | | } |
| | | junctionStringBuilder.AppendLine($"{x.Id}\t{x.Elev}\t{x.Demand}\t{demandPattern}\t;\t" + $"0\tInstrument"); |
| | | coorStringBuilder.AppendLine(x.Id + " " + x.Position.X + " " + x.Position.Y); |
| | | }); |
| | | |
| | | //水表处理 |
| | | network.Meters?.ForEach(x => |
| | | { |
| | |
| | | { |
| | | demandPattern = ""; |
| | | } |
| | | junctionSb.AppendLine($"{x.Id}\t{x.Elev}\t{x.Demand}\t{demandPattern}\t;\t" + $"0\tMeters"); |
| | | coorSb.AppendLine(x.Id + " " + x.Position.X + " " + x.Position.Y); |
| | | junctionStringBuilder.AppendLine($"{x.Id}\t{x.Elev}\t{x.Demand}\t{demandPattern}\t;\t" + $"0\tMeters"); |
| | | coorStringBuilder.AppendLine(x.Id + " " + x.Position.X + " " + x.Position.Y); |
| | | }); |
| | | //喷头处理 |
| | | network.Nozzles?.ForEach(x => |
| | |
| | | { |
| | | demandPattern = ""; |
| | | } |
| | | junctionSb.AppendLine($"{x.Id}\t{x.Elev}\t{x.Demand}\t{demandPattern}\t;\t" + $"0\tNozzle\t{x.Coefficient}"); |
| | | junctionStringBuilder.AppendLine($"{x.Id}\t{x.Elev}\t{x.Demand}\t{demandPattern}\t;\t" + $"0\tNozzle\t{x.Coefficient}"); |
| | | double coefficient = x.Coefficient * Math.Pow(10 / 101.972, 0.5) / 1000 * 60; |
| | | emitterSb.AppendLine(x.Id + " " + coefficient); |
| | | coorSb.AppendLine(x.Id + " " + x.Position.X + " " + x.Position.Y); |
| | | coorStringBuilder.AppendLine(x.Id + " " + x.Position.X + " " + x.Position.Y); |
| | | }); |
| | | var junctionString = junctionSb.ToString(); |
| | | var junctionString = junctionStringBuilder.ToString(); |
| | | |
| | | //水库处理 |
| | | var reservoirSb = new StringBuilder(); |
| | |
| | | network.Reservoirs?.ForEach(x => |
| | | { |
| | | reservoirSb.AppendLine($"{x.Id}\t{x.Head}\t{x.HeadPattern}\t;\t" + $"0\t{x.PoolElev}"); |
| | | coorSb.AppendLine(x.Id + " " + x.Position.X + " " + x.Position.Y); |
| | | coorStringBuilder.AppendLine(x.Id + " " + x.Position.X + " " + x.Position.Y); |
| | | }); |
| | | string reserverString = reservoirSb.ToString(); |
| | | |
| | |
| | | { |
| | | // tankStringBuilder.AppendLine($"{o.Id}\t{o.PoolElev}\t{o.InitLevel}\t{o.MinLevel}\t{o.MaxLevel}\t{o.Diameter}\t{o.MinVol}\t{o.VolCurve}\t{o.Overflow}\t;\t");// + $"0"); |
| | | tankSb.AppendLine($"{o.Id}\t{o.PoolElev}\t{o.InitLevel}\t{o.MinLevel}\t{o.MaxLevel}\t{o.Diameter}\t{o.MinVol}\t{o.VolCurve}\t;\t");// + $"0"); |
| | | coorSb.AppendLine(o.Id + " " + o.Position.X + " " + o.Position.Y); |
| | | coorStringBuilder.AppendLine(o.Id + " " + o.Position.X + " " + o.Position.Y); |
| | | }); |
| | | string tankString = tankSb.ToString(); |
| | | |
| | |
| | | x.Roughness = 110; |
| | | } |
| | | string statusString = x.LinkStatus == PipeStatus.Closed ? "CLOSED" : ""; |
| | | pipeSb.AppendLine($"{x.Id}\t{x.StartNode.Id}\t{x.EndNode.Id}\t{x.Length}\t{x.Diameter}\t{x.Roughness}\t{x.MinorLoss}\t{statusString}\t;\t");// + $"{p.Level}"); |
| | | double minorLoss = x.MinorLossCoeff + x.EndMinorLossCoeff + x.StartMinorLossCoeff; |
| | | pipeSb.AppendLine($"{x.Id}\t{x.StartNode.Id}\t{x.EndNode.Id}\t{x.Length}\t{x.Diameter}\t{x.Roughness}\t{minorLoss}\t{statusString}\t;\t");// + $"{p.Level}"); |
| | | if (x.LinkStatus != PipeStatus.Open) |
| | | { |
| | | statusSb.AppendLine(x.Id + "\t" + statusString); |
| | |
| | | valveSb.AppendLine(";ID Node1 Node2 Diameter Type Setting MinorLoss "); |
| | | network.Valves?.ForEach(x => |
| | | { |
| | | valveSb.AppendLine($"{x.Id}\t{x.StartNode.Id}\t{x.EndNode.Id}\t{x.Diameter:F4}\t{x.ValveType}\t{x.ValveSetting}\t{x.MinorLoss:F4}\t;\t");// + $"0"); |
| | | if (!string.IsNullOrEmpty(x.LinkStatus)) |
| | | if (x.Id == "694311") |
| | | { |
| | | |
| | | } |
| | | string settings; |
| | | if (x.LinkStatus == ValveStatus.None) |
| | | { |
| | | settings = x.ValveSetting; |
| | | } |
| | | else |
| | | { |
| | | settings = "Undefined"; |
| | | } |
| | | if (string.IsNullOrEmpty(settings)) settings = "Undefined"; |
| | | valveSb.AppendLine($"{x.Id}\t{x.StartNode.Id}\t{x.EndNode.Id}\t{x.Diameter:F4}\t{x.ValveType}\t{settings}\t{x.MinorLoss:F4}\t;\t");// + $"0"); |
| | | if (!string.IsNullOrEmpty(x.LinkStatus) && x.LinkStatus != ValveStatus.None) |
| | | { |
| | | statusSb.AppendLine(x.Id + "\t" + x.LinkStatus); |
| | | } |
| | |
| | | { |
| | | type = "Compressor"; |
| | | } |
| | | valveSb.AppendLine($"{x.Id}\t{x.StartNode.Id}\t{x.EndNode.Id}\t{x.Diameter:F4}\tGPV\t{x.CurveQL}\t{x.MinorLoss:F4}\t;\t{type}");// + $"0"); |
| | | if (!string.IsNullOrEmpty(x.LinkStatus)) |
| | | string settings; |
| | | if (x.LinkStatus == ValveStatus.None) |
| | | { |
| | | settings = x.CurveQL; |
| | | } |
| | | else |
| | | { |
| | | settings = "Undefined"; |
| | | } |
| | | if (string.IsNullOrEmpty(settings)) settings = "Undefined"; |
| | | |
| | | valveSb.AppendLine($"{x.Id}\t{x.StartNode.Id}\t{x.EndNode.Id}\t{x.Diameter:F4}\tGPV\t{settings}\t{x.MinorLoss:F4}\t;\t{type}");// + $"0"); |
| | | if (!string.IsNullOrEmpty(x.LinkStatus) && x.LinkStatus != ValveStatus.None) |
| | | { |
| | | statusSb.AppendLine(x.Id + "\t" + x.LinkStatus); |
| | | } |
| | |
| | | else |
| | | statusString = $"\t{o.SpeedRatio}"; |
| | | } |
| | | statusSb.AppendLine(o.Id + statusString); |
| | | if (!string.IsNullOrEmpty(o.LinkStatus)) |
| | | { |
| | | statusSb.AppendLine(o.Id + statusString); |
| | | } |
| | | |
| | | }); |
| | | string pumpString = pumpSb.ToString(); |
| | | |
| | |
| | | }); |
| | | string curveString = curveSb.ToString(); |
| | | |
| | | string coorString = coorSb.ToString(); |
| | | string coorString = coorStringBuilder.ToString(); |
| | | string output = ""; |
| | | string emitterString = emitterSb.ToString(); |
| | | string statusString = statusSb.ToString(); |
| | |
| | | p.Roughness = roughness; |
| | | float minorLoss; |
| | | if (float.TryParse(parts[6], out minorLoss)) |
| | | p.MinorLoss = minorLoss; |
| | | p.LinkStatus = parts.Length > 7 ? PipeStatus.Closed : PipeStatus.Open; |
| | | //int level; |
| | | //if (int.TryParse(parts[8], out level)) |
| | | // p.Level = level; |
| | | p.MinorLossCoeff = minorLoss; |
| | | p.LinkStatus = parts.Length > 7 ? (parts[7].ToUpper().Contains("CLOSE") ? PipeStatus.Closed : PipeStatus.Open) : PipeStatus.Open; |
| | | |
| | | net.Pipes.Add(p); |
| | | } |
| | | break; |
| | |
| | | |
| | | } |
| | | break; |
| | | case "PUMPS": |
| | | { |
| | | InpPump pump = new InpPump(); |
| | | |
| | | pump.Id = parts.ToString(0, null); |
| | | |
| | | // 取出Node1和Node2中的字母部分,例如“S201326593”被取出为“201326593” |
| | | pump.Node1 = parts.ToString(1, null); // Regex.Replace(parts[1], "[^0-9]", ""); |
| | | pump.Node2 = parts.ToString(2, null);// parts.ToString(2, null); // Regex.Replace(parts[2], "[^0-9]", ""); |
| | | int index = 3; |
| | | string label = null; |
| | | while ((label = parts.ToString(index, null)) != null) |
| | | { |
| | | label = label.ToUpper(); |
| | | switch (label) |
| | | { |
| | | case "HEAD": |
| | | pump.CurveQH = parts.ToString(index + 1, "PumpDefault"); |
| | | break; |
| | | case "SPEED": |
| | | pump.SpeedRatio = parts.ToFloat(index + 1, 0); |
| | | break; |
| | | } |
| | | index += 2; |
| | | } |
| | | //pump.Diameter = parts.ToFloat(3, 0); |
| | | |
| | | pump.LinkStatus = "OPEN"; |
| | | net.Pumps.Add(pump); |
| | | } |
| | | break; |
| | | case "STATUS": |
| | | { |
| | | Link link = net.GetAllLinks().Find(l => l.Id == parts.ToString(0, null)); |
| | | if (link != null) |
| | | link.LinkStatus = parts[1]; |
| | | } |
| | | break; |
| | | case "COORDINATES": |
| | | { |
| | | string id = parts[0]; |