예제 #1
0
        public static Room ToLadybugTools(this Space space, BuildingModel buildingModel, double silverSpacing = Core.Tolerance.MacroDistance, double tolerance = Core.Tolerance.Distance)
        {
            if (space == null || buildingModel == null)
            {
                return(null);
            }

            List <Face> faces = null;

            List <IPartition> partitions = buildingModel.OrientedPartitions(space, false, silverSpacing, tolerance);

            if (partitions != null)
            {
                faces = new List <Face>();
                foreach (IPartition partition in partitions)
                {
                    Face face = partition?.ToLadybugTools_Face(buildingModel, space);
                    if (face == null)
                    {
                        continue;
                    }

                    faces.Add(face);
                }
            }

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

            RoomPropertiesAbridged roomPropertiesAbridged = new RoomPropertiesAbridged();

            Room result = new Room(uniqueName, faces, roomPropertiesAbridged, space.Name);

            InternalCondition internalCondition = space.InternalCondition;

            if (internalCondition != null)
            {
                string uniqueName_InternalCondition = Core.LadybugTools.Query.UniqueName(internalCondition);
                if (!string.IsNullOrWhiteSpace(uniqueName_InternalCondition))
                {
                    roomPropertiesAbridged = result.Properties;
                    RoomEnergyPropertiesAbridged roomEnergyPropertiesAbridged = roomPropertiesAbridged.Energy;
                    if (roomEnergyPropertiesAbridged == null)
                    {
                        roomEnergyPropertiesAbridged = new RoomEnergyPropertiesAbridged(programType: uniqueName_InternalCondition);
                    }

                    result.Properties.Energy = roomEnergyPropertiesAbridged;
                }
            }

            return(result);
        }
예제 #2
0
        public static InternalCondition ToSAM_InternalCondition(this SpatialElement spatialElement, ConvertSettings convertSettings)
        {
            if (spatialElement == null)
            {
                return(null);
            }

            InternalCondition result = convertSettings?.GetObject <InternalCondition>(spatialElement.Id);

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

            string name = null;

            Core.TypeMap typeMap = ActiveSetting.Setting.GetValue <Core.TypeMap>(Core.Revit.ActiveSetting.Name.ParameterMap);
            if (typeMap != null)
            {
                string parameterName = typeMap.GetName(typeof(InternalCondition), typeof(Autodesk.Revit.DB.Mechanical.Space), "Name", 2);
                if (!string.IsNullOrWhiteSpace(parameterName))
                {
                    Parameter parameter = spatialElement.GetParameters(parameterName)?.ToList().Find(x => x.StorageType == StorageType.String);
                    if (parameter != null)
                    {
                        name = parameter.AsString();
                    }
                }

                if (string.IsNullOrWhiteSpace(name))
                {
                    name = Core.Revit.Query.Name(spatialElement);
                }

                if (string.IsNullOrWhiteSpace(name))
                {
                    name = spatialElement.Name;
                }
            }

            result = new InternalCondition(name);

            result.UpdateParameterSets(spatialElement, typeMap, null, null, false);

            convertSettings?.Add(spatialElement.Id, result);

            return(result);
        }
예제 #3
0
        public static InternalCondition ToSAM_InternalCondtion(this ProgramType programType)
        {
            if (programType == null)
            {
                return(null);
            }

            InternalCondition result = new InternalCondition(programType.DisplayName);

            People people = programType.People;

            if (people != null)
            {
                result.SetValue(Analytical.InternalConditionParameter.OccupancyProfileName, Core.LadybugTools.Query.Identifier(people.OccupancySchedule));
            }

            Lighting lighting = programType.Lighting;

            if (lighting != null)
            {
                result.SetValue(Analytical.InternalConditionParameter.LightingProfileName, Core.LadybugTools.Query.Identifier(lighting.Schedule));
            }

            ElectricEquipment electricEquipment = programType.ElectricEquipment;

            if (electricEquipment != null)
            {
                result.SetValue(Analytical.InternalConditionParameter.EquipmentSensibleProfileName, Core.LadybugTools.Query.Identifier(electricEquipment.Schedule));
            }

            Infiltration infiltration = programType.Infiltration;

            if (infiltration != null)
            {
                result.SetValue(Analytical.InternalConditionParameter.InfiltrationProfileName, Core.LadybugTools.Query.Identifier(infiltration.Schedule));
            }

            Setpoint setPoint = programType.Setpoint;

            if (setPoint != null)
            {
                result.SetValue(Analytical.InternalConditionParameter.CoolingProfileName, Core.LadybugTools.Query.Identifier(setPoint.CoolingSchedule));

                result.SetValue(Analytical.InternalConditionParameter.HeatingProfileName, Core.LadybugTools.Query.Identifier(setPoint.HeatingSchedule));
            }

            return(result);
        }
        public static bool UpdateInternalCondition_HDD(this TBD.InternalCondition internalCondition_TBD, Space space, ProfileLibrary profileLibrary)
        {
            if (internalCondition_TBD == null || space == null)
            {
                return(false);
            }

            InternalCondition internalCondition = space.InternalCondition;

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

            internalCondition_TBD.name = space.Name + " - HDD";

            return(UpdateInternalCondition_HDD(internalCondition_TBD, internalCondition, profileLibrary));
        }
예제 #5
0
        public static List <InternalCondition> ToSAM_InternalConditions(this ModelEnergyProperties modelEnergyProperties)
        {
            if (modelEnergyProperties == null)
            {
                return(null);
            }

            IEnumerable <IProgramtype> programTypes = modelEnergyProperties.ProgramTypeList;

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

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

            foreach (IProgramtype programType in programTypes)
            {
                InternalCondition internalCondition = null;

                if (programType is ProgramTypeAbridged)
                {
                    internalCondition = ((ProgramTypeAbridged)programType).ToSAM_InternalCondition(modelEnergyProperties);
                }
                else if (programType is ProgramType)
                {
                    internalCondition = ((ProgramType)programType).ToSAM_InternalCondtion();
                }

                if (internalCondition != null)
                {
                    result.Add(internalCondition);
                }
            }

            return(result);
        }
