예제 #1
0
        public static double getMolarWeight(Resources res)
        {
            double MW = 0;

            switch (res)
            {
            case Resources.CO2:
                MW = CoolProp.PropsSI("M", "", 0, "", 0, "CO2");
                return(MW);

            case Resources.O2:
                MW = CoolProp.PropsSI("M", "", 0, "", 0, "Oxygen");
                return(MW);

            case Resources.N2:
                MW = CoolProp.PropsSI("M", "", 0, "", 0, "Nitrogen");
                return(MW);

            case Resources.CH4:
                MW = CoolProp.PropsSI("M", "", 0, "", 0, "Methane");
                return(MW);

            case Resources.Humidity:
                MW = CoolProp.PropsSI("M", "", 0, "", 0, "Water");
                return(MW);

            default:
                throw new Exception("Cannot get molar weight for unknown resource");
            }
        }
예제 #2
0
        //static void Main(string[] args)
        //{
        //    Console.WriteLine(GetH20BoilingPoint(7500));

        //    //Console.Write("**************** INFORMATION ***************" + "\n");
        //    //Console.Write("This example was auto-generated by the language-agnostic dev/scripts/example_generator.py script written by Ian Bell" + "\n");
        //    //Console.Write("CoolProp version:" + " " + CoolProp.get_global_param_string("version") + "\n");
        //    //Console.Write("CoolProp gitrevision:" + " " + CoolProp.get_global_param_string("gitrevision") + "\n");
        //    //Console.Write("CoolProp Fluids:" + " " + CoolProp.get_global_param_string("FluidsList") + "\n");

        //    //var FluidString = CoolProp.get_global_param_string("FluidsList");
        //    //List<string> Fluids = FluidString.Split(',').ToList();
        //    //foreach (string Fluid in Fluids)
        //    //{
        //    //    try {
        //    //    Console.Write("Boiling temperature of " + Fluid + " at 101325 Pa:" + " " + (Math.Round(CoolProp.PropsSI("T", "P", 10000, "Q", 0, Fluid), 2) - 273.15) + " " + "C" + "\n");
        //    //    }
        //    //    catch { }

        //    //}



        //    //// See http://www.coolprop.org/coolprop/HighLevelAPI.html#table-of-string-inputs-to-propssi-function for a list of inputs to high-level interface;
        //    //Console.Write("*********** HIGH LEVEL INTERFACE *****************" + "\n");
        //    //Console.Write("Critical temperature of water:" + " " + CoolProp.Props1SI("Water", "Tcrit") + " " + "K" + "\n");
        //    //Console.Write("Boiling temperature of water at 101325 Pa:" + " " + CoolProp.PropsSI("T", "P", 101325, "Q", 0, "Water") + " " + "K" + "\n");

        //}

        public static decimal GetWaterBoilingPoint(decimal PressureInPa)
        {
            decimal BoilingPoint = 0;

            if (PressureInPa >= 612 && PressureInPa <= 500000)
            {
                BoilingPoint = Math.Round(Convert.ToDecimal(CoolProp.PropsSI("T", "P", Convert.ToDouble(PressureInPa), "Q", 0, "Water") - 273.15), 2);
            }
            return(BoilingPoint);
        }
예제 #3
0
        static void Main(string[] args)
        {
            Console.Write("**************** INFORMATION ***************" + "\n");
            Console.Write("This example was auto-generated by the language-agnostic dev/scripts/example_generator.py script written by Ian Bell" + "\n");
            Console.Write("CoolProp version:" + " " + CoolProp.get_global_param_string("version") + "\n");
            Console.Write("CoolProp gitrevision:" + " " + CoolProp.get_global_param_string("gitrevision") + "\n");
            Console.Write("CoolProp Fluids:" + " " + CoolProp.get_global_param_string("FluidsList") + "\n");
            // See http://www.coolprop.org/coolprop/HighLevelAPI.html#table-of-string-inputs-to-propssi-function for a list of inputs to high-level interface;
            Console.Write("*********** HIGH LEVEL INTERFACE *****************" + "\n");
            Console.Write("Critical temperature of water:" + " " + CoolProp.Props1SI("Water", "Tcrit") + " " + "K" + "\n");
            Console.Write("Boiling temperature of water at 101325 Pa:" + " " + CoolProp.PropsSI("T", "P", 101325, "Q", 0, "Water") + " " + "K" + "\n");
            Console.Write("Phase of water at 101325 Pa and 300 K:" + " " + CoolProp.PhaseSI("P", 101325, "T", 300, "Water") + "\n");
            Console.Write("c_p of water at 101325 Pa and 300 K:" + " " + CoolProp.PropsSI("C", "P", 101325, "T", 300, "Water") + " " + "J/kg/K" + "\n");
            Console.Write("c_p of water (using derivatives) at 101325 Pa and 300 K:" + " " + CoolProp.PropsSI("d(H)/d(T)|P", "P", 101325, "T", 300, "Water") + " " + "J/kg/K" + "\n");
            Console.Write("*********** HUMID AIR PROPERTIES *****************" + "\n");
            Console.Write("Humidity ratio of 50% rel. hum. air at 300 K, 101325 Pa:" + " " + CoolProp.HAPropsSI("W", "T", 300, "P", 101325, "R", 0.5) + " " + "kg_w/kg_da" + "\n");
            Console.Write("Relative humidity from last calculation:" + " " + CoolProp.HAPropsSI("R", "T", 300, "P", 101325, "W", CoolProp.HAPropsSI("W", "T", 300, "P", 101325, "R", 0.5)) + " " + "(fractional)" + "\n");
            Console.Write("*********** INCOMPRESSIBLE FLUID AND BRINES *****************" + "\n");
            Console.Write("Density of 50% (mass) ethylene glycol/water at 300 K, 101325 Pa:" + " " + CoolProp.PropsSI("D", "T", 300, "P", 101325, "INCOMP::MEG-50%") + " " + "kg/m^3" + "\n");
            Console.Write("Viscosity of Therminol D12 at 350 K, 101325 Pa:" + " " + CoolProp.PropsSI("V", "T", 350, "P", 101325, "INCOMP::TD12") + " " + "Pa-s" + "\n");
            // If you don't have REFPROP installed, disable the following lines;
            Console.Write("*********** REFPROP *****************" + "\n");
            Console.Write("REFPROP version:" + " " + CoolProp.get_global_param_string("REFPROP_version") + "\n");
            Console.Write("Critical temperature of water:" + " " + CoolProp.Props1SI("REFPROP::WATER", "Tcrit") + " " + "K" + "\n");
            Console.Write("Boiling temperature of water at 101325 Pa:" + " " + CoolProp.PropsSI("T", "P", 101325, "Q", 0, "REFPROP::WATER") + " " + "K" + "\n");
            Console.Write("c_p of water at 101325 Pa and 300 K:" + " " + CoolProp.PropsSI("C", "P", 101325, "T", 300, "REFPROP::WATER") + " " + "J/kg/K" + "\n");
            Console.Write("*********** TABULAR BACKENDS *****************" + "\n");
            AbstractState TAB = AbstractState.factory("BICUBIC&HEOS", "R245fa");

            TAB.update(input_pairs.PT_INPUTS, 101325, 300);
            Console.Write("Mass density of refrigerant R245fa at 300 K, 101325 Pa:" + " " + TAB.rhomass() + " " + "kg/m^3" + "\n");
            Console.Write("*********** SATURATION DERIVATIVES (LOW-LEVEL INTERFACE) ***************" + "\n");
            AbstractState AS_SAT = AbstractState.factory("HEOS", "R245fa");

            AS_SAT.update(input_pairs.PQ_INPUTS, 101325, 0);
            Console.Write("First saturation derivative:" + " " + AS_SAT.first_saturation_deriv(parameters.iP, parameters.iT) + " " + "Pa/K" + "\n");
            Console.Write("*********** LOW-LEVEL INTERFACE *****************" + "\n");
            AbstractState AS = AbstractState.factory("HEOS", "Water&Ethanol");
            DoubleVector  z  = new DoubleVector(new double[] { 0.5, 0.5 });

            AS.set_mole_fractions(z);
            AS.update(input_pairs.PQ_INPUTS, 101325, 1);
            Console.Write("Normal boiling point temperature of water and ethanol:" + " " + AS.T() + " " + "K" + "\n");
            // If you don't have REFPROP installed, disable the following block;
            Console.Write("*********** LOW-LEVEL INTERFACE (REFPROP) *****************" + "\n");
            AbstractState AS2 = AbstractState.factory("REFPROP", "METHANE&ETHANE");
            DoubleVector  z2  = new DoubleVector(new double[] { 0.2, 0.8 });

            AS2.set_mole_fractions(z2);
            AS2.update(input_pairs.QT_INPUTS, 1, 120);
            Console.Write("Vapor molar density:" + " " + AS2.keyed_output(parameters.iDmolar) + " " + "mol/m^3" + "\n");
        }
예제 #4
0
        static void Main(string[] args)
        {
            AbstractState State = AbstractState.factory("HEOS", "Water");

            State.update(input_pairs.PT_INPUTS, 1e5, 300);
            double hmol = State.hmolar();

            Console.Write("Hmol: " + hmol + " J/kg" + "\n");

            double T, h, p, D;

            //Console.Write("CoolProp version: " + CoolProp.get_global_param_string("version") + "\n");
            //Console.Write("CoolProp gitrevision: " + CoolProp.get_global_param_string("gitrevision") + "\n");
            //Console.Write("CoolProp fluids: " + CoolProp.get_global_param_string("FluidsList") + "\n");

            Console.Write(" " + "\n");
            Console.Write("************ USING EOS *************" + "\n");
            Console.Write(" " + "\n");
            Console.Write("FLUID STATE INDEPENDENT INPUTS" + "\n");
            //Console.Write("Critical Density Propane: " + CoolProp.Props1SI("Propane", "rhocrit") + " kg/m^3" + "\n");
            Console.Write("TWO PHASE INPUTS (Pressure)" + "\n");
            Console.Write("Density of saturated liquid Propane at 101325 Pa: " + CoolProp.PropsSI("D", "P", 101325, "Q", 0, "Propane") + " kg/m^3" + "\n");
            Console.Write("Density of saturated vapor R290 at 101325 Pa: " + CoolProp.PropsSI("D", "P", 101325, "Q", 1, "R290") + " kg/m^3" + "\n");
            Console.Write("TWO PHASE INPUTS (Temperature)" + "\n");
            Console.Write("Density of saturated liquid Propane at 300 K: " + CoolProp.PropsSI("D", "T", 300, "Q", 0, "Propane") + " kg/m^3" + "\n");
            Console.Write("Density of saturated vapor R290 at 300 K: " + CoolProp.PropsSI("D", "T", 300, "Q", 1, "R290") + " kg/m^3" + "\n");
            Console.Write("SINGLE PHASE CYCLE (propane)" + "\n");
            p = CoolProp.PropsSI("P", "T", 300, "D", 1, "Propane");
            h = CoolProp.PropsSI("H", "T", 300, "D", 1, "Propane");
            Console.Write("T,D -> P,H " + 300 + "," + 1 + " --> " + p + "," + h + "\n");
            T = CoolProp.PropsSI("T", "P", p, "H", h, "Propane");
            D = CoolProp.PropsSI("D", "P", p, "H", h, "Propane");
            Console.Write("P,H -> T,D " + p + "," + h + " --> " + T + "," + D + "\n");

            //~ Console.Write(" " + "\n");
            //~ Console.Write("************ USING TTSE ***************" + "\n");
            //~ Console.Write(" " + "\n");
            //~ //CoolProp.enable_TTSE_LUT("Propane");
            //~ Console.Write("TWO PHASE INPUTS (Pressure)" + "\n");
            //~ Console.Write("Density of saturated liquid Propane at 101325 Pa: " + CoolProp.PropsSI("D", "P", 101325, "Q", 0, "Propane") + " kg/m^3" + "\n");
            //~ Console.Write("Density of saturated vapor R290 at 101325 Pa: " + CoolProp.PropsSI("D", "P", 101325, "Q", 1, "R290") + " kg/m^3" + "\n");
            //~ Console.Write("TWO PHASE INPUTS (Temperature)" + "\n");
            //~ Console.Write("Density of saturated liquid Propane at 300 K: " + CoolProp.PropsSI("D", "T", 300, "Q", 0, "Propane") + " kg/m^3" + "\n");
            //~ Console.Write("Density of saturated vapor R290 at 300 K: " + CoolProp.PropsSI("D", "T", 300, "Q", 1, "R290") + " kg/m^3" + "\n");
            //~ Console.Write("SINGLE PHASE CYCLE (propane)" + "\n");
            //~ p = CoolProp.PropsSI("P", "T", 300, "D", 1, "Propane");
            //~ h = CoolProp.PropsSI("H", "T", 300, "D", 1, "Propane");
            //~ Console.Write("T,D -> P,H " + 300 + ","+ 1+ " --> " + p + "," + h + "\n");
            //~ T = CoolProp.PropsSI("T", "P", p, "H", h, "Propane");
            //~ D = CoolProp.PropsSI("D", "P", p, "H", h, "Propane");
            //~ Console.Write("P,H -> T,D " + p + "," + h + " --> " + T + "," + D + "\n");
            //CoolProp.disable_TTSE_LUT("Propane");

            try
            {
                Console.Write(" " + "\n");
                Console.Write("************ USING REFPROP ***************" + "\n");
                Console.Write(" " + "\n");
                Console.Write("TWO PHASE INPUTS (Pressure)" + "\n");
                Console.Write("Density of saturated liquid Propane at 101325 Pa: " + CoolProp.PropsSI("D", "P", 101325, "Q", 0, "REFPROP::Propane") + " kg/m^3" + "\n");
                Console.Write("TWO PHASE INPUTS (Temperature)" + "\n");
                Console.Write("Density of saturated liquid Propane at 300 K: " + CoolProp.PropsSI("D", "T", 300, "Q", 0, "REFPROP::Propane") + " kg/m^3" + "\n");
                Console.Write("SINGLE PHASE CYCLE (propane)" + "\n");
                p = CoolProp.PropsSI("P", "T", 300, "D", 1, "REFPROP::Propane");
                h = CoolProp.PropsSI("H", "T", 300, "D", 1, "REFPROP::Propane");
                Console.Write("T,D -> P,H " + 300 + "," + 1 + " --> " + p + "," + h + "\n");
                T = CoolProp.PropsSI("T", "P", p, "H", h, "REFPROP::Propane");
                D = CoolProp.PropsSI("D", "P", p, "H", h, "REFPROP::Propane");
                Console.Write("P,H -> T,D " + p + "," + h + " --> " + T + "," + D + "\n");
            }
            catch
            {
                Console.Write(" " + "\n");
                Console.Write("************ CANT USE REFPROP ************" + "\n");
                Console.Write(" " + "\n");
            }

            Console.Write(" " + "\n");
            Console.Write("************ BRINES AND SECONDARY WORKING FLUIDS *************" + "\n");
            Console.Write(" " + "\n");
            Console.Write("Density of 50% (mass) ethylene glycol/water at 300 K, 101325 Pa: " + CoolProp.PropsSI("D", "T", 300, "P", 101325, "EG-50%") + " kg/m^3" + "\n");
            Console.Write("Viscosity of Therminol D12 at 350 K, 101325 kPa: " + CoolProp.PropsSI("V", "T", 350, "P", 101325, "INCOMP::TD12") + " Pa-s" + "\n");

            Console.Write(" " + "\n");
            Console.Write("************ HUMID AIR PROPERTIES *************" + "\n");
            Console.Write(" " + "\n");
            //Console.Write("Humidity ratio of 50% rel. hum. air at 300 K, 101.325 kPa: " + CoolProp.HAProps("W", "T", 300, "P", 101.325, "R", 0.5) + " kg_w/kg_da" + "\n");
            //Console.Write("Relative humidity from last calculation: " + CoolProp.HAProps("R", "T", 300, "P", 101.325, "W", CoolProp.HAProps("W", "T", 300, "P", 101.325, "R", 0.5)) + "(fractional)" + "\n");

            //Console.Write("Enter to quit");
            //Console.ReadLine();
        }
예제 #5
0
 double ICoolProp.PropsSI(string Output, string Name1, double Prop1, string Name2, double Prop2, string FluidName)
 {
     return(CoolProp.PropsSI(Output, Name1, Prop1, Name2, Prop2, FluidName));
 }
