Пример #1
0
        public static List <Autodesk.Revit.DB.Mechanical.Space> ToRevit(this AdjacencyCluster adjacencyCluster, Zone zone, Document document, ConvertSettings convertSettings)
        {
            if (adjacencyCluster == null || zone == null)
            {
                return(null);
            }

            List <Autodesk.Revit.DB.Mechanical.Space> result = convertSettings?.GetObjects <Autodesk.Revit.DB.Mechanical.Space>(zone.Guid);

            if (result != null)
            {
                return(result);
            }

            Zone zone_Temp = adjacencyCluster.GetObject <Zone>(zone.Guid);

            if (zone_Temp == null)
            {
                zone_Temp = zone;
            }

            if (convertSettings.ConvertParameters)
            {
                List <Space> spaces = adjacencyCluster.GetSpaces(zone_Temp);
                if (spaces != null)
                {
                    List <Autodesk.Revit.DB.Mechanical.Space> spaces_Revit = new FilteredElementCollector(document).OfCategory(BuiltInCategory.OST_MEPSpaces).Cast <Autodesk.Revit.DB.Mechanical.Space>().ToList();

                    foreach (Space space in spaces)
                    {
                        Autodesk.Revit.DB.Mechanical.Space space_Revit = Core.Revit.Query.Element <Autodesk.Revit.DB.Mechanical.Space>(document, space);
                        if (space_Revit == null)
                        {
                            string name = space.Name;
                            if (name != null)
                            {
                                space_Revit = spaces_Revit?.Find(x => x.get_Parameter(BuiltInParameter.ROOM_NAME)?.AsString() == name);
                            }
                        }

                        if (space_Revit == null)
                        {
                            continue;
                        }

                        Core.Revit.Modify.SetValues(space_Revit, zone_Temp);
                        Core.Revit.Modify.SetValues(space_Revit, zone_Temp, ActiveSetting.Setting);
                    }
                }
            }

            convertSettings?.Add(zone.Guid, result);

            return(result);
        }
Пример #2
0
        /// <summary>
        /// This is the method that actually does the work.
        /// </summary>
        /// <param name="dataAccess">
        /// The DA object is used to retrieve from inputs and store in outputs.
        /// </param>
        protected override void SolveInstance(IGH_DataAccess dataAccess)
        {
            AdjacencyCluster adjacencyCluster = null;

            if (!dataAccess.GetData(0, ref adjacencyCluster))
            {
                AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Invalid data");
                return;
            }

            SAMObject sAMObject = null;

            if (!dataAccess.GetData(1, ref sAMObject))
            {
                AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Invalid data");
                return;
            }

            IEnumerable <SAMObject> result = null;

            if (sAMObject is Space)
            {
                result = adjacencyCluster.GetPanels((Space)sAMObject);
            }
            else if (sAMObject is Panel)
            {
                result = adjacencyCluster.GetSpaces((Panel)sAMObject);
            }

            if (result == null)
            {
                dataAccess.SetDataList(0, null);
                return;
            }

            if (result.Count() == 0)
            {
                dataAccess.SetDataList(0, result);
                return;
            }

            dataAccess.SetDataList(0, result.ToList().ConvertAll(x => new GooJSAMObject <SAMObject>(x)));
        }
Пример #3
0
        public static Log Log(this AdjacencyCluster adjacencyCluster, Document document)
        {
            if (adjacencyCluster == null || document == null)
            {
                return(null);
            }

            Log result = new Log();

            foreach (Construction construction in adjacencyCluster.GetConstructions())
            {
                result.AddRange(Log(construction, document));
            }

            foreach (ApertureConstruction apertureConstruction in adjacencyCluster.ApertureConstructions())
            {
                result.AddRange(Log(apertureConstruction, document));
            }

            List <Panel> panels = adjacencyCluster.GetPanels();

            panels?.ForEach(x => Core.Modify.AddRange(result, Core.Revit.Create.Log(x, document)));

            List <Architectural.Level> levels = Architectural.Create.Levels(panels);

            if (levels == null || levels.Count == 0)
            {
                result.Add("Could not find proper levels in AdjacencyCluster", LogRecordType.Error);
            }
            else
            {
                result.AddRange(Architectural.Revit.Create.Log(levels, document));
            }

            foreach (Space space in adjacencyCluster.GetSpaces())
            {
                Core.Modify.AddRange(result, Log(space, document));
            }

            return(result);
        }
Пример #4
0
        public static Dictionary <string, Space> SpaceDictionary(this AdjacencyCluster adjacencyCluster)
        {
            List <Space> spaces = adjacencyCluster?.GetSpaces();

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

            Dictionary <string, Space> result = new Dictionary <string, Space>();

            foreach (Space space in spaces)
            {
                string name = space?.Name;
                if (name == null)
                {
                    continue;
                }

                result[name] = space;
            }

            return(result);
        }
Пример #5
0
        /// <summary>
        /// This is the method that actually does the work.
        /// </summary>
        /// <param name="dataAccess">The DA object is used to retrieve from inputs and store in outputs.</param>
        protected override void SolveInstance(IGH_DataAccess dataAccess)
        {
            dataAccess.SetData(4, false);

            bool run = false;

            if (!dataAccess.GetData(2, ref run))
            {
                AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Invalid data");
                return;
            }
            if (!run)
            {
                return;
            }

            string path_TBD = null;

            if (!dataAccess.GetData(0, ref path_TBD) || string.IsNullOrWhiteSpace(path_TBD))
            {
                AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Invalid data");
                return;
            }

            IAnalyticalObject analyticalObject = null;

            if (!dataAccess.GetData(1, ref analyticalObject) || analyticalObject == null)
            {
                AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Invalid data");
                return;
            }

            List <SpaceSimulationResult> spaceSimulationResults_Cooling = null;
            List <SpaceSimulationResult> spaceSimulationResults_Heating = null;
            List <Space> spaces = null;
            bool         result = false;

            if (analyticalObject is AnalyticalModel)
            {
                analyticalObject = Analytical.Tas.Modify.UpdateDesignLoads(path_TBD, (AnalyticalModel)analyticalObject);
                AdjacencyCluster adjacencyCluster = ((AnalyticalModel)analyticalObject).AdjacencyCluster;
                if (adjacencyCluster != null)
                {
                    spaces = adjacencyCluster.GetSpaces();
                    if (spaces != null)
                    {
                        spaceSimulationResults_Cooling = new List <SpaceSimulationResult>();
                        spaceSimulationResults_Heating = new List <SpaceSimulationResult>();

                        foreach (Space space in spaces)
                        {
                            List <SpaceSimulationResult> spaceSimulationResults = adjacencyCluster.GetResults <SpaceSimulationResult>(space, Analytical.Tas.Query.Source());
                            if (spaceSimulationResults == null)
                            {
                                continue;
                            }

                            spaceSimulationResults_Cooling.AddRange(spaceSimulationResults.FindAll(x => x.LoadType() == LoadType.Cooling));
                            spaceSimulationResults_Cooling.AddRange(spaceSimulationResults.FindAll(x => x.LoadType() == LoadType.Heating));
                        }
                        result = true;
                    }
                }
            }
            else if (analyticalObject is BuildingModel)
            {
                BuildingModel buildingModel = new BuildingModel((BuildingModel)analyticalObject);
                spaces = Analytical.Tas.Modify.UpdateDesignLoads(buildingModel, path_TBD);
                if (spaces != null)
                {
                    spaceSimulationResults_Cooling = new List <SpaceSimulationResult>();
                    spaceSimulationResults_Heating = new List <SpaceSimulationResult>();

                    foreach (Space space in spaces)
                    {
                        List <SpaceSimulationResult> spaceSimulationResults = buildingModel.GetResults <SpaceSimulationResult>(space, Analytical.Tas.Query.Source());
                        if (spaceSimulationResults == null)
                        {
                            continue;
                        }

                        spaceSimulationResults_Cooling.AddRange(spaceSimulationResults.FindAll(x => x.LoadType() == LoadType.Cooling));
                        spaceSimulationResults_Cooling.AddRange(spaceSimulationResults.FindAll(x => x.LoadType() == LoadType.Heating));
                    }

                    result = true;
                }

                analyticalObject = buildingModel;
            }

            dataAccess.SetData(0, new GooAnalyticalObject(analyticalObject));
            dataAccess.SetDataList(1, spaces?.ConvertAll(x => new GooSpace(x)));
            dataAccess.SetDataList(2, spaceSimulationResults_Cooling?.ConvertAll(x => new GooResult(x)));
            dataAccess.SetDataList(3, spaceSimulationResults_Heating?.ConvertAll(x => new GooResult(x)));
            dataAccess.SetData(4, result);
        }