예제 #6
0
파일: Space.cs 프로젝트: HoareLea/SAM_Tas
        public static Space ToSAM(this TBD.zone zone, out List <InternalCondition> internalConditions)
        {
            internalConditions = null;

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

            Space result = new Space(zone.name);

            double area = zone.floorArea;

            result.SetValue(SpaceParameter.Area, area);
            result.SetValue(SpaceParameter.Volume, zone.volume);

            List <TBD.InternalCondition> internalConditions_TBD = zone.InternalConditions();

            if (internalConditions_TBD != null)
            {
                internalConditions = new List <InternalCondition>();

                foreach (TBD.InternalCondition internalCondition_TBD in internalConditions_TBD)
                {
                    InternalCondition internalCondition = internalCondition_TBD.ToSAM(area);
                    if (internalCondition == null)
                    {
                        continue;
                    }

                    internalConditions.Add(internalCondition);
                }
            }

            return(result);
        }
예제 #7
0
        public static double InfiltrationAirFlowPerExteriorArea(this AdjacencyCluster adjacencyCluster, Space space)
        {
            if (adjacencyCluster == null || space == null)
            {
                return(double.NaN);
            }

            double volume = double.NaN;

            space.TryGetValue(SpaceParameter.Volume, out volume);
            if (double.IsNaN(volume))
            {
                return(double.NaN);
            }

            InternalCondition internalCondintion = space.InternalCondition;

            if (internalCondintion == null)
            {
                return(double.NaN);
            }

            double airFlow = Analytical.Query.CalculatedInfiltrationAirFlow(space);

            if (double.IsNaN(airFlow))
            {
                return(double.NaN);
            }

            if (airFlow == 0)
            {
                return(0);
            }

            List <Panel> panels = adjacencyCluster.GetPanels(space);

            if (panels == null || panels.Count == 0)
            {
                return(double.NaN);
            }

            panels.RemoveAll(x => !adjacencyCluster.ExposedToSun(x));

            double area = 0;

            foreach (Panel panel in panels)
            {
                double area_Temp = panel.GetArea();
                if (!double.IsNaN(area_Temp))
                {
                    area += area_Temp;
                }
            }

            if (area == 0)
            {
                return(0);
            }

            return(airFlow / area);
        }
        public static bool UpdateInternalCondition_HDD(this TBD.InternalCondition internalCondition_TBD, InternalCondition internalCondition, ProfileLibrary profileLibrary)
        {
            if (internalCondition_TBD == null || internalCondition == null)
            {
                return(false);
            }

            internalCondition_TBD.description = internalCondition.Name + " - HDD";

            internalCondition_TBD.includeSolarInMRT = 0;

            TBD.Emitter emitter = null;
            double      value   = double.NaN;

            emitter = internalCondition_TBD.GetHeatingEmitter();
            if (emitter != null)
            {
                if (internalCondition.TryGetValue(InternalConditionParameter.HeatingEmitterRadiantProportion, out value))
                {
                    emitter.radiantProportion = System.Convert.ToSingle(value);
                }

                if (internalCondition.TryGetValue(InternalConditionParameter.HeatingEmitterCoefficient, out value))
                {
                    emitter.viewCoefficient = System.Convert.ToSingle(value);
                }
            }

            emitter = internalCondition_TBD.GetCoolingEmitter();
            if (emitter != null)
            {
                if (internalCondition.TryGetValue(InternalConditionParameter.CoolingEmitterRadiantProportion, out value))
                {
                    emitter.radiantProportion = System.Convert.ToSingle(value);
                }

                if (internalCondition.TryGetValue(InternalConditionParameter.CoolingEmitterCoefficient, out value))
                {
                    emitter.viewCoefficient = System.Convert.ToSingle(value);
                }
            }

            TBD.InternalGain internalGain = internalCondition_TBD.GetInternalGain();
            internalGain.name = internalCondition.Name + " - HDD";

            Profile profile = null;

            profile = internalCondition.GetProfile(ProfileType.Infiltration, profileLibrary);
            if (profile != null)
            {
                if (internalCondition.TryGetValue(InternalConditionParameter.InfiltrationAirChangesPerHour, out value))
                {
                    TBD.profile profile_TBD = internalGain.GetProfile((int)TBD.Profiles.ticI);
                    if (profile_TBD != null)
                    {
                        profile_TBD.name   = profile.Name;
                        profile_TBD.type   = TBD.ProfileTypes.ticValueProfile;
                        profile_TBD.factor = 1;
                        profile_TBD.value  = System.Convert.ToSingle(value);
                    }
                }
            }

            TBD.Thermostat thermostat = internalCondition_TBD.GetThermostat();
            if (thermostat != null)
            {
                thermostat.controlRange        = 0;
                thermostat.proportionalControl = 0;

                profile = internalCondition.GetProfile(ProfileType.Heating, profileLibrary);
                if (profile != null)
                {
                    thermostat.name = profile.Name;

                    TBD.profile profile_TBD = thermostat.GetProfile((int)TBD.Profiles.ticLL);
                    if (profile_TBD != null)
                    {
                        value = profile.MaxValue;
                        if (!double.IsNaN(value))
                        {
                            profile_TBD.name   = profile.Name;
                            profile_TBD.type   = TBD.ProfileTypes.ticValueProfile;
                            profile_TBD.factor = 1;
                            profile_TBD.value  = System.Convert.ToSingle(value);
                        }
                    }
                }
            }

            return(true);
        }