예제 #6
0
        public void PlotPHChart(string fluidName)
        {
            MathOperation PH = new MathOperation();


            //===============Test ===================//

            //for (double y = 0.005; y < 40; y *= 2)
            //{

            //  double pressureVal= PH.IAPWS_IF97_TowParameterEquivalentFxn("P", "T", 483.15, "H", 400 * 1000,  fluidName); //--This multiply is done to convert MPa to Pa and enthlapy is divided to convert J/kg to kJ/Kg
            //    aListTemperature.Add(temperature);


            //}

            //================End of test=========//



            /*
             * Lets do it step by step as the way that has been done in the Matlab
             *
             */
            //--1. press_rng = logspace(-2,2,300); % [MPa] pressure (p) range

            // var stopWatch = System.Diagnostics.Stopwatch.StartNew();

            //double[] press_rng = PH.LogSpace(-2, 2, 300,true,10).ToArray();
            double[] press_rng = PH.LogSpace(-3, 2, 300, true, 10).ToArray();// initially it was form -2,2,300 //-4,4,300 is not supported by coolprop
            //--For line spacing values
            //2. temp_rng = 273.15+linspace(1,800,300);
            //double[] temp_rng =  PH.LinSpace(1, 800, 300, true).ToArray();

            //--Here -4,800,300 doesnot work error by cool prop 0 onwards on negative axis(eg.0,-1,-2,-3,...) does not work
            double[] temp_rng = PH.LinSpace(1, 800, 300, true).ToArray();// changed from 1,800,300


            for (int i = 0; i < temp_rng.Length; i++)
            {
                temp_rng[i] += 273.15;
            }


            //--Now for meshgrid we have created truple
            //MeshGrid_Class ms1 = new MeshGrid_Class();
            //3.[p,T] = meshgrid(press_rng,temp_rng); % [MPa,K] mesh p & T

            MeshGridClass.MeshGrid(press_rng, temp_rng);

            Tuple <double[, ], double[, ]> tuple_x = MeshGridClass.MeshGrid(press_rng, temp_rng);

            double[,] p = tuple_x.Item1;
            double[,] T = tuple_x.Item2;

            //--8 pcrit = 22.064; % [MPa] critical pressure
            double pcrit = CoolProp.Props1SI(fluidName, "Pcrit") / 1000000;//To convert to Pa form MPa //22.064;//CoolProp.Props1SI( "Water", "Pcrit");//PropsSI("Pcrit", "", 0, "", 0, "Water");//PH.IAPWS_IF97_TowParameterEquivalentFxn("Pcrit", "", 0, "",0, fluidName); //CoolProp.Props1SI(fluidName, "Pcrit");// CP.PropsSI("Tcrit","",0,"",0,"Water")

            //--Now lets do the calculation for others
            //4.h = IAPWS_IF97('h_pT',p,T); % [kJ/kg] enthalpy = f(p,T)
            P_Value = p; //Copy
            T_Value = T; //Copy


            double[,] h = new double[p.GetLength(0), p.GetLength(1)];

            for (int i = 0; i < h.GetLength(0); i++)
            {
                for (int j = 0; j < h.GetLength(1); j++)
                {
                    double enthalpy = PH.IAPWS_IF97_TowParameterEquivalentFxn("H", "P", p[i, j] * 1000000, "T", T[i, j], fluidName) / 1000; //--This multiply is done to convert MPa to Pa and enthlapy is divided to convert J/kg to kJ/Kg
                    h[i, j] = enthalpy;
                }
            }
            H_Value = h;//Copy

            //--5 psat = IAPWS_IF97('psat_T',temp_rng); % [MPa] saturation pressure
            // 6. also trimming is done in this section
            List <double> psatList = new List <double>();

            psatList.Clear();

            //--Finding boundary condition i.e maximun temperature range and minimum temperature range for different fluid
            //--eg. For Water min to max is 273.06K - 647.096K [in kelvin]


            double maxCriticalTemperature = 0;

            //--For critical CP.PropsSI("Tcrit","",0,"",0,"Water")
            maxCriticalTemperature = PH.IAPWS_IF97_TowParameterEquivalentFxn("Tcrit", "", 0, "Q", 0, fluidName);

            for (int i = 0; i < temp_rng.Length; i++)
            {
                if (((temp_rng[i] <= maxCriticalTemperature)))
                {
                    double psat = PH.IAPWS_IF97_TowParameterEquivalentFxn("P", "T", temp_rng[i], "Q", 0, fluidName) / 1000000;
                    psatList.Add(psat);
                } //Close of if statement
            }     //Close of for


            //-- 6. psat = psat(~isnan(psat));
            //--Use dynamic list to trim data which are empty rather than array

            //--6 . hLsat = IAPWS_IF97('hL_p',psat); % [kJ/kg] saturated liquid enthalpy
            List <double> hLsatList = new List <double>();

            hLsatList.Clear();

            foreach (var item in psatList)
            {
                double hLsat = PH.IAPWS_IF97_TowParameterEquivalentFxn("H", "P", item * 1000000, "Q", 0, fluidName) / 1000;//Q=0 for liquid
                hLsatList.Add(hLsat);
            }

            //--7 . hVsat = IAPWS_IF97('hV_p',psat); % [kJ/kg] saturated vapor enthalpy
            List <double> hVsatList = new List <double>();

            hVsatList.Clear();
            foreach (var item in psatList)
            {
                double hVsat = CoolProp.PropsSI("H", "P", item * 1000000, "Q", 1, fluidName) / 1000;      // PH.IAPWS_IF97_TowParameterEquivalentFxn("H", "P", item, "Q", 1.0, fluidName);//Zero for vapor
                hVsatList.Add(hVsat);
            }

            //--8. already declared

            //--9 hLcrit = IAPWS_IF97('hL_p',pcrit);
            double hLcrit = PH.IAPWS_IF97_TowParameterEquivalentFxn("H", "P", pcrit * 1000000, "Q", 0, fluidName) / 1000;//Zero for liquid

            //--10 . hVcrit = IAPWS_IF97('hV_p',pcrit);
            double hVcrit = PH.IAPWS_IF97_TowParameterEquivalentFxn("H", "P", pcrit * 1000000, "Q", 1, fluidName) / 1000;    //Zero for liquid
            //--11. Tcrit = IAPWS_IF97('Tsat_p',pcrit);
            double Tcrit = maxCriticalTemperature;                                                                           // CoolProp.PropsSI("Tcrit", "", 0, "", 0, "Water");//PH.IAPWS_IF97_TowParameterEquivalentFxn("Tcrit", "", 0, "", 0, fluidName);//CoolProp.Props1SI(fluidName, "Tcrit");
            //--12. hcrit = IAPWS_IF97('h_pT',pcrit,Tcrit);
            double hcrit = PH.IAPWS_IF97_TowParameterEquivalentFxn("H", "P", pcrit * 1000000, "T", Tcrit, fluidName) / 1000; //Zero for liquid
                                                                                                                             //--13.hVL = hVsat - hLsat; % [kJ/kg] heat of vaporization
            List <double> hVL_List = new List <double>();

            hVL_List.Clear();
            for (int i = 0; i < hVsatList.Count; i++)
            {
                double subtracted_value = hVsatList[i] - hLsatList[i];
                hVL_List.Add(subtracted_value);
            }

            //--14. hX = hLsat*ones(1,9) + hVL*(0.1:0.1:0.9); % [kJ/kg] mixture enthalpy

            double[,] hX = new double[hLsatList.Count, 9];
            double[,] hVL_LeftSideValue    = new double[hLsatList.Count, 9]; //stores hVL*(0.1:0.1:0.9);
            double[,] hLsat_RightSideValue = new double[hLsatList.Count, 9]; //stores hLsat*ones(1,9)

            double stepVal = 0.1;

            for (int i = 0; i < 9; i++)
            {
                for (int j = 0; j < hVL_List.Count; j++)
                {
                    hVL_LeftSideValue[j, i] = hVL_List[j] * stepVal;
                }
                stepVal += 0.1;
            }

            for (int i = 0; i < 9; i++)
            {
                for (int j = 0; j < hLsatList.Count; j++)
                {
                    hLsat_RightSideValue[j, i] = hLsatList[j];
                }
            }

            //For final sum
            for (int i = 0; i < 9; i++)
            {
                for (int j = 0; j < hLsatList.Count; j++)
                {
                    hX[j, i] = hLsat_RightSideValue[j, i] + hVL_LeftSideValue[j, i];//  hLsatList[j].Value;
                }
            }

            //--Now lets move to plotting the things
            //Conture plot and

            /*
             * For this function plot
             * plot([hLsat;hLcrit],[psat;pcrit],'b', ...
             *      [hVsat;hVcrit],[psat;pcrit],'r', ...
             *      hcrit,pcrit,'o', ...
             *      hX,psat*ones(1,9),'g') % vapor dome
             */

            phChart.Series.Clear();
            phChart.ChartAreas[0].AxisX.Minimum  = 1 / 1000; //--This was 1/1000
            phChart.ChartAreas[0].AxisX.Maximum  = 4000;     //4000;
            phChart.ChartAreas[0].AxisX.Interval = 500;

            phChart.ChartAreas[0].AxisY.Minimum       = 0.01; //--This was 0.001
            phChart.ChartAreas[0].AxisY.IsLogarithmic = true;
            phChart.ChartAreas[0].AxisY.LogarithmBase = 10;
            phChart.ChartAreas[0].AxisY.Interval      = 1;
            // phChart.ChartAreas[0].AxisY.Maximum = 50;

            //--this one is for [hLsat;hLcrit],[psat;pcrit],'b', ...
            // ph_chart.ChartAreas[0].AxisX.Minimum =

            phChart.Series.Clear();

            phChart.Series.Add("Series01");
            phChart.Series["Series01"].ChartType = SeriesChartType.Line;
            for (int i = 0; i < hLsatList.Count; i++)
            {
                phChart.Series["Series01"].Points.AddXY(hLsatList[i], psatList[i]);
            }
            phChart.Series["Series01"].Points.AddXY(hLcrit, pcrit);
            phChart.Series["Series01"].Color = Color.Blue;
            phChart.Series["Series01"].Font  = new Font(FontFamily.GenericSansSerif, 8, FontStyle.Bold);
            //phChart.Series["Series01"].Font.

            // /*
            phChart.Series["Series01"].Points[12].Label = "S";
            phChart.Series["Series01"].Points[15].Label = "a";
            phChart.Series["Series01"].Points[18].Label = "t";
            phChart.Series["Series01"].Points[21].Label = "u";
            phChart.Series["Series01"].Points[24].Label = "r";
            phChart.Series["Series01"].Points[27].Label = "a";
            phChart.Series["Series01"].Points[30].Label = "t";
            phChart.Series["Series01"].Points[33].Label = "i";
            phChart.Series["Series01"].Points[36].Label = "o";
            phChart.Series["Series01"].Points[40].Label = "n";

            phChart.Series["Series01"].Points[50].Label = "L";
            phChart.Series["Series01"].Points[55].Label = "i";
            phChart.Series["Series01"].Points[63].Label = "q";
            phChart.Series["Series01"].Points[69].Label = "u";
            phChart.Series["Series01"].Points[75].Label = "i";
            phChart.Series["Series01"].Points[80].Label = "d";

            // */


            phChart.Series["Series01"].ChartArea = "ChartArea1";

            //This one if for  [hVsat;hVcrit],[psat;pcrit],'r', ...
            phChart.Series.Add("Series2");
            phChart.Series["Series2"].ChartType = SeriesChartType.Line;
            for (int i = 0; i < hVsatList.Count; i++)
            {
                phChart.Series["Series2"].Points.AddXY(hVsatList[i], psatList[i]);
            }
            phChart.Series["Series2"].Points.AddXY(hVcrit, pcrit);
            phChart.Series["Series2"].Color = Color.Red;
            //Chart1.Series(0).Font = New Font(Me.Font.Name, 5, FontStyle.Regular)
            phChart.Series["Series2"].Font = new Font(FontFamily.GenericSansSerif, 8, FontStyle.Bold);
            // phChart.Series["Series2"].Points[12].Label = $"Saturation Vapour";

            // /*
            phChart.Series["Series2"].Points[12].Label = "S";
            phChart.Series["Series2"].Points[15].Label = "a";
            phChart.Series["Series2"].Points[18].Label = "t";
            phChart.Series["Series2"].Points[21].Label = "u";
            phChart.Series["Series2"].Points[24].Label = "r";
            phChart.Series["Series2"].Points[27].Label = "a";
            phChart.Series["Series2"].Points[31].Label = "t";
            phChart.Series["Series2"].Points[35].Label = "i";
            phChart.Series["Series2"].Points[39].Label = "o";
            phChart.Series["Series2"].Points[44].Label = "n";

            phChart.Series["Series2"].Points[50].Label = "V";
            phChart.Series["Series2"].Points[55].Label = "a";
            phChart.Series["Series2"].Points[60].Label = "p";
            phChart.Series["Series2"].Points[67].Label = "o";
            phChart.Series["Series2"].Points[74].Label = "u";
            phChart.Series["Series2"].Points[80].Label = "r";
            // */

            phChart.Series["Series2"].ChartArea = "ChartArea1";

            //--For critical point
            //This one if for  hcrit,pcrit,'o', ...
            phChart.Series.Add("Series3");
            phChart.Series["Series3"].ChartType = SeriesChartType.Point;

            phChart.Series["Series3"].Points.AddXY(hcrit, pcrit);
            phChart.Series["Series3"].Color     = Color.Orange;
            phChart.Series["Series3"].ChartArea = "ChartArea1";

            //--This one is the last one
            double[,] psatOneToNine = new double[psatList.Count, 9];
            for (int i = 0; i < 9; i++)
            {
                for (int j = 0; j < psatList.Count; j++)
                {
                    psatOneToNine[j, i] = psatList[j];
                }
            }

            for (int i = 0; i < hX.GetLength(1); i++)//Row
            {
                phChart.Series.Add("Series4" + i);
                phChart.Series["Series4" + i].ChartType = SeriesChartType.Line;



                for (int j = 0; j < hX.GetLength(0); j++)//Column
                {
                    phChart.Series["Series4" + i].Points.AddXY(hX[j, i], psatOneToNine[j, i]);
                }

                phChart.Series["Series4" + i].Color            = Color.Green;
                phChart.Series["Series4" + i].Points[12].Label = $"{(i + 1) * 10} %";//initially no. 12
                phChart.Series["Series4" + i].Font             = new Font(FontFamily.GenericSansSerif, 8, FontStyle.Bold);

                phChart.Series["Series4" + i].ChartArea = "ChartArea1";
            }

            //---Contour line plotting chunk of code -----------//

            /*
             * Steps :
             * 1. number of contour
             * 2. series decleration
             * 3. ds the data setting for Jack xu book[data is already calculated so]
             * 4. calling the plot function in Jack xu code
             */

            int       numberOfContour = 25;
            ArrayList alSeries        = new ArrayList();

            for (int i = 0; i < numberOfContour; i++)
            {
                string name = "ContourSeries" + i;
                alSeries.Add(name);
            }

            ChartFunctions cf = new ChartFunctions();
            DataSeries     ds = new DataSeries();
            Form1_jack_xu  f1 = new Form1_jack_xu();
            DrawChart      dc = new DrawChart(f1);

            cf.SetDataPoints(ds, P_Value, T_Value, H_Value);
            //==After calling this we need to call the number of contour plots

            /* numberContours values =
             * 28 gives 20 lines,
             * 30 gives 20 lines,
             * 25 gives 17 lines
             * 35 gives 25 lines [max limit]
             * 20 gives 14 lines
             * 27 gives 19 lines
             * 13 gives 8 lines
             */
            dc.numberContours = 35;

            List <DrawChart.DataTypeForPointList> listPoints = new List <DrawChart.DataTypeForPointList>();

            listPoints = dc.AddContour_MyCustomFxn(ds);

            //-------------For indicator of Temperature---------//

            string seriesName1 = "TemperaturePoints";

            phChart.Series.Add(seriesName1);
            phChart.Series[seriesName1].ChartType = SeriesChartType.Point;
            int    ind = 0;
            int    flagSingleTemperatureIndicator = 1;//on first
            double zlevelValueForTempIndicator    = 0;
            int    dataPointCounter = 0;
            // int enthalpyValueForIndiator = 2000;

            //---------------End of indicator of temperature---//



            //--Serching z-levels and plotting
            int initialZ    = listPoints[0].zlevel;
            int initalIndex = 0;
            int runningz    = 0;

            for (int i = 0; i < numberOfContour; i++)
            {
                //==First one is for moving in the list
                string seriesName = alSeries[i].ToString();
                Series s1         = new Series(seriesName);
                //s1.MarkerSize = 15;//--This does not work so
                s1.ChartType = SeriesChartType.Line;
                phChart.Series.Add(s1);
                //phChart.Series.Add(seriesName);
                //phChart.Series[seriesName].ChartType = SeriesChartType.Line;
                //phChart.Series[seriesName].MarkerSize = 60;
                //==For moving in the list
                for (int z = initalIndex; z < listPoints.Count; z++)
                {
                    runningz = z;



                    if (initialZ == listPoints[z].zlevel)
                    {
                        //==Same zlevel then draw on one line
                        phChart.Series[seriesName].Points.AddXY(listPoints[z].x1, listPoints[z].y1);
                        phChart.Series[seriesName].Points.AddXY(listPoints[z].x2, listPoints[z].y2);

                        dataPointCounter++;


                        // /*
                        //===========Temperature indicator================//
                        if (flagSingleTemperatureIndicator == 1 && dataPointCounter > (listPoints[z].zlevel) && (listPoints[z].x1 > 200 && listPoints[z].x1 < 2500))     //(flagSingleTemperatureIndicator == 1 && zlevelValueForTempIndicator == listPoints[z].zlevel) //(listPoints[z].x1 == 2000)
                        {
                            double temperature = PH.IAPWS_IF97_TowParameterEquivalentFxn("T", "H", listPoints[z].x1 * 1000, "P", listPoints[z].y1 * 1000000, fluidName); //--This multiply is done to convert MPa to Pa and enthlapy is divided to convert J/kg to kJ/Kg
                            phChart.Series[seriesName1].Points.AddXY(listPoints[z].x1, listPoints[z].y1);
                            phChart.Series[seriesName1].Points[ind++].Label = $"{Math.Round(temperature - 273.15, 0)}°C";
                            flagSingleTemperatureIndicator = 0;//off

                            dataPointCounter = 0;
                        }

                        if (listPoints[z].zlevel > zlevelValueForTempIndicator)
                        {
                            flagSingleTemperatureIndicator = 1;//on
                            ////zlevelValueForTempIndicator = listPoints[z].zlevel;
                        }
                        zlevelValueForTempIndicator = listPoints[z].zlevel;
                        //===========Temper indiactor end==============//
                        // */
                    }
                    else
                    {
                        initialZ    = listPoints[z].zlevel;
                        initalIndex = z;

                        //flagSingleTemperatureIndicator = 1;//on
                        break;
                    }
                }

                if (runningz == listPoints.Count)
                {
                    break;
                }
            }

            //stopWatch.Stop();
            //MessageBox.Show($"Elapsed millisecond = { stopWatch.ElapsedMilliseconds} ms");

            //---End of the contour line plot chunk of code---//
            ArrayList aListTemperature = new ArrayList();
            //string seriesName1 = "TemperaturePoints";
            //phChart.Series.Add(seriesName1);
            //phChart.Series[seriesName1].ChartType = SeriesChartType.Point;
            //int ind = 0;

            //for (double y = 0.005; y < 40; y *= 2)
            //{
            //    double temperature = PH.IAPWS_IF97_TowParameterEquivalentFxn("T", "H", 400 * 1000, "P", y * 1000000, fluidName); //--This multiply is done to convert MPa to Pa and enthlapy is divided to convert J/kg to kJ/Kg
            //    aListTemperature.Add(temperature);
            //    phChart.Series[seriesName1].Points.AddXY(400, y);
            //    phChart.Series[seriesName1].Points[ind++].Label = $"{Math.Round(temperature - 273.15, 2)} DegC";
            //}

            //=================================This part is for regregration cycle=====================//
            ///*
            //--We need to convert temp to kelvine
            double T1 = 106 + 273.15; //Deg C+273.15 = kelving temperature ==>TEMPERATURE // changed from 10
            double P1 = 0.05;         //MPa ==>Y-Axis[Pressure] //changed form 0.05mpa
            double T2 = 200 + 273.15;
            double P2 = 2;            //MPa //changed form 1 MPa
            double T3 = 200 + 273.15;
            double P3 = P2;
            double T4 = T1;
            double P4 = P1;

            //--Lets calculate enthalpy
            //double enthalpy1 = PH.IAPWS_IF97_TowParameterEquivalentFxn("H", "P", P1 * 1000000, "T", T1, fluidName) / 1000;
            //double enthalpy2 = PH.IAPWS_IF97_TowParameterEquivalentFxn("H", "P", P2 * 1000000, "T", T2, fluidName) / 1000;
            //double enthalpy3 = PH.IAPWS_IF97_TowParameterEquivalentFxn("H", "P", P3 * 1000000, "T", T3, fluidName) / 1000;
            //double enthalpy4 = PH.IAPWS_IF97_TowParameterEquivalentFxn("H", "P", P4 * 1000000, "T", T4, fluidName) / 1000;

            double enthalpy1 = 2650;
            double enthalpy2 = 2900;
            double enthalpy3 = 900;
            double enthalpy4 = 900;


            // MessageBox.Show($"Different enthalpy values en1[same input as en4]= {enthalpy1} , en2 = {enthalpy2},en3 = {enthalpy3} , en4  ={enthalpy4}");
            string sName1 = "RefregrationCyclePoints";

            phChart.Series.Add(sName1);
            phChart.Series[sName1].ChartType   = SeriesChartType.Point;
            phChart.Series[sName1].MarkerStyle = MarkerStyle.Circle;
            phChart.Series[sName1].MarkerSize  = 8;

            phChart.Series[sName1].Points.AddXY(enthalpy1, P1);
            phChart.Series[sName1].Points.AddXY(enthalpy2, P2);
            phChart.Series[sName1].Points.AddXY(enthalpy3, P3);
            phChart.Series[sName1].Points.AddXY(enthalpy4, P4);

            string lineCycle1 = "LineRefCycle1";

            phChart.Series.Add(lineCycle1);
            phChart.Series[lineCycle1].ChartType = SeriesChartType.Line;

            phChart.Series[lineCycle1].BorderWidth = 5;
            phChart.Series[lineCycle1].MarkerStyle = MarkerStyle.Circle;
            phChart.Series[lineCycle1].MarkerSize  = 5;
            phChart.Series[lineCycle1].Color       = Color.Green;
            phChart.Series[lineCycle1].Points.AddXY(enthalpy1, P1);
            phChart.Series[lineCycle1].Points.AddXY((enthalpy1 + enthalpy2) / 2, 0.3);//1.2 is pressure it is manually given as scale is in log
            phChart.Series[lineCycle1].Points.AddXY(enthalpy2, P2);
            phChart.Series[lineCycle1].Points[1].Label = "Compression";


            string lineCycle2 = "LineRefCycle2";

            phChart.Series.Add(lineCycle2);
            phChart.Series[lineCycle2].ChartType   = SeriesChartType.Line;
            phChart.Series[lineCycle2].MarkerStyle = MarkerStyle.Circle;

            phChart.Series[lineCycle2].BorderWidth = 5;
            phChart.Series[lineCycle2].MarkerSize  = 5;
            phChart.Series[lineCycle2].Color       = Color.Green;
            phChart.Series[lineCycle2].Points.AddXY(enthalpy2, P2);
            phChart.Series[lineCycle2].Points.AddXY((enthalpy2 + enthalpy3) / 2, (P2 + P3) / 2);
            phChart.Series[lineCycle2].Points.AddXY(enthalpy3, P3);
            phChart.Series[lineCycle2].Points[1].Label = "Condensor";

            string lineCycle3 = "LineRefCycle3";

            phChart.Series.Add(lineCycle3);
            phChart.Series[lineCycle3].ChartType   = SeriesChartType.Line;
            phChart.Series[lineCycle3].MarkerStyle = MarkerStyle.Circle;

            phChart.Series[lineCycle3].BorderWidth = 5;
            phChart.Series[lineCycle3].MarkerSize  = 5;
            phChart.Series[lineCycle3].Color       = Color.Green;
            phChart.Series[lineCycle3].Points.AddXY(enthalpy3, P3);
            phChart.Series[lineCycle3].Points.AddXY((enthalpy3 + enthalpy4) / 2, 0.3);//0.3 is a pressure ie 0.3mpa
            phChart.Series[lineCycle3].Points.AddXY(enthalpy4, P4);
            phChart.Series[lineCycle3].Points[1].Label = "Expansion Valve";


            string lineCycle4 = "LineRefCycle4";

            phChart.Series.Add(lineCycle4);
            phChart.Series[lineCycle4].ChartType   = SeriesChartType.Line;
            phChart.Series[lineCycle4].MarkerStyle = MarkerStyle.Circle;

            phChart.Series[lineCycle4].BorderWidth = 5;
            phChart.Series[lineCycle4].MarkerSize  = 5;
            phChart.Series[lineCycle4].Color       = Color.Green;
            phChart.Series[lineCycle4].Points.AddXY(enthalpy4, P4);
            phChart.Series[lineCycle4].Points.AddXY((enthalpy4 + enthalpy1) / 2, (P4 + P1) / 2);
            phChart.Series[lineCycle4].Points.AddXY(enthalpy1, P1);
            phChart.Series[lineCycle4].Points[1].Label = "Evaporator";

            // */
            //=================================End regregration cycle=====================//
        }
