예제 #1
0
        public static Room ToLadybugTools(this Space space, AnalyticalModel analyticalModel = null, double silverSpacing = Core.Tolerance.MacroDistance, double tolerance = Core.Tolerance.Distance)
        {
            if (space == null)
            {
                return(null);
            }

            int          index  = -1;
            List <Panel> panels = null;

            AdjacencyCluster adjacencyCluster = analyticalModel?.AdjacencyCluster;

            if (adjacencyCluster != null)
            {
                index  = adjacencyCluster.GetIndex(space);
                panels = adjacencyCluster.UpdateNormals(space, false, silverSpacing, tolerance);
            }

            if (panels == null || panels.Count == 0)
            {
                return(null);
            }

            string uniqueName = Query.UniqueName(space);

            List <Face> faces = null;

            if (panels != null)
            {
                faces = new List <Face>();
                foreach (Panel panel in panels)
                {
                    if (panel == null)
                    {
                        continue;
                    }

                    bool reverse = true;

                    List <Space> spaces = adjacencyCluster?.GetSpaces(panel);
                    if (spaces != null && spaces.Count > 1)
                    {
                        reverse = adjacencyCluster.GetIndex(spaces[0]) != index;
                    }

                    Face face = panel.ToLadybugTools_Face(analyticalModel, index, reverse);
                    if (face == null)
                    {
                        continue;
                    }

                    faces.Add(face);
                }
            }

            RoomPropertiesAbridged roomPropertiesAbridged = new RoomPropertiesAbridged();

            Room result = new Room(uniqueName, faces, roomPropertiesAbridged, space.Name);

            InternalCondition internalCondition = space.InternalCondition;

            if (internalCondition != null)
            {
                string uniqueName_InternalCondition = Core.LadybugTools.Query.UniqueName(internalCondition);
                if (!string.IsNullOrWhiteSpace(uniqueName_InternalCondition))
                {
                    roomPropertiesAbridged = result.Properties;
                    RoomEnergyPropertiesAbridged roomEnergyPropertiesAbridged = roomPropertiesAbridged.Energy;
                    if (roomEnergyPropertiesAbridged == null)
                    {
                        roomEnergyPropertiesAbridged = new RoomEnergyPropertiesAbridged(programType: uniqueName_InternalCondition);
                    }

                    result.Properties.Energy = roomEnergyPropertiesAbridged;
                }
            }

            return(result);
        }