예제 #9
0
        public static Room ToLadybugTools(this Space space, AnalyticalModel analyticalModel = null, double silverSpacing = Core.Tolerance.MacroDistance, double tolerance = Core.Tolerance.Distance)
        {
            if (space == null)
            {
                return(null);
            }

            int          index  = -1;
            List <Panel> panels = null;

            AdjacencyCluster adjacencyCluster = analyticalModel?.AdjacencyCluster;

            if (adjacencyCluster != null)
            {
                index  = adjacencyCluster.GetIndex(space);
                panels = adjacencyCluster.UpdateNormals(space, false, silverSpacing, tolerance);
            }

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

            string uniqueName = Query.UniqueName(space);

            List <Face> faces = null;

            if (panels != null)
            {
                faces = new List <Face>();
                foreach (Panel panel in panels)
                {
                    if (panel == null)
                    {
                        continue;
                    }

                    bool reverse = true;

                    List <Space> spaces = adjacencyCluster?.GetSpaces(panel);
                    if (spaces != null && spaces.Count > 1)
                    {
                        reverse = adjacencyCluster.GetIndex(spaces[0]) != index;
                    }

                    Face face = panel.ToLadybugTools_Face(analyticalModel, index, reverse);
                    if (face == null)
                    {
                        continue;
                    }

                    faces.Add(face);
                }
            }

            RoomPropertiesAbridged roomPropertiesAbridged = new RoomPropertiesAbridged();

            Room result = new Room(uniqueName, faces, roomPropertiesAbridged, space.Name);

            InternalCondition internalCondition = space.InternalCondition;

            if (internalCondition != null)
            {
                string uniqueName_InternalCondition = Core.LadybugTools.Query.UniqueName(internalCondition);
                if (!string.IsNullOrWhiteSpace(uniqueName_InternalCondition))
                {
                    roomPropertiesAbridged = result.Properties;
                    RoomEnergyPropertiesAbridged roomEnergyPropertiesAbridged = roomPropertiesAbridged.Energy;
                    if (roomEnergyPropertiesAbridged == null)
                    {
                        roomEnergyPropertiesAbridged = new RoomEnergyPropertiesAbridged(programType: uniqueName_InternalCondition);
                    }

                    result.Properties.Energy = roomEnergyPropertiesAbridged;
                }
            }

            return(result);
        }
예제 #10
0
        public static ProgramType ToLadybugTools(this Space space, AdjacencyCluster adjacencyCluster, ProfileLibrary profileLibrary)
        {
            InternalCondition internalCondition = space.InternalCondition;

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

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

            if (string.IsNullOrWhiteSpace(uniqueName))
            {
                return(null);
            }

            People            people            = null;
            Lighting          lighting          = null;
            ElectricEquipment electricEquipment = null;
            Infiltration      infiltration      = null;
            Setpoint          setpoint          = null;

            if (profileLibrary != null)
            {
                double area = double.NaN;
                if (!space.TryGetValue(SpaceParameter.Area, out area))
                {
                    area = double.NaN;
                }

                Dictionary <ProfileType, Profile> dictionary = internalCondition.GetProfileDictionary(profileLibrary);

                if (dictionary.ContainsKey(ProfileType.Occupancy))
                {
                    Profile profile = dictionary[ProfileType.Occupancy];
                    if (profile != null)
                    {
                        double gain = Analytical.Query.OccupancyGain(space);
                        if (double.IsNaN(gain))
                        {
                            gain = 0;
                        }

                        ScheduleRuleset scheduleRuleset = profile.ToLadybugTools();
                        if (scheduleRuleset != null)
                        {
                            double gainPerPeople = gain;
                            if (double.IsNaN(gainPerPeople))
                            {
                                gainPerPeople = 0;
                            }

                            double occupancy = Analytical.Query.CalculatedOccupancy(space);
                            if (!double.IsNaN(occupancy) && occupancy != 0)
                            {
                                gainPerPeople = gainPerPeople / occupancy;
                            }

                            ScheduleRuleset scheduleRuleset_ActivityLevel = profile.ToLadybugTools_ActivityLevel(gainPerPeople);
                            if (scheduleRuleset_ActivityLevel != null)
                            {
                                double peoplePerArea = Analytical.Query.CalculatedPeoplePerArea(space);
                                if (double.IsNaN(peoplePerArea))
                                {
                                    peoplePerArea = 0;
                                }

                                double latentFraction        = double.NaN;
                                double sensibleOccupancyGain = Analytical.Query.OccupancySensibleGain(space);
                                double latentOccupancyGain   = Analytical.Query.OccupancyLatentGain(space);
                                if (!double.IsNaN(sensibleOccupancyGain) || !double.IsNaN(latentOccupancyGain))
                                {
                                    latentFraction = latentOccupancyGain / (latentOccupancyGain + sensibleOccupancyGain);
                                }

                                if (!internalCondition.TryGetValue(Analytical.InternalConditionParameter.OccupancyRadiantProportion, out double occuplancyRadiantProportion))
                                {
                                    occuplancyRadiantProportion = 0.3;
                                }

                                if (double.IsNaN(latentFraction))
                                {
                                    latentFraction = 0;
                                }


                                people = new People(
                                    identifier: string.Format("{0}_People", uniqueName),
                                    peoplePerArea: peoplePerArea,
                                    occupancySchedule: scheduleRuleset,
                                    displayName: profile.Name,
                                    userData: null,
                                    activitySchedule: scheduleRuleset_ActivityLevel,
                                    radiantFraction: occuplancyRadiantProportion,
                                    latentFraction: latentFraction);
                            }
                        }
                    }
                }

                if (dictionary.ContainsKey(ProfileType.Lighting))
                {
                    Profile profile = dictionary[ProfileType.Lighting];
                    if (profile != null)
                    {
                        double gain = Analytical.Query.CalculatedLightingGain(space);
                        if (double.IsNaN(gain))
                        {
                            gain = 0;
                        }

                        ScheduleRuleset scheduleRuleset = profile.ToLadybugTools();
                        if (scheduleRuleset != null)
                        {
                            double gainPerArea = gain;
                            if (double.IsNaN(gainPerArea))
                            {
                                gainPerArea = 0;
                            }

                            if (!double.IsNaN(area) && area != 0)
                            {
                                gainPerArea = gainPerArea / area;
                            }

                            if (!internalCondition.TryGetValue(Analytical.InternalConditionParameter.LightingRadiantProportion, out double lightingRadiantProportion))
                            {
                                lightingRadiantProportion = 0.32;
                            }

                            if (!internalCondition.TryGetValue(Analytical.InternalConditionParameter.LightingViewCoefficient, out double lightingViewCoefficient))
                            {
                                lightingViewCoefficient = 0.25;
                            }

                            lighting = new Lighting(
                                identifier: string.Format("{0}_Lighting", uniqueName),
                                wattsPerArea: gainPerArea,
                                schedule: scheduleRuleset,
                                visibleFraction: lightingViewCoefficient,
                                radiantFraction: lightingRadiantProportion,
                                displayName: profile.Name);
                        }
                    }
                }

                if (dictionary.ContainsKey(ProfileType.EquipmentSensible))
                {
                    double gain = Analytical.Query.CalculatedEquipmentSensibleGain(space);
                    if (double.IsNaN(gain))
                    {
                        gain = 0;
                    }

                    Profile profile = dictionary[ProfileType.EquipmentSensible];
                    if (profile != null)
                    {
                        ScheduleRuleset scheduleRuleset = profile.ToLadybugTools();
                        if (scheduleRuleset != null)
                        {
                            double gainPerArea = gain;
                            if (double.IsNaN(gainPerArea))
                            {
                                gainPerArea = 0;
                            }

                            if (!double.IsNaN(area) && area != 0)
                            {
                                gainPerArea = gainPerArea / area;
                            }

                            if (!internalCondition.TryGetValue(Analytical.InternalConditionParameter.EquipmentRadiantProportion, out double equipmentRadiantProportion))
                            {
                                equipmentRadiantProportion = 0;
                            }

                            electricEquipment = new ElectricEquipment(
                                identifier: string.Format("{0}_ElectricEquipment", uniqueName),
                                wattsPerArea: gainPerArea,
                                schedule: scheduleRuleset,
                                radiantFraction: equipmentRadiantProportion,
                                displayName: profile.Name);
                        }
                    }
                }

                if (dictionary.ContainsKey(ProfileType.Infiltration))
                {
                    Profile profile = dictionary[ProfileType.Infiltration];
                    if (profile != null)
                    {
                        ScheduleRuleset scheduleRuleset = profile.ToLadybugTools();
                        if (scheduleRuleset != null)
                        {
                            double airFlowPerExteriorArea = Query.InfiltrationAirFlowPerExteriorArea(adjacencyCluster, space);

                            infiltration = new Infiltration(
                                identifier: string.Format("{0}_Infiltration", uniqueName),
                                flowPerExteriorArea: airFlowPerExteriorArea,
                                schedule: scheduleRuleset,
                                displayName: profile.Name);
                        }
                    }
                }

                if (dictionary.ContainsKey(ProfileType.Cooling) && dictionary.ContainsKey(ProfileType.Heating))
                {
                    Profile profile_Cooling = dictionary[ProfileType.Cooling];
                    Profile profile_Heating = dictionary[ProfileType.Heating];
                    if (profile_Cooling != null && profile_Heating != null)
                    {
                        ScheduleRuleset scheduleRuleset_Cooling = profile_Cooling.ToLadybugTools();
                        ScheduleRuleset scheduleRuleset_Heating = profile_Heating.ToLadybugTools();
                        if (scheduleRuleset_Cooling != null && scheduleRuleset_Heating != null)
                        {
                            setpoint = new Setpoint(string.Format("{0}_Setpoint", uniqueName), scheduleRuleset_Cooling, scheduleRuleset_Heating, string.Format("Heating {0} Cooling {1}", profile_Heating.Name, profile_Cooling.Name));

                            Profile profile;

                            if (dictionary.TryGetValue(ProfileType.Humidification, out profile))
                            {
                                ScheduleRuleset scheduleRuleset = profile.ToLadybugTools();
                                if (scheduleRuleset != null)
                                {
                                    setpoint.HumidifyingSchedule = scheduleRuleset;
                                }
                            }

                            if (dictionary.TryGetValue(ProfileType.Dehumidification, out profile))
                            {
                                ScheduleRuleset scheduleRuleset = profile.ToLadybugTools();
                                if (scheduleRuleset != null)
                                {
                                    setpoint.DehumidifyingSchedule = scheduleRuleset;
                                }
                            }
                        }
                    }
                }
            }

            ProgramType result = new ProgramType(
                identifier: uniqueName,
                displayName: internalCondition.Name,
                userData: null,
                people: people,
                lighting: lighting,
                electricEquipment: electricEquipment,
                infiltration: infiltration,
                setpoint: setpoint);

            return(result);
        }
