Esempio n. 1
0
        public static AnalyticalModel UpdateDesignLoads(this TBDDocument tBDDocument, AnalyticalModel analyticalModel)
        {
            if (tBDDocument == null || analyticalModel == null)
            {
                return(null);
            }

            Building building = tBDDocument.Building;

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

            AdjacencyCluster adjacencyCluster = analyticalModel.AdjacencyCluster;

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

            adjacencyCluster = UpdateDesignLoads(tBDDocument, adjacencyCluster);

            return(new AnalyticalModel(analyticalModel, adjacencyCluster));
        }
Esempio n. 2
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);

            AdjacencyCluster adjacencyCluster = null;

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

            Document document = RhinoInside.Revit.Revit.ActiveDBDocument;

            List <Element> elements = Analytical.Revit.Convert.ToRevit(adjacencyCluster, document, convertSettings);

            dataAccess.SetDataList(0, elements);
        }
Esempio n. 3
0
        public static AdjacencyCluster ToSAM(this BuildingData buildingData, IEnumerable <SpaceDataType> spaceDataTypes = null, IEnumerable <PanelDataType> panelDataTypes = null)
        {
            if (buildingData == null)
            {
                return(null);
            }

            List <ZoneData> zoneDatas = buildingData.ZoneDatas();

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

            AdjacencyCluster result = new AdjacencyCluster();

            foreach (ZoneData zoneData in zoneDatas)
            {
                if (zoneData == null)
                {
                    continue;
                }

                Space space = zoneData.ToSAM(spaceDataTypes);
                if (space != null)
                {
                    result.AddObject(space);
                }

                List <SurfaceData> surfaceDatas = zoneData.SurfaceDatas();
                if (surfaceDatas == null)
                {
                    continue;
                }

                foreach (SurfaceData surfaceData in surfaceDatas)
                {
                    if (surfaceData == null)
                    {
                        continue;
                    }

                    Panel panel = surfaceData.ToSAM(panelDataTypes);
                    if (panel == null)
                    {
                        continue;
                    }

                    result.AddObject(panel);

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

            return(result);
        }
Esempio n. 4
0
        protected override void SolveInstance(IGH_DataAccess dataAccess)
        {
            int index;

            index = Params.IndexOfInputParam("_analytical");
            if (index == -1)
            {
                AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Invalid data");
                return;
            }

            Core.SAMObject sAMObject = null;
            if (!dataAccess.GetData(index, ref sAMObject) || sAMObject == null)
            {
                AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Invalid data");
                return;
            }

            AdjacencyCluster adjacencyCluster = null;

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

            List <Zone> zones = null;

            if (adjacencyCluster != null)
            {
                zones = adjacencyCluster.MapZones();
                if (zones != null && zones.Count != 0)
                {
                    if (sAMObject is AdjacencyCluster)
                    {
                        sAMObject = adjacencyCluster;
                    }
                    else if (sAMObject is AnalyticalModel)
                    {
                        sAMObject = new AnalyticalModel((AnalyticalModel)sAMObject, adjacencyCluster);
                    }
                }
            }

            index = Params.IndexOfOutputParam("Analytical");
            if (index != -1)
            {
                dataAccess.SetData(index, sAMObject);
            }

            index = Params.IndexOfOutputParam("Zones");
            if (index != -1)
            {
                dataAccess.SetDataList(index, zones);
            }
        }
Esempio n. 5
0
        public static List <Core.Result> AddResults(this TSDDocument tSDDocument, AdjacencyCluster adjacencyCLuster)
        {
            if (tSDDocument == null || adjacencyCLuster == null)
            {
                return(null);
            }

            return(AddResults(tSDDocument.SimulationData, adjacencyCLuster));
        }
Esempio n. 6
0
        public static AnalyticalModel UpdateFacingExternal(this AnalyticalModel analyticalModel, TBD.TBDDocument tBDDocument)
        {
            if (analyticalModel == null || tBDDocument == null)
            {
                return(null);
            }

            Dictionary <string, TBD.zone> zones = tBDDocument.Building?.ZoneDictionary();

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

            AdjacencyCluster adjacencyCluster = analyticalModel.AdjacencyCluster;

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

            Dictionary <string, Space> spaces = adjacencyCluster.SpaceDictionary();

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

            if (zones.Count == 0 || spaces.Count == 0)
            {
                return(new AnalyticalModel(analyticalModel));
            }

            foreach (KeyValuePair <string, Space> keyValuePair in spaces)
            {
                TBD.zone zone = null;
                if (!zones.TryGetValue(keyValuePair.Key, out zone))
                {
                    continue;
                }

                if (zone == null)
                {
                    continue;
                }

                Space space_New = UpdateFacingExternal(keyValuePair.Value, zone);
                if (space_New == null)
                {
                    continue;
                }

                adjacencyCluster.AddObject(space_New);
            }

            return(new AnalyticalModel(analyticalModel, adjacencyCluster));
        }
Esempio n. 7
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);
        }
        /// <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(1, 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;
            }

            AnalyticalModel analyticalModel = null;

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

            bool result = false;

            using (SAMTBDDocument sAMTBDDocument = new SAMTBDDocument(path_TBD))
            {
                result = Analytical.Tas.Modify.UpdateBuildingElements(sAMTBDDocument, analyticalModel);

                AdjacencyCluster adjacencyCluster = analyticalModel.AdjacencyCluster;
                Analytical.Tas.Modify.UpdateThermalParameters(adjacencyCluster, sAMTBDDocument.TBDDocument?.Building);
                analyticalModel = new AnalyticalModel(analyticalModel, adjacencyCluster);
                if (result)
                {
                    sAMTBDDocument.Save();
                }
            }

            dataAccess.SetData(0, new GooAnalyticalModel(analyticalModel));
            dataAccess.SetData(1, result);
        }
