예제 #1
0
        //
        //     returns the total mols in a gas mixture of o2, he, n2 by solving Van der Waals equation
        //     given pressure, volume and temperature in Celsius
        //
        public static double vdw_solve_mols(
            double pressure,
            double volume,
            double o2_f,
            double he_f,
            double n2_f,
            double temperature)
        {
            var temp_K = temperature + 273.0;
            var _tup_1 = vdw_mix_ab(o2_f, he_f, n2_f);
            var mix_a  = _tup_1.Item1;
            var mix_b  = _tup_1.Item2;
            var seed_n = ideal_gas_n(pressure, volume, temp_K);

            // fsolve not available, as we do not have scipy library in C# as such
            // var solved_n = fsolve(van_der_waals_n, seed_n, (pressure, volume, temp_K, mix_a, mix_b));

            // instead use algorithms at RootFinding.cs moduel, reused from
            // https://www.codeproject.com/Articles/79541/Three-Methods-for-Root-finding-in-C
            VdW_eqation vdw_eq = new VdW_eqation(p: pressure, n: seed_n, V: volume, T: temp_K, a: mix_a, b: mix_b);
            //TODO: add try cath exception here
            double solved_n = RootFinding.Bisect(vdw_eq.solve_mols, seed_n * 0.6, seed_n * 1.5, 0.001, 0.1);


            return(solved_n);
        }
예제 #2
0
        //
        //     returns the pressure of a gas mixture of o2, he, n2 by solving Van der Waals equation
        //     given mols, volume and temperature in Celsius
        //
        public static double vdw_solve_pressure(
            double mols,
            double volume,
            double o2_f,
            double he_f,
            double n2_f,
            double temperature)
        {
            double temp_K   = temperature + 273.0;
            var    _tup_1   = vdw_mix_ab(o2_f, he_f, n2_f);
            double mix_a    = _tup_1.Item1;
            double mix_b    = _tup_1.Item2;
            double seed_p   = ideal_gas_p(n: mols, V: volume, T: temp_K);
            double solved_p = 0;

            // fsolve not available, as we do not have scipy library in C# as such
            // var solved_p = fsolve(van_der_waals_p, seed_p, (mols, volume, temp_K, mix_a, mix_b));

            // instead use algorithms at RootFinding.cs module, reused from
            // https://www.codeproject.com/Articles/79541/Three-Methods-for-Root-finding-in-C
            VdW_eqation vdw_eq = new VdW_eqation(p: seed_p, n: mols, V: volume, T: temp_K, a: mix_a, b: mix_b);

            try
            {
                solved_p = RootFinding.Bisect(vdw_eq.solve_pressure, seed_p * 0.6, seed_p * 1.5, 0.001, 0.1);
            }
            catch (Exception e)
            {
                solved_p = -1;
                Console.WriteLine(e.Message);
            }

            return(solved_p);
        }