Esempio n. 1
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);
        }
        /// <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. 3
0
        public static bool UpdateWeatherData(string path_TBD, WeatherData weatherData)
        {
            if (string.IsNullOrWhiteSpace(path_TBD) || weatherData == null)
            {
                return(false);
            }

            bool result = false;

            using (SAMTBDDocument sAMTBDDocument = new SAMTBDDocument(path_TBD))
            {
                result = UpdateWeatherData(sAMTBDDocument, weatherData);
                if (result)
                {
                    sAMTBDDocument.Save();
                }
            }

            return(result);
        }
Esempio n. 4
0
        public static AnalyticalModel UpdateFacingExternal(this AnalyticalModel analyticalModel, string path_TBD)
        {
            if (analyticalModel == null || string.IsNullOrWhiteSpace(path_TBD))
            {
                return(null);
            }

            AnalyticalModel result = null;

            using (SAMTBDDocument sAMTBDDocument = new SAMTBDDocument(path_TBD))
            {
                result = UpdateFacingExternal(analyticalModel, sAMTBDDocument);
                if (result != null)
                {
                    sAMTBDDocument.Save();
                }
            }

            return(result);
        }
Esempio n. 5
0
        public static bool UpdateBuildingElements(this string path_TBD, AnalyticalModel analyticalModel)
        {
            if (string.IsNullOrWhiteSpace(path_TBD))
            {
                return(false);
            }

            bool result = false;

            using (SAMTBDDocument sAMTBDDocument = new SAMTBDDocument(path_TBD))
            {
                result = UpdateBuildingElements(sAMTBDDocument, analyticalModel);
                if (result)
                {
                    sAMTBDDocument.Save();
                }
            }

            return(result);
        }
Esempio n. 6
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. 7
0
        public static bool UpdateShading(string path_TBD, AnalyticalModel analyticalModel, double tolerance = Core.Tolerance.Distance)
        {
            if (analyticalModel == null || string.IsNullOrWhiteSpace(path_TBD))
            {
                return(false);
            }

            bool result = false;

            using (SAMTBDDocument sAMTBDDocument = new SAMTBDDocument(path_TBD))
            {
                result = UpdateShading(sAMTBDDocument?.TBDDocument, analyticalModel, tolerance);
                if (result)
                {
                    sAMTBDDocument.Save();
                }
            }

            return(result);
        }
        public static List <Guid> AssignBuildingElementType(this string path_TBD, TBD.BuildingElementType buildingElementType, IEnumerable <string> names, bool caseSensitive = true, bool trim = false)
        {
            if (string.IsNullOrWhiteSpace(path_TBD))
            {
                return(null);
            }

            List <Guid> result = null;

            using (SAMTBDDocument sAMTBDDocument = new SAMTBDDocument(path_TBD))
            {
                result = AssignBuildingElementType(sAMTBDDocument, buildingElementType, names, caseSensitive, trim);
                if (result != null)
                {
                    sAMTBDDocument.Save();
                }
            }

            return(result);
        }
Esempio n. 9
0
        public static List <Guid> AssignAdiabaticConstruction(this string path_TBD, string constructionName_Adiabatic, IEnumerable <string> constructionNames_Sufixes, bool caseSensitive = true, bool trim = false)
        {
            if (string.IsNullOrWhiteSpace(path_TBD))
            {
                return(null);
            }

            List <Guid> result = null;

            using (SAMTBDDocument sAMTBDDocument = new SAMTBDDocument(path_TBD))
            {
                result = AssignAdiabaticConstruction(sAMTBDDocument, constructionName_Adiabatic, constructionNames_Sufixes, caseSensitive, trim);
                if (result != null)
                {
                    sAMTBDDocument.Save();
                }
            }

            return(result);
        }
Esempio n. 10
0
        public static bool UpdateZones(this AnalyticalModel analyticalModel, string path_TBD, bool includeHDD = false)
        {
            if (analyticalModel == null || string.IsNullOrWhiteSpace(path_TBD))
            {
                return(false);
            }

            bool result = false;

            using (SAMTBDDocument sAMTBDDocument = new SAMTBDDocument(path_TBD))
            {
                result = UpdateZones(analyticalModel, sAMTBDDocument, includeHDD);
                if (result)
                {
                    sAMTBDDocument.Save();
                }
            }

            return(result);
        }