Esempio n. 9
0
        public static List <Core.Result> AddResults(this string path_TSD, AdjacencyCluster adjacencyCLuster)
        {
            if (adjacencyCLuster == null || string.IsNullOrWhiteSpace(path_TSD))
            {
                return(null);
            }

            List <Core.Result> result = null;

            using (SAMTSDDocument sAMTSDDocument = new SAMTSDDocument(path_TSD, true))
            {
                result = AddResults(sAMTSDDocument, adjacencyCLuster);
            }

            return(result);
        }
Esempio n. 10
0
        public static AdjacencyCluster ToSAM_AdjacencyCluster(this string path_TSD, IEnumerable <SpaceDataType> spaceDataTypes = null, IEnumerable <PanelDataType> panelDataTypes = null)
        {
            if (string.IsNullOrWhiteSpace(path_TSD))
            {
                return(null);
            }

            AdjacencyCluster result = null;

            using (SAMTSDDocument sAMTSDDocument = new SAMTSDDocument(path_TSD))
            {
                result = sAMTSDDocument.ToSAM(spaceDataTypes, panelDataTypes);
            }

            return(result);
        }
Esempio n. 11
0
        public static List <Zone> MapZones(this AdjacencyCluster adjacencyCluster)
        {
            if (adjacencyCluster == null)
            {
                return(null);
            }

            TextMap textMap;

            if (!ActiveSetting.Setting.TryGetValue(ActiveSetting.Name.ZoneMap, out textMap) || textMap == null)
            {
                return(null);
            }

            return(Analytical.Modify.MapZones(adjacencyCluster, textMap));
        }
Esempio n. 12
0
        public static string ZoneId(this AdjacencyCluster adjacencyCluster, ZoneSimulationResult zoneSimulationResult)
        {
            if (adjacencyCluster == null || zoneSimulationResult == null)
            {
                return(null);
            }

            Zone zone = adjacencyCluster.GetRelatedObjects <Zone>(zoneSimulationResult).FirstOrDefault();

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

            return(ZoneId(zone));
        }
