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); }
public MaterialStream FlashPZ() { FlashRoutines calc = new FlashRoutines(new Numerics.Solvers.Newton()); calc.CalculateZP(this); return(this); }
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); }
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(); } } }
public void FlashTrays() { var flash = new FlashRoutines(new Numerics.Solvers.Newton()); MaterialStream stageStream = new MaterialStream("Stage", System); var VIn = FindMaterialPort("VIn"); var LIn = FindMaterialPort("LIn"); for (int i = 0; i < NumberOfTrays; i++) { FlashCurrentStage(flash, stageStream, VIn, LIn, i); } for (int i = NumberOfTrays - 1; i >= 0; i--) { FlashCurrentStage(flash, stageStream, VIn, LIn, i); } }
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]); }
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); }
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 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(); }
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; } }
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); }
public PythonEnvironmentModule(IEventAggregator aggregator, IEntityManagerViewModel entityManager, IThermodynamicSystemImporter importer, IChartViewModelFactory chartFactory, IFlowsheetEntityEditorFactory flowsheetFactory, IPureComponentPropertyDatabase pureDB, IThermodynamicSystemViewModelFactory thermoEditorFactory ) { _aggregator = aggregator; _entityManager = entityManager; _importer = importer; _chartFactory = chartFactory; _flowsheetFactory = flowsheetFactory; _pyEngine = Python.CreateEngine(); _pyScope = _pyEngine.CreateScope(); _pureComponentDB = pureDB; _thermoEditorFactory = thermoEditorFactory; _pyScope.SetVariable("_host", this); _pyScope.SetVariable("Items", _entityManager); _pyEngine.SetSearchPaths(new List <string> { Environment.CurrentDirectory }); var pc = HostingHelpers.GetLanguageContext(_pyEngine) as PythonContext; var hooks = pc.SystemState.Get__dict__()["path_hooks"] as List; hooks.Clear(); Run("import sys"); Run("import clr"); Run("clr.AddReferenceToFile(\"OpenFMSL.Core.dll\")"); Run("clr.AddReferenceToFile(\"OpenFMSL.Contracts.dll\")"); Run("from OpenFMSL.Core.Expressions import *"); Run("from OpenFMSL.Core.Flowsheeting import *"); Run("from OpenFMSL.Core.Flowsheeting.Documentation import *"); Run("from OpenFMSL.Core.Numerics import *"); Run("from OpenFMSL.Core.Numerics.Solvers import *"); Run("from OpenFMSL.Core.UnitsOfMeasure import *"); Run("from OpenFMSL.Core.ModelLibrary import *"); Run("from OpenFMSL.Core.Thermodynamics import *"); Run("from OpenFMSL.Contracts.Entities import *"); Run("from OpenFMSL.Contracts.Infrastructure.Reporting import *"); Run("from System import Math"); Run("sys.stdout=_host"); Run("runFile= _host.RunFile"); Run("run= _host.RunEntity"); Run("pause= _host.WaitThread"); Run("CreateThermo= _host.LoadThermodynamicSystem"); _pureComponentDB.SetLogCallback(Write); ipopt = new IpoptSolver(); ipopt.OnLog = (x) => Write(" " + x + Environment.NewLine); _pyScope.SetVariable("_ipopt", ipopt); _pyScope.SetVariable("Database", _pureComponentDB); newton = new Newton(); newton.OnLog = (x) => Write(" " + x + Environment.NewLine); newton.OnLogDebug = (x) => Write(x + Environment.NewLine); newton.OnLogError = (x) => Write("!!! " + x + Environment.NewLine); newton.OnLogSuccess = (x) => Write("+++ " + x + Environment.NewLine); newton.OnLogWarning = (x) => Write("*** " + x + Environment.NewLine); newton.OnLogInfo = (x) => Write("--- " + x + Environment.NewLine); _pyScope.SetVariable("_newton", newton); var flash = new FlashRoutines(newton); _pyScope.SetVariable("_flash", flash); decomp = new Decomposer(); decomp.OnLog = (x) => Write(" " + x + Environment.NewLine); decomp.OnLogDebug = (x) => Write(x + Environment.NewLine); decomp.OnLogError = (x) => Write("!!! " + x + Environment.NewLine); decomp.OnLogSuccess = (x) => Write("+++ " + x + Environment.NewLine); decomp.OnLogWarning = (x) => Write("*** " + x + Environment.NewLine); decomp.OnLogInfo = (x) => Write("--- " + x + Environment.NewLine); _pyScope.SetVariable("_decomp", decomp); Run("solve= _host.Solve"); Run("decomp= _host.Decompose"); Run("report= _host.Report"); Run("show= _host.Show"); Run("check= _host.Check"); Run("info= _host.SendLogMessage"); Run("warn= _host.SendWarningMessage"); Run("error= _host.SendErrorMessage"); Run("FlashPT= _flash.CalculateTP"); Run("FlashPZ= _flash.CalculateZP"); Run("status= _host.SendStatusTextChangeMessage"); Run("print 'Python console running..."); }