コード例 #1
0
ファイル: FlashRoutines.cs プロジェクト: shao130/OpenFMSL
        public bool CalculatePQ(MaterialStream stream, double enthalpy)
        {
            var copy = new MaterialStream("copy", stream.System);

            copy.CopyFrom(stream);

            PrecalculateTP(copy);

            var problem2 = new EquationSystem()
            {
                Name = "PQ-Flash"
            };

            copy.GetVariable("p").IsFixed  = true;
            copy.GetVariable("T").IsFixed  = false;
            copy.GetVariable("VF").IsFixed = false;
            copy.Init("VF", stream.Vfmolar.ValueInSI);
            foreach (var comp in stream.System.Components)
            {
                copy.GetVariable("n[" + comp.ID + "]").IsFixed = true;
            }
            problem2.AddConstraints((copy.Mixed.SpecificEnthalpy * copy.Mixed.TotalMolarflow).IsEqualTo(enthalpy));
            copy.FillEquationSystem(problem2);

            var solver = new Decomposer();

            solver.Solve(problem2);

            performMassBalance(copy, copy.KValues);
            performDensityUpdate(copy);
            performEnthalpyUpdate(copy);

            stream.CopyFrom(copy);
            return(true);
        }
コード例 #2
0
        void RedrawBinaryAnalysisCharts()
        {
            var chart = new ChartModel();

            chart.Title      = SelectedBinaryAnalysis.ToString() + " [" + BinaryComponent1.ID + " /" + BinaryComponent2.ID + "]";
            chart.XAxisTitle = "Molar Composition " + BinaryComponent1.ID + " [mol/mol]";

            chart.XMin       = 0;
            chart.XMax       = 1;
            chart.AutoScaleY = true;
            int steps = 31;

            List <double> y1Values = new List <double>();
            List <double> y2Values = new List <double>();
            List <double> x1Values = new List <double>();
            List <double> x2Values = new List <double>();

            var eval = new Evaluator();

            var stream = new MaterialStream("S1", CurrentSystem);

            foreach (var comp in CurrentSystem.Components)
            {
                if (comp != BinaryComponent1 && comp != BinaryComponent2)
                {
                    stream.Specify("n[" + comp.ID + "]", 0.0);
                }
            }
            var solver    = new Newton();
            var flashAlgo = new FlashRoutines(solver);


            switch (SelectedBinaryAnalysis)
            {
            case BinaryAnalysisType.PXY:
            {
                chart.YAxisTitle     = "Pressure [mbar]";
                chart.Title         += " at " + TemperatureForPX + " °C";
                chart.LegendPosition = LegendPosition.TopLeft;
                stream.Specify("T", TemperatureForPX, METRIC.C);
                stream.Specify("p", 1000, METRIC.mbar);
                stream.Specify("n[" + BinaryComponent1.ID + "]", 0.0);
                stream.Specify("n[" + BinaryComponent2.ID + "]", 1.0);

                flashAlgo.CalculateTP(stream);
                stream.Unspecify("p");
                stream.Specify("VF", 0);
                var equationSystem = GetEquationSystem(stream);

                for (int i = 0; i < steps; i++)
                {
                    var x1 = (double)i / (double)(steps - 1);
                    var x2 = 1.0 - x1;

                    stream.Specify("n[" + BinaryComponent1.ID + "]", x1);
                    stream.Specify("n[" + BinaryComponent2.ID + "]", x2);

                    solver.Solve(equationSystem);
                    eval.Reset();

                    x1Values.Add(x1);
                    y1Values.Add(stream.GetVariable("p").ValueInSI / 100.0);
                }
                stream.Specify("VF", 1);

                for (int i = 0; i < steps; i++)
                {
                    var x1 = (double)i / (double)(steps - 1);
                    var x2 = 1.0 - x1;

                    stream.Specify("n[" + BinaryComponent1.ID + "]", x1);
                    stream.Specify("n[" + BinaryComponent2.ID + "]", x2);
                    solver.Solve(equationSystem);
                    eval.Reset();
                    x2Values.Add(x1);
                    y2Values.Add(stream.GetVariable("p").ValueInSI / 100.0);
                }
            }
            break;

            case BinaryAnalysisType.TXY:
            {
                chart.YAxisTitle     = "Temperature [°C]";
                chart.Title         += " at " + PressureForTX + " mbar";
                chart.LegendPosition = LegendPosition.TopRight;
                stream.Specify("T", 25, METRIC.C);
                stream.Specify("p", PressureForTX, METRIC.mbar);
                stream.Specify("n[" + BinaryComponent1.ID + "]", 0.0);
                stream.Specify("n[" + BinaryComponent2.ID + "]", 1.0);

                flashAlgo.CalculateTP(stream);
                stream.Unspecify("T");
                stream.Specify("VF", 0);
                var equationSystem = GetEquationSystem(stream);

                for (int i = 0; i < steps; i++)
                {
                    var x1 = (double)i / (double)(steps - 1);
                    var x2 = 1.0 - x1;
                    stream.Specify("VF", 0);
                    stream.Specify("n[" + BinaryComponent1.ID + "]", x1);
                    stream.Specify("n[" + BinaryComponent2.ID + "]", x2);

                    solver.Solve(equationSystem);
                    eval.Reset();

                    x1Values.Add(x1);
                    y1Values.Add(stream.GetVariable("T").ValueInSI - 273.15);

                    stream.Specify("VF", 1.0);
                    solver.Solve(equationSystem);
                    eval.Reset();
                    x2Values.Add(x1);
                    y2Values.Add(stream.GetVariable("T").ValueInSI - 273.150);
                }
            }
            break;

            case BinaryAnalysisType.XY:
            {
                chart.YAxisTitle     = "Molar Composition Vapor [mol/mol]";
                chart.Title         += " at " + PressureForTX + " mbar";
                chart.LegendPosition = LegendPosition.TopLeft;

                stream.Specify("T", 25, METRIC.C);
                stream.Specify("p", PressureForTX, METRIC.mbar);
                stream.Specify("n[" + BinaryComponent1.ID + "]", 0.0);
                stream.Specify("n[" + BinaryComponent2.ID + "]", 1.0);

                flashAlgo.CalculateTP(stream);
                stream.Specify("VF", 0);
                stream.Unspecify("T");
                var equationSystem = GetEquationSystem(stream);


                for (int i = 0; i < steps; i++)
                {
                    var x1 = (double)i / (double)(steps - 1);
                    var x2 = 1.0 - x1;
                    stream.Specify("n[" + BinaryComponent1.ID + "]", x1);
                    stream.Specify("n[" + BinaryComponent2.ID + "]", x2);
                    solver.Solve(equationSystem);
                    eval.Reset();
                    x1Values.Add(x1);
                    y1Values.Add(stream.GetVariable("xV[" + BinaryComponent1.ID + "]").ValueInSI);
                    x2Values.Add(x2);
                    y2Values.Add(stream.GetVariable("xV[" + BinaryComponent2.ID + "]").ValueInSI);
                }
            }
            break;
            }



            var ySeries1 = new SeriesModel(BinaryComponent1.ID, SeriesType.Line, x1Values, y1Values, "Red");
            var ySeries2 = new SeriesModel(BinaryComponent2.ID, SeriesType.Line, x2Values, y2Values, "Blue");

            chart.Series.Add(ySeries1);
            chart.Series.Add(ySeries2);
            BinaryAnalysisChart = _chartFactory.Create(chart);
        }