Пример #6
0
        /// <summary>
        /// Updates TBD.zones in given TBD.Buiding based on provided spaces and profileLibrary
        /// </summary>
        /// <param name="building">TBD.Buidling</param>
        /// <param name="spaces">SAM Analytical Spaces</param>
        /// <param name="profileLibrary">ProfileLibrary which contains information about profiles used in spaces</param>
        /// <param name="includeHDD">Include Heating Design Day in the process</param>
        /// <returns>TBD.zones have been used in update process</returns>
        public static bool UpdateZones(this TBD.Building building, AdjacencyCluster adjacencyCluster, ProfileLibrary profileLibrary, bool includeHDD = false)
        {
            if (building == null || adjacencyCluster == null || profileLibrary == null)
            {
                return(false);
            }

            List <Space> spaces = adjacencyCluster?.GetSpaces();

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

            //Zone Dictionary <- Dictionary constains zone.name as a key and TBD.zone as Value. Dictionary helps to match TBD.zone with SAM.Analytical.Space
            Dictionary <string, TBD.zone> dictionary_Zones = building.ZoneDictionary();

            if (dictionary_Zones == null)
            {
                return(false);
            }

            //Space Dictionary <- Dictionary constains Space.Name as a key and SAM.Analytical.Space as Value. Assumption: InternalCondition Name equals to Space Name. It also holds names for HDD Spaces/InternalConditions
            Dictionary <string, Space> dictionary_Spaces = new Dictionary <string, Space>();

            foreach (Space space in spaces)
            {
                string name = space.Name;
                if (name == null)
                {
                    continue;
                }

                dictionary_Spaces[name] = space;
                if (includeHDD)
                {
                    dictionary_Spaces[space.Name + " - HDD"] = space;
                }
            }

            //Removes Internal Conditions with given names. Names are taken from Space Name (assumption Space Name equals InternalCondtion Name)
            RemoveInternalConditions(building, dictionary_Spaces.Keys);

            List <TBD.zone> result = new List <TBD.zone>();

            foreach (Space space in spaces)
            {
                string name = space?.Name;
                if (name == null)
                {
                    continue;
                }

                //Matching Space with TBD.zone via name
                TBD.zone zone = null;
                if (!dictionary_Zones.TryGetValue(name, out zone) || zone == null)
                {
                    continue;
                }

                zone = building.UpdateZone(zone, space, profileLibrary);

                VentilationSystem ventilationSystem = adjacencyCluster.GetRelatedObjects <VentilationSystem>(space)?.FirstOrDefault();
                if (ventilationSystem != null)
                {
                    string ventilationSystemTypeName = (ventilationSystem.Type as VentilationSystemType)?.Name;
                    if (!string.IsNullOrWhiteSpace(ventilationSystemTypeName))
                    {
                        TBD.ZoneGroup zoneGroup = Query.ZoneGroups(building)?.Find(x => ventilationSystemTypeName.Equals(x.name));
                        if (zoneGroup == null)
                        {
                            zoneGroup      = building.AddZoneGroup();
                            zoneGroup.name = ventilationSystemTypeName;
                            zoneGroup.type = (int)TBD.ZoneGroupType.tbdHVACZG;
                        }

                        if (zoneGroup != null)
                        {
                            zoneGroup.InsertZone(zone);
                        }
                    }
                }

                //Update TBD.zone using data stored in space and ProfileLibrary
                result.Add(zone);

                //Include HDD if includeHDD input set to true
                if (includeHDD)
                {
                    building.UpdateZone_HDD(zone, space, profileLibrary);
                }
            }

            //Updating Builidng Information
            building.description = string.Format("Delivered by SAM https://github.com/HoareLea/SAM [{0}]", System.DateTime.Now.ToString("yyyy/MM/dd"));

            TBD.GeneralDetails generaldetails = building.GetGeneralDetails();
            if (generaldetails != null)
            {
                if (generaldetails.engineer1 == "")
                {
                    generaldetails.engineer1 = System.Environment.UserName;
                }
                else if (generaldetails.engineer1 != System.Environment.UserName)
                {
                    generaldetails.engineer2 = System.Environment.UserName;
                }

                if (generaldetails.externalPollutant == 315) //600
                {
                    generaldetails.externalPollutant = 415;
                }
                generaldetails.TerrainType = TBD.TerrainType.tbdCity;
            }

            //Returning TBD.zones have been used in update process
            return(result != null && result.Count > 0);
        }
Пример #7
0
        public static string ToGEM(this AdjacencyCluster adjacencyCluster, double silverSpacing = Core.Tolerance.MacroDistance, double tolerance = Core.Tolerance.Distance)
        {
            AdjacencyCluster adjacencyCluster_Temp = adjacencyCluster?.SplitByInternalEdges(tolerance);

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

            string result = null;

            List <Space> spaces = adjacencyCluster_Temp.GetSpaces();

            if (spaces != null && spaces.Count != 0)
            {
                foreach (Space space in spaces)
                {
                    List <Panel> panels = adjacencyCluster_Temp.UpdateNormals(space, false, silverSpacing, tolerance);
                    if (panels == null || panels.Count == 0)
                    {
                        continue;
                    }

                    string name = space.Name;
                    if (string.IsNullOrWhiteSpace(name))
                    {
                        name = space.Guid.ToString();
                    }

                    string result_space = ToGEM(panels, name, GEMType.Space, tolerance);
                    if (result_space == null)
                    {
                        continue;
                    }

                    if (result == null)
                    {
                        result = result_space;
                    }
                    else
                    {
                        result += result_space;
                    }
                }
            }

            List <Panel> panels_Shading = adjacencyCluster_Temp.GetShadingPanels();

            if (panels_Shading != null)
            {
                for (int i = 0; i < panels_Shading.Count; i++)
                {
                    string result_shade = ToGEM(new Panel[] { panels_Shading[i] }, string.Format("SHADE {0}", i + 1), GEMType.Shade, tolerance);
                    if (result_shade == null)
                    {
                        continue;
                    }

                    if (result == null)
                    {
                        result = result_shade;
                    }
                    else
                    {
                        result += result_shade;
                    }
                }
            }

            return(result);
        }
Пример #8
0
        public static List <Autodesk.Revit.DB.Mechanical.Space> ToRevit(this AdjacencyCluster adjacencyCluster, ZoneSimulationResult zoneSimulationResult, Document document, ConvertSettings convertSettings)
        {
            if (adjacencyCluster == null || zoneSimulationResult == null)
            {
                return(null);
            }

            List <Autodesk.Revit.DB.Mechanical.Space> result = convertSettings?.GetObjects <Autodesk.Revit.DB.Mechanical.Space>(zoneSimulationResult.Guid);

            if (result != null)
            {
                return(result);
            }

            ZoneSimulationResult zoneSimulationResult_Temp = adjacencyCluster.GetObject <ZoneSimulationResult>(zoneSimulationResult.Guid);

            if (zoneSimulationResult_Temp == null)
            {
                zoneSimulationResult_Temp = zoneSimulationResult;
            }

            List <Zone> zones = adjacencyCluster.GetRelatedObjects <Zone>(zoneSimulationResult_Temp);

            if (zones != null && zones.Count != 0)
            {
                if (convertSettings.ConvertParameters)
                {
                    foreach (Zone zone in zones)
                    {
                        List <Space> spaces = adjacencyCluster.GetSpaces(zone);
                        if (spaces != null)
                        {
                            ZoneType zoneType = zone.ZoneType();
                            if (zoneType == ZoneType.Undefined)
                            {
                                continue;
                            }

                            List <Autodesk.Revit.DB.Mechanical.Space> spaces_Revit = new FilteredElementCollector(document).OfCategory(BuiltInCategory.OST_MEPSpaces).Cast <Autodesk.Revit.DB.Mechanical.Space>().ToList();

                            foreach (Space space_SAM in spaces)
                            {
                                Autodesk.Revit.DB.Mechanical.Space space_Revit = Core.Revit.Query.Element <Autodesk.Revit.DB.Mechanical.Space>(document, zoneSimulationResult_Temp);

                                if (space_Revit == null)
                                {
                                    space_Revit = Core.Revit.Query.Element <Autodesk.Revit.DB.Mechanical.Space>(document, space_SAM);
                                }

                                if (space_Revit == null)
                                {
                                    space_Revit = spaces_Revit?.Find(x => x.get_Parameter(BuiltInParameter.ROOM_NAME)?.AsString() == space_SAM.Name);
                                }

                                if (space_Revit == null)
                                {
                                    space_Revit = spaces_Revit?.Find(x => space_SAM.Name.EndsWith(x.get_Parameter(BuiltInParameter.ROOM_NAME)?.AsString()) && space_SAM.Name.StartsWith(x.get_Parameter(BuiltInParameter.ROOM_NUMBER)?.AsString()));
                                }

                                if (space_Revit == null)
                                {
                                    continue;
                                }

                                Core.Revit.Modify.SetValues(space_Revit, zoneSimulationResult);
                                Core.Revit.Modify.SetValues(space_Revit, zoneSimulationResult, ActiveSetting.Setting);

                                Modify.SetValues(space_Revit, zoneSimulationResult, ActiveSetting.Setting, zoneType, convertSettings?.GetParameters());
                            }
                        }
                    }
                }
            }

            convertSettings?.Add(zoneSimulationResult.Guid, result);

            return(result);
        }
