示例#1
0
        public override ProcessUnit Initialize()
        {
            var In   = FindMaterialPort("In");
            var Out1 = FindMaterialPort("Out1");
            var Out2 = FindMaterialPort("Out2");
            int NC   = System.Components.Count;


            p.ValueInSI = In.Streams[0].Mixed.Pressure.ValueInSI;
            var eval = new Evaluator();

            for (int i = 0; i < NC; i++)
            {
                Out1.Streams[0].Mixed.ComponentMolarflow[i].ValueInSI = ((SplitFactor) * Sym.Sum(0, In.NumberOfStreams, (j) => In.Streams[j].Mixed.ComponentMolarflow[i])).Eval(eval);
                Out2.Streams[0].Mixed.ComponentMolarflow[i].ValueInSI = ((1 - SplitFactor) * Sym.Sum(0, In.NumberOfStreams, (j) => In.Streams[j].Mixed.ComponentMolarflow[i])).Eval(eval);
            }

            Out1.Streams[0].Mixed.Temperature.ValueInSI = In.Streams[0].Mixed.Temperature.ValueInSI;
            Out2.Streams[0].Mixed.Temperature.ValueInSI = In.Streams[0].Mixed.Temperature.ValueInSI;
            Out1.Streams[0].Mixed.Pressure.ValueInSI    = p.ValueInSI;
            Out2.Streams[0].Mixed.Pressure.ValueInSI    = p.ValueInSI;

            var flash = new FlashRoutines(new Numerics.Solvers.Newton());

            flash.CalculateTP(Out1.Streams[0]);
            flash.CalculateTP(Out2.Streams[0]);
            return(this);
        }
示例#2
0
        public override ProcessUnit Initialize()
        {
            var In  = FindMaterialPort("In");
            var Out = FindMaterialPort("Out");
            int NC  = System.Components.Count;

            if (!p.IsFixed)
            {
                p.ValueInSI = In.Streams[0].Mixed.Pressure.ValueInSI;
            }

            var eval = new Evaluator();

            for (int i = 0; i < NC; i++)
            {
                Out.Streams[0].Mixed.ComponentMolarflow[i].ValueInSI = Sym.Sum(0, In.NumberOfStreams, (j) => In.Streams[j].Mixed.ComponentMolarflow[i]).Eval(eval);
            }

            Out.Streams[0].Mixed.Temperature.ValueInSI = T.ValueInSI;
            Out.Streams[0].Mixed.Pressure.ValueInSI    = p.ValueInSI - dp.ValueInSI;
            Out.Streams[0].Vfmolar.ValueInSI           = In.Streams[0].Vfmolar.ValueInSI;


            var flash = new FlashRoutines(new Numerics.Solvers.Newton());

            if (T.IsFixed)
            {
                flash.CalculateTP(Out.Streams[0]);
            }

            Q.ValueInSI = -(In.Streams[0].Mixed.SpecificEnthalpy * In.Streams[0].Mixed.TotalMolarflow - Out.Streams[0].Mixed.SpecificEnthalpy * Out.Streams[0].Mixed.TotalMolarflow).Eval(eval);
            return(this);
        }
示例#3
0
        public MaterialStream FlashPT()
        {
            FlashRoutines calc = new FlashRoutines(new Numerics.Solvers.Newton());

            calc.CalculateTP(this);
            return(this);
        }
示例#4
0
        void InitOutlets()
        {
            int NC   = System.Components.Count;
            var VOut = FindMaterialPort("VOut");
            var LOut = FindMaterialPort("LOut");

            VOut.Streams[0].Mixed.Temperature.ValueInSI = _trays[0].TV.ValueInSI;
            VOut.Streams[0].Mixed.Pressure.ValueInSI    = _trays[0].p.ValueInSI - _trays[0].DP.ValueInSI;

            LOut.Streams[0].Mixed.Temperature.ValueInSI = _trays[NumberOfElements - 1].TL.ValueInSI;
            LOut.Streams[0].Mixed.Pressure.ValueInSI    = _trays[NumberOfElements - 1].p.ValueInSI;

            for (int j = 0; j < System.Components.Count; j++)
            {
                VOut.Streams[0].Mixed.ComponentMolarflow[j].ValueInSI = _trays[0].V.ValueInSI * _trays[0].y[j].ValueInSI;
                LOut.Streams[0].Mixed.ComponentMolarflow[j].ValueInSI = _trays[NumberOfElements - 1].L.ValueInSI * _trays[NumberOfElements - 1].x[j].ValueInSI;
            }
            var flash = new FlashRoutines(new Numerics.Solvers.Newton());

            flash.CalculateTP(VOut.Streams[0]);
            flash.CalculateTP(LOut.Streams[0]);
        }
