| | |
| | | namespace Yw.WinFrmUI |
| | | { |
| | | /// <summary> |
| | | /// |
| | | /// 水力信息拓展 |
| | | /// </summary> |
| | | public static class HydroModelInfoExtensions |
| | | { |
| | | #region 可见字典 |
| | | |
| | | /// <summary> |
| | | /// 获取可见字典 |
| | | /// </summary> |
| | |
| | | return allVisualList?.ToDictionary(x => x.Code); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 计算 |
| | | /// </summary> |
| | | public static HydroCalcuResult Calcu(this Yw.Model.HydroModelInfo hydroInfo, string calcuMode = Yw.EPAnet.CalcuMode.Simple) |
| | | { |
| | | var network = hydroInfo.ToNetwork(); |
| | | if (network == null) |
| | | { |
| | | return default; |
| | | } |
| | | var calcuResult = network.Calcu(calcuMode); |
| | | if (calcuResult == null) |
| | | { |
| | | return default; |
| | | } |
| | | return hydroInfo.GetCalcuResult(calcuResult); |
| | | } |
| | | #endregion |
| | | |
| | | #region 修复管网方向 |
| | | |
| | | /// <summary> |
| | | /// 获取计算结果 |
| | | /// 修复管网方向 |
| | | /// </summary> |
| | | public static HydroCalcuResult GetCalcuResult(this Yw.Model.HydroModelInfo hydroInfo, Yw.EPAnet.CalcuResult calcuResult) |
| | | { |
| | | if (hydroInfo == null) |
| | | { |
| | | return default; |
| | | } |
| | | if (calcuResult == null) |
| | | { |
| | | return default; |
| | | } |
| | | |
| | | var hydroCalcuResult = new HydroCalcuResult(calcuResult); |
| | | |
| | | //流量计 |
| | | var allFlowmeterList = hydroInfo.Flowmeters; |
| | | if (allFlowmeterList != null && allFlowmeterList.Count > 0) |
| | | { |
| | | var allLinkList = hydroInfo.GetAllLinks(); |
| | | foreach (var flowmeter in allFlowmeterList) |
| | | { |
| | | var calcuFlowmeterResult = hydroCalcuResult.NodeList?.Find(x => x.Code == flowmeter.Code); |
| | | if (calcuFlowmeterResult != null) |
| | | { |
| | | var calcuFlowmeterNewResult = new HydroCalcuFlowmeterResult(calcuFlowmeterResult); |
| | | var calcuFlowmeterLinkResultList = new List<HydroCalcuLinkResult>(); |
| | | var flowmeterLinkList = allLinkList?.Where(x => x.StartCode == flowmeter.Code || x.EndCode == flowmeter.Code).ToList(); |
| | | if (flowmeterLinkList != null && flowmeterLinkList.Count > 0) |
| | | { |
| | | foreach (var flowmeterLink in flowmeterLinkList) |
| | | { |
| | | var calcuFlowmeterLinkResult = hydroCalcuResult.LinkList?.Find(x => x.Code == flowmeterLink.Code); |
| | | if (calcuFlowmeterLinkResult != null) |
| | | { |
| | | calcuFlowmeterLinkResultList.Add(calcuFlowmeterLinkResult); |
| | | } |
| | | } |
| | | } |
| | | if (calcuFlowmeterLinkResultList.Exists(x => x.CalcuFlow.HasValue)) |
| | | { |
| | | calcuFlowmeterNewResult.CalcuQ = calcuFlowmeterLinkResultList.Where(x => x.CalcuFlow.HasValue).Average(x => x.CalcuFlow.Value); |
| | | } |
| | | hydroCalcuResult.NodeList.Remove(calcuFlowmeterResult); |
| | | hydroCalcuResult.NodeList.Add(calcuFlowmeterNewResult); |
| | | } |
| | | } |
| | | } |
| | | |
| | | //压力表 |
| | | var allPressmeterList = hydroInfo.Pressmeters; |
| | | if (allPressmeterList != null && allPressmeterList.Count > 0) |
| | | { |
| | | foreach (var pressmeter in allPressmeterList) |
| | | { |
| | | var calcuPressmeterResult = hydroCalcuResult.NodeList?.Find(x => x.Code == pressmeter.Code); |
| | | if (calcuPressmeterResult != null) |
| | | { |
| | | var calcuPressmeterNewResult = new HydroCalcuPressmeterResult(calcuPressmeterResult); |
| | | calcuPressmeterNewResult.CalcuPr = calcuPressmeterResult.CalcuPress; |
| | | hydroCalcuResult.NodeList.Remove(calcuPressmeterResult); |
| | | hydroCalcuResult.NodeList.Add(calcuPressmeterNewResult); |
| | | } |
| | | } |
| | | } |
| | | |
| | | //水泵 |
| | | var allPumpList = hydroInfo.Pumps; |
| | | if (allPumpList != null && allPumpList.Count > 0) |
| | | { |
| | | foreach (var pump in allPumpList) |
| | | { |
| | | var calcuPumpResult = hydroCalcuResult.LinkList.Find(x => x.Code == pump.Code); |
| | | if (calcuPumpResult != null) |
| | | { |
| | | var calcuPumpNewResult = new HydroCalcuPumpResult(calcuPumpResult); |
| | | calcuPumpNewResult.CalcuQ = calcuPumpResult.CalcuFlow; |
| | | if (calcuPumpNewResult.CalcuQ.HasValue) |
| | | { |
| | | var calcuNodeStartResult = hydroCalcuResult.NodeList?.Find(x => x.Code == pump.StartCode); |
| | | var calcuNodeEndResult = hydroCalcuResult.NodeList?.Find(x => x.Code == pump.EndCode); |
| | | if (calcuNodeStartResult != null && calcuNodeEndResult != null) |
| | | { |
| | | if (calcuNodeStartResult.CalcuPress.HasValue && calcuNodeEndResult.CalcuPress.HasValue) |
| | | { |
| | | calcuPumpNewResult.CalcuH = Math.Abs(calcuNodeStartResult.CalcuPress.Value - calcuNodeEndResult.CalcuPress.Value); |
| | | } |
| | | if (pump.LinkStatus == Yw.Hydro.PumpStatus.Open && pump.RatedN.HasValue) |
| | | { |
| | | var curveqp = hydroInfo.Curves?.Find(x => x.Code == pump.CurveQP); |
| | | if (curveqp != null) |
| | | { |
| | | if (curveqp.CurveData != null && curveqp.CurveData.Count > 3) |
| | | { |
| | | var point2dList = curveqp.CurveData.Select(x => new Yw.Geometry.Point2d(x.X, x.Y)).ToList(); |
| | | var point2dSimularList = point2dList.GetQPPointListByN(pump.RatedN.Value, pump.RatedN.Value * pump.SpeedRatio); |
| | | var pumpCurveQp = new Yw.Pump.CurveQP(eFeatType.Cubic, point2dSimularList); |
| | | calcuPumpNewResult.CalcuP = pumpCurveQp.FeatCurve.GetPointY(calcuPumpNewResult.CalcuQ.Value); |
| | | } |
| | | } |
| | | } |
| | | if (calcuPumpNewResult.CalcuH.HasValue && calcuPumpNewResult.CalcuP.HasValue) |
| | | { |
| | | calcuPumpNewResult.CalcuE = Yw.Pump.CalculationHelper.CalcuE(calcuPumpNewResult.CalcuQ.Value, calcuPumpNewResult.CalcuH.Value, calcuPumpNewResult.CalcuP.Value); |
| | | } |
| | | } |
| | | } |
| | | hydroCalcuResult.LinkList.Remove(calcuPumpResult); |
| | | hydroCalcuResult.LinkList.Add(calcuPumpNewResult); |
| | | |
| | | switch (pump.LinkStatus) |
| | | { |
| | | case Yw.Hydro.PumpStatus.Open: |
| | | { |
| | | if (calcuPumpNewResult.CalcuFlow.HasValue) |
| | | { |
| | | if (calcuPumpNewResult.CalcuFlow.Value <= 0) |
| | | { |
| | | hydroCalcuResult.WainingList.Add(new HydroCalcuWarning() |
| | | { |
| | | Code = pump.Code, |
| | | Message = $"[{pump.Name}]不满足当前工况 " |
| | | }); |
| | | } |
| | | } |
| | | else |
| | | { |
| | | hydroCalcuResult.WainingList.Add(new HydroCalcuWarning() |
| | | { |
| | | Code = pump.Code, |
| | | Message = $"[{pump.Name}]流量计算失败 " |
| | | }); |
| | | } |
| | | } |
| | | break; |
| | | case Yw.Hydro.PumpStatus.Closed: |
| | | { |
| | | if (calcuPumpNewResult.CalcuFlow.HasValue) |
| | | { |
| | | if (calcuPumpNewResult.CalcuFlow.Value > 0) |
| | | { |
| | | hydroCalcuResult.WainingList.Add(new HydroCalcuWarning() |
| | | { |
| | | Code = pump.Code, |
| | | Message = $"[{pump.Name}]不满足当前工况 " |
| | | }); |
| | | } |
| | | } |
| | | else |
| | | { |
| | | hydroCalcuResult.WainingList.Add(new HydroCalcuWarning() |
| | | { |
| | | Code = pump.Code, |
| | | Message = $"[{pump.Name}]流量计算失败 " |
| | | }); |
| | | } |
| | | } |
| | | break; |
| | | default: break; |
| | | } |
| | | |
| | | } |
| | | } |
| | | } |
| | | |
| | | |
| | | |
| | | return hydroCalcuResult; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 修复 |
| | | /// </summary> |
| | | public static bool Repair(this Yw.Model.HydroModelInfo hydroInfo, out string msg) |
| | | public static bool RepairLinksDirection(this Yw.Model.HydroModelInfo hydroInfo, out string msg) |
| | | { |
| | | msg = string.Empty; |
| | | if (hydroInfo == null) |
| | |
| | | return true; |
| | | } |
| | | |
| | | #endregion |
| | | |
| | | #region 修复参数 |
| | | |
| | | private const double _pipe_diameter_default = 500;//管道默认直径 |
| | | private const double _pipe_roughness_default = 110;//管道默认粗糙系数 |
| | | private const double _pipe_minorloss_default = 0.1;//管道默认粗糙系数 |
| | | //阀门默认局阻系数 |
| | | private const double _valve_minorloss_default = 0.3d; |
| | | |
| | | |
| | | /// <summary> |
| | | /// 修复参数 |
| | | /// </summary> |
| | | public static void RepairParas(this Yw.Model.HydroModelInfo hydroInfo, out string msg) |
| | | { |
| | | msg = string.Empty; |
| | | if (hydroInfo == null) |
| | | { |
| | | return; |
| | | } |
| | | |
| | | var allNodes = hydroInfo.GetAllNodes(); |
| | | var allLinks = hydroInfo.GetAllLinks(); |
| | | |
| | | //管道 |
| | | if (hydroInfo.Pipes != null && hydroInfo.Pumps.Count > 0) |
| | | { |
| | | foreach (var pipe in hydroInfo.Pipes) |
| | | { |
| | | if (pipe.Diameter <= 0) |
| | | { |
| | | pipe.Diameter = _pipe_diameter_default; |
| | | pipe.UpdatePropStatus(nameof(pipe.Diameter), ePropStatus.Lack, $"直径缺省,使用默认值【{_pipe_diameter_default}mm】修复"); |
| | | } |
| | | if (pipe.Roughness <= 0) |
| | | { |
| | | pipe.Roughness = _pipe_roughness_default; |
| | | pipe.UpdatePropStatus(nameof(pipe.Roughness), ePropStatus.Lack, $"粗糙系数缺省,使用默认值【{_pipe_roughness_default}】修复"); |
| | | } |
| | | if (pipe.MinorLoss <= 0) |
| | | { |
| | | pipe.MinorLoss = _pipe_minorloss_default; |
| | | pipe.UpdatePropStatus(nameof(pipe.MinorLoss), ePropStatus.Lack, $"粗糙系数缺省,使用默认值【{_pipe_minorloss_default}】修复"); |
| | | } |
| | | } |
| | | } |
| | | |
| | | //过渡件 |
| | | if (hydroInfo.Translations != null && hydroInfo.Translations.Count > 0) |
| | | { |
| | | foreach (var translation in hydroInfo.Translations) |
| | | { |
| | | if (translation.Diameter <= 0) |
| | | { |
| | | translation.Diameter = _pipe_diameter_default; |
| | | translation.UpdatePropStatus(nameof(translation.Diameter), ePropStatus.Lack, $"直径缺省,使用默认值【{_pipe_diameter_default}mm】修复"); |
| | | } |
| | | if (translation.Roughness <= 0) |
| | | { |
| | | translation.Roughness = _pipe_roughness_default; |
| | | translation.UpdatePropStatus(nameof(translation.Roughness), ePropStatus.Lack, $"粗糙系数缺省,使用默认值【{_pipe_roughness_default}】修复"); |
| | | } |
| | | if (translation.MinorLoss <= 0) |
| | | { |
| | | translation.MinorLoss = _pipe_minorloss_default; |
| | | translation.UpdatePropStatus(nameof(translation.MinorLoss), ePropStatus.Lack, $"粗糙系数缺省,使用默认值【{_pipe_minorloss_default}】修复"); |
| | | } |
| | | } |
| | | foreach (var translation in hydroInfo.Translations) |
| | | { |
| | | double? tempDiameter = null; |
| | | var startNode = allNodes.Find(x => x.Code == translation.StartCode); |
| | | if (startNode != null) |
| | | { |
| | | var startLink = allLinks.Find(x => x.EndCode == startNode.Code); |
| | | if (startLink != null) |
| | | { |
| | | var startPipe = startLink as Yw.Model.HydroPipeInfo; |
| | | if (startPipe != null) |
| | | { |
| | | tempDiameter = startPipe.Diameter; |
| | | if (translation.StartDiameter != startPipe.Diameter) |
| | | { |
| | | translation.StartDiameter = startPipe.Diameter; |
| | | translation.UpdatePropStatus(nameof(translation.StartDiameter), ePropStatus.Lack, $"上游直径缺省,使用上游管道【{startPipe.Code}】修复"); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | var endNode = allNodes.Find(x => x.Code == translation.EndCode); |
| | | if (endNode != null) |
| | | { |
| | | var endLink = allLinks.Find(x => x.StartCode == endNode.Code); |
| | | if (endLink != null) |
| | | { |
| | | var endPipe = endLink as Yw.Model.HydroPipeInfo; |
| | | if (endPipe != null) |
| | | { |
| | | if (translation.EndDiameter != endPipe.Diameter) |
| | | { |
| | | tempDiameter = endPipe.Diameter; |
| | | translation.EndDiameter = endPipe.Diameter; |
| | | translation.UpdatePropStatus(nameof(translation.EndDiameter), ePropStatus.Lack, $"下游直径缺省,使用下游管道【{endPipe.Code}】修复"); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | if (translation.StartDiameter <= 0) |
| | | { |
| | | if (tempDiameter.HasValue) |
| | | { |
| | | translation.StartDiameter = tempDiameter.Value; |
| | | } |
| | | } |
| | | if (translation.EndDiameter <= 0) |
| | | { |
| | | if (tempDiameter.HasValue) |
| | | { |
| | | translation.EndDiameter = tempDiameter.Value; |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | //阀门 |
| | | if (hydroInfo.Valves != null && hydroInfo.Valves.Count > 0) |
| | | { |
| | | foreach (var valve in hydroInfo.Valves) |
| | | { |
| | | if (valve.MinorLoss <= 0) |
| | | { |
| | | valve.MinorLoss = _valve_minorloss_default; |
| | | valve.UpdatePropStatus(nameof(valve.MinorLoss), ePropStatus.Lack, $"局阻系数缺省,使用默认值【{_valve_minorloss_default}】修复"); |
| | | } |
| | | if (valve.Diameter <= 0) |
| | | { |
| | | var startNode = allNodes.Find(x => x.Code == valve.StartCode); |
| | | if (startNode != null) |
| | | { |
| | | var startPipe = allLinks.Find(x => x.EndCode == startNode.Code) as Yw.Model.HydroPipeInfo; |
| | | if (startPipe != null) |
| | | { |
| | | valve.Diameter = startPipe.Diameter; |
| | | valve.UpdatePropStatus(nameof(valve.Diameter), ePropStatus.Lack, $"直径缺省,使用上游管道【{startPipe.Code}】修复"); |
| | | } |
| | | else |
| | | { |
| | | var endNode = allNodes.Find(x => x.Code == valve.EndCode); |
| | | if (endNode != null) |
| | | { |
| | | var endPipe = allLinks.Find(x => x.StartCode == endNode.Code) as Yw.Model.HydroPipeInfo; |
| | | if (endPipe != null) |
| | | { |
| | | valve.Diameter = endPipe.Diameter; |
| | | valve.UpdatePropStatus(nameof(valve.Diameter), ePropStatus.Lack, $"直径缺省,使用下游管道【{endPipe.Code}】修复"); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | } |
| | | |
| | | |
| | | #endregion |
| | | |
| | | } |
| | | } |