Beispiel #1
0
        public void saveinp(string[] vsol)
        {
            double[] vcustoe = new double[pumps.Count + 1];
            int[]    soli    = new int[25];

            int[,] msol = new int[pumps.Count + 1, 25];
            for (int j = 1; j <= 24; j++)
            {
                int[] vint = ConverterInt(vsol[j - 1]);
                for (int i = 1; i <= pumps.Count; i++)
                {
                    msol[i, j] = vint[i];
                }
            }


            Epanet.ENopen(f1, f2, "");

            Epanet.ENsettimeparam(0, 86400);



            Epanet.ENsettimeparam(4, 0);


            int cont = 0;

            foreach (pump p in pumps)
            {
                cont++;
                for (int h = 1; h <= 24; h++)
                {
                    Epanet.ENsetpatternvalue(p.indexpattern, h, msol[cont, h]);
                }
            }
            Epanet.ENsaveinpfile("output.inp");
            //Epanet.ENsolveH();
            Epanet.ENclose();
        }
Beispiel #2
0
        public string[] simulation1h(string solh, int h, string niveli)
        {
            Epanet.ENopen(f1, f2, "");


            Epanet.ENsettimeparam(0, 3600);


            int tstep_hid = 0;

            Epanet.ENgettimeparam(1, ref tstep_hid);


            float[] cod     = solhtof(solh);
            float[] vniveis = ConvertFloat(niveli);

            int cont = 0;

            foreach (pump b in pumps)
            {
                cont++;
                Epanet.ENsetpatternvalue(b.indexpattern, h, cod[cont]);
            }


            cont = 0;
            foreach (tank tk in tanks)
            {
                cont++;
                Epanet.ENsetnodevalue(tk.index, 8, vniveis[cont]);
            }


            Epanet.ENsettimeparam(4, (h - 1) * 3600);


            Epanet.ENopenH();
            Epanet.ENinitH(1);
            int  erro  = 0;
            long tstep = 1;
            long t     = 0;
            bool v     = true;


            while (tstep > 0)
            {
                erro = Epanet.ENrunH(ref t);
                if (erro > 0)
                {
                    v = false;
                }

                if (v)
                {
                    float pressure = 0;
                    //n170
                    Epanet.ENgetnodevalue(13, 11, ref pressure);
                    if (pressure < 30 + 0.0001)
                    {
                        feasible = false;
                    }
                    //n50
                    Epanet.ENgetnodevalue(9, 11, ref pressure);
                    if (pressure < 42 + 0.0001)
                    {
                        feasible = false;
                    }
                    //n90
                    Epanet.ENgetnodevalue(6, 11, ref pressure);
                    if (pressure < 51 + 0.0001)
                    {
                        feasible = false;
                    }
                }

                if (v)
                {
                    foreach (tank tk in tanks)
                    {
                        float nivel = 0;
                        Epanet.ENgetnodevalue(tk.index, 11, ref nivel);
                        if ((nivel < tk.nivelmin + 0.0001) || (nivel > tk.nivelmax - 0.0001))
                        {
                            v = false;
                        }
                    }
                }
                if (v && t == 3600 && h == 24)
                {
                    foreach (tank tk in tanks)
                    {
                        float nivel = 0;
                        Epanet.ENgetnodevalue(tk.index, 11, ref nivel);
                        if (nivel < tk.nivelini + 0.0001)
                        {
                            v = false;
                        }
                        if ((nivel < tk.nivelmin + 0.0001) || (nivel > tk.nivelmax - 0.0001))
                        {
                            v = false;
                        }
                    }
                }
                if (v)
                {
                    int erro2 = Epanet.ENnextH(ref tstep);
                    if (tstep > 0 && tstep < tstep_hid)
                    {
                        v = false;
                    }
                }
                if (v == false)
                {
                    break;
                }
            }

            float[] re = new float[this.tanks.Count + 1];
            re[0] = 0;


            if (v)
            {
                re[0] = 1;
                cont  = 0;
                foreach (tank tk in tanks)
                {
                    cont++;
                    Epanet.ENgetnodevalue(tk.index, 11, ref re[cont]);
                }
            }
            Epanet.ENcloseH();
            Epanet.ENclose();
            string[] vst = new string[2];
            vst[1] = ConvertString(re);
            if (v)
            {
                vst[0] = "T";
            }
            else
            {
                vst[0] = "F";
            }
            return(vst);
        }
