示例#1
0
        public static AdjacencyCluster ToSAM(this BuildingData buildingData, IEnumerable <SpaceDataType> spaceDataTypes = null, IEnumerable <PanelDataType> panelDataTypes = null)
        {
            if (buildingData == null)
            {
                return(null);
            }

            List <ZoneData> zoneDatas = buildingData.ZoneDatas();

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

            AdjacencyCluster result = new AdjacencyCluster();

            foreach (ZoneData zoneData in zoneDatas)
            {
                if (zoneData == null)
                {
                    continue;
                }

                Space space = zoneData.ToSAM(spaceDataTypes);
                if (space != null)
                {
                    result.AddObject(space);
                }

                List <SurfaceData> surfaceDatas = zoneData.SurfaceDatas();
                if (surfaceDatas == null)
                {
                    continue;
                }

                foreach (SurfaceData surfaceData in surfaceDatas)
                {
                    if (surfaceData == null)
                    {
                        continue;
                    }

                    Panel panel = surfaceData.ToSAM(panelDataTypes);
                    if (panel == null)
                    {
                        continue;
                    }

                    result.AddObject(panel);

                    if (space != null)
                    {
                        result.AddRelation(space, panel);
                    }
                }
            }

            return(result);
        }
示例#2
0
        public static AnalyticalModel UpdateFacingExternal(this AnalyticalModel analyticalModel, TBD.TBDDocument tBDDocument)
        {
            if (analyticalModel == null || tBDDocument == null)
            {
                return(null);
            }

            Dictionary <string, TBD.zone> zones = tBDDocument.Building?.ZoneDictionary();

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

            AdjacencyCluster adjacencyCluster = analyticalModel.AdjacencyCluster;

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

            Dictionary <string, Space> spaces = adjacencyCluster.SpaceDictionary();

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

            if (zones.Count == 0 || spaces.Count == 0)
            {
                return(new AnalyticalModel(analyticalModel));
            }

            foreach (KeyValuePair <string, Space> keyValuePair in spaces)
            {
                TBD.zone zone = null;
                if (!zones.TryGetValue(keyValuePair.Key, out zone))
                {
                    continue;
                }

                if (zone == null)
                {
                    continue;
                }

                Space space_New = UpdateFacingExternal(keyValuePair.Value, zone);
                if (space_New == null)
                {
                    continue;
                }

                adjacencyCluster.AddObject(space_New);
            }

            return(new AnalyticalModel(analyticalModel, adjacencyCluster));
        }
示例#3
0
        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);
        }
