Ejemplo n.º 1
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)
        {
            List <double>   valin  = new List <double>();
            List <double[]> valin2 = new List <double[]>();

            Mesh mshin = new Mesh();

            if (!DA.GetData(0, ref mshin))
            {
                return;
            }

            CResults results = null;

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

            int outputType = 0;

            if (!DA.GetData(2, ref outputType))
            {
                outputType = 0;
            }

            int sp = 0; //sensor point, or mesh vertex

            if (!DA.GetData(3, ref sp))
            {
                sp = 0;
            }

            double copyval;

            switch (outputType)
            {
            case 0:     // [kWh/m^2a] total
                copyval = results.I_total[sp];
                valin.Add(copyval);
                break;

            case 1:     // [kWh/m^2a] beam
                copyval = results.Ib_total[sp];
                valin.Add(copyval);
                break;

            case 2:     // [kWh/m^2a] diffuse
                copyval = results.Id_total[sp];
                valin.Add(copyval);
                break;

            case 3:     // [kWh/a] total
                valin = new List <double>(results.I_total);
                break;

            case 4:     // [W/m^2] total
                for (int t = 0; t < results.I_hourly.ColumnCount; t++)
                {
                    valin.Add(results.I_hourly[sp, t]);
                }
                break;

            case 5:     // [W/m^2] beam
                for (int t = 0; t < results.Ib_hourly.ColumnCount; t++)
                {
                    valin.Add(results.Ib_hourly[sp, t]);
                }
                break;

            case 6:     // [W/m^2] diffuse
                for (int t = 0; t < results.Id_hourly.ColumnCount; t++)
                {
                    valin.Add(results.Id_hourly[sp, t]);
                }
                break;

            case 7:     // [W] total
                for (int i = 0; i < results.I_hourly.RowCount; i++)
                {
                    double[] val_t = new double[results.I_hourly.ColumnCount];
                    for (int t = 0; t < results.I_hourly.ColumnCount; t++)
                    {
                        val_t[t] = results.I_hourly[i, t];
                    }
                    valin2.Add(val_t);
                }
                break;
            }

            if (outputType == 3)
            {
                double[] mshFaceAreas = new double[mshin.Faces.Count];

                double totVal = 0;
                for (int i = 0; i < mshin.Faces.Count; i++)
                {
                    mshFaceAreas[i] = CMisc.getMeshFaceArea(i, mshin);

                    double FaceVal;
                    double valVertex1 = valin[mshin.Faces[i].A];
                    double valVertex2 = valin[mshin.Faces[i].B];
                    double valVertex3 = valin[mshin.Faces[i].C];
                    if (mshin.Faces[i].IsQuad)
                    {
                        double valVertex4 = valin[mshin.Faces[i].D];
                        FaceVal = ((valVertex1 + valVertex2 + valVertex3 + valVertex4) / 4) * CMisc.getMeshFaceArea(i, mshin);
                    }
                    else
                    {
                        FaceVal = ((valVertex1 + valVertex2 + valVertex3) / 3) * CMisc.getMeshFaceArea(i, mshin);
                    }
                    totVal += FaceVal;
                }
                valin = new List <double>();
                valin.Add(totVal);
            }
            else if (outputType == 7)
            {
                List <double> valout = new List <double>();

                double[] mshFaceAreas = new double[mshin.Faces.Count];

                for (int t = 0; t < results.I_hourly.ColumnCount; t++)
                {
                    double totVal = 0;
                    for (int i = 0; i < mshin.Faces.Count; i++)
                    {
                        mshFaceAreas[i] = CMisc.getMeshFaceArea(i, mshin);

                        double FaceVal;
                        double valVertex1 = valin2[mshin.Faces[i].A][t];
                        double valVertex2 = valin2[mshin.Faces[i].B][t];
                        double valVertex3 = valin2[mshin.Faces[i].C][t];
                        if (mshin.Faces[i].IsQuad)
                        {
                            double valVertex4 = valin2[mshin.Faces[i].D][t];
                            FaceVal = ((valVertex1 + valVertex2 + valVertex3 + valVertex4) / 4) * CMisc.getMeshFaceArea(i, mshin);
                        }
                        else
                        {
                            FaceVal = ((valVertex1 + valVertex2 + valVertex3) / 3) * CMisc.getMeshFaceArea(i, mshin);
                        }
                        totVal += FaceVal;
                    }
                    valout.Add(totVal);
                }

                valin = new List <double>();
                valin = valout;
            }

            if (outputType == 0 || outputType == 1 || outputType == 2 || outputType == 3)
            {
                List <double> valin_copy = new List <double>(valin);
                for (int i = 0; i < valin.Count; i++)
                {
                    valin_copy[i] *= 0.001;
                }
                valin = new List <double>(valin_copy);
            }

            DA.SetDataList(0, valin);
            DA.SetData(1, results.coords[sp]);
        }