Esempio n. 11
0
        public static AnalyticalModel UpdateDesignLoads(this string path_TBD, AnalyticalModel analyticalModel)
        {
            if (string.IsNullOrWhiteSpace(path_TBD))
            {
                return(null);
            }

            AnalyticalModel result = null;

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

            return(result);
        }
Esempio n. 12
0
        public static List <string> RemoveSchedules(this string path_TBD, string sufix, bool caseSensitive = true, bool trim = false)
        {
            if (string.IsNullOrWhiteSpace(path_TBD))
            {
                return(null);
            }

            List <string> result = null;

            using (SAMTBDDocument sAMTBDDocument = new SAMTBDDocument(path_TBD))
            {
                result = RemoveSchedules(sAMTBDDocument, sufix, caseSensitive, trim);
                if (result != null)
                {
                    sAMTBDDocument.Save();
                }
            }

            return(result);
        }
Esempio n. 13
0
        public static List <string> UpdateIZAMs(this string path_TBD, IEnumerable <Space> spaces)
        {
            if (string.IsNullOrWhiteSpace(path_TBD))
            {
                return(null);
            }

            List <string> result = null;

            using (SAMTBDDocument sAMTBDDocument = new SAMTBDDocument(path_TBD))
            {
                result = UpdateIZAMs(sAMTBDDocument, spaces);
                if (result != null)
                {
                    sAMTBDDocument.Save();
                }
            }

            return(result);
        }
Esempio n. 14
0
        public static List <Guid> UpdateApertureControl(this string path_TBD, IEnumerable <ApertureConstruction> apertureConstructions)
        {
            if (string.IsNullOrWhiteSpace(path_TBD))
            {
                return(null);
            }

            List <Guid> result = null;

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

            return(result);
        }
Esempio n. 15
0
        public static List <Guid> AddDesignDays(this string path_TBD, IEnumerable <DesignDay> coolingDesignDays, IEnumerable <DesignDay> heatingDesignDays, int repetitions = 30)
        {
            if (string.IsNullOrWhiteSpace(path_TBD) || (coolingDesignDays == null && heatingDesignDays == null))
            {
                return(null);
            }

            List <Guid> result = null;

            using (SAMTBDDocument sAMTBDDocument = new SAMTBDDocument(path_TBD))
            {
                result = AddDesignDays(sAMTBDDocument, coolingDesignDays, heatingDesignDays, repetitions);
                if (result != null)
                {
                    sAMTBDDocument.Save();
                }
            }

            return(result);
        }
Esempio n. 16
0
        public static List <SAMType> UpdateConstructions(this string path_TBD, AnalyticalModel analyticalModel)
        {
            if (string.IsNullOrWhiteSpace(path_TBD))
            {
                return(null);
            }

            List <SAMType> result = null;

            using (SAMTBDDocument sAMTBDDocument = new SAMTBDDocument(path_TBD))
            {
                result = UpdateConstructions(sAMTBDDocument, analyticalModel);
                if (result != null)
                {
                    sAMTBDDocument.Save();
                }
            }

            return(result);
        }
Esempio n. 17
0
        public static List <Space> UpdateDesignLoads(this BuildingModel buildingModel, string path_TBD)
        {
            if (string.IsNullOrWhiteSpace(path_TBD))
            {
                return(null);
            }

            List <Space> result = null;

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

            return(result);
        }
Esempio n. 18
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);
        }
