using DevExpress.Drawing.Internal.Interop;
|
using Yw.EPAnet;
|
using Yw.Hydro;
|
using Yw.Model;
|
|
namespace Yw.WinFrmUI
|
{
|
/// <summary>
|
/// 水力信息拓展
|
/// </summary>
|
public static class HydroModelInfoExtensions
|
{
|
|
#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; //阀门默认局阻系数
|
private const double _resistance_minorloss_default = 9d;//阻件默认局阻系数
|
|
/// <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.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;
|
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 || 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;
|
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}】修复");
|
}
|
}
|
}
|
}
|
}
|
}
|
}
|
|
//阻件
|
var allResistanceList = hydroInfo.GetAllResistances();
|
if (allResistanceList != null && allResistanceList.Count > 0)
|
{
|
foreach (var resistance in allResistanceList)
|
{
|
if (resistance.MinorLoss <= 0)
|
{
|
resistance.MinorLoss = _resistance_minorloss_default;
|
resistance.UpdatePropStatus(nameof(resistance.MinorLoss), ePropStatus.Lack, $"局阻系数缺省,使用默认值【{_resistance_minorloss_default}】修复");
|
}
|
var startNode = allNodes.Find(x => x.Code == resistance.StartCode);
|
if (startNode != null)
|
{
|
var startPipe = allLinks.Find(x => x.EndCode == startNode.Code) as Yw.Model.HydroPipeInfo;
|
if (startPipe != null)
|
{
|
resistance.Diameter = startPipe.Diameter;
|
resistance.UpdatePropStatus(nameof(resistance.Diameter), ePropStatus.Lack, $"直径使用上游管道【{startPipe.Code}】修复");
|
}
|
else
|
{
|
var endNode = allNodes.Find(x => x.Code == resistance.EndCode);
|
if (endNode != null)
|
{
|
var endPipe = allLinks.Find(x => x.StartCode == endNode.Code) as Yw.Model.HydroPipeInfo;
|
if (endPipe != null)
|
{
|
resistance.Diameter = endPipe.Diameter;
|
resistance.UpdatePropStatus(nameof(resistance.Diameter), ePropStatus.Lack, $"直径使用下游管道【{endPipe.Code}】修复");
|
}
|
}
|
}
|
}
|
}
|
}
|
|
}
|
|
|
#endregion
|
|
#region 装置计算
|
|
/// <summary>
|
/// 获取扬程
|
/// </summary>
|
public static double GetHead(this Yw.Model.HydroModelInfo hydroInfo)
|
{
|
if (hydroInfo == null)
|
{
|
return default;
|
}
|
double startHeadValue = 0;
|
var allSourceList = hydroInfo.GetAllSources();
|
if (allSourceList != null && allSourceList.Count > 0)
|
{
|
var startSource = allSourceList.Matching(new List<string>()
|
{
|
Yw.Hydro.Flags.水源,
|
Yw.Hydro.Flags.始端,
|
Yw.Hydro.Flags.默认
|
});
|
if (startSource == null)
|
{
|
startSource = allSourceList.Matching(new List<string>()
|
{
|
Yw.Hydro.Flags.水源,
|
Yw.Hydro.Flags.始端
|
});
|
}
|
if (startSource != null)
|
{
|
if (startSource is HydroTankInfo tank)
|
{
|
startHeadValue = tank.PoolElev + tank.InitLevel;
|
}
|
}
|
}
|
|
double endHeadValue = 0;
|
var allNodeList = hydroInfo.GetAllNodes();
|
if (allNodeList != null && allNodeList.Count > 0)
|
{
|
var endSource = allNodeList.Matching(new List<string>()
|
{
|
Yw.Hydro.Flags.水源,
|
Yw.Hydro.Flags.末端,
|
Yw.Hydro.Flags.默认
|
});
|
if (endSource == null)
|
{
|
endSource = allSourceList.Matching(new List<string>()
|
{
|
Yw.Hydro.Flags.水源,
|
Yw.Hydro.Flags.末端
|
});
|
}
|
if (endSource != null)
|
{
|
if (endSource is HydroTankInfo tank)
|
{
|
endHeadValue = tank.PoolElev + tank.InitLevel;
|
}
|
else if (endSource is HydroEmitterInfo emitter)
|
{
|
endHeadValue = emitter.Elev;
|
}
|
}
|
}
|
|
return endHeadValue - startHeadValue;
|
}
|
|
/// <summary>
|
/// 获取总管流量
|
/// </summary>
|
public static double? GetPipeQ(this Yw.Model.HydroModelInfo hydroInfo, HydroCalcuResult calcuResult)
|
{
|
return GetPipeQ(hydroInfo, calcuResult?.GetVisualDict());
|
}
|
|
/// <summary>
|
/// 获取总管流量
|
/// </summary>
|
public static double? GetPipeQ(this Yw.Model.HydroModelInfo hydroInfo, Dictionary<string, HydroCalcuVisualResult> allCalcuVisualDict)
|
{
|
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 link = allLinkList.Matching(new List<string>()
|
{
|
Yw.Hydro.Flags.总管,
|
Yw.Hydro.Flags.出口,
|
Yw.Hydro.Flags.默认
|
});
|
if (link == null)
|
{
|
link = allLinkList.Matching(new List<string>()
|
{
|
Yw.Hydro.Flags.总管,
|
Yw.Hydro.Flags.出口
|
});
|
}
|
if (link == null)
|
{
|
return default;
|
}
|
|
var calcuVisualResult = allCalcuVisualDict.GetValue(link.Code);
|
if (calcuVisualResult == null)
|
{
|
return default;
|
}
|
var calcuValue = calcuVisualResult.GetCalcuValue(Yw.Hydro.VisualCalcuProp.CalcuFlow);
|
if (calcuValue == null)
|
{
|
return default;
|
}
|
return Math.Round(Math.Abs(calcuValue.Value), 1);
|
}
|
|
/// <summary>
|
/// 获取总管压力(绝对压力)
|
/// </summary>
|
public static double? GetPipeHead(this Yw.Model.HydroModelInfo hydroInfo, HydroCalcuResult calcuResult)
|
{
|
return GetPipeHead(hydroInfo, calcuResult?.GetVisualDict());
|
}
|
|
/// <summary>
|
/// 获取总管压力(绝对压力)
|
/// </summary>
|
public static double? GetPipeHead(this Yw.Model.HydroModelInfo hydroInfo, Dictionary<string, HydroCalcuVisualResult> allCalcuVisualDict)
|
{
|
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 node = allNodeList.Matching(new List<string>()
|
{
|
Yw.Hydro.Flags.总管,
|
Yw.Hydro.Flags.出口,
|
Yw.Hydro.Flags.默认
|
});
|
if (node == null)
|
{
|
node = allNodeList.Matching(new List<string>()
|
{
|
Yw.Hydro.Flags.总管,
|
Yw.Hydro.Flags.出口
|
});
|
}
|
if (node == null)
|
{
|
return default;
|
}
|
|
var calcuVisualResult = allCalcuVisualDict.GetValue(node.Code);
|
if (calcuVisualResult == null)
|
{
|
return default;
|
}
|
var calcuValue = calcuVisualResult.GetCalcuValue(Yw.Hydro.VisualCalcuProp.CalcuHead);
|
if (calcuValue == null)
|
{
|
return default;
|
}
|
return Math.Round(calcuValue.Value, 2);
|
}
|
|
#endregion
|
|
}
|
}
|