コード例 #1
0
        void InitOutlets()
        {
            int NC = System.Components.Count;



            var VOut = FindMaterialPort("VOut");
            var LOut = FindMaterialPort("LOut");

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

            LOut.Streams[0].Mixed.Temperature.ValueInSI = _trays[NumberOfTrays - 1].T.ValueInSI;
            LOut.Streams[0].Mixed.Pressure.ValueInSI    = _trays[NumberOfTrays - 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[NumberOfTrays - 1].L.ValueInSI * _trays[NumberOfTrays - 1].x[j].ValueInSI;
            }
            var flash = new FlashRoutines(new Numerics.Solvers.Newton());

            VOut.Streams[0].Vfmolar.ValueInSI = 1.0;
            LOut.Streams[0].Vfmolar.ValueInSI = 0.0;
            flash.CalculateZP(VOut.Streams[0]);
            flash.CalculateZP(LOut.Streams[0]);


            // VOut.Streams[0].State = PhaseState.DewPoint;
            LOut.Streams[0].State = PhaseState.BubblePoint;

            foreach (var feed in _sidestream)
            {
                if (feed.Phase == PhaseState.Liquid)
                {
                    _trays[feed.Stage - 1].RL.ValueInSI = feed.Factor.ValueInSI;
                    _trays[feed.Stage - 1].W.ValueInSI  = (_trays[feed.Stage - 1].RL.ValueInSI * _trays[feed.Stage - 1].L.ValueInSI);

                    feed.Stream.Mixed.Temperature.ValueInSI    = _trays[feed.Stage - 1].T.ValueInSI;
                    feed.Stream.Mixed.Pressure.ValueInSI       = _trays[feed.Stage - 1].p.ValueInSI;
                    feed.Stream.Mixed.TotalMolarflow.ValueInSI = _trays[feed.Stage - 1].W.ValueInSI;
                    for (var comp = 0; comp < NC; comp++)
                    {
                        feed.Stream.Mixed.ComponentMolarflow[comp].ValueInSI = _trays[feed.Stage - 1].x[comp].ValueInSI * _trays[feed.Stage - 1].W.ValueInSI;
                    }
                    feed.Stream.FlashPT();
                }
            }
        }
コード例 #2
0
        public MaterialStream FlashPZ()
        {
            FlashRoutines calc = new FlashRoutines(new Numerics.Solvers.Newton());

            calc.CalculateZP(this);
            return(this);
        }
コード例 #3
0
ファイル: Heater.cs プロジェクト: shao130/OpenFMSL
        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);
        }
コード例 #4
0
        void InitRectifaction()
        {
            int NC          = System.Components.Count;
            var In          = FindMaterialPort("Feeds");
            var VIn         = FindMaterialPort("VIn");
            var LIn         = FindMaterialPort("LIn");
            var VOut        = FindMaterialPort("VOut");
            var LOut        = FindMaterialPort("LOut");
            var Sidestreams = FindMaterialPort("Sidestreams");

            var TTop = LIn.Streams[0].Mixed.Temperature.ValueInSI;
            var TBot = VIn.Streams[0].Mixed.Temperature.ValueInSI;

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

            var feedcopy = new MaterialStream("FC", In.Streams[0].System);

            feedcopy.CopyFrom(In.Streams[0]);
            feedcopy.Vfmolar.ValueInSI = 0.01;
            flash1.CalculateZP(feedcopy);
            TTop = feedcopy.Mixed.Temperature.ValueInSI;
            feedcopy.Vfmolar.ValueInSI = 0.99;
            flash1.CalculateZP(feedcopy);
            TBot = feedcopy.Mixed.Temperature.ValueInSI;

            foreach (var feed in _feeds)
            {
                _trays[feed.Stage - 1].HF.ValueInSI  = feed.Stream.Mixed.SpecificEnthalpy.ValueInSI;
                _trays[feed.Stage - 1].F.ValueInSI   = feed.Stream.Mixed.TotalMolarflow.ValueInSI;
                _trays[feed.Stage - 1].HF.IsConstant = false;
                _trays[feed.Stage - 1].F.IsConstant  = false;
                for (var comp = 0; comp < NC; comp++)
                {
                    _trays[feed.Stage - 1].z[comp].ValueInSI  = feed.Stream.Mixed.ComponentMolarFraction[comp].ValueInSI;
                    _trays[feed.Stage - 1].z[comp].IsConstant = false;
                }
            }

            for (int i = 0; i < NumberOfTrays; i++)
            {
                _trays[i].T.ValueInSI  = TTop + (TBot - TTop) / (double)(NumberOfTrays - 1) * i;
                _trays[i].TV.ValueInSI = TTop + (TBot - TTop) / (double)(NumberOfTrays - 1) * i;
                if (i == 0)
                {
                    _trays[i].L.ValueInSI = In.Streams[0].Mixed.TotalMolarflow.ValueInSI * 0.5;// + LIn.Streams[0].Mixed.TotalMolarflow.ValueInSI;
                }
                else
                {
                    _trays[i].L.ValueInSI = _trays[i - 1].L.ValueInSI + _trays[i].F.ValueInSI;
                }

                _trays[i].V.ValueInSI = In.Streams[0].Mixed.TotalMolarflow.ValueInSI;// + VIn.Streams[0].Mixed.TotalMolarflow.ValueInSI;

                for (int j = 0; j < System.Components.Count; j++)
                {
                    _trays[i].x[j].ValueInSI   = _feeds[0].Stream.Mixed.ComponentMolarFraction[j].ValueInSI;
                    _trays[i].y[j].ValueInSI   = _feeds[0].Stream.Mixed.ComponentMolarFraction[j].ValueInSI;
                    _trays[i].yeq[j].ValueInSI = _feeds[0].Stream.Mixed.ComponentMolarFraction[j].ValueInSI;
                }
            }

            for (int i = NumberOfTrays - 1; i >= 0; i--)
            {
                if (i < NumberOfTrays - 1)
                {
                    _trays[i].p.ValueInSI = _trays[i + 1].p.ValueInSI - _trays[i + 1].DP.ValueInSI;
                }
                else
                {
                    _trays[i].p.ValueInSI = VIn.Streams[0].Mixed.Pressure.ValueInSI;
                }
            }

            InitOutlets();
        }
コード例 #5
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);
        }