示例#4
0
        public static AdjacencyCluster AdjacencyCluster(IEnumerable <Space> spaces, IEnumerable <Panel> panels, out List <Topology> topologies, out List <Panel> redundantPanels, double minArea = Tolerance.MacroDistance, bool updatePanels = true, bool tryCellComplexByCells = true, Log log = null, double silverSpacing = Tolerance.MacroDistance, double tolerance = Tolerance.Distance)
        {
            Core.Modify.Add(log, "Method Name: {0}, Tolerance: {1}, Update Panels: {2}", "SAM.Analytical.Topologic.Create.AdjacencyCluster", tolerance, updatePanels);

            topologies      = null;
            redundantPanels = null;

            AdjacencyCluster result = new AdjacencyCluster();

            result.AddObjects(spaces);
            result.AddObjects(panels);

            List <Face> faces = new List <Face>();

            int index = 1;

            foreach (Panel panel in result.GetObjects <Panel>())
            {
                if (panel == null)
                {
                    continue;
                }

                Face face = Convert.ToTopologic(panel);
                if (face == null)
                {
                    continue;
                }

                faces.Add(face);
                Core.Modify.Add(log, "Face {0:D4} added. Panel [{1}]", index, panel.Guid);
                index++;
            }

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

            topologies = new List <Topology>();
            List <Cell> cells = null;

            if (tryCellComplexByCells)
            {
                try
                {
                    Core.Modify.Add(log, "Trying to make CellComplex By Cells");
                    Cluster cluster = Cluster.ByTopologies(faces as IList <Topology>);
                    Core.Modify.Add(log, "Cluster.ByTopologies Done");
                    Topology topology = cluster.SelfMerge();
                    Core.Modify.Add(log, "Cluster SelfMerge Done");
                    if (topology.Cells != null && topology.Cells.Count != 0)
                    {
                        cells = topology.Cells?.ToList();
                        CellComplex cellComplex = null;
                        try
                        {
                            cellComplex = CellComplex.ByCells(cells);
                        }
                        catch (Exception exception)
                        {
                            Core.Modify.Add(log, "Cells could not be taken from CellComplex");
                            Core.Modify.Add(log, "Exception Message: {0}", exception.Message);
                        }

                        if (cellComplex != null && cellComplex.Cells != null && cellComplex.Cells.Count != 0)
                        {
                            topologies.Add(cellComplex);

                            cells = cellComplex.Cells?.ToList();
                        }
                        else
                        {
                            topologies.Add(topology);
                            Core.Modify.Add(log, "Cells taken from Cluster");
                        }
                    }
                }
                catch (Exception exception)
                {
                    Core.Modify.Add(log, "Cannot create CellComplex By Cells or Cells form Cluster SelfMerge");
                    Core.Modify.Add(log, "Exception Message: {0}", exception.Message);
                    cells = null;
                }
            }

            if (cells == null)
            {
                try
                {
                    Core.Modify.Add(log, "Trying to make CellComplex By Faces");
                    CellComplex cellComplex = CellComplex.ByFaces(faces, tolerance);
                    topologies.Add(cellComplex);
                    cells = cellComplex.Cells?.ToList();
                    Core.Modify.Add(log, "CellComplex By Faces Created");
                }
                catch (Exception exception)
                {
                    Core.Modify.Add(log, "Cannot create CellComplex By Faces");
                    Core.Modify.Add(log, "Exception Message: {0}", exception.Message);

                    cells = null;
                }
            }

            if (cells == null || cells.Count == 0)
            {
                Core.Modify.Add(log, "No cells found");
                return(null);
            }

            List <Geometry.Spatial.Shell> shells = cells.ToSAM();

            Core.Modify.Add(log, "Single CellComplex converted to shells");

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

            //Matching spaces with shells
            Dictionary <Geometry.Spatial.Shell, List <Space> > dictionary_Spaces = new Dictionary <Geometry.Spatial.Shell, List <Space> >();

            if (spaces != null)
            {
                foreach (Space space in spaces)
                {
                    if (space == null || space.Location == null || !space.IsPlaced())
                    {
                        continue;
                    }

                    List <Geometry.Spatial.Shell> shells_Temp = Analytical.Query.SpaceShells(shells, space.Location, silverSpacing, tolerance);
                    if (shells_Temp == null || shells_Temp.Count == 0)
                    {
                        continue;
                    }

                    foreach (Geometry.Spatial.Shell shell in shells_Temp)
                    {
                        if (!dictionary_Spaces.TryGetValue(shell, out List <Space> spaces_Shell))
                        {
                            spaces_Shell             = new List <Space>();
                            dictionary_Spaces[shell] = spaces_Shell;
                        }
                        spaces_Shell.Add(space);
                    }
                }
            }

            HashSet <Guid> guids_Updated = new HashSet <Guid>();

            Dictionary <Panel, Face3D> dictionary_Panel_Face3D = new Dictionary <Panel, Face3D>();

            result.GetObjects <Panel>().ForEach(x => dictionary_Panel_Face3D[x] = x.GetFace3D());

            index = 1;
            List <Tuple <Panel, Point3D> > tuples_InternalPoint3D = new List <Tuple <Panel, Point3D> >();

            for (int i = 0; i < shells.Count; i++)
            {
                Geometry.Spatial.Shell shell = shells[i];
                if (shell == null)
                {
                    return(null);
                }

                Core.Modify.Add(log, "Simplifying shell");
                //shell.Simplify(tolerance); // Low tolerance cause of rounding issues
                shell.Simplify();

                Core.Modify.Add(log, "Extracting faces from shell");
                List <Face3D> face3Ds = shell?.Face3Ds;
                if (face3Ds == null)
                {
                    Core.Modify.Add(log, "No face2Ds found in Shell");
                    continue;
                }

                dictionary_Spaces.TryGetValue(shell, out List <Space> spaces_Shell);

                if (spaces_Shell == null || spaces_Shell.Count == 0)
                {
                    Core.Modify.Add(log, "Creating new Space");

                    Point3D location = shell.CalculatedInternalPoint3D(silverSpacing, tolerance);
                    if (location == null)
                    {
                        continue;
                    }

                    Space space = new Space("Cell " + index, location);
                    index++;

                    if (!result.AddObject(space))
                    {
                        continue;
                    }

                    spaces_Shell = new List <Space>()
                    {
                        space
                    };
                    dictionary_Spaces[shell] = spaces_Shell;
                }

                if (spaces_Shell == null || spaces_Shell.Count == 0)
                {
                    continue;
                }

                double volume = double.NaN;
                if (cells[i] != null)
                {
                    Core.Modify.Add(log, "Calculating Volume");
                    volume = CellUtility.Volume(cells[i]);

                    foreach (Space space_Shell in spaces_Shell)
                    {
                        space_Shell.SetValue(SpaceParameter.Volume, volume);
                    }
                }

                Core.Modify.Add(log, "Upadting Panels");
                foreach (Face3D face3D in face3Ds)
                {
                    if (minArea != 0 && face3D.GetArea() <= minArea)
                    {
                        Core.Modify.Add(log, "Face3D is too small");
                        continue;
                    }

                    Core.Modify.Add(log, "Looking for existing Panel");
                    Tuple <Panel, Point3D> tuple_InternalPoint3D = tuples_InternalPoint3D.Find(x => face3D.Inside(x.Item2, tolerance));
                    if (tuple_InternalPoint3D != null)
                    {
                        Core.Modify.Add(log, "Existing Panel found: {0}", tuple_InternalPoint3D.Item1.Guid);
                        foreach (Space space in spaces_Shell)
                        {
                            if (result.AddRelation(space, tuple_InternalPoint3D.Item1))
                            {
                                Core.Modify.Add(log, "Space [{0}] and Panel [{1}] relation added", space.Guid, tuple_InternalPoint3D.Item1.Guid);
                            }
                        }
                        continue;
                    }

                    Core.Modify.Add(log, "Looking for old Panel");
                    //Panel panel_Old = Query.SimilarPanel(face3D, dictionary_Panel_Face3D);
                    //if (panel_Old == null)
                    //    continue;

                    List <Panel> panels_Old = Query.SimilarPanels(face3D, dictionary_Panel_Face3D);
                    if (panels_Old == null || panels_Old.Count == 0)
                    {
                        continue;
                    }

                    Panel panel_Old = panels_Old.First();
                    if (panels_Old.Count > 1)
                    {
                        if (redundantPanels == null)
                        {
                            redundantPanels = new List <Panel>();
                        }

                        panels_Old.RemoveAt(0);
                        redundantPanels.AddRange(panels_Old);
                    }

                    Core.Modify.Add(log, "Old Panel found: {0}", panel_Old.Guid);

                    Panel panel_New = null;

                    if (updatePanels)
                    {
                        if (guids_Updated.Contains(panel_Old.Guid))
                        {
                            panel_New = Analytical.Create.Panel(Guid.NewGuid(), panel_Old, face3D);
                            Core.Modify.Add(log, "Creating new Panel for Old Panel [{0}]. New Panel [{1}]", panel_Old.Guid, panel_New.Guid);
                        }
                        else
                        {
                            panel_New = Analytical.Create.Panel(panel_Old.Guid, panel_Old, face3D);
                            guids_Updated.Add(panel_Old.Guid);
                            Core.Modify.Add(log, "Updating Panel [{0}] with new geometry", panel_New.Guid);
                        }

                        result.AddObject(panel_New);
                    }
                    else
                    {
                        panel_New = Analytical.Create.Panel(panel_Old.Guid, panel_Old, face3D);
                        Core.Modify.Add(log, "Creating temporary Panel for Panel [{0}]", panel_New.Guid);
                    }

                    if (panel_New == null)
                    {
                        continue;
                    }

                    tuples_InternalPoint3D.Add(new Tuple <Panel, Point3D>(panel_New, face3D.InternalPoint3D(tolerance)));

                    foreach (Space space in spaces_Shell)
                    {
                        if (result.AddRelation(space, panel_New))
                        {
                            Core.Modify.Add(log, "Space [{0}] and Panel [{1}] relation added", space.Guid, panel_New.Guid);
                        }
                    }

                    Core.Modify.Add(log, "Adding face finished");
                }
            }

            if (redundantPanels != null && redundantPanels.Count != 0)
            {
                Core.Modify.Add(log, "Solving Redundant Panels");
                foreach (Panel panel in redundantPanels)
                {
                    result.RemoveObject <Panel>(panel.Guid);
                }
            }

            List <Panel> panels_Shading = Analytical.Query.CutShading(result.GetPanels(), panels, tolerance);

            if (panels_Shading != null || panels_Shading.Count != 0)
            {
                foreach (Panel panel_Shading in panels_Shading)
                {
                    result.AddObject(panel_Shading);
                }
            }

            Core.Modify.Add(log, "AdjacencyCluster verification");
            Log log_AdjacencyCluster = Analytical.Create.Log(result);

            if (log != null)
            {
                log.AddRange(log_AdjacencyCluster);
            }

            Core.Modify.Add(log, "Process completed");
            return(result);
        }