Esempio n. 19
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_successful = Params.IndexOfOutputParam("successful");

            if (index_successful != -1)
            {
                dataAccess.SetData(index_successful, false);
            }

            int index;

            bool run = false;

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

            if (!run)
            {
                return;
            }

            string path = null;

            index = Params.IndexOfInputParam("_path_TBD");
            if (index == -1 || !dataAccess.GetData(index, ref path) || string.IsNullOrWhiteSpace(path))
            {
                AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Invalid data");
                return;
            }

            AnalyticalModel analyticalModel = null;

            index = Params.IndexOfInputParam("_analyticalModel");
            if (index == -1 || !dataAccess.GetData(index, ref analyticalModel) || string.IsNullOrWhiteSpace(path))
            {
                AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Invalid data");
                return;
            }

            WeatherData weatherData = null;

            index = Params.IndexOfInputParam("weatherData_");
            if (index != -1)
            {
                if (!dataAccess.GetData(index, ref weatherData))
                {
                    weatherData = null;
                }
            }

            List <DesignDay> heatingDesignDays = new List <DesignDay>();

            index = Params.IndexOfInputParam("heatingDesignDays_");
            if (index == -1 || !dataAccess.GetDataList(index, heatingDesignDays) || heatingDesignDays == null || heatingDesignDays.Count == 0)
            {
                heatingDesignDays = null;
            }

            List <DesignDay> coolingDesignDays = new List <DesignDay>();

            index = Params.IndexOfInputParam("coolingDesignDays_");
            if (index == -1 || !dataAccess.GetDataList(index, coolingDesignDays) || coolingDesignDays == null || coolingDesignDays.Count == 0)
            {
                coolingDesignDays = null;
            }

            if (System.IO.File.Exists(path))
            {
                System.IO.File.Delete(path);
            }

            using (SAMTBDDocument sAMTBDDocument = new SAMTBDDocument(path))
            {
                TBD.TBDDocument tBDDocument = sAMTBDDocument.TBDDocument;

                if (weatherData != null)
                {
                    Weather.Tas.Modify.UpdateWeatherData(tBDDocument, weatherData);
                }

                TBD.Calendar calendar = tBDDocument.Building.GetCalendar();

                List <TBD.dayType> dayTypes = Grashopper.Tas.Query.DayTypes(calendar);
                if (dayTypes.Find(x => x.name == "HDD") == null)
                {
                    TBD.dayType dayType = calendar.AddDayType();
                    dayType.name = "HDD";
                }

                if (dayTypes.Find(x => x.name == "CDD") == null)
                {
                    TBD.dayType dayType = calendar.AddDayType();
                    dayType.name = "CDD";
                }

                Analytical.Tas.Convert.ToTBD(analyticalModel, tBDDocument);
                Analytical.Tas.Modify.UpdateZones(tBDDocument.Building, analyticalModel, true);

                if (coolingDesignDays != null || heatingDesignDays != null)
                {
                    Analytical.Tas.Modify.AddDesignDays(tBDDocument, coolingDesignDays, heatingDesignDays, 30);
                }

                sAMTBDDocument.Save();
            }

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

            if (index_successful != -1)
            {
                dataAccess.SetData(index_successful, true);
            }
        }
