/// <summary> /// This is the method that actually does the work. /// </summary> /// <param name="dataAccess">The DA object is used to retrieve from inputs and store in outputs.</param> protected override void SolveInstance(IGH_DataAccess dataAccess) { dataAccess.SetData(4, false); bool run = false; if (!dataAccess.GetData(2, ref run)) { AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Invalid data"); return; } if (!run) { return; } string path_TBD = null; if (!dataAccess.GetData(0, ref path_TBD) || string.IsNullOrWhiteSpace(path_TBD)) { AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Invalid data"); return; } IAnalyticalObject analyticalObject = null; if (!dataAccess.GetData(1, ref analyticalObject) || analyticalObject == null) { AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Invalid data"); return; } List <SpaceSimulationResult> spaceSimulationResults_Cooling = null; List <SpaceSimulationResult> spaceSimulationResults_Heating = null; List <Space> spaces = null; bool result = false; if (analyticalObject is AnalyticalModel) { analyticalObject = Analytical.Tas.Modify.UpdateDesignLoads(path_TBD, (AnalyticalModel)analyticalObject); AdjacencyCluster adjacencyCluster = ((AnalyticalModel)analyticalObject).AdjacencyCluster; if (adjacencyCluster != null) { spaces = adjacencyCluster.GetSpaces(); if (spaces != null) { spaceSimulationResults_Cooling = new List <SpaceSimulationResult>(); spaceSimulationResults_Heating = new List <SpaceSimulationResult>(); foreach (Space space in spaces) { List <SpaceSimulationResult> spaceSimulationResults = adjacencyCluster.GetResults <SpaceSimulationResult>(space, Analytical.Tas.Query.Source()); if (spaceSimulationResults == null) { continue; } spaceSimulationResults_Cooling.AddRange(spaceSimulationResults.FindAll(x => x.LoadType() == LoadType.Cooling)); spaceSimulationResults_Cooling.AddRange(spaceSimulationResults.FindAll(x => x.LoadType() == LoadType.Heating)); } result = true; } } } else if (analyticalObject is BuildingModel) { BuildingModel buildingModel = new BuildingModel((BuildingModel)analyticalObject); spaces = Analytical.Tas.Modify.UpdateDesignLoads(buildingModel, path_TBD); if (spaces != null) { spaceSimulationResults_Cooling = new List <SpaceSimulationResult>(); spaceSimulationResults_Heating = new List <SpaceSimulationResult>(); foreach (Space space in spaces) { List <SpaceSimulationResult> spaceSimulationResults = buildingModel.GetResults <SpaceSimulationResult>(space, Analytical.Tas.Query.Source()); if (spaceSimulationResults == null) { continue; } spaceSimulationResults_Cooling.AddRange(spaceSimulationResults.FindAll(x => x.LoadType() == LoadType.Cooling)); spaceSimulationResults_Cooling.AddRange(spaceSimulationResults.FindAll(x => x.LoadType() == LoadType.Heating)); } result = true; } analyticalObject = buildingModel; } dataAccess.SetData(0, new GooAnalyticalObject(analyticalObject)); dataAccess.SetDataList(1, spaces?.ConvertAll(x => new GooSpace(x))); dataAccess.SetDataList(2, spaceSimulationResults_Cooling?.ConvertAll(x => new GooResult(x))); dataAccess.SetDataList(3, spaceSimulationResults_Heating?.ConvertAll(x => new GooResult(x))); dataAccess.SetData(4, result); }
public static List <Core.Result> AddResults(this SimulationData simulationData, AdjacencyCluster adjacencyCluster) { if (simulationData == null || adjacencyCluster == 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 <Guid, List <SpaceSimulationResult> > dictionary = new Dictionary <Guid, List <SpaceSimulationResult> >(); List <Space> spaces = adjacencyCluster.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) { List <SpaceSimulationResult> spaceSimulationResults_Existing = adjacencyCluster.GetResults <SpaceSimulationResult>(space, Query.Source())?.FindAll(x => x.LoadType() == spaceSimulationResult.LoadType()); if (spaceSimulationResults_Existing != null && spaceSimulationResults_Existing.Count != 0) { adjacencyCluster.Remove(spaceSimulationResults_Existing); if (spaceSimulationResults_Existing[0].TryGetValue(Analytical.SpaceSimulationResultParameter.DesignLoad, out double designLoad)) { spaceSimulationResult.SetValue(Analytical.SpaceSimulationResultParameter.DesignLoad, designLoad); } } adjacencyCluster.AddObject(spaceSimulationResult); adjacencyCluster.AddRelation(space, spaceSimulationResult); } } foreach (Core.Result result_Temp in results) { PanelSimulationResult panelSimulationResult = result_Temp as PanelSimulationResult; if (panelSimulationResult == null) { continue; } if (!panelSimulationResult.TryGetValue(PanelSimulationResultParameter.ZoneName, out string zoneName) || !space.Name.Equals(zoneName)) { continue; } adjacencyCluster.AddObject(panelSimulationResult); adjacencyCluster.AddRelation(space, panelSimulationResult); } } } // get data data about SAM Zones like space GUID, Zone Category etc. List <Zone> zones = adjacencyCluster.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 = adjacencyCluster.GetSpaces(zone); if (spaces_Zone == null || spaces_Zone.Count == 0) { continue; } double area = adjacencyCluster.Sum(zone, SpaceParameter.Area); double volume = adjacencyCluster.Sum(zone, SpaceParameter.Volume); double occupancy = adjacencyCluster.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) { adjacencyCluster.AddObject(zoneSimulationResult_Cooling); adjacencyCluster.AddRelation(zone, zoneSimulationResult_Cooling); 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 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); }