Ejemplo n.º 1
0
        private static bool Sizing_PrepareDocument(string path_TBD, bool excludeOutdoorAir = true)
        {
            if (string.IsNullOrWhiteSpace(path_TBD) || !global::System.IO.File.Exists(path_TBD))
            {
                return(false);
            }

            bool result = false;

            using (SAMTBDDocument sAMTBDDocument = new SAMTBDDocument(path_TBD))
            {
                TBDDocument tBDDocument = sAMTBDDocument.TBDDocument;
                Building    building    = tBDDocument?.Building;
                if (building != null)
                {
                    SizingType sizingType = SizingType.tbdSizing;

                    List <zone> zones = building.Zones();
                    foreach (zone zone in zones)
                    {
                        zone.sizeCooling    = (int)sizingType;
                        zone.sizeHeating    = (int)sizingType;
                        zone.maxCoolingLoad = 0;
                        zone.maxHeatingLoad = 0;
                    }

                    List <TBD.InternalCondition> internalConditions = building.InternalConditions();
                    for (int i = internalConditions.Count - 1; i >= 0; i--)
                    {
                        TBD.InternalCondition internalCondition = building.GetIC(i);
                        if (internalCondition.name.EndsWith("HDD"))
                        {
                            if (excludeOutdoorAir)
                            {
                                profile profile = internalCondition.GetInternalGain()?.GetProfile((int)Profiles.ticV);
                                if (profile != null)
                                {
                                    profile.factor = 0;
                                }
                            }

                            //while (internalCondition.GetZone(0) != null)
                            //{
                            //    zone zone = internalCondition.GetZone(0);
                            //    zone.AssignIC(internalCondition, false);
                            //}
                        }
                    }

                    sAMTBDDocument.Save();
                    result = true;
                }
            }

            return(result);
        }
Ejemplo n.º 2
0
        private static bool Sizing_ApplyAirGlass(string path_TBD, bool excludePositiveInternalGains = false)
        {
            if (string.IsNullOrWhiteSpace(path_TBD) || !global::System.IO.File.Exists(path_TBD))
            {
                return(false);
            }

            bool result = false;

            using (SAMTBDDocument sAMTBDDocument = new SAMTBDDocument(path_TBD))
            {
                TBDDocument tBDDocument = sAMTBDDocument.TBDDocument;
                Building    building    = tBDDocument?.Building;
                if (building != null)
                {
                    TBD.Construction construction = building.GetConstructionByName("Air_Glass");
                    if (construction == null)
                    {
                        construction      = building.AddConstruction(null);
                        construction.name = "Air_Glass";
                        construction.type = TBD.ConstructionTypes.tcdTransparentConstruction;
                        material material = construction.AddMaterial();
                        material.name                  = "Air_Glass";
                        material.description           = "Special for HDD sizing";
                        material.type                  = (int)MaterialTypes.tcdTransparentLayer;
                        material.width                 = global::System.Convert.ToSingle(0.02 / 1000);
                        material.conductivity          = 1;
                        material.vapourDiffusionFactor = 1;
                        material.solarTransmittance    = 0.999999f;
                        material.externalEmissivity    = 0.00001f;
                        material.internalEmissivity    = 0.00001f;
                    }

                    List <buildingElement> buildingElements = building.BuildingElements();
                    foreach (buildingElement buildingElement in buildingElements)
                    {
                        if (!buildingElement.name.Contains("_AIR"))
                        {
                            continue;
                        }

                        buildingElement.ghost = 0;
                        buildingElement.AssignConstruction(construction);
                    }

                    if (excludePositiveInternalGains)
                    {
                        Sizing_ExcludePositiveInternalGains(tBDDocument);
                    }
                    else
                    {
                        SizingType sizingType = SizingType.tbdDesignSizingOnly;

                        List <zone> zones = building.Zones();
                        foreach (zone zone in zones)
                        {
                            zone.sizeCooling = (int)sizingType;
                            zone.sizeHeating = (int)sizingType;
                        }

                        tBDDocument.sizing(0);
                    }

                    sAMTBDDocument.Save();
                    result = true;
                }
            }

            return(result);
        }
