Exemple #1
0
        public static List <string> UpdateIZAMs(this TBDDocument tBDDocument, IEnumerable <Space> spaces)
        {
            if (tBDDocument == null || spaces == null)
            {
                return(null);
            }

            Building building = tBDDocument.Building;

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

            building.RemoveIZAMs();

            RemoveSchedules(tBDDocument, "_IZAMSCHED");

            List <IZAM> iZAMs = Create.IZAMs(building, spaces);

            if (iZAMs == null)
            {
                return(new List <string>());
            }

            return(iZAMs.ConvertAll(x => x.name));
        }
Exemple #2
0
        public SAMTBDDocument(string path, bool readOnly = false)
        {
            this.readOnly = readOnly;

            if (string.IsNullOrWhiteSpace(path))
            {
                return;
            }

            if (File.Exists(path))
            {
                FileInfo fileInfo = new FileInfo(path);

                if (Core.Query.Locked(fileInfo))
                {
                    readOnly = true;
                }
            }

            if (File.Exists(path))
            {
                if (readOnly)
                {
                    TBDDocument.openReadOnly(path);
                }
                else
                {
                    TBDDocument.open(path);
                }
            }
            else
            {
                TBDDocument.create(path);
            }
        }
Exemple #3
0
        public static bool TBDSizing(string tbdFile, bool run = false)
        {
            if (!run)
            {
                return(false);
            }

            if (string.IsNullOrEmpty(tbdFile))
            {
                BH.Engine.Base.Compute.RecordError("Please provide a valid TBD file path");
                return(false);
            }

            TBDDocument tbdDocument = new TBDDocument();

            tbdDocument.open(tbdFile);
            if (tbdDocument != null)
            {
                tbdDocument.sizing(0);
            }
            tbdDocument.save();
            tbdDocument.close();

            int intrefcountTBD = 0;

            do
            {
                intrefcountTBD = Marshal.FinalReleaseComObject(tbdDocument);
            } while (intrefcountTBD > 0);
            tbdDocument = null;

            return(true);
        }
        public static bool TBD3dVisualisation(string tbdFile, bool run = false)
        {
            if (!run)
            {
                return(false);
            }

            if (string.IsNullOrEmpty(tbdFile))
            {
                BH.Engine.Base.Compute.RecordError("Please provide a valid TBD file path");
                return(false);
            }


            TBDDocument tbdDocument = new TBDDocument();

            if (tbdDocument != null)
            {
                tbdDocument.openReadOnly(tbdFile);
                tbdDocument.ShowVisualisation();
            }


            return(true);
        }
        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));
        }
        public static bool UpdateBuildingElements(this TBDDocument tBDDocument, AnalyticalModel analyticalModel)
        {
            if (tBDDocument == null || analyticalModel == null)
            {
                return(false);
            }

            Building building = tBDDocument.Building;

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

            UpdateConstructions(tBDDocument, analyticalModel);

            List <buildingElement> buildingElements = building.BuildingElements();

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

            List <TBD.Construction> constructions = building.Constructions();

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

            foreach (buildingElement buildingElement in buildingElements)
            {
                string name = Query.Name(buildingElement);
                if (string.IsNullOrWhiteSpace(name))
                {
                    continue;
                }

                TBD.Construction construction = constructions.Find(x => name.Equals(x.name));
                if (construction == null)
                {
                    List <TBD.Construction> constructions_Temp = constructions.FindAll(x => name.EndsWith(x.name));
                    if (constructions_Temp != null && constructions_Temp.Count != 0)
                    {
                        constructions_Temp.Sort((x, y) => System.Math.Abs(x.name.Length - name.Length).CompareTo(System.Math.Abs(y.name.Length - name.Length)));
                        construction = constructions_Temp.First();
                    }
                }

                if (construction == null)
                {
                    continue;
                }

                buildingElement.AssignConstruction(construction);
            }

            return(true);
        }
Exemple #7
0
        private static bool Sizing_PrepareDocument(string path_TBD, bool excludeOutdoorAir = true)
        {
            if (string.IsNullOrWhiteSpace(path_TBD) || !global::System.IO.File.Exists(path_TBD))
            {
                return(false);
            }

            bool result = false;

            using (SAMTBDDocument sAMTBDDocument = new SAMTBDDocument(path_TBD))
            {
                TBDDocument tBDDocument = sAMTBDDocument.TBDDocument;
                Building    building    = tBDDocument?.Building;
                if (building != null)
                {
                    SizingType sizingType = SizingType.tbdSizing;

                    List <zone> zones = building.Zones();
                    foreach (zone zone in zones)
                    {
                        zone.sizeCooling    = (int)sizingType;
                        zone.sizeHeating    = (int)sizingType;
                        zone.maxCoolingLoad = 0;
                        zone.maxHeatingLoad = 0;
                    }

                    List <TBD.InternalCondition> internalConditions = building.InternalConditions();
                    for (int i = internalConditions.Count - 1; i >= 0; i--)
                    {
                        TBD.InternalCondition internalCondition = building.GetIC(i);
                        if (internalCondition.name.EndsWith("HDD"))
                        {
                            if (excludeOutdoorAir)
                            {
                                profile profile = internalCondition.GetInternalGain()?.GetProfile((int)Profiles.ticV);
                                if (profile != null)
                                {
                                    profile.factor = 0;
                                }
                            }

                            //while (internalCondition.GetZone(0) != null)
                            //{
                            //    zone zone = internalCondition.GetZone(0);
                            //    zone.AssignIC(internalCondition, false);
                            //}
                        }
                    }

                    sAMTBDDocument.Save();
                    result = true;
                }
            }

            return(result);
        }