Beispiel #3
0
        public double energy(string[] vsol)
        {
            double[] vcost = new double[pumps.Count + 1];
            int[]    soli  = new int[25];

            int[,] msol = new int[pumps.Count + 1, 25];
            for (int j = 1; j <= 24; j++)
            {
                int[] vint = ConverterInt(vsol[j - 1]);
                for (int i = 1; i <= pumps.Count; i++)
                {
                    msol[i, j] = vint[i];
                }
            }

            Epanet.ENopen(f1, f2, "");


            Epanet.ENsettimeparam(0, 86400);


            int tstep_hid = 0;

            Epanet.ENgettimeparam(1, ref tstep_hid);


            Epanet.ENsettimeparam(4, 0);


            int cont = 0;

            foreach (pump p in pumps)
            {
                cont++;
                for (int h = 1; h <= 24; h++)
                {
                    Epanet.ENsetpatternvalue(p.indexpattern, h, msol[cont, h]);
                }
            }


            Epanet.ENopenH();
            Epanet.ENinitH(1);
            long tstep = 1;
            long t     = 0;

            while (tstep > 0)
            {
                Epanet.ENrunH(ref t);
                Epanet.ENnextH(ref tstep);
                double db1  = t / 3600;
                int    hora = Convert.ToInt16(Math.Truncate(db1)) + 1;
                cont = 0;
                foreach (pump p in pumps)
                {
                    cont++;
                    float pot = 0;
                    Epanet.ENgetlinkvalue(p.index, 13, ref pot);
                    float tariff = 0;
                    Epanet.ENgetpatternvalue(p.indextariff, hora, ref tariff);
                    vcost[cont] += (tstep / 3600.0) * pot * tariff;
                }
            }
            double re = 0;

            cont = 0;
            double soma = 0;

            foreach (pump p in pumps)
            {
                cont++;
                soma = soma + vcost[cont];
            }
            re = soma;
            Epanet.ENcloseH();
            Epanet.ENclose();
            return(re);
        }
Beispiel #4
0
        public void runinp()
        {
            int tipo = 0, countNodes = 0, countLinks = 0, countPatterns = 0;

            Epanet.ENopen(f1, f2, "");
            Epanet.ENgetcount(0, ref countNodes);
            Epanet.ENgetcount(2, ref countLinks);
            Epanet.ENgetcount(3, ref countPatterns);


            for (int i = 1; i <= countNodes; i++)
            {
                Epanet.ENgetnodetype(i, ref tipo);
                if (tipo == 2)
                {
                    tank r = new tank();
                    r.index = i;
                    Epanet.ENgetnodeid(i, r.id);
                    Epanet.ENgetnodevalue(i, 8, ref r.nivelini);
                    Epanet.ENgetnodevalue(i, 20, ref r.nivelmin);
                    Epanet.ENgetnodevalue(i, 21, ref r.nivelmax);
                    r.k = (Math.Log(r.nivelini) - Math.Log(r.nivelmin)) / 24;
                    tanks.Add(r);
                }
            }
            this.ntank = tanks.Count;


            string price = "PRICES";

            for (int i = 1; i <= countLinks; i++)
            {
                Epanet.ENgetlinktype(i, ref tipo);
                if (tipo == 2)
                {
                    pump p = new pump();
                    p.index = i;
                    Epanet.ENgetlinkid(i, p.id);
                    //Leitura dos padrões
                    for (int j = 1; j <= countPatterns; j++)
                    {
                        StringBuilder aux = new StringBuilder("");
                        Epanet.ENgetpatternid(j, aux);
                        string st = "PMP" + Convert.ToString(p.id);
                        //string st = "PMP" + Convert.ToString(aux);
                        if (st == Convert.ToString(aux))
                        {
                            p.indexpattern = j;
                        }

                        if (Convert.ToString(aux) == price)
                        {
                            p.indextariff = j;
                        }
                    }
                    pumps.Add(p);
                }
            }
            this.npump = pumps.Count;

            Epanet.ENclose();
        }