示例#5
0
        public override ProcessUnit Initialize()
        {
            var In   = FindMaterialPort("In");
            var Out  = FindMaterialPort("Out");
            var Duty = FindHeatPort("Duty");
            int NC   = System.Components.Count;

            if (!p.IsFixed)
            {
                p.ValueInSI = In.Streams[0].Mixed.Pressure.ValueInSI;
            }

            var eval = new Evaluator();

            for (int i = 0; i < NC; i++)
            {
                Out.Streams[0].Mixed.ComponentMolarflow[i].ValueInSI = Sym.Sum(0, In.NumberOfStreams, (j) => In.Streams[j].Mixed.ComponentMolarflow[i]).Eval(eval);
            }


            if (ChemistryBlock != null)
            {
                foreach (var reac in ChemistryBlock.Reactions)
                {
                    foreach (var comp in reac.Stoichiometry)
                    {
                        if (Math.Abs(Out.Streams[0].Mixed.ComponentMolarflow[comp.Index].ValueInSI) < 1e-10 && Math.Abs(comp.StoichiometricFactor) > 1e-6)
                        {
                            Out.Streams[0].Mixed.ComponentMolarflow[comp.Index].ValueInSI = 1e-6;
                        }
                    }
                }
            }

            if (T.IsFixed)
            {
                Out.Streams[0].Mixed.Temperature.ValueInSI = T.ValueInSI;
            }
            else
            {
                Out.Streams[0].Mixed.Temperature.ValueInSI = In.Streams[0].Mixed.Temperature.ValueInSI;
            }

            Out.Streams[0].Mixed.Pressure.ValueInSI = p.ValueInSI - dp.ValueInSI;
            Out.Streams[0].Vfmolar.ValueInSI        = In.Streams[0].Vfmolar.ValueInSI;


            var flash = new FlashRoutines(new Numerics.Solvers.Newton());

            if (T.IsFixed)
            {
                flash.CalculateTP(Out.Streams[0]);
            }


            if (VF.IsFixed)
            {
                Out.Streams[0].Vfmolar.ValueInSI = VF.ValueInSI;
                flash.CalculateZP(Out.Streams[0]);
                Out.Streams[0].Vfmolar.FixValue(VF.ValueInSI);
                if (VF.ValueInSI == 0)
                {
                    Out.Streams[0].FixBubblePoint();
                }
                if (VF.ValueInSI == 1)
                {
                    Out.Streams[0].FixDewPoint();
                }
            }


            if (Q.IsFixed)
            {
                flash.CalculateTP(Out.Streams[0]);
                flash.CalculatePQ(Out.Streams[0], In.Streams[0].Mixed.SpecificEnthalpy.ValueInSI * In.Streams[0].Mixed.TotalMolarflow.ValueInSI);
            }
            else
            {
                if (Duty.IsConnected)
                {
                    if (Duty.Direction == PortDirection.In)
                    {
                        Duty.Streams[0].Q.ValueInSI = -(In.Streams[0].Mixed.SpecificEnthalpy * In.Streams[0].Mixed.TotalMolarflow - Out.Streams[0].Mixed.SpecificEnthalpy * Out.Streams[0].Mixed.TotalMolarflow).Eval(eval);
                    }
                    else
                    {
                        Duty.Streams[0].Q.ValueInSI = (In.Streams[0].Mixed.SpecificEnthalpy * In.Streams[0].Mixed.TotalMolarflow - Out.Streams[0].Mixed.SpecificEnthalpy * Out.Streams[0].Mixed.TotalMolarflow).Eval(eval);
                    }
                }
                else
                {
                    Q.ValueInSI = -(In.Streams[0].Mixed.SpecificEnthalpy * In.Streams[0].Mixed.TotalMolarflow - Out.Streams[0].Mixed.SpecificEnthalpy * Out.Streams[0].Mixed.TotalMolarflow).Eval(eval);
                }
            }



            return(this);
        }
