diff --git a/Simulator/BinaryPhaseEnvelope/NRTL.mo b/Simulator/BinaryPhaseEnvelope/NRTL.mo index cc33480..80622a3 100644 --- a/Simulator/BinaryPhaseEnvelope/NRTL.mo +++ b/Simulator/BinaryPhaseEnvelope/NRTL.mo @@ -4,52 +4,58 @@ package NRTL extends Modelica.Icons.ExamplesPackage; model NRTLmodel import Simulator.Files.ThermodynamicFunctions.*; - gammaNRTLmodel Gamma(NOC = NOC, comp = comp, molFrac = x[:], T = T); - Real density[NOC], BIPS[NOC, NOC, 2]; + parameter Integer Nc "Number of components"; + parameter Simulator.Files.ChemsepDatabase.GeneralProperties C[Nc] "Component instances array"; + gammaNRTLmodel Gamma(Nc = Nc, C = C, molFrac = x[:], T = T); + Real gamma[Nc]; + Real x[Nc]; + Real T(start = 300); + Real P; + Real K[Nc]; + Real density[Nc], BIPS[Nc, Nc, 2]; equation gamma = Gamma.gamma; BIPS = Gamma.BIPS; - for i in 1:NOC loop - density[i] = Dens(comp[i].LiqDen, comp[i].Tc, T, P); + for i in 1:Nc loop + density[i] = Dens(C[i].LiqDen, C[i].Tc, T, P); end for; - for i in 1:NOC loop - K[i] = gamma[i] * Psat(comp[i].VP, T) / P; + for i in 1:Nc loop + K[i] = gamma[i] * Psat(C[i].VP, T) / P; end for; end NRTLmodel; model gammaNRTLmodel - parameter Integer NOC; - parameter Simulator.Files.ChemsepDatabase.GeneralProperties comp[NOC]; - Real molFrac[NOC], T; - Real gamma[NOC]; - Real tau[NOC, NOC], G[NOC, NOC], alpha[NOC, NOC], A[NOC, NOC], BIPS[NOC, NOC, 2]; - Real sum1[NOC], sum2[NOC]; + parameter Integer Nc "Number of components"; + parameter Simulator.Files.ChemsepDatabase.GeneralProperties C[Nc] "Component instances array"; + Real molFrac[Nc], T(start = 300); + Real gamma[Nc]; + Real tau[Nc, Nc], G[Nc, Nc], alpha[Nc, Nc], A[Nc, Nc], BIPS[Nc, Nc, 2]; + Real sum1[Nc], sum2[Nc]; constant Real R = 1.98721; equation A = BIPS[:, :, 1]; alpha = BIPS[:, :, 2]; tau = A ./ (R * T); - for i in 1:NOC loop - for j in 1:NOC loop + for i in 1:Nc loop + for j in 1:Nc loop G[i, j] = exp(-alpha[i, j] * tau[i, j]); end for; end for; - for i in 1:NOC loop + for i in 1:Nc loop sum1[i] = sum(molFrac[:] .* G[:, i]); sum2[i] = sum(molFrac[:] .* tau[:, i] .* G[:, i]); end for; - for i in 1:NOC loop + for i in 1:Nc loop log(gamma[i]) = sum(molFrac[:] .* tau[:, i] .* G[:, i]) / sum(molFrac[:] .* G[:, i]) + sum(molFrac[:] .* G[i, :] ./ sum1[:] .* (tau[i, :] .- sum2[:] ./ sum1[:])); end for; end gammaNRTLmodel; model base - import data = Simulator.Files.ChemsepDatabase; - parameter Integer NOC; - parameter Real BIP[NOC, NOC, 2]; - parameter data.GeneralProperties comp[NOC]; + parameter Integer Nc; + parameter Real BIP[Nc, Nc, 2]; + parameter Simulator.Files.ChemsepDatabase.GeneralProperties C[Nc] "Component instances array"; extends NRTLmodel(BIPS = BIP); - Real P, T(start = 300), gamma[NOC], K[NOC], x[NOC](each start = 0.5), y[NOC]; + Real P, T(start = 300), gamma[Nc], K[Nc], x[Nc](each start = 0.5), y[Nc]; equation y[:] = K[:] .* x[:]; sum(x[:]) = 1; @@ -61,11 +67,11 @@ package NRTL import data = Simulator.Files.ChemsepDatabase; parameter data.Onehexene ohex; parameter data.Acetone acet; - parameter Integer NOC = 2; - parameter Real BIP[NOC, NOC, 2] = Simulator.Files.ThermodynamicFunctions.BIPNRTL(NOC, comp.CAS); - parameter data.GeneralProperties comp[NOC] = {ohex, acet}; - base points[41](each P = 1013250, each NOC = NOC, each comp = comp, each BIP = BIP); - Real x[41, NOC], y[41, NOC], T[41]; + parameter Integer Nc = 2; + parameter Real BIP[Nc, Nc, 2] = Simulator.Files.ThermodynamicFunctions.BIPNRTL(Nc, C.CAS); + parameter data.GeneralProperties C[Nc] = {ohex, acet}; + base points[41](each P = 1013250, each Nc = Nc, each C = C, each BIP = BIP); + Real x[41, Nc], y[41, Nc], T[41]; equation points[:].x = x; points[:].y = y; @@ -80,11 +86,11 @@ package NRTL import data = Simulator.Files.ChemsepDatabase; parameter data.Onehexene ohex; parameter data.Acetone acet; - parameter Integer NOC = 2; - parameter Real BIP[NOC, NOC, 2] = Simulator.Files.ThermodynamicFunctions.BIPNRTL(NOC, comp.CAS); - parameter data.GeneralProperties comp[NOC] = {ohex, acet}; - base points[41](each T = 424, each NOC = NOC, each comp = comp, each BIP = BIP); - Real x[41, NOC], y[41, NOC], P[41]; + parameter Integer Nc = 2; + parameter Real BIP[Nc, Nc, 2] = Simulator.Files.ThermodynamicFunctions.BIPNRTL(Nc, C.CAS); + parameter data.GeneralProperties C[Nc] = {ohex, acet}; + base points[41](each T = 424, each Nc = Nc, each C = C, each BIP = BIP); + Real x[41, Nc], y[41, Nc], P[41]; equation points[:].x = x; points[:].y = y; @@ -93,4 +99,4 @@ package NRTL x[i, 1] = 0 + (i - 1) * 0.025; end for; end Pxy; -end NRTL; +end NRTL; \ No newline at end of file diff --git a/Simulator/BinaryPhaseEnvelope/PR.mo b/Simulator/BinaryPhaseEnvelope/PR.mo index f9fa542..ac646fa 100644 --- a/Simulator/BinaryPhaseEnvelope/PR.mo +++ b/Simulator/BinaryPhaseEnvelope/PR.mo @@ -4,12 +4,12 @@ package PR extends Modelica.Icons.ExamplesPackage; function CompresseblityFactor extends Modelica.Icons.Function; - input Real b[NOC]; - input Real aij[NOC, NOC]; + input Real b[Nc]; + input Real aij[Nc, Nc]; input Real P; input Real T; - input Integer NOC; - input Real m[NOC]; + input Integer Nc; + input Real m[Nc]; output Real am; output Real bm; output Real A; @@ -20,7 +20,7 @@ package PR Real C[4]; Real ZR[3, 2]; algorithm - am := sum({{m[i] * m[j] * aij[i, j] for i in 1:NOC} for j in 1:NOC}); + am := sum({{m[i] * m[j] * aij[i, j] for i in 1:Nc} for j in 1:Nc}); bm := sum(b .* m); A := am * P / (R * T) ^ 2; B := bm * P / (R * T); @@ -28,77 +28,79 @@ package PR C[2] := B - 1; C[3] := A - 3 * B ^ 2 - 2 * B; C[4] := B ^ 3 + B ^ 2 - A * B; - ZR := Modelica.Math.Vectors.Utilities.roots(C); + ZR := Modelica.Math.Polynomials.roots(C); Z := {ZR[i, 1] for i in 1:3}; end CompresseblityFactor; model PR - parameter Simulator.Files.ChemsepDatabase.GeneralProperties comp[NOC]; - parameter Integer NOC; + parameter Simulator.Files.ChemsepDatabase.GeneralProperties C[Nc]; + parameter Integer Nc; parameter Real R = 8.314; - parameter Real kij[NOC, NOC] = Simulator.Files.ThermodynamicFunctions.BIPPR(NOC, comp.name); - Real Tr[NOC]; - Real b[NOC]; - Real m[NOC]; - Real q[NOC]; - Real a[NOC]; - Real aij[NOC, NOC]; + parameter Real kij[Nc, Nc] = Simulator.Files.ThermodynamicFunctions.BIPPR(Nc, C.name); + Real x[Nc]; + Real y[Nc]; + Real Tr[Nc]; + Real b[Nc]; + Real m[Nc]; + Real q[Nc]; + Real a[Nc]; + Real aij[Nc, Nc]; Real amL, bmL; Real AL, BL, Z_L[3]; Real ZL; - Real sum_xa[NOC]; - Real liqfugcoeff[NOC]; + Real sum_xa[Nc]; + Real liqfugcoeff[Nc]; Real amV, bmV; Real AV, BV, Z_V[3]; Real ZV; - Real sum_ya[NOC]; - Real vapfugcoeff[NOC]; + Real sum_ya[Nc]; + Real vapfugcoeff[Nc]; Real P; Real T(start = 273); - Real Psat[NOC]; + Real Psat[Nc]; //Bubble and Dew Point Calculation - Real Tr_bubl[NOC]; - Real a_bubl[NOC]; - Real aij_bubl[NOC, NOC]; - Real Psat_bubl[NOC]; + Real Tr_bubl[Nc]; + Real a_bubl[Nc]; + Real aij_bubl[Nc, Nc]; + Real Psat_bubl[Nc]; Real amL_bubl, bmL_bubl; - Real AL_bubl, BL_bubl, Z_L_bubl[3]; - Real ZL_bubl; - Real sum_xa_bubl[NOC]; - Real liqfugcoeff_bubl[NOC]; - Real gammaBubl[NOC]; + Real AL_bubl, BL_bubl(start = 0.005), Z_L_bubl[3]; + Real ZL_bubl (each start = 0.005); + Real sum_xa_bubl[Nc]; + Real liqfugcoeff_bubl[Nc]; + Real gammaBubl[Nc]; Real Tbubl(start = 273); equation - for i in 1:NOC loop - Psat_bubl[i] = Simulator.Files.ThermodynamicFunctions.Psat(comp[i].VP, Tbubl); - Psat[i] = Simulator.Files.ThermodynamicFunctions.Psat(comp[i].VP, T); + for i in 1:Nc loop + Psat_bubl[i] = Simulator.Files.ThermodynamicFunctions.Psat(C[i].VP, Tbubl); + Psat[i] = Simulator.Files.ThermodynamicFunctions.Psat(C[i].VP, T); end for; -//Bubble Point and Dew Point Calculation Routine - Tr_bubl = Tbubl ./ comp.Tc; + //Bubble Point and Dew Point Calculation Routine + Tr_bubl = Tbubl ./ C.Tc; a_bubl = q .* (1 .+ m .* (1 .- sqrt(Tr_bubl))) .^ 2; - aij_bubl = {{(1 - kij[i, j]) * sqrt(a_bubl[i] * a_bubl[j]) for i in 1:NOC} for j in 1:NOC}; - (amL_bubl, bmL_bubl, AL_bubl, BL_bubl, Z_L_bubl) = CompresseblityFactor(b, aij_bubl, P, Tbubl, NOC, x[:]); + aij_bubl = {{(1 - kij[i, j]) * sqrt(a_bubl[i] * a_bubl[j]) for i in 1:Nc} for j in 1:Nc}; + (amL_bubl, bmL_bubl, AL_bubl, BL_bubl, Z_L_bubl) = CompresseblityFactor(b, aij_bubl, P, Tbubl, Nc, x[:]); ZL_bubl = min({Z_L_bubl}); - sum_xa_bubl = {sum({x[j] * aij_bubl[i, j] for j in 1:NOC}) for i in 1:NOC}; + sum_xa_bubl = {sum({x[j] * aij_bubl[i, j] for j in 1:Nc}) for i in 1:Nc}; liqfugcoeff_bubl = exp(AL_bubl / (BL_bubl * sqrt(8)) * log((ZL_bubl + 2.4142135 * BL_bubl) / (ZL_bubl - 0.414213 * BL_bubl)) .* (b / bmL_bubl .- 2 * sum_xa_bubl / amL_bubl) .+ (ZL_bubl - 1) * (b / bmL_bubl) .- log(ZL_bubl - BL_bubl)); liqfugcoeff_bubl[:] = gammaBubl[:] .* P ./ Psat_bubl[:]; - P = sum(gammaBubl[:] .* x[:] .* exp(comp[:].VP[2] + comp[:].VP[3] / Tbubl + comp[:].VP[4] * log(Tbubl) + comp[:].VP[5] .* Tbubl .^ comp[:].VP[6]) ./ liqfugcoeff_bubl[:]); -//Calculation of Temperatures at different compositions - Tr = T ./ comp.Tc; - b = 0.0778 * R * comp.Tc ./ comp.Pc; - m = 0.37464 .+ 1.54226 * comp.AF .- 0.26992 * comp.AF .^ 2; - q = 0.45724 * R ^ 2 * comp.Tc .^ 2 ./ comp.Pc; + P = sum(gammaBubl[:] .* x[:] .* exp(C[:].VP[2] + C[:].VP[3] / Tbubl + C[:].VP[4] * log(Tbubl) + C[:].VP[5] .* Tbubl .^ C[:].VP[6]) ./ liqfugcoeff_bubl[:]); + //Calculation of Temperatures at different compositions + Tr = T ./ C.Tc; + b = 0.0778 * R * C.Tc ./ C.Pc; + m = 0.37464 .+ 1.54226 * C.AF .- 0.26992 * C.AF .^ 2; + q = 0.45724 * R ^ 2 *C.Tc.^(2)./ C.Pc; a = q .* (1 .+ m .* (1 .- sqrt(Tr))) .^ 2; - aij = {{(1 - kij[i, j]) * sqrt(a[i] * a[j]) for i in 1:NOC} for j in 1:NOC}; -//Liquid Phase Calculation Routine - (amL, bmL, AL, BL, Z_L) = CompresseblityFactor(b, aij, P, T, NOC, x[:]); + aij = {{(1 - kij[i, j]) * sqrt(a[i] * a[j]) for i in 1:Nc} for j in 1:Nc}; + //Liquid Phase Calculation Routine + (amL, bmL, AL, BL, Z_L) = CompresseblityFactor(b, aij, P, T, Nc, x[:]); ZL = min({Z_L}); - sum_xa = {sum({x[j] * aij[i, j] for j in 1:NOC}) for i in 1:NOC}; + sum_xa = {sum({x[j] * aij[i, j] for j in 1:Nc}) for i in 1:Nc}; liqfugcoeff = exp(AL / (BL * sqrt(8)) * log((ZL + 2.4142135 * BL) / (ZL - 0.414213 * BL)) .* (b / bmL .- 2 * sum_xa / amL) .+ (ZL - 1) * (b / bmL) .- log(ZL - BL)); -//Vapour Phase Calculation Routine - (amV, bmV, AV, BV, Z_V) = CompresseblityFactor(b, aij, P, T, NOC, y[:]); + //Vapour Phase Calculation Routine + (amV, bmV, AV, BV, Z_V) = CompresseblityFactor(b, aij, P, T, Nc, y[:]); ZV = max({Z_V}); - sum_ya = {sum({y[j] * aij[i, j] for j in 1:NOC}) for i in 1:NOC}; + sum_ya = {sum({y[j] * aij[i, j] for j in 1:Nc}) for i in 1:Nc}; vapfugcoeff = exp(AV / (BV * sqrt(8)) * log((ZV + 2.4142135 * BV) / (ZV - 0.414213 * BV)) .* (b / bmV .- 2 * sum_ya / amV) .+ (ZV - 1) * (b / bmV) .- log(ZV - BV)); end PR; @@ -106,8 +108,8 @@ package PR import data = Simulator.Files.ChemsepDatabase; parameter data.Ethane eth; parameter data.Propane prop; - extends PR(NOC = 2, comp = {eth, prop}); - Real P, T(start = 273), K[NOC], x[NOC](each start = 0.5), y[NOC], Tbubl(start = 273); + extends PR(Nc = 2, C = {eth, prop}); + Real P, T(start = 273), K[Nc], x[Nc](each start = 0.5), y[Nc], Tbubl(start = 273); equation K[:] = liqfugcoeff[:] ./ vapfugcoeff[:]; y[:] = K[:] .* x[:]; @@ -120,13 +122,13 @@ package PR import data = Simulator.Files.ChemsepDatabase; parameter data.Ethane eth; parameter data.Propane prop; - parameter Integer NOC = 2; - parameter Integer N = 2; - parameter data.GeneralProperties comp[NOC] = {eth, prop}; - PhaseEquilibria points[N](each T = 210, each NOC = NOC, each comp = comp, each T(start = 273), each Tbubl(start = 273), each x(each start = 0.5), each y(each start = 0.5)); + parameter Integer Nc = 2; + parameter Integer N = 10; + parameter data.GeneralProperties C[Nc] = {eth, prop}; + PhaseEquilibria points[N](each T = 210, each Nc = Nc, each C = C, each T(start = 273), each Tbubl(start = 273), each x(each start = 0.5), each y(each start = 0.5)); Real x1[N], y1[N], x2[N], y2[N], P[N](each start = 101325), Tbubl[N], Temp[N]; equation -//Generation of Points to compute Bubble Temperature + //Generation of Points to Compute Bubble Temperature points[:].x[1] = x1[:]; points[:].y[1] = y1[:]; points[:].x[2] = x2[:]; @@ -148,11 +150,11 @@ package PR import data = Simulator.Files.ChemsepDatabase; parameter data.Ethane eth; parameter data.Propane prop; - parameter Integer NOC = 2; - parameter Integer N = 10; - parameter data.GeneralProperties comp[NOC] = {eth, prop}; - PhaseEquilibria points[N](each P = 101325, each NOC = NOC, each comp = comp, each T(start = 273), each Tbubl(start = 273), each x(each start = 0.5), each y(each start = 0.5)); - Real x[N, NOC], y[N, NOC], T[N], Tbubl[N], T_PR[N]; + parameter Integer Nc = 2; + parameter Integer N = 21; + parameter data.GeneralProperties C[Nc] = {eth, prop}; + PhaseEquilibria points[N](each P = 101325, each Nc = Nc, each C = C, each T(start = 273), each Tbubl(start = 273), each x(each start = 0.5), each y(each start = 0.5)); + Real x[N, Nc], y[N, Nc], T[N], Tbubl[N], T_PR[N]; equation points[:].x = x; points[:].y = y; @@ -164,7 +166,7 @@ package PR T_PR[i] = T[i]; end for; for i in 1:N loop - x[i, 1] = 0 + (i - 1) * 0.025; + x[i, 1] = 0.5 + (i - 1) * 0.025; end for; end Txy; -end PR; +end PR; \ No newline at end of file diff --git a/Simulator/BinaryPhaseEnvelope/UNIFAC.mo b/Simulator/BinaryPhaseEnvelope/UNIFAC.mo index 59d3bc5..cd767ac 100644 --- a/Simulator/BinaryPhaseEnvelope/UNIFAC.mo +++ b/Simulator/BinaryPhaseEnvelope/UNIFAC.mo @@ -7,7 +7,7 @@ package UNIFAC //Libraries import Simulator.*; //Extension of Chemsep Database - Simulator.Files.ChemsepDatabase data; + import data = Simulator.Files.ChemsepDatabase; //Parameter Section //Selection of compounds parameter data.Methylethylketone meth; @@ -135,7 +135,7 @@ package UNIFAC //Libraries import Simulator.*; //Extension of Chemsep Database - Simulator.Files.ChemsepDatabase data; + import data = Simulator.Files.ChemsepDatabase; //Parameter Section //Selection of compounds parameter data.Methylethylketone meth; @@ -177,7 +177,7 @@ package UNIFAC //Mole Fractions (x-axis) of the T-x-y plot Real z1[N + 1], z2[N + 1]; //Bubble Temperature - Real T[N + 1](unit = "K", each start = 300); + Real T[N + 1](each unit = "K", each start = 300); //Distribution coefficient Real K1[N + 1]; //Vapour Phase Mole Fraction @@ -264,4 +264,4 @@ package UNIFAC end Txy; //================================================================================================================ -end UNIFAC; +end UNIFAC; \ No newline at end of file diff --git a/Simulator/BinaryPhaseEnvelope/UNIQUAC.mo b/Simulator/BinaryPhaseEnvelope/UNIQUAC.mo index bb9367f..600563d 100644 --- a/Simulator/BinaryPhaseEnvelope/UNIQUAC.mo +++ b/Simulator/BinaryPhaseEnvelope/UNIQUAC.mo @@ -14,12 +14,12 @@ package UNIQUAC input Real R[NOC], Q[NOC]; input Real tow[NOC, NOC]; input Real towk[N + 1, NOC, NOC]; - parameter Real Z = 10 "Compresseblity Factor"; - parameter Real R_gas = 1.98721 "Gas Constant"; //Activity coefficients output Real gammaBubl1[N + 1], gammaBubl2[N + 1]; protected //Intermediate parameters used to calculate the Combinatorial and Residual contribution" + parameter Real Z = 10 "Compresseblity Factor"; + parameter Real R_gas = 1.98721 "Gas Constant"; Real r_bubl[N + 1], q_bubl[N + 1]; Real teta1_bubl[N + 1], teta2_bubl[N + 1]; Real S1_bubl[N + 1], S2_bubl[N + 1]; @@ -87,7 +87,7 @@ package UNIQUAC //Libraries import Simulator.*; //Extension of Chemsep Database - Simulator.Files.ChemsepDatabase data; + import data = Simulator.Files.ChemsepDatabase; //Parameter Section //Selection of compounds parameter data.Water wat; @@ -120,7 +120,7 @@ package UNIQUAC //Vapour Phase Mole Fraction Real y1[N + 1](each start = 0.5), y2[N + 1](each start = 0.5); //Vapour Pressure at the chosen temperature - Real Psat[NOC](unit = "Pa") "Vapour Pressure"; + Real Psat[NOC](each unit = "Pa") "Vapour Pressure"; //========================================================================================= //Equation Section equation @@ -170,7 +170,7 @@ package UNIQUAC //Libraries import Simulator.*; //Extension of Chemsep database - Simulator.Files.ChemsepDatabase data; + import data = Simulator.Files.ChemsepDatabase; //Parameter Section //Selection of compounds parameter data.Water wat; @@ -255,4 +255,4 @@ package UNIQUAC //================================================================================================ //============================================================================================================== //================================================================================================================ -end UNIQUAC; +end UNIQUAC; \ No newline at end of file diff --git a/Simulator/Examples/Absorption.mo b/Simulator/Examples/Absorption.mo index 901a9c8..d94419e 100644 --- a/Simulator/Examples/Absorption.mo +++ b/Simulator/Examples/Absorption.mo @@ -17,8 +17,8 @@ package Absorption "Example of Simulating an Absorption Column" end Tray; model AbsColumn "Extension of Absorption COlumn with instance of Tray" - extends Simulator.UnitOperations.AbsorptionColumn.AbsCol; - Tray tray[Nt](each Nc = Nc, each C = C); + extends Simulator.UnitOperations.AbsorptionColumn.AbsCol( + redeclare Tray tray[Nt](each Nc = Nc, each C = C)); annotation( Documentation(info = "This is a non-executable model is created inside the package Absorption to extend the Absorption Column model along with the necessary property method from ThermodynamicPackages which is RaoultsLaw in this case.