Exemple #8
0
        public static List <Guid> SetBlinds(this TBDDocument tBDDocument, IEnumerable <ApertureConstruction> apertureConstructions)
        {
            if (tBDDocument == null || apertureConstructions == null)
            {
                return(null);
            }

            Building builidng = tBDDocument.Building;

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

            builidng.RemoveApertureTypes();
            tBDDocument.RemoveSchedules("_APSCHED");

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

            List <buildingElement> buildingElements = builidng.BuildingElements();

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

            List <dayType> dayTypes = builidng.DayTypes();

            dayTypes.RemoveAll(x => x.name.Equals("CDD") || x.name.Equals("HDD"));

            foreach (ApertureConstruction apertureConstruction in apertureConstructions)
            {
                string paneApertureConstructionName = apertureConstruction.PaneApertureConstructionUniqueName();

                buildingElement buildingElement = buildingElements.Find(x => x.name.Equals(paneApertureConstructionName));
                if (buildingElement == null)
                {
                    continue;
                }

                if (builidng.AssignApertureTypes(buildingElement, dayTypes, apertureConstruction))
                {
                    Guid guid;
                    if (Guid.TryParse(buildingElement.GUID, out guid))
                    {
                        result.Add(guid);
                    }
                }
            }

            return(result);
        }
Exemple #9
0
        public static bool TBDSizing(string tbdFile, int startDay = 0, int endDay = 365, bool autoViewResults = false, bool run = false)
        {
            if (!run)
            {
                return(false);
            }

            if (!run)
            {
                return(false);
            }

            if (string.IsNullOrEmpty(tbdFile))
            {
                BH.Engine.Base.Compute.RecordError("Please provide a valid TBD file path");
                return(false);
            }

            TBDDocument tbdDocument = new TBDDocument();

            tbdDocument.open(tbdFile);

            string tsdFile = tbdFile.Replace(".tbd", ".tsd");

            if (tbdDocument != null)
            {
                tbdDocument.simulate(startDay, endDay, autoViewResults ? 1 : 0, 1, 0, 0, tsdFile, 0, 0);
                tbdDocument.save();
                tbdDocument.close();
            }

            int intrefcountTBD = 0;

            do
            {
                intrefcountTBD = Marshal.FinalReleaseComObject(tbdDocument);
            } while (intrefcountTBD > 0);
            tbdDocument = null;

            return(true);
        }
Exemple #10
0
        private static bool Sizing_ApplyOversizingFactors(string path_TBD, AnalyticalModel analyticalModel = null)
        {
            if (string.IsNullOrWhiteSpace(path_TBD) || !global::System.IO.File.Exists(path_TBD))
            {
                return(false);
            }

            bool result = false;

            using (SAMTBDDocument sAMTBDDocument = new SAMTBDDocument(path_TBD))
            {
                TBDDocument tBDDocument = sAMTBDDocument.TBDDocument;
                Building    building    = tBDDocument?.Building;
                if (building != null)
                {
                    Modify.UpdateSizingFactors(building, analyticalModel);

                    List <buildingElement> buildingElements = building.BuildingElements();
                    foreach (buildingElement buildingElement in buildingElements)
                    {
                        if (!buildingElement.name.Contains("_AIR"))
                        {
                            continue;
                        }

                        buildingElement.ghost = 1;
                        buildingElement.AssignConstruction(null);
                    }

                    sAMTBDDocument.Save();
                    result = true;
                }
            }

            return(result);
        }
        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);
        }
Exemple #12
0
        public static List <Space> UpdateDesignLoads(this BuildingModel buildingModel, TBDDocument tBDDocument)
        {
            if (tBDDocument == null || buildingModel == null)
            {
                return(null);
            }

            Building building = tBDDocument.Building;

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

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

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

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

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

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

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

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

                result.Add(space);

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

                buildingModel.Add(space);

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

                    if (spaceSimulationResult != null)
                    {
                        buildingModel.Add(spaceSimulationResult, space);
                    }
                }
            }

            return(result);
        }