Esempio n. 13
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)
        {
            SAMObject sAMObject = null;

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

            if (sAMObject is Panel)
            {
                dataAccess.SetDataList(0, new List <global::Topologic.Face> {
                    Analytical.Topologic.Convert.ToTopologic((Panel)sAMObject)
                });
                return;
            }
            else if (sAMObject is AdjacencyCluster)
            {
                dataAccess.SetDataList(0, null);

                AdjacencyCluster adjacencyCluster    = sAMObject as AdjacencyCluster;
                List <Geometry.Spatial.Shell> shells = adjacencyCluster.GetShells();
                if (shells != null)
                {
                    dataAccess.SetDataList(0, shells.ConvertAll(x => Geometry.Topologic.Convert.ToTopologic_Cell(x)));
                }

                return;
            }
            else if (sAMObject is AnalyticalModel)
            {
                dataAccess.SetDataList(0, null);

                AdjacencyCluster adjacencyCluster    = (sAMObject as AnalyticalModel).AdjacencyCluster;
                List <Geometry.Spatial.Shell> shells = adjacencyCluster.GetShells();
                if (shells != null)
                {
                    dataAccess.SetDataList(0, shells.ConvertAll(x => Geometry.Topologic.Convert.ToTopologic_Cell(x)));
                }

                return;
            }

            AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Invalid data");
        }
Esempio n. 14
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(1, false);

            bool run = false;

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

            AdjacencyCluster adjacencyCluster = null;

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

            string path = null;

            dataAccess.GetData <string>(1, ref path);

            double tolerance = Tolerance.Distance;

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

            string gEM = Convert.ToGEM(adjacencyCluster, Tolerance.MacroDistance, tolerance);

            if (!string.IsNullOrWhiteSpace(path))
            {
                System.IO.File.WriteAllText(path, gEM);
            }

            dataAccess.SetData(0, gEM);
            dataAccess.SetData(1, true);
        }
Esempio n. 15
0
        protected override void TrySolveInstance(IGH_DataAccess dataAccess)
        {
            int index = -1;

            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);

            AdjacencyCluster adjacencyCluster = null;

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

            Document document = RhinoInside.Revit.Revit.ActiveDBDocument;

            StartTransaction(document);

            convertSettings.AddParameter("AdjacencyCluster", adjacencyCluster);

            List <Element> elements = Analytical.Revit.Convert.ToRevit(adjacencyCluster, document, convertSettings);

            index = Params.IndexOfOutputParam("elements");
            if (index != -1)
            {
                dataAccess.SetDataList(index, elements);
            }
        }
        /// <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)));
        }
Esempio n. 17
0
        public static AdjacencyCluster UpdateDesignLoads(this string path_TBD, AdjacencyCluster adjacencyCluster)
        {
            if (string.IsNullOrWhiteSpace(path_TBD))
            {
                return(null);
            }

            AdjacencyCluster result = null;

            using (SAMTBDDocument sAMTBDDocument = new SAMTBDDocument(path_TBD, true))
            {
                result = UpdateDesignLoads(sAMTBDDocument.TBDDocument, adjacencyCluster);
                if (result != null)
                {
                    sAMTBDDocument.Save();
                }
            }

            return(result);
        }
Esempio n. 18
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);
        }
Esempio n. 19
0
        public static List <Guid> SetBlinds(this AnalyticalModel analyticalModel, string path_TBD, string path_TSD, string path_TBD_Output = null)
        {
            if (analyticalModel == null || string.IsNullOrWhiteSpace(path_TBD) || string.IsNullOrWhiteSpace(path_TSD))
            {
                return(null);
            }

            AdjacencyCluster adjacencyCluster = analyticalModel.AdjacencyCluster;

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

            List <SAMType> sAMTypes = new List <SAMType>();

            List <Construction> constructions = adjacencyCluster.GetConstructions();

            if (constructions != null)
            {
                sAMTypes.AddRange(constructions);
            }

            List <ApertureConstruction> apertureConstructions = adjacencyCluster.GetApertureConstructions();

            if (apertureConstructions != null)
            {
                sAMTypes.AddRange(apertureConstructions);
            }

            string path = path_TBD;

            if (!string.IsNullOrWhiteSpace(path_TBD_Output))
            {
                System.IO.File.Copy(path_TBD, path_TBD_Output, true);
                path = path_TBD_Output;
            }

            return(SetBlinds(sAMTypes, path, path_TSD));
        }
