Exemplo n.º 1
0
        public static Face ToLadybugTools_Face(this IPartition partition, BuildingModel buildingModel, Space space)
        {
            Face3D face3D = Geometry.LadybugTools.Convert.ToLadybugTools(partition?.Face3D);

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

            FaceType?faceType = partition.FaceType();

            if (faceType == null || !faceType.HasValue)
            {
                return(null);
            }

            int          index          = -1;
            int          index_Adjacent = -1;
            bool         reverse        = true;
            List <Space> spaces         = buildingModel.GetSpaces(partition);

            if (spaces != null && spaces.Count != 0)
            {
                index = spaces.FindIndex(x => x.Guid == space.Guid);
                index = buildingModel.UniqueIndex(spaces[index]);

                index_Adjacent = spaces.FindIndex(x => x.Guid != space.Guid);
                index_Adjacent = buildingModel.UniqueIndex(spaces[index_Adjacent]);

                reverse = buildingModel.UniqueIndex(spaces[0]) != index;
            }

            AnyOf <Ground, Outdoors, Adiabatic, Surface> boundaryCondition = partition.ToLadybugTools_BoundaryCondition(buildingModel, space);

            FaceEnergyPropertiesAbridged faceEnergyPropertiesAbridged = new FaceEnergyPropertiesAbridged();

            if (partition is IHostPartition)
            {
                faceEnergyPropertiesAbridged.Construction = Query.UniqueName(((IHostPartition)partition).Type(), reverse);
            }

            Face face = new Face(Query.UniqueName(partition, index), face3D, faceType.Value, boundaryCondition, new FacePropertiesAbridged(faceEnergyPropertiesAbridged), partition.Name);

            if (partition is IHostPartition)
            {
                List <IOpening> openings = ((IHostPartition)partition).GetOpenings();
                if (openings != null && openings.Count != 0)
                {
                    List <HoneybeeSchema.Aperture> apertures = new List <HoneybeeSchema.Aperture>();
                    List <HoneybeeSchema.Door>     doors     = new List <HoneybeeSchema.Door>();

                    foreach (IOpening opening in openings)
                    {
                        MaterialType materialType = MaterialType.Opaque;

                        OpeningType openingType = opening.Type();
                        if (openingType != null)
                        {
                            materialType = buildingModel.GetMaterialType(openingType.PaneMaterialLayers);
                        }


                        if (opening is Window && materialType != MaterialType.Opaque)
                        {
                            HoneybeeSchema.Aperture aperture = ((Window)opening).ToLadybugTools(buildingModel, space);
                            if (aperture != null)
                            {
                                apertures.Add(aperture);
                            }
                        }
                        else
                        {
                            HoneybeeSchema.Door door = opening.ToLadybugTools(buildingModel, space);
                            if (door != null)
                            {
                                doors.Add(door);
                            }
                        }
                    }

                    if (apertures != null && apertures.Count != 0)
                    {
                        face.Apertures = apertures;
                    }

                    if (doors != null && doors.Count != 0)
                    {
                        face.Doors = doors;
                    }
                }
            }

            return(face);
        }
Exemplo n.º 2
0
        public static HoneybeeSchema.Door ToLadybugTools(this IOpening opening, BuildingModel buildingModel, Space space)
        {
            if (opening == null || buildingModel == null)
            {
                return(null);
            }

            OpeningType openingType = opening.Type();

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

            //Opaque Windows to be replaced by Doors
            if (opening is Window && buildingModel.GetMaterialType(openingType.PaneMaterialLayers) != MaterialType.Opaque)
            {
                return(null);
            }

            IHostPartition hostPartition = buildingModel.GetHostPartition(opening);

            int          index          = -1;
            int          index_Adjacent = -1;
            List <Space> spaces         = null;

            if (hostPartition != null)
            {
                spaces = buildingModel.GetSpaces(hostPartition);
                if (spaces != null && spaces.Count != 0)
                {
                    index = spaces.FindIndex(x => x.Guid == space.Guid);
                    index = buildingModel.UniqueIndex(spaces[index]);

                    index_Adjacent = spaces.FindIndex(x => x.Guid != space.Guid);
                    index_Adjacent = buildingModel.UniqueIndex(spaces[index_Adjacent]);
                }
            }

            HoneybeeSchema.AnyOf <Outdoors, Surface> anyOf = null;
            if (index == -1 || index_Adjacent == -1)
            {
                anyOf = new Outdoors();
            }
            else
            {
                bool          reversed    = index_Adjacent < index;
                List <string> uniqueNames = new List <string>();
                uniqueNames.Add(Core.LadybugTools.Query.UniqueName(opening as SAMObject, index_Adjacent));
                uniqueNames.Add(Query.UniqueName(hostPartition, index_Adjacent));
                uniqueNames.Add(Query.UniqueName(spaces[index_Adjacent]));
                anyOf = new Surface(uniqueNames);
            }

            Face3D face3D = Geometry.LadybugTools.Convert.ToLadybugTools(opening);

            DoorEnergyPropertiesAbridged doorEnergyPropertiesAbridged = new DoorEnergyPropertiesAbridged(construction: Query.UniqueName(opening.Type(), !(index_Adjacent != -1 && index <= index_Adjacent)));

            return(new HoneybeeSchema.Door(
                       identifier: Core.LadybugTools.Query.UniqueName(opening as SAMObject, index),
                       geometry: face3D,
                       boundaryCondition: anyOf,
                       properties: new DoorPropertiesAbridged(doorEnergyPropertiesAbridged),
                       displayName: opening.Name));
        }
