/// <summary>
        /// This is the method that actually does the work.
        /// </summary>
        /// <param name="DA">The DA object is used to retrieve from inputs and store in outputs.</param>
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            int sleeptime = 1500;

            if (!DA.GetData(3, ref sleeptime))
            {
                sleeptime = 1500;
            }

            int folderint = 0;

            if (!DA.GetData(4, ref folderint))
            {
                folderint = 0;
            }
            string path_in  = @"c:\eplus\EPOpti17\Input" + folderint + @"\";
            string path_out = @"c:\eplus\EPOpti17\Output" + folderint + @"\";
            string eplusexe = @"c:\eplus\EPOpti17\Input" + folderint + @"\ep\energyplus.exe";

            //get idf and weather files
            string idffile = @"blabla";

            if (!DA.GetData(0, ref idffile))
            {
                return;
            }
            string weatherfile = @"blabla";

            if (!DA.GetData(1, ref weatherfile))
            {
                return;
            }


            //RUN SIMU
            bool runit = false;

            if (!DA.GetData(2, ref runit))
            {
                return;
            }


            //get input parameters
            int dvar = 17;

            double[] x = new double[dvar];
            for (int i = 0; i < x.Length; i++)
            {
                if (!DA.GetData(i + 6, ref x[i]))
                {
                    return;
                }
            }
            ;


            if (runit == true)
            {
                //***********************************************************************************
                //***********************************************************************************
                //***********************************************************************************
                //modify idf file with parameters and save as new idf file
                string idfmodified = idffile + "_modi";

                //load idf into a huge string
                string[] lines;
                var      list       = new List <string>();
                var      fileStream = new FileStream(path_in + idffile + ".idf", FileMode.Open, FileAccess.Read);
                using (var streamReader = new StreamReader(fileStream))
                {
                    string line;
                    while ((line = streamReader.ReadLine()) != null)
                    {
                        list.Add(line);
                    }
                }
                lines = list.ToArray();
                fileStream.Close();

                //to be replaced
                string[] replacethis = new string[dvar + 1];
                replacethis[0]  = @"%azimuth%";
                replacethis[1]  = @"%width%";
                replacethis[2]  = @"%osize1%";
                replacethis[3]  = @"%osize2%";
                replacethis[4]  = @"%osize3%";
                replacethis[5]  = @"%osize4%";
                replacethis[6]  = @"%wwidth1%";
                replacethis[7]  = @"%wwidth2%";
                replacethis[8]  = @"%wwidth3%";
                replacethis[9]  = @"%wwidth4%";
                replacethis[10] = @"%absor%";
                replacethis[11] = @"%infil%";
                replacethis[12] = @"%tmass%";
                replacethis[13] = @"%floortype%";
                replacethis[14] = @"%rooftype%";
                replacethis[15] = @"%wintype%";
                replacethis[16] = @"%exwall%";
                replacethis[17] = @"%length%";


                //replacers
                string[] replacers = new string[dvar + 1];
                for (int i = 0; i < dvar; i++)
                {
                    replacers[i] = x[i].ToString();
                }

                double xlength = 100 / x[1];
                replacers[17] = xlength.ToString();


                //scan string for keywords and replace them with parameters
                for (int i = 0; i < lines.Length; i++)
                {
                    for (int u = 0; u < replacethis.Length; u++)
                    {
                        lines[i] = lines[i].Replace(replacethis[u], replacers[u]);
                    }
                }



                //write a new idf file
                File.WriteAllLines(path_in + idfmodified + ".idf", lines);
                string idffilenew    = path_in + idfmodified + ".idf";
                string weatherfilein = path_in + @"ep\WeatherData\" + weatherfile + ".epw";



                //***********************************************************************************
                //***********************************************************************************
                //***********************************************************************************
                //run eplus
                string command = @" -w " + weatherfilein + @" -d " + path_out + @" " + idffilenew;
                Misc.RunEplus(eplusexe, command);



                //***********************************************************************************
                //***********************************************************************************
                //***********************************************************************************
                //process Outputs
                string outputfile = "eplustbl.csv";
                while (!File.Exists(path_out + outputfile))
                {
                    Console.WriteLine("waiting");
                }



                //output result
                double result = double.NaN;
                //identify correct result file. load it. get the right numbers from it
                lines      = new string[] { };
                list       = new List <string>();
                fileStream = new FileStream(path_out + outputfile, FileMode.Open, FileAccess.Read);
                using (var streamReader = new StreamReader(fileStream))
                {
                    string line;
                    while ((line = streamReader.ReadLine()) != null)
                    {
                        list.Add(line);
                    }
                }
                lines = list.ToArray();
                fileStream.Close();

                double Fx;


                string[] split;
                char     delimiter = ',';

                split = lines[591].Split(delimiter);
                string LCC = split[2];


                Fx = Convert.ToDouble(LCC);



                result = Fx;
                System.Threading.Thread.Sleep(sleeptime);
                System.IO.File.Delete(path_in + idfmodified + ".idf");
                System.IO.DirectoryInfo di = new DirectoryInfo(path_out);

                foreach (FileInfo file in di.GetFiles())
                {
                    file.Delete();
                }
                foreach (DirectoryInfo dir in di.GetDirectories())
                {
                    dir.Delete(true);
                }



                DA.SetData(0, result);
            }
        }