示例#5
0
        protected override void TrySolveInstance(IGH_DataAccess dataAccess)
        {
            int index = -1;

            Document document = RhinoInside.Revit.Revit.ActiveDBDocument;

            if (document == null)
            {
                AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Invalid data");
                return;
            }

            Core.SAMObject sAMObject = null;
            index = Params.IndexOfInputParam("_analytical");
            if (index == -1 || !dataAccess.GetData(index, ref sAMObject))
            {
                AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Invalid data");
                return;
            }

            List <Panel> panels = null;

            if (sAMObject is Panel)
            {
                panels = new List <Panel>()
                {
                    (Panel)sAMObject
                };
            }
            else if (sAMObject is AdjacencyCluster)
            {
                panels = ((AdjacencyCluster)sAMObject).GetPanels();
            }
            else if (sAMObject is AnalyticalModel)
            {
                panels = ((AnalyticalModel)sAMObject).GetPanels();
            }

            if (panels == null || panels.Count == 0)
            {
                AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Invalid data");
                return;
            }

            StartTransaction(document);

            List <ElementType> elementTypes = new List <ElementType>();

            for (int i = 0; i < panels.Count; i++)
            {
                Panel panel = panels[i];
                if (panel == null)
                {
                    continue;
                }

                Geometry.Spatial.Vector3D normal = panel.Normal;
                PanelType panelType = panel.PanelType;

                if (panelType == PanelType.Air || panelType == PanelType.Undefined)
                {
                    panels[i] = Create.Panel(panel);
                    ElementType elementType = Analytical.Revit.Convert.ToRevit_HostObjAttributes(panel, document, new Core.Revit.ConvertSettings(false, true, false));
                    if (elementType != null && elementTypes.Find(x => x.Id == elementType.Id) == null)
                    {
                        elementTypes.Add(elementType);
                    }

                    continue;
                }

                PanelType panelType_Normal = Analytical.Revit.Query.PanelType(normal);
                if (panelType_Normal == PanelType.Undefined || panelType.PanelGroup() == panelType_Normal.PanelGroup())
                {
                    panels[i] = Create.Panel(panel);
                    ElementType elementType = Analytical.Revit.Convert.ToRevit_HostObjAttributes(panel, document, new Core.Revit.ConvertSettings(false, true, false));
                    if (elementType != null && elementTypes.Find(x => x.Id == elementType.Id) == null)
                    {
                        elementTypes.Add(elementType);
                    }

                    continue;
                }

                if (panelType.PanelGroup() == PanelGroup.Floor || panelType.PanelGroup() == PanelGroup.Roof)
                {
                    double value = normal.Unit.DotProduct(Geometry.Spatial.Vector3D.WorldY);
                    if (Math.Abs(value) <= Core.Revit.Tolerance.Tilt)
                    {
                        panels[i] = Create.Panel(panel);
                        ElementType elementType = Analytical.Revit.Convert.ToRevit_HostObjAttributes(panel, document, new Core.Revit.ConvertSettings(false, true, false));
                        if (elementType != null && elementTypes.Find(x => x.Id == elementType.Id) == null)
                        {
                            elementTypes.Add(elementType);
                        }

                        continue;
                    }
                }

                HostObjAttributes hostObjAttributes = Analytical.Revit.Modify.DuplicateByType(document, panelType_Normal, panel.Construction) as HostObjAttributes;
                if (hostObjAttributes == null)
                {
                    AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, string.Format("Skipped - Could not duplicate construction for {0} panel (Guid: {1}).", panel.Name, panel.Guid));
                    continue;
                }

                panels[i] = Create.Panel(panel, panelType_Normal);

                if (elementTypes.Find(x => x.Id == hostObjAttributes.Id) == null)
                {
                    elementTypes.Add(hostObjAttributes);
                }
            }


            int index_Analytical = Params.IndexOfOutputParam("analytical");

            if (index_Analytical != -1)
            {
                if (sAMObject is Panel)
                {
                    dataAccess.SetData(index_Analytical, panels?.FirstOrDefault());
                }
                else if (sAMObject is AnalyticalModel)
                {
                    AnalyticalModel analyticalModel = new AnalyticalModel((AnalyticalModel)sAMObject);
                    panels.ForEach(x => analyticalModel.AddPanel(x));
                    dataAccess.SetData(index_Analytical, analyticalModel);
                }
                else if (sAMObject is AdjacencyCluster)
                {
                    AdjacencyCluster adjacencyCluster = new AdjacencyCluster((AdjacencyCluster)sAMObject);
                    panels.ForEach(x => adjacencyCluster.AddObject(x));
                    dataAccess.SetData(index_Analytical, adjacencyCluster);
                }
            }

            int index_ElementType = Params.IndexOfOutputParam("elementType");

            if (index_ElementType != -1)
            {
                dataAccess.SetDataList(index_ElementType, elementTypes);
            }
        }
示例#6
0
        public static Dictionary <Panel, double> UpdateThermalParameters(this AdjacencyCluster adjacencyCluster, TBD.Building building)
        {
            List <TBD.Construction> constructions_TBD = building?.Constructions();

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

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

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

            Dictionary <Panel, double> result = new Dictionary <Panel, double>();

            foreach (Panel panel in panels)
            {
                Construction construction = panel?.Construction;
                if (construction == null)
                {
                    continue;
                }

                string name = construction.Name;

                TBD.Construction construction_TBD = constructions_TBD.Find(x => x.name == name);
                if (construction_TBD == null)
                {
                    name             = Analytical.Query.UniqueName(panel.PanelType, name);
                    construction_TBD = constructions_TBD.Find(x => x.name == name);
                }

                if (construction_TBD == null)
                {
                    continue;
                }

                double thermalTransmittance = Query.ThermalTransmittance(construction_TBD, panel.PanelType);
                if (!double.IsNaN(thermalTransmittance))
                {
                    panel.SetValue(PanelParameter.ThermalTransmittance, thermalTransmittance);
                }

                Query.GlazingValues(construction_TBD,
                                    out double lightTransmittance,
                                    out double lightReflectance,
                                    out double directSolarEnergyTransmittance,
                                    out double directSolarEnergyReflectance,
                                    out double directSolarEnergyAbsorptance,
                                    out double totalSolarEnergyTransmittance,
                                    out double pilkingtonShortWavelengthCoefficient,
                                    out double pilkingtonLongWavelengthCoefficient);

                if (!double.IsNaN(lightTransmittance))
                {
                    panel.SetValue(PanelParameter.LightTransmittance, lightTransmittance);
                }

                if (!double.IsNaN(lightReflectance))
                {
                    panel.SetValue(PanelParameter.LightReflectance, lightReflectance);
                }

                if (!double.IsNaN(directSolarEnergyTransmittance))
                {
                    panel.SetValue(PanelParameter.DirectSolarEnergyTransmittance, directSolarEnergyTransmittance);
                }

                if (!double.IsNaN(directSolarEnergyReflectance))
                {
                    panel.SetValue(PanelParameter.DirectSolarEnergyReflectance, directSolarEnergyReflectance);
                }

                if (!double.IsNaN(directSolarEnergyAbsorptance))
                {
                    panel.SetValue(PanelParameter.DirectSolarEnergyAbsorptance, directSolarEnergyAbsorptance);
                }

                if (!double.IsNaN(totalSolarEnergyTransmittance))
                {
                    panel.SetValue(PanelParameter.TotalSolarEnergyTransmittance, totalSolarEnergyTransmittance);
                }

                if (!double.IsNaN(pilkingtonShortWavelengthCoefficient))
                {
                    panel.SetValue(PanelParameter.PilkingtonShadingShortWavelengthCoefficient, pilkingtonShortWavelengthCoefficient);
                }

                if (!double.IsNaN(pilkingtonLongWavelengthCoefficient))
                {
                    panel.SetValue(PanelParameter.PilkingtonShadingLongWavelengthCoefficient, pilkingtonLongWavelengthCoefficient);
                }


                adjacencyCluster.AddObject(panel);
                result[panel] = thermalTransmittance;
            }

            return(result);
        }