Esempio n. 20
0
        public static List <Guid> SetBlinds(this IEnumerable <SAMType> sAMTypes, string path_TBD, string path_TSD)
        {
            List <Tuple <SAMType, double, double> > tuples = new List <Tuple <SAMType, double, double> >();

            foreach (SAMType sAMType in sAMTypes)
            {
                double blindSolarGainPerAreaToClose;
                if (!sAMType.TryGetValue("SAM_BuildingElementBlindSolarGainPerAreaToClose", out blindSolarGainPerAreaToClose, true) || double.IsNaN(blindSolarGainPerAreaToClose) || blindSolarGainPerAreaToClose == 0)
                {
                    continue;
                }

                double blindFactor;
                if (!sAMType.TryGetValue("SAM_BuildingElementBlindFactor", out blindFactor, true) || double.IsNaN(blindFactor) || blindFactor == 0)
                {
                    continue;
                }

                tuples.Add(new Tuple <SAMType, double, double> (sAMType, blindSolarGainPerAreaToClose, blindFactor));
            }

            if (tuples == null || tuples.Count == 0)
            {
                return(new List <Guid>());
            }


            AdjacencyCluster adjacencyCluster_TSD = path_TSD.ToSAM_AdjacencyCluster(null, new PanelDataType[] { PanelDataType.ExternalSolarGain });

            throw new NotImplementedException();

            //using (SAMTBDDocument sAMTBDDocument = new SAMTBDDocument(path_TBD))
            //{
            //    result = SetBlinds(sAMTBDDocument, apertureConstructions);
            //    if (result != null)
            //        sAMTBDDocument.Save();
            //}

            //return result;
        }
Esempio n. 21
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);
        }
Esempio n. 22
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);
        }
Esempio n. 23
0
        public static List <Core.Result> AddResults(this SAMTSDDocument sAMTSDDocument, AdjacencyCluster adjacencyCLuster)
        {
            if (sAMTSDDocument == null || adjacencyCLuster == null)
            {
                return(null);
            }

            return(AddResults(sAMTSDDocument.TSDDocument, adjacencyCLuster));
        }