예제 #2
0
        public static Face ToLadybugTools_Face(this Panel panel, AnalyticalModel analyticalModel = null, int index = -1, bool reverse = true)
        {
            if (panel == null || panel.PanelType == PanelType.Shade)
            {
                return(null);
            }

            Face3D face3D = panel.PlanarBoundary3D.ToLadybugTools();

            if (face3D == null)
            {
                return(null);
            }

            AdjacencyCluster adjacencyCluster = analyticalModel?.AdjacencyCluster;

            Space space_Adjacent = null;
            int   index_Adjacent = -1;

            if (adjacencyCluster != null && index != -1)
            {
                List <Space> spaces = adjacencyCluster.GetSpaces(panel);
                if (spaces != null && spaces.Count != 0)
                {
                    foreach (Space space in spaces)
                    {
                        int index_Temp = adjacencyCluster.GetIndex(space);
                        if (!index_Temp.Equals(index))
                        {
                            space_Adjacent = space;
                            index_Adjacent = index_Temp;
                            break;
                        }
                    }
                }
            }

            string adjacentPanelUniqueName = null;
            string adjacentSpaceUniqueName = null;

            if (space_Adjacent != null && index_Adjacent != -1)
            {
                adjacentPanelUniqueName = Query.UniqueName(panel, index_Adjacent);
                adjacentSpaceUniqueName = Query.UniqueName(space_Adjacent);
            }

            AnyOf <Ground, Outdoors, Adiabatic, Surface> boundaryCondition = panel.ToLadybugTools_BoundaryCondition(adjacentPanelUniqueName, adjacentSpaceUniqueName);

            FaceType faceType;

            PanelType  panelType  = panel.PanelType;
            PanelGroup panelGroup = panelType.PanelGroup();

            if (panelGroup == PanelGroup.Floor && Analytical.Query.PanelType(panel.Normal) == PanelType.Roof)
            {
                faceType = FaceType.RoofCeiling;
            }
            else
            {
                faceType = Query.FaceTypeEnum(panelType);
            }

            FaceEnergyPropertiesAbridged faceEnergyPropertiesAbridged = new FaceEnergyPropertiesAbridged();

            if (faceType != FaceType.AirBoundary)
            {
                faceEnergyPropertiesAbridged.Construction = Query.UniqueName(panel.Construction, reverse);
            }

            Face face = new Face(Query.UniqueName(panel, index), face3D, faceType, boundaryCondition, new FacePropertiesAbridged(faceEnergyPropertiesAbridged), panel.Name);

            List <Aperture> apertures = panel.Apertures;//Analytical.Query.OffsetAperturesOnEdge(panel, 0.1);

            if (apertures != null && apertures.Count > 0)
            {
                MaterialLibrary materialLibrary = analyticalModel?.MaterialLibrary;

                face.Apertures = apertures.ConvertAll(x => x.ToLadybugTools(materialLibrary, index, index_Adjacent, adjacentPanelUniqueName, adjacentSpaceUniqueName)).FindAll(x => x != null);
                face.Doors     = apertures.ConvertAll(x => x.ToLadybugTools_Door(materialLibrary, index, index_Adjacent, adjacentPanelUniqueName, adjacentSpaceUniqueName)).FindAll(x => x != null);
            }

            return(face);
        }
예제 #3
0
        public static Campus TogbXML_Campus(this AnalyticalModel analyticalModel, double silverSpacing = Core.Tolerance.MacroDistance, double tolerance = Core.Tolerance.Distance)
        {
            if (analyticalModel == null)
            {
                return(null);
            }

            Campus campus = new Campus();

            campus.id       = Core.gbXML.Query.Id(analyticalModel, typeof(Campus));
            campus.Location = Core.gbXML.Convert.TogbXML(analyticalModel.Location, analyticalModel.Address, tolerance);

            AdjacencyCluster adjacencyCluster = analyticalModel.AdjacencyCluster;

            if (adjacencyCluster != null)
            {
                adjacencyCluster = adjacencyCluster.SplitByInternalEdges(tolerance);
                adjacencyCluster = adjacencyCluster.UpdateNormals(false, silverSpacing, tolerance);

                campus.Buildings = new Building[] { adjacencyCluster.TogbXML(analyticalModel.Name, analyticalModel.Description, tolerance) };
                List <Panel> panels = adjacencyCluster.GetPanels();
                if (panels != null)
                {
                    int            count_opening = 1;
                    List <Surface> surfaces      = new List <Surface>();
                    for (int i = 0; i < panels.Count; i++)
                    {
                        Panel panel = panels[i];
                        if (panel == null)
                        {
                            continue;
                        }

                        List <Space> spaces = adjacencyCluster.GetRelatedObjects <Space>(panel);
                        if (spaces != null && spaces.Count > 1)
                        {
                            //Spaces have to be in correct order!
                            //https://www.gbxml.org/schema_doc/6.01/GreenBuildingXML_Ver6.01.html#Link7

                            SortedDictionary <int, Space> sortedDictionary = new SortedDictionary <int, Space>();
                            spaces.ForEach(x => sortedDictionary[adjacencyCluster.GetIndex(x)] = x);
                            spaces = sortedDictionary.Values.ToList();
                        }

                        Surface surface = panel.TogbXML(spaces, i + 1, count_opening, tolerance);
                        if (surface != null)
                        {
                            surfaces.Add(surface);
                        }

                        if (surface.Opening != null)
                        {
                            count_opening += surface.Opening.Length;
                        }
                    }
                    campus.Surface = surfaces.ToArray();
                }
            }

            return(campus);
        }