Ejemplo 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)
        {
            Mesh mshin = new Mesh();

            if (!DA.GetData(0, ref mshin))
            {
                return;
            }

            CResults results = null;

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

            int outputType = 0;

            if (!DA.GetData(2, ref outputType))
            {
                outputType = 0;
            }


            Grasshopper.DataTree <double> avgI = new Grasshopper.DataTree <double>();

            List <double> areas = new List <double>();

            MeshFaceList mshfaces = mshin.Faces;


            for (int m = 0; m < mshfaces.Count; m++)
            {
                MeshFace fc = mshfaces[m];

                int    spA       = fc.A;
                int    spB       = fc.B;
                int    spC       = fc.C;
                int    spD       = fc.D;
                int    intvert   = 3;
                double quadmulti = 0;
                if (fc.IsQuad)
                {
                    intvert   = 4;
                    quadmulti = 1;
                }

                Grasshopper.Kernel.Data.GH_Path ghpath = new Grasshopper.Kernel.Data.GH_Path(m);

                List <double> sp_I = new List <double>();

                switch (outputType)
                {
                case 0:
                    avgI.Add((results.I_total[spA] + results.I_total[spB] + results.I_total[spC] + (results.I_total[spD] * quadmulti)) / intvert, ghpath);
                    break;

                case 1:
                    avgI.Add((results.Ib_total[spA] + results.Ib_total[spB] + results.Ib_total[spC] + (results.Ib_total[spD] * quadmulti)) / intvert, ghpath);
                    break;

                case 2:
                    avgI.Add((results.Id_total[spA] + results.Id_total[spB] + results.Id_total[spC] + (results.Id_total[spD] * quadmulti)) / intvert, ghpath);
                    break;

                case 3:
                    for (int t = 0; t < results.I_hourly.ColumnCount; t++)
                    {
                        avgI.Add((results.I_hourly[spA, t] + results.I_hourly[spB, t] + results.I_hourly[spC, t] + (results.I_hourly[spD, t] * quadmulti)) / intvert, ghpath);
                    }
                    break;

                case 4:
                    for (int t = 0; t < results.Ib_hourly.ColumnCount; t++)
                    {
                        avgI.Add((results.Ib_hourly[spA, t] + results.Ib_hourly[spB, t] + results.Ib_hourly[spC, t] + (results.Ib_hourly[spD, t] * quadmulti)) / intvert, ghpath);
                    }
                    break;

                case 5:
                    for (int t = 0; t < results.Id_hourly.ColumnCount; t++)
                    {
                        avgI.Add((results.Id_hourly[spA, t] + results.Id_hourly[spB, t] + results.Id_hourly[spC, t] + (results.Id_hourly[spD, t] * quadmulti)) / intvert, ghpath);
                    }
                    break;

                case 6:
                    for (int t = 0; t < results.Ib_hourly.ColumnCount; t++)
                    {
                        int shdwcount = 0;
                        if (results.Ib_hourly[spA, t] == 0)
                        {
                            shdwcount++;
                        }
                        if (results.Ib_hourly[spB, t] == 0)
                        {
                            shdwcount++;
                        }
                        if (results.Ib_hourly[spC, t] == 0)
                        {
                            shdwcount++;
                        }
                        if (results.Ib_hourly[spD, t] == 0)
                        {
                            shdwcount++;
                        }
                        if (shdwcount > 1)
                        {
                            avgI.Add(0, ghpath);
                        }
                        else
                        {
                            avgI.Add(1, ghpath);
                        }
                    }
                    break;
                }
                areas.Add(CMisc.getMeshFaceArea(m, mshin));
            }



            DA.SetDataTree(0, avgI);
            DA.SetDataList(1, areas);
        }