Tray model is also instantiated in this model to complete building of absorption column model.

It will be instantiated in the AbsorptionSimulation model to create the required instance of the absorption column model.
")); end AbsColumn; @@ -39,7 +39,7 @@ package Absorption "Example of Simulating an Absorption Column" Placement(visible = true, transformation(origin = {52, 80}, extent = {{-10, -10}, {10, 10}}, rotation = 0))); Simulator.Examples.Absorption.MS S4(Nc = Nc, C = C) annotation( Placement(visible = true, transformation(origin = {52, -94}, extent = {{-10, -10}, {10, 10}}, rotation = 0))); - Simulator.Examples.Absorption.MS S2 annotation( + Simulator.Examples.Absorption.MS S2(Nc = Nc, C = C) annotation( Placement(visible = true, transformation(origin = {-88, -54}, extent = {{-10, -10}, {10, 10}}, rotation = 0))); equation connect(B1.Out_Bot, S4.In) annotation( @@ -63,4 +63,4 @@ package Absorption "Example of Simulating an Absorption Column" end AbsorptionSimulation; annotation( Documentation(info = "
Following problem statement is simulated in this Absorption Column example:


Problem Statement:

Component System: Air, Water, Acetone
Thermodynamics: Raoult's Law

Material Stream Information

Feed Stream 1 (Solvent)
Molar Flow Rate: 30 mol/s
Mole Fraction (Water): 1
Pressure: 101325 Pa
Temperature: 325 K

