Beispiel #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)
        {
            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);
        }
Beispiel #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)
        {
            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]);
        }
        /// <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);
        }