Ejemplo n.º 3
0
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            //______________________________________________________________________________________________
            ////////////////////////////////        I N P U T S          ///////////////////////////////////
            Mesh            msh    = new Mesh();
            CObstacleObject mshobj = null;

            if (!DA.GetData(0, ref mshobj))
            {
                return;
            }
            msh = mshobj.mesh;

            //should containt analysis surface itself
            List <CObstacleObject> objObst = new List <CObstacleObject>();

            if (!DA.GetDataList(1, objObst))
            {
                return;
            }

            List <CPermObject> treeObst = new List <CPermObject>();

            DA.GetDataList(2, treeObst);

            double latitude = 0.0;

            if (!DA.GetData(4, ref latitude))
            {
                return;
            }
            double longitude = 0.0;

            if (!DA.GetData(5, ref longitude))
            {
                return;
            }

            int year = 0;

            if (!DA.GetData(6, ref year))
            {
                return;
            }

            double snow_threshold = 1.0;

            if (!DA.GetData(7, ref snow_threshold))
            {
                snow_threshold = 1.0;
            }
            double tilt_threshold = 60.0;

            if (!DA.GetData(8, ref tilt_threshold))
            {
                tilt_threshold = 60.0;
            }


            List <double> DNI = new List <double>();

            if (!DA.GetDataList(10, DNI))
            {
                return;
            }
            List <double> DHI = new List <double>();

            if (!DA.GetDataList(11, DHI))
            {
                return;
            }
            List <double> SNOW = new List <double>();

            if (!DA.GetDataList(12, SNOW))
            {
                for (int t = 0; t < 8760; t++)
                {
                    SNOW.Add(0.0);
                }
            }
            List <double> groundalbedo = new List <double>();

            if (!DA.GetDataList(13, groundalbedo))
            {
                for (int t = 0; t < 8760; t++)
                {
                    groundalbedo.Add(0.2);
                }
            }
            List <double> solarAzimuth = new List <double>();

            DA.GetDataList(14, solarAzimuth);
            List <double> solarAltitude = new List <double>();

            DA.GetDataList(15, solarAltitude);

            int MainSkyRes = 0;

            if (!DA.GetData(17, ref MainSkyRes))
            {
                MainSkyRes = 1;
            }
            int MainInterpMode = 0;

            if (!DA.GetData(18, ref MainInterpMode))
            {
                MainInterpMode = 0;
            }

            int SpecBounces = 1;

            if (!DA.GetData(20, ref SpecBounces))
            {
                SpecBounces = 1;
            }
            SpecBounces = (SpecBounces < 0) ? 0 : SpecBounces;
            int SpecInterpMode = 0;

            if (!DA.GetData(21, ref SpecInterpMode))
            {
                SpecInterpMode = 0;
            }

            int DiffIReflSkyRes = 0;

            if (!DA.GetData(23, ref DiffIReflSkyRes))
            {
                DiffIReflSkyRes = 0;
            }
            int DiffIReflSkyRes2nd = 0;

            if (!DA.GetData(24, ref DiffIReflSkyRes2nd))
            {
                DiffIReflSkyRes2nd = 0;
            }
            int DiffIReflMode = 1;

            if (!DA.GetData(25, ref DiffIReflMode))
            {
                DiffIReflMode = 1;
            }

            CResultsInterreflections ResultsIreflIn = null;

            DA.GetData(27, ref ResultsIreflIn);

            bool mt = false;

            if (!DA.GetData(29, ref mt))
            {
                mt = false;
            }
            ////////////////////////////////////////////////////////////////////////////////////////////////
            //______________________________________________________________________________________________


            //______________________________________________________________________________________________
            ////////////////////////////////        S I M U L A T E      ///////////////////////////////////
            CCalculateSolarMesh calc = new CCalculateSolarMesh(
                mshobj, objObst, treeObst, latitude, longitude, DNI, DHI, SNOW, groundalbedo, snow_threshold, tilt_threshold,
                year, null, mt, solarAzimuth, solarAltitude);

            calc.RunAnnualSimulation_MT(
                mshobj.tolerance, MainSkyRes, MainInterpMode, SpecBounces, SpecInterpMode, DiffIReflSkyRes, DiffIReflSkyRes2nd, DiffIReflMode);

            CResults results = calc.getResults();

            //cResultsInterreflections resultsIreflOut = calc.getResultsInterreflections();
            ////////////////////////////////////////////////////////////////////////////////////////////////
            //______________________________________________________________________________________________


            //______________________________________________________________________________________________
            ////////////////////////////////          O U T P U T        ///////////////////////////////////
            DA.SetData(0, results);

            ////////////////////////////////////////////////////////////////////////////////////////////////
            //______________________________________________________________________________________________


            Rhino.RhinoApp.WriteLine("SOLAR MODEL... Done");
        }
