Esempio n. 1
0
        public Logger FFind_repr_logger(EFavorTest efavor, WaterNetwork waternetwork)
        {
            GenListWaterNetworkNode(waternetwork);
            Logger closest = GenListofLogers(efavor).OrderBy(item => Math.Abs(FNodeAverageElevation - item.elevation)).First();

            return(closest);
        }
Esempio n. 2
0
 public czart(List <Favad1.favadresults> data, WaterNetwork waterNetwork, BurstCoeffs burst, Favad1.favadcoefficients favadcoeff, Favad1.difference diff)
 {
     this.InitializeComponent();
     //this.Model = CreateNormalDistributionModel();
     this.DataContext  = this;
     this.rekord       = data;
     this.waterNetwork = waterNetwork;
     this.bust         = burst;
     this.diff         = diff;
     this.Model        = CreateNormalDistributionModel(data, waterNetwork, favadcoeff, burst);
     this.ShowResults(data, burst, diff);
 }
Esempio n. 3
0
        public List <Node> GenListWaterNetworkNode(WaterNetwork Fwaternetworknodelist)
        {
            List <Node> F_Node_list = new List <Node> {
            };

            F_Node_list = Fwaternetworknodelist.listOfNodes;
            foreach (var item in F_Node_list)
            {
                FNodeSumOfElevation = FNodeSumOfElevation + item.elevation;
            }
            FNodeAverageElevation = FNodeSumOfElevation / F_Node_list.Count();
            return(F_Node_list);
        }
Esempio n. 4
0
        public double Get_minDemand(WaterNetwork waternetwork)
        {
            List <double> demand_list     = new List <double>();
            double        suma            = 0;
            var           demands_counter = waternetwork.listOfNodes[0].demand.Count();
            var           nodes_counter   = waternetwork.listOfNodes.Count();

            for (int m = 0; m < demands_counter; m++)
            {
                for (int n = 0; n < nodes_counter; n++)
                {
                    suma = (suma + waternetwork.listOfNodes[n].demand[m]);
                }
                demand_list.Add(suma);
                suma = 0;
            }
            //MessageBox.Show("Minimal demand"+ demand_list.Min().ToString());
            return(demand_list.Min());
        }
Esempio n. 5
0
        public int GenFAVADOutput(WaterNetwork waternetwork_tk, EFavorTest efavor, BurstCoeffs burstCoeffs)
        {
            try
            {
                Favad                    favad2         = new Favad();
                double                   demand         = favad2.Get_minDemand(waternetwork_tk);
                Logger                   representative = favad2.FFind_repr_logger(efavor, waternetwork_tk);
                List <FlowMeter>         inlets         = favad2.FInlet(efavor);
                List <pair_values_favad> records        = new List <pair_values_favad>();
                for (int n = 0; n < representative.measured_pressure.Count(); n++)
                {
                    pair_values_favad pair = new pair_values_favad();
                    pair.flow     = inlets[0].measured_flow[n];
                    pair.pressure = representative.measured_pressure[n];
                    records.Add(pair);
                }
                //calibration process
                var    last     = records.Last();
                var    previous = records.AsEnumerable().Reverse().Skip(1).FirstOrDefault();
                double anzp0    = previous.pressure;
                double anzp1    = last.pressure;
                double L0       = previous.flow;;
                double L1       = last.flow;

                N1 = (Math.Log(L1 / L0)) / (Math.Log(anzp1 / anzp0));
                var B = ((L0 - demand) / Math.Pow(anzp0, 0.5) - (L1 - demand) / Math.Pow(anzp1, 0.5)) / (anzp0 - anzp1);
                var A = ((L0 - demand) / Math.Pow(anzp0, 0.5)) - B * anzp0;
                favadcoeff.A = A;
                favadcoeff.B = B;
                var text = String.Format("N1 Coefficient: {0}", N1.ToString());
                //MessageBox.Show(text);
                LeakEstimation(N1, records, demand, waternetwork_tk, burstCoeffs, favadcoeff);
                return(0);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                return(-1);

                throw;
            }
        }