Пример #9
0
        public static TBD.Building ToTBD(this AnalyticalModel analyticalModel, TBD.TBDDocument tBDDocument)
        {
            if (analyticalModel == null)
            {
                return(null);
            }

            TBD.Building result = tBDDocument.Building;
            if (result == null)
            {
                return(null);
            }

            AdjacencyCluster adjacencyCluster = analyticalModel.AdjacencyCluster;

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

            List <Space> spaces = adjacencyCluster.GetSpaces();

            if (spaces == null)
            {
                return(result);
            }

            MaterialLibrary materialLibrary = analyticalModel.MaterialLibrary;

            Plane plane = Plane.WorldXY;

            List <TBD.DaysShade> daysShades = new List <TBD.DaysShade>();

            result.ClearShadingData();

            Dictionary <System.Guid, List <TBD.zoneSurface> > dictionary_Panel    = new Dictionary <System.Guid, List <TBD.zoneSurface> >();
            Dictionary <System.Guid, List <TBD.zoneSurface> > dictionary_Aperture = new Dictionary <System.Guid, List <TBD.zoneSurface> >();

            foreach (Space space in spaces)
            {
                Shell shell = adjacencyCluster.Shell(space);
                if (shell == null)
                {
                    return(null);
                }

                TBD.zone zone = result.AddZone();
                zone.name   = space.Name;
                zone.volume = System.Convert.ToSingle(shell.Volume());

                if (space.TryGetValue(SpaceParameter.Color, out SAMColor sAMColor) && sAMColor != null)
                {
                    zone.colour = Core.Convert.ToUint(sAMColor.ToColor());
                }

                List <Face3D> face3Ds = Geometry.Spatial.Query.Section(shell, 0.01, false);
                if (face3Ds != null && face3Ds.Count != 0)
                {
                    face3Ds.RemoveAll(x => x == null || !x.IsValid());
                    zone.floorArea        = System.Convert.ToSingle(face3Ds.ConvertAll(x => x.GetArea()).Sum());
                    zone.exposedPerimeter = System.Convert.ToSingle(face3Ds.ConvertAll(x => Geometry.Planar.Query.Perimeter(x.ExternalEdge2D)).Sum());
                    zone.length           = System.Convert.ToSingle(face3Ds.ConvertAll(x => Geometry.Tas.Query.Length(x)).Sum());
                }

                TBD.room room = zone.AddRoom();

                List <TBD.buildingElement> buildingElements = result.BuildingElements();
                List <TBD.Construction>    constructions    = result.Constructions();

                List <Panel> panels = adjacencyCluster?.GetPanels(space);
                if (panels != null || panels.Count != 0)
                {
                    foreach (Panel panel in panels)
                    {
                        string name_Panel = panel.Name;
                        if (string.IsNullOrWhiteSpace(name_Panel))
                        {
                            continue;
                        }

                        Face3D face3D_Panel = panel.Face3D;
                        if (face3D_Panel == null)
                        {
                            continue;
                        }

                        BoundingBox3D boundingBox3D_Panel = face3D_Panel.GetBoundingBox();

                        TBD.zoneSurface zoneSurface_Panel = zone.AddSurface();
                        zoneSurface_Panel.orientation = System.Convert.ToSingle(Geometry.Spatial.Query.Azimuth(panel, Vector3D.WorldY));
                        zoneSurface_Panel.inclination = System.Convert.ToSingle(Geometry.Spatial.Query.Tilt(panel));

                        zoneSurface_Panel.altitude              = System.Convert.ToSingle(boundingBox3D_Panel.GetCentroid().Z);
                        zoneSurface_Panel.altitudeRange         = System.Convert.ToSingle(boundingBox3D_Panel.Max.Z - boundingBox3D_Panel.Min.Z);
                        zoneSurface_Panel.area                  = System.Convert.ToSingle(face3D_Panel.GetArea());
                        zoneSurface_Panel.planHydraulicDiameter = System.Convert.ToSingle(Geometry.Tas.Query.HydraulicDiameter(face3D_Panel));

                        TBD.RoomSurface roomSurface_Panel = room.AddSurface();
                        roomSurface_Panel.area        = zoneSurface_Panel.area;
                        roomSurface_Panel.zoneSurface = zoneSurface_Panel;

                        Geometry.SolarCalculator.SolarFaceSimulationResult solarFaceSimulationResult = analyticalModel.GetResults <Geometry.SolarCalculator.SolarFaceSimulationResult>(panel)?.FirstOrDefault();
                        if (solarFaceSimulationResult != null)
                        {
                            List <TBD.SurfaceShade> surfaceShades = Modify.UpdateSurfaceShades(result, daysShades, zoneSurface_Panel, analyticalModel, solarFaceSimulationResult);
                        }

                        TBD.Perimeter perimeter_Panel = Geometry.Tas.Convert.ToTBD(panel.GetFace3D(true), roomSurface_Panel);
                        if (perimeter_Panel == null)
                        {
                            continue;
                        }

                        PanelType panelType = panel.PanelType;

                        TBD.buildingElement buildingElement_Panel = buildingElements.Find(x => x.name == name_Panel);
                        if (buildingElement_Panel == null)
                        {
                            TBD.Construction construction_TBD = null;

                            Construction construction = panel.Construction;
                            if (construction != null)
                            {
                                construction_TBD = constructions.Find(x => x.name == construction.Name);
                                if (construction_TBD == null)
                                {
                                    construction_TBD      = result.AddConstruction(null);
                                    construction_TBD.name = construction.Name;

                                    if (construction.Transparent(materialLibrary))
                                    {
                                        construction_TBD.type = TBD.ConstructionTypes.tcdTransparentConstruction;
                                    }

                                    List <ConstructionLayer> constructionLayers = construction.ConstructionLayers;
                                    if (constructionLayers != null && constructionLayers.Count != 0)
                                    {
                                        int index = 1;
                                        foreach (ConstructionLayer constructionLayer in constructionLayers)
                                        {
                                            Material material = analyticalModel?.MaterialLibrary?.GetMaterial(constructionLayer.Name) as Core.Material;
                                            if (material == null)
                                            {
                                                continue;
                                            }

                                            TBD.material material_TBD = construction_TBD.AddMaterial(material);
                                            if (material_TBD != null)
                                            {
                                                material_TBD.width = System.Convert.ToSingle(constructionLayer.Thickness);
                                                construction_TBD.materialWidth[index] = System.Convert.ToSingle(constructionLayer.Thickness);
                                                index++;
                                            }
                                        }
                                    }

                                    constructions.Add(construction_TBD);
                                }

                                if (panelType == PanelType.Undefined && construction != null)
                                {
                                    panelType = construction.PanelType();
                                    if (panelType == PanelType.Undefined && construction.TryGetValue(ConstructionParameter.DefaultPanelType, out string panelTypeString))
                                    {
                                        panelType = Core.Query.Enum <PanelType>(panelTypeString);
                                    }
                                }
                            }

                            buildingElement_Panel        = result.AddBuildingElement();
                            buildingElement_Panel.name   = name_Panel;
                            buildingElement_Panel.colour = Core.Convert.ToUint(Analytical.Query.Color(panelType));
                            buildingElement_Panel.BEType = Query.BEType(panelType.Text());
                            buildingElement_Panel.AssignConstruction(construction_TBD);
                            buildingElements.Add(buildingElement_Panel);
                        }

                        if (buildingElement_Panel != null)
                        {
                            zoneSurface_Panel.buildingElement = buildingElement_Panel;
                        }

                        zoneSurface_Panel.type = TBD.SurfaceType.tbdExposed;

                        List <Aperture> apertures = panel.Apertures;
                        if (apertures != null && apertures.Count != 0)
                        {
                            bool @internal = adjacencyCluster.Internal(panel);

                            foreach (Aperture aperture in apertures)
                            {
                                string name_Aperture = aperture.Name;
                                if (string.IsNullOrWhiteSpace(name_Aperture))
                                {
                                    continue;
                                }

                                name_Aperture = string.Format("{0} -pane", aperture.Name);

                                Face3D face3D_Aperture = aperture.Face3D;
                                if (face3D_Aperture == null)
                                {
                                    continue;
                                }

                                BoundingBox3D boundingBox3D_Aperture = face3D_Aperture.GetBoundingBox();

                                float area = System.Convert.ToSingle(face3D_Aperture.GetArea());

                                TBD.zoneSurface zoneSurface_Aperture = zoneSurface_Panel.AddChildSurface(area);
                                if (zoneSurface_Aperture == null)
                                {
                                    continue;
                                }

                                zoneSurface_Aperture.orientation           = zoneSurface_Panel.orientation;
                                zoneSurface_Aperture.inclination           = zoneSurface_Panel.inclination;
                                zoneSurface_Aperture.altitude              = System.Convert.ToSingle(boundingBox3D_Aperture.GetCentroid().Z);
                                zoneSurface_Aperture.altitudeRange         = System.Convert.ToSingle(boundingBox3D_Aperture.Max.Z - boundingBox3D_Aperture.Min.Z);
                                zoneSurface_Aperture.planHydraulicDiameter = System.Convert.ToSingle(Geometry.Tas.Query.HydraulicDiameter(face3D_Aperture));
                                //zoneSurface_Aperture.area = System.Convert.ToSingle(face3D_Aperture.GetArea());

                                zoneSurface_Aperture.type = @internal ? TBD.SurfaceType.tbdLink : zoneSurface_Panel.type;

                                TBD.RoomSurface roomSurface_Aperture = room.AddSurface();
                                roomSurface_Aperture.area        = zoneSurface_Aperture.area;
                                roomSurface_Aperture.zoneSurface = zoneSurface_Aperture;

                                TBD.Perimeter perimeter_Aperture = Geometry.Tas.Convert.ToTBD(face3D_Aperture, roomSurface_Aperture);
                                if (perimeter_Aperture == null)
                                {
                                    continue;
                                }

                                TBD.buildingElement buildingElement_Aperture = buildingElements.Find(x => x.name == name_Aperture);
                                if (buildingElement_Aperture == null)
                                {
                                    TBD.Construction construction_TBD = null;

                                    ApertureConstruction apertureConstruction = aperture.ApertureConstruction;
                                    if (apertureConstruction != null)
                                    {
                                        construction_TBD = constructions.Find(x => x.name == apertureConstruction.Name);
                                        if (construction_TBD == null)
                                        {
                                            construction_TBD      = result.AddConstruction(null);
                                            construction_TBD.name = name_Aperture;

                                            if (apertureConstruction.Transparent(materialLibrary))
                                            {
                                                construction_TBD.type = TBD.ConstructionTypes.tcdTransparentConstruction;
                                            }

                                            List <ConstructionLayer> constructionLayers = apertureConstruction.PaneConstructionLayers;
                                            if (constructionLayers != null && constructionLayers.Count != 0)
                                            {
                                                int index = 1;
                                                foreach (ConstructionLayer constructionLayer in constructionLayers)
                                                {
                                                    Core.Material material = materialLibrary?.GetMaterial(constructionLayer.Name) as Material;
                                                    if (material == null)
                                                    {
                                                        continue;
                                                    }

                                                    TBD.material material_TBD = construction_TBD.AddMaterial(material);
                                                    if (material_TBD != null)
                                                    {
                                                        material_TBD.width = System.Convert.ToSingle(constructionLayer.Thickness);
                                                        construction_TBD.materialWidth[index] = System.Convert.ToSingle(constructionLayer.Thickness);
                                                        index++;
                                                    }
                                                }
                                            }

                                            constructions.Add(construction_TBD);
                                        }
                                    }

                                    ApertureType apertureType = aperture.ApertureType;

                                    buildingElement_Aperture        = result.AddBuildingElement();
                                    buildingElement_Aperture.name   = name_Aperture;
                                    buildingElement_Aperture.colour = Core.Convert.ToUint(Analytical.Query.Color(apertureType));
                                    buildingElement_Aperture.BEType = Query.BEType(apertureType, false);
                                    buildingElement_Aperture.AssignConstruction(construction_TBD);
                                    buildingElements.Add(buildingElement_Aperture);
                                }

                                if (buildingElement_Aperture != null)
                                {
                                    zoneSurface_Aperture.buildingElement = buildingElement_Aperture;
                                }

                                if (!dictionary_Aperture.TryGetValue(aperture.Guid, out List <TBD.zoneSurface> zoneSurfaces_Aperture) || zoneSurfaces_Aperture == null)
                                {
                                    zoneSurfaces_Aperture = new List <TBD.zoneSurface>();
                                    dictionary_Aperture[aperture.Guid] = zoneSurfaces_Aperture;
                                }

                                zoneSurfaces_Aperture.Add(zoneSurface_Aperture);
                            }
                        }

                        zoneSurface_Panel.type = Query.SurfaceType(panelType);

                        if (!dictionary_Panel.TryGetValue(panel.Guid, out List <TBD.zoneSurface> zoneSurfaces_Panel) || zoneSurfaces_Panel == null)
                        {
                            zoneSurfaces_Panel           = new List <TBD.zoneSurface>();
                            dictionary_Panel[panel.Guid] = zoneSurfaces_Panel;
                        }

                        zoneSurfaces_Panel.Add(zoneSurface_Panel);
                    }
                }
            }

            foreach (KeyValuePair <System.Guid, List <TBD.zoneSurface> > keyValuePair in dictionary_Panel)
            {
                if (keyValuePair.Value == null || keyValuePair.Value.Count <= 1)
                {
                    continue;
                }

                keyValuePair.Value[1].linkSurface = keyValuePair.Value[0];
                keyValuePair.Value[0].linkSurface = keyValuePair.Value[1];

                if (keyValuePair.Value[0].inclination == 0 || keyValuePair.Value[0].inclination == 180)
                {
                    float inclination = keyValuePair.Value[1].inclination;
                    inclination -= 180;
                    if (inclination < 0)
                    {
                        inclination += 360;
                    }

                    keyValuePair.Value[1].inclination = inclination;
                    keyValuePair.Value[1].reversed    = 1;
                }
                else
                {
                    float orientation = keyValuePair.Value[1].orientation;
                    orientation += 180;
                    if (orientation >= 360)
                    {
                        orientation -= 360;
                    }

                    keyValuePair.Value[1].orientation = orientation;
                    keyValuePair.Value[1].reversed    = 1;

                    float inclination = keyValuePair.Value[1].inclination;
                    if (inclination > 180)
                    {
                        inclination -= 180;
                    }
                    keyValuePair.Value[1].inclination = inclination;
                }
            }

            foreach (KeyValuePair <System.Guid, List <TBD.zoneSurface> > keyValuePair in dictionary_Aperture)
            {
                if (keyValuePair.Value == null || keyValuePair.Value.Count <= 1)
                {
                    continue;
                }

                keyValuePair.Value[1].linkSurface = keyValuePair.Value[0];
                keyValuePair.Value[0].linkSurface = keyValuePair.Value[1];

                if (keyValuePair.Value[0].inclination == 0 || keyValuePair.Value[0].inclination == 180)
                {
                    float inclination = keyValuePair.Value[0].inclination;
                    inclination -= 180;
                    if (inclination < 0)
                    {
                        inclination += 360;
                    }

                    keyValuePair.Value[0].inclination = inclination;
                    keyValuePair.Value[0].reversed    = 1;
                }
                else
                {
                    float orientation = keyValuePair.Value[1].orientation;
                    orientation += 180;
                    if (orientation >= 360)
                    {
                        orientation -= 360;
                    }

                    keyValuePair.Value[1].orientation = orientation;
                    keyValuePair.Value[1].reversed    = 1;
                }
            }

            return(result);
        }