Esempio n. 20
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_successful = Params.IndexOfOutputParam("successful");

            if (index_successful != -1)
            {
                dataAccess.SetData(index_successful, false);
            }

            int index;

            bool run = false;

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

            if (!run)
            {
                return;
            }

            string path_TBD = null;

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

            AnalyticalModel analyticalModel = null;

            index = Params.IndexOfInputParam("_analyticalModel");
            if (index == -1 || !dataAccess.GetData(index, ref analyticalModel) || string.IsNullOrWhiteSpace(path_TBD))
            {
                AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Invalid data");
                return;
            }

            WeatherData weatherData = null;

            index = Params.IndexOfInputParam("weatherData_");
            if (index != -1)
            {
                if (!dataAccess.GetData(index, ref weatherData))
                {
                    weatherData = null;
                }
            }

            List <DesignDay> heatingDesignDays = new List <DesignDay>();

            index = Params.IndexOfInputParam("heatingDesignDays_");
            if (index == -1 || !dataAccess.GetDataList(index, heatingDesignDays) || heatingDesignDays == null || heatingDesignDays.Count == 0)
            {
                heatingDesignDays = null;
            }

            List <DesignDay> coolingDesignDays = new List <DesignDay>();

            index = Params.IndexOfInputParam("coolingDesignDays_");
            if (index == -1 || !dataAccess.GetDataList(index, coolingDesignDays) || coolingDesignDays == null || coolingDesignDays.Count == 0)
            {
                coolingDesignDays = null;
            }

            List <SurfaceOutputSpec> surfaceOutputSpecs = null;

            List <GH_ObjectWrapper> objectWrappers = new List <GH_ObjectWrapper>();

            index = Params.IndexOfInputParam("surfaceOutputSpec_");
            if (index != -1 && dataAccess.GetDataList(index, objectWrappers) && objectWrappers != null && objectWrappers.Count != 0)
            {
                surfaceOutputSpecs = new List <SurfaceOutputSpec>();
                foreach (GH_ObjectWrapper objectWrapper in objectWrappers)
                {
                    object value = objectWrapper.Value;
                    if (value is IGH_Goo)
                    {
                        value = (value as dynamic)?.Value;
                    }

                    if (value is bool && ((bool)value))
                    {
                        SurfaceOutputSpec surfaceOutputSpec = new SurfaceOutputSpec("Tas.Simulate");
                        surfaceOutputSpec.SolarGain    = true;
                        surfaceOutputSpec.Conduction   = true;
                        surfaceOutputSpec.ApertureData = false;
                        surfaceOutputSpec.Condensation = false;
                        surfaceOutputSpec.Convection   = false;
                        surfaceOutputSpec.LongWave     = false;
                        surfaceOutputSpec.Temperature  = false;

                        surfaceOutputSpecs.Add(surfaceOutputSpec);
                    }
                    else if (Core.Query.IsNumeric(value) && Core.Query.TryConvert(value, out double @double) && @double == 2.0)
                    {
                        surfaceOutputSpecs = new List <SurfaceOutputSpec>()
                        {
                            new SurfaceOutputSpec("Tas.Simulate")
                        };
                        surfaceOutputSpecs[0].SolarGain    = true;
                        surfaceOutputSpecs[0].Conduction   = true;
                        surfaceOutputSpecs[0].ApertureData = true;
                        surfaceOutputSpecs[0].Condensation = true;
                        surfaceOutputSpecs[0].Convection   = true;
                        surfaceOutputSpecs[0].LongWave     = true;
                        surfaceOutputSpecs[0].Temperature  = true;
                    }
                    else if (value is SurfaceOutputSpec)
                    {
                        surfaceOutputSpecs.Add((SurfaceOutputSpec)value);
                    }
                }
            }

            bool unmetHours = false;

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

            if (System.IO.File.Exists(path_TBD))
            {
                System.IO.File.Delete(path_TBD);
            }

            using (SAMTBDDocument sAMTBDDocument = new SAMTBDDocument(path_TBD))
            {
                TBD.TBDDocument tBDDocument = sAMTBDDocument.TBDDocument;

                if (weatherData != null)
                {
                    Weather.Tas.Modify.UpdateWeatherData(tBDDocument, weatherData);
                }

                TBD.Calendar calendar = tBDDocument.Building.GetCalendar();

                List <TBD.dayType> dayTypes = Grashopper.Tas.Query.DayTypes(calendar);
                if (dayTypes.Find(x => x.name == "HDD") == null)
                {
                    TBD.dayType dayType = calendar.AddDayType();
                    dayType.name = "HDD";
                }

                if (dayTypes.Find(x => x.name == "CDD") == null)
                {
                    TBD.dayType dayType = calendar.AddDayType();
                    dayType.name = "CDD";
                }

                Analytical.Tas.Convert.ToTBD(analyticalModel, tBDDocument);
                Analytical.Tas.Modify.UpdateZones(tBDDocument.Building, analyticalModel, true);

                if (coolingDesignDays != null || heatingDesignDays != null)
                {
                    Analytical.Tas.Modify.AddDesignDays(tBDDocument, coolingDesignDays, heatingDesignDays, 30);
                }

                sAMTBDDocument.Save();
            }

            analyticalModel = Analytical.Tas.Modify.RunWorkflow(analyticalModel, path_TBD, null, weatherData, heatingDesignDays, coolingDesignDays, surfaceOutputSpecs, unmetHours);

            index = Params.IndexOfOutputParam("_path_TSD");
            if (index != -1)
            {
                string directory = System.IO.Path.GetDirectoryName(path_TBD);
                string fileName  = System.IO.Path.GetFileNameWithoutExtension(path_TBD);

                string path_TSD = System.IO.Path.Combine(directory, string.Format("{0}.{1}", fileName, "tsd"));

                dataAccess.SetData(index, path_TSD);
            }

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

            if (index_successful != -1)
            {
                dataAccess.SetData(index_successful, true);
            }
        }
Esempio n. 21
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);
        }