예제 #11
0
        public static bool UpdateInternalCondition(this TBD.InternalCondition internalCondition_TBD, Space space, ProfileLibrary profileLibrary)
        {
            if (space == null || internalCondition_TBD == null)
            {
                return(false);
            }

            InternalCondition internalCondition = space.InternalCondition;

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

            internalCondition_TBD.name        = space.Name;
            internalCondition_TBD.description = internalCondition.Name;

            internalCondition_TBD.includeSolarInMRT = 1;

            TBD.Emitter emitter = null;
            double      value   = double.NaN;

            emitter = internalCondition_TBD.GetHeatingEmitter();
            if (emitter != null)
            {
                emitter.name = internalCondition.GetSystemTypeName <HeatingSystemType>();

                if (internalCondition.TryGetValue(InternalConditionParameter.HeatingEmitterRadiantProportion, out value))
                {
                    emitter.radiantProportion = System.Convert.ToSingle(value);
                }

                if (internalCondition.TryGetValue(InternalConditionParameter.HeatingEmitterCoefficient, out value))
                {
                    emitter.viewCoefficient = System.Convert.ToSingle(value);
                }
            }

            emitter = internalCondition_TBD.GetCoolingEmitter();
            if (emitter != null)
            {
                emitter.name = internalCondition.GetSystemTypeName <CoolingSystemType>();

                if (internalCondition.TryGetValue(InternalConditionParameter.CoolingEmitterRadiantProportion, out value))
                {
                    emitter.radiantProportion = System.Convert.ToSingle(value);
                }

                if (internalCondition.TryGetValue(InternalConditionParameter.CoolingEmitterCoefficient, out value))
                {
                    emitter.viewCoefficient = System.Convert.ToSingle(value);
                }
            }

            TBD.InternalGain internalGain = internalCondition_TBD.GetInternalGain();

            if (internalCondition.TryGetValue(InternalConditionParameter.LightingRadiantProportion, out value))
            {
                internalGain.lightingRadProp = System.Convert.ToSingle(value);
            }

            if (internalCondition.TryGetValue(InternalConditionParameter.OccupancyRadiantProportion, out value))
            {
                internalGain.occupantRadProp = System.Convert.ToSingle(value);
            }

            if (internalCondition.TryGetValue(InternalConditionParameter.EquipmentRadiantProportion, out value))
            {
                internalGain.equipmentRadProp = System.Convert.ToSingle(value);
            }

            if (internalCondition.TryGetValue(InternalConditionParameter.LightingViewCoefficient, out value))
            {
                internalGain.lightingViewCoefficient = System.Convert.ToSingle(value);
            }

            if (internalCondition.TryGetValue(InternalConditionParameter.OccupancyViewCoefficient, out value))
            {
                internalGain.occupantViewCoefficient = System.Convert.ToSingle(value);
            }

            if (internalCondition.TryGetValue(InternalConditionParameter.EquipmentViewCoefficient, out value))
            {
                internalGain.equipmentViewCoefficient = System.Convert.ToSingle(value);
            }

            internalGain.domesticHotWater = (float)0.197;

            internalGain.name        = internalCondition.Name;
            internalGain.description = internalCondition.GetSystemTypeName <VentilationSystemType>();

            if (internalCondition.TryGetValue(InternalConditionParameter.LightingLevel, out value))
            {
                internalGain.targetIlluminance = System.Convert.ToSingle(value);
            }

            internalGain.personGain = 0;
            double occupancyGainPerPerson = Analytical.Query.OccupancyGainPerPerson(space);

            if (!double.IsNaN(occupancyGainPerPerson))
            {
                internalGain.personGain = System.Convert.ToSingle(occupancyGainPerPerson);
            }

            Profile profile = null;

            profile = internalCondition.GetProfile(ProfileType.Infiltration, profileLibrary);
            if (profile != null)
            {
                if (internalCondition.TryGetValue(InternalConditionParameter.InfiltrationAirChangesPerHour, out value))
                {
                    TBD.profile profile_TBD = internalGain.GetProfile((int)TBD.Profiles.ticI);
                    if (profile_TBD != null)
                    {
                        Update(profile_TBD, profile, value);
                    }
                }
            }

            double area = double.NaN;

            if (!space.TryGetValue(SpaceParameter.Area, out area))
            {
                area = double.NaN;
            }

            profile = internalCondition.GetProfile(ProfileType.Lighting, profileLibrary);
            if (profile != null)
            {
                TBD.profile profile_TBD = internalGain.GetProfile((int)TBD.Profiles.ticLG);
                if (profile_TBD != null)
                {
                    double gain = Analytical.Query.CalculatedLightingGain(space);
                    if (double.IsNaN(area) || area == 0 || double.IsNaN(gain))
                    {
                        gain = 0;
                    }
                    else
                    {
                        gain = gain / area;
                    }

                    Update(profile_TBD, profile, gain);
                }
            }

            profile = internalCondition.GetProfile(ProfileType.Occupancy, profileLibrary);
            if (profile != null)
            {
                TBD.profile profile_TBD = null;

                profile_TBD = internalGain.GetProfile((int)TBD.Profiles.ticOLG);
                if (profile_TBD != null)
                {
                    double gain = Analytical.Query.OccupancyLatentGain(space);
                    if (double.IsNaN(area) || area == 0 || double.IsNaN(gain))
                    {
                        gain = 0;
                    }
                    else
                    {
                        gain = gain / area;
                    }

                    Update(profile_TBD, profile, gain);
                }

                profile_TBD = internalGain.GetProfile((int)TBD.Profiles.ticOSG);
                if (profile_TBD != null)
                {
                    double gain = Analytical.Query.OccupancySensibleGain(space);
                    if (double.IsNaN(area) || area == 0 || double.IsNaN(gain))
                    {
                        gain = 0;
                    }
                    else
                    {
                        gain = gain / area;
                    }

                    Update(profile_TBD, profile, gain);
                }
            }

            profile = internalCondition.GetProfile(ProfileType.EquipmentSensible, profileLibrary);
            if (profile != null)
            {
                TBD.profile profile_TBD = internalGain.GetProfile((int)TBD.Profiles.ticESG);
                if (profile_TBD != null)
                {
                    double gain = Analytical.Query.CalculatedEquipmentSensibleGain(space);
                    if (double.IsNaN(area) || area == 0 || double.IsNaN(gain))
                    {
                        gain = 0;
                    }
                    else
                    {
                        gain = gain / area;
                    }

                    Update(profile_TBD, profile, gain);
                }
            }

            profile = internalCondition.GetProfile(ProfileType.EquipmentLatent, profileLibrary);
            if (profile != null)
            {
                TBD.profile profile_TBD = internalGain.GetProfile((int)TBD.Profiles.ticELG);
                if (profile_TBD != null)
                {
                    double gain = Analytical.Query.CalculatedEquipmentLatentGain(space);
                    if (double.IsNaN(area) || area == 0 || double.IsNaN(gain))
                    {
                        gain = 0;
                    }
                    else
                    {
                        gain = gain / area;
                    }

                    Update(profile_TBD, profile, gain);
                }
            }

            profile = internalCondition.GetProfile(ProfileType.Pollutant, profileLibrary);
            if (profile != null)
            {
                TBD.profile profile_TBD = internalGain.GetProfile((int)TBD.Profiles.ticCOG);
                if (profile_TBD != null)
                {
                    double generation = Analytical.Query.CalculatedPollutantGeneration(space);
                    if (double.IsNaN(area) || area == 0 || double.IsNaN(generation))
                    {
                        generation = 0;
                    }
                    else
                    {
                        generation = generation / area;
                    }

                    Update(profile_TBD, profile, generation);
                }
            }

            TBD.Thermostat thermostat = internalCondition_TBD.GetThermostat();
            if (thermostat != null)
            {
                List <string> names = new List <string>();

                thermostat.controlRange        = 0;
                thermostat.proportionalControl = 0;

                profile = internalCondition.GetProfile(ProfileType.Cooling, profileLibrary);
                if (profile != null)
                {
                    names.Add(profile.Name);

                    TBD.profile profile_TBD = thermostat.GetProfile((int)TBD.Profiles.ticUL);
                    if (profile_TBD != null)
                    {
                        Update(profile_TBD, profile, 1);
                    }
                }

                profile = internalCondition.GetProfile(ProfileType.Heating, profileLibrary);
                if (profile != null)
                {
                    names.Add(profile.Name);

                    TBD.profile profile_TBD = thermostat.GetProfile((int)TBD.Profiles.ticLL);
                    if (profile_TBD != null)
                    {
                        Update(profile_TBD, profile, 1);
                    }
                }

                profile = internalCondition.GetProfile(ProfileType.Humidification, profileLibrary);
                if (profile != null)
                {
                    names.Add(profile.Name);

                    TBD.profile profile_TBD = thermostat.GetProfile((int)TBD.Profiles.ticHLL);
                    if (profile_TBD != null)
                    {
                        Update(profile_TBD, profile, 1);
                    }
                }

                profile = internalCondition.GetProfile(ProfileType.Dehumidification, profileLibrary);
                if (profile != null)
                {
                    names.Add(profile.Name);

                    TBD.profile profile_TBD = thermostat.GetProfile((int)TBD.Profiles.ticHUL);
                    if (profile_TBD != null)
                    {
                        Update(profile_TBD, profile, 1);
                    }
                }

                names.RemoveAll(x => string.IsNullOrWhiteSpace(x));

                if (names.Count != 0)
                {
                    thermostat.name = string.Join(" & ", names);
                }
            }

            return(true);
        }