Feed Stream 2 (Gas Mixture)
Molar Flow Rate: 30 mol/s
Mole Fraction (Air): 0.5
Mole Fraction (Acetone): 0.5
Pressure: 101325 Pa
Temperature: 335 K


Simulate an absorption column with 10 stages where the solvent enters from the top and gas mixture enters from bottom to remove acetone from air.


This package is created to demnostrate the simualtion of an Absorption Column. Following models are created inside the package:
  1. MS (Non-executable model): created to extend the material stream along with the necessary thermodynamic package.
  2. Tray (Non-executable model): created to extend the tray along with the necessary thermodynamic package.
  3. AbsColumn (Non-executable model): created to extend the Absorption Column along with the necessary thermodynamic package.
  4. AbsorptionSimulation (Executable model): All the components are defined, material stream & Absorption Column specifications are declared, model instances are connected to make the file executable.
")); -end Absorption; +end Absorption; \ No newline at end of file diff --git a/Simulator/Examples/Distillation.mo b/Simulator/Examples/Distillation.mo index 1afa644..09edf60 100644 --- a/Simulator/Examples/Distillation.mo +++ b/Simulator/Examples/Distillation.mo @@ -24,10 +24,10 @@ package Distillation "Example of Simulating a Distillation Column" end Reboiler; model DistColumn "Extension of Distillation Column along with instances of Condenser, Tray and Reboiler" - extends Simulator.UnitOperations.DistillationColumn.DistCol; - Condenser condenser(Nc = Nc, C = C, Ctype = Ctype, Bin = Bin_t[1]); - Reboiler reboiler(Nc = Nc, C = C, Bin = Bin_t[Nt]); - Tray tray[Nt - 2](each Nc = Nc, each C = C, Bin = Bin_t[2:Nt - 1]); + extends Simulator.UnitOperations.DistillationColumn.DistCol( + redeclare Condenser condenser(Nc = Nc, C = C, Ctype = Ctype), + redeclare Reboiler reboiler(Nc = Nc, C = C), + redeclare Tray tray[Nt - 2](each Nc = Nc, each C = C)); annotation( Documentation(info = "This is a non-executable model is created inside the package Distillation to extend the Distillation Column model along with the necessary property method from ThermodynamicPackages which is RaoultsLaw in this case.

Condenser, Tray and Reboiler models are also instantiated in this model to complete building of distillation column model.

It will be instantiated in the DistillationSimulation_Ex1
DistillationSimulation_Ex2DistillationSimulation_Ex3
DistillationSimulation_Ex4DistillationSimulation_Ex5 model to create the required instance of the distillation column model.
")); end DistColumn; @@ -88,7 +88,7 @@ package Distillation "Example of Simulating a Distillation Column" parameter data.Benzene benz; parameter data.Toluene tol; parameter Simulator.Files.ChemsepDatabase.GeneralProperties C[Nc] = {benz, tol}; - Simulator.Examples.Distillation.DistColumn B1(Nc = Nc, C = C, Nt = 12, Ni = 1, InT_s = {7}) annotation( + Simulator.Examples.Distillation.DistColumn B1(Nc = Nc, C = C, Nt = 12, Ni = 1, InT_s = {7}, Ctype = "Total") annotation( Placement(visible = true, transformation(origin = {-26, 6.66134e-16}, extent = {{-10, -10}, {10, 10}}, rotation = 0))); Simulator.Examples.Distillation.MS S1(Nc = Nc, C = C) annotation( Placement(visible = true, transformation(origin = {-76, 2}, extent = {{-10, -10}, {10, 10}}, rotation = 0))); @@ -260,4 +260,4 @@ package Distillation "Example of Simulating a Distillation Column" end DistillationSimulation_Ex5; annotation( Documentation(info = "
Following five problem statement are simulated in this Distillation Column example:

Problem Statement 1:

Component System: Benzene, Toluene
Thermodynamics: Raoult's Law

Material Stream Information

Molar Flow Rate: 100 mol/s
Mole Fraction (Benzene): 0.5
Mole Fraction (Toluene): 0.5
Pressure: 101325 Pa
Temperature: 298.15 K

Simulate a distillation column with 4 stages (excluding condenser and reboiler) where the feed is entering the 3rd stage. The column is operated at uniform pressure of 101325 Pa and with a partial condenser. The column is specified to have reflux ratio of 2 and bottoms flow rate of 50 mol/s.


Problem Statement 2:

Component System: Benzene, Toluene
Thermodynamics: Raoult's Law

Material Stream Information

Molar Flow Rate: 100 mol/s
Mole Fraction (Benzene): 0.5
Mole Fraction (Toluene): 0.5
Pressure: 101325 Pa
Temperature: 298.15 K

Simulate a distillation column with 12 stages (excluding condenser and reboiler) where the feed is entering the 7th stage. The column is operated at uniform pressure of 101325 Pa and with a total condenser. The column is specified to have reflux ratio of 2 and bottoms flow rate of 50 mol/s.


Problem Statement 3:

Component System: Benzene, Toluene
Thermodynamics: Raoult's Law

Material Stream Information

Molar Flow Rate: 100 mol/s
Mole Fraction (Benzene): 0.3
Mole Fraction (Toluene): 0.7
Pressure: 101325 Pa
Temperature: 298.15 K

Simulate a distillation column with 22 stages (excluding condenser and reboiler) where the feed is entering the 10th stage. The column is operated at uniform pressure of 101325 Pa and with a total condenser. The column is specified to have reflux ratio of 1.5 and bottoms flow rate of 70 mol/s.


Problem Statement 4:

Component System: Benzene, Toluene
Thermodynamics: Raoult's Law

Material Stream Information

Molar Flow Rate: 96.8 mol/s
Mole Fraction (Benzene): 0.3
Mole Fraction (Toluene): 0.7
Pressure: 101325 Pa
Temperature: 298.15 K

Simulate a distillation column with 22 stages (excluding condenser and reboiler) where the feed is entering the 10th stage. The column is operated at top pressure of 151325 Pa and with a total condenser. The bottom pressure of the column is 101325 Pa. The column is specified to have reflux ratio of 1.5 and bottoms flow rate of 70 mol/s.


Problem Statement 5:

Component System: Benzene, Toluene
Thermodynamics: Raoult's Law

Material Stream Information

Feed Stream 1
Molar Flow Rate: 100 mol/s
Mole Fraction (Benzene): 0.5
Mole Fraction (Toluene): 0.5
Pressure: 101325 Pa
Temperature: 298.15 K