示例#7
0
        public static AdjacencyCluster ToSAM(this TBD.Building building)
        {
            if (building == null)
            {
                return(null);
            }

            AdjacencyCluster adjacencyCluster = new AdjacencyCluster();

            Dictionary <string, Construction> dictionary_Construction = new Dictionary <string, Construction>();

            foreach (TBD.Construction construction_TBD in building.Constructions())
            {
                Construction construction = construction_TBD.ToSAM();
                if (construction == null)
                {
                    continue;
                }

                dictionary_Construction[construction_TBD.GUID] = construction;
                adjacencyCluster.AddObject(construction);
            }

            foreach (TBD.zone zone in building.Zones())
            {
                Space space = zone.ToSAM(out List <InternalCondition> internalConditions);
                if (space == null)
                {
                    continue;
                }

                adjacencyCluster.AddObject(space);

                foreach (TBD.IZoneSurface zoneSurface in zone.ZoneSurfaces())
                {
                    TBD.buildingElement buildingElement  = zoneSurface.buildingElement;
                    TBD.Construction    construction_TBD = buildingElement.GetConstruction();

                    PanelType panelType = Query.PanelType(buildingElement.BEType);

                    Construction construction = null;
                    if (construction_TBD != null)
                    {
                        construction = dictionary_Construction[construction_TBD.GUID];
                    }

                    foreach (TBD.IRoomSurface roomSurface in zoneSurface.RoomSurfaces())
                    {
                        Geometry.Spatial.Polygon3D polygon3D = Geometry.Tas.Convert.ToSAM(roomSurface?.GetPerimeter()?.GetFace());
                        if (polygon3D == null)
                        {
                            continue;
                        }

                        Panel panel = Analytical.Create.Panel(construction, panelType, new Geometry.Spatial.Face3D(polygon3D));
                        if (panel == null)
                        {
                            continue;
                        }

                        adjacencyCluster.AddObject(panel);
                        adjacencyCluster.AddRelation(panel, space);
                    }
                }

                if (internalConditions != null)
                {
                    foreach (InternalCondition internalCondition in internalConditions)
                    {
                        adjacencyCluster.AddObject(internalCondition);
                        adjacencyCluster.AddRelation(space, internalCondition);
                    }
                }
            }

            return(adjacencyCluster);
        }
        public static AnalyticalModel ToSAM(this Model model)
        {
            if (model == null)
            {
                return(null);
            }

            MaterialLibrary             materialLibrary       = null;
            ProfileLibrary              profileLibrary        = null;
            List <Construction>         constructions         = null;
            List <ApertureConstruction> apertureConstructions = null;
            List <InternalCondition>    internalConditions    = null;

            ModelEnergyProperties modelEnergyProperties = model.Properties?.Energy;

            if (modelEnergyProperties != null)
            {
                materialLibrary       = modelEnergyProperties.ToSAM_MaterialLibrary();
                constructions         = modelEnergyProperties.ToSAM_Constructions();
                apertureConstructions = modelEnergyProperties.ToSAM_ApertureConstructions();
                internalConditions    = modelEnergyProperties.ToSAM_InternalConditions();
                profileLibrary        = modelEnergyProperties.ToSAM_ProfileLibrary();
            }

            if (materialLibrary == null)
            {
                materialLibrary = new MaterialLibrary(string.Empty);
            }

            if (constructions == null)
            {
                constructions = new List <Construction>();
            }

            if (apertureConstructions == null)
            {
                apertureConstructions = new List <ApertureConstruction>();
            }

            List <Tuple <Panel, Geometry.Spatial.BoundingBox3D> > tuples = new List <Tuple <Panel, Geometry.Spatial.BoundingBox3D> >();

            AdjacencyCluster adjacencyCluster = new AdjacencyCluster();
            List <Room>      rooms            = model.Rooms;

            if (rooms != null)
            {
                foreach (Room room in rooms)
                {
                    room.IndoorShades?.ConvertAll(x => x.ToSAM(constructions))?.ForEach(x => adjacencyCluster.AddObject(x));
                    room.OutdoorShades?.ConvertAll(x => x.ToSAM(constructions))?.ForEach(x => adjacencyCluster.AddObject(x));

                    List <Face> faces = room.Faces;
                    if (faces == null)
                    {
                        continue;
                    }

                    List <Panel> panels = new List <Panel>();
                    foreach (Face face in faces)
                    {
                        Panel panel = face.ToSAM(constructions, apertureConstructions);
                        if (panel == null)
                        {
                            continue;
                        }

                        Geometry.Spatial.Point3D point3D = panel.GetFace3D().GetInternalPoint3D();
                        if (point3D == null)
                        {
                            continue;
                        }

                        Panel panel_Existing = tuples.FindAll(x => x.Item2.Inside(point3D, true))?.Find(x => x.Item1.GetFace3D().On(point3D))?.Item1;
                        if (panel_Existing != null)
                        {
                            panel = panel_Existing;
                        }
                        else
                        {
                            tuples.Add(new Tuple <Panel, Geometry.Spatial.BoundingBox3D>(panel, panel.GetFace3D().GetBoundingBox()));

                            face.IndoorShades?.ConvertAll(x => x.ToSAM(constructions))?.ForEach(x => adjacencyCluster.AddObject(x));
                            face.OutdoorShades?.ConvertAll(x => x.ToSAM(constructions))?.ForEach(x => adjacencyCluster.AddObject(x));

                            Construction construction = panel.Construction;
                            if (construction != null)
                            {
                                if (constructions.Find(x => x.Name.Equals(construction.Name)) == null)
                                {
                                    constructions.Add(construction);
                                }

                                materialLibrary.AddDefaultMaterials(construction);
                            }

                            List <Aperture> apertures = panel.Apertures;
                            if (apertures != null)
                            {
                                foreach (Aperture aperture in apertures)
                                {
                                    ApertureConstruction apertureConstruction = aperture.ApertureConstruction;
                                    if (apertureConstruction != null)
                                    {
                                        if (apertureConstructions.Find(x => x.Name.Equals(apertureConstruction.Name)) == null)
                                        {
                                            apertureConstructions.Add(apertureConstruction);
                                        }

                                        materialLibrary.AddDefaultMaterials(apertureConstruction);
                                    }
                                }
                            }

                            List <HoneybeeSchema.Aperture> apertures_HoneybeeSchema = face.Apertures;
                            if (apertures_HoneybeeSchema != null)
                            {
                                foreach (HoneybeeSchema.Aperture aperture_HoneybeeSchema in apertures_HoneybeeSchema)
                                {
                                    aperture_HoneybeeSchema.IndoorShades?.ConvertAll(x => x.ToSAM(constructions))?.ForEach(x => adjacencyCluster.AddObject(x));
                                    aperture_HoneybeeSchema.OutdoorShades?.ConvertAll(x => x.ToSAM(constructions))?.ForEach(x => adjacencyCluster.AddObject(x));
                                }
                            }

                            List <HoneybeeSchema.Door> doors_HoneybeeSchema = face.Doors;
                            if (doors_HoneybeeSchema != null)
                            {
                                foreach (HoneybeeSchema.Door door_HoneybeeSchema in doors_HoneybeeSchema)
                                {
                                    door_HoneybeeSchema.IndoorShades?.ConvertAll(x => x.ToSAM(constructions))?.ForEach(x => adjacencyCluster.AddObject(x));
                                    door_HoneybeeSchema.OutdoorShades?.ConvertAll(x => x.ToSAM(constructions))?.ForEach(x => adjacencyCluster.AddObject(x));
                                }
                            }
                        }

                        panels.Add(panel);
                    }

                    Space space = room.ToSAM(internalConditions);
                    adjacencyCluster.AddObject(space);

                    if (panels != null)
                    {
                        foreach (Panel panel in panels)
                        {
                            adjacencyCluster.AddObject(panel);
                            adjacencyCluster.AddRelation(space, panel);
                        }
                    }
                }
            }

            List <Shade> shades = model.OrphanedShades;

            if (shades != null && shades.Count != 0)
            {
                foreach (Shade shade in shades)
                {
                    Panel panel = shade?.ToSAM(constructions);
                    if (panel != null)
                    {
                        Construction construction = panel.Construction;
                        if (construction != null)
                        {
                            if (constructions.Find(x => x.Name.Equals(construction.Name)) == null)
                            {
                                constructions.Add(construction);
                            }

                            materialLibrary.AddDefaultMaterials(construction);
                        }

                        List <Aperture> apertures = panel.Apertures;
                        if (apertures != null)
                        {
                            foreach (Aperture aperture in apertures)
                            {
                                ApertureConstruction apertureConstruction = aperture.ApertureConstruction;
                                if (apertureConstruction != null)
                                {
                                    if (apertureConstructions.Find(x => x.Name.Equals(apertureConstruction.Name)) == null)
                                    {
                                        apertureConstructions.Add(apertureConstruction);
                                    }

                                    materialLibrary.AddDefaultMaterials(apertureConstruction);
                                }
                            }
                        }

                        adjacencyCluster.AddObject(panel);
                    }
                }
            }

            AnalyticalModel result = new AnalyticalModel(model.DisplayName, null, null, null, adjacencyCluster, materialLibrary, profileLibrary);

            return(result);
        }
