示例#1
0
        private void FlashCurrentStage(FlashRoutines flash, MaterialStream stageStream, Port <MaterialStream> VIn, Port <MaterialStream> LIn, int i)
        {
            stageStream.Mixed.Temperature.ValueInSI = _trays[i].T.ValueInSI;
            stageStream.Mixed.Pressure.ValueInSI    = _trays[i].p.ValueInSI;
            var enthsum = 0.0;

            if (i > 0)
            {
                enthsum += _trays[i - 1].L.ValueInSI * _trays[i - 1].HL.ValueInSI;
            }
            else
            {
                enthsum += LIn.Streams[0].Mixed.TotalMolarflow.ValueInSI * LIn.Streams[0].Mixed.SpecificEnthalpy.ValueInSI;
            }

            if (i < NumberOfTrays - 1)
            {
                enthsum += _trays[i + 1].V.ValueInSI * _trays[i + 1].HV.ValueInSI;
            }
            else
            {
                enthsum += VIn.Streams[0].Mixed.TotalMolarflow.ValueInSI * VIn.Streams[0].Mixed.SpecificEnthalpy.ValueInSI;
            }
            enthsum += _trays[i].F.ValueInSI * _trays[i].HF.ValueInSI;

            for (int j = 0; j < System.Components.Count; j++)
            {
                var flowsum = 0.0;

                if (i > 0)
                {
                    flowsum += _trays[i - 1].L.ValueInSI * _trays[i - 1].x[j].ValueInSI;
                }
                else
                {
                    flowsum += LIn.Streams[0].Mixed.ComponentMolarflow[j].ValueInSI;
                }

                flowsum += _trays[i].F.ValueInSI * _trays[i].z[j].ValueInSI;

                if (i < NumberOfTrays - 1)
                {
                    flowsum += _trays[i].V.ValueInSI * _trays[i].y[j].ValueInSI;
                }
                else
                {
                    flowsum += VIn.Streams[0].Mixed.ComponentMolarflow[j].ValueInSI;
                }

                stageStream.Mixed.ComponentMolarflow[j].ValueInSI = flowsum;
            }

            //stageStream.Mixed. = enthsum ;

            //stageStream.Vfmolar.ValueInSI = 0.5;
            //flash.CalculateZP(stageStream);
            flash.CalculatePQ(stageStream, enthsum);

            _trays[i].V.ValueInSI = stageStream.Vapor.TotalMolarflow.ValueInSI;
            _trays[i].L.ValueInSI = stageStream.Liquid.TotalMolarflow.ValueInSI;

            for (int j = 0; j < System.Components.Count; j++)
            {
                _trays[i].y[j].ValueInSI = stageStream.Vapor.ComponentMolarFraction[j].ValueInSI;
                _trays[i].x[j].ValueInSI = stageStream.Liquid.ComponentMolarFraction[j].ValueInSI;
            }
        }
示例#2
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);
        }
示例#3
0
        public override ProcessUnit Initialize()
        {
            int NC    = System.Components.Count;
            var In    = FindMaterialPort("In");
            var Vap   = FindMaterialPort("Vap");
            var Liq   = FindMaterialPort("Liq");
            var flash = new FlashRoutines(new Numerics.Solvers.Newton());

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

            flashStream.CopyFrom(In.Streams[0]);



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

            if (T.IsFixed)
            {
                flashStream.Specify("T", T.ValueInSI);
            }
            else
            {
                flashStream.Specify("T", In.Streams[0].Mixed.Temperature.ValueInSI);
            }

            if (VF.IsFixed)
            {
                flashStream.Specify("VF", VF.ValueInSI);
            }
            else
            {
                flashStream.Specify("VF", In.Streams[0].Vfmolar.ValueInSI);
            }

            if (T.IsFixed && p.IsFixed)
            {
                flash.CalculateTP(flashStream);
            }
            else if (VF.IsFixed && p.IsFixed)
            {
                flash.CalculateZP(flashStream);
            }
            else if (Q.IsFixed && p.IsFixed)
            {
                flashStream.Init("VF", In.Streams[0].GetVariable("VF").ValueInSI);
                flashStream.Init("T", In.Streams[0].GetVariable("T").ValueInSI);
                flash.CalculatePQ(flashStream, In.Streams[0].Mixed.SpecificEnthalpy.ValueInSI * In.Streams[0].Mixed.TotalMolarflow.ValueInSI);
            }
            else if (Q.IsFixed)
            {
                flashStream.Init("VF", In.Streams[0].GetVariable("VF").ValueInSI);
                flashStream.Init("T", In.Streams[0].GetVariable("T").ValueInSI);
                flash.CalculatePQ(flashStream, In.Streams[0].Mixed.SpecificEnthalpy.ValueInSI * In.Streams[0].Mixed.TotalMolarflow.ValueInSI);
            }
            else
            {
                flash.CalculateTP(flashStream);
            }

            // p.ValueInSI = In.Streams[0].Mixed.Pressure.ValueInSI;
            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);
            }
            if (!VF.IsFixed)
            {
                VF.ValueInSI = flashStream.Vfmolar.ValueInSI;
            }

            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);
        }