コード例 #1
0
ファイル: HydraulicSim.cs プロジェクト: chinaray/Epanet.Net
        ///<summary>Computes time step to advance hydraulic simulation.</summary>
        private long TimeStep()
        {
            long tstep = net.HStep;

            long n = (Htime + net.PStart) / net.PStep + 1;
            long t = n * net.PStep - Htime;

            if (t > 0 && t < tstep)
            {
                tstep = t;
            }

            // Revise time step based on smallest time to fill or drain a tank
            t = Rtime - Htime;
            if (t > 0 && t < tstep)
            {
                tstep = t;
            }

            tstep = SimulationTank.MinimumTimeStep(_tanks, tstep);
            tstep = SimulationControl.MinimumTimeStep(net, _controls, Htime, tstep);

            if (_rules.Length > 0)
            {
                long step, htime;

                SimulationRule.MinimumTimeStep(
                    net,
                    _logger,
                    _rules,
                    _tanks,
                    Htime,
                    tstep,
                    _dsystem,
                    out step,
                    out htime);

                tstep = step;
                Htime = htime;
            }
            else
            {
                SimulationTank.StepWaterLevels(_tanks, net.FieldsMap, tstep);
            }

            return(tstep);
        }
コード例 #2
0
ファイル: HydraulicSim.cs プロジェクト: chinaray/Epanet.Net
        ///<summary>Init hydraulic simulation, preparing the linear solver and the hydraulic structures wrappers.</summary>
        /// <param name="net">Hydraulic network reference.</param>
        /// <param name="log">Logger reference.</param>
        public HydraulicSim(EpanetNetwork net, TraceSource log)
        {
            _running = false;
            _logger  = log;
            // this.CreateSimulationNetwork(net);


            _nodes     = new SimulationNode[net.Nodes.Count];
            _links     = new SimulationLink[net.Links.Count];
            _pumps     = new List <SimulationPump>();
            _tanks     = new List <SimulationTank>();
            _junctions = new List <SimulationNode>();
            _valves    = new List <SimulationValve>();

            var nodesById = new Dictionary <string, SimulationNode>(net.Nodes.Count);

            for (int i = 0; i < net.Nodes.Count; i++)
            {
                SimulationNode node;

                var networkNode = net.Nodes[i];

                if (networkNode.Type == NodeType.JUNC)
                {
                    node = new SimulationNode(networkNode, i);
                    _junctions.Add(node);
                }
                else
                {
                    node = new SimulationTank(networkNode, i);
                    _tanks.Add((SimulationTank)node);
                }

                _nodes[i]          = node;
                nodesById[node.Id] = node;
            }

            for (int i = 0; i < net.Links.Count; i++)
            {
                SimulationLink link;

                var networkLink = net.Links[i];

                if (networkLink is Valve)
                {
                    var valve = new SimulationValve(nodesById, networkLink, i);
                    _valves.Add(valve);
                    link = valve;
                }
                else if (networkLink is Pump)
                {
                    var pump = new SimulationPump(nodesById, networkLink, i);
                    _pumps.Add(pump);
                    link = pump;
                }
                else
                {
                    link = new SimulationLink(nodesById, networkLink, i);
                }

                _links[i] = link;
            }

            _rules = net.Rules.Select(r => new SimulationRule(r, _links, _nodes)).ToArray();

            _curves = net.Curves.ToArray();

            _controls = net.Controls.Select(x => new SimulationControl(_nodes, _links, x)).ToArray();


            this.net = net;
            _epat    = net.GetPattern(this.net.EPatId);
            _smat    = new SparseMatrix(_nodes, _links, _junctions.Count);
            _lsv     = new LsVariables(_nodes.Length, _smat.CoeffsCount);

            Htime = 0;

            switch (this.net.FormFlag)
            {
            case FormType.HW:
                _pHlModel = PipeHeadModelCalculators.HwModelCalculator;
                break;

            case FormType.DW:
                _pHlModel = PipeHeadModelCalculators.DwModelCalculator;
                break;

            case FormType.CM:
                _pHlModel = PipeHeadModelCalculators.CmModelCalculator;
                break;
            }

            foreach (SimulationLink link in _links)
            {
                link.InitLinkFlow();
            }

            foreach (SimulationNode node in _junctions)
            {
                if (node.Ke > 0.0)
                {
                    node.SimEmitter = 1.0;
                }
            }

            foreach (SimulationLink link in _links)
            {
                if ((link.Type == LinkType.PRV ||
                     link.Type == LinkType.PSV ||
                     link.Type == LinkType.FCV) &&
                    !double.IsNaN(link.Roughness))
                {
                    link.SimStatus = StatType.ACTIVE;
                }


                if (link.SimStatus <= StatType.CLOSED)
                {
                    link.SimFlow = Constants.QZERO;
                }
                else if (Math.Abs(link.SimFlow) <= Constants.QZERO)
                {
                    link.InitLinkFlow(link.SimStatus, link.SimSetting);
                }

                link.SimOldStatus = link.SimStatus;
            }


            Htime = 0;
            Rtime = this.net.RStep;
        }