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