Пример #10
0
        /// <summary>
        /// This is the method that actually does the work.
        /// </summary>
        /// <param name="dataAccess">
        /// The DA object is used to retrieve from inputs and store in outputs.
        /// </param>
        protected override void SolveInstance(IGH_DataAccess dataAccess)
        {
            bool run = false;

            if (!dataAccess.GetData(6, ref run))
            {
                AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Invalid data");
                dataAccess.SetData(2, false);
                return;
            }
            if (!run)
            {
                return;
            }

            List <Panel> panels = new List <Panel>();

            if (!dataAccess.GetDataList(0, panels) || panels == null)
            {
                AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Invalid data");
                dataAccess.SetData(2, false);
                return;
            }

            List <Space> spaces = new List <Space>();

            dataAccess.GetDataList(1, spaces);

            double tolerance = double.NaN;

            if (!dataAccess.GetData(2, ref tolerance) || double.IsNaN(tolerance))
            {
                AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Invalid data");
                dataAccess.SetData(2, false);
                return;
            }

            bool tryCellComplexByCells = false;

            if (!dataAccess.GetData(3, ref tryCellComplexByCells))
            {
                AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Invalid data");
                dataAccess.SetData(2, false);
                return;
            }

            //string reportPath = null;
            //if (dataAccess.GetData(4, ref reportPath))
            //{
            //    if (System.IO.File.Exists(reportPath))
            //        System.IO.File.Delete(reportPath);
            //}

            double minArea = Tolerance.MacroDistance;

            dataAccess.GetData(4, ref minArea);

            double silverSpacing = Tolerance.MacroDistance;

            dataAccess.GetData(5, ref silverSpacing);

            List <Topology> topologies = null;
            Log             log        = new Log();

            List <Panel>     panels_Redundant = null;
            AdjacencyCluster adjacencyCluster = Analytical.Topologic.Create.AdjacencyCluster(spaces, panels, out topologies, out panels_Redundant, minArea, true, tryCellComplexByCells, log, silverSpacing, tolerance);

            if (adjacencyCluster != null)
            {
                List <Space> spaces_Temp = adjacencyCluster.GetSpaces();
                if (spaces_Temp == null || spaces_Temp.Count == 0)
                {
                    AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "No spaces have been detected");
                }
                else
                {
                    List <Point3D> locations = spaces_Temp.ConvertAll(x => x.Location);

                    if (locations.RemoveAll(x => x == null) > 0)
                    {
                        AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "There are spaces without Location Points");
                    }

                    List <Space> spaces_Unbounded = new List <Space>();
                    List <Space> spaces_Multiple  = new List <Space>();

                    HashSet <int>        indexes_Multiple     = new HashSet <int>();
                    List <List <Space> > spacesList_Locations = adjacencyCluster.GetSpaces(locations);
                    for (int i = 0; i < spacesList_Locations.Count; i++)
                    {
                        List <Space> spaces_Locations = spacesList_Locations[i];
                        Point3D      point3D_Location = locations[i];

                        if (spaces_Locations == null)
                        {
                            spaces_Unbounded.Add(spaces_Temp.Find(x => point3D_Location.AlmostEquals(x.Location)));
                            continue;
                        }

                        if (spacesList_Locations.Count > 2)
                        {
                            indexes_Multiple.Add(i);
                        }
                    }

                    foreach (Space space in spaces_Unbounded)
                    {
                        string text = "There are unbounded spaces in topology model";
                        if (!string.IsNullOrWhiteSpace(space.Name))
                        {
                            text += " " + space.Name;
                        }

                        text += " " + "Guid: " + space.Guid;

                        AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, text);
                    }

                    foreach (Space space in spaces_Multiple)
                    {
                        string text = "There are multiple spaces in topology cell";
                        if (!string.IsNullOrWhiteSpace(space.Name))
                        {
                            text += " " + space.Name;
                        }

                        text += " " + "Guid: " + space.Guid;

                        AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, text);
                    }
                }

                dataAccess.SetData(0, new GooAdjacencyCluster(adjacencyCluster));
            }
            else
            {
                dataAccess.SetData(0, null);
            }

            dataAccess.SetDataList(1, topologies);
            dataAccess.SetDataList(2, adjacencyCluster?.GetPanels());
            dataAccess.SetDataList(3, adjacencyCluster?.GetSpaces());
            dataAccess.SetDataList(4, adjacencyCluster?.GetInternalPanels());
            dataAccess.SetDataList(5, adjacencyCluster?.GetExternalPanels());
            dataAccess.SetDataList(6, adjacencyCluster?.GetShadingPanels());
            dataAccess.SetDataList(7, panels_Redundant);
            dataAccess.SetData(8, new GooLog(log));
            dataAccess.SetData(9, adjacencyCluster != null);
        }
Пример #11
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);
        }
Пример #12
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);
        }
Пример #13
0
        public static Building TogbXML(this AdjacencyCluster adjacencyCluster, string name, string description, double tolerance = Tolerance.MicroDistance)
        {
            List <Panel> panels = adjacencyCluster?.GetPanels();

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

            List <Space> spaces = adjacencyCluster.GetSpaces();

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

            //Dictionary of Minimal Elevations and List of Panels
            Dictionary <double, List <Panel> > dictionary_MinElevations = Analytical.Query.MinElevationDictionary(panels, true, Tolerance.MacroDistance);

            //Dictionary of gbXML BuildingStoreys and its elevations
            Dictionary <BuildingStorey, double> dictionary_buildingStoreys = new Dictionary <BuildingStorey, double>();

            //Dictionary of SAM Panels related buildingSorey, minimal elevation and maximal elevation
            Dictionary <Panel, Tuple <BuildingStorey, double, double, double> > dictionary_Panels = new Dictionary <Panel, Tuple <BuildingStorey, double, double, double> >();

            foreach (KeyValuePair <double, List <Panel> > keyValuePair in dictionary_MinElevations)
            {
                BuildingStorey buildingStorey = Architectural.Create.Level(keyValuePair.Key).TogbXML(tolerance);
                dictionary_buildingStoreys[buildingStorey] = keyValuePair.Key;
                foreach (Panel panel in keyValuePair.Value)
                {
                    dictionary_Panels[panel] = new Tuple <BuildingStorey, double, double, double> (buildingStorey, keyValuePair.Key, panel.MinElevation(), panel.MaxElevation());
                }
            }

            List <gbXMLSerializer.Space>     spaces_gbXML = new List <gbXMLSerializer.Space>();
            Dictionary <Guid, SpaceBoundary> dictionary   = new Dictionary <Guid, SpaceBoundary>();

            foreach (Space space in spaces)
            {
                List <Panel> panels_Space = adjacencyCluster.GetRelatedObjects <Panel>(space);
                if (panels_Space == null || panels_Space.Count == 0)
                {
                    continue;
                }

                double         elevation_Level = panels_Space.ConvertAll(x => dictionary_Panels[x].Item2).Min();
                double         elevation_Min   = panels_Space.ConvertAll(x => dictionary_Panels[x].Item3).Min();
                double         elevation_Max   = panels_Space.ConvertAll(x => dictionary_Panels[x].Item4).Max();
                BuildingStorey buildingStorey  = null;
                foreach (KeyValuePair <BuildingStorey, double> keyValuePair in dictionary_buildingStoreys)
                {
                    if (keyValuePair.Value.Equals(elevation_Level))
                    {
                        buildingStorey = keyValuePair.Key;
                        break;
                    }
                }

                if (buildingStorey == null)
                {
                    continue;
                }

                List <Panel> panels_PlanarGeometry = panels_Space.FindAll(x => x.PanelType.PanelGroup() == PanelGroup.Floor || (x.Normal.AlmostSimilar(Vector3D.WorldZ.GetNegated()) && dictionary_Panels[x].Item3 == elevation_Min));
                panels_PlanarGeometry = panels_PlanarGeometry?.MergeCoplanarPanels(Tolerance.MacroDistance, false, false, Tolerance.MacroDistance);
                if (panels_PlanarGeometry == null || panels_PlanarGeometry.Count == 0)
                {
                    continue;
                }

                panels_PlanarGeometry.Sort((x, y) => y.GetArea().CompareTo(x.GetArea()));

                Face3D face3D = panels_PlanarGeometry.First().PlanarBoundary3D?.GetFace3D();
                if (face3D == null)
                {
                    continue;
                }

                double area = face3D.GetArea();
                if (area < Tolerance.MacroDistance)
                {
                    continue;
                }

                double volume = Math.Abs(elevation_Max - elevation_Min) * area;
                if (volume < Tolerance.MacroDistance)
                {
                    continue;
                }

                List <SpaceBoundary> spaceBoundaries = new List <SpaceBoundary>();
                foreach (Panel panel in panels_Space)
                {
                    if (panel == null)
                    {
                        continue;
                    }

                    SpaceBoundary spaceBoundary = null;
                    if (!dictionary.TryGetValue(panel.Guid, out spaceBoundary))
                    {
                        spaceBoundary          = panel.TogbXML_SpaceBoundary(tolerance);
                        dictionary[panel.Guid] = spaceBoundary;
                    }

                    spaceBoundaries.Add(spaceBoundary);
                }

                gbXMLSerializer.Space space_gbXML = new gbXMLSerializer.Space();
                space_gbXML.Name      = space.Name;
                space_gbXML.spacearea = new Area()
                {
                    val = area.ToString()
                };
                space_gbXML.spacevol = new Volume()
                {
                    val = volume.ToString()
                };
                space_gbXML.buildingStoreyIdRef = buildingStorey.id;
                space_gbXML.cadid = new CADObjectId()
                {
                    id = space.Guid.ToString()
                };
                space_gbXML.PlanarGeo = face3D.TogbXML(tolerance);
                space_gbXML.id        = Core.gbXML.Query.Id(space, typeof(gbXMLSerializer.Space));
                space_gbXML.spbound   = spaceBoundaries.ToArray();
                space_gbXML.ShellGeo  = panels_Space.TogbXML(space, tolerance);

                spaces_gbXML.Add(space_gbXML);
            }

            Building building = new Building();

            building.id           = Core.gbXML.Query.Id(adjacencyCluster, typeof(Building));
            building.Name         = name;
            building.Description  = description;
            building.bldgStories  = dictionary_buildingStoreys.Keys.ToArray();
            building.Area         = Analytical.Query.Area(panels, PanelGroup.Floor);
            building.buildingType = buildingTypeEnum.Office;
            building.Spaces       = spaces_gbXML.ToArray();

            return(building);
        }