示例#9
0
        public static AnalyticalModel ToSAM_AnalyticalModel(this Document document, ConvertSettings convertSettings)
        {
            if (document == null)
            {
                return(null);
            }

            ProjectInfo projectInfo = document.ProjectInformation;

            AnalyticalModel result = convertSettings?.GetObject <AnalyticalModel>(projectInfo?.Id);

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

            Core.Location location = Core.Revit.Query.Location(document);
            Address       address  = null;

            if (projectInfo != null)
            {
                address = new Address(Guid.NewGuid(), projectInfo.BuildingName, projectInfo.Address, null, null, CountryCode.Undefined);
            }

            AdjacencyCluster adjacencyCluster = new AdjacencyCluster();

            EnergyAnalysisDetailModelOptions energyAnalysisDetailModelOptions = new EnergyAnalysisDetailModelOptions();

            energyAnalysisDetailModelOptions.Tier                   = EnergyAnalysisDetailModelTier.SecondLevelBoundaries;
            energyAnalysisDetailModelOptions.EnergyModelType        = EnergyModelType.SpatialElement;
            energyAnalysisDetailModelOptions.ExportMullions         = true;
            energyAnalysisDetailModelOptions.IncludeShadingSurfaces = true;
            energyAnalysisDetailModelOptions.SimplifyCurtainSystems = false;

            EnergyDataSettings energyDataSettings = EnergyDataSettings.GetFromDocument(document);

            energyDataSettings.ExportComplexity = gbXMLExportComplexity.ComplexWithMullionsAndShadingSurfaces;
            energyDataSettings.ExportDefaults   = false;
#if Revit2017 || Revit2018 || Revit2019 || Revit2020
            energyDataSettings.SliverSpaceTolerance = UnitUtils.ConvertToInternalUnits(0.005, DisplayUnitType.DUT_METERS);
#else
            energyDataSettings.SliverSpaceTolerance = UnitUtils.ConvertToInternalUnits(0.005, UnitTypeId.Meters);
#endif
            energyDataSettings.AnalysisType = AnalysisMode.BuildingElements;
            energyDataSettings.EnergyModel  = false;

            //Reseting Project Base Point
            IEnumerable <Element> elements = new FilteredElementCollector(document).OfCategory(BuiltInCategory.OST_ProjectBasePoint);
            foreach (Element element in elements)
            {
                if (element.Pinned)
                {
                    element.Pinned = false;
                }

                Parameter parameter = null;

                parameter = element.get_Parameter(BuiltInParameter.BASEPOINT_EASTWEST_PARAM);
                if (parameter != null && !parameter.IsReadOnly)
                {
                    parameter.Set(0.0);
                }

                parameter = element.get_Parameter(BuiltInParameter.BASEPOINT_NORTHSOUTH_PARAM);
                if (parameter != null && !parameter.IsReadOnly)
                {
                    parameter.Set(0.0);
                }

                parameter = element.get_Parameter(BuiltInParameter.BASEPOINT_ELEVATION_PARAM);
                if (parameter != null && !parameter.IsReadOnly)
                {
                    parameter.Set(0.0);
                }

                parameter = element.get_Parameter(BuiltInParameter.BASEPOINT_ELEVATION_PARAM);
                if (parameter != null && !parameter.IsReadOnly)
                {
                    parameter.Set(0.0);
                }

                parameter = element.get_Parameter(BuiltInParameter.BASEPOINT_ANGLETON_PARAM);
                if (parameter != null && !parameter.IsReadOnly)
                {
                    parameter.Set(0.0);
                }
            }

            //AnalyticalSpaces
            EnergyAnalysisDetailModel   energyAnalysisDetailModel         = EnergyAnalysisDetailModel.Create(document, energyAnalysisDetailModelOptions);
            IList <EnergyAnalysisSpace> energyAnalysisSpaces              = energyAnalysisDetailModel.GetAnalyticalSpaces();
            Dictionary <string, Tuple <Panel, List <Space> > > dictionary = new Dictionary <string, Tuple <Panel, List <Space> > >();
            foreach (EnergyAnalysisSpace energyAnalysisSpace in energyAnalysisSpaces)
            {
                try
                {
                    if (energyAnalysisSpace.Area <= Core.Tolerance.MacroDistance)
                    {
                        continue;
                    }

                    Space space = energyAnalysisSpace.ToSAM(convertSettings);
                    if (space == null)
                    {
                        continue;
                    }

                    Shell shell = Geometry.Revit.Convert.ToSAM(energyAnalysisSpace.GetClosedShell());
                    if (shell == null)
                    {
                        continue;
                    }

                    adjacencyCluster.AddObject(space);

                    foreach (EnergyAnalysisSurface energyAnalysisSurface in energyAnalysisSpace.GetAnalyticalSurfaces())
                    {
                        Tuple <Panel, List <Space> > tuple;
                        if (!dictionary.TryGetValue(energyAnalysisSurface.SurfaceName, out tuple))
                        {
                            Panel panel = energyAnalysisSurface.ToSAM(convertSettings, shell);
                            if (panel == null)
                            {
                                continue;
                            }

                            tuple = new Tuple <Panel, List <Space> >(panel, new List <Space>());
                            dictionary[energyAnalysisSurface.SurfaceName] = tuple;
                        }

                        tuple.Item2.Add(space);
                    }
                }
                catch
                {
                }
            }

            #region Additional Checks (WIP)
            //Additional Check for wrongly recoginzed internal panels (WIP)
            List <Tuple <string, Panel, Space, Face3D> > tuples_External = new List <Tuple <string, Panel, Space, Face3D> >();
            foreach (KeyValuePair <string, Tuple <Panel, List <Space> > > keyValuePair in dictionary)
            {
                Tuple <Panel, List <Space> > tuple = keyValuePair.Value;
                if (tuple.Item1 != null && tuple.Item2 != null && tuple.Item2.Count == 1)
                {
                    Face3D face3D = tuple.Item1.GetFace3D();
                    if (face3D != null)
                    {
                        tuples_External.Add(new Tuple <string, Panel, Space, Face3D>(keyValuePair.Key, tuple.Item1, tuple.Item2[0], face3D));
                    }
                }
            }

            while (tuples_External.Count > 0)
            {
                Tuple <string, Panel, Space, Face3D> tuple = tuples_External[0];
                tuples_External.RemoveAt(0);

                Point3D point3D = tuple.Item4.InternalPoint3D();
                if (point3D == null)
                {
                    continue;
                }

                List <Tuple <string, Panel, Space, Face3D> > tuples_Overlap = tuples_External.FindAll(x => x.Item4.Inside(point3D));
                if (tuples_Overlap.Count != 1)
                {
                    continue;
                }

                tuples_Overlap.Add(tuple);

                tuples_Overlap.Sort((x, y) => y.Item4.GetArea().CompareTo(x.Item4.GetArea()));

                tuple = tuples_Overlap[0];
                Tuple <string, Panel, Space, Face3D> tuple_Overlap = tuples_Overlap[1];

                dictionary[tuple.Item1].Item2.Add(tuple_Overlap.Item3);
                dictionary[tuple_Overlap.Item1] = new Tuple <Panel, List <Space> >(Analytical.Create.Panel(dictionary[tuple_Overlap.Item1].Item1, PanelType.Shade), null);
                int index = tuples_External.IndexOf(tuple_Overlap);
                if (index != -1)
                {
                    tuples_External.RemoveAt(index);
                }
            }
            #endregion

            foreach (Tuple <Panel, List <Space> > tuple in dictionary.Values)
            {
                Panel panel = tuple.Item1;

                adjacencyCluster.AddObject(panel);
                tuple.Item2?.ForEach(x => adjacencyCluster.AddRelation(x, panel));
            }

            //AnalyticalShadingSurfaces
            IList <EnergyAnalysisSurface> analyticalShadingSurfaces = energyAnalysisDetailModel.GetAnalyticalShadingSurfaces();
            foreach (EnergyAnalysisSurface energyAnalysisSurface in analyticalShadingSurfaces)
            {
                try
                {
                    Panel panel = energyAnalysisSurface.ToSAM(convertSettings);
                    if (panel == null)
                    {
                        continue;
                    }

                    panel = Analytical.Create.Panel(panel, PanelType.Shade);

                    adjacencyCluster.AddObject(panel);
                }
                catch
                {
                }
            }

            adjacencyCluster.MapZones();

            IEnumerable <IMaterial> materials       = Analytical.Query.Materials(adjacencyCluster, Analytical.ActiveSetting.Setting.GetValue <MaterialLibrary>(AnalyticalSettingParameter.DefaultMaterialLibrary));
            MaterialLibrary         materialLibrary = Core.Create.MaterialLibrary("Default Material Library", materials);

            IEnumerable <Profile> profiles       = Analytical.Query.Profiles(adjacencyCluster, Analytical.ActiveSetting.Setting.GetValue <ProfileLibrary>(AnalyticalSettingParameter.DefaultProfileLibrary));
            ProfileLibrary        profileLibrary = new ProfileLibrary("Default Profile Library", profiles);

            result = new AnalyticalModel(document.Title, null, location, address, adjacencyCluster, materialLibrary, profileLibrary);
            result.UpdateParameterSets(document.ProjectInformation, ActiveSetting.Setting.GetValue <TypeMap>(Core.Revit.ActiveSetting.Name.ParameterMap));

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

            return(result);
        }
