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)); }
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); }
public static AnalyticalModel UpdateT3D(this AnalyticalModel analyticalModel, T3DDocument t3DDocument) { if (analyticalModel == null) { return(null); } Building building = t3DDocument?.Building; if (building == null) { return(null); } Modify.RemoveUnsusedZones(building); double northAngle = double.NaN; if (analyticalModel.TryGetValue(AnalyticalModelParameter.NorthAngle, out northAngle)) { building.northAngle = global::System.Math.Round(Units.Convert.ToDegrees(northAngle), 1); } Location location = analyticalModel.Location; if (location != null) { building.longitude = location.Longitude; building.latitude = location.Latitude; if (location.TryGetValue(LocationParameter.TimeZone, out string timeZone)) { double @double = Core.Query.Double(Core.Query.UTC(timeZone)); if (!double.IsNaN(@double)) { building.timeZone = global::System.Convert.ToSingle(@double); } } } AdjacencyCluster adjacencyCluster = analyticalModel?.AdjacencyCluster; if (adjacencyCluster != null) { //Zones -> Spaces Dictionary <string, Space> spaces = adjacencyCluster.SpaceDictionary(); if (spaces != null) { Dictionary <string, TAS3D.Zone> zones = building.ZoneDictionary(); if (zones != null) { foreach (KeyValuePair <string, TAS3D.Zone> keyValuePair in zones) { Space space; if (!spaces.TryGetValue(keyValuePair.Key, out space)) { continue; } if (space == null) { continue; } //TODO: Update Zone Space space_New = space.Clone(); space_New.Add(Create.ParameterSet(ActiveSetting.Setting, keyValuePair.Value)); adjacencyCluster.AddObject(space_New); } } } //Elements -> Constructions List <Construction> constructions = adjacencyCluster.GetConstructions(); if (constructions != null) { List <Element> elements = building.Elements(); if (elements != null) { foreach (Element element in elements) { Construction construction = element.Match(constructions); if (construction == null) { continue; } //Update Element //Thickness double thickness = construction.GetValue <double>(ConstructionParameter.DefaultThickness); if (double.IsNaN(thickness) || thickness == 0) { thickness = construction.GetThickness(); } if (!double.IsNaN(thickness)) { element.width = thickness; } //if (Core.Query.TryGetValue(construction, Analytical.Query.ParameterName_Thickness(), out thickness, true)) // element.width= thickness; //Colour System.Drawing.Color color = global::System.Drawing.Color.Empty; if (construction.TryGetValue(ConstructionParameter.Color, out color)) { element.colour = Core.Convert.ToUint(color); } //Transparent bool transparent = false; MaterialType materialType = Analytical.Query.MaterialType(construction.ConstructionLayers, analyticalModel.MaterialLibrary); if (materialType == MaterialType.Undefined) { materialType = MaterialType.Opaque; if (construction.TryGetValue(ConstructionParameter.Transparent, out transparent)) { element.transparent = transparent; } } else { element.transparent = materialType == MaterialType.Transparent; } //InternalShadows bool internalShadows = false; if (construction.TryGetValue(ConstructionParameter.IsInternalShadow, out internalShadows)) { element.internalShadows = internalShadows; } else { element.internalShadows = element.transparent; } //BEType string string_BEType = null; PanelType panelType = construction.PanelType(); if (panelType != Analytical.PanelType.Undefined) { string_BEType = panelType.Text(); } else { if (!construction.TryGetValue(ConstructionParameter.DefaultPanelType, out string_BEType)) { string_BEType = null; } } if (!string.IsNullOrEmpty(string_BEType)) { int bEType = BEType(string_BEType); if (bEType != -1) { element.BEType = bEType; panelType = PanelType(bEType); } } else { panelType = Analytical.PanelType.Undefined; List <Panel> panels_Construction = adjacencyCluster.GetPanels(construction); if (panels_Construction != null && panels_Construction.Count > 0) { Panel panel = panels_Construction.Find(x => x.PanelType != Analytical.PanelType.Undefined); if (panel != null) { panelType = panel.PanelType; } } } if (panelType == Analytical.PanelType.Undefined) { List <Panel> panels_Construction = adjacencyCluster.GetPanels(construction); if (panels_Construction != null && panels_Construction.Count != 0) { element.zoneFloorArea = panels_Construction.Find(x => x.PanelType.PanelGroup() == PanelGroup.Floor) != null; } } if (panelType.PanelGroup() == PanelGroup.Floor) { element.zoneFloorArea = true; } //Ground bool ground = false; if (construction.TryGetValue(ConstructionParameter.IsGround, out ground)) { element.ground = ground; } //Air bool air = false; if (construction.TryGetValue(ConstructionParameter.IsAir, out air)) { element.ghost = air; } List <Panel> panels = adjacencyCluster.GetPanels(construction); if (panels != null && panels.Count > 0) { ParameterSet parameterSet = Create.ParameterSet(ActiveSetting.Setting, element); construction.Add(parameterSet); foreach (Panel panel in panels) { Panel panel_New = Analytical.Create.Panel(panel, construction); adjacencyCluster.AddObject(panel_New); } } } } } //Windows -> ApertureConstruction List <ApertureConstruction> apertureConstructions = adjacencyCluster.GetApertureConstructions(); if (apertureConstructions != null) { List <window> windows = building.Windows(); if (windows != null) { foreach (window window in windows) { if (window == null) { continue; } ApertureConstruction apertureConstruction = window.Match(apertureConstructions); if (apertureConstruction == null) { continue; } //Colour System.Drawing.Color color = global::System.Drawing.Color.Empty; if (!apertureConstruction.TryGetValue(ApertureConstructionParameter.Color, out color)) { color = Analytical.Query.Color(apertureConstruction.ApertureType); } if (color != global::System.Drawing.Color.Empty) { window.colour = Core.Convert.ToUint(color); } //Transparent List <ConstructionLayer> constructionLayers = null; if (true) { constructionLayers = apertureConstruction.PaneConstructionLayers; } else { constructionLayers = apertureConstruction.FrameConstructionLayers; } window.transparent = false; //Requested by Michal 2021.03.01 bool transparent = false; MaterialType materialType = Analytical.Query.MaterialType(constructionLayers, analyticalModel.MaterialLibrary); if (materialType == MaterialType.Undefined) { materialType = MaterialType.Opaque; if (apertureConstruction.TryGetValue(ApertureConstructionParameter.Transparent, out transparent)) { window.transparent = transparent; } } else { window.transparent = materialType == MaterialType.Transparent; } if (window.transparent) { //InternalShadows window.internalShadows = false; //Requested by Michal 2021.03.01 bool internalShadows = false; if (apertureConstruction.TryGetValue(ApertureConstructionParameter.IsInternalShadow, out internalShadows)) { window.internalShadows = internalShadows; } else { List <Panel> panels = adjacencyCluster.GetPanels(apertureConstruction); if (panels != null && panels.Count != 0) { window.internalShadows = panels.TrueForAll(x => adjacencyCluster.External(x)); } } } //FrameWidth double frameWidth = double.NaN; if (apertureConstruction.TryGetValue(ApertureConstructionParameter.DefaultFrameWidth, out frameWidth)) { window.frameWidth = frameWidth; } } } } } AnalyticalModel result = new AnalyticalModel(analyticalModel, adjacencyCluster); return(result); }