Пример #14
0
        protected override void TrySolveInstance(IGH_DataAccess dataAccess)
        {
            bool run = false;

            if (!dataAccess.GetData(2, ref run) || !run)
            {
                return;
            }

            ConvertSettings convertSettings = null;

            dataAccess.GetData(1, ref convertSettings);
            convertSettings = this.UpdateSolutionEndEventHandler(convertSettings);

            SAMObject sAMObject = null;

            if (!dataAccess.GetData(0, ref sAMObject))
            {
                return;
            }

            Document document = RhinoInside.Revit.Revit.ActiveDBDocument;

            if (sAMObject is AnalyticalModel)
            {
                sAMObject = ((AnalyticalModel)sAMObject).AdjacencyCluster;
            }

            if (!(sAMObject is Panel) && !(sAMObject is Aperture) && !(sAMObject is Space) && !(sAMObject is AdjacencyCluster))
            {
                dataAccess.SetData(0, null);
                return;
            }

            if (sAMObject is AdjacencyCluster)
            {
                AdjacencyCluster adjacencyCluster = (AdjacencyCluster)sAMObject;
                adjacencyCluster.GetPanels()?.ForEach(x => Core.Revit.Modify.RemoveExisting(convertSettings, document, x));
                adjacencyCluster.GetSpaces()?.ForEach(x => Core.Revit.Modify.RemoveExisting(convertSettings, document, x));
            }
            else
            {
                Core.Revit.Modify.RemoveExisting(convertSettings, document, sAMObject);
            }

            object @object = Analytical.Revit.Convert.ToRevit(sAMObject as dynamic, document, convertSettings);

            IEnumerable <Element> elements = null;

            if (@object is IEnumerable)
            {
                elements = ((IEnumerable)@object).Cast <Element>();
            }
            else
            {
                elements = new List <Element>()
                {
                    @object as Element
                }
            };

            dataAccess.SetDataList(0, elements);
        }
    }
Пример #15
0
        protected override void TrySolveInstance(IGH_DataAccess dataAccess)
        {
            int index            = -1;
            int index_Elements   = -1;
            int index_Successful = -1;

            index_Successful = Params.IndexOfOutputParam("successful");
            if (index_Successful != -1)
            {
                dataAccess.SetData(index_Successful, false);
            }

            index_Elements = Params.IndexOfOutputParam("elements");
            if (index_Elements != -1)
            {
                dataAccess.SetData(index_Elements, null);
            }

            bool run = false;

            index = Params.IndexOfInputParam("_run");
            if (index == -1 || !dataAccess.GetData(index, ref run) || !run)
            {
                return;
            }

            ConvertSettings convertSettings = null;

            index = Params.IndexOfInputParam("_convertSettings_");
            if (index != -1)
            {
                dataAccess.GetData(index, ref convertSettings);
            }

            convertSettings = this.UpdateSolutionEndEventHandler(convertSettings);

            SAMObject sAMObject = null;

            index = Params.IndexOfInputParam("_analytical");
            if (index == -1 || !dataAccess.GetData(index, ref sAMObject))
            {
                return;
            }

            Document document = RhinoInside.Revit.Revit.ActiveDBDocument;

            StartTransaction(document);

            if (!(sAMObject is Panel) && !(sAMObject is Aperture) && !(sAMObject is Space) && !(sAMObject is AdjacencyCluster) && !(sAMObject is AnalyticalModel))
            {
                return;
            }

            AdjacencyCluster adjacencyCluster = null;

            if (sAMObject is AdjacencyCluster)
            {
                adjacencyCluster = (AdjacencyCluster)sAMObject;
                convertSettings.AddParameter("AdjacencyCluster", adjacencyCluster);
            }
            else if (sAMObject is AnalyticalModel)
            {
                adjacencyCluster = ((AnalyticalModel)sAMObject).AdjacencyCluster;
                convertSettings.AddParameter("AnalyticalModel", (AnalyticalModel)sAMObject);
            }


            if (adjacencyCluster != null)
            {
                adjacencyCluster.GetPanels()?.ForEach(x => Core.Revit.Modify.RemoveExisting(convertSettings, document, x));
                adjacencyCluster.GetSpaces()?.ForEach(x => Core.Revit.Modify.RemoveExisting(convertSettings, document, x));
            }
            else
            {
                Core.Revit.Modify.RemoveExisting(convertSettings, document, sAMObject);
            }


            object @object = Analytical.Revit.Convert.ToRevit(sAMObject as dynamic, document, convertSettings);

            IEnumerable <Element> elements = null;

            if (@object is IEnumerable)
            {
                elements = ((IEnumerable)@object).Cast <Element>();
            }
            else
            {
                elements = new List <Element>()
                {
                    @object as Element
                }
            };

            //if(elements != null)
            //{
            //    foreach(Element element in elements)
            //    {
            //        ElementId elementId = element.Id;
            //        if (elementId == null)
            //            continue;

            //        elementIds.Add(elementId);
            //    }
            //}

            if (index_Elements != -1)
            {
                dataAccess.SetDataList(index_Elements, elements);
            }

            if (index_Successful != -1)
            {
                dataAccess.SetData(index_Successful, elements != null && elements.Count() > 0);
            }
        }

        //protected override void OnAfterStart(Document document, string strTransactionName)
        //{
        //    base.OnAfterStart(document, strTransactionName);

        //    elementIds = new HashSet<ElementId>();
        //}

        //protected override void OnBeforeCommit(Document document, string strTransactionName)
        //{
        //    base.OnBeforeCommit(document, strTransactionName);

        //    if(elementIds != null && elementIds.Count != 0)
        //    {
        //        List<Wall> walls = new FilteredElementCollector(document, elementIds).OfClass(typeof(Wall)).Cast<Wall>().ToList();
        //        if(walls != null && walls.Count != 0)
        //        {
        //            Dictionary<Wall, int> dictionary = new Dictionary<Wall, int>();
        //            walls.ForEach(x => dictionary[x] = x.get_Parameter(BuiltInParameter.WALL_ATTR_ROOM_BOUNDING).AsInteger());

        //            using (SubTransaction subTransaction = new SubTransaction(document))
        //            {
        //                subTransaction.Start();

        //                foreach (Wall wall in dictionary.Keys)
        //                    wall.get_Parameter(BuiltInParameter.WALL_ATTR_ROOM_BOUNDING).Set(0);

        //                document.Regenerate();

        //                subTransaction.Commit();

        //                subTransaction.Start();

        //                foreach (KeyValuePair<Wall, int> keyValuePair in dictionary)
        //                    keyValuePair.Key.get_Parameter(BuiltInParameter.WALL_ATTR_ROOM_BOUNDING).Set(keyValuePair.Value);

        //                subTransaction.Commit();
        //            }
        //        }
        //    }
        //}
    }