Esempio n. 6
0
        public List <string> measurement_inlet_set_order = new List <string>();    ///Each item is inlet set id; order of items in this list determines which measurement number (i.e. which element of measured_flow in FlowMeter and which element of measured_pressure in Logger) correspond to which inlet set
        //list_of_throttled_inlets field is not needed if one EFavorTest allows throttling of inlets one-by-one
        //public List<FlowMeter> list_of_throttled_inlets = new List<FlowMeter>(); ///list of inlet flowmeters (and hence valves) that are throttled at the same time in this experiment
        //prv_settings will be a property of each Flowmeter object
        //public List<double[]> prv_settings = new List<double[]>(); ///no of elements in list = no_of_inlets, length of each list element (array) = no_of_pressure_steps; with field like this we have flexibility in how prvs are manipulated for multi-inlet DMA (one-by-one, all-at-once, etc.); we can still use this field, even if we assume that in each EFavorTest object only 1 prv is throttled

        /// <summary>load experiment data from Excel file
        /// </summary>
        /// <param name="file_name">xls file to be loaded</param>
        /// <param name="water_network">water_network object to use for allocating loggers to nodes and flowmeters to valves</param>
        /// <returns>0 if successful</returns>
        /// <returns>-1 if wrong logger node name</returns>
        /// <returns>-2 if wrong flowmeter valve name</returns>
        /// <returns>-3 if error in PRV setpoints</returns>
        /// <returns>-4 if unknown logger ID used in pressure_measurements sheet</returns>
        /// <returns>-5 if unknown inlet set in pressure_measurements sheet</returns>
        /// <returns>-6 if error while reading pressure in pressure_measurements sheet</returns>
        /// <returns>-7 if unknown flowmeter ID used in flow_measurements sheet</returns>
        /// <returns>-8 if unknown inlet set in flow_measurements sheet</returns>
        /// <returns>-9 if order on inlet sets different in flow measurement sheet and pressure measurement sheet</returns>
        /// <returns>-10 if error while reading flow in flow_measurements sheet</returns>
        /// <returns>-11 if VerifyEFavorSetup() returned error in data</returns>
        /// <returns>-12 if error in parsing loggers sheet</returns>
        /// <returns>-13 if error in reading times sheet</returns>
        /// <returns>-20 if other exception thrown</returns>
        public int LoadEFavorData(string file_name, WaterNetwork water_network)
        {
            //!!!TODO: test for multi-inlet DMA
            bool parse_ok;

            try
            {
                ExcelFile efavor_data = new ExcelFile();
                efavor_data.LoadXls(file_name);
                ExcelWorksheet efavor_loggers_sheet = efavor_data.Worksheets["loggers"];
                foreach (ExcelRow logger_row in efavor_loggers_sheet.Rows)
                {
                    string logger_id = logger_row.Cells[0].Value.ToString();
                    string node_id   = logger_row.Cells[1].Value.ToString();
                    if (logger_id.StartsWith("Logger ID")) //header row
                    {
                        continue;
                    }
                    double logger_elevation;
                    parse_ok = double.TryParse(logger_row.Cells[2].Value.ToString(), out logger_elevation);
                    if (!parse_ok)
                    {
                        MessageBox.Show("Unexpected string: " + logger_row.Cells[2].Value.ToString() + ", when parsing logger elevation data, expected number");
                        return(-12);
                    }
                    bool is_inlet;
                    parse_ok = bool.TryParse(logger_row.Cells[3].Value.ToString(), out is_inlet);
                    if (!parse_ok)
                    {
                        MessageBox.Show("Unexpected string: " + logger_row.Cells[3].Value.ToString() + ", when parsing logger data, expected true/false");
                        return(-12);
                    }
                    Node logger_node = water_network.listOfNodes.Find(tmp => tmp.name == node_id);
                    if (logger_node == null)
                    {
                        MessageBox.Show("Can't find node " + node_id + " when processing logger ID " + logger_id);
                        return(-1);
                    }
                    Logger new_logger = new Logger(logger_id, logger_node, is_inlet);
                    if (logger_elevation <= -1000)
                    {
                        new_logger.elevation = logger_node.elevation;
                    }
                    else
                    {
                        new_logger.elevation = logger_elevation;
                    }
                    list_of_loggers.Add(new_logger);
                    if (is_inlet)
                    {
                        list_of_inlet_loggers.Add(new_logger);
                    }
                }
                no_of_loggers = list_of_loggers.Count;
                //MessageBox.Show(efavor_loggers_sheet.Rows.Count.ToString()); //used number of rows

                ExcelWorksheet efavor_flowmeters_sheet = efavor_data.Worksheets["inlets"];
                foreach (ExcelRow flowmeter_row in efavor_flowmeters_sheet.Rows)
                {
                    string flowmeter_id     = flowmeter_row.Cells[0].Value.ToString();
                    string valve_id         = flowmeter_row.Cells[1].Value.ToString();
                    string set_of_inlets_id = flowmeter_row.Cells[2].Value.ToString(); //Inlets belonging to the same set are throttled at the same time.
                    if (flowmeter_id.StartsWith("Flowmeter ID"))                       //header row - !!! check if all headings are as expected
                    {
                        continue;
                    }
                    Valve flowmeter_valve = water_network.listOfValves.Find(tmp => tmp.link.name == valve_id);
                    if (flowmeter_valve == null)
                    {
                        MessageBox.Show("Can't find valve " + valve_id + " when processing flowmeter ID " + flowmeter_id);
                        return(-2);
                    }
                    FlowMeter new_flowmeter = new FlowMeter(flowmeter_id, flowmeter_valve, set_of_inlets_id);
                    for (int i = 3; i < flowmeter_row.AllocatedCells.Count; i++) //first 3 columns are flowmeter id, valve id and set
                    {
                        double prv_setting;
                        parse_ok = double.TryParse(flowmeter_row.Cells[i].Value.ToString(), out prv_setting);
                        if (parse_ok)
                        {
                            new_flowmeter.prv_settings.Add(prv_setting);
                        }
                        else
                        {
                            MessageBox.Show("Error while reading PRV setpoints for flowmeter ID " + flowmeter_id);
                            return(-3);  //perhaps this could be just ignored instead of return???
                        }
                    }
                    list_of_inlet_flowmeters.Add(new_flowmeter);
                    bool already_defined = list_of_inlet_set_ids.Exists(tmp => tmp == set_of_inlets_id); //check if this set_of_inlets has already been added to the list of sets
                    if (!already_defined)
                    {
                        list_of_inlet_set_ids.Add(set_of_inlets_id);
                    }
                }
                no_of_inlets = list_of_inlet_flowmeters.Count;
                if (no_of_inlets == 0)
                {
                    throw new Exception("This experiment data does not seem to have any PRV inlets!");
                }

                ExcelWorksheet efavor_pressure_measure_sheet = efavor_data.Worksheets["pressure_measurements"];
                List <int>     logger_index_order            = new List <int>();                     //order of loggers in the pressure_measurements sheet
                for (int i = 1; i < efavor_pressure_measure_sheet.Rows[0].AllocatedCells.Count; i++) //read header row, get order of loggers; use AllocatedCells.Count instead of no_of_loggers to avoid error in case pressure_measurements sheet did not have enough columns, correctness of all measurement data is checked later on anyway
                {
                    string logger_id = efavor_pressure_measure_sheet.Cells[0, i].Value.ToString();
                    int    tmp_index = list_of_loggers.FindIndex(tmp => tmp.logger_id == logger_id);
                    if (tmp_index < 0)
                    {
                        MessageBox.Show("Unknown logger ID " + logger_id + " in pressure_measurements sheet");
                        return(-4);
                    }
                    else
                    {
                        logger_index_order.Add(tmp_index);
                    }
                }
                if (logger_index_order.Count != list_of_loggers.Count)
                {
                    MessageBox.Show("Number of declared loggers does not match number of loggers in sheet \"pressure_measurements\"");
                    return(-6);
                }
                for (int i = 1; i < efavor_pressure_measure_sheet.Rows.Count; i++)
                {
                    ExcelRow current_row = efavor_pressure_measure_sheet.Rows[i];
                    string   inlet_set   = current_row.Cells[0].Value.ToString();
                    if (!list_of_inlet_set_ids.Exists(tmp => tmp == inlet_set))
                    {
                        MessageBox.Show("Unknown inlet set " + inlet_set + " when processing pressure_measurements sheet");
                        return(-5);
                    }
                    measurement_inlet_set_order.Add(inlet_set);
                    for (int j = 1; j < no_of_loggers + 1; j++)
                    {
                        double pressure;
                        parse_ok = double.TryParse(current_row.Cells[j].Value.ToString(), out pressure);
                        if (parse_ok)
                        {
                            list_of_loggers[logger_index_order[j - 1]].measured_pressure.Add(pressure);
                        }
                        else
                        {
                            MessageBox.Show("Error while reading pressure measurement for logger ID " + list_of_loggers[logger_index_order[j - 1]].logger_id);
                            return(-6);
                        }
                    }
                }

                ExcelWorksheet efavor_flow_measure_sheet = efavor_data.Worksheets["flow_measurements"];
                List <int>     flowmeter_index_order     = new List <int>(); //order of flowmeters in the flow_measurements sheet
                if (efavor_flow_measure_sheet.Rows[0].AllocatedCells.Count - 1 != no_of_inlets)
                {
                    MessageBox.Show("Missing data in flow measurement sheet. Declared flowmeters: " + no_of_inlets.ToString() + ". Flow measurement datasets: " + (efavor_flow_measure_sheet.Rows[0].AllocatedCells.Count - 1).ToString());
                    return(-10);
                }
                for (int i = 1; i < efavor_flow_measure_sheet.Rows[0].AllocatedCells.Count; i++) //read header row, get order of flowmeters; use AllocatedCells.Count instead of no_of_inlets to avoid error in case flow_measurements sheet did not have enough columns, correctness of all measurement data is checked later on anyway
                {
                    string flowmeter_id = efavor_flow_measure_sheet.Cells[0, i].Value.ToString();
                    int    tmp_index    = list_of_inlet_flowmeters.FindIndex(tmp => tmp.flowmeter_id == flowmeter_id);
                    if (tmp_index < 0)
                    {
                        MessageBox.Show("Unknown flowmeter ID " + flowmeter_id + " in flow_measurements sheet");
                        return(-7);
                    }
                    else
                    {
                        flowmeter_index_order.Add(tmp_index);
                    }
                }
                total_no_of_pressure_steps = 0;
                for (int i = 1; i < efavor_flow_measure_sheet.Rows.Count; i++)
                {
                    total_no_of_pressure_steps++;
                    ExcelRow current_row = efavor_flow_measure_sheet.Rows[i];
                    string   inlet_set   = current_row.Cells[0].Value.ToString();
                    if (!list_of_inlet_set_ids.Exists(tmp => tmp == inlet_set))
                    {
                        MessageBox.Show("Unknown inlet set " + inlet_set + " when processing flow_measurements sheet");
                        return(-8);
                    }
                    if (measurement_inlet_set_order[i - 1] != inlet_set)
                    {
                        MessageBox.Show("Order on inlet sets different in flow measurement sheet and pressure measurement sheet");
                        return(-9);
                    }
                    for (int j = 1; j < no_of_inlets + 1; j++)
                    {
                        double flow;
                        parse_ok = double.TryParse(current_row.Cells[j].Value.ToString(), out flow);
                        if (parse_ok)
                        {
                            list_of_inlet_flowmeters[flowmeter_index_order[j - 1]].measured_flow.Add(flow);
                        }
                        else
                        {
                            MessageBox.Show("Error while reading flow measurement for flowmeter ID " + list_of_inlet_flowmeters[flowmeter_index_order[j - 1]].flowmeter_id);
                            return(-10);
                        }
                    }
                }

                //load experiment time variables
                ExcelWorksheet efavor_times_sheet = efavor_data.Worksheets["times"];
                int            tmp_time;
                parse_ok = int.TryParse(efavor_times_sheet.Rows[0].Cells[1].Value.ToString(), out tmp_time);
                if (parse_ok)
                {
                    first_measure_time = tmp_time;
                }
                else
                {
                    MessageBox.Show("Error while reading start time. Value read: " + efavor_times_sheet.Rows[0].Cells[1].Value.ToString());
                    return(-13);
                }
                parse_ok = int.TryParse(efavor_times_sheet.Rows[1].Cells[1].Value.ToString(), out tmp_time);
                if (parse_ok)
                {
                    time_step_pressure_stepping = tmp_time;
                }
                else
                {
                    MessageBox.Show("Error while reading measurement time step. Value read: " + efavor_times_sheet.Rows[1].Cells[1].Value.ToString());
                    return(-13);
                }
                if ((first_measure_time <= 0) || (time_step_pressure_stepping <= 0))
                {
                    MessageBox.Show("Times cannot be negative!");
                    return(-13);
                }
            }//try
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                return(-20);
            }
            //Verify that the experiment data makes sense
            if (VerifyEFavorSetup() < 0)
            {
                return(-11);
            }
            return(0);
        }