Ejemplo n.º 4
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)
        {
            Mesh mshin = new Mesh();

            if (!DA.GetData(0, ref mshin))
            {
                return;
            }

            List <double> valin = new List <double>();
            //if (!DA.GetDataList(1, valin)) { return; }
            CResults results = null;

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

            int outputType = 0;

            if (!DA.GetData(2, ref outputType))
            {
                outputType = 0;
            }

            int t = 0;

            if (!DA.GetData(3, ref t))
            {
                t = 0;
            }
            if (results.Ib_hourly.ColumnCount == 1)
            {
                t = 0;                                      //if its a one hour simulation only ->GHSolarMeshHour.
            }
            switch (outputType)
            {
            case 0:     // [kWh/m^2a] total
                valin = new List <double>(results.I_total);
                break;

            case 1:     // [kWh/m^2a] beam
                valin = new List <double>(results.Ib_total);
                break;

            case 2:     // [kWh/m^2a] diffuse
                valin = new List <double>(results.Id_total);
                break;

            case 3:     // [kWh/a] total
                valin = new List <double>(results.I_total);
                break;

            case 4:     // [W/m^2] total
                for (int i = 0; i < results.Ib_hourly.RowCount; i++)
                {
                    valin.Add(results.I_hourly[i, t]);
                }
                break;

            case 5:     // [W/m^2] beam
                for (int i = 0; i < results.Ib_hourly.RowCount; i++)
                {
                    valin.Add(results.Ib_hourly[i, t]);
                }
                break;

            case 6:     // [W/m^2] diffuse
                for (int i = 0; i < results.Id_hourly.RowCount; i++)
                {
                    valin.Add(results.Id_hourly[i, t]);
                }
                break;

            case 7:     // [W] total
                for (int i = 0; i < results.I_hourly.RowCount; i++)
                {
                    valin.Add(results.I_hourly[i, t]);
                }
                break;
            }

            if (outputType == 0 || outputType == 1 || outputType == 2 || outputType == 3)
            {
                for (int i = 0; i < valin.Count; i++)
                {
                    valin[i] *= 0.001;      // in kW, not W
                }
            }



            double min = 0;

            if (!DA.GetData(4, ref min))
            {
                min = valin.Min();
            }

            double max = 1;

            if (!DA.GetData(5, ref max))
            {
                max = valin.Max();
            }

            int clr = 0;

            if (!DA.GetData(6, ref clr))
            {
                clr = 0;
            }


            Color c      = new Color();
            Mesh  mshcol = new Mesh();
            int   count  = 0;

            if (outputType != 3 && outputType != 7)
            {
                for (int i = 0; i < mshin.Faces.Count; i++)
                {
                    c = CMisc.GetRGB(clr, valin[mshin.Faces[i].A], max, min);
                    mshcol.Vertices.Add(mshin.Vertices[mshin.Faces[i].A]);
                    mshcol.VertexColors.SetColor(count, c);

                    c = CMisc.GetRGB(clr, valin[mshin.Faces[i].B], max, min);
                    mshcol.Vertices.Add(mshin.Vertices[mshin.Faces[i].B]);
                    mshcol.VertexColors.SetColor(count + 1, c);

                    c = CMisc.GetRGB(clr, valin[mshin.Faces[i].C], max, min);
                    mshcol.Vertices.Add(mshin.Vertices[mshin.Faces[i].C]);
                    mshcol.VertexColors.SetColor(count + 2, c);

                    if (mshin.Faces[i].IsQuad)
                    {
                        c = CMisc.GetRGB(clr, valin[mshin.Faces[i].D], max, min);
                        mshcol.Vertices.Add(mshin.Vertices[mshin.Faces[i].D]);
                        mshcol.VertexColors.SetColor(count + 3, c);
                        mshcol.Faces.AddFace(count, count + 1, count + 2, count + 3);
                        count += 4;
                    }
                    else
                    {
                        mshcol.Faces.AddFace(count, count + 1, count + 2);
                        count += 3;
                    }
                }
            }
            else
            {
                double[] mshFaceAreas = new double[mshin.Faces.Count];

                double totVal = 0;
                for (int i = 0; i < mshin.Faces.Count; i++)
                {
                    mshFaceAreas[i] = CMisc.getMeshFaceArea(i, mshin);

                    double FaceVal;
                    double valVertex1 = valin[mshin.Faces[i].A];
                    double valVertex2 = valin[mshin.Faces[i].B];
                    double valVertex3 = valin[mshin.Faces[i].C];
                    if (mshin.Faces[i].IsQuad)
                    {
                        double valVertex4 = valin[mshin.Faces[i].D];
                        FaceVal = ((valVertex1 + valVertex2 + valVertex3 + valVertex4) / 4) * CMisc.getMeshFaceArea(i, mshin);
                    }
                    else
                    {
                        FaceVal = ((valVertex1 + valVertex2 + valVertex3) / 3) * CMisc.getMeshFaceArea(i, mshin);
                    }
                    totVal += FaceVal;
                }
                count = 0;
                for (int i = 0; i < mshin.Faces.Count; i++)
                {
                    c = CMisc.GetRGB(clr, totVal, max, min);
                    mshcol.Vertices.Add(mshin.Vertices[mshin.Faces[i].A]);
                    mshcol.VertexColors.SetColor(count, c);
                    mshcol.Vertices.Add(mshin.Vertices[mshin.Faces[i].B]);
                    mshcol.VertexColors.SetColor(count + 1, c);
                    mshcol.Vertices.Add(mshin.Vertices[mshin.Faces[i].C]);
                    mshcol.VertexColors.SetColor(count + 2, c);

                    if (mshin.Faces[i].IsQuad)
                    {
                        mshcol.Vertices.Add(mshin.Vertices[mshin.Faces[i].D]);
                        mshcol.VertexColors.SetColor(count + 3, c);
                        mshcol.Faces.AddFace(count, count + 1, count + 2, count + 3);
                        count += 4;
                    }
                    else
                    {
                        mshcol.Faces.AddFace(count, count + 1, count + 2);
                        count += 3;
                    }
                }
            }



            DA.SetData(0, mshcol);
        }