Пример #16
0
        public static Model ToLadybugTools(this AnalyticalModel analyticalModel, double silverSpacing = Tolerance.MacroDistance, double tolerance = Tolerance.Distance)
        {
            if (analyticalModel == null)
            {
                return(null);
            }

            AnalyticalModel analyticalModel_Temp = new AnalyticalModel(analyticalModel);

            analyticalModel_Temp.OffsetAperturesOnEdge(0.1, tolerance);
            analyticalModel_Temp.ReplaceTransparentPanels(0.1);

            string uniqueName = Core.LadybugTools.Query.UniqueName(analyticalModel_Temp);

            AdjacencyCluster adjacencyCluster = analyticalModel_Temp.AdjacencyCluster;

            List <Room> rooms = null;
            List <AnyOf <IdealAirSystemAbridged, VAV, PVAV, PSZ, PTAC, ForcedAirFurnace, FCUwithDOASAbridged, WSHPwithDOASAbridged, VRFwithDOASAbridged, FCU, WSHP, VRF, Baseboard, EvaporativeCooler, Residential, WindowAC, GasUnitHeater> > hvacs = null;

            List <Space> spaces = adjacencyCluster?.GetSpaces();

            if (spaces != null)
            {
                hvacs = new List <AnyOf <IdealAirSystemAbridged, VAV, PVAV, PSZ, PTAC, ForcedAirFurnace, FCUwithDOASAbridged, WSHPwithDOASAbridged, VRFwithDOASAbridged, FCU, WSHP, VRF, Baseboard, EvaporativeCooler, Residential, WindowAC, GasUnitHeater> >();
                rooms = new List <Room>();

                Dictionary <double, List <Panel> > dictionary_elevations = Analytical.Query.MinElevationDictionary(adjacencyCluster.GetPanels(), true);
                List <Level> levels = dictionary_elevations?.Keys.ToList().ConvertAll(x => Architectural.Create.Level(x));

                for (int i = 0; i < spaces.Count; i++)
                {
                    Space space = spaces[i];
                    if (space == null)
                    {
                        continue;
                    }

                    Room room = space.ToLadybugTools(analyticalModel_Temp, silverSpacing, tolerance);
                    if (room == null)
                    {
                        continue;
                    }

                    if (levels != null && levels.Count > 0)
                    {
                        double elevation_Min = space.MinElevation(adjacencyCluster);
                        if (!double.IsNaN(elevation_Min))
                        {
                            double difference_Min = double.MaxValue;
                            Level  level_Min      = null;
                            foreach (Level level in levels)
                            {
                                double difference = System.Math.Abs(elevation_Min - level.Elevation);
                                if (difference < difference_Min)
                                {
                                    difference_Min = difference;
                                    level_Min      = level;
                                }
                            }

                            room.Story = level_Min.Name;
                        }
                    }

                    InternalCondition internalCondition = space.InternalCondition;
                    if (internalCondition != null)
                    {
                        //Michal Idea of filtering Uncondition Spaces
                        string name_InternalCondition = internalCondition.Name;

                        if (name_InternalCondition == null || (name_InternalCondition != null && !name_InternalCondition.ToLower().Contains("unconditioned") && !name_InternalCondition.ToLower().Contains("external")))
                        {
                            IdealAirSystemAbridged idealAirSystemAbridged = new IdealAirSystemAbridged(string.Format("{0}__{1}", i.ToString(), "IdealAir"), string.Format("Ideal Air System Abridged {0}", space.Name));
                            hvacs.Add(idealAirSystemAbridged);

                            if (room.Properties == null)
                            {
                                room.Properties = new RoomPropertiesAbridged();
                            }

                            if (room.Properties.Energy == null)
                            {
                                room.Properties.Energy = new RoomEnergyPropertiesAbridged();
                            }

                            room.Properties.Energy.Hvac = idealAirSystemAbridged.Identifier;
                        }
                    }

                    rooms.Add(room);
                }
            }

            List <Shade> shades         = null;
            List <Face>  faces_Orphaned = null;

            List <Panel> panels_Shading = adjacencyCluster.GetShadingPanels();

            if (panels_Shading != null)
            {
                foreach (Panel panel_Shading in panels_Shading)
                {
                    if (panels_Shading == null)
                    {
                        continue;
                    }

                    if (panel_Shading.PanelType == PanelType.Shade)
                    {
                        Shade shade = panel_Shading.ToLadybugTools_Shade();
                        if (shade == null)
                        {
                            continue;
                        }

                        if (shades == null)
                        {
                            shades = new List <Shade>();
                        }

                        shades.Add(shade);
                    }
                    else
                    {
                        Face face_Orphaned = panel_Shading.ToLadybugTools_Face();
                        if (face_Orphaned == null)
                        {
                            continue;
                        }

                        if (faces_Orphaned == null)
                        {
                            faces_Orphaned = new List <Face>();
                        }

                        faces_Orphaned.Add(face_Orphaned);
                    }
                }
            }

            MaterialLibrary materialLibrary = analyticalModel_Temp?.MaterialLibrary;

            List <Construction>         constructions_AdjacencyCluster         = adjacencyCluster.GetConstructions();
            List <ApertureConstruction> apertureConstructions_AdjacencyCluster = adjacencyCluster.GetApertureConstructions();

            ConstructionSetAbridged constructionSetAbridged = Core.LadybugTools.Query.DefaultConstructionSetAbridged();
            List <HoneybeeSchema.AnyOf <ConstructionSetAbridged, ConstructionSet> > constructionSets = new List <HoneybeeSchema.AnyOf <ConstructionSetAbridged, ConstructionSet> >();// { constructionSetAbridged  };

            List <AnyOf <OpaqueConstructionAbridged, WindowConstructionAbridged, WindowConstructionShadeAbridged, AirBoundaryConstructionAbridged, OpaqueConstruction, WindowConstruction, WindowConstructionShade, WindowConstructionDynamicAbridged, WindowConstructionDynamic, AirBoundaryConstruction, ShadeConstruction> > constructions = new List <AnyOf <OpaqueConstructionAbridged, WindowConstructionAbridged, WindowConstructionShadeAbridged, AirBoundaryConstructionAbridged, OpaqueConstruction, WindowConstruction, WindowConstructionShade, WindowConstructionDynamicAbridged, WindowConstructionDynamic, AirBoundaryConstruction, ShadeConstruction> >();

            Dictionary <string, HoneybeeSchema.Energy.IMaterial> dictionary_Materials = new Dictionary <string, HoneybeeSchema.Energy.IMaterial>();

            if (constructions_AdjacencyCluster != null)
            {
                foreach (Construction construction in constructions_AdjacencyCluster)
                {
                    List <ConstructionLayer> constructionLayers = construction.ConstructionLayers;
                    if (constructionLayers == null)
                    {
                        continue;
                    }

                    constructions.Add(construction.ToLadybugTools());
                    constructions.Add(construction.ToLadybugTools(false));

                    foreach (ConstructionLayer constructionLayer in constructionLayers)
                    {
                        IMaterial material = constructionLayer.Material(materialLibrary);
                        if (material == null)
                        {
                            continue;
                        }

                        if (dictionary_Materials.ContainsKey(material.Name))
                        {
                            continue;
                        }

                        if (material is GasMaterial)
                        {
                            List <Panel>  panels = Analytical.Query.Panels(adjacencyCluster, construction);
                            List <double> tilts  = panels.ConvertAll(x => Analytical.Query.Tilt(x).Round(Tolerance.MacroDistance));
                            double        tilt   = tilts.Distinct().ToList().Average();

                            tilt = Units.Convert.ToRadians(tilt);

                            dictionary_Materials[material.Name] = ((GasMaterial)material).ToLadybugTools(tilt, constructionLayer.Thickness);
                        }
                        else if (material is OpaqueMaterial)
                        {
                            EnergyMaterial energyMaterial = ((OpaqueMaterial)material).ToLadybugTools();
                            dictionary_Materials[material.Name] = energyMaterial;
                            if (!double.IsNaN(constructionLayer.Thickness))
                            {
                                energyMaterial.Thickness = constructionLayer.Thickness;
                            }
                        }
                    }
                }
            }

            if (apertureConstructions_AdjacencyCluster != null)
            {
                foreach (ApertureConstruction apertureConstruction in apertureConstructions_AdjacencyCluster)
                {
                    List <ConstructionLayer> constructionLayers = null;

                    constructionLayers = apertureConstruction.PaneConstructionLayers;
                    if (constructionLayers != null)
                    {
                        MaterialType materialType = Analytical.Query.MaterialType(constructionLayers, materialLibrary);
                        if (materialType != MaterialType.Undefined && materialType != MaterialType.Gas)
                        {
                            if (materialType == MaterialType.Opaque)
                            {
                                constructions.Add(apertureConstruction.ToLadybugTools());
                                constructions.Add(apertureConstruction.ToLadybugTools(false));
                            }
                            else
                            {
                                constructions.Add(apertureConstruction.ToLadybugTools_WindowConstructionAbridged());
                                constructions.Add(apertureConstruction.ToLadybugTools_WindowConstructionAbridged(false));
                            }

                            foreach (ConstructionLayer constructionLayer in constructionLayers)
                            {
                                IMaterial material = constructionLayer.Material(materialLibrary);
                                if (material == null)
                                {
                                    continue;
                                }

                                string name = material.Name;

                                if (dictionary_Materials.ContainsKey(name))
                                {
                                    continue;
                                }

                                if (material is TransparentMaterial)
                                {
                                    dictionary_Materials[name] = ((TransparentMaterial)material).ToLadybugTools();
                                }
                                else if (material is GasMaterial)
                                {
                                    dictionary_Materials[name] = ((GasMaterial)material).ToLadybugTools_EnergyWindowMaterialGas();
                                }
                                else
                                {
                                    dictionary_Materials[name] = ((OpaqueMaterial)material).ToLadybugTools();
                                }
                            }
                        }
                    }
                }
            }


            ProfileLibrary profileLibrary = analyticalModel.ProfileLibrary;

            Dictionary <System.Guid, ProgramType> dictionary_InternalConditions = new Dictionary <System.Guid, ProgramType>();

            if (spaces != null)
            {
                foreach (Space space in spaces)
                {
                    InternalCondition internalCondition = space?.InternalCondition;
                    if (internalCondition == null)
                    {
                        continue;
                    }

                    if (dictionary_InternalConditions.ContainsKey(internalCondition.Guid))
                    {
                        continue;
                    }

                    ProgramType programType = space.ToLadybugTools(adjacencyCluster, profileLibrary);
                    if (programType != null)
                    {
                        dictionary_InternalConditions[internalCondition.Guid] = programType;
                    }
                }
            }

            List <AnyOf <EnergyMaterial, EnergyMaterialNoMass, EnergyWindowMaterialGas, EnergyWindowMaterialGasCustom, EnergyWindowMaterialGasMixture, EnergyWindowMaterialSimpleGlazSys, EnergyWindowMaterialBlind, EnergyWindowMaterialGlazing, EnergyWindowMaterialShade> > materials = new List <AnyOf <EnergyMaterial, EnergyMaterialNoMass, EnergyWindowMaterialGas, EnergyWindowMaterialGasCustom, EnergyWindowMaterialGasMixture, EnergyWindowMaterialSimpleGlazSys, EnergyWindowMaterialBlind, EnergyWindowMaterialGlazing, EnergyWindowMaterialShade> >();

            HoneybeeSchema.Helper.EnergyLibrary.DefaultMaterials?.ToList().ForEach(x => materials.Add(x as dynamic));
            dictionary_Materials.Values.ToList().ForEach(x => materials.Add(x as dynamic));

            List <AnyOf <ScheduleRulesetAbridged, ScheduleFixedIntervalAbridged, ScheduleRuleset, ScheduleFixedInterval> > schedules = new List <AnyOf <ScheduleRulesetAbridged, ScheduleFixedIntervalAbridged, ScheduleRuleset, ScheduleFixedInterval> >();

            HoneybeeSchema.Helper.EnergyLibrary.DefaultScheduleRuleset?.ToList().ForEach(x => schedules.Add(x));

            List <HoneybeeSchema.AnyOf <ProgramTypeAbridged, ProgramType> > programTypes = new List <HoneybeeSchema.AnyOf <ProgramTypeAbridged, ProgramType> >();

            HoneybeeSchema.Helper.EnergyLibrary.DefaultProgramTypes?.ToList().ForEach(x => programTypes.Add(x));
            dictionary_InternalConditions.Values.ToList().ForEach(x => programTypes.Add(x));

            List <ScheduleTypeLimit> scheduleTypeLimits = new List <ScheduleTypeLimit>();

            HoneybeeSchema.Helper.EnergyLibrary.DefaultScheduleTypeLimit?.ToList().ForEach(x => scheduleTypeLimits.Add(x));

            constructionSets.RemoveAll(x => x == null);
            constructions.RemoveAll(x => x == null);
            materials.RemoveAll(x => x == null);

            ModelEnergyProperties modelEnergyProperties = new ModelEnergyProperties(constructionSets, constructions, materials, hvacs, null, programTypes, schedules, scheduleTypeLimits);

            ModelProperties modelProperties = new ModelProperties(modelEnergyProperties);

            Model model = new Model(uniqueName, modelProperties, adjacencyCluster.Name, null, rooms, faces_Orphaned, shades);

            model.AngleTolerance = Units.Convert.ToDegrees(Tolerance.Angle);// 2;
            model.Tolerance      = Tolerance.MacroDistance;

            return(model);
        }