Feed Stream 2
Molar Flow Rate: 100 mol/s
Mole Fraction (Benzene): 0.5
Mole Fraction (Toluene): 0.5
Pressure: 101325 Pa
Temperature: 298.15 K

Simulate a distillation column with 5 stages (excluding condenser and reboiler) where the feed streams are entering the 3rd and 4th stage. The column is operated at uniform pressure of 101325 Pa and with a partial condenser. The column is specified to have reflux ratio of 2 and bottoms flow rate of 50 mol/s.


This package is created to demnostrate the simualtion of Distillation Column. Following models are created inside the package:
  1. Condenser (Non-executable model): created to extend the condenser along with the necessary thermodynamic package.
  2. Tray (Non-executable model): created to extend the tray along with the necessary thermodynamic package.
  3. Reboiler (Non-executable model): created to extend the reboiler along with the necessary thermodynamic package.
  4. DistColumn (Non-executable model): created to extend the Distillation Column along with the necessary thermodynamic package.
  5. MS (Non-executable model): created to extend the material stream along with the necessary thermodynamic package.
  6. DistillationSimulation_Ex1 (Executable model for Problem Statement 1): All the components are defined, material stream & Distillation Column specifications are declared, model instances are connected to make the file executable.
  7. DistillationSimulation_Ex2 (Executable model for Problem Statement 2): All the components are defined, material stream & Distillation Column specifications are declared, model instances are connected to make the file executable.
  8. DistillationSimulation_Ex3 (Executable model for Problem Statement 3): All the components are defined, material stream & Distillation Column specifications are declared, model instances are connected to make the file executable.
  9. DistillationSimulation_Ex4 (Executable model for Problem Statement 4): All the components are defined, material stream & Distillation Column specifications are declared, model instances are connected to make the file executable.
  10. DistillationSimulation_Ex5 (Executable model for Problem Statement 5): All the components are defined, material stream & Distillation Column specifications are declared, model instances are connected to make the file executable.
")); -end Distillation; +end Distillation; \ No newline at end of file diff --git a/Simulator/Examples/MaterialStream.mo b/Simulator/Examples/MaterialStream.mo index 5e13052..3cfcce2 100644 --- a/Simulator/Examples/MaterialStream.mo +++ b/Simulator/Examples/MaterialStream.mo @@ -10,7 +10,7 @@ package MaterialStream "Examples of Simulating Material Stream using Different M parameter data.Ethanol eth; parameter data.Water wat; extends Streams.MaterialStream(Nc = 3, C = {meth, eth, wat}); - extends Simulator.Files.ThermodynamicPackages.RaoultsLaw; + extends Simulator.Files.ThermodynamicPackages.RaoultsLaw(Nc = 3, C = {meth, eth, wat}); equation P = 101325; T = 351; @@ -22,12 +22,12 @@ package MaterialStream "Examples of Simulating Material Stream using Different M model TVFflash"Material Stream simulation with temperature and vapor fraction flash specifications" - Simulator.Files.ChemsepDatabase data; + import data = Simulator.Files.ChemsepDatabase; parameter data.Methanol meth; parameter data.Ethanol eth; parameter data.Water wat; extends Streams.MaterialStream(Nc = 3, C = {meth, eth, wat}); - extends Simulator.Files.ThermodynamicPackages.RaoultsLaw; + extends Simulator.Files.ThermodynamicPackages.RaoultsLaw(Nc = 3, C = {meth, eth, wat}); equation xvap = 0.036257; T = 351; @@ -44,7 +44,7 @@ package MaterialStream "Examples of Simulating Material Stream using Different M parameter data.Ethanol eth; parameter data.Water wat; extends Streams.MaterialStream(Nc = 3, C = {meth, eth, wat}); - extends Simulator.Files.ThermodynamicPackages.RaoultsLaw; + extends Simulator.Files.ThermodynamicPackages.RaoultsLaw(Nc = 3, C = {meth, eth, wat}); equation P = 101325; xvap = 0.036257; @@ -61,7 +61,7 @@ package MaterialStream "Examples of Simulating Material Stream using Different M parameter data.Ethanol eth; parameter data.Water wat; extends Streams.MaterialStream(Nc = 3, C = {meth, eth, wat}); - extends Simulator.Files.ThermodynamicPackages.RaoultsLaw; + extends Simulator.Files.ThermodynamicPackages.RaoultsLaw(Nc = 3, C = {meth, eth, wat}); equation P = 101325; H_p[1] = -34452; @@ -78,7 +78,7 @@ package MaterialStream "Examples of Simulating Material Stream using Different M parameter data.Ethanol eth; parameter data.Water wat; extends Streams.MaterialStream(Nc = 3, C = {meth, eth, wat}); - extends Simulator.Files.ThermodynamicPackages.RaoultsLaw; + extends Simulator.Files.ThermodynamicPackages.RaoultsLaw(Nc = 3, C = {meth, eth, wat}); equation P = 101325; S_p[1] = -84.39; @@ -95,7 +95,7 @@ package MaterialStream "Examples of Simulating Material Stream using Different M parameter data.Ethanol eth; parameter data.Water wat; extends Streams.MaterialStream(Nc = 3, C = {meth, eth, wat}); - extends Simulator.Files.ThermodynamicPackages.RaoultsLaw; + extends Simulator.Files.ThermodynamicPackages.RaoultsLaw(Nc = 3, C = {meth, eth, wat}); equation P = 202650; T = 320; @@ -110,8 +110,8 @@ package MaterialStream "Examples of Simulating Material Stream using Different M import data = Simulator.Files.ChemsepDatabase; parameter data.Ethanol eth; parameter data.Water wat; - extends Simulator.Streams.MaterialStream(Nc = 2, C = {eth, wat}, Pbubl(start = 101325), Pdew(start = 101325), x_pc(each start = 0.33), xvap(start = 0.68)); - extends Simulator.Files.ThermodynamicPackages.UNIQUAC; + extends Simulator.Streams.MaterialStream(Nc = 2, C = {eth, wat}, Pbubl(start = 101325), Pdew(start = 101325), xvap(start = 0.68),gmadew_c(each start = 2.2), gmabubl_c(each start = 1)); + extends Simulator.Files.ThermodynamicPackages.UNIQUAC(Nc = 2, C = {eth, wat}); equation x_pc[1, :] = {0.5, 0.5}; F_p[1] = 50; @@ -127,7 +127,7 @@ package MaterialStream "Examples of Simulating Material Stream using Different M parameter data.Onehexene ohex; parameter data.Ethanol eth; extends Simulator.Streams.MaterialStream(Nc = 2, C = {ohex, eth}, x_pc(each start = 0.33)); - extends Simulator.Files.ThermodynamicPackages.NRTL; + extends Simulator.Files.ThermodynamicPackages.NRTL(Nc = 2, C = {ohex, eth}); equation x_pc[1, :] = {0.5, 0.5}; F_p[1] = 100; @@ -138,7 +138,7 @@ package MaterialStream "Examples of Simulating Material Stream using Different M end NRTL; model GraysonStreed "Material stream simulated with Grayson-Streed property package" - + //This example can be run using the homotopy non linear solver, the results differ from those obtained using the old frontend. import data = Simulator.Files.ChemsepDatabase; parameter data.Ethylene eth; parameter data.Acetylene acet; @@ -148,7 +148,7 @@ package MaterialStream "Examples of Simulating Material Stream using Different M //Sp = Solublity Parameter //V = Molar Volume //All the above three parameters have to be mentioned as arguments while extending the thermodynamic Package Grayson Streed as shown below - extends Simulator.Files.ThermodynamicPackages.GraysonStreed(W_c = {0.0949, 0.1841, 0.244612, 0.3125}, SP_c = {0.00297044, 0.00449341, 0.00437069, 0.00419199}, V_c = {61, 42.1382, 84.7207, 60.4292}); + extends Simulator.Files.ThermodynamicPackages.GraysonStreed(Nc = 4, C = {eth, acet, dich, prop}, W_c = {0.0949, 0.1841, 0.244612, 0.3125}, SP_c = {0.00297044, 0.00449341, 0.00437069, 0.00419199}, V_c = {61, 42.1382, 84.7207, 60.4292}); extends Simulator.Streams.MaterialStream(Nc = 4, C = {eth, acet, dich, prop}); //Equations equation @@ -180,4 +180,4 @@ NOTE: Please note that these examples are standalone examples of material stream CompositeMS.

")); -end MaterialStream; +end MaterialStream; \ No newline at end of file diff --git a/Simulator/Examples/PFR.mo b/Simulator/Examples/PFR.mo index 61ab4c9..632e97e 100644 --- a/Simulator/Examples/PFR.mo +++ b/Simulator/Examples/PFR.mo @@ -31,24 +31,24 @@ package PFR "Example of Simulating a PFR" Simulator.Streams.EnergyStream Energy annotation( Placement(visible = true, transformation(origin = {-14, -54}, extent = {{-10, -10}, {10, 10}}, rotation = 0))); equation -//======================================================================== -//Connections + //======================================================================== + //Connections connect(Energy.Out, B1.En) annotation( Line(points = {{-4, -54}, {2, -54}, {2, 0}, {4, 0}}, color = {255, 0, 0})); connect(B1.Out, S2.In) annotation( Line(points = {{36, 0}, {80, 0}, {80, 0}, {80, 0}}, color = {0, 70, 70})); connect(S1.Out, B1.In) annotation( Line(points = {{-60, 0}, {-30, 0}, {-30, 0}, {-30, 0}}, color = {0, 70, 70})); -//======================================================================== -//Inputs and Specifications + //======================================================================== + //Inputs and Specifications S1.x_pc[1, :] = {0.2, 0.8, 0}; + B1.X_r[1] = 0.0991; S1.P = 100000; S1.T = 360; S1.F_p[1] = 100; - B1.X_r[1] = 0.0991; annotation( Documentation(info = "This is an executable model to simualate the PFR example where all the components are defined, material stream, plug flow reactor & kinetic reaction specifications are declared, model instances are connectedPFR model from the UnitOperations package has been instantiated here.

Material Stream Information

Molar Flow Rate: 100 mol/s
Mole Fraction (Ethylene Oxide): 0.2
Mole Fraction (Water): 0.8
Mole Fraction (Ethylene Glycol): 0
Pressure: 100000 Pa
Temperature: 360 K

Reaction
Ethylene Oxide + Water ----> Ethylene Glycol

Compressor Specification: Conversion of Ethylene Oxide: 9.91%
   Operation Mode: isothermal