示例#10
0
        public static AnalyticalModel UpdateT3D(this AnalyticalModel analyticalModel, T3DDocument t3DDocument)
        {
            if (analyticalModel == null)
            {
                return(null);
            }


            Building building = t3DDocument?.Building;

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

            Modify.RemoveUnsusedZones(building);

            double northAngle = double.NaN;

            if (analyticalModel.TryGetValue(AnalyticalModelParameter.NorthAngle, out northAngle))
            {
                building.northAngle = global::System.Math.Round(Units.Convert.ToDegrees(northAngle), 1);
            }

            Location location = analyticalModel.Location;

            if (location != null)
            {
                building.longitude = location.Longitude;
                building.latitude  = location.Latitude;

                if (location.TryGetValue(LocationParameter.TimeZone, out string timeZone))
                {
                    double @double = Core.Query.Double(Core.Query.UTC(timeZone));
                    if (!double.IsNaN(@double))
                    {
                        building.timeZone = global::System.Convert.ToSingle(@double);
                    }
                }
            }

            AdjacencyCluster adjacencyCluster = analyticalModel?.AdjacencyCluster;

            if (adjacencyCluster != null)
            {
                //Zones -> Spaces
                Dictionary <string, Space> spaces = adjacencyCluster.SpaceDictionary();
                if (spaces != null)
                {
                    Dictionary <string, TAS3D.Zone> zones = building.ZoneDictionary();
                    if (zones != null)
                    {
                        foreach (KeyValuePair <string, TAS3D.Zone> keyValuePair in zones)
                        {
                            Space space;
                            if (!spaces.TryGetValue(keyValuePair.Key, out space))
                            {
                                continue;
                            }

                            if (space == null)
                            {
                                continue;
                            }

                            //TODO: Update Zone
                            Space space_New = space.Clone();
                            space_New.Add(Create.ParameterSet(ActiveSetting.Setting, keyValuePair.Value));
                            adjacencyCluster.AddObject(space_New);
                        }
                    }
                }

                //Elements -> Constructions
                List <Construction> constructions = adjacencyCluster.GetConstructions();
                if (constructions != null)
                {
                    List <Element> elements = building.Elements();
                    if (elements != null)
                    {
                        foreach (Element element in elements)
                        {
                            Construction construction = element.Match(constructions);
                            if (construction == null)
                            {
                                continue;
                            }

                            //Update Element

                            //Thickness
                            double thickness = construction.GetValue <double>(ConstructionParameter.DefaultThickness);
                            if (double.IsNaN(thickness) || thickness == 0)
                            {
                                thickness = construction.GetThickness();
                            }

                            if (!double.IsNaN(thickness))
                            {
                                element.width = thickness;
                            }

                            //if (Core.Query.TryGetValue(construction, Analytical.Query.ParameterName_Thickness(), out thickness, true))
                            //    element.width= thickness;

                            //Colour
                            System.Drawing.Color color = global::System.Drawing.Color.Empty;
                            if (construction.TryGetValue(ConstructionParameter.Color, out color))
                            {
                                element.colour = Core.Convert.ToUint(color);
                            }


                            //Transparent
                            bool         transparent  = false;
                            MaterialType materialType = Analytical.Query.MaterialType(construction.ConstructionLayers, analyticalModel.MaterialLibrary);
                            if (materialType == MaterialType.Undefined)
                            {
                                materialType = MaterialType.Opaque;
                                if (construction.TryGetValue(ConstructionParameter.Transparent, out transparent))
                                {
                                    element.transparent = transparent;
                                }
                            }
                            else
                            {
                                element.transparent = materialType == MaterialType.Transparent;
                            }

                            //InternalShadows
                            bool internalShadows = false;
                            if (construction.TryGetValue(ConstructionParameter.IsInternalShadow, out internalShadows))
                            {
                                element.internalShadows = internalShadows;
                            }
                            else
                            {
                                element.internalShadows = element.transparent;
                            }


                            //BEType
                            string string_BEType = null;

                            PanelType panelType = construction.PanelType();
                            if (panelType != Analytical.PanelType.Undefined)
                            {
                                string_BEType = panelType.Text();
                            }
                            else
                            {
                                if (!construction.TryGetValue(ConstructionParameter.DefaultPanelType, out string_BEType))
                                {
                                    string_BEType = null;
                                }
                            }

                            if (!string.IsNullOrEmpty(string_BEType))
                            {
                                int bEType = BEType(string_BEType);
                                if (bEType != -1)
                                {
                                    element.BEType = bEType;
                                    panelType      = PanelType(bEType);
                                }
                            }
                            else
                            {
                                panelType = Analytical.PanelType.Undefined;

                                List <Panel> panels_Construction = adjacencyCluster.GetPanels(construction);
                                if (panels_Construction != null && panels_Construction.Count > 0)
                                {
                                    Panel panel = panels_Construction.Find(x => x.PanelType != Analytical.PanelType.Undefined);
                                    if (panel != null)
                                    {
                                        panelType = panel.PanelType;
                                    }
                                }
                            }

                            if (panelType == Analytical.PanelType.Undefined)
                            {
                                List <Panel> panels_Construction = adjacencyCluster.GetPanels(construction);
                                if (panels_Construction != null && panels_Construction.Count != 0)
                                {
                                    element.zoneFloorArea = panels_Construction.Find(x => x.PanelType.PanelGroup() == PanelGroup.Floor) != null;
                                }
                            }

                            if (panelType.PanelGroup() == PanelGroup.Floor)
                            {
                                element.zoneFloorArea = true;
                            }

                            //Ground
                            bool ground = false;
                            if (construction.TryGetValue(ConstructionParameter.IsGround, out ground))
                            {
                                element.ground = ground;
                            }

                            //Air
                            bool air = false;
                            if (construction.TryGetValue(ConstructionParameter.IsAir, out air))
                            {
                                element.ghost = air;
                            }

                            List <Panel> panels = adjacencyCluster.GetPanels(construction);
                            if (panels != null && panels.Count > 0)
                            {
                                ParameterSet parameterSet = Create.ParameterSet(ActiveSetting.Setting, element);
                                construction.Add(parameterSet);

                                foreach (Panel panel in panels)
                                {
                                    Panel panel_New = Analytical.Create.Panel(panel, construction);
                                    adjacencyCluster.AddObject(panel_New);
                                }
                            }
                        }
                    }
                }

                //Windows -> ApertureConstruction
                List <ApertureConstruction> apertureConstructions = adjacencyCluster.GetApertureConstructions();
                if (apertureConstructions != null)
                {
                    List <window> windows = building.Windows();
                    if (windows != null)
                    {
                        foreach (window window in windows)
                        {
                            if (window == null)
                            {
                                continue;
                            }

                            ApertureConstruction apertureConstruction = window.Match(apertureConstructions);
                            if (apertureConstruction == null)
                            {
                                continue;
                            }

                            //Colour
                            System.Drawing.Color color = global::System.Drawing.Color.Empty;
                            if (!apertureConstruction.TryGetValue(ApertureConstructionParameter.Color, out color))
                            {
                                color = Analytical.Query.Color(apertureConstruction.ApertureType);
                            }

                            if (color != global::System.Drawing.Color.Empty)
                            {
                                window.colour = Core.Convert.ToUint(color);
                            }


                            //Transparent
                            List <ConstructionLayer> constructionLayers = null;
                            if (true)
                            {
                                constructionLayers = apertureConstruction.PaneConstructionLayers;
                            }
                            else
                            {
                                constructionLayers = apertureConstruction.FrameConstructionLayers;
                            }

                            window.transparent = false; //Requested by Michal 2021.03.01
                            bool         transparent  = false;
                            MaterialType materialType = Analytical.Query.MaterialType(constructionLayers, analyticalModel.MaterialLibrary);
                            if (materialType == MaterialType.Undefined)
                            {
                                materialType = MaterialType.Opaque;
                                if (apertureConstruction.TryGetValue(ApertureConstructionParameter.Transparent, out transparent))
                                {
                                    window.transparent = transparent;
                                }
                            }
                            else
                            {
                                window.transparent = materialType == MaterialType.Transparent;
                            }


                            if (window.transparent)
                            {
                                //InternalShadows
                                window.internalShadows = false; //Requested by Michal 2021.03.01
                                bool internalShadows = false;
                                if (apertureConstruction.TryGetValue(ApertureConstructionParameter.IsInternalShadow, out internalShadows))
                                {
                                    window.internalShadows = internalShadows;
                                }
                                else
                                {
                                    List <Panel> panels = adjacencyCluster.GetPanels(apertureConstruction);
                                    if (panels != null && panels.Count != 0)
                                    {
                                        window.internalShadows = panels.TrueForAll(x => adjacencyCluster.External(x));
                                    }
                                }
                            }

                            //FrameWidth
                            double frameWidth = double.NaN;
                            if (apertureConstruction.TryGetValue(ApertureConstructionParameter.DefaultFrameWidth, out frameWidth))
                            {
                                window.frameWidth = frameWidth;
                            }
                        }
                    }
                }
            }

            AnalyticalModel result = new AnalyticalModel(analyticalModel, adjacencyCluster);

            return(result);
        }
        public static AnalyticalModel ToSAM(this Campus campus, double silverSpacing = Tolerance.MacroDistance, double tolerance = Tolerance.MicroDistance)
        {
            Address address = campus.Location.ToSAM_Address();

            Core.Location location = campus.Location.ToSAM(tolerance);

            AdjacencyCluster adjacencyCluster = new AdjacencyCluster();

            Dictionary <string, Space> dictionary_Space = new Dictionary <string, Space>();

            Building[] buildings = campus.Buildings;
            if (buildings != null)
            {
                foreach (Building building in buildings)
                {
                    gbXMLSerializer.Space[] spaces = building.Spaces;
                    if (spaces != null)
                    {
                        foreach (gbXMLSerializer.Space space_gbXML in spaces)
                        {
                            if (space_gbXML == null)
                            {
                                continue;
                            }

                            Space space_SAM = space_gbXML.ToSAM(silverSpacing, tolerance);
                            if (space_SAM == null)
                            {
                                continue;
                            }

                            dictionary_Space[space_gbXML.id] = space_SAM;

                            adjacencyCluster.AddObject(space_SAM);
                        }
                    }
                }
            }

            Surface[] surfaces = campus.Surface;
            if (surfaces != null)
            {
                foreach (Surface surface in surfaces)
                {
                    if (surface == null)
                    {
                        continue;
                    }

                    Panel panel = surface.ToSAM(tolerance);
                    if (panel == null)
                    {
                        continue;
                    }

                    adjacencyCluster.AddObject(panel);

                    AdjacentSpaceId[] adjacentSpaceIds = surface.AdjacentSpaceId;
                    if (adjacentSpaceIds == null || adjacentSpaceIds.Length == 0)
                    {
                        continue;
                    }

                    foreach (AdjacentSpaceId adjacentSpaceId in adjacentSpaceIds)
                    {
                        string id = adjacentSpaceId?.spaceIdRef;
                        if (string.IsNullOrWhiteSpace(id))
                        {
                            continue;
                        }

                        Space space = null;

                        if (!dictionary_Space.TryGetValue(id, out space))
                        {
                            continue;
                        }

                        adjacencyCluster.AddRelation(panel, space);
                    }
                }
            }

            AnalyticalModel result = new AnalyticalModel(string.Empty, string.Empty, location, address, adjacencyCluster);

            return(result);
        }