Esempio n. 2
0
        /// <summary>
        /// This is the method that actually does the work.
        /// </summary>
        /// <param name="DA">The DA object is used to retrieve from inputs and store in outputs.</param>
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            int sleeptime = 1500;

            if (!DA.GetData(3, ref sleeptime))
            {
                sleeptime = 1500;
            }

            int folderint = 0;

            if (!DA.GetData(4, ref folderint))
            {
                folderint = 0;
            }
            string path_in  = @"c:\eplus\EPOpti17\Input" + folderint + @"\";
            string path_out = @"c:\eplus\EPOpti17\Output" + folderint + @"\";
            string eplusexe = @"c:\eplus\EPOpti17\Input" + folderint + @"\ep\energyplus.exe";

            //get idf and weather files
            string idffile = @"blabla";

            if (!DA.GetData(0, ref idffile))
            {
                return;
            }
            string weatherfile = @"blabla";

            if (!DA.GetData(1, ref weatherfile))
            {
                return;
            }


            //RUN SIMU
            bool runit = false;

            if (!DA.GetData(2, ref runit))
            {
                return;
            }


            //get input parameters
            int dvar = 20;

            double[] x = new double[dvar];
            for (int i = 0; i < x.Length; i++)
            {
                if (!DA.GetData(i + 6, ref x[i]))
                {
                    return;
                }
            }
            ;


            if (runit == true)
            {
                //***********************************************************************************
                //***********************************************************************************
                //***********************************************************************************
                //modify idf file with parameters and save as new idf file
                string idfmodified = idffile + "_modi";

                //load idf into a huge string
                string[] lines;
                var      list       = new List <string>();
                var      fileStream = new FileStream(path_in + idffile + ".idf", FileMode.Open, FileAccess.Read);
                using (var streamReader = new StreamReader(fileStream))
                {
                    string line;
                    while ((line = streamReader.ReadLine()) != null)
                    {
                        list.Add(line);
                    }
                }
                lines = list.ToArray();
                fileStream.Close();

                //to be replaced
                string[] replacethis = new string[dvar + 71];

                replacethis[0] = @"%x0%";    //infiltration
                int xvar_count = 1;
                for (int i = 1; i < 13; i++) //aspect ratio
                {
                    replacethis[xvar_count]     = @"%x1_p" + i.ToString() + @"_x%";
                    replacethis[xvar_count + 1] = @"%x1_p" + i.ToString() + @"_y%";
                    replacethis[xvar_count + 2] = @"%x1_p" + i.ToString() + @"_z%";
                    xvar_count += 3;
                }
                for (int i = 1; i < 9; i++)
                {
                    replacethis[xvar_count]     = @"%x1_pi" + i.ToString() + @"_x%";
                    replacethis[xvar_count + 1] = @"%x1_pi" + i.ToString() + @"_y%";
                    replacethis[xvar_count + 2] = @"%x1_pi" + i.ToString() + @"_z%";
                    xvar_count += 3;
                }
                replacethis[xvar_count] = @"%x2%"; // u-value
                xvar_count++;

                replacethis[xvar_count]      = @"%x3_xstart%";    // fenestration xstart, zstart, length, height. North
                replacethis[xvar_count + 1]  = @"%x3_zstart%";
                replacethis[xvar_count + 2]  = @"%x3_length%";
                replacethis[xvar_count + 3]  = @"%x3_height%";
                replacethis[xvar_count + 4]  = @"%x4_xstart%";    // South
                replacethis[xvar_count + 5]  = @"%x4_zstart%";
                replacethis[xvar_count + 6]  = @"%x4_length%";
                replacethis[xvar_count + 7]  = @"%x4_height%";
                replacethis[xvar_count + 8]  = @"%x5_xstart%";    // East
                replacethis[xvar_count + 9]  = @"%x5_zstart%";
                replacethis[xvar_count + 10] = @"%x5_length%";
                replacethis[xvar_count + 11] = @"%x5_height%";
                replacethis[xvar_count + 12] = @"%x6_xstart%";    // West
                replacethis[xvar_count + 13] = @"%x6_zstart%";
                replacethis[xvar_count + 14] = @"%x6_length%";
                replacethis[xvar_count + 15] = @"%x6_height%";
                xvar_count += 16;

                for (int i = 7; i < dvar; i++)
                {
                    replacethis[xvar_count] = @"%x" + i.ToString() + @"%";
                    xvar_count++;
                }



                //replacers
                string[] replacers = new string[replacethis.Length];
                replacers[0] = x[0].ToString();

                double     floor_area = 70; //according to paper. but in his file its 100 though
                double[][] x1_p;
                double[][] x1_pi;
                Misc.insert_surface(out x1_p, out x1_pi, floor_area, x[1]);

                xvar_count = 1;
                for (int i = 0; i < 12; i++)        //aspect ratio
                {
                    replacers[xvar_count]     = x1_p[i][0].ToString();
                    replacers[xvar_count + 1] = x1_p[i][1].ToString();
                    replacers[xvar_count + 2] = x1_p[i][2].ToString();
                    xvar_count += 3;
                }
                for (int i = 0; i < 8; i++)
                {
                    replacers[xvar_count]     = x1_pi[i][0].ToString();
                    replacers[xvar_count + 1] = x1_pi[i][1].ToString();
                    replacers[xvar_count + 2] = x1_pi[i][2].ToString();
                    xvar_count += 3;
                }
                replacers[xvar_count] = x[2].ToString();
                xvar_count++;

                double[] xstart;
                double[] zstart;
                double[] length;
                double[] height;
                Misc.insert_window(out xstart, out zstart, out length, out height, x1_p, new double[4] {
                    x[3], x[4], x[5], x[6]
                });

                replacers[xvar_count]      = xstart[0].ToString();    // fenestration xstart, zstart, length, height. North
                replacers[xvar_count + 1]  = zstart[0].ToString();
                replacers[xvar_count + 2]  = length[0].ToString();
                replacers[xvar_count + 3]  = height[0].ToString();
                replacers[xvar_count + 4]  = xstart[1].ToString();    // South
                replacers[xvar_count + 5]  = zstart[1].ToString();
                replacers[xvar_count + 6]  = length[1].ToString();
                replacers[xvar_count + 7]  = height[1].ToString();
                replacers[xvar_count + 8]  = xstart[2].ToString();    // East
                replacers[xvar_count + 9]  = zstart[2].ToString();
                replacers[xvar_count + 10] = length[2].ToString();
                replacers[xvar_count + 11] = height[2].ToString();
                replacers[xvar_count + 12] = xstart[3].ToString();    // West
                replacers[xvar_count + 13] = zstart[3].ToString();
                replacers[xvar_count + 14] = length[3].ToString();
                replacers[xvar_count + 15] = height[3].ToString();
                xvar_count += 16;

                switch (Convert.ToInt16(x[7]))
                {
                case 1:
                    replacers[xvar_count] = "Wall_1";
                    break;

                case 2:
                    replacers[xvar_count] = "Wall_2";
                    break;

                case 3:
                    replacers[xvar_count] = "Wall_3";
                    break;

                case 4:
                    replacers[xvar_count] = "Wall_4";
                    break;
                }
                xvar_count++;
                replacers[xvar_count] = (x[8] / 1000).ToString();
                xvar_count++;

                for (int i = 9; i < dvar; i++)
                {
                    replacers[xvar_count] = x[i].ToString();
                    xvar_count++;
                }



                //scan string for keywords and replace them with parameters
                for (int i = 0; i < lines.Length; i++)
                {
                    for (int u = 0; u < replacethis.Length; u++)
                    {
                        lines[i] = lines[i].Replace(replacethis[u], replacers[u]);
                    }
                }



                //write a new idf file
                File.WriteAllLines(path_in + idfmodified + ".idf", lines);
                string idffilenew    = path_in + idfmodified + ".idf";
                string weatherfilein = path_in + @"ep\WeatherData\" + weatherfile + ".epw";



                //***********************************************************************************
                //***********************************************************************************
                //***********************************************************************************
                //run eplus
                string command   = @" -w " + weatherfilein + @" -x -d " + path_out + @" -i " + path_in + @"ep\Energy+.idd " + idffilenew;
                string directory = path_out;
                Misc.RunEplus(eplusexe, command, directory);



                //***********************************************************************************
                //***********************************************************************************
                //***********************************************************************************
                //process Outputs
                string outputfile = "eplusout.eso";
                while (!File.Exists(path_out + outputfile))
                {
                    Console.WriteLine("waiting");
                }



                //output result
                double result = double.NaN;
                //identify correct result file. load it. get the right numbers from it
                lines      = new string[] { };
                list       = new List <string>();
                fileStream = new FileStream(path_out + outputfile, FileMode.Open, FileAccess.Read);
                using (var streamReader = new StreamReader(fileStream))
                {
                    string line;
                    while ((line = streamReader.ReadLine()) != null)
                    {
                        list.Add(line);
                    }
                }
                lines = list.ToArray();
                fileStream.Close();

                double Fx;


                string[] split;
                char     delimiter = ',';

                split = lines[11].Split(delimiter);
                string heat = split[1];
                split = lines[12].Split(delimiter);
                string cool    = split[1];
                double dblheat = 0.001 * Convert.ToDouble(heat) / 3600;
                double dblcool = 0.001 * Convert.ToDouble(cool) / 3600 * 3;

                Fx = dblheat + dblcool;


                result = Fx;
                System.Threading.Thread.Sleep(sleeptime);
                System.IO.File.Delete(path_in + idfmodified + ".idf");
                System.IO.DirectoryInfo di = new DirectoryInfo(path_out);

                foreach (FileInfo file in di.GetFiles())
                {
                    file.Delete();
                }
                foreach (DirectoryInfo dir in di.GetDirectories())
                {
                    dir.Delete(true);
                }



                DA.SetData(0, result);
            }
        }
        /// <summary>
        /// This is the method that actually does the work.
        /// </summary>
        /// <param name="DA">The DA object is used to retrieve from inputs and store in outputs.</param>
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            int sleeptime = 1500;

            if (!DA.GetData(3, ref sleeptime))
            {
                sleeptime = 1500;
            }

            int folderint = 0;

            if (!DA.GetData(4, ref folderint))
            {
                folderint = 0;
            }
            string path_in  = @"c:\eplus\EPOpti17\Input" + folderint + @"\";
            string path_out = @"c:\eplus\EPOpti17\Output" + folderint + @"\";
            string eplusexe = @"c:\eplus\EPOpti17\Input" + folderint + @"\ep\energyplus.exe";

            //get idf and weather files
            string idffile = @"blabla";

            if (!DA.GetData(0, ref idffile))
            {
                return;
            }
            string weatherfile = @"blabla";

            if (!DA.GetData(1, ref weatherfile))
            {
                return;
            }


            //RUN SIMU
            bool runit = false;

            if (!DA.GetData(2, ref runit))
            {
                return;
            }


            //get input parameters
            int dvar = 13;

            double[] x = new double[dvar];
            for (int i = 0; i < x.Length; i++)
            {
                if (!DA.GetData(i + 6, ref x[i]))
                {
                    return;
                }
            }
            ;


            if (runit == true)
            {
                //***********************************************************************************
                //***********************************************************************************
                //***********************************************************************************
                //modify idf file with parameters and save as new idf file
                string idfmodified = idffile + "_modi";

                //load idf into a huge string
                string[] lines;
                var      list       = new List <string>();
                var      fileStream = new FileStream(path_in + idffile + ".idf", FileMode.Open, FileAccess.Read);
                using (var streamReader = new StreamReader(fileStream))
                {
                    string line;
                    while ((line = streamReader.ReadLine()) != null)
                    {
                        list.Add(line);
                    }
                }
                lines = list.ToArray();
                fileStream.Close();

                //to be replaced
                string[] replacethis = new string[dvar + 17];
                for (int i = 0; i < replacethis.Length; i++)
                {
                    replacethis[i] = @"%" + i.ToString() + @"%";
                }


                //replacers
                string[] replacers = new string[replacethis.Length];
                for (int i = 0; i < dvar; i++)
                {
                    replacers[i] = x[i].ToString();
                }

                for (int i = dvar; i < dvar + 8; i++)
                {
                    replacers[i] = (x[i - dvar] + 16.7683).ToString();
                }

                for (int i = dvar + 8; i < dvar + 16; i++)
                {
                    replacers[i] = (x[i - dvar - 8] + 33.5366).ToString();
                }

                replacers[29] = (x[8] * 0.0006875 - 0.00025).ToString();


                //constraints
                bool[] gx = new bool[4];        //true means constraint violation
                if (x[0] - x[1] + 0.5488 >= 0)
                {
                    gx[0] = true;
                }
                if (x[2] - x[3] + 0.5488 >= 0)
                {
                    gx[1] = true;
                }
                if (x[4] - x[5] + 0.5488 >= 0)
                {
                    gx[2] = true;
                }
                if (x[6] - x[7] + 0.5488 >= 0)
                {
                    gx[3] = true;
                }


                //scan string for keywords and replace them with parameters
                for (int i = 0; i < lines.Length; i++)
                {
                    for (int u = 0; u < replacethis.Length; u++)
                    {
                        lines[i] = lines[i].Replace(replacethis[u], replacers[u]);
                    }
                }



                //write a new idf file
                File.WriteAllLines(path_in + idfmodified + ".idf", lines);
                string idffilenew    = path_in + idfmodified + ".idf";
                string weatherfilein = path_in + @"ep\WeatherData\" + weatherfile + ".epw";



                //***********************************************************************************
                //***********************************************************************************
                //***********************************************************************************
                //run eplus
                string command = @" -w " + weatherfilein + @" -d " + path_out + @" " + idffilenew;
                Misc.RunEplus(eplusexe, command);



                //***********************************************************************************
                //***********************************************************************************
                //***********************************************************************************
                //process Outputs
                string outputfile = "eplustbl.csv";
                while (!File.Exists(path_out + outputfile))
                {
                    Console.WriteLine("waiting");
                }



                //output result
                double result = double.NaN;
                //identify correct result file. load it. get the right numbers from it
                lines      = new string[] { };
                list       = new List <string>();
                fileStream = new FileStream(path_out + outputfile, FileMode.Open, FileAccess.Read);
                using (var streamReader = new StreamReader(fileStream))
                {
                    string line;
                    while ((line = streamReader.ReadLine()) != null)
                    {
                        list.Add(line);
                    }
                }
                lines = list.ToArray();
                fileStream.Close();

                double Fx;


                string[] split;
                char     delimiter = ',';

                split = lines[16].Split(delimiter);
                string MJm2 = split[4];

                Fx = (Convert.ToDouble(gx[0]) * 0.5 +
                      Convert.ToDouble(gx[1]) * 0.5 +
                      Convert.ToDouble(gx[2]) * 0.5 +
                      Convert.ToDouble(gx[3]) * 0.5 +
                      1) * Convert.ToDouble(MJm2);


                result = Fx;
                System.Threading.Thread.Sleep(sleeptime);
                System.IO.File.Delete(path_in + idfmodified + ".idf");
                System.IO.DirectoryInfo di = new DirectoryInfo(path_out);

                foreach (FileInfo file in di.GetFiles())
                {
                    file.Delete();
                }
                foreach (DirectoryInfo dir in di.GetDirectories())
                {
                    dir.Delete(true);
                }



                DA.SetData(0, result);
            }
        }
        /// <summary>
        /// This is the method that actually does the work.
        /// </summary>
        /// <param name="DA">The DA object is used to retrieve from inputs and store in outputs.</param>
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            int sleeptime = 1500;

            if (!DA.GetData(17, ref sleeptime))
            {
                sleeptime = 1500;
            }


            int folderint = 0;

            if (!DA.GetData(18, ref folderint))
            {
                folderint = 0;
            }
            string path_in  = @"c:\eplus\EPOpti17\Input" + folderint + @"\";
            string path_out = @"c:\eplus\EPOpti17\Output" + folderint + @"\";
            string eplusexe = @"c:\eplus\EPOpti17\Input" + folderint + @"\ep\energyplus.exe";

            //get idf and weather files
            string idffile = @"blabla";

            if (!DA.GetData(0, ref idffile))
            {
                return;
            }
            string weatherfile = @"blabla";

            if (!DA.GetData(1, ref weatherfile))
            {
                return;
            }


            //RUN SIMU
            bool runit = false;

            if (!DA.GetData(2, ref runit))
            {
                return;
            }


            //get input parameters
            double wn = double.NaN;
            double ww = double.NaN;
            double we = double.NaN;
            double ws = double.NaN;

            if (!DA.GetData(3, ref wn))
            {
                return;
            }
            ;
            if (!DA.GetData(4, ref ww))
            {
                return;
            }
            ;
            if (!DA.GetData(5, ref we))
            {
                return;
            }
            ;
            if (!DA.GetData(6, ref ws))
            {
                return;
            }
            ;

            double ow = double.NaN;
            double oe = double.NaN;
            double os = double.NaN;

            if (!DA.GetData(7, ref ow))
            {
                return;
            }
            if (!DA.GetData(8, ref oe))
            {
                return;
            }
            if (!DA.GetData(9, ref os))
            {
                return;
            }

            double sw = double.NaN;
            double se = double.NaN;
            double ss = double.NaN;

            if (!DA.GetData(10, ref sw))
            {
                return;
            }
            if (!DA.GetData(11, ref se))
            {
                return;
            }
            if (!DA.GetData(12, ref ss))
            {
                return;
            }

            double tu = double.NaN;
            double ti = double.NaN;
            double td = double.NaN;

            if (!DA.GetData(13, ref tu))
            {
                return;
            }
            if (!DA.GetData(14, ref ti))
            {
                return;
            }
            if (!DA.GetData(15, ref td))
            {
                return;
            }



            if (runit == true)
            {
                //***********************************************************************************
                //***********************************************************************************
                //***********************************************************************************
                //modify idf file with parameters and save as new idf file
                //string now = DateTime.Now.ToString("h:mm:ss");
                //now = now.Replace(':', '_');
                string idfmodified = idffile + "_modi";

                //load idf into a huge string
                string[] lines;
                var      list       = new List <string>();
                var      fileStream = new FileStream(path_in + idffile + ".idf", FileMode.Open, FileAccess.Read);
                using (var streamReader = new StreamReader(fileStream))
                {
                    string line;
                    while ((line = streamReader.ReadLine()) != null)
                    {
                        list.Add(line);
                    }
                }
                lines = list.ToArray();
                fileStream.Close();

                //to be replaced
                string[] replacethis = new string[29];
                replacethis[0] = @"%x0WinNor%";
                replacethis[1] = @"%x1WinNor%";
                replacethis[2] = @"%y0WinNor%";
                replacethis[3] = @"%x0OveNor%";
                replacethis[4] = @"%x1OveNor%";

                replacethis[5]  = @"%x0WinWes%";
                replacethis[6]  = @"%x1WinWes%";
                replacethis[7]  = @"%y0WinWes%";
                replacethis[8]  = @"%x0OveWes%";
                replacethis[9]  = @"%x1OveWes%";
                replacethis[10] = @"%yOveWes%";

                replacethis[11] = @"%x0WinEas%";
                replacethis[12] = @"%x1WinEas%";
                replacethis[13] = @"%y0WinEas%";
                replacethis[14] = @"%x0OveEas%";
                replacethis[15] = @"%x1OveEas%";
                replacethis[16] = @"%yOveEas%";

                replacethis[17] = @"%x0WinSou%";
                replacethis[18] = @"%x1WinSou%";
                replacethis[19] = @"%y0WinSou%";
                replacethis[20] = @"%x0OveSou%";
                replacethis[21] = @"%x1OveSou%";
                replacethis[22] = @"%yOveSou%";

                replacethis[23] = @"%shaWes%";
                replacethis[24] = @"%shaEas%";
                replacethis[25] = @"%shaSou%";

                replacethis[26] = @"%TZonCooNigSum%";
                replacethis[27] = @"%TZonCooNigWin%";
                replacethis[28] = @"%CooDesSupTem%";


                //replacers
                string[] replacers = new string[29];
                replacers[0] = (3.0 - (wn / 2.0)).ToString();       //x0
                replacers[1] = (3.0 + (wn / 2.0)).ToString();       //x1
                replacers[2] = (0.6).ToString();                    //y0
                replacers[3] = (3.0 - (wn / 2.0) - 0.5).ToString(); //x0 over
                replacers[4] = (3.0 + (wn / 2.0) + 0.5).ToString(); //x1 over

                replacers[5]  = (12.0 - (ww / 2.0)).ToString();     //x0
                replacers[6]  = (12.0 + (ww / 2.0)).ToString();     //x1
                replacers[7]  = (0.6).ToString();
                replacers[8]  = (12.0 - (ww / 2.0) - 0.5).ToString();
                replacers[9]  = (12.0 + (ww / 2.0) + 0.5).ToString();
                replacers[10] = (ow + 8.0).ToString();

                replacers[11] = (12.0 - (we / 2.0)).ToString();      //x0
                replacers[12] = (12.0 + (we / 2.0)).ToString();      //x1
                replacers[13] = (0.6).ToString();
                replacers[14] = (12.0 - (we / 2.0) - 0.5).ToString();
                replacers[15] = (12.0 + (we / 2.0) + 0.5).ToString();
                replacers[16] = (oe + 8.0).ToString();


                replacers[17] = (3.0 - (ws / 2.0)).ToString();       //x0
                replacers[18] = (3.0 + (ws / 2.0)).ToString();       //x1
                replacers[19] = (0.6).ToString();                    //y0
                replacers[20] = (3.0 - (ws / 2.0) - 0.5).ToString(); //x0 over
                replacers[21] = (3.0 + (ws / 2.0) + 0.5).ToString(); //x1 over
                replacers[22] = (os + 8.0).ToString();

                replacers[23] = sw.ToString();
                replacers[24] = se.ToString();
                replacers[25] = ss.ToString();

                replacers[26] = tu.ToString();
                replacers[27] = ti.ToString();
                replacers[28] = td.ToString();


                //scan string for keywords and replace them with parameters
                for (int i = 0; i < lines.Length; i++)
                {
                    for (int u = 0; u < replacethis.Length; u++)
                    {
                        lines[i] = lines[i].Replace(replacethis[u], replacers[u]);
                    }
                }


                //write a new idf file
                File.WriteAllLines(path_in + idfmodified + ".idf", lines);
                string idffilenew    = path_in + idfmodified + ".idf";
                string weatherfilein = path_in + @"ep\WeatherData\" + weatherfile + ".epw";



                //***********************************************************************************
                //***********************************************************************************
                //***********************************************************************************
                //run eplus
                string command = @" -w " + weatherfilein + @" -d " + path_out + @" " + idffilenew;
                Misc.RunEplus(eplusexe, command);

                //System.Threading.Thread.Sleep(sleeptime);



                //***********************************************************************************
                //***********************************************************************************
                //***********************************************************************************
                while (!File.Exists(path_out + "eplusout.eso"))
                {
                    Console.WriteLine("waiting");
                }
                //System.Threading.Thread.Sleep(sleeptime);


                //output result (kWh/m2a)
                double result = double.NaN;
                //identify correct result file. load it. get the right numbers from it
                lines      = new string[] { };
                list       = new List <string>();
                fileStream = new FileStream(path_out + "eplusout.eso", FileMode.Open, FileAccess.Read);
                using (var streamReader = new StreamReader(fileStream))
                {
                    string line;
                    while ((line = streamReader.ReadLine()) != null)
                    {
                        list.Add(line);
                    }
                }
                lines = list.ToArray();
                fileStream.Close();


                double primEnElec = 3.0;
                double primEnGas  = 1.0;

                string[] split;
                char     delimiter = ',';
                //split = lines[49].Split(delimiter );
                //string heat = split[3];
                //double dblHeat = Convert.ToDouble(heat) * primEnGas;

                //split = lines[50].Split(delimiter);
                //string cool = split[2];
                //double dblCool = Convert.ToDouble(cool) * primEnElec;

                //split = lines[51].Split(delimiter);
                //string light = split[2];
                //double dblLight = Convert.ToDouble(light) * primEnElec;

                //split = lines[55].Split(delimiter);
                //string fan = split[2];
                //double dblFan = Convert.ToDouble(fan) * primEnElec;
                split = lines[28].Split(delimiter);
                string heat_north = split[1];
                split = lines[29].Split(delimiter);
                string heat_west = split[1];
                split = lines[30].Split(delimiter);
                string heat_east = split[1];
                split = lines[31].Split(delimiter);
                string heat_south = split[1];
                split = lines[32].Split(delimiter);
                string heat_interior = split[1];
                split = lines[33].Split(delimiter);
                string heat_main = split[1];
                double dblHeat   = (Convert.ToDouble(heat_north) + Convert.ToDouble(heat_west)
                                    + Convert.ToDouble(heat_east) + Convert.ToDouble(heat_south)
                                    + Convert.ToDouble(heat_interior) + Convert.ToDouble(heat_main))
                                   * primEnGas / 3600000;

                split = lines[36].Split(delimiter);
                string cool    = split[1];
                double dblCool = Convert.ToDouble(cool) * primEnElec / 3600000;

                split = lines[23].Split(delimiter);
                string light_north = split[1];
                split = lines[24].Split(delimiter);
                string light_west = split[1];
                split = lines[25].Split(delimiter);
                string light_east = split[1];
                split = lines[26].Split(delimiter);
                string light_south = split[1];
                split = lines[27].Split(delimiter);
                string light_interior = split[1];
                double dblLight       = (Convert.ToDouble(light_north) * 5.0 + Convert.ToDouble(light_west)
                                         + Convert.ToDouble(light_east) + Convert.ToDouble(light_south) * 5.0 + Convert.ToDouble(light_interior))
                                        * primEnElec / 3600000; //zone north and south need to be multiplied with 5 (5 rooms). This is not considered in the .eso

                split = lines[34].Split(delimiter);
                string fan_supply = split[1];
                split = lines[34].Split(delimiter);
                string fan_return = split[1];
                double dblFan     = (Convert.ToDouble(fan_supply) + Convert.ToDouble(fan_return)) * primEnElec / 3600000;

                result = (dblHeat + dblCool + dblLight + dblFan) / 1104;   //1104 is the square meter


                System.Threading.Thread.Sleep(sleeptime);
                System.IO.File.Delete(path_in + idfmodified + ".idf");
                System.IO.DirectoryInfo di = new DirectoryInfo(path_out);
                foreach (FileInfo file in di.GetFiles())
                {
                    file.Delete();
                }
                foreach (DirectoryInfo dir in di.GetDirectories())
                {
                    dir.Delete(true);
                }

                // System.Threading.Thread.Sleep(sleeptime);
                DA.SetData(0, result);
            }
        }