Esempio n. 7
0
        /// <summary>
        /// Copy constructor
        /// </summary>
        /// <param name="waterNetworkObject">Water network object</param>
        public WaterNetwork(WaterNetwork waterNetworkObject)
        {
            nNodes      = waterNetworkObject.nNodes;
            nLinks      = waterNetworkObject.nLinks;
            nPumps      = waterNetworkObject.nPumps;
            nValves     = waterNetworkObject.nValves;
            nPipes      = waterNetworkObject.nPipes;
            nPipesCV    = waterNetworkObject.nPipesCV;
            nJunctions  = waterNetworkObject.nJunctions;
            nReservoirs = waterNetworkObject.nReservoirs;
            nTanks      = waterNetworkObject.nTanks;
            nPatterns   = waterNetworkObject.nPatterns;
            nCurves     = waterNetworkObject.nCurves;

            nReportingPeriods  = waterNetworkObject.nReportingPeriods;
            reportingStartTime = waterNetworkObject.reportingStartTime;
            reportingTimeStep  = waterNetworkObject.reportingTimeStep;
            simulationDuration = waterNetworkObject.simulationDuration;

            emitterExponent = waterNetworkObject.emitterExponent;

            flowUnits           = waterNetworkObject.flowUnits;
            pressureUnits       = waterNetworkObject.pressureUnits;
            flowConversion      = waterNetworkObject.flowConversion;
            lengthConversion    = waterNetworkObject.lengthConversion;
            presssureConversion = waterNetworkObject.presssureConversion;
            waterNetworkType    = waterNetworkObject.waterNetworkType;
            title     = waterNetworkObject.title;
            isPlotted = waterNetworkObject.isPlotted;

            foreach (Link link in waterNetworkObject.listOfLinks)
            {
                listOfLinks.Add(link);
            }

            foreach (Node node in waterNetworkObject.listOfNodes)
            {
                listOfNodes.Add(node);
            }

            foreach (Pump pump in waterNetworkObject.listOfPumps)
            {
                listOfPumps.Add(pump);
            }

            foreach (Valve valve in waterNetworkObject.listOfValves)
            {
                listOfValves.Add(valve);
            }

            foreach (Reservoir reservoir in waterNetworkObject.listOfReservoirs)
            {
                listOfReservoirs.Add(reservoir);
            }

            foreach (Tank tank in waterNetworkObject.listOfTanks)
            {
                listOfTanks.Add(tank);
            }
            foreach (Pattern pattern in waterNetworkObject.listOfPatterns)
            {
                listOfPatterns.Add(pattern);
            }
            foreach (Curve curve in waterNetworkObject.listOfCurves)
            {
                listOfCurves.Add(curve);
            }

            foreach (Controls control in waterNetworkObject.listOfControls)
            {
                listOfControls.Add(control);
            }
        }
