duheng
2025-03-18 7ee0220b5f5626deef516b6e5c417bfa201e5a88
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
using IStation.Epanet.Enums;
 
namespace IStation.Epanet.Network.Structures
{
 
    ///<summary>Hydraulic link structure (pipe)</summary>
    public abstract class Link : Element
    {
 
        ///<summary>Init links flow resistance values.</summary>
        public abstract void InitResistance(HeadLossFormulaType formflag, double hexp);
 
        public abstract void ConvertUnits(Network nw);
 
        protected Link(string name) : base(name)
        {
            Vertices = new List<EnPoint>();
            Status = StatusType.XHEAD;
        }
 
        public override ElementType ElementType => ElementType.LINK;
 
        ///<summary>Link subtype.</summary>
        public abstract LinkType LinkType { get; }
 
        ///<summary>Initial species concentrations.</summary>
        public double C0 { get; set; }
 
        ///<summary>Link diameter (feet).</summary>
        public double Diameter { get; set; }
 
        ///<summary>First node.</summary>
        public Node FirstNode { get; set; }
 
        ///<summary>Flow resistance.</summary>
        public double FlowResistance { get; protected set; }
 
        ///<summary>Bulk react. coeff.</summary>
        public double Kb { get; set; }
 
        ///<summary>Minor loss coeff.</summary>
        public double Km { get; set; }
 
        ///<summary>Wall react. coeff.</summary>
        public double Kw { get; set; }
 
        ///<summary>Link length (feet).</summary>
        public double Lenght { get; set; }
 
        ///<summary>Kinetic parameter values.</summary>
        public double[] Param { get; set; }
 
        ///<summary>Roughness factor.</summary>
        public double Kc { get; set; }
 
        ///<summary>Second node.</summary>
        public Node SecondNode { get; set; }
 
        ///<summary>Link status.</summary>
        public StatusType Status { get; set; }
 
        ///<summary>List of points for link path rendering.</summary>
        public List<EnPoint> Vertices { get; }
 
        ///<summary>Link report flag.</summary>
        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);
        }
 
        /// <summary>Returns string with length of pipe with given index.</summary>
 
        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
    }
 
}