Exemplo n.º 3
0
        public static Model ToLadybugTools(this BuildingModel buildingModel, double silverSpacing = Tolerance.MacroDistance, double tolerance = Tolerance.Distance)
        {
            if (buildingModel == null)
            {
                return(null);
            }

            BuildingModel architecturalModel_Temp = new BuildingModel(buildingModel);

            architecturalModel_Temp.OffsetAperturesOnEdge(0.1, tolerance);
            architecturalModel_Temp.ReplaceTransparentPartitions(0.1);
            architecturalModel_Temp.UpdateMaterialsByMaterialLayerThickness(tolerance);
            architecturalModel_Temp.UpdateMaterialsByHeatTransferCoefficients(true, true);

            string uniqueName = Core.LadybugTools.Query.UniqueName(architecturalModel_Temp);

            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 = architecturalModel_Temp.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 <IPartition> > dictionary_elevations = Geometry.Spatial.Query.ElevationDictionary(buildingModel.GetPartitions());
                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(architecturalModel_Temp, silverSpacing, tolerance);
                    if (room == null)
                    {
                        continue;
                    }

                    if (levels != null && levels.Count > 0)
                    {
                        double elevation_Min = Analytical.Query.MinElevation(buildingModel, space);
                        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 <IPartition> partitions_Shade = buildingModel.GetShadePartitions();

            if (partitions_Shade != null)
            {
                foreach (IPartition partition_Shade in partitions_Shade)
                {
                    if (partitions_Shade == null)
                    {
                        continue;
                    }

                    Shade shade = partition_Shade.ToLadybugTools_Shade();
                    if (shade == null)
                    {
                        continue;
                    }

                    if (shades == null)
                    {
                        shades = new List <Shade>();
                    }

                    shades.Add(shade);
                }
            }

            List <HostPartitionType> hostPartitionTypes = buildingModel.GetHostPartitionTypes();
            List <OpeningType>       openingTypes       = buildingModel.GetOpeningTypes();

            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 (hostPartitionTypes != null)
            {
                foreach (HostPartitionType hostPartitionType in hostPartitionTypes)
                {
                    List <MaterialLayer> materialLayers = hostPartitionType.MaterialLayers;
                    if (materialLayers == null)
                    {
                        continue;
                    }

                    constructions.Add(hostPartitionType.ToLadybugTools());
                    constructions.Add(hostPartitionType.ToLadybugTools(false));

                    foreach (MaterialLayer materialLayer in materialLayers)
                    {
                        IMaterial material = buildingModel.GetMaterial(materialLayer);
                        if (material == null)
                        {
                            continue;
                        }

                        if (dictionary_Materials.ContainsKey(material.Name))
                        {
                            continue;
                        }

                        HoneybeeSchema.Energy.IMaterial material_HoneybeeSchema = material.ToLadybugTools(materialLayer.Thickness, false);
                        if (material_HoneybeeSchema == null)
                        {
                            continue;
                        }

                        dictionary_Materials[material.Name] = material_HoneybeeSchema;
                    }
                }
            }

            if (openingTypes != null)
            {
                foreach (OpeningType openingType in openingTypes)
                {
                    List <MaterialLayer> materialLayers = openingType.PaneMaterialLayers;
                    if (materialLayers == null)
                    {
                        continue;
                    }

                    MaterialType materialType = buildingModel.GetMaterialType(materialLayers);

                    if (openingType is WindowType && materialType != MaterialType.Opaque)
                    {
                        WindowType windowType = (WindowType)openingType;

                        constructions.Add(windowType.ToLadybugTools_WindowConstructionAbridged());
                        constructions.Add(windowType.ToLadybugTools_WindowConstructionAbridged(false));
                    }
                    else
                    {
                        constructions.Add(openingType.ToLadybugTools());
                        constructions.Add(openingType.ToLadybugTools(false));
                    }

                    foreach (MaterialLayer materialLayer in materialLayers)
                    {
                        IMaterial material = buildingModel.GetMaterial(materialLayer);
                        if (material == null)
                        {
                            continue;
                        }

                        if (dictionary_Materials.ContainsKey(material.Name))
                        {
                            continue;
                        }

                        HoneybeeSchema.Energy.IMaterial material_HoneybeeSchema = material.ToLadybugTools(materialLayer.Thickness, false);
                        if (material_HoneybeeSchema == null)
                        {
                            continue;
                        }

                        dictionary_Materials[material.Name] = material_HoneybeeSchema;
                    }
                }
            }

            Dictionary <System.Guid, ProgramType> dictionary_ProgramTypes = new Dictionary <System.Guid, ProgramType>();

            if (spaces != null)
            {
                foreach (Space space in spaces)
                {
                    InternalCondition internalCondition = space?.InternalCondition;
                    if (internalCondition == null)
                    {
                        continue;
                    }

                    if (dictionary_ProgramTypes.ContainsKey(internalCondition.Guid))
                    {
                        continue;
                    }

                    ProgramType programType = space.ToLadybugTools(buildingModel);
                    if (programType != null)
                    {
                        dictionary_ProgramTypes[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_ProgramTypes.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, buildingModel.Name, null, rooms, faces_Orphaned, shades);

            model.AngleTolerance = Units.Convert.ToDegrees(Tolerance.Angle);// 2;
            model.Tolerance      = Tolerance.MacroDistance;

            return(model);
        }