Esempio n. 8
0
        public int LeakEstimation(double N1, List <pair_values_favad> para, double demand, WaterNetwork network, BurstCoeffs burstCoeffs, favadcoefficients favadcoeff)
        {
            try
            {
                //favad_res.N1 = N1;
                para.Reverse();
                for (int jx = 0; jx < para.Count() - 1; jx++)
                {
                    favadresults favad_res = new favadresults();
                    favad_res.N1    = N1;
                    favad_res.Flow0 = para[jx].flow - demand;
                    favad_res.AZNP0 = para[jx].pressure;
                    favad_res.AZNP1 = para[jx + 1].pressure;
                    favad_res.Flow1 = favad_res.Flow0 * Math.Pow((favad_res.AZNP1 / favad_res.AZNP0), favad_res.N1);
                    favadres.Add(favad_res);
                }
                var nodes              = network.listOfNodes;
                var emmiter            = nodes.Where(s => s.emmitterCoefficient != 0).First();
                var result_comparation = ComparativeRres(favadcoeff.A, favadcoeff.B, N1, emmiter.emmitterCoefficient, network.emitterExponent, burstCoeffs.est_burst_coeff, burstCoeffs.est_burst_exponent);

                czart czart1 = new czart(favadres, network, burstCoeffs, favadcoeff, result_comparation);
                czart1.Show();



                return(0);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                return(-1);
            }
        }