예제 #12
0
파일: Space.cs 프로젝트: HoareLea/SAM_Revit
        public static Autodesk.Revit.DB.Mechanical.Space ToRevit(this Space space, Document document, ConvertSettings convertSettings)
        {
            if (space == null)
            {
                return(null);
            }

            Autodesk.Revit.DB.Mechanical.Space result = convertSettings?.GetObject <Autodesk.Revit.DB.Mechanical.Space>(space.Guid);
            if (result != null)
            {
                return(result);
            }

            if (!convertSettings.RemoveExisting)
            {
                result = Core.Revit.Query.Element <Autodesk.Revit.DB.Mechanical.Space>(document, space);
            }

            if (result == null)
            {
                double lowElevation = Query.LowElevation(space);
                if (double.IsNaN(lowElevation))
                {
                    return(null);
                }

                Level level = Geometry.Revit.Query.LowLevel(document, lowElevation);
                if (level == null)
                {
                    return(null);
                }

#if Revit2017 || Revit2018 || Revit2019 || Revit2020
                result = document.Create.NewSpace(level, new UV(UnitUtils.ConvertToInternalUnits(space.Location.X, DisplayUnitType.DUT_METERS), UnitUtils.ConvertToInternalUnits(space.Location.Y, DisplayUnitType.DUT_METERS)));
#else
                result = document.Create.NewSpace(level, new UV(UnitUtils.ConvertToInternalUnits(space.Location.X, UnitTypeId.Meters), UnitUtils.ConvertToInternalUnits(space.Location.Y, UnitTypeId.Meters)));
#endif
            }

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

            //result.get_Parameter(BuiltInParameter.ROOM_NAME).Set(string.Empty);
            //result.get_Parameter(BuiltInParameter.ROOM_NUMBER).Set(space.Name);

            result.get_Parameter(BuiltInParameter.ROOM_NAME).Set(space.Name);

            if (convertSettings.ConvertParameters)
            {
                Dictionary <string, object> parameters = convertSettings.GetParameters();

                InternalCondition internalCondition = space.InternalCondition;
                if (internalCondition != null)
                {
                    Core.Revit.Modify.SetValues(result, internalCondition);
                    Core.Revit.Modify.SetValues(result, internalCondition, ActiveSetting.Setting, parameters);
                }

                Core.Revit.Modify.SetValues(result, space);
                Core.Revit.Modify.SetValues(result, space, ActiveSetting.Setting, parameters);

                Core.Revit.Modify.SetJson(result, space.ToJObject()?.ToString());
            }

            convertSettings?.Add(space.Guid, result);

            return(result);
        }