Esempio n. 5
0
        /// <summary>
        /// This is the method that actually does the work.
        /// </summary>
        /// <param name="DA">The DA object is used to retrieve from inputs and store in outputs.</param>
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            int sleeptime = 1500;

            if (!DA.GetData(3, ref sleeptime))
            {
                sleeptime = 1500;
            }


            int folderint = 0;

            if (!DA.GetData(4, ref folderint))
            {
                folderint = 0;
            }
            string path_in  = @"c:\eplus\EPOpti17\Input" + folderint + @"\";
            string path_out = @"c:\eplus\EPOpti17\Output" + folderint + @"\";
            string eplusexe = @"c:\eplus\EPOpti17\Input" + folderint + @"\ep\energyplus.exe";

            //get idf and weather files
            string idffile = @"blabla";

            if (!DA.GetData(0, ref idffile))
            {
                return;
            }
            string weatherfile = @"blabla";

            if (!DA.GetData(1, ref weatherfile))
            {
                return;
            }

            //RUN SIMU
            bool runit = false;

            if (!DA.GetData(2, ref runit))
            {
                return;
            }

            int dvar = 10;

            double[] x = new double[dvar];
            for (int i = 0; i < x.Length; i++)
            {
                if (!DA.GetData(i + 6, ref x[i]))
                {
                    return;
                }
            }
            ;



            if (!runit)
            {
                return;
            }
            string        idfmodified = idffile + "_modi";
            List <string> list        = new List <string>();
            FileStream    fileStream  = new FileStream(path_in + idffile + ".idf", FileMode.Open, FileAccess.Read);

            using (StreamReader streamReader = new StreamReader((Stream)fileStream))
            {
                string line;
                while ((line = streamReader.ReadLine()) != null)
                {
                    list.Add(line);
                }
            }
            string[] lines = list.ToArray();
            fileStream.Close();
            string[] strArray1 = new string[dvar];
            strArray1[0] = "%delta%";
            strArray1[1] = "%UA1%";
            strArray1[2] = "%UA2%";
            strArray1[3] = "%UA3%";
            strArray1[4] = "%UA4%";
            strArray1[5] = "%UA5%";
            strArray1[6] = "%UA6%";
            strArray1[7] = "%UA7%";
            strArray1[8] = "%UA8%";
            strArray1[9] = "%UA9%";
            string[] strArray2 = new string[strArray1.Length];
            for (int index = 0; index < dvar; ++index)
            {
                strArray2[index] = x[index].ToString();
            }
            for (int index1 = 0; index1 < lines.Length; ++index1)
            {
                for (int index2 = 0; index2 < strArray1.Length; ++index2)
                {
                    lines[index1] = lines[index1].Replace(strArray1[index2], strArray2[index2]);
                }
            }
            File.WriteAllLines(path_in + idfmodified + ".idf", lines);
            string str6       = path_in + idfmodified + ".idf";
            string command    = " -w " + (path_in + "ep\\WeatherData\\" + weatherfile + ".epw") + " -x -d " + path_out + " -i " + path_in + "ep\\Energy+.idd " + str6;
            string directory1 = path_out;

            Misc.RunEplus(eplusexe, command, directory1);
            string str7 = "eplusout.eso";

            while (!File.Exists(path_out + str7))
            {
                Console.WriteLine("waiting");
            }
            string[]      strArray3   = new string[0];
            List <string> stringList2 = new List <string>();
            FileStream    fileStream2 = new FileStream(path_out + str7, FileMode.Open, FileAccess.Read);

            using (StreamReader streamReader = new StreamReader((Stream)fileStream2))
            {
                string str5;
                while ((str5 = streamReader.ReadLine()) != null)
                {
                    stringList2.Add(str5);
                }
            }
            string[] array2 = stringList2.ToArray();
            fileStream2.Close();
            char   ch       = ',';
            double num2     = Convert.ToDouble(array2[55].Split(ch)[1]) / 3600000.0 * (2520.0 * 0.6 * 0.75 / (19.0 - -11.5)) * 0.034 + Convert.ToDouble(array2[56].Split(ch)[1]) / 1000.0 * 12.42;
            double maxValue = (double)byte.MaxValue;
            double num3     = 0.19 * (x[0] * 100.0) - 0.15;
            double num4     = 10.0;
            double num5     = 1.4 * (maxValue * num3 / num4);
            double num6     = 10.5;
            double num7     = 0.3;
            double num8     = 8.0;
            double num9     = 0.0;

            for (int index = 0; index < 9; ++index)
            {
                num9 += x[index + 1];
            }
            double num10 = num6 / num7 * (num9 / num8) * (1.0 / num4);
            double num11 = num2 + num10 + num5;

            System.Threading.Thread.Sleep(sleeptime);
            File.Delete(path_in + idfmodified + ".idf");
            DirectoryInfo directoryInfo = new DirectoryInfo(path_out);

            foreach (FileSystemInfo file in directoryInfo.GetFiles())
            {
                file.Delete();
            }
            foreach (DirectoryInfo directory2 in directoryInfo.GetDirectories())
            {
                directory2.Delete(true);
            }
            DA.SetData(0, num11);
        }
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            int sleeptime = 1500;

            if (!DA.GetData(8, ref sleeptime))
            {
                sleeptime = 1500;
            }

            int folderint = 0;

            if (!DA.GetData(9, ref folderint))
            {
                folderint = 0;
            }
            string path_in  = @"c:\eplus\EPOpti17\Input" + folderint + @"\";
            string path_out = @"c:\eplus\EPOpti17\Output" + folderint + @"\";
            string eplusbat = @"c:\eplus\EPOpti17\Input" + folderint + @"\ep\RunEPlusEPOpti17_" + folderint + @".bat";
            string eplusexe = @"c:\eplus\EPOpti17\Input" + folderint + @"\ep\energyplus.exe";

            //get idf and weather files
            string idffile = @"blabla";

            if (!DA.GetData(0, ref idffile))
            {
                return;
            }
            string weatherfile = @"blabla";

            if (!DA.GetData(1, ref weatherfile))
            {
                return;
            }


            //RUN SIMU
            bool runit = false;

            if (!DA.GetData(2, ref runit))
            {
                return;
            }


            //get input parameters
            double alpha = double.NaN;
            double ww    = double.NaN;
            double we    = double.NaN;
            double tau   = double.NaN;

            if (!DA.GetData(3, ref alpha))
            {
                return;
            }
            ;
            if (!DA.GetData(4, ref ww))
            {
                return;
            }
            ;
            if (!DA.GetData(5, ref we))
            {
                return;
            }
            ;
            if (!DA.GetData(6, ref tau))
            {
                return;
            }
            ;



            if (runit == true)
            {
                //***********************************************************************************
                //***********************************************************************************
                //***********************************************************************************
                //modify idf file with parameters and save as new idf file
                //string now = DateTime.Now.ToString("h:mm:ss");
                //now = now.Replace(':', '_');
                //string idfmodified = idffile + "_" + now;
                string idfmodified = idffile + "_modi";

                //load idf into a huge string
                string[] lines;
                var      list       = new List <string>();
                var      fileStream = new FileStream(path_in + idffile + ".idf", FileMode.Open, FileAccess.Read);
                using (var streamReader = new StreamReader(fileStream))
                {
                    string line;
                    while ((line = streamReader.ReadLine()) != null)
                    {
                        list.Add(line);
                    }
                }
                lines = list.ToArray();
                fileStream.Close();

                //to be replaced
                string[] replacethis = new string[4];
                replacethis[0] = @"%azimuth%";
                replacethis[1] = @"%w_we_win%";
                replacethis[2] = @"%w_ea_win%";
                replacethis[3] = @"%tau%";


                //replacers
                string[] replacers = new string[4];
                replacers[0] = alpha.ToString();
                replacers[1] = ww.ToString();
                replacers[2] = we.ToString();
                replacers[3] = tau.ToString();



                //scan string for keywords and replace them with parameters
                for (int i = 0; i < lines.Length; i++)
                {
                    for (int u = 0; u < replacethis.Length; u++)
                    {
                        lines[i] = lines[i].Replace(replacethis[u], replacers[u]);
                    }
                }


                //write a new idf file
                File.WriteAllLines(path_in + idfmodified + ".idf", lines);

                string idffilenew    = path_in + idfmodified + ".idf";
                string weatherfilein = path_in + @"ep\WeatherData\" + weatherfile + ".epw";



                //***********************************************************************************
                //***********************************************************************************
                //***********************************************************************************
                //run eplus
                string command = @" -w " + weatherfilein + @" -d " + path_out + @" " + idffilenew;
                Misc.RunEplus(eplusexe, command);



                //***********************************************************************************
                //***********************************************************************************
                //***********************************************************************************
                while (!File.Exists(path_out + "eplusout.eso"))
                {
                    Console.WriteLine("waiting");
                }
                //System.Threading.Thread.Sleep(sleeptime);


                //output result (kWh/m2a)
                double result = double.NaN;
                //identify correct result file. load it. get the right numbers from it
                lines      = new string[] { };
                list       = new List <string>();
                fileStream = new FileStream(path_out + "eplusout.eso", FileMode.Open, FileAccess.Read);
                using (var streamReader = new StreamReader(fileStream))
                {
                    string line;
                    while ((line = streamReader.ReadLine()) != null)
                    {
                        list.Add(line);
                    }
                }
                lines = list.ToArray();
                fileStream.Close();


                double primEnElec = 3.0;
                double EffHeat    = 0.44;
                double EffCool    = 0.77;

                string[] split;
                //split = System.Text.RegularExpressions.Regex.Split(lines[49], "\r\n");
                char delimiter = ',';
                split = lines[12].Split(delimiter);
                string light    = split[1];
                double dblLight = Convert.ToDouble(light) / 3600000 / 96 * primEnElec;
                split = lines[13].Split(delimiter);
                string heat    = split[1];
                double dblHeat = Convert.ToDouble(heat) / 3600000 / 96 / EffHeat;
                split = lines[14].Split(delimiter);
                string cool    = split[1];
                double dblCool = Convert.ToDouble(cool) / 3600000 / 96 / EffCool;



                result = (dblHeat + dblCool + dblLight);
                System.Threading.Thread.Sleep(sleeptime);
                System.IO.File.Delete(path_in + idfmodified + ".idf");
                System.IO.DirectoryInfo di = new DirectoryInfo(path_out);

                foreach (FileInfo file in di.GetFiles())
                {
                    file.Delete();
                }
                foreach (DirectoryInfo dir in di.GetDirectories())
                {
                    dir.Delete(true);
                }



                DA.SetData(0, result);
                //System.Threading.Thread.Sleep(sleeptime);
            }
        }