コード例 #1
0
ファイル: EPATool.cs プロジェクト: congcongshang/Epanet.Net
        private static double GetNodeValue(NodeVariableType type, FieldsMap fmap, AwareStep step, Node node, int index)
        {
            switch (type)
            {
            case NodeVariableType.BASEDEMAND: {
                double dsum = node.Demands.Sum(demand => demand.Base);
                return(fmap.RevertUnit((FieldType)type, dsum));
            }

            case NodeVariableType.ELEVATION:
                return(fmap.RevertUnit((FieldType)type, node.Elevation));

            case NodeVariableType.DEMAND:
                return(step != null?step.GetNodeDemand(index, node, fmap) : 0);

            case NodeVariableType.HEAD:
                return(step != null?step.GetNodeHead(index, node, fmap) : 0);

            case NodeVariableType.INITQUALITY:
                return(fmap.RevertUnit((FieldType)type, node.C0));

            case NodeVariableType.PRESSURE:
                return(step != null?step.GetNodePressure(index, node, fmap) : 0);

            case NodeVariableType.QUALITY:
                return(step != null?step.GetNodeQuality(index) : 0);

            default:
                return(0.0);
            }
        }
コード例 #2
0
ファイル: Quality.cs プロジェクト: chinaray/Epanet.Net
        /// <summary>
        /// Retrieves hydraulic solution and time step for next hydraulic event  from a hydraulics file.
        /// </summary>
        private ErrorCodeType GetHydVars()
        {
            AwareStep step = _tk2.GetStep((int)_msx.Htime);

            int n = _msx.Nobjects[(int)ObjectTypes.NODE];

            for (int i = 0; i < n; i++)
            {
                _msx.D[i + 1] = (float)step.GetNodeDemand(i, null, null);
            }

            for (int i = 0; i < n; i++)
            {
                _msx.H[i + 1] = (float)step.GetNodeHead(i, null, null);
            }

            n = _msx.Nobjects[(int)ObjectTypes.LINK];

            for (int i = 0; i < n; i++)
            {
                _msx.Q[i + 1] = (float)step.GetLinkFlow(i, null, null);
            }

            // update elapsed time until next hydraulic event
            _msx.Htime = step.Time + step.Step;

            // Initialize pipe segments (at time 0) or else re-orient segments to accommodate any flow reversals
            if (_msx.Qtime < _msx.Dur)
            {
                if (_msx.Qtime == 0)
                {
                    InitSegs();
                }
                else
                {
                    ReorientSegs();
                }
            }

            return(0);
        }
コード例 #3
0
        public static void main(string[] args)
        {
            int i;

            var net = new EpanetNetwork();

            //Tank
            Tank tank = new Tank("0")
            {
                Elevation = 210
            };

            net.Nodes.Add(tank);

            //Nodes
            Node[] node = new Node[7];

            for (i = 1; i < 7; i++)
            {
                node[i] = new Node(i.ToString());
            }


            node[1].Elevation = 150;
            node[1].Demands.Add(new Demand(100, null));
            node[2].Elevation = 160;
            node[2].Demands.Add(new Demand(100, null));
            node[3].Elevation = 155;
            node[3].Demands.Add(new Demand(120, null));
            node[4].Elevation = 150;
            node[4].Demands.Add(new Demand(270, null));
            node[5].Elevation = 165;
            node[5].Demands.Add(new Demand(330, null));
            node[6].Elevation = 160;
            node[6].Demands.Add(new Demand(200, null));

            //Links
            Link[] pipe = new Link[8];
            for (i = 0; i < 8; i++)
            {
                pipe[i] = new Link(i.ToString())
                {
                    Lenght = 1000
                };
            }
            pipe[0].FirstNode  = tank;
            pipe[0].SecondNode = node[1];
            pipe[1].FirstNode  = node[1];
            pipe[1].SecondNode = node[2];
            pipe[2].FirstNode  = node[1];
            pipe[2].SecondNode = node[3];
            pipe[3].FirstNode  = node[3];
            pipe[3].SecondNode = node[4];
            pipe[4].FirstNode  = node[3];
            pipe[4].SecondNode = node[5];
            pipe[5].FirstNode  = node[5];
            pipe[5].SecondNode = node[6];
            pipe[6].FirstNode  = node[2];
            pipe[6].SecondNode = node[4];
            pipe[7].FirstNode  = node[4];
            pipe[7].SecondNode = node[6];

            for (i = 1; i < 7; i++)
            {
                net.Nodes.Add(node[i]);
            }
            for (i = 0; i < 8; i++)
            {
                net.Links.Add(pipe[i]);
            }

            //Prepare Network
            TraceSource log = new TraceSource(typeof(SampleOOPNetwork2).FullName, SourceLevels.All);
            NullParser  nP  = (NullParser)InputParser.Create(FileType.NULL_FILE);

            Debug.Assert(nP != null);
            nP.Parse(new EpanetNetwork(), null);

            //// Simulate hydraulics
            string       hydFile = Path.GetTempFileName(); // ("hydSim", "bin");
            HydraulicSim hydSim  = new HydraulicSim(net, log);

            hydSim.Simulate(hydFile);

            // Read hydraulic results

            HydraulicReader hydReader = new HydraulicReader(hydFile);

            for (long time = net.RStart; time <= net.Duration; time += net.RStep)
            {
                AwareStep step = hydReader.GetStep((int)time);
                Console.WriteLine("Time : " + step.Time.GetClockTime() + ", nodes heads : ");

                i = 0;
                foreach (Node inode in net.Nodes)
                {
                    Console.Write("{0:F2}\t", step.GetNodeHead(i++, inode, null));
                }

                Console.WriteLine();
            }

            hydReader.Close();
        }