Esempio n. 1
0
        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);
        }
Esempio n. 2
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);
        }
Esempio n. 3
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();
        }