Ejemplo n.º 1
0
        public static bool Rename(this gbXMLSerializer.Space space, string name)
        {
            if (string.IsNullOrWhiteSpace(name))
            {
                return(false);
            }

            space.Name = name;
            return(true);
        }
        public static Space assignSimpleDefaults(Space zespace, int zonecount)
        {
            CultureInfo ci = new CultureInfo(String.Empty);

            try
            {
                //area and volume should already be computed
                //zespace.id = "Space-1";
                zespace.lightScheduleIdRef = "lightSchedule-1";
                zespace.equipmentScheduleIdRef = "equipmentSchedule-1";
                zespace.peopleScheduleIdRef = "peopleSchedule-1";
                zespace.conditionType = "HeatedAndCooled";
                zespace.buildingStoreyIdRef = "bldg-story-1";
                zespace.Name = "Test Space-" + zonecount;

                zespace.peoplenum = zespace.Area / 150;
                PeopleNumber pn = new PeopleNumber();
                pn.unit = peopleNumberUnitEnum.NumberOfPeople;
                pn.valuefield = (zespace.Area/150).ToString();
                zespace.PeopleNumber = pn;

                zespace.PeopleHeatGains = new PeopleHeatGain[3];

                zespace.totalpeoplegain = 450;
                PeopleHeatGain tph = new PeopleHeatGain();
                tph.heatGainType = peopleHeatGainTypeEnum.Total;
                tph.unit = peopleHeatGainUnitEnum.BtuPerHourPerson;
                tph.value = string.Format(ci, "{0:0.000000}","450");
                zespace.PeopleHeatGains[0] = tph;

                zespace.senspeoplegain = 250;
                PeopleHeatGain sph = new PeopleHeatGain();
                sph.heatGainType = peopleHeatGainTypeEnum.Sensible;
                sph.unit = peopleHeatGainUnitEnum.BtuPerHourPerson;
                sph.value = string.Format(ci, "{0:0.000000}","250");
                zespace.PeopleHeatGains[1] = sph;

                zespace.latpeoplegain = 200;
                PeopleHeatGain lph = new PeopleHeatGain();
                lph.heatGainType = peopleHeatGainTypeEnum.Latent;
                lph.unit = peopleHeatGainUnitEnum.BtuPerHourPerson;
                lph.value = string.Format(ci, "{0:0.000000}","200");
                zespace.PeopleHeatGains[2] = lph;

                zespace.lpd = 1.2;
                LightPowerPerArea lp = new LightPowerPerArea();
                lp.unit = powerPerAreaUnitEnum.WattPerSquareFoot;
                lp.lpd = string.Format(ci, "{0:0.000000}","1.2");
                zespace.LightPowerPerArea = lp;

                zespace.epd = 1.5;
                EquipPowerPerArea ep = new EquipPowerPerArea();
                ep.unit = powerPerAreaUnitEnum.WattPerSquareFoot;
                ep.epd = string.Format(ci, "{0:0.000000}","1.5");
                zespace.EquipPowerPerArea = ep;

                Area a = new Area();
                a.val = string.Format(ci, "{0:0.000000}",zespace.Area.ToString());
                zespace.spacearea = a;

                Volume v = new Volume();
                v.val = string.Format(ci, "{0:0.000000}",zespace.Volume.ToString());
                zespace.spacevol = v;

                //everything is prepared for geometry
                zespace.PlanarGeo = new PlanarGeometry();
                zespace.ShellGeo = new ShellGeometry();
                return zespace;
            }
            catch (Exception e)
            {
                throw e;
            }
        }
        public static List<Space> MakeSpacesFromEPObj(List<EPObj.MemorySafe_Spaces> myspace)
        {
            List<Space> retspaces = new List<Space>();
            int spacecount = 0;
            foreach (EPObj.MemorySafe_Spaces space in myspace)
            {
                //foreach Space space in your ListofSpaces
                Space zespace = new Space();
                zespace.id = "Space-1";
                zespace.lightScheduleIdRef = "lightSchedule-1";
                zespace.equipmentScheduleIdRef = "equipmentSchedule-1";
                zespace.peopleScheduleIdRef = "peopleSchedule-1";
                zespace.conditionType = "HeatedAndCooled";
                zespace.buildingStoreyIdRef = "bldg-story-1";
                zespace.Name = "Test Space-" + spacecount;
                zespace.peoplenum = 12;
                zespace.totalpeoplegain = 450;
                zespace.senspeoplegain = 250;
                zespace.latpeoplegain = 200;
                zespace.PeopleHeatGains = new PeopleHeatGain[3];
                zespace.lpd = 1.2;
                zespace.epd = 1.5;
                zespace.Area = 2450;
                zespace.Volume = 24500;
                zespace.PlanarGeo = new PlanarGeometry();
                zespace.ShellGeo = new ShellGeometry();

                PeopleNumber pn = new PeopleNumber();
                pn.unit = peopleNumberUnitEnum.NumberOfPeople;

                string people = gb.FormatDoubleToString(zespace.peoplenum);
                pn.valuefield = people;
                zespace.PeopleNumber = pn;

                PeopleHeatGain phg = new PeopleHeatGain();
                phg.unit = peopleHeatGainUnitEnum.BtuPerHourPerson;
                phg.heatGainType = peopleHeatGainTypeEnum.Total;
                string totalpopload = gb.FormatDoubleToString(zespace.totalpeoplegain);
                phg.value = totalpopload;
                zespace.PeopleHeatGains[0] = phg;

                PeopleHeatGain shg = new PeopleHeatGain();
                shg.unit = peopleHeatGainUnitEnum.BtuPerHourPerson;
                shg.heatGainType = peopleHeatGainTypeEnum.Sensible;
                string senspopload = gb.FormatDoubleToString(zespace.senspeoplegain);
                shg.value = senspopload;
                zespace.PeopleHeatGains[1] = shg;

                PeopleHeatGain lhg = new PeopleHeatGain();
                lhg.unit = peopleHeatGainUnitEnum.BtuPerHourPerson;
                lhg.heatGainType = peopleHeatGainTypeEnum.Latent;
                string latpopload = gb.FormatDoubleToString(zespace.latpeoplegain);
                lhg.value = latpopload;
                zespace.PeopleHeatGains[2] = lhg;

                LightPowerPerArea lpd = new LightPowerPerArea();
                lpd.unit = powerPerAreaUnitEnum.WattPerSquareFoot;
                lpd.lpd = gb.FormatDoubleToString(zespace.lpd);
                zespace.LightPowerPerArea = lpd;

                EquipPowerPerArea epd = new EquipPowerPerArea();
                epd.unit = powerPerAreaUnitEnum.WattPerSquareFoot;
                epd.epd = gb.FormatDoubleToString(zespace.epd);
                zespace.EquipPowerPerArea = epd;

                Area spacearea = new Area();
                spacearea.val = gb.FormatDoubleToString(zespace.Area);
                zespace.spacearea = spacearea;

                Volume spacevol = new Volume();
                spacevol.val = gb.FormatDoubleToString(zespace.Volume);
                zespace.spacevol = spacevol;

                //same as the planar geometry of the floor planes above
                PlanarGeometry spaceplpoly = new PlanarGeometry();
                //get a list of points that makes up the polyloop
                List<List<double>> spacepoints = prod.MakeFakeList(3);
                //make polyloop with points
                spaceplpoly.PolyLoop = new PolyLoop();
                spaceplpoly.PolyLoop = prod.makePolyLoopsFromDbleList(spaceplpoly.PolyLoop, spacepoints);
                zespace.PlanarGeo = spaceplpoly;
                //@@
                //ShellGeometry
                //similar to planar geometry, but with more planes
                ShellGeometry sg = new ShellGeometry();
                sg.unit = lengthUnitEnum.Feet;
                sg.id = "sg" + space.name;
                sg.ClosedShell = new ClosedShell();
                //up to 100 surfaces per space?  base on the space instance surfaces
                sg.ClosedShell.PolyLoops = new PolyLoop[space.spaceSurfaces.Count()];
                //I would have a list of surface elements that make up the space surfaces.
                //each surface would consist of a series of points that defines the surface.
                for (int i = 0; i < space.spaceSurfaces.Count(); i++)
                {
                    //get points from the space surfaces
                    List<List<double>> epluspoints = new List<List<double>>();
                    epluspoints = EnergyPlusClass.GetCoordinDoubles(space.spaceSurfaces[i].SurfaceCoords);
                    sg.ClosedShell.PolyLoops[i] = new PolyLoop();
                    sg.ClosedShell.PolyLoops[i] = prod.makePolyLoopsFromDbleList(sg.ClosedShell.PolyLoops[i], epluspoints);
                }
                zespace.ShellGeo = sg;

                zespace.cadid = new CADObjectId();
                zespace.cadid.id = "990099-" + spacecount;
                //make surface boundaries..special code needed so that space boundaries are not duplicated...
                //option 1 : the surfaces already declared as internal somehow and how shared.
                //option 2:  the api tries to figure it out
                zespace.spbound = new SpaceBoundary[space.spaceSurfaces.Count()];
                int psurfacecount = 0;
                for (int i = 0; i < space.spaceSurfaces.Count(); i++)
                {
                    //get points from the space surfaces
                    List<List<double>> epluspoints = new List<List<double>>();
                    epluspoints = EnergyPlusClass.GetCoordinDoubles(space.spaceSurfaces[i].SurfaceCoords);
                    //if surface is exterior
                    SpaceBoundary sb = new SpaceBoundary();
                    zespace.spbound[i] = prod.MakeSpaceBoundary(sb, epluspoints, psurfacecount);

                    psurfacecount++;
                    //else if surface is interior and it has not been listed before
                    //then do the same
                    //else do nothing because it is interior and it has already been listed

                    //I also would like to keep track of all the surfaces that I create to better prepare me for the surface definition
                    uniquesurf.Add(zespace.spbound[i].PlanarGeometry);
                    //make a dictionary that stores the name of a surface and its planar geometry?
                    uniqueplanes.Add(zespace.spbound[i].surfaceIdRef, zespace.spbound[i].PlanarGeometry);
                    //make a dictionary that stores the name of a surface and create a surface as the value

                    Surface newsurface = new Surface();
                    //this took a lot of customization...a user would have to make their own code to attach to my object here
                    newsurface = prod.SetUpSurfaceFromIDF(space.spaceSurfaces[i], zespace.spbound[i].PlanarGeometry);
                    uniquesurfaces.Add(zespace.spbound[i].surfaceIdRef, newsurface);
                }

                retspaces.Add(zespace);
                spacecount++;
            }
            return retspaces;
        }