예제 #7
0
파일: Slab.cs 프로젝트: birdol/LinglanCoil
        public static CalcResult SlabCalc(int[,] CirArrange, CircuitNumber CircuitInfo, int Nrow, int[] Ntube, int Nelement, string fluid, //double Npass, int[] N_tubes_pass,
                                          double l, Geometry geo, double[, ,] ta, double[, ,] RH,
                                          double te, double pe, double hri, double mr, double[,] ma, double[,] ha, double[,] haw,
                                          double eta_surface, double zh, double zdp, int hexType, double thickness, double conductivity, double Pwater, string Airdirection, CapiliaryInput cap_inlet, CapiliaryInput cap_outlet, AbstractState coolprop, double[,] SourceTableData)

        {
            //------->
            // R2   R1

            // [11   1] <====
            // [12   2] <====
            //          <==== Air
            // [13   3] <====
            // [14   4] <====
            // [15   5]  <====
            // [16   6] <====
            // [17   7] <====
            // [18   8]  <====
            // [19   9] <====
            // [20  10] <====

            //  Ncir=1, 11in, 20->10 1out


            // [19 - 17 - 15 - 13   11   9   7   5   3   1] <====Air
            // [20 - 18 - 16 - 14   12   10  8   6   4   2] <====Air
            //  Ncir=1, 20in, 20->19 1out

            // CirArrange = new int[,] { { 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1 } };
            // Nrow=2
            // Ncir=2
            //AbstractState coolprop = AbstractState.factory("HEOS", fluid);

            double[] Q1    = new double[50];
            double   tri   = te; //Refrigerant.SATP(fluid, composition, pri, 1).Temperature - 273.15;
            double   pri   = pe;
            int      Nciri = CircuitInfo.number[0];
            int      Nciro = CircuitInfo.number[1];
            int      Ncir  = (Nciri == Nciro ? Nciri : Nciri + Nciro);

            int    N_tube       = Ntube[0];
            int    N_tube_total = 0;
            int    iRow         = 0;
            int    iTube_o      = 0;
            int    iTube_n      = 0;
            int    index_o      = 0;
            int    index_n      = 0;
            double te_calc_org  = 0;

            CirArr[]     cirArr       = new CirArr[Nrow * N_tube];
            CirArrforAir cirArrforAir = new CirArrforAir();

            cirArrforAir = CirArrangement.ReadCirArr(CirArrange, CircuitInfo, Nrow, Ntube, 0);
            cirArr       = cirArrforAir.CirArr;

            CalcResult res_slab = new CalcResult();

            double[]        pri_cir      = new double[Ncir]; //[element, tube, row]
            double[]        hri_cir      = new double[Ncir];
            double[]        tri_cir      = new double[Ncir];
            double[]        mr_ciri      = new double[Nciri];
            List <double[]> mr_ciri_base = new List <double[]>();

            double[] mr_ciro         = new double[Nciro];
            int[]    Ngroupin        = new int[Nciro];
            int      index           = 0;
            int      restartDP_index = 0;
            int      N_tube2         = 0;

            int[] index_cir          = new int[Ncir];
            int   index_mr_ciri_base = 0;

            CalcResult[] r        = new CalcResult[Ncir];
            CalcResult[] r1       = new CalcResult[Ncir];
            CalcResult[] r2       = new CalcResult[Ncir]; //for NinMout only
            CalcResult[] res_cir2 = new CalcResult[Nciro + 1];
            CalcResult[] res_type = new CalcResult[Nciri + 1];

            double[,] Q_detail      = new double[N_tube, Nrow];//detail output
            double[,] DP_detail     = new double[N_tube, Nrow];
            double[,] Tri_detail    = new double[N_tube, Nrow];
            double[,] Pri_detail    = new double[N_tube, Nrow];
            double[,] hri_detail    = new double[N_tube, Nrow];
            double[,] Tro_detail    = new double[N_tube, Nrow];
            double[,] Pro_detail    = new double[N_tube, Nrow];
            double[,] hro_detail    = new double[N_tube, Nrow];
            double[,] href_detail   = new double[N_tube, Nrow];
            double[,] mr_detail     = new double[N_tube, Nrow];
            double[,] charge_detail = new double[N_tube, Nrow];

            int flag_ciro  = 0;
            int Ncir_forDP = 0;

            double[] mr_forDP = new double[Nciri];
            int      k;
            double   te_calc = 0;

            CheckAir airConverge = new CheckAir();
            CheckDP  dPconverge  = new CheckDP();
            CheckPri priconverge = new CheckPri();

            for (int i = 0; i < Nrow; i++)
            {
                N_tube_total += Ntube[i];
            }
            for (int i = 0; i < Nciro; i++)
            {
                mr_ciro[i] = mr / Nciro;
            }

            bool index_outbig;

            if (CircuitInfo.UnequalCir == null || CircuitInfo.UnequalCir[0] > 0)
            {
                index_outbig = false;
            }
            else
            {
                index_outbig = true;
            }

            if (CircuitInfo.UnequalCir != null)
            {
                for (int j = 0; j < Nciro; j++)
                {
                    for (int i = 0; i < Ncir; i++)
                    {
                        if (CircuitInfo.UnequalCir[i] == Nciri + 1 + j)
                        {
                            Ngroupin[j]++;
                        }
                    }
                    //for (int i = 0; i < Nciri; i++) mr_ciri[i] = mr_ciro[j] / Ngroupin[j];
                }
            }
            int    iterforAir = 0;
            int    iterforDP  = 0;
            int    iterforPri = 0;
            double pri_1      = 0;
            double pri_2      = 0;
            double pri_3      = 0;
            double pri_4      = 0;

            double tri1 = 0;
            double te1  = 0;

            double iterforDP_ciri = 0;
            double iterforDP_ciro = 0;

            //Starting properties
            iterforDP_ciro = 0;
            double[] mr_forDP_o_4 = new double[Nciri];
            double[] mr_forDP_o_3 = new double[Nciri];
            double[] mr_forDP_o_2 = new double[Nciri];
            double[] mr_forDP_o_1 = new double[Nciri];
            do
            {
                #region //AirConverge
                do
                {
                    //iterforDP = 0;
                    r        = new CalcResult[Ncir];
                    r1       = new CalcResult[Ncir];
                    res_cir2 = new CalcResult[Nciro + 1];


                    flag_ciro = (index_outbig ? 1 : 0);
                    //tri = tri;
                    //制冷制热模块计算切换
                    if (hexType == 0)
                    {
                        coolprop.update(input_pairs.PQ_INPUTS, pri * 1000, 0);
                        tri = coolprop.T() - 273.15;
                        tri = CoolProp.PropsSI("T", "P", pri * 1000, "Q", 0, fluid) - 273.15;
                        int a = 1;
                    }
                    else
                    {
                        coolprop.update(input_pairs.PQ_INPUTS, pri * 1000, 0);
                        te = coolprop.T() - 273.15;
                        te = CoolProp.PropsSI("T", "P", pri * 1000, "Q", 0, fluid) - 273.15;
                        int a = 1;
                    }

                    for (int j = 0; j < (flag_ciro == 1 ? (index_outbig ? Nciri + 1 : 1) : Nciro + 1); j++)
                    {
                        if (j >= Nciro)
                        {
                            j         = j - Nciro; //for Nciro
                            flag_ciro = (index_outbig ? 0 : 1);
                        }
                        if (j == 1 && index_outbig && index == 0)
                        {
                            j         = j - 1;
                            flag_ciro = 0;
                        }

                        index          = 0;
                        iterforDP_ciri = 0;
                        double[] mr_forDP_4 = new double[Nciri];
                        double[] mr_forDP_3 = new double[Nciri];
                        double[] mr_forDP_2 = new double[Nciri];
                        double[] mr_forDP_1 = new double[Nciri];

                        double [] mr0_forDP = new double[5];
                        #region //DPConverge
                        do
                        {
                            res_type = new CalcResult[Nciri + 1];
                            k        = 0;
                            if (!index_outbig)
                            {
                                for (int i = 0; i < (flag_ciro == 1 ? Nciro : (Nciri == Nciro ? Ncir : Ncir - Nciro)); i++)
                                {
                                    if (flag_ciro == 1)
                                    {
                                        pri_cir[i + Ncir - Nciro] = res_cir2[i].Pro;
                                        hri_cir[i + Ncir - Nciro] = res_cir2[i].hro;
                                        tri_cir[i + Ncir - Nciro] = res_cir2[i].Tro;
                                    }
                                    else
                                    {
                                        pri_cir[i] = pri;
                                        hri_cir[i] = hri;
                                        tri_cir[i] = tri;
                                    }
                                }
                            }
                            else
                            {
                                for (int i = 0; i < (flag_ciro == 1 ? Nciro : Ncir); i++)
                                {
                                    if (flag_ciro == 1)
                                    {
                                        pri_cir[i] = pri;
                                        hri_cir[i] = hri;
                                        tri_cir[i] = tri;
                                    }
                                    else
                                    {
                                        if (CircuitInfo.UnequalCir[i] == Nciri + 1 + j)
                                        {
                                            pri_cir[i] = r2[j].Pro;
                                            hri_cir[i] = r2[j].hro;
                                            tri_cir[i] = r2[j].Tro;
                                        }
                                    }
                                }
                            }
                            for (int i = 0; i < Ncir; i++)
                            {
                                if (flag_ciro == 1)
                                {
                                    //汇管计算
                                    if (CircuitInfo.UnequalCir[i] <= 0)
                                    {
                                        //for (int i = 0; i < Ncir; i++)

                                        //r[i] = Circuit.CircuitCalc(i, cirArr, CircuitInfo, Nrow, Ntube, Nelement, fluid, dh, l, geo.element, ta, RH,
                                        //   tri_cir[i], pri_cir[i], hri_cir[i], mr_ciro[k], ma, ha, haw, eta_surface, zh, zdp, hexType, thickness, conductivity, Pwater, Airdirection, d_cap, lenth_cap);

                                        r[i] = Circuit.CircuitCalc(i, cirArr, CircuitInfo, Nrow, Ntube, Nelement, fluid, l, geo, ta, RH,
                                                                   tri_cir[i], pri_cir[i], hri_cir[i], mr_ciro[k], ma, ha, haw, eta_surface, zh, zdp, hexType, thickness, conductivity, Pwater, cap_inlet, cap_outlet, coolprop, SourceTableData);

                                        if (r[i].Pro < 0)
                                        {
                                            res_slab.Pro = -10000000; return(res_slab);
                                        }
                                        r1[k] = r[i].ShallowCopy();
                                        r2[k] = r[i].ShallowCopy();
                                        if (!index_outbig)
                                        {
                                            r1[k].DP += res_cir2[k].DP;
                                        }

                                        index_cir[k] = i;
                                        k++;
                                        Ncir_forDP = Nciro;
                                        mr_forDP   = (double[])mr_ciro.Clone(); // mr_forDP = mr_ciro
                                        if (k == Nciro)
                                        {
                                            break;
                                        }
                                    }
                                }
                                else if (Nciri == Nciro || CircuitInfo.UnequalCir[i] == Nciri + 1 + j)
                                {
                                    //均匀流路计算和不均匀流路开始部分(独立管)计算
                                    if (index == 0)
                                    {
                                        if (Nciri == Nciro && iterforPri == 0)
                                        {
                                            mr_ciro.CopyTo(mr_ciri, 0);
                                        }
                                        else if (Nciri != Nciro)
                                        {
                                            if (restartDP_index == 1 || !priconverge.flag)
                                            {
                                                var mm = mr_ciri_base[j].Sum();
                                                //foreach (var item in mr_ciri_base[j])
                                                //mm += item;
                                                mr_ciri[k] = mr_ciri_base[j][k] * mr_ciro[j] / mm;//(mr / Nciro);
                                            }
                                            else
                                            {
                                                mr_ciri[k] = mr_ciro[j] / Ngroupin[j];
                                            }
                                        }
                                    }
                                    //else mr_ciri_base.CopyTo(mr_ciri[k], 0);

                                    //for (int i = 0; i < Ncir; i++)

                                    //首次流路计算
                                    if (CircuitInfo.CirType != null && CircuitInfo.CirType.flag == true)
                                    {
                                        bool circuit_cap = false;
                                        //if (d_cap[index] == 0 && lenth_cap[index] == 0) circuit_cap = true;
                                        if ((CircuitInfo.CirType.flag == true) && (CircuitInfo.CirType.type[i, 0] == 0) && (res_type[CircuitInfo.CirType.type[i, 1]] != null && circuit_cap))
                                        {
                                            //r[i] = res_type[CircuitInfo.CirType.type[i, 1]];
                                            r[i]               = new CalcResult();
                                            r[i].DP            = res_type[CircuitInfo.CirType.type[i, 1]].DP;
                                            r[i].DP_cap        = res_type[CircuitInfo.CirType.type[i, 1]].DP_cap;
                                            r[i].href          = res_type[CircuitInfo.CirType.type[i, 1]].href;
                                            r[i].hro           = res_type[CircuitInfo.CirType.type[i, 1]].hro;
                                            r[i].M             = res_type[CircuitInfo.CirType.type[i, 1]].M;
                                            r[i].Pro           = res_type[CircuitInfo.CirType.type[i, 1]].Pro;
                                            r[i].Q             = res_type[CircuitInfo.CirType.type[i, 1]].Q;
                                            r[i].R_1           = res_type[CircuitInfo.CirType.type[i, 1]].R_1;
                                            r[i].R_1a          = res_type[CircuitInfo.CirType.type[i, 1]].R_1a;
                                            r[i].R_1r          = res_type[CircuitInfo.CirType.type[i, 1]].R_1r;
                                            r[i].Ra_ratio      = res_type[CircuitInfo.CirType.type[i, 1]].Ra_ratio;
                                            r[i].RHout         = res_type[CircuitInfo.CirType.type[i, 1]].RHout;
                                            r[i].Tao           = res_type[CircuitInfo.CirType.type[i, 1]].Tao;
                                            r[i].Tri           = res_type[CircuitInfo.CirType.type[i, 1]].Tri;
                                            r[i].Tro           = res_type[CircuitInfo.CirType.type[i, 1]].Tro;
                                            r[i].x_i           = res_type[CircuitInfo.CirType.type[i, 1]].x_i;
                                            r[i].x_o           = res_type[CircuitInfo.CirType.type[i, 1]].x_o;
                                            r[i].Vel_r         = res_type[CircuitInfo.CirType.type[i, 1]].Vel_r;
                                            r[i].mr            = res_type[CircuitInfo.CirType.type[i, 1]].mr;
                                            r[i].Q_detail      = new double[N_tube, Nrow];//
                                            r[i].DP_detail     = new double[N_tube, Nrow];
                                            r[i].Tri_detail    = new double[N_tube, Nrow];
                                            r[i].Pri_detail    = new double[N_tube, Nrow];
                                            r[i].hri_detail    = new double[N_tube, Nrow];
                                            r[i].Tro_detail    = new double[N_tube, Nrow];
                                            r[i].Pro_detail    = new double[N_tube, Nrow];
                                            r[i].hro_detail    = new double[N_tube, Nrow];
                                            r[i].href_detail   = new double[N_tube, Nrow];
                                            r[i].mr_detail     = new double[N_tube, Nrow];
                                            r[i].Tao_Detail    = new double[Nelement, N_tube, Nrow];
                                            r[i].RHo_Detail    = new double[Nelement, N_tube, Nrow];
                                            r[i].charge_detail = new double[N_tube, Nrow];
                                            for (int m = 0; m < CircuitInfo.TubeofCir[i]; m++)
                                            {
                                                index_o = 0;
                                                index_n = 0;
                                                if (i == 0)
                                                {
                                                    index_n = 0;
                                                }
                                                else
                                                {
                                                    for (int n = 1; n <= i; n++)
                                                    {
                                                        index_n += CircuitInfo.TubeofCir[n - 1];
                                                    }
                                                }
                                                if (res_type[CircuitInfo.CirType.type[i, 1]].index == 0)
                                                {
                                                    index_o = 0;
                                                }
                                                else
                                                {
                                                    for (int n = 1; n <= res_type[CircuitInfo.CirType.type[i, 1]].index; n++)
                                                    {
                                                        index_o += CircuitInfo.TubeofCir[n - 1];
                                                    }
                                                }
                                                iRow    = cirArr[m + index_o].iRow;
                                                iTube_o = cirArr[m + index_o].iTube;
                                                iTube_n = cirArr[m + index_n].iTube;
                                                r[i].Q_detail[iTube_n, iRow]      = res_type[CircuitInfo.CirType.type[i, 1]].Q_detail[iTube_o, iRow];//
                                                r[i].DP_detail[iTube_n, iRow]     = res_type[CircuitInfo.CirType.type[i, 1]].DP_detail[iTube_o, iRow];
                                                r[i].Tri_detail[iTube_n, iRow]    = res_type[CircuitInfo.CirType.type[i, 1]].Tri_detail[iTube_o, iRow];
                                                r[i].Pri_detail[iTube_n, iRow]    = res_type[CircuitInfo.CirType.type[i, 1]].Pri_detail[iTube_o, iRow];
                                                r[i].hri_detail[iTube_n, iRow]    = res_type[CircuitInfo.CirType.type[i, 1]].hri_detail[iTube_o, iRow];
                                                r[i].Tro_detail[iTube_n, iRow]    = res_type[CircuitInfo.CirType.type[i, 1]].Tro_detail[iTube_o, iRow];
                                                r[i].Pro_detail[iTube_n, iRow]    = res_type[CircuitInfo.CirType.type[i, 1]].Pro_detail[iTube_o, iRow];
                                                r[i].hro_detail[iTube_n, iRow]    = res_type[CircuitInfo.CirType.type[i, 1]].hro_detail[iTube_o, iRow];
                                                r[i].href_detail[iTube_n, iRow]   = res_type[CircuitInfo.CirType.type[i, 1]].href_detail[iTube_o, iRow];
                                                r[i].mr_detail[iTube_n, iRow]     = res_type[CircuitInfo.CirType.type[i, 1]].mr_detail[iTube_o, iRow];
                                                r[i].charge_detail[iTube_n, iRow] = res_type[CircuitInfo.CirType.type[i, 1]].charge_detail[iTube_o, iRow];

                                                for (int p = 0; p < Nelement; p++)
                                                {
                                                    //ta[p, iTube_n, iRow + 1] = res_type[CircuitInfo.CirType.type[i, 1]].Tao_Detail[p, iTube_o, iRow];
                                                    //RH[p, iTube_n, iRow + 1] = res_type[CircuitInfo.CirType.type[i, 1]].RHo_Detail[p, iTube_o, iRow];
                                                    r[i].Tao_Detail[p, iTube_n, iRow] = res_type[CircuitInfo.CirType.type[i, 1]].Tao_Detail[p, iTube_o, iRow];
                                                    r[i].RHo_Detail[p, iTube_n, iRow] = res_type[CircuitInfo.CirType.type[i, 1]].RHo_Detail[p, iTube_o, iRow];
                                                }
                                            }
                                            //r[i].Tao_Detail = ta;
                                            //r[i].RHo_Detail = RH;
                                        }
                                        else
                                        {
                                            //r[i] = Circuit.CircuitCalc(i, cirArr, CircuitInfo, Nrow, Ntube, Nelement, fluid, dh, l, geo.element, ta, RH,
                                            //tri_cir[i], pri_cir[i], hri_cir[i], mr_ciri[k], ma, ha, haw, eta_surface, zh, zdp, hexType, thickness, conductivity, Pwater, Airdirection, d_cap, lenth_cap);

                                            r[i] = Circuit.CircuitCalc(i, cirArr, CircuitInfo, Nrow, Ntube, Nelement, fluid, l, geo, ta, RH,
                                                                       tri_cir[i], pri_cir[i], hri_cir[i], mr_ciri[k], ma, ha, haw, eta_surface, zh, zdp, hexType, thickness, conductivity, Pwater, cap_inlet, cap_outlet, coolprop, SourceTableData);

                                            if (r[i].Pro < 0)
                                            {
                                                res_slab.Pro = -10000000; return(res_slab);
                                            }

                                            if (CircuitInfo.CirType.type[i, 0] == 0)
                                            {
                                                res_type[CircuitInfo.CirType.type[i, 1]]       = r[i];
                                                res_type[CircuitInfo.CirType.type[i, 1]].index = i;
                                            }
                                        }
                                    }

                                    else
                                    {
                                        //r[i] = Circuit.CircuitCalc(i, cirArr, CircuitInfo, Nrow, Ntube, Nelement, fluid, dh, l, geo.element, ta, RH,
                                        //tri_cir[i], pri_cir[i], hri_cir[i], mr_ciri[k], ma, ha, haw, eta_surface, zh, zdp, hexType, thickness, conductivity, Pwater, Airdirection, d_cap, lenth_cap);

                                        r[i] = Circuit.CircuitCalc(i, cirArr, CircuitInfo, Nrow, Ntube, Nelement, fluid, l, geo, ta, RH,
                                                                   tri_cir[i], pri_cir[i], hri_cir[i], mr_ciri[k], ma, ha, haw, eta_surface, zh, zdp, hexType, thickness, conductivity, Pwater, cap_inlet, cap_outlet, coolprop, SourceTableData);

                                        if (r[i].Pro < 0)
                                        {
                                            res_slab.Pro = -10000000; return(res_slab);
                                        }
                                    }

                                    r1[k]        = r[i].ShallowCopy();
                                    index_cir[k] = i;//不均匀流路的输出才会用到
                                    k++;

                                    if (k == (Nciri == Nciro ? Ncir : Ngroupin[j]))
                                    {
                                        Ncir_forDP = (Nciri == Nciro ? Ncir : Ngroupin[j]);
                                        mr_forDP   = (double[])mr_ciri.Clone();
                                        break;
                                    }
                                }
                            }

                            if (index_outbig && flag_ciro == 1)
                            {
                                break;
                            }

                            index++;
                            //dPconverge = CheckDPforCircuits.CheckDPConverge(mr, mr_ciri, r, Ncir);
                            dPconverge = CheckDPforCircuits.CheckDPConverge(hexType, res_cir2, iterforPri, flag_ciro, mr_forDP, r1, Ncir_forDP);

                            if (flag_ciro == 0)
                            {
                                iterforDP_ciri++;
                                if (iterforDP_ciri >= 5)
                                {
                                    mr_forDP_4 = mr_forDP_3;
                                    mr_forDP_3 = mr_forDP_2;
                                    mr_forDP_2 = mr_forDP_1;
                                    mr_forDP_1 = mr_forDP;
                                    try
                                    {
                                        if (mr_forDP_1[0] < mr_forDP_2[0] && (Math.Abs(mr_forDP_1[0] - mr_forDP_3[0]) / mr_forDP_1[0] < 0.0001) ||
                                            Math.Abs(mr_forDP_1[0] - mr_forDP_4[0]) / mr_forDP_1[0] < 0.0001)
                                        {
                                            dPconverge.flag = true;
                                        }
                                    }
                                    catch (Exception ex)
                                    {
                                        continue;
                                    }
                                }
                                restartDP_index = 0;
                                if (!dPconverge.flag)
                                {
                                    dPconverge.mr.CopyTo(mr_ciri, 0);              //mr_ciri = dPconverge.mr;
                                }
                            }
                            else //(flag_ciro == 1)
                            {
                                iterforDP_ciro++;
                                if (iterforDP_ciro >= 5)
                                {
                                    mr_forDP_o_4 = mr_forDP_o_3;
                                    mr_forDP_o_3 = mr_forDP_o_2;
                                    mr_forDP_o_2 = mr_forDP_o_1;
                                    mr_forDP_o_1 = mr_forDP;
                                    try
                                    {
                                        if (mr_forDP_o_1[0] < mr_forDP_o_2[0] && (Math.Abs(mr_forDP_o_1[0] - mr_forDP_o_3[0]) / mr_forDP_o_1[0] < 0.0001) ||
                                            Math.Abs(mr_forDP_o_1[0] - mr_forDP_o_4[0]) / mr_forDP_o_1[0] < 0.0001)
                                        {
                                            dPconverge.flag = true;
                                        }
                                    }
                                    catch (Exception ex)
                                    {
                                        continue;
                                    }
                                }

                                if (dPconverge.flag)
                                {
                                    restartDP_index = 0;
                                }
                                else
                                {
                                    restartDP_index = 1;
                                    dPconverge.mr.CopyTo(mr_ciro, 0); //mr_ciro = dPconverge.mr;
                                    break;
                                }
                            }
                            iterforDP++;


                            N_tube2 = 0;
                            #region //Result print out
                            if (dPconverge.flag)
                            {
                                if (Nciri == Nciro)
                                {
                                    //te_calc = Refrigerant.SATP(fluid, composition, r[j].Pro, 1).Temperature;
                                    coolprop.update(input_pairs.PQ_INPUTS, r[j].Pro * 1000, 0);
                                    te_calc = coolprop.T();
                                    te_calc = CoolProp.PropsSI("T", "P", r[j].Pro * 1000, "Q", 0, fluid);
                                    int a = 1;
                                }
                                else
                                {
                                    if (mr_ciri_base.Count == Nciro && flag_ciro == 0)
                                    {
                                        mr_ciri_base.RemoveAt(index_mr_ciri_base);
                                        mr_ciri_base.Insert(index_mr_ciri_base, mr_forDP);
                                        index_mr_ciri_base++;
                                        index_mr_ciri_base %= mr_ciri_base.Count;
                                    }
                                    if (mr_ciri_base.Count < Nciro)
                                    {
                                        mr_ciri_base.Add(mr_forDP);                         //keep original mr ratio for fast iter
                                    }
                                    j           = (flag_ciro == 1 ? j + Nciro : j);
                                    res_cir2[j] = new CalcResult();
                                    for (int i = 0; i < (flag_ciro == 1 ? Nciro : Ngroupin[j]); i++)
                                    {
                                        res_cir2[j].Q   += r1[i].Q;
                                        res_cir2[j].M   += r1[i].M;
                                        res_cir2[j].hro += (flag_ciro == 1 ? mr_ciro[i] : mr_ciri[i]) * r1[i].hro;
                                        if (fluid == "Water")
                                        {
                                            res_cir2[j].Tro += (flag_ciro == 1 ? mr_ciro[i] : mr_ciri[i]) * r1[i].Tro;
                                        }

                                        res_cir2[j].Vel_r = r1[i].Vel_r;
                                        res_cir2[j].href += r1[i].href * CircuitInfo.TubeofCir[index_cir[i]];
                                        res_cir2[j].R_1  += r1[i].R_1 * CircuitInfo.TubeofCir[index_cir[i]];
                                        res_cir2[j].R_1a += r1[i].R_1a * CircuitInfo.TubeofCir[index_cir[i]];
                                        res_cir2[j].R_1r += r1[i].R_1r * CircuitInfo.TubeofCir[index_cir[i]];

                                        N_tube2 += CircuitInfo.TubeofCir[index_cir[i]];
                                    }
                                    res_cir2[j].DP         = r1[(flag_ciro == 1 ? Nciro : Ngroupin[j]) - 1].DP;
                                    res_cir2[j].Tao_Detail = ta;
                                    res_cir2[j].Pro        = r1[(flag_ciro == 1 ? Nciro : Ngroupin[j]) - 1].Pro;
                                    res_cir2[j].hro        = res_cir2[j].hro / (flag_ciro == 1 ? mr : mr_ciro[j]);

                                    res_cir2[j].href = res_cir2[j].href / N_tube2;
                                    res_cir2[j].R_1  = res_cir2[j].R_1 / N_tube2;
                                    res_cir2[j].R_1a = res_cir2[j].R_1a / N_tube2;
                                    res_cir2[j].R_1r = res_cir2[j].R_1r / N_tube2;
                                    res_cir2[j].Tri  = tri;

                                    //te_calc = Refrigerant.SATP(fluid, composition, res_cir2[j].Pro, 1).Temperature;
                                    coolprop.update(input_pairs.PQ_INPUTS, res_cir2[j].Pro * 1000, 0);
                                    te_calc = coolprop.T();
                                    te_calc = CoolProp.PropsSI("T", "P", res_cir2[j].Pro * 1000, "Q", 0, fluid);

                                    if (fluid == "Water")
                                    {
                                        res_cir2[j].Tro = res_cir2[j].Tro / (flag_ciro == 1 ? mr : mr_ciro[j]) - 273.15;
                                    }
                                    else
                                    {
                                        res_cir2[j].Tro = CoolProp.PropsSI("T", "P", res_cir2[j].Pro * 1000, "H", res_cir2[j].hro * 1000, fluid) - 273.15;
                                    }
                                }
                            }
                            #endregion
                            #endregion
                        } while (!dPconverge.flag && iterforDP < 200);

                        if (Nciri == Nciro)
                        {
                            break;
                        }

                        if (index_outbig && (j == Nciro - 1) && (res_cir2[0] != null))
                        {
                            for (int i = 0; i < Nciro; i++)
                            {
                                r2[i].DP += res_cir2[i].DP;
                            }
                            flag_ciro  = 1;
                            Ncir_forDP = Nciro;
                            mr_forDP   = (double[])mr_ciro.Clone(); // mr_forDP = mr_ciro
                            dPconverge = CheckDPforCircuits.CheckDPConverge(hexType, res_cir2, iterforPri, flag_ciro, mr_forDP, r2, Ncir_forDP);
                            iterforDP_ciro++;
                            if (iterforDP_ciro >= 5)
                            {
                                mr_forDP_o_4 = mr_forDP_o_3;
                                mr_forDP_o_3 = mr_forDP_o_2;
                                mr_forDP_o_2 = mr_forDP_o_1;
                                mr_forDP_o_1 = mr_forDP;
                                try
                                {
                                    if (mr_forDP_o_1[0] < mr_forDP_o_2[0] && (Math.Abs(mr_forDP_o_1[0] - mr_forDP_o_3[0]) / mr_forDP_o_1[0] < 0.0001) ||
                                        Math.Abs(mr_forDP_o_1[0] - mr_forDP_o_4[0]) / mr_forDP_o_1[0] < 0.0001)
                                    {
                                        dPconverge.flag = true;
                                    }
                                }
                                catch (Exception ex)
                                {
                                    continue;
                                }
                            }
                            if (!dPconverge.flag)
                            {
                                restartDP_index = 1;
                                dPconverge.mr.CopyTo(mr_ciro, 0); //mr_ciro = dPconverge.mr;
                            }
                            break;
                        }
                    }
                    if (Airdirection == "顺流")
                    {
                        airConverge.flag = true;
                        for (int ii = 0; ii < Ncir; ii++)
                        {
                            for (int i = 0; i < Nrow; i++)
                            {
                                for (int j = 0; j < N_tube; j++)
                                {
                                    for (int kk = 0; kk < Nelement; kk++)
                                    {
                                        if (r[ii].Tao_Detail[kk, j, i] != 0)
                                        {
                                            ta[kk, j, i + 1] = r[ii].Tao_Detail[kk, j, i];
                                        }
                                        if (r[ii].RHo_Detail[kk, j, i] != 0)
                                        {
                                            RH[kk, j, i + 1] = r[ii].RHo_Detail[kk, j, i];
                                        }
                                    }
                                }
                            }
                        }
                    }

                    else//Counter
                    {
                        airConverge = CheckAirConvergeforCircuits.CheckAirConverge(cirArrforAir.TotalDirection, Nrow, N_tube, Nelement, ta, RH, r); //taout_calc, RHout_calc
                        ta          = airConverge.ta;
                        RH          = airConverge.RH;
                        iterforAir++;
                    }
                    //Add Q converge criterion to avoid results oscillation, ruhao 20180426
                    if (Airdirection != "顺流") //No airConverge iter for Parallel
                    {
                        for (int i = 0; i < Ncir; i++)
                        {
                            Q1[iterforAir - 1] += r[i].Q;
                        }

                        try
                        {
                            if (Q1[iterforAir - 1] < Q1[iterforAir - 2] && (Math.Abs(Q1[iterforAir - 1] - Q1[iterforAir - 3]) / Q1[iterforAir - 1] < 0.0001) ||
                                Math.Abs(Q1[iterforAir - 1] - Q1[iterforAir - 4]) / Q1[iterforAir - 1] < 0.0001)
                            {
                                airConverge.flag = true;
                            }
                        }
                        catch (Exception ex)
                        {
                            continue;
                        }
                    }
                } while (!airConverge.flag && iterforAir < 50);

                #endregion
                //using (StreamWriter wr = File.AppendText(@"D:\Work\Simulation\Test\MinNout.txt"))
                //{
                //for (int i = 0; i < Ncir; i++)
                //{
                //wr.WriteLine("Q, {0}, DP, {1}, href, {2}, Ra_ratio, {3}, Tao, {4}, Tro, {5}, mr, {6}", r[i].Q, r[i].DP, r[i].href, r[i].Ra_ratio, r[i].Tao, r[i].Tro, r[i].mr);
                //}
                //}
                if (restartDP_index == 1)
                {
                    priconverge.flag = false;
                }
                else if (hexType == 0 && (fluid != "Water"))
                {
                    priconverge = CheckPin.CheckPriConverge(te, te_calc - 273.15, te_calc_org - 273.15, pri, pe, r[Ncir - 1].Pro); //res_slab.Pro
                    iterforPri++;
                    if (iterforPri >= 20)
                    {
                        pri_4 = pri_3;
                        pri_3 = pri_2;
                        pri_2 = pri_1;
                        pri_1 = pri;
                        try
                        {
                            if (pri_1 < pri_2 && (Math.Abs(pri_1 - pri_3) / pri_1 < 1e-5) ||
                                Math.Abs(pri_1 - pri_4) / pri_1 < 1e-5)
                            {
                                priconverge.flag = true;
                            }
                        }
                        catch (Exception ex)
                        {
                            continue;
                        }
                    }
                    pri         = priconverge.pri;
                    te_calc_org = te_calc;
                    if (priconverge.flag && iterforPri == 1 && iterforDP == 1)
                    {
                        priconverge.flag = false; //to avoid not even iterate but converge by chance
                    }
                }
                else
                {
                    priconverge.flag = true;
                }
            } while (!priconverge.flag && iterforPri < 100);


            // if (iterforDP >= 200)
            //{
            //    return res_slab;
            //    throw new Exception("iter for DPConverge > 100.");
            //}
            //if (iterforPri >= 50)
            //{
            //    return res_slab;
            //    throw new Exception("iter for Pri > 50.");
            //}

            #region //Result print out

            for (int i = 0; i < Ncir; i++)
            {
                res_slab.Q += r[i].Q;
                res_slab.M += r[i].M;
                if (Nciri == Nciro)
                {
                    res_slab.hro += mr_ciri[i] * r[i].hro;
                }
                res_slab.href += r[i].href * CircuitInfo.TubeofCir[i];
                res_slab.R_1  += r[i].R_1 * CircuitInfo.TubeofCir[i];
                res_slab.R_1a += r[i].R_1a * CircuitInfo.TubeofCir[i];
                res_slab.R_1r += r[i].R_1r * CircuitInfo.TubeofCir[i];
                for (int j = 0; j < N_tube; j++)//detail output
                {
                    for (k = 0; k < Nrow; k++)
                    {
                        if (r[i].Q_detail[j, k] != 0)
                        {
                            Q_detail[j, k] = r[i].Q_detail[j, k];
                        }
                        if (r[i].DP_detail[j, k] != 0)
                        {
                            DP_detail[j, k] = r[i].DP_detail[j, k];
                        }
                        if (r[i].Tri_detail[j, k] != 0)
                        {
                            Tri_detail[j, k] = r[i].Tri_detail[j, k];
                        }
                        if (r[i].Pri_detail[j, k] != 0)
                        {
                            Pri_detail[j, k] = r[i].Pri_detail[j, k];
                        }
                        if (r[i].hri_detail[j, k] != 0)
                        {
                            hri_detail[j, k] = r[i].hri_detail[j, k];
                        }
                        if (r[i].Tro_detail[j, k] != 0)
                        {
                            Tro_detail[j, k] = r[i].Tro_detail[j, k];
                        }
                        if (r[i].Pro_detail[j, k] != 0)
                        {
                            Pro_detail[j, k] = r[i].Pro_detail[j, k];                            //
                        }
                        if (r[i].hro_detail[j, k] != 0)
                        {
                            hro_detail[j, k] = r[i].hro_detail[j, k];
                        }
                        if (r[i].href_detail[j, k] != 0)
                        {
                            href_detail[j, k] = r[i].href_detail[j, k];
                        }
                        if (r[i].mr_detail[j, k] != 0)
                        {
                            mr_detail[j, k] = r[i].mr_detail[j, k];
                        }
                        if (r[i].charge_detail[j, k] != 0)
                        {
                            charge_detail[j, k] = r[i].charge_detail[j, k];
                        }
                    }
                }
            }
            if (Nciri == Nciro)
            {
                res_slab.hro    = res_slab.hro / mr;
                res_slab.Pro    = r[Ncir - 1].Pro;
                res_slab.DP_cap = r[Ncir - 1].DP_cap;
                res_slab.Vel_r  = r[Ncir - 1].Vel_r;
            }
            else if (!index_outbig)
            {
                res_slab.hro    = res_cir2[Nciro].hro;
                res_slab.Pro    = res_cir2[Nciro].Pro;
                res_slab.DP_cap = res_cir2[Nciro].DP_cap;
                res_slab.Vel_r  = res_cir2[Nciro].Vel_r;
            }
            else
            {
                res_slab.hro    = res_cir2[Nciro - 1].hro;
                res_slab.Pro    = res_cir2[Nciro - 1].Pro;
                res_slab.DP_cap = res_cir2[Nciro - 1].DP_cap;
                res_slab.Vel_r  = res_cir2[Nciro - 1].Vel_r;
            }
            res_slab.Pri        = pri;
            res_slab.Tri        = tri;
            res_slab.hri        = hri;
            res_slab.mr         = mr;
            res_slab.DP         = pri - res_slab.Pro;
            res_slab.Tao_Detail = ta;
            res_slab.RHo_Detail = RH;
            res_slab.href       = res_slab.href / N_tube_total;
            for (int i = 0; i < ha.GetLength(0); i++)
            {
                for (int j = 0; j < ha.GetLength(1); j++)
                {
                    res_slab.ha += ha[i, j];
                }
            }
            res_slab.ha   = res_slab.ha / ha.Length;
            res_slab.R_1  = res_slab.R_1 / N_tube_total;
            res_slab.R_1a = res_slab.R_1a / N_tube_total;
            res_slab.R_1r = res_slab.R_1r / N_tube_total;

            coolprop.update(input_pairs.PQ_INPUTS, res_slab.Pro * 1000, 0);
            te_calc = coolprop.T() - 273.15;
            te_calc = CoolProp.PropsSI("T", "P", res_slab.Pro * 1000, "Q", 0, fluid) - 273.15;
            coolprop.update(input_pairs.QT_INPUTS, 0, te_calc + 273.15);
            double densityLo = coolprop.rhomass();
            //double densityLo = CoolProp.PropsSI("D", "T", te_calc + 273.15, "Q", 0, fluid);
            coolprop.update(input_pairs.QT_INPUTS, 1, te_calc + 273.15);
            double densityVo = coolprop.rhomass();
            //double densityVo = CoolProp.PropsSI("D", "T", te_calc + 273.15, "Q", 1, fluid);
            coolprop.update(input_pairs.DmassT_INPUTS, densityLo, te_calc + 273.15);
            double hlo = coolprop.hmass() / 1000;
            //double hlo = CoolProp.PropsSI("H", "T", te_calc + 273.15, "D", densityLo, fluid) / 1000 ;
            coolprop.update(input_pairs.DmassT_INPUTS, densityVo, te_calc + 273.15);
            double hvo = coolprop.hmass() / 1000;
            //double hvo = CoolProp.PropsSI("H", "T", te_calc + 273.15, "D", densityVo, fluid) / 1000 ;
            res_slab.x_o = (res_slab.hro - hlo) / (hvo - hlo);

            coolprop.update(input_pairs.PQ_INPUTS, pri * 1000, 0);
            double hli = coolprop.hmass() / 1000;
            //double hli = CoolProp.PropsSI("H", "P", pri * 1000, "Q", 0, fluid) / 1000 ;
            coolprop.update(input_pairs.PQ_INPUTS, pri * 1000, 1);
            double hvi = coolprop.hmass() / 1000;
            //double hvi = CoolProp.PropsSI("H", "P", pri * 1000, "Q", 1, fluid) / 1000 ;

            res_slab.x_i = (res_slab.hri - hli) / (hvi - hli);
            coolprop.update(input_pairs.HmassP_INPUTS, res_slab.hro * 1000, res_slab.Pro * 1000);
            res_slab.Tro = coolprop.T() - 273.15;
            //res_slab.Tro = CoolProp.PropsSI("T", "P", res_slab.Pro * 1000, "H", res_slab.hro * 1000, fluid) - 273.15;

            double h = res_slab.hro;
            for (int j = 0; j < N_tube; j++)
            {
                for (int i = 0; i < Nelement; i++)
                {
                    res_slab.Tao   += res_slab.Tao_Detail[i, j, Nrow];
                    res_slab.RHout += res_slab.RHo_Detail[i, j, Nrow];
                }
            }

            res_slab.Tao      = res_slab.Tao / (N_tube * Nelement);
            res_slab.RHout    = res_slab.RHout / (N_tube * Nelement);
            res_slab.Ra_ratio = res_slab.R_1a / res_slab.R_1;
            for (int i = 0; i < ma.GetLength(0); i++)
            {
                for (int j = 0; j < ma.GetLength(1); j++)
                {
                    res_slab.ma += ma[i, j];
                }
            }
            res_slab.Va            = res_slab.ma / 1.2 * 3600;
            res_slab.Q_detail      = Q_detail;//detail output
            res_slab.DP_detail     = DP_detail;
            res_slab.Tri_detail    = Tri_detail;
            res_slab.Pri_detail    = Pri_detail;
            res_slab.hri_detail    = hri_detail;
            res_slab.Tro_detail    = Tro_detail;
            res_slab.Pro_detail    = Pro_detail;
            res_slab.hro_detail    = hro_detail;
            res_slab.href_detail   = href_detail;
            res_slab.mr_detail     = mr_detail;
            res_slab.Aa            = geo.TotalArea.A_a;
            res_slab.Ar            = geo.TotalArea.A_r;
            res_slab.AHx           = geo.TotalArea.A_hx;
            res_slab.N_row         = Nrow;
            res_slab.tube_row      = N_tube;
            res_slab.charge_detail = charge_detail;

            return(res_slab);

            #endregion
        }
