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); }
/// <summary> /// This is the method that actually does the work. /// </summary> /// <param name="dataAccess"> /// The DA object is used to retrieve from inputs and store in outputs. /// </param> protected override void SolveInstance(IGH_DataAccess dataAccess) { bool run = false; if (!dataAccess.GetData(6, ref run)) { AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Invalid data"); dataAccess.SetData(2, false); return; } if (!run) { return; } List <Panel> panels = new List <Panel>(); if (!dataAccess.GetDataList(0, panels) || panels == null) { AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Invalid data"); dataAccess.SetData(2, false); return; } List <Space> spaces = new List <Space>(); dataAccess.GetDataList(1, spaces); double tolerance = double.NaN; if (!dataAccess.GetData(2, ref tolerance) || double.IsNaN(tolerance)) { AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Invalid data"); dataAccess.SetData(2, false); return; } bool tryCellComplexByCells = false; if (!dataAccess.GetData(3, ref tryCellComplexByCells)) { AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Invalid data"); dataAccess.SetData(2, false); return; } //string reportPath = null; //if (dataAccess.GetData(4, ref reportPath)) //{ // if (System.IO.File.Exists(reportPath)) // System.IO.File.Delete(reportPath); //} double minArea = Tolerance.MacroDistance; dataAccess.GetData(4, ref minArea); double silverSpacing = Tolerance.MacroDistance; dataAccess.GetData(5, ref silverSpacing); List <Topology> topologies = null; Log log = new Log(); List <Panel> panels_Redundant = null; AdjacencyCluster adjacencyCluster = Analytical.Topologic.Create.AdjacencyCluster(spaces, panels, out topologies, out panels_Redundant, minArea, true, tryCellComplexByCells, log, silverSpacing, tolerance); if (adjacencyCluster != null) { List <Space> spaces_Temp = adjacencyCluster.GetSpaces(); if (spaces_Temp == null || spaces_Temp.Count == 0) { AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "No spaces have been detected"); } else { List <Point3D> locations = spaces_Temp.ConvertAll(x => x.Location); if (locations.RemoveAll(x => x == null) > 0) { AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "There are spaces without Location Points"); } List <Space> spaces_Unbounded = new List <Space>(); List <Space> spaces_Multiple = new List <Space>(); HashSet <int> indexes_Multiple = new HashSet <int>(); List <List <Space> > spacesList_Locations = adjacencyCluster.GetSpaces(locations); for (int i = 0; i < spacesList_Locations.Count; i++) { List <Space> spaces_Locations = spacesList_Locations[i]; Point3D point3D_Location = locations[i]; if (spaces_Locations == null) { spaces_Unbounded.Add(spaces_Temp.Find(x => point3D_Location.AlmostEquals(x.Location))); continue; } if (spacesList_Locations.Count > 2) { indexes_Multiple.Add(i); } } foreach (Space space in spaces_Unbounded) { string text = "There are unbounded spaces in topology model"; if (!string.IsNullOrWhiteSpace(space.Name)) { text += " " + space.Name; } text += " " + "Guid: " + space.Guid; AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, text); } foreach (Space space in spaces_Multiple) { string text = "There are multiple spaces in topology cell"; if (!string.IsNullOrWhiteSpace(space.Name)) { text += " " + space.Name; } text += " " + "Guid: " + space.Guid; AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, text); } } dataAccess.SetData(0, new GooAdjacencyCluster(adjacencyCluster)); } else { dataAccess.SetData(0, null); } dataAccess.SetDataList(1, topologies); dataAccess.SetDataList(2, adjacencyCluster?.GetPanels()); dataAccess.SetDataList(3, adjacencyCluster?.GetSpaces()); dataAccess.SetDataList(4, adjacencyCluster?.GetInternalPanels()); dataAccess.SetDataList(5, adjacencyCluster?.GetExternalPanels()); dataAccess.SetDataList(6, adjacencyCluster?.GetShadingPanels()); dataAccess.SetDataList(7, panels_Redundant); dataAccess.SetData(8, new GooLog(log)); dataAccess.SetData(9, adjacencyCluster != null); }
public static string ToGEM(this AdjacencyCluster adjacencyCluster, double silverSpacing = Core.Tolerance.MacroDistance, double tolerance = Core.Tolerance.Distance) { AdjacencyCluster adjacencyCluster_Temp = adjacencyCluster?.SplitByInternalEdges(tolerance); if (adjacencyCluster_Temp == null) { return(null); } string result = null; List <Space> spaces = adjacencyCluster_Temp.GetSpaces(); if (spaces != null && spaces.Count != 0) { foreach (Space space in spaces) { List <Panel> panels = adjacencyCluster_Temp.UpdateNormals(space, false, silverSpacing, tolerance); if (panels == null || panels.Count == 0) { continue; } string name = space.Name; if (string.IsNullOrWhiteSpace(name)) { name = space.Guid.ToString(); } string result_space = ToGEM(panels, name, GEMType.Space, tolerance); if (result_space == null) { continue; } if (result == null) { result = result_space; } else { result += result_space; } } } List <Panel> panels_Shading = adjacencyCluster_Temp.GetShadingPanels(); if (panels_Shading != null) { for (int i = 0; i < panels_Shading.Count; i++) { string result_shade = ToGEM(new Panel[] { panels_Shading[i] }, string.Format("SHADE {0}", i + 1), GEMType.Shade, tolerance); if (result_shade == null) { continue; } if (result == null) { result = result_shade; } else { result += result_shade; } } } return(result); }
public static List <Element> ToRevit(this AdjacencyCluster adjacencyCluster, Document document, ConvertSettings convertSettings) { if (adjacencyCluster == null || document == null) { return(null); } List <Element> result = convertSettings?.GetObjects <Element>(adjacencyCluster.Guid); if (result != null) { return(result); } Dictionary <Space, Shell> dictionary_Shell = adjacencyCluster.ShellDictionary(); if (dictionary_Shell == null) { return(null); } //List<Level> levels = new FilteredElementCollector(document).OfClass(typeof(Level)).Cast<Level>().ToList(); //if (levels == null || levels.Count == 0) // return null; Dictionary <ElementId, Element> dictionary_Element = new Dictionary <ElementId, Element>(); HashSet <System.Guid> guids = new HashSet <System.Guid>(); foreach (KeyValuePair <Space, Shell> keyValuePair in dictionary_Shell) { Space space = keyValuePair.Key; List <Panel> panels_Space = adjacencyCluster.GetPanels(space); if (panels_Space != null && panels_Space.Count != 0) { foreach (Panel panel in panels_Space) { if (guids.Contains(panel.Guid)) { continue; } guids.Add(panel.Guid); HostObject hostObject = panel.ToRevit(document, convertSettings); if (hostObject == null) { continue; } dictionary_Element[hostObject.Id] = hostObject; } } Autodesk.Revit.DB.Mechanical.Space space_Revit = space.ToRevit(document, convertSettings); if (space_Revit == null) { continue; } dictionary_Element[space_Revit.Id] = space_Revit; BoundingBox3D boundingBox3D = keyValuePair.Value.GetBoundingBox(); if (boundingBox3D == null) { continue; } Parameter parameter; parameter = space_Revit.get_Parameter(BuiltInParameter.ROOM_UPPER_LEVEL); Level level = document.ClosestLevel(boundingBox3D.Max.Z); if (level == null) { continue; } parameter.Set(level.Id); if (level.Id != space_Revit.LevelId && level.Elevation > (document.GetElement(space_Revit.LevelId) as Level).Elevation) { parameter = space_Revit.get_Parameter(BuiltInParameter.ROOM_UPPER_OFFSET); parameter.Set(0); } } List <Panel> panels = adjacencyCluster.GetShadingPanels(); if (panels != null && panels.Count != 0) { foreach (Panel panel in panels) { HostObject hostObject = panel.ToRevit(document, convertSettings); if (hostObject == null) { continue; } dictionary_Element[hostObject.Id] = hostObject; } } List <Zone> zones = adjacencyCluster.GetObjects <Zone>(); if (zones != null) { foreach (Zone zone in zones) { List <Autodesk.Revit.DB.Mechanical.Space> spaces = ToRevit(adjacencyCluster, zone, document, convertSettings); spaces?.ForEach(x => dictionary_Element[x.Id] = x); } } List <ZoneSimulationResult> zoneSimulationResults = adjacencyCluster.GetObjects <ZoneSimulationResult>(); if (zoneSimulationResults != null) { foreach (ZoneSimulationResult zoneSimulationResult in zoneSimulationResults) { List <Autodesk.Revit.DB.Mechanical.Space> spaces = ToRevit(adjacencyCluster, zoneSimulationResult, document, convertSettings); spaces?.ForEach(x => dictionary_Element[x.Id] = x); } } List <SpaceSimulationResult> spaceSimulationResults = adjacencyCluster.GetObjects <SpaceSimulationResult>(); if (zoneSimulationResults != null) { foreach (SpaceSimulationResult spaceSimulationResult in spaceSimulationResults) { List <Autodesk.Revit.DB.Mechanical.Space> spaces = ToRevit(adjacencyCluster, spaceSimulationResult, document, convertSettings); spaces?.ForEach(x => dictionary_Element[x.Id] = x); } } List <AdjacencyClusterSimulationResult> adjacencyClusterSimulationResults = adjacencyCluster.GetObjects <AdjacencyClusterSimulationResult>(); if (adjacencyClusterSimulationResults != null) { foreach (AdjacencyClusterSimulationResult adjacencyClusterSimulationResult in adjacencyClusterSimulationResults) { ProjectInfo projectInfo = ToRevit(adjacencyClusterSimulationResult, document, convertSettings); if (projectInfo != null) { dictionary_Element[projectInfo.Id] = projectInfo; } } } result = dictionary_Element.Values.ToList(); convertSettings?.Add(adjacencyCluster.Guid, result); return(result); }