source: branches/gui/eml/stage_separators/column.mso @ 791

Last change on this file since 791 was 791, checked in by gerson bicca, 13 years ago

updated (fixed bug)

File size: 119.1 KB
Line 
1#*-------------------------------------------------------------------
2* EMSO Model Library (EML) Copyright (C) 2004 - 2007 ALSOC.
3*
4* This LIBRARY is free software; you can distribute it and/or modify
5* it under the therms of the ALSOC FREE LICENSE as available at
6* http://www.enq.ufrgs.br/alsoc.
7*
8* EMSO Copyright (C) 2004 - 2007 ALSOC, original code
9* from http://www.rps.eng.br Copyright (C) 2002-2004.
10* All rights reserved.
11*
12* EMSO is distributed under the therms of the ALSOC LICENSE as
13* available at http://www.enq.ufrgs.br/alsoc.
14*
15*----------------------------------------------------------------------
16* File containg models of columns: distillation, stripping, absorbers
17* rectifier, ....
18*
19* The default nomenclature is:
20*               Type_Column_reboilertype_condensertyper
21*
22* where:
23*       Type = refluxed or reboiled or section
24*       Column = Stripping, Absorption, Rectifier, Distillation
25*       Reboiler type (if exists) = kettle or thermosyphon
26*       Condenser type (if exists) = with subccoling or without subcooling
27*
28*-----------------------------------------------------------------------
29* Author: Paula B. Staudt
30* $Id: column.mso 511 2008-05-12 17:25:33Z paula $
31*---------------------------------------------------------------------*#
32
33using "tray";
34using "reboiler";
35using "condenser";
36using "mixers_splitters/splitter";
37using "tank";
38using "pressure_changers/pump";
39
40Model ControlSection
41
42ATTRIBUTES
43        Pallete = false;
44        Brief = "Control variables for column section.";
45
46PARAMETERS
47        outer NComp             as Integer      (Brief="Number of components");
48
49        Tindicator_TrayNumber   as Integer      (Brief="Temperature Indicator in the tray");
50        Pindicator_TrayNumber   as Integer      (Brief="Pressure Indicator in the tray");
51
52end
53
54Model InitializeSection
55
56ATTRIBUTES
57        Pallete = false;
58        Brief = "Initial conditions for column section.";
59
60PARAMETERS
61        outer NComp             as Integer      (Brief="Number of components");
62
63        TopTemperature          as temperature  (Brief = "Tray Temperature at Column Top", Default = 300);
64        BottomTemperature       as temperature  (Brief = "Tray Temperature at Column Bottom", Default = 330);
65        LevelFraction           as fraction             (Brief = "Tray Level Fraction", Default = 0.5);
66
67        TopComposition(NComp)           as fraction     (Brief = "Component Molar Fraction at Column Top", Default = 0.30);
68        BottomComposition(NComp)        as fraction     (Brief = "Component Molar Fraction at Column Bottom", Default = 0.30);
69
70end
71
72Model InitializeStage
73
74ATTRIBUTES
75        Pallete = false;
76        Brief = "Initial conditions for Packed column section.";
77
78PARAMETERS
79        outer NComp             as Integer      (Brief="Number of components");
80
81        TopStageTemperature             as temperature  (Brief = "Tray Temperature at Column Top", Default = 300);
82        BottomStageTemperature          as temperature  (Brief = "Tray Temperature at Column Bottom", Default = 300);
83       
84        TopStageComposition(NComp)              as fraction     (Brief = "Component Molar Fraction at Top");
85        BottomStageComposition(NComp)   as fraction     (Brief = "Component Molar Fraction at Bottom");
86        LiquidMolarHoldup                               as mol          (Brief="Molar liquid holdup", Default=0.01);
87
88end
89
90Model Section_ColumnBasicX
91
92ATTRIBUTES
93        Pallete         = false;
94        Brief   = "Model of a basic column section.";
95        Info            =
96"Model of a basic column section containing a vetor of TRAYS numbered from the top-down.";
97
98PARAMETERS
99        outer PP                                                        as Plugin                       (Brief="External Physical Properties", Type="PP");
100        outer NComp                                     as Integer              (Brief="Number of components");
101#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
102# Section Column Feed Tray - Side Streams  Location and Numbering
103#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
104        NumberOfTrays                                           as Integer                      (Brief="Number of trays", Default=8);
105        LiqSideTrayIndex(NumberOfTrays)         as Integer                      (Brief="Liquid Side Tray Index", Default=0,Hidden=true);
106        VapSideTrayIndex(NumberOfTrays)         as Integer                      (Brief="Vapour Side Tray Index", Default=0,Hidden=true);
107        FeedTrayTopLocation                                     as Integer                      (Brief="Top Feed tray Location", Default=2);
108        FeedTrayBottomLocation                                  as Integer                      (Brief="Bottom Feed tray Location", Default=3);
109        LiquidSideStreamLocation                        as Integer                      (Brief="Liquid Side Stream Location", Default=2);
110        VapourSideStreamLocation                        as Integer                      (Brief="Vapour Side Stream Location", Default=2);
111        g                                                                       as acceleration         (Brief="Gravity Acceleration",Default=9.81,Hidden=true);
112        Mw(NComp)                                                       as molweight            (Brief="Component Mol Weight",Hidden=true);
113#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
114# Section Column Flow Model for Liquid and Vapour
115#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
116        VapourFlowModel         as Switcher     (Valid = ["Reepmeyer", "Feehery_Fv", "Roffel_Fv", "Klingberg", "Wang_Fv", "Elgue"], Default = "Reepmeyer");
117        LiquidFlowModel         as Switcher     (Valid = ["default", "Wang_Fl", "Olsen", "Feehery_Fl", "Roffel_Fl"], Default = "default");
118#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
119# Section Column Tray Geometry and Auxiliar Parameters
120#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
121        VolumeOfTray            as volume               (Brief="Total Volume of the tray");
122        HeatSupply                      as heat_rate    (Brief="Rate of heat supply");
123        PlateArea                       as area                 (Brief="Plate area = Atray - Adowncomer");
124        HolesArea                       as area                 (Brief="Total holes area");
125        WeirLength                      as length               (Brief="Weir length");
126        WeirHeight                      as length               (Brief="Weir height");
127        FeeheryCoeff            as Real                 (Brief="Feeherys correlation coefficient", Unit='1/m^4', Default=1);
128        ElgueCoeff                      as Real                 (Brief="Elgues correlation coefficient", Unit='kg/m/mol^2', Default=1);
129        OlsenCoeff                      as Real                 (Brief="Olsens correlation coefficient", Default=1);
130        TrayLiquidPasses        as Real                 (Brief="Number of liquid passes in the tray", Default=1);
131       
132        V                               as volume               (Brief="Total Volume of the tray",Hidden=true);
133        Q                               as heat_rate    (Brief="Rate of heat supply",Hidden=true);
134        Ap                              as area                 (Brief="Plate area = Atray - Adowncomer",Hidden=true);
135        Ah                              as area                 (Brief="Total holes area",Hidden=true);
136        lw                              as length               (Brief="Weir length",Hidden=true);
137        hw                              as length               (Brief="Weir height",Hidden=true);
138        beta                    as fraction     (Brief="Aeration fraction");
139        alfa                    as fraction     (Brief="Dry pressure drop coefficient");
140        w                               as Real                 (Brief="Feeherys correlation coefficient", Unit='1/m^4', Default=1,Hidden=true);
141        btray                   as Real                 (Brief="Elgues correlation coefficient", Unit='kg/m/mol^2', Default=1,Hidden=true);
142        fw                              as Real                 (Brief="Olsens correlation coefficient", Default=1,Hidden=true);
143        Np                              as Real                 (Brief="Number of liquid passes in the tray", Default=1,Hidden=true);
144
145        VapourFlow      as Switcher     (Valid = ["on", "off"], Default = "on",Hidden=true);
146        LiquidFlow      as Switcher     (Valid = ["on", "off"], Default = "on",Hidden=true);
147
148SET
149        VapSideTrayIndex(VapourSideStreamLocation) =1;
150        LiqSideTrayIndex(LiquidSideStreamLocation) =1;
151        Mw = PP.MolecularWeight();
152
153        V=VolumeOfTray;
154        Q=HeatSupply;
155        Ap=PlateArea;
156        Ah=HolesArea;
157        lw=WeirLength;
158        hw=WeirHeight ;
159        w=FeeheryCoeff;
160        btray=ElgueCoeff;
161        fw=OlsenCoeff;
162        Np=TrayLiquidPasses;
163
164VARIABLES
165#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
166# Tray Initialization For the Whole Column Section
167#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
168        INITIALIZATION as InitializeSection (Brief = "Column Model Initialization");
169#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
170# Control Ports
171#+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
172        CONTROL as ControlSection (Brief = "Control");
173        out     TCI as control_signal   (Brief="Temperature  Indicator", Protected = true, PosX=1, PosY=0.73);
174        out     PCI as control_signal   (Brief="Pressure Indicator", Protected = true, PosX=0, PosY=0.24);
175#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
176# Column Feed - Side Stream Flow and Murphree Efficiency
177#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++             
178        in      FeedTrayTop                             as stream               (Brief="Feed stream", PosX=0, PosY=0.45);
179        in      FeedTrayBottom                  as stream               (Brief="Feed stream", PosX=0, PosY=0.65);
180       
181                TRAYS(NumberOfTrays)    as tray                 (Brief="Number of trays in the Column Section");
182                VapourDrawOffFlow               as flow_mol     (Brief="Vapour Draw Off Stream Molar Flow Rate");
183                LiquidDrawOffFlow               as flow_mol     (Brief="Vapour Draw Off Stream Molar Flow Rate");
184                MurphreeEff                     as Real                 (Brief="Murphree efficiency for All Trays",Lower=0.01,Upper=1);
185
186CONNECTIONS
187#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
188# Connecting Intermediate Trays
189#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
190        TRAYS([2:NumberOfTrays]).OutletVapour   to TRAYS([1:NumberOfTrays-1]).InletVapour;
191        TRAYS([1:NumberOfTrays-1]).OutletLiquid         to TRAYS([2:NumberOfTrays]).InletLiquid;
192       
193INITIAL
194#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
195# Tray Initialization
196#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
197for i in 1:NumberOfTrays do
198
199"The initial temperature of the TRAYS"
200        TRAYS(i).OutletLiquid.T = INITIALIZATION.TopTemperature+(INITIALIZATION.BottomTemperature-INITIALIZATION.TopTemperature)*((i-1)/(NumberOfTrays-1));
201
202"The initial Level of the TRAYS"
203        TRAYS(i).Level = INITIALIZATION.LevelFraction*hw;
204end
205
206for i in 1:NComp-1 do
207
208for j in 1:NumberOfTrays do
209
210"The initial composition of the TRAYS - Normalized"
211        TRAYS(j).OutletLiquid.z(i) = INITIALIZATION.TopComposition(i)/sum(INITIALIZATION.TopComposition) +(INITIALIZATION.BottomComposition(i)/sum(INITIALIZATION.BottomComposition)-INITIALIZATION.TopComposition(i)/sum(INITIALIZATION.TopComposition) )*((j-1)/(NumberOfTrays-1));
212end
213
214end
215
216EQUATIONS
217#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
218# Control Ports
219#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
220
221"Tray Temperature Indicator"   
222        #TCI*'K' = TRAYS(min([NumberOfTrays, CONTROL.Tindicator_TrayNumber])).OutletVapour.T;
223        TCI*'K' = TRAYS(CONTROL.Tindicator_TrayNumber).OutletVapour.T;
224
225"Tray Pressure Indicator"       
226        #PCI*'atm' = TRAYS(min([NumberOfTrays, CONTROL.Pindicator_TrayNumber])).OutletVapour.P;
227        PCI*'atm' = TRAYS(CONTROL.Pindicator_TrayNumber).OutletVapour.P;
228
229#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
230# Equating Feed Trays Variables to Trays Variables
231#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
232
233for i in 1:NumberOfTrays do
234
235if   i equal FeedTrayTopLocation then   
236
237"FeedTrayTop Inlet Flow"       
238        FeedTrayTop.F= TRAYS(i).Inlet.F;
239
240"FeedTrayTop Inlet Temperature"
241        FeedTrayTop.T = TRAYS(i).Inlet.T;
242
243"FeedTrayTop Inlet Pressure"
244        FeedTrayTop.P = TRAYS(i).Inlet.P;
245
246"FeedTrayTop Inlet Composition"
247        FeedTrayTop.z = TRAYS(i).Inlet.z;
248
249"FeedTrayTop Inlet Vapour Fraction"
250        FeedTrayTop.v = TRAYS(i).Inlet.v;
251
252"FeedTrayTop Inlet Enthalpy"
253        FeedTrayTop.h = TRAYS(i).Inlet.h;
254
255else if   i equal FeedTrayBottomLocation then   
256
257"FeedTrayBottom Inlet Flow"     
258        FeedTrayBottom.F= TRAYS(i).Inlet.F;
259
260"FeedTrayBottom Inlet Temperature"
261        FeedTrayBottom.T = TRAYS(i).Inlet.T;
262
263"FeedTrayBottom Inlet Pressure"
264        FeedTrayBottom.P = TRAYS(i).Inlet.P;
265
266"FeedTrayBottom Inlet Composition"
267        FeedTrayBottom.z = TRAYS(i).Inlet.z;
268
269"FeedTrayBottom Inlet Vapour Fraction"
270        FeedTrayBottom.v = TRAYS(i).Inlet.v;
271
272"FeedTrayBottom Inlet Enthalpy"
273        FeedTrayBottom.h = TRAYS(i).Inlet.h;
274
275else
276
277"Inlet Tray - Flow Sealed"     
278        0*'mol/h'= TRAYS(i).Inlet.F;
279
280"Inlet Tray -  Temperature"
281        FeedTrayBottom.T = TRAYS(i).Inlet.T;
282
283"Inlet Tray -  Pressure"
284        FeedTrayBottom.P = TRAYS(i).Inlet.P;
285
286"Inlet Tray -  Composition"
287        FeedTrayBottom.z = TRAYS(i).Inlet.z;
288
289"Inlet Tray -  Vapour Fraction"
290        FeedTrayBottom.v = TRAYS(i).Inlet.v;
291
292"Inlet Tray -  Enthalpy"
293        FeedTrayBottom.h = TRAYS(i).Inlet.h;
294
295end
296
297end
298
299end
300
301#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
302# Trays Equations
303#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
304
305for i in [1:NumberOfTrays] do
306
307"Murphree Efficiency"
308        TRAYS(i).OutletVapour.z =  MurphreeEff * (TRAYS(i).yideal - TRAYS(i).InletVapour.z) + TRAYS(i).InletVapour.z;
309
310"Level of clear liquid over the weir"
311        TRAYS(i).Level = TRAYS(i).ML*TRAYS(i).vL/Ap;
312
313"Geometry Constraint"
314        V = TRAYS(i).ML* TRAYS(i).vL + TRAYS(i).MV*TRAYS(i).vV;
315
316"Energy Holdup"
317        TRAYS(i).E = TRAYS(i).ML*TRAYS(i).OutletLiquid.h + TRAYS(i).MV*TRAYS(i).OutletVapour.h - TRAYS(i).OutletLiquid.P*V;
318
319"Energy Balance"
320        diff(TRAYS(i).E) = ( TRAYS(i).Inlet.F*TRAYS(i).Inlet.h + TRAYS(i).InletLiquid.F*TRAYS(i).InletLiquid.h + TRAYS(i).InletVapour.F*TRAYS(i).InletVapour.h- TRAYS(i).OutletLiquid.F*TRAYS(i).OutletLiquid.h - TRAYS(i).OutletVapour.F*TRAYS(i).OutletVapour.h
321        -TRAYS(i).VapourSideStream.F*TRAYS(i).VapourSideStream.h - TRAYS(i).LiquidSideStream.F*TRAYS(i).LiquidSideStream.h + Q );
322
323switch LiquidFlow
324                case "on":
325                        switch LiquidFlowModel
326                                case "default":
327                                "Francis Equation"
328                                TRAYS(i).OutletLiquid.F*TRAYS(i).vL = 1.84*'1/s'*lw*((TRAYS(i).Level-(beta*hw))/(beta))^2;
329                       
330                                case "Wang_Fl":
331                                TRAYS(i).OutletLiquid.F*TRAYS(i).vL = 1.84*'m^0.5/s'*lw*((TRAYS(i).Level-(beta*hw))/(beta))^1.5;
332                       
333                                case "Olsen":
334                                TRAYS(i).OutletLiquid.F / 'mol/s'= lw*Np*TRAYS(i).rhoL/sum(Mw*TRAYS(i).OutletVapour.z)/(0.665*fw)^1.5 * ((TRAYS(i).ML*sum(Mw*TRAYS(i).OutletLiquid.z)/TRAYS(i).rhoL/Ap)-hw)^1.5 * 'm^0.5/mol';
335                       
336                                case "Feehery_Fl":
337                                TRAYS(i).OutletLiquid.F = lw*TRAYS(i).rhoL/sum(Mw*TRAYS(i).OutletLiquid.z) * ((TRAYS(i).Level-hw)/750/'mm')^1.5 * 'm^2/s';
338                       
339                                case "Roffel_Fl":
340                                TRAYS(i).OutletLiquid.F = 2/3*TRAYS(i).rhoL/sum(Mw*TRAYS(i).OutletLiquid.z)*lw*(TRAYS(i).ML*sum(Mw*TRAYS(i).OutletLiquid.z)/(Ap*1.3)/TRAYS(i).rhoL)^1.5*sqrt(2*g/
341                                                        (2*(1 - 0.3593/'Pa^0.0888545'*abs(TRAYS(i).OutletVapour.F*sum(Mw*TRAYS(i).OutletVapour.z)/(Ap*1.3)/sqrt(TRAYS(i).rhoV))^0.177709)-1)); #/'(kg/m)^0.0888545/s^0.177709';
342                        end
343                when TRAYS(i).Level < (beta *hw) switchto "off";
344               
345                case "off":
346                "Low level"
347                TRAYS(i).OutletLiquid.F = 0 * 'mol/h';
348                when TRAYS(i).Level > (beta * hw) + 1e-6*'m' switchto "on";
349        end
350       
351switch VapourFlow
352                case "on":
353                        switch VapourFlowModel
354                                case "Reepmeyer":
355                                TRAYS(i).InletVapour.F*TRAYS(i).vV = sqrt((TRAYS(i).InletVapour.P - TRAYS(i).OutletVapour.P)/(TRAYS(i).rhoV*alfa))*Ah;
356                       
357                                case "Feehery_Fv":
358                                TRAYS(i).InletVapour.F = TRAYS(i).rhoV/Ap/w/sum(Mw*TRAYS(i).OutletVapour.z) * sqrt(((TRAYS(i).InletVapour.P - TRAYS(i).OutletVapour.P)-(TRAYS(i).rhoV*g*TRAYS(i).ML*TRAYS(i).vL/Ap))/TRAYS(i).rhoV);
359                       
360                                case "Roffel_Fv":
361                                TRAYS(i).InletVapour.F^1.08 * 0.0013 * 'kg/m/mol^1.08/s^0.92*1e5' = (TRAYS(i).InletVapour.P - TRAYS(i).OutletVapour.P)*1e5 - (beta*sum(TRAYS(i).M*Mw)/(Ap*1.3)*g*1e5) * (TRAYS(i).rhoV*Ah/sum(Mw*TRAYS(i).OutletVapour.z))^1.08 * 'm^1.08/mol^1.08';
362                       
363                                case "Klingberg":
364                                TRAYS(i).InletVapour.F * TRAYS(i).vV = Ap * sqrt(((TRAYS(i).InletVapour.P - TRAYS(i).OutletVapour.P)-TRAYS(i).rhoL*g*TRAYS(i).Level)/TRAYS(i).rhoV);
365                       
366                                case "Wang_Fv":
367                                TRAYS(i).InletVapour.F * TRAYS(i).vV = Ap * sqrt(((TRAYS(i).InletVapour.P - TRAYS(i).OutletVapour.P)-TRAYS(i).rhoL*g*TRAYS(i).Level)/TRAYS(i).rhoV*alfa);
368                               
369                                case "Elgue":
370                                TRAYS(i).InletVapour.F  = sqrt((TRAYS(i).InletVapour.P - TRAYS(i).OutletVapour.P)/btray);
371                        end
372                when TRAYS(i).InletVapour.F < 1e-6 * 'kmol/h' switchto "off";
373               
374                case "off":
375                TRAYS(i).InletVapour.F = 0 * 'mol/s';
376                when TRAYS(i).InletVapour.P > TRAYS(i).OutletVapour.P + TRAYS(i).Level*g*TRAYS(i).rhoL + 1e-1 * 'atm' switchto "on";
377        end
378
379end
380
381end
382
383
384Model SectionColumnBasic
385
386ATTRIBUTES
387        Pallete         = false;
388        Brief   = "Model of a basic column section.";
389        Info            =
390"Model of a basic column section containing a vetor of TRAYS numbered from the top-down.";
391
392PARAMETERS
393        outer PP                as Plugin               (Brief="External Physical Properties", Type="PP");
394        outer NComp     as Integer              (Brief="Number of components");
395#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
396# Section Column Feed Tray - Side Streams  Location and Numbering
397#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
398        NumberOfFeeds                                           as Integer                      (Brief="Number of Feed Trays",Default=3,Protected=true);
399        FeedTrayLocation(NumberOfFeeds)         as Integer                      (Brief="Feed tray Location",Default=2);
400        NumberOfTrays                                           as Integer                      (Brief="Number of trays", Default=8);
401        LiqSideTrayIndex(NumberOfTrays)         as Integer                      (Brief="Liquid Side Tray Index", Default=0,Hidden=true);
402        VapSideTrayIndex(NumberOfTrays)         as Integer                      (Brief="Vapour Side Tray Index", Default=0,Hidden=true);
403
404        LiquidSideStreamLocation                        as Integer                      (Brief="Liquid Side Stream Location", Default=2);
405        VapourSideStreamLocation                        as Integer                      (Brief="Vapour Side Stream Location", Default=2);
406        g                                                                       as acceleration         (Brief="Gravity Acceleration",Default=9.81,Hidden=true);
407        Mw(NComp)                                                       as molweight            (Brief="Component Mol Weight",Hidden=true);
408#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
409# Section Column Flow Model for Liquid and Vapour
410#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
411        VapourFlowModel         as Switcher     (Valid = ["Reepmeyer", "Feehery_Fv", "Roffel_Fv", "Klingberg", "Wang_Fv", "Elgue"], Default = "Reepmeyer");
412        LiquidFlowModel         as Switcher     (Valid = ["default", "Wang_Fl", "Olsen", "Feehery_Fl", "Roffel_Fl"], Default = "default");
413#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
414# Section Column Tray Geometry and Auxiliar Parameters
415#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
416        VolumeOfTray            as volume               (Brief="Total Volume of the tray");
417        HeatSupply                      as heat_rate    (Brief="Rate of heat supply");
418        PlateArea                       as area                 (Brief="Plate area = Atray - Adowncomer");
419        HolesArea                       as area                 (Brief="Total holes area");
420        WeirLength                      as length               (Brief="Weir length");
421        WeirHeight                      as length               (Brief="Weir height");
422        FeeheryCoeff            as Real                 (Brief="Feeherys correlation coefficient", Unit='1/m^4', Default=1,Hidden=true);
423        ElgueCoeff                      as Real                 (Brief="Elgues correlation coefficient", Unit='kg/m/mol^2', Default=1,Hidden=true);
424        OlsenCoeff                      as Real                 (Brief="Olsens correlation coefficient", Default=1,Hidden=true);
425        TrayLiquidPasses        as Real                 (Brief="Number of liquid passes in the tray", Default=1);
426       
427        V                               as volume               (Brief="Total Volume of the tray",Hidden=true);
428        Q                               as heat_rate    (Brief="Rate of heat supply",Hidden=true);
429        Ap                              as area                 (Brief="Plate area = Atray - Adowncomer",Hidden=true);
430        Ah                              as area                 (Brief="Total holes area",Hidden=true);
431        lw                              as length               (Brief="Weir length",Hidden=true);
432        hw                              as length               (Brief="Weir height",Hidden=true);
433        beta                    as fraction     (Brief="Aeration fraction");
434        alfa                    as fraction     (Brief="Dry pressure drop coefficient");
435        w                               as Real                 (Brief="Feeherys correlation coefficient", Unit='1/m^4', Default=1,Hidden=true);
436        btray                   as Real                 (Brief="Elgues correlation coefficient", Unit='kg/m/mol^2', Default=1,Hidden=true);
437        fw                              as Real                 (Brief="Olsens correlation coefficient", Default=1,Hidden=true);
438        Np                              as Real                 (Brief="Number of liquid passes in the tray", Default=1,Hidden=true);
439
440        VapourFlow      as Switcher     (Valid = ["on", "off"], Default = "on",Hidden=true);
441        LiquidFlow      as Switcher     (Valid = ["on", "off"], Default = "on",Hidden=true);
442
443SET
444        VapSideTrayIndex(VapourSideStreamLocation) =1;
445        LiqSideTrayIndex(LiquidSideStreamLocation) =1;
446        Mw = PP.MolecularWeight();
447
448        V=VolumeOfTray;
449        Q=HeatSupply;
450        Ap=PlateArea;
451        Ah=HolesArea;
452        lw=WeirLength;
453        hw=WeirHeight ;
454        w=FeeheryCoeff;
455        btray=ElgueCoeff;
456        fw=OlsenCoeff;
457        Np=TrayLiquidPasses;
458
459VARIABLES
460#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
461# Tray Initialization For the Whole Column Section
462#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
463        INITIALIZATION as InitializeSection (Brief = "Column Model Initialization");
464#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
465# Control Ports
466#+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
467        CONTROL as ControlSection (Brief = "Control");
468        out     TCI as control_signal   (Brief="Temperature  Indicator", Protected = true, PosX=1, PosY=0.73);
469        out     PCI as control_signal   (Brief="Pressure Indicator", Protected = true, PosX=0, PosY=0.24);
470#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
471# Column Feed - Side Stream Flow and Murphree Efficiency
472#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++             
473#       in      FeedTrayTop                             as stream               (Brief="Feed stream", PosX=0, PosY=0.45);
474#       in      FeedTrayBottom                  as stream               (Brief="Feed stream", PosX=0, PosY=0.65);
475       in      LiquidInlet             as      stream                  (Brief="Liquid Inlet in the section", PosX=0.70, PosY=0);
476        out     VapourOutlet    as vapour_stream        (Brief="Vapour Outlet in the section", PosX=0.30, PosY=0);
477       
478        out     VapourDrawOff   as vapour_stream        (Brief="Vapour Draw Off Port in the section", PosX=1, PosY=0.35,Protected = true);
479                out     LiquidDrawOff   as liquid_stream        (Brief="Liquid Draw Off Port in the section", PosX=1, PosY=0.65,Protected = true);
480       
481                TRAYS(NumberOfTrays)    as tray                 (Brief="Number of trays in the Column Section");
482                VapourDrawOffFlow               as flow_mol     (Brief="Vapour Draw Off Stream Molar Flow Rate");
483                LiquidDrawOffFlow               as flow_mol     (Brief="Vapour Draw Off Stream Molar Flow Rate");
484                MurphreeEff                     as Real                 (Brief="Murphree efficiency for All Trays",Lower=0.01,Upper=1);
485
486#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
487# Section Inlet Vapour and Outlet Liquid Material Ports
488#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
489        in      VapourInlet             as stream                       (Brief="Vapour Inlet in the section", PosX=0.30, PosY=1);
490        out     LiquidOutlet    as liquid_stream        (Brief="Liquid Outlet in the section", PosX=0.70, PosY=1);
491       
492                LiquidConnector as stream       (Brief="Liquid connection in the middle TRAYS", PosX=0.75, PosY=1,Hidden=true);
493            VapourConnector as stream       (Brief="Vapour connection in the middle TRAYS", PosX=0.55, PosY=0,Hidden=true);
494CONNECTIONS
495#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
496# Connecting Intermediate Trays
497#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
498        TRAYS([2:NumberOfTrays]).OutletVapour   to TRAYS([1:NumberOfTrays-1]).InletVapour;
499        TRAYS([1:NumberOfTrays-1]).OutletLiquid         to TRAYS([2:NumberOfTrays]).InletLiquid;
500       
501#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
502# Connecting Connectors
503#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
504    LiquidConnector to TRAYS(1).InletLiquid;
505    VapourConnector to TRAYS(NumberOfTrays).InletVapour;
506       
507INITIAL
508#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
509# Tray Initialization
510#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
511for i in 1:NumberOfTrays do
512
513"The initial temperature of the TRAYS"
514        TRAYS(i).OutletLiquid.T = INITIALIZATION.TopTemperature+(INITIALIZATION.BottomTemperature-INITIALIZATION.TopTemperature)*((i-1)/(NumberOfTrays-1));
515
516"The initial Level of the TRAYS"
517        TRAYS(i).Level = INITIALIZATION.LevelFraction*hw;
518end
519
520for i in 1:NComp-1 do
521
522for j in 1:NumberOfTrays do
523
524"The initial composition of the TRAYS - Normalized"
525        TRAYS(j).OutletLiquid.z(i) = INITIALIZATION.TopComposition(i)/sum(INITIALIZATION.TopComposition) +(INITIALIZATION.BottomComposition(i)/sum(INITIALIZATION.BottomComposition)-INITIALIZATION.TopComposition(i)/sum(INITIALIZATION.TopComposition) )*((j-1)/(NumberOfTrays-1));
526end
527
528end
529
530EQUATIONS
531#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
532# Control Ports
533#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
534
535"Tray Temperature Indicator"   
536        #TCI*'K' = TRAYS(min([NumberOfTrays, CONTROL.Tindicator_TrayNumber])).OutletVapour.T;
537        TCI*'K' = TRAYS(CONTROL.Tindicator_TrayNumber).OutletVapour.T;
538
539"Tray Pressure Indicator"       
540        #PCI*'atm' = TRAYS(min([NumberOfTrays, CONTROL.Pindicator_TrayNumber])).OutletVapour.P;
541        PCI*'atm' = TRAYS(CONTROL.Pindicator_TrayNumber).OutletVapour.P;
542
543#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
544# Equating Feed Trays Variables to Trays Variables
545#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
546#*
547for i in 1:NumberOfTrays do
548
549if   i equal FeedTrayTopLocation then   
550
551"FeedTrayTop Inlet Flow"       
552        FeedTrayTop.F= TRAYS(i).Inlet.F;
553
554"FeedTrayTop Inlet Temperature"
555        FeedTrayTop.T = TRAYS(i).Inlet.T;
556
557"FeedTrayTop Inlet Pressure"
558        FeedTrayTop.P = TRAYS(i).Inlet.P;
559
560"FeedTrayTop Inlet Composition"
561        FeedTrayTop.z = TRAYS(i).Inlet.z;
562
563"FeedTrayTop Inlet Vapour Fraction"
564        FeedTrayTop.v = TRAYS(i).Inlet.v;
565
566"FeedTrayTop Inlet Enthalpy"
567        FeedTrayTop.h = TRAYS(i).Inlet.h;
568
569else if   i equal FeedTrayBottomLocation then   
570
571"FeedTrayBottom Inlet Flow"     
572        FeedTrayBottom.F= TRAYS(i).Inlet.F;
573
574"FeedTrayBottom Inlet Temperature"
575        FeedTrayBottom.T = TRAYS(i).Inlet.T;
576
577"FeedTrayBottom Inlet Pressure"
578        FeedTrayBottom.P = TRAYS(i).Inlet.P;
579
580"FeedTrayBottom Inlet Composition"
581        FeedTrayBottom.z = TRAYS(i).Inlet.z;
582
583"FeedTrayBottom Inlet Vapour Fraction"
584        FeedTrayBottom.v = TRAYS(i).Inlet.v;
585
586"FeedTrayBottom Inlet Enthalpy"
587        FeedTrayBottom.h = TRAYS(i).Inlet.h;
588
589else
590
591"Inlet Tray - Flow Sealed"     
592        0*'mol/h'= TRAYS(i).Inlet.F;
593
594"Inlet Tray -  Temperature"
595        FeedTrayBottom.T = TRAYS(i).Inlet.T;
596
597"Inlet Tray -  Pressure"
598        FeedTrayBottom.P = TRAYS(i).Inlet.P;
599
600"Inlet Tray -  Composition"
601        FeedTrayBottom.z = TRAYS(i).Inlet.z;
602
603"Inlet Tray -  Vapour Fraction"
604        FeedTrayBottom.v = TRAYS(i).Inlet.v;
605
606"Inlet Tray -  Enthalpy"
607        FeedTrayBottom.h = TRAYS(i).Inlet.h;
608
609end
610
611end
612
613end
614*#
615#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
616# Trays Equations
617#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
618
619for i in [1:NumberOfTrays] do
620
621"Murphree Efficiency"
622        TRAYS(i).OutletVapour.z =  MurphreeEff * (TRAYS(i).yideal - TRAYS(i).InletVapour.z) + TRAYS(i).InletVapour.z;
623
624"Level of clear liquid over the weir"
625        TRAYS(i).Level = TRAYS(i).ML*TRAYS(i).vL/Ap;
626
627"Geometry Constraint"
628        V = TRAYS(i).ML* TRAYS(i).vL + TRAYS(i).MV*TRAYS(i).vV;
629
630"Energy Holdup"
631        TRAYS(i).E = TRAYS(i).ML*TRAYS(i).OutletLiquid.h + TRAYS(i).MV*TRAYS(i).OutletVapour.h - TRAYS(i).OutletLiquid.P*V;
632
633"Energy Balance"
634        diff(TRAYS(i).E) = ( TRAYS(i).Inlet.F*TRAYS(i).Inlet.h + TRAYS(i).InletLiquid.F*TRAYS(i).InletLiquid.h + TRAYS(i).InletVapour.F*TRAYS(i).InletVapour.h- TRAYS(i).OutletLiquid.F*TRAYS(i).OutletLiquid.h - TRAYS(i).OutletVapour.F*TRAYS(i).OutletVapour.h
635        -TRAYS(i).VapourSideStream.F*TRAYS(i).VapourSideStream.h - TRAYS(i).LiquidSideStream.F*TRAYS(i).LiquidSideStream.h + Q );
636
637switch LiquidFlow
638                case "on":
639                        switch LiquidFlowModel
640                                case "default":
641                                "Francis Equation"
642                                TRAYS(i).OutletLiquid.F*TRAYS(i).vL = 1.84*'1/s'*lw*((TRAYS(i).Level-(beta*hw))/(beta))^2;
643                       
644                                case "Wang_Fl":
645                                TRAYS(i).OutletLiquid.F*TRAYS(i).vL = 1.84*'m^0.5/s'*lw*((TRAYS(i).Level-(beta*hw))/(beta))^1.5;
646                       
647                                case "Olsen":
648                                TRAYS(i).OutletLiquid.F / 'mol/s'= lw*Np*TRAYS(i).rhoL/sum(Mw*TRAYS(i).OutletVapour.z)/(0.665*fw)^1.5 * ((TRAYS(i).ML*sum(Mw*TRAYS(i).OutletLiquid.z)/TRAYS(i).rhoL/Ap)-hw)^1.5 * 'm^0.5/mol';
649                       
650                                case "Feehery_Fl":
651                                TRAYS(i).OutletLiquid.F = lw*TRAYS(i).rhoL/sum(Mw*TRAYS(i).OutletLiquid.z) * ((TRAYS(i).Level-hw)/750/'mm')^1.5 * 'm^2/s';
652                       
653                                case "Roffel_Fl":
654                                TRAYS(i).OutletLiquid.F = 2/3*TRAYS(i).rhoL/sum(Mw*TRAYS(i).OutletLiquid.z)*lw*(TRAYS(i).ML*sum(Mw*TRAYS(i).OutletLiquid.z)/(Ap*1.3)/TRAYS(i).rhoL)^1.5*sqrt(2*g/
655                                                        (2*(1 - 0.3593/'Pa^0.0888545'*abs(TRAYS(i).OutletVapour.F*sum(Mw*TRAYS(i).OutletVapour.z)/(Ap*1.3)/sqrt(TRAYS(i).rhoV))^0.177709)-1)); #/'(kg/m)^0.0888545/s^0.177709';
656                        end
657                when TRAYS(i).Level < (beta *hw) switchto "off";
658               
659                case "off":
660                "Low level"
661                TRAYS(i).OutletLiquid.F = 0 * 'mol/h';
662                when TRAYS(i).Level > (beta * hw) + 1e-6*'m' switchto "on";
663        end
664       
665switch VapourFlow
666                case "on":
667                        switch VapourFlowModel
668                                case "Reepmeyer":
669                                TRAYS(i).InletVapour.F*TRAYS(i).vV = sqrt((TRAYS(i).InletVapour.P - TRAYS(i).OutletVapour.P)/(TRAYS(i).rhoV*alfa))*Ah;
670                       
671                                case "Feehery_Fv":
672                                TRAYS(i).InletVapour.F = TRAYS(i).rhoV/Ap/w/sum(Mw*TRAYS(i).OutletVapour.z) * sqrt(((TRAYS(i).InletVapour.P - TRAYS(i).OutletVapour.P)-(TRAYS(i).rhoV*g*TRAYS(i).ML*TRAYS(i).vL/Ap))/TRAYS(i).rhoV);
673                       
674                                case "Roffel_Fv":
675                                TRAYS(i).InletVapour.F^1.08 * 0.0013 * 'kg/m/mol^1.08/s^0.92*1e5' = (TRAYS(i).InletVapour.P - TRAYS(i).OutletVapour.P)*1e5 - (beta*sum(TRAYS(i).M*Mw)/(Ap*1.3)*g*1e5) * (TRAYS(i).rhoV*Ah/sum(Mw*TRAYS(i).OutletVapour.z))^1.08 * 'm^1.08/mol^1.08';
676                       
677                                case "Klingberg":
678                                TRAYS(i).InletVapour.F * TRAYS(i).vV = Ap * sqrt(((TRAYS(i).InletVapour.P - TRAYS(i).OutletVapour.P)-TRAYS(i).rhoL*g*TRAYS(i).Level)/TRAYS(i).rhoV);
679                       
680                                case "Wang_Fv":
681                                TRAYS(i).InletVapour.F * TRAYS(i).vV = Ap * sqrt(((TRAYS(i).InletVapour.P - TRAYS(i).OutletVapour.P)-TRAYS(i).rhoL*g*TRAYS(i).Level)/TRAYS(i).rhoV*alfa);
682                               
683                                case "Elgue":
684                                TRAYS(i).InletVapour.F  = sqrt((TRAYS(i).InletVapour.P - TRAYS(i).OutletVapour.P)/btray);
685                        end
686                when TRAYS(i).InletVapour.F < 1e-6 * 'kmol/h' switchto "off";
687               
688                case "off":
689                TRAYS(i).InletVapour.F = 0 * 'mol/s';
690                when TRAYS(i).InletVapour.P > TRAYS(i).OutletVapour.P + TRAYS(i).Level*g*TRAYS(i).rhoL + 1e-1 * 'atm' switchto "on";
691        end
692
693end
694
695#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
696# Equating Inlet Liquid Connector Variables
697#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
698"Liquid Inlet Flow"     
699        LiquidConnector.F = LiquidInlet.F;
700
701"Liquid Inlet Temperature"             
702        LiquidConnector.T = LiquidInlet.T;
703
704"Liquid Inlet Pressure"         
705        LiquidConnector.P = LiquidInlet.P;
706
707"Liquid Inlet Composition"             
708        LiquidConnector.z = LiquidInlet.z;
709
710"Liquid Inlet Vapour Fraction"         
711        LiquidConnector.v = LiquidInlet.v;
712
713"Liquid Inlet Enthalpy"         
714        LiquidConnector.h = LiquidInlet.h;
715#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
716# Equating Inlet Vapour Connector Variables
717#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
718"Vapour Inlet Flow"             
719        VapourConnector.F = VapourInlet.F;
720
721"Vapour Inlet Temperature"             
722        VapourConnector.T = VapourInlet.T;
723
724"Vapour Inlet Pressure"         
725        VapourConnector.P = VapourInlet.P;
726
727"Vapour Inlet Composition"             
728        VapourConnector.z = VapourInlet.z;
729
730"Vapour Inlet Vapour Fraction"         
731        VapourConnector.v = VapourInlet.v;
732
733"Vapour Inlet Enthalpy"         
734        VapourConnector.h = VapourInlet.h;
735#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
736# Equating Outlet Liquid Variables
737#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
738"Liquid Outlet Flow"   
739        LiquidOutlet.F = TRAYS(NumberOfTrays).OutletLiquid.F;
740
741"Liquid Outlet Temperature"     
742        LiquidOutlet.T = TRAYS(NumberOfTrays).OutletLiquid.T;
743
744"Liquid Outlet Pressure"       
745        LiquidOutlet.P = TRAYS(NumberOfTrays).OutletLiquid.P;
746
747"Liquid Outlet Composition"     
748        LiquidOutlet.z = TRAYS(NumberOfTrays).OutletLiquid.z;
749#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
750# Equating Outlet Vapour Variables
751#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
752"Vapour Outlet Flow"           
753        VapourOutlet.F = TRAYS(1).OutletVapour.F;
754
755"Vapour Outlet Temperature"             
756        VapourOutlet.T = TRAYS(1).OutletVapour.T;
757
758"Vapour Outlet Pressure"               
759        VapourOutlet.P = TRAYS(1).OutletVapour.P;
760
761"Vapour Outlet Composition"             
762        VapourOutlet.z = TRAYS(1).OutletVapour.z;
763#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
764# Equating Outlet Vapour Side Stream Variables
765#+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
766"Vapour Draw Off Stream - Flow"         
767        VapourDrawOff.F*VapSideTrayIndex= TRAYS.VapourSideStream.F;
768
769"Vapour Draw Off Stream - Temperature"         
770        VapourDrawOff.T = TRAYS(VapourSideStreamLocation).VapourSideStream.T;
771
772"Vapour Draw Off Stream - Pressure"             
773        VapourDrawOff.P = TRAYS(VapourSideStreamLocation).VapourSideStream.P;
774
775"Vapour Draw Off Stream - Composition"         
776        VapourDrawOff.z = TRAYS(VapourSideStreamLocation).VapourSideStream.z;
777
778"Vapour Draw Off Stream"       
779        VapourDrawOffFlow = VapourDrawOff.F;
780#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
781# Equating Outlet Liquid Side Stream Variables
782#+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
783"Liquid Draw Off Stream - Flow"         
784        LiquidDrawOff.F*LiqSideTrayIndex= TRAYS.LiquidSideStream.F;
785
786"Liquid Draw Off Stream - Temperature" 
787        LiquidDrawOff.T = TRAYS(LiquidSideStreamLocation).LiquidSideStream.T;
788
789"Liquid Draw Off Stream - Pressure"                     
790        LiquidDrawOff.P = TRAYS(LiquidSideStreamLocation).LiquidSideStream.P;
791
792"Liquid Draw Off Stream - Composition" 
793        LiquidDrawOff.z = TRAYS(LiquidSideStreamLocation).LiquidSideStream.z;
794
795"Liquid Draw Off Stream"       
796        LiquidDrawOffFlow = LiquidDrawOff.F;
797
798end
799
800Model Section_Column    as SectionColumnBasic
801
802ATTRIBUTES
803        Pallete         = true;
804        Icon            = "icon/SectionColumn";
805        Brief   = "Model of a column section.";
806        Info            =
807"== Model of a column section containing ==
808* NumberOfTrays TRAYS.
809* One Feed Inlet.
810       
811== Specify ==
812* the feed stream of each tray (Inlet);
813* the Murphree eficiency for each tray Emv;
814* the InletLiquid stream of the top tray;
815* the InletVapour stream of the bottom tray.
816       
817== Initial Conditions ==
818* the TRAYS temperature (OutletLiquid.T);
819* the TRAYS liquid level (Level) OR the TRAYS liquid flow (OutletLiquid.F);
820* (NoComps - 1) OutletLiquid (OR OutletVapour) compositions for each tray.
821";
822
823SET
824        NumberOfFeeds = 1;
825
826VARIABLES
827       
828        in      FeedTray        as stream               (Brief="Feed stream", PosX=0, PosY=0.55);
829
830EQUATIONS
831#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
832# Equating Feed Tray Variables to Trays Variables
833#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
834for i in 1:NumberOfTrays do
835
836if   i equal FeedTrayLocation(1) then   
837
838"FeedTrayTop Inlet Flow"       
839        FeedTray.F= TRAYS(i).Inlet.F;
840
841"FeedTrayTop Inlet Temperature"
842        FeedTray.T = TRAYS(i).Inlet.T;
843
844"FeedTrayTop Inlet Pressure"
845        FeedTray.P = TRAYS(i).Inlet.P;
846
847"FeedTrayTop Inlet Composition"
848        FeedTray.z = TRAYS(i).Inlet.z;
849
850"FeedTrayTop Inlet Vapour Fraction"
851        FeedTray.v = TRAYS(i).Inlet.v;
852
853"FeedTrayTop Inlet Enthalpy"
854        FeedTray.h = TRAYS(i).Inlet.h;
855
856else
857
858"Inlet Tray - Flow Sealed"     
859        0*'mol/h'= TRAYS(i).Inlet.F;
860
861"Inlet Tray -  Temperature"
862        FeedTray.T = TRAYS(i).Inlet.T;
863
864"Inlet Tray -  Pressure"
865        FeedTray.P = TRAYS(i).Inlet.P;
866
867"Inlet Tray -  Composition"
868        FeedTray.z = TRAYS(i).Inlet.z;
869
870"Inlet Tray -  Vapour Fraction"
871        FeedTray.v = TRAYS(i).Inlet.v;
872
873"Inlet Tray -  Enthalpy"
874        FeedTray.h = TRAYS(i).Inlet.h;
875
876end
877
878end
879
880end
881
882Model Section_Column2   as SectionColumnBasic
883
884ATTRIBUTES
885        Pallete         = true;
886        Icon            = "icon/SectionColumn";
887        Brief   = "Model of a column section.";
888        Info            =
889"== Model of a column section containing ==
890* NumberOfTrays TRAYS.
891* Two Feed Inlets.
892       
893== Specify ==
894* the feed stream of each tray (Inlet);
895* the Murphree eficiency for each tray Emv;
896* the InletLiquid stream of the top tray;
897* the InletVapour stream of the bottom tray.
898       
899== Initial Conditions ==
900* the TRAYS temperature (OutletLiquid.T);
901* the TRAYS liquid level (Level) OR the TRAYS liquid flow (OutletLiquid.F);
902* (NoComps - 1) OutletLiquid (OR OutletVapour) compositions for each tray.
903";
904
905SET
906        NumberOfFeeds = 2;
907
908VARIABLES
909       
910        in      FeedTrayOne     as stream               (Brief="Feed stream", PosX=0, PosY=0.45);
911        in      FeedTrayTwo     as stream               (Brief="Feed stream", PosX=0, PosY=0.65);
912
913EQUATIONS
914
915for i in 1:NumberOfTrays do
916
917if   i equal FeedTrayLocation(1) then   
918
919"FeedTrayTop Inlet Flow"       
920        FeedTrayOne.F= TRAYS(i).Inlet.F;
921
922"FeedTrayTop Inlet Temperature"
923        FeedTrayOne.T = TRAYS(i).Inlet.T;
924
925"FeedTrayTop Inlet Pressure"
926        FeedTrayOne.P = TRAYS(i).Inlet.P;
927
928"FeedTrayTop Inlet Composition"
929        FeedTrayOne.z = TRAYS(i).Inlet.z;
930
931"FeedTrayTop Inlet Vapour Fraction"
932        FeedTrayOne.v = TRAYS(i).Inlet.v;
933
934"FeedTrayTop Inlet Enthalpy"
935        FeedTrayOne.h = TRAYS(i).Inlet.h;
936
937else if   i equal FeedTrayLocation(2) then   
938
939"FeedTrayBottom Inlet Flow"     
940        FeedTrayTwo.F= TRAYS(i).Inlet.F;
941
942"FeedTrayBottom Inlet Temperature"
943        FeedTrayTwo.T = TRAYS(i).Inlet.T;
944
945"FeedTrayBottom Inlet Pressure"
946        FeedTrayTwo.P = TRAYS(i).Inlet.P;
947
948"FeedTrayBottom Inlet Composition"
949        FeedTrayTwo.z = TRAYS(i).Inlet.z;
950
951"FeedTrayBottom Inlet Vapour Fraction"
952        FeedTrayTwo.v = TRAYS(i).Inlet.v;
953
954"FeedTrayBottom Inlet Enthalpy"
955        FeedTrayTwo.h = TRAYS(i).Inlet.h;
956
957else
958
959"Inlet Tray - Flow Sealed"     
960        0*'mol/h'= TRAYS(i).Inlet.F;
961
962"Inlet Tray -  Temperature"
963        FeedTrayTwo.T = TRAYS(i).Inlet.T;
964
965"Inlet Tray -  Pressure"
966        FeedTrayTwo.P = TRAYS(i).Inlet.P;
967
968"Inlet Tray -  Composition"
969        FeedTrayTwo.z = TRAYS(i).Inlet.z;
970
971"Inlet Tray -  Vapour Fraction"
972        FeedTrayTwo.v = TRAYS(i).Inlet.v;
973
974"Inlet Tray -  Enthalpy"
975        FeedTrayTwo.h = TRAYS(i).Inlet.h;
976
977end
978
979end
980
981end
982
983end
984
985Model Section_Column3   as SectionColumnBasic
986
987ATTRIBUTES
988        Pallete         = true;
989        Icon            = "icon/SectionColumn";
990        Brief   = "Model of a column section.";
991        Info            =
992"== Model of a column section containing ==
993* NumberOfTrays TRAYS.
994* Three Feed Inlets.
995       
996== Specify ==
997* the feed stream of each tray (Inlet);
998* the Murphree eficiency for each tray Emv;
999* the InletLiquid stream of the top tray;
1000* the InletVapour stream of the bottom tray.
1001       
1002== Initial Conditions ==
1003* the TRAYS temperature (OutletLiquid.T);
1004* the TRAYS liquid level (Level) OR the TRAYS liquid flow (OutletLiquid.F);
1005* (NoComps - 1) OutletLiquid (OR OutletVapour) compositions for each tray.
1006";
1007
1008SET
1009        NumberOfFeeds = 3;
1010
1011VARIABLES
1012       
1013        in      FeedTrayOne     as stream               (Brief="Feed stream", PosX=0, PosY=0.45);
1014        in      FeedTrayTwo     as stream               (Brief="Feed stream", PosX=0, PosY=0.65);
1015        in      FeedTrayThree   as stream               (Brief="Feed stream", PosX=0, PosY=0.85);
1016
1017EQUATIONS
1018
1019for i in 1:NumberOfTrays do
1020
1021if   i equal FeedTrayLocation(1) then   
1022
1023"FeedTrayTop Inlet Flow"       
1024        FeedTrayOne.F= TRAYS(i).Inlet.F;
1025
1026"FeedTrayTop Inlet Temperature"
1027        FeedTrayOne.T = TRAYS(i).Inlet.T;
1028
1029"FeedTrayTop Inlet Pressure"
1030        FeedTrayOne.P = TRAYS(i).Inlet.P;
1031
1032"FeedTrayTop Inlet Composition"
1033        FeedTrayOne.z = TRAYS(i).Inlet.z;
1034
1035"FeedTrayTop Inlet Vapour Fraction"
1036        FeedTrayOne.v = TRAYS(i).Inlet.v;
1037
1038"FeedTrayTop Inlet Enthalpy"
1039        FeedTrayOne.h = TRAYS(i).Inlet.h;
1040
1041else if   i equal FeedTrayLocation(2) then   
1042
1043"FeedTrayBottom Inlet Flow"     
1044        FeedTrayTwo.F= TRAYS(i).Inlet.F;
1045
1046"FeedTrayBottom Inlet Temperature"
1047        FeedTrayTwo.T = TRAYS(i).Inlet.T;
1048
1049"FeedTrayBottom Inlet Pressure"
1050        FeedTrayTwo.P = TRAYS(i).Inlet.P;
1051
1052"FeedTrayBottom Inlet Composition"
1053        FeedTrayTwo.z = TRAYS(i).Inlet.z;
1054
1055"FeedTrayBottom Inlet Vapour Fraction"
1056        FeedTrayTwo.v = TRAYS(i).Inlet.v;
1057
1058"FeedTrayBottom Inlet Enthalpy"
1059        FeedTrayTwo.h = TRAYS(i).Inlet.h;
1060
1061else if   i equal FeedTrayLocation(3) then   
1062
1063"FeedTrayBottom Inlet Flow"     
1064        FeedTrayThree.F= TRAYS(i).Inlet.F;
1065
1066"FeedTrayBottom Inlet Temperature"
1067        FeedTrayThree.T = TRAYS(i).Inlet.T;
1068
1069"FeedTrayBottom Inlet Pressure"
1070        FeedTrayThree.P = TRAYS(i).Inlet.P;
1071
1072"FeedTrayBottom Inlet Composition"
1073        FeedTrayThree.z = TRAYS(i).Inlet.z;
1074
1075"FeedTrayBottom Inlet Vapour Fraction"
1076        FeedTrayThree.v = TRAYS(i).Inlet.v;
1077
1078"FeedTrayBottom Inlet Enthalpy"
1079        FeedTrayThree.h = TRAYS(i).Inlet.h;
1080
1081else
1082
1083"Inlet Tray - Flow Sealed"     
1084        0*'mol/h'= TRAYS(i).Inlet.F;
1085
1086"Inlet Tray -  Temperature"
1087        FeedTrayTwo.T = TRAYS(i).Inlet.T;
1088
1089"Inlet Tray -  Pressure"
1090        FeedTrayTwo.P = TRAYS(i).Inlet.P;
1091
1092"Inlet Tray -  Composition"
1093        FeedTrayTwo.z = TRAYS(i).Inlet.z;
1094
1095"Inlet Tray -  Vapour Fraction"
1096        FeedTrayTwo.v = TRAYS(i).Inlet.v;
1097
1098"Inlet Tray -  Enthalpy"
1099        FeedTrayTwo.h = TRAYS(i).Inlet.h;
1100
1101end
1102
1103end
1104
1105end
1106
1107end
1108
1109end
1110
1111Model Distillation_kettle_cond  as Section_ColumnBasicX
1112
1113ATTRIBUTES
1114        Pallete         = true;
1115        Icon            = "icon/DistillationKettleCond";
1116        Brief           = "Model of a distillation column with dynamic condenser and dynamic reboiler.";
1117        Info            =
1118"== Specify ==
1119* the feed stream of each tray (Inlet);
1120* the Murphree eficiency for each tray Emv;
1121* the pump pressure difference;
1122* the heat supllied in reboiler and condenser;
1123* the condenser vapor outlet flow (OutletVapour.F);
1124* the reboiler liquid outlet flow (OutletLiquid.F);
1125* both splitter outlet flows OR one of the splitter outlet flows and the splitter frac.
1126       
1127== Initial Conditions ==
1128* the TRAYS temperature (OutletLiquid.T);
1129* the TRAYS liquid level (Level) OR the TRAYS liquid flow (OutletLiquid.F);
1130* (NoComps - 1) OutletLiquid (OR OutletVapour) compositions for each tray;
1131       
1132* the condenser temperature (OutletLiquid.T);
1133* the condenser liquid level (Level);
1134* (NoComps - 1) OutletLiquid (OR OutletVapour) compositions;
1135       
1136* the reboiler temperature (OutletLiquid.T);
1137* the reboiler liquid level (Level);
1138* (NoComps - 1) OutletLiquid (OR OutletVapour) compositions.
1139";
1140       
1141PARAMETERS
1142        CondenserVapourFlow             as Switcher     (Valid = ["on", "off"], Default = "on",Hidden=true);
1143
1144VARIABLES
1145        out     VapourDrawOff   as vapour_stream                (Brief="Vapour Outlet in the section", PosX=1, PosY=0.375,Protected = true);
1146        out     LiquidDrawOff           as liquid_stream                        (Brief="Liquid Outlet in the section", PosX=1, PosY=0.42,Protected = true);
1147#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1148# Column Devices
1149#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++     
1150        CONDENSER               as condenser;
1151        REBOILER                as reboiler;
1152        SPLITTER                as splitter2;
1153        PUMP                    as pump;
1154        alfaTopo                as Real;
1155#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1156# Heat Ports
1157#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1158        in      HeatToReboiler  as power (Brief="Heat supplied to Reboiler",Protected = true, PosX=1, PosY=0.90);
1159        in      HeatToCondenser as power (Brief="Heat supplied to Condenser", Protected = true, PosX=1, PosY=0.034);
1160#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1161# Column Connectors
1162#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++     
1163                ConnectorHeatReboiler   as power        (Brief="Heat supplied to Reboiler", Hidden=true);
1164                ConnectorHeatCondenser  as power        (Brief="Heat supplied to Condenser", Hidden=true);
1165        in      ConnectorCondenserVout  as stream       (Brief="Connector for Vapour outlet stream From Condenser", Hidden=true);
1166        in      ConnectorReboilerLout   as stream       (Brief="Connector for Liquid outlet stream From Reboiler", Hidden=true);
1167        in      ConnectorSplitterOut    as stream       (Brief="Connector for Liquid outlet stream From Top Splitter", Hidden=true);
1168#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1169# Column products
1170#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++     
1171        out     VapourDistillate        as vapour_stream        (Brief="Vapour outlet stream From Condenser", PosX=0.66, PosY=0);
1172        out     LiquidDistillate        as liquid_stream        (Brief="Liquid outlet stream From Top Splitter", PosX=1, PosY=0.20);
1173        out     BottomProduct           as liquid_stream        (Brief="Liquid outlet stream From Reboiler", PosX=0.67, PosY=1);
1174
1175EQUATIONS
1176
1177switch CondenserVapourFlow
1178
1179        case "on":
1180                CONDENSER.InletVapour.F*TRAYS(1).vV = alfaTopo *Ah * sqrt(2*(TRAYS(1).OutletVapour.P -
1181                CONDENSER.OutletLiquid.P + 1e-8 * 'atm') / (alfa*TRAYS(1).rhoV));
1182                when CONDENSER.InletVapour.F < 1e-6 * 'kmol/h' switchto "off";
1183
1184        case "off":
1185                CONDENSER.InletVapour.F = 0 * 'mol/s';
1186                when TRAYS(1).OutletVapour.P > CONDENSER.OutletLiquid.P + 1e-1 * 'atm' switchto "on";
1187
1188end     
1189
1190# Condenser Connector Equations
1191        ConnectorCondenserVout.T = VapourDistillate.T;
1192        ConnectorCondenserVout.P = VapourDistillate.P;
1193        ConnectorCondenserVout.F = VapourDistillate.F;
1194        ConnectorCondenserVout.z = VapourDistillate.z;
1195
1196# Splitter Connector Equations
1197        ConnectorSplitterOut.T = LiquidDistillate.T;
1198        ConnectorSplitterOut.P = LiquidDistillate.P;
1199        ConnectorSplitterOut.F = LiquidDistillate.F;
1200        ConnectorSplitterOut.z = LiquidDistillate.z;
1201
1202# Reboiler Connector Equations
1203        ConnectorReboilerLout.T = BottomProduct.T;
1204        ConnectorReboilerLout.P = BottomProduct.P;
1205        ConnectorReboilerLout.F = BottomProduct.F;
1206        ConnectorReboilerLout.z = BottomProduct.z;
1207
1208        VapourDrawOff.F*VapSideTrayIndex= TRAYS.VapourSideStream.F;
1209        VapourDrawOff.T = TRAYS(VapourSideStreamLocation).VapourSideStream.T;
1210        VapourDrawOff.P = TRAYS(VapourSideStreamLocation).VapourSideStream.P;
1211        VapourDrawOff.z = TRAYS(VapourSideStreamLocation).VapourSideStream.z;
1212
1213        LiquidDrawOff.F*LiqSideTrayIndex= TRAYS.LiquidSideStream.F;
1214        LiquidDrawOff.T = TRAYS(LiquidSideStreamLocation).LiquidSideStream.T;
1215        LiquidDrawOff.P = TRAYS(LiquidSideStreamLocation).LiquidSideStream.P;
1216        LiquidDrawOff.z = TRAYS(LiquidSideStreamLocation).LiquidSideStream.z;
1217
1218        VapourDrawOffFlow = VapourDrawOff.F;
1219        LiquidDrawOffFlow = LiquidDrawOff.F;
1220
1221        HeatToReboiler  = ConnectorHeatReboiler;
1222        HeatToCondenser = ConnectorHeatCondenser;
1223
1224CONNECTIONS
1225#vapor
1226        REBOILER.OutletVapour   to      TRAYS(NumberOfTrays).InletVapour;
1227        TRAYS(1).OutletVapour   to      CONDENSER.InletVapour;
1228
1229#liquid
1230        CONDENSER.OutletLiquid                          to      SPLITTER.Inlet;
1231        SPLITTER.Outlet2                        to      PUMP.Inlet;
1232        PUMP.Outlet                                     to      TRAYS(1).InletLiquid;
1233        TRAYS(NumberOfTrays).OutletLiquid       to      REBOILER.InletLiquid;
1234
1235#Connectors
1236        CONDENSER.OutletVapour  to ConnectorCondenserVout;
1237        SPLITTER.Outlet1 to ConnectorSplitterOut;
1238        REBOILER.OutletLiquid   to ConnectorReboilerLout;
1239
1240        ConnectorHeatReboiler   to REBOILER.InletQ;
1241        ConnectorHeatCondenser  to CONDENSER.InletQ;
1242
1243end
1244
1245Model Distillation_thermosyphon_subcooling      as Section_ColumnBasicX
1246        ATTRIBUTES
1247        Pallete         = true;
1248        Icon            = "icon/DistillationThermosyphonSubcooling";
1249        Brief           = "Model of a distillation column with steady condenser and steady reboiler.";
1250        Info            =
1251"== Specify ==
1252* the feed stream of each tray (Inlet);
1253* the Murphree eficiency for each tray Emv;
1254* the pump head;
1255* the condenser pressure drop;
1256* the heat supllied in top and bottom tanks;
1257* the heat supllied in condenser and reboiler;
1258* the Outlet1 flow in the bottom splitter (spbottom.Outlet1.F) that corresponds to the bottom product;
1259* both  top splitter outlet flows OR one of the splitter outlet flows and the splitter frac.
1260       
1261== Initial Conditions ==
1262* the TRAYS temperature (OutletLiquid.T);
1263* the TRAYS liquid level (Level) OR the TRAYS liquid flow (OutletLiquid.F);
1264* (NoComps - 1) OutletLiquid (OR OutletVapour) compositions for each tray;
1265       
1266* the top tank temperature (OutletLiquid.T);
1267* the top tank liquid level (Level);
1268* (NoComps - 1) OutletLiquid (OR OutletVapour) compositions;
1269       
1270* the bottom tank temperature (OutletLiquid.T);
1271* the bottom tank liquid level (Level);
1272* (NoComps - 1) OutletLiquid (OR OutletVapour) compositions.
1273";
1274
1275PARAMETERS
1276
1277        CondenserVapourFlow as Switcher(Valid = ["on", "off"], Hidden=true, Default = "on");
1278
1279VARIABLES
1280#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1281# Column Vapour and Liquid Draw Sides
1282#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1283        out     VapourDrawOff   as vapour_stream                (Brief="Vapour Outlet in the section", PosX=1, PosY=0.41,Protected = true);
1284        out     LiquidDrawOff   as liquid_stream                (Brief="Liquid Outlet in the section", PosX=1, PosY=0.45,Protected = true);
1285#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1286# Column Devices
1287#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1288        CONDENSER                       as condenserSteady      (Brief="steady state condenser with subcooling");
1289        ACCUMULATOR_TOP         as tank_cylindrical     (Brief="vessel drum (layed cilinder)");
1290        SPLITTER_TOP            as splitter2                    (Brief="splitter which separate reflux and distillate");
1291        PUMP                            as pump                         (Brief="pump in reflux stream");
1292        REBOILER                        as reboilerSteady       (Brief="steady state reboiler (thermosyphon)");
1293        ACCUMULATOR_BOTTOM      as tank                         (Brief="vessel in the bottom of column");
1294        SPLITTER_BOTTOM         as splitter2                    (Brief="splitter who separate the bottom product and the stream to reboiler");
1295        alfaTopo                        as Real;
1296#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1297# Heat Ports
1298#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1299in              HeatToCondenser                 as power        (Brief="Heat supplied to Condenser",PosX=1, PosY=0.099, Protected=true);
1300in              HeatToReboiler                  as power        (Brief="Heat supplied to Reboiler", PosX=1, PosY=0.92,Protected=true);
1301in              HeatToBottomAccumulator as power        (Brief="Heat supplied to Bottom Accumulator",PosX=0, PosY=0.925,Protected=true);
1302in              HeatToTopAccumulator    as power        (Brief="Heat supplied to Top Accumulator", PosX=1, PosY=0.19,Protected=true);
1303#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1304# Column Control Ports
1305#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1306        out     TRI as control_signal   (Brief="Temperature Indicator of Reboiler ", PosX=1, PosY=0.88);
1307        out     LTAI as control_signal  (Brief="Level Indicator of Top Accumulator ", PosX=1, PosY=0.15);
1308        out     TCI as control_signal   (Brief="Temperature Indicator of Condenser ", PosX=1, PosY=0.059);
1309        out     LBAI as control_signal  (Brief="Level Indicator of Bottom Accumulator", PosX=1, PosY=0.77);
1310#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1311# Column Top and Bottom product
1312#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1313out     LiquidDistillate        as liquid_stream        (Brief="Liquid outlet stream From Top Splitter", PosX=1, PosY=0.24);
1314out     BottomProduct           as liquid_stream        (Brief="Liquid outlet stream From Bottom Splitter", PosX=0.18, PosY=1);
1315#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1316# Column Model Connectors
1317#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1318in      ConnectorSplitterBottom         as stream       (Brief="Connector for Liquid outlet stream From Reboiler", Hidden=true);
1319in      ConnectorSplitterTop            as stream       (Brief="Connector for Liquid outlet stream From Top Splitter", Hidden=true);
1320
1321        ConnectorHeatReboiler                   as power        (Brief="Connector for Heat supplied to Reboiler", Hidden=true);
1322        ConnectorHeatCondenser                  as power        (Brief="Connector for Heat supplied to Condenser", Hidden=true);
1323        ConnectorHeatTopAccumulator     as power        (Brief="Connector for Heat supplied to Top Accumulator", Hidden=true);
1324        ConnectorHeatBottomAccumulator  as power        (Brief="Connector for Heat supplied to Bottom Accumulator", Hidden=true);
1325       
1326EQUATIONS
1327
1328"Reboiler Temperature indicator"
1329        TRI * 'K' = REBOILER.OutletVapour.T;
1330
1331"Condenser Temperature indicator"
1332        TCI * 'K' = CONDENSER.OutletLiquid.T;
1333
1334"Top Accumulator Level indicator"
1335        LTAI*ACCUMULATOR_TOP.Vtotal = ACCUMULATOR_TOP.Vfilled;
1336
1337"Bottom Accumulator Level indicator"
1338        LBAI*ACCUMULATOR_BOTTOM.Vtotal = ACCUMULATOR_BOTTOM.Vfilled;
1339       
1340# Heat Connector Equations
1341        HeatToCondenser                 =       ConnectorHeatCondenser;
1342        HeatToReboiler                  =       ConnectorHeatReboiler;
1343        HeatToBottomAccumulator =       ConnectorHeatBottomAccumulator;
1344        HeatToTopAccumulator    =       ConnectorHeatTopAccumulator;
1345
1346# Top Splitter Connector Equations
1347        ConnectorSplitterTop.T = LiquidDistillate.T;
1348        ConnectorSplitterTop.P = LiquidDistillate.P;
1349        ConnectorSplitterTop.F = LiquidDistillate.F;
1350        ConnectorSplitterTop.z = LiquidDistillate.z;
1351
1352# Bottom Splitter Connector Equations
1353        ConnectorSplitterBottom.T = BottomProduct.T;
1354        ConnectorSplitterBottom.P = BottomProduct.P;
1355        ConnectorSplitterBottom.F = BottomProduct.F;
1356        ConnectorSplitterBottom.z = BottomProduct.z;
1357
1358        VapourDrawOff.F*VapSideTrayIndex= TRAYS.VapourSideStream.F;
1359        VapourDrawOff.T = TRAYS(VapourSideStreamLocation).VapourSideStream.T;
1360        VapourDrawOff.P = TRAYS(VapourSideStreamLocation).VapourSideStream.P;
1361        VapourDrawOff.z = TRAYS(VapourSideStreamLocation).VapourSideStream.z;
1362
1363        LiquidDrawOff.F*LiqSideTrayIndex= TRAYS.LiquidSideStream.F;
1364        LiquidDrawOff.T = TRAYS(LiquidSideStreamLocation).LiquidSideStream.T;
1365        LiquidDrawOff.P = TRAYS(LiquidSideStreamLocation).LiquidSideStream.P;
1366        LiquidDrawOff.z = TRAYS(LiquidSideStreamLocation).LiquidSideStream.z;
1367
1368        VapourDrawOffFlow = VapourDrawOff.F;
1369        LiquidDrawOffFlow = LiquidDrawOff.F;
1370
1371switch CondenserVapourFlow
1372
1373        case "on":
1374                CONDENSER.InletVapour.F*TRAYS(1).vV = alfaTopo * Ah * sqrt(2*(TRAYS(1).OutletVapour.P -
1375                CONDENSER.OutletLiquid.P + 1e-8 * 'atm') / (alfa*TRAYS(1).rhoV));
1376                when CONDENSER.InletVapour.F < 1e-6 * 'kmol/h' switchto "off";
1377
1378        case "off":
1379                CONDENSER.InletVapour.F = 0 * 'mol/s';
1380                when TRAYS(1).OutletVapour.P > CONDENSER.OutletLiquid.P + 1e-1 * 'atm' switchto "on";
1381
1382end     
1383
1384CONNECTIONS
1385#vapor
1386        REBOILER.OutletVapour   to TRAYS(NumberOfTrays).InletVapour;
1387        TRAYS(1).OutletVapour   to CONDENSER.InletVapour;
1388
1389#liquid
1390        CONDENSER.OutletLiquid                          to ACCUMULATOR_TOP.Inlet;       
1391        ACCUMULATOR_TOP.Outlet                  to SPLITTER_TOP.Inlet;
1392        SPLITTER_TOP.Outlet2                    to PUMP.Inlet; 
1393        PUMP.Outlet                                     to TRAYS(1).InletLiquid;
1394        TRAYS(NumberOfTrays).OutletLiquid       to ACCUMULATOR_BOTTOM.Inlet;
1395        ACCUMULATOR_BOTTOM.Outlet               to SPLITTER_BOTTOM.Inlet;
1396        SPLITTER_BOTTOM.Outlet2                 to REBOILER.InletLiquid;
1397
1398#Connectors
1399        ConnectorHeatCondenser                  to CONDENSER.InletQ;
1400        ConnectorHeatReboiler                   to REBOILER.InletQ;
1401        ConnectorHeatBottomAccumulator  to ACCUMULATOR_BOTTOM.InletQ;
1402        ConnectorHeatTopAccumulator             to ACCUMULATOR_TOP.InletQ;
1403        SPLITTER_TOP.Outlet1                    to ConnectorSplitterTop;
1404        SPLITTER_BOTTOM.Outlet1                 to ConnectorSplitterBottom;
1405
1406end
1407
1408Model Distillation_thermosyphon_cond as Section_ColumnBasicX
1409        ATTRIBUTES
1410        Pallete         = true;
1411        Icon            = "icon/DistillationThermosyphonCond";
1412        Brief           = "Model of a distillation column with dynamic condenser and steady reboiler.";
1413        Info            =
1414"== Specify ==
1415* the feed stream of each tray (Inlet);
1416* the Murphree eficiency for each tray Emv;
1417* the pump head;
1418* the condenser vapor outlet flow (OutletVapour.F);
1419* the heat supllied in bottom tank;
1420* the heat supllied in condenser and reboiler;
1421* the Outlet1 flow in the bottom splitter (spbottom.Outlet1.F) that corresponds to the bottom product;
1422       
1423== Initial Conditions ==
1424* the TRAYS temperature (OutletLiquid.T);
1425* the TRAYS liquid level (Level) OR the TRAYS liquid flow (OutletLiquid.F);
1426* (NoComps - 1) OutletLiquid (OR OutletVapour) compositions for each tray;
1427       
1428* the condenser temperature (OutletLiquid.T);
1429* the condenser liquid level (Level);
1430* (NoComps - 1) OutletLiquid (OR OutletVapour) compositions;
1431       
1432* the bottom tank temperature (OutletLiquid.T);
1433* the bottom tank liquid level (Level);
1434* (NoComps - 1) OutletLiquid (OR OutletVapour) compositions.
1435";
1436
1437PARAMETERS
1438        CondenserVapourFlow     as Switcher     (Valid = ["on", "off"], Default = "on",Hidden=true);
1439
1440VARIABLES
1441#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1442# Column Vapour and Liquid Draw Sides
1443#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1444        out     VapourDrawOff   as vapour_stream        (Brief="Vapour Outlet in the section", PosX=1, PosY=0.379,Protected = true);
1445        out     LiquidDrawOff   as liquid_stream        (Brief="Liquid Outlet in the section", PosX=1, PosY=0.425,Protected = true);
1446#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1447# Column Devices
1448#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1449        CONDENSER                       as condenser            (Brief="dynamic condenser without subcooling");
1450        SPLITTER_TOP            as splitter2                    (Brief="splitter which separate reflux and distillate");
1451        PUMP                            as pump                         (Brief="pump in reflux stream");
1452        ACCUMULATOR_BOTTOM      as tank                         (Brief="vessel in the bottom of column");
1453        SPLITTER_BOTTOM         as splitter2                    (Brief="splitter who separate the bottom product and the stream to reboiler");
1454        REBOILER                        as reboilerSteady       (Brief="steady state reboiler (thermosyphon)");
1455        alfaTopo                        as Real;
1456#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1457# Heat Ports
1458#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1459in      HeatToCondenser                 as power        (Brief="Heat supplied to Condenser",PosX=1, PosY=0.035, Protected=true);
1460in      HeatToReboiler                  as power        (Brief="Heat supplied to Reboiler", PosX=1, PosY=0.865,Protected=true);
1461in      HeatToBottomAccumulator as power        (Brief="Heat supplied to Bottom Accumulator",PosX=0, PosY=0.92,Protected=true);
1462#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1463# Column Top and Bottom product
1464#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1465out     VapourDistillate        as vapour_stream        (Brief="Vapour outlet stream From Top Condenser", PosX=0.665, PosY=0);
1466out     LiquidDistillate        as liquid_stream        (Brief="Liquid outlet stream From Top Splitter", PosX=1, PosY=0.20);
1467out     BottomProduct           as liquid_stream        (Brief="Liquid outlet stream From Bottom Splitter", PosX=0.18, PosY=1);
1468#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1469# Column Model Connectors
1470#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1471in      ConnectorSplitterBottom as stream       (Brief="Connector for Liquid outlet stream From Reboiler", Hidden=true);
1472in      ConnectorSplitterTop    as stream       (Brief="Connector for Liquid outlet stream From Top Splitter", Hidden=true);
1473in      ConnectorCondenserVout  as stream       (Brief="Connector for Vapour outlet stream From Top Condenser", Hidden=true);
1474
1475        ConnectorHeatReboiler                   as power        (Brief="Connector for Heat supplied to Reboiler", Hidden=true);
1476        ConnectorHeatCondenser                  as power        (Brief="Connector for Heat supplied to Condenser", Hidden=true);
1477        ConnectorHeatBottomAccumulator  as power        (Brief="Connector for Heat supplied to Bottom Accumulator", Hidden=true);
1478
1479EQUATIONS
1480# Heat Connector Equations
1481        HeatToCondenser                 =       ConnectorHeatCondenser;
1482        HeatToReboiler                  =       ConnectorHeatReboiler;
1483        HeatToBottomAccumulator =       ConnectorHeatBottomAccumulator;
1484
1485# Condenser Connector Equations
1486        ConnectorCondenserVout.T = VapourDistillate.T;
1487        ConnectorCondenserVout.P = VapourDistillate.P;
1488        ConnectorCondenserVout.F = VapourDistillate.F;
1489        ConnectorCondenserVout.z = VapourDistillate.z;
1490
1491# Top Splitter Connector Equations
1492        ConnectorSplitterTop.T = LiquidDistillate.T;
1493        ConnectorSplitterTop.P = LiquidDistillate.P;
1494        ConnectorSplitterTop.F = LiquidDistillate.F;
1495        ConnectorSplitterTop.z = LiquidDistillate.z;
1496
1497# Bottom Splitter Connector Equations
1498        ConnectorSplitterBottom.T = BottomProduct.T;
1499        ConnectorSplitterBottom.P = BottomProduct.P;
1500        ConnectorSplitterBottom.F = BottomProduct.F;
1501        ConnectorSplitterBottom.z = BottomProduct.z;
1502
1503        VapourDrawOff.F*VapSideTrayIndex= TRAYS.VapourSideStream.F;
1504        VapourDrawOff.T = TRAYS(VapourSideStreamLocation).VapourSideStream.T;
1505        VapourDrawOff.P = TRAYS(VapourSideStreamLocation).VapourSideStream.P;
1506        VapourDrawOff.z = TRAYS(VapourSideStreamLocation).VapourSideStream.z;
1507
1508        LiquidDrawOff.F*LiqSideTrayIndex= TRAYS.LiquidSideStream.F;
1509        LiquidDrawOff.T = TRAYS(LiquidSideStreamLocation).LiquidSideStream.T;
1510        LiquidDrawOff.P = TRAYS(LiquidSideStreamLocation).LiquidSideStream.P;
1511        LiquidDrawOff.z = TRAYS(LiquidSideStreamLocation).LiquidSideStream.z;
1512
1513        VapourDrawOffFlow = VapourDrawOff.F;
1514        LiquidDrawOffFlow = LiquidDrawOff.F;
1515       
1516switch CondenserVapourFlow
1517                case "on":
1518                CONDENSER.InletVapour.F*TRAYS(1).vV = alfaTopo * Ah * sqrt(2*(TRAYS(1).OutletVapour.P -
1519                CONDENSER.OutletLiquid.P + 1e-8 * 'atm') / (alfa*TRAYS(1).rhoV));
1520                when CONDENSER.InletVapour.F < 1e-6 * 'kmol/h' switchto "off";
1521               
1522                case "off":
1523                CONDENSER.InletVapour.F = 0 * 'mol/s';
1524                when TRAYS(1).OutletVapour.P > CONDENSER.OutletLiquid.P + 1e-1 * 'atm' switchto "on";
1525end     
1526
1527CONNECTIONS
1528#vapor
1529        REBOILER.OutletVapour   to TRAYS(NumberOfTrays).InletVapour;
1530        TRAYS(1).OutletVapour                           to CONDENSER.InletVapour;
1531
1532#liquid
1533        CONDENSER.OutletLiquid          to SPLITTER_TOP.Inlet; 
1534        SPLITTER_TOP.Outlet2                            to PUMP.Inlet;
1535        PUMP.Outlet                                     to TRAYS(1).InletLiquid;
1536        TRAYS(NumberOfTrays).OutletLiquid       to ACCUMULATOR_BOTTOM.Inlet;
1537        ACCUMULATOR_BOTTOM.Outlet                               to SPLITTER_BOTTOM.Inlet;
1538        SPLITTER_BOTTOM.Outlet2                         to REBOILER.InletLiquid;
1539
1540#Connectors
1541ConnectorHeatCondenser                  to CONDENSER.InletQ;
1542ConnectorHeatReboiler                   to REBOILER.InletQ;
1543ConnectorHeatBottomAccumulator  to ACCUMULATOR_BOTTOM.InletQ;
1544CONDENSER.OutletVapour                          to ConnectorCondenserVout;
1545SPLITTER_TOP.Outlet1                    to ConnectorSplitterTop;
1546SPLITTER_BOTTOM.Outlet1                 to ConnectorSplitterBottom;
1547
1548end
1549
1550Model Distillation_kettle_subcooling as Section_ColumnBasicX
1551
1552ATTRIBUTES
1553        Pallete         = true;
1554        Icon            = "icon/DistillationKettleSubcooling";
1555        Brief   = "Model of a distillation column with steady condenser and dynamic reboiler.";
1556        Info            =
1557"== Specify ==
1558* the feed stream of each tray (Inlet);
1559* the Murphree eficiency for each tray (Emv);
1560* the pump pressure difference;
1561* the heat supllied in reboiler and condenser;
1562* the heat supllied in the top tank;
1563* the condenser pressure drop;
1564* the reboiler liquid outlet flow (OutletLiquid.F);
1565* both splitter outlet flows OR one of the splitter outlet flows and the splitter frac.
1566       
1567== Initial Conditions ==
1568* the TRAYS temperature (OutletLiquid.T);
1569* the TRAYS liquid level (Level) OR the TRAYS liquid flow (OutletLiquid.F);
1570* (NoComps - 1) OutletLiquid (OR OutletVapour) compositions for each tray;
1571       
1572* the top tank temperature (OutletLiquid.T);
1573* the top tank liquid level (Level);
1574* (NoComps - 1) OutletLiquid (OR OutletVapour) compositions;
1575       
1576* the reboiler temperature (OutletLiquid.T);
1577* the reboiler liquid level (Level);
1578* (NoComps - 1) OutletLiquid (OR OutletVapour) compositions.
1579";
1580       
1581PARAMETERS
1582        CondenserVapourFlow as Switcher(Valid = ["on", "off"], Default = "on",Hidden=true);
1583
1584VARIABLES
1585#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1586# Column Vapour and Liquid Draw Sides
1587#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1588        out     VapourDrawOff   as vapour_stream        (Brief="Vapour Outlet in the section", PosX=1, PosY=0.41,Protected = true);
1589        out     LiquidDrawOff   as liquid_stream        (Brief="Liquid Outlet in the section", PosX=1, PosY=0.45,Protected = true);
1590#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1591# Column Devices
1592#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++     
1593        CONDENSER               as condenserSteady      (Brief="steady state condenser with subcooling");
1594        ACCUMULATOR             as tank_cylindrical     (Brief="vessel drum (layed cilinder)");
1595        SPLITTER                as splitter2                    (Brief="splitter which separate reflux and distillate");
1596        PUMP                    as pump                         (Brief="pump in reflux stream");
1597        REBOILER                as reboiler                     (Brief="kettle reboiler");
1598        alfaTopo                as Real;
1599#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1600# Heat Ports
1601#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1602in              HeatToCondenser         as power        (Brief="Heat supplied to Condenser", PosX=1, PosY=0.065, Protected=true);
1603in              HeatToReboiler          as power        (Brief="Heat supplied to Reboiler", PosX=1, PosY=0.905, Protected=true);
1604in              HeatToAccumulator       as power        (Brief="Heat supplied to Top Vessel", PosX=1, PosY=0.195, Protected=true);
1605#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1606# Column Model Connectors
1607#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1608in      ConnectorSplitterOut            as stream       (Brief="Connector for Liquid outlet stream From Top Splitter", Hidden=true);
1609in      ConnectorReboilerLout           as stream       (Brief="Connector for Liquid outlet stream From Reboiler", Hidden=true);
1610        ConnectorHeatReboiler           as power        (Brief="Connector for Heat supplied to Reboiler", Hidden=true);
1611        ConnectorHeatCondenser          as power        (Brief="Connector for Heat supplied to Condenser", Hidden=true);
1612        ConnectorHeatAccumulator        as power        (Brief="Connector for Heat supplied to TopVessel", Hidden=true);
1613#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1614# Column Top and Bottom product
1615#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1616out     LiquidDistillate as liquid_stream       (Brief="Liquid outlet stream From Top Splitter", PosX=1, PosY=0.24);
1617out     BottomProduct    as liquid_stream       (Brief="Liquid outlet stream From Reboiler", PosX=0.67, PosY=1);
1618
1619EQUATIONS
1620
1621#Heat Connectors
1622HeatToCondenser         = ConnectorHeatCondenser;
1623HeatToReboiler          = ConnectorHeatReboiler;
1624HeatToAccumulator       = ConnectorHeatAccumulator;
1625
1626# Splitter Connector Equations
1627        ConnectorSplitterOut.T = LiquidDistillate.T;
1628        ConnectorSplitterOut.P = LiquidDistillate.P;
1629        ConnectorSplitterOut.F = LiquidDistillate.F;
1630        ConnectorSplitterOut.z = LiquidDistillate.z;
1631
1632# Reboiler Connector Equations
1633        ConnectorReboilerLout.T = BottomProduct.T;
1634        ConnectorReboilerLout.P = BottomProduct.P;
1635        ConnectorReboilerLout.F = BottomProduct.F;
1636        ConnectorReboilerLout.z = BottomProduct.z;
1637       
1638        VapourDrawOff.F*VapSideTrayIndex= TRAYS.VapourSideStream.F;
1639        VapourDrawOff.T = TRAYS(VapourSideStreamLocation).VapourSideStream.T;
1640        VapourDrawOff.P = TRAYS(VapourSideStreamLocation).VapourSideStream.P;
1641        VapourDrawOff.z = TRAYS(VapourSideStreamLocation).VapourSideStream.z;
1642
1643        LiquidDrawOff.F*LiqSideTrayIndex= TRAYS.LiquidSideStream.F;
1644        LiquidDrawOff.T = TRAYS(LiquidSideStreamLocation).LiquidSideStream.T;
1645        LiquidDrawOff.P = TRAYS(LiquidSideStreamLocation).LiquidSideStream.P;
1646        LiquidDrawOff.z = TRAYS(LiquidSideStreamLocation).LiquidSideStream.z;
1647
1648        VapourDrawOffFlow = VapourDrawOff.F;
1649        LiquidDrawOffFlow = LiquidDrawOff.F;
1650       
1651        switch CondenserVapourFlow
1652                case "on":
1653                CONDENSER.InletVapour.F*TRAYS(1).vV = alfaTopo * Ah * sqrt(2*(TRAYS(1).OutletVapour.P -
1654                CONDENSER.OutletLiquid.P + 1e-8 * 'atm') / (alfa*TRAYS(1).rhoV));
1655                when CONDENSER.InletVapour.F < 1e-6 * 'kmol/h' switchto "off";
1656               
1657                case "off":
1658                CONDENSER.InletVapour.F = 0 * 'mol/s';
1659                when TRAYS(1).OutletVapour.P > CONDENSER.OutletLiquid.P + 1e-1 * 'atm' switchto "on";
1660end     
1661
1662CONNECTIONS
1663#vapor
1664        REBOILER.OutletVapour to TRAYS(NumberOfTrays).InletVapour;
1665        TRAYS(1).OutletVapour to CONDENSER.InletVapour;
1666
1667#liquid
1668        CONDENSER.OutletLiquid                          to ACCUMULATOR.Inlet;   
1669        ACCUMULATOR.Outlet                                      to SPLITTER.Inlet;
1670        SPLITTER.Outlet2                        to PUMP.Inlet; 
1671        PUMP.Outlet                                     to TRAYS(1).InletLiquid;
1672        TRAYS(NumberOfTrays).OutletLiquid       to REBOILER.InletLiquid;
1673
1674#Connectors
1675ConnectorHeatCondenser          to CONDENSER.InletQ;
1676ConnectorHeatReboiler           to REBOILER.InletQ;
1677ConnectorHeatAccumulator        to ACCUMULATOR.InletQ;
1678
1679SPLITTER.Outlet1 to ConnectorSplitterOut;
1680REBOILER.OutletLiquid   to ConnectorReboilerLout;
1681
1682end
1683
1684Model Rectifier as Section_ColumnBasicX
1685
1686ATTRIBUTES
1687        Pallete         = true;
1688        Icon            = "icon/RefluxedCond";
1689        Brief           = "Model of a rectifier column with dynamic condenser.";
1690        Info            =
1691"== Specify ==
1692* the feed stream of each tray (Inlet);
1693* the Murphree eficiency for each tray Emv;
1694* the InletVapour stream of the bottom tray unless its flow;
1695* the pump pressure difference;
1696* the heat supllied in the condenser;
1697* the condenser vapor outlet flow (OutletVapour.F);
1698* both splitter outlet flows OR one of the splitter outlet flows and the splitter frac.
1699       
1700== Initial Conditions ==
1701* the TRAYS temperature (OutletLiquid.T);
1702* the TRAYS liquid level (Level) OR the TRAYS liquid flow (OutletLiquid.F);
1703* (NoComps - 1) OutletLiquid (OR OutletVapour) compositions for each tray;
1704       
1705* the condenser temperature (OutletLiquid.T);
1706* the condenser liquid level (Level);
1707* (NoComps - 1) OutletLiquid (OR OutletVapour) compositions;
1708";
1709
1710PARAMETERS
1711        CondenserVapourFlow as Switcher(Valid = ["on", "off"], Default = "on",Hidden=true);
1712
1713VARIABLES
1714#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1715# Column Vapour and Liquid Draw Sides
1716#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1717        out     VapourDrawOff   as vapour_stream        (Brief="Vapour Outlet in the section", PosX=1, PosY=0.45,Protected = true);
1718        out     LiquidDrawOff   as liquid_stream        (Brief="Liquid Outlet in the section", PosX=1, PosY=0.50,Protected = true);
1719#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1720# Column Devices
1721#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1722        CONDENSER       as condenser    (Brief="dymamic condenser without subcooling");
1723        SPLITTER        as splitter2            (Brief="splitter which separate reflux and distillate");
1724        PUMP            as pump                 (Brief="pump in reflux stream");
1725        alfaTopo        as Real;
1726#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1727# Column Top product
1728#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1729        out     VapourDistillate        as vapour_stream        (Brief="Vapour outlet stream From Top Condenser", PosX=0.66, PosY=0);
1730        out     LiquidDistillate        as liquid_stream        (Brief="Liquid outlet stream From Top Splitter", PosX=1, PosY=0.24);
1731#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1732# Heat Port
1733#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1734        in      HeatToCondenser         as power (Brief="Heat supplied to Condenser",PosX=1, PosY=0.04, Protected = true);
1735#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1736# Column Bottom Outlets
1737#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++     
1738        in      VapourInlet             as stream                       (Brief="Vapour Inlet in the section", PosX=0.07, PosY=1);
1739        out     LiquidOutlet    as liquid_stream        (Brief="Liquid Outlet in the section", PosX=0.32, PosY=1);
1740#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1741# Column Model Connectors
1742#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1743        in      ConnectorSplitterOut    as stream       (Brief="Connector for Liquid outlet stream From Top Splitter", Hidden=true);
1744        in      ConnectorCondenserVout  as stream       (Brief="Connector for Vapour outlet stream From Top Condenser", Hidden=true);
1745                VapourConnector                 as stream       (Brief="Vapour connection at the middle TRAYS", PosX=0.55, PosY=0,Hidden=true);
1746                ConnectorHeatCondenser  as power        (Brief="Connector for Heat supplied to Condenser", Hidden=true);
1747       
1748EQUATIONS
1749
1750switch CondenserVapourFlow
1751
1752        case "on":
1753                CONDENSER.InletVapour.F*TRAYS(1).vV = alfaTopo * Ah * sqrt(2*(TRAYS(1).OutletVapour.P -
1754                CONDENSER.OutletLiquid.P + 1e-8 * 'atm') / (alfa*TRAYS(1).rhoV));
1755                when CONDENSER.InletVapour.F < 1e-6 * 'kmol/h' switchto "off";
1756               
1757        case "off":
1758                CONDENSER.InletVapour.F = 0 * 'mol/s';
1759                when TRAYS(1).OutletVapour.P > CONDENSER.OutletLiquid.P + 1e-1 * 'atm' switchto "on";
1760
1761end     
1762
1763HeatToCondenser = ConnectorHeatCondenser;
1764
1765# Condenser Connector Equations
1766        ConnectorCondenserVout.T = VapourDistillate.T;
1767        ConnectorCondenserVout.P = VapourDistillate.P;
1768        ConnectorCondenserVout.F = VapourDistillate.F;
1769        ConnectorCondenserVout.z = VapourDistillate.z;
1770       
1771# Splitter Connector Equations
1772        ConnectorSplitterOut.T = LiquidDistillate.T;
1773        ConnectorSplitterOut.P = LiquidDistillate.P;
1774        ConnectorSplitterOut.F = LiquidDistillate.F;
1775        ConnectorSplitterOut.z = LiquidDistillate.z;
1776       
1777        LiquidOutlet.F= TRAYS(NumberOfTrays).OutletLiquid.F;
1778        LiquidOutlet.T = TRAYS(NumberOfTrays).OutletLiquid.T;
1779        LiquidOutlet.P = TRAYS(NumberOfTrays).OutletLiquid.P;
1780        LiquidOutlet.z = TRAYS(NumberOfTrays).OutletLiquid.z;
1781
1782        VapourConnector.F= VapourInlet.F;
1783        VapourConnector.T = VapourInlet.T;
1784        VapourConnector.P = VapourInlet.P;
1785        VapourConnector.z = VapourInlet.z;
1786        VapourConnector.v = VapourInlet.v;
1787        VapourConnector.h = VapourInlet.h;
1788
1789        VapourDrawOff.F*VapSideTrayIndex= TRAYS.VapourSideStream.F;
1790        VapourDrawOff.T = TRAYS(VapourSideStreamLocation).VapourSideStream.T;
1791        VapourDrawOff.P = TRAYS(VapourSideStreamLocation).VapourSideStream.P;
1792        VapourDrawOff.z = TRAYS(VapourSideStreamLocation).VapourSideStream.z;
1793
1794        LiquidDrawOff.F*LiqSideTrayIndex= TRAYS.LiquidSideStream.F;
1795        LiquidDrawOff.T = TRAYS(LiquidSideStreamLocation).LiquidSideStream.T;
1796        LiquidDrawOff.P = TRAYS(LiquidSideStreamLocation).LiquidSideStream.P;
1797        LiquidDrawOff.z = TRAYS(LiquidSideStreamLocation).LiquidSideStream.z;
1798
1799        VapourDrawOffFlow = VapourDrawOff.F;
1800        LiquidDrawOffFlow = LiquidDrawOff.F;
1801
1802CONNECTIONS
1803#vapor
1804        TRAYS(1).OutletVapour to CONDENSER.InletVapour;
1805
1806#liquid
1807        CONDENSER.OutletLiquid  to SPLITTER.Inlet;     
1808        SPLITTER.Outlet2        to PUMP.Inlet; 
1809        PUMP.Outlet             to TRAYS(1).InletLiquid;
1810
1811#Connectors
1812ConnectorHeatCondenser  to CONDENSER.InletQ;
1813VapourConnector                 to TRAYS(NumberOfTrays).InletVapour;
1814SPLITTER.Outlet1                to ConnectorSplitterOut;
1815CONDENSER.OutletVapour          to ConnectorCondenserVout;
1816
1817end
1818
1819Model Rectifier_subcooling as Section_ColumnBasicX
1820
1821ATTRIBUTES
1822        Pallete         = true;
1823        Icon            = "icon/RefluxedSubcooling";
1824        Brief           = "Model of a rectifier column with steady condenser.";
1825        Info            =
1826"== Specify ==
1827* the feed stream of each tray (Inlet);
1828* the Murphree eficiency for each tray Emv;
1829* the InletVapour stream of the bottom tray unless its flow;
1830* the pump head;
1831* the condenser pressure drop;
1832* the heat supllied in  the top tank;
1833* the heat supllied in condenser;
1834* both  top splitter outlet flows OR one of the splitter outlet flows and the splitter frac.
1835       
1836== Initial Conditions ==
1837* the TRAYS temperature (OutletLiquid.T);
1838* the TRAYS liquid level (Level) OR the TRAYS liquid flow (OutletLiquid.F);
1839* (NoComps - 1) OutletLiquid (OR OutletVapour) compositions for each tray;
1840       
1841* the top tank temperature (OutletLiquid.T);
1842* the top tank liquid level (Level);
1843* (NoComps - 1) OutletLiquid (OR OutletVapour) compositions;
1844";
1845       
1846PARAMETERS
1847        CondenserVapourFlow             as Switcher     (Valid = ["on", "off"], Default = "on",Hidden=true);
1848
1849VARIABLES
1850#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1851# Column Vapour and Liquid Draw Sides
1852#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1853        out     VapourDrawOff   as vapour_stream        (Brief="Vapour Outlet in the section", PosX=1, PosY=0.485,Protected = true);
1854        out     LiquidDrawOff   as liquid_stream        (Brief="Liquid Outlet in the section", PosX=1, PosY=0.535,Protected = true);
1855#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1856# Column Devices
1857#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1858        CONDENSER               as condenserSteady      (Brief="steady state condenser with subcooling");
1859        ACCUMULATOR             as tank_cylindrical     (Brief="vessel drum (layed cilinder)");
1860        SPLITTER                as splitter2                    (Brief="plitter which separate reflux and distillate");
1861        PUMP                    as pump                         (Brief="pump in reflux stream");
1862        alfaTopo                as Real;
1863#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1864# Column Bottom outlets
1865#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1866        in      VapourInlet             as stream                       (Brief="Vapour Inlet in the section", PosX=0.07, PosY=1);
1867        out     LiquidOutlet    as liquid_stream        (Brief="Liquid Outlet in the section", PosX=0.32, PosY=1);
1868#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1869# Heat Ports
1870#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1871        in      HeatToCondenser         as power        (Brief="Heat supplied to Condenser", PosX=1, PosY=0.070, Protected=true);
1872        in      HeatToAccumulator       as power        (Brief="Heat supplied to Top Accumulator", PosX=1, PosY=0.23, Protected=true);
1873#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1874# Column Top Product
1875#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1876        out     LiquidDistillate                as liquid_stream        (Brief="Liquid outlet stream From Top Splitter", PosX=1, PosY=0.285);
1877#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1878# Column Connectors
1879#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1880in      ConnectorSplitterTop            as stream       (Brief="Connector for Liquid outlet stream From Top Splitter", Hidden=true);
1881        VapourConnector                         as stream       (Brief="Vapour connection at the middle TRAYS", PosX=0.55, PosY=0,Hidden=true);
1882        ConnectorHeatCondenser          as power        (Brief="Connector for Heat supplied to Condenser", Hidden=true);
1883        ConnectorHeatAccumulator        as power        (Brief="Connector for Heat supplied to Top Accumulator", Hidden=true);
1884
1885EQUATIONS
1886#Heat Connectors
1887        HeatToCondenser         = ConnectorHeatCondenser;
1888        HeatToAccumulator       = ConnectorHeatAccumulator;
1889       
1890        LiquidOutlet.F= TRAYS(NumberOfTrays).OutletLiquid.F;
1891        LiquidOutlet.T = TRAYS(NumberOfTrays).OutletLiquid.T;
1892        LiquidOutlet.P = TRAYS(NumberOfTrays).OutletLiquid.P;
1893        LiquidOutlet.z = TRAYS(NumberOfTrays).OutletLiquid.z;
1894
1895        VapourConnector.F= VapourInlet.F;
1896        VapourConnector.T = VapourInlet.T;
1897        VapourConnector.P = VapourInlet.P;
1898        VapourConnector.z = VapourInlet.z;
1899        VapourConnector.v = VapourInlet.v;
1900        VapourConnector.h = VapourInlet.h;
1901       
1902# Splitter Connector Equations
1903        ConnectorSplitterTop.T = LiquidDistillate.T;
1904        ConnectorSplitterTop.P = LiquidDistillate.P;
1905        ConnectorSplitterTop.F = LiquidDistillate.F;
1906        ConnectorSplitterTop.z = LiquidDistillate.z;
1907
1908        VapourDrawOff.F*VapSideTrayIndex= TRAYS.VapourSideStream.F;
1909        VapourDrawOff.T = TRAYS(VapourSideStreamLocation).VapourSideStream.T;
1910        VapourDrawOff.P = TRAYS(VapourSideStreamLocation).VapourSideStream.P;
1911        VapourDrawOff.z = TRAYS(VapourSideStreamLocation).VapourSideStream.z;
1912
1913        LiquidDrawOff.F*LiqSideTrayIndex= TRAYS.LiquidSideStream.F;
1914        LiquidDrawOff.T = TRAYS(LiquidSideStreamLocation).LiquidSideStream.T;
1915        LiquidDrawOff.P = TRAYS(LiquidSideStreamLocation).LiquidSideStream.P;
1916        LiquidDrawOff.z = TRAYS(LiquidSideStreamLocation).LiquidSideStream.z;
1917
1918        VapourDrawOffFlow = VapourDrawOff.F;
1919        LiquidDrawOffFlow = LiquidDrawOff.F;
1920       
1921switch CondenserVapourFlow
1922
1923        case "on":
1924                CONDENSER.InletVapour.F*TRAYS(1).vV = alfaTopo *Ah * sqrt(2*(TRAYS(1).OutletVapour.P -
1925                CONDENSER.OutletLiquid.P + 1e-8 * 'atm') / (alfa*TRAYS(1).rhoV));
1926        when CONDENSER.InletVapour.F < 1e-6 * 'kmol/h' switchto "off";
1927               
1928        case "off":
1929                CONDENSER.InletVapour.F = 0 * 'mol/s';
1930        when TRAYS(1).OutletVapour.P > CONDENSER.OutletLiquid.P + 1e-1 * 'atm' switchto "on";
1931
1932end     
1933
1934CONNECTIONS
1935#vapor
1936        TRAYS(1).OutletVapour to CONDENSER.InletVapour;
1937
1938#liquid
1939        CONDENSER.OutletLiquid          to ACCUMULATOR.Inlet;   
1940        ACCUMULATOR.Outlet                                      to SPLITTER.Inlet;
1941        SPLITTER.Outlet2                to PUMP.Inlet; 
1942        PUMP.Outlet                                             to TRAYS(1).InletLiquid;
1943
1944#Connectors
1945        VapourConnector                         to TRAYS(NumberOfTrays).InletVapour;
1946        ConnectorHeatCondenser                  to CONDENSER.InletQ;
1947        SPLITTER.Outlet1        to ConnectorSplitterTop;
1948        ConnectorHeatAccumulator                        to ACCUMULATOR.InletQ;
1949
1950end
1951
1952Model Reboiled_Stripping_kettle as Section_ColumnBasicX
1953       
1954ATTRIBUTES
1955        Pallete         = true;
1956        Icon            = "icon/ReboiledKettle";
1957        Brief           = "Model of a reboiled stripping column with dynamic reboiler.";
1958        Info            =
1959"== Specify ==
1960* the feed stream of each tray (Inlet);
1961* the Murphree eficiency for each tray Emv;
1962* the vapour flow leaving the top of the column;
1963* the InletLiquidiquid stream of the top tray;
1964* the heat supllied in the reboiler;
1965* the reboiler liquid outlet flow (OutletLiquid.F);
1966       
1967== Initial Conditions ==
1968* the TRAYS temperature (OutletLiquid.T);
1969* the TRAYS liquid level (Level) OR the TRAYS liquid flow (OutletLiquid.F);
1970* (NoComps - 1) OutletLiquid (OR OutletVapour) compositions for each tray;
1971       
1972* the reboiler temperature (OutletLiquid.T);
1973* the reboiler liquid level (Level);
1974* (NoComps - 1) OutletLiquid (OR OutletVapour) compositions.
1975";
1976
1977VARIABLES
1978#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1979# Column Vapour and Liquid Draw Sides
1980#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1981        out     VapourDrawOff   as vapour_stream        (Brief="Vapour Outlet in the section", PosX=1, PosY=0.28,Protected = true);
1982        out     LiquidDrawOff   as liquid_stream        (Brief="Liquid Outlet in the section", PosX=1, PosY=0.33,Protected = true);
1983#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1984# Column Devices
1985#+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 
1986        REBOILER as reboiler (Brief="Kettle Reboiler");
1987#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1988# Heat Port
1989#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++     
1990        in      HeatToReboiler  as power        (Brief="Heat supplied to Reboiler",PosX=1, PosY=0.865,Protected=true);
1991#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1992# Column Top Outlets
1993#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++             
1994        in      LiquidInlet             as      stream                  (Brief="Liquid Inlet in the section", PosX=0.30, PosY=0);
1995        out     VapourOutlet    as vapour_stream        (Brief="Vapour Outlet in the section", PosX=0.07, PosY=0);
1996#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1997# Column Bottom Product
1998#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++     
1999        out     BottomProduct   as liquid_stream        (Brief="Liquid outlet stream From Reboiler", PosX=0.68, PosY=1);
2000#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2001# Column Connectors
2002#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2003        in      ConnectorReboilerLout   as stream       (Brief="Connector for Liquid outlet stream From Reboiler", Hidden=true);
2004                LiquidConnector                 as stream       (Brief="Liquid connection at the middle TRAYS", PosX=0.75, PosY=1,Hidden=true);
2005                ConnectorHeatReboiler   as power        (Brief="Connector for Heat supplied to Reboiler", Hidden=true);
2006
2007CONNECTIONS
2008#vapor
2009        REBOILER.OutletVapour to TRAYS(NumberOfTrays).InletVapour;
2010       
2011#liquid
2012        TRAYS(NumberOfTrays).OutletLiquid to REBOILER.InletLiquid;
2013
2014#Connectors
2015REBOILER.OutletLiquid           to ConnectorReboilerLout;
2016LiquidConnector                 to TRAYS(1).InletLiquid;
2017ConnectorHeatReboiler   to REBOILER.InletQ;
2018
2019EQUATIONS
2020#Heat Connectors
2021        HeatToReboiler = ConnectorHeatReboiler;
2022       
2023        LiquidConnector.F= LiquidInlet.F;
2024        LiquidConnector.T = LiquidInlet.T;
2025        LiquidConnector.P = LiquidInlet.P;
2026        LiquidConnector.z = LiquidInlet.z;
2027        LiquidConnector.v = LiquidInlet.v;
2028        LiquidConnector.h = LiquidInlet.h;
2029       
2030        VapourOutlet.F= TRAYS(1).OutletVapour.F;
2031        VapourOutlet.T = TRAYS(1).OutletVapour.T;
2032        VapourOutlet.P = TRAYS(1).OutletVapour.P;
2033        VapourOutlet.z = TRAYS(1).OutletVapour.z;
2034       
2035# Reboiler Connector Equations
2036        ConnectorReboilerLout.T = BottomProduct.T;
2037        ConnectorReboilerLout.P = BottomProduct.P;
2038        ConnectorReboilerLout.F = BottomProduct.F;
2039        ConnectorReboilerLout.z = BottomProduct.z;
2040       
2041        VapourDrawOff.F*VapSideTrayIndex= TRAYS.VapourSideStream.F;
2042        VapourDrawOff.T = TRAYS(VapourSideStreamLocation).VapourSideStream.T;
2043        VapourDrawOff.P = TRAYS(VapourSideStreamLocation).VapourSideStream.P;
2044        VapourDrawOff.z = TRAYS(VapourSideStreamLocation).VapourSideStream.z;
2045
2046        LiquidDrawOff.F*LiqSideTrayIndex= TRAYS.LiquidSideStream.F;
2047        LiquidDrawOff.T = TRAYS(LiquidSideStreamLocation).LiquidSideStream.T;
2048        LiquidDrawOff.P = TRAYS(LiquidSideStreamLocation).LiquidSideStream.P;
2049        LiquidDrawOff.z = TRAYS(LiquidSideStreamLocation).LiquidSideStream.z;
2050
2051        VapourDrawOffFlow = VapourDrawOff.F;
2052        LiquidDrawOffFlow = LiquidDrawOff.F;
2053
2054end
2055
2056Model Reboiled_Stripping_thermosyphon as Section_ColumnBasicX
2057
2058ATTRIBUTES
2059        Pallete         = true;
2060        Icon            = "icon/ReboiledThermosyphon";
2061        Brief           = "Model of a reboiled stripping column with steady reboiler.";
2062        Info            =
2063"== Specify ==
2064* the feed stream of each tray (Inlet);
2065* the Murphree eficiency for each tray (Emv);
2066* the vapour flow leaving the top of the column;
2067* the InletLiquidiquid stream of the top tray;
2068* the heat supllied in bottom tank;
2069* the heat supllied in the reboiler;
2070* the Outlet1 flow in the bottom splitter (spbottom.Outlet1.F) that corresponds to the bottom product;
2071       
2072== Initial Conditions ==
2073* the TRAYS temperature (OutletLiquid.T);
2074* the TRAYS liquid level (Level) OR the TRAYS liquid flow (OutletLiquid.F);
2075* (NoComps - 1) OutletLiquid (OR OutletVapour) compositions for each tray;
2076
2077* the bottom tank temperature (OutletLiquid.T);
2078* the bottom tank liquid level (Level);
2079* (NoComps - 1) OutletLiquid (OR OutletVapour) compositions.
2080";
2081
2082VARIABLES
2083#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2084# Column Vapour and Liquid Draw Sides
2085#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2086        out     VapourDrawOff   as vapour_stream        (Brief="Vapour Outlet in the section", PosX=1, PosY=0.28,Protected = true);
2087        out     LiquidDrawOff   as liquid_stream        (Brief="Liquid Outlet in the section", PosX=1, PosY=0.33,Protected = true);
2088#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2089# Column Devices
2090#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++     
2091        REBOILER                as reboilerSteady       (Brief="steady state reboiler (thermosyphon)");
2092        SPLITTER                as splitter2            (Brief="splitter which separate the bottom product and the stream to reboiler");
2093        ACCUMULATOR     as tank                         (Brief="vessel in the bottom of column");
2094#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2095# Heat Ports
2096#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++     
2097        in      HeatToReboiler          as power        (Brief="Heat supplied to Reboiler",PosX=1, PosY=0.84,Protected=true);
2098        in      HeatToAccumulator       as power        (Brief="Heat supplied to Bottom Vessel",PosX=0, PosY=0.91,Protected=true);
2099#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2100# Column Top Outlets
2101#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++     
2102        in      LiquidInlet             as      stream                  (Brief="Liquid Inlet in the section", PosX=0.32, PosY=0);
2103        out     VapourOutlet    as vapour_stream        (Brief="Vapour Outlet in the section", PosX=0.07, PosY=0);
2104#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2105# Column Bottom Product
2106#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++     
2107        out     BottomProduct   as liquid_stream        (Brief="Liquid outlet stream From Reboiler", PosX=0.19, PosY=1);
2108        LiquidConnector         as stream                       (Brief="Liquid connection at the middle TRAYS", PosX=0.75, PosY=1,Hidden=true);
2109#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2110# Column Connectors
2111#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2112        in      ConnectorSplitterBottom         as stream       (Brief="Connector for Liquid outlet stream From Reboiler", Hidden=true);
2113        ConnectorHeatReboiler                   as power        (Brief="Connector for Heat supplied to Reboiler", Hidden=true);
2114        ConnectorHeatAccumulator                as power        (Brief="Connector for Heat supplied to Bottom Accumulator", Hidden=true);
2115
2116CONNECTIONS
2117#vapor
2118        REBOILER.OutletVapour to TRAYS(NumberOfTrays).InletVapour;
2119       
2120#liquid
2121        TRAYS(NumberOfTrays).OutletLiquid       to ACCUMULATOR.Inlet;
2122        ACCUMULATOR.Outlet                              to SPLITTER.Inlet;
2123        SPLITTER.Outlet2                                to REBOILER.InletLiquid;
2124
2125#Connectors
2126LiquidConnector                         to TRAYS(1).InletLiquid;
2127ConnectorHeatReboiler           to REBOILER.InletQ;
2128ConnectorHeatAccumulator        to ACCUMULATOR.InletQ;
2129SPLITTER.Outlet1                        to ConnectorSplitterBottom;
2130
2131EQUATIONS
2132#Heat Connectors
2133        HeatToReboiler  = ConnectorHeatReboiler;
2134        HeatToAccumulator       = ConnectorHeatAccumulator;
2135       
2136        ConnectorSplitterBottom.T = BottomProduct.T;
2137        ConnectorSplitterBottom.P = BottomProduct.P;
2138        ConnectorSplitterBottom.F = BottomProduct.F;
2139        ConnectorSplitterBottom.z = BottomProduct.z;
2140       
2141        LiquidConnector.F= LiquidInlet.F;
2142        LiquidConnector.T = LiquidInlet.T;
2143        LiquidConnector.P = LiquidInlet.P;
2144        LiquidConnector.z = LiquidInlet.z;
2145        LiquidConnector.v = LiquidInlet.v;
2146        LiquidConnector.h = LiquidInlet.h;
2147       
2148        VapourOutlet.F= TRAYS(1).OutletVapour.F;
2149        VapourOutlet.T = TRAYS(1).OutletVapour.T;
2150        VapourOutlet.P = TRAYS(1).OutletVapour.P;
2151        VapourOutlet.z = TRAYS(1).OutletVapour.z;
2152       
2153        VapourDrawOff.F*VapSideTrayIndex= TRAYS.VapourSideStream.F;
2154        VapourDrawOff.T = TRAYS(VapourSideStreamLocation).VapourSideStream.T;
2155        VapourDrawOff.P = TRAYS(VapourSideStreamLocation).VapourSideStream.P;
2156        VapourDrawOff.z = TRAYS(VapourSideStreamLocation).VapourSideStream.z;
2157
2158        LiquidDrawOff.F*LiqSideTrayIndex= TRAYS.LiquidSideStream.F;
2159        LiquidDrawOff.T = TRAYS(LiquidSideStreamLocation).LiquidSideStream.T;
2160        LiquidDrawOff.P = TRAYS(LiquidSideStreamLocation).LiquidSideStream.P;
2161        LiquidDrawOff.z = TRAYS(LiquidSideStreamLocation).LiquidSideStream.z;
2162
2163        VapourDrawOffFlow = VapourDrawOff.F;
2164        LiquidDrawOffFlow = LiquidDrawOff.F;
2165
2166end
2167
2168Model ReactiveDistillation
2169       
2170ATTRIBUTES
2171        Pallete         = true;
2172        Icon            = "icon/DistillationReac";
2173        Brief           = "Model of a reactive distillation column with dynamic condenser and reboiler.";
2174        Info            =
2175"== Specify ==
2176* the reaction related variables for each tray, condenser and reboiler;
2177* the feed stream of each tray (Inlet);
2178* the Murphree eficiency for each tray Emv;
2179* the pump pressure difference;
2180* the heat supllied in reboiler and condenser;
2181* the condenser vapor outlet flow (OutletVapour.F);
2182* the reboiler liquid outlet flow (OutletLiquid.F);
2183* both splitter outlet flows OR one of the splitter outlet flows and the splitter frac.
2184       
2185== Initial Conditions ==
2186* the TRAYS temperature (OutletLiquid.T);
2187* the TRAYS liquid level (Level) OR the TRAYS liquid flow (OutletLiquid.F);
2188* (NoComps - 1) OutletLiquid (OR OutletVapour) compositions for each tray;
2189       
2190* the condenser temperature (OutletLiquid.T);
2191* the condenser liquid level (Level);
2192* (NoComps - 1) OutletLiquid (OR OutletVapour) compositions;
2193       
2194* the reboiler temperature (OutletLiquid.T);
2195* the reboiler liquid level (Level);
2196* (NoComps - 1) OutletLiquid (OR OutletVapour) compositions.
2197";
2198       
2199PARAMETERS
2200        outer PP        as Plugin       (Type="PP");
2201        outer NComp as Integer  (Brief="Number of Components");
2202#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2203# Section Column Feed Tray - Side Streams  Location and Numbering
2204#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2205        NumberOfTrays                                           as Integer      (Brief="Number of TRAYS", Default=2);
2206        FeedTrayIndex(NumberOfTrays)            as Integer      (Brief="Feed Tray Index", Default=0,Hidden=true);
2207        LiqSideTrayIndex(NumberOfTrays)         as Integer      (Brief="Liquid Side Tray Index", Default=0,Hidden=true);
2208        VapSideTrayIndex(NumberOfTrays)         as Integer      (Brief="Vapour Side Tray Index", Default=0,Hidden=true);
2209        FeedTrayLocation                                        as Integer      (Brief="Feed tray Location", Default=2);
2210        LiquidSideStreamLocation                        as Integer      (Brief="Liquid Side Stream Location", Default=2);
2211        VapourSideStreamLocation                        as Integer      (Brief="Vapour Side Stream Location", Default=2);
2212#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2213# Section Column Flow Model for Liquid and Vapour
2214#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2215        VapourFlow              as Switcher     (Valid = ["on", "off"], Default = "off",Hidden=true);
2216        TrayVapourFlow  as Switcher     (Valid = ["on", "off"], Default = "off",Hidden=true);
2217        TrayLiquidFlow  as Switcher     (Valid = ["on", "off"], Default = "off",Hidden=true);
2218        alfacond                as Real;
2219#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2220# Section Column Tray Geometry and Auxiliar Parameters
2221#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2222        V               as volume               (Brief="Total Volume of the tray",Hidden=true);
2223        Q               as power                (Brief="Rate of heat supply",Hidden=true);
2224        Ap              as area                 (Brief="Plate area = Atray - Adowncomer",Hidden=true);
2225        Ah              as area                 (Brief="Total holes area",Hidden=true);
2226        lw              as length               (Brief="Weir length",Hidden=true);
2227        g               as acceleration (Brief="Gravity Acceleration",Default=9.81,Hidden=true);
2228        hw              as length               (Brief="Weir height",Hidden=true);
2229        beta    as fraction     (Brief="Aeration fraction");
2230        alfa    as fraction     (Brief="Dry pressure drop coefficient");
2231
2232        VolumeOfTray            as volume               (Brief="Total Volume of the tray");
2233        HeatSupply                      as heat_rate    (Brief="Rate of heat supply");
2234        PlateArea                       as area                 (Brief="Plate area = Atray - Adowncomer");
2235        HolesArea                       as area                 (Brief="Total holes area");
2236        WeirLength                      as length               (Brief="Weir length");
2237        WeirHeight                      as length               (Brief="Weir height");
2238
2239        stoic(NComp)    as Real(Brief="Stoichiometric matrix");
2240        Hr                                              as energy_mol;
2241       
2242SET
2243
2244        FeedTrayIndex(FeedTrayLocation)         =1;
2245        VapSideTrayIndex(FeedTrayLocation)      =1;
2246        LiqSideTrayIndex(FeedTrayLocation)      =1;
2247
2248        V=VolumeOfTray;
2249        Q=HeatSupply;
2250        Ap=PlateArea;
2251        Ah=HolesArea;
2252        lw=WeirLength;
2253        hw=WeirHeight ;
2254       
2255VARIABLES
2256#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2257# Tray Initialization For the Whole Column Section
2258#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2259        INITIALIZATION          as InitializeSection    (Brief = "Column Model Initialization");
2260#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2261# Column Feed - Side Stream Flow and Murphree Efficiency
2262#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++     
2263        in      FeedTray                        as stream       (Brief="Feed stream", PosX=0, PosY=0.55);
2264                VapourDrawOffFlow       as flow_mol (Brief = "Stream Molar Flow Rate");
2265                LiquidDrawOffFlow   as flow_mol (Brief = "Stream Molar Flow Rate");
2266                MurphreeEff             as Real         (Brief = "Murphree efficiency");
2267#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2268# Column Vapour and Liquid Draw Sides
2269#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2270        out     VapourDrawOff   as vapour_stream        (Brief="Vapour Outlet in the section", PosX=1, PosY=0.395,Protected = true);
2271        out     LiquidDrawOff   as liquid_stream        (Brief="Liquid Outlet in the section", PosX=1, PosY=0.44,Protected = true);
2272#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2273# Heat Ports
2274#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2275        in      HeatToReboiler  as power (Brief="Heat supplied to Reboiler", PosX=1, PosY=0.89);
2276        in      HeatToCondenser as power (Brief="Heat supplied to Condenser", PosX=1, PosY=0.07);
2277#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2278# Column Devices
2279#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2280        TRAYS(NumberOfTrays)    as trayReac;
2281        CONDENSER                               as condenserReact;
2282        REBOILER                                as reboilerReact;
2283        SPLITTER                                as splitter2;
2284        PUMP                                    as pump;
2285#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2286# Column Outlets
2287#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2288        out     VapourDistillate        as vapour_stream        (Brief="Vapour outlet stream From Condenser", PosX=0.59, PosY=0);
2289        out     LiquidDistillate        as liquid_stream        (Brief="Liquid outlet stream From Splitter", PosX=1, PosY=0.23);
2290        out     BottomProduct           as liquid_stream        (Brief="Liquid outlet stream From Reboiler", PosX=0.67, PosY=1);
2291#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2292# Column Connectors
2293#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2294in      ConnectorCondenserVout  as stream       (Brief="Connector for Vapour outlet stream From Top Condenser", Hidden=true);
2295in      ConnectorSplitterOut    as stream       (Brief="Connector for Liquid outlet stream From Top Splitter", Hidden=true);
2296in      ConnectorReboilerLout   as stream       (Brief="Connector for Liquid outlet stream From Reboiler", Hidden=true);
2297#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2298# Column Control Ports
2299#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2300        out     TRI as control_signal   (Brief="Temperature of Reboiler Indicator", PosX=1, PosY=0.83);
2301        out     LRI as control_signal   (Brief="Level of Reboiler Indicator", PosX=1, PosY=0.855);
2302        out     TCI as control_signal   (Brief="Temperature of Condenser Indicator", PosX=1, PosY=0.01);
2303        out     LCI as control_signal   (Brief="Level of Condenser Indicator", PosX=1, PosY=0.04);
2304
2305CONNECTIONS
2306#vapor
2307        REBOILER.OutletVapour                                   to TRAYS(NumberOfTrays).InletVapour;
2308        TRAYS(1).OutletVapour                                   to CONDENSER.InletVapour;
2309        TRAYS([2:NumberOfTrays]).OutletVapour   to TRAYS([1:NumberOfTrays-1]).InletVapour;
2310
2311#liquid
2312        CONDENSER.OutletLiquid                                  to SPLITTER.Inlet;     
2313        SPLITTER.Outlet2                                        to PUMP.Inlet;
2314        PUMP.Outlet                                             to TRAYS(1).InletLiquid;
2315        TRAYS([1:NumberOfTrays-1]).OutletLiquid         to TRAYS([2:NumberOfTrays]).InletLiquid;
2316        TRAYS(NumberOfTrays).OutletLiquid               to REBOILER.InletLiquid;
2317
2318#Connectors
2319        CONDENSER.OutletVapour  to ConnectorCondenserVout;
2320        SPLITTER.Outlet1        to ConnectorSplitterOut;
2321        REBOILER.OutletLiquid   to ConnectorReboilerLout;
2322
2323INITIAL
2324#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2325# Tray Initialization
2326#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2327for i in 1:NumberOfTrays do
2328
2329"The initial temperature of the TRAYS"
2330        TRAYS(i).OutletLiquid.T = INITIALIZATION.TopTemperature+(INITIALIZATION.BottomTemperature-INITIALIZATION.TopTemperature)*((i-1)/(NumberOfTrays-1));
2331
2332"The initial Level of the TRAYS"
2333        TRAYS(i).Level = INITIALIZATION.LevelFraction*hw;
2334end
2335
2336for i in 1:NComp-1 do
2337
2338for j in 1:NumberOfTrays do
2339
2340"The initial composition of the TRAYS - Normalized"
2341        TRAYS(j).OutletLiquid.z(i) = INITIALIZATION.TopComposition(i)/sum(INITIALIZATION.TopComposition) +(INITIALIZATION.BottomComposition(i)/sum(INITIALIZATION.BottomComposition)-INITIALIZATION.TopComposition(i)/sum(INITIALIZATION.TopComposition) )*((j-1)/(NumberOfTrays-1));
2342end
2343
2344end
2345
2346EQUATIONS
2347
2348for i in [1:NumberOfTrays] do
2349
2350"Murphree Efficiency"
2351        TRAYS(i).OutletVapour.z =  MurphreeEff * (TRAYS(i).yideal - TRAYS(i).InletVapour.z) + TRAYS(i).InletVapour.z;
2352       
2353"Energy Holdup"
2354        TRAYS(i).E = TRAYS(i).ML*TRAYS(i).OutletLiquid.h + TRAYS(i).MV*TRAYS(i).OutletVapour.h - TRAYS(i).OutletLiquid.P*V;
2355
2356"Component Molar Balance"
2357        diff(TRAYS(i).M)=TRAYS(i).Inlet.F*TRAYS(i).Inlet.z + TRAYS(i).InletLiquid.F*TRAYS(i).InletLiquid.z + TRAYS(i).InletVapour.F*TRAYS(i).InletVapour.z- TRAYS(i).OutletLiquid.F*TRAYS(i).OutletLiquid.z - TRAYS(i).OutletVapour.F*TRAYS(i).OutletVapour.z-
2358        TRAYS(i).LiquidSideStream.F*TRAYS(i).LiquidSideStream.z-TRAYS(i).VapourSideStream.F*TRAYS(i).VapourSideStream.z + stoic*TRAYS(i).r3*TRAYS(i).ML*TRAYS(i).vL;
2359       
2360"Energy Balance"
2361        diff(TRAYS(i).E) = ( TRAYS(i).Inlet.F*TRAYS(i).Inlet.h + TRAYS(i).InletLiquid.F*TRAYS(i).InletLiquid.h + TRAYS(i).InletVapour.F*TRAYS(i).InletVapour.h- TRAYS(i).OutletLiquid.F*TRAYS(i).OutletLiquid.h - TRAYS(i).OutletVapour.F*TRAYS(i).OutletVapour.h
2362        -TRAYS(i).VapourSideStream.F*TRAYS(i).VapourSideStream.h - TRAYS(i).LiquidSideStream.F*TRAYS(i).LiquidSideStream.h + Q ) + Hr * TRAYS(i).r3 *TRAYS(i). vL*TRAYS(i).ML;
2363
2364"Level of clear liquid over the weir"
2365        TRAYS(i).Level = TRAYS(i).ML*TRAYS(i).vL/Ap;
2366
2367"Geometry Constraint"
2368        V = TRAYS(i).ML* TRAYS(i).vL + TRAYS(i).MV*TRAYS(i).vV;
2369
2370end
2371
2372switch VapourFlow
2373                case "on":
2374                "Pressure Drop through the condenser"
2375                CONDENSER.InletVapour.F*TRAYS(1).vV / 'm^2' =
2376                        sqrt((TRAYS(1).OutletVapour.P - CONDENSER.OutletLiquid.P + 1e-8 * 'atm')/(TRAYS(1).rhoV*alfacond));
2377                when TRAYS(1).OutletVapour.P < CONDENSER.OutletLiquid.P switchto "off";
2378               
2379                case "off":
2380                "Prato selado"
2381                CONDENSER.InletVapour.F = 0.0 * 'mol/s';
2382                when TRAYS(1).OutletVapour.P > CONDENSER.OutletLiquid.P + 1e-3 * 'atm' switchto "on";
2383        end
2384
2385for i in [1:NumberOfTrays] do
2386
2387        switch TrayLiquidFlow
2388                case "on":
2389                "Francis Equation"
2390                TRAYS(i).OutletLiquid.F*TRAYS(i).vL = 1.84*'1/s'*lw*((TRAYS(i).Level-(beta*hw)+1e-6*'m')/(beta))^2;
2391                when TRAYS(i).Level < (beta * hw) switchto "off";
2392               
2393                case "off":
2394                "Low level"
2395                TRAYS(i).OutletLiquid.F = 0 * 'mol/h';
2396                when TRAYS(i).Level > (beta * hw) + 1e-6*'m' switchto "on";
2397        end
2398
2399        switch TrayVapourFlow
2400                case "on":
2401                TRAYS(i).InletVapour.F*TRAYS(i).vV = sqrt((TRAYS(i).InletVapour.P - TRAYS(i).OutletVapour.P - TRAYS(i).Level*g*TRAYS(i).rhoL + 1e-8 * 'atm')/(TRAYS(i).rhoV*alfa))*Ah;
2402                when TRAYS(i).InletVapour.P < TRAYS(i).OutletVapour.P + TRAYS(i).Level*g*TRAYS(i).rhoL switchto "off";
2403               
2404                case "off":
2405                TRAYS(i).InletVapour.F = 0 * 'mol/s';
2406                when TRAYS(i).InletVapour.P > TRAYS(i).OutletVapour.P + TRAYS(i).Level*g*TRAYS(i).rhoL + 3e-2 * 'atm' switchto "on";
2407        end
2408
2409end
2410
2411# Connecting Trays
2412        FeedTray.F*FeedTrayIndex= TRAYS.Inlet.F;
2413        FeedTray.T = TRAYS.Inlet.T;
2414        FeedTray.P = TRAYS.Inlet.P;
2415        FeedTray.z = TRAYS.Inlet.z;
2416        FeedTray.v = TRAYS.Inlet.v;
2417        FeedTray.h = TRAYS.Inlet.h;
2418
2419        HeatToReboiler  = REBOILER.InletQ;
2420        HeatToCondenser = CONDENSER.InletQ;
2421
2422"Reboiler Temperature indicator"
2423        TRI * 'K' = REBOILER.OutletLiquid.T;
2424
2425"Reboiler Level indicator"
2426        LRI*REBOILER.V = REBOILER.Level*REBOILER.Across;
2427
2428"Condenser Temperature indicator"
2429        TCI * 'K' = CONDENSER.OutletLiquid.T;
2430
2431"Condenser Level indicator"
2432        LCI*CONDENSER.V = CONDENSER.Level*CONDENSER.Across;
2433
2434# Condenser Connector Equations
2435        ConnectorCondenserVout.T = VapourDistillate.T;
2436        ConnectorCondenserVout.P = VapourDistillate.P;
2437        ConnectorCondenserVout.F = VapourDistillate.F;
2438        ConnectorCondenserVout.z = VapourDistillate.z;
2439
2440# Splitter Connector Equations
2441        ConnectorSplitterOut.T = LiquidDistillate.T;
2442        ConnectorSplitterOut.P = LiquidDistillate.P;
2443        ConnectorSplitterOut.F = LiquidDistillate.F;
2444        ConnectorSplitterOut.z = LiquidDistillate.z;
2445
2446# Reboiler Connector Equations
2447        ConnectorReboilerLout.T = BottomProduct.T;
2448        ConnectorReboilerLout.P = BottomProduct.P;
2449        ConnectorReboilerLout.F = BottomProduct.F;
2450        ConnectorReboilerLout.z = BottomProduct.z;
2451
2452        VapourDrawOff.F*VapSideTrayIndex= TRAYS.VapourSideStream.F;
2453        VapourDrawOff.T = TRAYS(VapourSideStreamLocation).VapourSideStream.T;
2454        VapourDrawOff.P = TRAYS(VapourSideStreamLocation).VapourSideStream.P;
2455        VapourDrawOff.z = TRAYS(VapourSideStreamLocation).VapourSideStream.z;
2456
2457        LiquidDrawOff.F*LiqSideTrayIndex= TRAYS.LiquidSideStream.F;
2458        LiquidDrawOff.T = TRAYS(LiquidSideStreamLocation).LiquidSideStream.T;
2459        LiquidDrawOff.P = TRAYS(LiquidSideStreamLocation).LiquidSideStream.P;
2460        LiquidDrawOff.z = TRAYS(LiquidSideStreamLocation).LiquidSideStream.z;
2461
2462        VapourDrawOffFlow = VapourDrawOff.F;
2463        LiquidDrawOffFlow = LiquidDrawOff.F;
2464
2465end
2466
2467Model Packed_Section_ColumnBasic
2468        ATTRIBUTES
2469        Pallete         = false;
2470        Icon            = "icon/PackedSectionColumn";
2471        Brief           = "Model of a packed column section.";
2472        Info            =
2473"== Model of a packed column section containing ==
2474* NStages theoretical stages.
2475       
2476== Specify ==
2477* the feed stream of each tray (Inlet);
2478* the InletLiquid stream of the top tray;
2479* the InletVapour stream of the bottom tray;
2480* the total pressure drop (dP) of the section.
2481       
2482== Initial Conditions ==
2483* the stages temperature (OutletLiquid.T);
2484* the stages liquid holdup;
2485* (NoComps - 1) OutletLiquid (OR OutletVapour) compositions for each tray.
2486";
2487       
2488PARAMETERS
2489
2490        outer PP                as Plugin(Brief = "External Physical Properties", Type="PP");
2491        outer NComp     as Integer;
2492       
2493        NumberOfStages                                  as Integer      (Brief="Number of Stages", Default=3);
2494        FeedStageIndex(NumberOfStages)  as Integer      (Brief="Number of Stages", Default=0,Hidden=true);
2495        FeedStageLocation                               as Integer      (Brief="Feed Stage Location", Default=2);
2496       
2497        PackingHeight           as length               (Brief="Height of packing");
2498        HeatSupply                      as heat_rate    (Brief="Rate of heat supply");
2499        ColumnDiameter          as length               (Brief="Column diameter");
2500        VoidFraction            as Real                 (Brief="Void fraction of packing, m^3/m^3");
2501        ResistanceCoeff         as positive     (Brief="Resistance coefficient on the liquid load", Default=1);
2502        AreaPerPackingVol       as Real                 (Brief="surface area per packing volume", Unit='m^2/m^3');
2503       
2504        V                               as volume               (Brief="Total Volume of the tray",Hidden=true);
2505        g                               as acceleration (Brief="Gravity Acceleration",Default=9.81,Hidden=true);
2506        hs                              as length               (Brief="Height of the packing stage",Hidden=true);
2507        ColumnArea              as area                 (Brief="Column Sectional Cross Area",Hidden=true);
2508
2509VARIABLES
2510#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2511# Stages Initialization For the Whole Column Section
2512#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2513        INITIALIZATION          as InitializeStage      (Brief = "Column Model Initialization");
2514        in      FeedStage       as stream               (Brief="Feed stream", PosX=0, PosY=0.55);
2515       
2516        STAGES(NumberOfStages) as packedStage;
2517        PressureDrop               as pressure;
2518       
2519SET
2520        FeedStageIndex(FeedStageLocation) =1;
2521       
2522        ColumnArea = ColumnDiameter^2*3.14159*0.25;
2523        hs =PackingHeight/NumberOfStages;       
2524        V = hs * ColumnArea;
2525       
2526CONNECTIONS
2527
2528        STAGES([2:NumberOfStages]).OutletVapour                 to STAGES([1:NumberOfStages-1]).InletVapour;
2529        STAGES([1:NumberOfStages-1]).OutletLiquid       to STAGES([2:NumberOfStages]).InletLiquid;
2530
2531EQUATIONS
2532# Connecting STAGES
2533        FeedStage.F*FeedStageIndex= STAGES.Inlet.F;
2534        FeedStage.T = STAGES.Inlet.T;
2535        FeedStage.P = STAGES.Inlet.P;
2536        FeedStage.z = STAGES.Inlet.z;
2537        FeedStage.v = STAGES.Inlet.v;
2538        FeedStage.h = STAGES.Inlet.h;
2539
2540        STAGES.deltaP = PressureDrop/NumberOfStages;
2541
2542for i in [1:NumberOfStages] do
2543
2544"Energy Balance"
2545        diff(STAGES(i).E) = ( STAGES(i).Inlet.F*STAGES(i).Inlet.h + STAGES(i).InletLiquid.F*STAGES(i).InletLiquid.h + STAGES(i).InletVapour.F*STAGES(i).InletVapour.h- STAGES(i).OutletLiquid.F*STAGES(i).OutletLiquid.h
2546        - STAGES(i).OutletVapour.F*STAGES(i).OutletVapour.h + HeatSupply );
2547       
2548"Energy Holdup"
2549        STAGES(i).E = STAGES(i).ML*STAGES(i).OutletLiquid.h + STAGES(i).MV*STAGES(i).OutletVapour.h - STAGES(i).OutletLiquid.P*V;
2550       
2551"Geometry Constraint"
2552        V*VoidFraction= STAGES(i).ML*STAGES(i).vL + STAGES(i).MV*STAGES(i).vV;
2553       
2554"Volume flow rate of vapor, m^3/m^2/s"
2555        STAGES(i).uV * ((ColumnArea)*VoidFraction - STAGES(i).Al) = STAGES(i).OutletVapour.F * STAGES(i).vV;
2556       
2557"Liquid holdup"
2558        STAGES(i).hl = STAGES(i).ML*STAGES(i).vL/V/VoidFraction;
2559       
2560"Particle diameter"
2561        STAGES(i).dp = 6 * (1-VoidFraction)/AreaPerPackingVol;
2562       
2563"Wall Factor"
2564        STAGES(i).invK = (1 + (2*STAGES(i).dp/(3*ColumnDiameter*(1-VoidFraction))));
2565       
2566"Reynolds number of the vapor stream"
2567        STAGES(i).Rev*STAGES(i).invK = STAGES(i).dp*STAGES(i).uV*STAGES(i).rhoV / (STAGES(i).miV*(1-VoidFraction));
2568       
2569"Pressure drop and Vapor flow"
2570        STAGES(i).deltaP/hs  = ResistanceCoeff*AreaPerPackingVol*STAGES(i).uV^2*STAGES(i).rhoV*STAGES(i).invK / (2*(VoidFraction-STAGES(i).hl)^3);
2571
2572"Liquid holdup"
2573        STAGES(i).hl = (12*STAGES(i).miL*AreaPerPackingVol^2*STAGES(i).uL/STAGES(i).rhoL/g)^1/3;
2574
2575"Area occupied by the liquid"
2576        STAGES(i).Al = STAGES(i).ML*STAGES(i).vL/hs;
2577
2578end
2579
2580INITIAL
2581
2582for i in 1:NumberOfStages do
2583
2584"The initial temperature of the STAGES"
2585        STAGES(i).OutletLiquid.T = INITIALIZATION.TopStageTemperature+(INITIALIZATION.BottomStageTemperature-INITIALIZATION.TopStageTemperature)*((i-1)/(NumberOfStages-1));
2586
2587"The Liquid Holdup of the STAGES"
2588        STAGES(i).ML = INITIALIZATION.LiquidMolarHoldup;
2589
2590end
2591
2592for i in 1:NComp-1 do
2593       
2594for j in 1:NumberOfStages do
2595
2596"The initial composition of the TRAYS"
2597        STAGES(j).OutletLiquid.z(i) = INITIALIZATION.TopStageComposition(i)/sum(INITIALIZATION.TopStageComposition) +(INITIALIZATION.BottomStageComposition(i)/sum(INITIALIZATION.BottomStageComposition)-INITIALIZATION.TopStageComposition(i)/sum(INITIALIZATION.TopStageComposition) )*((j-1)/(NumberOfStages-1));
2598
2599end
2600
2601end
2602
2603end
2604
2605Model Packed_Section_Column as Packed_Section_ColumnBasic
2606
2607        ATTRIBUTES
2608        Pallete         = true;
2609        Icon            = "icon/PackedSectionColumn";
2610        Brief           = "Model of a packed column section.";
2611        Info            =
2612"== Model of a packed column section containing ==
2613* NStages theoretical stages.
2614       
2615== Specify ==
2616* the feed stream of each tray (Inlet);
2617* the InletLiquid stream of the top tray;
2618* the InletVapour stream of the bottom tray;
2619* the total pressure drop (dP) of the section.
2620       
2621== Initial Conditions ==
2622* the stages temperature (OutletLiquid.T);
2623* the stages liquid holdup;
2624* (NoComps - 1) OutletLiquid (OR OutletVapour) compositions for each tray.
2625";
2626
2627VARIABLES
2628
2629        in              LiquidInlet             as      stream                          (Brief="Liquid Inlet in the section", PosX=0.70, PosY=0);
2630        out     VapourOutlet            as vapour_stream        (Brief="Vapour Outlet in the section", PosX=0.30, PosY=0);
2631       
2632        in              VapourInlet             as stream                               (Brief="Vapour Inlet in the section", PosX=0.30, PosY=1);
2633        out     LiquidOutlet            as liquid_stream                (Brief="Liquid Outlet in the section", PosX=0.70, PosY=1);
2634       
2635        LiquidConnector as stream       (Brief="Liquid connection at the middle STAGES", PosX=0.75, PosY=1,Hidden=true);
2636        VapourConnector as stream       (Brief="Vapour connection at the middle STAGES", PosX=0.55, PosY=0,Hidden=true);
2637
2638CONNECTIONS
2639
2640        LiquidConnector to STAGES(1).InletLiquid;
2641        VapourConnector to STAGES(NumberOfStages).InletVapour;
2642       
2643EQUATIONS
2644
2645        LiquidConnector.F= LiquidInlet.F;
2646        LiquidConnector.T = LiquidInlet.T;
2647        LiquidConnector.P = LiquidInlet.P;
2648        LiquidConnector.z = LiquidInlet.z;
2649        LiquidConnector.v = LiquidInlet.v;
2650        LiquidConnector.h = LiquidInlet.h;
2651       
2652        VapourConnector.F= VapourInlet.F;
2653        VapourConnector.T = VapourInlet.T;
2654        VapourConnector.P = VapourInlet.P;
2655        VapourConnector.z = VapourInlet.z;
2656        VapourConnector.v = VapourInlet.v;
2657        VapourConnector.h = VapourInlet.h;
2658       
2659        LiquidOutlet.F= STAGES(NumberOfStages).OutletLiquid.F;
2660        LiquidOutlet.T = STAGES(NumberOfStages).OutletLiquid.T;
2661        LiquidOutlet.P = STAGES(NumberOfStages).OutletLiquid.P;
2662        LiquidOutlet.z = STAGES(NumberOfStages).OutletLiquid.z;
2663       
2664        VapourOutlet.F= STAGES(1).OutletVapour.F;
2665        VapourOutlet.T = STAGES(1).OutletVapour.T;
2666        VapourOutlet.P = STAGES(1).OutletVapour.P;
2667        VapourOutlet.z = STAGES(1).OutletVapour.z;
2668
2669end
2670
2671Model PackedDistillation_kettle_cond as Packed_Section_ColumnBasic
2672        ATTRIBUTES
2673        Pallete         = true;
2674        Icon            = "icon/PackedDistillationKettleCond";
2675        Brief           = "Model of a distillation column with dynamic condenser and dynamic reboiler.";
2676        Info            =
2677"== Specify ==
2678* the feed stream of each tray (Inlet);
2679* the pump pressure difference;
2680* the total pressure drop (dP) of the packing;
2681* the heat supllied in reboiler and condenser;
2682* the condenser vapor outlet flow (OutletVapour.F);
2683* the reboiler liquid outlet flow (OutletLiquid.F);
2684* both splitter outlet flows OR one of the splitter outlet flows and the splitter frac.
2685       
2686== Initial Conditions ==
2687* the stages temperature (OutletLiquid.T);
2688* the stages initial molar holdup;
2689* (NoComps - 1) OutletLiquid (OR OutletVapour) compositions for each stage;
2690       
2691* the condenser temperature (OutletLiquid.T);
2692* the condenser liquid level (Level);
2693* (NoComps - 1) OutletLiquid (OR OutletVapour) compositions;
2694       
2695* the reboiler temperature (OutletLiquid.T);
2696* the reboiler liquid level (Level);
2697* (NoComps - 1) OutletLiquid (OR OutletVapour) compositions.
2698";
2699       
2700PARAMETERS
2701
2702        VapourFlow as Switcher  (Valid = ["on", "off"], Hidden = true ,Default = "on");
2703       
2704VARIABLES
2705#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2706# Column Devices
2707#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++     
2708        CONDENSER       as condenser    (Brief="dymamic condenser");
2709        REBOILER        as reboiler             (Brief="kettle reboiler");
2710        SPLITTER        as splitter2            (Brief="splitter which separate reflux and distillate");
2711        PUMP            as pump                 (Brief="pump in reflux stream");
2712#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2713# Heat Ports
2714#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++     
2715        in      HeatToReboiler  as power (Brief="Heat supplied to Reboiler",Protected = true, PosX=1, PosY=0.885);
2716        in      HeatToCondenser as power (Brief="Heat supplied to Condenser", Protected = true, PosX=1, PosY=0.034);
2717#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2718# Column Products
2719#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++     
2720        out     VapourDistillate        as vapour_stream        (Brief="Vapour outlet stream From Top Condenser", PosX=0.66, PosY=0);
2721        out     LiquidDistillate        as liquid_stream        (Brief="Liquid outlet stream From Top Splitter", PosX=1, PosY=0.20);
2722        out     BottomProduct           as liquid_stream        (Brief="Liquid outlet stream From Reboiler", PosX=0.68, PosY=1);
2723#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2724# Column Connectors
2725#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++             
2726        in      ConnectorCondenserVout  as stream       (Brief="Connector for Vapour outlet stream From Top Condenser", Hidden=true);
2727        in      ConnectorSplitterOut    as stream       (Brief="Connector for Liquid outlet stream From Top Splitter", Hidden=true);
2728        in      ConnectorReboilerLout   as stream       (Brief="Connector for Liquid outlet stream From Reboiler", Hidden=true);
2729                ConnectorHeatReboiler   as power        (Brief="Heat supplied to Reboiler", Hidden=true);
2730                ConnectorHeatCondenser  as power        (Brief="Heat supplied to Condenser", Hidden=true);
2731
2732CONNECTIONS
2733
2734#vapor
2735        REBOILER.OutletVapour           to STAGES(NumberOfStages).InletVapour;
2736        STAGES(1).OutletVapour          to CONDENSER.InletVapour;
2737
2738#liquid
2739        CONDENSER.OutletLiquid                          to SPLITTER.Inlet;     
2740        SPLITTER.Outlet2                                to PUMP.Inlet;
2741        PUMP.Outlet                                     to STAGES(1).InletLiquid;
2742        STAGES(NumberOfStages).OutletLiquid     to REBOILER.InletLiquid;
2743
2744#Connectors
2745ConnectorHeatReboiler   to REBOILER.InletQ;
2746ConnectorHeatCondenser  to CONDENSER.InletQ;
2747
2748CONDENSER.OutletVapour          to ConnectorCondenserVout;
2749SPLITTER.Outlet1                to ConnectorSplitterOut;
2750REBOILER.OutletLiquid           to ConnectorReboilerLout;
2751
2752EQUATIONS
2753        HeatToReboiler  = ConnectorHeatReboiler;
2754        HeatToCondenser = ConnectorHeatCondenser;
2755       
2756# Condenser Connector Equations
2757        ConnectorCondenserVout.T = VapourDistillate.T;
2758        ConnectorCondenserVout.P = VapourDistillate.P;
2759        ConnectorCondenserVout.F = VapourDistillate.F;
2760        ConnectorCondenserVout.z = VapourDistillate.z;
2761
2762# Splitter Connector Equations
2763        ConnectorSplitterOut.T = LiquidDistillate.T;
2764        ConnectorSplitterOut.P = LiquidDistillate.P;
2765        ConnectorSplitterOut.F = LiquidDistillate.F;
2766        ConnectorSplitterOut.z = LiquidDistillate.z;
2767
2768# Reboiler Connector Equations
2769        ConnectorReboilerLout.T = BottomProduct.T;
2770        ConnectorReboilerLout.P = BottomProduct.P;
2771        ConnectorReboilerLout.F = BottomProduct.F;
2772        ConnectorReboilerLout.z = BottomProduct.z;
2773
2774switch VapourFlow
2775        case "on":
2776                STAGES(NumberOfStages).InletVapour.F*STAGES(NumberOfStages).vV = sqrt((REBOILER.OutletVapour.P - STAGES(NumberOfStages).OutletVapour.P)/
2777                                        (STAGES(NumberOfStages).rhoV*ResistanceCoeff*20))*(ColumnArea*VoidFraction - STAGES(NumberOfStages).Al);
2778                when STAGES(NumberOfStages).InletVapour.F < 1e-6 * 'kmol/h' switchto "off";
2779
2780        case "off":
2781                STAGES(NumberOfStages).InletVapour.F = 0 * 'mol/s';
2782                when REBOILER.OutletVapour.P > STAGES(NumberOfStages).OutletVapour.P + 1e-1 * 'atm' switchto "on";
2783end
2784
2785end
2786
Note: See TracBrowser for help on using the repository browser.