예제 #13
0
        public static InternalCondition ToSAM(this TBD.InternalCondition internalCondition, double area = double.NaN)
        {
            if (internalCondition == null)
            {
                return(null);
            }

            InternalCondition result = new InternalCondition(internalCondition.name);

            TBD.Emitter emitter = null;

            emitter = internalCondition.GetHeatingEmitter();
            if (emitter != null)
            {
                result.SetValue(InternalConditionParameter.HeatingEmitterRadiantProportion, emitter.radiantProportion);
                result.SetValue(InternalConditionParameter.HeatingEmitterCoefficient, emitter.viewCoefficient);
            }

            emitter = internalCondition.GetCoolingEmitter();
            if (emitter != null)
            {
                result.SetValue(InternalConditionParameter.CoolingEmitterRadiantProportion, emitter.radiantProportion);
                result.SetValue(InternalConditionParameter.CoolingEmitterCoefficient, emitter.viewCoefficient);
            }

            TBD.InternalGain internalGain = internalCondition.GetInternalGain();
            if (internalGain != null)
            {
                result.SetValue(InternalConditionParameter.LightingRadiantProportion, internalGain.lightingRadProp);
                result.SetValue(InternalConditionParameter.OccupancyRadiantProportion, internalGain.occupantRadProp);
                result.SetValue(InternalConditionParameter.EquipmentRadiantProportion, internalGain.equipmentRadProp);

                result.SetValue(InternalConditionParameter.LightingViewCoefficient, internalGain.lightingViewCoefficient);
                result.SetValue(InternalConditionParameter.OccupancyViewCoefficient, internalGain.occupantViewCoefficient);
                result.SetValue(InternalConditionParameter.EquipmentViewCoefficient, internalGain.equipmentViewCoefficient);

                TBD.profile profile_TBD = null;
                profile_TBD = internalGain.GetProfile((int)TBD.Profiles.ticI);
                if (profile_TBD != null)
                {
                    result.SetValue(InternalConditionParameter.InfiltrationProfileName, string.Format("{0} [{1}]", internalCondition.name, profile_TBD.name));
                    result.SetValue(InternalConditionParameter.InfiltrationAirChangesPerHour, profile_TBD.GetExtremeValue(true));
                }

                profile_TBD = internalGain.GetProfile((int)TBD.Profiles.ticLG);
                if (profile_TBD != null)
                {
                    result.SetValue(InternalConditionParameter.LightingProfileName, string.Format("{0} [{1}]", internalCondition.name, profile_TBD.name));
                    result.SetValue(InternalConditionParameter.LightingGainPerArea, profile_TBD.GetExtremeValue(true));
                    result.SetValue(InternalConditionParameter.LightingLevel, internalGain.targetIlluminance);
                }

                double personGain = internalGain.personGain;
                double gain       = 0;

                profile_TBD = internalGain.GetProfile((int)TBD.Profiles.ticOSG);
                if (profile_TBD != null)
                {
                    double value = profile_TBD.GetExtremeValue(true);
                    result.SetValue(InternalConditionParameter.OccupancySensibleGainPerPerson, value);
                    gain += value;
                }

                profile_TBD = internalGain.GetProfile((int)TBD.Profiles.ticOLG);
                if (profile_TBD != null)
                {
                    double value = profile_TBD.GetExtremeValue(true);
                    result.SetValue(InternalConditionParameter.OccupancyProfileName, string.Format("{0} [{1}]", internalCondition.name, profile_TBD.name));
                    result.SetValue(InternalConditionParameter.OccupancyLatentGainPerPerson, value);
                    gain += value;
                }

                if (!double.IsNaN(area) && !double.IsNaN(gain))
                {
                    double occupancy = (gain * area) / personGain;
                    result.SetValue(InternalConditionParameter.AreaPerPerson, area / occupancy);
                }

                profile_TBD = internalGain.GetProfile((int)TBD.Profiles.ticESG);
                if (profile_TBD != null)
                {
                    result.SetValue(InternalConditionParameter.EquipmentSensibleProfileName, string.Format("{0} [{1}]", internalCondition.name, profile_TBD.name));
                    result.SetValue(InternalConditionParameter.EquipmentSensibleGainPerArea, profile_TBD.GetExtremeValue(true));
                }

                profile_TBD = internalGain.GetProfile((int)TBD.Profiles.ticELG);
                if (profile_TBD != null)
                {
                    result.SetValue(InternalConditionParameter.EquipmentLatentProfileName, string.Format("{0} [{1}]", internalCondition.name, profile_TBD.name));
                    result.SetValue(InternalConditionParameter.EquipmentLatentGainPerArea, profile_TBD.GetExtremeValue(true));
                }

                profile_TBD = internalGain.GetProfile((int)TBD.Profiles.ticCOG);
                if (profile_TBD != null)
                {
                    result.SetValue(InternalConditionParameter.PollutantProfileName, string.Format("{0} [{1}]", internalCondition.name, profile_TBD.name));
                    result.SetValue(InternalConditionParameter.PollutantGenerationPerArea, profile_TBD.GetExtremeValue(true));
                }
            }

            TBD.Thermostat thermostat = internalCondition.GetThermostat();
            if (internalGain != null)
            {
                TBD.profile profile_TBD = null;

                profile_TBD = thermostat.GetProfile((int)TBD.Profiles.ticUL);
                if (profile_TBD != null)
                {
                    result.SetValue(InternalConditionParameter.CoolingProfileName, string.Format("{0} [{1}]", internalCondition.name, profile_TBD.name));
                }

                profile_TBD = thermostat.GetProfile((int)TBD.Profiles.ticLL);
                if (profile_TBD != null)
                {
                    result.SetValue(InternalConditionParameter.HeatingProfileName, string.Format("{0} [{1}]", internalCondition.name, profile_TBD.name));
                }

                profile_TBD = thermostat.GetProfile((int)TBD.Profiles.ticHLL);
                if (profile_TBD != null)
                {
                    result.SetValue(InternalConditionParameter.HumidificationProfileName, string.Format("{0} [{1}]", internalCondition.name, profile_TBD.name));
                }

                profile_TBD = thermostat.GetProfile((int)TBD.Profiles.ticHUL);
                if (profile_TBD != null)
                {
                    result.SetValue(InternalConditionParameter.DehumidificationProfileName, string.Format("{0} [{1}]", internalCondition.name, profile_TBD.name));
                }
            }

            return(result);
        }