示例#6
0
        public override ProcessUnit Initialize()
        {
            int NC  = System.Components.Count;
            var In  = FindMaterialPort("In");
            var Vap = FindMaterialPort("VOut");
            var Liq = FindMaterialPort("LOut");

            var VIN = FindMaterialPort("VIn");
            var LIN = FindMaterialPort("LIn");

            var flash = new FlashRoutines(new Numerics.Solvers.Newton());

            var flashStream = new MaterialStream("FLASH", System);

            flashStream.CopyFrom(In.Streams[0]);
            for (int i = 0; i < NC; i++)
            {
                flashStream.Mixed.ComponentMolarflow[i].ValueInSI += LIN.Streams[0].Mixed.ComponentMolarflow[i].ValueInSI + VIN.Streams[0].Mixed.ComponentMolarflow[i].ValueInSI;
            }

            if (p.IsFixed)
            {
                flashStream.Specify("p", p.ValueInSI);
            }
            else if (dp.IsFixed)
            {
                flashStream.Specify("p", In.Streams[0].Mixed.Pressure.ValueInSI - dp.ValueInSI);
            }

            flashStream.Specify("T", In.Streams[0].Mixed.Temperature.ValueInSI);
            flash.CalculateTP(flashStream);
            var eval = new Evaluator();

            for (int i = 0; i < NC; i++)
            {
                Vap.Streams[0].Mixed.ComponentMolarflow[i].ValueInSI = (flashStream.Vapor.ComponentMolarflow[i]).Eval(eval);
                Liq.Streams[0].Mixed.ComponentMolarflow[i].ValueInSI = (flashStream.Liquid.ComponentMolarflow[i]).Eval(eval);
            }

            if (T.IsFixed)
            {
                Vap.Streams[0].Mixed.Temperature.ValueInSI = T.ValueInSI;
                Liq.Streams[0].Mixed.Temperature.ValueInSI = T.ValueInSI;
            }
            else
            {
                Vap.Streams[0].Mixed.Temperature.ValueInSI = flashStream.Mixed.Temperature.ValueInSI;
                Liq.Streams[0].Mixed.Temperature.ValueInSI = flashStream.Mixed.Temperature.ValueInSI;
                T.ValueInSI = flashStream.Mixed.Temperature.ValueInSI;
            }

            if (p.IsFixed)
            {
                Vap.Streams[0].Mixed.Pressure.ValueInSI = p.ValueInSI;
                Liq.Streams[0].Mixed.Pressure.ValueInSI = p.ValueInSI;
            }
            else
            {
                Vap.Streams[0].Mixed.Pressure.ValueInSI = flashStream.Mixed.Pressure.ValueInSI;
                Liq.Streams[0].Mixed.Pressure.ValueInSI = flashStream.Mixed.Pressure.ValueInSI;
                p.ValueInSI = flashStream.Mixed.Pressure.ValueInSI;
            }

            if (!Q.IsFixed)
            {
                Q.ValueInSI = -(In.Streams[0].Mixed.SpecificEnthalpy * In.Streams[0].Mixed.TotalMolarflow - Liq.Streams[0].Mixed.SpecificEnthalpy * Liq.Streams[0].Mixed.TotalMolarflow - Vap.Streams[0].Mixed.SpecificEnthalpy * Vap.Streams[0].Mixed.TotalMolarflow).Eval(eval);
            }

            Vap.Streams[0].GetVariable("VF").SetValue(1);
            Liq.Streams[0].GetVariable("VF").SetValue(0);

            flash.CalculateTP(Vap.Streams[0]);
            flash.CalculateTP(Liq.Streams[0]);

            Vap.Streams[0].State = PhaseState.DewPoint;
            Liq.Streams[0].State = PhaseState.BubblePoint;

            return(this);
        }
        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);
        }