Ejemplo n.º 5
0
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            #region INPUTS
            //___________________________________________________________________
            /////////////////////////////////////////////////////////////////////
            //INPUTS
            Mesh            msh    = new Mesh();
            CObstacleObject mshobj = null;
            if (!DA.GetData(0, ref mshobj))
            {
                return;
            }
            msh = mshobj.mesh;

            //should containt analysis surface itself
            List <CObstacleObject> objObst = new List <CObstacleObject>();
            if (!DA.GetDataList(1, objObst))
            {
                return;
            }

            List <CPermObject> treeObst = new List <CPermObject>();
            DA.GetDataList(2, treeObst);

            double latitude = 0.0;
            if (!DA.GetData(4, ref latitude))
            {
                return;
            }
            double longitude = 0.0;
            if (!DA.GetData(5, ref longitude))
            {
                return;
            }

            int year = 0;
            if (!DA.GetData(6, ref year))
            {
                return;
            }
            int month = 0;
            if (!DA.GetData(7, ref month))
            {
                return;
            }
            int day = 0;
            if (!DA.GetData(8, ref day))
            {
                return;
            }
            int hour = 0;
            if (!DA.GetData(9, ref hour))
            {
                return;
            }

            double snow_threshold = 1.0;
            if (!DA.GetData(10, ref snow_threshold))
            {
                snow_threshold = 1.0;
            }
            double tilt_threshold = 60.0;
            if (!DA.GetData(11, ref tilt_threshold))
            {
                tilt_threshold = 60.0;
            }


            List <double> DNI = new List <double>();
            if (!DA.GetDataList(13, DNI))
            {
                return;
            }
            List <double> DHI = new List <double>();
            if (!DA.GetDataList(14, DHI))
            {
                return;
            }
            List <double> SNOW = new List <double>();
            if (!DA.GetDataList(15, SNOW))
            {
                for (int t = 0; t < 8760; t++)
                {
                    SNOW.Add(0.0);
                }
            }
            List <double> groundalbedo = new List <double>();
            if (!DA.GetDataList(16, groundalbedo))
            {
                for (int t = 0; t < 8760; t++)
                {
                    groundalbedo.Add(0.2);
                }
            }
            List <double> solarAzimuth = new List <double>();
            DA.GetDataList(17, solarAzimuth);
            List <double> solarAltitude = new List <double>();
            DA.GetDataList(18, solarAltitude);


            int MainSkyRes = 0;
            if (!DA.GetData(20, ref MainSkyRes))
            {
                MainSkyRes = 1;
            }
            int SpecBounces = 1;
            if (!DA.GetData(21, ref SpecBounces))
            {
                SpecBounces = 1;
            }
            SpecBounces = (SpecBounces < 0) ? 0 : SpecBounces;
            int DiffIReflSkyRes = 0;
            if (!DA.GetData(22, ref DiffIReflSkyRes))
            {
                DiffIReflSkyRes = 0;
            }
            int DiffIReflSkyRes2nd = 0;
            if (!DA.GetData(23, ref DiffIReflSkyRes2nd))
            {
                DiffIReflSkyRes2nd = 0;
            }

            CResultsInterreflections ResultsIreflIn = null;
            DA.GetData(25, ref ResultsIreflIn);

            bool mt = false;
            if (!DA.GetData(27, ref mt))
            {
                mt = false;
            }

            int timezone = 0;
            DA.GetData(28, ref timezone);

            /////////////////////////////////////////////////////////////////////
            //___________________________________________________________________
            #endregion



            #region SIMULATE
            //______________________________________________________________________________________________
            ////////////////////////////////        S I M U L A T E      ///////////////////////////////////
            CCalculateSolarMesh calc = new CCalculateSolarMesh(
                mshobj, objObst, treeObst, latitude, longitude, DNI, DHI, SNOW, groundalbedo, snow_threshold,
                tilt_threshold, year, null, mt, solarAzimuth, solarAltitude, timezone);
            calc.RunHourSimulationMT(month, day, hour, MainSkyRes, SpecBounces, DiffIReflSkyRes, DiffIReflSkyRes2nd);
            Line     ln      = calc.getSolarVec();
            CResults results = calc.getResults();
            CResultsInterreflections resultsIreflOut = calc.getResultsInterreflections();
            ////////////////////////////////////////////////////////////////////////////////////////////////
            //______________________________________________________________________________________________
            #endregion



            #region OUTPUT
            //______________________________________________________________________________________________
            ////////////////////////////////          O U T P U T        ///////////////////////////////////
            DA.SetData(0, ln);
            DA.SetData(1, results);
            DA.SetData(2, resultsIreflOut);
            ////////////////////////////////////////////////////////////////////////////////////////////////
            //______________________________________________________________________________________________
            #endregion
        }