Esempio n. 24
0
        public static AdjacencyCluster AdjacencyCluster(IEnumerable <Space> spaces, IEnumerable <Panel> panels, out List <Topology> topologies, out List <Panel> redundantPanels, double minArea = Tolerance.MacroDistance, bool updatePanels = true, bool tryCellComplexByCells = true, Log log = null, double silverSpacing = Tolerance.MacroDistance, double tolerance = Tolerance.Distance)
        {
            Core.Modify.Add(log, "Method Name: {0}, Tolerance: {1}, Update Panels: {2}", "SAM.Analytical.Topologic.Create.AdjacencyCluster", tolerance, updatePanels);

            topologies      = null;
            redundantPanels = null;

            AdjacencyCluster result = new AdjacencyCluster();

            result.AddObjects(spaces);
            result.AddObjects(panels);

            List <Face> faces = new List <Face>();

            int index = 1;

            foreach (Panel panel in result.GetObjects <Panel>())
            {
                if (panel == null)
                {
                    continue;
                }

                Face face = Convert.ToTopologic(panel);
                if (face == null)
                {
                    continue;
                }

                faces.Add(face);
                Core.Modify.Add(log, "Face {0:D4} added. Panel [{1}]", index, panel.Guid);
                index++;
            }

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

            topologies = new List <Topology>();
            List <Cell> cells = null;

            if (tryCellComplexByCells)
            {
                try
                {
                    Core.Modify.Add(log, "Trying to make CellComplex By Cells");
                    Cluster cluster = Cluster.ByTopologies(faces as IList <Topology>);
                    Core.Modify.Add(log, "Cluster.ByTopologies Done");
                    Topology topology = cluster.SelfMerge();
                    Core.Modify.Add(log, "Cluster SelfMerge Done");
                    if (topology.Cells != null && topology.Cells.Count != 0)
                    {
                        cells = topology.Cells?.ToList();
                        CellComplex cellComplex = null;
                        try
                        {
                            cellComplex = CellComplex.ByCells(cells);
                        }
                        catch (Exception exception)
                        {
                            Core.Modify.Add(log, "Cells could not be taken from CellComplex");
                            Core.Modify.Add(log, "Exception Message: {0}", exception.Message);
                        }

                        if (cellComplex != null && cellComplex.Cells != null && cellComplex.Cells.Count != 0)
                        {
                            topologies.Add(cellComplex);

                            cells = cellComplex.Cells?.ToList();
                        }
                        else
                        {
                            topologies.Add(topology);
                            Core.Modify.Add(log, "Cells taken from Cluster");
                        }
                    }
                }
                catch (Exception exception)
                {
                    Core.Modify.Add(log, "Cannot create CellComplex By Cells or Cells form Cluster SelfMerge");
                    Core.Modify.Add(log, "Exception Message: {0}", exception.Message);
                    cells = null;
                }
            }

            if (cells == null)
            {
                try
                {
                    Core.Modify.Add(log, "Trying to make CellComplex By Faces");
                    CellComplex cellComplex = CellComplex.ByFaces(faces, tolerance);
                    topologies.Add(cellComplex);
                    cells = cellComplex.Cells?.ToList();
                    Core.Modify.Add(log, "CellComplex By Faces Created");
                }
                catch (Exception exception)
                {
                    Core.Modify.Add(log, "Cannot create CellComplex By Faces");
                    Core.Modify.Add(log, "Exception Message: {0}", exception.Message);

                    cells = null;
                }
            }

            if (cells == null || cells.Count == 0)
            {
                Core.Modify.Add(log, "No cells found");
                return(null);
            }

            List <Geometry.Spatial.Shell> shells = cells.ToSAM();

            Core.Modify.Add(log, "Single CellComplex converted to shells");

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

            //Matching spaces with shells
            Dictionary <Geometry.Spatial.Shell, List <Space> > dictionary_Spaces = new Dictionary <Geometry.Spatial.Shell, List <Space> >();

            if (spaces != null)
            {
                foreach (Space space in spaces)
                {
                    if (space == null || space.Location == null || !space.IsPlaced())
                    {
                        continue;
                    }

                    List <Geometry.Spatial.Shell> shells_Temp = Analytical.Query.SpaceShells(shells, space.Location, silverSpacing, tolerance);
                    if (shells_Temp == null || shells_Temp.Count == 0)
                    {
                        continue;
                    }

                    foreach (Geometry.Spatial.Shell shell in shells_Temp)
                    {
                        if (!dictionary_Spaces.TryGetValue(shell, out List <Space> spaces_Shell))
                        {
                            spaces_Shell             = new List <Space>();
                            dictionary_Spaces[shell] = spaces_Shell;
                        }
                        spaces_Shell.Add(space);
                    }
                }
            }

            HashSet <Guid> guids_Updated = new HashSet <Guid>();

            Dictionary <Panel, Face3D> dictionary_Panel_Face3D = new Dictionary <Panel, Face3D>();

            result.GetObjects <Panel>().ForEach(x => dictionary_Panel_Face3D[x] = x.GetFace3D());

            index = 1;
            List <Tuple <Panel, Point3D> > tuples_InternalPoint3D = new List <Tuple <Panel, Point3D> >();

            for (int i = 0; i < shells.Count; i++)
            {
                Geometry.Spatial.Shell shell = shells[i];
                if (shell == null)
                {
                    return(null);
                }

                Core.Modify.Add(log, "Simplifying shell");
                //shell.Simplify(tolerance); // Low tolerance cause of rounding issues
                shell.Simplify();

                Core.Modify.Add(log, "Extracting faces from shell");
                List <Face3D> face3Ds = shell?.Face3Ds;
                if (face3Ds == null)
                {
                    Core.Modify.Add(log, "No face2Ds found in Shell");
                    continue;
                }

                dictionary_Spaces.TryGetValue(shell, out List <Space> spaces_Shell);

                if (spaces_Shell == null || spaces_Shell.Count == 0)
                {
                    Core.Modify.Add(log, "Creating new Space");

                    Point3D location = shell.CalculatedInternalPoint3D(silverSpacing, tolerance);
                    if (location == null)
                    {
                        continue;
                    }

                    Space space = new Space("Cell " + index, location);
                    index++;

                    if (!result.AddObject(space))
                    {
                        continue;
                    }

                    spaces_Shell = new List <Space>()
                    {
                        space
                    };
                    dictionary_Spaces[shell] = spaces_Shell;
                }

                if (spaces_Shell == null || spaces_Shell.Count == 0)
                {
                    continue;
                }

                double volume = double.NaN;
                if (cells[i] != null)
                {
                    Core.Modify.Add(log, "Calculating Volume");
                    volume = CellUtility.Volume(cells[i]);

                    foreach (Space space_Shell in spaces_Shell)
                    {
                        space_Shell.SetValue(SpaceParameter.Volume, volume);
                    }
                }

                Core.Modify.Add(log, "Upadting Panels");
                foreach (Face3D face3D in face3Ds)
                {
                    if (minArea != 0 && face3D.GetArea() <= minArea)
                    {
                        Core.Modify.Add(log, "Face3D is too small");
                        continue;
                    }

                    Core.Modify.Add(log, "Looking for existing Panel");
                    Tuple <Panel, Point3D> tuple_InternalPoint3D = tuples_InternalPoint3D.Find(x => face3D.Inside(x.Item2, tolerance));
                    if (tuple_InternalPoint3D != null)
                    {
                        Core.Modify.Add(log, "Existing Panel found: {0}", tuple_InternalPoint3D.Item1.Guid);
                        foreach (Space space in spaces_Shell)
                        {
                            if (result.AddRelation(space, tuple_InternalPoint3D.Item1))
                            {
                                Core.Modify.Add(log, "Space [{0}] and Panel [{1}] relation added", space.Guid, tuple_InternalPoint3D.Item1.Guid);
                            }
                        }
                        continue;
                    }

                    Core.Modify.Add(log, "Looking for old Panel");
                    //Panel panel_Old = Query.SimilarPanel(face3D, dictionary_Panel_Face3D);
                    //if (panel_Old == null)
                    //    continue;

                    List <Panel> panels_Old = Query.SimilarPanels(face3D, dictionary_Panel_Face3D);
                    if (panels_Old == null || panels_Old.Count == 0)
                    {
                        continue;
                    }

                    Panel panel_Old = panels_Old.First();
                    if (panels_Old.Count > 1)
                    {
                        if (redundantPanels == null)
                        {
                            redundantPanels = new List <Panel>();
                        }

                        panels_Old.RemoveAt(0);
                        redundantPanels.AddRange(panels_Old);
                    }

                    Core.Modify.Add(log, "Old Panel found: {0}", panel_Old.Guid);

                    Panel panel_New = null;

                    if (updatePanels)
                    {
                        if (guids_Updated.Contains(panel_Old.Guid))
                        {
                            panel_New = Analytical.Create.Panel(Guid.NewGuid(), panel_Old, face3D);
                            Core.Modify.Add(log, "Creating new Panel for Old Panel [{0}]. New Panel [{1}]", panel_Old.Guid, panel_New.Guid);
                        }
                        else
                        {
                            panel_New = Analytical.Create.Panel(panel_Old.Guid, panel_Old, face3D);
                            guids_Updated.Add(panel_Old.Guid);
                            Core.Modify.Add(log, "Updating Panel [{0}] with new geometry", panel_New.Guid);
                        }

                        result.AddObject(panel_New);
                    }
                    else
                    {
                        panel_New = Analytical.Create.Panel(panel_Old.Guid, panel_Old, face3D);
                        Core.Modify.Add(log, "Creating temporary Panel for Panel [{0}]", panel_New.Guid);
                    }

                    if (panel_New == null)
                    {
                        continue;
                    }

                    tuples_InternalPoint3D.Add(new Tuple <Panel, Point3D>(panel_New, face3D.InternalPoint3D(tolerance)));

                    foreach (Space space in spaces_Shell)
                    {
                        if (result.AddRelation(space, panel_New))
                        {
                            Core.Modify.Add(log, "Space [{0}] and Panel [{1}] relation added", space.Guid, panel_New.Guid);
                        }
                    }

                    Core.Modify.Add(log, "Adding face finished");
                }
            }

            if (redundantPanels != null && redundantPanels.Count != 0)
            {
                Core.Modify.Add(log, "Solving Redundant Panels");
                foreach (Panel panel in redundantPanels)
                {
                    result.RemoveObject <Panel>(panel.Guid);
                }
            }

            List <Panel> panels_Shading = Analytical.Query.CutShading(result.GetPanels(), panels, tolerance);

            if (panels_Shading != null || panels_Shading.Count != 0)
            {
                foreach (Panel panel_Shading in panels_Shading)
                {
                    result.AddObject(panel_Shading);
                }
            }

            Core.Modify.Add(log, "AdjacencyCluster verification");
            Log log_AdjacencyCluster = Analytical.Create.Log(result);

            if (log != null)
            {
                log.AddRange(log_AdjacencyCluster);
            }

            Core.Modify.Add(log, "Process completed");
            return(result);
        }