Ejemplo n.º 3
0
        private static bool Sizing_ExcludePositiveInternalGains(this TBDDocument tBDDocument)
        {
            if (tBDDocument == null)
            {
                return(false);
            }

            List <zone> zones = tBDDocument?.Building?.Zones();

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

            SizingType sizingType = SizingType.tbdDesignSizingOnly;

            List <Tuple <zone, TBD.InternalCondition, double> > tuples = new List <Tuple <zone, TBD.InternalCondition, double> >();

            foreach (zone zone in zones)
            {
                zone.sizeHeating = (int)sizingType;
                zone.sizeCooling = (int)sizingType;

                List <TBD.InternalCondition> internalConditions = zone.InternalConditions();
                if (internalConditions == null || internalConditions.Count == 0)
                {
                    tuples.Add(new Tuple <zone, TBD.InternalCondition, double>(zone, null, -50));
                    continue;
                }

                TBD.InternalCondition internalCondition = internalConditions.Find(x => x.name.EndsWith(" - HDD"));
                if (internalCondition == null)
                {
                    tuples.Add(new Tuple <zone, TBD.InternalCondition, double>(zone, null, -50));
                    continue;
                }

                tuples.Add(new Tuple <zone, TBD.InternalCondition, double>(zone, internalCondition, internalCondition.GetLowerLimit()));
            }

            List <double> temperatures_Unique = tuples.ConvertAll(x => x.Item3).Distinct().ToList();

            temperatures_Unique.Sort();

            if (temperatures_Unique.Count == 0)
            {
                return(false);
            }

            Dictionary <zone, double> dictionary = new Dictionary <zone, double>();

            foreach (double tempearture in temperatures_Unique)
            {
                if (tempearture <= -50)
                {
                    continue;
                }

                //Here we filter room that have higher temperature than current set point
                List <Tuple <zone, TBD.InternalCondition, double> > tuples_Temperature = tuples.FindAll(x => x.Item3 >= tempearture);

                foreach (Tuple <zone, TBD.InternalCondition, double> tuple in tuples_Temperature)
                {
                    Thermostat thermostat = tuple.Item2?.GetThermostat();
                    if (thermostat == null)
                    {
                        continue;
                    }

                    profile profile = thermostat.GetProfile((int)Profiles.ticLL);
                    if (profile == null)
                    {
                        continue;
                    }

                    profile.value = global::System.Convert.ToSingle(tempearture);
                }

                tBDDocument.save();
                tBDDocument.sizing(0);

                tuples_Temperature = tuples_Temperature.FindAll(x => x.Item3 == tempearture);
                foreach (Tuple <zone, TBD.InternalCondition, double> tuple in tuples_Temperature)
                {
                    if (!dictionary.ContainsKey(tuple.Item1))
                    {
                        dictionary[tuple.Item1] = tuple.Item1.maxHeatingLoad;
                    }
                }
            }

            sizingType = SizingType.tbdNoSizing;
            foreach (KeyValuePair <zone, double> keyValuePair in dictionary)
            {
                zone zone = keyValuePair.Key;

                zone.sizeCooling = (int)sizingType;
                zone.sizeHeating = (int)sizingType;

                zone.maxHeatingLoad = global::System.Convert.ToSingle(keyValuePair.Value);
            }

            return(true);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// 缩放(超出留白,剪裁,拉伸)
        /// </summary>
        /// <param name="savePath">保存路径</param>
        /// <param name="width">目标宽度</param>
        /// <param name="height">目标高度</param>
        /// <param name="mode"></param>
        /// <param name="level"></param>
        /// <returns></returns>
        public bool Scale(string savePath, int width, int height, SizingType mode, int level = 100)
        {
            try
            {
                #region 尺寸计算
                //画布
                int x = 0;
                int y = 0;
                int ow = drawingImages.Width;
                int oh = drawingImages.Height;
                //目标图像宽高
                int toWidth = width;
                int toHeight = height;

                switch (mode)
                {
                    case SizingType.HW:
                        if ((double)drawingImages.Width / (double)drawingImages.Height > (double)toWidth / (double)toHeight)
                        {
                            ow = drawingImages.Width;
                            oh = drawingImages.Width * height / toWidth;
                            x = 0;
                            y = (drawingImages.Height - oh) / 2;
                        }
                        else
                        {
                            oh = drawingImages.Height;
                            ow = drawingImages.Height * width / toHeight;
                            x = (drawingImages.Width - ow) / 2;
                            y = 0;
                        }
                        break;
                    case SizingType.Cut:
                        bool cut = Cut(savePath, 0, 0, width, height);
                        if (cut) return true;
                        break;
                    case SizingType.Stretch:
                        break;
                    default:
                        break;
                }

                if (toWidth == drawingImages.Width && toHeight == drawingImages.Height)
                {
                    drawingImages.Save(savePath);
                    return true;
                }
                #endregion
                string mimetype = GetFormat(savePath).ToString().ToLower();
                using (Bitmap bm = new Bitmap(toWidth, toHeight))
                {
                    using (Graphics g = Graphics.FromImage(bm))
                    {
                        g.CompositingQuality = CompositingQuality.HighQuality;  //合成图像的呈现质量
                        g.InterpolationMode = InterpolationMode.HighQualityBicubic;   //指定高质量的双三次插值法
                        g.SmoothingMode = SmoothingMode.HighQuality;    //指定抗锯齿的呈现
                        Color color = mimetype == "png" ? Color.Transparent : Color.White;  //png设置背景透明
                        g.Clear(color);
                        g.DrawImage(drawingImages, new Rectangle(0, 0, toWidth, toHeight), new Rectangle(x, y, ow, oh), GraphicsUnit.Pixel);
                        g.Dispose();
                    }
                    setQuality(level, mimetype);
                    bm.Save(savePath, ici, ep);
                    bm.Dispose();
                }
                drawingImages.Dispose();

                return File.Exists(savePath) ? true : false;
            }
            catch (Exception)
            {
                drawingImages.Dispose();
                throw;
            }

        }