using IStation.Epanet.Enums;
using System;
using System.Collections.Generic;
namespace IStation.Epanet.Network.Structures
{
///Hydraulic link structure (pipe)
public abstract class Link : Element
{
///Init links flow resistance values.
public abstract void InitResistance(HeadLossFormulaType formflag, double hexp);
public abstract void ConvertUnits(Network nw);
protected Link(string name) : base(name)
{
Vertices = new List();
Status = StatusType.XHEAD;
}
public override ElementType ElementType => ElementType.LINK;
///Link subtype.
public abstract LinkType LinkType { get; }
///Initial species concentrations.
public double C0 { get; set; }
///Link diameter (feet).
public double Diameter { get; set; }
///First node.
public Node FirstNode { get; set; }
///Flow resistance.
public double FlowResistance { get; protected set; }
///Bulk react. coeff.
public double Kb { get; set; }
///Minor loss coeff.
public double Km { get; set; }
///Wall react. coeff.
public double Kw { get; set; }
///Link length (feet).
public double Lenght { get; set; }
///Kinetic parameter values.
public double[] Param { get; set; }
///Roughness factor.
public double Kc { get; set; }
///Second node.
public Node SecondNode { get; set; }
///Link status.
public StatusType Status { get; set; }
///List of points for link path rendering.
public List Vertices { get; }
///Link report flag.
public bool RptFlag { get; set; }
public void SetDiameterAndUpdate(double diameter, Network net)
{
double realkm = Km * Math.Pow(Diameter, 4.0) / 0.02517;
Diameter = diameter;
Km = 0.02517 * realkm / Math.Pow(diameter, 4);
InitResistance(net.FormFlag, net.HExp);
}
/// Returns string with length of pipe with given index.
public double GetPipeLength(UnitsType type)
{
double length = 0;
EnPoint pt1 = FirstNode.Coordinate;
foreach (var pt in Vertices)
{
length += pt1.DistanceTo(pt);
pt1 = pt;
}
length += pt1.DistanceTo(SecondNode.Coordinate);
// length = MapDimensions.LengthUCF * length;
if (type == UnitsType.SI)
length *= 1 / Constants.MperFT;
return Lenght = length;
}
#if NUCONVERT
public double GetNuDiameter(UnitsType utype)
{
return NUConvert.RevertDiameter(utype, Diameter);
}
public double GetNuLength(UnitsType utype)
{
return NUConvert.RevertDistance(utype, Lenght);
}
public void SetNuDiameter(UnitsType utype, double value)
{
Diameter = NUConvert.ConvertDistance(utype, value);
}
public void SetNuLenght(UnitsType utype, double value)
{
Lenght = NUConvert.ConvertDistance(utype, value);
}
public virtual double GetNuRoughness(FlowUnitsType fType, PressUnitsType pType, double spGrav)
{
return Kc;
}
#endif
}
}