Esempio n. 25
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);
        }
Esempio n. 26
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();
        //            }
        //        }
        //    }
        //}
    }
Esempio n. 27
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);
        }
Esempio n. 28
0
        public static List <SAMType> UpdateConstructions(this TBDDocument tBDDocument, AnalyticalModel analyticalModel)
        {
            if (tBDDocument == null || analyticalModel == null)
            {
                return(null);
            }

            Building building = tBDDocument.Building;

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

            AdjacencyCluster adjacencyCluster = analyticalModel.AdjacencyCluster;

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

            adjacencyCluster.SetConstructionsDefaultPanelType();

            List <SAMType> result = new List <SAMType>();

            Dictionary <System.Guid, Construction> dictionary_Construction = new Dictionary <System.Guid, Construction>();

            foreach (Panel panel in adjacencyCluster.GetPanels())
            {
                if (panel == null || panel.PanelType == PanelType.Air)
                {
                    continue;
                }

                Construction construction = panel.Construction;
                if (construction == null)
                {
                    continue;
                }

                dictionary_Construction[construction.Guid] = construction;
            }

            if (dictionary_Construction != null && dictionary_Construction.Count != 0)
            {
                List <Construction> constructions = UpdateConstructions(building, dictionary_Construction.Values, analyticalModel.MaterialLibrary);
                if (constructions != null && constructions.Count != 0)
                {
                    constructions.ForEach(x => result.Add(x));
                }
            }

            List <ApertureConstruction> apertureConstructions = analyticalModel.AdjacencyCluster?.GetApertureConstructions();

            if (apertureConstructions != null && apertureConstructions.Count != 0)
            {
                apertureConstructions = UpdateConstructions(building, apertureConstructions, analyticalModel.MaterialLibrary);
                if (apertureConstructions != null && apertureConstructions.Count != 0)
                {
                    apertureConstructions.ForEach(x => result.Add(x));
                }
            }

            return(result);
        }