")); end PFRSimulation; annotation( Documentation(info = "
Following problem statement is simulated in this Plug Flow Reactor example

Component System: Ethylene Oxide, Water, Ethylene Glycol
Thermodynamics: Raoult's Law

Material Stream Information

Molar Flow Rate: 100 mol/s
Mole Fraction (Ethylene Oxide): 0.2
Mole Fraction (Water): 0.8
Mole Fraction (Ethylene Glycol): 0
Pressure: 100000 Pa
Temperature: 360 K

Simulate a plug flow reactor where Ethylene Oxide reacts with Water to form Ethylene Glycol. The conversion of ethylene oxide is 9.91%. Assume the reactor to be operated isothermally. Pressure drop across the PFR is 90.56 Pa.

This package is created to demnostrate the simualtion of a Plug Flow Reactor. Following models are created inside the package:
  1. MS (Non-executable model): created to extend the material stream along with the necessary thermodynamic package.
  2. PFRSimulation (Executable model): All the components are defined, material stream & plug flow reactor specifications are declared, model instances are connected to make the file executable.
")); -end PFR; +end PFR; \ No newline at end of file diff --git a/Simulator/Files/ChemsepDatabase/GeneralProperties.mo b/Simulator/Files/ChemsepDatabase/GeneralProperties.mo index 4e0f1c2..950d940 100644 --- a/Simulator/Files/ChemsepDatabase/GeneralProperties.mo +++ b/Simulator/Files/ChemsepDatabase/GeneralProperties.mo @@ -1,6 +1,6 @@ within Simulator.Files.ChemsepDatabase; -model GeneralProperties "Model to declare the variables for thermophysical properties" +record GeneralProperties "Model to declare the variables for thermophysical properties" extends Modelica.Icons.Record; parameter Integer SN "Serial Number"; parameter String name "Compound Name"; diff --git a/Simulator/Files/Models/Flash.mo b/Simulator/Files/Models/Flash.mo index c548260..236efb7 100644 --- a/Simulator/Files/Models/Flash.mo +++ b/Simulator/Files/Models/Flash.mo @@ -12,7 +12,10 @@ within Simulator.Files.Models; Real T(min = 0, start = Tg); Real Pbubl(start = Pmin, min = 0)"Bubble point pressure"; Real Pdew(start = Pmax, min = 0)"dew point pressure"; - + //Thermodynamics packages variables + Real K_c[Nc](each min = 0), Cpres_p[3], Hres_p[3], Sres_p[3]; + Real gma_c[Nc], gmabubl_c[Nc], gmadew_c[Nc]; + Real philiqbubl_c[Nc], phivapdew_c[Nc], Pvap_c[Nc]; extends GuessModels.InitialGuess; equation diff --git a/Simulator/Files/Models/ReactionManager/BaseCalc.mo b/Simulator/Files/Models/ReactionManager/BaseCalc.mo index 578ca9f..5ea5f5a 100644 --- a/Simulator/Files/Models/ReactionManager/BaseCalc.mo +++ b/Simulator/Files/Models/ReactionManager/BaseCalc.mo @@ -17,8 +17,6 @@ for i in 1:Nc loop if Sc[i]<0 then N:=i; break; - else - i:=i; end if; end for; @@ -30,11 +28,7 @@ if Sc[i]<0 then if v2

For variables which are decalared as 1-D array, the array size represent the phase where the array element indices 1 represents mixed phase, 2 represents liquid phase and 3 represents vapor phase.

For example, variable F_p[3] represents Total molar flow in different phase. So when simulated, the variables in the results will be as follow:
F_p[1] is Molar flow in mixed phase
F_p[2] is Molar flow in liquid phase
F_p[3] is Molar flow in vapor phase


For variables which are decalared as 2-D array, the first indice represent phase and second indice represents components.

For example, variable F_pc[3,Nc] represents Component molar flow in different phase. So when simulated, the variables in the results will be as follow:
F_pc[1,Nc] is Molar flow of Ncth in mixed phase
F_pc[2,Nc] is Molar flow of Ncth in liquid phase
F_pc[3,Nc] is Molar flow of Ncth in vapor phase