Ejemplo n.º 4
0
        public static Building TogbXML(this AdjacencyCluster adjacencyCluster, string name, string description, double tolerance = Tolerance.MicroDistance)
        {
            List <Panel> panels = adjacencyCluster?.GetPanels();

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

            List <Space> spaces = adjacencyCluster.GetSpaces();

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

            //Dictionary of Minimal Elevations and List of Panels
            Dictionary <double, List <Panel> > dictionary_MinElevations = Analytical.Query.MinElevationDictionary(panels, true, Tolerance.MacroDistance);

            //Dictionary of gbXML BuildingStoreys and its elevations
            Dictionary <BuildingStorey, double> dictionary_buildingStoreys = new Dictionary <BuildingStorey, double>();

            //Dictionary of SAM Panels related buildingSorey, minimal elevation and maximal elevation
            Dictionary <Panel, Tuple <BuildingStorey, double, double, double> > dictionary_Panels = new Dictionary <Panel, Tuple <BuildingStorey, double, double, double> >();

            foreach (KeyValuePair <double, List <Panel> > keyValuePair in dictionary_MinElevations)
            {
                BuildingStorey buildingStorey = Architectural.Create.Level(keyValuePair.Key).TogbXML(tolerance);
                dictionary_buildingStoreys[buildingStorey] = keyValuePair.Key;
                foreach (Panel panel in keyValuePair.Value)
                {
                    dictionary_Panels[panel] = new Tuple <BuildingStorey, double, double, double> (buildingStorey, keyValuePair.Key, panel.MinElevation(), panel.MaxElevation());
                }
            }

            List <gbXMLSerializer.Space>     spaces_gbXML = new List <gbXMLSerializer.Space>();
            Dictionary <Guid, SpaceBoundary> dictionary   = new Dictionary <Guid, SpaceBoundary>();

            foreach (Space space in spaces)
            {
                List <Panel> panels_Space = adjacencyCluster.GetRelatedObjects <Panel>(space);
                if (panels_Space == null || panels_Space.Count == 0)
                {
                    continue;
                }

                double         elevation_Level = panels_Space.ConvertAll(x => dictionary_Panels[x].Item2).Min();
                double         elevation_Min   = panels_Space.ConvertAll(x => dictionary_Panels[x].Item3).Min();
                double         elevation_Max   = panels_Space.ConvertAll(x => dictionary_Panels[x].Item4).Max();
                BuildingStorey buildingStorey  = null;
                foreach (KeyValuePair <BuildingStorey, double> keyValuePair in dictionary_buildingStoreys)
                {
                    if (keyValuePair.Value.Equals(elevation_Level))
                    {
                        buildingStorey = keyValuePair.Key;
                        break;
                    }
                }

                if (buildingStorey == null)
                {
                    continue;
                }

                List <Panel> panels_PlanarGeometry = panels_Space.FindAll(x => x.PanelType.PanelGroup() == PanelGroup.Floor || (x.Normal.AlmostSimilar(Vector3D.WorldZ.GetNegated()) && dictionary_Panels[x].Item3 == elevation_Min));
                panels_PlanarGeometry = panels_PlanarGeometry?.MergeCoplanarPanels(Tolerance.MacroDistance, false, false, Tolerance.MacroDistance);
                if (panels_PlanarGeometry == null || panels_PlanarGeometry.Count == 0)
                {
                    continue;
                }

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

                Face3D face3D = panels_PlanarGeometry.First().PlanarBoundary3D?.GetFace3D();
                if (face3D == null)
                {
                    continue;
                }

                double area = face3D.GetArea();
                if (area < Tolerance.MacroDistance)
                {
                    continue;
                }

                double volume = Math.Abs(elevation_Max - elevation_Min) * area;
                if (volume < Tolerance.MacroDistance)
                {
                    continue;
                }

                List <SpaceBoundary> spaceBoundaries = new List <SpaceBoundary>();
                foreach (Panel panel in panels_Space)
                {
                    if (panel == null)
                    {
                        continue;
                    }

                    SpaceBoundary spaceBoundary = null;
                    if (!dictionary.TryGetValue(panel.Guid, out spaceBoundary))
                    {
                        spaceBoundary          = panel.TogbXML_SpaceBoundary(tolerance);
                        dictionary[panel.Guid] = spaceBoundary;
                    }

                    spaceBoundaries.Add(spaceBoundary);
                }

                gbXMLSerializer.Space space_gbXML = new gbXMLSerializer.Space();
                space_gbXML.Name      = space.Name;
                space_gbXML.spacearea = new Area()
                {
                    val = area.ToString()
                };
                space_gbXML.spacevol = new Volume()
                {
                    val = volume.ToString()
                };
                space_gbXML.buildingStoreyIdRef = buildingStorey.id;
                space_gbXML.cadid = new CADObjectId()
                {
                    id = space.Guid.ToString()
                };
                space_gbXML.PlanarGeo = face3D.TogbXML(tolerance);
                space_gbXML.id        = Core.gbXML.Query.Id(space, typeof(gbXMLSerializer.Space));
                space_gbXML.spbound   = spaceBoundaries.ToArray();
                space_gbXML.ShellGeo  = panels_Space.TogbXML(space, tolerance);

                spaces_gbXML.Add(space_gbXML);
            }

            Building building = new Building();

            building.id           = Core.gbXML.Query.Id(adjacencyCluster, typeof(Building));
            building.Name         = name;
            building.Description  = description;
            building.bldgStories  = dictionary_buildingStoreys.Keys.ToArray();
            building.Area         = Analytical.Query.Area(panels, PanelGroup.Floor);
            building.buildingType = buildingTypeEnum.Office;
            building.Spaces       = spaces_gbXML.ToArray();

            return(building);
        }