Exemple #13
0
        private static bool Sizing_ApplyAirGlass(string path_TBD, bool excludePositiveInternalGains = false)
        {
            if (string.IsNullOrWhiteSpace(path_TBD) || !global::System.IO.File.Exists(path_TBD))
            {
                return(false);
            }

            bool result = false;

            using (SAMTBDDocument sAMTBDDocument = new SAMTBDDocument(path_TBD))
            {
                TBDDocument tBDDocument = sAMTBDDocument.TBDDocument;
                Building    building    = tBDDocument?.Building;
                if (building != null)
                {
                    TBD.Construction construction = building.GetConstructionByName("Air_Glass");
                    if (construction == null)
                    {
                        construction      = building.AddConstruction(null);
                        construction.name = "Air_Glass";
                        construction.type = TBD.ConstructionTypes.tcdTransparentConstruction;
                        material material = construction.AddMaterial();
                        material.name                  = "Air_Glass";
                        material.description           = "Special for HDD sizing";
                        material.type                  = (int)MaterialTypes.tcdTransparentLayer;
                        material.width                 = global::System.Convert.ToSingle(0.02 / 1000);
                        material.conductivity          = 1;
                        material.vapourDiffusionFactor = 1;
                        material.solarTransmittance    = 0.999999f;
                        material.externalEmissivity    = 0.00001f;
                        material.internalEmissivity    = 0.00001f;
                    }

                    List <buildingElement> buildingElements = building.BuildingElements();
                    foreach (buildingElement buildingElement in buildingElements)
                    {
                        if (!buildingElement.name.Contains("_AIR"))
                        {
                            continue;
                        }

                        buildingElement.ghost = 0;
                        buildingElement.AssignConstruction(construction);
                    }

                    if (excludePositiveInternalGains)
                    {
                        Sizing_ExcludePositiveInternalGains(tBDDocument);
                    }
                    else
                    {
                        SizingType sizingType = SizingType.tbdDesignSizingOnly;

                        List <zone> zones = building.Zones();
                        foreach (zone zone in zones)
                        {
                            zone.sizeCooling = (int)sizingType;
                            zone.sizeHeating = (int)sizingType;
                        }

                        tBDDocument.sizing(0);
                    }

                    sAMTBDDocument.Save();
                    result = true;
                }
            }

            return(result);
        }
Exemple #14
0
        private static bool Sizing_ExcludePositiveInternalGains(this TBDDocument tBDDocument)
        {
            if (tBDDocument == null)
            {
                return(false);
            }

            List <zone> zones = tBDDocument?.Building?.Zones();

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

            SizingType sizingType = SizingType.tbdDesignSizingOnly;

            List <Tuple <zone, TBD.InternalCondition, double> > tuples = new List <Tuple <zone, TBD.InternalCondition, double> >();

            foreach (zone zone in zones)
            {
                zone.sizeHeating = (int)sizingType;
                zone.sizeCooling = (int)sizingType;

                List <TBD.InternalCondition> internalConditions = zone.InternalConditions();
                if (internalConditions == null || internalConditions.Count == 0)
                {
                    tuples.Add(new Tuple <zone, TBD.InternalCondition, double>(zone, null, -50));
                    continue;
                }

                TBD.InternalCondition internalCondition = internalConditions.Find(x => x.name.EndsWith(" - HDD"));
                if (internalCondition == null)
                {
                    tuples.Add(new Tuple <zone, TBD.InternalCondition, double>(zone, null, -50));
                    continue;
                }

                tuples.Add(new Tuple <zone, TBD.InternalCondition, double>(zone, internalCondition, internalCondition.GetLowerLimit()));
            }

            List <double> temperatures_Unique = tuples.ConvertAll(x => x.Item3).Distinct().ToList();

            temperatures_Unique.Sort();

            if (temperatures_Unique.Count == 0)
            {
                return(false);
            }

            Dictionary <zone, double> dictionary = new Dictionary <zone, double>();

            foreach (double tempearture in temperatures_Unique)
            {
                if (tempearture <= -50)
                {
                    continue;
                }

                //Here we filter room that have higher temperature than current set point
                List <Tuple <zone, TBD.InternalCondition, double> > tuples_Temperature = tuples.FindAll(x => x.Item3 >= tempearture);

                foreach (Tuple <zone, TBD.InternalCondition, double> tuple in tuples_Temperature)
                {
                    Thermostat thermostat = tuple.Item2?.GetThermostat();
                    if (thermostat == null)
                    {
                        continue;
                    }

                    profile profile = thermostat.GetProfile((int)Profiles.ticLL);
                    if (profile == null)
                    {
                        continue;
                    }

                    profile.value = global::System.Convert.ToSingle(tempearture);
                }

                tBDDocument.save();
                tBDDocument.sizing(0);

                tuples_Temperature = tuples_Temperature.FindAll(x => x.Item3 == tempearture);
                foreach (Tuple <zone, TBD.InternalCondition, double> tuple in tuples_Temperature)
                {
                    if (!dictionary.ContainsKey(tuple.Item1))
                    {
                        dictionary[tuple.Item1] = tuple.Item1.maxHeatingLoad;
                    }
                }
            }

            sizingType = SizingType.tbdNoSizing;
            foreach (KeyValuePair <zone, double> keyValuePair in dictionary)
            {
                zone zone = keyValuePair.Key;

                zone.sizeCooling = (int)sizingType;
                zone.sizeHeating = (int)sizingType;

                zone.maxHeatingLoad = global::System.Convert.ToSingle(keyValuePair.Value);
            }

            return(true);
        }