예제 #8
0
        //------------------------End of logspace---------------------------------------------------//

        /// <summary>
        /// Equivalent of matlab function IAPWS_IF97()
        /// returns parameters based on the outputName
        /// </summary>
        /// <param name="outputName">output we want</param>
        /// <param name="prop1">proerty1(like T(tempr), P(Pressure),h(enthalpy),etc)</param>
        /// <param name="prop1Value">Value of prop1</param>
        /// <param name="prop2">proerty2(like T(tempr), P(Pressure),h(enthalpy),etc)</param>
        /// <param name="prop2Value">Value of prop2</param>
        /// <param name="fluidName">Fluid Name(eg. Water,n-Propane,etc)</param>
        /// <returns>values based on pased parameter generally, temperature, pressure and enthalpy</returns>
        public double IAPWS_IF97_TowParameterEquivalentFxn(string outputParamName, string prop1, double prop1Value, string prop2, double prop2Value, string fluidName)
        {
            return(CoolProp.PropsSI(outputParamName, prop1, prop1Value, prop2, prop2Value, fluidName));
        }
예제 #9
0
        //Start
        public static CalcResult SlabCalc(int[,] CirArrange, CircuitNumber CircuitInfo, int Nrow, int[] Ntube, int Nelement, string fluid, //double Npass, int[] N_tubes_pass,
                                          double l, Geometry geo, double[, ,] ta, double[, ,] RH, double te, double pe, double hri, double mr, double[,] ma, double[,] ha, double[,] haw,
                                          double eta_surface, double zh, double zdp, int hexType, double thickness, double conductivity, double Pwater, int AirFlowDirection, List <NodeInfo> Nodes, int N_Node, CapiliaryInput cap_inlet, CapiliaryInput cap_outlet, AbstractState coolprop, double[,] SourceTableData)
        {
            double tri         = te; //Refrigerant.SATP(fluid, composition, pri, 1).Temperature - 273.15;
            double pri         = pe;
            double te_calc_org = 0;
            int    N_tube      = Ntube[0];

            CirArr[]     cirArr       = new CirArr[Nrow * N_tube];
            CirArrforAir cirArrforAir = new CirArrforAir();

            cirArrforAir = CirArrangement.ReadCirArr(CirArrange, CircuitInfo, Nrow, Ntube, AirFlowDirection);
            cirArr       = cirArrforAir.CirArr;
            CheckAir   airConverge  = new CheckAir();
            CheckDP    dPconverge   = new CheckDP();
            CheckPri   priconverge  = new CheckPri();
            int        iterforAir   = 0;
            int        iterforDP    = 0;
            int        iterforPri   = 0;
            CalcResult r            = new CalcResult();
            CalcResult res_slab     = new CalcResult();
            int        N_cir        = CircuitInfo.TubeofCir.Length;
            int        N_tube_total = CircuitInfo.TubeofCir.Sum();

            CalcResult[] res_cir = new CalcResult[N_cir];
            double[, ,] taout_calc  = new double[Nelement, N_tube, Nrow];
            double[, ,] RHout_calc  = new double[Nelement, N_tube, Nrow];
            double[,] Q_detail      = new double[N_tube, Nrow];//detail output
            double[,] DP_detail     = new double[N_tube, Nrow];
            double[,] Tri_detail    = new double[N_tube, Nrow];
            double[,] Pri_detail    = new double[N_tube, Nrow];
            double[,] hri_detail    = new double[N_tube, Nrow];
            double[,] Tro_detail    = new double[N_tube, Nrow];
            double[,] Pro_detail    = new double[N_tube, Nrow];
            double[,] hro_detail    = new double[N_tube, Nrow];//
            double[,] href_detail   = new double[N_tube, Nrow];
            double[,] mr_detail     = new double[N_tube, Nrow];
            double[,] charge_detail = new double[N_tube, Nrow];
            int  index_Node      = 0;
            int  index_couple    = 0;
            int  index_last_Node = 0;
            bool index_end       = false;

            int[]  index_status     = new int[N_Node];
            int[]  index_FullStatus = new int[N_Node];
            int[]  index_DP         = new int[N_Node];//
            double mri_cal          = 0;
            double pri_cal          = 0;
            double hri_cal          = 0;
            double tri_cal          = 0;
            int    index_cir        = 0;
            double te_calc;

            do                    //Pri iteration
            {
                if (hexType == 0) // need to be under pri iteration
                {
                    tri = CoolProp.PropsSI("T", "P", pri * 1000, "Q", 0, fluid) - 273.15;
                }
                else
                {
                    te = CoolProp.PropsSI("T", "P", pri * 1000, "Q", 0, fluid) - 273.15;
                }

                int iiii = 0;
                do//Air iteration
                {
                    //Node[] Nodes=new Node[N_node];
                    //Nodes[0]=First Node;
                    for (int i = 0; i < N_Node; i++)
                    {
                        index_FullStatus[i] = Math.Max(Nodes[i].N_in, Nodes[i].N_out);
                        index_status[i]     = 0;
                    }

                    index_Node = SearchNode.FindNextNode(-1, 0, Nodes, N_Node); //Find the first node
                    index_status[index_Node] = 0;                               //initial status
                    //index_FullStatus[index_Node]=Nodes[index_Node].N_out;
                    //index_DP[index_Node] = 0;
                    index_end = false;
                    for (int i = 0; i < 1000; i++)            //for DP converge
                    {
                        if (Nodes[index_Node].inlet[0] == -1) //First Node(diverse)
                        {
                            Nodes[index_Node].mri[0] = mr;
                            Nodes[index_Node].pri[0] = pri;
                            Nodes[index_Node].hri[0] = hri;
                            Nodes[index_Node].tri[0] = tri;
                            //index_cir=Node[index].out[i];//?
                        }
                        if (Nodes[index_Node].type == 'D' || Nodes[index_Node].type == 'S') //Diverse Node Distribution
                        {
                            if (index_DP[index_Node] == 0)                                  //first time calculation
                            {
                                Nodes[index_Node].mro[index_status[index_Node]] = Nodes[index_Node].mri[0] / Nodes[index_Node].N_out;
                            }
                            else
                            {
                                Nodes[index_Node].mro[index_status[index_Node]] = Nodes[index_Node].mri[0] * Nodes[index_Node].mr_ratio[index_status[index_Node]];
                            }
                            Nodes[index_Node].pro[index_status[index_Node]] = Nodes[index_Node].pri[0];
                            Nodes[index_Node].tro[index_status[index_Node]] = Nodes[index_Node].tri[0];
                            Nodes[index_Node].hro[index_status[index_Node]] = Nodes[index_Node].hri[0];
                            if (Nodes[index_Node].outType[index_status[index_Node]] == 0)//0:out is Node,1:out is Circuit
                            {
                                index_last_Node          = index_Node;
                                index_Node               = SearchNode.FindNextNode(index_Node, index_status[index_Node], Nodes, N_Node);//find node
                                Nodes[index_Node].pri[0] = Nodes[index_last_Node].pro[index_status[index_last_Node]];
                                Nodes[index_Node].tri[0] = Nodes[index_last_Node].tro[index_status[index_last_Node]];
                                Nodes[index_Node].hri[0] = Nodes[index_last_Node].hro[index_status[index_last_Node]];
                                Nodes[index_Node].mri[0] = Nodes[index_last_Node].mro[index_status[index_last_Node]];
                                index_status[index_Node] = 0;
                                //i_end=Nodes[index_Node].N_out;
                                continue;
                            }
                            else//out is Circuit
                            {
                                mri_cal   = Nodes[index_Node].mro[index_status[index_Node]];
                                pri_cal   = Nodes[index_Node].pro[index_status[index_Node]];
                                tri_cal   = Nodes[index_Node].tro[index_status[index_Node]];
                                hri_cal   = Nodes[index_Node].hro[index_status[index_Node]];
                                index_cir = Nodes[index_Node].outlet[index_status[index_Node]];
                            }
                        }
                        else if (Nodes[index_Node].type == 'C')//Converge Node
                        {
                            mri_cal   = Nodes[index_Node].mro[0];
                            pri_cal   = Nodes[index_Node].pro[0];
                            hri_cal   = Nodes[index_Node].hro[0];
                            tri_cal   = Nodes[index_Node].tro[0];
                            index_cir = Nodes[index_Node].outlet[0];
                        }

                        //index_status[index_Node]=i;//status
                        r = Circuit.CircuitCalc(index_cir, cirArr, CircuitInfo, Nrow, Ntube, Nelement, fluid, l, geo, ta, RH,
                                                tri_cal, pri_cal, hri_cal, mri_cal, ma, ha, haw, eta_surface, zh, zdp, hexType, thickness, conductivity, Pwater, cap_inlet, cap_outlet, coolprop, SourceTableData);

                        res_cir[index_cir] = r;
                        if (r.Pro < 0)
                        {
                            res_slab.Pro = -10000000; return(res_slab);
                        }
                        for (int aa = 0; aa < Nrow; aa++)// detail result print
                        {
                            for (int bb = 0; bb < N_tube; bb++)
                            {
                                Q_detail[bb, aa]      = r.Q_detail[bb, aa] == 0 ? Q_detail[bb, aa] : r.Q_detail[bb, aa];
                                DP_detail[bb, aa]     = r.DP_detail[bb, aa] == 0 ? DP_detail[bb, aa] : r.DP_detail[bb, aa];
                                Pri_detail[bb, aa]    = r.Pri_detail[bb, aa] == 0 ? Pri_detail[bb, aa] : r.Pri_detail[bb, aa];
                                Tri_detail[bb, aa]    = r.Tri_detail[bb, aa] == 0 ? Tri_detail[bb, aa] : r.Tri_detail[bb, aa];
                                hri_detail[bb, aa]    = r.hri_detail[bb, aa] == 0 ? hri_detail[bb, aa] : r.hri_detail[bb, aa];
                                Pro_detail[bb, aa]    = r.Pro_detail[bb, aa] == 0 ? Pro_detail[bb, aa] : r.Pro_detail[bb, aa];
                                Tro_detail[bb, aa]    = r.Tro_detail[bb, aa] == 0 ? Tro_detail[bb, aa] : r.Tro_detail[bb, aa];
                                hro_detail[bb, aa]    = r.hro_detail[bb, aa] == 0 ? hro_detail[bb, aa] : r.hro_detail[bb, aa];
                                href_detail[bb, aa]   = r.href_detail[bb, aa] == 0 ? href_detail[bb, aa] : r.href_detail[bb, aa];
                                mr_detail[bb, aa]     = r.mr_detail[bb, aa] == 0 ? mr_detail[bb, aa] : r.mr_detail[bb, aa];
                                charge_detail[bb, aa] = r.charge_detail[bb, aa] == 0 ? charge_detail[bb, aa] : r.charge_detail[bb, aa];
                                for (int cc = 0; cc < Nelement; cc++)
                                {
                                    taout_calc[cc, bb, aa] = r.Tao_Detail[cc, bb, aa] == 0 ? taout_calc[cc, bb, aa] : r.Tao_Detail[cc, bb, aa];
                                    RHout_calc[cc, bb, aa] = r.RHo_Detail[cc, bb, aa] == 0 ? RHout_calc[cc, bb, aa] : r.RHo_Detail[cc, bb, aa];
                                }
                            }
                        }
                        index_Node = SearchNode.FindNextNode(index_Node, index_status[index_Node], Nodes, N_Node); //Find Next Node

                        if (Nodes[index_Node].type == 'D')                                                         //Diverse Node cal
                        {
                            index_status[index_Node] = 0;
                            //i_end=Nodes[index_Node].N_out;
                            Nodes[index_Node].pri[0] = r.Pro;
                            Nodes[index_Node].tri[0] = r.Tro;
                            Nodes[index_Node].hri[0] = r.hro;
                            Nodes[index_Node].mri[0] = r.mr;
                            continue;
                        }
                        else if (Nodes[index_Node].type == 'C')//Converge Node cal
                        {
                            for (int ii = 0; ii < N_Node; ii++)
                            {
                                if (Nodes[ii].couple == Nodes[index_Node].couple && ii != index_Node)
                                {
                                    index_couple = ii;
                                    break;
                                }
                            }//Find the Couple Node
                            Nodes[index_Node].pri[index_status[index_couple]] = r.Pro;
                            Nodes[index_Node].tri[index_status[index_couple]] = r.Tro;
                            Nodes[index_Node].hri[index_status[index_couple]] = r.hro;
                            Nodes[index_Node].mri[index_status[index_couple]] = r.mr;
                            for (int k = 0; k < 100; k++)
                            {
                                if (index_status[index_couple] < index_FullStatus[index_couple] - 1)//continue
                                {
                                    index_Node = index_couple;
                                    index_status[index_Node]++;
                                    //i_end=Nodes[index_couple].N_out;
                                    break;
                                }
                                else if (index_status[index_couple] == index_FullStatus[index_couple] - 1)//dp converge calculation
                                {
                                    //DPconverge=DPConverge(Nodes[index_Node].mri,Nodes[index_Node].pri);
                                    dPconverge = CheckDPforCircuits.CheckDPConverge2(hexType, iterforPri, Nodes[index_Node].mri, Nodes[index_Node].pri, Nodes[index_couple].pri[0], index_FullStatus[index_couple]);
                                    iterforDP++;
                                    if (dPconverge.flag == false)//need to be modified
                                    {
                                        Nodes[index_couple].mro      = dPconverge.mr;
                                        Nodes[index_couple].mr_ratio = dPconverge.mr_ratio;
                                        index_DP[index_couple]++;
                                        index_Node = index_couple;
                                        index_status[index_Node] = 0;
                                        //i_end=Nodes[index_Node].N_out;
                                        break;
                                    }
                                    else if (dPconverge.flag == true)
                                    {
                                        index_DP[index_couple]       = 1;
                                        Nodes[index_couple].mr_ratio = dPconverge.mr_ratio;
                                        double mr_sum  = 0;
                                        double tro_ave = 0;
                                        double hro_ave = 0;
                                        for (int ii = 0; ii < index_FullStatus[index_couple]; ii++)
                                        {
                                            mr_sum += Nodes[index_Node].mri[ii];
                                        }
                                        for (int ii = 0; ii < index_FullStatus[index_couple]; ii++)
                                        {
                                            tro_ave += Nodes[index_Node].mri[ii] * Nodes[index_Node].tri[ii];
                                            hro_ave += Nodes[index_Node].mri[ii] * Nodes[index_Node].hri[ii];
                                        }
                                        Nodes[index_Node].mro[0] = mr_sum;
                                        Nodes[index_Node].tro[0] = tro_ave / mr_sum;
                                        Nodes[index_Node].hro[0] = hro_ave / mr_sum;
                                        Nodes[index_Node].pro[0] = Nodes[index_Node].pri[0];
                                        if (Nodes[index_Node].outType[0] == 0)//0:out is Node
                                        {
                                            index_last_Node = index_Node;
                                            index_Node      = SearchNode.FindNextNode(index_Node, 0, Nodes, N_Node);
                                            if (Nodes[index_Node].type == 'C')
                                            {
                                                for (int ii = 0; ii < N_Node; ii++)
                                                {
                                                    if (Nodes[ii].couple == Nodes[index_Node].couple && ii != index_Node)
                                                    {
                                                        index_couple = ii;
                                                        break;
                                                    }
                                                }//Find the Couple Node
                                                Nodes[index_Node].pri[index_status[index_couple]] = Nodes[index_last_Node].pro[0];
                                                Nodes[index_Node].tri[index_status[index_couple]] = Nodes[index_last_Node].tro[0];
                                                Nodes[index_Node].hri[index_status[index_couple]] = Nodes[index_last_Node].hro[0];
                                                Nodes[index_Node].mri[index_status[index_couple]] = Nodes[index_last_Node].mro[0];
                                                continue;
                                            }
                                            else if (Nodes[index_Node].type == 'D')
                                            {
                                                index_status[index_Node] = 0;
                                                Nodes[index_Node].mri[0] = Nodes[index_last_Node].mro[0];
                                                Nodes[index_Node].tri[0] = Nodes[index_last_Node].tro[0];
                                                Nodes[index_Node].hri[0] = Nodes[index_last_Node].hro[0];
                                                Nodes[index_Node].pri[0] = Nodes[index_last_Node].pro[0];
                                                break;
                                            }
                                        }
                                        else if (Nodes[index_Node].outType[0] == -1)
                                        {
                                            index_end = true;
                                            break;
                                        }
                                        else//out is Circuit
                                        {
                                            break;
                                        }
                                        continue;
                                    }
                                } //end if
                            }     //end for
                            if (index_end == true)
                            {
                                break;
                            }
                        }
                        else if (Nodes[index_Node].type == 'E')//for 1 out case
                        {
                            Nodes[index_Node].pri[0] = r.Pro;
                            Nodes[index_Node].tri[0] = r.Tro;
                            Nodes[index_Node].hri[0] = r.hro;
                            Nodes[index_Node].mro[0] = r.mr;
                            Nodes[index_Node].pro[0] = r.Pro;
                            Nodes[index_Node].tro[0] = r.Tro;
                            Nodes[index_Node].hro[0] = r.hro;
                            Nodes[index_Node].mro[0] = r.mr;
                            break;
                        }
                    }//end out for
                    airConverge = CheckAirConvergeforCircuits.CheckAirConverge2(cirArrforAir.TotalDirection, Nrow, N_tube, Nelement, ta, RH, taout_calc, RHout_calc); //taout_calc, RHout_calc
                    ta          = airConverge.ta;
                    RH          = airConverge.RH;
                    iterforAir++;
                } while (airConverge.flag == false && iterforAir < 50);
                if (hexType == 0)
                {
                    te_calc     = CoolProp.PropsSI("T", "P", Nodes[index_Node].pro[0] * 1000, "Q", 0, fluid);
                    priconverge = CheckPin.CheckPriConverge(te, te_calc - 273.15, te_calc_org - 273.15, pri, pe, Nodes[index_Node].pro[0]); //res_slab.Pro
                    iterforPri++;
                    pri         = priconverge.pri;
                    te_calc_org = te_calc;
                    if (priconverge.flag && iterforPri == 1)
                    {
                        priconverge.flag = false; //to avoid not even iterate but converge by chance
                    }
                }
            } while (priconverge.flag == false && iterforPri < 20);
            //result print
            if (iterforDP >= 200)
            {
                return(res_slab);

                throw new Exception("iter for DPConverge > 200.");
            }
            if (iterforPri >= 50)
            {
                return(res_slab);

                throw new Exception("iter for Pri > 50.");
            }
            #region result print
            for (int i = 0; i < N_cir; i++)
            {
                res_slab.R_1  += res_cir[i].R_1 * CircuitInfo.TubeofCir[i];
                res_slab.R_1a += res_cir[i].R_1a * CircuitInfo.TubeofCir[i];
                res_slab.R_1r += res_cir[i].R_1r * CircuitInfo.TubeofCir[i];
            }
            for (int j = 0; j < N_tube; j++)//detail output
            {
                for (int k = 0; k < Nrow; k++)
                {
                    res_slab.Q    += Q_detail[j, k];
                    res_slab.M    += charge_detail[j, k];
                    res_slab.href += href_detail[j, k];
                }
            }
            res_slab.hro        = Nodes[index_Node].hro[0];
            res_slab.Pro        = Nodes[index_Node].pro[0];
            res_slab.Pri        = pri;
            res_slab.Tri        = tri;
            res_slab.hri        = hri;
            res_slab.mr         = mr;
            res_slab.DP         = pri - res_slab.Pro;
            res_slab.Tao_Detail = ta;
            res_slab.RHo_Detail = RH;
            res_slab.href       = res_slab.href / N_tube_total;
            for (int i = 0; i < ha.GetLength(0); i++)
            {
                for (int j = 0; j < ha.GetLength(1); j++)
                {
                    res_slab.ha += ha[i, j];
                }
            }
            res_slab.ha   = res_slab.ha / ha.Length;
            res_slab.R_1  = res_slab.R_1 / N_tube_total;
            res_slab.R_1a = res_slab.R_1a / N_tube_total;
            res_slab.R_1r = res_slab.R_1r / N_tube_total;
            te_calc       = CoolProp.PropsSI("T", "P", res_slab.Pro * 1000, "Q", 0, fluid) - 273.15;
            double densityLo = CoolProp.PropsSI("D", "T", te_calc + 273.15, "Q", 0, fluid);
            double densityVo = CoolProp.PropsSI("D", "T", te_calc + 273.15, "Q", 1, fluid);
            double hlo       = CoolProp.PropsSI("H", "T", te_calc + 273.15, "D", densityLo, fluid) / 1000;
            double hvo       = CoolProp.PropsSI("H", "T", te_calc + 273.15, "D", densityVo, fluid) / 1000;
            res_slab.x_o = (res_slab.hro - hlo) / (hvo - hlo);
            double hli = CoolProp.PropsSI("H", "P", pri * 1000, "Q", 0, fluid) / 1000;
            double hvi = CoolProp.PropsSI("H", "P", pri * 1000, "Q", 1, fluid) / 1000;
            res_slab.x_i = (res_slab.hri - hli) / (hvi - hli);
            res_slab.Tro = CoolProp.PropsSI("T", "P", res_slab.Pro * 1000, "H", res_slab.hro * 1000, fluid) - 273.15;
            for (int j = 0; j < N_tube; j++)
            {
                for (int i = 0; i < Nelement; i++)
                {
                    res_slab.Tao   += res_slab.Tao_Detail[i, j, Nrow];
                    res_slab.RHout += res_slab.RHo_Detail[i, j, Nrow];
                }
            }

            res_slab.Tao      = res_slab.Tao / (N_tube * Nelement);
            res_slab.RHout    = res_slab.RHout / (N_tube * Nelement);
            res_slab.Ra_ratio = res_slab.R_1a / res_slab.R_1;
            for (int i = 0; i < ma.GetLength(0); i++)
            {
                for (int j = 0; j < ma.GetLength(1); j++)
                {
                    res_slab.ma += ma[i, j];
                }
            }
            res_slab.Va            = res_slab.ma / 1.2 * 3600;
            res_slab.Q_detail      = Q_detail;//detail output
            res_slab.DP_detail     = DP_detail;
            res_slab.Tri_detail    = Tri_detail;
            res_slab.Pri_detail    = Pri_detail;
            res_slab.hri_detail    = hri_detail;
            res_slab.Tro_detail    = Tro_detail;
            res_slab.Pro_detail    = Pro_detail;
            res_slab.hro_detail    = hro_detail;
            res_slab.href_detail   = href_detail;
            res_slab.mr_detail     = mr_detail;
            res_slab.Aa            = geo.TotalArea.A_a;
            res_slab.Ar            = geo.TotalArea.A_r;
            res_slab.AHx           = geo.TotalArea.A_hx;
            res_slab.N_row         = Nrow;
            res_slab.tube_row      = N_tube;
            res_slab.charge_detail = charge_detail;
            #endregion
            return(res_slab);
        } //end function
