Пример #1
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);
        }
        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);
        }
Пример #3
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);
        }