Esempio n. 29
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)
        {
            int index;

            bool run = false;

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

            if (!run)
            {
                return;
            }

            index = Params.IndexOfInputParam("_pathTasTSD");
            if (index == -1)
            {
                AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Invalid data");
                return;
            }

            string path_TSD = null;

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

            index = Params.IndexOfInputParam("_pathTasTBD");
            if (index == -1)
            {
                AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Invalid data");
                return;
            }

            string path_TBD = null;

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

            index = Params.IndexOfInputParam("_analyticalObject");
            if (index == -1)
            {
                AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Invalid data");
                return;
            }

            Core.SAMObject sAMObject = null;
            if (!dataAccess.GetData(index, ref sAMObject) || sAMObject == null)
            {
                AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Invalid data");
                return;
            }

            bool unmetHours = false;

            index = Params.IndexOfInputParam("_runUnmetHours_");
            if (index != -1)
            {
                if (!dataAccess.GetData(index, ref unmetHours))
                {
                    unmetHours = true;
                }
            }

            double unmetHoursMargin = 0.5;

            index = Params.IndexOfInputParam("_unmetHoursMargin_");
            if (index != -1)
            {
                if (!dataAccess.GetData(index, ref unmetHoursMargin))
                {
                    unmetHoursMargin = 0.5;
                }
            }

            AdjacencyCluster adjacencyCluster = null;

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

            List <Core.Result> results = null;

            if (adjacencyCluster != null)
            {
                results = Analytical.Tas.Modify.AddResults(path_TSD, adjacencyCluster);

                if (unmetHours)
                {
                    List <Core.Result> results_UnmetHours = Analytical.Tas.Query.UnmetHours(path_TSD, path_TBD, unmetHoursMargin);
                    if (results_UnmetHours != null && results_UnmetHours.Count > 0)
                    {
                        foreach (Core.Result result in results_UnmetHours)
                        {
                            if (result is AdjacencyClusterSimulationResult)
                            {
                                adjacencyCluster.AddObject(result);
                                results.Add(result);
                            }
                            else if (result is SpaceSimulationResult)
                            {
                                SpaceSimulationResult spaceSimulationResult = (SpaceSimulationResult)result;

                                List <SpaceSimulationResult> spaceSimulationResults = Analytical.Tas.Query.Results(results, spaceSimulationResult);
                                if (spaceSimulationResults == null)
                                {
                                    results.Add(spaceSimulationResult);
                                }
                                else
                                {
                                    spaceSimulationResults.ForEach(x => Core.Modify.Copy(spaceSimulationResult, x, SpaceSimulationResultParameter.UnmetHourFirstIndex, SpaceSimulationResultParameter.UnmetHours, SpaceSimulationResultParameter.OccupiedUnmetHours));
                                }
                            }
                        }
                    }
                }

                adjacencyCluster = Analytical.Tas.Modify.UpdateDesignLoads(path_TBD, adjacencyCluster);

                if (sAMObject is AdjacencyCluster)
                {
                    sAMObject = adjacencyCluster;
                }
                else if (sAMObject is AnalyticalModel)
                {
                    sAMObject = new AnalyticalModel((AnalyticalModel)sAMObject, adjacencyCluster);
                }
            }

            index = Params.IndexOfOutputParam("analyticalObject");
            if (index != -1)
            {
                dataAccess.SetData(index, sAMObject);
            }

            index = Params.IndexOfOutputParam("zoneSimulationResultsHeating");
            if (index != -1)
            {
                dataAccess.SetDataList(index, results?.FindAll(x => x is ZoneSimulationResult && ((ZoneSimulationResult)x).LoadType() == LoadType.Heating));
            }

            index = Params.IndexOfOutputParam("spaceSimulationResultsHeating");
            if (index != -1)
            {
                dataAccess.SetDataList(index, results?.FindAll(x => x is SpaceSimulationResult && ((SpaceSimulationResult)x).LoadType() == LoadType.Heating));
            }

            index = Params.IndexOfOutputParam("zoneSimulationResultsCooling");
            if (index != -1)
            {
                dataAccess.SetDataList(index, results?.FindAll(x => x is ZoneSimulationResult && ((ZoneSimulationResult)x).LoadType() == LoadType.Cooling));
            }

            index = Params.IndexOfOutputParam("spaceSimulationResultsCooling");
            if (index != -1)
            {
                dataAccess.SetDataList(index, results?.FindAll(x => x is SpaceSimulationResult && ((SpaceSimulationResult)x).LoadType() == LoadType.Cooling));
            }

            index = Params.IndexOfOutputParam("panelSimulationResultsCooling");
            if (index != -1)
            {
                dataAccess.SetDataList(index, results?.FindAll(x => x is PanelSimulationResult && Analytical.Query.LoadType(((PanelSimulationResult)x)) == LoadType.Cooling));
            }

            index = Params.IndexOfOutputParam("panelSimulationResultsHeating");
            if (index != -1)
            {
                dataAccess.SetDataList(index, results?.FindAll(x => x is PanelSimulationResult && Analytical.Query.LoadType(((PanelSimulationResult)x)) == LoadType.Heating));
            }

            index = Params.IndexOfOutputParam("_adjacencyClusterSimulationResultCooling");
            if (index != -1)
            {
                dataAccess.SetData(index, results?.Find(x => x is AdjacencyClusterSimulationResult && Analytical.Query.LoadType(((AdjacencyClusterSimulationResult)x)) == LoadType.Cooling));
            }

            index = Params.IndexOfOutputParam("adjacencyClusterSimulationResultHeating");
            if (index != -1)
            {
                dataAccess.SetData(index, results?.Find(x => x is AdjacencyClusterSimulationResult && Analytical.Query.LoadType(((AdjacencyClusterSimulationResult)x)) == LoadType.Heating));
            }
        }
Esempio n. 30
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);
        }