예제 #14
0
        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);
        }
예제 #15
0
        public static InternalCondition ToSAM_InternalCondition(this ProgramTypeAbridged programTypeAbridged, ModelEnergyProperties modelEnergyProperties)
        {
            if (programTypeAbridged == null)
            {
                return(null);
            }

            InternalCondition result = new InternalCondition(programTypeAbridged.Identifier);

            PeopleAbridged peopleAbridged = programTypeAbridged.People;

            if (peopleAbridged != null)
            {
                result.SetValue(Analytical.InternalConditionParameter.OccupancyProfileName, peopleAbridged.OccupancySchedule);
                result.SetValue(Analytical.InternalConditionParameter.AreaPerPerson, 1 / peopleAbridged.PeoplePerArea);

                if (modelEnergyProperties != null)
                {
                    IEnumerable <HoneybeeSchema.Energy.ISchedule> schedules = modelEnergyProperties.ScheduleList;
                    if (schedules != null)
                    {
                        foreach (HoneybeeSchema.Energy.ISchedule schedule in schedules)
                        {
                            if (schedule.Identifier == peopleAbridged.ActivitySchedule)
                            {
                                Profile profile = schedule.ToSAM(ProfileType.Other);
                                if (profile != null)
                                {
                                    result.SetValue(InternalConditionParameter.TotalMetabolicRatePerPerson, profile.MaxValue);
                                }
                            }
                        }
                    }
                }

                result.SetValue(Analytical.InternalConditionParameter.OccupancyRadiantProportion, peopleAbridged.RadiantFraction);
                result.SetValue(Analytical.InternalConditionParameter.OccupancyViewCoefficient, 0.227); //TODDO: Implement proper OccupancyViewCoefficient

                if (peopleAbridged.LatentFraction != null && peopleAbridged.LatentFraction.Obj is double)
                {
                    result.SetValue(InternalConditionParameter.LatentFraction, (double)peopleAbridged.LatentFraction.Obj); //TODO: Recalculate value per space
                }
            }

            LightingAbridged lightingAbridged = programTypeAbridged.Lighting;

            if (lightingAbridged != null)
            {
                result.SetValue(Analytical.InternalConditionParameter.LightingProfileName, lightingAbridged.Schedule);
                result.SetValue(Analytical.InternalConditionParameter.LightingGainPerArea, lightingAbridged.WattsPerArea);

                result.SetValue(Analytical.InternalConditionParameter.LightingRadiantProportion, lightingAbridged.RadiantFraction);
                result.SetValue(Analytical.InternalConditionParameter.LightingViewCoefficient, lightingAbridged.VisibleFraction);
            }

            ElectricEquipmentAbridged electricEquipmentAbridged = programTypeAbridged.ElectricEquipment;

            if (electricEquipmentAbridged != null)
            {
                result.SetValue(Analytical.InternalConditionParameter.EquipmentSensibleProfileName, electricEquipmentAbridged.Schedule);
                result.SetValue(Analytical.InternalConditionParameter.EquipmentSensibleGainPerArea, electricEquipmentAbridged.WattsPerArea);

                result.SetValue(Analytical.InternalConditionParameter.EquipmentRadiantProportion, electricEquipmentAbridged.RadiantFraction);
                result.SetValue(Analytical.InternalConditionParameter.EquipmentViewCoefficient, 0.372); //TODDO: Implement proper EquipmentViewCoefficient
            }

            InfiltrationAbridged infiltrationAbridged = programTypeAbridged.Infiltration;

            if (infiltrationAbridged != null)
            {
                result.SetValue(Analytical.InternalConditionParameter.InfiltrationProfileName, infiltrationAbridged.Schedule);
                result.SetValue(InternalConditionParameter.FlowPerExteriorArea, infiltrationAbridged.FlowPerExteriorArea); //TODO: Recalculate value per space
            }

            SetpointAbridged setPoint = programTypeAbridged.Setpoint;

            if (setPoint != null)
            {
                result.SetValue(Analytical.InternalConditionParameter.CoolingProfileName, setPoint.CoolingSchedule);

                result.SetValue(Analytical.InternalConditionParameter.HeatingProfileName, setPoint.HeatingSchedule);
            }

            VentilationAbridged ventilationAbridged = programTypeAbridged.Ventilation;

            if (ventilationAbridged != null)
            {
                result.SetValue(Analytical.InternalConditionParameter.SupplyAirFlow, ventilationAbridged.FlowPerZone);
                result.SetValue(Analytical.InternalConditionParameter.SupplyAirFlowPerArea, ventilationAbridged.FlowPerArea);
                result.SetValue(Analytical.InternalConditionParameter.SupplyAirFlowPerPerson, ventilationAbridged.FlowPerPerson);

                result.SetValue(Analytical.InternalConditionParameter.ExhaustAirFlow, ventilationAbridged.FlowPerZone);
                result.SetValue(Analytical.InternalConditionParameter.ExhaustAirFlowPerArea, ventilationAbridged.FlowPerArea);
                result.SetValue(Analytical.InternalConditionParameter.ExhaustAirFlowPerPerson, ventilationAbridged.FlowPerPerson);
            }

            return(result);
        }
