public static PartitionSimulationResult ToSAM_PartitionSimulationResult(this SurfaceData surfaceData, IEnumerable <PanelDataType> panelDataTypes = null) { if (surfaceData == null) { return(null); } PartitionSimulationResult result = new PartitionSimulationResult(surfaceData.BEName, Assembly.GetExecutingAssembly().GetName()?.Name, surfaceData.surfaceNumber.ToString()); result.SetValue("BuildingElementType", ((TBD.BuildingElementType)surfaceData.BEType).ToString()); result.SetValue("Area", surfaceData.area); result.SetValue("Orientation", surfaceData.orientation); ParameterSet parameterSet = Create.ParameterSet(ActiveSetting.Setting, surfaceData); if (panelDataTypes != null) { foreach (PanelDataType panelDataType in panelDataTypes) { List <double> values = surfaceData.AnnualSurfaceResult <double>(panelDataType); if (values == null) { continue; } JArray jArray = new JArray(); values.ForEach(x => jArray.Add(x)); parameterSet.Add(panelDataType.Text(), jArray); } } result.Add(parameterSet); return(result); }
public static Panel ToSAM(this SurfaceData surfaceData, IEnumerable <PanelDataType> panelDataTypes = null) { if (surfaceData == null) { return(null); } ParameterSet parameterSet = Create.ParameterSet(ActiveSetting.Setting, surfaceData); if (panelDataTypes != null) { foreach (PanelDataType panelDataType in panelDataTypes) { List <double> values = surfaceData.AnnualSurfaceResult <double>(panelDataType); if (values == null) { continue; } JArray jArray = new JArray(); values.ForEach(x => jArray.Add(x)); parameterSet.Add(panelDataType.Text(), jArray); } } PanelType panelType = Query.PanelType(surfaceData.BEType); PlanarBoundary3D planarBoundary3D = null; Panel panel = Analytical.Create.Panel(new Construction(surfaceData.BEName), panelType, planarBoundary3D); panel.Add(parameterSet); return(panel); }
public static List <Core.Result> AddResults(this SimulationData simulationData, BuildingModel buildingModel) { if (simulationData == null || buildingModel == null) { return(null); } List <Core.Result> result = null; //get simulaton data from Tas for individal SAM Space List <Core.Result> results = Convert.ToSAM(simulationData); if (results == null) { return(result); } result = new List <Core.Result>(results); Dictionary <System.Guid, List <SpaceSimulationResult> > dictionary = new Dictionary <System.Guid, List <SpaceSimulationResult> >(); List <Space> spaces = buildingModel.GetSpaces(); if (spaces != null && spaces.Count > 0) { foreach (Space space in spaces) { List <SpaceSimulationResult> spaceSimulationResults_Space = results.FindAll(x => x is SpaceSimulationResult && space.Name.Equals(x.Name)).ConvertAll(x => (SpaceSimulationResult)x); dictionary[space.Guid] = spaceSimulationResults_Space; if (spaceSimulationResults_Space != null && spaceSimulationResults_Space.Count > 0) { foreach (SpaceSimulationResult spaceSimulationResult in spaceSimulationResults_Space) { buildingModel.Add(spaceSimulationResult, space.Guid); } } } } // get data data about SAM Zones like space GUID, Zone Category etc. List <Zone> zones = buildingModel.GetZones(); if (zones != null && zones.Count > 0) { // Query Tas Zones, that can be linked with SAM Spaces BuildingData buildingData = simulationData.GetBuildingData(); Dictionary <string, ZoneData> dictionary_ZoneData = Query.ZoneDataDictionary(buildingData); // Our SAM Zones(list of Space GUIDs) foreach (Zone zone in zones) { List <Space> spaces_Zone = buildingModel.GetSpaces(zone); if (spaces_Zone == null || spaces_Zone.Count == 0) { continue; } double area = buildingModel.Sum(zone, SpaceParameter.Area); double volume = buildingModel.Sum(zone, SpaceParameter.Volume); double occupancy = buildingModel.Sum(zone, SpaceParameter.Occupancy); List <ZoneData> zoneDatas = new List <ZoneData>(); foreach (Space space in spaces_Zone) { string name = space?.Name; if (string.IsNullOrWhiteSpace(name)) { continue; } List <SpaceSimulationResult> spaceSimulationResults_Space; if (!dictionary.TryGetValue(space.Guid, out spaceSimulationResults_Space) || spaceSimulationResults_Space == null || spaceSimulationResults_Space.Count == 0) { continue; } SpaceSimulationResult spaceSimulationResult = spaceSimulationResults_Space[0]; if (spaceSimulationResult == null || string.IsNullOrWhiteSpace(spaceSimulationResult.Reference)) { continue; } ZoneData zoneData = dictionary_ZoneData[spaceSimulationResult.Reference]; if (zoneData == null) { continue; } zoneDatas.Add(zoneData); } int index; double max; //Cooling ZoneSimulationResult zoneSimulationResult_Cooling = null; if (buildingData.TryGetMax(zoneDatas.ConvertAll(x => x.zoneGUID), tsdZoneArray.coolingLoad, out index, out max) && index != -1 && !double.IsNaN(max)) { zoneSimulationResult_Cooling = new ZoneSimulationResult(zone.Name, Assembly.GetExecutingAssembly().GetName()?.Name, zone.Guid.ToString()); zoneSimulationResult_Cooling.SetValue(ZoneSimulationResultParameter.MaxSensibleLoad, max); zoneSimulationResult_Cooling.SetValue(ZoneSimulationResultParameter.MaxSensibleLoadIndex, index); zoneSimulationResult_Cooling.SetValue(ZoneSimulationResultParameter.LoadType, LoadType.Cooling.Text()); List <SpaceSimulationResult> spaceSimulationResults_Zone = new List <SpaceSimulationResult>(); foreach (ZoneData zoneData in zoneDatas) { SpaceSimulationResult spaceSimulationResult_Temp = Create.SpaceSimulationResult(zoneData, index, LoadType.Cooling, SizingMethod.Simulation); if (spaceSimulationResult_Temp == null) { continue; } spaceSimulationResults_Zone.Add(spaceSimulationResult_Temp); } if (spaceSimulationResults_Zone != null && spaceSimulationResults_Zone.Count != 0) { double airMovementGain = spaceSimulationResults_Zone.Sum(Analytical.SpaceSimulationResultParameter.AirMovementGain); if (!double.IsNaN(airMovementGain)) { zoneSimulationResult_Cooling.SetValue(ZoneSimulationResultParameter.AirMovementGain, airMovementGain); } double buildingHeatTransfer = spaceSimulationResults_Zone.Sum(Analytical.SpaceSimulationResultParameter.BuildingHeatTransfer); if (!double.IsNaN(buildingHeatTransfer)) { zoneSimulationResult_Cooling.SetValue(ZoneSimulationResultParameter.BuildingHeatTransfer, buildingHeatTransfer); } double equipmentSensibleGain = spaceSimulationResults_Zone.Sum(Analytical.SpaceSimulationResultParameter.EquipmentSensibleGain); if (!double.IsNaN(equipmentSensibleGain)) { zoneSimulationResult_Cooling.SetValue(ZoneSimulationResultParameter.EquipmentSensibleGain, equipmentSensibleGain); } double glazingExternalConduction = spaceSimulationResults_Zone.Sum(Analytical.SpaceSimulationResultParameter.GlazingExternalConduction); if (!double.IsNaN(glazingExternalConduction)) { zoneSimulationResult_Cooling.SetValue(ZoneSimulationResultParameter.GlazingExternalConduction, glazingExternalConduction); } double lightingGain = spaceSimulationResults_Zone.Sum(Analytical.SpaceSimulationResultParameter.LightingGain); if (!double.IsNaN(lightingGain)) { zoneSimulationResult_Cooling.SetValue(ZoneSimulationResultParameter.LightingGain, lightingGain); } double infiltrationGain = spaceSimulationResults_Zone.Sum(Analytical.SpaceSimulationResultParameter.InfiltrationGain); if (!double.IsNaN(infiltrationGain)) { zoneSimulationResult_Cooling.SetValue(ZoneSimulationResultParameter.InfiltrationGain, infiltrationGain); } double occupancySensibleGain = spaceSimulationResults_Zone.Sum(Analytical.SpaceSimulationResultParameter.OccupancySensibleGain); if (!double.IsNaN(occupancySensibleGain)) { zoneSimulationResult_Cooling.SetValue(ZoneSimulationResultParameter.OccupancySensibleGain, occupancySensibleGain); } double opaqueExternalConduction = spaceSimulationResults_Zone.Sum(Analytical.SpaceSimulationResultParameter.OpaqueExternalConduction); if (!double.IsNaN(opaqueExternalConduction)) { zoneSimulationResult_Cooling.SetValue(ZoneSimulationResultParameter.OpaqueExternalConduction, opaqueExternalConduction); } double solarGain = spaceSimulationResults_Zone.Sum(Analytical.SpaceSimulationResultParameter.SolarGain); if (!double.IsNaN(solarGain)) { zoneSimulationResult_Cooling.SetValue(ZoneSimulationResultParameter.SolarGain, solarGain); } } } if (!double.IsNaN(occupancy)) { zoneSimulationResult_Cooling?.SetValue(ZoneSimulationResultParameter.Occupancy, occupancy); } if (!double.IsNaN(area)) { zoneSimulationResult_Cooling?.SetValue(ZoneSimulationResultParameter.Area, area); } if (!double.IsNaN(volume)) { zoneSimulationResult_Cooling?.SetValue(ZoneSimulationResultParameter.Volume, volume); } if (zoneSimulationResult_Cooling != null) { buildingModel.Add(zoneSimulationResult_Cooling, zone); result.Add(zoneSimulationResult_Cooling); } //Heating //ZoneSimulationResult zoneSimulationResult_Heating = null; //if (buildingData.TryGetMax(zoneDatas.ConvertAll(x => x.zoneGUID), tsdZoneArray.heatingLoad, out index, out max) && index != -1 && !double.IsNaN(max)) //{ //zoneSimulationResult_Heating = new ZoneSimulationResult(zone.Name, Assembly.GetExecutingAssembly().GetName()?.Name, zone.Guid.ToString()); //zoneSimulationResult_Heating.SetValue(ZoneSimulationResultParameter.MaxSensibleLoad, max); //zoneSimulationResult_Heating.SetValue(ZoneSimulationResultParameter.MaxSensibleLoadIndex, index); //zoneSimulationResult_Heating.SetValue(ZoneSimulationResultParameter.LoadType, LoadType.Heating.Text()); //List<SpaceSimulationResult> spaceSimulationResults_Zone = new List<SpaceSimulationResult>(); //foreach (ZoneData zoneData in zoneDatas) //{ // SpaceSimulationResult spaceSimulationResult_Temp = spaceSimulationResults.FindAll(x => x.LoadType() == LoadType.Heating).Find(x => x.Reference == zoneData.zoneGUID); // if (spaceSimulationResult_Temp == null) // continue; // spaceSimulationResults_Zone.Add(spaceSimulationResult_Temp); //} //if (spaceSimulationResults_Zone != null && spaceSimulationResults_Zone.Count != 0) //{ // //double senisbleLoad = spaceSimulationResults_Zone.Sum(SpaceSimulationResultParameter.Load); // //if (!double.IsNaN(senisbleLoad)) // // zoneSimulationResult_Heating.SetValue(ZoneSimulationResultParameter.MaxSensibleLoad, senisbleLoad); // //double airMovementGain = spaceSimulationResults_Zone.Sum(SpaceSimulationResultParameter.AirMovementGain); // //if (!double.IsNaN(airMovementGain)) // // zoneSimulationResult_Heating.SetValue(ZoneSimulationResultParameter.AirMovementGain, airMovementGain); // //double buildingHeatTransfer = spaceSimulationResults_Zone.Sum(SpaceSimulationResultParameter.BuildingHeatTransfer); // //if (!double.IsNaN(buildingHeatTransfer)) // // zoneSimulationResult_Heating.SetValue(ZoneSimulationResultParameter.BuildingHeatTransfer, buildingHeatTransfer); // //double glazingExternalConduction = spaceSimulationResults_Zone.Sum(SpaceSimulationResultParameter.GlazingExternalConduction); // //if (!double.IsNaN(glazingExternalConduction)) // // zoneSimulationResult_Heating.SetValue(ZoneSimulationResultParameter.GlazingExternalConduction, glazingExternalConduction); // //double infiltrationGain = spaceSimulationResults_Zone.Sum(SpaceSimulationResultParameter.InfiltrationGain); // //if (!double.IsNaN(infiltrationGain)) // // zoneSimulationResult_Heating.SetValue(ZoneSimulationResultParameter.InfiltrationGain, infiltrationGain); // //double opaqueExternalConduction = spaceSimulationResults_Zone.Sum(SpaceSimulationResultParameter.OpaqueExternalConduction); // //if (!double.IsNaN(opaqueExternalConduction)) // // zoneSimulationResult_Heating.SetValue(ZoneSimulationResultParameter.OpaqueExternalConduction, opaqueExternalConduction); //} //} //if (!double.IsNaN(occupancy)) // zoneSimulationResult_Heating?.SetValue(ZoneSimulationResultParameter.Occupancy, occupancy); //if (!double.IsNaN(area)) // zoneSimulationResult_Heating?.SetValue(ZoneSimulationResultParameter.Area, area); //if (!double.IsNaN(volume)) // zoneSimulationResult_Heating?.SetValue(ZoneSimulationResultParameter.Volume, volume); //if (zoneSimulationResult_Heating != null) //{ // adjacencyCluster.AddObject(zoneSimulationResult_Heating); // adjacencyCluster.AddRelation(zone, zoneSimulationResult_Heating); // result.Add(zoneSimulationResult_Heating); //} } } return(result); }
public static bool AssignOpeningTypes(this TBD.Building building, TBD.buildingElement buildingElement, IEnumerable <TBD.dayType> dayTypes, OpeningType openingType) { if (building == null || buildingElement == null || openingType == null || dayTypes == null) { return(false); } TBD.ApertureType apertureType_Day = null; string function; function = null; if (openingType.TryGetValue("SAM_ApertureFunctionDay", out function, true) && !string.IsNullOrWhiteSpace(function)) { apertureType_Day = building.AddApertureType(null); apertureType_Day.name = buildingElement.name + "_Day"; foreach (TBD.dayType aDayType in dayTypes) { apertureType_Day.SetDayType(aDayType, true); } int sheltered; if (openingType.TryGetValue("SAM_ApertureShelteredDay", out sheltered, true)) { apertureType_Day.sheltered = sheltered; } else { apertureType_Day.sheltered = 0; } string description_ApertureType; if (openingType.TryGetValue("SAM_ApertureDescriptionDay", out description_ApertureType, true)) { apertureType_Day.description = description_ApertureType; } TBD.profile profile = apertureType_Day.GetProfile(); profile.type = TBD.ProfileTypes.ticFunctionProfile; profile.function = function; double factor; if (openingType.TryGetValue("SAM_ApertureOpeningProportionDay", out factor, true)) { profile.factor = (float)factor; } double setbackValue; if (openingType.TryGetValue("SAM_ApertureOpeningProportionDaySetBack", out setbackValue, true)) { profile.setbackValue = (float)setbackValue; } string description_Profile; if (openingType.TryGetValue("SAM_ApertureProfileDescriptionDay", out description_Profile, true)) { profile.description = description_Profile; } string scheduleValues; if (openingType.TryGetValue("SAM_ApertureScheduleDay", out scheduleValues, true)) { string name_Schedule = string.Format("{0}_{1}", apertureType_Day.name, "APSCHED"); List <int> values = scheduleValues.Ints(); TBD.schedule schedule = Create.Schedule(building, name_Schedule, values); if (schedule != null) { profile.schedule = schedule; } } } TBD.ApertureType apertureType_Night = null; function = null; if (openingType.TryGetValue("SAM_ApertureFunctionNight", out function, true) && !string.IsNullOrWhiteSpace(function)) { apertureType_Day = building.AddApertureType(null); apertureType_Day.name = buildingElement.name + "_Night"; foreach (TBD.dayType aDayType in dayTypes) { apertureType_Day.SetDayType(aDayType, true); } int sheltered; if (openingType.TryGetValue("SAM_ApertureShelteredNight", out sheltered, true)) { apertureType_Day.sheltered = sheltered; } else { apertureType_Day.sheltered = 0; } string description_ApertureType; if (openingType.TryGetValue("SAM_ApertureDescriptionNight", out description_ApertureType, true)) { apertureType_Day.description = description_ApertureType; } TBD.profile profile = apertureType_Day.GetProfile(); profile.type = TBD.ProfileTypes.ticFunctionProfile; profile.function = function; double factor; if (openingType.TryGetValue("SAM_ApertureOpeningProportionNight", out factor, true)) { profile.factor = (float)factor; } double setbackValue; if (openingType.TryGetValue("SAM_ApertureOpeningProportionNightSetBack", out setbackValue, true)) { profile.setbackValue = (float)setbackValue; } string description_Profile; if (openingType.TryGetValue("SAM_ApertureProfileDescriptionNight", out description_Profile, true)) { profile.description = description_Profile; } string scheduleValues; if (openingType.TryGetValue("SAM_ApertureScheduleNight", out scheduleValues, true)) { string name_Schedule = string.Format("{0}_{1}", apertureType_Day.name, "APSCHED"); List <int> values = scheduleValues.Ints(); TBD.schedule schedule = Create.Schedule(building, name_Schedule, values); if (schedule != null) { profile.schedule = schedule; } } } if (apertureType_Day != null) { buildingElement.AssignApertureType(apertureType_Day); } if (apertureType_Night != null) { buildingElement.AssignApertureType(apertureType_Night); } return(true); }
public static AdjacencyCluster UpdateDesignLoads(this TBDDocument tBDDocument, AdjacencyCluster adjacencyCluster) { if (tBDDocument == null || adjacencyCluster == null) { return(null); } Building building = tBDDocument.Building; if (building == null) { return(null); } AdjacencyCluster result = new AdjacencyCluster(adjacencyCluster); List <Space> spaces = result.GetSpaces(); if (spaces == null || spaces.Count == 0) { return(result); } Dictionary <string, zone> zones = building.ZoneDictionary(); if (zones == null) { return(null); } foreach (Space space in spaces) { string name = space?.Name; if (string.IsNullOrEmpty(name)) { continue; } zone zone; if (!zones.TryGetValue(name, out zone) || zone == null) { continue; } space.SetValue(SpaceParameter.DesignHeatingLoad, zone.maxHeatingLoad); space.SetValue(SpaceParameter.DesignCoolingLoad, zone.maxCoolingLoad); result.AddObject(space); List <SpaceSimulationResult> spaceSimulationResults = result.GetResults <SpaceSimulationResult>(space, Query.Source()); foreach (LoadType loadType in new LoadType[] { LoadType.Heating, LoadType.Cooling }) { SpaceSimulationResult spaceSimulationResult = spaceSimulationResults?.Find(x => x.LoadType() == loadType); if (spaceSimulationResult == null) { spaceSimulationResult = Create.SpaceSimulationResult(zone, loadType); } else { spaceSimulationResult = new SpaceSimulationResult(spaceSimulationResult); spaceSimulationResult.SetValue(Analytical.SpaceSimulationResultParameter.Area, zone.floorArea); spaceSimulationResult.SetValue(Analytical.SpaceSimulationResultParameter.Volume, zone.volume); spaceSimulationResult.SetValue(Analytical.SpaceSimulationResultParameter.DesignLoad, loadType == LoadType.Cooling ? zone.maxCoolingLoad : zone.maxHeatingLoad); } if (spaceSimulationResult != null) { result.AddObject(spaceSimulationResult); result.AddRelation(space, spaceSimulationResult); } } } return(result); }