예제 #10
0
        static void Main(string[] args)
        {
            String s;
            String option;
            String s1;

            Console.WriteLine("please enter the total pressure in atmosphere or bar");
            s = Console.ReadLine();
            double v = Convert.ToDouble(s);

            Console.WriteLine("is the pressure in atmosphere or bar? if it is in atmosphere write atm and if it is in bar please enter bar");
            s = Console.ReadLine();
            if (s == "bar")
            {
                v = v * 0.986923267;
            }
            Console.WriteLine("please give tG in celcius");
            s1 = Console.ReadLine();
            double tg = Convert.ToDouble(s1);

            Console.WriteLine("enter which parameter you would like to enter?");
            Console.WriteLine("1. R.H");
            Console.WriteLine("2. Absolute Humidity");
            Console.WriteLine("3. wet temperature");
            Console.WriteLine("4. humidity percentege");
            Console.WriteLine("1 or 2 or 3 or 4?");
            option = Console.ReadLine();
            int option1 = Convert.ToInt32(option);

            if (option1 == 1)
            {
                Console.WriteLine("enter R.H?");
                double rh      = Convert.ToDouble(Console.ReadLine());
                double pa      = (CoolProp.PropsSI("P", "T", tg + 273.15, "Q", 0, "Water") * 0.00986923267) / 1000;
                double paprime = (rh / 100) * pa;
                double yprime  = ((paprime) / (v - paprime)) * 0.62;
                double H       = ((1005 + (1884 * yprime)) * tg) + (yprime * 2502300);
                double vp      = v * 101325;
                double vh      = 8315 * ((tg + 273) / vp) * (0.034 + (0.05 * yprime));
                double tw      = tg - 0.01;
                l1 : double yprimew = (CoolProp.PropsSI("P", "T", tw + 273.15, "Q", 0, "Water") * 0.00986923267) / 1000;
                double twprime = tg - ((2260 * (yprimew - yprime)) / 950);
                if (twprime != tw)
                {
                    tw = twprime;
                    goto l1;
                }
                double sum1       = ((yprimew) / (v - yprimew));
                double percentage = (yprime / sum1) * 100;
                Console.WriteLine("value of Absolute Humidity is " + yprime.ToString());
                Console.WriteLine("value of wet temperature is " + tw.ToString());
                Console.WriteLine("value of percent humidity is " + percentage.ToString());
                Console.WriteLine("value of Humid Volume is " + vh.ToString());
                Console.WriteLine("value of Enthalpy is " + H.ToString());
                Console.WriteLine("value of partial pressure is " + paprime.ToString());
            }
            if (option1 == 2)
            {
                Console.WriteLine("enter Absolute Humidity?");
                double yprime  = Convert.ToDouble(Console.ReadLine());
                double H       = ((1005 + (1884 * yprime)) * tg) + (yprime * 2502300);
                double vp      = v * 101325;
                double vh      = 8315 * ((tg + 273) / vp) * (0.034 + (0.05 * yprime));
                double paprime = (yprime * v) / (0.62 + yprime);
                double t1      = ((CoolProp.PropsSI("P", "T", tg + 273.15, "Q", 0, "Water")) * 0.00986923267) / 1000;

                double rh = (paprime / t1) * 100;
                double tw = tg - 0.01;
                l2 : double yprimew = (CoolProp.PropsSI("P", "T", tw + 273.15, "Q", 0, "Water") * 0.00986923267) / 1000;
                double twprime = tg - ((2260 * (yprimew - yprime)) / 950);
                if (twprime != tw)
                {
                    tw = twprime;
                    goto l2;
                }
                double sum1       = ((yprimew) / (v - yprimew));
                double percentage = (yprime / sum1) * 100;
                //double percentage = (yprime / yprimew) * 100;
                Console.WriteLine("value of R.H is " + rh.ToString());
                Console.WriteLine("value of wet temperature is " + tw.ToString());
                Console.WriteLine("value of percent humidity is " + percentage.ToString());
                Console.WriteLine("value of Humid Volume is " + vh.ToString());
                Console.WriteLine("value of Enthalpy is " + H.ToString());
                Console.WriteLine("value of partial pressure is " + paprime.ToString());
            }
            if (option1 == 3)
            {
                Console.WriteLine("enter wet temperature?");
                double tw         = Convert.ToDouble(Console.ReadLine());
                double yprimew    = (CoolProp.PropsSI("P", "T", tw + 273.15, "Q", 0, "Water") * 0.00986923267) / 1000;
                double yprime     = (((tw - tg) * 950) / 2260) + yprimew;
                double H          = ((1005 + (1884 * yprime)) * tg) + (yprime * 2502300);
                double vp         = v * 101325;
                double vh         = 8315 * ((tg + 273) / vp) * (0.034 + (0.05 * yprime));
                double paprime    = (yprime * v) / (0.62 + yprime);
                double t1         = (CoolProp.PropsSI("P", "T", tg + 273.15, "Q", 0, "Water") * 0.00986923267) / 1000;
                double rh         = (paprime / t1) * 100;
                double sum1       = ((yprimew) / (v - yprimew));
                double percentage = (yprime / sum1) * 100;
                //double percentage = (yprime / yprimew) * 100;
                Console.WriteLine("value of Absolute Humidity is " + yprime.ToString());
                Console.WriteLine("value of R.H is " + rh.ToString());
                Console.WriteLine("value of percent humidity is " + percentage.ToString());
                Console.WriteLine("value of Humid Volume is " + vh.ToString());
                Console.WriteLine("value of Enthalpy is " + H.ToString());
                Console.WriteLine("value of partial pressure is " + paprime.ToString());
            }
            if (option1 == 4)
            {
                Console.WriteLine("enter humidity percentage?");
                double percentage = Convert.ToDouble(Console.ReadLine());
                double yprimew    = (CoolProp.PropsSI("P", "T", tg + 273.15, "Q", 0, "Water") * 0.00986923267) / 1000;
                double yprimes    = (yprimew / (v - yprimew));
                double yprime     = (percentage / 100) * yprimes;
                double H          = ((1005 + (1884 * yprime)) * tg) + (yprime * 2502300);
                double vp         = v * 101325;
                double vh         = 8315 * ((tg + 273) / vp) * (0.034 + (0.05 * yprime));
                double paprime    = (yprime * v) / (0.62 + yprime);
                double t1         = (CoolProp.PropsSI("P", "T", tg + 273.15, "Q", 0, "Water") * 0.00986923267) / 1000;
                double rh         = (paprime / t1) * 100;
                double tw         = tg - 0.01;
                l3 : double yprimew1 = (CoolProp.PropsSI("P", "T", tw + 273.15, "Q", 0, "Water") * 0.00986923267) / 1000;
                double twprime = tg - ((2260 * (yprimew1 - yprime)) / 950);
                if (twprime != tw)
                {
                    tw = twprime;
                    goto l3;
                }

                Console.WriteLine("value of Absolute Humidity is " + yprime.ToString());
                Console.WriteLine("value of wet temperature is " + tw.ToString());
                Console.WriteLine("value of R.H is " + rh.ToString());
                Console.WriteLine("value of Humid Volume is " + vh.ToString());
                Console.WriteLine("value of Enthalpy is " + H.ToString());
                Console.WriteLine("value of partial pressure is " + paprime.ToString());
            }

            Console.WriteLine("please enter any key to exit");
            Console.ReadKey();
        }