예제 #16
0
        public static Space ToSAM(this Room room, IEnumerable <InternalCondition> internalConditions = null)
        {
            if (room == null)
            {
                return(null);
            }

            Geometry.Spatial.Point3D location = null;
            double area   = double.NaN;
            double volume = double.NaN;

            Geometry.Spatial.Shell shell = Geometry.LadybugTools.Query.Shell(room);
            if (shell != null)
            {
                location = shell.InternalPoint3D();
                area     = Geometry.Spatial.Query.Area(shell, 0.1);
                volume   = Geometry.Spatial.Query.Volume(shell);
            }

            Space result = new Space(room.DisplayName, location);

            if (!double.IsNaN(area))
            {
                result.SetValue(SpaceParameter.Area, area);
            }

            if (!double.IsNaN(volume))
            {
                result.SetValue(SpaceParameter.Volume, volume);
            }

            result.SetValue(SpaceParameter.LevelName, room.Story);

            string programType = room.Properties?.Energy?.ProgramType;

            if (!string.IsNullOrWhiteSpace(programType))
            {
                InternalCondition internalCondition = null;
                if (internalConditions != null)
                {
                    foreach (InternalCondition internalCondition_Temp in internalConditions)
                    {
                        if (internalCondition_Temp.Name == programType)
                        {
                            internalCondition = internalCondition_Temp;
                            break;
                        }
                    }
                }

                if (internalCondition == null)
                {
                    internalCondition = new InternalCondition(programType);
                }

                if (internalCondition != null && !double.IsNaN(volume))
                {
                    if (internalCondition.TryGetValue(InternalConditionParameter.FlowPerExteriorArea, out double flowPerExteriorArea))
                    {
                        internalCondition = new InternalCondition(System.Guid.NewGuid(), internalCondition);
                        double exteriorArea = Geometry.LadybugTools.Query.ExteriorArea(room);

                        double flow = flowPerExteriorArea * exteriorArea;

                        internalCondition.SetValue(Analytical.InternalConditionParameter.InfiltrationAirChangesPerHour, flow / volume * 3600);
                    }
                }

                if (!double.IsNaN(area) && internalCondition.TryGetValue(InternalConditionParameter.TotalMetabolicRatePerPerson, out double totalMetabolicRate) && internalCondition.TryGetValue(Analytical.InternalConditionParameter.AreaPerPerson, out double areaPerPerson))
                {
                    double people = area / areaPerPerson;

                    double occupancyLatentGainPerPerson   = 0;
                    double occupancySensibleGainPerPerson = 0;

                    if (internalCondition.TryGetValue(InternalConditionParameter.LatentFraction, out double latentFraction))
                    {
                        occupancyLatentGainPerPerson   = totalMetabolicRate * latentFraction;
                        occupancySensibleGainPerPerson = totalMetabolicRate * (1 - latentFraction);
                    }
                    else
                    {
                        //2021-XI-16 if latent is missin or autocalcutlate zero will be used in Tas! custom specific settings
                        occupancySensibleGainPerPerson = totalMetabolicRate;
                    }

                    internalCondition.SetValue(Analytical.InternalConditionParameter.OccupancyLatentGainPerPerson, occupancyLatentGainPerPerson);
                    internalCondition.SetValue(Analytical.InternalConditionParameter.OccupancySensibleGainPerPerson, occupancySensibleGainPerPerson);
                }

                result.InternalCondition = internalCondition;
            }

            return(result);
        }
예제 #17
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);
        }