| | |
| | | namespace Yw.WinFrmUI |
| | | using Yw.EPAnet; |
| | | using Yw.Hydro; |
| | | using Yw.Model; |
| | | |
| | | namespace Yw.WinFrmUI |
| | | { |
| | | /// <summary> |
| | | /// |
| | | /// 水力信息拓展 |
| | | /// </summary> |
| | | public static class HydroModelInfoExtensions |
| | | { |
| | | #region 可见字典 |
| | | |
| | | /// <summary> |
| | | /// 更新工况信息 |
| | | /// 获取可见字典 |
| | | /// </summary> |
| | | public static void UpdateWorkingInfo(this Yw.Model.HydroModelInfo hydroInfo, HydroWorkingInfoViewModel workingInfo) |
| | | public static Dictionary<string, HydroVisualInfo> GetVisualDict(this Yw.Model.HydroModelInfo hydroInfo) |
| | | { |
| | | if (hydroInfo == null) |
| | | { |
| | | return default; |
| | | } |
| | | var allVisualList = hydroInfo.GetAllVisuals(); |
| | | return allVisualList?.ToDictionary(x => x.Code); |
| | | } |
| | | |
| | | #endregion |
| | | |
| | | #region 修复管网方向 |
| | | |
| | | /// <summary> |
| | | /// 修复管网方向 |
| | | /// </summary> |
| | | public static bool RepairLinksDirection(this Yw.Model.HydroModelInfo hydroInfo, out string msg) |
| | | { |
| | | msg = string.Empty; |
| | | if (hydroInfo == null) |
| | | { |
| | | return false; |
| | | } |
| | | |
| | | var checkResult = hydroInfo.Check(); |
| | | if (!checkResult.Succeed) |
| | | { |
| | | msg = "检查失败导致无法进行试算,停止管网修复!"; |
| | | return false; |
| | | } |
| | | |
| | | var calcuResult = hydroInfo.Calcu(Yw.EPAnet.CalcuMode.Simple); |
| | | if (!calcuResult.Succeed) |
| | | { |
| | | msg = "试算失败,停止管网修复!"; |
| | | return false; |
| | | } |
| | | |
| | | var allLinkList = hydroInfo.GetAllLinks(); |
| | | if (allLinkList != null && allLinkList.Count < 1) |
| | | { |
| | | msg = "模型中未包含管段信息,停止管网修复!"; |
| | | return false; |
| | | } |
| | | |
| | | int count = 0; |
| | | foreach (var link in allLinkList) |
| | | { |
| | | var calcuLink = calcuResult.LinkList?.Find(x => x.Code == link.Code); |
| | | if (calcuLink == null) |
| | | { |
| | | continue; |
| | | } |
| | | if (!calcuLink.CalcuFlow.HasValue) |
| | | { |
| | | continue; |
| | | } |
| | | if (calcuLink.CalcuFlow.Value < 0) |
| | | { |
| | | var tempCode = link.StartCode; |
| | | link.StartCode = link.EndCode; |
| | | link.EndCode = tempCode; |
| | | count++; |
| | | } |
| | | } |
| | | |
| | | msg = $"修复完成,共修复管段({count})个!"; |
| | | 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; |
| | | } |
| | | if (workingInfo == null) |
| | | |
| | | var allNodes = hydroInfo.GetAllNodes(); |
| | | var allLinks = hydroInfo.GetAllLinks(); |
| | | |
| | | //管道 |
| | | if (hydroInfo.Pipes != null && hydroInfo.Pumps.Count > 0) |
| | | { |
| | | return; |
| | | } |
| | | //水箱 |
| | | if (hydroInfo.Waterboxs != null && hydroInfo.Waterboxs.Count > 0) |
| | | { |
| | | foreach (var parter in hydroInfo.Waterboxs) |
| | | foreach (var pipe in hydroInfo.Pipes) |
| | | { |
| | | var parterWorkingInfo = workingInfo.Waterboxs?.Find(x => x.Code == parter.Code); |
| | | if (parterWorkingInfo != null) |
| | | if (pipe.Diameter <= 0) |
| | | { |
| | | parter.InitLevel = parterWorkingInfo.InitLevel; |
| | | 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.Pumps != null && hydroInfo.Pumps.Count > 0) |
| | | //过渡件 |
| | | if (hydroInfo.Translations != null && hydroInfo.Translations.Count > 0) |
| | | { |
| | | foreach (var parter in hydroInfo.Pumps) |
| | | foreach (var translation in hydroInfo.Translations) |
| | | { |
| | | var parterWorkingInfo = workingInfo.Pumps?.Find(x => x.Code == parter.Code); |
| | | if (parterWorkingInfo != null) |
| | | if (translation.Diameter <= 0) |
| | | { |
| | | parter.LinkStatus = parterWorkingInfo.LinkStatus; |
| | | parter.SpeedRatio = Math.Round(parterWorkingInfo.CurrentHz / parter.RatedHz, 1); |
| | | 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 parter in hydroInfo.Valves) |
| | | foreach (var valve in hydroInfo.Valves) |
| | | { |
| | | var parterWorkingInfo = workingInfo.Valves?.Find(x => x.Code == parter.Code); |
| | | if (parterWorkingInfo != null) |
| | | if (valve.MinorLoss <= 0) |
| | | { |
| | | parter.LinkStatus = parterWorkingInfo.LinkStatus; |
| | | parter.OpeningDegree = parterWorkingInfo.OpeningDegree; |
| | | valve.MinorLoss = _valve_minorloss_default; |
| | | valve.UpdatePropStatus(nameof(valve.MinorLoss), ePropStatus.Lack, $"局阻系数缺省,使用默认值【{_valve_minorloss_default}】修复"); |
| | | } |
| | | } |
| | | } |
| | | |
| | | //流量计 |
| | | if (hydroInfo.Flowmeters != null && hydroInfo.Flowmeters.Count > 0) |
| | | { |
| | | foreach (var parter in hydroInfo.Flowmeters) |
| | | { |
| | | var parterWorkingInfo = workingInfo.Flowmeters?.Find(x => x.Code == parter.Code); |
| | | if (parterWorkingInfo != null) |
| | | if (valve.Diameter <= 0) |
| | | { |
| | | parter.CurrentFlow = parterWorkingInfo.CurrentFlow; |
| | | } |
| | | } |
| | | } |
| | | |
| | | //压力表 |
| | | if (hydroInfo.Pressmeters != null && hydroInfo.Pressmeters.Count > 0) |
| | | { |
| | | foreach (var parter in hydroInfo.Pressmeters) |
| | | { |
| | | var parterWorkingInfo = workingInfo.Pressmeters?.Find(x => x.Code == parter.Code); |
| | | if (parterWorkingInfo != null) |
| | | { |
| | | parter.CurrentPress = parterWorkingInfo.CurrentPress; |
| | | 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 |
| | | |
| | | } |
| | | } |