Пример #17
0
        public static List <Autodesk.Revit.DB.Mechanical.Space> ToRevit(this AdjacencyCluster adjacencyCluster, Zone zone, Document document, ConvertSettings convertSettings)
        {
            if (adjacencyCluster == null || zone == null)
            {
                return(null);
            }

            List <Autodesk.Revit.DB.Mechanical.Space> result = convertSettings?.GetObjects <Autodesk.Revit.DB.Mechanical.Space>(zone.Guid);

            if (result != null)
            {
                return(result);
            }

            Zone zone_Temp = adjacencyCluster.GetObject <Zone>(zone.Guid);

            if (zone_Temp == null)
            {
                zone_Temp = zone;
            }

            if (convertSettings.ConvertParameters)
            {
                string zoneParameterName = Query.ZoneParameterName(zone);

                ZoneType zoneType = zone.ZoneType();

                List <Space> spaces = adjacencyCluster.GetSpaces(zone_Temp);
                if (spaces != null)
                {
                    List <Autodesk.Revit.DB.Mechanical.Space> spaces_Revit = new FilteredElementCollector(document).OfCategory(BuiltInCategory.OST_MEPSpaces).Cast <Autodesk.Revit.DB.Mechanical.Space>().ToList();

                    foreach (Space space_SAM in spaces)
                    {
                        Autodesk.Revit.DB.Mechanical.Space space_Revit = Core.Revit.Query.Element <Autodesk.Revit.DB.Mechanical.Space>(document, zone);

                        if (space_Revit == null)
                        {
                            space_Revit = Core.Revit.Query.Element <Autodesk.Revit.DB.Mechanical.Space>(document, space_SAM);
                        }

                        if (space_Revit == null)
                        {
                            space_Revit = spaces_Revit?.Find(x => x.get_Parameter(BuiltInParameter.ROOM_NAME)?.AsString() == space_SAM.Name);
                        }

                        if (space_Revit == null)
                        {
                            space_Revit = spaces_Revit?.Find(x => space_SAM.Name.EndsWith(x.get_Parameter(BuiltInParameter.ROOM_NAME)?.AsString()) && space_SAM.Name.StartsWith(x.get_Parameter(BuiltInParameter.ROOM_NUMBER)?.AsString()));
                        }


                        if (space_Revit == null)
                        {
                            continue;
                        }

                        if (!string.IsNullOrWhiteSpace(zoneParameterName))
                        {
                            IEnumerable <Parameter> parameters = space_Revit.GetParameters(zoneParameterName);
                            if (parameters != null)
                            {
                                foreach (Parameter parameter in parameters)
                                {
                                    if (parameter == null || parameter.IsReadOnly || parameter.StorageType != StorageType.String)
                                    {
                                        continue;
                                    }

                                    parameter.Set(zone.Name);
                                }
                            }
                        }

                        Core.Revit.Modify.SetValues(space_Revit, zone_Temp);
                        Core.Revit.Modify.SetValues(space_Revit, zone_Temp, ActiveSetting.Setting);

                        if (zoneType != ZoneType.Undefined)
                        {
                            Modify.SetValues(space_Revit, zone_Temp, ActiveSetting.Setting, zoneType, convertSettings?.GetParameters());
                        }
                    }
                }
            }

            convertSettings?.Add(zone.Guid, result);

            return(result);
        }
