namespace Yw.Epanet
{
///
///
///
public static class NetworkRepairExtensions
{
///
/// 修复
///
public static void Repair(this Network nw)
{
//验证
if (nw == null)
{
return;
}
var allNodeList = nw.GetAllNodes();
if (allNodeList == null || allNodeList.Count < 1)
{
return;
}
var allLinkList = nw.GetAllLinks();
if (allLinkList == null || allLinkList.Count < 1)
{
return;
}
var allJunctionList = nw.GetAllJunctions();
if (allJunctionList == null || allJunctionList.Count < 1)
{
return;
}
//节点links处理
foreach (var node in allNodeList)
{
var links = allLinkList.Where(x => x.StartNodeId == node.Id || x.EndNodeId == node.Id).ToList();
node.Links = links;
}
//管段上下游处理
foreach (var link in allLinkList)
{
link.StartNode = allNodeList.Find(x => x.Id == link.StartNodeId);
link.EndNode = allNodeList.Find(x => x.Id == link.EndNodeId);
}
//管道参数处理
var allPipeList = nw.Pipes;
if (allPipeList != null && allPipeList.Count > 0)
{
foreach (var pipe in allPipeList)
{
if (pipe.Roughness < 10)
{
pipe.Roughness = ConstParas.DefaultRoughness;
}
if (pipe.Length < ConstParas.MinPipeLength)
{
pipe.Length = ConstParas.MinPipeLength;
}
pipe.StartMinorLoss = 0;
pipe.EndMinorLoss = 0;
}
}
//连接节点参数处理
foreach (var junction in allJunctionList)
{
if (junction.Demand < 0)
{
junction.Demand = 0;
}
if (junction.MinorLoss < 0)
{
junction.MinorLoss = 0;
}
if (junction.MinorLoss > 0)
{
var pipes = junction.GetPipes();
if (pipes != null && pipes.Count > 0)
{
var littleMinorLoss = junction.MinorLoss / pipes.Count;
var nextPipes = junction.GetNextPipes();
nextPipes?.ForEach(x => x.StartMinorLoss += littleMinorLoss);
var prevPipes = junction.GetPrevPipes();
prevPipes?.ForEach(x => x.EndMinorLoss += littleMinorLoss);
}
}
}
}
}
}