Esempio n. 22
0
        public static AnalyticalModel RunWorkflow(this AnalyticalModel analyticalModel, string path_TBD, string path_gbXML = null, Weather.WeatherData weatherData = null, List <DesignDay> heatingDesignDays = null, List <DesignDay> coolingDesignDays = null, List <SurfaceOutputSpec> surfaceOutputSpecs = null, bool unmetHours = true)
        {
            if (analyticalModel == null || string.IsNullOrWhiteSpace(path_TBD))
            {
                return(null);
            }

            string directory = System.IO.Path.GetDirectoryName(path_TBD);
            string fileName  = System.IO.Path.GetFileNameWithoutExtension(path_TBD);

            string path_TSD = System.IO.Path.Combine(directory, string.Format("{0}.{1}", fileName, "tsd"));

            if (!string.IsNullOrWhiteSpace(path_gbXML))
            {
                string path_T3D = System.IO.Path.Combine(directory, string.Format("{0}.{1}", fileName, "t3d"));

                string guid = null;
                using (SAMT3DDocument sAMT3DDocument = new SAMT3DDocument(path_T3D))
                {
                    TAS3D.T3DDocument t3DDocument = sAMT3DDocument.T3DDocument;
                    guid = t3DDocument.Building.GUID;
                    sAMT3DDocument.Save();
                }

                float latitude  = float.NaN;
                float longitude = float.NaN;
                float timeZone  = float.NaN;
                using (SAMTBDDocument sAMTBDDocument = new SAMTBDDocument(path_TBD))
                {
                    TBD.TBDDocument tBDDocument = sAMTBDDocument.TBDDocument;

                    if (weatherData != null)
                    {
                        Weather.Tas.Modify.UpdateWeatherData(tBDDocument, weatherData);
                    }

                    if (!string.IsNullOrWhiteSpace(guid))
                    {
                        tBDDocument.Building.GUID = guid;
                    }

                    TBD.Calendar calendar = tBDDocument.Building.GetCalendar();

                    List <TBD.dayType> dayTypes = Query.DayTypes(calendar);
                    if (dayTypes.Find(x => x.name == "HDD") == null)
                    {
                        TBD.dayType dayType = calendar.AddDayType();
                        dayType.name = "HDD";
                    }

                    if (dayTypes.Find(x => x.name == "CDD") == null)
                    {
                        TBD.dayType dayType = calendar.AddDayType();
                        dayType.name = "CDD";
                    }

                    latitude  = tBDDocument.Building.latitude;
                    longitude = tBDDocument.Building.longitude;
                    timeZone  = tBDDocument.Building.timeZone;

                    sAMTBDDocument.Save();
                }

                using (SAMT3DDocument sAMT3DDocument = new SAMT3DDocument(path_T3D))
                {
                    TAS3D.T3DDocument t3DDocument = sAMT3DDocument.T3DDocument;

                    t3DDocument.TogbXML(path_gbXML, true, true, true);
                    t3DDocument.SetUseBEWidths(false);
                    analyticalModel = Query.UpdateT3D(analyticalModel, t3DDocument);

                    t3DDocument.Building.latitude  = float.IsNaN(latitude) ? t3DDocument.Building.latitude : latitude;
                    t3DDocument.Building.longitude = float.IsNaN(longitude) ? t3DDocument.Building.longitude : longitude;
                    t3DDocument.Building.timeZone  = float.IsNaN(timeZone) ? t3DDocument.Building.timeZone : timeZone;

                    sAMT3DDocument.Save();

                    Convert.ToTBD(t3DDocument, path_TBD, 1, 365, 15, true);
                }
            }

            AdjacencyCluster adjacencyCluster = null;

            bool hasWeatherData = false;

            using (SAMTBDDocument sAMTBDDocument = new SAMTBDDocument(path_TBD))
            {
                TBD.TBDDocument tBDDocument = sAMTBDDocument.TBDDocument;

                hasWeatherData = tBDDocument?.Building.GetWeatherYear() != null;

                analyticalModel = Query.UpdateFacingExternal(analyticalModel, tBDDocument);
                AssignAdiabaticConstruction(tBDDocument, "Adiabatic", new string[] { "-unzoned", "-internal", "-exposed" }, false, true);
                UpdateBuildingElements(tBDDocument, analyticalModel);

                adjacencyCluster = analyticalModel.AdjacencyCluster;
                UpdateThermalParameters(adjacencyCluster, tBDDocument.Building);
                analyticalModel = new AnalyticalModel(analyticalModel, adjacencyCluster);

                UpdateZones(tBDDocument.Building, analyticalModel, true);

                if (coolingDesignDays != null || heatingDesignDays != null)
                {
                    AddDesignDays(tBDDocument, coolingDesignDays, heatingDesignDays, 30);
                }

                sAMTBDDocument.Save();
            }

            if (!hasWeatherData)
            {
                return(new AnalyticalModel(analyticalModel, adjacencyCluster));
            }

            Query.Sizing(path_TBD, analyticalModel, false, true);

            using (SAMTBDDocument sAMTBDDocument = new SAMTBDDocument(path_TBD))
            {
                TBD.TBDDocument tBDDocument = sAMTBDDocument.TBDDocument;

                if (surfaceOutputSpecs != null && surfaceOutputSpecs.Count > 0)
                {
                    Core.Tas.Modify.UpdateSurfaceOutputSpecs(tBDDocument, surfaceOutputSpecs);
                    Core.Tas.Modify.AssignSurfaceOutputSpecs(tBDDocument, surfaceOutputSpecs[0].Name);
                    sAMTBDDocument.Save();
                }

                Simulate(tBDDocument, path_TSD, 1, 1);
            }

            adjacencyCluster = analyticalModel.AdjacencyCluster;
            List <Core.Result> results = AddResults(path_TSD, adjacencyCluster);

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

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

            AnalyticalModel analyticalModel_Temp = new AnalyticalModel(analyticalModel, adjacencyCluster);

            //if (System.IO.File.Exists(path_TSD))
            //{
            //    string path_TPD = System.IO.Path.Combine(directory, string.Format("{0}.{1}", fileName, "tpd"));

            //    CreateTPD(path_TPD, path_TSD, analyticalModel_Temp);
            //}

            adjacencyCluster = UpdateDesignLoads(path_TBD, analyticalModel_Temp.AdjacencyCluster);

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

            bool run = false;

            if (!dataAccess.GetData(5, 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;
            }

            string path_TSD = null;

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

            int day_First = -1;

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

            int day_Last = -1;

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

            List <SurfaceOutputSpec> surfaceOutputSpecs = null;

            List <GH_ObjectWrapper> objectWrappers = new List <GH_ObjectWrapper>();

            if (dataAccess.GetDataList(2, objectWrappers) && objectWrappers != null && objectWrappers.Count != 0)
            {
                surfaceOutputSpecs = new List <SurfaceOutputSpec>();
                foreach (GH_ObjectWrapper objectWrapper in objectWrappers)
                {
                    object value = objectWrapper.Value;
                    if (value is IGH_Goo)
                    {
                        value = (value as dynamic)?.Value;
                    }

                    if (value is bool && ((bool)value))
                    {
                        SurfaceOutputSpec surfaceOutputSpec = new SurfaceOutputSpec("Tas.Simulate");
                        surfaceOutputSpec.SolarGain    = true;
                        surfaceOutputSpec.Conduction   = true;
                        surfaceOutputSpec.ApertureData = false;
                        surfaceOutputSpec.Condensation = false;
                        surfaceOutputSpec.Convection   = false;
                        surfaceOutputSpec.LongWave     = false;
                        surfaceOutputSpec.Temperature  = false;

                        surfaceOutputSpecs.Add(surfaceOutputSpec);
                    }
                    else if (Core.Query.IsNumeric(value) && Core.Query.TryConvert(value, out double @double) && @double == 2.0)
                    {
                        surfaceOutputSpecs = new List <SurfaceOutputSpec>()
                        {
                            new SurfaceOutputSpec("Tas.Simulate")
                        };
                        surfaceOutputSpecs[0].SolarGain    = true;
                        surfaceOutputSpecs[0].Conduction   = true;
                        surfaceOutputSpecs[0].ApertureData = true;
                        surfaceOutputSpecs[0].Condensation = true;
                        surfaceOutputSpecs[0].Convection   = true;
                        surfaceOutputSpecs[0].LongWave     = true;
                        surfaceOutputSpecs[0].Temperature  = true;
                    }
                    else if (value is SurfaceOutputSpec)
                    {
                        surfaceOutputSpecs.Add((SurfaceOutputSpec)value);
                    }
                }
            }

            if (surfaceOutputSpecs != null && surfaceOutputSpecs.Count > 0)
            {
                using (SAMTBDDocument sAMTBDDocument = new SAMTBDDocument(path_TBD))
                {
                    TBD.TBDDocument tBDDocument = sAMTBDDocument.TBDDocument;

                    Core.Tas.Modify.UpdateSurfaceOutputSpecs(tBDDocument, surfaceOutputSpecs);
                    Core.Tas.Modify.AssignSurfaceOutputSpecs(tBDDocument, surfaceOutputSpecs[0].Name);
                    sAMTBDDocument.Save();
                }
            }

            bool result = Analytical.Tas.Modify.Simulate(path_TBD, path_TSD, day_First, day_Last);

            dataAccess.SetData(0, result);
        }