Пример #18
0
        public static List <Core.Result> AddResults(this SimulationData simulationData, AdjacencyCluster adjacencyCluster)
        {
            if (simulationData == null || adjacencyCluster == null)
            {
                return(null);
            }

            List <Core.Result> result = null;

            //get simulaton data from Tas for individal SAM Space
            List <Core.Result> results = Convert.ToSAM(simulationData);

            if (results == null)
            {
                return(result);
            }

            result = new List <Core.Result>(results);

            Dictionary <Guid, List <SpaceSimulationResult> > dictionary = new Dictionary <Guid, List <SpaceSimulationResult> >();
            List <Space> spaces = adjacencyCluster.GetSpaces();

            if (spaces != null && spaces.Count > 0)
            {
                foreach (Space space in spaces)
                {
                    List <SpaceSimulationResult> spaceSimulationResults_Space = results.FindAll(x => x is SpaceSimulationResult && space.Name.Equals(x.Name)).ConvertAll(x => (SpaceSimulationResult)x);
                    dictionary[space.Guid] = spaceSimulationResults_Space;
                    if (spaceSimulationResults_Space != null && spaceSimulationResults_Space.Count != 0)
                    {
                        foreach (SpaceSimulationResult spaceSimulationResult in spaceSimulationResults_Space)
                        {
                            List <SpaceSimulationResult> spaceSimulationResults_Existing = adjacencyCluster.GetResults <SpaceSimulationResult>(space, Query.Source())?.FindAll(x => x.LoadType() == spaceSimulationResult.LoadType());
                            if (spaceSimulationResults_Existing != null && spaceSimulationResults_Existing.Count != 0)
                            {
                                adjacencyCluster.Remove(spaceSimulationResults_Existing);
                                if (spaceSimulationResults_Existing[0].TryGetValue(Analytical.SpaceSimulationResultParameter.DesignLoad, out double designLoad))
                                {
                                    spaceSimulationResult.SetValue(Analytical.SpaceSimulationResultParameter.DesignLoad, designLoad);
                                }
                            }

                            adjacencyCluster.AddObject(spaceSimulationResult);
                            adjacencyCluster.AddRelation(space, spaceSimulationResult);
                        }
                    }

                    foreach (Core.Result result_Temp in results)
                    {
                        PanelSimulationResult panelSimulationResult = result_Temp as PanelSimulationResult;
                        if (panelSimulationResult == null)
                        {
                            continue;
                        }

                        if (!panelSimulationResult.TryGetValue(PanelSimulationResultParameter.ZoneName, out string zoneName) || !space.Name.Equals(zoneName))
                        {
                            continue;
                        }

                        adjacencyCluster.AddObject(panelSimulationResult);
                        adjacencyCluster.AddRelation(space, panelSimulationResult);
                    }
                }
            }

            // get data data about SAM Zones like space GUID, Zone Category etc.
            List <Zone> zones = adjacencyCluster.GetZones();

            if (zones != null && zones.Count > 0)
            {
                //  Query Tas Zones,  that can be linked with SAM Spaces
                BuildingData buildingData = simulationData.GetBuildingData();
                Dictionary <string, ZoneData> dictionary_ZoneData = Query.ZoneDataDictionary(buildingData);

                // Our SAM Zones(list of Space GUIDs)
                foreach (Zone zone in zones)
                {
                    List <Space> spaces_Zone = adjacencyCluster.GetSpaces(zone);
                    if (spaces_Zone == null || spaces_Zone.Count == 0)
                    {
                        continue;
                    }

                    double area      = adjacencyCluster.Sum(zone, SpaceParameter.Area);
                    double volume    = adjacencyCluster.Sum(zone, SpaceParameter.Volume);
                    double occupancy = adjacencyCluster.Sum(zone, SpaceParameter.Occupancy);

                    List <ZoneData> zoneDatas = new List <ZoneData>();
                    foreach (Space space in spaces_Zone)
                    {
                        string name = space?.Name;
                        if (string.IsNullOrWhiteSpace(name))
                        {
                            continue;
                        }

                        List <SpaceSimulationResult> spaceSimulationResults_Space;
                        if (!dictionary.TryGetValue(space.Guid, out spaceSimulationResults_Space) || spaceSimulationResults_Space == null || spaceSimulationResults_Space.Count == 0)
                        {
                            continue;
                        }

                        SpaceSimulationResult spaceSimulationResult = spaceSimulationResults_Space[0];
                        if (spaceSimulationResult == null || string.IsNullOrWhiteSpace(spaceSimulationResult.Reference))
                        {
                            continue;
                        }

                        ZoneData zoneData = dictionary_ZoneData[spaceSimulationResult.Reference];
                        if (zoneData == null)
                        {
                            continue;
                        }

                        zoneDatas.Add(zoneData);
                    }

                    int    index;
                    double max;

                    //Cooling
                    ZoneSimulationResult zoneSimulationResult_Cooling = null;
                    if (buildingData.TryGetMax(zoneDatas.ConvertAll(x => x.zoneGUID), tsdZoneArray.coolingLoad, out index, out max) && index != -1 && !double.IsNaN(max))
                    {
                        zoneSimulationResult_Cooling = new ZoneSimulationResult(zone.Name, Assembly.GetExecutingAssembly().GetName()?.Name, zone.Guid.ToString());
                        zoneSimulationResult_Cooling.SetValue(ZoneSimulationResultParameter.MaxSensibleLoad, max);
                        zoneSimulationResult_Cooling.SetValue(ZoneSimulationResultParameter.MaxSensibleLoadIndex, index);
                        zoneSimulationResult_Cooling.SetValue(ZoneSimulationResultParameter.LoadType, LoadType.Cooling.Text());

                        List <SpaceSimulationResult> spaceSimulationResults_Zone = new List <SpaceSimulationResult>();
                        foreach (ZoneData zoneData in zoneDatas)
                        {
                            SpaceSimulationResult spaceSimulationResult_Temp = Create.SpaceSimulationResult(zoneData, index, LoadType.Cooling, SizingMethod.Simulation);
                            if (spaceSimulationResult_Temp == null)
                            {
                                continue;
                            }

                            spaceSimulationResults_Zone.Add(spaceSimulationResult_Temp);
                        }

                        if (spaceSimulationResults_Zone != null && spaceSimulationResults_Zone.Count != 0)
                        {
                            double airMovementGain = spaceSimulationResults_Zone.Sum(Analytical.SpaceSimulationResultParameter.AirMovementGain);
                            if (!double.IsNaN(airMovementGain))
                            {
                                zoneSimulationResult_Cooling.SetValue(ZoneSimulationResultParameter.AirMovementGain, airMovementGain);
                            }

                            double buildingHeatTransfer = spaceSimulationResults_Zone.Sum(Analytical.SpaceSimulationResultParameter.BuildingHeatTransfer);
                            if (!double.IsNaN(buildingHeatTransfer))
                            {
                                zoneSimulationResult_Cooling.SetValue(ZoneSimulationResultParameter.BuildingHeatTransfer, buildingHeatTransfer);
                            }

                            double equipmentSensibleGain = spaceSimulationResults_Zone.Sum(Analytical.SpaceSimulationResultParameter.EquipmentSensibleGain);
                            if (!double.IsNaN(equipmentSensibleGain))
                            {
                                zoneSimulationResult_Cooling.SetValue(ZoneSimulationResultParameter.EquipmentSensibleGain, equipmentSensibleGain);
                            }

                            double glazingExternalConduction = spaceSimulationResults_Zone.Sum(Analytical.SpaceSimulationResultParameter.GlazingExternalConduction);
                            if (!double.IsNaN(glazingExternalConduction))
                            {
                                zoneSimulationResult_Cooling.SetValue(ZoneSimulationResultParameter.GlazingExternalConduction, glazingExternalConduction);
                            }

                            double lightingGain = spaceSimulationResults_Zone.Sum(Analytical.SpaceSimulationResultParameter.LightingGain);
                            if (!double.IsNaN(lightingGain))
                            {
                                zoneSimulationResult_Cooling.SetValue(ZoneSimulationResultParameter.LightingGain, lightingGain);
                            }

                            double infiltrationGain = spaceSimulationResults_Zone.Sum(Analytical.SpaceSimulationResultParameter.InfiltrationGain);
                            if (!double.IsNaN(infiltrationGain))
                            {
                                zoneSimulationResult_Cooling.SetValue(ZoneSimulationResultParameter.InfiltrationGain, infiltrationGain);
                            }

                            double occupancySensibleGain = spaceSimulationResults_Zone.Sum(Analytical.SpaceSimulationResultParameter.OccupancySensibleGain);
                            if (!double.IsNaN(occupancySensibleGain))
                            {
                                zoneSimulationResult_Cooling.SetValue(ZoneSimulationResultParameter.OccupancySensibleGain, occupancySensibleGain);
                            }

                            double opaqueExternalConduction = spaceSimulationResults_Zone.Sum(Analytical.SpaceSimulationResultParameter.OpaqueExternalConduction);
                            if (!double.IsNaN(opaqueExternalConduction))
                            {
                                zoneSimulationResult_Cooling.SetValue(ZoneSimulationResultParameter.OpaqueExternalConduction, opaqueExternalConduction);
                            }

                            double solarGain = spaceSimulationResults_Zone.Sum(Analytical.SpaceSimulationResultParameter.SolarGain);
                            if (!double.IsNaN(solarGain))
                            {
                                zoneSimulationResult_Cooling.SetValue(ZoneSimulationResultParameter.SolarGain, solarGain);
                            }
                        }
                    }

                    if (!double.IsNaN(occupancy))
                    {
                        zoneSimulationResult_Cooling?.SetValue(ZoneSimulationResultParameter.Occupancy, occupancy);
                    }

                    if (!double.IsNaN(area))
                    {
                        zoneSimulationResult_Cooling?.SetValue(ZoneSimulationResultParameter.Area, area);
                    }

                    if (!double.IsNaN(volume))
                    {
                        zoneSimulationResult_Cooling?.SetValue(ZoneSimulationResultParameter.Volume, volume);
                    }


                    if (zoneSimulationResult_Cooling != null)
                    {
                        adjacencyCluster.AddObject(zoneSimulationResult_Cooling);
                        adjacencyCluster.AddRelation(zone, zoneSimulationResult_Cooling);
                        result.Add(zoneSimulationResult_Cooling);
                    }

                    //Heating
                    //ZoneSimulationResult zoneSimulationResult_Heating = null;
                    //if (buildingData.TryGetMax(zoneDatas.ConvertAll(x => x.zoneGUID), tsdZoneArray.heatingLoad, out index, out max) && index != -1 && !double.IsNaN(max))
                    //{
                    //zoneSimulationResult_Heating = new ZoneSimulationResult(zone.Name, Assembly.GetExecutingAssembly().GetName()?.Name, zone.Guid.ToString());
                    //zoneSimulationResult_Heating.SetValue(ZoneSimulationResultParameter.MaxSensibleLoad, max);
                    //zoneSimulationResult_Heating.SetValue(ZoneSimulationResultParameter.MaxSensibleLoadIndex, index);
                    //zoneSimulationResult_Heating.SetValue(ZoneSimulationResultParameter.LoadType, LoadType.Heating.Text());

                    //List<SpaceSimulationResult> spaceSimulationResults_Zone = new List<SpaceSimulationResult>();
                    //foreach (ZoneData zoneData in zoneDatas)
                    //{
                    //    SpaceSimulationResult spaceSimulationResult_Temp = spaceSimulationResults.FindAll(x => x.LoadType() == LoadType.Heating).Find(x => x.Reference == zoneData.zoneGUID);
                    //    if (spaceSimulationResult_Temp == null)
                    //        continue;

                    //    spaceSimulationResults_Zone.Add(spaceSimulationResult_Temp);
                    //}

                    //if (spaceSimulationResults_Zone != null && spaceSimulationResults_Zone.Count != 0)
                    //{
                    //    //double senisbleLoad = spaceSimulationResults_Zone.Sum(SpaceSimulationResultParameter.Load);
                    //    //if (!double.IsNaN(senisbleLoad))
                    //    //    zoneSimulationResult_Heating.SetValue(ZoneSimulationResultParameter.MaxSensibleLoad, senisbleLoad);

                    //    //double airMovementGain = spaceSimulationResults_Zone.Sum(SpaceSimulationResultParameter.AirMovementGain);
                    //    //if (!double.IsNaN(airMovementGain))
                    //    //    zoneSimulationResult_Heating.SetValue(ZoneSimulationResultParameter.AirMovementGain, airMovementGain);

                    //    //double buildingHeatTransfer = spaceSimulationResults_Zone.Sum(SpaceSimulationResultParameter.BuildingHeatTransfer);
                    //    //if (!double.IsNaN(buildingHeatTransfer))
                    //    //    zoneSimulationResult_Heating.SetValue(ZoneSimulationResultParameter.BuildingHeatTransfer, buildingHeatTransfer);

                    //    //double glazingExternalConduction = spaceSimulationResults_Zone.Sum(SpaceSimulationResultParameter.GlazingExternalConduction);
                    //    //if (!double.IsNaN(glazingExternalConduction))
                    //    //    zoneSimulationResult_Heating.SetValue(ZoneSimulationResultParameter.GlazingExternalConduction, glazingExternalConduction);

                    //    //double infiltrationGain = spaceSimulationResults_Zone.Sum(SpaceSimulationResultParameter.InfiltrationGain);
                    //    //if (!double.IsNaN(infiltrationGain))
                    //    //    zoneSimulationResult_Heating.SetValue(ZoneSimulationResultParameter.InfiltrationGain, infiltrationGain);

                    //    //double opaqueExternalConduction = spaceSimulationResults_Zone.Sum(SpaceSimulationResultParameter.OpaqueExternalConduction);
                    //    //if (!double.IsNaN(opaqueExternalConduction))
                    //    //    zoneSimulationResult_Heating.SetValue(ZoneSimulationResultParameter.OpaqueExternalConduction, opaqueExternalConduction);
                    //}
                    //}

                    //if (!double.IsNaN(occupancy))
                    //    zoneSimulationResult_Heating?.SetValue(ZoneSimulationResultParameter.Occupancy, occupancy);

                    //if (!double.IsNaN(area))
                    //    zoneSimulationResult_Heating?.SetValue(ZoneSimulationResultParameter.Area, area);

                    //if (!double.IsNaN(volume))
                    //    zoneSimulationResult_Heating?.SetValue(ZoneSimulationResultParameter.Volume, volume);


                    //if (zoneSimulationResult_Heating != null)
                    //{
                    //    adjacencyCluster.AddObject(zoneSimulationResult_Heating);
                    //    adjacencyCluster.AddRelation(zone, zoneSimulationResult_Heating);
                    //    result.Add(zoneSimulationResult_Heating);
                    //}
                }
            }

            return(result);
        }
Пример #19
0
        public static AdjacencyCluster UpdateDesignLoads(this TBDDocument tBDDocument, AdjacencyCluster adjacencyCluster)
        {
            if (tBDDocument == null || adjacencyCluster == null)
            {
                return(null);
            }

            Building building = tBDDocument.Building;

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

            AdjacencyCluster result = new AdjacencyCluster(adjacencyCluster);

            List <Space> spaces = result.GetSpaces();

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

            Dictionary <string, zone> zones = building.ZoneDictionary();

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

            foreach (Space space in spaces)
            {
                string name = space?.Name;
                if (string.IsNullOrEmpty(name))
                {
                    continue;
                }

                zone zone;
                if (!zones.TryGetValue(name, out zone) || zone == null)
                {
                    continue;
                }

                space.SetValue(SpaceParameter.DesignHeatingLoad, zone.maxHeatingLoad);
                space.SetValue(SpaceParameter.DesignCoolingLoad, zone.maxCoolingLoad);

                result.AddObject(space);

                List <SpaceSimulationResult> spaceSimulationResults = result.GetResults <SpaceSimulationResult>(space, Query.Source());
                foreach (LoadType loadType in new LoadType[] { LoadType.Heating, LoadType.Cooling })
                {
                    SpaceSimulationResult spaceSimulationResult = spaceSimulationResults?.Find(x => x.LoadType() == loadType);
                    if (spaceSimulationResult == null)
                    {
                        spaceSimulationResult = Create.SpaceSimulationResult(zone, loadType);
                    }
                    else
                    {
                        spaceSimulationResult = new SpaceSimulationResult(spaceSimulationResult);
                        spaceSimulationResult.SetValue(Analytical.SpaceSimulationResultParameter.Area, zone.floorArea);
                        spaceSimulationResult.SetValue(Analytical.SpaceSimulationResultParameter.Volume, zone.volume);
                        spaceSimulationResult.SetValue(Analytical.SpaceSimulationResultParameter.DesignLoad, loadType == LoadType.Cooling ? zone.maxCoolingLoad : zone.maxHeatingLoad);
                    }

                    if (spaceSimulationResult != null)
                    {
                        result.AddObject(spaceSimulationResult);
                        result.AddRelation(space, spaceSimulationResult);
                    }
                }
            }

            return(result);
        }