using Yw.EPAnet; using Yw.Hydro; using Yw.Model; namespace Yw.WinFrmUI { /// /// 水力信息拓展 /// public static class HydroModelInfoExtensions { #region 修复参数 private const double _pipe_roughness_default = 110;//管道默认粗糙系数 private const double _translation_roughness_default = 120;//过渡件默认粗糙系数 private const double _translation_minorloss_default = 0.3;//过渡件默认局阻系数 private const double _valve_minorloss_default = 0.3d; //阀门默认局阻系数 private const double _resistance_minorloss_default = 9d;//阻件默认局阻系数 private const double _blunthead_minorloss_default = 0.1d;//闷头局部阻力系数 private const double _cooling_coefficient_default = 100000d;//冷却塔流量系数 /// /// 修复参数 /// public static void RepairParas ( this Yw.Model.HydroModelInfo hydroInfo, HydroPropStatusHelper propStatusHelper, out string msg ) { msg = string.Empty; if (hydroInfo == null) { return; } var allNodes = hydroInfo.GetAllNodes(); var allLinks = hydroInfo.GetAllLinks(); //管道 if (hydroInfo.Pipes != null && hydroInfo.Pipes.Count > 0) { foreach (var pipe in hydroInfo.Pipes) { if (pipe.Roughness <= 0) { pipe.Roughness = _pipe_roughness_default; propStatusHelper.UpdatePropStatus(pipe, nameof(pipe.Roughness), ePropStatus.Abnormal, "【粗糙系数】数据异常"); } } } //过渡件 if (hydroInfo.Translations != null && hydroInfo.Translations.Count > 0) { 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.StartCode == startNode.Code || x.EndCode == startNode.Code) && x.Code != translation.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; } } } } var endNode = allNodes.Find(x => x.Code == translation.EndCode); if (endNode != null) { var endLink = allLinks .Find(x => (x.StartCode == endNode.Code || x.EndCode == endNode.Code) && x.Code != translation.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; } } } } 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; } if (valve.Diameter <= 0) { var startNode = allNodes.Find(x => x.Code == valve.StartCode); if (startNode != null) { var startPipe = allLinks .Find(x => (x.StartCode == startNode.Code || x.EndCode == startNode.Code) && x.Code != valve.Code) as Yw.Model.HydroPipeInfo; if (startPipe != null) { valve.Diameter = startPipe.Diameter; } else { var endNode = allNodes.Find(x => x.Code == valve.EndCode); if (endNode != null) { var endPipe = allLinks .Find(x => (x.StartCode == endNode.Code || x.EndCode == endNode.Code) && x.Code != valve.Code) as Yw.Model.HydroPipeInfo; if (endPipe != null) { valve.Diameter = endPipe.Diameter; } } } } } } } //阻件 var allResistanceList = hydroInfo.GetAllResistances(); if (allResistanceList != null && allResistanceList.Count > 0) { foreach (var resistance in allResistanceList) { if (resistance.MinorLoss <= 0) { resistance.MinorLoss = _resistance_minorloss_default; } var startNode = allNodes.Find(x => x.Code == resistance.StartCode); if (startNode != null) { var startPipe = allLinks .Find(x => (x.StartCode == startNode.Code || x.EndCode == startNode.Code) && x.Code != resistance.Code) as Yw.Model.HydroPipeInfo; if (startPipe != null) { resistance.Diameter = startPipe.Diameter; } else { var endNode = allNodes.Find(x => x.Code == resistance.EndCode); if (endNode != null) { var endPipe = allLinks .Find(x => (x.StartCode == endNode.Code || x.EndCode == endNode.Code) && x.Code != resistance.Code) as Yw.Model.HydroPipeInfo; if (endPipe != null) { resistance.Diameter = endPipe.Diameter; } } } } } } //闷头 if (hydroInfo.Bluntheads != null && hydroInfo.Bluntheads.Count > 0) { foreach (var visual in hydroInfo.Bluntheads) { if (visual.MinorLoss <= 0) { visual.MinorLoss = _blunthead_minorloss_default; } if (visual.Caliber < 1) { var link = allLinks.Find(x => x.StartCode == visual.Code || x.EndCode == visual.Code); if (link != null) { if (link is HydroResistanceInfo resistance) { visual.Caliber = resistance.Diameter; } else if (link is HydroValveInfo valve) { visual.Caliber = valve.Diameter; } else if (link is HydroTranslationInfo translation) { } else if (link is HydroPipeInfo pipe) { visual.Caliber = pipe.Diameter; } } } } } #region 弯头 if (hydroInfo.Elbows != null && hydroInfo.Elbows.Count > 0) { foreach (var visual in hydroInfo.Elbows) { if (visual.MinorLoss <= 0) { visual.MinorLoss = _blunthead_minorloss_default; } if (visual.Caliber < 1) { var link = allLinks.Find(x => x.StartCode == visual.Code || x.EndCode == visual.Code); if (link != null) { if (link is HydroResistanceInfo resistance) { visual.Caliber = resistance.Diameter; } else if (link is HydroValveInfo valve) { visual.Caliber = valve.Diameter; } else if (link is HydroTranslationInfo translation) { } else if (link is HydroPipeInfo pipe) { visual.Caliber = pipe.Diameter; } } } } } #endregion #region 冷却塔 if (hydroInfo.Coolings != null && hydroInfo.Coolings.Count > 0) { foreach (var cooling in hydroInfo.Coolings) { if (cooling.Coefficient < 1) { cooling.Coefficient = _cooling_coefficient_default; propStatusHelper.UpdatePropStatus(cooling.Code, nameof(cooling.Coefficient), ePropStatus.Abnormal, $"【流量系数】数据异常,使用默认值[{_cooling_coefficient_default}]修复"); } if (cooling.Caliber < 1) { var link = allLinks.Find(x => x.StartCode == cooling.Code || x.EndCode == cooling.Code); if (link != null) { if (link is HydroPipeInfo pipe) { if (pipe.Diameter > 0) { cooling.Caliber = pipe.Diameter; propStatusHelper.UpdatePropStatus(cooling.Code, nameof(cooling.Caliber), ePropStatus.Abnormal, $"【口径】数据异常,使用相邻管道修复"); } } } } } } #endregion } #endregion #region 装置计算 //获取开始压力(m) public static double GetStartHead(this Yw.Model.HydroModelInfo hydroInfo, string beginGroup = null) { if (hydroInfo == null) { return default; } var allNodeList = hydroInfo.GetAllNodes(); if (allNodeList == null || allNodeList.Count < 1) { return default; } var nodeList = allNodeList.Where(x => { var group1 = string.IsNullOrEmpty(x.BeginGroup) ? string.Empty : x.BeginGroup; var group2 = string.IsNullOrEmpty(beginGroup) ? string.Empty : beginGroup; return group1 == group2; }).ToList(); return GetStartHead(nodeList); } // 获取结束压力(m) public static double GetEndHead(this Yw.Model.HydroModelInfo hydroInfo, string beginGroup = null) { if (hydroInfo == null) { return default; } var allNodeList = hydroInfo.GetAllNodes(); if (allNodeList == null || allNodeList.Count < 1) { return default; } var nodeList = allNodeList.Where(x => { var group1 = string.IsNullOrEmpty(x.BeginGroup) ? string.Empty : x.BeginGroup; var group2 = string.IsNullOrEmpty(beginGroup) ? string.Empty : beginGroup; return group1 == group2; }).ToList(); return GetEndHead(nodeList); } //获取开始压力(m) private static double GetStartHead(List allNodeList) { if (allNodeList == null) { return default; } double startHeadValue = 0; var startNode = allNodeList.Matching(new List() { Yw.Hydro.Flags.水源, Yw.Hydro.Flags.始端, Yw.Hydro.Flags.默认 }); if (startNode == null) { startNode = allNodeList.Matching(new List() { Yw.Hydro.Flags.水源, Yw.Hydro.Flags.始端 }); } if (startNode != null) { if (startNode is HydroTankInfo tank) { startHeadValue = tank.PoolElev + tank.InitLevel; } else if (startNode is HydroJunctionInfo junction) { startHeadValue = junction.Elev; } } return startHeadValue; } //获取结束压力(m) private static double GetEndHead(List allNodeList) { if (allNodeList == null) { return default; } double endHeadValue = 0; var endNode = allNodeList.Matching(new List() { Yw.Hydro.Flags.水源, Yw.Hydro.Flags.末端, Yw.Hydro.Flags.默认 }); if (endNode == null) { endNode = allNodeList.Matching(new List() { Yw.Hydro.Flags.水源, Yw.Hydro.Flags.末端 }); } if (endNode != null) { if (endNode is HydroTankInfo tank) { endHeadValue = tank.PoolElev + tank.InitLevel; } else if (endNode is HydroJunctionInfo junction) { endHeadValue = junction.Elev; } } return endHeadValue; } /// /// 获取扬程 /// public static double GetHead(this Yw.Model.HydroModelInfo hydroInfo, string beginGroup = null) { if (hydroInfo == null) { return default; } var startHeadValue = GetStartHead(hydroInfo, beginGroup); var endHeadValue = GetEndHead(hydroInfo, beginGroup); return endHeadValue - startHeadValue; } //获取总管流量 private static double? GetPipeQ ( List allLinkList, Dictionary allCalcuVisualDict ) { if (allLinkList == null || allLinkList.Count < 1) { return default; } if (allCalcuVisualDict == null || allCalcuVisualDict.Count < 1) { return default; } var link = allLinkList.Matching(new List() { Yw.Hydro.Flags.总管, Yw.Hydro.Flags.出口, Yw.Hydro.Flags.默认 }); if (link == null) { link = allLinkList.Matching(new List() { Yw.Hydro.Flags.总管, Yw.Hydro.Flags.出口 }); } if (link == null) { return default; } var calcuLinkResult = allCalcuVisualDict.GetValue(link.Code) as HydroCalcuLinkResult; if (calcuLinkResult == null) { return default; } if (!calcuLinkResult.CalcuFlow.HasValue) { return default; } return Math.Round(Math.Abs(calcuLinkResult.CalcuFlow.Value), 1); } // 获取总管流量 private static double? GetPipeQ ( List allLinkList, HydroCalcuResult calcuResult ) { var allCalcuVisualResult = calcuResult?.GetVisualDict(); return GetPipeQ(allLinkList, allCalcuVisualResult); } /// /// 获取总管流量 /// public static double? GetPipeQ ( this Yw.Model.HydroModelInfo hydroInfo, Dictionary allCalcuVisualDict, string beginGroup = null ) { if (hydroInfo == null) { return default; } if (allCalcuVisualDict == null || allCalcuVisualDict.Count < 1) { return default; } var allLinkList = hydroInfo.GetAllLinks(); if (allLinkList == null || allLinkList.Count < 1) { return default; } var linkList = allLinkList.Where(x => { var group1 = string.IsNullOrEmpty(x.BeginGroup) ? string.Empty : x.BeginGroup; var group2 = string.IsNullOrEmpty(beginGroup) ? string.Empty : beginGroup; return group1 == group2; }).ToList(); return GetPipeQ(linkList, allCalcuVisualDict); } // 获取总管流量 public static double? GetPipeQ ( this Yw.Model.HydroModelInfo hydroInfo, HydroCalcuResult calcuResult, string beginGroup = null ) { var allCalcuVisualResult = calcuResult?.GetVisualDict(); return GetPipeQ(hydroInfo, allCalcuVisualResult, beginGroup); } //获取总管结束压力(绝对压力) private static double? GetPipeEndHead ( List allNodeList, Dictionary allCalcuVisualDict ) { if (allNodeList == null || allNodeList.Count < 1) { return default; } if (allCalcuVisualDict == null || allCalcuVisualDict.Count < 1) { return default; } var node = allNodeList.Matching(new List() { Yw.Hydro.Flags.总管, Yw.Hydro.Flags.出口, Yw.Hydro.Flags.默认 }); if (node == null) { node = allNodeList.Matching(new List() { Yw.Hydro.Flags.总管, Yw.Hydro.Flags.出口 }); } if (node == null) { return default; } var calcuNodeResult = allCalcuVisualDict.GetValue(node.Code) as HydroCalcuNodeResult; if (calcuNodeResult == null) { return default; } if (!calcuNodeResult.CalcuHead.HasValue) { return default; } var calcuValue = calcuNodeResult.GetCalcuValue(Yw.Hydro.VisualCalcuProp.CalcuHead); if (calcuValue == null) { return default; } return Math.Round(calcuValue.Value, 2); } //获取总管结束压力(绝对压力) private static double? GetPipeEndHead ( List allNodeList, HydroCalcuResult calcuResult ) { var allCalcuVisualDict = calcuResult?.GetVisualDict(); return GetPipeEndHead(allNodeList, allCalcuVisualDict); } //获取总管结束压力(绝对压力) public static double? GetPipeEndHead ( this Yw.Model.HydroModelInfo hydroInfo, Dictionary allCalcuVisualDict, string beginGroup = null ) { if (hydroInfo == null) { return default; } if (allCalcuVisualDict == null || allCalcuVisualDict.Count < 1) { return default; } var allNodeList = hydroInfo.GetAllNodes(); if (allNodeList == null || allNodeList.Count < 1) { return default; } var nodeList = allNodeList.Where(x => { var group1 = string.IsNullOrEmpty(x.BeginGroup) ? string.Empty : x.BeginGroup; var group2 = string.IsNullOrEmpty(beginGroup) ? string.Empty : beginGroup; return group1 == group2; }).ToList(); return GetPipeEndHead(nodeList, allCalcuVisualDict); } //获取总管结束压力(绝对压力) public static double? GetPipeEndHead ( this Yw.Model.HydroModelInfo hydroInfo, HydroCalcuResult calcuResult, string beginGroup = null ) { var allCalcuVisualDict = calcuResult?.GetVisualDict(); return GetPipeEndHead(hydroInfo, allCalcuVisualDict, beginGroup); } /// /// 获取总管压力(绝对压力) /// public static double? GetPipeHead ( this Yw.Model.HydroModelInfo hydroInfo, Dictionary allCalcuVisualDict, string beginGroup = null ) { if (hydroInfo == null) { return default; } if (allCalcuVisualDict == null || allCalcuVisualDict.Count < 1) { return default; } var endHeadValue = GetPipeEndHead(hydroInfo, allCalcuVisualDict, beginGroup); if (!endHeadValue.HasValue) { return default; } var startHeadValue = GetStartHead(hydroInfo, beginGroup); return Math.Round(endHeadValue.Value - startHeadValue, 2); } /// /// 获取总管压力(绝对压力) /// public static double? GetPipeHead ( this Yw.Model.HydroModelInfo hydroInfo, HydroCalcuResult calcuResult, string beginGroup = null ) { return GetPipeHead(hydroInfo, calcuResult?.GetVisualDict(), beginGroup); } #endregion } }