示例#12
0
        public static AnalyticalModel RunWorkflow(this AnalyticalModel analyticalModel, string path_TBD, string path_gbXML = null, Weather.WeatherData weatherData = null, List <DesignDay> heatingDesignDays = null, List <DesignDay> coolingDesignDays = null, List <SurfaceOutputSpec> surfaceOutputSpecs = null, bool unmetHours = true)
        {
            if (analyticalModel == null || string.IsNullOrWhiteSpace(path_TBD))
            {
                return(null);
            }

            string directory = System.IO.Path.GetDirectoryName(path_TBD);
            string fileName  = System.IO.Path.GetFileNameWithoutExtension(path_TBD);

            string path_TSD = System.IO.Path.Combine(directory, string.Format("{0}.{1}", fileName, "tsd"));

            if (!string.IsNullOrWhiteSpace(path_gbXML))
            {
                string path_T3D = System.IO.Path.Combine(directory, string.Format("{0}.{1}", fileName, "t3d"));

                string guid = null;
                using (SAMT3DDocument sAMT3DDocument = new SAMT3DDocument(path_T3D))
                {
                    TAS3D.T3DDocument t3DDocument = sAMT3DDocument.T3DDocument;
                    guid = t3DDocument.Building.GUID;
                    sAMT3DDocument.Save();
                }

                float latitude  = float.NaN;
                float longitude = float.NaN;
                float timeZone  = float.NaN;
                using (SAMTBDDocument sAMTBDDocument = new SAMTBDDocument(path_TBD))
                {
                    TBD.TBDDocument tBDDocument = sAMTBDDocument.TBDDocument;

                    if (weatherData != null)
                    {
                        Weather.Tas.Modify.UpdateWeatherData(tBDDocument, weatherData);
                    }

                    if (!string.IsNullOrWhiteSpace(guid))
                    {
                        tBDDocument.Building.GUID = guid;
                    }

                    TBD.Calendar calendar = tBDDocument.Building.GetCalendar();

                    List <TBD.dayType> dayTypes = Query.DayTypes(calendar);
                    if (dayTypes.Find(x => x.name == "HDD") == null)
                    {
                        TBD.dayType dayType = calendar.AddDayType();
                        dayType.name = "HDD";
                    }

                    if (dayTypes.Find(x => x.name == "CDD") == null)
                    {
                        TBD.dayType dayType = calendar.AddDayType();
                        dayType.name = "CDD";
                    }

                    latitude  = tBDDocument.Building.latitude;
                    longitude = tBDDocument.Building.longitude;
                    timeZone  = tBDDocument.Building.timeZone;

                    sAMTBDDocument.Save();
                }

                using (SAMT3DDocument sAMT3DDocument = new SAMT3DDocument(path_T3D))
                {
                    TAS3D.T3DDocument t3DDocument = sAMT3DDocument.T3DDocument;

                    t3DDocument.TogbXML(path_gbXML, true, true, true);
                    t3DDocument.SetUseBEWidths(false);
                    analyticalModel = Query.UpdateT3D(analyticalModel, t3DDocument);

                    t3DDocument.Building.latitude  = float.IsNaN(latitude) ? t3DDocument.Building.latitude : latitude;
                    t3DDocument.Building.longitude = float.IsNaN(longitude) ? t3DDocument.Building.longitude : longitude;
                    t3DDocument.Building.timeZone  = float.IsNaN(timeZone) ? t3DDocument.Building.timeZone : timeZone;

                    sAMT3DDocument.Save();

                    Convert.ToTBD(t3DDocument, path_TBD, 1, 365, 15, true);
                }
            }

            AdjacencyCluster adjacencyCluster = null;

            bool hasWeatherData = false;

            using (SAMTBDDocument sAMTBDDocument = new SAMTBDDocument(path_TBD))
            {
                TBD.TBDDocument tBDDocument = sAMTBDDocument.TBDDocument;

                hasWeatherData = tBDDocument?.Building.GetWeatherYear() != null;

                analyticalModel = Query.UpdateFacingExternal(analyticalModel, tBDDocument);
                AssignAdiabaticConstruction(tBDDocument, "Adiabatic", new string[] { "-unzoned", "-internal", "-exposed" }, false, true);
                UpdateBuildingElements(tBDDocument, analyticalModel);

                adjacencyCluster = analyticalModel.AdjacencyCluster;
                UpdateThermalParameters(adjacencyCluster, tBDDocument.Building);
                analyticalModel = new AnalyticalModel(analyticalModel, adjacencyCluster);

                UpdateZones(tBDDocument.Building, analyticalModel, true);

                if (coolingDesignDays != null || heatingDesignDays != null)
                {
                    AddDesignDays(tBDDocument, coolingDesignDays, heatingDesignDays, 30);
                }

                sAMTBDDocument.Save();
            }

            if (!hasWeatherData)
            {
                return(new AnalyticalModel(analyticalModel, adjacencyCluster));
            }

            Query.Sizing(path_TBD, analyticalModel, false, true);

            using (SAMTBDDocument sAMTBDDocument = new SAMTBDDocument(path_TBD))
            {
                TBD.TBDDocument tBDDocument = sAMTBDDocument.TBDDocument;

                if (surfaceOutputSpecs != null && surfaceOutputSpecs.Count > 0)
                {
                    Core.Tas.Modify.UpdateSurfaceOutputSpecs(tBDDocument, surfaceOutputSpecs);
                    Core.Tas.Modify.AssignSurfaceOutputSpecs(tBDDocument, surfaceOutputSpecs[0].Name);
                    sAMTBDDocument.Save();
                }

                Simulate(tBDDocument, path_TSD, 1, 1);
            }

            adjacencyCluster = analyticalModel.AdjacencyCluster;
            List <Core.Result> results = AddResults(path_TSD, adjacencyCluster);

            if (unmetHours)
            {
                List <Core.Result> results_UnmetHours = Query.UnmetHours(path_TSD, path_TBD, 0.5);
                if (results_UnmetHours != null && results_UnmetHours.Count > 0)
                {
                    foreach (Core.Result result in results_UnmetHours)
                    {
                        if (result is AdjacencyClusterSimulationResult)
                        {
                            adjacencyCluster.AddObject(result);
                        }
                        else if (result is SpaceSimulationResult)
                        {
                            SpaceSimulationResult spaceSimulationResult = (SpaceSimulationResult)result;

                            List <SpaceSimulationResult> spaceSimulationResults = Query.Results(results, spaceSimulationResult);
                            if (spaceSimulationResults == null)
                            {
                                results.Add(spaceSimulationResult);
                            }
                            else
                            {
                                spaceSimulationResults.ForEach(x => Core.Modify.Copy(spaceSimulationResult, x, Analytical.SpaceSimulationResultParameter.UnmetHourFirstIndex, Analytical.SpaceSimulationResultParameter.UnmetHours, Analytical.SpaceSimulationResultParameter.OccupiedUnmetHours));
                            }
                        }
                    }
                }
            }

            AnalyticalModel analyticalModel_Temp = new AnalyticalModel(analyticalModel, adjacencyCluster);

            //if (System.IO.File.Exists(path_TSD))
            //{
            //    string path_TPD = System.IO.Path.Combine(directory, string.Format("{0}.{1}", fileName, "tpd"));

            //    CreateTPD(path_TPD, path_TSD, analyticalModel_Temp);
            //}

            adjacencyCluster = UpdateDesignLoads(path_TBD, analyticalModel_Temp.AdjacencyCluster);

            return(new AnalyticalModel(analyticalModel, adjacencyCluster));
        }
示例#13
0
        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);
        }