예제 #11
0
        public static decimal GetAcetoneBoilingPoint(decimal PressureInPa)
        {
            decimal BoilingPoint = Math.Round(Convert.ToDecimal(CoolProp.PropsSI("T", "P", Convert.ToDouble(PressureInPa), "Q", 0, "Acetone") - 273.15), 2);

            return(BoilingPoint);
        }
예제 #12
0
        public static void ComputeAdditionalProperty(ref SystemInputStream _in, ref double AirX, ref double WaterX)
        {
            #region Variable declarations
            const double Epsilon = 0.75;

            //All properties are final state
            double DensityWaterInitial;
            double DensityAirInitial;

            double MassFlowWaterFinal;
            double MassFlowAirFinal;

            double TWaterFinal;
            double TAirFinal;
            double TWaterMeanFinal;
            double TAirMeanFinal;
            double ViscosityAir;
            double ViscosityWater;
            double CpAir;
            double CpWater;
            double PrandtlAir;
            double PrandtlWater;
            double G_Air;
            double G_Water;
            double Reynolds_Air;
            double Reynolds_Water;
            double J_Water;
            double F_Water;
            double J_Air;
            double F_Air;
            double H_Water;
            double H_Air;
            double c7;
            double c8;
            double c9;
            double VelocityAir;
            double FinEfficiency;
            double OverallEfficiency;
            double Rw;
            double UaInverse;
            double C_Water;
            double C_Air;
            double C_Min;
            double C_Star;
            double NTU;
            double epsilon;
            double ConductionAreaWater;
            double ConductionAreaAir;
            double lambdaAir;
            double lambdaWater;
            double M1;
            double M2;
            double EpsilonRatio;
            double deltaEpsilon;
            double ActualEpsilon;
            double HeatTransferRate;
            double prevvalWater;
            double prevvalAir;
            #endregion

            #region User Input acquisition
            double L1           = _in.NumericalReadings.First(x => x.Parameter == "L1").Value;
            double L2           = _in.NumericalReadings.First(x => x.Parameter == "L2").Value;
            double L3           = _in.NumericalReadings.First(x => x.Parameter == "L3").Value;
            double Xt           = _in.NumericalReadings.First(x => x.Parameter == "Xt").Value;
            double Xl           = _in.NumericalReadings.First(x => x.Parameter == "Xl").Value;
            double Do           = _in.NumericalReadings.First(x => x.Parameter == "Do").Value;
            double Di           = _in.NumericalReadings.First(x => x.Parameter == "Di").Value;
            double DelH         = _in.NumericalReadings.First(x => x.Parameter == "DelH").Value;
            double FinThickness = _in.NumericalReadings.First(x => x.Parameter == "FinThickness").Value;

            double QWaterInitial = _in.NumericalReadings.First(x => x.Parameter == "QWaterInitial").Value;
            double TWaterInitial = _in.NumericalReadings.First(x => x.Parameter == "TWaterInitial").Value;
            double PWaterInitial = _in.NumericalReadings.First(x => x.Parameter == "PWaterInitial").Value;

            double QAirInitial = _in.NumericalReadings.First(x => x.Parameter == "QAirInitial").Value;
            double TAirInitial = _in.NumericalReadings.First(x => x.Parameter == "TAirInitial").Value;
            double PAirInitial = _in.NumericalReadings.First(x => x.Parameter == "PAirInitial").Value;
            //double Nr = _in.NumericalReadings.First(x => x.Parameter == "Nr").Value;
            double FinPitch = _in.NumericalReadings.First(x => x.Parameter == "FinPitch").Value;

            double Nr = L3 / Xt;

            DensityWaterInitial = PWaterInitial / (287.04 * (TWaterInitial));
            DensityAirInitial   = PAirInitial / (287.04 * (TAirInitial));

            MassFlowWaterFinal = QWaterInitial * DensityWaterInitial;
            MassFlowAirFinal   = QAirInitial * DensityAirInitial;
            #endregion

            #region Iteration
            do
            {
                #region TMean calculation

                TWaterFinal     = TWaterInitial - Epsilon * (TWaterInitial - TAirInitial);
                TAirFinal       = TAirInitial + Epsilon * (MassFlowWaterFinal / MassFlowAirFinal) * (TWaterInitial - TAirInitial);
                TWaterMeanFinal = (TWaterFinal + TWaterInitial) / 2;
                TAirMeanFinal   = (TAirFinal + TAirInitial) / 2;

                #endregion

                prevvalAir   = TAirFinal;
                prevvalWater = TWaterFinal;

                #region CoolProp

                //Calculate additional properties
                ViscosityAir   = CoolProp.PropsSI("V", "T", TAirMeanFinal, "P", 101325, "Air");
                ViscosityWater = CoolProp.PropsSI("V", "T", TWaterMeanFinal, "P", 101325, "Water");
                CpAir          = CoolProp.PropsSI("CPMASS", "T", TWaterMeanFinal, "P", 101325, "Water");
                CpWater        = CoolProp.PropsSI("CPMASS", "T", TWaterMeanFinal, "P", 101325, "Water");
                PrandtlAir     = CoolProp.PropsSI("CPMASS", "T", TWaterMeanFinal, "P", 101325, "Water");
                PrandtlWater   = CoolProp.PropsSI("CPMASS", "T", TWaterMeanFinal, "P", 101325, "Water");

                #endregion

                #region Calculate G and Re

                G_Air = MassFlowAirFinal /
                        ((_in.SysType == SystemType.Inline)
                            ? _in.TubeOutsideInlineData.TotalMinFfArea
                            : _in.TubeOutsideStaggered.TotalMinFfArea);

                G_Water = MassFlowWaterFinal /
                          ((_in.SysType == SystemType.Inline)
                              ? _in.TubeOutsideInlineData.TotalMinFfArea
                              : _in.TubeOutsideStaggered.TotalMinFfArea);

                Reynolds_Air = G_Air * ((_in.SysType == SystemType.Inline)
                    ? _in.TubeOutsideInlineData.HydDiameter
                    : _in.TubeOutsideStaggered.HydDiameter) / ViscosityAir;

                Reynolds_Water = G_Water * ((_in.SysType == SystemType.Inline)
                    ? _in.TubeOutsideInlineData.HydDiameter
                    : _in.TubeOutsideStaggered.HydDiameter) / ViscosityWater;

                #endregion

                #region Calculation of J

                if (Nr <= 1)
                {
                    if (_in.SysType == SystemType.Inline)
                    {
                        double c1 = 1.9 - 0.23 * Math.Log(Reynolds_Water);
                        double c2 = -0.236 + 0.126 * Math.Log(Reynolds_Water);
                        J_Water = 0.108 * Math.Pow(Reynolds_Water, -0.29) * Math.Pow(Xt / Xl, c1) * Math.Pow(FinPitch / Do, 1.084) *
                                  Math.Pow(FinPitch / _in.TubeOutsideInlineData.HydDiameter, -0.786) *
                                  Math.Pow(FinPitch / Xt, c2);


                        c1    = 1.9 - 0.23 * Math.Log(Reynolds_Air);
                        c2    = -0.236 + 0.126 * Math.Log(Reynolds_Air);
                        J_Air = 0.108 * Math.Pow(Reynolds_Air, -0.29) * Math.Pow(Xt / Xl, c1) * Math.Pow(FinPitch / Do, 1.084) *
                                Math.Pow(FinPitch / _in.TubeOutsideInlineData.HydDiameter, -0.786) *
                                Math.Pow(FinPitch / Xt, c2);
                    }
                    else
                    {
                        double c1 = 1.9 - 0.23 * Math.Log(Reynolds_Water);
                        double c2 = -0.236 + 0.126 * Math.Log(Reynolds_Water);
                        J_Water = 0.108 * Math.Pow(Reynolds_Water, -0.29) * Math.Pow(Xt / Xl, c1) * Math.Pow(FinPitch / Do, 1.084) *
                                  Math.Pow(FinPitch / _in.TubeOutsideStaggered.HydDiameter, -0.786) *
                                  Math.Pow(FinPitch / Xt, c2);


                        c1    = 1.9 - 0.23 * Math.Log(Reynolds_Air);
                        c2    = -0.236 + 0.126 * Math.Log(Reynolds_Air);
                        J_Air = 0.108 * Math.Pow(Reynolds_Air, -0.29) * Math.Pow(Xt / Xl, c1) * Math.Pow(FinPitch / Do, 1.084) *
                                Math.Pow(FinPitch / _in.TubeOutsideStaggered.HydDiameter, -0.786) *
                                Math.Pow(FinPitch / Xt, c2);
                    }
                }
                else
                {
                    if (_in.SysType == SystemType.Inline)
                    {
                        //Water
                        double c3 = -0.361 - 0.042 * Nr / Math.Log(Reynolds_Water) +
                                    0.158 * Math.Log(Nr * Math.Pow(FinPitch / Do, 0.41));
                        double c4 = -1.224 -
                                    0.076 * Math.Pow(Xl / _in.TubeOutsideInlineData.HydDiameter, 1.42) /
                                    Math.Log(Reynolds_Water);
                        double c5 = -0.083 + 0.058 * Nr / Math.Log(Reynolds_Water);
                        double c6 = -5.735 + 1.21 * Math.Log(Reynolds_Water / Nr);
                        J_Water = 0.086 * Math.Pow(Reynolds_Water, c3) * Math.Pow(Nr, c4) * Math.Pow(FinPitch / Do, c5) *
                                  Math.Pow(FinPitch / _in.TubeOutsideInlineData.HydDiameter, c6) *
                                  Math.Pow(FinPitch / Xt, -0.93);
                        //Air
                        c3 = -0.361 - 0.042 * Nr / Math.Log(Reynolds_Air) + 0.158 * Math.Log(Nr * Math.Pow(FinPitch / Do, 0.41));
                        c4 = -1.224 -
                             0.076 * Math.Pow(Xl / _in.TubeOutsideInlineData.HydDiameter, 1.42) / Math.Log(Reynolds_Air);
                        c5    = -0.083 + 0.058 * Nr / Math.Log(Reynolds_Air);
                        c6    = -5.735 + 1.21 * Math.Log(Reynolds_Air / Nr);
                        J_Air = 0.086 * Math.Pow(Reynolds_Air, c3) * Math.Pow(Nr, c4) * Math.Pow(FinPitch / Do, c5) *
                                Math.Pow(FinPitch / _in.TubeOutsideInlineData.HydDiameter, c6) *
                                Math.Pow(FinPitch / Xt, -0.93);
                    }
                    else
                    {
                        //Water
                        double c3 = -0.361 - 0.042 * Nr / Math.Log(Reynolds_Water) +
                                    0.158 * Math.Log(Nr * Math.Pow(FinPitch / Do, 0.41));
                        double c4 = -1.224 -
                                    0.076 * Math.Pow(Xl / _in.TubeOutsideStaggered.HydDiameter, 1.42) /
                                    Math.Log(Reynolds_Water);
                        double c5 = -0.083 + 0.058 * Nr / Math.Log(Reynolds_Water);
                        double c6 = -5.735 + 1.21 * Math.Log(Reynolds_Water / Nr);
                        J_Water = 0.086 * Math.Pow(Reynolds_Water, c3) * Math.Pow(Nr, c4) * Math.Pow(FinPitch / Do, c5) *
                                  Math.Pow(FinPitch / _in.TubeOutsideStaggered.HydDiameter, c6) *
                                  Math.Pow(FinPitch / Xt, -0.93);
                        //Air
                        c3 = -0.361 - 0.042 * Nr / Math.Log(Reynolds_Air) + 0.158 * Math.Log(Nr * Math.Pow(FinPitch / Do, 0.41));
                        c4 = -1.224 -
                             0.076 * Math.Pow(Xl / _in.TubeOutsideStaggered.HydDiameter, 1.42) / Math.Log(Reynolds_Air);
                        c5    = -0.083 + 0.058 * Nr / Math.Log(Reynolds_Air);
                        c6    = -5.735 + 1.21 * Math.Log(Reynolds_Air / Nr);
                        J_Air = 0.086 * Math.Pow(Reynolds_Air, c3) * Math.Pow(Nr, c4) * Math.Pow(FinPitch / Do, c5) *
                                Math.Pow(FinPitch / _in.TubeOutsideStaggered.HydDiameter, c6) * Math.Pow(FinPitch / Xt, -0.93);
                    }
                }

                #endregion

                #region H Calculation

                H_Water = J_Water * G_Water * CpWater / Math.Pow(PrandtlWater, (double)2 / 3);
                H_Air   = J_Air * G_Air * CpAir / Math.Pow(PrandtlAir, (double)2 / 3);

                #endregion

                #region F Calculation

                c7      = -0.764 + 0.739 * Xt / Xl + 0.177 * FinPitch / Do - 0.00758 / Nr;
                c8      = -15.689 + 64.021 / Math.Log(Reynolds_Water);
                c9      = 1.696 - 15.695 / Math.Log(Reynolds_Water);
                F_Water = 0.0267 * Math.Pow(Reynolds_Water, c7) * Math.Pow(Xt / Xl, c8) * Math.Pow(FinPitch / Do, c9);

                c7    = -0.764 + 0.739 * Xt / Xl + 0.177 * FinPitch / Do - 0.00758 / Nr;
                c8    = -15.689 + 64.021 / Math.Log(Reynolds_Air);
                c9    = 1.696 - 15.695 / Math.Log(Reynolds_Air);
                F_Air = 0.0267 * Math.Pow(Reynolds_Air, c7) * Math.Pow(Xt / Xl, c8) * Math.Pow(FinPitch / Do, c9);

                #endregion

                #region Fin Efficiency

                VelocityAir = QAirInitial / (L1 * L3 - Nr * L1 * Do);
                if (VelocityAir <= 15 && VelocityAir >= 6)
                {
                    MessageBox.Show("Velocity should be between 6m/s and 15m/s", "Input out of limits");
                    return;
                }

                FinEfficiency = 7.41 * Math.Pow(VelocityAir, -0.12) *
                                Math.Pow(Xt / (2 * FinThickness), -2.32) * Math.Pow(Xl / (2 * FinThickness), -0.198);

                OverallEfficiency = 1 - ((1 - FinEfficiency) * (L2 * L3 - _in.Nt * Math.PI * Do * Do) /
                                         ((_in.SysType == SystemType.Inline)
                                             ? _in.TubeOutsideInlineData.TotalHeatArea
                                             : _in.TubeOutsideStaggered.TotalHeatArea));

                Rw = (Do - Di) / (_in.MaterialCoeff * (_in.Nt + 1) * 2 * L1 * L2);

                #endregion

                #region UA Calculation


                if (_in.SysType == SystemType.Inline)
                {
                    UaInverse = Rw + (1 / (OverallEfficiency * H_Water * _in.TubeOutsideInlineData.TotalHeatArea)) +
                                (1 / (OverallEfficiency * H_Air * _in.TubeOutsideInlineData.TotalHeatArea));
                }
                else
                {
                    UaInverse = Rw + (1 / (OverallEfficiency * H_Water * _in.TubeOutsideStaggered.TotalHeatArea)) +
                                (1 / (OverallEfficiency * H_Air * _in.TubeOutsideStaggered.TotalHeatArea));
                }

                C_Water = MassFlowWaterFinal * CpWater;
                C_Air   = MassFlowAirFinal * CpAir;
                C_Min   = Math.Min(C_Air, C_Water);
                C_Star  = (C_Water / C_Air);
                if (C_Star > 1)
                {
                    C_Star = 1 / C_Star;
                }

                NTU = 1 / (UaInverse * C_Min);

                #endregion

                epsilon             = FactorialCompute(25, NTU, C_Star);
                ConductionAreaWater = _in.Nt * Math.PI * Di * L1;
                ConductionAreaAir   = _in.Nt * Math.PI * Do * L1;

                lambdaAir   = _in.MaterialCoeff * ConductionAreaAir / (L1 * C_Air);
                lambdaWater = _in.MaterialCoeff * ConductionAreaWater / (L1 * C_Water);

                M1 = H_Air / H_Water;
                M2 = lambdaWater / lambdaAir;

                XPlatHelper.OpenImageTables();


                while (true)
                {
                    UserInputDialog userInput = new UserInputDialog("Enter Delta(Epsilon)/Epsilon");
                    userInput.ShowDialog();
                    if (!string.IsNullOrWhiteSpace(userInput.Answer))
                    {
                        double x;
                        if (double.TryParse(userInput.Answer, out x))
                        {
                            EpsilonRatio = x;
                            break;
                        }
                    }
                }

                deltaEpsilon  = EpsilonRatio * Epsilon;
                ActualEpsilon = Epsilon - deltaEpsilon;

                HeatTransferRate = ActualEpsilon * (TAirInitial - TWaterInitial) * C_Min;

                TWaterFinal = prevvalWater - HeatTransferRate / C_Water;
                TAirFinal   = prevvalAir - HeatTransferRate / C_Air;
            } while (!((Math.Abs((prevvalWater - TWaterFinal) / prevvalWater) < 0.05) &&
                       (Math.Abs((prevvalAir - TAirFinal) / prevvalAir) < 0.05)));
            #endregion

            {
                double TMeanAir     = (TAirInitial + TAirFinal) / 2;
                double TMeanWater   = (TWaterInitial + TWaterFinal) / 2;
                double RoFinalAir   = (PAirInitial / 287.04) / TAirFinal;
                double RoFinalWater = (PWaterInitial / 287.04) / TWaterFinal;
                double RoMeanAir    = 2 * RoFinalAir * DensityAirInitial / (RoFinalAir + DensityAirInitial);
                double RoMeanWater  = 2 * RoFinalWater * DensityWaterInitial / (RoFinalWater + DensityWaterInitial);
                double RhFinal      = (_in.SysType == SystemType.Inline)
                    ? _in.TubeOutsideInlineData.TotalMinFfArea
                    : _in.TubeOutsideStaggered.TotalMinFfArea;
                RhFinal /= 2;
                double GAirFinal = MassFlowAirFinal / ((_in.SysType == SystemType.Inline)
                    ? _in.TubeOutsideInlineData.TotalMinFfArea
                    : _in.TubeOutsideStaggered.TotalMinFfArea);
                double GWaterFinal = MassFlowWaterFinal / ((_in.SysType == SystemType.Inline)
                    ? _in.TubeOutsideInlineData.TotalMinFfArea
                    : _in.TubeOutsideStaggered.TotalMinFfArea);

                XPlatHelper.OpenFinalTable();
                double Kc, Ke;
                while (true)
                {
                    UserInputDialog userInput = new UserInputDialog("Enter Kc");
                    userInput.ShowDialog();
                    if (!string.IsNullOrWhiteSpace(userInput.Answer))
                    {
                        double x;
                        if (double.TryParse(userInput.Answer, out x))
                        {
                            Kc = x;
                            break;
                        }
                    }
                }
                while (true)
                {
                    UserInputDialog userInput = new UserInputDialog("Enter Ke");
                    userInput.ShowDialog();
                    if (!string.IsNullOrWhiteSpace(userInput.Answer))
                    {
                        double x;
                        if (double.TryParse(userInput.Answer, out x))
                        {
                            Ke = x;
                            break;
                        }
                    }
                }

                double Sigma = (_in.SysType == SystemType.Inline)
                    ? _in.TubeOutsideInlineData.RatioFfFrontalArea
                    : _in.TubeOutsideStaggered.RatioFfFrontalArea;

                double delPAir =
                    Math.Pow(GAirFinal, 2) / (2 * DensityAirInitial) * (
                        (1 - Sigma * Sigma + Kc) + 2 * (DensityAirInitial / RoFinalAir - 1) +
                        (F_Air * L1 / RhFinal * DensityAirInitial / RoMeanAir)
                        - (1 - Sigma * Sigma - Ke * DensityAirInitial / RoFinalAir));

                double delPWater =
                    Math.Pow(GWaterFinal, 2) / (2 * DensityWaterInitial) * (
                        (1 - Sigma * Sigma + Kc) + 2 * (DensityWaterInitial / RoFinalWater - 1) +
                        (F_Water * L1 / RhFinal * DensityWaterInitial / RoMeanWater)
                        - (1 - Sigma * Sigma - Ke * DensityWaterInitial / RoFinalWater));

                AirX   = delPAir;
                WaterX = delPWater;
            }
        }