duheng
2025-03-20 5f2a6e10c6c7ccafb46594f6f8fd3f87c9448c39
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
using IStation.Epanet.Enums;
 
namespace IStation.Epanet.Network.Structures
{
 
    ///<summary>Hydraulic valve structure.</summary>
    public class Valve : Link
    {
 
        public Valve(string name, ValveType type) : base(name) => ValveType = type;
 
        public ValveType ValveType { get; }
 
        public override LinkType LinkType => LinkType.VALVE;
 
        public override void InitResistance(HeadLossFormulaType formflag, double hexp) { }
 
        public override void ConvertUnits(Network nw)
        {
            FieldsMap fMap = nw.FieldsMap;
 
            Diameter /= fMap.GetUnits(FieldType.DIAM);
 
            double diam = Math.Pow(Diameter, 2);
            Km = 0.02517 * Km / diam / diam;
 
            if (!double.IsNaN(Kc))
                switch (ValveType)
                {
                    case ValveType.FCV:
                        Kc /= fMap.GetUnits(FieldType.FLOW);
                        break;
                    case ValveType.PRV:
                    case ValveType.PSV:
                    case ValveType.PBV:
                        Kc /= fMap.GetUnits(FieldType.PRESSURE);
                        break;
                }
 
        }
 
        ///<summary>Settings curve.</summary>
        public Curve Curve { get; set; }
 
#if NUCONVERT
        public override double GetNuRoughness(FlowUnitsType fType, PressUnitsType pType, double spGrav)
        {
 
            switch (ValveType)
            {
                case ValveType.FCV:
                    return NUConvert.RevertFlow(fType, Kc);
                case ValveType.PRV:
                case ValveType.PSV:
                case ValveType.PBV:
                    return NUConvert.RevertPressure(pType, spGrav, Kc);
            }
 
            return Kc;
        }
 
#endif
 
    }
 
}