For demonstration on how to use this model to simulate a Material Stream, go to Material Stream Example
")); end MaterialStream; + diff --git a/Simulator/UnitOperations/AbsorptionColumn/AbsCol.mo b/Simulator/UnitOperations/AbsorptionColumn/AbsCol.mo index 48142e5..20c9d79 100644 --- a/Simulator/UnitOperations/AbsorptionColumn/AbsCol.mo +++ b/Simulator/UnitOperations/AbsorptionColumn/AbsCol.mo @@ -1,6 +1,6 @@ within Simulator.UnitOperations.AbsorptionColumn; -model AbsCol "Model of an absorption column representing fractionating towers where mixture is separated in equilibrium stages" +model AbsCol "Model of an absorption column representing fractionating towers where mixture is separated in equilibrium stages" //Model seems to be broken, doesn't run on the old frontend either. extends Simulator.Files.Icons.AbsorptionColumn; import data = Simulator.Files.ChemsepDatabase; parameter data.GeneralProperties C[Nc] "Component instances array" annotation( @@ -18,6 +18,7 @@ model AbsCol "Model of an absorption column representing fractionating towers wh Placement(visible = true, transformation(origin = {100, 80}, extent = {{-10, -10}, {10, 10}}, rotation = 0), iconTransformation(origin = {250, 300}, extent = {{-10, -10}, {10, 10}}, rotation = 0))); Simulator.Files.Interfaces.matConn Out_Bot(Nc = Nc) annotation( Placement(visible = true, transformation(origin = {100, -80}, extent = {{-10, -10}, {10, 10}}, rotation = 0), iconTransformation(origin = {250, -300}, extent = {{-10, -10}, {10, 10}}, rotation = 0))); + replaceable Simulator.UnitOperations.AbsorptionColumn.AbsTray tray[2](each Nc = Nc); equation //connector equation tray[1].Fliq_s[1] = In_Top.F; diff --git a/Simulator/UnitOperations/AbsorptionColumn/AbsTray.mo b/Simulator/UnitOperations/AbsorptionColumn/AbsTray.mo index dcdf2bf..cff0037 100644 --- a/Simulator/UnitOperations/AbsorptionColumn/AbsTray.mo +++ b/Simulator/UnitOperations/AbsorptionColumn/AbsTray.mo @@ -8,12 +8,16 @@ model AbsTray "Model of a tray used in absorption column" Real T(min = 0, start = Tg); Real Fvap_s[2](each min = 0, start={Fg,Fg}); Real Fliq_s[2](each min = 0, start={Fliqg,Fliqg}); - Real xvap_sc[2, Nc](each min = 0, each max = 1, start=xvapg); - Real xliq_sc[2, Nc](each min = 0, each max = 1, start=xliqg); + Real xvap_sc[2, Nc](each min = 0, each max = 1, each start=xvapg); + Real xliq_sc[2, Nc](each min = 0, each max = 1, each start=xliqg); Real Hvap_s[2](start={Hvapg,Hvapg}), Hliq_s[2](start={Hliqg,Hliqg}), Hvapout_c[Nc], Hliqout_c[Nc]; - Real x_pc[3, Nc](each min =0, each max = 0,start=xliqg); - Real Pdew(min = 0, start =Pmax); - Real Pbubl(min = 0, start =Pmin); + Real x_pc[3, Nc](each min =0, each max = 1, each start=xliqg); + Real Pdew(min = 0, start = Pmax); + Real Pbubl(min = 0, start = Pmin); + //Thermodynamics packages variables + Real K_c[Nc](each min = 0), Cpres_p[3], Hres_p[3], Sres_p[3]; + Real gma_c[Nc], gmabubl_c[Nc], gmadew_c[Nc]; + Real philiqbubl_c[Nc], phivapdew_c[Nc], Pvap_c[Nc]; Simulator.Files.Interfaces.trayConn In_Liq(Nc = Nc) annotation( Placement(visible = true, transformation(origin = {-50, 40}, extent = {{-10, -10}, {10, 10}}, rotation = 0), iconTransformation(origin = {-50, 40}, extent = {{-10, -10}, {10, 10}}, rotation = 0))); diff --git a/Simulator/UnitOperations/CentrifugalPump.mo b/Simulator/UnitOperations/CentrifugalPump.mo index 8d38019..0bdb02e 100644 --- a/Simulator/UnitOperations/CentrifugalPump.mo +++ b/Simulator/UnitOperations/CentrifugalPump.mo @@ -6,7 +6,7 @@ model CentrifugalPump "Model of a centrifugal pump to provide energy to liquid s extends Simulator.Files.Icons.CentrifugalPump; parameter Simulator.Files.ChemsepDatabase.GeneralProperties C[Nc] "Component instances array" annotation( Dialog(tab = "Pump Specifications", group = "Component Parameters")); - parameter Integer Nc = 2 "Number of components" annotation( + parameter Integer Nc "Number of components" annotation( Dialog(tab = "Pump Specifications", group = "Component Parameters")); parameter Real Eff(unit = "-") "Efficiency" annotation( Dialog(tab = "Pump Specifications", group = "Calculation Parameters")); diff --git a/Simulator/UnitOperations/CompoundSeparator.mo b/Simulator/UnitOperations/CompoundSeparator.mo index 943177d..53bf256 100644 --- a/Simulator/UnitOperations/CompoundSeparator.mo +++ b/Simulator/UnitOperations/CompoundSeparator.mo @@ -22,10 +22,10 @@ model CompoundSeparator Real Pout_s[2](each unit = "Pa", each min = 0, start={Pg,Pg}) "Outlet stream pressure"; Real Tout_s[2](each unit = "K", each min = 0, start={Tg,Tg}) "Outlet stream temperature"; - Real xout_sc[2, Nc](each unit = "-", each min = 0, each max = 1, start={xg,xg}) "Component mole fraction at outlet stream"; + Real xout_sc[2, Nc](each unit = "-", each min = 0, each max = 1,start = fill(xg,2)) "Component mole fraction at outlet stream"; Real Fout_s[2](each unit = "mol/s", each min = 0, start = {Fg,Fg}) "Outlet stream molar flow"; - Real Fout_sc[2, Nc](each unit = "mol/s", each min = 0, start = {Fg,Fg}) "Outlet compounds molar flow"; - Real Fmout_sc[2, Nc](each unit = "kg/s", each min = 0, start={Fg,Fg}) "Outlet compound mass flow"; + Real Fout_sc[2, Nc](each unit = "mol/s", each min = 0, each start = Fg) "Outlet compounds molar flow"; + Real Fmout_sc[2, Nc](each unit = "kg/s", each min = 0, each start = Fg) "Outlet compound mass flow"; Real Hout_s[2](each unit = "kJ/kmol", start={Hvapg,Hliqg}) "Outlet mixture molar enthalpy"; parameter String SepFact_c[Nc] "Separation factor: ''Molar_Flow'', ''Mass_Flow'', ''Inlet_Molar_Flow_Percent'', ''Inlet_Mass_Flow_Percent''" annotation( diff --git a/Simulator/UnitOperations/ConversionReactor.mo b/Simulator/UnitOperations/ConversionReactor.mo index 1381147..fad7c4f 100644 --- a/Simulator/UnitOperations/ConversionReactor.mo +++ b/Simulator/UnitOperations/ConversionReactor.mo @@ -17,6 +17,15 @@ model ConversionReactor "Model of a conversion reactor to calculate the outlet s Dialog(tab = "Reactor Specifications", group = "Calculation Parameters")); parameter Real X_r[Nr] = fill(0.4, Nr) "Conversion of base component" annotation( Dialog(tab = "Reactions", group = "Conversion Reaction Parameters")); + //Reactor variables + parameter Integer Nr "Number of reactions" annotation( + Dialog(tab = "Reactions", group = "Conversion Reaction Parameters")); + parameter Integer BC_r[Nr] "Base component in the reactions" annotation( + Dialog(tab = "Reactions", group = "Conversion Reaction Parameters")); + parameter Real Coef_cr[Nc, Nr] "Stoichiometric coefficient of components" annotation( + Dialog(tab = "Reactions", group = "Conversion Reaction Parameters")); + Real Hr_r[Nr]; + //============================================================================= //Model Variables Real Fin(unit = "mol/s", min = 0, start = Fg) "Inlet stream molar flow rate"; diff --git a/Simulator/UnitOperations/DistillationColumn/Cond.mo b/Simulator/UnitOperations/DistillationColumn/Cond.mo index 9518248..9eff65b 100644 --- a/Simulator/UnitOperations/DistillationColumn/Cond.mo +++ b/Simulator/UnitOperations/DistillationColumn/Cond.mo @@ -3,20 +3,20 @@ within Simulator.UnitOperations.DistillationColumn; model Cond "Model of a condenser used in distillation column" import Simulator.Files.*; parameter ChemsepDatabase.GeneralProperties C[Nc]; - parameter Integer Nc = 2 "Number of components"; + parameter Integer Nc "Number of components"; parameter Boolean Bin = false; Real P(unit = "K", min = 0, start = Pg) "Pressure"; Real T(unit = "Pa", min = 0, start = Tg) "Temperature"; Real Fin(unit = "mol/s", min = 0, start =Fg) "Feed molar flow rate"; Real xin_c[Nc](each unit = "-", each min = 0, each max = 1, start=xg) "Feed components mole fraction"; - Real xvapin_c[Nc](each unit = "-", each min = 0, each max = 1, start=xvapg) "Inlet components vapor molar fraction"; + Real xvapin_c[Nc](each unit = "-", each min = 0, each max = 1, each start=xvapg) "Inlet components vapor molar fraction"; Real Hin(unit = "kJ/kmol",start=Htotg) "Feed inlet molar enthalpy"; Real Fout(unit = "mol/s", min = 0, start = Fg) "Side draw molar flow"; Real Fvapin(unit = "mol/s", min = 0, start = Fg) "Inlet vapor molar flow"; Real Fliqout(unit = "mol/s", min = 0, start = Fg) "Outlet liquid molar flow"; Real xout_c[Nc](each unit = "-", each min = 0, each max = 1, start=xg) "Side draw components mole fraction"; - Real xliqout_c[Nc](each unit = "-", each min = 0, each max = 1, start=xliqg) "Outlet components liquid mole fraction"; + Real xliqout_c[Nc](each unit = "-", each min = 0, each max = 1, each start=xliqg) "Outlet components liquid mole fraction"; Real Hvapin(unit = "kJ/kmol",start=Hvapg) "Inlet vapor molar enthalpy"; Real Hliqout(unit = "kJ/kmol",start=Hliqg) "Outlet liquid molar enthalpy"; @@ -27,6 +27,11 @@ within Simulator.UnitOperations.DistillationColumn; Real Pdew(unit = "Pa", min = 0, start = Pmax) "Dew point pressure"; Real Pbubl(unit = "Pa", min = 0,start=Pmin) "Bubble point pressure"; + //Thermodynamics packages variables + Real K_c[Nc](each min = 0), Cpres_p[3], Hres_p[3], Sres_p[3]; + Real gma_c[Nc], gmabubl_c[Nc], gmadew_c[Nc]; + Real philiqbubl_c[Nc], phivapdew_c[Nc], Pvap_c[Nc]; + //String sideDrawType(start = "Null"); //L or V parameter String Ctype "Condenser type: Partial or Total"; diff --git a/Simulator/UnitOperations/DistillationColumn/DistCol.mo b/Simulator/UnitOperations/DistillationColumn/DistCol.mo index 106c2bd..d88cb16 100644 --- a/Simulator/UnitOperations/DistillationColumn/DistCol.mo +++ b/Simulator/UnitOperations/DistillationColumn/DistCol.mo @@ -35,8 +35,13 @@ within Simulator.UnitOperations.DistillationColumn; Placement(visible = true, transformation(origin = {252, -588}, extent = {{-10, -10}, {10, 10}}, rotation = 0), iconTransformation(origin = {250, -598}, extent = {{-10, -10}, {10, 10}}, rotation = 0))); Simulator.Files.Interfaces.matConn Out_s[Nout](each Nc = Nc) annotation( Placement(visible = true, transformation(origin = {-36, 32}, extent = {{-10, -10}, {10, 10}}, rotation = 0), iconTransformation(origin = {-70, 60}, extent = {{-10, -10}, {10, 10}}, rotation = 0))); - Simulator.Files.Interfaces.enConn En[NQ](each Nc = Nc) annotation( - Placement(visible = true, transformation(origin = {-34, -54}, extent = {{-10, -10}, {10, 10}}, rotation = 0), iconTransformation(origin = {-70, -60}, extent = {{-10, -10}, {10, 10}}, rotation = 0))); + //Simulator.Files.Interfaces.enConn En[NQ](each Nc = Nc) annotation( + // Placement(visible = true, transformation(origin = {-34, -54}, extent = {{-10, -10}, {10, 10}}, rotation = 0), iconTransformation(origin = {-70, -60}, extent = {{-10, -10}, {10, 10}}, rotation = 0))); //Commented out since energy connectors don't have Nc parameters + replaceable Simulator.UnitOperations.DistillationColumn.Cond condenser(Nc = Nc, C = C, Ctype = Ctype, Bin = Bin_t[1]); + replaceable Simulator.UnitOperations.DistillationColumn.Reb reboiler(Nc = Nc, C = C, Bin = Bin_t[Nt]); + parameter Boolean Bin_tray[Nt-2] = Bin_t[2:Nt-1]; //Temporary workaround until bug is fixed + replaceable Simulator.UnitOperations.DistillationColumn.DistTray tray[2](each Nc = Nc, each C = C, Bin = Bin_tray); + equation for i in 1:Ni loop if InT_s[i] == 1 then diff --git a/Simulator/UnitOperations/DistillationColumn/DistTray.mo b/Simulator/UnitOperations/DistillationColumn/DistTray.mo index fe2fbad..7636a6b 100644 --- a/Simulator/UnitOperations/DistillationColumn/DistTray.mo +++ b/Simulator/UnitOperations/DistillationColumn/DistTray.mo @@ -3,7 +3,7 @@ within Simulator.UnitOperations.DistillationColumn; model DistTray "Model of a tray used in distillation column" import Simulator.Files.*; parameter ChemsepDatabase.GeneralProperties C[Nc]; - parameter Integer Nc = 2 "Number of components"; + parameter Integer Nc "Number of components"; parameter Boolean Bin = true; Real P(unit = "Pa", min = 0, start = Pg) "Pressure"; Real T(unit = "K", min = 0, start = Tg) "Temperature"; @@ -18,17 +18,23 @@ within Simulator.UnitOperations.DistillationColumn; Real xvap_sc[2, Nc](each unit = "-", each min = 0, each max = 1, start={yg,yg}) "Components vapor mole fraction"; Real xliq_sc[2, Nc](each unit = "-", each min = 0, each max = 1, start={xg,xg}) "Components liquid mole fraction"; - Real Hvap_s[2](unit = "kJ/kmol",start=Hvapg) "Vapor molar enthalpy"; - Real Hliq_s[2](unit = "kJ/kmol",start=Hliqg) "Liquid molar enthalpy"; + Real Hvap_s[2](each unit = "kJ/kmol",each start=Hvapg) "Vapor molar enthalpy"; + Real Hliq_s[2](each unit = "kJ/kmol",each start=Hliqg) "Liquid molar enthalpy"; Real Q(unit = "W") "Heat load"; Real Hout(unit = "kJ/kmol",start=Htotg) "Side draw molar enthalpy"; - Real Hvapout_c[Nc](unit = "kJ/kmol",start=Hvapg) "Outlet components vapor molar enthalpy"; - Real Hliqout_c[Nc](unit = "kJ/kmol",start=Hliqg) "Outlet components liquid molar enthalpy"; - Real x_pc[3, Nc](each min =0, each max = 0,start={xguess,xguess,xguess}); + Real Hvapout_c[Nc](each unit = "kJ/kmol",each start=Hvapg) "Outlet components vapor molar enthalpy"; + Real Hliqout_c[Nc](each unit = "kJ/kmol",each start=Hliqg) "Outlet components liquid molar enthalpy"; + Real x_pc[3, Nc](each min =0, each max = 1,start={xguess,xguess,xguess}); Real Pdew(unit = "Pa", min = 0, start = Pmax) "Dew pressure"; Real Pbubl(unit = "Pa", min = 0, start = Pmin) "Bubble pressure"; Real Pdmy1, Tdmy1, xdmy1_pc[3,Nc], Fdmy1,Hdmy1, Sdmy1, xvapdmy1; + + //Thermodynamics packages variables + Real K_c[Nc](each min = 0), Cpres_p[3], Hres_p[3], Sres_p[3]; + Real gma_c[Nc], gmabubl_c[Nc], gmadew_c[Nc]; + Real philiqbubl_c[Nc], phivapdew_c[Nc], Pvap_c[Nc]; + //this is adjustment done since OpenModelica 1.11 is not handling array modification properly String OutType(start = "Null"); //L or V @@ -49,7 +55,7 @@ within Simulator.UnitOperations.DistillationColumn; Simulator.Files.Interfaces.enConn En annotation( Placement(visible = true, transformation(origin = {100, 40}, extent = {{-10, -10}, {10, 10}}, rotation = 0), iconTransformation(origin = {100, 40}, extent = {{-10, -10}, {10, 10}}, rotation = 0))); extends GuessModels.InitialGuess; - + equation //connector equation if Bin then diff --git a/Simulator/UnitOperations/DistillationColumn/Reb.mo b/Simulator/UnitOperations/DistillationColumn/Reb.mo index 21383aa..110d8c5 100644 --- a/Simulator/UnitOperations/DistillationColumn/Reb.mo +++ b/Simulator/UnitOperations/DistillationColumn/Reb.mo @@ -2,7 +2,7 @@ within Simulator.UnitOperations.DistillationColumn; model Reb "Model of a reboiler used in distillation column" import Simulator.Files.*; - parameter Integer Nc = 2 "Number of components"; + parameter Integer Nc "Number of components"; parameter ChemsepDatabase.GeneralProperties C[Nc]; parameter Boolean Bin = false; Real P(unit = "Pa", min = 0, start = Pg) "Pressure"; @@ -17,7 +17,7 @@ within Simulator.UnitOperations.DistillationColumn; Real Fout(unit = "mol/s", min = 0, start = Fg) "Side draw molar flow"; Real Fvapout(unit = "mol/s", min = 0, start =Fvapg) "Outlet vapor molar flow"; Real xout_c[Nc](each unit = "-", each min = 0, each max = 1, start=xg) "Side draw mole fraction"; - Real xvapout_c[Nc](each unit = "-", each min = 0, each max = 1, start=xvapg) "Outlet vapor component mole fraction"; + Real xvapout_c[Nc](each unit = "-", each min = 0, each max = 1, each start=xvapg) "Outlet vapor component mole fraction"; Real Hvapout(unit = "kJ/kmol",start=Hvapg) "Outlet vapor molar enthalpy"; Real Hvapout_c[Nc](each unit = "kJ/kmol") "Outlet vapor component molar enthalpy"; Real Q(unit = "W") "Heat load"; @@ -25,6 +25,11 @@ within Simulator.UnitOperations.DistillationColumn; Real x_pc[3, Nc](each unit = "-", each min = 0, each max = 1, each start = 1/(Nc + 1)) "Component mole fraction"; Real Pdew(unit = "Pa", min = 0, start = sum(C[:].Pc)/Nc) "Dew point pressure"; Real Pbubl(unit = "Pa", min = 0, start = sum(C[:].Pc)/Nc) "Bubble point pressure"; + + //Thermodynamics packages variables + Real K_c[Nc](each min = 0), Cpres_p[3], Hres_p[3], Sres_p[3]; + Real gma_c[Nc], gmabubl_c[Nc], gmadew_c[Nc]; + Real philiqbubl_c[Nc], phivapdew_c[Nc], Pvap_c[Nc]; replaceable Simulator.Files.Interfaces.matConn In(Nc = Nc) if Bin annotation( Placement(visible = true, transformation(origin = {-100, 0}, extent = {{-10, -10}, {10, 10}}, rotation = 0), iconTransformation(origin = {-100, 0}, extent = {{-10, -10}, {10, 10}}, rotation = 0))); diff --git a/Simulator/UnitOperations/EquilibriumReactor.mo b/Simulator/UnitOperations/EquilibriumReactor.mo index 4791fb0..d7e96e9 100644 --- a/Simulator/UnitOperations/EquilibriumReactor.mo +++ b/Simulator/UnitOperations/EquilibriumReactor.mo @@ -13,7 +13,6 @@ extends Simulator.Files.Icons.EquilibriumReactor; parameter Integer Nc "Number of components" annotation( Dialog(tab = "Reactor Specifications", group = "Component Parameters")); //====================================================================================== - extends Simulator.GuessModels.InitialGuess; //Connector Variables Real Pin(unit = "Pa", min = 0, start = Pg) "Inlet stream pressure"; Real Tin(unit = "K", min = 0, start = Tg) "Inlet stream temperature"; diff --git a/Simulator/UnitOperations/Flash.mo b/Simulator/UnitOperations/Flash.mo index 9a527c8..96171b8 100644 --- a/Simulator/UnitOperations/Flash.mo +++ b/Simulator/UnitOperations/Flash.mo @@ -17,6 +17,10 @@ model Flash "Model of a flash column to separate vapor and liquid phases from a Dialog(tab = "Flash Specifications", group = "Calculation Parameters")); parameter Real Pdef(unit = "Pa") = 101325 "Separation pressure if BPdef is true" annotation( Dialog(tab = "Flash Specifications", group = "Calculation Parameters")); + //Thermodynamics packages variables + Real K_c[Nc](each min = 0), Cpres_p[3], Hres_p[3], Sres_p[3]; + Real gma_c[Nc], gmabubl_c[Nc], gmadew_c[Nc]; + Real philiqbubl_c[Nc], phivapdew_c[Nc], Pvap_c[Nc]; //============================================================================== //Model Variables Real T(unit = "K", start = Tg, min = 0) "Flash column temperature"; diff --git a/Simulator/UnitOperations/HeatExchanger.mo b/Simulator/UnitOperations/HeatExchanger.mo index e60093e..d157a3b 100644 --- a/Simulator/UnitOperations/HeatExchanger.mo +++ b/Simulator/UnitOperations/HeatExchanger.mo @@ -1,9 +1,10 @@ within Simulator.UnitOperations; model HeatExchanger "Model of a heat exchanger used for two streams heat exchange" - extends Simulator.Files.Icons.HeatExchanger; + extends Simulator.Files.Icons.HeatExchanger; + extends GuessModels.InitialGuess; import Simulator.Files.*; - import Simulator.Files.Thermodynamic_Functions.*; + import Simulator.Files.ThermodynamicFunctions.*; parameter Simulator.Files.ChemsepDatabase.GeneralProperties C[Nc] "Component instances array" annotation( Dialog(tab = "Heat Exchanger Specifications", group = "Component Parameters")); parameter Integer Nc "Number of components" annotation( @@ -50,16 +51,16 @@ model HeatExchanger "Model of a heat exchanger used for two streams heat exchang //Cold Stream Inlet Real Pcin(unit = "Pa", start=Pg) "Cold inlet stream pressure"; Real Tcin(unit = "K", start=Tg) "Cold inlet stream temperature"; - Real Fcin[1](unit = "mol/s", start=Fg) "Cold inlet stream molar flow rate"; + Real Fcin[1](unit = {"mol/s"}, start={Fg}) "Cold inlet stream molar flow rate"; Real Hcin(unit = "kJ/kmol", start=Htotg) "Cold inlet stream molar enthalpy"; Real Scin(unit = "kJ/[kmol.K]") "Cold inlet stream molar entropy"; - Real xcin_pc[2, Nc](unit = "-") "Cold inlet stream component mole fraction"; + Real xcin_pc[2, Nc](each unit = "-") "Cold inlet stream component mole fraction"; Real xvapcin(unit = "-", start=xvapg) "Cold inlet stream vapor phase mole fraction"; //Cold Stream Outlet Real Pcout(unit = "Pa", start=Pg) "Cold outlet stream pressure"; Real Tcout(unit = "K", start=Tg)"Cold outlet stream temperature"; Real couttT(unit = "K", start=Tg) ; - Real Fcout[1](unit = "mol/s", start=Fg) "Cold outlet stream molar flow rate"; + Real Fcout[1](unit = {"mol/s"}, start={Fg}) "Cold outlet stream molar flow rate"; Real Hcout(unit = "kJ/kmol", start=Htotg) "Cold outlet stream molar enthalpy"; Real Scout(unit = "kJ/kmol.K") "Cold outlet stream molar entropy"; Real xcout_pc[2, Nc](each unit = "-", start={xg,xg}) "Cold outlet stream component mole fraction"; @@ -277,7 +278,6 @@ model HeatExchanger "Model of a heat exchanger used for two streams heat exchang parameter Real F =0.9828; parameter Real m = 0.96; //=========================================================================================================== - extends GuessModels.InitialGuess; equation //Hot Stream Inlet In_Hot.P = Phin; @@ -725,7 +725,7 @@ Cph_pc[3, i] = ThermodynamicFunctions.VapCpId(C[i].VapCp, Thin); end for; //================================================================================================== for i in 2:3 loop - Cph_p[i] = sum(xhin_pc[i, :] .* Cph_pc[i, :]); + Cph_p[i] = sum(xhin_pc[i-1, :] .* Cph_pc[i, :]); end for; Cph_p[1] = (1-xvaphin) * Cph_p[2] + xvaphin * Cph_p[3]; Cph_pc[1, :] = xhin_pc[1, :] .* Cph_p[1]; @@ -738,7 +738,7 @@ Cpc_pc[3, i] = ThermodynamicFunctions.VapCpId(C[i].VapCp, Tcin); end for; for i in 2:3 loop - Cpc_p[i] = sum(xcin_pc[i, :] .* Cpc_pc[i, :]); + Cpc_p[i] = sum(xcin_pc[i-1, :] .* Cpc_pc[i, :]); end for; Cpc_p[1] = (1-xvapcin) * Cpc_p[2] + xvapcin * Cpc_p[3]; Cpc_pc[1, :] = xcin_pc[1, :] .* Cpc_p[1]; diff --git a/Simulator/UnitOperations/Mixer.mo b/Simulator/UnitOperations/Mixer.mo index 7f52dc8..ba22095 100644 --- a/Simulator/UnitOperations/Mixer.mo +++ b/Simulator/UnitOperations/Mixer.mo @@ -10,7 +10,7 @@ model Mixer "Model of a mixer to mix multiple material streams" parameter Integer NI = 6 "Number of inlet streams" annotation( Dialog(tab = "Mixer Specifications", group = "Calculation Parameters")); - Real Pin[NI](unit = "Pa", min = 0, start = Pg) "Inlet stream pressure"; + Real Pin[NI](each unit = "Pa", each min = 0, each start = Pg) "Inlet stream pressure"; Real xin_sc[NI, Nc](each unit = "-", each min = 0, each max = 1) "Inlet stream component mol fraction"; Real Fin_s[NI](each unit = "mol/s", each min = 0, each start = Fg) "Inlet stream Molar Flow"; Real Hin_s[NI](each unit = "kJ/kmol") "Inlet stream molar enthalpy"; diff --git a/Simulator/UnitOperations/PFR/Integral.mo b/Simulator/UnitOperations/PFR/Integral.mo index 8868634..887e010 100644 --- a/Simulator/UnitOperations/PFR/Integral.mo +++ b/Simulator/UnitOperations/PFR/Integral.mo @@ -1,6 +1,6 @@ within Simulator.UnitOperations.PFR; - function Integral "Function to define the integral part used in the performance equation of a plug floiw reactor" + function Integral "Function to define the integral part used in the performance equation of a plug flow reactor" extends Modelica.Math.Nonlinear.Interfaces.partialScalarFunction; input Integer Nc; @@ -17,14 +17,17 @@ within Simulator.UnitOperations.PFR; input Real Bc[Nr]; input Real Fao; input Real k; + protected Real Rate; algorithm Rate := 1; for i in 2:Nc loop if DO[Base_comp, 1] == 0 then - Rate := Rate * product((Co[i] + Sc[i, 1] / Bc[1] * Co[Base_comp] * u) ^ DO[i, 1]); +// Rate := Rate * product((Co[i] + Sc[i, 1] / Bc[1] * Co[Base_comp] * u) ^ DO[i, 1]); Needs to be changed later when adding support for multiple reactions. + Rate := Rate * (Co[i] + Sc[i, 1] / Bc[1] * Co[Base_comp] * u) ^ DO[i, 1]; else - Rate := Rate * product((Co_dummy[i - 1] * (1 - X_dummy[i - 1])) ^ DO_dummy[i - 1, 1]); +// Rate := Rate * product((Co_dummy[i - 1] * (1 - X_dummy[i - 1])) ^ DO_dummy[i - 1, 1]); + Rate := Rate * (Co_dummy[i - 1] * (1 - X_dummy[i - 1])) ^ DO_dummy[i - 1, 1]; end if; end for; y := Fao / (k * (Co[Base_comp] * (1 - u)) ^ DO[Base_comp, 1] * Rate); diff --git a/Simulator/UnitOperations/PFR/PFR.mo b/Simulator/UnitOperations/PFR/PFR.mo index 76e321c..b1f104c 100644 --- a/Simulator/UnitOperations/PFR/PFR.mo +++ b/Simulator/UnitOperations/PFR/PFR.mo @@ -24,14 +24,14 @@ within Simulator.UnitOperations.PFR; Dialog(tab = "Reactor Specifications", group = "Calculation Parameters")); parameter Real Pdel(unit = "Pa") "Pressure Drop" annotation( Dialog(tab = "Reactor Specifications", group = "Calculation Parameters")); - Integer Base_C "Base component"; + parameter Integer Base_C = BC_r[1] "Base component"; //========================================================================= //Model Variables Integer Phaseindex; //Inlet Stream Variables Real Tin(unit = "K", min = 0, start = Tg) "Inlet stream temperature"; Real Pin(unit = "Pa", min = 0, start = Pg) "Inlet stream pressure"; - Real Fin_pc[3, Nc](each unit = "mol/s", each min = 0, start={Fg,Fliqg,Fvapg}) "Inlet stream components molar flow rate in phase"; + Real Fin_pc[3, Nc](each unit = "mol/s", each min = 0, start=transpose(fill({Fg,Fliqg,Fvapg},Nc))) "Inlet stream components molar flow rate in phase"; Real Fin_p[3](each unit = "mol/s", each min = 0,start={Fg,Fliqg,Fvapg}) "Inlet stream molar flow rate in phase"; Real xin_pc[3, Nc](each unit = "-", each min = 0, each max = 1, start={xg,xg,xg}) "Inlet stream mole fraction"; Real Hin(unit = "kJ/kmol",start=Htotg) "Inlet stream enthalpy"; @@ -43,7 +43,7 @@ within Simulator.UnitOperations.PFR; Real Tout(unit = "K", min = 0, start = Tg) "Outlet stream temperature"; Real Pout(unit = "Pa", min = 0, start = Pg) "Outlet stream pressure"; Real Fout_p[3](each unit = "mol/s", each min = 0, start={Fg,Fliqg,Fvapg}) "Outlet stream molar flow rate"; - Real Fout_pc[3, Nc](each unit = "mol/s", each min = 0, start={Fg,Fliqg,Fvapg}) "Outlet stream components molar flow rate"; + Real Fout_pc[3, Nc](each unit = "mol/s", each min = 0, start=transpose(fill({Fg,Fliqg,Fvapg},Nc))) "Outlet stream components molar flow rate"; Real xout_pc[3, Nc](each min = 0,start={xg,xg,xg}) "Mole Fraction of Component in outlet stream"; Real Hout(unit = "kJ/kmol",start=Htotg) "Outlet stream molar enthalpy"; Real Sout(unit = "kJ/[kmol.K]") "Outlet stream molar entropy"; @@ -97,7 +97,7 @@ within Simulator.UnitOperations.PFR; equation //connector-Equations - In.P = Pin; + In.P = Pin; In.T = Tin; In.F = Fin_p[1]; In.H = Hin; @@ -115,7 +115,6 @@ within Simulator.UnitOperations.PFR; En.Q = Q; //Phase Equilibria //========================================================================================================== - Base_C = BC_r[1]; for i in 1:Nc loop Pvapin_c[i] = Simulator.Files.ThermodynamicFunctions.Psat(C[i].VP, Tin); Pvapout_c[i] = Simulator.Files.ThermodynamicFunctions.Psat(C[i].VP, Tout); diff --git a/Simulator/UnitOperations/ShortcutColumn.mo b/Simulator/UnitOperations/ShortcutColumn.mo index d841d1d..93b7c9b 100644 --- a/Simulator/UnitOperations/ShortcutColumn.mo +++ b/Simulator/UnitOperations/ShortcutColumn.mo @@ -5,6 +5,7 @@ model ShortcutColumn "Model of a shortcut column to calculate minimum reflux in //============================================================================== //Header Files and Parameters extends Simulator.Files.Icons.DistillationColumn; + extends GuessModels.InitialGuess; import data = Simulator.Files.ChemsepDatabase; parameter data.GeneralProperties C[Nc] "Component instances array" annotation( Dialog(tab = "Column Specifications", group = "Component Parameters")); @@ -16,6 +17,10 @@ model ShortcutColumn "Model of a shortcut column to calculate minimum reflux in Dialog(tab = "Column Specifications", group = "Calculation Parameters")); parameter String Ctype = "Total" "Condenser type: Total or Partial" annotation( Dialog(tab = "Column Specifications", group = "Calculation Parameters")); + //Thermodynamics packages variables + Real K_c[Nc](each min = 0), Cpres_p[3], Hres_p[3], Sres_p[3]; + Real gma_c[Nc], gmabubl_c[Nc], gmadew_c[Nc]; + Real philiqbubl_c[Nc], phivapdew_c[Nc], Pvap_c[Nc]; //============================================================================== //Model Variables Real F_p[3](each unit = "mol/s", each min = 0, each start = Fg) "Inlet stream molar flow"; @@ -28,7 +33,7 @@ model ShortcutColumn "Model of a shortcut column to calculate minimum reflux in Real Ntmin(unit = "-", min = 0, start = 10) "Minimum Number of trays"; Real RRmin(unit = "-", start = 1) "Minimum Reflux Ratio"; - Real alpha_c[Nc](unit = "-") "Relative Volatility"; + Real alpha_c[Nc](each unit = "-") "Relative Volatility"; Real theta(unit = "-", start = 1) "Fraction"; Real T(start=Tg) "Thermodynamic Adjustment", P(start=Pg) "Thermodynamic Adjustment"; Real Tcond(unit = "K", start = max(C[:].Tb), min = 0)"Condenser temperature"; @@ -70,7 +75,6 @@ model ShortcutColumn "Model of a shortcut column to calculate minimum reflux in Simulator.Files.Interfaces.enConn En2 annotation( Placement(visible = true, transformation(origin = {254, -592}, extent = {{-10, -10}, {10, 10}}, rotation = 0), iconTransformation(origin = {250, -600}, extent = {{-10, -10}, {10, 10}}, rotation = 0))); - extends GuessModels.InitialGuess; equation //============================================================================== // Connector equations @@ -211,7 +215,7 @@ equation Hvapcond = sum(xvapcond_c[:] .* Hvapcond_c[:]); Fvaprec .* xvapcond_c[:] = Fliqrec .* xliqcond_c[:] + F_p[3] .* x_pc[3, :]; if Ctype == "Partial" then - x_pc[3, :] = K[:] .* xliqcond_c[:]; + x_pc[3, :] = K_c[:] .* xliqcond_c[:]; elseif Ctype == "Total" then x_pc[3, :] = xliqcond_c[:]; end if; diff --git a/Simulator/UnitOperations/Splitter.mo b/Simulator/UnitOperations/Splitter.mo index e4e623c..14e28b8 100644 --- a/Simulator/UnitOperations/Splitter.mo +++ b/Simulator/UnitOperations/Splitter.mo @@ -26,8 +26,8 @@ model Splitter "Model of a splitter to split one material stream into multiple o Real Pout_s[No](each unit = "Pa", each min = 0, each start = Pg) "Outlet Pressure"; Real Tout_s[No](each unit = "K", each min = 0, each start = Tg) "Outlet Temperature"; Real xout_sc[No, Nc](each unit = "-", each min = 0, each max = 1) "Outlet Mixture Molar Fraction"; - Real Fout_c[No](each unit = "mol/s", each min = 0, start = Fg) "Outlet Mixture Molar Flow"; - Real Fmout_c[No](each unit = "kg/s", each min = 0, start = Fg) "Outlet Mixture Mass Flow"; + Real Fout_c[No](each unit = "mol/s", each min = 0, each start = Fg) "Outlet Mixture Molar Flow"; + Real Fmout_c[No](each unit = "kg/s", each min = 0, each start = Fg) "Outlet Mixture Mass Flow"; //============================================================================== //Instantiation of Connectors Simulator.Files.Interfaces.matConn In(Nc = Nc) annotation( diff --git a/Simulator/UnitOperations/Valve.mo b/Simulator/UnitOperations/Valve.mo index 32d3783..d428702 100644 --- a/Simulator/UnitOperations/Valve.mo +++ b/Simulator/UnitOperations/Valve.mo @@ -4,7 +4,7 @@ model Valve "Model of a valve to regulate the pressure of a material stream" extends Simulator.Files.Icons.Valve; parameter Simulator.Files.ChemsepDatabase.GeneralProperties C[Nc] "Component instances array" annotation( Dialog(tab = "Valve Specifications", group = "Component Parameters")); - parameter Integer Nc = 3 "Number of components" annotation( + parameter Integer Nc "Number of components" annotation( Dialog(tab = "Valve Specifications", group = "Component Parameters")); //==================================================================================== Real Fin(unit = "mol/s", min = 0, start = Fg) "Inlet stream molar flow rate";