double GetExactApproach(MerkelData merkelData)
        {
            double approach;
            double delta = 1.0;

            //---------------------------------------------------------------------
            // Find approach within .001
            //---------------------------------------------------------------------
            for (approach = 0.0; approach < 100.0; approach += delta)
            {
                merkelData.Approach = approach;
                double kavl = CalculationLibrary.CalculateMerkel(merkelData);

                if (delta > 0.9)
                {
                    if (kavl < merkelData.KaV_L)
                    {
                        delta = -0.001;
                    }
                    else
                    {
                        break; // calculation error?
                    }
                }
                else
                {
                    if (kavl >= merkelData.KaV_L)
                    {
                        approach = Math.Round(approach, 3, MidpointRounding.ToEven);
                        break;
                    }
                }
            }
            return(approach);
        }
Exemplo n.º 2
0
        public bool MerkelCalculation(MerkelData data, out string errorMessage)
        {
            data.Range    = data.HotWaterTemperature - data.ColdWaterTemperature;
            data.Approach = data.ColdWaterTemperature - data.WetBulbTemperature;

            CalculationLibrary.CalculateMerkel(data);

            return(Merkel_CheckCalculationValues(data, out errorMessage));
        }
        void InitializeApproachList(DemandCurveData data)
        {
            MerkelData merkelData = new MerkelData()
            {
                WetBulbTemperature = data.WetBulbTemperature,
                Range            = data.Range,
                Elevation        = data.Elevation,
                LiquidToGasRatio = 0.1
            };

            foreach (double approachValue in InitialApproachXValues)
            {
                merkelData.Approach = approachValue;

                double KaVL            = CalculationLibrary.CalculateMerkel(merkelData);
                bool   approachInRange = (KaVL > 0.1) && (KaVL < 5.0);
                ApproachInRange.Add(approachInRange);
                ApproachOutOfRange.Add(!approachInRange);
            }
        }
        void CalculateApproaches(DemandCurveData data)
        {
            //StreamWriter fs = new StreamWriter("new.txt");

            MerkelData merkelData = new MerkelData()
            {
                WetBulbTemperature = 80, // data.WetBulbTemperature,
                Range            = data.Range,
                Elevation        = data.Elevation,
                LiquidToGasRatio = data.LiquidToGasRatio
            };

            double       kaVL = 0;
            double       calculatedWaterAirRatio = 0.0;
            const double waterAirRatio_MIN = 0.01, waterAirRatio_MAX = 5.0;
            double       calculatedWaterAirRatio_MIN = 999.0;

            //ApproachXValues[INDEX_TARGETAPPROACH] = TargetApproach;
            //ApproachXValues[INDEX_USERAPPROACH] = UserApproach;

            for (double waterAirRatio = waterAirRatio_MIN; waterAirRatio < waterAirRatio_MAX; waterAirRatio += .05)
            {
                //fs.WriteLine("\ndLG {0} \n", waterAirRatio.ToString("F6"));
                DataRow dataRow = data.DataTable.NewRow();

                for (int i = 0; i < InitialApproachXValues.Length; i++)
                {
                    //fs.WriteLine("\niIndex {0}  getapp(iIndex) {1} App[iIndex] {2} ", i, 1, (int)ApproachXValues[i]);
                    string approachXValue = ((int)InitialApproachXValues[i]).ToString();

                    if (ApproachInRange[i] && !ApproachOutOfRange[i])
                    {
                        merkelData.LiquidToGasRatio = waterAirRatio;
                        merkelData.Approach         = InitialApproachXValues[i];
                        if (data.IsInternationalSystemOfUnits_IS_)
                        {
                            merkelData.Approach *= 1.8;
                        }

                        if (waterAirRatio > 1.3 && waterAirRatio < 1.4)
                        {
                            //fs.WriteLine();
                        }

                        //fs.WriteLine(" m_dblCurveWBT {0}, m_dblCurveRange {1}, App[iIndex] {2}, dLG {3}, m_dblAltitude {4} ", merkelData.WetBulbTemperature.ToString("F6"), merkelData.Range.ToString("F6"), merkelData.Approach.ToString("F6"), merkelData.WaterAirRatio.ToString("F6"), merkelData.Elevation.ToString("F6"));

                        kaVL = CalculationLibrary.CalculateMerkel(merkelData);

                        //fs.WriteLine(" m_dblCurveWBT {0}, m_dblCurveRange {1}, App[iIndex] {2}, dLG {3}, m_dblAltitude {4} ", merkelData.WetBulbTemperature.ToString("F6"), merkelData.Range.ToString("F6"), merkelData.Approach.ToString("F6"), merkelData.WaterAirRatio.ToString("F6"), merkelData.Elevation.ToString("F6"));
                        //fs.WriteLine("kavl {0} minVal {1} maxVal {2} dLG {3} App[iIndex] {4} ", kaVL.ToString("F6"), waterAirRatio_MIN.ToString("F6"), waterAirRatio_MAX.ToString("F6"), waterAirRatio.ToString("F6"), ApproachXValues[i].ToString("F6"));

                        // ddp
                        if ((kaVL < waterAirRatio_MIN) || (kaVL >= waterAirRatio_MAX))
                        {
                            double dInterp;
                            for (dInterp = waterAirRatio; ((kaVL < waterAirRatio_MIN) || (kaVL >= waterAirRatio_MAX)) && (dInterp > .1); dInterp -= 0.0002)
                            {
                                merkelData.Approach = InitialApproachXValues[i];
                                if (data.IsInternationalSystemOfUnits_IS_)
                                {
                                    merkelData.Approach *= 1.8;
                                }
                                merkelData.LiquidToGasRatio = dInterp;
                                kaVL = CalculationLibrary.CalculateMerkel(merkelData);
                            }
                            calculatedWaterAirRatio = dInterp;
                            ApproachOutOfRange[i]   = true; //DDP This is the last point
                        }
                        else
                        {
                            calculatedWaterAirRatio = waterAirRatio;
                        }

                        //fs.WriteLine("kavl {0} dLG {1} App[iIndex] {2} ", kaVL.ToString("F6"), waterAirRatio.ToString("F6"), ApproachXValues[i].ToString("F6"));

                        if ((calculatedWaterAirRatio_MIN > kaVL) && (kaVL > .1))
                        {
                            calculatedWaterAirRatio_MIN = kaVL;
                        }
                        //fs.Write("sDLG {0} ", calculatedWaterAirRatio.ToString("F6"));
                        //fs.Write("min4Lg {0} \n", min4Lg.ToString("F6"));

                        if ((kaVL <= 10.0) && (kaVL >= .1))
                        {
                            //fs.WriteLine("index {2} m_wndGraph {0} {1}", calculatedWaterAirRatio.ToString("F6"), kaVL.ToString("F6"), i);
                            dataRow[string.Format("L/G-{0}", approachXValue)]  = calculatedWaterAirRatio;
                            dataRow[string.Format("kaVL-{0}", approachXValue)] = kaVL;
                        }
                    }
                }
                data.DataTable.Rows.Add(dataRow);
            }

            ////---------------------------------------------------------------------
            //// Draw Fill Line
            ////---------------------------------------------------------------------
            //if ((data.CurveC1 != 0) && (data.CurveC2 != 0))//&& coef)
            //{
            //    for (double waterAirRatio = data.CurveMinimum; waterAirRatio <= data.CurveMaximum; waterAirRatio += .05)
            //    {
            //        DataRow dataRow = data.DataTable.NewRow();
            //        if ((waterAirRatio >= data.CurveMinimum) && (waterAirRatio <= data.CurveMaximum))
            //        {
            //            double dblK = data.CurveC1 * Math.Pow(waterAirRatio, data.CurveC2);

            //            if ((dblK >= calculatedWaterAirRatio_MIN) && (dblK <= waterAirRatio_MAX))
            //            {
            //                dataRow["kaVL-COEF"] = kaVL;
            //                dataRow["L/G-COEF"] = calculatedWaterAirRatio;
            //                //m_wndGraph.GetSeries(INDEX_COEF).AddXY(waterAirRatio, dblK, NULL, 00099FF);
            //            }
            //        }
            //        data.DataTable.Rows.Add(dataRow);
            //    }
            //}

            //////---------------------------------------------------------------------
            ////// Draw L/G line
            //////---------------------------------------------------------------------
            //if (data.WaterAirRatio > waterAirRatio_MIN && data.WaterAirRatio <= waterAirRatio_MAX)// && Lg)
            //{
            //    DataColumn dataColumn = new DataColumn();
            //    dataColumn.ColumnName = "L/G-X";
            //    dataColumn.DataType = Type.GetType("System.Double");
            //    data.DataTable.Columns.Add(dataColumn);
            //    dataColumn = new DataColumn();
            //    dataColumn.ColumnName = "L/G-Y";
            //    dataColumn.DataType = Type.GetType("System.Double");
            //    data.DataTable.Columns.Add(dataColumn);

            //    DataRow dataRow = data.DataTable.NewRow();
            //    dataRow["L/G-Y"] = data.WaterAirRatio;
            //    dataRow["L/G-X"] = calculatedWaterAirRatio_MIN;
            //    data.DataTable.Rows.Add(dataRow);

            //    dataRow = data.DataTable.NewRow();
            //    dataRow["L/G-Y"] = data.WaterAirRatio;
            //    dataRow["L/G-X"] = waterAirRatio_MAX;
            //    data.DataTable.Rows.Add(dataRow);
            //}

            //////---------------------------------------------------------------------
            ////// Draw KaV/L line
            //////---------------------------------------------------------------------
            //if ((data.KaV_L > 0.1) && (data.KaV_L <= waterAirRatio_MAX)) // && m_bShowKaVLLine)
            //{
            //    DataRow dataRow = data.DataTable.NewRow();
            //    dataRow[string.Format("kaVL-{0}", INDEX_KAVL)] = waterAirRatio_MIN;
            //    dataRow[string.Format("L/G-{0}", INDEX_KAVL)] = data.KaV_L;
            //    data.DataTable.Rows.Add(dataRow);
            //    dataRow = data.DataTable.NewRow();
            //    dataRow[string.Format("kaVL-{0}", INDEX_KAVL)] = waterAirRatio_MAX;
            //    dataRow[string.Format("L/G-{0}", INDEX_KAVL)] = data.KaV_L;
            //    data.DataTable.Rows.Add(dataRow);
            data.DataTable.Rows[0][string.Format("kaVL-{0}", INDEX_KAVL)] = waterAirRatio_MAX;
            //    data.DataTable.Rows[0][columnName] = waterAirRatio_MAX;
            //    data.DataTable.Rows[1][columnName] = waterAirRatio_MAX;
            //}

            //fs.Flush();
            //fs.Close();
        }